Commit 82528f38 authored by Mark Tyneway's avatar Mark Tyneway

op-node: fix small bugs in genesis script

parent ae148960
...@@ -188,7 +188,7 @@ func (d *DeployConfig) Copy() *DeployConfig { ...@@ -188,7 +188,7 @@ func (d *DeployConfig) Copy() *DeployConfig {
// Check will ensure that the config is sane and return an error when it is not // Check will ensure that the config is sane and return an error when it is not
func (d *DeployConfig) Check() error { func (d *DeployConfig) Check() error {
if d.L1StartingBlockTag == nil { if d.L1StartingBlockTag == nil {
return fmt.Errorf("%w: L2StartingBlockTag cannot be nil", ErrInvalidDeployConfig) return fmt.Errorf("%w: L1StartingBlockTag cannot be nil", ErrInvalidDeployConfig)
} }
if d.L1ChainID == 0 { if d.L1ChainID == 0 {
return fmt.Errorf("%w: L1ChainID cannot be 0", ErrInvalidDeployConfig) return fmt.Errorf("%w: L1ChainID cannot be 0", ErrInvalidDeployConfig)
......
...@@ -14,6 +14,7 @@ import ( ...@@ -14,6 +14,7 @@ import (
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethclient" "github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/rpc"
"github.com/ethereum-optimism/optimism/op-bindings/hardhat" "github.com/ethereum-optimism/optimism/op-bindings/hardhat"
"github.com/ethereum-optimism/optimism/op-chain-ops/genesis" "github.com/ethereum-optimism/optimism/op-chain-ops/genesis"
...@@ -132,10 +133,6 @@ var Subcommands = cli.Commands{ ...@@ -132,10 +133,6 @@ var Subcommands = cli.Commands{
if err := config.GetDeployedAddresses(hh); err != nil { if err := config.GetDeployedAddresses(hh); err != nil {
return err return err
} }
// Sanity check the config
if err := config.Check(); err != nil {
return err
}
client, err := ethclient.Dial(ctx.String("l1-rpc")) client, err := ethclient.Dial(ctx.String("l1-rpc"))
if err != nil { if err != nil {
...@@ -145,6 +142,8 @@ var Subcommands = cli.Commands{ ...@@ -145,6 +142,8 @@ var Subcommands = cli.Commands{
var l1StartBlock *types.Block var l1StartBlock *types.Block
if config.L1StartingBlockTag == nil { if config.L1StartingBlockTag == nil {
l1StartBlock, err = client.BlockByNumber(context.Background(), nil) l1StartBlock, err = client.BlockByNumber(context.Background(), nil)
tag := rpc.BlockNumberOrHashWithHash(l1StartBlock.Hash(), true)
config.L1StartingBlockTag = (*genesis.MarshalableRPCBlockNumberOrHash)(&tag)
} else if config.L1StartingBlockTag.BlockHash != nil { } else if config.L1StartingBlockTag.BlockHash != nil {
l1StartBlock, err = client.BlockByHash(context.Background(), *config.L1StartingBlockTag.BlockHash) l1StartBlock, err = client.BlockByHash(context.Background(), *config.L1StartingBlockTag.BlockHash)
} else if config.L1StartingBlockTag.BlockNumber != nil { } else if config.L1StartingBlockTag.BlockNumber != nil {
...@@ -153,6 +152,13 @@ var Subcommands = cli.Commands{ ...@@ -153,6 +152,13 @@ var Subcommands = cli.Commands{
if err != nil { if err != nil {
return fmt.Errorf("error getting l1 start block: %w", err) return fmt.Errorf("error getting l1 start block: %w", err)
} }
// Sanity check the config. Do this after filling in the L1StartingBlockTag
// if it is not defined.
if err := config.Check(); err != nil {
return err
}
log.Info("Using L1 Start Block", "number", l1StartBlock.Number(), "hash", l1StartBlock.Hash().Hex()) log.Info("Using L1 Start Block", "number", l1StartBlock.Number(), "hash", l1StartBlock.Hash().Hex())
// Build the developer L2 genesis block // Build the developer L2 genesis block
......
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