Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

internal/ethapi: eth_simulateV1 #27720

Merged
merged 131 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from 114 commits
Commits
Show all changes
131 commits
Select commit Hold shift + click to select a range
62d33d5
internal/ethapi: add multicall method
s1na May 26, 2023
80df50d
add test case for logs
s1na Jun 5, 2023
c3f1494
add ecrecover override
s1na Jun 6, 2023
a219206
forgot to commit other files
s1na Jun 6, 2023
0285f81
dont abort on call validation error
s1na Jun 6, 2023
c301ce4
add state buildup test
s1na Jun 6, 2023
922f72c
test block override defaults to base
s1na Jun 6, 2023
80bcb16
check block nums are in order
s1na Jun 6, 2023
4478f20
add method to web3ext
s1na Jun 8, 2023
2ae2fe5
add transfers
s1na Jun 8, 2023
0aaaf34
forgot the tracer
s1na Jun 8, 2023
2db37b9
minor
s1na Jun 8, 2023
04965a3
fix marshaling of empty values
s1na Jun 15, 2023
c78330d
rename to multicallV1
s1na Jun 30, 2023
8fff7fd
return block info except blockhash
s1na Jul 3, 2023
637acc5
Finalise state after call, add selfdestruct test
s1na Jul 13, 2023
d23eb89
Add status field to call result
s1na Jul 13, 2023
a7af5a9
wrap params into an object
s1na Jul 13, 2023
98882fc
blockhash = keccak(blockNum)
s1na Jul 13, 2023
b865824
name tests
s1na Jul 17, 2023
da3102e
persist precompiles in evm
s1na Jul 17, 2023
6a2c96c
add storage clearing test case for eth_call
s1na Jul 18, 2023
b3efbad
implement precompile override and moveTo feature
s1na Jul 18, 2023
9aed710
copy storage over in MoveTo
s1na Jul 18, 2023
2c25ab6
add todo comments
s1na Jul 24, 2023
5d351c9
add testcase moveto precompile
s1na Jul 31, 2023
63f4f6e
rm ecrecover override field
s1na Jul 31, 2023
80506ea
rename blocks to blockStateCalls
s1na Jul 31, 2023
fd786c0
rename to moveToAddress
s1na Aug 1, 2023
6845b5e
add optional validation of txes
s1na Aug 1, 2023
c5e33fa
test coinbase
s1na Aug 2, 2023
d4e332e
fix storage clearing
s1na Aug 3, 2023
b0e7869
Rename block override field names
s1na Sep 4, 2023
56b4402
auto-set and validate block number and timestamp
s1na Sep 4, 2023
7e17e4c
implement transfers as logs
s1na Sep 4, 2023
fe3bb83
add prevrandao to result
s1na Sep 5, 2023
906d93a
clear logs on call fail
s1na Sep 5, 2023
8e02675
add txhash to logs
s1na Sep 7, 2023
a0d2706
moveTo only for precompiles
s1na Sep 11, 2023
ed4cbaf
resolve merge conflicts
s1na Sep 13, 2023
3231291
optional block param
s1na Sep 20, 2023
3df0fec
rename return to returnData
s1na Sep 20, 2023
760f5e5
fix tx gaslimit and type default
s1na Sep 20, 2023
b3996e4
dont set defaults for calls
s1na Sep 20, 2023
100c593
fix crasher
s1na Sep 29, 2023
523e3d2
cover it in test case
s1na Sep 29, 2023
d5c0ff4
add error codes to calls
s1na Oct 4, 2023
45ba37e
compute block hash based on header
s1na Oct 5, 2023
973116c
repair logs
s1na Oct 5, 2023
a5ffd9a
serve blockhash requests
s1na Oct 6, 2023
cc1158a
possibly fix crasher
s1na Oct 10, 2023
2690445
fix block hash cache
s1na Oct 10, 2023
d1ce690
move multicall logic to struct
s1na Oct 10, 2023
e230258
move precompile list to own func
s1na Oct 10, 2023
c02d29d
limit number of blocks
s1na Oct 24, 2023
e4eb56a
add error code for blocks length check
s1na Oct 24, 2023
ed37821
rename types
s1na Oct 24, 2023
f5ac039
fix error codes
s1na Oct 26, 2023
23ef9c6
minor fix
s1na Nov 13, 2023
6da9202
Fix extra delegatecall value log
s1na Dec 14, 2023
12d59b5
update transfer log address
s1na Dec 14, 2023
1616559
resolve merge conflicts
s1na Dec 14, 2023
7fff1c4
Add cancun to precompiled contracts
s1na Dec 14, 2023
bf78094
safer api for getting active precompiles
s1na Dec 14, 2023
c594f74
fix godoc comment
s1na Jan 3, 2024
11133e0
fix precompileMove in eth_call
s1na Jan 3, 2024
ad24d2e
rename block overrides receiver name
s1na Jan 3, 2024
c77da8c
rename validate param
s1na Jan 3, 2024
3d29c1f
copy header prior to applying overrides
s1na Jan 3, 2024
31e2cc9
legacy tx if gasPrice provided
s1na Jan 4, 2024
5ed9958
resolve merge conflict
s1na Jan 4, 2024
2b1cf22
fix graphql test
s1na Jan 4, 2024
fd0f626
fix rpcgascap for ethclient tests
s1na Jan 4, 2024
1e7b497
fix block overrides in gethclient
s1na Jan 4, 2024
589107b
rename to blobGasPrice
s1na Jan 5, 2024
89df0e3
rename method to eth_simulateV1
s1na Jan 11, 2024
1a28a17
move call sanitization to own method
s1na Jan 15, 2024
115117c
move tx type detection check
s1na Jan 15, 2024
df14718
compute receipts
s1na Jan 16, 2024
ae33566
finish renaming to simulate
s1na Jan 17, 2024
12d7dd0
fix empty tx, receipts hash
s1na Jan 17, 2024
214e209
minor rename:
s1na Jan 17, 2024
af155c1
move block processing logic to func
s1na Jan 17, 2024
c73c10a
merge master
s1na Feb 19, 2024
489ef43
fix lint errs
s1na Feb 19, 2024
0c0b13d
rename to blobBaseFee
s1na Feb 19, 2024
86ce924
revert setDefaults changes, skip extra validations:
s1na Feb 21, 2024
4a017ff
rm obsolete test
s1na Feb 21, 2024
49bf257
resolve merge conflict
s1na Feb 21, 2024
9fa1556
fix makeHeaders using unpopulated parent
s1na Mar 5, 2024
7177f22
check gas fee in validation mode
s1na Mar 5, 2024
3daabda
add empty withdrawals obj
s1na Mar 29, 2024
c08ba25
resolve merge conflict
s1na Mar 29, 2024
81e7fe1
fix baseFee, add blobGasUsed and excessBlobGas to result
s1na Apr 5, 2024
8698221
default timestamp bump to 12
s1na May 6, 2024
48ca188
generate empty blocks for gaps
s1na May 7, 2024
81e065c
fix block hashes
s1na May 7, 2024
263cfd7
compute basefee prior to execution
s1na May 22, 2024
e382782
return full header
s1na May 28, 2024
9139685
add fullTx option
s1na May 28, 2024
569a2d7
move out base fee lowering to api code
s1na Jun 6, 2024
d7cd3a0
missed one file
s1na Jun 6, 2024
399812a
set base fee to 0 in non-validating mode
s1na Jun 6, 2024
1c154e9
check base fee in test block results
s1na Jun 6, 2024
638d82b
resolve merge conflict
s1na Jun 7, 2024
ac690f0
fix chainId default
s1na Jun 12, 2024
a9842e5
add td
s1na Jun 12, 2024
a6f80c7
add data on reverts
s1na Jun 12, 2024
5db0106
fix
s1na Jun 12, 2024
4c325ba
skip EoA check in validation mode
s1na Jun 12, 2024
102aa80
resolve merge conflict
s1na Jul 15, 2024
172ed02
refactors
s1na Jul 15, 2024
ddba7dd
rm stale todos
s1na Jul 15, 2024
c0d5dfb
resolve merge conflict
s1na Jul 25, 2024
e3cd999
default timestamp bump 1 sec
s1na Aug 14, 2024
33400fb
review comments, pt. 1
s1na Aug 16, 2024
5f0fafd
fix precompile moveTo
s1na Aug 16, 2024
73ff7e5
move timestamp sanitization
s1na Aug 19, 2024
5d8c058
Clean up sanitizeCall
s1na Aug 19, 2024
edf9e37
Fix lint errors
s1na Aug 19, 2024
e7bac20
add test comments
s1na Aug 19, 2024
9a963dc
add license to simulate_test
s1na Sep 4, 2024
7198fc1
update test to use fixed address
s1na Sep 4, 2024
6ec5083
Merge branch 'master' into multicall
s1na Sep 4, 2024
791719a
core/vm: use maps.Clone
holiman Sep 4, 2024
c216ef5
internal: refactored ToTransaction of transaction args
holiman Sep 4, 2024
2415110
Merge branch 'master' into multicall
s1na Sep 4, 2024
6205806
internal/ethapi: simplify
holiman Sep 5, 2024
098a448
internal/ethapi: abort when context is cancelled
holiman Sep 5, 2024
9da10f9
Merge branch 'master' into multicall
holiman Sep 6, 2024
f25fcd3
internal/ethapi: fix merge-conflicts
holiman Sep 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions core/state_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,14 @@ func ApplyTransactionWithEVM(msg *Message, config *params.ChainConfig, gp *GasPo
}
*usedGas += result.UsedGas

