Skip to content

Commit

Permalink
op-node: Skip L2 Genesis Check when EL syncing (ethereum-optimism#8610)
Browse files Browse the repository at this point in the history
* op-node: Skip L2 Genesis Check when EL syncing

This is done because the transition block does not exist in a geth when
performing a snap sync and the actual genesis block header is pre-london
which breaks all of our fetching code.

* Update op-node/rollup/types.go
  • Loading branch information
trianglesphere authored Jan 19, 2024
1 parent 7e10a04 commit 2929bbf
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
2 changes: 1 addition & 1 deletion op-node/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ func (n *OpNode) initL2(ctx context.Context, cfg *Config, snapshotLog log.Logger
return fmt.Errorf("failed to create Engine client: %w", err)
}

if err := cfg.Rollup.ValidateL2Config(ctx, n.l2Source); err != nil {
if err := cfg.Rollup.ValidateL2Config(ctx, n.l2Source, cfg.Sync.SyncMode == sync.ELSync); err != nil {
return err
}

Expand Down
7 changes: 5 additions & 2 deletions op-node/rollup/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,16 @@ func (cfg *Config) ValidateL1Config(ctx context.Context, client L1Client) error
}

// ValidateL2Config checks L2 config variables for errors.
func (cfg *Config) ValidateL2Config(ctx context.Context, client L2Client) error {
func (cfg *Config) ValidateL2Config(ctx context.Context, client L2Client, skipL2GenesisBlockHash bool) error {
// Validate the L2 Client Chain ID
if err := cfg.CheckL2ChainID(ctx, client); err != nil {
return err
}

// Validate the Rollup L2 Genesis Blockhash
// Validate the Rollup L2 Genesis Blockhash if requested. We skip this when doing EL sync
if skipL2GenesisBlockHash {
return nil
}
if err := cfg.CheckL2GenesisBlockHash(ctx, client); err != nil {
return err
}
Expand Down
23 changes: 18 additions & 5 deletions op-node/rollup/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ func TestValidateL2Config(t *testing.T) {
config.Genesis.L2.Number = 100
config.Genesis.L2.Hash = [32]byte{0x01}
mockClient := mockL2Client{chainID: big.NewInt(100), Hash: common.Hash{0x01}}
err := config.ValidateL2Config(context.TODO(), &mockClient)
err := config.ValidateL2Config(context.TODO(), &mockClient, false)
assert.NoError(t, err)
}

Expand All @@ -229,10 +229,10 @@ func TestValidateL2ConfigInvalidChainIdFails(t *testing.T) {
config.Genesis.L2.Number = 100
config.Genesis.L2.Hash = [32]byte{0x01}
mockClient := mockL2Client{chainID: big.NewInt(100), Hash: common.Hash{0x01}}
err := config.ValidateL2Config(context.TODO(), &mockClient)
err := config.ValidateL2Config(context.TODO(), &mockClient, false)
assert.Error(t, err)
config.L2ChainID = big.NewInt(99)
err = config.ValidateL2Config(context.TODO(), &mockClient)
err = config.ValidateL2Config(context.TODO(), &mockClient, false)
assert.Error(t, err)
}

Expand All @@ -242,13 +242,26 @@ func TestValidateL2ConfigInvalidGenesisHashFails(t *testing.T) {
config.Genesis.L2.Number = 100
config.Genesis.L2.Hash = [32]byte{0x00}
mockClient := mockL2Client{chainID: big.NewInt(100), Hash: common.Hash{0x01}}
err := config.ValidateL2Config(context.TODO(), &mockClient)
err := config.ValidateL2Config(context.TODO(), &mockClient, false)
assert.Error(t, err)
config.Genesis.L2.Hash = [32]byte{0x02}
err = config.ValidateL2Config(context.TODO(), &mockClient)
err = config.ValidateL2Config(context.TODO(), &mockClient, false)
assert.Error(t, err)
}

func TestValidateL2ConfigInvalidGenesisHashSkippedWhenRequested(t *testing.T) {
config := randConfig()
config.L2ChainID = big.NewInt(100)
config.Genesis.L2.Number = 100
config.Genesis.L2.Hash = [32]byte{0x00}
mockClient := mockL2Client{chainID: big.NewInt(100), Hash: common.Hash{0x01}}
err := config.ValidateL2Config(context.TODO(), &mockClient, true)
assert.NoError(t, err)
config.Genesis.L2.Hash = [32]byte{0x02}
err = config.ValidateL2Config(context.TODO(), &mockClient, true)
assert.NoError(t, err)
}

func TestCheckL2ChainID(t *testing.T) {
config := randConfig()
config.L2ChainID = big.NewInt(100)
Expand Down

0 comments on commit 2929bbf

Please sign in to comment.