Commit 2df8ab61 authored by Mark Tyneway's avatar Mark Tyneway

op-chain-ops: better deploy config validation

Ensure that the `DeployConfig.Check` function checks for
the existence of the `L1StartingBlockTag`. This check was
previously being done outside of the `Check` function.
Also remove a check for the L2 genesis gas limit being
non zero since this is being done inside of `Check`.
Also add some better error messages in the case of bad
deploy config parsing.
parent 509df58e
...@@ -109,6 +109,9 @@ type DeployConfig struct { ...@@ -109,6 +109,9 @@ type DeployConfig struct {
// 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 {
return fmt.Errorf("%w: L2StartingBlockTag 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)
} }
...@@ -328,7 +331,7 @@ func NewDeployConfig(path string) (*DeployConfig, error) { ...@@ -328,7 +331,7 @@ func NewDeployConfig(path string) (*DeployConfig, error) {
var config DeployConfig var config DeployConfig
if err := json.Unmarshal(file, &config); err != nil { if err := json.Unmarshal(file, &config); err != nil {
return nil, err return nil, fmt.Errorf("cannot unmarshal deploy config: %w", err)
} }
return &config, nil return &config, nil
......
...@@ -3,7 +3,6 @@ package genesis ...@@ -3,7 +3,6 @@ package genesis
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"errors"
"fmt" "fmt"
"math/big" "math/big"
"os" "os"
...@@ -114,16 +113,24 @@ var Subcommands = cli.Commands{ ...@@ -114,16 +113,24 @@ var Subcommands = cli.Commands{
return err return err
} }
if config.L1StartingBlockTag == nil { depPath, network := filepath.Split(ctx.String("deployment-dir"))
return errors.New("must specify a starting block tag in genesis") hh, err := hardhat.New(network, nil, []string{depPath})
if err != nil {
return err
}
// Read the appropriate deployment addresses from disk
if err := config.GetDeployedAddresses(hh); err != nil {
return err
} }
if config.L2GenesisBlockGasLimit == 0 { // TODO: this is a hotfix, need to set default values in more clean way + sanity check the config // Sanity check the config
config.L2GenesisBlockGasLimit = 15_000_000 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 {
return err return fmt.Errorf("cannot dial %s: %w", ctx.String("l1-rpc"), err)
} }
var l1StartBlock *types.Block var l1StartBlock *types.Block
...@@ -136,20 +143,6 @@ var Subcommands = cli.Commands{ ...@@ -136,20 +143,6 @@ var Subcommands = cli.Commands{
return fmt.Errorf("error getting l1 start block: %w", err) return fmt.Errorf("error getting l1 start block: %w", err)
} }
depPath, network := filepath.Split(ctx.String("deployment-dir"))
hh, err := hardhat.New(network, nil, []string{depPath})
if err != nil {
return err
}
// Read the appropriate deployment addresses from disk
if err := config.GetDeployedAddresses(hh); err != nil {
return err
}
// Sanity check the config
if err := config.Check(); err != nil {
return err
}
// Build the developer L2 genesis block // Build the developer L2 genesis block
l2Genesis, err := genesis.BuildL2DeveloperGenesis(config, l1StartBlock) l2Genesis, err := genesis.BuildL2DeveloperGenesis(config, l1StartBlock)
if err != nil { if err != nil {
......
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