Commit 5ad549a3 authored by protolambda's avatar protolambda Committed by GitHub

op-node: limit reorg depth with sanity check (#3422)

Co-authored-by: default avatarmergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
parent 636c54c4
...@@ -49,7 +49,7 @@ var ReorgFinalizedErr = errors.New("cannot reorg finalized block") ...@@ -49,7 +49,7 @@ var ReorgFinalizedErr = errors.New("cannot reorg finalized block")
var WrongChainErr = errors.New("wrong chain") var WrongChainErr = errors.New("wrong chain")
var TooDeepReorgErr = errors.New("reorg is too deep") var TooDeepReorgErr = errors.New("reorg is too deep")
const MaxReorgDepth = 500 const MaxReorgSeqWindows = 5
type FindHeadsResult struct { type FindHeadsResult struct {
Unsafe eth.L2BlockRef Unsafe eth.L2BlockRef
...@@ -154,7 +154,7 @@ func FindL2Heads(ctx context.Context, cfg *rollup.Config, l1 L1Chain, l2 L2Chain ...@@ -154,7 +154,7 @@ func FindL2Heads(ctx context.Context, cfg *rollup.Config, l1 L1Chain, l2 L2Chain
return nil, fmt.Errorf("%w: finalized %s, got: %s", ReorgFinalizedErr, result.Finalized, n) return nil, fmt.Errorf("%w: finalized %s, got: %s", ReorgFinalizedErr, result.Finalized, n)
} }
// Check we are not reorging L2 incredibly deep // Check we are not reorging L2 incredibly deep
if n.Number+MaxReorgDepth < prevUnsafe.Number { if n.L1Origin.Number+(MaxReorgSeqWindows*cfg.SeqWindowSize) < prevUnsafe.L1Origin.Number {
// If the reorg depth is too large, something is fishy. // If the reorg depth is too large, something is fishy.
// This can legitimately happen if L1 goes down for a while. But in that case, // This can legitimately happen if L1 goes down for a while. But in that case,
// restarting the L2 node with a bigger configured MaxReorgDepth is an acceptable // restarting the L2 node with a bigger configured MaxReorgDepth is an acceptable
......
...@@ -221,6 +221,7 @@ func TestFindSyncStart(t *testing.T) { ...@@ -221,6 +221,7 @@ func TestFindSyncStart(t *testing.T) {
GenesisL1: 'a', GenesisL1: 'a',
GenesisL2: 'A', GenesisL2: 'A',
UnsafeL2Head: 0, UnsafeL2Head: 0,
SeqWindowSize: 2,
ExpectedErr: WrongChainErr, ExpectedErr: WrongChainErr,
}, },
{ {
...@@ -234,6 +235,7 @@ func TestFindSyncStart(t *testing.T) { ...@@ -234,6 +235,7 @@ func TestFindSyncStart(t *testing.T) {
GenesisL1: 'a', GenesisL1: 'a',
GenesisL2: 'X', GenesisL2: 'X',
UnsafeL2Head: 0, UnsafeL2Head: 0,
SeqWindowSize: 2,
ExpectedErr: WrongChainErr, ExpectedErr: WrongChainErr,
}, },
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment