Skip to content

Commit

Permalink
Merge pull request #1955 from OffchainLabs/execution-reverted-case
Browse files Browse the repository at this point in the history
Match against "execution reverted" case insensitive
  • Loading branch information
PlasmaPower authored Nov 2, 2023
2 parents ed4ec22 + 57faa80 commit fdd098e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
26 changes: 26 additions & 0 deletions staker/execution_reverted_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package staker

import (
"io"
"testing"
)

func TestExecutionRevertedRegexp(t *testing.T) {
executionRevertedErrors := []string{
// go-ethereum and most other execution clients return "execution reverted"
"execution reverted",
// execution clients may decode the EVM revert data as a string and include it in the error
"execution reverted: FOO",
// besu returns "Execution reverted"
"Execution reverted",
}
for _, errString := range executionRevertedErrors {
if !executionRevertedRegexp.MatchString(errString) {
t.Fatalf("execution reverted regexp didn't match %q", errString)
}
}
// This regexp should not match random IO errors
if executionRevertedRegexp.MatchString(io.ErrUnexpectedEOF.Error()) {
t.Fatal("execution reverted regexp matched unexpected EOF")
}
}
7 changes: 5 additions & 2 deletions staker/rollup_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"errors"
"fmt"
"math/big"
"strings"
"regexp"
"sync/atomic"

"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -72,6 +72,9 @@ func (r *RollupWatcher) getCallOpts(ctx context.Context) *bind.CallOpts {
return &opts
}

// A regexp matching "execution reverted" errors returned from the parent chain RPC.
var executionRevertedRegexp = regexp.MustCompile("(?i)execution reverted")

func (r *RollupWatcher) getNodeCreationBlock(ctx context.Context, nodeNum uint64) (*big.Int, error) {
callOpts := r.getCallOpts(ctx)
if !r.unSupportedL3Method.Load() {
Expand All @@ -80,7 +83,7 @@ func (r *RollupWatcher) getNodeCreationBlock(ctx context.Context, nodeNum uint64
return createdAtBlock, nil
}
log.Trace("failed to call getNodeCreationBlockForLogLookup, falling back on node CreatedAtBlock field", "err", err)
if strings.Contains(err.Error(), "execution reverted") {
if executionRevertedRegexp.MatchString(err.Error()) {
r.unSupportedL3Method.Store(true)
} else {
return nil, err
Expand Down

0 comments on commit fdd098e

Please sign in to comment.