mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-01-09 15:28:01 -05:00
chore: optimize evm_env if header is available (#20691)
This commit is contained in:
@@ -666,7 +666,7 @@ pub trait Call:
|
|||||||
};
|
};
|
||||||
let (tx, tx_info) = transaction.split();
|
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
|
// we need to get the state of the parent block because we're essentially replaying the
|
||||||
// block the transaction is included in
|
// block the transaction is included in
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ use alloy_serde::JsonStorageKey;
|
|||||||
use futures::Future;
|
use futures::Future;
|
||||||
use reth_errors::RethError;
|
use reth_errors::RethError;
|
||||||
use reth_evm::{ConfigureEvm, EvmEnvFor};
|
use reth_evm::{ConfigureEvm, EvmEnvFor};
|
||||||
|
use reth_primitives_traits::SealedHeaderFor;
|
||||||
use reth_rpc_convert::RpcConvert;
|
use reth_rpc_convert::RpcConvert;
|
||||||
use reth_rpc_eth_types::{
|
use reth_rpc_eth_types::{
|
||||||
error::FromEvmError, EthApiError, PendingBlockEnv, RpcInvalidTransactionError,
|
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`]
|
/// Returns the revm evm env for the requested [`BlockId`]
|
||||||
///
|
///
|
||||||
/// If the [`BlockId`] this will return the [`BlockId`] of the block the env was configured
|
/// 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)
|
.sealed_header_by_id(at)
|
||||||
.map_err(Self::Error::from_eth_err)?
|
.map_err(Self::Error::from_eth_err)?
|
||||||
.ok_or_else(|| EthApiError::HeaderNotFound(at))?;
|
.ok_or_else(|| EthApiError::HeaderNotFound(at))?;
|
||||||
let evm_env = self
|
let evm_env = self.evm_env_for_header(&header)?;
|
||||||
.evm_config()
|
|
||||||
.evm_env(&header)
|
|
||||||
.map_err(RethError::other)
|
|
||||||
.map_err(Self::Error::from_eth_err)?;
|
|
||||||
|
|
||||||
Ok((evm_env, header.hash().into()))
|
Ok((evm_env, header.hash().into()))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -168,7 +168,7 @@ pub trait Trace: LoadState<Error: FromEvmError<Self::Evm>> + Call {
|
|||||||
};
|
};
|
||||||
let (tx, tx_info) = transaction.split();
|
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
|
// we need to get the state of the parent block because we're essentially replaying the
|
||||||
// block the transaction is included in
|
// block the transaction is included in
|
||||||
|
|||||||
Reference in New Issue
Block a user