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-deployer: Add deploy config inspect command #12570

Merged
merged 3 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
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
46 changes: 46 additions & 0 deletions op-deployer/pkg/deployer/inspect/deploy_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
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
}
8 changes: 8 additions & 0 deletions op-deployer/pkg/deployer/inspect/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
20 changes: 15 additions & 5 deletions op-deployer/pkg/deployer/state/deploy_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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{
Expand Down