Skip to content

Commit

Permalink
fix: apply block overrides before create env (#7135)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse committed Mar 13, 2024
1 parent 28f3a2e commit 455b2af
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions crates/rpc/rpc/src/eth/revm_utils.rs
Expand Up @@ -237,7 +237,7 @@ where
/// - `nonce` is set to `None`
pub(crate) fn prepare_call_env<DB>(
mut cfg: CfgEnvWithHandlerCfg,
block: BlockEnv,
mut block: BlockEnv,
request: TransactionRequest,
gas_limit: u64,
db: &mut CacheDB<DB>,
Expand All @@ -260,26 +260,27 @@ where
// <https://github.com/ethereum/go-ethereum/blob/ee8e83fa5f6cb261dad2ed0a7bbcde4930c41e6c/internal/ethapi/api.go#L985>
cfg.disable_base_fee = true;

let request_gas = request.gas;
// 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 {
if let Some(block_hashes) = block_overrides.block_hash.take() {
// override block hashes
db.block_hashes
.extend(block_hashes.into_iter().map(|(num, hash)| (U256::from(num), hash)))
}
apply_block_overrides(*block_overrides, &mut block);
}

let request_gas = request.gas;
let mut env = 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 {
apply_state_overrides(state_overrides, db)?;
}

// apply block overrides
if let Some(mut block_overrides) = overrides.block {
if let Some(block_hashes) = block_overrides.block_hash.take() {
// override block hashes
db.block_hashes
.extend(block_hashes.into_iter().map(|(num, hash)| (U256::from(num), hash)))
}
apply_block_overrides(*block_overrides, &mut env.env.block);
}

if request_gas.is_none() {
// No gas limit was provided in the request, so we need to cap the transaction gas limit
if env.tx.gas_price > U256::ZERO {
Expand Down

0 comments on commit 455b2af

Please sign in to comment.