diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index d2c5b983a5..688bb337c8 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -1228,7 +1228,7 @@ func (s *BlockChainAPI) Call(ctx context.Context, args TransactionArgs, blockNrO // // Note, this function doesn't make any changes in the state/blockchain and is // useful to execute and retrieve values. -func (s *BlockChainAPI) MulticallV1(ctx context.Context, opts multicallOpts, blockNrOrHash *rpc.BlockNumberOrHash) ([]blockResult, error) { +func (s *BlockChainAPI) MulticallV1(ctx context.Context, opts mcOpts, blockNrOrHash *rpc.BlockNumberOrHash) ([]mcBlockResult, error) { if len(opts.BlockStateCalls) == 0 { return nil, &invalidParamsError{message: "empty input"} } else if len(opts.BlockStateCalls) > maxMulticallBlocks { diff --git a/internal/ethapi/api_test.go b/internal/ethapi/api_test.go index 82375f32d5..da4ca698e8 100644 --- a/internal/ethapi/api_test.go +++ b/internal/ethapi/api_test.go @@ -1013,7 +1013,7 @@ func TestMulticallV1(t *testing.T) { } var testSuite = []struct { name string - blocks []CallBatch + blocks []mcBlock tag rpc.BlockNumberOrHash includeTransfers *bool validation *bool @@ -1026,7 +1026,7 @@ func TestMulticallV1(t *testing.T) { { name: "simple", tag: latest, - blocks: []CallBatch{{ + blocks: []mcBlock{{ StateOverrides: &StateOverride{ randomAccounts[0].addr: OverrideAccount{Balance: newRPCBalance(big.NewInt(1000))}, }, @@ -1068,7 +1068,7 @@ func TestMulticallV1(t *testing.T) { // State build-up over blocks. name: "simple-multi-block", tag: latest, - blocks: []CallBatch{{ + blocks: []mcBlock{{ StateOverrides: &StateOverride{ randomAccounts[0].addr: OverrideAccount{Balance: newRPCBalance(big.NewInt(2000))}, }, @@ -1137,7 +1137,7 @@ func TestMulticallV1(t *testing.T) { // Block overrides should work, each call is simulated on a different block number name: "block-overrides", tag: latest, - blocks: []CallBatch{{ + blocks: []mcBlock{{ BlockOverrides: &BlockOverrides{ Number: (*hexutil.Big)(big.NewInt(11)), FeeRecipient: &cac, @@ -1193,7 +1193,7 @@ func TestMulticallV1(t *testing.T) { { name: "block-number-order", tag: latest, - blocks: []CallBatch{{ + blocks: []mcBlock{{ BlockOverrides: &BlockOverrides{ Number: (*hexutil.Big)(big.NewInt(12)), }, @@ -1225,7 +1225,7 @@ func TestMulticallV1(t *testing.T) { { name: "storage-contract", tag: latest, - blocks: []CallBatch{{ + blocks: []mcBlock{{ StateOverrides: &StateOverride{ randomAccounts[2].addr: OverrideAccount{ Code: hex2Bytes("608060405234801561001057600080fd5b50600436106100365760003560e01c80632e64cec11461003b5780636057361d14610059575b600080fd5b610043610075565b60405161005091906100d9565b60405180910390f35b610073600480360381019061006e919061009d565b61007e565b005b60008054905090565b8060008190555050565b60008135905061009781610103565b92915050565b6000602082840312156100b3576100b26100fe565b5b60006100c184828501610088565b91505092915050565b6100d3816100f4565b82525050565b60006020820190506100ee60008301846100ca565b92915050565b6000819050919050565b600080fd5b61010c816100f4565b811461011757600080fd5b5056fea2646970667358221220404e37f487a89a932dca5e77faaf6ca2de3b991f93d230604b1b8daaef64766264736f6c63430008070033"), @@ -1266,7 +1266,7 @@ func TestMulticallV1(t *testing.T) { { name: "logs", tag: latest, - blocks: []CallBatch{{ + blocks: []mcBlock{{ StateOverrides: &StateOverride{ randomAccounts[2].addr: OverrideAccount{ // Yul code: @@ -1307,7 +1307,7 @@ func TestMulticallV1(t *testing.T) { { name: "ecrecover-override", tag: latest, - blocks: []CallBatch{{ + blocks: []mcBlock{{ StateOverrides: &StateOverride{ randomAccounts[2].addr: OverrideAccount{ // Yul code that returns ecrecover(0, 0, 0, 0). @@ -1371,7 +1371,7 @@ func TestMulticallV1(t *testing.T) { { name: "precompile-move", tag: latest, - blocks: []CallBatch{{ + blocks: []mcBlock{{ StateOverrides: &StateOverride{ sha256Address: OverrideAccount{ // Yul code that returns the calldata. @@ -1425,7 +1425,7 @@ func TestMulticallV1(t *testing.T) { { name: "transfer-logs", tag: latest, - blocks: []CallBatch{{ + blocks: []mcBlock{{ StateOverrides: &StateOverride{ randomAccounts[0].addr: OverrideAccount{ Balance: newRPCBalance(big.NewInt(100)), @@ -1487,7 +1487,7 @@ func TestMulticallV1(t *testing.T) { { name: "selfdestruct", tag: latest, - blocks: []CallBatch{{ + blocks: []mcBlock{{ Calls: []TransactionArgs{{ From: &accounts[0].addr, To: &cac, @@ -1550,7 +1550,7 @@ func TestMulticallV1(t *testing.T) { { name: "validation-checks", tag: latest, - blocks: []CallBatch{{ + blocks: []mcBlock{{ Calls: []TransactionArgs{{ From: &accounts[2].addr, To: &cac, @@ -1576,7 +1576,7 @@ func TestMulticallV1(t *testing.T) { { name: "clear-storage", tag: latest, - blocks: []CallBatch{{ + blocks: []mcBlock{{ StateOverrides: &StateOverride{ randomAccounts[2].addr: { Code: newBytes(genesis.Alloc[bab].Code), @@ -1643,7 +1643,7 @@ func TestMulticallV1(t *testing.T) { { name: "blockhash-opcode", tag: latest, - blocks: []CallBatch{{ + blocks: []mcBlock{{ BlockOverrides: &BlockOverrides{ Number: (*hexutil.Big)(big.NewInt(12)), }, @@ -1729,7 +1729,7 @@ func TestMulticallV1(t *testing.T) { for _, tc := range testSuite { t.Run(tc.name, func(t *testing.T) { - opts := multicallOpts{BlockStateCalls: tc.blocks} + opts := mcOpts{BlockStateCalls: tc.blocks} if tc.includeTransfers != nil && *tc.includeTransfers { opts.TraceTransfers = true } diff --git a/internal/ethapi/multicall.go b/internal/ethapi/multicall.go index c3e20da04d..44c79895ec 100644 --- a/internal/ethapi/multicall.go +++ b/internal/ethapi/multicall.go @@ -43,14 +43,14 @@ const ( maxMulticallBlocks = 256 ) -// CallBatch is a batch of calls to be simulated sequentially. -type CallBatch struct { +// mcBlock is a batch of calls to be simulated sequentially. +type mcBlock struct { BlockOverrides *BlockOverrides StateOverrides *StateOverride Calls []TransactionArgs } -type blockResult struct { +type mcBlockResult struct { Number hexutil.Uint64 `json:"number"` Hash common.Hash `json:"hash"` Time hexutil.Uint64 `json:"timestamp"` @@ -59,11 +59,11 @@ type blockResult struct { FeeRecipient common.Address `json:"feeRecipient"` BaseFee *hexutil.Big `json:"baseFeePerGas"` PrevRandao common.Hash `json:"prevRandao"` - Calls []callResult `json:"calls"` + Calls []mcCallResult `json:"calls"` } -func mcBlockResultFromHeader(header *types.Header, callResults []callResult) blockResult { - return blockResult{ +func mcBlockResultFromHeader(header *types.Header, callResults []mcCallResult) mcBlockResult { + return mcBlockResult{ Number: hexutil.Uint64(header.Number.Uint64()), Hash: header.Hash(), Time: hexutil.Uint64(header.Time), @@ -76,7 +76,7 @@ func mcBlockResultFromHeader(header *types.Header, callResults []callResult) blo } } -type callResult struct { +type mcCallResult struct { ReturnValue hexutil.Bytes `json:"returnData"` Logs []*types.Log `json:"logs"` GasUsed hexutil.Uint64 `json:"gasUsed"` @@ -84,8 +84,8 @@ type callResult struct { Error *callError `json:"error,omitempty"` } -func (r *callResult) MarshalJSON() ([]byte, error) { - type callResultAlias callResult +func (r *mcCallResult) MarshalJSON() ([]byte, error) { + type callResultAlias mcCallResult // Marshal logs to be an empty array instead of nil when empty if r.Logs == nil { r.Logs = []*types.Log{} @@ -93,8 +93,8 @@ func (r *callResult) MarshalJSON() ([]byte, error) { return json.Marshal((*callResultAlias)(r)) } -type multicallOpts struct { - BlockStateCalls []CallBatch +type mcOpts struct { + BlockStateCalls []mcBlock TraceTransfers bool Validation bool } @@ -105,7 +105,7 @@ type multicall struct { hashes []common.Hash } -func (mc *multicall) execute(ctx context.Context, opts multicallOpts) ([]blockResult, error) { +func (mc *multicall) execute(ctx context.Context, opts mcOpts) ([]mcBlockResult, error) { state, base, err := mc.b.StateAndHeaderByNumberOrHash(ctx, mc.blockNrOrHash) if state == nil || err != nil { return nil, err @@ -130,7 +130,7 @@ func (mc *multicall) execute(ctx context.Context, opts multicallOpts) ([]blockRe return nil, err } var ( - results = make([]blockResult, len(blocks)) + results = make([]mcBlockResult, len(blocks)) // Each tx and all the series of txes shouldn't consume more gas than cap gp = new(core.GasPool).AddGas(mc.b.RPCGasCap()) precompiles = mc.activePrecompiles(ctx, base) @@ -157,7 +157,7 @@ func (mc *multicall) execute(ctx context.Context, opts multicallOpts) ([]blockRe var ( gasUsed uint64 txes = make([]*types.Transaction, len(block.Calls)) - callResults = make([]callResult, len(block.Calls)) + callResults = make([]mcCallResult, len(block.Calls)) ) for i, call := range block.Calls { if call.Nonce == nil { @@ -188,7 +188,7 @@ func (mc *multicall) execute(ctx context.Context, opts multicallOpts) ([]blockRe result, err := applyMessage(ctx, mc.b, call, state, header, timeout, gp, &blockContext, vmConfig, precompiles, opts.Validation) if err != nil { callErr := callErrorFromError(err) - callResults[i] = callResult{Error: callErr, Status: hexutil.Uint64(types.ReceiptStatusFailed)} + callResults[i] = mcCallResult{Error: callErr, Status: hexutil.Uint64(types.ReceiptStatusFailed)} continue } // If the result contains a revert reason, try to unpack it. @@ -196,7 +196,7 @@ func (mc *multicall) execute(ctx context.Context, opts multicallOpts) ([]blockRe result.Err = newRevertError(result) } logs := vmConfig.Tracer.(*tracer).Logs() - callRes := callResult{ReturnValue: result.Return(), Logs: logs, GasUsed: hexutil.Uint64(result.UsedGas)} + callRes := mcCallResult{ReturnValue: result.Return(), Logs: logs, GasUsed: hexutil.Uint64(result.UsedGas)} if result.Failed() { callRes.Status = hexutil.Uint64(types.ReceiptStatusFailed) if errors.Is(result.Err, vm.ErrExecutionReverted) { @@ -301,7 +301,7 @@ func (mc *multicall) activePrecompiles(ctx context.Context, base *types.Header) // repairLogs updates the block hash in the logs present in a multicall // result object. This is needed as during execution when logs are collected // the block hash is not known. -func repairLogs(results []blockResult, blockHash common.Hash) { +func repairLogs(results []mcBlockResult, blockHash common.Hash) { for i := range results { for j := range results[i].Calls { for k := range results[i].Calls[j].Logs { @@ -310,7 +310,7 @@ func repairLogs(results []blockResult, blockHash common.Hash) { } } } -func makeHeaders(config *params.ChainConfig, blocks []CallBatch, base *types.Header) ([]*types.Header, error) { +func makeHeaders(config *params.ChainConfig, blocks []mcBlock, base *types.Header) ([]*types.Header, error) { res := make([]*types.Header, len(blocks)) var ( prevNumber = base.Number.Uint64()