return MakeReceipt(evm, result, statedb, blockNumber, blockHash, tx, *usedGas, root), err
s1na marked this conversation as resolved.
Show resolved Hide resolved
}

// MakeReceipt generates the receipt object for a transaction given its execution result.
func MakeReceipt(evm *vm.EVM, result *ExecutionResult, statedb *state.StateDB, blockNumber *big.Int, blockHash common.Hash, tx *types.Transaction, usedGas uint64, root []byte) *types.Receipt {
// Create a new receipt for the transaction, storing the intermediate root and gas used
// by the tx.
receipt = &types.Receipt{Type: tx.Type(), PostState: root, CumulativeGasUsed: *usedGas}
receipt := &types.Receipt{Type: tx.Type(), PostState: root, CumulativeGasUsed: usedGas}
if result.Failed() {
receipt.Status = types.ReceiptStatusFailed
} else {
Expand All @@ -152,7 +157,7 @@ func ApplyTransactionWithEVM(msg *Message, config *params.ChainConfig, gp *GasPo
}

// If the transaction created a contract, store the creation address in the receipt.
if msg.To == nil {
if tx.To() == nil {
receipt.ContractAddress = crypto.CreateAddress(evm.TxContext.Origin, tx.Nonce())
}

Expand All @@ -162,7 +167,7 @@ func ApplyTransactionWithEVM(msg *Message, config *params.ChainConfig, gp *GasPo
receipt.BlockHash = blockHash
receipt.BlockNumber = blockNumber
receipt.TransactionIndex = uint(statedb.TxIndex())
return receipt, err
return receipt
}

// ApplyTransaction attempts to apply a transaction to the given state database
Expand Down
37 changes: 21 additions & 16 deletions core/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,27 +142,30 @@ type Message struct {
BlobGasFeeCap *big.Int
BlobHashes []common.Hash

// When SkipAccountChecks is true, the message nonce is not checked against the
// account nonce in state. It also disables checking that the sender is an EOA.
// When SkipNonceChecks is true, the message nonce is not checked against the
// account nonce in state.
// This field will be set to true for operations like RPC eth_call.
SkipAccountChecks bool
SkipNonceChecks bool
s1na marked this conversation as resolved.
Show resolved Hide resolved
// When SkipFromEoACheck is true, the message sender is not checked to be an EOA.
SkipFromEoACheck bool
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick, please rename it to SkipFromEOACheck

btw, do you know in which scenario this field/feature will be used?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right should be EOA definitely 👍

This is used when simulating in validation mode. In validation mode we want everything to be checked but only relax the requirement of the sender to be an EOA, e.g. to still allow calling from a multisig contract.

}

// TransactionToMessage converts a transaction into a Message.
func TransactionToMessage(tx *types.Transaction, s types.Signer, baseFee *big.Int) (*Message, error) {
msg := &Message{
Nonce: tx.Nonce(),
GasLimit: tx.Gas(),
GasPrice: new(big.Int).Set(tx.GasPrice()),
GasFeeCap: new(big.Int).Set(tx.GasFeeCap()),
GasTipCap: new(big.Int).Set(tx.GasTipCap()),
To: tx.To(),
Value: tx.Value(),
Data: tx.Data(),
AccessList: tx.AccessList(),
SkipAccountChecks: false,
BlobHashes: tx.BlobHashes(),
BlobGasFeeCap: tx.BlobGasFeeCap(),
Nonce: tx.Nonce(),
GasLimit: tx.Gas(),
GasPrice: new(big.Int).Set(tx.GasPrice()),
GasFeeCap: new(big.Int).Set(tx.GasFeeCap()),
GasTipCap: new(big.Int).Set(tx.GasTipCap()),
To: tx.To(),
Value: tx.Value(),
Data: tx.Data(),
AccessList: tx.AccessList(),
SkipNonceChecks: false,
SkipFromEoACheck: false,
BlobHashes: tx.BlobHashes(),
BlobGasFeeCap: tx.BlobGasFeeCap(),
}
// If baseFee provided, set gasPrice to effectiveGasPrice.
if baseFee != nil {
Expand Down Expand Up @@ -280,7 +283,7 @@ func (st *StateTransition) buyGas() error {
func (st *StateTransition) preCheck() error {
// Only check transactions that are not fake
msg := st.msg
if !msg.SkipAccountChecks {
if !msg.SkipNonceChecks {
// Make sure this transaction's nonce is correct.
stNonce := st.state.GetNonce(msg.From)
if msgNonce := msg.Nonce; stNonce < msgNonce {
Expand All @@ -293,6 +296,8 @@ func (st *StateTransition) preCheck() error {
return fmt.Errorf("%w: address %v, nonce: %d", ErrNonceMax,
msg.From.Hex(), stNonce)
}
}
if !msg.SkipFromEoACheck {
// Make sure the sender is an EOA
codeHash := st.state.GetCodeHash(msg.From)
if codeHash != (common.Hash{}) && codeHash != types.EmptyCodeHash {
Expand Down
50 changes: 43 additions & 7 deletions core/vm/contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,12 @@ type PrecompiledContract interface {
Run(input []byte) ([]byte, error) // Run runs the precompiled contract
}

// PrecompiledContracts contains the precompiled contracts supported at the given fork.
type PrecompiledContracts map[common.Address]PrecompiledContract
s1na marked this conversation as resolved.
Show resolved Hide resolved

// PrecompiledContractsHomestead contains the default set of pre-compiled Ethereum
// contracts used in the Frontier and Homestead releases.
var PrecompiledContractsHomestead = map[common.Address]PrecompiledContract{
var PrecompiledContractsHomestead = PrecompiledContracts{
common.BytesToAddress([]byte{0x1}): &ecrecover{},
common.BytesToAddress([]byte{0x2}): &sha256hash{},
common.BytesToAddress([]byte{0x3}): &ripemd160hash{},
Expand All @@ -57,7 +60,7 @@ var PrecompiledContractsHomestead = map[common.Address]PrecompiledContract{

// PrecompiledContractsByzantium contains the default set of pre-compiled Ethereum
// contracts used in the Byzantium release.
var PrecompiledContractsByzantium = map[common.Address]PrecompiledContract{
var PrecompiledContractsByzantium = PrecompiledContracts{
common.BytesToAddress([]byte{0x1}): &ecrecover{},
common.BytesToAddress([]byte{0x2}): &sha256hash{},
common.BytesToAddress([]byte{0x3}): &ripemd160hash{},
Expand All @@ -70,7 +73,7 @@ var PrecompiledContractsByzantium = map[common.Address]PrecompiledContract{

// PrecompiledContractsIstanbul contains the default set of pre-compiled Ethereum
// contracts used in the Istanbul release.
var PrecompiledContractsIstanbul = map[common.Address]PrecompiledContract{
var PrecompiledContractsIstanbul = PrecompiledContracts{
common.BytesToAddress([]byte{0x1}): &ecrecover{},
common.BytesToAddress([]byte{0x2}): &sha256hash{},
common.BytesToAddress([]byte{0x3}): &ripemd160hash{},
Expand All @@ -84,7 +87,7 @@ var PrecompiledContractsIstanbul = map[common.Address]PrecompiledContract{

// PrecompiledContractsBerlin contains the default set of pre-compiled Ethereum
// contracts used in the Berlin release.
var PrecompiledContractsBerlin = map[common.Address]PrecompiledContract{
var PrecompiledContractsBerlin = PrecompiledContracts{
common.BytesToAddress([]byte{0x1}): &ecrecover{},
common.BytesToAddress([]byte{0x2}): &sha256hash{},
common.BytesToAddress([]byte{0x3}): &ripemd160hash{},
Expand All @@ -98,7 +101,7 @@ var PrecompiledContractsBerlin = map[common.Address]PrecompiledContract{

// PrecompiledContractsCancun contains the default set of pre-compiled Ethereum
// contracts used in the Cancun release.
var PrecompiledContractsCancun = map[common.Address]PrecompiledContract{
var PrecompiledContractsCancun = PrecompiledContracts{
common.BytesToAddress([]byte{0x1}): &ecrecover{},
common.BytesToAddress([]byte{0x2}): &sha256hash{},
common.BytesToAddress([]byte{0x3}): &ripemd160hash{},
Expand All @@ -113,7 +116,7 @@ var PrecompiledContractsCancun = map[common.Address]PrecompiledContract{

// PrecompiledContractsPrague contains the set of pre-compiled Ethereum
// contracts used in the Prague release.
var PrecompiledContractsPrague = map[common.Address]PrecompiledContract{
var PrecompiledContractsPrague = PrecompiledContracts{
common.BytesToAddress([]byte{0x01}): &ecrecover{},
common.BytesToAddress([]byte{0x02}): &sha256hash{},
common.BytesToAddress([]byte{0x03}): &ripemd160hash{},
Expand Down Expand Up @@ -169,7 +172,40 @@ func init() {
}
}

// ActivePrecompiles returns the precompiles enabled with the current configuration.
// Copy returns a copy of the precompiled contracts.
s1na marked this conversation as resolved.
Show resolved Hide resolved
func (p PrecompiledContracts) Copy() PrecompiledContracts {
c := make(PrecompiledContracts)
for k, v := range p {
c[k] = v
}
return c
}

func activePrecompiledContracts(rules params.Rules) PrecompiledContracts {
switch {
case rules.IsVerkle:
return PrecompiledContractsVerkle
case rules.IsPrague:
return PrecompiledContractsPrague
case rules.IsCancun:
return PrecompiledContractsCancun
case rules.IsBerlin:
return PrecompiledContractsBerlin
case rules.IsIstanbul:
return PrecompiledContractsIstanbul
case rules.IsByzantium:
return PrecompiledContractsByzantium
default:
return PrecompiledContractsHomestead
}
}

// ActivePrecompiledContracts returns a copy of precompiled contracts enabled with the current configuration.
func ActivePrecompiledContracts(rules params.Rules) PrecompiledContracts {
return activePrecompiledContracts(rules).Copy()
}

// ActivePrecompiles returns the precompile addresses enabled with the current configuration.
func ActivePrecompiles(rules params.Rules) []common.Address {
switch {
case rules.IsPrague:
Expand Down
40 changes: 11 additions & 29 deletions core/vm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,7 @@ type (
)

func (evm *EVM) precompile(addr common.Address) (PrecompiledContract, bool) {
var precompiles map[common.Address]PrecompiledContract
switch {
case evm.chainRules.IsVerkle:
precompiles = PrecompiledContractsVerkle
case evm.chainRules.IsPrague:
precompiles = PrecompiledContractsPrague
case evm.chainRules.IsCancun:
precompiles = PrecompiledContractsCancun
case evm.chainRules.IsBerlin:
precompiles = PrecompiledContractsBerlin
case evm.chainRules.IsIstanbul:
precompiles = PrecompiledContractsIstanbul
case evm.chainRules.IsByzantium:
precompiles = PrecompiledContractsByzantium
default:
precompiles = PrecompiledContractsHomestead
}
p, ok := precompiles[addr]
p, ok := evm.precompiles[addr]
return p, ok
}

Expand Down Expand Up @@ -129,22 +112,13 @@ type EVM struct {
// available gas is calculated in gasCall* according to the 63/64 rule and later
// applied in opCall*.
callGasTemp uint64
// precompiles holds the precompiled contracts for the current epoch
precompiles map[common.Address]PrecompiledContract
}

// NewEVM returns a new EVM. The returned EVM is not thread safe and should
// only ever be used *once*.
func NewEVM(blockCtx BlockContext, txCtx TxContext, statedb StateDB, chainConfig *params.ChainConfig, config Config) *EVM {
// If basefee tracking is disabled (eth_call, eth_estimateGas, etc), and no
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any particular reason to remove this part of code?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not removed but moved to the API layer. It will cause some duplication of code but I believe it's more correct.

// gas prices were specified, lower the basefee to 0 to avoid breaking EVM
// invariants (basefee < feecap)
if config.NoBaseFee {
if txCtx.GasPrice.BitLen() == 0 {
blockCtx.BaseFee = new(big.Int)
}
if txCtx.BlobFeeCap != nil && txCtx.BlobFeeCap.BitLen() == 0 {
blockCtx.BlobBaseFee = new(big.Int)
}
}
evm := &EVM{
Context: blockCtx,
TxContext: txCtx,
Expand All @@ -153,10 +127,18 @@ func NewEVM(blockCtx BlockContext, txCtx TxContext, statedb StateDB, chainConfig
chainConfig: chainConfig,
chainRules: chainConfig.Rules(blockCtx.BlockNumber, blockCtx.Random != nil, blockCtx.Time),
}
evm.precompiles = activePrecompiledContracts(evm.chainRules)
evm.interpreter = NewEVMInterpreter(evm)
return evm
}

// SetPrecompiles sets the precompiled contracts for the EVM.
// This method is only used through RPC calls.
// It is not thread-safe.
func (evm *EVM) SetPrecompiles(precompiles PrecompiledContracts) {
evm.precompiles = precompiles
}

// Reset resets the EVM with a new transaction context.Reset
// This is not threadsafe and should only be done very cautiously.
func (evm *EVM) Reset(txCtx TxContext, statedb StateDB) {
Expand Down
10 changes: 9 additions & 1 deletion eth/gasestimator/gasestimator.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,16 @@ func run(ctx context.Context, call *core.Message, opts *Options) (*core.Executio
evmContext = core.NewEVMBlockContext(opts.Header, opts.Chain, nil)

dirtyState = opts.State.Copy()
evm = vm.NewEVM(evmContext, msgContext, dirtyState, opts.Config, vm.Config{NoBaseFee: true})
)
// Lower the basefee to 0 to avoid breaking EVM
// invariants (basefee < feecap).
if msgContext.GasPrice.Sign() == 0 {
evmContext.BaseFee = new(big.Int)
}
if msgContext.BlobFeeCap != nil && msgContext.BlobFeeCap.BitLen() == 0 {
evmContext.BlobBaseFee = new(big.Int)
}
evm := vm.NewEVM(evmContext, msgContext, dirtyState, opts.Config, vm.Config{NoBaseFee: true})
// Monitor the outer context and interrupt the EVM upon cancellation. To avoid
// a dangling goroutine until the outer estimation finishes, create an internal
// context for the lifetime of this method call.
Expand Down
19 changes: 15 additions & 4 deletions eth/tracers/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"encoding/json"
"errors"
"fmt"
"math/big"
"os"
"runtime"
"sync"
Expand Down Expand Up @@ -938,20 +939,30 @@ func (api *API) TraceCall(ctx context.Context, args ethapi.TransactionArgs, bloc
vmctx := core.NewEVMBlockContext(block.Header(), api.chainContext(ctx), nil)
// Apply the customization rules if required.
if config != nil {
if err := config.StateOverrides.Apply(statedb); err != nil {
config.BlockOverrides.Apply(&vmctx)
rules := api.backend.ChainConfig().Rules(vmctx.BlockNumber, vmctx.Random != nil, vmctx.Time)
precompiles := vm.ActivePrecompiledContracts(rules)
if err := config.StateOverrides.Apply(statedb, precompiles); err != nil {
return nil, err
}
config.BlockOverrides.Apply(&vmctx)
}
// Execute the trace
if err := args.CallDefaults(api.backend.RPCGasCap(), vmctx.BaseFee, api.backend.ChainConfig().ChainID); err != nil {
return nil, err
}
var (
msg = args.ToMessage(vmctx.BaseFee)
tx = args.ToTransaction()
msg = args.ToMessage(vmctx.BaseFee, true, true)
tx = args.ToTransaction(args.GasPrice == nil)
traceConfig *TraceConfig
)
// Lower the basefee to 0 to avoid breaking EVM
// invariants (basefee < feecap).
if msg.GasPrice.Sign() == 0 {
vmctx.BaseFee = new(big.Int)
}
if msg.BlobGasFeeCap != nil && msg.BlobGasFeeCap.BitLen() == 0 {
vmctx.BlobBaseFee = new(big.Int)
}
if config != nil {
traceConfig = &config.TraceConfig
}
Expand Down
2 changes: 1 addition & 1 deletion ethclient/ethclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ func newTestBackend(t *testing.T) (*node.Node, []*types.Block) {
t.Fatalf("can't create new node: %v", err)
}
// Create Ethereum Service
config := &ethconfig.Config{Genesis: genesis}
config := &ethconfig.Config{Genesis: genesis, RPCGasCap: 1000000}
ethservice, err := eth.New(n, config)
if err != nil {
t.Fatalf("can't create new ethereum service: %v", err)
Expand Down
6 changes: 3 additions & 3 deletions ethclient/gethclient/gethclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,9 +328,9 @@ func (o BlockOverrides) MarshalJSON() ([]byte, error) {
Difficulty *hexutil.Big `json:"difficulty,omitempty"`
Time hexutil.Uint64 `json:"time,omitempty"`
GasLimit hexutil.Uint64 `json:"gasLimit,omitempty"`
Coinbase *common.Address `json:"coinbase,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not renaming the fields to FeeRecipient?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean in the override type? Happy to do that but changing the BlockOverrides type would be a breaking change so would prefer to avoid that.

Random *common.Hash `json:"random,omitempty"`
BaseFee *hexutil.Big `json:"baseFee,omitempty"`
Coinbase *common.Address `json:"feeRecipient,omitempty"`
Random *common.Hash `json:"prevRandao,omitempty"`
BaseFee *hexutil.Big `json:"baseFeePerGas,omitempty"`
}

output := override{
Expand Down
6 changes: 3 additions & 3 deletions ethclient/gethclient/gethclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func newTestBackend(t *testing.T) (*node.Node, []*types.Block) {
t.Fatalf("can't create new node: %v", err)
}
// Create Ethereum Service
config := &ethconfig.Config{Genesis: genesis}
config := &ethconfig.Config{Genesis: genesis, RPCGasCap: 1000000}
ethservice, err := eth.New(n, config)
if err != nil {
t.Fatalf("can't create new ethereum service: %v", err)
Expand Down Expand Up @@ -510,7 +510,7 @@ func TestBlockOverridesMarshal(t *testing.T) {
bo: BlockOverrides{
Coinbase: common.HexToAddress("0x1111111111111111111111111111111111111111"),
},
want: `{"coinbase":"0x1111111111111111111111111111111111111111"}`,
want: `{"feeRecipient":"0x1111111111111111111111111111111111111111"}`,
},
{
bo: BlockOverrides{
Expand All @@ -520,7 +520,7 @@ func TestBlockOverridesMarshal(t *testing.T) {
GasLimit: 4,
BaseFee: big.NewInt(5),
},
want: `{"number":"0x1","difficulty":"0x2","time":"0x3","gasLimit":"0x4","baseFee":"0x5"}`,
want: `{"number":"0x1","difficulty":"0x2","time":"0x3","gasLimit":"0x4","baseFeePerGas":"0x5"}`,
},
} {
marshalled, err := json.Marshal(&tt.bo)
Expand Down
1 change: 1 addition & 0 deletions graphql/graphql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,7 @@ func newGQLService(t *testing.T, stack *node.Node, shanghai bool, gspec *core.Ge
TrieDirtyCache: 5,
TrieTimeout: 60 * time.Minute,
SnapshotCache: 5,
RPCGasCap: 1000000,
StateScheme: rawdb.HashScheme,
}
var engine consensus.Engine = ethash.NewFaker()
Expand Down
Loading