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