Skip to content

Commit

Permalink
op-node: Restore previous unsafe chain when invalid span batch (#8925)
Browse files Browse the repository at this point in the history
* op-node: Restore previous unsafe chain using backupUnsafe

* op-e2e: Enable custom error while mocking L2 RPC error

* op-e2e: Add BackupUnsafe tests

* op-node: Fix comment

* op-node: Follow convention for backup unsafe head metric

* op-e2e: Fix BackupUnsafe tests

* op-node: Tailered/Consistent log message

* op-e2e: Better coding style

* op-node: Refactor code for trying backupUnsafe reorg

* op-node: Better variable name

* op-e2e: Remove global variable

Test are run concurrently so accessing shared global object is problematic
  • Loading branch information
pcw109550 authored Mar 7, 2024
1 parent 4b7627c commit 9cccd6b
Show file tree
Hide file tree
Showing 6 changed files with 603 additions and 13 deletions.
6 changes: 3 additions & 3 deletions op-e2e/actions/l2_engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,13 @@ func (e *L2Engine) EngineClient(t Testing, cfg *rollup.Config) *sources.EngineCl
return l2Cl
}

// ActL2RPCFail makes the next L2 RPC request fail
func (e *L2Engine) ActL2RPCFail(t Testing) {
// ActL2RPCFail makes the next L2 RPC request fail with given error
func (e *L2Engine) ActL2RPCFail(t Testing, err error) {
if e.failL2RPC != nil { // already set to fail?
t.InvalidAction("already set a mock L2 rpc error")
return
}
e.failL2RPC = errors.New("mock L2 RPC error")
e.failL2RPC = err
}

// ActL2IncludeTx includes the next transaction from the given address in the block that is being built
Expand Down
6 changes: 4 additions & 2 deletions op-e2e/actions/l2_engine_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package actions

import (
"errors"
"math/big"
"testing"

Expand Down Expand Up @@ -192,12 +193,13 @@ func TestL2EngineAPIFail(gt *testing.T) {
log := testlog.Logger(t, log.LevelDebug)
engine := NewL2Engine(t, log, sd.L2Cfg, sd.RollupCfg.Genesis.L1, jwtPath)
// mock an RPC failure
engine.ActL2RPCFail(t)
mockErr := errors.New("mock L2 RPC error")
engine.ActL2RPCFail(t, mockErr)
// check RPC failure
l2Cl, err := sources.NewL2Client(engine.RPCClient(), log, nil, sources.L2ClientDefaultConfig(sd.RollupCfg, false))
require.NoError(t, err)
_, err = l2Cl.InfoByLabel(t.Ctx(), eth.Unsafe)
require.ErrorContains(t, err, "mock")
require.ErrorIs(t, err, mockErr)
head, err := l2Cl.InfoByLabel(t.Ctx(), eth.Unsafe)
require.NoError(t, err)
require.Equal(gt, sd.L2Cfg.ToBlock().Hash(), head.Hash(), "expecting engine to start at genesis")
Expand Down
4 changes: 4 additions & 0 deletions op-e2e/actions/l2_verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ func (s *L2Verifier) L2Unsafe() eth.L2BlockRef {
return s.engine.UnsafeL2Head()
}

func (s *L2Verifier) L2BackupUnsafe() eth.L2BlockRef {
return s.engine.BackupUnsafeL2Head()
}

func (s *L2Verifier) SyncStatus() *eth.SyncStatus {
return &eth.SyncStatus{
CurrentL1: s.derivation.Origin(),
Expand Down
Loading

0 comments on commit 9cccd6b

Please sign in to comment.