Commit 857640a7 authored by Adrian Sutton's avatar Adrian Sutton Committed by GitHub

abi_loader: Embed specific ABIs (#10239)

* abi_loader: Embed specific ABIs, panic if they fail to parse

* fix(op-challenger): bond claimer

---------
Co-authored-by: default avatarrefcell <abigger87@gmail.com>
parent 32651b28
...@@ -48,10 +48,7 @@ func ListClaims(ctx *cli.Context) error { ...@@ -48,10 +48,7 @@ func ListClaims(ctx *cli.Context) error {
defer l1Client.Close() defer l1Client.Close()
caller := batching.NewMultiCaller(l1Client.Client(), batching.DefaultBatchSize) caller := batching.NewMultiCaller(l1Client.Client(), batching.DefaultBatchSize)
contract, err := contracts.NewFaultDisputeGameContract(metrics.NoopContractMetrics, gameAddr, caller) contract := contracts.NewFaultDisputeGameContract(metrics.NoopContractMetrics, gameAddr, caller)
if err != nil {
return fmt.Errorf("failed to create dispute game bindings: %w", err)
}
return listClaims(ctx.Context, contract) return listClaims(ctx.Context, contract)
} }
......
...@@ -40,10 +40,7 @@ func ListGames(ctx *cli.Context) error { ...@@ -40,10 +40,7 @@ func ListGames(ctx *cli.Context) error {
defer l1Client.Close() defer l1Client.Close()
caller := batching.NewMultiCaller(l1Client.Client(), batching.DefaultBatchSize) caller := batching.NewMultiCaller(l1Client.Client(), batching.DefaultBatchSize)
contract, err := contracts.NewDisputeGameFactoryContract(metrics.NoopContractMetrics, factoryAddr, caller) contract := contracts.NewDisputeGameFactoryContract(metrics.NoopContractMetrics, factoryAddr, caller)
if err != nil {
return fmt.Errorf("failed to create dispute game bindings: %w", err)
}
head, err := l1Client.HeaderByNumber(ctx.Context, nil) head, err := l1Client.HeaderByNumber(ctx.Context, nil)
if err != nil { if err != nil {
return fmt.Errorf("failed to retrieve current head block: %w", err) return fmt.Errorf("failed to retrieve current head block: %w", err)
...@@ -69,10 +66,7 @@ func listGames(ctx context.Context, caller *batching.MultiCaller, factory *contr ...@@ -69,10 +66,7 @@ func listGames(ctx context.Context, caller *batching.MultiCaller, factory *contr
infos := make([]*gameInfo, len(games)) infos := make([]*gameInfo, len(games))
var wg sync.WaitGroup var wg sync.WaitGroup
for idx, game := range games { for idx, game := range games {
gameContract, err := contracts.NewFaultDisputeGameContract(metrics.NoopContractMetrics, game.Proxy, caller) gameContract := contracts.NewFaultDisputeGameContract(metrics.NoopContractMetrics, game.Proxy, caller)
if err != nil {
return fmt.Errorf("failed to bind game contract at %v: %w", game.Proxy, err)
}
info := gameInfo{GameMetadata: game} info := gameInfo{GameMetadata: game}
infos[idx] = &info infos[idx] = &info
gameProxy := game.Proxy gameProxy := game.Proxy
......
...@@ -14,7 +14,7 @@ import ( ...@@ -14,7 +14,7 @@ import (
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
) )
type ContractCreator[T any] func(contractMetrics.ContractMetricer, common.Address, *batching.MultiCaller) (T, error) type ContractCreator[T any] func(contractMetrics.ContractMetricer, common.Address, *batching.MultiCaller) T
// NewContractWithTxMgr creates a new contract and a transaction manager. // NewContractWithTxMgr creates a new contract and a transaction manager.
func NewContractWithTxMgr[T any](ctx *cli.Context, flagName string, creator ContractCreator[T]) (T, txmgr.TxManager, error) { func NewContractWithTxMgr[T any](ctx *cli.Context, flagName string, creator ContractCreator[T]) (T, txmgr.TxManager, error) {
...@@ -40,10 +40,7 @@ func newContractFromCLI[T any](ctx *cli.Context, flagName string, caller *batchi ...@@ -40,10 +40,7 @@ func newContractFromCLI[T any](ctx *cli.Context, flagName string, caller *batchi
return contract, err return contract, err
} }
created, err := creator(contractMetrics.NoopContractMetrics, gameAddr, caller) created := creator(contractMetrics.NoopContractMetrics, gameAddr, caller)
if err != nil {
return contract, fmt.Errorf("failed to create dispute game bindings: %w", err)
}
return created, nil return created, nil
} }
......
...@@ -62,8 +62,9 @@ func (c *Claimer) claimBond(ctx context.Context, game types.GameMetadata, addr c ...@@ -62,8 +62,9 @@ func (c *Claimer) claimBond(ctx context.Context, game types.GameMetadata, addr c
contract, err := c.contractCreator(game) contract, err := c.contractCreator(game)
if err != nil { if err != nil {
return fmt.Errorf("failed to create bond contract bindings: %w", err) return fmt.Errorf("failed to create bond contract: %w", err)
} }
credit, status, err := contract.GetCredit(ctx, addr) credit, status, err := contract.GetCredit(ctx, addr)
if err != nil { if err != nil {
return fmt.Errorf("failed to get credit: %w", err) return fmt.Errorf("failed to get credit: %w", err)
......
...@@ -27,16 +27,13 @@ type WithdrawalRequest struct { ...@@ -27,16 +27,13 @@ type WithdrawalRequest struct {
Timestamp *big.Int Timestamp *big.Int
} }
func NewDelayedWETHContract(metrics metrics.ContractMetricer, addr common.Address, caller *batching.MultiCaller) (*DelayedWETHContract, error) { func NewDelayedWETHContract(metrics metrics.ContractMetricer, addr common.Address, caller *batching.MultiCaller) *DelayedWETHContract {
contractAbi, err := snapshots.LoadDelayedWETHABI() contractAbi := snapshots.LoadDelayedWETHABI()
if err != nil {
return nil, fmt.Errorf("failed to load delayed weth ABI: %w", err)
}
return &DelayedWETHContract{ return &DelayedWETHContract{
metrics: metrics, metrics: metrics,
multiCaller: caller, multiCaller: caller,
contract: batching.NewBoundContract(contractAbi, addr), contract: batching.NewBoundContract(contractAbi, addr),
}, nil }
} }
// GetWithdrawals returns all withdrawals made from the contract since the given block. // GetWithdrawals returns all withdrawals made from the contract since the given block.
......
...@@ -42,11 +42,9 @@ func TestDelayedWeth_GetWithdrawals(t *testing.T) { ...@@ -42,11 +42,9 @@ func TestDelayedWeth_GetWithdrawals(t *testing.T) {
} }
func setupDelayedWethTest(t *testing.T) (*batchingTest.AbiBasedRpc, *DelayedWETHContract) { func setupDelayedWethTest(t *testing.T) (*batchingTest.AbiBasedRpc, *DelayedWETHContract) {
delayedWethAbi, err := snapshots.LoadDelayedWETHABI() delayedWethAbi := snapshots.LoadDelayedWETHABI()
require.NoError(t, err)
stubRpc := batchingTest.NewAbiBasedRpc(t, delayedWeth, delayedWethAbi) stubRpc := batchingTest.NewAbiBasedRpc(t, delayedWeth, delayedWethAbi)
caller := batching.NewMultiCaller(stubRpc, batching.DefaultBatchSize) caller := batching.NewMultiCaller(stubRpc, batching.DefaultBatchSize)
weth, err := NewDelayedWETHContract(contractMetrics.NoopContractMetrics, delayedWeth, caller) weth := NewDelayedWETHContract(contractMetrics.NoopContractMetrics, delayedWeth, caller)
require.NoError(t, err)
return stubRpc, weth return stubRpc, weth
} }
...@@ -58,17 +58,14 @@ type Proposal struct { ...@@ -58,17 +58,14 @@ type Proposal struct {
OutputRoot common.Hash OutputRoot common.Hash
} }
func NewFaultDisputeGameContract(metrics metrics.ContractMetricer, addr common.Address, caller *batching.MultiCaller) (*FaultDisputeGameContract, error) { func NewFaultDisputeGameContract(metrics metrics.ContractMetricer, addr common.Address, caller *batching.MultiCaller) *FaultDisputeGameContract {
contractAbi, err := snapshots.LoadFaultDisputeGameABI() contractAbi := snapshots.LoadFaultDisputeGameABI()
if err != nil {
return nil, fmt.Errorf("failed to load fault dispute game ABI: %w", err)
}
return &FaultDisputeGameContract{ return &FaultDisputeGameContract{
metrics: metrics, metrics: metrics,
multiCaller: caller, multiCaller: caller,
contract: batching.NewBoundContract(contractAbi, addr), contract: batching.NewBoundContract(contractAbi, addr),
}, nil }
} }
// GetBalance returns the total amount of ETH controlled by this contract. // GetBalance returns the total amount of ETH controlled by this contract.
...@@ -263,7 +260,7 @@ func (f *FaultDisputeGameContract) getDelayedWETH(ctx context.Context) (*Delayed ...@@ -263,7 +260,7 @@ func (f *FaultDisputeGameContract) getDelayedWETH(ctx context.Context) (*Delayed
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to fetch WETH addr: %w", err) return nil, fmt.Errorf("failed to fetch WETH addr: %w", err)
} }
return NewDelayedWETHContract(f.metrics, result.GetAddress(0), f.multiCaller) return NewDelayedWETHContract(f.metrics, result.GetAddress(0), f.multiCaller), nil
} }
func (f *FaultDisputeGameContract) GetOracle(ctx context.Context) (*PreimageOracleContract, error) { func (f *FaultDisputeGameContract) GetOracle(ctx context.Context) (*PreimageOracleContract, error) {
...@@ -377,7 +374,7 @@ func (f *FaultDisputeGameContract) vm(ctx context.Context) (*VMContract, error) ...@@ -377,7 +374,7 @@ func (f *FaultDisputeGameContract) vm(ctx context.Context) (*VMContract, error)
return nil, fmt.Errorf("failed to fetch VM addr: %w", err) return nil, fmt.Errorf("failed to fetch VM addr: %w", err)
} }
vmAddr := result.GetAddress(0) vmAddr := result.GetAddress(0)
return NewVMContract(vmAddr, f.multiCaller) return NewVMContract(vmAddr, f.multiCaller), nil
} }
func (f *FaultDisputeGameContract) AttackTx(parentContractIndex uint64, pivot common.Hash) (txmgr.TxCandidate, error) { func (f *FaultDisputeGameContract) AttackTx(parentContractIndex uint64, pivot common.Hash) (txmgr.TxCandidate, error) {
......
...@@ -481,19 +481,15 @@ func TestFaultDisputeGame_IsResolved(t *testing.T) { ...@@ -481,19 +481,15 @@ func TestFaultDisputeGame_IsResolved(t *testing.T) {
} }
func setupFaultDisputeGameTest(t *testing.T) (*batchingTest.AbiBasedRpc, *FaultDisputeGameContract) { func setupFaultDisputeGameTest(t *testing.T) (*batchingTest.AbiBasedRpc, *FaultDisputeGameContract) {
fdgAbi, err := snapshots.LoadFaultDisputeGameABI() fdgAbi := snapshots.LoadFaultDisputeGameABI()
require.NoError(t, err)
vmAbi, err := snapshots.LoadMIPSABI() vmAbi := snapshots.LoadMIPSABI()
require.NoError(t, err) oracleAbi := snapshots.LoadPreimageOracleABI()
oracleAbi, err := snapshots.LoadPreimageOracleABI()
require.NoError(t, err)
stubRpc := batchingTest.NewAbiBasedRpc(t, fdgAddr, fdgAbi) stubRpc := batchingTest.NewAbiBasedRpc(t, fdgAddr, fdgAbi)
stubRpc.AddContract(vmAddr, vmAbi) stubRpc.AddContract(vmAddr, vmAbi)
stubRpc.AddContract(oracleAddr, oracleAbi) stubRpc.AddContract(oracleAddr, oracleAbi)
caller := batching.NewMultiCaller(stubRpc, batching.DefaultBatchSize) caller := batching.NewMultiCaller(stubRpc, batching.DefaultBatchSize)
game, err := NewFaultDisputeGameContract(contractMetrics.NoopContractMetrics, fdgAddr, caller) game := NewFaultDisputeGameContract(contractMetrics.NoopContractMetrics, fdgAddr, caller)
require.NoError(t, err)
return stubRpc, game return stubRpc, game
} }
...@@ -29,16 +29,13 @@ type DisputeGameFactoryContract struct { ...@@ -29,16 +29,13 @@ type DisputeGameFactoryContract struct {
contract *batching.BoundContract contract *batching.BoundContract
} }
func NewDisputeGameFactoryContract(m metrics.ContractMetricer, addr common.Address, caller *batching.MultiCaller) (*DisputeGameFactoryContract, error) { func NewDisputeGameFactoryContract(m metrics.ContractMetricer, addr common.Address, caller *batching.MultiCaller) *DisputeGameFactoryContract {
factoryAbi, err := snapshots.LoadDisputeGameFactoryABI() factoryAbi := snapshots.LoadDisputeGameFactoryABI()
if err != nil {
return nil, fmt.Errorf("failed to load dispute game factory ABI: %w", err)
}
return &DisputeGameFactoryContract{ return &DisputeGameFactoryContract{
metrics: m, metrics: m,
multiCaller: caller, multiCaller: caller,
contract: batching.NewBoundContract(factoryAbi, addr), contract: batching.NewBoundContract(factoryAbi, addr),
}, nil }
} }
func (f *DisputeGameFactoryContract) GetGameFromParameters(ctx context.Context, traceType uint32, outputRoot common.Hash, l2BlockNum uint64) (common.Address, error) { func (f *DisputeGameFactoryContract) GetGameFromParameters(ctx context.Context, traceType uint32, outputRoot common.Hash, l2BlockNum uint64) (common.Address, error) {
......
...@@ -224,12 +224,10 @@ func TestCreateTx(t *testing.T) { ...@@ -224,12 +224,10 @@ func TestCreateTx(t *testing.T) {
} }
func setupDisputeGameFactoryTest(t *testing.T) (*batchingTest.AbiBasedRpc, *DisputeGameFactoryContract) { func setupDisputeGameFactoryTest(t *testing.T) (*batchingTest.AbiBasedRpc, *DisputeGameFactoryContract) {
fdgAbi, err := snapshots.LoadDisputeGameFactoryABI() fdgAbi := snapshots.LoadDisputeGameFactoryABI()
require.NoError(t, err)
stubRpc := batchingTest.NewAbiBasedRpc(t, factoryAddr, fdgAbi) stubRpc := batchingTest.NewAbiBasedRpc(t, factoryAddr, fdgAbi)
caller := batching.NewMultiCaller(stubRpc, batchSize) caller := batching.NewMultiCaller(stubRpc, batchSize)
factory, err := NewDisputeGameFactoryContract(metrics.NoopContractMetrics, factoryAddr, caller) factory := NewDisputeGameFactoryContract(metrics.NoopContractMetrics, factoryAddr, caller)
require.NoError(t, err)
return stubRpc, factory return stubRpc, factory
} }
...@@ -83,17 +83,14 @@ func toPreimageOracleLeaf(l keccakTypes.Leaf) preimageOracleLeaf { ...@@ -83,17 +83,14 @@ func toPreimageOracleLeaf(l keccakTypes.Leaf) preimageOracleLeaf {
} }
} }
func NewPreimageOracleContract(addr common.Address, caller *batching.MultiCaller) (*PreimageOracleContract, error) { func NewPreimageOracleContract(addr common.Address, caller *batching.MultiCaller) *PreimageOracleContract {
oracleAbi, err := snapshots.LoadPreimageOracleABI() oracleAbi := snapshots.LoadPreimageOracleABI()
if err != nil {
return nil, fmt.Errorf("failed to load preimage oracle ABI: %w", err)
}
return &PreimageOracleContract{ return &PreimageOracleContract{
addr: addr, addr: addr,
multiCaller: caller, multiCaller: caller,
contract: batching.NewBoundContract(oracleAbi, addr), contract: batching.NewBoundContract(oracleAbi, addr),
}, nil }
} }
func (c *PreimageOracleContract) Addr() common.Address { func (c *PreimageOracleContract) Addr() common.Address {
......
...@@ -355,12 +355,10 @@ func setupPreimageOracleTestWithProposals(t *testing.T, block rpcblock.Block) (* ...@@ -355,12 +355,10 @@ func setupPreimageOracleTestWithProposals(t *testing.T, block rpcblock.Block) (*
} }
func setupPreimageOracleTest(t *testing.T) (*batchingTest.AbiBasedRpc, *PreimageOracleContract) { func setupPreimageOracleTest(t *testing.T) (*batchingTest.AbiBasedRpc, *PreimageOracleContract) {
oracleAbi, err := snapshots.LoadPreimageOracleABI() oracleAbi := snapshots.LoadPreimageOracleABI()
require.NoError(t, err)
stubRpc := batchingTest.NewAbiBasedRpc(t, oracleAddr, oracleAbi) stubRpc := batchingTest.NewAbiBasedRpc(t, oracleAddr, oracleAbi)
oracleContract, err := NewPreimageOracleContract(oracleAddr, batching.NewMultiCaller(stubRpc, batching.DefaultBatchSize)) oracleContract := NewPreimageOracleContract(oracleAddr, batching.NewMultiCaller(stubRpc, batching.DefaultBatchSize))
require.NoError(t, err)
return stubRpc, oracleContract return stubRpc, oracleContract
} }
......
...@@ -20,16 +20,13 @@ type VMContract struct { ...@@ -20,16 +20,13 @@ type VMContract struct {
contract *batching.BoundContract contract *batching.BoundContract
} }
func NewVMContract(addr common.Address, caller *batching.MultiCaller) (*VMContract, error) { func NewVMContract(addr common.Address, caller *batching.MultiCaller) *VMContract {
mipsAbi, err := snapshots.LoadMIPSABI() mipsAbi := snapshots.LoadMIPSABI()
if err != nil {
return nil, fmt.Errorf("failed to load VM ABI: %w", err)
}
return &VMContract{ return &VMContract{
multiCaller: caller, multiCaller: caller,
contract: batching.NewBoundContract(mipsAbi, addr), contract: batching.NewBoundContract(mipsAbi, addr),
}, nil }
} }
func (c *VMContract) Oracle(ctx context.Context) (*PreimageOracleContract, error) { func (c *VMContract) Oracle(ctx context.Context) (*PreimageOracleContract, error) {
...@@ -37,5 +34,5 @@ func (c *VMContract) Oracle(ctx context.Context) (*PreimageOracleContract, error ...@@ -37,5 +34,5 @@ func (c *VMContract) Oracle(ctx context.Context) (*PreimageOracleContract, error
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to load oracle address: %w", err) return nil, fmt.Errorf("failed to load oracle address: %w", err)
} }
return NewPreimageOracleContract(results.GetAddress(0), c.multiCaller) return NewPreimageOracleContract(results.GetAddress(0), c.multiCaller), nil
} }
...@@ -15,12 +15,10 @@ import ( ...@@ -15,12 +15,10 @@ import (
) )
func TestVMContract_Oracle(t *testing.T) { func TestVMContract_Oracle(t *testing.T) {
vmAbi, err := snapshots.LoadMIPSABI() vmAbi := snapshots.LoadMIPSABI()
require.NoError(t, err)
stubRpc := batchingTest.NewAbiBasedRpc(t, vmAddr, vmAbi) stubRpc := batchingTest.NewAbiBasedRpc(t, vmAddr, vmAbi)
vmContract, err := NewVMContract(vmAddr, batching.NewMultiCaller(stubRpc, batching.DefaultBatchSize)) vmContract := NewVMContract(vmAddr, batching.NewMultiCaller(stubRpc, batching.DefaultBatchSize))
require.NoError(t, err)
stubRpc.SetResponse(vmAddr, methodOracle, rpcblock.Latest, nil, []interface{}{oracleAddr}) stubRpc.SetResponse(vmAddr, methodOracle, rpcblock.Latest, nil, []interface{}{oracleAddr})
......
...@@ -111,10 +111,7 @@ func registerAlphabet( ...@@ -111,10 +111,7 @@ func registerAlphabet(
claimants []common.Address, claimants []common.Address,
) error { ) error {
playerCreator := func(game types.GameMetadata, dir string) (scheduler.GamePlayer, error) { playerCreator := func(game types.GameMetadata, dir string) (scheduler.GamePlayer, error) {
contract, err := contracts.NewFaultDisputeGameContract(m, game.Proxy, caller) contract := contracts.NewFaultDisputeGameContract(m, game.Proxy, caller)
if err != nil {
return nil, err
}
oracle, err := contract.GetOracle(ctx) oracle, err := contract.GetOracle(ctx)
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to load oracle for game %v: %w", game.Proxy, err) return nil, fmt.Errorf("failed to load oracle for game %v: %w", game.Proxy, err)
...@@ -151,7 +148,7 @@ func registerAlphabet( ...@@ -151,7 +148,7 @@ func registerAlphabet(
registry.RegisterGameType(faultTypes.AlphabetGameType, playerCreator) registry.RegisterGameType(faultTypes.AlphabetGameType, playerCreator)
contractCreator := func(game types.GameMetadata) (claims.BondContract, error) { contractCreator := func(game types.GameMetadata) (claims.BondContract, error) {
return contracts.NewFaultDisputeGameContract(m, game.Proxy, caller) return contracts.NewFaultDisputeGameContract(m, game.Proxy, caller), nil
} }
registry.RegisterBondContract(faultTypes.AlphabetGameType, contractCreator) registry.RegisterBondContract(faultTypes.AlphabetGameType, contractCreator)
return nil return nil
...@@ -162,10 +159,7 @@ func registerOracle(ctx context.Context, m metrics.Metricer, oracles OracleRegis ...@@ -162,10 +159,7 @@ func registerOracle(ctx context.Context, m metrics.Metricer, oracles OracleRegis
if err != nil { if err != nil {
return fmt.Errorf("failed to load implementation for game type %v: %w", gameType, err) return fmt.Errorf("failed to load implementation for game type %v: %w", gameType, err)
} }
contract, err := contracts.NewFaultDisputeGameContract(m, implAddr, caller) contract := contracts.NewFaultDisputeGameContract(m, implAddr, caller)
if err != nil {
return err
}
oracle, err := contract.GetOracle(ctx) oracle, err := contract.GetOracle(ctx)
if err != nil { if err != nil {
return fmt.Errorf("failed to load oracle address: %w", err) return fmt.Errorf("failed to load oracle address: %w", err)
...@@ -196,10 +190,7 @@ func registerAsterisc( ...@@ -196,10 +190,7 @@ func registerAsterisc(
) error { ) error {
asteriscPrestateProvider := asterisc.NewPrestateProvider(cfg.AsteriscAbsolutePreState) asteriscPrestateProvider := asterisc.NewPrestateProvider(cfg.AsteriscAbsolutePreState)
playerCreator := func(game types.GameMetadata, dir string) (scheduler.GamePlayer, error) { playerCreator := func(game types.GameMetadata, dir string) (scheduler.GamePlayer, error) {
contract, err := contracts.NewFaultDisputeGameContract(m, game.Proxy, caller) contract := contracts.NewFaultDisputeGameContract(m, game.Proxy, caller)
if err != nil {
return nil, err
}
oracle, err := contract.GetOracle(ctx) oracle, err := contract.GetOracle(ctx)
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to load oracle for game %v: %w", game.Proxy, err) return nil, fmt.Errorf("failed to load oracle for game %v: %w", game.Proxy, err)
...@@ -236,7 +227,7 @@ func registerAsterisc( ...@@ -236,7 +227,7 @@ func registerAsterisc(
registry.RegisterGameType(gameType, playerCreator) registry.RegisterGameType(gameType, playerCreator)
contractCreator := func(game types.GameMetadata) (claims.BondContract, error) { contractCreator := func(game types.GameMetadata) (claims.BondContract, error) {
return contracts.NewFaultDisputeGameContract(m, game.Proxy, caller) return contracts.NewFaultDisputeGameContract(m, game.Proxy, caller), nil
} }
registry.RegisterBondContract(gameType, contractCreator) registry.RegisterBondContract(gameType, contractCreator)
return nil return nil
...@@ -264,10 +255,7 @@ func registerCannon( ...@@ -264,10 +255,7 @@ func registerCannon(
) error { ) error {
cannonPrestateProvider := cannon.NewPrestateProvider(cfg.CannonAbsolutePreState) cannonPrestateProvider := cannon.NewPrestateProvider(cfg.CannonAbsolutePreState)
playerCreator := func(game types.GameMetadata, dir string) (scheduler.GamePlayer, error) { playerCreator := func(game types.GameMetadata, dir string) (scheduler.GamePlayer, error) {
contract, err := contracts.NewFaultDisputeGameContract(m, game.Proxy, caller) contract := contracts.NewFaultDisputeGameContract(m, game.Proxy, caller)
if err != nil {
return nil, err
}
oracle, err := contract.GetOracle(ctx) oracle, err := contract.GetOracle(ctx)
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to load oracle for game %v: %w", game.Proxy, err) return nil, fmt.Errorf("failed to load oracle for game %v: %w", game.Proxy, err)
...@@ -304,7 +292,7 @@ func registerCannon( ...@@ -304,7 +292,7 @@ func registerCannon(
registry.RegisterGameType(gameType, playerCreator) registry.RegisterGameType(gameType, playerCreator)
contractCreator := func(game types.GameMetadata) (claims.BondContract, error) { contractCreator := func(game types.GameMetadata) (claims.BondContract, error) {
return contracts.NewFaultDisputeGameContract(m, game.Proxy, caller) return contracts.NewFaultDisputeGameContract(m, game.Proxy, caller), nil
} }
registry.RegisterBondContract(gameType, contractCreator) registry.RegisterBondContract(gameType, contractCreator)
return nil return nil
......
...@@ -198,11 +198,8 @@ func (s *Service) initMetricsServer(cfg *opmetrics.CLIConfig) error { ...@@ -198,11 +198,8 @@ func (s *Service) initMetricsServer(cfg *opmetrics.CLIConfig) error {
} }
func (s *Service) initFactoryContract(cfg *config.Config) error { func (s *Service) initFactoryContract(cfg *config.Config) error {
factoryContract, err := contracts.NewDisputeGameFactoryContract(s.metrics, cfg.GameFactoryAddress, factoryContract := contracts.NewDisputeGameFactoryContract(s.metrics, cfg.GameFactoryAddress,
batching.NewMultiCaller(s.l1Client.Client(), batching.DefaultBatchSize)) batching.NewMultiCaller(s.l1Client.Client(), batching.DefaultBatchSize))
if err != nil {
return fmt.Errorf("failed to bind the fault dispute game factory contract: %w", err)
}
s.factoryContract = factoryContract s.factoryContract = factoryContract
return nil return nil
} }
......
...@@ -52,10 +52,7 @@ func (g *GameCallerCreator) CreateContract(game gameTypes.GameMetadata) (GameCal ...@@ -52,10 +52,7 @@ func (g *GameCallerCreator) CreateContract(game gameTypes.GameMetadata) (GameCal
} }
switch game.GameType { switch game.GameType {
case faultTypes.CannonGameType, faultTypes.AsteriscGameType, faultTypes.AlphabetGameType: case faultTypes.CannonGameType, faultTypes.AsteriscGameType, faultTypes.AlphabetGameType:
fdg, err := contracts.NewFaultDisputeGameContract(g.m, game.Proxy, g.caller) fdg := contracts.NewFaultDisputeGameContract(g.m, game.Proxy, g.caller)
if err != nil {
return nil, fmt.Errorf("failed to create FaultDisputeGameContract: %w", err)
}
g.cache.Add(game.Proxy, fdg) g.cache.Add(game.Proxy, fdg)
return fdg, nil return fdg, nil
default: default:
......
...@@ -209,11 +209,8 @@ func (s *Service) initMetricsServer(cfg *opmetrics.CLIConfig) error { ...@@ -209,11 +209,8 @@ func (s *Service) initMetricsServer(cfg *opmetrics.CLIConfig) error {
} }
func (s *Service) initFactoryContract(cfg *config.Config) error { func (s *Service) initFactoryContract(cfg *config.Config) error {
factoryContract, err := contracts.NewDisputeGameFactoryContract(s.metrics, cfg.GameFactoryAddress, factoryContract := contracts.NewDisputeGameFactoryContract(s.metrics, cfg.GameFactoryAddress,
batching.NewMultiCaller(s.l1Client.Client(), batching.DefaultBatchSize)) batching.NewMultiCaller(s.l1Client.Client(), batching.DefaultBatchSize))
if err != nil {
return fmt.Errorf("failed to bind the fault dispute game factory contract: %w", err)
}
s.factoryContract = factoryContract s.factoryContract = factoryContract
return nil return nil
} }
......
...@@ -39,8 +39,7 @@ func (g *OutputAlphabetGameHelper) StartChallenger( ...@@ -39,8 +39,7 @@ func (g *OutputAlphabetGameHelper) StartChallenger(
func (g *OutputAlphabetGameHelper) CreateHonestActor(ctx context.Context, l2Node string) *OutputHonestHelper { func (g *OutputAlphabetGameHelper) CreateHonestActor(ctx context.Context, l2Node string) *OutputHonestHelper {
logger := testlog.Logger(g.t, log.LevelInfo).New("role", "HonestHelper", "game", g.addr) logger := testlog.Logger(g.t, log.LevelInfo).New("role", "HonestHelper", "game", g.addr)
caller := batching.NewMultiCaller(g.system.NodeClient("l1").Client(), batching.DefaultBatchSize) caller := batching.NewMultiCaller(g.system.NodeClient("l1").Client(), batching.DefaultBatchSize)
contract, err := contracts.NewFaultDisputeGameContract(contractMetrics.NoopContractMetrics, g.addr, caller) contract := contracts.NewFaultDisputeGameContract(contractMetrics.NoopContractMetrics, g.addr, caller)
g.require.NoError(err, "Failed to create game contact")
prestateBlock, poststateBlock, err := contract.GetBlockRange(ctx) prestateBlock, poststateBlock, err := contract.GetBlockRange(ctx)
g.require.NoError(err, "Get block range") g.require.NoError(err, "Get block range")
splitDepth := g.SplitDepth(ctx) splitDepth := g.SplitDepth(ctx)
......
...@@ -64,8 +64,7 @@ func (g *OutputCannonGameHelper) CreateHonestActor(ctx context.Context, l2Node s ...@@ -64,8 +64,7 @@ func (g *OutputCannonGameHelper) CreateHonestActor(ctx context.Context, l2Node s
logger := testlog.Logger(g.t, log.LevelInfo).New("role", "HonestHelper", "game", g.addr) logger := testlog.Logger(g.t, log.LevelInfo).New("role", "HonestHelper", "game", g.addr)
l2Client := g.system.NodeClient(l2Node) l2Client := g.system.NodeClient(l2Node)
caller := batching.NewMultiCaller(g.system.NodeClient("l1").Client(), batching.DefaultBatchSize) caller := batching.NewMultiCaller(g.system.NodeClient("l1").Client(), batching.DefaultBatchSize)
contract, err := contracts.NewFaultDisputeGameContract(contractMetrics.NoopContractMetrics, g.addr, caller) contract := contracts.NewFaultDisputeGameContract(contractMetrics.NoopContractMetrics, g.addr, caller)
g.require.NoError(err, "Failed to create game contact")
prestateBlock, poststateBlock, err := contract.GetBlockRange(ctx) prestateBlock, poststateBlock, err := contract.GetBlockRange(ctx)
g.require.NoError(err, "Failed to load block range") g.require.NoError(err, "Failed to load block range")
...@@ -296,8 +295,7 @@ func (g *OutputCannonGameHelper) createCannonTraceProvider(ctx context.Context, ...@@ -296,8 +295,7 @@ func (g *OutputCannonGameHelper) createCannonTraceProvider(ctx context.Context,
caller := batching.NewMultiCaller(g.system.NodeClient("l1").Client(), batching.DefaultBatchSize) caller := batching.NewMultiCaller(g.system.NodeClient("l1").Client(), batching.DefaultBatchSize)
l2Client := g.system.NodeClient(l2Node) l2Client := g.system.NodeClient(l2Node)
contract, err := contracts.NewFaultDisputeGameContract(contractMetrics.NoopContractMetrics, g.addr, caller) contract := contracts.NewFaultDisputeGameContract(contractMetrics.NoopContractMetrics, g.addr, caller)
g.require.NoError(err, "Failed to create game contact")
prestateBlock, poststateBlock, err := contract.GetBlockRange(ctx) prestateBlock, poststateBlock, err := contract.GetBlockRange(ctx)
g.require.NoError(err, "Failed to load block range") g.require.NoError(err, "Failed to load block range")
......
...@@ -702,8 +702,7 @@ func (g *OutputGameHelper) uploadPreimage(ctx context.Context, data *types.Preim ...@@ -702,8 +702,7 @@ func (g *OutputGameHelper) uploadPreimage(ctx context.Context, data *types.Preim
func (g *OutputGameHelper) oracle(ctx context.Context) *contracts.PreimageOracleContract { func (g *OutputGameHelper) oracle(ctx context.Context) *contracts.PreimageOracleContract {
caller := batching.NewMultiCaller(g.system.NodeClient("l1").Client(), batching.DefaultBatchSize) caller := batching.NewMultiCaller(g.system.NodeClient("l1").Client(), batching.DefaultBatchSize)
contract, err := contracts.NewFaultDisputeGameContract(contractMetrics.NoopContractMetrics, g.addr, caller) contract := contracts.NewFaultDisputeGameContract(contractMetrics.NoopContractMetrics, g.addr, caller)
g.require.NoError(err, "Failed to create game contract")
oracle, err := contract.GetOracle(ctx) oracle, err := contract.GetOracle(ctx)
g.require.NoError(err, "Failed to create oracle contract") g.require.NoError(err, "Failed to create oracle contract")
return oracle return oracle
......
...@@ -43,8 +43,7 @@ func NewHelper(t *testing.T, opts *bind.TransactOpts, client *ethclient.Client, ...@@ -43,8 +43,7 @@ func NewHelper(t *testing.T, opts *bind.TransactOpts, client *ethclient.Client,
oracleBindings, err := bindings.NewPreimageOracle(addr, client) oracleBindings, err := bindings.NewPreimageOracle(addr, client)
require.NoError(err) require.NoError(err)
oracle, err := contracts.NewPreimageOracleContract(addr, batching.NewMultiCaller(client.Client(), batching.DefaultBatchSize)) oracle := contracts.NewPreimageOracleContract(addr, batching.NewMultiCaller(client.Client(), batching.DefaultBatchSize))
require.NoError(err)
return &Helper{ return &Helper{
t: t, t: t,
require: require, require: require,
......
package snapshots package snapshots
import ( import (
"embed" "bytes"
"fmt" _ "embed"
"path/filepath"
"github.com/ethereum/go-ethereum/accounts/abi" "github.com/ethereum/go-ethereum/accounts/abi"
) )
//go:embed abi //go:embed abi/DisputeGameFactory.json
var abis embed.FS var disputeGameFactory []byte
func LoadDisputeGameFactoryABI() (*abi.ABI, error) { //go:embed abi/FaultDisputeGame.json
return loadABI("DisputeGameFactory") var faultDisputeGame []byte
//go:embed abi/PreimageOracle.json
var preimageOracle []byte
//go:embed abi/MIPS.json
var mips []byte
//go:embed abi/DelayedWETH.json
var delayedWETH []byte
func LoadDisputeGameFactoryABI() *abi.ABI {
return loadABI(disputeGameFactory)
} }
func LoadFaultDisputeGameABI() (*abi.ABI, error) { func LoadFaultDisputeGameABI() *abi.ABI {
return loadABI("FaultDisputeGame") return loadABI(faultDisputeGame)
} }
func LoadPreimageOracleABI() (*abi.ABI, error) { func LoadPreimageOracleABI() *abi.ABI {
return loadABI("PreimageOracle") return loadABI(preimageOracle)
} }
func LoadMIPSABI() (*abi.ABI, error) { func LoadMIPSABI() *abi.ABI {
return loadABI("MIPS") return loadABI(mips)
} }
func LoadDelayedWETHABI() (*abi.ABI, error) { func LoadDelayedWETHABI() *abi.ABI {
return loadABI("DelayedWETH") return loadABI(delayedWETH)
} }
func loadABI(name string) (*abi.ABI, error) { func loadABI(json []byte) *abi.ABI {
in, err := abis.Open(filepath.Join("abi", name+".json")) if parsed, err := abi.JSON(bytes.NewReader(json)); err != nil {
if err != nil { panic(err)
return nil, fmt.Errorf("failed to load ABI for contract %v: %w", name, err)
}
defer in.Close()
if parsed, err := abi.JSON(in); err != nil {
return nil, err
} else { } else {
return &parsed, nil return &parsed
} }
} }
...@@ -10,7 +10,7 @@ import ( ...@@ -10,7 +10,7 @@ import (
func TestLoadABIs(t *testing.T) { func TestLoadABIs(t *testing.T) {
tests := []struct { tests := []struct {
contract string contract string
method func() (*abi.ABI, error) method func() *abi.ABI
}{ }{
{"DisputeGameFactory", LoadDisputeGameFactoryABI}, {"DisputeGameFactory", LoadDisputeGameFactoryABI},
{"FaultDisputeGame", LoadFaultDisputeGameABI}, {"FaultDisputeGame", LoadFaultDisputeGameABI},
...@@ -21,8 +21,7 @@ func TestLoadABIs(t *testing.T) { ...@@ -21,8 +21,7 @@ func TestLoadABIs(t *testing.T) {
for _, test := range tests { for _, test := range tests {
test := test test := test
t.Run(test.contract, func(t *testing.T) { t.Run(test.contract, func(t *testing.T) {
actual, err := test.method() actual := test.method()
require.NoError(t, err)
require.NotNil(t, actual) require.NotNil(t, actual)
}) })
} }
......
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