parent
b1c4588a8c
commit
89763b373f
|
@ -27,7 +27,7 @@ type BlockchainHealthManagerSuite struct {
|
||||||
suite.Suite
|
suite.Suite
|
||||||
blockchainHealthManager *healthmanager.BlockchainHealthManager
|
blockchainHealthManager *healthmanager.BlockchainHealthManager
|
||||||
mockProviders map[uint64]*healthmanager.ProvidersHealthManager
|
mockProviders map[uint64]*healthmanager.ProvidersHealthManager
|
||||||
mockEthClients map[uint64]*mockEthclient.MockRPSLimitedEthClientInterface
|
mockEthClients map[uint64]*mockEthclient.MockEthClientInterface
|
||||||
clients map[uint64]*ClientWithFallback
|
clients map[uint64]*ClientWithFallback
|
||||||
mockCtrl *gomock.Controller
|
mockCtrl *gomock.Controller
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ type BlockchainHealthManagerSuite struct {
|
||||||
func (s *BlockchainHealthManagerSuite) SetupTest() {
|
func (s *BlockchainHealthManagerSuite) SetupTest() {
|
||||||
s.blockchainHealthManager = healthmanager.NewBlockchainHealthManager()
|
s.blockchainHealthManager = healthmanager.NewBlockchainHealthManager()
|
||||||
s.mockProviders = make(map[uint64]*healthmanager.ProvidersHealthManager)
|
s.mockProviders = make(map[uint64]*healthmanager.ProvidersHealthManager)
|
||||||
s.mockEthClients = make(map[uint64]*mockEthclient.MockRPSLimitedEthClientInterface)
|
s.mockEthClients = make(map[uint64]*mockEthclient.MockEthClientInterface)
|
||||||
s.clients = make(map[uint64]*ClientWithFallback)
|
s.clients = make(map[uint64]*ClientWithFallback)
|
||||||
s.mockCtrl = gomock.NewController(s.T())
|
s.mockCtrl = gomock.NewController(s.T())
|
||||||
}
|
}
|
||||||
|
@ -49,11 +49,11 @@ func (s *BlockchainHealthManagerSuite) setupClients(chainIDs []uint64) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
for _, chainID := range chainIDs {
|
for _, chainID := range chainIDs {
|
||||||
mockEthClient := mockEthclient.NewMockRPSLimitedEthClientInterface(s.mockCtrl)
|
mockEthClient := mockEthclient.NewMockEthClientInterface(s.mockCtrl)
|
||||||
mockEthClient.EXPECT().GetName().AnyTimes().Return(fmt.Sprintf("test_client_chain_%d", chainID))
|
mockEthClient.EXPECT().GetName().AnyTimes().Return(fmt.Sprintf("test_client_chain_%d", chainID))
|
||||||
|
|
||||||
phm := healthmanager.NewProvidersHealthManager(chainID)
|
phm := healthmanager.NewProvidersHealthManager(chainID)
|
||||||
client := NewClient([]ethclient.RPSLimitedEthClientInterface{mockEthClient}, chainID, phm)
|
client := NewClient([]ethclient.EthClientInterface{mockEthClient}, chainID, phm)
|
||||||
|
|
||||||
err := s.blockchainHealthManager.RegisterProvidersHealthManager(ctx, phm)
|
err := s.blockchainHealthManager.RegisterProvidersHealthManager(ctx, phm)
|
||||||
require.NoError(s.T(), err)
|
require.NoError(s.T(), err)
|
||||||
|
|
|
@ -62,7 +62,7 @@ func ClientWithTag(chainClient ClientInterface, tag, groupTag string) ClientInte
|
||||||
|
|
||||||
type ClientWithFallback struct {
|
type ClientWithFallback struct {
|
||||||
ChainID uint64
|
ChainID uint64
|
||||||
ethClients []ethclient.RPSLimitedEthClientInterface
|
ethClients []ethclient.EthClientInterface
|
||||||
circuitbreaker *circuitbreaker.CircuitBreaker
|
circuitbreaker *circuitbreaker.CircuitBreaker
|
||||||
providersHealthManager *healthmanager.ProvidersHealthManager
|
providersHealthManager *healthmanager.ProvidersHealthManager
|
||||||
|
|
||||||
|
@ -108,7 +108,7 @@ var propagateErrors = []error{
|
||||||
bind.ErrNoCode,
|
bind.ErrNoCode,
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewClient(ethClients []ethclient.RPSLimitedEthClientInterface, chainID uint64, providersHealthManager *healthmanager.ProvidersHealthManager) *ClientWithFallback {
|
func NewClient(ethClients []ethclient.EthClientInterface, chainID uint64, providersHealthManager *healthmanager.ProvidersHealthManager) *ClientWithFallback {
|
||||||
cbConfig := circuitbreaker.Config{
|
cbConfig := circuitbreaker.Config{
|
||||||
Timeout: 20000,
|
Timeout: 20000,
|
||||||
MaxConcurrentRequests: 100,
|
MaxConcurrentRequests: 100,
|
||||||
|
@ -178,7 +178,7 @@ func (c *ClientWithFallback) IsConnected() bool {
|
||||||
return c.isConnected.Load()
|
return c.isConnected.Load()
|
||||||
}
|
}
|
||||||
|
|
||||||
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.EthClientInterface, f func(client ethclient.EthClientInterface) (interface{}, error)) (interface{}, error) {
|
||||||
c.LastCheckedAt = time.Now().Unix()
|
c.LastCheckedAt = time.Now().Unix()
|
||||||
|
|
||||||
cmd := circuitbreaker.NewCommand(ctx, nil)
|
cmd := circuitbreaker.NewCommand(ctx, nil)
|
||||||
|
@ -213,7 +213,7 @@ func (c *ClientWithFallback) BlockByHash(ctx context.Context, hash common.Hash)
|
||||||
rpcstats.CountCallWithTag("eth_BlockByHash", c.tag)
|
rpcstats.CountCallWithTag("eth_BlockByHash", c.tag)
|
||||||
|
|
||||||
res, err := c.makeCall(
|
res, err := c.makeCall(
|
||||||
ctx, c.ethClients, func(client ethclient.RPSLimitedEthClientInterface) (interface{}, error) {
|
ctx, c.ethClients, func(client ethclient.EthClientInterface) (interface{}, error) {
|
||||||
return client.BlockByHash(ctx, hash)
|
return client.BlockByHash(ctx, hash)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -230,7 +230,7 @@ func (c *ClientWithFallback) BlockByHash(ctx context.Context, hash common.Hash)
|
||||||
func (c *ClientWithFallback) BlockByNumber(ctx context.Context, number *big.Int) (*types.Block, error) {
|
func (c *ClientWithFallback) BlockByNumber(ctx context.Context, number *big.Int) (*types.Block, error) {
|
||||||
rpcstats.CountCallWithTag("eth_BlockByNumber", c.tag)
|
rpcstats.CountCallWithTag("eth_BlockByNumber", c.tag)
|
||||||
res, err := c.makeCall(
|
res, err := c.makeCall(
|
||||||
ctx, c.ethClients, func(client ethclient.RPSLimitedEthClientInterface) (interface{}, error) {
|
ctx, c.ethClients, func(client ethclient.EthClientInterface) (interface{}, error) {
|
||||||
return client.BlockByNumber(ctx, number)
|
return client.BlockByNumber(ctx, number)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -248,7 +248,7 @@ func (c *ClientWithFallback) BlockNumber(ctx context.Context) (uint64, error) {
|
||||||
rpcstats.CountCallWithTag("eth_BlockNumber", c.tag)
|
rpcstats.CountCallWithTag("eth_BlockNumber", c.tag)
|
||||||
|
|
||||||
res, err := c.makeCall(
|
res, err := c.makeCall(
|
||||||
ctx, c.ethClients, func(client ethclient.RPSLimitedEthClientInterface) (interface{}, error) {
|
ctx, c.ethClients, func(client ethclient.EthClientInterface) (interface{}, error) {
|
||||||
return client.BlockNumber(ctx)
|
return client.BlockNumber(ctx)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -265,7 +265,7 @@ func (c *ClientWithFallback) BlockNumber(ctx context.Context) (uint64, error) {
|
||||||
func (c *ClientWithFallback) HeaderByHash(ctx context.Context, hash common.Hash) (*types.Header, error) {
|
func (c *ClientWithFallback) HeaderByHash(ctx context.Context, hash common.Hash) (*types.Header, error) {
|
||||||
rpcstats.CountCallWithTag("eth_HeaderByHash", c.tag)
|
rpcstats.CountCallWithTag("eth_HeaderByHash", c.tag)
|
||||||
res, err := c.makeCall(
|
res, err := c.makeCall(
|
||||||
ctx, c.ethClients, func(client ethclient.RPSLimitedEthClientInterface) (interface{}, error) {
|
ctx, c.ethClients, func(client ethclient.EthClientInterface) (interface{}, error) {
|
||||||
return client.HeaderByHash(ctx, hash)
|
return client.HeaderByHash(ctx, hash)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -282,7 +282,7 @@ func (c *ClientWithFallback) HeaderByHash(ctx context.Context, hash common.Hash)
|
||||||
func (c *ClientWithFallback) HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error) {
|
func (c *ClientWithFallback) HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error) {
|
||||||
rpcstats.CountCallWithTag("eth_HeaderByNumber", c.tag)
|
rpcstats.CountCallWithTag("eth_HeaderByNumber", c.tag)
|
||||||
res, err := c.makeCall(
|
res, err := c.makeCall(
|
||||||
ctx, c.ethClients, func(client ethclient.RPSLimitedEthClientInterface) (interface{}, error) {
|
ctx, c.ethClients, func(client ethclient.EthClientInterface) (interface{}, error) {
|
||||||
return client.HeaderByNumber(ctx, number)
|
return client.HeaderByNumber(ctx, number)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -300,7 +300,7 @@ func (c *ClientWithFallback) TransactionByHash(ctx context.Context, hash common.
|
||||||
rpcstats.CountCallWithTag("eth_TransactionByHash", c.tag)
|
rpcstats.CountCallWithTag("eth_TransactionByHash", c.tag)
|
||||||
|
|
||||||
res, err := c.makeCall(
|
res, err := c.makeCall(
|
||||||
ctx, c.ethClients, func(client ethclient.RPSLimitedEthClientInterface) (interface{}, error) {
|
ctx, c.ethClients, func(client ethclient.EthClientInterface) (interface{}, error) {
|
||||||
tx, isPending, err := client.TransactionByHash(ctx, hash)
|
tx, isPending, err := client.TransactionByHash(ctx, hash)
|
||||||
return []any{tx, isPending}, err
|
return []any{tx, isPending}, err
|
||||||
},
|
},
|
||||||
|
@ -320,7 +320,7 @@ func (c *ClientWithFallback) TransactionSender(ctx context.Context, tx *types.Tr
|
||||||
rpcstats.CountCall("eth_TransactionSender")
|
rpcstats.CountCall("eth_TransactionSender")
|
||||||
|
|
||||||
res, err := c.makeCall(
|
res, err := c.makeCall(
|
||||||
ctx, c.ethClients, func(client ethclient.RPSLimitedEthClientInterface) (interface{}, error) {
|
ctx, c.ethClients, func(client ethclient.EthClientInterface) (interface{}, error) {
|
||||||
return client.TransactionSender(ctx, tx, block, index)
|
return client.TransactionSender(ctx, tx, block, index)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -334,7 +334,7 @@ func (c *ClientWithFallback) TransactionReceipt(ctx context.Context, txHash comm
|
||||||
rpcstats.CountCall("eth_TransactionReceipt")
|
rpcstats.CountCall("eth_TransactionReceipt")
|
||||||
|
|
||||||
res, err := c.makeCall(
|
res, err := c.makeCall(
|
||||||
ctx, c.ethClients, func(client ethclient.RPSLimitedEthClientInterface) (interface{}, error) {
|
ctx, c.ethClients, func(client ethclient.EthClientInterface) (interface{}, error) {
|
||||||
return client.TransactionReceipt(ctx, txHash)
|
return client.TransactionReceipt(ctx, txHash)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -352,7 +352,7 @@ func (c *ClientWithFallback) SyncProgress(ctx context.Context) (*ethereum.SyncPr
|
||||||
rpcstats.CountCall("eth_SyncProgress")
|
rpcstats.CountCall("eth_SyncProgress")
|
||||||
|
|
||||||
res, err := c.makeCall(
|
res, err := c.makeCall(
|
||||||
ctx, c.ethClients, func(client ethclient.RPSLimitedEthClientInterface) (interface{}, error) {
|
ctx, c.ethClients, func(client ethclient.EthClientInterface) (interface{}, error) {
|
||||||
return client.SyncProgress(ctx)
|
return client.SyncProgress(ctx)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -374,7 +374,7 @@ func (c *ClientWithFallback) BalanceAt(ctx context.Context, account common.Addre
|
||||||
rpcstats.CountCallWithTag("eth_BalanceAt", c.tag)
|
rpcstats.CountCallWithTag("eth_BalanceAt", c.tag)
|
||||||
|
|
||||||
res, err := c.makeCall(
|
res, err := c.makeCall(
|
||||||
ctx, c.ethClients, func(client ethclient.RPSLimitedEthClientInterface) (interface{}, error) {
|
ctx, c.ethClients, func(client ethclient.EthClientInterface) (interface{}, error) {
|
||||||
return client.BalanceAt(ctx, account, blockNumber)
|
return client.BalanceAt(ctx, account, blockNumber)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -392,7 +392,7 @@ func (c *ClientWithFallback) StorageAt(ctx context.Context, account common.Addre
|
||||||
rpcstats.CountCall("eth_StorageAt")
|
rpcstats.CountCall("eth_StorageAt")
|
||||||
|
|
||||||
res, err := c.makeCall(
|
res, err := c.makeCall(
|
||||||
ctx, c.ethClients, func(client ethclient.RPSLimitedEthClientInterface) (interface{}, error) {
|
ctx, c.ethClients, func(client ethclient.EthClientInterface) (interface{}, error) {
|
||||||
return client.StorageAt(ctx, account, key, blockNumber)
|
return client.StorageAt(ctx, account, key, blockNumber)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -410,7 +410,7 @@ func (c *ClientWithFallback) CodeAt(ctx context.Context, account common.Address,
|
||||||
rpcstats.CountCall("eth_CodeAt")
|
rpcstats.CountCall("eth_CodeAt")
|
||||||
|
|
||||||
res, err := c.makeCall(
|
res, err := c.makeCall(
|
||||||
ctx, c.ethClients, func(client ethclient.RPSLimitedEthClientInterface) (interface{}, error) {
|
ctx, c.ethClients, func(client ethclient.EthClientInterface) (interface{}, error) {
|
||||||
return client.CodeAt(ctx, account, blockNumber)
|
return client.CodeAt(ctx, account, blockNumber)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -428,7 +428,7 @@ func (c *ClientWithFallback) NonceAt(ctx context.Context, account common.Address
|
||||||
rpcstats.CountCallWithTag("eth_NonceAt", c.tag)
|
rpcstats.CountCallWithTag("eth_NonceAt", c.tag)
|
||||||
|
|
||||||
res, err := c.makeCall(
|
res, err := c.makeCall(
|
||||||
ctx, c.ethClients, func(client ethclient.RPSLimitedEthClientInterface) (interface{}, error) {
|
ctx, c.ethClients, func(client ethclient.EthClientInterface) (interface{}, error) {
|
||||||
return client.NonceAt(ctx, account, blockNumber)
|
return client.NonceAt(ctx, account, blockNumber)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -446,13 +446,13 @@ func (c *ClientWithFallback) FilterLogs(ctx context.Context, q ethereum.FilterQu
|
||||||
rpcstats.CountCallWithTag("eth_FilterLogs", c.tag)
|
rpcstats.CountCallWithTag("eth_FilterLogs", c.tag)
|
||||||
|
|
||||||
// Override providers name to use a separate circuit for this command as it more often fails due to rate limiting
|
// Override providers name to use a separate circuit for this command as it more often fails due to rate limiting
|
||||||
ethClients := make([]ethclient.RPSLimitedEthClientInterface, len(c.ethClients))
|
ethClients := make([]ethclient.EthClientInterface, len(c.ethClients))
|
||||||
for i, client := range c.ethClients {
|
for i, client := range c.ethClients {
|
||||||
ethClients[i] = client.CopyWithName(client.GetName() + "_FilterLogs")
|
ethClients[i] = client.CopyWithName(client.GetName() + "_FilterLogs")
|
||||||
}
|
}
|
||||||
|
|
||||||
res, err := c.makeCall(
|
res, err := c.makeCall(
|
||||||
ctx, c.ethClients, func(client ethclient.RPSLimitedEthClientInterface) (interface{}, error) {
|
ctx, c.ethClients, func(client ethclient.EthClientInterface) (interface{}, error) {
|
||||||
return client.FilterLogs(ctx, q)
|
return client.FilterLogs(ctx, q)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -471,7 +471,7 @@ func (c *ClientWithFallback) SubscribeFilterLogs(ctx context.Context, q ethereum
|
||||||
rpcstats.CountCall("eth_SubscribeFilterLogs")
|
rpcstats.CountCall("eth_SubscribeFilterLogs")
|
||||||
|
|
||||||
res, err := c.makeCall(
|
res, err := c.makeCall(
|
||||||
ctx, c.ethClients, func(client ethclient.RPSLimitedEthClientInterface) (interface{}, error) {
|
ctx, c.ethClients, func(client ethclient.EthClientInterface) (interface{}, error) {
|
||||||
return client.SubscribeFilterLogs(ctx, q, ch)
|
return client.SubscribeFilterLogs(ctx, q, ch)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -489,7 +489,7 @@ func (c *ClientWithFallback) PendingBalanceAt(ctx context.Context, account commo
|
||||||
rpcstats.CountCall("eth_PendingBalanceAt")
|
rpcstats.CountCall("eth_PendingBalanceAt")
|
||||||
|
|
||||||
res, err := c.makeCall(
|
res, err := c.makeCall(
|
||||||
ctx, c.ethClients, func(client ethclient.RPSLimitedEthClientInterface) (interface{}, error) {
|
ctx, c.ethClients, func(client ethclient.EthClientInterface) (interface{}, error) {
|
||||||
return client.PendingBalanceAt(ctx, account)
|
return client.PendingBalanceAt(ctx, account)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -507,7 +507,7 @@ func (c *ClientWithFallback) PendingStorageAt(ctx context.Context, account commo
|
||||||
rpcstats.CountCall("eth_PendingStorageAt")
|
rpcstats.CountCall("eth_PendingStorageAt")
|
||||||
|
|
||||||
res, err := c.makeCall(
|
res, err := c.makeCall(
|
||||||
ctx, c.ethClients, func(client ethclient.RPSLimitedEthClientInterface) (interface{}, error) {
|
ctx, c.ethClients, func(client ethclient.EthClientInterface) (interface{}, error) {
|
||||||
return client.PendingStorageAt(ctx, account, key)
|
return client.PendingStorageAt(ctx, account, key)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -525,7 +525,7 @@ func (c *ClientWithFallback) PendingCodeAt(ctx context.Context, account common.A
|
||||||
rpcstats.CountCall("eth_PendingCodeAt")
|
rpcstats.CountCall("eth_PendingCodeAt")
|
||||||
|
|
||||||
res, err := c.makeCall(
|
res, err := c.makeCall(
|
||||||
ctx, c.ethClients, func(client ethclient.RPSLimitedEthClientInterface) (interface{}, error) {
|
ctx, c.ethClients, func(client ethclient.EthClientInterface) (interface{}, error) {
|
||||||
return client.PendingCodeAt(ctx, account)
|
return client.PendingCodeAt(ctx, account)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -543,7 +543,7 @@ func (c *ClientWithFallback) PendingNonceAt(ctx context.Context, account common.
|
||||||
rpcstats.CountCall("eth_PendingNonceAt")
|
rpcstats.CountCall("eth_PendingNonceAt")
|
||||||
|
|
||||||
res, err := c.makeCall(
|
res, err := c.makeCall(
|
||||||
ctx, c.ethClients, func(client ethclient.RPSLimitedEthClientInterface) (interface{}, error) {
|
ctx, c.ethClients, func(client ethclient.EthClientInterface) (interface{}, error) {
|
||||||
return client.PendingNonceAt(ctx, account)
|
return client.PendingNonceAt(ctx, account)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -561,7 +561,7 @@ func (c *ClientWithFallback) PendingTransactionCount(ctx context.Context) (uint,
|
||||||
rpcstats.CountCall("eth_PendingTransactionCount")
|
rpcstats.CountCall("eth_PendingTransactionCount")
|
||||||
|
|
||||||
res, err := c.makeCall(
|
res, err := c.makeCall(
|
||||||
ctx, c.ethClients, func(client ethclient.RPSLimitedEthClientInterface) (interface{}, error) {
|
ctx, c.ethClients, func(client ethclient.EthClientInterface) (interface{}, error) {
|
||||||
return client.PendingTransactionCount(ctx)
|
return client.PendingTransactionCount(ctx)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -579,7 +579,7 @@ func (c *ClientWithFallback) CallContract(ctx context.Context, msg ethereum.Call
|
||||||
rpcstats.CountCall("eth_CallContract_" + msg.To.String())
|
rpcstats.CountCall("eth_CallContract_" + msg.To.String())
|
||||||
|
|
||||||
res, err := c.makeCall(
|
res, err := c.makeCall(
|
||||||
ctx, c.ethClients, func(client ethclient.RPSLimitedEthClientInterface) (interface{}, error) {
|
ctx, c.ethClients, func(client ethclient.EthClientInterface) (interface{}, error) {
|
||||||
return client.CallContract(ctx, msg, blockNumber)
|
return client.CallContract(ctx, msg, blockNumber)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -597,7 +597,7 @@ func (c *ClientWithFallback) PendingCallContract(ctx context.Context, msg ethere
|
||||||
rpcstats.CountCall("eth_PendingCallContract")
|
rpcstats.CountCall("eth_PendingCallContract")
|
||||||
|
|
||||||
res, err := c.makeCall(
|
res, err := c.makeCall(
|
||||||
ctx, c.ethClients, func(client ethclient.RPSLimitedEthClientInterface) (interface{}, error) {
|
ctx, c.ethClients, func(client ethclient.EthClientInterface) (interface{}, error) {
|
||||||
return client.PendingCallContract(ctx, msg)
|
return client.PendingCallContract(ctx, msg)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -615,7 +615,7 @@ func (c *ClientWithFallback) SuggestGasPrice(ctx context.Context) (*big.Int, err
|
||||||
rpcstats.CountCall("eth_SuggestGasPrice")
|
rpcstats.CountCall("eth_SuggestGasPrice")
|
||||||
|
|
||||||
res, err := c.makeCall(
|
res, err := c.makeCall(
|
||||||
ctx, c.ethClients, func(client ethclient.RPSLimitedEthClientInterface) (interface{}, error) {
|
ctx, c.ethClients, func(client ethclient.EthClientInterface) (interface{}, error) {
|
||||||
return client.SuggestGasPrice(ctx)
|
return client.SuggestGasPrice(ctx)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -633,7 +633,7 @@ func (c *ClientWithFallback) SuggestGasTipCap(ctx context.Context) (*big.Int, er
|
||||||
rpcstats.CountCall("eth_SuggestGasTipCap")
|
rpcstats.CountCall("eth_SuggestGasTipCap")
|
||||||
|
|
||||||
res, err := c.makeCall(
|
res, err := c.makeCall(
|
||||||
ctx, c.ethClients, func(client ethclient.RPSLimitedEthClientInterface) (interface{}, error) {
|
ctx, c.ethClients, func(client ethclient.EthClientInterface) (interface{}, error) {
|
||||||
return client.SuggestGasTipCap(ctx)
|
return client.SuggestGasTipCap(ctx)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -651,7 +651,7 @@ func (c *ClientWithFallback) FeeHistory(ctx context.Context, blockCount uint64,
|
||||||
rpcstats.CountCall("eth_FeeHistory")
|
rpcstats.CountCall("eth_FeeHistory")
|
||||||
|
|
||||||
res, err := c.makeCall(
|
res, err := c.makeCall(
|
||||||
ctx, c.ethClients, func(client ethclient.RPSLimitedEthClientInterface) (interface{}, error) {
|
ctx, c.ethClients, func(client ethclient.EthClientInterface) (interface{}, error) {
|
||||||
return client.FeeHistory(ctx, blockCount, lastBlock, rewardPercentiles)
|
return client.FeeHistory(ctx, blockCount, lastBlock, rewardPercentiles)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -669,7 +669,7 @@ func (c *ClientWithFallback) EstimateGas(ctx context.Context, msg ethereum.CallM
|
||||||
rpcstats.CountCall("eth_EstimateGas")
|
rpcstats.CountCall("eth_EstimateGas")
|
||||||
|
|
||||||
res, err := c.makeCall(
|
res, err := c.makeCall(
|
||||||
ctx, c.ethClients, func(client ethclient.RPSLimitedEthClientInterface) (interface{}, error) {
|
ctx, c.ethClients, func(client ethclient.EthClientInterface) (interface{}, error) {
|
||||||
return client.EstimateGas(ctx, msg)
|
return client.EstimateGas(ctx, msg)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -687,7 +687,7 @@ func (c *ClientWithFallback) SendTransaction(ctx context.Context, tx *types.Tran
|
||||||
rpcstats.CountCall("eth_SendTransaction")
|
rpcstats.CountCall("eth_SendTransaction")
|
||||||
|
|
||||||
_, err := c.makeCall(
|
_, err := c.makeCall(
|
||||||
ctx, c.ethClients, func(client ethclient.RPSLimitedEthClientInterface) (interface{}, error) {
|
ctx, c.ethClients, func(client ethclient.EthClientInterface) (interface{}, error) {
|
||||||
return nil, client.SendTransaction(ctx, tx)
|
return nil, client.SendTransaction(ctx, tx)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -701,7 +701,7 @@ func (c *ClientWithFallback) CallContext(ctx context.Context, result interface{}
|
||||||
rpcstats.CountCall("eth_CallContext")
|
rpcstats.CountCall("eth_CallContext")
|
||||||
|
|
||||||
_, err := c.makeCall(
|
_, err := c.makeCall(
|
||||||
ctx, c.ethClients, func(client ethclient.RPSLimitedEthClientInterface) (interface{}, error) {
|
ctx, c.ethClients, func(client ethclient.EthClientInterface) (interface{}, error) {
|
||||||
return nil, client.CallContext(ctx, result, method, args...)
|
return nil, client.CallContext(ctx, result, method, args...)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -715,7 +715,7 @@ func (c *ClientWithFallback) BatchCallContext(ctx context.Context, b []rpc.Batch
|
||||||
rpcstats.CountCall("eth_BatchCallContext")
|
rpcstats.CountCall("eth_BatchCallContext")
|
||||||
|
|
||||||
_, err := c.makeCall(
|
_, err := c.makeCall(
|
||||||
ctx, c.ethClients, func(client ethclient.RPSLimitedEthClientInterface) (interface{}, error) {
|
ctx, c.ethClients, func(client ethclient.EthClientInterface) (interface{}, error) {
|
||||||
return nil, client.BatchCallContext(ctx, b)
|
return nil, client.BatchCallContext(ctx, b)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
|
@ -24,7 +24,7 @@ import (
|
||||||
type ClientWithFallbackSuite struct {
|
type ClientWithFallbackSuite struct {
|
||||||
suite.Suite
|
suite.Suite
|
||||||
client *ClientWithFallback
|
client *ClientWithFallback
|
||||||
mockEthClients []*mockEthclient.MockRPSLimitedEthClientInterface
|
mockEthClients []*mockEthclient.MockEthClientInterface
|
||||||
providersHealthManager *healthManager.ProvidersHealthManager
|
providersHealthManager *healthManager.ProvidersHealthManager
|
||||||
mockCtrl *gomock.Controller
|
mockCtrl *gomock.Controller
|
||||||
}
|
}
|
||||||
|
@ -38,11 +38,11 @@ func (s *ClientWithFallbackSuite) TearDownTest() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *ClientWithFallbackSuite) setupClients(numClients int) {
|
func (s *ClientWithFallbackSuite) setupClients(numClients int) {
|
||||||
s.mockEthClients = make([]*mockEthclient.MockRPSLimitedEthClientInterface, 0)
|
s.mockEthClients = make([]*mockEthclient.MockEthClientInterface, 0)
|
||||||
ethClients := make([]ethclient.RPSLimitedEthClientInterface, 0)
|
ethClients := make([]ethclient.EthClientInterface, 0)
|
||||||
|
|
||||||
for i := 0; i < numClients; i++ {
|
for i := 0; i < numClients; i++ {
|
||||||
ethClient := mockEthclient.NewMockRPSLimitedEthClientInterface(s.mockCtrl)
|
ethClient := mockEthclient.NewMockEthClientInterface(s.mockCtrl)
|
||||||
ethClient.EXPECT().GetName().AnyTimes().Return("test" + strconv.Itoa(i))
|
ethClient.EXPECT().GetName().AnyTimes().Return("test" + strconv.Itoa(i))
|
||||||
|
|
||||||
s.mockEthClients = append(s.mockEthClients, ethClient)
|
s.mockEthClients = append(s.mockEthClients, ethClient)
|
||||||
|
|
|
@ -21,7 +21,7 @@ func setupClientTest(t *testing.T) (*ClientWithFallback, []*mock_ethclient.MockR
|
||||||
mockCtrl := gomock.NewController(t)
|
mockCtrl := gomock.NewController(t)
|
||||||
|
|
||||||
mockEthClients := make([]*mock_ethclient.MockRPSLimitedEthClientInterface, 0)
|
mockEthClients := make([]*mock_ethclient.MockRPSLimitedEthClientInterface, 0)
|
||||||
ethClients := make([]ethclient.RPSLimitedEthClientInterface, 0)
|
ethClients := make([]ethclient.EthClientInterface, 0)
|
||||||
|
|
||||||
for i := 0; i < 3; i++ {
|
for i := 0; i < 3; i++ {
|
||||||
ethCl := mock_ethclient.NewMockRPSLimitedEthClientInterface(mockCtrl)
|
ethCl := mock_ethclient.NewMockRPSLimitedEthClientInterface(mockCtrl)
|
||||||
|
|
|
@ -61,6 +61,8 @@ type EthClientInterface interface {
|
||||||
BaseEthClientInterface
|
BaseEthClientInterface
|
||||||
// Additional external calls
|
// Additional external calls
|
||||||
RPCClientInterface
|
RPCClientInterface
|
||||||
|
GetName() string
|
||||||
|
CopyWithName(name string) EthClientInterface
|
||||||
GetBaseFeeFromBlock(ctx context.Context, blockNumber *big.Int) (string, error)
|
GetBaseFeeFromBlock(ctx context.Context, blockNumber *big.Int) (string, error)
|
||||||
bind.ContractCaller
|
bind.ContractCaller
|
||||||
bind.ContractBackend
|
bind.ContractBackend
|
||||||
|
@ -69,16 +71,25 @@ type EthClientInterface interface {
|
||||||
// EthClient implements EthClientInterface
|
// EthClient implements EthClientInterface
|
||||||
type EthClient struct {
|
type EthClient struct {
|
||||||
*ethclient.Client
|
*ethclient.Client
|
||||||
|
name string
|
||||||
rpcClient *rpc.Client
|
rpcClient *rpc.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewEthClient(rpcClient *rpc.Client) *EthClient {
|
func NewEthClient(rpcClient *rpc.Client, name string) *EthClient {
|
||||||
return &EthClient{
|
return &EthClient{
|
||||||
Client: ethclient.NewClient(rpcClient),
|
Client: ethclient.NewClient(rpcClient),
|
||||||
|
name: name,
|
||||||
rpcClient: rpcClient,
|
rpcClient: rpcClient,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *EthClient) GetName() string {
|
||||||
|
return c.name
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *EthClient) CopyWithName(name string) EthClientInterface {
|
||||||
|
return NewEthClient(c.rpcClient, name)
|
||||||
|
}
|
||||||
func (ec *EthClient) BatchCallContext(ctx context.Context, b []rpc.BatchElem) error {
|
func (ec *EthClient) BatchCallContext(ctx context.Context, b []rpc.BatchElem) error {
|
||||||
return ec.rpcClient.BatchCallContext(ctx, b)
|
return ec.rpcClient.BatchCallContext(ctx, b)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,38 +0,0 @@
|
||||||
package ethclient
|
|
||||||
|
|
||||||
//go:generate mockgen -package=mock_ethclient -source=rps_limited_eth_client.go -destination=mock/client/ethclient/rps_limited_eth_client.go
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/ethereum/go-ethereum/rpc"
|
|
||||||
)
|
|
||||||
|
|
||||||
// RPSLimitedEthClientInterface extends EthClientInterface with additional
|
|
||||||
// RPS-Limiting related capabilities.
|
|
||||||
// Ideally this shouldn't exist, instead we should be using EthClientInterface
|
|
||||||
// everywhere and clients shouldn't be aware of additional capabilities like
|
|
||||||
// PRS limiting. fallback mechanisms or caching.
|
|
||||||
type RPSLimitedEthClientInterface interface {
|
|
||||||
EthClientInterface
|
|
||||||
GetName() string
|
|
||||||
CopyWithName(name string) RPSLimitedEthClientInterface
|
|
||||||
}
|
|
||||||
|
|
||||||
type RPSLimitedEthClient struct {
|
|
||||||
*EthClient
|
|
||||||
name string
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewRPSLimitedEthClient(rpcClient *rpc.Client, name string) *RPSLimitedEthClient {
|
|
||||||
return &RPSLimitedEthClient{
|
|
||||||
EthClient: NewEthClient(rpcClient),
|
|
||||||
name: name,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *RPSLimitedEthClient) GetName() string {
|
|
||||||
return c.name
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *RPSLimitedEthClient) CopyWithName(name string) RPSLimitedEthClientInterface {
|
|
||||||
return NewRPSLimitedEthClient(c.rpcClient, name)
|
|
||||||
}
|
|
|
@ -277,7 +277,7 @@ func (c *Client) getClientUsingCache(chainID uint64) (chain.ClientInterface, err
|
||||||
return client, nil
|
return client, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) getEthClients(network *params.Network) []ethclient.RPSLimitedEthClientInterface {
|
func (c *Client) getEthClients(network *params.Network) []ethclient.EthClientInterface {
|
||||||
urls := make(map[string]string)
|
urls := make(map[string]string)
|
||||||
keys := make([]string, 0)
|
keys := make([]string, 0)
|
||||||
authMap := make(map[string]string)
|
authMap := make(map[string]string)
|
||||||
|
@ -304,7 +304,7 @@ func (c *Client) getEthClients(network *params.Network) []ethclient.RPSLimitedEt
|
||||||
urls["main"] = network.RPCURL
|
urls["main"] = network.RPCURL
|
||||||
urls["fallback"] = network.FallbackURL
|
urls["fallback"] = network.FallbackURL
|
||||||
|
|
||||||
ethClients := make([]ethclient.RPSLimitedEthClientInterface, 0)
|
ethClients := make([]ethclient.EthClientInterface, 0)
|
||||||
for index, key := range keys {
|
for index, key := range keys {
|
||||||
var rpcClient *gethrpc.Client
|
var rpcClient *gethrpc.Client
|
||||||
var err error
|
var err error
|
||||||
|
|
|
@ -73,7 +73,7 @@ func (s *TransactorSuite) SetupTest() {
|
||||||
|
|
||||||
rpcClient.UpstreamChainID = chainID
|
rpcClient.UpstreamChainID = chainID
|
||||||
|
|
||||||
ethClients := []ethclient.RPSLimitedEthClientInterface{
|
ethClients := []ethclient.EthClientInterface{
|
||||||
ethclient.NewRPSLimitedEthClient(s.client, "local-1-chain-id-1"),
|
ethclient.NewRPSLimitedEthClient(s.client, "local-1-chain-id-1"),
|
||||||
}
|
}
|
||||||
localClient := chain.NewClient(ethClients, chainID, nil)
|
localClient := chain.NewClient(ethClients, chainID, nil)
|
||||||
|
|
Loading…
Reference in New Issue