chore: optimize evm_env if header is available (#20691)

This commit is contained in:
Karl Yu
2025-12-31 21:45:35 +08:00
committed by GitHub
parent dc931f5669
commit 0c69e294c3
3 changed files with 15 additions and 7 deletions

View File

@@ -666,7 +666,7 @@ pub trait Call:
};
let (tx, tx_info) = transaction.split();
let (evm_env, _) = self.evm_env_at(block.hash().into()).await?;
let evm_env = self.evm_env_for_header(block.sealed_block().sealed_header())?;
// we need to get the state of the parent block because we're essentially replaying the
// block the transaction is included in

View File

@@ -11,6 +11,7 @@ use alloy_serde::JsonStorageKey;
use futures::Future;
use reth_errors::RethError;
use reth_evm::{ConfigureEvm, EvmEnvFor};
use reth_primitives_traits::SealedHeaderFor;
use reth_rpc_convert::RpcConvert;
use reth_rpc_eth_types::{
error::FromEvmError, EthApiError, PendingBlockEnv, RpcInvalidTransactionError,
@@ -256,6 +257,17 @@ pub trait LoadState:
}
}
/// Returns the revm evm env for the given sealed header.
fn evm_env_for_header(
&self,
header: &SealedHeaderFor<Self::Primitives>,
) -> Result<EvmEnvFor<Self::Evm>, Self::Error> {
self.evm_config()
.evm_env(header)
.map_err(RethError::other)
.map_err(Self::Error::from_eth_err)
}
/// Returns the revm evm env for the requested [`BlockId`]
///
/// If the [`BlockId`] this will return the [`BlockId`] of the block the env was configured
@@ -281,11 +293,7 @@ pub trait LoadState:
.sealed_header_by_id(at)
.map_err(Self::Error::from_eth_err)?
.ok_or_else(|| EthApiError::HeaderNotFound(at))?;
let evm_env = self
.evm_config()
.evm_env(&header)
.map_err(RethError::other)
.map_err(Self::Error::from_eth_err)?;
let evm_env = self.evm_env_for_header(&header)?;
Ok((evm_env, header.hash().into()))
}

View File

@@ -168,7 +168,7 @@ pub trait Trace: LoadState<Error: FromEvmError<Self::Evm>> + Call {
};
let (tx, tx_info) = transaction.split();
let (evm_env, _) = self.evm_env_at(block.hash().into()).await?;
let evm_env = self.evm_env_for_header(block.sealed_block().sealed_header())?;
// we need to get the state of the parent block because we're essentially replaying the
// block the transaction is included in