2023-02-20 09:32:45 +00:00
|
|
|
package chain
|
|
|
|
|
2024-08-29 00:33:46 +00:00
|
|
|
//go:generate mockgen -package=mock_client -source=client.go -destination=mock/client/client.go
|
|
|
|
|
2023-02-20 09:32:45 +00:00
|
|
|
import (
|
|
|
|
"context"
|
2024-05-22 10:16:06 +00:00
|
|
|
"errors"
|
2023-02-20 09:32:45 +00:00
|
|
|
"fmt"
|
|
|
|
"math/big"
|
2023-03-28 16:22:11 +00:00
|
|
|
"strings"
|
2024-05-21 17:40:37 +00:00
|
|
|
"sync/atomic"
|
2023-02-20 09:32:45 +00:00
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum"
|
2023-04-27 14:44:24 +00:00
|
|
|
"github.com/ethereum/go-ethereum/accounts/abi/bind"
|
2023-02-20 09:32:45 +00:00
|
|
|
"github.com/ethereum/go-ethereum/common"
|
2024-03-05 09:33:12 +00:00
|
|
|
"github.com/ethereum/go-ethereum/core"
|
2023-02-20 09:32:45 +00:00
|
|
|
"github.com/ethereum/go-ethereum/core/types"
|
2023-03-28 16:22:11 +00:00
|
|
|
"github.com/ethereum/go-ethereum/core/vm"
|
2024-07-29 17:07:43 +00:00
|
|
|
"github.com/ethereum/go-ethereum/log"
|
2023-02-20 09:32:45 +00:00
|
|
|
"github.com/ethereum/go-ethereum/rpc"
|
2024-07-02 17:58:55 +00:00
|
|
|
"github.com/status-im/status-go/circuitbreaker"
|
2024-09-24 13:07:26 +00:00
|
|
|
"github.com/status-im/status-go/rpc/chain/ethclient"
|
|
|
|
"github.com/status-im/status-go/rpc/chain/rpclimiter"
|
|
|
|
"github.com/status-im/status-go/rpc/chain/tagger"
|
2023-02-20 09:32:45 +00:00
|
|
|
"github.com/status-im/status-go/services/rpcstats"
|
2024-05-20 11:21:21 +00:00
|
|
|
"github.com/status-im/status-go/services/wallet/connection"
|
2023-02-20 09:32:45 +00:00
|
|
|
)
|
|
|
|
|
2024-09-24 13:07:26 +00:00
|
|
|
type ClientInterface interface {
|
|
|
|
ethclient.EthClientInterface
|
2023-09-19 11:17:36 +00:00
|
|
|
NetworkID() uint64
|
|
|
|
ToBigInt() *big.Int
|
2024-05-20 11:21:21 +00:00
|
|
|
GetWalletNotifier() func(chainId uint64, message string)
|
|
|
|
SetWalletNotifier(notifier func(chainId uint64, message string))
|
|
|
|
connection.Connectable
|
2024-09-24 13:07:26 +00:00
|
|
|
GetLimiter() rpclimiter.RequestLimiter
|
|
|
|
SetLimiter(rpclimiter.RequestLimiter)
|
2024-05-20 11:21:21 +00:00
|
|
|
}
|
|
|
|
|
2024-07-29 17:07:43 +00:00
|
|
|
type HealthMonitor interface {
|
|
|
|
GetCircuitBreaker() *circuitbreaker.CircuitBreaker
|
|
|
|
SetCircuitBreaker(cb *circuitbreaker.CircuitBreaker)
|
|
|
|
}
|
|
|
|
|
|
|
|
type Copyable interface {
|
|
|
|
Copy() interface{}
|
|
|
|
}
|
|
|
|
|
2024-05-21 17:40:37 +00:00
|
|
|
// Shallow copy of the client with a deep copy of tag and group tag
|
|
|
|
// To avoid passing tags as parameter to every chain call, it is sufficient for now
|
|
|
|
// to set the tag and group tag once on the client
|
|
|
|
func ClientWithTag(chainClient ClientInterface, tag, groupTag string) ClientInterface {
|
2024-05-20 11:21:21 +00:00
|
|
|
newClient := chainClient
|
2024-09-24 13:07:26 +00:00
|
|
|
if tagIface, ok := chainClient.(tagger.Tagger); ok {
|
|
|
|
tagIface = tagger.DeepCopyTagger(tagIface)
|
2024-05-20 11:21:21 +00:00
|
|
|
tagIface.SetTag(tag)
|
2024-05-23 10:01:55 +00:00
|
|
|
tagIface.SetGroupTag(groupTag)
|
2024-05-20 11:21:21 +00:00
|
|
|
newClient = tagIface.(ClientInterface)
|
|
|
|
}
|
|
|
|
|
|
|
|
return newClient
|
|
|
|
}
|
|
|
|
|
2024-07-02 17:58:55 +00:00
|
|
|
type ClientWithFallback struct {
|
|
|
|
ChainID uint64
|
2024-09-24 13:07:26 +00:00
|
|
|
ethClients []ethclient.RPSLimitedEthClientInterface
|
|
|
|
commonLimiter rpclimiter.RequestLimiter
|
2024-07-02 17:58:55 +00:00
|
|
|
circuitbreaker *circuitbreaker.CircuitBreaker
|
2023-02-20 09:32:45 +00:00
|
|
|
|
2023-03-20 13:02:09 +00:00
|
|
|
WalletNotifier func(chainId uint64, message string)
|
|
|
|
|
2024-05-21 17:40:37 +00:00
|
|
|
isConnected *atomic.Bool
|
|
|
|
LastCheckedAt int64
|
2024-03-06 13:49:17 +00:00
|
|
|
|
2024-07-02 17:58:55 +00:00
|
|
|
tag string // tag for the limiter
|
|
|
|
groupTag string // tag for the limiter group
|
2023-02-20 09:32:45 +00:00
|
|
|
}
|
|
|
|
|
2024-07-29 17:07:43 +00:00
|
|
|
func (c *ClientWithFallback) Copy() interface{} {
|
|
|
|
return &ClientWithFallback{
|
|
|
|
ChainID: c.ChainID,
|
|
|
|
ethClients: c.ethClients,
|
|
|
|
commonLimiter: c.commonLimiter,
|
|
|
|
circuitbreaker: c.circuitbreaker,
|
|
|
|
WalletNotifier: c.WalletNotifier,
|
|
|
|
isConnected: c.isConnected,
|
|
|
|
LastCheckedAt: c.LastCheckedAt,
|
|
|
|
tag: c.tag,
|
|
|
|
groupTag: c.groupTag,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-27 14:44:24 +00:00
|
|
|
// Don't mark connection as failed if we get one of these errors
|
|
|
|
var propagateErrors = []error{
|
2023-03-28 16:22:11 +00:00
|
|
|
vm.ErrOutOfGas,
|
|
|
|
vm.ErrCodeStoreOutOfGas,
|
|
|
|
vm.ErrDepth,
|
|
|
|
vm.ErrInsufficientBalance,
|
|
|
|
vm.ErrContractAddressCollision,
|
|
|
|
vm.ErrExecutionReverted,
|
|
|
|
vm.ErrMaxCodeSizeExceeded,
|
|
|
|
vm.ErrInvalidJump,
|
|
|
|
vm.ErrWriteProtection,
|
|
|
|
vm.ErrReturnDataOutOfBounds,
|
|
|
|
vm.ErrGasUintOverflow,
|
|
|
|
vm.ErrInvalidCode,
|
|
|
|
vm.ErrNonceUintOverflow,
|
2023-04-27 14:44:24 +00:00
|
|
|
|
|
|
|
// Used by balance history to check state
|
|
|
|
bind.ErrNoCode,
|
2023-03-28 16:22:11 +00:00
|
|
|
}
|
|
|
|
|
2024-09-24 13:07:26 +00:00
|
|
|
func NewClient(ethClients []ethclient.RPSLimitedEthClientInterface, chainID uint64) *ClientWithFallback {
|
2024-07-02 17:58:55 +00:00
|
|
|
cbConfig := circuitbreaker.Config{
|
2023-03-28 12:46:46 +00:00
|
|
|
Timeout: 20000,
|
2023-02-20 09:32:45 +00:00
|
|
|
MaxConcurrentRequests: 100,
|
|
|
|
SleepWindow: 300000,
|
|
|
|
ErrorPercentThreshold: 25,
|
|
|
|
}
|
2024-07-02 17:58:55 +00:00
|
|
|
|
2024-05-21 17:40:37 +00:00
|
|
|
isConnected := &atomic.Bool{}
|
|
|
|
isConnected.Store(true)
|
|
|
|
|
2023-02-20 09:32:45 +00:00
|
|
|
return &ClientWithFallback{
|
2024-07-02 17:58:55 +00:00
|
|
|
ChainID: chainID,
|
|
|
|
ethClients: ethClients,
|
|
|
|
isConnected: isConnected,
|
|
|
|
LastCheckedAt: time.Now().Unix(),
|
|
|
|
circuitbreaker: circuitbreaker.NewCircuitBreaker(cbConfig),
|
2023-02-20 09:32:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *ClientWithFallback) Close() {
|
2024-07-02 17:58:55 +00:00
|
|
|
for _, client := range c.ethClients {
|
2024-09-24 13:07:26 +00:00
|
|
|
client.Close()
|
2023-02-20 09:32:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-08-19 12:44:46 +00:00
|
|
|
// Not found should not be cancelling the requests, as that's returned
|
|
|
|
// when we are hitting a non archival node for example, it should continue the
|
|
|
|
// chain as the next provider might have archival support.
|
|
|
|
func isNotFoundError(err error) bool {
|
|
|
|
return strings.Contains(err.Error(), ethereum.NotFound.Error())
|
|
|
|
}
|
|
|
|
|
2023-03-28 16:22:11 +00:00
|
|
|
func isVMError(err error) bool {
|
2024-03-07 11:05:53 +00:00
|
|
|
if strings.Contains(err.Error(), core.ErrInsufficientFunds.Error()) {
|
|
|
|
return true
|
|
|
|
}
|
2023-04-27 14:44:24 +00:00
|
|
|
for _, vmError := range propagateErrors {
|
2024-07-04 15:01:42 +00:00
|
|
|
if strings.Contains(err.Error(), vmError.Error()) {
|
2023-03-28 16:22:11 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2024-02-23 14:27:08 +00:00
|
|
|
func isRPSLimitError(err error) bool {
|
2024-05-09 12:07:41 +00:00
|
|
|
return strings.Contains(err.Error(), "backoff_seconds") ||
|
|
|
|
strings.Contains(err.Error(), "has exceeded its throughput limit") ||
|
|
|
|
strings.Contains(err.Error(), "request rate exceeded")
|
2024-02-23 14:27:08 +00:00
|
|
|
}
|
|
|
|
|
2023-03-31 08:47:14 +00:00
|
|
|
func (c *ClientWithFallback) SetIsConnected(value bool) {
|
2023-03-20 13:02:09 +00:00
|
|
|
c.LastCheckedAt = time.Now().Unix()
|
2023-03-23 14:08:55 +00:00
|
|
|
if !value {
|
2024-05-21 17:40:37 +00:00
|
|
|
if c.isConnected.Load() {
|
2023-03-23 14:08:55 +00:00
|
|
|
if c.WalletNotifier != nil {
|
|
|
|
c.WalletNotifier(c.ChainID, "down")
|
|
|
|
}
|
2024-05-21 17:40:37 +00:00
|
|
|
c.isConnected.Store(false)
|
2023-03-20 13:02:09 +00:00
|
|
|
}
|
2023-03-23 14:08:55 +00:00
|
|
|
|
|
|
|
} else {
|
2024-05-21 17:40:37 +00:00
|
|
|
if !c.isConnected.Load() {
|
|
|
|
c.isConnected.Store(true)
|
2023-03-23 14:21:02 +00:00
|
|
|
if c.WalletNotifier != nil {
|
|
|
|
c.WalletNotifier(c.ChainID, "up")
|
|
|
|
}
|
2023-03-20 13:02:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-20 11:21:21 +00:00
|
|
|
func (c *ClientWithFallback) IsConnected() bool {
|
2024-05-21 17:40:37 +00:00
|
|
|
return c.isConnected.Load()
|
2023-09-20 08:41:23 +00:00
|
|
|
}
|
|
|
|
|
2024-09-24 13:07:26 +00:00
|
|
|
func (c *ClientWithFallback) makeCall(ctx context.Context, ethClients []ethclient.RPSLimitedEthClientInterface, f func(client ethclient.RPSLimitedEthClientInterface) (interface{}, error)) (interface{}, error) {
|
2024-05-20 12:38:02 +00:00
|
|
|
if c.commonLimiter != nil {
|
2024-05-21 13:57:34 +00:00
|
|
|
if allow, err := c.commonLimiter.Allow(c.tag); !allow {
|
2024-05-21 13:05:04 +00:00
|
|
|
return nil, fmt.Errorf("tag=%s, %w", c.tag, err)
|
2024-05-20 12:38:02 +00:00
|
|
|
}
|
2024-05-21 17:40:37 +00:00
|
|
|
|
|
|
|
if allow, err := c.commonLimiter.Allow(c.groupTag); !allow {
|
|
|
|
return nil, fmt.Errorf("groupTag=%s, %w", c.groupTag, err)
|
|
|
|
}
|
2024-05-20 12:38:02 +00:00
|
|
|
}
|
|
|
|
|
2023-02-20 09:32:45 +00:00
|
|
|
c.LastCheckedAt = time.Now().Unix()
|
2024-05-09 12:07:41 +00:00
|
|
|
|
2024-07-02 17:58:55 +00:00
|
|
|
cmd := circuitbreaker.NewCommand(ctx, nil)
|
|
|
|
for _, provider := range ethClients {
|
|
|
|
provider := provider
|
|
|
|
cmd.Add(circuitbreaker.NewFunctor(func() ([]interface{}, error) {
|
2024-09-24 13:07:26 +00:00
|
|
|
limiter := provider.GetLimiter()
|
|
|
|
if limiter != nil {
|
|
|
|
err := provider.GetLimiter().WaitForRequestsAvailability(1)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2024-05-09 12:07:41 +00:00
|
|
|
}
|
|
|
|
|
2024-07-02 17:58:55 +00:00
|
|
|
res, err := f(provider)
|
|
|
|
if err != nil {
|
2024-09-24 13:07:26 +00:00
|
|
|
if limiter != nil && isRPSLimitError(err) {
|
|
|
|
provider.GetLimiter().ReduceLimit()
|
2024-02-23 14:27:08 +00:00
|
|
|
|
2024-09-24 13:07:26 +00:00
|
|
|
err = provider.GetLimiter().WaitForRequestsAvailability(1)
|
2024-07-02 17:58:55 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2024-05-09 12:07:41 +00:00
|
|
|
|
2024-07-02 17:58:55 +00:00
|
|
|
res, err = f(provider)
|
|
|
|
if err == nil {
|
|
|
|
return []interface{}{res}, err
|
|
|
|
}
|
2024-05-09 12:07:41 +00:00
|
|
|
}
|
|
|
|
|
2024-07-29 17:07:43 +00:00
|
|
|
if isVMError(err) || errors.Is(err, context.Canceled) {
|
2024-07-02 17:58:55 +00:00
|
|
|
cmd.Cancel()
|
2024-05-09 12:07:41 +00:00
|
|
|
}
|
|
|
|
|
2024-07-02 17:58:55 +00:00
|
|
|
return nil, err
|
2024-05-09 12:07:41 +00:00
|
|
|
}
|
2024-07-02 17:58:55 +00:00
|
|
|
return []interface{}{res}, err
|
2024-09-24 13:07:26 +00:00
|
|
|
}, provider.GetName()))
|
2024-07-02 17:58:55 +00:00
|
|
|
}
|
2024-05-09 12:07:41 +00:00
|
|
|
|
2024-07-02 17:58:55 +00:00
|
|
|
result := c.circuitbreaker.Execute(cmd)
|
|
|
|
if result.Error() != nil {
|
|
|
|
return nil, result.Error()
|
2023-02-20 09:32:45 +00:00
|
|
|
}
|
2024-07-02 17:58:55 +00:00
|
|
|
|
|
|
|
return result.Result()[0], nil
|
2023-02-20 09:32:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *ClientWithFallback) BlockByHash(ctx context.Context, hash common.Hash) (*types.Block, error) {
|
2024-05-20 11:21:21 +00:00
|
|
|
rpcstats.CountCallWithTag("eth_BlockByHash", c.tag)
|
2023-02-20 09:32:45 +00:00
|
|
|
|
2024-03-06 13:49:17 +00:00
|
|
|
res, err := c.makeCall(
|
2024-09-24 13:07:26 +00:00
|
|
|
ctx, c.ethClients, func(client ethclient.RPSLimitedEthClientInterface) (interface{}, error) {
|
|
|
|
return client.BlockByHash(ctx, hash)
|
2024-07-02 17:58:55 +00:00
|
|
|
},
|
2023-02-20 09:32:45 +00:00
|
|
|
)
|
|
|
|
|
2024-03-06 13:49:17 +00:00
|
|
|
c.toggleConnectionState(err)
|
|
|
|
|
2023-02-20 09:32:45 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2024-07-02 17:58:55 +00:00
|
|
|
return res.(*types.Block), nil
|
2023-02-20 09:32:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *ClientWithFallback) BlockByNumber(ctx context.Context, number *big.Int) (*types.Block, error) {
|
2024-05-20 11:21:21 +00:00
|
|
|
rpcstats.CountCallWithTag("eth_BlockByNumber", c.tag)
|
2024-03-06 13:49:17 +00:00
|
|
|
res, err := c.makeCall(
|
2024-09-24 13:07:26 +00:00
|
|
|
ctx, c.ethClients, func(client ethclient.RPSLimitedEthClientInterface) (interface{}, error) {
|
|
|
|
return client.BlockByNumber(ctx, number)
|
2024-07-02 17:58:55 +00:00
|
|
|
},
|
2023-02-20 09:32:45 +00:00
|
|
|
)
|
|
|
|
|
2024-03-06 13:49:17 +00:00
|
|
|
c.toggleConnectionState(err)
|
|
|
|
|
2023-02-20 09:32:45 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2024-07-02 17:58:55 +00:00
|
|
|
return res.(*types.Block), nil
|
2023-02-20 09:32:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *ClientWithFallback) BlockNumber(ctx context.Context) (uint64, error) {
|
2024-05-20 11:21:21 +00:00
|
|
|
rpcstats.CountCallWithTag("eth_BlockNumber", c.tag)
|
2023-02-20 09:32:45 +00:00
|
|
|
|
2024-03-06 13:49:17 +00:00
|
|
|
res, err := c.makeCall(
|
2024-09-24 13:07:26 +00:00
|
|
|
ctx, c.ethClients, func(client ethclient.RPSLimitedEthClientInterface) (interface{}, error) {
|
|
|
|
return client.BlockNumber(ctx)
|
2024-07-02 17:58:55 +00:00
|
|
|
},
|
2023-02-20 09:32:45 +00:00
|
|
|
)
|
|
|
|
|
2024-03-06 13:49:17 +00:00
|
|
|
c.toggleConnectionState(err)
|
|
|
|
|
2023-02-20 09:32:45 +00:00
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
|
2024-07-02 17:58:55 +00:00
|
|
|
return res.(uint64), nil
|
2023-02-20 09:32:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *ClientWithFallback) HeaderByHash(ctx context.Context, hash common.Hash) (*types.Header, error) {
|
2024-05-20 11:21:21 +00:00
|
|
|
rpcstats.CountCallWithTag("eth_HeaderByHash", c.tag)
|
2024-03-06 13:49:17 +00:00
|
|
|
res, err := c.makeCall(
|
2024-09-24 13:07:26 +00:00
|
|
|
ctx, c.ethClients, func(client ethclient.RPSLimitedEthClientInterface) (interface{}, error) {
|
|
|
|
return client.HeaderByHash(ctx, hash)
|
2024-07-02 17:58:55 +00:00
|
|
|
},
|
2023-02-20 09:32:45 +00:00
|
|
|
)
|
|
|
|
|
2024-07-02 17:58:55 +00:00
|
|
|
c.toggleConnectionState(err)
|
|
|
|
|
2023-02-20 09:32:45 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2024-07-02 17:58:55 +00:00
|
|
|
return res.(*types.Header), nil
|
2023-02-20 09:32:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *ClientWithFallback) HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error) {
|
2024-05-20 11:21:21 +00:00
|
|
|
rpcstats.CountCallWithTag("eth_HeaderByNumber", c.tag)
|
2024-03-06 13:49:17 +00:00
|
|
|
res, err := c.makeCall(
|
2024-09-24 13:07:26 +00:00
|
|
|
ctx, c.ethClients, func(client ethclient.RPSLimitedEthClientInterface) (interface{}, error) {
|
|
|
|
return client.HeaderByNumber(ctx, number)
|
2024-07-02 17:58:55 +00:00
|
|
|
},
|
2023-02-20 09:32:45 +00:00
|
|
|
)
|
|
|
|
|
2024-07-02 17:58:55 +00:00
|
|
|
c.toggleConnectionState(err)
|
|
|
|
|
2023-02-20 09:32:45 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2024-07-02 17:58:55 +00:00
|
|
|
return res.(*types.Header), nil
|
2023-02-20 09:32:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *ClientWithFallback) TransactionByHash(ctx context.Context, hash common.Hash) (*types.Transaction, bool, error) {
|
2024-05-20 11:21:21 +00:00
|
|
|
rpcstats.CountCallWithTag("eth_TransactionByHash", c.tag)
|
2023-02-20 09:32:45 +00:00
|
|
|
|
2024-03-06 13:49:17 +00:00
|
|
|
res, err := c.makeCall(
|
2024-09-24 13:07:26 +00:00
|
|
|
ctx, c.ethClients, func(client ethclient.RPSLimitedEthClientInterface) (interface{}, error) {
|
|
|
|
tx, isPending, err := client.TransactionByHash(ctx, hash)
|
2024-07-02 17:58:55 +00:00
|
|
|
return []any{tx, isPending}, err
|
|
|
|
},
|
2023-02-20 09:32:45 +00:00
|
|
|
)
|
|
|
|
|
2024-07-02 17:58:55 +00:00
|
|
|
c.toggleConnectionState(err)
|
|
|
|
|
2023-02-20 09:32:45 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, false, err
|
|
|
|
}
|
|
|
|
|
2024-07-02 17:58:55 +00:00
|
|
|
resArr := res.([]any)
|
|
|
|
return resArr[0].(*types.Transaction), resArr[1].(bool), nil
|
2023-02-20 09:32:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *ClientWithFallback) TransactionSender(ctx context.Context, tx *types.Transaction, block common.Hash, index uint) (common.Address, error) {
|
|
|
|
rpcstats.CountCall("eth_TransactionSender")
|
|
|
|
|
2024-03-06 13:49:17 +00:00
|
|
|
res, err := c.makeCall(
|
2024-09-24 13:07:26 +00:00
|
|
|
ctx, c.ethClients, func(client ethclient.RPSLimitedEthClientInterface) (interface{}, error) {
|
|
|
|
return client.TransactionSender(ctx, tx, block, index)
|
2024-03-06 13:49:17 +00:00
|
|
|
},
|
2023-02-20 09:32:45 +00:00
|
|
|
)
|
|
|
|
|
2024-03-06 13:49:17 +00:00
|
|
|
c.toggleConnectionState(err)
|
|
|
|
|
2024-07-02 17:58:55 +00:00
|
|
|
return res.(common.Address), err
|
2023-02-20 09:32:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *ClientWithFallback) TransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error) {
|
|
|
|
rpcstats.CountCall("eth_TransactionReceipt")
|
|
|
|
|
2024-03-06 13:49:17 +00:00
|
|
|
res, err := c.makeCall(
|
2024-09-24 13:07:26 +00:00
|
|
|
ctx, c.ethClients, func(client ethclient.RPSLimitedEthClientInterface) (interface{}, error) {
|
|
|
|
return client.TransactionReceipt(ctx, txHash)
|
2024-07-02 17:58:55 +00:00
|
|
|
},
|
2023-02-20 09:32:45 +00:00
|
|
|
)
|
|
|
|
|
2024-03-06 13:49:17 +00:00
|
|
|
c.toggleConnectionState(err)
|
|
|
|
|
2023-02-20 09:32:45 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2024-07-02 17:58:55 +00:00
|
|
|
return res.(*types.Receipt), nil
|
2023-02-20 09:32:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *ClientWithFallback) SyncProgress(ctx context.Context) (*ethereum.SyncProgress, error) {
|
|
|
|
rpcstats.CountCall("eth_SyncProgress")
|
|
|
|
|
2024-03-06 13:49:17 +00:00
|
|
|
res, err := c.makeCall(
|
2024-09-24 13:07:26 +00:00
|
|
|
ctx, c.ethClients, func(client ethclient.RPSLimitedEthClientInterface) (interface{}, error) {
|
|
|
|
return client.SyncProgress(ctx)
|
2024-07-02 17:58:55 +00:00
|
|
|
},
|
2023-02-20 09:32:45 +00:00
|
|
|
)
|
|
|
|
|
2024-03-06 13:49:17 +00:00
|
|
|
c.toggleConnectionState(err)
|
|
|
|
|
2023-02-20 09:32:45 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2024-07-02 17:58:55 +00:00
|
|
|
return res.(*ethereum.SyncProgress), nil
|
2023-02-20 09:32:45 +00:00
|
|
|
}
|
|
|
|
|
2023-09-06 09:13:46 +00:00
|
|
|
func (c *ClientWithFallback) NetworkID() uint64 {
|
|
|
|
return c.ChainID
|
2023-02-20 09:32:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *ClientWithFallback) BalanceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (*big.Int, error) {
|
2024-05-20 11:21:21 +00:00
|
|
|
rpcstats.CountCallWithTag("eth_BalanceAt", c.tag)
|
2023-02-20 09:32:45 +00:00
|
|
|
|
2024-03-06 13:49:17 +00:00
|
|
|
res, err := c.makeCall(
|
2024-09-24 13:07:26 +00:00
|
|
|
ctx, c.ethClients, func(client ethclient.RPSLimitedEthClientInterface) (interface{}, error) {
|
|
|
|
return client.BalanceAt(ctx, account, blockNumber)
|
2024-07-02 17:58:55 +00:00
|
|
|
},
|
2023-02-20 09:32:45 +00:00
|
|
|
)
|
|
|
|
|
2024-03-06 13:49:17 +00:00
|
|
|
c.toggleConnectionState(err)
|
|
|
|
|
2023-02-20 09:32:45 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2024-07-02 17:58:55 +00:00
|
|
|
return res.(*big.Int), nil
|
2023-02-20 09:32:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *ClientWithFallback) StorageAt(ctx context.Context, account common.Address, key common.Hash, blockNumber *big.Int) ([]byte, error) {
|
|
|
|
rpcstats.CountCall("eth_StorageAt")
|
|
|
|
|
2024-03-06 13:49:17 +00:00
|
|
|
res, err := c.makeCall(
|
2024-09-24 13:07:26 +00:00
|
|
|
ctx, c.ethClients, func(client ethclient.RPSLimitedEthClientInterface) (interface{}, error) {
|
|
|
|
return client.StorageAt(ctx, account, key, blockNumber)
|
2024-03-06 13:49:17 +00:00
|
|
|
},
|
2023-02-20 09:32:45 +00:00
|
|
|
)
|
|
|
|
|
2024-03-06 13:49:17 +00:00
|
|
|
c.toggleConnectionState(err)
|
|
|
|
|
2023-02-20 09:32:45 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2024-07-02 17:58:55 +00:00
|
|
|
return res.([]byte), nil
|
2023-02-20 09:32:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *ClientWithFallback) CodeAt(ctx context.Context, account common.Address, blockNumber *big.Int) ([]byte, error) {
|
|
|
|
rpcstats.CountCall("eth_CodeAt")
|
|
|
|
|
2024-03-06 13:49:17 +00:00
|
|
|
res, err := c.makeCall(
|
2024-09-24 13:07:26 +00:00
|
|
|
ctx, c.ethClients, func(client ethclient.RPSLimitedEthClientInterface) (interface{}, error) {
|
|
|
|
return client.CodeAt(ctx, account, blockNumber)
|
2024-07-02 17:58:55 +00:00
|
|
|
},
|
2023-02-20 09:32:45 +00:00
|
|
|
)
|
|
|
|
|
2024-03-06 13:49:17 +00:00
|
|
|
c.toggleConnectionState(err)
|
|
|
|
|
2023-02-20 09:32:45 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2024-07-02 17:58:55 +00:00
|
|
|
return res.([]byte), nil
|
2023-02-20 09:32:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *ClientWithFallback) NonceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (uint64, error) {
|
2024-05-20 11:21:21 +00:00
|
|
|
rpcstats.CountCallWithTag("eth_NonceAt", c.tag)
|
2023-02-20 09:32:45 +00:00
|
|
|
|
2024-03-06 13:49:17 +00:00
|
|
|
res, err := c.makeCall(
|
2024-09-24 13:07:26 +00:00
|
|
|
ctx, c.ethClients, func(client ethclient.RPSLimitedEthClientInterface) (interface{}, error) {
|
|
|
|
return client.NonceAt(ctx, account, blockNumber)
|
2024-07-02 17:58:55 +00:00
|
|
|
},
|
2023-02-20 09:32:45 +00:00
|
|
|
)
|
|
|
|
|
2024-03-06 13:49:17 +00:00
|
|
|
c.toggleConnectionState(err)
|
|
|
|
|
2023-02-20 09:32:45 +00:00
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
|
2024-07-02 17:58:55 +00:00
|
|
|
return res.(uint64), nil
|
2023-02-20 09:32:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *ClientWithFallback) FilterLogs(ctx context.Context, q ethereum.FilterQuery) ([]types.Log, error) {
|
2024-05-20 11:21:21 +00:00
|
|
|
rpcstats.CountCallWithTag("eth_FilterLogs", c.tag)
|
2023-02-20 09:32:45 +00:00
|
|
|
|
2024-07-02 17:58:55 +00:00
|
|
|
// Override providers name to use a separate circuit for this command as it more often fails due to rate limiting
|
2024-09-24 13:07:26 +00:00
|
|
|
ethClients := make([]ethclient.RPSLimitedEthClientInterface, len(c.ethClients))
|
2024-07-02 17:58:55 +00:00
|
|
|
for i, client := range c.ethClients {
|
2024-09-24 13:07:26 +00:00
|
|
|
ethClients[i] = client.CopyWithName(client.GetName() + "_FilterLogs")
|
2024-07-02 17:58:55 +00:00
|
|
|
}
|
|
|
|
|
2024-03-06 13:49:17 +00:00
|
|
|
res, err := c.makeCall(
|
2024-09-24 13:07:26 +00:00
|
|
|
ctx, c.ethClients, func(client ethclient.RPSLimitedEthClientInterface) (interface{}, error) {
|
|
|
|
return client.FilterLogs(ctx, q)
|
2024-07-02 17:58:55 +00:00
|
|
|
},
|
2023-02-20 09:32:45 +00:00
|
|
|
)
|
|
|
|
|
2024-07-02 17:58:55 +00:00
|
|
|
// No connection state toggling here, as it often mail fail due to archive node rate limiting
|
|
|
|
// which does not impact other calls
|
2024-03-06 13:49:17 +00:00
|
|
|
|
2023-02-20 09:32:45 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2024-07-02 17:58:55 +00:00
|
|
|
return res.([]types.Log), nil
|
2023-02-20 09:32:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *ClientWithFallback) SubscribeFilterLogs(ctx context.Context, q ethereum.FilterQuery, ch chan<- types.Log) (ethereum.Subscription, error) {
|
|
|
|
rpcstats.CountCall("eth_SubscribeFilterLogs")
|
|
|
|
|
2024-03-06 13:49:17 +00:00
|
|
|
res, err := c.makeCall(
|
2024-09-24 13:07:26 +00:00
|
|
|
ctx, c.ethClients, func(client ethclient.RPSLimitedEthClientInterface) (interface{}, error) {
|
|
|
|
return client.SubscribeFilterLogs(ctx, q, ch)
|
2024-07-02 17:58:55 +00:00
|
|
|
},
|
2023-02-20 09:32:45 +00:00
|
|
|
)
|
|
|
|
|
2024-03-06 13:49:17 +00:00
|
|
|
c.toggleConnectionState(err)
|
|
|
|
|
2023-02-20 09:32:45 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2024-07-02 17:58:55 +00:00
|
|
|
return res.(ethereum.Subscription), nil
|
2023-02-20 09:32:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *ClientWithFallback) PendingBalanceAt(ctx context.Context, account common.Address) (*big.Int, error) {
|
|
|
|
rpcstats.CountCall("eth_PendingBalanceAt")
|
|
|
|
|
2024-03-06 13:49:17 +00:00
|
|
|
res, err := c.makeCall(
|
2024-09-24 13:07:26 +00:00
|
|
|
ctx, c.ethClients, func(client ethclient.RPSLimitedEthClientInterface) (interface{}, error) {
|
|
|
|
return client.PendingBalanceAt(ctx, account)
|
2024-07-02 17:58:55 +00:00
|
|
|
},
|
2023-02-20 09:32:45 +00:00
|
|
|
)
|
|
|
|
|
2024-03-06 13:49:17 +00:00
|
|
|
c.toggleConnectionState(err)
|
|
|
|
|
2023-02-20 09:32:45 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2024-07-02 17:58:55 +00:00
|
|
|
return res.(*big.Int), nil
|
2023-02-20 09:32:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *ClientWithFallback) PendingStorageAt(ctx context.Context, account common.Address, key common.Hash) ([]byte, error) {
|
|
|
|
rpcstats.CountCall("eth_PendingStorageAt")
|
|
|
|
|
2024-03-06 13:49:17 +00:00
|
|
|
res, err := c.makeCall(
|
2024-09-24 13:07:26 +00:00
|
|
|
ctx, c.ethClients, func(client ethclient.RPSLimitedEthClientInterface) (interface{}, error) {
|
|
|
|
return client.PendingStorageAt(ctx, account, key)
|
2024-07-02 17:58:55 +00:00
|
|
|
},
|
2023-02-20 09:32:45 +00:00
|
|
|
)
|
|
|
|
|
2024-03-06 13:49:17 +00:00
|
|
|
c.toggleConnectionState(err)
|
|
|
|
|
2023-02-20 09:32:45 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2024-07-02 17:58:55 +00:00
|
|
|
return res.([]byte), nil
|
2023-02-20 09:32:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *ClientWithFallback) PendingCodeAt(ctx context.Context, account common.Address) ([]byte, error) {
|
|
|
|
rpcstats.CountCall("eth_PendingCodeAt")
|
|
|
|
|
2024-03-06 13:49:17 +00:00
|
|
|
res, err := c.makeCall(
|
2024-09-24 13:07:26 +00:00
|
|
|
ctx, c.ethClients, func(client ethclient.RPSLimitedEthClientInterface) (interface{}, error) {
|
|
|
|
return client.PendingCodeAt(ctx, account)
|
2024-07-02 17:58:55 +00:00
|
|
|
},
|
2023-02-20 09:32:45 +00:00
|
|
|
)
|
|
|
|
|
2024-03-06 13:49:17 +00:00
|
|
|
c.toggleConnectionState(err)
|
|
|
|
|
2023-02-20 09:32:45 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2024-07-02 17:58:55 +00:00
|
|
|
return res.([]byte), nil
|
2023-02-20 09:32:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *ClientWithFallback) PendingNonceAt(ctx context.Context, account common.Address) (uint64, error) {
|
|
|
|
rpcstats.CountCall("eth_PendingNonceAt")
|
|
|
|
|
2024-03-06 13:49:17 +00:00
|
|
|
res, err := c.makeCall(
|
2024-09-24 13:07:26 +00:00
|
|
|
ctx, c.ethClients, func(client ethclient.RPSLimitedEthClientInterface) (interface{}, error) {
|
|
|
|
return client.PendingNonceAt(ctx, account)
|
2024-07-02 17:58:55 +00:00
|
|
|
},
|
2023-02-20 09:32:45 +00:00
|
|
|
)
|
|
|
|
|
2024-03-06 13:49:17 +00:00
|
|
|
c.toggleConnectionState(err)
|
|
|
|
|
2023-02-20 09:32:45 +00:00
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
|
2024-07-02 17:58:55 +00:00
|
|
|
return res.(uint64), nil
|
2023-02-20 09:32:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *ClientWithFallback) PendingTransactionCount(ctx context.Context) (uint, error) {
|
|
|
|
rpcstats.CountCall("eth_PendingTransactionCount")
|
|
|
|
|
2024-03-06 13:49:17 +00:00
|
|
|
res, err := c.makeCall(
|
2024-09-24 13:07:26 +00:00
|
|
|
ctx, c.ethClients, func(client ethclient.RPSLimitedEthClientInterface) (interface{}, error) {
|
|
|
|
return client.PendingTransactionCount(ctx)
|
2024-07-02 17:58:55 +00:00
|
|
|
},
|
2023-02-20 09:32:45 +00:00
|
|
|
)
|
|
|
|
|
2024-03-06 13:49:17 +00:00
|
|
|
c.toggleConnectionState(err)
|
|
|
|
|
2023-02-20 09:32:45 +00:00
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
|
2024-07-02 17:58:55 +00:00
|
|
|
return res.(uint), nil
|
2023-02-20 09:32:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *ClientWithFallback) CallContract(ctx context.Context, msg ethereum.CallMsg, blockNumber *big.Int) ([]byte, error) {
|
2024-01-19 15:57:04 +00:00
|
|
|
rpcstats.CountCall("eth_CallContract_" + msg.To.String())
|
2023-02-20 09:32:45 +00:00
|
|
|
|
2024-03-06 13:49:17 +00:00
|
|
|
res, err := c.makeCall(
|
2024-09-24 13:07:26 +00:00
|
|
|
ctx, c.ethClients, func(client ethclient.RPSLimitedEthClientInterface) (interface{}, error) {
|
|
|
|
return client.CallContract(ctx, msg, blockNumber)
|
2024-03-06 13:49:17 +00:00
|
|
|
},
|
2023-02-20 09:32:45 +00:00
|
|
|
)
|
|
|
|
|
2024-03-06 13:49:17 +00:00
|
|
|
c.toggleConnectionState(err)
|
|
|
|
|
2023-02-20 09:32:45 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2024-07-02 17:58:55 +00:00
|
|
|
return res.([]byte), nil
|
2023-02-20 09:32:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *ClientWithFallback) PendingCallContract(ctx context.Context, msg ethereum.CallMsg) ([]byte, error) {
|
|
|
|
rpcstats.CountCall("eth_PendingCallContract")
|
|
|
|
|
2024-03-06 13:49:17 +00:00
|
|
|
res, err := c.makeCall(
|
2024-09-24 13:07:26 +00:00
|
|
|
ctx, c.ethClients, func(client ethclient.RPSLimitedEthClientInterface) (interface{}, error) {
|
|
|
|
return client.PendingCallContract(ctx, msg)
|
2024-07-02 17:58:55 +00:00
|
|
|
},
|
2023-02-20 09:32:45 +00:00
|
|
|
)
|
|
|
|
|
2024-03-06 13:49:17 +00:00
|
|
|
c.toggleConnectionState(err)
|
|
|
|
|
2023-02-20 09:32:45 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2024-07-02 17:58:55 +00:00
|
|
|
return res.([]byte), nil
|
2023-02-20 09:32:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *ClientWithFallback) SuggestGasPrice(ctx context.Context) (*big.Int, error) {
|
|
|
|
rpcstats.CountCall("eth_SuggestGasPrice")
|
|
|
|
|
2024-03-06 13:49:17 +00:00
|
|
|
res, err := c.makeCall(
|
2024-09-24 13:07:26 +00:00
|
|
|
ctx, c.ethClients, func(client ethclient.RPSLimitedEthClientInterface) (interface{}, error) {
|
|
|
|
return client.SuggestGasPrice(ctx)
|
2024-07-02 17:58:55 +00:00
|
|
|
},
|
2023-02-20 09:32:45 +00:00
|
|
|
)
|
|
|
|
|
2024-03-06 13:49:17 +00:00
|
|
|
c.toggleConnectionState(err)
|
|
|
|
|
2023-02-20 09:32:45 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2024-07-02 17:58:55 +00:00
|
|
|
return res.(*big.Int), nil
|
2023-02-20 09:32:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *ClientWithFallback) SuggestGasTipCap(ctx context.Context) (*big.Int, error) {
|
|
|
|
rpcstats.CountCall("eth_SuggestGasTipCap")
|
|
|
|
|
2024-03-06 13:49:17 +00:00
|
|
|
res, err := c.makeCall(
|
2024-09-24 13:07:26 +00:00
|
|
|
ctx, c.ethClients, func(client ethclient.RPSLimitedEthClientInterface) (interface{}, error) {
|
|
|
|
return client.SuggestGasTipCap(ctx)
|
2024-07-02 17:58:55 +00:00
|
|
|
},
|
2023-02-20 09:32:45 +00:00
|
|
|
)
|
|
|
|
|
2024-03-06 13:49:17 +00:00
|
|
|
c.toggleConnectionState(err)
|
|
|
|
|
2023-02-20 09:32:45 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2024-07-02 17:58:55 +00:00
|
|
|
return res.(*big.Int), nil
|
2023-02-20 09:32:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *ClientWithFallback) FeeHistory(ctx context.Context, blockCount uint64, lastBlock *big.Int, rewardPercentiles []float64) (*ethereum.FeeHistory, error) {
|
|
|
|
rpcstats.CountCall("eth_FeeHistory")
|
|
|
|
|
2024-03-06 13:49:17 +00:00
|
|
|
res, err := c.makeCall(
|
2024-09-24 13:07:26 +00:00
|
|
|
ctx, c.ethClients, func(client ethclient.RPSLimitedEthClientInterface) (interface{}, error) {
|
|
|
|
return client.FeeHistory(ctx, blockCount, lastBlock, rewardPercentiles)
|
2024-03-06 13:49:17 +00:00
|
|
|
},
|
2023-02-20 09:32:45 +00:00
|
|
|
)
|
|
|
|
|
2024-03-06 13:49:17 +00:00
|
|
|
c.toggleConnectionState(err)
|
|
|
|
|
2023-02-20 09:32:45 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2024-07-02 17:58:55 +00:00
|
|
|
return res.(*ethereum.FeeHistory), nil
|
2023-02-20 09:32:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *ClientWithFallback) EstimateGas(ctx context.Context, msg ethereum.CallMsg) (uint64, error) {
|
|
|
|
rpcstats.CountCall("eth_EstimateGas")
|
|
|
|
|
2024-03-06 13:49:17 +00:00
|
|
|
res, err := c.makeCall(
|
2024-09-24 13:07:26 +00:00
|
|
|
ctx, c.ethClients, func(client ethclient.RPSLimitedEthClientInterface) (interface{}, error) {
|
|
|
|
return client.EstimateGas(ctx, msg)
|
2024-07-02 17:58:55 +00:00
|
|
|
},
|
2023-02-20 09:32:45 +00:00
|
|
|
)
|
|
|
|
|
2024-03-06 13:49:17 +00:00
|
|
|
c.toggleConnectionState(err)
|
|
|
|
|
2023-02-20 09:32:45 +00:00
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
|
2024-07-02 17:58:55 +00:00
|
|
|
return res.(uint64), nil
|
2023-02-20 09:32:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *ClientWithFallback) SendTransaction(ctx context.Context, tx *types.Transaction) error {
|
|
|
|
rpcstats.CountCall("eth_SendTransaction")
|
|
|
|
|
2024-03-06 13:49:17 +00:00
|
|
|
_, err := c.makeCall(
|
2024-09-24 13:07:26 +00:00
|
|
|
ctx, c.ethClients, func(client ethclient.RPSLimitedEthClientInterface) (interface{}, error) {
|
|
|
|
return nil, client.SendTransaction(ctx, tx)
|
2024-07-02 17:58:55 +00:00
|
|
|
},
|
2023-02-20 09:32:45 +00:00
|
|
|
)
|
2024-07-02 17:58:55 +00:00
|
|
|
|
|
|
|
c.toggleConnectionState(err)
|
|
|
|
|
2024-03-06 13:49:17 +00:00
|
|
|
return err
|
2023-02-20 09:32:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *ClientWithFallback) CallContext(ctx context.Context, result interface{}, method string, args ...interface{}) error {
|
|
|
|
rpcstats.CountCall("eth_CallContext")
|
|
|
|
|
2024-03-06 13:49:17 +00:00
|
|
|
_, err := c.makeCall(
|
2024-09-24 13:07:26 +00:00
|
|
|
ctx, c.ethClients, func(client ethclient.RPSLimitedEthClientInterface) (interface{}, error) {
|
|
|
|
return nil, client.CallContext(ctx, result, method, args...)
|
2024-07-02 17:58:55 +00:00
|
|
|
},
|
2023-02-20 09:32:45 +00:00
|
|
|
)
|
2024-07-02 17:58:55 +00:00
|
|
|
|
|
|
|
c.toggleConnectionState(err)
|
|
|
|
|
2024-03-06 13:49:17 +00:00
|
|
|
return err
|
2023-02-20 09:32:45 +00:00
|
|
|
}
|
|
|
|
|
2023-08-01 18:50:30 +00:00
|
|
|
func (c *ClientWithFallback) BatchCallContext(ctx context.Context, b []rpc.BatchElem) error {
|
|
|
|
rpcstats.CountCall("eth_BatchCallContext")
|
|
|
|
|
2024-03-06 13:49:17 +00:00
|
|
|
_, err := c.makeCall(
|
2024-09-24 13:07:26 +00:00
|
|
|
ctx, c.ethClients, func(client ethclient.RPSLimitedEthClientInterface) (interface{}, error) {
|
|
|
|
return nil, client.BatchCallContext(ctx, b)
|
2024-07-02 17:58:55 +00:00
|
|
|
},
|
2023-08-01 18:50:30 +00:00
|
|
|
)
|
2024-07-02 17:58:55 +00:00
|
|
|
|
|
|
|
c.toggleConnectionState(err)
|
|
|
|
|
2024-03-06 13:49:17 +00:00
|
|
|
return err
|
2023-08-01 18:50:30 +00:00
|
|
|
}
|
|
|
|
|
2023-02-20 09:32:45 +00:00
|
|
|
func (c *ClientWithFallback) ToBigInt() *big.Int {
|
|
|
|
return big.NewInt(int64(c.ChainID))
|
|
|
|
}
|
|
|
|
|
2024-02-23 14:27:08 +00:00
|
|
|
func (c *ClientWithFallback) GetBaseFeeFromBlock(ctx context.Context, blockNumber *big.Int) (string, error) {
|
2023-02-20 09:32:45 +00:00
|
|
|
rpcstats.CountCall("eth_GetBaseFeeFromBlock")
|
2024-02-23 14:27:08 +00:00
|
|
|
|
|
|
|
feeHistory, err := c.FeeHistory(ctx, 1, blockNumber, nil)
|
|
|
|
|
2023-02-20 09:32:45 +00:00
|
|
|
if err != nil {
|
|
|
|
if err.Error() == "the method eth_feeHistory does not exist/is not available" {
|
|
|
|
return "", nil
|
|
|
|
}
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
var baseGasFee string = ""
|
2024-02-23 14:27:08 +00:00
|
|
|
if len(feeHistory.BaseFee) > 0 {
|
|
|
|
baseGasFee = feeHistory.BaseFee[0].String()
|
2023-02-20 09:32:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return baseGasFee, err
|
|
|
|
}
|
2023-06-01 17:16:50 +00:00
|
|
|
|
2023-09-20 08:41:23 +00:00
|
|
|
func (c *ClientWithFallback) GetWalletNotifier() func(chainId uint64, message string) {
|
|
|
|
return c.WalletNotifier
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *ClientWithFallback) SetWalletNotifier(notifier func(chainId uint64, message string)) {
|
|
|
|
c.WalletNotifier = notifier
|
|
|
|
}
|
2024-03-06 13:49:17 +00:00
|
|
|
|
|
|
|
func (c *ClientWithFallback) toggleConnectionState(err error) {
|
|
|
|
connected := true
|
|
|
|
if err != nil {
|
2024-09-24 13:07:26 +00:00
|
|
|
if !isNotFoundError(err) && !isVMError(err) && !errors.Is(err, rpclimiter.ErrRequestsOverLimit) && !errors.Is(err, context.Canceled) {
|
2024-08-14 13:15:14 +00:00
|
|
|
log.Warn("Error not in chain call", "error", err, "chain", c.ChainID)
|
2024-03-06 13:49:17 +00:00
|
|
|
connected = false
|
2024-07-29 17:07:43 +00:00
|
|
|
} else {
|
|
|
|
log.Warn("Error in chain call", "error", err)
|
2024-03-06 13:49:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
c.SetIsConnected(connected)
|
|
|
|
}
|
2024-05-20 11:21:21 +00:00
|
|
|
|
|
|
|
func (c *ClientWithFallback) Tag() string {
|
|
|
|
return c.tag
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *ClientWithFallback) SetTag(tag string) {
|
|
|
|
c.tag = tag
|
|
|
|
}
|
|
|
|
|
2024-05-21 17:40:37 +00:00
|
|
|
func (c *ClientWithFallback) GroupTag() string {
|
|
|
|
return c.groupTag
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *ClientWithFallback) SetGroupTag(tag string) {
|
|
|
|
c.groupTag = tag
|
|
|
|
}
|
|
|
|
|
2024-09-24 13:07:26 +00:00
|
|
|
func (c *ClientWithFallback) DeepCopyTag() tagger.Tagger {
|
2024-05-20 11:21:21 +00:00
|
|
|
copy := *c
|
|
|
|
return ©
|
|
|
|
}
|
2024-05-20 12:38:02 +00:00
|
|
|
|
2024-09-24 13:07:26 +00:00
|
|
|
func (c *ClientWithFallback) GetLimiter() rpclimiter.RequestLimiter {
|
2024-05-20 12:38:02 +00:00
|
|
|
return c.commonLimiter
|
|
|
|
}
|
|
|
|
|
2024-09-24 13:07:26 +00:00
|
|
|
func (c *ClientWithFallback) SetLimiter(limiter rpclimiter.RequestLimiter) {
|
2024-05-20 12:38:02 +00:00
|
|
|
c.commonLimiter = limiter
|
|
|
|
}
|
2024-07-29 17:07:43 +00:00
|
|
|
|
|
|
|
func (c *ClientWithFallback) GetCircuitBreaker() *circuitbreaker.CircuitBreaker {
|
|
|
|
return c.circuitbreaker
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *ClientWithFallback) SetCircuitBreaker(cb *circuitbreaker.CircuitBreaker) {
|
|
|
|
c.circuitbreaker = cb
|
|
|
|
}
|