Commit 70c0778d authored by Adrian Sutton's avatar Adrian Sutton Committed by GitHub

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: default avatarrefcell <abigger87@gmail.com>
parent 53573e0e
...@@ -10,6 +10,7 @@ import ( ...@@ -10,6 +10,7 @@ import (
"github.com/ethereum-optimism/optimism/op-challenger/game/fault/types" "github.com/ethereum-optimism/optimism/op-challenger/game/fault/types"
gameTypes "github.com/ethereum-optimism/optimism/op-challenger/game/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"
"github.com/ethereum-optimism/optimism/op-service/sources/batching/rpcblock"
"github.com/ethereum-optimism/optimism/op-service/txmgr" "github.com/ethereum-optimism/optimism/op-service/txmgr"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
) )
...@@ -64,7 +65,7 @@ func NewFaultDisputeGameContract(addr common.Address, caller *batching.MultiCall ...@@ -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) // 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). // 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) { 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(methodGenesisBlockNumber),
c.contract.Call(methodL2BlockNumber)) c.contract.Call(methodL2BlockNumber))
if err != nil { if err != nil {
...@@ -82,7 +83,7 @@ func (c *FaultDisputeGameContract) GetBlockRange(ctx context.Context) (prestateB ...@@ -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. // 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) { 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(methodL2BlockNumber),
c.contract.Call(methodRootClaim), c.contract.Call(methodRootClaim),
c.contract.Call(methodStatus), c.contract.Call(methodStatus),
...@@ -104,7 +105,7 @@ func (c *FaultDisputeGameContract) GetGameMetadata(ctx context.Context) (uint64, ...@@ -104,7 +105,7 @@ func (c *FaultDisputeGameContract) GetGameMetadata(ctx context.Context) (uint64,
} }
func (c *FaultDisputeGameContract) GetGenesisOutputRoot(ctx context.Context) (common.Hash, error) { 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 { if err != nil {
return common.Hash{}, fmt.Errorf("failed to retrieve genesis output root: %w", err) 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 ...@@ -112,7 +113,7 @@ func (c *FaultDisputeGameContract) GetGenesisOutputRoot(ctx context.Context) (co
} }
func (c *FaultDisputeGameContract) GetSplitDepth(ctx context.Context) (types.Depth, error) { 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 { if err != nil {
return 0, fmt.Errorf("failed to retrieve split depth: %w", err) return 0, fmt.Errorf("failed to retrieve split depth: %w", err)
} }
...@@ -120,7 +121,7 @@ func (c *FaultDisputeGameContract) GetSplitDepth(ctx context.Context) (types.Dep ...@@ -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) { 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(methodCredit, recipient),
c.contract.Call(methodStatus)) c.contract.Call(methodStatus))
if err != nil { if err != nil {
...@@ -137,7 +138,7 @@ func (c *FaultDisputeGameContract) GetCredit(ctx context.Context, recipient comm ...@@ -137,7 +138,7 @@ func (c *FaultDisputeGameContract) GetCredit(ctx context.Context, recipient comm
return credit, status, nil 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)) calls := make([]batching.Call, 0, len(recipients))
for _, recipient := range recipients { for _, recipient := range recipients {
calls = append(calls, c.contract.Call(methodCredit, recipient)) calls = append(calls, c.contract.Call(methodCredit, recipient))
...@@ -159,7 +160,7 @@ func (f *FaultDisputeGameContract) ClaimCredit(recipient common.Address) (txmgr. ...@@ -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) { 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 { if err != nil {
return nil, fmt.Errorf("failed to retrieve required bond: %w", err) return nil, fmt.Errorf("failed to retrieve required bond: %w", err)
} }
...@@ -200,7 +201,7 @@ func (f *FaultDisputeGameContract) GetOracle(ctx context.Context) (*PreimageOrac ...@@ -200,7 +201,7 @@ func (f *FaultDisputeGameContract) GetOracle(ctx context.Context) (*PreimageOrac
} }
func (f *FaultDisputeGameContract) GetGameDuration(ctx context.Context) (uint64, error) { 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 { if err != nil {
return 0, fmt.Errorf("failed to fetch game duration: %w", err) return 0, fmt.Errorf("failed to fetch game duration: %w", err)
} }
...@@ -208,7 +209,7 @@ func (f *FaultDisputeGameContract) GetGameDuration(ctx context.Context) (uint64, ...@@ -208,7 +209,7 @@ func (f *FaultDisputeGameContract) GetGameDuration(ctx context.Context) (uint64,
} }
func (f *FaultDisputeGameContract) GetMaxGameDepth(ctx context.Context) (types.Depth, error) { 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 { if err != nil {
return 0, fmt.Errorf("failed to fetch max game depth: %w", err) 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 ...@@ -216,7 +217,7 @@ func (f *FaultDisputeGameContract) GetMaxGameDepth(ctx context.Context) (types.D
} }
func (f *FaultDisputeGameContract) GetAbsolutePrestateHash(ctx context.Context) (common.Hash, error) { 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 { if err != nil {
return common.Hash{}, fmt.Errorf("failed to fetch absolute prestate hash: %w", err) return common.Hash{}, fmt.Errorf("failed to fetch absolute prestate hash: %w", err)
} }
...@@ -224,7 +225,7 @@ func (f *FaultDisputeGameContract) GetAbsolutePrestateHash(ctx context.Context) ...@@ -224,7 +225,7 @@ func (f *FaultDisputeGameContract) GetAbsolutePrestateHash(ctx context.Context)
} }
func (f *FaultDisputeGameContract) GetL1Head(ctx context.Context) (common.Hash, error) { 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 { if err != nil {
return common.Hash{}, fmt.Errorf("failed to fetch L1 head: %w", err) 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, ...@@ -232,7 +233,7 @@ func (f *FaultDisputeGameContract) GetL1Head(ctx context.Context) (common.Hash,
} }
func (f *FaultDisputeGameContract) GetStatus(ctx context.Context) (gameTypes.GameStatus, error) { 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 { if err != nil {
return 0, fmt.Errorf("failed to fetch status: %w", err) return 0, fmt.Errorf("failed to fetch status: %w", err)
} }
...@@ -240,7 +241,7 @@ func (f *FaultDisputeGameContract) GetStatus(ctx context.Context) (gameTypes.Gam ...@@ -240,7 +241,7 @@ func (f *FaultDisputeGameContract) GetStatus(ctx context.Context) (gameTypes.Gam
} }
func (f *FaultDisputeGameContract) GetClaimCount(ctx context.Context) (uint64, error) { 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 { if err != nil {
return 0, fmt.Errorf("failed to fetch claim count: %w", err) return 0, fmt.Errorf("failed to fetch claim count: %w", err)
} }
...@@ -248,7 +249,7 @@ func (f *FaultDisputeGameContract) GetClaimCount(ctx context.Context) (uint64, e ...@@ -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) { 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 { if err != nil {
return types.Claim{}, fmt.Errorf("failed to fetch claim %v: %w", idx, err) 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 ...@@ -256,7 +257,7 @@ func (f *FaultDisputeGameContract) GetClaim(ctx context.Context, idx uint64) (ty
} }
func (f *FaultDisputeGameContract) GetAllClaims(ctx context.Context) ([]types.Claim, error) { 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) return f.contract.Call(methodClaim, i)
}) })
if err != nil { if err != nil {
...@@ -271,7 +272,7 @@ func (f *FaultDisputeGameContract) GetAllClaims(ctx context.Context) ([]types.Cl ...@@ -271,7 +272,7 @@ func (f *FaultDisputeGameContract) GetAllClaims(ctx context.Context) ([]types.Cl
} }
func (f *FaultDisputeGameContract) vm(ctx context.Context) (*VMContract, error) { 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 { if err != nil {
return nil, fmt.Errorf("failed to fetch VM addr: %w", err) return nil, fmt.Errorf("failed to fetch VM addr: %w", err)
} }
...@@ -296,7 +297,7 @@ func (f *FaultDisputeGameContract) StepTx(claimIdx uint64, isAttack bool, stateD ...@@ -296,7 +297,7 @@ func (f *FaultDisputeGameContract) StepTx(claimIdx uint64, isAttack bool, stateD
func (f *FaultDisputeGameContract) CallResolveClaim(ctx context.Context, claimIdx uint64) error { func (f *FaultDisputeGameContract) CallResolveClaim(ctx context.Context, claimIdx uint64) error {
call := f.resolveClaimCall(claimIdx) call := f.resolveClaimCall(claimIdx)
_, err := f.multiCaller.SingleCall(ctx, batching.BlockLatest, call) _, err := f.multiCaller.SingleCall(ctx, rpcblock.Latest, call)
if err != nil { if err != nil {
return fmt.Errorf("failed to call resolve claim: %w", err) return fmt.Errorf("failed to call resolve claim: %w", err)
} }
...@@ -314,7 +315,7 @@ func (f *FaultDisputeGameContract) resolveClaimCall(claimIdx uint64) *batching.C ...@@ -314,7 +315,7 @@ func (f *FaultDisputeGameContract) resolveClaimCall(claimIdx uint64) *batching.C
func (f *FaultDisputeGameContract) CallResolve(ctx context.Context) (gameTypes.GameStatus, error) { func (f *FaultDisputeGameContract) CallResolve(ctx context.Context) (gameTypes.GameStatus, error) {
call := f.resolveCall() call := f.resolveCall()
result, err := f.multiCaller.SingleCall(ctx, batching.BlockLatest, call) result, err := f.multiCaller.SingleCall(ctx, rpcblock.Latest, call)
if err != nil { if err != nil {
return gameTypes.GameStatusInProgress, fmt.Errorf("failed to call resolve: %w", err) return gameTypes.GameStatusInProgress, fmt.Errorf("failed to call resolve: %w", err)
} }
......
...@@ -8,6 +8,7 @@ import ( ...@@ -8,6 +8,7 @@ import (
"github.com/ethereum-optimism/optimism/op-bindings/bindings" "github.com/ethereum-optimism/optimism/op-bindings/bindings"
"github.com/ethereum-optimism/optimism/op-challenger/game/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"
"github.com/ethereum-optimism/optimism/op-service/sources/batching/rpcblock"
"github.com/ethereum-optimism/optimism/op-service/txmgr" "github.com/ethereum-optimism/optimism/op-service/txmgr"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
) )
...@@ -37,7 +38,7 @@ func NewDisputeGameFactoryContract(addr common.Address, caller *batching.MultiCa ...@@ -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) { 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 { if err != nil {
return common.Address{}, fmt.Errorf("failed to fetch game from parameters: %w", err) return common.Address{}, fmt.Errorf("failed to fetch game from parameters: %w", err)
} }
...@@ -45,7 +46,7 @@ func (f *DisputeGameFactoryContract) GetGameFromParameters(ctx context.Context, ...@@ -45,7 +46,7 @@ func (f *DisputeGameFactoryContract) GetGameFromParameters(ctx context.Context,
} }
func (f *DisputeGameFactoryContract) GetGameCount(ctx context.Context, blockHash common.Hash) (uint64, error) { 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 { if err != nil {
return 0, fmt.Errorf("failed to load game count: %w", err) return 0, fmt.Errorf("failed to load game count: %w", err)
} }
...@@ -53,7 +54,7 @@ func (f *DisputeGameFactoryContract) GetGameCount(ctx context.Context, blockHash ...@@ -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) { 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 { if err != nil {
return types.GameMetadata{}, fmt.Errorf("failed to load game %v: %w", idx, err) 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 ...@@ -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) { 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 { if err != nil {
return common.Address{}, fmt.Errorf("failed to load game impl for type %v: %w", gameType, err) 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 ...@@ -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 { if err != nil {
return nil, fmt.Errorf("failed to fetch games: %w", err) return nil, fmt.Errorf("failed to fetch games: %w", err)
} }
...@@ -122,7 +123,7 @@ func (f *DisputeGameFactoryContract) GetAllGames(ctx context.Context, blockHash ...@@ -122,7 +123,7 @@ func (f *DisputeGameFactoryContract) GetAllGames(ctx context.Context, blockHash
calls[i] = f.contract.Call(methodGameAtIndex, new(big.Int).SetUint64(i)) 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 { if err != nil {
return nil, fmt.Errorf("failed to fetch games: %w", err) return nil, fmt.Errorf("failed to fetch games: %w", err)
} }
......
...@@ -10,6 +10,7 @@ import ( ...@@ -10,6 +10,7 @@ import (
"github.com/ethereum-optimism/optimism/op-bindings/bindings" "github.com/ethereum-optimism/optimism/op-bindings/bindings"
"github.com/ethereum-optimism/optimism/op-challenger/game/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"
"github.com/ethereum-optimism/optimism/op-service/sources/batching/rpcblock"
batchingTest "github.com/ethereum-optimism/optimism/op-service/sources/batching/test" batchingTest "github.com/ethereum-optimism/optimism/op-service/sources/batching/test"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
...@@ -42,7 +43,7 @@ func TestDisputeGameFactorySimpleGetters(t *testing.T) { ...@@ -42,7 +43,7 @@ func TestDisputeGameFactorySimpleGetters(t *testing.T) {
test := test test := test
t.Run(test.method, func(t *testing.T) { t.Run(test.method, func(t *testing.T) {
stubRpc, factory := setupDisputeGameFactoryTest(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) status, err := test.call(factory)
require.NoError(t, err) require.NoError(t, err)
expected := test.expected expected := test.expected
...@@ -101,7 +102,7 @@ func TestGetAllGames(t *testing.T) { ...@@ -101,7 +102,7 @@ func TestGetAllGames(t *testing.T) {
} }
expectedGames := []types.GameMetadata{game0, game1, game2} 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 { for idx, expected := range expectedGames {
expectGetGame(stubRpc, idx, blockHash, expected) expectGetGame(stubRpc, idx, blockHash, expected)
} }
...@@ -138,7 +139,7 @@ func TestGetAllGamesAtOrAfter(t *testing.T) { ...@@ -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 { for idx, expected := range allGames {
expectGetGame(stubRpc, idx, blockHash, expected) expectGetGame(stubRpc, idx, blockHash, expected)
} }
...@@ -169,7 +170,7 @@ func TestGetGameFromParameters(t *testing.T) { ...@@ -169,7 +170,7 @@ func TestGetGameFromParameters(t *testing.T) {
stubRpc.SetResponse( stubRpc.SetResponse(
factoryAddr, factoryAddr,
methodGames, methodGames,
batching.BlockLatest, rpcblock.Latest,
[]interface{}{traceType, outputRoot, l2BlockNum}, []interface{}{traceType, outputRoot, l2BlockNum},
[]interface{}{common.Address{0xaa}, uint64(1)}, []interface{}{common.Address{0xaa}, uint64(1)},
) )
...@@ -185,7 +186,7 @@ func TestGetGameImpl(t *testing.T) { ...@@ -185,7 +186,7 @@ func TestGetGameImpl(t *testing.T) {
stubRpc.SetResponse( stubRpc.SetResponse(
factoryAddr, factoryAddr,
methodGameImpls, methodGameImpls,
batching.BlockLatest, rpcblock.Latest,
[]interface{}{gameType}, []interface{}{gameType},
[]interface{}{gameImplAddr}) []interface{}{gameImplAddr})
actual, err := factory.GetGameImpl(context.Background(), gameType) actual, err := factory.GetGameImpl(context.Background(), gameType)
...@@ -197,7 +198,7 @@ func expectGetGame(stubRpc *batchingTest.AbiBasedRpc, idx int, blockHash common. ...@@ -197,7 +198,7 @@ func expectGetGame(stubRpc *batchingTest.AbiBasedRpc, idx int, blockHash common.
stubRpc.SetResponse( stubRpc.SetResponse(
factoryAddr, factoryAddr,
methodGameAtIndex, methodGameAtIndex,
batching.BlockByHash(blockHash), rpcblock.ByHash(blockHash),
[]interface{}{big.NewInt(int64(idx))}, []interface{}{big.NewInt(int64(idx))},
[]interface{}{ []interface{}{
game.GameType, game.GameType,
...@@ -211,7 +212,7 @@ func TestCreateTx(t *testing.T) { ...@@ -211,7 +212,7 @@ func TestCreateTx(t *testing.T) {
traceType := uint32(123) traceType := uint32(123)
outputRoot := common.Hash{0x01} outputRoot := common.Hash{0x01}
l2BlockNum := common.BigToHash(big.NewInt(456)).Bytes() 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)) tx, err := factory.CreateTx(traceType, outputRoot, uint64(456))
require.NoError(t, err) require.NoError(t, err)
stubRpc.VerifyTxCandidate(tx) stubRpc.VerifyTxCandidate(tx)
......
...@@ -15,6 +15,7 @@ import ( ...@@ -15,6 +15,7 @@ import (
keccakTypes "github.com/ethereum-optimism/optimism/op-challenger/game/keccak/types" keccakTypes "github.com/ethereum-optimism/optimism/op-challenger/game/keccak/types"
preimage "github.com/ethereum-optimism/optimism/op-preimage" 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"
"github.com/ethereum-optimism/optimism/op-service/sources/batching/rpcblock"
"github.com/ethereum-optimism/optimism/op-service/txmgr" "github.com/ethereum-optimism/optimism/op-service/txmgr"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
) )
...@@ -130,7 +131,7 @@ func (c *PreimageOracleContract) AddLeaves(uuid *big.Int, startingBlockIndex *bi ...@@ -130,7 +131,7 @@ func (c *PreimageOracleContract) AddLeaves(uuid *big.Int, startingBlockIndex *bi
// MinLargePreimageSize returns the minimum size of a large preimage. // MinLargePreimageSize returns the minimum size of a large preimage.
func (c *PreimageOracleContract) MinLargePreimageSize(ctx context.Context) (uint64, error) { 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 { if err != nil {
return 0, fmt.Errorf("failed to fetch min lpp size bytes: %w", err) 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 ...@@ -142,7 +143,7 @@ func (c *PreimageOracleContract) ChallengePeriod(ctx context.Context) (uint64, e
if period := c.challengePeriod.Load(); period != 0 { if period := c.challengePeriod.Load(); period != 0 {
return period, nil 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 { if err != nil {
return 0, fmt.Errorf("failed to fetch challenge period: %w", err) return 0, fmt.Errorf("failed to fetch challenge period: %w", err)
} }
...@@ -162,7 +163,7 @@ func (c *PreimageOracleContract) CallSqueeze( ...@@ -162,7 +163,7 @@ func (c *PreimageOracleContract) CallSqueeze(
postStateProof merkle.Proof, postStateProof merkle.Proof,
) error { ) error {
call := c.contract.Call(methodSqueezeLPP, claimant, uuid, abiEncodeSnapshot(prestateMatrix), toPreimageOracleLeaf(preState), preStateProof, toPreimageOracleLeaf(postState), postStateProof) 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 { if err != nil {
return fmt.Errorf("failed to call squeeze: %w", err) return fmt.Errorf("failed to call squeeze: %w", err)
} }
...@@ -196,7 +197,7 @@ func abiEncodeSnapshot(packedState keccakTypes.StateSnapshot) bindings.LibKeccak ...@@ -196,7 +197,7 @@ func abiEncodeSnapshot(packedState keccakTypes.StateSnapshot) bindings.LibKeccak
} }
func (c *PreimageOracleContract) GetActivePreimages(ctx context.Context, blockHash common.Hash) ([]keccakTypes.LargePreimageMetaData, error) { 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 { results, err := batching.ReadArray(ctx, c.multiCaller, block, c.contract.Call(methodProposalCount), func(i *big.Int) *batching.ContractCall {
return c.contract.Call(methodProposals, i) return c.contract.Call(methodProposals, i)
}) })
...@@ -212,7 +213,7 @@ func (c *PreimageOracleContract) GetActivePreimages(ctx context.Context, blockHa ...@@ -212,7 +213,7 @@ func (c *PreimageOracleContract) GetActivePreimages(ctx context.Context, blockHa
return c.GetProposalMetadata(ctx, block, idents...) 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 var calls []batching.Call
for _, ident := range idents { for _, ident := range idents {
calls = append(calls, c.contract.Call(methodProposalMetadata, ident.Claimant, ident.UUID)) calls = append(calls, c.contract.Call(methodProposalMetadata, ident.Claimant, ident.UUID))
...@@ -237,7 +238,7 @@ func (c *PreimageOracleContract) GetProposalMetadata(ctx context.Context, block ...@@ -237,7 +238,7 @@ func (c *PreimageOracleContract) GetProposalMetadata(ctx context.Context, block
return proposals, nil 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) call := c.contract.Call(methodGetTreeRootLPP, ident.Claimant, ident.UUID)
result, err := c.multiCaller.SingleCall(ctx, block, call) result, err := c.multiCaller.SingleCall(ctx, block, call)
if err != nil { if err != nil {
...@@ -246,7 +247,7 @@ func (c *PreimageOracleContract) GetProposalTreeRoot(ctx context.Context, block ...@@ -246,7 +247,7 @@ func (c *PreimageOracleContract) GetProposalTreeRoot(ctx context.Context, block
return result.GetHash(0), nil 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, results, err := batching.ReadArray(ctx, c.multiCaller, block,
c.contract.Call(methodProposalBlocksLen, ident.Claimant, ident.UUID), c.contract.Call(methodProposalBlocksLen, ident.Claimant, ident.UUID),
func(i *big.Int) *batching.ContractCall { func(i *big.Int) *batching.ContractCall {
...@@ -295,7 +296,7 @@ func (c *PreimageOracleContract) DecodeInputData(data []byte) (*big.Int, keccakT ...@@ -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) { 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))) 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 { if err != nil {
return false, fmt.Errorf("failed to get preimagePartOk: %w", err) return false, fmt.Errorf("failed to get preimagePartOk: %w", err)
} }
...@@ -329,7 +330,7 @@ func (c *PreimageOracleContract) GetMinBondLPP(ctx context.Context) (*big.Int, e ...@@ -329,7 +330,7 @@ func (c *PreimageOracleContract) GetMinBondLPP(ctx context.Context) (*big.Int, e
if bondSize := c.minBondSizeLPP.Load(); bondSize != 0 { if bondSize := c.minBondSizeLPP.Load(); bondSize != 0 {
return big.NewInt(int64(bondSize)), nil 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 { if err != nil {
return nil, fmt.Errorf("failed to fetch min bond size for LPPs: %w", err) return nil, fmt.Errorf("failed to fetch min bond size for LPPs: %w", err)
} }
......
...@@ -14,6 +14,7 @@ import ( ...@@ -14,6 +14,7 @@ import (
keccakTypes "github.com/ethereum-optimism/optimism/op-challenger/game/keccak/types" keccakTypes "github.com/ethereum-optimism/optimism/op-challenger/game/keccak/types"
preimage "github.com/ethereum-optimism/optimism/op-preimage" 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"
"github.com/ethereum-optimism/optimism/op-service/sources/batching/rpcblock"
batchingTest "github.com/ethereum-optimism/optimism/op-service/sources/batching/test" batchingTest "github.com/ethereum-optimism/optimism/op-service/sources/batching/test"
"github.com/ethereum-optimism/optimism/op-service/testutils" "github.com/ethereum-optimism/optimism/op-service/testutils"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
...@@ -31,7 +32,7 @@ func TestPreimageOracleContract_AddGlobalDataTx(t *testing.T) { ...@@ -31,7 +32,7 @@ func TestPreimageOracleContract_AddGlobalDataTx(t *testing.T) {
t.Run("Keccak256", func(t *testing.T) { t.Run("Keccak256", func(t *testing.T) {
stubRpc, oracle := setupPreimageOracleTest(t) stubRpc, oracle := setupPreimageOracleTest(t)
data := types.NewPreimageOracleData(common.Hash{byte(preimage.Keccak256KeyType), 0xcc}.Bytes(), make([]byte, 20), uint32(545)) 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)), new(big.Int).SetUint64(uint64(data.OracleOffset)),
data.GetPreimageWithoutSize(), data.GetPreimageWithoutSize(),
}, nil) }, nil)
...@@ -44,7 +45,7 @@ func TestPreimageOracleContract_AddGlobalDataTx(t *testing.T) { ...@@ -44,7 +45,7 @@ func TestPreimageOracleContract_AddGlobalDataTx(t *testing.T) {
t.Run("Sha256", func(t *testing.T) { t.Run("Sha256", func(t *testing.T) {
stubRpc, oracle := setupPreimageOracleTest(t) stubRpc, oracle := setupPreimageOracleTest(t)
data := types.NewPreimageOracleData(common.Hash{byte(preimage.Sha256KeyType), 0xcc}.Bytes(), make([]byte, 20), uint32(545)) 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)), new(big.Int).SetUint64(uint64(data.OracleOffset)),
data.GetPreimageWithoutSize(), data.GetPreimageWithoutSize(),
}, nil) }, nil)
...@@ -58,7 +59,7 @@ func TestPreimageOracleContract_AddGlobalDataTx(t *testing.T) { ...@@ -58,7 +59,7 @@ func TestPreimageOracleContract_AddGlobalDataTx(t *testing.T) {
stubRpc, oracle := setupPreimageOracleTest(t) stubRpc, oracle := setupPreimageOracleTest(t)
fieldData := testutils.RandomData(rand.New(rand.NewSource(23)), 32) fieldData := testutils.RandomData(rand.New(rand.NewSource(23)), 32)
data := types.NewPreimageOracleData(common.Hash{byte(preimage.BlobKeyType), 0xcc}.Bytes(), fieldData, uint32(545)) 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).SetUint64(data.BlobFieldIndex),
new(big.Int).SetBytes(data.GetPreimageWithoutSize()), new(big.Int).SetBytes(data.GetPreimageWithoutSize()),
data.BlobCommitment, data.BlobCommitment,
...@@ -75,7 +76,7 @@ func TestPreimageOracleContract_AddGlobalDataTx(t *testing.T) { ...@@ -75,7 +76,7 @@ func TestPreimageOracleContract_AddGlobalDataTx(t *testing.T) {
stubRpc, oracle := setupPreimageOracleTest(t) stubRpc, oracle := setupPreimageOracleTest(t)
input := testutils.RandomData(rand.New(rand.NewSource(23)), 200) input := testutils.RandomData(rand.New(rand.NewSource(23)), 200)
data := types.NewPreimageOracleData(common.Hash{byte(preimage.PrecompileKeyType), 0xcc}.Bytes(), input, uint32(545)) 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)), new(big.Int).SetUint64(uint64(data.OracleOffset)),
data.GetPrecompileAddress(), data.GetPrecompileAddress(),
data.GetPrecompileInput(), data.GetPrecompileInput(),
...@@ -89,7 +90,7 @@ func TestPreimageOracleContract_AddGlobalDataTx(t *testing.T) { ...@@ -89,7 +90,7 @@ func TestPreimageOracleContract_AddGlobalDataTx(t *testing.T) {
func TestPreimageOracleContract_ChallengePeriod(t *testing.T) { func TestPreimageOracleContract_ChallengePeriod(t *testing.T) {
stubRpc, oracle := setupPreimageOracleTest(t) stubRpc, oracle := setupPreimageOracleTest(t)
stubRpc.SetResponse(oracleAddr, methodChallengePeriod, batching.BlockLatest, stubRpc.SetResponse(oracleAddr, methodChallengePeriod, rpcblock.Latest,
[]interface{}{}, []interface{}{},
[]interface{}{big.NewInt(123)}, []interface{}{big.NewInt(123)},
) )
...@@ -106,7 +107,7 @@ func TestPreimageOracleContract_ChallengePeriod(t *testing.T) { ...@@ -106,7 +107,7 @@ func TestPreimageOracleContract_ChallengePeriod(t *testing.T) {
func TestPreimageOracleContract_MinLargePreimageSize(t *testing.T) { func TestPreimageOracleContract_MinLargePreimageSize(t *testing.T) {
stubRpc, oracle := setupPreimageOracleTest(t) stubRpc, oracle := setupPreimageOracleTest(t)
stubRpc.SetResponse(oracleAddr, methodMinProposalSize, batching.BlockLatest, stubRpc.SetResponse(oracleAddr, methodMinProposalSize, rpcblock.Latest,
[]interface{}{}, []interface{}{},
[]interface{}{big.NewInt(123)}, []interface{}{big.NewInt(123)},
) )
...@@ -117,7 +118,7 @@ func TestPreimageOracleContract_MinLargePreimageSize(t *testing.T) { ...@@ -117,7 +118,7 @@ func TestPreimageOracleContract_MinLargePreimageSize(t *testing.T) {
func TestPreimageOracleContract_MinBondSizeLPP(t *testing.T) { func TestPreimageOracleContract_MinBondSizeLPP(t *testing.T) {
stubRpc, oracle := setupPreimageOracleTest(t) stubRpc, oracle := setupPreimageOracleTest(t)
stubRpc.SetResponse(oracleAddr, methodMinBondSizeLPP, batching.BlockLatest, stubRpc.SetResponse(oracleAddr, methodMinBondSizeLPP, rpcblock.Latest,
[]interface{}{}, []interface{}{},
[]interface{}{big.NewInt(123)}, []interface{}{big.NewInt(123)},
) )
...@@ -136,7 +137,7 @@ func TestPreimageOracleContract_PreimageDataExists(t *testing.T) { ...@@ -136,7 +137,7 @@ func TestPreimageOracleContract_PreimageDataExists(t *testing.T) {
t.Run("exists", func(t *testing.T) { t.Run("exists", func(t *testing.T) {
stubRpc, oracle := setupPreimageOracleTest(t) stubRpc, oracle := setupPreimageOracleTest(t)
data := types.NewPreimageOracleData(common.Hash{0xcc}.Bytes(), make([]byte, 20), 545) 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{}{common.Hash(data.OracleKey), new(big.Int).SetUint64(uint64(data.OracleOffset))},
[]interface{}{true}, []interface{}{true},
) )
...@@ -147,7 +148,7 @@ func TestPreimageOracleContract_PreimageDataExists(t *testing.T) { ...@@ -147,7 +148,7 @@ func TestPreimageOracleContract_PreimageDataExists(t *testing.T) {
t.Run("does not exist", func(t *testing.T) { t.Run("does not exist", func(t *testing.T) {
stubRpc, oracle := setupPreimageOracleTest(t) stubRpc, oracle := setupPreimageOracleTest(t)
data := types.NewPreimageOracleData(common.Hash{0xcc}.Bytes(), make([]byte, 20), 545) 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{}{common.Hash(data.OracleKey), new(big.Int).SetUint64(uint64(data.OracleOffset))},
[]interface{}{false}, []interface{}{false},
) )
...@@ -163,7 +164,7 @@ func TestPreimageOracleContract_InitLargePreimage(t *testing.T) { ...@@ -163,7 +164,7 @@ func TestPreimageOracleContract_InitLargePreimage(t *testing.T) {
uuid := big.NewInt(123) uuid := big.NewInt(123)
partOffset := uint32(1) partOffset := uint32(1)
claimedSize := uint32(2) claimedSize := uint32(2)
stubRpc.SetResponse(oracleAddr, methodInitLPP, batching.BlockLatest, []interface{}{ stubRpc.SetResponse(oracleAddr, methodInitLPP, rpcblock.Latest, []interface{}{
uuid, uuid,
partOffset, partOffset,
claimedSize, claimedSize,
...@@ -182,7 +183,7 @@ func TestPreimageOracleContract_AddLeaves(t *testing.T) { ...@@ -182,7 +183,7 @@ func TestPreimageOracleContract_AddLeaves(t *testing.T) {
input := []byte{0x12} input := []byte{0x12}
commitments := []common.Hash{{0x34}} commitments := []common.Hash{{0x34}}
finalize := true finalize := true
stubRpc.SetResponse(oracleAddr, methodAddLeavesLPP, batching.BlockLatest, []interface{}{ stubRpc.SetResponse(oracleAddr, methodAddLeavesLPP, rpcblock.Latest, []interface{}{
uuid, uuid,
startingBlockIndex, startingBlockIndex,
input, input,
...@@ -213,7 +214,7 @@ func TestPreimageOracleContract_Squeeze(t *testing.T) { ...@@ -213,7 +214,7 @@ func TestPreimageOracleContract_Squeeze(t *testing.T) {
StateCommitment: common.Hash{0x56}, StateCommitment: common.Hash{0x56},
} }
postStateProof := merkle.Proof{{0x56}} postStateProof := merkle.Proof{{0x56}}
stubRpc.SetResponse(oracleAddr, methodSqueezeLPP, batching.BlockLatest, []interface{}{ stubRpc.SetResponse(oracleAddr, methodSqueezeLPP, rpcblock.Latest, []interface{}{
claimant, claimant,
uuid, uuid,
abiEncodeSnapshot(preStateMatrix), abiEncodeSnapshot(preStateMatrix),
...@@ -230,7 +231,7 @@ func TestPreimageOracleContract_Squeeze(t *testing.T) { ...@@ -230,7 +231,7 @@ func TestPreimageOracleContract_Squeeze(t *testing.T) {
func TestGetActivePreimages(t *testing.T) { func TestGetActivePreimages(t *testing.T) {
blockHash := common.Hash{0xaa} 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) preimages, err := oracle.GetActivePreimages(context.Background(), blockHash)
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, proposals, preimages) require.Equal(t, proposals, preimages)
...@@ -238,7 +239,7 @@ func TestGetActivePreimages(t *testing.T) { ...@@ -238,7 +239,7 @@ func TestGetActivePreimages(t *testing.T) {
func TestGetProposalMetadata(t *testing.T) { func TestGetProposalMetadata(t *testing.T) {
blockHash := common.Hash{0xaa} blockHash := common.Hash{0xaa}
block := batching.BlockByHash(blockHash) block := rpcblock.ByHash(blockHash)
stubRpc, oracle, proposals := setupPreimageOracleTestWithProposals(t, block) stubRpc, oracle, proposals := setupPreimageOracleTestWithProposals(t, block)
preimages, err := oracle.GetProposalMetadata( preimages, err := oracle.GetProposalMetadata(
context.Background(), context.Background(),
...@@ -259,7 +260,7 @@ func TestGetProposalMetadata(t *testing.T) { ...@@ -259,7 +260,7 @@ func TestGetProposalMetadata(t *testing.T) {
block, block,
[]interface{}{ident.Claimant, ident.UUID}, []interface{}{ident.Claimant, ident.UUID},
[]interface{}{meta}) []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.NoError(t, err)
require.Equal(t, []keccakTypes.LargePreimageMetaData{{LargePreimageIdent: ident}}, preimages) require.Equal(t, []keccakTypes.LargePreimageMetaData{{LargePreimageIdent: ident}}, preimages)
} }
...@@ -269,15 +270,15 @@ func TestGetProposalTreeRoot(t *testing.T) { ...@@ -269,15 +270,15 @@ func TestGetProposalTreeRoot(t *testing.T) {
expectedRoot := common.Hash{0xbb} expectedRoot := common.Hash{0xbb}
ident := keccakTypes.LargePreimageIdent{Claimant: common.Address{0x12}, UUID: big.NewInt(123)} ident := keccakTypes.LargePreimageIdent{Claimant: common.Address{0x12}, UUID: big.NewInt(123)}
stubRpc, oracle := setupPreimageOracleTest(t) stubRpc, oracle := setupPreimageOracleTest(t)
stubRpc.SetResponse(oracleAddr, methodGetTreeRootLPP, batching.BlockByHash(blockHash), stubRpc.SetResponse(oracleAddr, methodGetTreeRootLPP, rpcblock.ByHash(blockHash),
[]interface{}{ident.Claimant, ident.UUID}, []interface{}{ident.Claimant, ident.UUID},
[]interface{}{expectedRoot}) []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.NoError(t, err)
require.Equal(t, expectedRoot, actualRoot) 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, oracle := setupPreimageOracleTest(t)
stubRpc.SetResponse( stubRpc.SetResponse(
oracleAddr, oracleAddr,
...@@ -427,7 +428,7 @@ func TestMetadata_Countered(t *testing.T) { ...@@ -427,7 +428,7 @@ func TestMetadata_Countered(t *testing.T) {
func TestGetInputDataBlocks(t *testing.T) { func TestGetInputDataBlocks(t *testing.T) {
stubRpc, oracle := setupPreimageOracleTest(t) stubRpc, oracle := setupPreimageOracleTest(t)
block := batching.BlockByHash(common.Hash{0xaa}) block := rpcblock.ByHash(common.Hash{0xaa})
preimage := keccakTypes.LargePreimageIdent{ preimage := keccakTypes.LargePreimageIdent{
Claimant: common.Address{0xbb}, Claimant: common.Address{0xbb},
...@@ -589,7 +590,7 @@ func TestChallenge_First(t *testing.T) { ...@@ -589,7 +590,7 @@ func TestChallenge_First(t *testing.T) {
}, },
PoststateProof: merkle.Proof{common.Hash{0x01}, common.Hash{0x02}}, PoststateProof: merkle.Proof{common.Hash{0x01}, common.Hash{0x02}},
} }
stubRpc.SetResponse(oracleAddr, methodChallengeFirstLPP, batching.BlockLatest, stubRpc.SetResponse(oracleAddr, methodChallengeFirstLPP, rpcblock.Latest,
[]interface{}{ []interface{}{
ident.Claimant, ident.UUID, ident.Claimant, ident.UUID,
bindings.PreimageOracleLeaf{ bindings.PreimageOracleLeaf{
...@@ -627,7 +628,7 @@ func TestChallenge_NotFirst(t *testing.T) { ...@@ -627,7 +628,7 @@ func TestChallenge_NotFirst(t *testing.T) {
}, },
PoststateProof: merkle.Proof{common.Hash{0x03}, common.Hash{0x04}}, PoststateProof: merkle.Proof{common.Hash{0x03}, common.Hash{0x04}},
} }
stubRpc.SetResponse(oracleAddr, methodChallengeLPP, batching.BlockLatest, stubRpc.SetResponse(oracleAddr, methodChallengeLPP, rpcblock.Latest,
[]interface{}{ []interface{}{
ident.Claimant, ident.UUID, ident.Claimant, ident.UUID,
bindings.LibKeccakStateMatrix{State: challenge.StateMatrix}, bindings.LibKeccakStateMatrix{State: challenge.StateMatrix},
......
...@@ -6,6 +6,7 @@ import ( ...@@ -6,6 +6,7 @@ import (
"github.com/ethereum-optimism/optimism/op-bindings/bindings" "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"
"github.com/ethereum-optimism/optimism/op-service/sources/batching/rpcblock"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
) )
...@@ -32,7 +33,7 @@ func NewVMContract(addr common.Address, caller *batching.MultiCaller) (*VMContra ...@@ -32,7 +33,7 @@ func NewVMContract(addr common.Address, caller *batching.MultiCaller) (*VMContra
} }
func (c *VMContract) Oracle(ctx context.Context) (*PreimageOracleContract, error) { 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 { if err != nil {
return nil, fmt.Errorf("failed to load oracle address: %w", err) return nil, fmt.Errorf("failed to load oracle address: %w", err)
} }
......
...@@ -8,6 +8,7 @@ import ( ...@@ -8,6 +8,7 @@ import (
"github.com/ethereum-optimism/optimism/op-challenger/game/fault/types" "github.com/ethereum-optimism/optimism/op-challenger/game/fault/types"
preimage "github.com/ethereum-optimism/optimism/op-preimage" 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"
"github.com/ethereum-optimism/optimism/op-service/sources/batching/rpcblock"
batchingTest "github.com/ethereum-optimism/optimism/op-service/sources/batching/test" batchingTest "github.com/ethereum-optimism/optimism/op-service/sources/batching/test"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
...@@ -21,7 +22,7 @@ func TestVMContract_Oracle(t *testing.T) { ...@@ -21,7 +22,7 @@ func TestVMContract_Oracle(t *testing.T) {
vmContract, err := NewVMContract(vmAddr, batching.NewMultiCaller(stubRpc, batching.DefaultBatchSize)) vmContract, err := NewVMContract(vmAddr, batching.NewMultiCaller(stubRpc, batching.DefaultBatchSize))
require.NoError(t, err) 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()) oracleContract, err := vmContract.Oracle(context.Background())
require.NoError(t, err) require.NoError(t, err)
......
...@@ -13,7 +13,7 @@ import ( ...@@ -13,7 +13,7 @@ import (
"github.com/ethereum-optimism/optimism/op-challenger/game/keccak/matrix" "github.com/ethereum-optimism/optimism/op-challenger/game/keccak/matrix"
keccakTypes "github.com/ethereum-optimism/optimism/op-challenger/game/keccak/types" keccakTypes "github.com/ethereum-optimism/optimism/op-challenger/game/keccak/types"
gameTypes "github.com/ethereum-optimism/optimism/op-challenger/game/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-optimism/optimism/op-service/txmgr"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/common/hexutil"
...@@ -60,7 +60,7 @@ func (p *LargePreimageUploader) UploadPreimage(ctx context.Context, parent uint6 ...@@ -60,7 +60,7 @@ func (p *LargePreimageUploader) UploadPreimage(ctx context.Context, parent uint6
// Fetch the current metadata for this preimage data, if it exists. // Fetch the current metadata for this preimage data, if it exists.
ident := keccakTypes.LargePreimageIdent{Claimant: p.txSender.From(), UUID: uuid} 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 { if err != nil {
return fmt.Errorf("failed to get pre-image oracle metadata: %w", err) 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 ...@@ -132,7 +132,7 @@ func (p *LargePreimageUploader) Squeeze(ctx context.Context, uuid *big.Int, stat
} }
currentTimestamp := p.clock.Now().Unix() currentTimestamp := p.clock.Now().Unix()
ident := keccakTypes.LargePreimageIdent{Claimant: p.txSender.From(), UUID: uuid} 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 { if err != nil {
return fmt.Errorf("failed to get pre-image oracle metadata: %w", err) return fmt.Errorf("failed to get pre-image oracle metadata: %w", err)
} }
......
...@@ -16,7 +16,7 @@ import ( ...@@ -16,7 +16,7 @@ import (
keccakTypes "github.com/ethereum-optimism/optimism/op-challenger/game/keccak/types" keccakTypes "github.com/ethereum-optimism/optimism/op-challenger/game/keccak/types"
preimage "github.com/ethereum-optimism/optimism/op-preimage" preimage "github.com/ethereum-optimism/optimism/op-preimage"
"github.com/ethereum-optimism/optimism/op-service/clock" "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/testlog"
"github.com/ethereum-optimism/optimism/op-service/txmgr" "github.com/ethereum-optimism/optimism/op-service/txmgr"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
...@@ -310,7 +310,7 @@ func (s *mockPreimageOracleContract) ChallengePeriod(_ context.Context) (uint64, ...@@ -310,7 +310,7 @@ func (s *mockPreimageOracleContract) ChallengePeriod(_ context.Context) (uint64,
return mockChallengePeriod, nil 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 { if s.squeezeCallClaimSize > 0 {
metadata := make([]keccakTypes.LargePreimageMetaData, 0) metadata := make([]keccakTypes.LargePreimageMetaData, 0)
for _, ident := range idents { for _, ident := range idents {
......
...@@ -8,7 +8,7 @@ import ( ...@@ -8,7 +8,7 @@ import (
"github.com/ethereum-optimism/optimism/op-challenger/game/fault/types" "github.com/ethereum-optimism/optimism/op-challenger/game/fault/types"
"github.com/ethereum-optimism/optimism/op-challenger/game/keccak/merkle" "github.com/ethereum-optimism/optimism/op-challenger/game/keccak/merkle"
keccakTypes "github.com/ethereum-optimism/optimism/op-challenger/game/keccak/types" 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-optimism/optimism/op-service/txmgr"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
) )
...@@ -27,7 +27,7 @@ type PreimageOracleContract interface { ...@@ -27,7 +27,7 @@ type PreimageOracleContract interface {
AddLeaves(uuid *big.Int, startingBlockIndex *big.Int, input []byte, commitments []common.Hash, finalize bool) (txmgr.TxCandidate, error) 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) 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 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) ChallengePeriod(ctx context.Context) (uint64, error)
GetMinBondLPP(ctx context.Context) (*big.Int, error) GetMinBondLPP(ctx context.Context) (*big.Int, error)
} }
...@@ -8,7 +8,7 @@ import ( ...@@ -8,7 +8,7 @@ import (
"github.com/ethereum-optimism/optimism/op-challenger/game/fault/contracts" "github.com/ethereum-optimism/optimism/op-challenger/game/fault/contracts"
keccakTypes "github.com/ethereum-optimism/optimism/op-challenger/game/keccak/types" 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/common"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
...@@ -26,7 +26,7 @@ type L1Source interface { ...@@ -26,7 +26,7 @@ type L1Source interface {
type Oracle interface { type Oracle interface {
Addr() common.Address 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) DecodeInputData(data []byte) (*big.Int, keccakTypes.InputData, error)
} }
...@@ -36,7 +36,7 @@ type InputFetcher struct { ...@@ -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) { 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 { if err != nil {
return nil, fmt.Errorf("failed to retrieve leaf block nums: %w", err) return nil, fmt.Errorf("failed to retrieve leaf block nums: %w", err)
} }
......
...@@ -9,7 +9,7 @@ import ( ...@@ -9,7 +9,7 @@ import (
"github.com/ethereum-optimism/optimism/op-challenger/game/fault/contracts" "github.com/ethereum-optimism/optimism/op-challenger/game/fault/contracts"
keccakTypes "github.com/ethereum-optimism/optimism/op-challenger/game/keccak/types" 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-optimism/optimism/op-service/testlog"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
...@@ -188,7 +188,7 @@ func (o *stubOracle) Addr() common.Address { ...@@ -188,7 +188,7 @@ func (o *stubOracle) Addr() common.Address {
return oracleAddr 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 return o.leafBlocks, nil
} }
......
...@@ -10,7 +10,7 @@ import ( ...@@ -10,7 +10,7 @@ import (
keccakTypes "github.com/ethereum-optimism/optimism/op-challenger/game/keccak/types" 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/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/testlog"
"github.com/ethereum-optimism/optimism/op-service/txmgr" "github.com/ethereum-optimism/optimism/op-service/txmgr"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
...@@ -77,7 +77,7 @@ func (s *stubOracle) ChallengePeriod(_ context.Context) (uint64, error) { ...@@ -77,7 +77,7 @@ func (s *stubOracle) ChallengePeriod(_ context.Context) (uint64, error) {
return stubChallengePeriod, nil 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") panic("not supported")
} }
...@@ -106,7 +106,7 @@ func (s *stubOracle) ChallengeTx(_ keccakTypes.LargePreimageIdent, _ keccakTypes ...@@ -106,7 +106,7 @@ func (s *stubOracle) ChallengeTx(_ keccakTypes.LargePreimageIdent, _ keccakTypes
panic("not supported") 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] root, ok := s.treeRoots[ident]
if ok { if ok {
return root, nil return root, nil
......
...@@ -6,7 +6,7 @@ import ( ...@@ -6,7 +6,7 @@ import (
"time" "time"
"github.com/ethereum-optimism/optimism/op-challenger/game/keccak/merkle" "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-optimism/optimism/op-service/txmgr"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/math" "github.com/ethereum/go-ethereum/common/math"
...@@ -99,8 +99,8 @@ type Challenge struct { ...@@ -99,8 +99,8 @@ type Challenge struct {
type LargePreimageOracle interface { type LargePreimageOracle interface {
Addr() common.Address Addr() common.Address
GetActivePreimages(ctx context.Context, blockHash common.Hash) ([]LargePreimageMetaData, error) GetActivePreimages(ctx context.Context, blockHash common.Hash) ([]LargePreimageMetaData, error)
GetInputDataBlocks(ctx context.Context, block batching.Block, ident LargePreimageIdent) ([]uint64, error) GetInputDataBlocks(ctx context.Context, block rpcblock.Block, ident LargePreimageIdent) ([]uint64, error)
GetProposalTreeRoot(ctx context.Context, block batching.Block, ident LargePreimageIdent) (common.Hash, error) GetProposalTreeRoot(ctx context.Context, block rpcblock.Block, ident LargePreimageIdent) (common.Hash, error)
DecodeInputData(data []byte) (*big.Int, InputData, error) DecodeInputData(data []byte) (*big.Int, InputData, error)
ChallengeTx(ident LargePreimageIdent, challenge Challenge) (txmgr.TxCandidate, error) ChallengeTx(ident LargePreimageIdent, challenge Challenge) (txmgr.TxCandidate, error)
ChallengePeriod(ctx context.Context) (uint64, error) ChallengePeriod(ctx context.Context) (uint64, error)
......
...@@ -10,7 +10,7 @@ import ( ...@@ -10,7 +10,7 @@ import (
"github.com/ethereum-optimism/optimism/op-challenger/game/keccak/fetcher" "github.com/ethereum-optimism/optimism/op-challenger/game/keccak/fetcher"
"github.com/ethereum-optimism/optimism/op-challenger/game/keccak/matrix" "github.com/ethereum-optimism/optimism/op-challenger/game/keccak/matrix"
keccakTypes "github.com/ethereum-optimism/optimism/op-challenger/game/keccak/types" 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/common"
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
lru "github.com/hashicorp/golang-lru/v2" lru "github.com/hashicorp/golang-lru/v2"
...@@ -20,7 +20,7 @@ const validPreimageCacheSize = 500 ...@@ -20,7 +20,7 @@ const validPreimageCacheSize = 500
type VerifierPreimageOracle interface { type VerifierPreimageOracle interface {
fetcher.Oracle 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 { type Fetcher interface {
...@@ -47,7 +47,7 @@ func NewPreimageVerifier(logger log.Logger, fetcher Fetcher) *PreimageVerifier { ...@@ -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) { 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 { if err != nil {
return keccakTypes.Challenge{}, fmt.Errorf("failed to get proposal merkle root: %w", err) return keccakTypes.Challenge{}, fmt.Errorf("failed to get proposal merkle root: %w", err)
} }
......
...@@ -10,7 +10,7 @@ import ( ...@@ -10,7 +10,7 @@ import (
"github.com/ethereum-optimism/optimism/op-challenger/game/scheduler" "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/scheduler/test"
"github.com/ethereum-optimism/optimism/op-challenger/game/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"
"github.com/ethereum-optimism/optimism/op-service/txmgr" "github.com/ethereum-optimism/optimism/op-service/txmgr"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
...@@ -97,7 +97,7 @@ func (s stubPreimageOracle) ChallengePeriod(_ context.Context) (uint64, error) { ...@@ -97,7 +97,7 @@ func (s stubPreimageOracle) ChallengePeriod(_ context.Context) (uint64, error) {
panic("not supported") 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") panic("not supported")
} }
...@@ -105,7 +105,7 @@ func (s stubPreimageOracle) ChallengeTx(_ keccakTypes.LargePreimageIdent, _ kecc ...@@ -105,7 +105,7 @@ func (s stubPreimageOracle) ChallengeTx(_ keccakTypes.LargePreimageIdent, _ kecc
panic("not supported") 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") panic("not supported")
} }
......
...@@ -7,13 +7,13 @@ import ( ...@@ -7,13 +7,13 @@ import (
faultTypes "github.com/ethereum-optimism/optimism/op-challenger/game/fault/types" faultTypes "github.com/ethereum-optimism/optimism/op-challenger/game/fault/types"
monTypes "github.com/ethereum-optimism/optimism/op-dispute-mon/mon/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/ethereum/go-ethereum/common"
"golang.org/x/exp/maps" "golang.org/x/exp/maps"
) )
type BondContract interface { 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 // 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 ...@@ -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 { if err != nil {
return nil, fmt.Errorf("failed to load credits: %w", err) return nil, fmt.Errorf("failed to load credits: %w", err)
} }
......
...@@ -7,7 +7,7 @@ import ( ...@@ -7,7 +7,7 @@ import (
"github.com/ethereum-optimism/optimism/op-challenger/game/fault/types" "github.com/ethereum-optimism/optimism/op-challenger/game/fault/types"
monTypes "github.com/ethereum-optimism/optimism/op-dispute-mon/mon/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/ethereum/go-ethereum/common"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
...@@ -51,7 +51,7 @@ type stubBondContract struct { ...@@ -51,7 +51,7 @@ type stubBondContract struct {
credits map[common.Address]*big.Int 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)) results := make([]*big.Int, len(recipients))
for i, recipient := range recipients { for i, recipient := range recipients {
credit, ok := s.credits[recipient] credit, ok := s.credits[recipient]
......
...@@ -22,6 +22,7 @@ import ( ...@@ -22,6 +22,7 @@ import (
"github.com/ethereum-optimism/optimism/op-e2e/e2eutils/wait" "github.com/ethereum-optimism/optimism/op-e2e/e2eutils/wait"
preimage "github.com/ethereum-optimism/optimism/op-preimage" 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"
"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/testlog"
"github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
...@@ -267,7 +268,7 @@ func (g *OutputCannonGameHelper) VerifyPreimage(ctx context.Context, outputRootC ...@@ -267,7 +268,7 @@ func (g *OutputCannonGameHelper) VerifyPreimage(ctx context.Context, outputRootC
abi, err := bindings.MIPSMetaData.GetAbi() abi, err := bindings.MIPSMetaData.GetAbi()
g.require.NoError(err, "Failed to load MIPS ABI") g.require.NoError(err, "Failed to load MIPS ABI")
caller := batching.NewMultiCaller(g.client.Client(), batching.DefaultBatchSize) 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, Abi: abi,
Addr: vmAddr, Addr: vmAddr,
Method: "step", Method: "step",
......
...@@ -18,6 +18,7 @@ import ( ...@@ -18,6 +18,7 @@ import (
preimage "github.com/ethereum-optimism/optimism/op-preimage" preimage "github.com/ethereum-optimism/optimism/op-preimage"
"github.com/ethereum-optimism/optimism/op-service/eth" "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"
"github.com/ethereum-optimism/optimism/op-service/sources/batching/rpcblock"
"github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
gethtypes "github.com/ethereum/go-ethereum/core/types" gethtypes "github.com/ethereum/go-ethereum/core/types"
...@@ -611,7 +612,7 @@ func (g *OutputGameHelper) WaitForChallengePeriodStart(ctx context.Context, send ...@@ -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 { func (g *OutputGameHelper) ChallengePeriodStartTime(ctx context.Context, sender common.Address, data *types.PreimageOracleData) uint64 {
oracle := g.oracle(ctx) oracle := g.oracle(ctx)
uuid := preimages.NewUUID(sender, data) 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, Claimant: sender,
UUID: uuid, UUID: uuid,
}) })
......
...@@ -18,6 +18,7 @@ import ( ...@@ -18,6 +18,7 @@ import (
"github.com/ethereum-optimism/optimism/op-challenger/game/keccak/types" "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-e2e/e2eutils/wait"
"github.com/ethereum-optimism/optimism/op-service/sources/batching" "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-optimism/optimism/op-service/testutils"
"github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
...@@ -127,7 +128,7 @@ func (h *Helper) WaitForChallenged(ctx context.Context, ident types.LargePreimag ...@@ -127,7 +128,7 @@ func (h *Helper) WaitForChallenged(ctx context.Context, ident types.LargePreimag
timedCtx, cancel := context.WithTimeout(ctx, 30*time.Second) timedCtx, cancel := context.WithTimeout(ctx, 30*time.Second)
defer cancel() defer cancel()
err := wait.For(timedCtx, time.Second, func() (bool, error) { 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 { if err != nil {
return false, err return false, err
} }
......
...@@ -4,13 +4,15 @@ import ( ...@@ -4,13 +4,15 @@ import (
"context" "context"
"fmt" "fmt"
"math/big" "math/big"
"github.com/ethereum-optimism/optimism/op-service/sources/batching/rpcblock"
) )
// ReadArray uses batch calls to load all entries from an array. // 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 // 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. // 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. // 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) result, err := caller.SingleCall(ctx, block, countCall)
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to load array length: %w", err) return nil, fmt.Errorf("failed to load array length: %w", err)
......
...@@ -4,6 +4,7 @@ import ( ...@@ -4,6 +4,7 @@ import (
"fmt" "fmt"
"math/big" "math/big"
"github.com/ethereum-optimism/optimism/op-service/sources/batching/rpcblock"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/rpc" "github.com/ethereum/go-ethereum/rpc"
...@@ -20,11 +21,11 @@ func NewBalanceCall(addr common.Address) *BalanceCall { ...@@ -20,11 +21,11 @@ func NewBalanceCall(addr common.Address) *BalanceCall {
} }
func (b *BalanceCall) ToBatchElemCreator() (BatchElementCreator, error) { 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) out := new(hexutil.Big)
return out, rpc.BatchElem{ return out, rpc.BatchElem{
Method: "eth_getBalance", Method: "eth_getBalance",
Args: []interface{}{b.addr, block.value}, Args: []interface{}{b.addr, block.ArgValue()},
Result: &out, Result: &out,
} }
}, nil }, nil
......
package test package batching
import ( import (
"context" "context"
"math/big" "math/big"
"testing" "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/ethereum/go-ethereum/common"
"github.com/stretchr/testify/require" "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) { func TestGetBalance(t *testing.T) {
addr := common.Address{0xab, 0xcd} addr := common.Address{0xab, 0xcd}
expectedBalance := big.NewInt(248924) expectedBalance := big.NewInt(248924)
stub := NewRpcStub(t) stub := test.NewRpcStub(t)
stub.AddExpectedCall(NewGetBalanceCall(addr, batching.BlockLatest, expectedBalance)) stub.AddExpectedCall(test.NewGetBalanceCall(addr, rpcblock.Latest, expectedBalance))
caller := batching.NewMultiCaller(stub, batching.DefaultBatchSize) caller := NewMultiCaller(stub, DefaultBatchSize)
result, err := caller.SingleCall(context.Background(), batching.BlockLatest, batching.NewBalanceCall(addr)) result, err := caller.SingleCall(context.Background(), rpcblock.Latest, NewBalanceCall(addr))
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, expectedBalance, result.GetBigInt(0)) require.Equal(t, expectedBalance, result.GetBigInt(0))
} }
...@@ -3,12 +3,13 @@ package batching ...@@ -3,12 +3,13 @@ package batching
import ( import (
"math/big" "math/big"
"github.com/ethereum-optimism/optimism/op-service/sources/batching/rpcblock"
"github.com/ethereum/go-ethereum/accounts/abi" "github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/rpc" "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 { type Call interface {
ToBatchElemCreator() (BatchElementCreator, error) ToBatchElemCreator() (BatchElementCreator, error)
......
...@@ -3,6 +3,7 @@ package batching ...@@ -3,6 +3,7 @@ package batching
import ( import (
"fmt" "fmt"
"github.com/ethereum-optimism/optimism/op-service/sources/batching/rpcblock"
"github.com/ethereum-optimism/optimism/op-service/txmgr" "github.com/ethereum-optimism/optimism/op-service/txmgr"
"github.com/ethereum/go-ethereum/accounts/abi" "github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
...@@ -40,11 +41,11 @@ func (c *ContractCall) ToBatchElemCreator() (BatchElementCreator, error) { ...@@ -40,11 +41,11 @@ func (c *ContractCall) ToBatchElemCreator() (BatchElementCreator, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
f := func(block Block) (any, rpc.BatchElem) { f := func(block rpcblock.Block) (any, rpc.BatchElem) {
out := new(hexutil.Bytes) out := new(hexutil.Bytes)
return out, rpc.BatchElem{ return out, rpc.BatchElem{
Method: "eth_call", Method: "eth_call",
Args: []interface{}{args, block.value}, Args: []interface{}{args, block.ArgValue()},
Result: &out, Result: &out,
} }
} }
......
...@@ -5,7 +5,7 @@ import ( ...@@ -5,7 +5,7 @@ import (
"fmt" "fmt"
"io" "io"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum-optimism/optimism/op-service/sources/batching/rpcblock"
"github.com/ethereum/go-ethereum/rpc" "github.com/ethereum/go-ethereum/rpc"
) )
...@@ -32,7 +32,7 @@ func (m *MultiCaller) BatchSize() int { ...@@ -32,7 +32,7 @@ func (m *MultiCaller) BatchSize() int {
return m.batchSize 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) results, err := m.Call(ctx, block, call)
if err != nil { if err != nil {
return nil, err return nil, err
...@@ -40,7 +40,7 @@ func (m *MultiCaller) SingleCall(ctx context.Context, block Block, call Call) (* ...@@ -40,7 +40,7 @@ func (m *MultiCaller) SingleCall(ctx context.Context, block Block, call Call) (*
return results[0], nil 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)) keys := make([]BatchElementCreator, len(calls))
for i := 0; i < len(calls); i++ { for i := 0; i < len(calls); i++ {
creator, err := calls[i].ToBatchElemCreator() creator, err := calls[i].ToBatchElemCreator()
...@@ -80,30 +80,3 @@ func (m *MultiCaller) Call(ctx context.Context, block Block, calls ...Call) ([]* ...@@ -80,30 +80,3 @@ func (m *MultiCaller) Call(ctx context.Context, block Block, calls ...Call) ([]*
} }
return callResults, nil 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)}
}
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)}
}
...@@ -6,7 +6,7 @@ import ( ...@@ -6,7 +6,7 @@ import (
"fmt" "fmt"
"testing" "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-optimism/optimism/op-service/txmgr"
"github.com/ethereum/go-ethereum/accounts/abi" "github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
...@@ -19,7 +19,7 @@ import ( ...@@ -19,7 +19,7 @@ import (
type expectedCall struct { type expectedCall struct {
abiMethod abi.Method abiMethod abi.Method
to common.Address to common.Address
block batching.Block block rpcblock.Block
args []interface{} args []interface{}
packedArgs []byte packedArgs []byte
outputs []interface{} outputs []interface{}
...@@ -107,7 +107,7 @@ func (l *AbiBasedRpc) abi(to common.Address) *abi.ABI { ...@@ -107,7 +107,7 @@ func (l *AbiBasedRpc) abi(to common.Address) *abi.ABI {
return 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 { if expected == nil {
expected = []interface{}{} expected = []interface{}{}
} }
...@@ -134,5 +134,5 @@ func (l *AbiBasedRpc) VerifyTxCandidate(candidate txmgr.TxCandidate) { ...@@ -134,5 +134,5 @@ func (l *AbiBasedRpc) VerifyTxCandidate(candidate txmgr.TxCandidate) {
"to": candidate.To, "to": candidate.To,
"input": hexutil.Bytes(candidate.TxData), "input": hexutil.Bytes(candidate.TxData),
"value": candidate.Value, "value": candidate.Value,
}, batching.BlockLatest.ArgValue()) }, rpcblock.Latest.ArgValue())
} }
...@@ -8,7 +8,7 @@ import ( ...@@ -8,7 +8,7 @@ import (
"math/big" "math/big"
"testing" "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"
"github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/rpc" "github.com/ethereum/go-ethereum/rpc"
...@@ -73,7 +73,7 @@ type GenericExpectedCall struct { ...@@ -73,7 +73,7 @@ type GenericExpectedCall struct {
result interface{} 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{ return &GenericExpectedCall{
method: "eth_getBalance", method: "eth_getBalance",
args: []interface{}{addr, block.ArgValue()}, args: []interface{}{addr, block.ArgValue()},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment