Skip to content

Commit

Permalink
chore(op-deployer): Fork in asterisc + dispute game deployment jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
clabby committed Dec 4, 2024
1 parent 4ce84f1 commit 9697726
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 43 deletions.
12 changes: 12 additions & 0 deletions op-deployer/pkg/deployer/bootstrap/asterisc.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,18 @@ func Asterisc(ctx context.Context, cfg AsteriscConfig) error {
return fmt.Errorf("failed to create script host: %w", err)
}

latest, err := l1Client.HeaderByNumber(ctx, nil)
if err != nil {
return fmt.Errorf("failed to get latest block: %w", err)
}

if _, err := l1Host.CreateSelectFork(
script.ForkWithURLOrAlias("main"),
script.ForkWithBlockNumberU256(latest.Number),
); err != nil {
return fmt.Errorf("failed to select fork: %w", err)
}

dgo, err := opcm.DeployAsterisc(
l1Host,
opcm.DeployAsteriscInput{
Expand Down
27 changes: 24 additions & 3 deletions op-deployer/pkg/deployer/bootstrap/delayed_weth.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"math/big"
"strings"

"github.com/ethereum-optimism/optimism/op-chain-ops/script"
"github.com/ethereum-optimism/optimism/op-chain-ops/script/forking"
artifacts2 "github.com/ethereum-optimism/optimism/op-deployer/pkg/deployer/artifacts"

"github.com/ethereum-optimism/optimism/op-deployer/pkg/env"
Expand All @@ -26,6 +28,7 @@ import (
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/rpc"
"github.com/urfave/cli/v2"
)

Expand Down Expand Up @@ -158,21 +161,39 @@ func DelayedWETH(ctx context.Context, cfg DelayedWETHConfig) error {
return fmt.Errorf("failed to create broadcaster: %w", err)
}

nonce, err := l1Client.NonceAt(ctx, chainDeployer, nil)
l1RPC, err := rpc.Dial(cfg.L1RPCUrl)
if err != nil {
return fmt.Errorf("failed to get starting nonce: %w", err)
return fmt.Errorf("failed to connect to L1 RPC: %w", err)
}

host, err := env.DefaultScriptHost(
bcaster,
lgr,
chainDeployer,
artifactsFS,
script.WithForkHook(func(cfg *script.ForkConfig) (forking.ForkSource, error) {
src, err := forking.RPCSourceByNumber(cfg.URLOrAlias, l1RPC, *cfg.BlockNumber)
if err != nil {
return nil, fmt.Errorf("failed to create RPC fork source: %w", err)
}
return forking.Cache(src), nil
}),
)
if err != nil {
return fmt.Errorf("failed to create script host: %w", err)
}
host.SetNonce(chainDeployer, nonce)

latest, err := l1Client.HeaderByNumber(ctx, nil)
if err != nil {
return fmt.Errorf("failed to get latest block: %w", err)
}

if _, err := host.CreateSelectFork(
script.ForkWithURLOrAlias("main"),
script.ForkWithBlockNumberU256(latest.Number),
); err != nil {
return fmt.Errorf("failed to select fork: %w", err)
}

var release string
if cfg.ArtifactsLocator.IsTag() {
Expand Down
67 changes: 27 additions & 40 deletions op-deployer/pkg/deployer/bootstrap/dispute_game.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import (
"fmt"
"strings"

"github.com/ethereum-optimism/optimism/op-chain-ops/script"
"github.com/ethereum-optimism/optimism/op-chain-ops/script/forking"
artifacts2 "github.com/ethereum-optimism/optimism/op-deployer/pkg/deployer/artifacts"
"github.com/ethereum-optimism/optimism/packages/contracts-bedrock/snapshots"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/rpc"

"github.com/ethereum-optimism/optimism/op-deployer/pkg/env"

Expand Down Expand Up @@ -149,6 +151,10 @@ func DisputeGame(ctx context.Context, cfg DisputeGameConfig) error {
if err != nil {
return 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)
}

chainID, err := l1Client.ChainID(ctx)
if err != nil {
Expand All @@ -175,21 +181,34 @@ func DisputeGame(ctx context.Context, cfg DisputeGameConfig) error {
return fmt.Errorf("failed to create broadcaster: %w", err)
}

nonce, err := l1Client.NonceAt(ctx, chainDeployer, nil)
if err != nil {
return fmt.Errorf("failed to get starting nonce: %w", err)
}

host, err := env.DefaultScriptHost(
bcaster,
lgr,
chainDeployer,
artifactsFS,
script.WithForkHook(func(forkCfg *script.ForkConfig) (forking.ForkSource, error) {
src, err := forking.RPCSourceByNumber(forkCfg.URLOrAlias, l1Rpc, *forkCfg.BlockNumber)
if err != nil {
return nil, fmt.Errorf("failed to create RPC fork source: %w", err)
}
return forking.Cache(src), nil
}),
)
if err != nil {
return fmt.Errorf("failed to create script host: %w", err)
return fmt.Errorf("failed to create L1 script host: %w", err)
}

latest, err := l1Client.HeaderByNumber(ctx, nil)
if err != nil {
return fmt.Errorf("failed to get latest block: %w", err)
}

if _, err := host.CreateSelectFork(
script.ForkWithURLOrAlias("main"),
script.ForkWithBlockNumberU256(latest.Number),
); err != nil {
return fmt.Errorf("failed to select fork: %w", err)
}
host.SetNonce(chainDeployer, nonce)

var release string
if cfg.ArtifactsLocator.IsTag() {
Expand All @@ -198,27 +217,7 @@ func DisputeGame(ctx context.Context, cfg DisputeGameConfig) error {
release = "dev"
}

// We need to etch the VM and PreimageOracle addresses so that they have nonzero code
// and the checks in the FaultDisputeGame constructor pass.
oracleAddr, err := loadOracleAddr(ctx, l1Client, cfg.Vm)
if err != nil {
return err
}
addresses := []common.Address{
cfg.Vm,
oracleAddr,
}
for _, addr := range addresses {
code, err := l1Client.CodeAt(ctx, addr, nil)
if err != nil {
return fmt.Errorf("failed to get code for %v: %w", addr, err)
}
host.ImportAccount(addr, types.Account{
Code: code,
})
}
lgr.Info("deploying dispute game", "release", release)

dgo, err := opcm.DeployDisputeGame(
host,
opcm.DeployDisputeGameInput{
Expand Down Expand Up @@ -254,15 +253,3 @@ func DisputeGame(ctx context.Context, cfg DisputeGameConfig) error {
}
return nil
}

func loadOracleAddr(ctx context.Context, l1Client *ethclient.Client, vmAddr common.Address) (common.Address, error) {
callData, err := snapshots.LoadMIPSABI().Pack("oracle")
if err != nil {
return common.Address{}, fmt.Errorf("failed to create vm.oracle() calldata: %w", err)
}
result, err := l1Client.CallContract(ctx, ethereum.CallMsg{Data: callData, To: &vmAddr}, nil)
if err != nil {
return common.Address{}, fmt.Errorf("failed to call vm.oracle(): %w", err)
}
return common.BytesToAddress(result), nil
}

0 comments on commit 9697726

Please sign in to comment.