Skip to content

Commit

Permalink
chore_: remove rpclimiter from rpc/chain/client.go
Browse files Browse the repository at this point in the history
proper refactoring will be in a separate PR
  • Loading branch information
friofry committed Oct 16, 2024
1 parent fadce93 commit 7b46060
Showing 1 changed file with 1 addition and 34 deletions.
35 changes: 1 addition & 34 deletions rpc/chain/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package chain
import (
"context"
"errors"
"fmt"
"math/big"
"strings"
"sync/atomic"
Expand Down Expand Up @@ -67,7 +66,7 @@ func ClientWithTag(chainClient ClientInterface, tag, groupTag string) ClientInte
type ClientWithFallback struct {
ChainID uint64
ethClients []ethclient.RPSLimitedEthClientInterface
commonLimiter rpclimiter.RequestLimiter
commonLimiter rpclimiter.RequestLimiter // FIXME: remove from RPC client https://github.com/status-im/status-go/issues/5942
circuitbreaker *circuitbreaker.CircuitBreaker
providersHealthManager *healthmanager.ProvidersHealthManager

Expand Down Expand Up @@ -191,46 +190,14 @@ func (c *ClientWithFallback) IsConnected() bool {
}

func (c *ClientWithFallback) makeCall(ctx context.Context, ethClients []ethclient.RPSLimitedEthClientInterface, f func(client ethclient.RPSLimitedEthClientInterface) (interface{}, error)) (interface{}, error) {
if c.commonLimiter != nil {
if allow, err := c.commonLimiter.Allow(c.tag); !allow {
return nil, fmt.Errorf("tag=%s, %w", c.tag, err)
}

if allow, err := c.commonLimiter.Allow(c.groupTag); !allow {
return nil, fmt.Errorf("groupTag=%s, %w", c.groupTag, err)
}
}

c.LastCheckedAt = time.Now().Unix()

cmd := circuitbreaker.NewCommand(ctx, nil)
for _, provider := range ethClients {
provider := provider
cmd.Add(circuitbreaker.NewFunctor(func() ([]interface{}, error) {
limiter := provider.GetLimiter()
if limiter != nil {
err := provider.GetLimiter().WaitForRequestsAvailability(1)
if err != nil {
return nil, err
}
}

res, err := f(provider)
if err != nil {
if limiter != nil && isRPSLimitError(err) {
provider.GetLimiter().ReduceLimit()

err = provider.GetLimiter().WaitForRequestsAvailability(1)
if err != nil {
return nil, err
}

res, err = f(provider)
if err == nil {
return []interface{}{res}, err
}
}

if isVMError(err) || errors.Is(err, context.Canceled) {
cmd.Cancel()
}
Expand Down

0 comments on commit 7b46060

Please sign in to comment.