From f56bc8cd716fea4dd87706c05a522ec75de9df75 Mon Sep 17 00:00:00 2001 From: Adrian Sutton <adrian@oplabs.co> Date: Thu, 30 Nov 2023 13:56:10 +1000 Subject: [PATCH] challenger: Don't export the base dispute game contract. --- .../game/fault/contracts/disputegame.go | 40 +++++++++---------- .../game/fault/contracts/disputegame_test.go | 18 ++++----- .../game/fault/contracts/faultdisputegame.go | 4 +- .../fault/contracts/faultdisputegame_test.go | 4 +- .../fault/contracts/outputbisectiongame.go | 6 +-- .../contracts/outputbisectiongame_test.go | 4 +- 6 files changed, 38 insertions(+), 38 deletions(-) diff --git a/op-challenger/game/fault/contracts/disputegame.go b/op-challenger/game/fault/contracts/disputegame.go index 5d873482c..fd51e51cf 100644 --- a/op-challenger/game/fault/contracts/disputegame.go +++ b/op-challenger/game/fault/contracts/disputegame.go @@ -29,7 +29,7 @@ const ( methodVM = "VM" ) -type DisputeGameContract struct { +type disputeGameContract struct { multiCaller *batching.MultiCaller contract *batching.BoundContract } @@ -55,7 +55,7 @@ func asProposal(p contractProposal) Proposal { } } -func (f *DisputeGameContract) GetGameDuration(ctx context.Context) (uint64, error) { +func (f *disputeGameContract) GetGameDuration(ctx context.Context) (uint64, error) { result, err := f.multiCaller.SingleCall(ctx, batching.BlockLatest, f.contract.Call(methodGameDuration)) if err != nil { return 0, fmt.Errorf("failed to fetch game duration: %w", err) @@ -63,7 +63,7 @@ func (f *DisputeGameContract) GetGameDuration(ctx context.Context) (uint64, erro return result.GetUint64(0), nil } -func (f *DisputeGameContract) GetMaxGameDepth(ctx context.Context) (uint64, error) { +func (f *disputeGameContract) GetMaxGameDepth(ctx context.Context) (uint64, error) { result, err := f.multiCaller.SingleCall(ctx, batching.BlockLatest, f.contract.Call(methodMaxGameDepth)) if err != nil { return 0, fmt.Errorf("failed to fetch max game depth: %w", err) @@ -71,7 +71,7 @@ func (f *DisputeGameContract) GetMaxGameDepth(ctx context.Context) (uint64, erro return result.GetBigInt(0).Uint64(), nil } -func (f *DisputeGameContract) GetAbsolutePrestateHash(ctx context.Context) (common.Hash, error) { +func (f *disputeGameContract) GetAbsolutePrestateHash(ctx context.Context) (common.Hash, error) { result, err := f.multiCaller.SingleCall(ctx, batching.BlockLatest, f.contract.Call(methodAbsolutePrestate)) if err != nil { return common.Hash{}, fmt.Errorf("failed to fetch absolute prestate hash: %w", err) @@ -79,7 +79,7 @@ func (f *DisputeGameContract) GetAbsolutePrestateHash(ctx context.Context) (comm return result.GetHash(0), nil } -func (f *DisputeGameContract) GetL1Head(ctx context.Context) (common.Hash, error) { +func (f *disputeGameContract) GetL1Head(ctx context.Context) (common.Hash, error) { result, err := f.multiCaller.SingleCall(ctx, batching.BlockLatest, f.contract.Call(methodL1Head)) if err != nil { return common.Hash{}, fmt.Errorf("failed to fetch L1 head: %w", err) @@ -87,7 +87,7 @@ func (f *DisputeGameContract) GetL1Head(ctx context.Context) (common.Hash, error return result.GetHash(0), nil } -func (f *DisputeGameContract) GetStatus(ctx context.Context) (gameTypes.GameStatus, error) { +func (f *disputeGameContract) GetStatus(ctx context.Context) (gameTypes.GameStatus, error) { result, err := f.multiCaller.SingleCall(ctx, batching.BlockLatest, f.contract.Call(methodStatus)) if err != nil { return 0, fmt.Errorf("failed to fetch status: %w", err) @@ -95,7 +95,7 @@ func (f *DisputeGameContract) GetStatus(ctx context.Context) (gameTypes.GameStat return gameTypes.GameStatusFromUint8(result.GetUint8(0)) } -func (f *DisputeGameContract) GetClaimCount(ctx context.Context) (uint64, error) { +func (f *disputeGameContract) GetClaimCount(ctx context.Context) (uint64, error) { result, err := f.multiCaller.SingleCall(ctx, batching.BlockLatest, f.contract.Call(methodClaimCount)) if err != nil { return 0, fmt.Errorf("failed to fetch claim count: %w", err) @@ -103,7 +103,7 @@ func (f *DisputeGameContract) GetClaimCount(ctx context.Context) (uint64, error) return result.GetBigInt(0).Uint64(), nil } -func (f *DisputeGameContract) GetClaim(ctx context.Context, idx uint64) (types.Claim, error) { +func (f *disputeGameContract) GetClaim(ctx context.Context, idx uint64) (types.Claim, error) { result, err := f.multiCaller.SingleCall(ctx, batching.BlockLatest, f.contract.Call(methodClaim, new(big.Int).SetUint64(idx))) if err != nil { return types.Claim{}, fmt.Errorf("failed to fetch claim %v: %w", idx, err) @@ -111,7 +111,7 @@ func (f *DisputeGameContract) GetClaim(ctx context.Context, idx uint64) (types.C return f.decodeClaim(result, int(idx)), nil } -func (f *DisputeGameContract) GetAllClaims(ctx context.Context) ([]types.Claim, error) { +func (f *disputeGameContract) GetAllClaims(ctx context.Context) ([]types.Claim, error) { count, err := f.GetClaimCount(ctx) if err != nil { return nil, fmt.Errorf("failed to load claim count: %w", err) @@ -134,7 +134,7 @@ func (f *DisputeGameContract) GetAllClaims(ctx context.Context) ([]types.Claim, return claims, nil } -func (f *DisputeGameContract) vm(ctx context.Context) (*VMContract, error) { +func (f *disputeGameContract) vm(ctx context.Context) (*VMContract, error) { result, err := f.multiCaller.SingleCall(ctx, batching.BlockLatest, f.contract.Call(methodVM)) if err != nil { return nil, fmt.Errorf("failed to fetch VM addr: %w", err) @@ -143,22 +143,22 @@ func (f *DisputeGameContract) vm(ctx context.Context) (*VMContract, error) { return NewVMContract(vmAddr, f.multiCaller) } -func (f *DisputeGameContract) AttackTx(parentContractIndex uint64, pivot common.Hash) (txmgr.TxCandidate, error) { +func (f *disputeGameContract) AttackTx(parentContractIndex uint64, pivot common.Hash) (txmgr.TxCandidate, error) { call := f.contract.Call(methodAttack, new(big.Int).SetUint64(parentContractIndex), pivot) return call.ToTxCandidate() } -func (f *DisputeGameContract) DefendTx(parentContractIndex uint64, pivot common.Hash) (txmgr.TxCandidate, error) { +func (f *disputeGameContract) DefendTx(parentContractIndex uint64, pivot common.Hash) (txmgr.TxCandidate, error) { call := f.contract.Call(methodDefend, new(big.Int).SetUint64(parentContractIndex), pivot) return call.ToTxCandidate() } -func (f *DisputeGameContract) StepTx(claimIdx uint64, isAttack bool, stateData []byte, proof []byte) (txmgr.TxCandidate, error) { +func (f *disputeGameContract) StepTx(claimIdx uint64, isAttack bool, stateData []byte, proof []byte) (txmgr.TxCandidate, error) { call := f.contract.Call(methodStep, new(big.Int).SetUint64(claimIdx), isAttack, stateData, proof) return call.ToTxCandidate() } -func (f *DisputeGameContract) CallResolveClaim(ctx context.Context, claimIdx uint64) error { +func (f *disputeGameContract) CallResolveClaim(ctx context.Context, claimIdx uint64) error { call := f.resolveClaimCall(claimIdx) _, err := f.multiCaller.SingleCall(ctx, batching.BlockLatest, call) if err != nil { @@ -167,16 +167,16 @@ func (f *DisputeGameContract) CallResolveClaim(ctx context.Context, claimIdx uin return nil } -func (f *DisputeGameContract) ResolveClaimTx(claimIdx uint64) (txmgr.TxCandidate, error) { +func (f *disputeGameContract) ResolveClaimTx(claimIdx uint64) (txmgr.TxCandidate, error) { call := f.resolveClaimCall(claimIdx) return call.ToTxCandidate() } -func (f *DisputeGameContract) resolveClaimCall(claimIdx uint64) *batching.ContractCall { +func (f *disputeGameContract) resolveClaimCall(claimIdx uint64) *batching.ContractCall { return f.contract.Call(methodResolveClaim, new(big.Int).SetUint64(claimIdx)) } -func (f *DisputeGameContract) CallResolve(ctx context.Context) (gameTypes.GameStatus, error) { +func (f *disputeGameContract) CallResolve(ctx context.Context) (gameTypes.GameStatus, error) { call := f.resolveCall() result, err := f.multiCaller.SingleCall(ctx, batching.BlockLatest, call) if err != nil { @@ -185,16 +185,16 @@ func (f *DisputeGameContract) CallResolve(ctx context.Context) (gameTypes.GameSt return gameTypes.GameStatusFromUint8(result.GetUint8(0)) } -func (f *DisputeGameContract) ResolveTx() (txmgr.TxCandidate, error) { +func (f *disputeGameContract) ResolveTx() (txmgr.TxCandidate, error) { call := f.resolveCall() return call.ToTxCandidate() } -func (f *DisputeGameContract) resolveCall() *batching.ContractCall { +func (f *disputeGameContract) resolveCall() *batching.ContractCall { return f.contract.Call(methodResolve) } -func (f *DisputeGameContract) decodeClaim(result *batching.CallResult, contractIndex int) types.Claim { +func (f *disputeGameContract) decodeClaim(result *batching.CallResult, contractIndex int) types.Claim { parentIndex := result.GetUint32(0) countered := result.GetBool(1) claim := result.GetHash(2) diff --git a/op-challenger/game/fault/contracts/disputegame_test.go b/op-challenger/game/fault/contracts/disputegame_test.go index 02cf1373c..5d0f4891d 100644 --- a/op-challenger/game/fault/contracts/disputegame_test.go +++ b/op-challenger/game/fault/contracts/disputegame_test.go @@ -20,7 +20,7 @@ var ( oracleAddr = common.HexToAddress("0x44442842371dFC380576ebb09Ae16Cb6B6ca4444") ) -type disputeGameSetupFunc func(t *testing.T) (*batchingTest.AbiBasedRpc, *DisputeGameContract) +type disputeGameSetupFunc func(t *testing.T) (*batchingTest.AbiBasedRpc, *disputeGameContract) func runCommonDisputeGameTests(t *testing.T, setup disputeGameSetupFunc) { tests := []struct { @@ -52,19 +52,19 @@ func runSimpleGettersTest(t *testing.T, setup disputeGameSetupFunc) { args []interface{} result interface{} expected interface{} // Defaults to expecting the same as result - call func(game *DisputeGameContract) (any, error) + call func(game *disputeGameContract) (any, error) }{ { method: methodStatus, result: types.GameStatusChallengerWon, - call: func(game *DisputeGameContract) (any, error) { + call: func(game *disputeGameContract) (any, error) { return game.GetStatus(context.Background()) }, }, { method: methodGameDuration, result: uint64(5566), - call: func(game *DisputeGameContract) (any, error) { + call: func(game *disputeGameContract) (any, error) { return game.GetGameDuration(context.Background()) }, }, @@ -72,14 +72,14 @@ func runSimpleGettersTest(t *testing.T, setup disputeGameSetupFunc) { method: methodMaxGameDepth, result: big.NewInt(128), expected: uint64(128), - call: func(game *DisputeGameContract) (any, error) { + call: func(game *disputeGameContract) (any, error) { return game.GetMaxGameDepth(context.Background()) }, }, { method: methodAbsolutePrestate, result: common.Hash{0xab}, - call: func(game *DisputeGameContract) (any, error) { + call: func(game *disputeGameContract) (any, error) { return game.GetAbsolutePrestateHash(context.Background()) }, }, @@ -87,21 +87,21 @@ func runSimpleGettersTest(t *testing.T, setup disputeGameSetupFunc) { method: methodClaimCount, result: big.NewInt(9876), expected: uint64(9876), - call: func(game *DisputeGameContract) (any, error) { + call: func(game *disputeGameContract) (any, error) { return game.GetClaimCount(context.Background()) }, }, { method: methodL1Head, result: common.Hash{0xdd, 0xbb}, - call: func(game *DisputeGameContract) (any, error) { + call: func(game *disputeGameContract) (any, error) { return game.GetL1Head(context.Background()) }, }, { method: methodResolve, result: types.GameStatusInProgress, - call: func(game *DisputeGameContract) (any, error) { + call: func(game *disputeGameContract) (any, error) { return game.CallResolve(context.Background()) }, }, diff --git a/op-challenger/game/fault/contracts/faultdisputegame.go b/op-challenger/game/fault/contracts/faultdisputegame.go index 7b7a3edd1..ebcaf60ed 100644 --- a/op-challenger/game/fault/contracts/faultdisputegame.go +++ b/op-challenger/game/fault/contracts/faultdisputegame.go @@ -17,7 +17,7 @@ const ( ) type FaultDisputeGameContract struct { - DisputeGameContract + disputeGameContract } func NewFaultDisputeGameContract(addr common.Address, caller *batching.MultiCaller) (*FaultDisputeGameContract, error) { @@ -27,7 +27,7 @@ func NewFaultDisputeGameContract(addr common.Address, caller *batching.MultiCall } return &FaultDisputeGameContract{ - DisputeGameContract: DisputeGameContract{ + disputeGameContract: disputeGameContract{ multiCaller: caller, contract: batching.NewBoundContract(fdgAbi, addr), }, diff --git a/op-challenger/game/fault/contracts/faultdisputegame_test.go b/op-challenger/game/fault/contracts/faultdisputegame_test.go index 9a6968327..f96ffecb9 100644 --- a/op-challenger/game/fault/contracts/faultdisputegame_test.go +++ b/op-challenger/game/fault/contracts/faultdisputegame_test.go @@ -14,9 +14,9 @@ import ( ) func TestFaultDisputeGameContract_CommonTests(t *testing.T) { - runCommonDisputeGameTests(t, func(t *testing.T) (*batchingTest.AbiBasedRpc, *DisputeGameContract) { + runCommonDisputeGameTests(t, func(t *testing.T) (*batchingTest.AbiBasedRpc, *disputeGameContract) { stubRpc, contract := setupFaultDisputeGameTest(t) - return stubRpc, &contract.DisputeGameContract + return stubRpc, &contract.disputeGameContract }) } diff --git a/op-challenger/game/fault/contracts/outputbisectiongame.go b/op-challenger/game/fault/contracts/outputbisectiongame.go index dce47ea4c..8e20b5ce5 100644 --- a/op-challenger/game/fault/contracts/outputbisectiongame.go +++ b/op-challenger/game/fault/contracts/outputbisectiongame.go @@ -19,7 +19,7 @@ var ( ) type OutputBisectionGameContract struct { - DisputeGameContract + disputeGameContract } func NewOutputBisectionGameContract(addr common.Address, caller *batching.MultiCaller) (*OutputBisectionGameContract, error) { @@ -29,7 +29,7 @@ func NewOutputBisectionGameContract(addr common.Address, caller *batching.MultiC } return &OutputBisectionGameContract{ - DisputeGameContract: DisputeGameContract{ + disputeGameContract: disputeGameContract{ multiCaller: caller, contract: batching.NewBoundContract(contractAbi, addr), }, @@ -78,7 +78,7 @@ func (f *OutputBisectionGameContract) addLocalDataTx(claimIdx uint64, data *type return call.ToTxCandidate() } -func (f *DisputeGameContract) addGlobalDataTx(ctx context.Context, data *types.PreimageOracleData) (txmgr.TxCandidate, error) { +func (f *disputeGameContract) addGlobalDataTx(ctx context.Context, data *types.PreimageOracleData) (txmgr.TxCandidate, error) { vm, err := f.vm(ctx) if err != nil { return txmgr.TxCandidate{}, err diff --git a/op-challenger/game/fault/contracts/outputbisectiongame_test.go b/op-challenger/game/fault/contracts/outputbisectiongame_test.go index d8bcbba0b..e109ed104 100644 --- a/op-challenger/game/fault/contracts/outputbisectiongame_test.go +++ b/op-challenger/game/fault/contracts/outputbisectiongame_test.go @@ -14,9 +14,9 @@ import ( ) func TestOutputBisectionGameContract_CommonTests(t *testing.T) { - runCommonDisputeGameTests(t, func(t *testing.T) (*batchingTest.AbiBasedRpc, *DisputeGameContract) { + runCommonDisputeGameTests(t, func(t *testing.T) (*batchingTest.AbiBasedRpc, *disputeGameContract) { stubRpc, contract := setupOutputBisectionGameTest(t) - return stubRpc, &contract.DisputeGameContract + return stubRpc, &contract.disputeGameContract }) } -- 2.23.0