Commit c9e3ad6e authored by Matthew Slipper's avatar Matthew Slipper Committed by GitHub

op-deployer: Add deploy config inspect command (#12570)

* op-deployer: Add deploy config inspect command

* goimports

* error check
parent 3b83710f
package inspect
import (
"fmt"
"github.com/ethereum-optimism/optimism/op-deployer/pkg/deployer/pipeline"
"github.com/ethereum-optimism/optimism/op-deployer/pkg/deployer/state"
"github.com/ethereum-optimism/optimism/op-service/ioutil"
"github.com/ethereum-optimism/optimism/op-service/jsonutil"
"github.com/urfave/cli/v2"
)
func DeployConfigCLI(cliCtx *cli.Context) error {
cliCfg, err := readConfig(cliCtx)
if err != nil {
return err
}
globalState, err := pipeline.ReadState(cliCfg.Workdir)
if err != nil {
return fmt.Errorf("failed to read intent: %w", err)
}
chainState, err := globalState.Chain(cliCfg.ChainID)
if err != nil {
return fmt.Errorf("failed to find chain state: %w", err)
}
intent := globalState.AppliedIntent
if intent == nil {
return fmt.Errorf("can only run this command following a full apply")
}
chainIntent, err := intent.Chain(cliCfg.ChainID)
if err != nil {
return fmt.Errorf("failed to find chain intent: %w", err)
}
config, err := state.CombineDeployConfig(intent, chainIntent, globalState, chainState)
if err != nil {
return fmt.Errorf("failed to generate deploy config: %w", err)
}
if err := jsonutil.WriteJSON(config, ioutil.ToStdOutOrFileOrNoop(cliCfg.Outfile, 0o666)); err != nil {
return fmt.Errorf("failed to write deploy config: %w", err)
}
return nil
}
......@@ -53,6 +53,14 @@ var Commands = []*cli.Command{
Action: RollupCLI,
Flags: Flags,
},
{
Name: "deploy-config",
Usage: "outputs the deploy config for an L2 chain",
Args: true,
ArgsUsage: "<l2-chain-id>",
Action: DeployConfigCLI,
Flags: Flags,
},
}
type cliConfig struct {
......
......@@ -5,11 +5,11 @@ import (
"fmt"
"math/big"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/rpc"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum-optimism/optimism/op-chain-ops/genesis"
"github.com/ethereum/go-ethereum/common/hexutil"
......@@ -101,14 +101,24 @@ func CombineDeployConfig(intent *Intent, chainIntent *ChainIntent, state *State,
},
}
if chainState.StartBlock == nil {
// These are dummy variables - see below for rationale.
num := rpc.LatestBlockNumber
cfg.L1StartingBlockTag = &genesis.MarshalableRPCBlockNumberOrHash{
BlockNumber: &num,
}
} else {
startHash := chainState.StartBlock.Hash()
cfg.L1StartingBlockTag = &genesis.MarshalableRPCBlockNumberOrHash{
BlockHash: &startHash,
}
}
// The below dummy variables are set in order to allow the deploy
// config to pass validation. The validation checks are useful to
// ensure that the L2 is properly configured. They are not used by
// the L2 genesis script itself.
num := rpc.LatestBlockNumber
cfg.L1StartingBlockTag = &genesis.MarshalableRPCBlockNumberOrHash{
BlockNumber: &num,
}
cfg.L1BlockTime = 12
dummyAddr := common.Address{19: 0x01}
cfg.SuperchainL1DeployConfig = genesis.SuperchainL1DeployConfig{
......
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