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