Skip to content

Commit

Permalink
Improve stability of getNodeCreationBlock for L3s
Browse files Browse the repository at this point in the history
  • Loading branch information
PlasmaPower committed Sep 18, 2024
1 parent ac929a7 commit 2cdce53
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions staker/rollup_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@
package staker

import (
"bytes"
"context"
"encoding/binary"
"errors"
"fmt"
"math/big"
"strings"
"sync/atomic"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/rpc"
"github.com/offchainlabs/nitro/arbutil"
"github.com/offchainlabs/nitro/solgen/go/rollupgen"
"github.com/offchainlabs/nitro/util/headerreader"
Expand Down Expand Up @@ -51,6 +54,7 @@ type RollupWatcher struct {
client arbutil.L1Interface
baseCallOpts bind.CallOpts
unSupportedL3Method atomic.Bool
supportedL3Method atomic.Bool
}

func NewRollupWatcher(address common.Address, client arbutil.L1Interface, callOpts bind.CallOpts) (*RollupWatcher, error) {
Expand All @@ -73,15 +77,40 @@ func (r *RollupWatcher) getCallOpts(ctx context.Context) *bind.CallOpts {
return &opts
}

const noNodeErr string = "NO_NODE"

func looksLikeNoNodeError(err error) bool {
if err == nil {
return false
}
if strings.Contains(err.Error(), noNodeErr) {
return true
}
errWithData, ok := err.(rpc.DataError)

Check failure on line 89 in staker/rollup_watcher.go

View workflow job for this annotation

GitHub Actions / Go Tests (challenge)

type assertion on error will fail on wrapped errors. Use errors.As to check for specific errors (errorlint)

Check failure on line 89 in staker/rollup_watcher.go

View workflow job for this annotation

GitHub Actions / Go Tests (defaults)

type assertion on error will fail on wrapped errors. Use errors.As to check for specific errors (errorlint)

Check failure on line 89 in staker/rollup_watcher.go

View workflow job for this annotation

GitHub Actions / Go Tests (long)

type assertion on error will fail on wrapped errors. Use errors.As to check for specific errors (errorlint)

Check failure on line 89 in staker/rollup_watcher.go

View workflow job for this annotation

GitHub Actions / Go Tests (stylus)

type assertion on error will fail on wrapped errors. Use errors.As to check for specific errors (errorlint)

Check failure on line 89 in staker/rollup_watcher.go

View workflow job for this annotation

GitHub Actions / Go Tests (race)

type assertion on error will fail on wrapped errors. Use errors.As to check for specific errors (errorlint)
if !ok {
return false
}
dataString, ok := errWithData.ErrorData().(string)
if !ok {
return false
}
data := common.FromHex(dataString)
return bytes.Contains(data, []byte(noNodeErr))
}

func (r *RollupWatcher) getNodeCreationBlock(ctx context.Context, nodeNum uint64) (*big.Int, error) {
callOpts := r.getCallOpts(ctx)
if !r.unSupportedL3Method.Load() {
createdAtBlock, err := r.GetNodeCreationBlockForLogLookup(callOpts, nodeNum)
if err == nil {
r.supportedL3Method.Store(true)
return createdAtBlock, nil
}
log.Trace("failed to call getNodeCreationBlockForLogLookup, falling back on node CreatedAtBlock field", "err", err)
if headerreader.ExecutionRevertedRegexp.MatchString(err.Error()) {
if headerreader.ExecutionRevertedRegexp.MatchString(err.Error()) && !looksLikeNoNodeError(err) {
if r.supportedL3Method.Load() {
return nil, fmt.Errorf("getNodeCreationBlockForLogLookup failed despite previously succeeding: %w", err)
}
log.Trace("failed to call getNodeCreationBlockForLogLookup, falling back on node CreatedAtBlock field", "err", err)
r.unSupportedL3Method.Store(true)
} else {
return nil, err
Expand Down

0 comments on commit 2cdce53

Please sign in to comment.