diff --git a/op-node/node/safedb/disabled.go b/op-node/node/safedb/disabled.go index 0b24091e982f..09ff5cf2433a 100644 --- a/op-node/node/safedb/disabled.go +++ b/op-node/node/safedb/disabled.go @@ -14,6 +14,10 @@ var ( ErrNotEnabled = errors.New("safe head database not enabled") ) +func (d *DisabledDB) Enabled() bool { + return false +} + func (d *DisabledDB) SafeHeadUpdated(_ eth.L2BlockRef, _ eth.BlockID) error { return nil } diff --git a/op-node/node/safedb/safedb.go b/op-node/node/safedb/safedb.go index b6cc806d0a9a..6b45411b7981 100644 --- a/op-node/node/safedb/safedb.go +++ b/op-node/node/safedb/safedb.go @@ -93,6 +93,10 @@ func NewSafeDB(logger log.Logger, path string) (*SafeDB, error) { }, nil } +func (d *SafeDB) Enabled() bool { + return true +} + func (d *SafeDB) SafeHeadUpdated(safeHead eth.L2BlockRef, l1Head eth.BlockID) error { d.m.Lock() defer d.m.Unlock() diff --git a/op-node/rollup/derive/engine_queue.go b/op-node/rollup/derive/engine_queue.go index 230bec9cf170..6817ba96b3c9 100644 --- a/op-node/rollup/derive/engine_queue.go +++ b/op-node/rollup/derive/engine_queue.go @@ -99,6 +99,12 @@ type LocalEngineControl interface { // The safe head may advance by more than one block in a single update // The l1Block specified is the first L1 block that includes sufficient information to derive the new safe head type SafeHeadListener interface { + + // Enabled reports if this safe head listener is actively using the posted data. This allows the engine queue to + // optionally skip making calls that may be expensive to prepare. + // Callbacks may still be made if Enabled returns false but are not guaranteed. + Enabled() bool + // SafeHeadUpdated indicates that the safe head has been updated in response to processing batch data // The l1Block specified is the first L1 block containing all required batch data to derive newSafeHead SafeHeadUpdated(newSafeHead eth.L2BlockRef, l1Block eth.BlockID) error @@ -723,7 +729,7 @@ func (eq *EngineQueue) Reset(ctx context.Context, _ eth.L1BlockRef, _ eth.System if err := eq.safeHeadNotifs.SafeHeadReset(safe); err != nil { return err } - if safe.Number == eq.cfg.Genesis.L2.Number && safe.Hash == eq.cfg.Genesis.L2.Hash { + if eq.safeHeadNotifs.Enabled() && safe.Number == eq.cfg.Genesis.L2.Number && safe.Hash == eq.cfg.Genesis.L2.Hash { // The rollup genesis block is always safe by definition. So if the pipeline resets this far back we know // we will process all safe head updates and can record genesis as always safe from L1 genesis. // Note that it is not safe to use cfg.Genesis.L1 here as it is the block immediately before the L2 genesis diff --git a/op-node/rollup/derive/engine_queue_test.go b/op-node/rollup/derive/engine_queue_test.go index aa4504eddc97..45bcc8ef558b 100644 --- a/op-node/rollup/derive/engine_queue_test.go +++ b/op-node/rollup/derive/engine_queue_test.go @@ -898,7 +898,6 @@ func TestBlockBuildingRace(t *testing.T) { l1F.ExpectL1BlockRefByNumber(refA.Number, refA, nil) l1F.ExpectL1BlockRefByHash(refA.Hash, refA, nil) l1F.ExpectL1BlockRefByHash(refA.Hash, refA, nil) - l1F.ExpectL1BlockRefByNumber(0, refA, nil) eng.ExpectSystemConfigByL2Hash(refA0.Hash, cfg.Genesis.SystemConfig, nil) @@ -1024,7 +1023,6 @@ func TestResetLoop(t *testing.T) { rng := rand.New(rand.NewSource(1234)) - l1Genesis := eth.L1BlockRef{Number: 0} refA := testutils.RandomBlockRef(rng) refA0 := eth.L2BlockRef{ Hash: testutils.RandomHash(rng), @@ -1082,7 +1080,6 @@ func TestResetLoop(t *testing.T) { eng.ExpectL2BlockRefByHash(refA1.Hash, refA1, nil) eng.ExpectL2BlockRefByHash(refA0.Hash, refA0, nil) eng.ExpectSystemConfigByL2Hash(refA0.Hash, cfg.Genesis.SystemConfig, nil) - l1F.ExpectL1BlockRefByNumber(0, l1Genesis, nil) l1F.ExpectL1BlockRefByNumber(refA.Number, refA, nil) l1F.ExpectL1BlockRefByHash(refA.Hash, refA, nil) l1F.ExpectL1BlockRefByHash(refA.Hash, refA, nil)