chore_: remove rpclimiter from rpc/chain/client.go
proper refactoring will be in a separate PR
This commit is contained in:
parent
fadce938e4
commit
72a4734935
|
@ -62,9 +62,7 @@ func determineRpcErrorType(err error) RpcProviderErrorType {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return RpcErrorTypeNone
|
return RpcErrorTypeNone
|
||||||
}
|
}
|
||||||
//if IsRpsLimitError(err) {
|
|
||||||
// return RpcErrorTypeRPSLimit
|
|
||||||
//}
|
|
||||||
if IsMethodNotFoundError(err) || IsNotFoundError(err) {
|
if IsMethodNotFoundError(err) || IsNotFoundError(err) {
|
||||||
return RpcErrorTypeMethodNotFound
|
return RpcErrorTypeMethodNotFound
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,6 @@ package chain
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
"math/big"
|
"math/big"
|
||||||
"strings"
|
"strings"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
@ -67,7 +66,7 @@ func ClientWithTag(chainClient ClientInterface, tag, groupTag string) ClientInte
|
||||||
type ClientWithFallback struct {
|
type ClientWithFallback struct {
|
||||||
ChainID uint64
|
ChainID uint64
|
||||||
ethClients []ethclient.RPSLimitedEthClientInterface
|
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
|
circuitbreaker *circuitbreaker.CircuitBreaker
|
||||||
providersHealthManager *healthmanager.ProvidersHealthManager
|
providersHealthManager *healthmanager.ProvidersHealthManager
|
||||||
|
|
||||||
|
@ -160,12 +159,6 @@ func isVMError(err error) bool {
|
||||||
return false
|
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) {
|
func (c *ClientWithFallback) SetIsConnected(value bool) {
|
||||||
c.LastCheckedAt = time.Now().Unix()
|
c.LastCheckedAt = time.Now().Unix()
|
||||||
if !value {
|
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) {
|
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()
|
c.LastCheckedAt = time.Now().Unix()
|
||||||
|
|
||||||
cmd := circuitbreaker.NewCommand(ctx, nil)
|
cmd := circuitbreaker.NewCommand(ctx, nil)
|
||||||
for _, provider := range ethClients {
|
for _, provider := range ethClients {
|
||||||
provider := provider
|
provider := provider
|
||||||
cmd.Add(circuitbreaker.NewFunctor(func() ([]interface{}, error) {
|
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)
|
res, err := f(provider)
|
||||||
if err != nil {
|
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) {
|
if isVMError(err) || errors.Is(err, context.Canceled) {
|
||||||
cmd.Cancel()
|
cmd.Cancel()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue