Commit a3416a2f authored by Mark Tyneway's avatar Mark Tyneway Committed by GitHub

Merge pull request #6456 from ethereum-optimism/fix/genesis-script

op-node: safer genesis script
parents fff05ea7 a8a4b229
...@@ -3,6 +3,7 @@ package genesis ...@@ -3,6 +3,7 @@ package genesis
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"errors"
"fmt" "fmt"
"math/big" "math/big"
"os" "os"
...@@ -12,6 +13,7 @@ import ( ...@@ -12,6 +13,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"
...@@ -91,11 +93,11 @@ var Subcommands = cli.Commands{ ...@@ -91,11 +93,11 @@ var Subcommands = cli.Commands{
}, },
&cli.StringFlag{ &cli.StringFlag{
Name: "deploy-config", Name: "deploy-config",
Usage: "Path to hardhat deploy config file", Usage: "Path to deploy config file",
}, },
&cli.StringFlag{ &cli.StringFlag{
Name: "deployment-dir", Name: "deployment-dir",
Usage: "Path to deployment directory", Usage: "Path to network deployment directory",
}, },
&cli.StringFlag{ &cli.StringFlag{
Name: "outfile.l2", Name: "outfile.l2",
...@@ -108,12 +110,19 @@ var Subcommands = cli.Commands{ ...@@ -108,12 +110,19 @@ 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
} }
depPath, network := filepath.Split(ctx.String("deployment-dir")) deployDir := ctx.String("deployment-dir")
if deployDir == "" {
return errors.New("Must specify --deployment-dir")
}
log.Info("Deployment directory", "path", deployDir)
depPath, network := filepath.Split(deployDir)
hh, err := hardhat.New(network, nil, []string{depPath}) hh, err := hardhat.New(network, nil, []string{depPath})
if err != nil { if err != nil {
return err return err
...@@ -134,7 +143,9 @@ var Subcommands = cli.Commands{ ...@@ -134,7 +143,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 +153,7 @@ var Subcommands = cli.Commands{ ...@@ -142,6 +153,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