From 72a4734935ee04b46cf20395dedfa39edfad906c Mon Sep 17 00:00:00 2001 From: Andrey Bocharnikov Date: Wed, 16 Oct 2024 15:57:01 +0400 Subject: [PATCH] chore_: remove rpclimiter from rpc/chain/client.go proper refactoring will be in a separate PR --- .../provider_errors/rpc_provider_errors.go | 4 +- rpc/chain/client.go | 41 +------------------ 2 files changed, 2 insertions(+), 43 deletions(-) diff --git a/healthmanager/provider_errors/rpc_provider_errors.go b/healthmanager/provider_errors/rpc_provider_errors.go index 7f1c8c90e..907b89808 100644 --- a/healthmanager/provider_errors/rpc_provider_errors.go +++ b/healthmanager/provider_errors/rpc_provider_errors.go @@ -62,9 +62,7 @@ func determineRpcErrorType(err error) RpcProviderErrorType { if err == nil { return RpcErrorTypeNone } - //if IsRpsLimitError(err) { - // return RpcErrorTypeRPSLimit - //} + if IsMethodNotFoundError(err) || IsNotFoundError(err) { return RpcErrorTypeMethodNotFound } diff --git a/rpc/chain/client.go b/rpc/chain/client.go index 226c5aa73..ae414d911 100644 --- a/rpc/chain/client.go +++ b/rpc/chain/client.go @@ -5,7 +5,6 @@ package chain import ( "context" "errors" - "fmt" "math/big" "strings" "sync/atomic" @@ -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 @@ -160,12 +159,6 @@ func isVMError(err error) bool { return false } -func isRPSLimitError(err error) bool { - return strings.Contains(err.Error(), "backoff_seconds") || - strings.Contains(err.Error(), "has exceeded its throughput limit") || - strings.Contains(err.Error(), "request rate exceeded") -} - func (c *ClientWithFallback) SetIsConnected(value bool) { c.LastCheckedAt = time.Now().Unix() if !value { @@ -191,46 +184,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() }