Commit ac6c0e81 authored by Mark Tyneway's avatar Mark Tyneway

op-node: safer genesis script

Updates the `op-node` genesis gen script to prevent `nil` pointer
access accidentally. Run the command like so:

```go
go run op-node/cmd/main.go genesis l2 \
  --deploy-config $PWD/packages/contracts-bedrock/deploy-config/mainnet.json \
  --outfile.l2 l2.json \
  --outfile.rollup rollup.json \
  --l1-rpc $ETH_RPC_URL \
  --deployment-dir $PWD/packages/contracts-bedrock/deployments/mainnet
```

When generating the genesis file, it is ok to leave the
`l1StartingBlockTag` value as undefined, this script will select an
appropriate value and then the value will end up inside of the rollup
config under `.genesis.l1.hash` which can then be backported to
the deploy config to make the script deterministic.
parent 9af277e9
...@@ -12,6 +12,7 @@ import ( ...@@ -12,6 +12,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-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"
...@@ -108,6 +109,7 @@ var Subcommands = cli.Commands{ ...@@ -108,6 +109,7 @@ var Subcommands = cli.Commands{
}, },
Action: func(ctx *cli.Context) error { Action: func(ctx *cli.Context) error {
deployConfig := ctx.String("deploy-config") deployConfig := ctx.String("deploy-config")
log.Info("Deploy config", "path", deployConfig)
config, err := genesis.NewDeployConfig(deployConfig) config, err := genesis.NewDeployConfig(deployConfig)
if err != nil { if err != nil {
return err return err
...@@ -134,7 +136,9 @@ var Subcommands = cli.Commands{ ...@@ -134,7 +136,9 @@ var Subcommands = cli.Commands{
} }
var l1StartBlock *types.Block var l1StartBlock *types.Block
if config.L1StartingBlockTag.BlockHash != nil { if config.L1StartingBlockTag == nil {
l1StartBlock, err = client.BlockByNumber(context.Background(), 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 {
l1StartBlock, err = client.BlockByNumber(context.Background(), big.NewInt(config.L1StartingBlockTag.BlockNumber.Int64())) l1StartBlock, err = client.BlockByNumber(context.Background(), big.NewInt(config.L1StartingBlockTag.BlockNumber.Int64()))
...@@ -142,6 +146,7 @@ var Subcommands = cli.Commands{ ...@@ -142,6 +146,7 @@ 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)
} }
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
l2Genesis, err := genesis.BuildL2Genesis(config, l1StartBlock) l2Genesis, err := genesis.BuildL2Genesis(config, l1StartBlock)
......
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