From 84a51cd0f7565f981822c3f23d71ef6b29904356 Mon Sep 17 00:00:00 2001 From: Kelvyne Date: Tue, 18 Jul 2023 15:15:59 +0200 Subject: [PATCH 1/2] fix(op-node): Correctly pop unsafe payload queue when payload is too older Fixes #6092 --- op-node/rollup/derive/engine_queue.go | 5 ++ op-node/rollup/derive/engine_queue_test.go | 85 ++++++++++++++++++++++ 2 files changed, 90 insertions(+) diff --git a/op-node/rollup/derive/engine_queue.go b/op-node/rollup/derive/engine_queue.go index 1fe213d843..6cdb69e630 100644 --- a/op-node/rollup/derive/engine_queue.go +++ b/op-node/rollup/derive/engine_queue.go @@ -473,6 +473,11 @@ func (eq *EngineQueue) tryNextUnsafePayload(ctx context.Context) error { eq.unsafePayloads.Pop() return nil } + if uint64(first.BlockNumber) <= eq.unsafeHead.Number { + eq.log.Info("skipping unsafe payload, since it is older than unsafe head", "unsafe", eq.unsafeHead.ID(), "unsafe_payload", first.ID()) + eq.unsafePayloads.Pop() + return nil + } // Ensure that the unsafe payload builds upon the current unsafe head if !eq.syncCfg.EngineSync && first.ParentHash != eq.unsafeHead.Hash { diff --git a/op-node/rollup/derive/engine_queue_test.go b/op-node/rollup/derive/engine_queue_test.go index 3a7a8625d7..2fa4fbb3cf 100644 --- a/op-node/rollup/derive/engine_queue_test.go +++ b/op-node/rollup/derive/engine_queue_test.go @@ -1117,3 +1117,88 @@ func TestResetLoop(t *testing.T) { l1F.AssertExpectations(t) eng.AssertExpectations(t) } + +func TestEngineQueue_StepPopOlderUnsafe(t *testing.T) { + logger := testlog.Logger(t, log.LvlInfo) + eng := &testutils.MockEngine{} + l1F := &testutils.MockL1Source{} + + rng := rand.New(rand.NewSource(1234)) + + refA := testutils.RandomBlockRef(rng) + refA0 := eth.L2BlockRef{ + Hash: testutils.RandomHash(rng), + Number: 0, + ParentHash: common.Hash{}, + Time: refA.Time, + L1Origin: refA.ID(), + SequenceNumber: 0, + } + gasLimit := eth.Uint64Quantity(20_000_000) + cfg := &rollup.Config{ + Genesis: rollup.Genesis{ + L1: refA.ID(), + L2: refA0.ID(), + L2Time: refA0.Time, + SystemConfig: eth.SystemConfig{ + BatcherAddr: common.Address{42}, + Overhead: [32]byte{123}, + Scalar: [32]byte{42}, + GasLimit: 20_000_000, + }, + }, + BlockTime: 1, + SeqWindowSize: 2, + } + + refA1 := eth.L2BlockRef{ + Hash: testutils.RandomHash(rng), + Number: refA0.Number + 1, + ParentHash: refA0.Hash, + Time: refA0.Time + cfg.BlockTime, + L1Origin: refA.ID(), + SequenceNumber: 1, + } + refA2 := eth.L2BlockRef{ + Hash: testutils.RandomHash(rng), + Number: refA1.Number + 1, + ParentHash: refA1.Hash, + Time: refA1.Time + cfg.BlockTime, + L1Origin: refA.ID(), + SequenceNumber: 2, + } + payloadA1 := ð.ExecutionPayload{ + ParentHash: refA1.ParentHash, + FeeRecipient: common.Address{}, + StateRoot: eth.Bytes32{}, + ReceiptsRoot: eth.Bytes32{}, + LogsBloom: eth.Bytes256{}, + PrevRandao: eth.Bytes32{}, + BlockNumber: eth.Uint64Quantity(refA1.Number), + GasLimit: gasLimit, + GasUsed: 0, + Timestamp: eth.Uint64Quantity(refA1.Time), + ExtraData: nil, + BaseFeePerGas: *uint256.NewInt(7), + BlockHash: refA1.Hash, + Transactions: []eth.Data{}, + } + + prev := &fakeAttributesQueue{origin: refA} + + eq := NewEngineQueue(logger, cfg, eng, metrics.NoopMetrics, prev, l1F) + eq.unsafeHead = refA2 + eq.safeHead = refA0 + eq.finalized = refA0 + + eq.AddUnsafePayload(payloadA1) + + err := eq.Step(context.Background()) + require.NoError(t, err) + + require.Nil(t, eq.unsafePayloads.Peek(), "should pop the unsafe payload because it is too old") + fmt.Println(eq.unsafePayloads.Peek()) + + l1F.AssertExpectations(t) + eng.AssertExpectations(t) +} From b52cd80c301a9ed817b3505365aa5d82e922e816 Mon Sep 17 00:00:00 2001 From: bnoieh <135800952+bnoieh@users.noreply.github.com> Date: Mon, 6 Nov 2023 17:51:40 +0800 Subject: [PATCH 2/2] chore: fix ci lint --- op-node/rollup/derive/engine_queue_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/op-node/rollup/derive/engine_queue_test.go b/op-node/rollup/derive/engine_queue_test.go index 2fa4fbb3cf..64bc658980 100644 --- a/op-node/rollup/derive/engine_queue_test.go +++ b/op-node/rollup/derive/engine_queue_test.go @@ -1186,7 +1186,7 @@ func TestEngineQueue_StepPopOlderUnsafe(t *testing.T) { prev := &fakeAttributesQueue{origin: refA} - eq := NewEngineQueue(logger, cfg, eng, metrics.NoopMetrics, prev, l1F) + eq := NewEngineQueue(logger, cfg, eng, metrics.NoopMetrics, prev, l1F, &sync.Config{}) eq.unsafeHead = refA2 eq.safeHead = refA0 eq.finalized = refA0