mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 10:22:23 +00:00
move call sanitization to own method
This commit is contained in:
parent
89df0e3b2c
commit
1a28a17b66
1 changed files with 30 additions and 21 deletions
|
|
@ -27,6 +27,7 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||||
"github.com/ethereum/go-ethereum/consensus/misc/eip1559"
|
"github.com/ethereum/go-ethereum/consensus/misc/eip1559"
|
||||||
"github.com/ethereum/go-ethereum/core"
|
"github.com/ethereum/go-ethereum/core"
|
||||||
|
"github.com/ethereum/go-ethereum/core/state"
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"github.com/ethereum/go-ethereum/core/vm"
|
"github.com/ethereum/go-ethereum/core/vm"
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
|
|
@ -163,33 +164,13 @@ func (mc *multicall) execute(ctx context.Context, opts mcOpts) ([]mcBlockResult,
|
||||||
callResults = make([]mcCallResult, 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 err := mc.sanitizeCall(&call, state, &gasUsed, blockContext); err != nil {
|
||||||
nonce := state.GetNonce(call.from())
|
|
||||||
call.Nonce = (*hexutil.Uint64)(&nonce)
|
|
||||||
}
|
|
||||||
var gas uint64
|
|
||||||
if call.Gas != nil {
|
|
||||||
gas = uint64(*call.Gas)
|
|
||||||
}
|
|
||||||
if gasUsed+gas > blockContext.GasLimit {
|
|
||||||
return nil, &blockGasLimitReachedError{fmt.Sprintf("block gas limit reached: %d >= %d", gasUsed, blockContext.GasLimit)}
|
|
||||||
}
|
|
||||||
// Let the call run wild unless explicitly specified.
|
|
||||||
if call.Gas == nil {
|
|
||||||
remaining := blockContext.GasLimit - gasUsed
|
|
||||||
call.Gas = (*hexutil.Uint64)(&remaining)
|
|
||||||
}
|
|
||||||
// TODO: check chainID and against current header for london fees
|
|
||||||
if err := call.validateAll(mc.b); err != nil {
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
// Default to dynamic-fee transaction type.
|
// Default to dynamic-fee transaction type.
|
||||||
type2 := true
|
type2 := true
|
||||||
if call.GasPrice != nil {
|
if call.GasPrice != nil {
|
||||||
type2 = false
|
type2 = false
|
||||||
} else if call.MaxFeePerGas == nil && call.MaxPriorityFeePerGas == nil {
|
|
||||||
call.MaxFeePerGas = (*hexutil.Big)(big.NewInt(0))
|
|
||||||
call.MaxPriorityFeePerGas = (*hexutil.Big)(big.NewInt(0))
|
|
||||||
}
|
}
|
||||||
tx := call.ToTransaction(type2)
|
tx := call.ToTransaction(type2)
|
||||||
txes[i] = tx
|
txes[i] = tx
|
||||||
|
|
@ -242,6 +223,34 @@ func (mc *multicall) execute(ctx context.Context, opts mcOpts) ([]mcBlockResult,
|
||||||
return results, nil
|
return results, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (mc *multicall) sanitizeCall(call *TransactionArgs, state *state.StateDB, gasUsed *uint64, blockContext vm.BlockContext) error {
|
||||||
|
if call.Nonce == nil {
|
||||||
|
nonce := state.GetNonce(call.from())
|
||||||
|
call.Nonce = (*hexutil.Uint64)(&nonce)
|
||||||
|
}
|
||||||
|
var gas uint64
|
||||||
|
if call.Gas != nil {
|
||||||
|
gas = uint64(*call.Gas)
|
||||||
|
}
|
||||||
|
if *gasUsed+gas > blockContext.GasLimit {
|
||||||
|
return &blockGasLimitReachedError{fmt.Sprintf("block gas limit reached: %d >= %d", gasUsed, blockContext.GasLimit)}
|
||||||
|
}
|
||||||
|
// Let the call run wild unless explicitly specified.
|
||||||
|
if call.Gas == nil {
|
||||||
|
remaining := blockContext.GasLimit - *gasUsed
|
||||||
|
call.Gas = (*hexutil.Uint64)(&remaining)
|
||||||
|
}
|
||||||
|
// TODO: check chainID and against current header for london fees
|
||||||
|
if err := call.validateAll(mc.b); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if call.GasPrice == nil && call.MaxFeePerGas == nil && call.MaxPriorityFeePerGas == nil {
|
||||||
|
call.MaxFeePerGas = (*hexutil.Big)(big.NewInt(0))
|
||||||
|
call.MaxPriorityFeePerGas = (*hexutil.Big)(big.NewInt(0))
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// getBlockHash returns the hash for the block of the given number. Block can be
|
// getBlockHash returns the hash for the block of the given number. Block can be
|
||||||
// part of the canonical chain, a simulated block or a phantom block.
|
// part of the canonical chain, a simulated block or a phantom block.
|
||||||
// Note getBlockHash assumes `n` is smaller than the last already simulated block
|
// Note getBlockHash assumes `n` is smaller than the last already simulated block
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue