Skip to content

Commit

Permalink
fix(op-node/op-batcher): fallbackClient should ignore ethereum.NotFou…
Browse files Browse the repository at this point in the history
…nd error (#94)

* add log

* fix: fallbackClient should ignore ethereum.NotFound error

---------

Co-authored-by: Welkin <welkin.b@nodereal.com>
  • Loading branch information
welkin22 and Welkin authored Dec 12, 2023
1 parent 5e5fe2c commit 3711711
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
3 changes: 3 additions & 0 deletions op-node/sources/fallback_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ func (l *FallbackClient) handleErr(err error) {
if errors.Is(err, rpc.ErrNoResult) {
return
}
if errors.Is(err, ethereum.NotFound) {
return
}
var targetErr rpc.Error
if errors.As(err, &targetErr) {
return
Expand Down
32 changes: 18 additions & 14 deletions op-service/client/fallback_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,55 +99,55 @@ func NewFallbackClient(rpc EthClient, urlList []string, log log.Logger, fallback
func (l *FallbackClient) BlockNumber(ctx context.Context) (uint64, error) {
number, err := (*l.currentClient.Load()).BlockNumber(ctx)
if err != nil {
l.handleErr(err)
l.handleErr(err, "BlockNumber")
}
return number, err
}

func (l *FallbackClient) TransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error) {
receipt, err := (*l.currentClient.Load()).TransactionReceipt(ctx, txHash)
if err != nil {
l.handleErr(err)
l.handleErr(err, "TransactionReceipt")
}
return receipt, err
}

func (l *FallbackClient) SendTransaction(ctx context.Context, tx *types.Transaction) error {
err := (*l.currentClient.Load()).SendTransaction(ctx, tx)
if err != nil {
l.handleErr(err)
l.handleErr(err, "SendTransaction")
}
return err
}

func (l *FallbackClient) SuggestGasTipCap(ctx context.Context) (*big.Int, error) {
tipCap, err := (*l.currentClient.Load()).SuggestGasTipCap(ctx)
if err != nil {
l.handleErr(err)
l.handleErr(err, "SuggestGasTipCap")
}
return tipCap, err
}

func (l *FallbackClient) PendingNonceAt(ctx context.Context, account common.Address) (uint64, error) {
at, err := (*l.currentClient.Load()).PendingNonceAt(ctx, account)
if err != nil {
l.handleErr(err)
l.handleErr(err, "PendingNonceAt")
}
return at, err
}

func (l *FallbackClient) EstimateGas(ctx context.Context, msg ethereum.CallMsg) (uint64, error) {
estimateGas, err := (*l.currentClient.Load()).EstimateGas(ctx, msg)
if err != nil {
l.handleErr(err)
l.handleErr(err, "EstimateGas")
}
return estimateGas, err
}

func (l *FallbackClient) CallContract(ctx context.Context, call ethereum.CallMsg, blockNumber *big.Int) ([]byte, error) {
contract, err := (*l.currentClient.Load()).CallContract(ctx, call, blockNumber)
if err != nil {
l.handleErr(err)
l.handleErr(err, "CallContract")
}
return contract, err
}
Expand All @@ -166,59 +166,63 @@ func (l *FallbackClient) Close() {
func (l *FallbackClient) ChainID(ctx context.Context) (*big.Int, error) {
id, err := (*l.currentClient.Load()).ChainID(ctx)
if err != nil {
l.handleErr(err)
l.handleErr(err, "ChainID")
}
return id, err
}

func (l *FallbackClient) BalanceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (*big.Int, error) {
balanceAt, err := (*l.currentClient.Load()).BalanceAt(ctx, account, blockNumber)
if err != nil {
l.handleErr(err)
l.handleErr(err, "BalanceAt")
}
return balanceAt, err
}

func (l *FallbackClient) HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error) {
headerByNumber, err := (*l.currentClient.Load()).HeaderByNumber(ctx, number)
if err != nil {
l.handleErr(err)
l.handleErr(err, "HeaderByNumber")
}
return headerByNumber, err
}

func (l *FallbackClient) StorageAt(ctx context.Context, account common.Address, key common.Hash, blockNumber *big.Int) ([]byte, error) {
storageAt, err := (*l.currentClient.Load()).StorageAt(ctx, account, key, blockNumber)
if err != nil {
l.handleErr(err)
l.handleErr(err, "StorageAt")
}
return storageAt, err
}

func (l *FallbackClient) CodeAt(ctx context.Context, account common.Address, blockNumber *big.Int) ([]byte, error) {
codeAt, err := (*l.currentClient.Load()).CodeAt(ctx, account, blockNumber)
if err != nil {
l.handleErr(err)
l.handleErr(err, "CodeAt")
}
return codeAt, err
}

func (l *FallbackClient) NonceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (uint64, error) {
nonceAt, err := (*l.currentClient.Load()).NonceAt(ctx, account, blockNumber)
if err != nil {
l.handleErr(err)
l.handleErr(err, "NonceAt")
}
return nonceAt, err
}

func (l *FallbackClient) handleErr(err error) {
func (l *FallbackClient) handleErr(err error, methodName string) {
if errors.Is(err, rpc.ErrNoResult) {
return
}
if errors.Is(err, ethereum.NotFound) {
return
}
var targetErr rpc.Error
if errors.As(err, &targetErr) {
return
}
log.Debug("fallback client fail count+1", "err", err, "methodName", methodName)
l.lastMinuteFail.Add(1)
}

Expand Down

0 comments on commit 3711711

Please sign in to comment.