Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

op-node: safer genesis script #6456

Merged
merged 4 commits into from
Jul 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions op-node/cmd/genesis/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package genesis
import (
"context"
"encoding/json"
"errors"
"fmt"
"math/big"
"os"
Expand All @@ -12,6 +13,7 @@ import (

"github.com/ethereum/go-ethereum/core/types"
"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-chain-ops/genesis"
Expand Down Expand Up @@ -91,11 +93,11 @@ var Subcommands = cli.Commands{
},
&cli.StringFlag{
Name: "deploy-config",
Usage: "Path to hardhat deploy config file",
Usage: "Path to deploy config file",
},
&cli.StringFlag{
Name: "deployment-dir",
Usage: "Path to deployment directory",
Usage: "Path to network deployment directory",
},
&cli.StringFlag{
Name: "outfile.l2",
Expand All @@ -108,12 +110,19 @@ var Subcommands = cli.Commands{
},
Action: func(ctx *cli.Context) error {
deployConfig := ctx.String("deploy-config")
log.Info("Deploy config", "path", deployConfig)
config, err := genesis.NewDeployConfig(deployConfig)
if err != nil {
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})
if err != nil {
return err
Expand All @@ -134,14 +143,17 @@ var Subcommands = cli.Commands{
}

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)
} else if config.L1StartingBlockTag.BlockNumber != nil {
l1StartBlock, err = client.BlockByNumber(context.Background(), big.NewInt(config.L1StartingBlockTag.BlockNumber.Int64()))
}
if err != nil {
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
l2Genesis, err := genesis.BuildL2Genesis(config, l1StartBlock)
Expand Down