Commit 47a1478a authored by Adrian Sutton's avatar Adrian Sutton Committed by GitHub

op-program: Avoid requesting L1 genesis block when starting from L2 genesis (#9807)

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

* op-program: Fix unit tests
parent fdd43835
......@@ -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
}
......
......@@ -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()
......
......@@ -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
......
......@@ -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)
......
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