Skip to content

Commit

Permalink
chore: rm evm_env_for_raw_block function (#13403)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse authored Dec 16, 2024
1 parent c314aa6 commit 4e6ed39
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 33 deletions.
34 changes: 5 additions & 29 deletions crates/rpc/rpc-eth-api/src/helpers/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,21 @@
//! RPC methods.
use super::{EthApiSpec, LoadPendingBlock, SpawnBlocking};
use crate::{EthApiTypes, FromEthApiError, RpcNodeCore, RpcNodeCoreExt};
use alloy_consensus::{constants::KECCAK_EMPTY, BlockHeader};
use alloy_consensus::constants::KECCAK_EMPTY;
use alloy_eips::BlockId;
use alloy_primitives::{Address, Bytes, B256, U256};
use alloy_rpc_types_eth::{Account, EIP1186AccountProofResponse};
use alloy_serde::JsonStorageKey;
use futures::Future;
use reth_chainspec::{EthChainSpec, EthereumHardforks};
use reth_errors::RethError;
use reth_evm::{env::EvmEnv, ConfigureEvmEnv};
use reth_evm::env::EvmEnv;
use reth_provider::{
BlockIdReader, BlockNumReader, ChainSpecProvider, EvmEnvProvider as _, ProviderHeader,
StateProvider, StateProviderBox, StateProviderFactory,
BlockIdReader, BlockNumReader, ChainSpecProvider, EvmEnvProvider as _, StateProvider,
StateProviderBox, StateProviderFactory,
};
use reth_rpc_eth_types::{EthApiError, PendingBlockEnv, RpcInvalidTransactionError};
use reth_transaction_pool::TransactionPool;
use revm_primitives::SpecId;

/// Helper methods for `eth_` methods relating to state (accounts).
pub trait EthState: LoadState + SpawnBlocking {
Expand Down Expand Up @@ -232,38 +231,15 @@ pub trait LoadState:

let header =
self.cache().get_header(block_hash).await.map_err(Self::Error::from_eth_err)?;
let evm_config = self.evm_config().clone();
let evm_env = self
.provider()
.env_with_header(&header, evm_config)
.env_with_header(&header, self.evm_config().clone())
.map_err(Self::Error::from_eth_err)?;
Ok((evm_env, block_hash.into()))
}
}
}

/// Returns the revm evm env for the raw block header
///
/// This is used for tracing raw blocks
fn evm_env_for_raw_block(
&self,
header: &ProviderHeader<Self::Provider>,
) -> impl Future<Output = Result<EvmEnv, Self::Error>> + Send
where
Self: LoadPendingBlock + SpawnBlocking,
{
async move {
// get the parent config first
let (evm_env, _) = self.evm_env_at(header.parent_hash().into()).await?;
let EvmEnv { cfg_env_with_handler_cfg, mut block_env } = evm_env;

let after_merge = cfg_env_with_handler_cfg.handler_cfg.spec_id >= SpecId::MERGE;
self.evm_config().fill_block_env(&mut block_env, header, after_merge);

Ok((cfg_env_with_handler_cfg, block_env).into())
}
}

/// Returns the next available nonce without gaps for the given address
/// Next available nonce is either the on chain nonce of the account or the highest consecutive
/// nonce in the pool + 1
Expand Down
11 changes: 7 additions & 4 deletions crates/rpc/rpc/src/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ use reth_evm::{
use reth_primitives::{BlockExt, NodePrimitives, ReceiptWithBloom, SealedBlockWithSenders};
use reth_primitives_traits::{Block as _, BlockBody, SignedTransaction};
use reth_provider::{
BlockIdReader, BlockReaderIdExt, ChainSpecProvider, HeaderProvider, ProviderBlock,
ReceiptProviderIdExt, StateProofProvider, TransactionVariant,
BlockIdReader, BlockReaderIdExt, ChainSpecProvider, EvmEnvProvider, HeaderProvider,
ProviderBlock, ReceiptProviderIdExt, StateProofProvider, TransactionVariant,
};
use reth_revm::{database::StateProviderDatabase, witness::ExecutionWitnessRecord};
use reth_rpc_api::DebugApiServer;
Expand Down Expand Up @@ -162,8 +162,11 @@ where
.map_err(BlockError::RlpDecodeRawBlock)
.map_err(Eth::Error::from_eth_err)?;

let evm_env = self.eth_api().evm_env_for_raw_block(block.header()).await?;
let EvmEnv { cfg_env_with_handler_cfg, block_env } = evm_env;
// Note: we assume the block has a valid height
let EvmEnv { cfg_env_with_handler_cfg, block_env } = self
.provider()
.env_with_header(block.header(), self.eth_api().evm_config().clone())
.map_err(Eth::Error::from_eth_err)?;

// Depending on EIP-2 we need to recover the transactions differently
let senders =
Expand Down

0 comments on commit 4e6ed39

Please sign in to comment.