From f17c72ff04253f3232ff39398ea0763e3bb898e6 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Thu, 1 Aug 2024 09:06:40 +0200 Subject: [PATCH] fix: also ignore nonce in eth_estimate (#9968) --- crates/rpc/rpc-eth-api/src/helpers/call.rs | 33 ++++++++++++++++------ 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/crates/rpc/rpc-eth-api/src/helpers/call.rs b/crates/rpc/rpc-eth-api/src/helpers/call.rs index dee74fb6cf..9280154b8f 100644 --- a/crates/rpc/rpc-eth-api/src/helpers/call.rs +++ b/crates/rpc/rpc-eth-api/src/helpers/call.rs @@ -507,12 +507,20 @@ pub trait Call: LoadState + SpawnBlocking { /// Estimates the gas usage of the `request` with the state. /// - /// This will execute the [`TransactionRequest`] and find the best gas limit via binary search + /// This will execute the [`TransactionRequest`] and find the best gas limit via binary search. + /// + /// ## EVM settings + /// + /// This modifies certain EVM settings to mirror geth's `SkipAccountChecks` when transacting requests, see also: : + /// + /// - `disable_eip3607` is set to `true` + /// - `disable_base_fee` is set to `true` + /// - `nonce` is set to `None` fn estimate_gas_with( &self, mut cfg: CfgEnvWithHandlerCfg, block: BlockEnv, - request: TransactionRequest, + mut request: TransactionRequest, state: S, state_override: Option, ) -> Result @@ -523,11 +531,14 @@ pub trait Call: LoadState + SpawnBlocking { // See cfg.disable_eip3607 = true; - // The basefee should be ignored for eth_createAccessList + // The basefee should be ignored for eth_estimateGas and similar // See: // cfg.disable_base_fee = true; + // set nonce to None so that the correct nonce is chosen by the EVM + request.nonce = None; + // Keep a copy of gas related request values let tx_request_gas_limit = request.gas; let tx_request_gas_price = request.gas_price; @@ -885,16 +896,21 @@ pub trait Call: LoadState + SpawnBlocking { /// /// Does not commit any changes to the underlying database. /// - /// EVM settings: - /// - `disable_block_gas_limit` is set to `true` + /// ## EVM settings + /// + /// This modifies certain EVM settings to mirror geth's `SkipAccountChecks` when transacting requests, see also: : + /// /// - `disable_eip3607` is set to `true` /// - `disable_base_fee` is set to `true` /// - `nonce` is set to `None` + /// + /// Additionally, the block gas limit so that higher tx gas limits can be used in `eth_call`. + /// - `disable_block_gas_limit` is set to `true` fn prepare_call_env( &self, mut cfg: CfgEnvWithHandlerCfg, mut block: BlockEnv, - request: TransactionRequest, + mut request: TransactionRequest, gas_limit: u64, db: &mut CacheDB, overrides: EvmOverrides, @@ -916,6 +932,9 @@ pub trait Call: LoadState + SpawnBlocking { // cfg.disable_base_fee = true; + // set nonce to None so that the correct nonce is chosen by the EVM + request.nonce = None; + // apply block overrides, we need to apply them first so that they take effect when we we // create the evm env via `build_call_evm_env`, e.g. basefee if let Some(mut block_overrides) = overrides.block { @@ -929,8 +948,6 @@ pub trait Call: LoadState + SpawnBlocking { let request_gas = request.gas; let mut env = self.build_call_evm_env(cfg, block, request)?; - // set nonce to None so that the next nonce is used when transacting the call - env.tx.nonce = None; // apply state overrides if let Some(state_overrides) = overrides.state {