From 70c0778dc1f2ee3addc733b264da3f0d3bf7761a Mon Sep 17 00:00:00 2001 From: Adrian Sutton Date: Fri, 8 Mar 2024 04:59:51 +1000 Subject: [PATCH] multicaller: Move Block type to separate package to avoid dependency cycles (#9768) * multicaller: Support generic calls, not just eth_call * multicaller: Support generic calls, not just eth_call * multicaller: Implement balance_call * multicaller: Split out a generic rpc stub for testing RPC requests other than eth_call Test balance call * multicaller: Move Block type to separate package to avoid dependency cycles for multicaller tests. * fix(op-service): remove old balance call test --------- Co-authored-by: refcell --- .../game/fault/contracts/faultdisputegame.go | 37 +++++++------ .../fault/contracts/faultdisputegame_test.go | 55 ++++++++++--------- .../game/fault/contracts/gamefactory.go | 13 +++-- .../game/fault/contracts/gamefactory_test.go | 15 ++--- op-challenger/game/fault/contracts/oracle.go | 19 ++++--- .../game/fault/contracts/oracle_test.go | 43 ++++++++------- op-challenger/game/fault/contracts/vm.go | 3 +- op-challenger/game/fault/contracts/vm_test.go | 3 +- op-challenger/game/fault/preimages/large.go | 6 +- .../game/fault/preimages/large_test.go | 4 +- op-challenger/game/fault/preimages/types.go | 4 +- op-challenger/game/keccak/fetcher/fetcher.go | 6 +- .../game/keccak/fetcher/fetcher_test.go | 4 +- op-challenger/game/keccak/scheduler_test.go | 6 +- op-challenger/game/keccak/types/types.go | 6 +- op-challenger/game/keccak/verifier.go | 6 +- op-challenger/game/registry/registry_test.go | 6 +- op-dispute-mon/mon/bonds/bonds.go | 6 +- op-dispute-mon/mon/bonds/bonds_test.go | 4 +- .../disputegame/output_cannon_helper.go | 3 +- .../disputegame/output_game_helper.go | 3 +- .../disputegame/preimage/preimage_helper.go | 3 +- op-service/sources/batching/arrays.go | 4 +- op-service/sources/batching/balance_call.go | 5 +- .../batching/{test => }/balance_call_test.go | 15 +++-- op-service/sources/batching/call.go | 3 +- op-service/sources/batching/contract_call.go | 5 +- op-service/sources/batching/multicall.go | 33 +---------- .../sources/batching/rpcblock/blocks.go | 33 +++++++++++ op-service/sources/batching/test/abi_stub.go | 8 +-- .../sources/batching/test/generic_stub.go | 4 +- 31 files changed, 193 insertions(+), 172 deletions(-) rename op-service/sources/batching/{test => }/balance_call_test.go (51%) create mode 100644 op-service/sources/batching/rpcblock/blocks.go diff --git a/op-challenger/game/fault/contracts/faultdisputegame.go b/op-challenger/game/fault/contracts/faultdisputegame.go index 7c91a8d1a353..c286d035053a 100644 --- a/op-challenger/game/fault/contracts/faultdisputegame.go +++ b/op-challenger/game/fault/contracts/faultdisputegame.go @@ -10,6 +10,7 @@ import ( "github.com/ethereum-optimism/optimism/op-challenger/game/fault/types" gameTypes "github.com/ethereum-optimism/optimism/op-challenger/game/types" "github.com/ethereum-optimism/optimism/op-service/sources/batching" + "github.com/ethereum-optimism/optimism/op-service/sources/batching/rpcblock" "github.com/ethereum-optimism/optimism/op-service/txmgr" "github.com/ethereum/go-ethereum/common" ) @@ -64,7 +65,7 @@ func NewFaultDisputeGameContract(addr common.Address, caller *batching.MultiCall // GetBlockRange returns the block numbers of the absolute pre-state block (typically genesis or the bedrock activation block) // and the post-state block (that the proposed output root is for). func (c *FaultDisputeGameContract) GetBlockRange(ctx context.Context) (prestateBlock uint64, poststateBlock uint64, retErr error) { - results, err := c.multiCaller.Call(ctx, batching.BlockLatest, + results, err := c.multiCaller.Call(ctx, rpcblock.Latest, c.contract.Call(methodGenesisBlockNumber), c.contract.Call(methodL2BlockNumber)) if err != nil { @@ -82,7 +83,7 @@ func (c *FaultDisputeGameContract) GetBlockRange(ctx context.Context) (prestateB // GetGameMetadata returns the game's L2 block number, root claim, status, and game duration. func (c *FaultDisputeGameContract) GetGameMetadata(ctx context.Context) (uint64, common.Hash, gameTypes.GameStatus, uint64, error) { - results, err := c.multiCaller.Call(ctx, batching.BlockLatest, + results, err := c.multiCaller.Call(ctx, rpcblock.Latest, c.contract.Call(methodL2BlockNumber), c.contract.Call(methodRootClaim), c.contract.Call(methodStatus), @@ -104,7 +105,7 @@ func (c *FaultDisputeGameContract) GetGameMetadata(ctx context.Context) (uint64, } func (c *FaultDisputeGameContract) GetGenesisOutputRoot(ctx context.Context) (common.Hash, error) { - genesisOutputRoot, err := c.multiCaller.SingleCall(ctx, batching.BlockLatest, c.contract.Call(methodGenesisOutputRoot)) + genesisOutputRoot, err := c.multiCaller.SingleCall(ctx, rpcblock.Latest, c.contract.Call(methodGenesisOutputRoot)) if err != nil { return common.Hash{}, fmt.Errorf("failed to retrieve genesis output root: %w", err) } @@ -112,7 +113,7 @@ func (c *FaultDisputeGameContract) GetGenesisOutputRoot(ctx context.Context) (co } func (c *FaultDisputeGameContract) GetSplitDepth(ctx context.Context) (types.Depth, error) { - splitDepth, err := c.multiCaller.SingleCall(ctx, batching.BlockLatest, c.contract.Call(methodSplitDepth)) + splitDepth, err := c.multiCaller.SingleCall(ctx, rpcblock.Latest, c.contract.Call(methodSplitDepth)) if err != nil { return 0, fmt.Errorf("failed to retrieve split depth: %w", err) } @@ -120,7 +121,7 @@ func (c *FaultDisputeGameContract) GetSplitDepth(ctx context.Context) (types.Dep } func (c *FaultDisputeGameContract) GetCredit(ctx context.Context, recipient common.Address) (*big.Int, gameTypes.GameStatus, error) { - results, err := c.multiCaller.Call(ctx, batching.BlockLatest, + results, err := c.multiCaller.Call(ctx, rpcblock.Latest, c.contract.Call(methodCredit, recipient), c.contract.Call(methodStatus)) if err != nil { @@ -137,7 +138,7 @@ func (c *FaultDisputeGameContract) GetCredit(ctx context.Context, recipient comm return credit, status, nil } -func (c *FaultDisputeGameContract) GetCredits(ctx context.Context, block batching.Block, recipients ...common.Address) ([]*big.Int, error) { +func (c *FaultDisputeGameContract) GetCredits(ctx context.Context, block rpcblock.Block, recipients ...common.Address) ([]*big.Int, error) { calls := make([]batching.Call, 0, len(recipients)) for _, recipient := range recipients { calls = append(calls, c.contract.Call(methodCredit, recipient)) @@ -159,7 +160,7 @@ func (f *FaultDisputeGameContract) ClaimCredit(recipient common.Address) (txmgr. } func (c *FaultDisputeGameContract) GetRequiredBond(ctx context.Context, position types.Position) (*big.Int, error) { - bond, err := c.multiCaller.SingleCall(ctx, batching.BlockLatest, c.contract.Call(methodRequiredBond, position.ToGIndex())) + bond, err := c.multiCaller.SingleCall(ctx, rpcblock.Latest, c.contract.Call(methodRequiredBond, position.ToGIndex())) if err != nil { return nil, fmt.Errorf("failed to retrieve required bond: %w", err) } @@ -200,7 +201,7 @@ func (f *FaultDisputeGameContract) GetOracle(ctx context.Context) (*PreimageOrac } func (f *FaultDisputeGameContract) GetGameDuration(ctx context.Context) (uint64, error) { - result, err := f.multiCaller.SingleCall(ctx, batching.BlockLatest, f.contract.Call(methodGameDuration)) + result, err := f.multiCaller.SingleCall(ctx, rpcblock.Latest, f.contract.Call(methodGameDuration)) if err != nil { return 0, fmt.Errorf("failed to fetch game duration: %w", err) } @@ -208,7 +209,7 @@ func (f *FaultDisputeGameContract) GetGameDuration(ctx context.Context) (uint64, } func (f *FaultDisputeGameContract) GetMaxGameDepth(ctx context.Context) (types.Depth, error) { - result, err := f.multiCaller.SingleCall(ctx, batching.BlockLatest, f.contract.Call(methodMaxGameDepth)) + result, err := f.multiCaller.SingleCall(ctx, rpcblock.Latest, f.contract.Call(methodMaxGameDepth)) if err != nil { return 0, fmt.Errorf("failed to fetch max game depth: %w", err) } @@ -216,7 +217,7 @@ func (f *FaultDisputeGameContract) GetMaxGameDepth(ctx context.Context) (types.D } func (f *FaultDisputeGameContract) GetAbsolutePrestateHash(ctx context.Context) (common.Hash, error) { - result, err := f.multiCaller.SingleCall(ctx, batching.BlockLatest, f.contract.Call(methodAbsolutePrestate)) + result, err := f.multiCaller.SingleCall(ctx, rpcblock.Latest, f.contract.Call(methodAbsolutePrestate)) if err != nil { return common.Hash{}, fmt.Errorf("failed to fetch absolute prestate hash: %w", err) } @@ -224,7 +225,7 @@ func (f *FaultDisputeGameContract) GetAbsolutePrestateHash(ctx context.Context) } func (f *FaultDisputeGameContract) GetL1Head(ctx context.Context) (common.Hash, error) { - result, err := f.multiCaller.SingleCall(ctx, batching.BlockLatest, f.contract.Call(methodL1Head)) + result, err := f.multiCaller.SingleCall(ctx, rpcblock.Latest, f.contract.Call(methodL1Head)) if err != nil { return common.Hash{}, fmt.Errorf("failed to fetch L1 head: %w", err) } @@ -232,7 +233,7 @@ func (f *FaultDisputeGameContract) GetL1Head(ctx context.Context) (common.Hash, } func (f *FaultDisputeGameContract) GetStatus(ctx context.Context) (gameTypes.GameStatus, error) { - result, err := f.multiCaller.SingleCall(ctx, batching.BlockLatest, f.contract.Call(methodStatus)) + result, err := f.multiCaller.SingleCall(ctx, rpcblock.Latest, f.contract.Call(methodStatus)) if err != nil { return 0, fmt.Errorf("failed to fetch status: %w", err) } @@ -240,7 +241,7 @@ func (f *FaultDisputeGameContract) GetStatus(ctx context.Context) (gameTypes.Gam } func (f *FaultDisputeGameContract) GetClaimCount(ctx context.Context) (uint64, error) { - result, err := f.multiCaller.SingleCall(ctx, batching.BlockLatest, f.contract.Call(methodClaimCount)) + result, err := f.multiCaller.SingleCall(ctx, rpcblock.Latest, f.contract.Call(methodClaimCount)) if err != nil { return 0, fmt.Errorf("failed to fetch claim count: %w", err) } @@ -248,7 +249,7 @@ func (f *FaultDisputeGameContract) GetClaimCount(ctx context.Context) (uint64, e } func (f *FaultDisputeGameContract) 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))) + result, err := f.multiCaller.SingleCall(ctx, rpcblock.Latest, 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) } @@ -256,7 +257,7 @@ func (f *FaultDisputeGameContract) GetClaim(ctx context.Context, idx uint64) (ty } func (f *FaultDisputeGameContract) GetAllClaims(ctx context.Context) ([]types.Claim, error) { - results, err := batching.ReadArray(ctx, f.multiCaller, batching.BlockLatest, f.contract.Call(methodClaimCount), func(i *big.Int) *batching.ContractCall { + results, err := batching.ReadArray(ctx, f.multiCaller, rpcblock.Latest, f.contract.Call(methodClaimCount), func(i *big.Int) *batching.ContractCall { return f.contract.Call(methodClaim, i) }) if err != nil { @@ -271,7 +272,7 @@ func (f *FaultDisputeGameContract) GetAllClaims(ctx context.Context) ([]types.Cl } func (f *FaultDisputeGameContract) vm(ctx context.Context) (*VMContract, error) { - result, err := f.multiCaller.SingleCall(ctx, batching.BlockLatest, f.contract.Call(methodVM)) + result, err := f.multiCaller.SingleCall(ctx, rpcblock.Latest, f.contract.Call(methodVM)) if err != nil { return nil, fmt.Errorf("failed to fetch VM addr: %w", err) } @@ -296,7 +297,7 @@ func (f *FaultDisputeGameContract) StepTx(claimIdx uint64, isAttack bool, stateD func (f *FaultDisputeGameContract) CallResolveClaim(ctx context.Context, claimIdx uint64) error { call := f.resolveClaimCall(claimIdx) - _, err := f.multiCaller.SingleCall(ctx, batching.BlockLatest, call) + _, err := f.multiCaller.SingleCall(ctx, rpcblock.Latest, call) if err != nil { return fmt.Errorf("failed to call resolve claim: %w", err) } @@ -314,7 +315,7 @@ func (f *FaultDisputeGameContract) resolveClaimCall(claimIdx uint64) *batching.C func (f *FaultDisputeGameContract) CallResolve(ctx context.Context) (gameTypes.GameStatus, error) { call := f.resolveCall() - result, err := f.multiCaller.SingleCall(ctx, batching.BlockLatest, call) + result, err := f.multiCaller.SingleCall(ctx, rpcblock.Latest, call) if err != nil { return gameTypes.GameStatusInProgress, fmt.Errorf("failed to call resolve: %w", err) } diff --git a/op-challenger/game/fault/contracts/faultdisputegame_test.go b/op-challenger/game/fault/contracts/faultdisputegame_test.go index 3fdf83d179e5..547de4602232 100644 --- a/op-challenger/game/fault/contracts/faultdisputegame_test.go +++ b/op-challenger/game/fault/contracts/faultdisputegame_test.go @@ -10,6 +10,7 @@ import ( faultTypes "github.com/ethereum-optimism/optimism/op-challenger/game/fault/types" "github.com/ethereum-optimism/optimism/op-challenger/game/types" "github.com/ethereum-optimism/optimism/op-service/sources/batching" + "github.com/ethereum-optimism/optimism/op-service/sources/batching/rpcblock" batchingTest "github.com/ethereum-optimism/optimism/op-service/sources/batching/test" "github.com/ethereum/go-ethereum/common" "github.com/stretchr/testify/require" @@ -93,7 +94,7 @@ func TestSimpleGetters(t *testing.T) { test := test t.Run(test.methodAlias, func(t *testing.T) { stubRpc, game := setupFaultDisputeGameTest(t) - stubRpc.SetResponse(fdgAddr, test.method, batching.BlockLatest, nil, []interface{}{test.result}) + stubRpc.SetResponse(fdgAddr, test.method, rpcblock.Latest, nil, []interface{}{test.result}) status, err := test.call(game) require.NoError(t, err) expected := test.expected @@ -145,8 +146,8 @@ func TestClock_EncodingDecoding(t *testing.T) { func TestGetOracleAddr(t *testing.T) { stubRpc, game := setupFaultDisputeGameTest(t) - stubRpc.SetResponse(fdgAddr, methodVM, batching.BlockLatest, nil, []interface{}{vmAddr}) - stubRpc.SetResponse(vmAddr, methodOracle, batching.BlockLatest, nil, []interface{}{oracleAddr}) + stubRpc.SetResponse(fdgAddr, methodVM, rpcblock.Latest, nil, []interface{}{vmAddr}) + stubRpc.SetResponse(vmAddr, methodOracle, rpcblock.Latest, nil, []interface{}{oracleAddr}) actual, err := game.GetOracle(context.Background()) require.NoError(t, err) @@ -163,7 +164,7 @@ func TestGetClaim(t *testing.T) { value := common.Hash{0xab} position := big.NewInt(2) clock := big.NewInt(1234) - stubRpc.SetResponse(fdgAddr, methodClaim, batching.BlockLatest, []interface{}{idx}, []interface{}{parentIndex, counteredBy, claimant, bond, value, position, clock}) + stubRpc.SetResponse(fdgAddr, methodClaim, rpcblock.Latest, []interface{}{idx}, []interface{}{parentIndex, counteredBy, claimant, bond, value, position, clock}) status, err := game.GetClaim(context.Background(), idx.Uint64()) require.NoError(t, err) require.Equal(t, faultTypes.Claim{ @@ -218,7 +219,7 @@ func TestGetAllClaims(t *testing.T) { ParentContractIndex: 1, } expectedClaims := []faultTypes.Claim{claim0, claim1, claim2} - stubRpc.SetResponse(fdgAddr, methodClaimCount, batching.BlockLatest, nil, []interface{}{big.NewInt(int64(len(expectedClaims)))}) + stubRpc.SetResponse(fdgAddr, methodClaimCount, rpcblock.Latest, nil, []interface{}{big.NewInt(int64(len(expectedClaims)))}) for _, claim := range expectedClaims { expectGetClaim(stubRpc, claim) } @@ -229,14 +230,14 @@ func TestGetAllClaims(t *testing.T) { func TestCallResolveClaim(t *testing.T) { stubRpc, game := setupFaultDisputeGameTest(t) - stubRpc.SetResponse(fdgAddr, methodResolveClaim, batching.BlockLatest, []interface{}{big.NewInt(123)}, nil) + stubRpc.SetResponse(fdgAddr, methodResolveClaim, rpcblock.Latest, []interface{}{big.NewInt(123)}, nil) err := game.CallResolveClaim(context.Background(), 123) require.NoError(t, err) } func TestResolveClaimTxTest(t *testing.T) { stubRpc, game := setupFaultDisputeGameTest(t) - stubRpc.SetResponse(fdgAddr, methodResolveClaim, batching.BlockLatest, []interface{}{big.NewInt(123)}, nil) + stubRpc.SetResponse(fdgAddr, methodResolveClaim, rpcblock.Latest, []interface{}{big.NewInt(123)}, nil) tx, err := game.ResolveClaimTx(123) require.NoError(t, err) stubRpc.VerifyTxCandidate(tx) @@ -244,7 +245,7 @@ func TestResolveClaimTxTest(t *testing.T) { func TestResolveTx(t *testing.T) { stubRpc, game := setupFaultDisputeGameTest(t) - stubRpc.SetResponse(fdgAddr, methodResolve, batching.BlockLatest, nil, nil) + stubRpc.SetResponse(fdgAddr, methodResolve, rpcblock.Latest, nil, nil) tx, err := game.ResolveTx() require.NoError(t, err) stubRpc.VerifyTxCandidate(tx) @@ -253,7 +254,7 @@ func TestResolveTx(t *testing.T) { func TestAttackTx(t *testing.T) { stubRpc, game := setupFaultDisputeGameTest(t) value := common.Hash{0xaa} - stubRpc.SetResponse(fdgAddr, methodAttack, batching.BlockLatest, []interface{}{big.NewInt(111), value}, nil) + stubRpc.SetResponse(fdgAddr, methodAttack, rpcblock.Latest, []interface{}{big.NewInt(111), value}, nil) tx, err := game.AttackTx(111, value) require.NoError(t, err) stubRpc.VerifyTxCandidate(tx) @@ -262,7 +263,7 @@ func TestAttackTx(t *testing.T) { func TestDefendTx(t *testing.T) { stubRpc, game := setupFaultDisputeGameTest(t) value := common.Hash{0xaa} - stubRpc.SetResponse(fdgAddr, methodDefend, batching.BlockLatest, []interface{}{big.NewInt(111), value}, nil) + stubRpc.SetResponse(fdgAddr, methodDefend, rpcblock.Latest, []interface{}{big.NewInt(111), value}, nil) tx, err := game.DefendTx(111, value) require.NoError(t, err) stubRpc.VerifyTxCandidate(tx) @@ -272,7 +273,7 @@ func TestStepTx(t *testing.T) { stubRpc, game := setupFaultDisputeGameTest(t) stateData := []byte{1, 2, 3} proofData := []byte{4, 5, 6, 7, 8, 9} - stubRpc.SetResponse(fdgAddr, methodStep, batching.BlockLatest, []interface{}{big.NewInt(111), true, stateData, proofData}, nil) + stubRpc.SetResponse(fdgAddr, methodStep, rpcblock.Latest, []interface{}{big.NewInt(111), true, stateData, proofData}, nil) tx, err := game.StepTx(111, true, stateData, proofData) require.NoError(t, err) stubRpc.VerifyTxCandidate(tx) @@ -282,7 +283,7 @@ func expectGetClaim(stubRpc *batchingTest.AbiBasedRpc, claim faultTypes.Claim) { stubRpc.SetResponse( fdgAddr, methodClaim, - batching.BlockLatest, + rpcblock.Latest, []interface{}{big.NewInt(int64(claim.ContractIndex))}, []interface{}{ uint32(claim.ParentContractIndex), @@ -299,8 +300,8 @@ func TestGetBlockRange(t *testing.T) { stubRpc, contract := setupFaultDisputeGameTest(t) expectedStart := uint64(65) expectedEnd := uint64(102) - stubRpc.SetResponse(fdgAddr, methodGenesisBlockNumber, batching.BlockLatest, nil, []interface{}{new(big.Int).SetUint64(expectedStart)}) - stubRpc.SetResponse(fdgAddr, methodL2BlockNumber, batching.BlockLatest, nil, []interface{}{new(big.Int).SetUint64(expectedEnd)}) + stubRpc.SetResponse(fdgAddr, methodGenesisBlockNumber, rpcblock.Latest, nil, []interface{}{new(big.Int).SetUint64(expectedStart)}) + stubRpc.SetResponse(fdgAddr, methodL2BlockNumber, rpcblock.Latest, nil, []interface{}{new(big.Int).SetUint64(expectedEnd)}) start, end, err := contract.GetBlockRange(context.Background()) require.NoError(t, err) require.Equal(t, expectedStart, start) @@ -310,7 +311,7 @@ func TestGetBlockRange(t *testing.T) { func TestGetSplitDepth(t *testing.T) { stubRpc, contract := setupFaultDisputeGameTest(t) expectedSplitDepth := faultTypes.Depth(15) - stubRpc.SetResponse(fdgAddr, methodSplitDepth, batching.BlockLatest, nil, []interface{}{new(big.Int).SetUint64(uint64(expectedSplitDepth))}) + stubRpc.SetResponse(fdgAddr, methodSplitDepth, rpcblock.Latest, nil, []interface{}{new(big.Int).SetUint64(uint64(expectedSplitDepth))}) splitDepth, err := contract.GetSplitDepth(context.Background()) require.NoError(t, err) require.Equal(t, expectedSplitDepth, splitDepth) @@ -322,10 +323,10 @@ func TestGetGameMetadata(t *testing.T) { expectedGameDuration := uint64(456) expectedRootClaim := common.Hash{0x01, 0x02} expectedStatus := types.GameStatusChallengerWon - stubRpc.SetResponse(fdgAddr, methodL2BlockNumber, batching.BlockLatest, nil, []interface{}{new(big.Int).SetUint64(expectedL2BlockNumber)}) - stubRpc.SetResponse(fdgAddr, methodRootClaim, batching.BlockLatest, nil, []interface{}{expectedRootClaim}) - stubRpc.SetResponse(fdgAddr, methodStatus, batching.BlockLatest, nil, []interface{}{expectedStatus}) - stubRpc.SetResponse(fdgAddr, methodGameDuration, batching.BlockLatest, nil, []interface{}{expectedGameDuration}) + stubRpc.SetResponse(fdgAddr, methodL2BlockNumber, rpcblock.Latest, nil, []interface{}{new(big.Int).SetUint64(expectedL2BlockNumber)}) + stubRpc.SetResponse(fdgAddr, methodRootClaim, rpcblock.Latest, nil, []interface{}{expectedRootClaim}) + stubRpc.SetResponse(fdgAddr, methodStatus, rpcblock.Latest, nil, []interface{}{expectedStatus}) + stubRpc.SetResponse(fdgAddr, methodGameDuration, rpcblock.Latest, nil, []interface{}{expectedGameDuration}) l2BlockNumber, rootClaim, status, duration, err := contract.GetGameMetadata(context.Background()) require.NoError(t, err) require.Equal(t, expectedL2BlockNumber, l2BlockNumber) @@ -337,7 +338,7 @@ func TestGetGameMetadata(t *testing.T) { func TestGetGenesisOutputRoot(t *testing.T) { stubRpc, contract := setupFaultDisputeGameTest(t) expectedOutputRoot := common.HexToHash("0x1234") - stubRpc.SetResponse(fdgAddr, methodGenesisOutputRoot, batching.BlockLatest, nil, []interface{}{expectedOutputRoot}) + stubRpc.SetResponse(fdgAddr, methodGenesisOutputRoot, rpcblock.Latest, nil, []interface{}{expectedOutputRoot}) genesisOutputRoot, err := contract.GetGenesisOutputRoot(context.Background()) require.NoError(t, err) require.Equal(t, expectedOutputRoot, genesisOutputRoot) @@ -348,7 +349,7 @@ func TestFaultDisputeGame_UpdateOracleTx(t *testing.T) { stubRpc, game := setupFaultDisputeGameTest(t) data := faultTypes.NewPreimageOracleData(common.Hash{0x01, 0xbc}.Bytes(), []byte{1, 2, 3, 4, 5, 6, 7}, 16) claimIdx := uint64(6) - stubRpc.SetResponse(fdgAddr, methodAddLocalData, batching.BlockLatest, []interface{}{ + stubRpc.SetResponse(fdgAddr, methodAddLocalData, rpcblock.Latest, []interface{}{ data.GetIdent(), new(big.Int).SetUint64(claimIdx), new(big.Int).SetUint64(uint64(data.OracleOffset)), @@ -362,9 +363,9 @@ func TestFaultDisputeGame_UpdateOracleTx(t *testing.T) { stubRpc, game := setupFaultDisputeGameTest(t) data := faultTypes.NewPreimageOracleData(common.Hash{0x02, 0xbc}.Bytes(), []byte{1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 12, 13, 14, 15}, 16) claimIdx := uint64(6) - stubRpc.SetResponse(fdgAddr, methodVM, batching.BlockLatest, nil, []interface{}{vmAddr}) - stubRpc.SetResponse(vmAddr, methodOracle, batching.BlockLatest, nil, []interface{}{oracleAddr}) - stubRpc.SetResponse(oracleAddr, methodLoadKeccak256PreimagePart, batching.BlockLatest, []interface{}{ + stubRpc.SetResponse(fdgAddr, methodVM, rpcblock.Latest, nil, []interface{}{vmAddr}) + stubRpc.SetResponse(vmAddr, methodOracle, rpcblock.Latest, nil, []interface{}{oracleAddr}) + stubRpc.SetResponse(oracleAddr, methodLoadKeccak256PreimagePart, rpcblock.Latest, []interface{}{ new(big.Int).SetUint64(uint64(data.OracleOffset)), data.GetPreimageWithoutSize(), }, nil) @@ -379,8 +380,8 @@ func TestFaultDisputeGame_GetCredit(t *testing.T) { addr := common.Address{0x01} expectedCredit := big.NewInt(4284) expectedStatus := types.GameStatusChallengerWon - stubRpc.SetResponse(fdgAddr, methodCredit, batching.BlockLatest, []interface{}{addr}, []interface{}{expectedCredit}) - stubRpc.SetResponse(fdgAddr, methodStatus, batching.BlockLatest, nil, []interface{}{expectedStatus}) + stubRpc.SetResponse(fdgAddr, methodCredit, rpcblock.Latest, []interface{}{addr}, []interface{}{expectedCredit}) + stubRpc.SetResponse(fdgAddr, methodStatus, rpcblock.Latest, nil, []interface{}{expectedStatus}) actualCredit, actualStatus, err := game.GetCredit(context.Background(), addr) require.NoError(t, err) @@ -391,7 +392,7 @@ func TestFaultDisputeGame_GetCredit(t *testing.T) { func TestFaultDisputeGame_GetCredits(t *testing.T) { stubRpc, game := setupFaultDisputeGameTest(t) - block := batching.BlockByNumber(482) + block := rpcblock.ByNumber(482) addrs := []common.Address{{0x01}, {0x02}, {0x03}} expected := []*big.Int{big.NewInt(1), big.NewInt(2), big.NewInt(0)} diff --git a/op-challenger/game/fault/contracts/gamefactory.go b/op-challenger/game/fault/contracts/gamefactory.go index 18fab1f2a567..346a0eea7390 100644 --- a/op-challenger/game/fault/contracts/gamefactory.go +++ b/op-challenger/game/fault/contracts/gamefactory.go @@ -8,6 +8,7 @@ import ( "github.com/ethereum-optimism/optimism/op-bindings/bindings" "github.com/ethereum-optimism/optimism/op-challenger/game/types" "github.com/ethereum-optimism/optimism/op-service/sources/batching" + "github.com/ethereum-optimism/optimism/op-service/sources/batching/rpcblock" "github.com/ethereum-optimism/optimism/op-service/txmgr" "github.com/ethereum/go-ethereum/common" ) @@ -37,7 +38,7 @@ func NewDisputeGameFactoryContract(addr common.Address, caller *batching.MultiCa } func (f *DisputeGameFactoryContract) GetGameFromParameters(ctx context.Context, traceType uint32, outputRoot common.Hash, l2BlockNum uint64) (common.Address, error) { - result, err := f.multiCaller.SingleCall(ctx, batching.BlockLatest, f.contract.Call(methodGames, traceType, outputRoot, common.BigToHash(big.NewInt(int64(l2BlockNum))).Bytes())) + result, err := f.multiCaller.SingleCall(ctx, rpcblock.Latest, f.contract.Call(methodGames, traceType, outputRoot, common.BigToHash(big.NewInt(int64(l2BlockNum))).Bytes())) if err != nil { return common.Address{}, fmt.Errorf("failed to fetch game from parameters: %w", err) } @@ -45,7 +46,7 @@ func (f *DisputeGameFactoryContract) GetGameFromParameters(ctx context.Context, } func (f *DisputeGameFactoryContract) GetGameCount(ctx context.Context, blockHash common.Hash) (uint64, error) { - result, err := f.multiCaller.SingleCall(ctx, batching.BlockByHash(blockHash), f.contract.Call(methodGameCount)) + result, err := f.multiCaller.SingleCall(ctx, rpcblock.ByHash(blockHash), f.contract.Call(methodGameCount)) if err != nil { return 0, fmt.Errorf("failed to load game count: %w", err) } @@ -53,7 +54,7 @@ func (f *DisputeGameFactoryContract) GetGameCount(ctx context.Context, blockHash } func (f *DisputeGameFactoryContract) GetGame(ctx context.Context, idx uint64, blockHash common.Hash) (types.GameMetadata, error) { - result, err := f.multiCaller.SingleCall(ctx, batching.BlockByHash(blockHash), f.contract.Call(methodGameAtIndex, new(big.Int).SetUint64(idx))) + result, err := f.multiCaller.SingleCall(ctx, rpcblock.ByHash(blockHash), f.contract.Call(methodGameAtIndex, new(big.Int).SetUint64(idx))) if err != nil { return types.GameMetadata{}, fmt.Errorf("failed to load game %v: %w", idx, err) } @@ -61,7 +62,7 @@ func (f *DisputeGameFactoryContract) GetGame(ctx context.Context, idx uint64, bl } func (f *DisputeGameFactoryContract) GetGameImpl(ctx context.Context, gameType uint32) (common.Address, error) { - result, err := f.multiCaller.SingleCall(ctx, batching.BlockLatest, f.contract.Call(methodGameImpls, gameType)) + result, err := f.multiCaller.SingleCall(ctx, rpcblock.Latest, f.contract.Call(methodGameImpls, gameType)) if err != nil { return common.Address{}, fmt.Errorf("failed to load game impl for type %v: %w", gameType, err) } @@ -95,7 +96,7 @@ func (f *DisputeGameFactoryContract) GetGamesAtOrAfter(ctx context.Context, bloc } } - results, err := f.multiCaller.Call(ctx, batching.BlockByHash(blockHash), calls...) + results, err := f.multiCaller.Call(ctx, rpcblock.ByHash(blockHash), calls...) if err != nil { return nil, fmt.Errorf("failed to fetch games: %w", err) } @@ -122,7 +123,7 @@ func (f *DisputeGameFactoryContract) GetAllGames(ctx context.Context, blockHash calls[i] = f.contract.Call(methodGameAtIndex, new(big.Int).SetUint64(i)) } - results, err := f.multiCaller.Call(ctx, batching.BlockByHash(blockHash), calls...) + results, err := f.multiCaller.Call(ctx, rpcblock.ByHash(blockHash), calls...) if err != nil { return nil, fmt.Errorf("failed to fetch games: %w", err) } diff --git a/op-challenger/game/fault/contracts/gamefactory_test.go b/op-challenger/game/fault/contracts/gamefactory_test.go index ca2576c4f602..f7f98760eebb 100644 --- a/op-challenger/game/fault/contracts/gamefactory_test.go +++ b/op-challenger/game/fault/contracts/gamefactory_test.go @@ -10,6 +10,7 @@ import ( "github.com/ethereum-optimism/optimism/op-bindings/bindings" "github.com/ethereum-optimism/optimism/op-challenger/game/types" "github.com/ethereum-optimism/optimism/op-service/sources/batching" + "github.com/ethereum-optimism/optimism/op-service/sources/batching/rpcblock" batchingTest "github.com/ethereum-optimism/optimism/op-service/sources/batching/test" "github.com/ethereum/go-ethereum/common" "github.com/stretchr/testify/require" @@ -42,7 +43,7 @@ func TestDisputeGameFactorySimpleGetters(t *testing.T) { test := test t.Run(test.method, func(t *testing.T) { stubRpc, factory := setupDisputeGameFactoryTest(t) - stubRpc.SetResponse(factoryAddr, test.method, batching.BlockByHash(blockHash), nil, []interface{}{test.result}) + stubRpc.SetResponse(factoryAddr, test.method, rpcblock.ByHash(blockHash), nil, []interface{}{test.result}) status, err := test.call(factory) require.NoError(t, err) expected := test.expected @@ -101,7 +102,7 @@ func TestGetAllGames(t *testing.T) { } expectedGames := []types.GameMetadata{game0, game1, game2} - stubRpc.SetResponse(factoryAddr, methodGameCount, batching.BlockByHash(blockHash), nil, []interface{}{big.NewInt(int64(len(expectedGames)))}) + stubRpc.SetResponse(factoryAddr, methodGameCount, rpcblock.ByHash(blockHash), nil, []interface{}{big.NewInt(int64(len(expectedGames)))}) for idx, expected := range expectedGames { expectGetGame(stubRpc, idx, blockHash, expected) } @@ -138,7 +139,7 @@ func TestGetAllGamesAtOrAfter(t *testing.T) { }) } - stubRpc.SetResponse(factoryAddr, methodGameCount, batching.BlockByHash(blockHash), nil, []interface{}{big.NewInt(int64(len(allGames)))}) + stubRpc.SetResponse(factoryAddr, methodGameCount, rpcblock.ByHash(blockHash), nil, []interface{}{big.NewInt(int64(len(allGames)))}) for idx, expected := range allGames { expectGetGame(stubRpc, idx, blockHash, expected) } @@ -169,7 +170,7 @@ func TestGetGameFromParameters(t *testing.T) { stubRpc.SetResponse( factoryAddr, methodGames, - batching.BlockLatest, + rpcblock.Latest, []interface{}{traceType, outputRoot, l2BlockNum}, []interface{}{common.Address{0xaa}, uint64(1)}, ) @@ -185,7 +186,7 @@ func TestGetGameImpl(t *testing.T) { stubRpc.SetResponse( factoryAddr, methodGameImpls, - batching.BlockLatest, + rpcblock.Latest, []interface{}{gameType}, []interface{}{gameImplAddr}) actual, err := factory.GetGameImpl(context.Background(), gameType) @@ -197,7 +198,7 @@ func expectGetGame(stubRpc *batchingTest.AbiBasedRpc, idx int, blockHash common. stubRpc.SetResponse( factoryAddr, methodGameAtIndex, - batching.BlockByHash(blockHash), + rpcblock.ByHash(blockHash), []interface{}{big.NewInt(int64(idx))}, []interface{}{ game.GameType, @@ -211,7 +212,7 @@ func TestCreateTx(t *testing.T) { traceType := uint32(123) outputRoot := common.Hash{0x01} l2BlockNum := common.BigToHash(big.NewInt(456)).Bytes() - stubRpc.SetResponse(factoryAddr, methodCreateGame, batching.BlockLatest, []interface{}{traceType, outputRoot, l2BlockNum}, nil) + stubRpc.SetResponse(factoryAddr, methodCreateGame, rpcblock.Latest, []interface{}{traceType, outputRoot, l2BlockNum}, nil) tx, err := factory.CreateTx(traceType, outputRoot, uint64(456)) require.NoError(t, err) stubRpc.VerifyTxCandidate(tx) diff --git a/op-challenger/game/fault/contracts/oracle.go b/op-challenger/game/fault/contracts/oracle.go index 784a3869726d..4524034cffe9 100644 --- a/op-challenger/game/fault/contracts/oracle.go +++ b/op-challenger/game/fault/contracts/oracle.go @@ -15,6 +15,7 @@ import ( keccakTypes "github.com/ethereum-optimism/optimism/op-challenger/game/keccak/types" preimage "github.com/ethereum-optimism/optimism/op-preimage" "github.com/ethereum-optimism/optimism/op-service/sources/batching" + "github.com/ethereum-optimism/optimism/op-service/sources/batching/rpcblock" "github.com/ethereum-optimism/optimism/op-service/txmgr" "github.com/ethereum/go-ethereum/common" ) @@ -130,7 +131,7 @@ func (c *PreimageOracleContract) AddLeaves(uuid *big.Int, startingBlockIndex *bi // MinLargePreimageSize returns the minimum size of a large preimage. func (c *PreimageOracleContract) MinLargePreimageSize(ctx context.Context) (uint64, error) { - result, err := c.multiCaller.SingleCall(ctx, batching.BlockLatest, c.contract.Call(methodMinProposalSize)) + result, err := c.multiCaller.SingleCall(ctx, rpcblock.Latest, c.contract.Call(methodMinProposalSize)) if err != nil { return 0, fmt.Errorf("failed to fetch min lpp size bytes: %w", err) } @@ -142,7 +143,7 @@ func (c *PreimageOracleContract) ChallengePeriod(ctx context.Context) (uint64, e if period := c.challengePeriod.Load(); period != 0 { return period, nil } - result, err := c.multiCaller.SingleCall(ctx, batching.BlockLatest, c.contract.Call(methodChallengePeriod)) + result, err := c.multiCaller.SingleCall(ctx, rpcblock.Latest, c.contract.Call(methodChallengePeriod)) if err != nil { return 0, fmt.Errorf("failed to fetch challenge period: %w", err) } @@ -162,7 +163,7 @@ func (c *PreimageOracleContract) CallSqueeze( postStateProof merkle.Proof, ) error { call := c.contract.Call(methodSqueezeLPP, claimant, uuid, abiEncodeSnapshot(prestateMatrix), toPreimageOracleLeaf(preState), preStateProof, toPreimageOracleLeaf(postState), postStateProof) - _, err := c.multiCaller.SingleCall(ctx, batching.BlockLatest, call) + _, err := c.multiCaller.SingleCall(ctx, rpcblock.Latest, call) if err != nil { return fmt.Errorf("failed to call squeeze: %w", err) } @@ -196,7 +197,7 @@ func abiEncodeSnapshot(packedState keccakTypes.StateSnapshot) bindings.LibKeccak } func (c *PreimageOracleContract) GetActivePreimages(ctx context.Context, blockHash common.Hash) ([]keccakTypes.LargePreimageMetaData, error) { - block := batching.BlockByHash(blockHash) + block := rpcblock.ByHash(blockHash) results, err := batching.ReadArray(ctx, c.multiCaller, block, c.contract.Call(methodProposalCount), func(i *big.Int) *batching.ContractCall { return c.contract.Call(methodProposals, i) }) @@ -212,7 +213,7 @@ func (c *PreimageOracleContract) GetActivePreimages(ctx context.Context, blockHa return c.GetProposalMetadata(ctx, block, idents...) } -func (c *PreimageOracleContract) GetProposalMetadata(ctx context.Context, block batching.Block, idents ...keccakTypes.LargePreimageIdent) ([]keccakTypes.LargePreimageMetaData, error) { +func (c *PreimageOracleContract) GetProposalMetadata(ctx context.Context, block rpcblock.Block, idents ...keccakTypes.LargePreimageIdent) ([]keccakTypes.LargePreimageMetaData, error) { var calls []batching.Call for _, ident := range idents { calls = append(calls, c.contract.Call(methodProposalMetadata, ident.Claimant, ident.UUID)) @@ -237,7 +238,7 @@ func (c *PreimageOracleContract) GetProposalMetadata(ctx context.Context, block return proposals, nil } -func (c *PreimageOracleContract) GetProposalTreeRoot(ctx context.Context, block batching.Block, ident keccakTypes.LargePreimageIdent) (common.Hash, error) { +func (c *PreimageOracleContract) GetProposalTreeRoot(ctx context.Context, block rpcblock.Block, ident keccakTypes.LargePreimageIdent) (common.Hash, error) { call := c.contract.Call(methodGetTreeRootLPP, ident.Claimant, ident.UUID) result, err := c.multiCaller.SingleCall(ctx, block, call) if err != nil { @@ -246,7 +247,7 @@ func (c *PreimageOracleContract) GetProposalTreeRoot(ctx context.Context, block return result.GetHash(0), nil } -func (c *PreimageOracleContract) GetInputDataBlocks(ctx context.Context, block batching.Block, ident keccakTypes.LargePreimageIdent) ([]uint64, error) { +func (c *PreimageOracleContract) GetInputDataBlocks(ctx context.Context, block rpcblock.Block, ident keccakTypes.LargePreimageIdent) ([]uint64, error) { results, err := batching.ReadArray(ctx, c.multiCaller, block, c.contract.Call(methodProposalBlocksLen, ident.Claimant, ident.UUID), func(i *big.Int) *batching.ContractCall { @@ -295,7 +296,7 @@ func (c *PreimageOracleContract) DecodeInputData(data []byte) (*big.Int, keccakT func (c *PreimageOracleContract) GlobalDataExists(ctx context.Context, data *types.PreimageOracleData) (bool, error) { call := c.contract.Call(methodPreimagePartOk, common.Hash(data.OracleKey), new(big.Int).SetUint64(uint64(data.OracleOffset))) - results, err := c.multiCaller.SingleCall(ctx, batching.BlockLatest, call) + results, err := c.multiCaller.SingleCall(ctx, rpcblock.Latest, call) if err != nil { return false, fmt.Errorf("failed to get preimagePartOk: %w", err) } @@ -329,7 +330,7 @@ func (c *PreimageOracleContract) GetMinBondLPP(ctx context.Context) (*big.Int, e if bondSize := c.minBondSizeLPP.Load(); bondSize != 0 { return big.NewInt(int64(bondSize)), nil } - result, err := c.multiCaller.SingleCall(ctx, batching.BlockLatest, c.contract.Call(methodMinBondSizeLPP)) + result, err := c.multiCaller.SingleCall(ctx, rpcblock.Latest, c.contract.Call(methodMinBondSizeLPP)) if err != nil { return nil, fmt.Errorf("failed to fetch min bond size for LPPs: %w", err) } diff --git a/op-challenger/game/fault/contracts/oracle_test.go b/op-challenger/game/fault/contracts/oracle_test.go index 29189ec86365..0a65b239aef4 100644 --- a/op-challenger/game/fault/contracts/oracle_test.go +++ b/op-challenger/game/fault/contracts/oracle_test.go @@ -14,6 +14,7 @@ import ( keccakTypes "github.com/ethereum-optimism/optimism/op-challenger/game/keccak/types" preimage "github.com/ethereum-optimism/optimism/op-preimage" "github.com/ethereum-optimism/optimism/op-service/sources/batching" + "github.com/ethereum-optimism/optimism/op-service/sources/batching/rpcblock" batchingTest "github.com/ethereum-optimism/optimism/op-service/sources/batching/test" "github.com/ethereum-optimism/optimism/op-service/testutils" "github.com/ethereum/go-ethereum/common" @@ -31,7 +32,7 @@ func TestPreimageOracleContract_AddGlobalDataTx(t *testing.T) { t.Run("Keccak256", func(t *testing.T) { stubRpc, oracle := setupPreimageOracleTest(t) data := types.NewPreimageOracleData(common.Hash{byte(preimage.Keccak256KeyType), 0xcc}.Bytes(), make([]byte, 20), uint32(545)) - stubRpc.SetResponse(oracleAddr, methodLoadKeccak256PreimagePart, batching.BlockLatest, []interface{}{ + stubRpc.SetResponse(oracleAddr, methodLoadKeccak256PreimagePart, rpcblock.Latest, []interface{}{ new(big.Int).SetUint64(uint64(data.OracleOffset)), data.GetPreimageWithoutSize(), }, nil) @@ -44,7 +45,7 @@ func TestPreimageOracleContract_AddGlobalDataTx(t *testing.T) { t.Run("Sha256", func(t *testing.T) { stubRpc, oracle := setupPreimageOracleTest(t) data := types.NewPreimageOracleData(common.Hash{byte(preimage.Sha256KeyType), 0xcc}.Bytes(), make([]byte, 20), uint32(545)) - stubRpc.SetResponse(oracleAddr, methodLoadSha256PreimagePart, batching.BlockLatest, []interface{}{ + stubRpc.SetResponse(oracleAddr, methodLoadSha256PreimagePart, rpcblock.Latest, []interface{}{ new(big.Int).SetUint64(uint64(data.OracleOffset)), data.GetPreimageWithoutSize(), }, nil) @@ -58,7 +59,7 @@ func TestPreimageOracleContract_AddGlobalDataTx(t *testing.T) { stubRpc, oracle := setupPreimageOracleTest(t) fieldData := testutils.RandomData(rand.New(rand.NewSource(23)), 32) data := types.NewPreimageOracleData(common.Hash{byte(preimage.BlobKeyType), 0xcc}.Bytes(), fieldData, uint32(545)) - stubRpc.SetResponse(oracleAddr, methodLoadBlobPreimagePart, batching.BlockLatest, []interface{}{ + stubRpc.SetResponse(oracleAddr, methodLoadBlobPreimagePart, rpcblock.Latest, []interface{}{ new(big.Int).SetUint64(data.BlobFieldIndex), new(big.Int).SetBytes(data.GetPreimageWithoutSize()), data.BlobCommitment, @@ -75,7 +76,7 @@ func TestPreimageOracleContract_AddGlobalDataTx(t *testing.T) { stubRpc, oracle := setupPreimageOracleTest(t) input := testutils.RandomData(rand.New(rand.NewSource(23)), 200) data := types.NewPreimageOracleData(common.Hash{byte(preimage.PrecompileKeyType), 0xcc}.Bytes(), input, uint32(545)) - stubRpc.SetResponse(oracleAddr, methodLoadPrecompilePreimagePart, batching.BlockLatest, []interface{}{ + stubRpc.SetResponse(oracleAddr, methodLoadPrecompilePreimagePart, rpcblock.Latest, []interface{}{ new(big.Int).SetUint64(uint64(data.OracleOffset)), data.GetPrecompileAddress(), data.GetPrecompileInput(), @@ -89,7 +90,7 @@ func TestPreimageOracleContract_AddGlobalDataTx(t *testing.T) { func TestPreimageOracleContract_ChallengePeriod(t *testing.T) { stubRpc, oracle := setupPreimageOracleTest(t) - stubRpc.SetResponse(oracleAddr, methodChallengePeriod, batching.BlockLatest, + stubRpc.SetResponse(oracleAddr, methodChallengePeriod, rpcblock.Latest, []interface{}{}, []interface{}{big.NewInt(123)}, ) @@ -106,7 +107,7 @@ func TestPreimageOracleContract_ChallengePeriod(t *testing.T) { func TestPreimageOracleContract_MinLargePreimageSize(t *testing.T) { stubRpc, oracle := setupPreimageOracleTest(t) - stubRpc.SetResponse(oracleAddr, methodMinProposalSize, batching.BlockLatest, + stubRpc.SetResponse(oracleAddr, methodMinProposalSize, rpcblock.Latest, []interface{}{}, []interface{}{big.NewInt(123)}, ) @@ -117,7 +118,7 @@ func TestPreimageOracleContract_MinLargePreimageSize(t *testing.T) { func TestPreimageOracleContract_MinBondSizeLPP(t *testing.T) { stubRpc, oracle := setupPreimageOracleTest(t) - stubRpc.SetResponse(oracleAddr, methodMinBondSizeLPP, batching.BlockLatest, + stubRpc.SetResponse(oracleAddr, methodMinBondSizeLPP, rpcblock.Latest, []interface{}{}, []interface{}{big.NewInt(123)}, ) @@ -136,7 +137,7 @@ func TestPreimageOracleContract_PreimageDataExists(t *testing.T) { t.Run("exists", func(t *testing.T) { stubRpc, oracle := setupPreimageOracleTest(t) data := types.NewPreimageOracleData(common.Hash{0xcc}.Bytes(), make([]byte, 20), 545) - stubRpc.SetResponse(oracleAddr, methodPreimagePartOk, batching.BlockLatest, + stubRpc.SetResponse(oracleAddr, methodPreimagePartOk, rpcblock.Latest, []interface{}{common.Hash(data.OracleKey), new(big.Int).SetUint64(uint64(data.OracleOffset))}, []interface{}{true}, ) @@ -147,7 +148,7 @@ func TestPreimageOracleContract_PreimageDataExists(t *testing.T) { t.Run("does not exist", func(t *testing.T) { stubRpc, oracle := setupPreimageOracleTest(t) data := types.NewPreimageOracleData(common.Hash{0xcc}.Bytes(), make([]byte, 20), 545) - stubRpc.SetResponse(oracleAddr, methodPreimagePartOk, batching.BlockLatest, + stubRpc.SetResponse(oracleAddr, methodPreimagePartOk, rpcblock.Latest, []interface{}{common.Hash(data.OracleKey), new(big.Int).SetUint64(uint64(data.OracleOffset))}, []interface{}{false}, ) @@ -163,7 +164,7 @@ func TestPreimageOracleContract_InitLargePreimage(t *testing.T) { uuid := big.NewInt(123) partOffset := uint32(1) claimedSize := uint32(2) - stubRpc.SetResponse(oracleAddr, methodInitLPP, batching.BlockLatest, []interface{}{ + stubRpc.SetResponse(oracleAddr, methodInitLPP, rpcblock.Latest, []interface{}{ uuid, partOffset, claimedSize, @@ -182,7 +183,7 @@ func TestPreimageOracleContract_AddLeaves(t *testing.T) { input := []byte{0x12} commitments := []common.Hash{{0x34}} finalize := true - stubRpc.SetResponse(oracleAddr, methodAddLeavesLPP, batching.BlockLatest, []interface{}{ + stubRpc.SetResponse(oracleAddr, methodAddLeavesLPP, rpcblock.Latest, []interface{}{ uuid, startingBlockIndex, input, @@ -213,7 +214,7 @@ func TestPreimageOracleContract_Squeeze(t *testing.T) { StateCommitment: common.Hash{0x56}, } postStateProof := merkle.Proof{{0x56}} - stubRpc.SetResponse(oracleAddr, methodSqueezeLPP, batching.BlockLatest, []interface{}{ + stubRpc.SetResponse(oracleAddr, methodSqueezeLPP, rpcblock.Latest, []interface{}{ claimant, uuid, abiEncodeSnapshot(preStateMatrix), @@ -230,7 +231,7 @@ func TestPreimageOracleContract_Squeeze(t *testing.T) { func TestGetActivePreimages(t *testing.T) { blockHash := common.Hash{0xaa} - _, oracle, proposals := setupPreimageOracleTestWithProposals(t, batching.BlockByHash(blockHash)) + _, oracle, proposals := setupPreimageOracleTestWithProposals(t, rpcblock.ByHash(blockHash)) preimages, err := oracle.GetActivePreimages(context.Background(), blockHash) require.NoError(t, err) require.Equal(t, proposals, preimages) @@ -238,7 +239,7 @@ func TestGetActivePreimages(t *testing.T) { func TestGetProposalMetadata(t *testing.T) { blockHash := common.Hash{0xaa} - block := batching.BlockByHash(blockHash) + block := rpcblock.ByHash(blockHash) stubRpc, oracle, proposals := setupPreimageOracleTestWithProposals(t, block) preimages, err := oracle.GetProposalMetadata( context.Background(), @@ -259,7 +260,7 @@ func TestGetProposalMetadata(t *testing.T) { block, []interface{}{ident.Claimant, ident.UUID}, []interface{}{meta}) - preimages, err = oracle.GetProposalMetadata(context.Background(), batching.BlockByHash(blockHash), ident) + preimages, err = oracle.GetProposalMetadata(context.Background(), rpcblock.ByHash(blockHash), ident) require.NoError(t, err) require.Equal(t, []keccakTypes.LargePreimageMetaData{{LargePreimageIdent: ident}}, preimages) } @@ -269,15 +270,15 @@ func TestGetProposalTreeRoot(t *testing.T) { expectedRoot := common.Hash{0xbb} ident := keccakTypes.LargePreimageIdent{Claimant: common.Address{0x12}, UUID: big.NewInt(123)} stubRpc, oracle := setupPreimageOracleTest(t) - stubRpc.SetResponse(oracleAddr, methodGetTreeRootLPP, batching.BlockByHash(blockHash), + stubRpc.SetResponse(oracleAddr, methodGetTreeRootLPP, rpcblock.ByHash(blockHash), []interface{}{ident.Claimant, ident.UUID}, []interface{}{expectedRoot}) - actualRoot, err := oracle.GetProposalTreeRoot(context.Background(), batching.BlockByHash(blockHash), ident) + actualRoot, err := oracle.GetProposalTreeRoot(context.Background(), rpcblock.ByHash(blockHash), ident) require.NoError(t, err) require.Equal(t, expectedRoot, actualRoot) } -func setupPreimageOracleTestWithProposals(t *testing.T, block batching.Block) (*batchingTest.AbiBasedRpc, *PreimageOracleContract, []keccakTypes.LargePreimageMetaData) { +func setupPreimageOracleTestWithProposals(t *testing.T, block rpcblock.Block) (*batchingTest.AbiBasedRpc, *PreimageOracleContract, []keccakTypes.LargePreimageMetaData) { stubRpc, oracle := setupPreimageOracleTest(t) stubRpc.SetResponse( oracleAddr, @@ -427,7 +428,7 @@ func TestMetadata_Countered(t *testing.T) { func TestGetInputDataBlocks(t *testing.T) { stubRpc, oracle := setupPreimageOracleTest(t) - block := batching.BlockByHash(common.Hash{0xaa}) + block := rpcblock.ByHash(common.Hash{0xaa}) preimage := keccakTypes.LargePreimageIdent{ Claimant: common.Address{0xbb}, @@ -589,7 +590,7 @@ func TestChallenge_First(t *testing.T) { }, PoststateProof: merkle.Proof{common.Hash{0x01}, common.Hash{0x02}}, } - stubRpc.SetResponse(oracleAddr, methodChallengeFirstLPP, batching.BlockLatest, + stubRpc.SetResponse(oracleAddr, methodChallengeFirstLPP, rpcblock.Latest, []interface{}{ ident.Claimant, ident.UUID, bindings.PreimageOracleLeaf{ @@ -627,7 +628,7 @@ func TestChallenge_NotFirst(t *testing.T) { }, PoststateProof: merkle.Proof{common.Hash{0x03}, common.Hash{0x04}}, } - stubRpc.SetResponse(oracleAddr, methodChallengeLPP, batching.BlockLatest, + stubRpc.SetResponse(oracleAddr, methodChallengeLPP, rpcblock.Latest, []interface{}{ ident.Claimant, ident.UUID, bindings.LibKeccakStateMatrix{State: challenge.StateMatrix}, diff --git a/op-challenger/game/fault/contracts/vm.go b/op-challenger/game/fault/contracts/vm.go index bdc23cd4f974..2fb354d89bd8 100644 --- a/op-challenger/game/fault/contracts/vm.go +++ b/op-challenger/game/fault/contracts/vm.go @@ -6,6 +6,7 @@ import ( "github.com/ethereum-optimism/optimism/op-bindings/bindings" "github.com/ethereum-optimism/optimism/op-service/sources/batching" + "github.com/ethereum-optimism/optimism/op-service/sources/batching/rpcblock" "github.com/ethereum/go-ethereum/common" ) @@ -32,7 +33,7 @@ func NewVMContract(addr common.Address, caller *batching.MultiCaller) (*VMContra } func (c *VMContract) Oracle(ctx context.Context) (*PreimageOracleContract, error) { - results, err := c.multiCaller.SingleCall(ctx, batching.BlockLatest, c.contract.Call(methodOracle)) + results, err := c.multiCaller.SingleCall(ctx, rpcblock.Latest, c.contract.Call(methodOracle)) if err != nil { return nil, fmt.Errorf("failed to load oracle address: %w", err) } diff --git a/op-challenger/game/fault/contracts/vm_test.go b/op-challenger/game/fault/contracts/vm_test.go index 86ebd7279a0d..13758ccd6500 100644 --- a/op-challenger/game/fault/contracts/vm_test.go +++ b/op-challenger/game/fault/contracts/vm_test.go @@ -8,6 +8,7 @@ import ( "github.com/ethereum-optimism/optimism/op-challenger/game/fault/types" preimage "github.com/ethereum-optimism/optimism/op-preimage" "github.com/ethereum-optimism/optimism/op-service/sources/batching" + "github.com/ethereum-optimism/optimism/op-service/sources/batching/rpcblock" batchingTest "github.com/ethereum-optimism/optimism/op-service/sources/batching/test" "github.com/ethereum/go-ethereum/common" "github.com/stretchr/testify/require" @@ -21,7 +22,7 @@ func TestVMContract_Oracle(t *testing.T) { vmContract, err := NewVMContract(vmAddr, batching.NewMultiCaller(stubRpc, batching.DefaultBatchSize)) require.NoError(t, err) - stubRpc.SetResponse(vmAddr, methodOracle, batching.BlockLatest, nil, []interface{}{oracleAddr}) + stubRpc.SetResponse(vmAddr, methodOracle, rpcblock.Latest, nil, []interface{}{oracleAddr}) oracleContract, err := vmContract.Oracle(context.Background()) require.NoError(t, err) diff --git a/op-challenger/game/fault/preimages/large.go b/op-challenger/game/fault/preimages/large.go index 8133107e1184..47fa47e804f7 100644 --- a/op-challenger/game/fault/preimages/large.go +++ b/op-challenger/game/fault/preimages/large.go @@ -13,7 +13,7 @@ import ( "github.com/ethereum-optimism/optimism/op-challenger/game/keccak/matrix" keccakTypes "github.com/ethereum-optimism/optimism/op-challenger/game/keccak/types" gameTypes "github.com/ethereum-optimism/optimism/op-challenger/game/types" - "github.com/ethereum-optimism/optimism/op-service/sources/batching" + "github.com/ethereum-optimism/optimism/op-service/sources/batching/rpcblock" "github.com/ethereum-optimism/optimism/op-service/txmgr" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" @@ -60,7 +60,7 @@ func (p *LargePreimageUploader) UploadPreimage(ctx context.Context, parent uint6 // Fetch the current metadata for this preimage data, if it exists. ident := keccakTypes.LargePreimageIdent{Claimant: p.txSender.From(), UUID: uuid} - metadata, err := p.contract.GetProposalMetadata(ctx, batching.BlockLatest, ident) + metadata, err := p.contract.GetProposalMetadata(ctx, rpcblock.Latest, ident) if err != nil { return fmt.Errorf("failed to get pre-image oracle metadata: %w", err) } @@ -132,7 +132,7 @@ func (p *LargePreimageUploader) Squeeze(ctx context.Context, uuid *big.Int, stat } currentTimestamp := p.clock.Now().Unix() ident := keccakTypes.LargePreimageIdent{Claimant: p.txSender.From(), UUID: uuid} - metadata, err := p.contract.GetProposalMetadata(ctx, batching.BlockLatest, ident) + metadata, err := p.contract.GetProposalMetadata(ctx, rpcblock.Latest, ident) if err != nil { return fmt.Errorf("failed to get pre-image oracle metadata: %w", err) } diff --git a/op-challenger/game/fault/preimages/large_test.go b/op-challenger/game/fault/preimages/large_test.go index 0f4e379cd24b..1913e5a6a47d 100644 --- a/op-challenger/game/fault/preimages/large_test.go +++ b/op-challenger/game/fault/preimages/large_test.go @@ -16,7 +16,7 @@ import ( keccakTypes "github.com/ethereum-optimism/optimism/op-challenger/game/keccak/types" preimage "github.com/ethereum-optimism/optimism/op-preimage" "github.com/ethereum-optimism/optimism/op-service/clock" - "github.com/ethereum-optimism/optimism/op-service/sources/batching" + "github.com/ethereum-optimism/optimism/op-service/sources/batching/rpcblock" "github.com/ethereum-optimism/optimism/op-service/testlog" "github.com/ethereum-optimism/optimism/op-service/txmgr" "github.com/ethereum/go-ethereum/common" @@ -310,7 +310,7 @@ func (s *mockPreimageOracleContract) ChallengePeriod(_ context.Context) (uint64, return mockChallengePeriod, nil } -func (s *mockPreimageOracleContract) GetProposalMetadata(_ context.Context, _ batching.Block, idents ...keccakTypes.LargePreimageIdent) ([]keccakTypes.LargePreimageMetaData, error) { +func (s *mockPreimageOracleContract) GetProposalMetadata(_ context.Context, _ rpcblock.Block, idents ...keccakTypes.LargePreimageIdent) ([]keccakTypes.LargePreimageMetaData, error) { if s.squeezeCallClaimSize > 0 { metadata := make([]keccakTypes.LargePreimageMetaData, 0) for _, ident := range idents { diff --git a/op-challenger/game/fault/preimages/types.go b/op-challenger/game/fault/preimages/types.go index 1c6418191fe0..45665d5fc94e 100644 --- a/op-challenger/game/fault/preimages/types.go +++ b/op-challenger/game/fault/preimages/types.go @@ -8,7 +8,7 @@ import ( "github.com/ethereum-optimism/optimism/op-challenger/game/fault/types" "github.com/ethereum-optimism/optimism/op-challenger/game/keccak/merkle" keccakTypes "github.com/ethereum-optimism/optimism/op-challenger/game/keccak/types" - "github.com/ethereum-optimism/optimism/op-service/sources/batching" + "github.com/ethereum-optimism/optimism/op-service/sources/batching/rpcblock" "github.com/ethereum-optimism/optimism/op-service/txmgr" "github.com/ethereum/go-ethereum/common" ) @@ -27,7 +27,7 @@ type PreimageOracleContract interface { AddLeaves(uuid *big.Int, startingBlockIndex *big.Int, input []byte, commitments []common.Hash, finalize bool) (txmgr.TxCandidate, error) Squeeze(claimant common.Address, uuid *big.Int, prestateMatrix keccakTypes.StateSnapshot, preState keccakTypes.Leaf, preStateProof merkle.Proof, postState keccakTypes.Leaf, postStateProof merkle.Proof) (txmgr.TxCandidate, error) CallSqueeze(ctx context.Context, claimant common.Address, uuid *big.Int, prestateMatrix keccakTypes.StateSnapshot, preState keccakTypes.Leaf, preStateProof merkle.Proof, postState keccakTypes.Leaf, postStateProof merkle.Proof) error - GetProposalMetadata(ctx context.Context, block batching.Block, idents ...keccakTypes.LargePreimageIdent) ([]keccakTypes.LargePreimageMetaData, error) + GetProposalMetadata(ctx context.Context, block rpcblock.Block, idents ...keccakTypes.LargePreimageIdent) ([]keccakTypes.LargePreimageMetaData, error) ChallengePeriod(ctx context.Context) (uint64, error) GetMinBondLPP(ctx context.Context) (*big.Int, error) } diff --git a/op-challenger/game/keccak/fetcher/fetcher.go b/op-challenger/game/keccak/fetcher/fetcher.go index 4158061463f0..755f96b164f3 100644 --- a/op-challenger/game/keccak/fetcher/fetcher.go +++ b/op-challenger/game/keccak/fetcher/fetcher.go @@ -8,7 +8,7 @@ import ( "github.com/ethereum-optimism/optimism/op-challenger/game/fault/contracts" keccakTypes "github.com/ethereum-optimism/optimism/op-challenger/game/keccak/types" - "github.com/ethereum-optimism/optimism/op-service/sources/batching" + "github.com/ethereum-optimism/optimism/op-service/sources/batching/rpcblock" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/log" @@ -26,7 +26,7 @@ type L1Source interface { type Oracle interface { Addr() common.Address - GetInputDataBlocks(ctx context.Context, block batching.Block, ident keccakTypes.LargePreimageIdent) ([]uint64, error) + GetInputDataBlocks(ctx context.Context, block rpcblock.Block, ident keccakTypes.LargePreimageIdent) ([]uint64, error) DecodeInputData(data []byte) (*big.Int, keccakTypes.InputData, error) } @@ -36,7 +36,7 @@ type InputFetcher struct { } func (f *InputFetcher) FetchInputs(ctx context.Context, blockHash common.Hash, oracle Oracle, ident keccakTypes.LargePreimageIdent) ([]keccakTypes.InputData, error) { - blockNums, err := oracle.GetInputDataBlocks(ctx, batching.BlockByHash(blockHash), ident) + blockNums, err := oracle.GetInputDataBlocks(ctx, rpcblock.ByHash(blockHash), ident) if err != nil { return nil, fmt.Errorf("failed to retrieve leaf block nums: %w", err) } diff --git a/op-challenger/game/keccak/fetcher/fetcher_test.go b/op-challenger/game/keccak/fetcher/fetcher_test.go index b46a77ae33da..c236712c8466 100644 --- a/op-challenger/game/keccak/fetcher/fetcher_test.go +++ b/op-challenger/game/keccak/fetcher/fetcher_test.go @@ -9,7 +9,7 @@ import ( "github.com/ethereum-optimism/optimism/op-challenger/game/fault/contracts" keccakTypes "github.com/ethereum-optimism/optimism/op-challenger/game/keccak/types" - "github.com/ethereum-optimism/optimism/op-service/sources/batching" + "github.com/ethereum-optimism/optimism/op-service/sources/batching/rpcblock" "github.com/ethereum-optimism/optimism/op-service/testlog" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" @@ -188,7 +188,7 @@ func (o *stubOracle) Addr() common.Address { return oracleAddr } -func (o *stubOracle) GetInputDataBlocks(_ context.Context, _ batching.Block, _ keccakTypes.LargePreimageIdent) ([]uint64, error) { +func (o *stubOracle) GetInputDataBlocks(_ context.Context, _ rpcblock.Block, _ keccakTypes.LargePreimageIdent) ([]uint64, error) { return o.leafBlocks, nil } diff --git a/op-challenger/game/keccak/scheduler_test.go b/op-challenger/game/keccak/scheduler_test.go index ec3c5ff18dd5..8f61663b8a98 100644 --- a/op-challenger/game/keccak/scheduler_test.go +++ b/op-challenger/game/keccak/scheduler_test.go @@ -10,7 +10,7 @@ import ( keccakTypes "github.com/ethereum-optimism/optimism/op-challenger/game/keccak/types" "github.com/ethereum-optimism/optimism/op-service/clock" - "github.com/ethereum-optimism/optimism/op-service/sources/batching" + "github.com/ethereum-optimism/optimism/op-service/sources/batching/rpcblock" "github.com/ethereum-optimism/optimism/op-service/testlog" "github.com/ethereum-optimism/optimism/op-service/txmgr" "github.com/ethereum/go-ethereum/common" @@ -77,7 +77,7 @@ func (s *stubOracle) ChallengePeriod(_ context.Context) (uint64, error) { return stubChallengePeriod, nil } -func (s *stubOracle) GetInputDataBlocks(_ context.Context, _ batching.Block, _ keccakTypes.LargePreimageIdent) ([]uint64, error) { +func (s *stubOracle) GetInputDataBlocks(_ context.Context, _ rpcblock.Block, _ keccakTypes.LargePreimageIdent) ([]uint64, error) { panic("not supported") } @@ -106,7 +106,7 @@ func (s *stubOracle) ChallengeTx(_ keccakTypes.LargePreimageIdent, _ keccakTypes panic("not supported") } -func (s *stubOracle) GetProposalTreeRoot(_ context.Context, _ batching.Block, ident keccakTypes.LargePreimageIdent) (common.Hash, error) { +func (s *stubOracle) GetProposalTreeRoot(_ context.Context, _ rpcblock.Block, ident keccakTypes.LargePreimageIdent) (common.Hash, error) { root, ok := s.treeRoots[ident] if ok { return root, nil diff --git a/op-challenger/game/keccak/types/types.go b/op-challenger/game/keccak/types/types.go index 5c13468a09af..9c423a7a10ca 100644 --- a/op-challenger/game/keccak/types/types.go +++ b/op-challenger/game/keccak/types/types.go @@ -6,7 +6,7 @@ import ( "time" "github.com/ethereum-optimism/optimism/op-challenger/game/keccak/merkle" - "github.com/ethereum-optimism/optimism/op-service/sources/batching" + "github.com/ethereum-optimism/optimism/op-service/sources/batching/rpcblock" "github.com/ethereum-optimism/optimism/op-service/txmgr" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/math" @@ -99,8 +99,8 @@ type Challenge struct { type LargePreimageOracle interface { Addr() common.Address GetActivePreimages(ctx context.Context, blockHash common.Hash) ([]LargePreimageMetaData, error) - GetInputDataBlocks(ctx context.Context, block batching.Block, ident LargePreimageIdent) ([]uint64, error) - GetProposalTreeRoot(ctx context.Context, block batching.Block, ident LargePreimageIdent) (common.Hash, error) + GetInputDataBlocks(ctx context.Context, block rpcblock.Block, ident LargePreimageIdent) ([]uint64, error) + GetProposalTreeRoot(ctx context.Context, block rpcblock.Block, ident LargePreimageIdent) (common.Hash, error) DecodeInputData(data []byte) (*big.Int, InputData, error) ChallengeTx(ident LargePreimageIdent, challenge Challenge) (txmgr.TxCandidate, error) ChallengePeriod(ctx context.Context) (uint64, error) diff --git a/op-challenger/game/keccak/verifier.go b/op-challenger/game/keccak/verifier.go index dbd7dbdd413f..026462b127e0 100644 --- a/op-challenger/game/keccak/verifier.go +++ b/op-challenger/game/keccak/verifier.go @@ -10,7 +10,7 @@ import ( "github.com/ethereum-optimism/optimism/op-challenger/game/keccak/fetcher" "github.com/ethereum-optimism/optimism/op-challenger/game/keccak/matrix" keccakTypes "github.com/ethereum-optimism/optimism/op-challenger/game/keccak/types" - "github.com/ethereum-optimism/optimism/op-service/sources/batching" + "github.com/ethereum-optimism/optimism/op-service/sources/batching/rpcblock" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/log" lru "github.com/hashicorp/golang-lru/v2" @@ -20,7 +20,7 @@ const validPreimageCacheSize = 500 type VerifierPreimageOracle interface { fetcher.Oracle - GetProposalTreeRoot(ctx context.Context, block batching.Block, ident keccakTypes.LargePreimageIdent) (common.Hash, error) + GetProposalTreeRoot(ctx context.Context, block rpcblock.Block, ident keccakTypes.LargePreimageIdent) (common.Hash, error) } type Fetcher interface { @@ -47,7 +47,7 @@ func NewPreimageVerifier(logger log.Logger, fetcher Fetcher) *PreimageVerifier { } func (v *PreimageVerifier) CreateChallenge(ctx context.Context, blockHash common.Hash, oracle VerifierPreimageOracle, preimage keccakTypes.LargePreimageMetaData) (keccakTypes.Challenge, error) { - root, err := oracle.GetProposalTreeRoot(ctx, batching.BlockByHash(blockHash), preimage.LargePreimageIdent) + root, err := oracle.GetProposalTreeRoot(ctx, rpcblock.ByHash(blockHash), preimage.LargePreimageIdent) if err != nil { return keccakTypes.Challenge{}, fmt.Errorf("failed to get proposal merkle root: %w", err) } diff --git a/op-challenger/game/registry/registry_test.go b/op-challenger/game/registry/registry_test.go index e2c4c8c258f4..ecf2cc9d4be1 100644 --- a/op-challenger/game/registry/registry_test.go +++ b/op-challenger/game/registry/registry_test.go @@ -10,7 +10,7 @@ import ( "github.com/ethereum-optimism/optimism/op-challenger/game/scheduler" "github.com/ethereum-optimism/optimism/op-challenger/game/scheduler/test" "github.com/ethereum-optimism/optimism/op-challenger/game/types" - "github.com/ethereum-optimism/optimism/op-service/sources/batching" + "github.com/ethereum-optimism/optimism/op-service/sources/batching/rpcblock" "github.com/ethereum-optimism/optimism/op-service/txmgr" "github.com/ethereum/go-ethereum/common" "github.com/stretchr/testify/require" @@ -97,7 +97,7 @@ func (s stubPreimageOracle) ChallengePeriod(_ context.Context) (uint64, error) { panic("not supported") } -func (s stubPreimageOracle) GetProposalTreeRoot(_ context.Context, _ batching.Block, _ keccakTypes.LargePreimageIdent) (common.Hash, error) { +func (s stubPreimageOracle) GetProposalTreeRoot(_ context.Context, _ rpcblock.Block, _ keccakTypes.LargePreimageIdent) (common.Hash, error) { panic("not supported") } @@ -105,7 +105,7 @@ func (s stubPreimageOracle) ChallengeTx(_ keccakTypes.LargePreimageIdent, _ kecc panic("not supported") } -func (s stubPreimageOracle) GetInputDataBlocks(_ context.Context, _ batching.Block, _ keccakTypes.LargePreimageIdent) ([]uint64, error) { +func (s stubPreimageOracle) GetInputDataBlocks(_ context.Context, _ rpcblock.Block, _ keccakTypes.LargePreimageIdent) ([]uint64, error) { panic("not supported") } diff --git a/op-dispute-mon/mon/bonds/bonds.go b/op-dispute-mon/mon/bonds/bonds.go index 993a2ae483a4..67d15cbe1f10 100644 --- a/op-dispute-mon/mon/bonds/bonds.go +++ b/op-dispute-mon/mon/bonds/bonds.go @@ -7,13 +7,13 @@ import ( faultTypes "github.com/ethereum-optimism/optimism/op-challenger/game/fault/types" monTypes "github.com/ethereum-optimism/optimism/op-dispute-mon/mon/types" - "github.com/ethereum-optimism/optimism/op-service/sources/batching" + "github.com/ethereum-optimism/optimism/op-service/sources/batching/rpcblock" "github.com/ethereum/go-ethereum/common" "golang.org/x/exp/maps" ) type BondContract interface { - GetCredits(ctx context.Context, block batching.Block, recipients ...common.Address) ([]*big.Int, error) + GetCredits(ctx context.Context, block rpcblock.Block, recipients ...common.Address) ([]*big.Int, error) } // CalculateRequiredCollateral determines the minimum balance required for a fault dispute game contract in order @@ -32,7 +32,7 @@ func CalculateRequiredCollateral(ctx context.Context, contract BondContract, blo } } - credits, err := contract.GetCredits(ctx, batching.BlockByHash(blockHash), maps.Keys(recipients)...) + credits, err := contract.GetCredits(ctx, rpcblock.ByHash(blockHash), maps.Keys(recipients)...) if err != nil { return nil, fmt.Errorf("failed to load credits: %w", err) } diff --git a/op-dispute-mon/mon/bonds/bonds_test.go b/op-dispute-mon/mon/bonds/bonds_test.go index 102ef3a32574..7445a6076315 100644 --- a/op-dispute-mon/mon/bonds/bonds_test.go +++ b/op-dispute-mon/mon/bonds/bonds_test.go @@ -7,7 +7,7 @@ import ( "github.com/ethereum-optimism/optimism/op-challenger/game/fault/types" monTypes "github.com/ethereum-optimism/optimism/op-dispute-mon/mon/types" - "github.com/ethereum-optimism/optimism/op-service/sources/batching" + "github.com/ethereum-optimism/optimism/op-service/sources/batching/rpcblock" "github.com/ethereum/go-ethereum/common" "github.com/stretchr/testify/require" ) @@ -51,7 +51,7 @@ type stubBondContract struct { credits map[common.Address]*big.Int } -func (s *stubBondContract) GetCredits(_ context.Context, _ batching.Block, recipients ...common.Address) ([]*big.Int, error) { +func (s *stubBondContract) GetCredits(_ context.Context, _ rpcblock.Block, recipients ...common.Address) ([]*big.Int, error) { results := make([]*big.Int, len(recipients)) for i, recipient := range recipients { credit, ok := s.credits[recipient] diff --git a/op-e2e/e2eutils/disputegame/output_cannon_helper.go b/op-e2e/e2eutils/disputegame/output_cannon_helper.go index 7a5712fc154c..2228439c13ba 100644 --- a/op-e2e/e2eutils/disputegame/output_cannon_helper.go +++ b/op-e2e/e2eutils/disputegame/output_cannon_helper.go @@ -22,6 +22,7 @@ import ( "github.com/ethereum-optimism/optimism/op-e2e/e2eutils/wait" preimage "github.com/ethereum-optimism/optimism/op-preimage" "github.com/ethereum-optimism/optimism/op-service/sources/batching" + "github.com/ethereum-optimism/optimism/op-service/sources/batching/rpcblock" "github.com/ethereum-optimism/optimism/op-service/testlog" "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" @@ -267,7 +268,7 @@ func (g *OutputCannonGameHelper) VerifyPreimage(ctx context.Context, outputRootC abi, err := bindings.MIPSMetaData.GetAbi() g.require.NoError(err, "Failed to load MIPS ABI") caller := batching.NewMultiCaller(g.client.Client(), batching.DefaultBatchSize) - result, err := caller.SingleCall(ctx, batching.BlockLatest, &batching.ContractCall{ + result, err := caller.SingleCall(ctx, rpcblock.Latest, &batching.ContractCall{ Abi: abi, Addr: vmAddr, Method: "step", diff --git a/op-e2e/e2eutils/disputegame/output_game_helper.go b/op-e2e/e2eutils/disputegame/output_game_helper.go index acce4da9e619..3bac273cd268 100644 --- a/op-e2e/e2eutils/disputegame/output_game_helper.go +++ b/op-e2e/e2eutils/disputegame/output_game_helper.go @@ -18,6 +18,7 @@ import ( preimage "github.com/ethereum-optimism/optimism/op-preimage" "github.com/ethereum-optimism/optimism/op-service/eth" "github.com/ethereum-optimism/optimism/op-service/sources/batching" + "github.com/ethereum-optimism/optimism/op-service/sources/batching/rpcblock" "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" gethtypes "github.com/ethereum/go-ethereum/core/types" @@ -611,7 +612,7 @@ func (g *OutputGameHelper) WaitForChallengePeriodStart(ctx context.Context, send func (g *OutputGameHelper) ChallengePeriodStartTime(ctx context.Context, sender common.Address, data *types.PreimageOracleData) uint64 { oracle := g.oracle(ctx) uuid := preimages.NewUUID(sender, data) - metadata, err := oracle.GetProposalMetadata(ctx, batching.BlockLatest, keccakTypes.LargePreimageIdent{ + metadata, err := oracle.GetProposalMetadata(ctx, rpcblock.Latest, keccakTypes.LargePreimageIdent{ Claimant: sender, UUID: uuid, }) diff --git a/op-e2e/e2eutils/disputegame/preimage/preimage_helper.go b/op-e2e/e2eutils/disputegame/preimage/preimage_helper.go index 76308466858e..f124add19d63 100644 --- a/op-e2e/e2eutils/disputegame/preimage/preimage_helper.go +++ b/op-e2e/e2eutils/disputegame/preimage/preimage_helper.go @@ -18,6 +18,7 @@ import ( "github.com/ethereum-optimism/optimism/op-challenger/game/keccak/types" "github.com/ethereum-optimism/optimism/op-e2e/e2eutils/wait" "github.com/ethereum-optimism/optimism/op-service/sources/batching" + "github.com/ethereum-optimism/optimism/op-service/sources/batching/rpcblock" "github.com/ethereum-optimism/optimism/op-service/testutils" "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" @@ -127,7 +128,7 @@ func (h *Helper) WaitForChallenged(ctx context.Context, ident types.LargePreimag timedCtx, cancel := context.WithTimeout(ctx, 30*time.Second) defer cancel() err := wait.For(timedCtx, time.Second, func() (bool, error) { - metadata, err := h.oracle.GetProposalMetadata(ctx, batching.BlockLatest, ident) + metadata, err := h.oracle.GetProposalMetadata(ctx, rpcblock.Latest, ident) if err != nil { return false, err } diff --git a/op-service/sources/batching/arrays.go b/op-service/sources/batching/arrays.go index f028459189be..b946014215c1 100644 --- a/op-service/sources/batching/arrays.go +++ b/op-service/sources/batching/arrays.go @@ -4,13 +4,15 @@ import ( "context" "fmt" "math/big" + + "github.com/ethereum-optimism/optimism/op-service/sources/batching/rpcblock" ) // ReadArray uses batch calls to load all entries from an array. // countCall is used to retrieve the current array length, then getCall is used to create calls for each element // which are sent in a batch call. // The returned *CallResult slice, contains a result for each entry in the array, in the same order as in the contract. -func ReadArray(ctx context.Context, caller *MultiCaller, block Block, countCall *ContractCall, getCall func(i *big.Int) *ContractCall) ([]*CallResult, error) { +func ReadArray(ctx context.Context, caller *MultiCaller, block rpcblock.Block, countCall *ContractCall, getCall func(i *big.Int) *ContractCall) ([]*CallResult, error) { result, err := caller.SingleCall(ctx, block, countCall) if err != nil { return nil, fmt.Errorf("failed to load array length: %w", err) diff --git a/op-service/sources/batching/balance_call.go b/op-service/sources/batching/balance_call.go index fcac4acb9845..a91bca04a30b 100644 --- a/op-service/sources/batching/balance_call.go +++ b/op-service/sources/batching/balance_call.go @@ -4,6 +4,7 @@ import ( "fmt" "math/big" + "github.com/ethereum-optimism/optimism/op-service/sources/batching/rpcblock" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/rpc" @@ -20,11 +21,11 @@ func NewBalanceCall(addr common.Address) *BalanceCall { } func (b *BalanceCall) ToBatchElemCreator() (BatchElementCreator, error) { - return func(block Block) (any, rpc.BatchElem) { + return func(block rpcblock.Block) (any, rpc.BatchElem) { out := new(hexutil.Big) return out, rpc.BatchElem{ Method: "eth_getBalance", - Args: []interface{}{b.addr, block.value}, + Args: []interface{}{b.addr, block.ArgValue()}, Result: &out, } }, nil diff --git a/op-service/sources/batching/test/balance_call_test.go b/op-service/sources/batching/balance_call_test.go similarity index 51% rename from op-service/sources/batching/test/balance_call_test.go rename to op-service/sources/batching/balance_call_test.go index 4b2fa8548d36..5541360ae966 100644 --- a/op-service/sources/batching/test/balance_call_test.go +++ b/op-service/sources/batching/balance_call_test.go @@ -1,26 +1,25 @@ -package test +package batching import ( "context" "math/big" "testing" - "github.com/ethereum-optimism/optimism/op-service/sources/batching" + "github.com/ethereum-optimism/optimism/op-service/sources/batching/rpcblock" + "github.com/ethereum-optimism/optimism/op-service/sources/batching/test" "github.com/ethereum/go-ethereum/common" "github.com/stretchr/testify/require" ) -// Note: These tests are in the test subpackage to avoid dependency cycles since they need to use the stubs - func TestGetBalance(t *testing.T) { addr := common.Address{0xab, 0xcd} expectedBalance := big.NewInt(248924) - stub := NewRpcStub(t) - stub.AddExpectedCall(NewGetBalanceCall(addr, batching.BlockLatest, expectedBalance)) + stub := test.NewRpcStub(t) + stub.AddExpectedCall(test.NewGetBalanceCall(addr, rpcblock.Latest, expectedBalance)) - caller := batching.NewMultiCaller(stub, batching.DefaultBatchSize) - result, err := caller.SingleCall(context.Background(), batching.BlockLatest, batching.NewBalanceCall(addr)) + caller := NewMultiCaller(stub, DefaultBatchSize) + result, err := caller.SingleCall(context.Background(), rpcblock.Latest, NewBalanceCall(addr)) require.NoError(t, err) require.Equal(t, expectedBalance, result.GetBigInt(0)) } diff --git a/op-service/sources/batching/call.go b/op-service/sources/batching/call.go index 3a7bbbfc4c75..d84932fac6ee 100644 --- a/op-service/sources/batching/call.go +++ b/op-service/sources/batching/call.go @@ -3,12 +3,13 @@ package batching import ( "math/big" + "github.com/ethereum-optimism/optimism/op-service/sources/batching/rpcblock" "github.com/ethereum/go-ethereum/accounts/abi" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/rpc" ) -type BatchElementCreator func(block Block) (any, rpc.BatchElem) +type BatchElementCreator func(block rpcblock.Block) (any, rpc.BatchElem) type Call interface { ToBatchElemCreator() (BatchElementCreator, error) diff --git a/op-service/sources/batching/contract_call.go b/op-service/sources/batching/contract_call.go index c99931e4a680..87b265e84717 100644 --- a/op-service/sources/batching/contract_call.go +++ b/op-service/sources/batching/contract_call.go @@ -3,6 +3,7 @@ package batching import ( "fmt" + "github.com/ethereum-optimism/optimism/op-service/sources/batching/rpcblock" "github.com/ethereum-optimism/optimism/op-service/txmgr" "github.com/ethereum/go-ethereum/accounts/abi" "github.com/ethereum/go-ethereum/common" @@ -40,11 +41,11 @@ func (c *ContractCall) ToBatchElemCreator() (BatchElementCreator, error) { if err != nil { return nil, err } - f := func(block Block) (any, rpc.BatchElem) { + f := func(block rpcblock.Block) (any, rpc.BatchElem) { out := new(hexutil.Bytes) return out, rpc.BatchElem{ Method: "eth_call", - Args: []interface{}{args, block.value}, + Args: []interface{}{args, block.ArgValue()}, Result: &out, } } diff --git a/op-service/sources/batching/multicall.go b/op-service/sources/batching/multicall.go index 57d7fd681d9c..2a02ce774f73 100644 --- a/op-service/sources/batching/multicall.go +++ b/op-service/sources/batching/multicall.go @@ -5,7 +5,7 @@ import ( "fmt" "io" - "github.com/ethereum/go-ethereum/common" + "github.com/ethereum-optimism/optimism/op-service/sources/batching/rpcblock" "github.com/ethereum/go-ethereum/rpc" ) @@ -32,7 +32,7 @@ func (m *MultiCaller) BatchSize() int { return m.batchSize } -func (m *MultiCaller) SingleCall(ctx context.Context, block Block, call Call) (*CallResult, error) { +func (m *MultiCaller) SingleCall(ctx context.Context, block rpcblock.Block, call Call) (*CallResult, error) { results, err := m.Call(ctx, block, call) if err != nil { return nil, err @@ -40,7 +40,7 @@ func (m *MultiCaller) SingleCall(ctx context.Context, block Block, call Call) (* return results[0], nil } -func (m *MultiCaller) Call(ctx context.Context, block Block, calls ...Call) ([]*CallResult, error) { +func (m *MultiCaller) Call(ctx context.Context, block rpcblock.Block, calls ...Call) ([]*CallResult, error) { keys := make([]BatchElementCreator, len(calls)) for i := 0; i < len(calls); i++ { creator, err := calls[i].ToBatchElemCreator() @@ -80,30 +80,3 @@ func (m *MultiCaller) Call(ctx context.Context, block Block, calls ...Call) ([]* } return callResults, nil } - -// Block represents the block ref value in RPC calls. -// It can be either a label (e.g. latest), a block number or block hash. -type Block struct { - value any -} - -func (b Block) ArgValue() any { - return b.value -} - -var ( - BlockPending = Block{"pending"} - BlockLatest = Block{"latest"} - BlockSafe = Block{"safe"} - BlockFinalized = Block{"finalized"} -) - -// BlockByNumber references a canonical block by number. -func BlockByNumber(blockNum uint64) Block { - return Block{rpc.BlockNumber(blockNum)} -} - -// BlockByHash references a block by hash. Canonical or non-canonical blocks may be referenced. -func BlockByHash(hash common.Hash) Block { - return Block{rpc.BlockNumberOrHashWithHash(hash, false)} -} diff --git a/op-service/sources/batching/rpcblock/blocks.go b/op-service/sources/batching/rpcblock/blocks.go new file mode 100644 index 000000000000..caf8bf94c78f --- /dev/null +++ b/op-service/sources/batching/rpcblock/blocks.go @@ -0,0 +1,33 @@ +package rpcblock + +import ( + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/rpc" +) + +// Block represents the block ref value in RPC calls. +// It can be either a label (e.g. latest), a block number or block hash. +type Block struct { + value any +} + +func (b Block) ArgValue() any { + return b.value +} + +var ( + Pending = Block{"pending"} + Latest = Block{"latest"} + Safe = Block{"safe"} + Finalized = Block{"finalized"} +) + +// ByNumber references a canonical block by number. +func ByNumber(blockNum uint64) Block { + return Block{rpc.BlockNumber(blockNum)} +} + +// ByHash references a block by hash. Canonical or non-canonical blocks may be referenced. +func ByHash(hash common.Hash) Block { + return Block{rpc.BlockNumberOrHashWithHash(hash, false)} +} diff --git a/op-service/sources/batching/test/abi_stub.go b/op-service/sources/batching/test/abi_stub.go index 2fe79aa05391..f4a70b907a96 100644 --- a/op-service/sources/batching/test/abi_stub.go +++ b/op-service/sources/batching/test/abi_stub.go @@ -6,7 +6,7 @@ import ( "fmt" "testing" - "github.com/ethereum-optimism/optimism/op-service/sources/batching" + "github.com/ethereum-optimism/optimism/op-service/sources/batching/rpcblock" "github.com/ethereum-optimism/optimism/op-service/txmgr" "github.com/ethereum/go-ethereum/accounts/abi" "github.com/ethereum/go-ethereum/common" @@ -19,7 +19,7 @@ import ( type expectedCall struct { abiMethod abi.Method to common.Address - block batching.Block + block rpcblock.Block args []interface{} packedArgs []byte outputs []interface{} @@ -107,7 +107,7 @@ func (l *AbiBasedRpc) abi(to common.Address) *abi.ABI { return abi } -func (l *AbiBasedRpc) SetResponse(to common.Address, method string, block batching.Block, expected []interface{}, output []interface{}) { +func (l *AbiBasedRpc) SetResponse(to common.Address, method string, block rpcblock.Block, expected []interface{}, output []interface{}) { if expected == nil { expected = []interface{}{} } @@ -134,5 +134,5 @@ func (l *AbiBasedRpc) VerifyTxCandidate(candidate txmgr.TxCandidate) { "to": candidate.To, "input": hexutil.Bytes(candidate.TxData), "value": candidate.Value, - }, batching.BlockLatest.ArgValue()) + }, rpcblock.Latest.ArgValue()) } diff --git a/op-service/sources/batching/test/generic_stub.go b/op-service/sources/batching/test/generic_stub.go index 05ed157d0f88..9e78656ad48f 100644 --- a/op-service/sources/batching/test/generic_stub.go +++ b/op-service/sources/batching/test/generic_stub.go @@ -8,7 +8,7 @@ import ( "math/big" "testing" - "github.com/ethereum-optimism/optimism/op-service/sources/batching" + "github.com/ethereum-optimism/optimism/op-service/sources/batching/rpcblock" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/rpc" @@ -73,7 +73,7 @@ type GenericExpectedCall struct { result interface{} } -func NewGetBalanceCall(addr common.Address, block batching.Block, balance *big.Int) ExpectedRpcCall { +func NewGetBalanceCall(addr common.Address, block rpcblock.Block, balance *big.Int) ExpectedRpcCall { return &GenericExpectedCall{ method: "eth_getBalance", args: []interface{}{addr, block.ArgValue()},