Skip to content

Commit

Permalink
op-deployer: Support output files in bootstrap (ethereum-optimism#13302)
Browse files Browse the repository at this point in the history
* op-deployer: Support output files in bootstrap

* lint
  • Loading branch information
mslipper authored Dec 6, 2024
1 parent a2e7d85 commit d6106dd
Show file tree
Hide file tree
Showing 8 changed files with 137 additions and 89 deletions.
40 changes: 23 additions & 17 deletions op-deployer/pkg/deployer/bootstrap/asterisc.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ func AsteriscCLI(cliCtx *cli.Context) error {
l := oplog.NewLogger(oplog.AppOut(cliCtx), logCfg)
oplog.SetGlobalLogHandler(l.Handler())

outfile := cliCtx.String(OutfileFlagName)
l1RPCUrl := cliCtx.String(deployer.L1RPCURLFlagName)
privateKey := cliCtx.String(deployer.PrivateKeyFlagName)
artifactsURLStr := cliCtx.String(ArtifactsLocatorFlagName)
Expand All @@ -85,18 +86,27 @@ func AsteriscCLI(cliCtx *cli.Context) error {

ctx := ctxinterrupt.WithCancelOnInterrupt(cliCtx.Context)

return Asterisc(ctx, AsteriscConfig{
dao, err := Asterisc(ctx, AsteriscConfig{
L1RPCUrl: l1RPCUrl,
PrivateKey: privateKey,
Logger: l,
ArtifactsLocator: artifactsLocator,
PreimageOracle: preimageOracle,
})
if err != nil {
return fmt.Errorf("failed to deploy Asterisc: %w", err)
}

if err := jsonutil.WriteJSON(dao, ioutil.ToStdOutOrFileOrNoop(outfile, 0o755)); err != nil {
return fmt.Errorf("failed to write output: %w", err)
}
return nil
}

func Asterisc(ctx context.Context, cfg AsteriscConfig) error {
func Asterisc(ctx context.Context, cfg AsteriscConfig) (opcm.DeployAsteriscOutput, error) {
var dao opcm.DeployAsteriscOutput
if err := cfg.Check(); err != nil {
return fmt.Errorf("invalid config for Asterisc: %w", err)
return dao, fmt.Errorf("invalid config for Asterisc: %w", err)
}

lgr := cfg.Logger
Expand All @@ -106,7 +116,7 @@ func Asterisc(ctx context.Context, cfg AsteriscConfig) error {

artifactsFS, cleanup, err := artifacts.Download(ctx, cfg.ArtifactsLocator, progressor)
if err != nil {
return fmt.Errorf("failed to download artifacts: %w", err)
return dao, fmt.Errorf("failed to download artifacts: %w", err)
}
defer func() {
if err := cleanup(); err != nil {
Expand All @@ -116,12 +126,12 @@ func Asterisc(ctx context.Context, cfg AsteriscConfig) error {

l1Client, err := ethclient.Dial(cfg.L1RPCUrl)
if err != nil {
return fmt.Errorf("failed to connect to L1 RPC: %w", err)
return dao, fmt.Errorf("failed to connect to L1 RPC: %w", err)
}

chainID, err := l1Client.ChainID(ctx)
if err != nil {
return fmt.Errorf("failed to get chain ID: %w", err)
return dao, fmt.Errorf("failed to get chain ID: %w", err)
}

signer := opcrypto.SignerFnFromBind(opcrypto.PrivateKeySignerFn(cfg.privateKeyECDSA, chainID))
Expand All @@ -135,12 +145,12 @@ func Asterisc(ctx context.Context, cfg AsteriscConfig) error {
From: chainDeployer,
})
if err != nil {
return fmt.Errorf("failed to create broadcaster: %w", err)
return dao, fmt.Errorf("failed to create broadcaster: %w", err)
}

l1RPC, err := rpc.Dial(cfg.L1RPCUrl)
if err != nil {
return fmt.Errorf("failed to connect to L1 RPC: %w", err)
return dao, fmt.Errorf("failed to connect to L1 RPC: %w", err)
}

l1Host, err := env.DefaultForkedScriptHost(
Expand All @@ -152,27 +162,23 @@ func Asterisc(ctx context.Context, cfg AsteriscConfig) error {
l1RPC,
)
if err != nil {
return fmt.Errorf("failed to create script host: %w", err)
return dao, fmt.Errorf("failed to create script host: %w", err)
}

dgo, err := opcm.DeployAsterisc(
dao, err = opcm.DeployAsterisc(
l1Host,
opcm.DeployAsteriscInput{
PreimageOracle: cfg.PreimageOracle,
},
)
if err != nil {
return fmt.Errorf("error deploying asterisc VM: %w", err)
return dao, fmt.Errorf("error deploying asterisc VM: %w", err)
}

if _, err := bcaster.Broadcast(ctx); err != nil {
return fmt.Errorf("failed to broadcast: %w", err)
return dao, fmt.Errorf("failed to broadcast: %w", err)
}

lgr.Info("deployed asterisc VM")

if err := jsonutil.WriteJSON(dgo, ioutil.ToStdOut()); err != nil {
return fmt.Errorf("failed to write output: %w", err)
}
return nil
return dao, nil
}
46 changes: 26 additions & 20 deletions op-deployer/pkg/deployer/bootstrap/delayed_weth.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,23 @@ func DelayedWETHCLI(cliCtx *cli.Context) error {
l := oplog.NewLogger(oplog.AppOut(cliCtx), logCfg)
oplog.SetGlobalLogHandler(l.Handler())

outfile := cliCtx.String(OutfileFlagName)
config, err := NewDelayedWETHConfigFromClI(cliCtx, l)
if err != nil {
return err
}

ctx := ctxinterrupt.WithCancelOnInterrupt(cliCtx.Context)

return DelayedWETH(ctx, config)
dwo, err := DelayedWETH(ctx, config)
if err != nil {
return fmt.Errorf("failed to deploy DelayedWETH: %w", err)
}

if err := jsonutil.WriteJSON(dwo, ioutil.ToStdOutOrFileOrNoop(outfile, 0o755)); err != nil {
return fmt.Errorf("failed to write output: %w", err)
}
return nil
}

func NewDelayedWETHConfigFromClI(cliCtx *cli.Context, l log.Logger) (DelayedWETHConfig, error) {
Expand All @@ -100,9 +109,10 @@ func NewDelayedWETHConfigFromClI(cliCtx *cli.Context, l log.Logger) (DelayedWETH
return config, nil
}

func DelayedWETH(ctx context.Context, cfg DelayedWETHConfig) error {
func DelayedWETH(ctx context.Context, cfg DelayedWETHConfig) (opcm.DeployDelayedWETHOutput, error) {
var dwo opcm.DeployDelayedWETHOutput
if err := cfg.Check(); err != nil {
return fmt.Errorf("invalid config for DelayedWETH: %w", err)
return dwo, fmt.Errorf("invalid config for DelayedWETH: %w", err)
}

lgr := cfg.Logger
Expand All @@ -112,7 +122,7 @@ func DelayedWETH(ctx context.Context, cfg DelayedWETHConfig) error {

artifactsFS, cleanup, err := artifacts2.Download(ctx, cfg.ArtifactsLocator, progressor)
if err != nil {
return fmt.Errorf("failed to download artifacts: %w", err)
return dwo, fmt.Errorf("failed to download artifacts: %w", err)
}
defer func() {
if err := cleanup(); err != nil {
Expand All @@ -122,26 +132,26 @@ func DelayedWETH(ctx context.Context, cfg DelayedWETHConfig) error {

l1Client, err := ethclient.Dial(cfg.L1RPCUrl)
if err != nil {
return fmt.Errorf("failed to connect to L1 RPC: %w", err)
return dwo, fmt.Errorf("failed to connect to L1 RPC: %w", err)
}

chainID, err := l1Client.ChainID(ctx)
if err != nil {
return fmt.Errorf("failed to get chain ID: %w", err)
return dwo, fmt.Errorf("failed to get chain ID: %w", err)
}
chainIDU64 := chainID.Uint64()

superCfg, err := standard.SuperchainFor(chainIDU64)
if err != nil {
return fmt.Errorf("error getting superchain config: %w", err)
return dwo, fmt.Errorf("error getting superchain config: %w", err)
}
proxyAdmin, err := standard.ManagerOwnerAddrFor(chainIDU64)
if err != nil {
return fmt.Errorf("error getting superchain proxy admin: %w", err)
return dwo, fmt.Errorf("error getting superchain proxy admin: %w", err)
}
delayedWethOwner, err := standard.SystemOwnerAddrFor(chainIDU64)
if err != nil {
return fmt.Errorf("error getting superchain system owner: %w", err)
return dwo, fmt.Errorf("error getting superchain system owner: %w", err)
}

signer := opcrypto.SignerFnFromBind(opcrypto.PrivateKeySignerFn(cfg.privateKeyECDSA, chainID))
Expand All @@ -155,12 +165,12 @@ func DelayedWETH(ctx context.Context, cfg DelayedWETHConfig) error {
From: chainDeployer,
})
if err != nil {
return fmt.Errorf("failed to create broadcaster: %w", err)
return dwo, fmt.Errorf("failed to create broadcaster: %w", err)
}

l1RPC, err := rpc.Dial(cfg.L1RPCUrl)
if err != nil {
return fmt.Errorf("failed to connect to L1 RPC: %w", err)
return dwo, fmt.Errorf("failed to connect to L1 RPC: %w", err)
}

host, err := env.DefaultForkedScriptHost(
Expand All @@ -172,7 +182,7 @@ func DelayedWETH(ctx context.Context, cfg DelayedWETHConfig) error {
l1RPC,
)
if err != nil {
return fmt.Errorf("failed to create script host: %w", err)
return dwo, fmt.Errorf("failed to create script host: %w", err)
}

var release string
Expand All @@ -186,7 +196,7 @@ func DelayedWETH(ctx context.Context, cfg DelayedWETHConfig) error {

superchainConfigAddr := common.Address(*superCfg.Config.SuperchainConfigAddr)

dwo, err := opcm.DeployDelayedWETH(
dwo, err = opcm.DeployDelayedWETH(
host,
opcm.DeployDelayedWETHInput{
Release: release,
Expand All @@ -198,17 +208,13 @@ func DelayedWETH(ctx context.Context, cfg DelayedWETHConfig) error {
},
)
if err != nil {
return fmt.Errorf("error deploying DelayedWETH: %w", err)
return dwo, fmt.Errorf("error deploying DelayedWETH: %w", err)
}

if _, err := bcaster.Broadcast(ctx); err != nil {
return fmt.Errorf("failed to broadcast: %w", err)
return dwo, fmt.Errorf("failed to broadcast: %w", err)
}

lgr.Info("deployed DelayedWETH")

if err := jsonutil.WriteJSON(dwo, ioutil.ToStdOut()); err != nil {
return fmt.Errorf("failed to write output: %w", err)
}
return nil
return dwo, nil
}
44 changes: 26 additions & 18 deletions op-deployer/pkg/deployer/bootstrap/dispute_game.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,22 @@ func DisputeGameCLI(cliCtx *cli.Context) error {
l := oplog.NewLogger(oplog.AppOut(cliCtx), logCfg)
oplog.SetGlobalLogHandler(l.Handler())

outfile := cliCtx.String(OutfileFlagName)
cfg, err := NewDisputeGameConfigFromCLI(cliCtx, l)
if err != nil {
return err
}
ctx := ctxinterrupt.WithCancelOnInterrupt(cliCtx.Context)
return DisputeGame(ctx, cfg)
dgo, err := DisputeGame(ctx, cfg)
if err != nil {
return fmt.Errorf("failed to deploy dispute game: %w", err)
}

if err := jsonutil.WriteJSON(dgo, ioutil.ToStdOutOrFileOrNoop(outfile, 0o755)); err != nil {
return fmt.Errorf("failed to write output: %w", err)
}

return nil
}

func NewDisputeGameConfigFromCLI(cliCtx *cli.Context, l log.Logger) (DisputeGameConfig, error) {
Expand Down Expand Up @@ -123,9 +133,10 @@ func NewDisputeGameConfigFromCLI(cliCtx *cli.Context, l log.Logger) (DisputeGame
return cfg, nil
}

func DisputeGame(ctx context.Context, cfg DisputeGameConfig) error {
func DisputeGame(ctx context.Context, cfg DisputeGameConfig) (opcm.DeployDisputeGameOutput, error) {
var dgo opcm.DeployDisputeGameOutput
if err := cfg.Check(); err != nil {
return fmt.Errorf("invalid config for DisputeGame: %w", err)
return dgo, fmt.Errorf("invalid config for DisputeGame: %w", err)
}

lgr := cfg.Logger
Expand All @@ -135,7 +146,7 @@ func DisputeGame(ctx context.Context, cfg DisputeGameConfig) error {

artifactsFS, cleanup, err := artifacts2.Download(ctx, cfg.ArtifactsLocator, progressor)
if err != nil {
return fmt.Errorf("failed to download artifacts: %w", err)
return dgo, fmt.Errorf("failed to download artifacts: %w", err)
}
defer func() {
if err := cleanup(); err != nil {
Expand All @@ -145,22 +156,22 @@ func DisputeGame(ctx context.Context, cfg DisputeGameConfig) error {

l1Client, err := ethclient.Dial(cfg.L1RPCUrl)
if err != nil {
return fmt.Errorf("failed to connect to L1 RPC: %w", err)
return dgo, fmt.Errorf("failed to connect to L1 RPC: %w", err)
}
l1Rpc, err := rpc.Dial(cfg.L1RPCUrl)
if err != nil {
return fmt.Errorf("failed to connect to L1 RPC: %w", err)
return dgo, fmt.Errorf("failed to connect to L1 RPC: %w", err)
}

chainID, err := l1Client.ChainID(ctx)
if err != nil {
return fmt.Errorf("failed to get chain ID: %w", err)
return dgo, fmt.Errorf("failed to get chain ID: %w", err)
}
chainIDU64 := chainID.Uint64()

standardVersionsTOML, err := standard.L1VersionsDataFor(chainIDU64)
if err != nil {
return fmt.Errorf("error getting standard versions TOML: %w", err)
return dgo, fmt.Errorf("error getting standard versions TOML: %w", err)
}

signer := opcrypto.SignerFnFromBind(opcrypto.PrivateKeySignerFn(cfg.privateKeyECDSA, chainID))
Expand All @@ -174,7 +185,7 @@ func DisputeGame(ctx context.Context, cfg DisputeGameConfig) error {
From: chainDeployer,
})
if err != nil {
return fmt.Errorf("failed to create broadcaster: %w", err)
return dgo, fmt.Errorf("failed to create broadcaster: %w", err)
}

host, err := env.DefaultForkedScriptHost(
Expand All @@ -186,7 +197,7 @@ func DisputeGame(ctx context.Context, cfg DisputeGameConfig) error {
l1Rpc,
)
if err != nil {
return fmt.Errorf("failed to create L1 script host: %w", err)
return dgo, fmt.Errorf("failed to create L1 script host: %w", err)
}

var release string
Expand All @@ -197,7 +208,8 @@ func DisputeGame(ctx context.Context, cfg DisputeGameConfig) error {
}

lgr.Info("deploying dispute game", "release", release)
dgo, err := opcm.DeployDisputeGame(

dgo, err = opcm.DeployDisputeGame(
host,
opcm.DeployDisputeGameInput{
Release: release,
Expand All @@ -218,17 +230,13 @@ func DisputeGame(ctx context.Context, cfg DisputeGameConfig) error {
},
)
if err != nil {
return fmt.Errorf("error deploying dispute game: %w", err)
return dgo, fmt.Errorf("error deploying dispute game: %w", err)
}

if _, err := bcaster.Broadcast(ctx); err != nil {
return fmt.Errorf("failed to broadcast: %w", err)
return dgo, fmt.Errorf("failed to broadcast: %w", err)
}

lgr.Info("deployed dispute game")

if err := jsonutil.WriteJSON(dgo, ioutil.ToStdOut()); err != nil {
return fmt.Errorf("failed to write output: %w", err)
}
return nil
return dgo, nil
}
Loading

0 comments on commit d6106dd

Please sign in to comment.