From e8f8bcbf5a9a235e55f5d40ebafcf9abd42d5044 Mon Sep 17 00:00:00 2001 From: Matthew Slipper Date: Tue, 22 Oct 2024 11:04:12 -0600 Subject: [PATCH 1/3] op-deployer: Add deploy config inspect command --- .../pkg/deployer/inspect/deploy_config.go | 42 +++++++++++++++++++ op-deployer/pkg/deployer/inspect/flags.go | 8 ++++ .../pkg/deployer/state/deploy_config.go | 23 ++++++---- 3 files changed, 66 insertions(+), 7 deletions(-) create mode 100644 op-deployer/pkg/deployer/inspect/deploy_config.go diff --git a/op-deployer/pkg/deployer/inspect/deploy_config.go b/op-deployer/pkg/deployer/inspect/deploy_config.go new file mode 100644 index 000000000000..04f771f1a156 --- /dev/null +++ b/op-deployer/pkg/deployer/inspect/deploy_config.go @@ -0,0 +1,42 @@ +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 := jsonutil.WriteJSON(config, ioutil.ToStdOutOrFileOrNoop(cliCfg.Outfile, 0o666)); err != nil { + return fmt.Errorf("failed to write deploy config: %w", err) + } + + return nil +} diff --git a/op-deployer/pkg/deployer/inspect/flags.go b/op-deployer/pkg/deployer/inspect/flags.go index af10a035d37e..e1ff38e001e8 100644 --- a/op-deployer/pkg/deployer/inspect/flags.go +++ b/op-deployer/pkg/deployer/inspect/flags.go @@ -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: "", + Action: DeployConfigCLI, + Flags: Flags, + }, } type cliConfig struct { diff --git a/op-deployer/pkg/deployer/state/deploy_config.go b/op-deployer/pkg/deployer/state/deploy_config.go index 56cdae93690b..1803e5675892 100644 --- a/op-deployer/pkg/deployer/state/deploy_config.go +++ b/op-deployer/pkg/deployer/state/deploy_config.go @@ -3,13 +3,12 @@ package state import ( "encoding/json" "fmt" - "math/big" - - "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/rpc" + "math/big" "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 +100,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{ From 73a8942106879b4e59484e0493e0ce7341985358 Mon Sep 17 00:00:00 2001 From: Matthew Slipper Date: Tue, 22 Oct 2024 11:05:36 -0600 Subject: [PATCH 2/3] goimports --- op-deployer/pkg/deployer/inspect/deploy_config.go | 1 + op-deployer/pkg/deployer/state/deploy_config.go | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/op-deployer/pkg/deployer/inspect/deploy_config.go b/op-deployer/pkg/deployer/inspect/deploy_config.go index 04f771f1a156..c9a810ab9969 100644 --- a/op-deployer/pkg/deployer/inspect/deploy_config.go +++ b/op-deployer/pkg/deployer/inspect/deploy_config.go @@ -2,6 +2,7 @@ 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" diff --git a/op-deployer/pkg/deployer/state/deploy_config.go b/op-deployer/pkg/deployer/state/deploy_config.go index 1803e5675892..2bc8307ab9d8 100644 --- a/op-deployer/pkg/deployer/state/deploy_config.go +++ b/op-deployer/pkg/deployer/state/deploy_config.go @@ -3,9 +3,10 @@ package state import ( "encoding/json" "fmt" - "github.com/ethereum/go-ethereum/rpc" "math/big" + "github.com/ethereum/go-ethereum/rpc" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/log" From fb28728d2fb6982338c48ea27ad559b769080665 Mon Sep 17 00:00:00 2001 From: Matthew Slipper Date: Tue, 22 Oct 2024 11:28:49 -0600 Subject: [PATCH 3/3] error check --- op-deployer/pkg/deployer/inspect/deploy_config.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/op-deployer/pkg/deployer/inspect/deploy_config.go b/op-deployer/pkg/deployer/inspect/deploy_config.go index c9a810ab9969..ead006c7d622 100644 --- a/op-deployer/pkg/deployer/inspect/deploy_config.go +++ b/op-deployer/pkg/deployer/inspect/deploy_config.go @@ -35,6 +35,9 @@ func DeployConfigCLI(cliCtx *cli.Context) error { } 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) }