Skip to content

Commit

Permalink
op-program: Avoid requesting L1 genesis block when starting from L2 g…
Browse files Browse the repository at this point in the history
…enesis (ethereum-optimism#9807)

* op-program: Avoid requesting L1 genesis block when starting from L2 genesis.

* op-program: Fix unit tests
  • Loading branch information
ajsutton authored Mar 11, 2024
1 parent fdd4383 commit 47a1478
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
4 changes: 4 additions & 0 deletions op-node/node/safedb/disabled.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 4 additions & 0 deletions op-node/node/safedb/safedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
8 changes: 7 additions & 1 deletion op-node/rollup/derive/engine_queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions op-node/rollup/derive/engine_queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 47a1478

Please sign in to comment.