Skip to content

Commit

Permalink
handle basefee correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
klkvr committed Sep 11, 2024
1 parent bae3095 commit 9aa6c52
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion crates/rpc/rpc-eth-api/src/helpers/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::{AsEthApiError, FromEthApiError, FromEvmError, IntoEthApiError};
use futures::Future;
use reth_evm::{ConfigureEvm, ConfigureEvmEnv};
use reth_primitives::{
basefee::calc_next_block_base_fee,
revm_primitives::{
BlockEnv, CfgEnvWithHandlerCfg, EnvWithHandlerCfg, ExecutionResult, HaltReason,
ResultAndState, TransactTo, TxEnv,
Expand Down Expand Up @@ -103,13 +104,35 @@ pub trait EthCall: Call + LoadPendingBlock {
let this = self.clone();
self.spawn_with_state_at_block(block, move |state| {
let mut db = CacheDB::new(StateProviderDatabase::new(state));
let mut blocks = Vec::with_capacity(block_state_calls.len());
let mut blocks: Vec<
SimulatedBlock<Block<WithOtherFields<reth_rpc_types::Transaction>>>,
> = Vec::with_capacity(block_state_calls.len());
let mut gas_used = 0;
for block in block_state_calls {
// Increase number and timestamp for every new block
block_env.number += U256::from(1);
block_env.timestamp += U256::from(1);

if !validation {
block_env.basefee = U256::ZERO;
} else {
let chain_spec = LoadPendingBlock::provider(&this).chain_spec();
let base_fee_params =
chain_spec.base_fee_params_at_timestamp(block_env.timestamp.to());
let base_fee = if let Some(latest) = blocks.last() {
let header = &latest.inner.header;
calc_next_block_base_fee(
header.gas_used,
header.gas_limit,
header.base_fee_per_gas.unwrap_or_default(),
base_fee_params,
)
} else {
base_block.header.next_block_base_fee(base_fee_params).unwrap_or_default() as u128
};
block_env.basefee = U256::from(base_fee);
}

let SimBlock { block_overrides, state_overrides, mut calls } = block;

if let Some(block_overrides) = block_overrides {
Expand Down

0 comments on commit 9aa6c52

Please sign in to comment.