mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
chore(evm): turn associated ConfigureEvm fns into methods (#9322)
This commit is contained in:
@ -145,7 +145,8 @@ where
|
||||
DB::Error: Into<ProviderError> + std::fmt::Display,
|
||||
{
|
||||
// apply pre execution changes
|
||||
apply_beacon_root_contract_call::<EvmConfig, _, _>(
|
||||
apply_beacon_root_contract_call(
|
||||
&self.evm_config,
|
||||
&self.chain_spec,
|
||||
block.timestamp,
|
||||
block.number,
|
||||
@ -220,7 +221,7 @@ where
|
||||
|
||||
// Collect all EIP-7685 requests
|
||||
let withdrawal_requests =
|
||||
apply_withdrawal_requests_contract_call::<EvmConfig, _, _>(&mut evm)?;
|
||||
apply_withdrawal_requests_contract_call(&self.evm_config, &mut evm)?;
|
||||
|
||||
[deposit_requests, withdrawal_requests].concat()
|
||||
} else {
|
||||
@ -275,7 +276,7 @@ where
|
||||
fn evm_env_for_block(&self, header: &Header, total_difficulty: U256) -> EnvWithHandlerCfg {
|
||||
let mut cfg = CfgEnvWithHandlerCfg::new(Default::default(), Default::default());
|
||||
let mut block_env = BlockEnv::default();
|
||||
EvmConfig::fill_cfg_and_block_env(
|
||||
self.executor.evm_config.fill_cfg_and_block_env(
|
||||
&mut cfg,
|
||||
&mut block_env,
|
||||
self.chain_spec(),
|
||||
|
||||
@ -36,6 +36,7 @@ pub struct EthEvmConfig;
|
||||
|
||||
impl ConfigureEvmEnv for EthEvmConfig {
|
||||
fn fill_cfg_env(
|
||||
&self,
|
||||
cfg_env: &mut CfgEnvWithHandlerCfg,
|
||||
chain_spec: &ChainSpec,
|
||||
header: &Header,
|
||||
@ -63,6 +64,7 @@ impl ConfigureEvmEnv for EthEvmConfig {
|
||||
}
|
||||
|
||||
fn fill_tx_env_system_contract_call(
|
||||
&self,
|
||||
env: &mut Env,
|
||||
caller: Address,
|
||||
contract: Address,
|
||||
@ -132,7 +134,7 @@ mod tests {
|
||||
let chain_spec = ChainSpec::default();
|
||||
let total_difficulty = U256::ZERO;
|
||||
|
||||
EthEvmConfig::fill_cfg_and_block_env(
|
||||
EthEvmConfig::default().fill_cfg_and_block_env(
|
||||
&mut cfg_env,
|
||||
&mut block_env,
|
||||
&chain_spec,
|
||||
|
||||
@ -118,7 +118,7 @@ where
|
||||
// apply eip-4788 pre block contract call
|
||||
pre_block_beacon_root_contract_call(
|
||||
&mut db,
|
||||
self.evm_config.clone(),
|
||||
&self.evm_config,
|
||||
&chain_spec,
|
||||
&initialized_cfg,
|
||||
&initialized_block_env,
|
||||
@ -201,6 +201,7 @@ where
|
||||
// We do not calculate the EIP-6110 deposit requests because there are no
|
||||
// transactions in an empty payload.
|
||||
let withdrawal_requests = post_block_withdrawal_requests_contract_call::<EvmConfig, _>(
|
||||
&self.evm_config,
|
||||
&mut db,
|
||||
&initialized_cfg,
|
||||
&initialized_block_env,
|
||||
@ -296,7 +297,7 @@ where
|
||||
// apply eip-4788 pre block contract call
|
||||
pre_block_beacon_root_contract_call(
|
||||
&mut db,
|
||||
evm_config.clone(),
|
||||
&evm_config,
|
||||
&chain_spec,
|
||||
&initialized_cfg,
|
||||
&initialized_block_env,
|
||||
@ -443,7 +444,8 @@ where
|
||||
{
|
||||
let deposit_requests = parse_deposits_from_receipts(&chain_spec, receipts.iter().flatten())
|
||||
.map_err(|err| PayloadBuilderError::Internal(RethError::Execution(err.into())))?;
|
||||
let withdrawal_requests = post_block_withdrawal_requests_contract_call::<EvmConfig, _>(
|
||||
let withdrawal_requests = post_block_withdrawal_requests_contract_call(
|
||||
&evm_config,
|
||||
&mut db,
|
||||
&initialized_cfg,
|
||||
&initialized_block_env,
|
||||
|
||||
@ -122,6 +122,7 @@ pub trait ConfigureEvmEnv: Send + Sync + Unpin + Clone + 'static {
|
||||
|
||||
/// Fill transaction environment with a system contract call.
|
||||
fn fill_tx_env_system_contract_call(
|
||||
&self,
|
||||
env: &mut Env,
|
||||
caller: Address,
|
||||
contract: Address,
|
||||
@ -130,6 +131,7 @@ pub trait ConfigureEvmEnv: Send + Sync + Unpin + Clone + 'static {
|
||||
|
||||
/// Fill [`CfgEnvWithHandlerCfg`] fields according to the chain spec and given header
|
||||
fn fill_cfg_env(
|
||||
&self,
|
||||
cfg_env: &mut CfgEnvWithHandlerCfg,
|
||||
chain_spec: &ChainSpec,
|
||||
header: &Header,
|
||||
@ -145,11 +147,12 @@ pub trait ConfigureEvmEnv: Send + Sync + Unpin + Clone + 'static {
|
||||
after_merge: bool,
|
||||
) {
|
||||
let coinbase = block_coinbase(chain_spec, header, after_merge);
|
||||
Self::fill_block_env_with_coinbase(block_env, header, after_merge, coinbase);
|
||||
self.fill_block_env_with_coinbase(block_env, header, after_merge, coinbase);
|
||||
}
|
||||
|
||||
/// Fill block environment with coinbase.
|
||||
fn fill_block_env_with_coinbase(
|
||||
&self,
|
||||
block_env: &mut BlockEnv,
|
||||
header: &Header,
|
||||
after_merge: bool,
|
||||
@ -177,15 +180,16 @@ pub trait ConfigureEvmEnv: Send + Sync + Unpin + Clone + 'static {
|
||||
/// Convenience function to call both [`fill_cfg_env`](ConfigureEvmEnv::fill_cfg_env) and
|
||||
/// [`ConfigureEvmEnv::fill_block_env`].
|
||||
fn fill_cfg_and_block_env(
|
||||
&self,
|
||||
cfg: &mut CfgEnvWithHandlerCfg,
|
||||
block_env: &mut BlockEnv,
|
||||
chain_spec: &ChainSpec,
|
||||
header: &Header,
|
||||
total_difficulty: U256,
|
||||
) {
|
||||
Self::fill_cfg_env(cfg, chain_spec, header, total_difficulty);
|
||||
self.fill_cfg_env(cfg, chain_spec, header, total_difficulty);
|
||||
let after_merge = cfg.handler_cfg.spec_id >= SpecId::MERGE;
|
||||
Self::fill_block_env_with_coinbase(
|
||||
self.fill_block_env_with_coinbase(
|
||||
block_env,
|
||||
header,
|
||||
after_merge,
|
||||
|
||||
@ -24,7 +24,7 @@ use revm_primitives::{
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn pre_block_beacon_root_contract_call<EvmConfig, DB>(
|
||||
db: &mut DB,
|
||||
_emv_config: EvmConfig,
|
||||
evm_config: &EvmConfig,
|
||||
chain_spec: &ChainSpec,
|
||||
initialized_cfg: &CfgEnvWithHandlerCfg,
|
||||
initialized_block_env: &BlockEnv,
|
||||
@ -48,7 +48,8 @@ where
|
||||
.build();
|
||||
|
||||
// initialize a block from the env, because the pre block call needs the block itself
|
||||
apply_beacon_root_contract_call::<EvmConfig, _, _>(
|
||||
apply_beacon_root_contract_call(
|
||||
evm_config,
|
||||
chain_spec,
|
||||
block_timestamp,
|
||||
block_number,
|
||||
@ -66,6 +67,7 @@ where
|
||||
/// [EIP-4788]: https://eips.ethereum.org/EIPS/eip-4788
|
||||
#[inline]
|
||||
pub fn apply_beacon_root_contract_call<EvmConfig, EXT, DB>(
|
||||
evm_config: &EvmConfig,
|
||||
chain_spec: &ChainSpec,
|
||||
block_timestamp: u64,
|
||||
block_number: u64,
|
||||
@ -100,7 +102,7 @@ where
|
||||
let previous_env = Box::new(evm.context.env().clone());
|
||||
|
||||
// modify env for pre block call
|
||||
EvmConfig::fill_tx_env_system_contract_call(
|
||||
evm_config.fill_tx_env_system_contract_call(
|
||||
&mut evm.context.evm.env,
|
||||
alloy_eips::eip4788::SYSTEM_ADDRESS,
|
||||
BEACON_ROOTS_ADDRESS,
|
||||
@ -138,6 +140,7 @@ where
|
||||
/// This uses [`apply_withdrawal_requests_contract_call`] to ultimately calculate the
|
||||
/// [requests](Request).
|
||||
pub fn post_block_withdrawal_requests_contract_call<EvmConfig, DB>(
|
||||
evm_config: &EvmConfig,
|
||||
db: &mut DB,
|
||||
initialized_cfg: &CfgEnvWithHandlerCfg,
|
||||
initialized_block_env: &BlockEnv,
|
||||
@ -158,7 +161,7 @@ where
|
||||
.build();
|
||||
|
||||
// initialize a block from the env, because the post block call needs the block itself
|
||||
apply_withdrawal_requests_contract_call::<EvmConfig, _, _>(&mut evm_post_block)
|
||||
apply_withdrawal_requests_contract_call::<EvmConfig, _, _>(evm_config, &mut evm_post_block)
|
||||
}
|
||||
|
||||
/// Applies the post-block call to the EIP-7002 withdrawal requests contract.
|
||||
@ -167,6 +170,7 @@ where
|
||||
/// returned. Otherwise, the withdrawal requests are returned.
|
||||
#[inline]
|
||||
pub fn apply_withdrawal_requests_contract_call<EvmConfig, EXT, DB>(
|
||||
evm_config: &EvmConfig,
|
||||
evm: &mut Evm<'_, EXT, DB>,
|
||||
) -> Result<Vec<Request>, BlockExecutionError>
|
||||
where
|
||||
@ -185,7 +189,7 @@ where
|
||||
// At the end of processing any execution block where `block.timestamp >= FORK_TIMESTAMP` (i.e.
|
||||
// after processing all transactions and after performing the block body withdrawal requests
|
||||
// validations), call the contract as `SYSTEM_ADDRESS`.
|
||||
EvmConfig::fill_tx_env_system_contract_call(
|
||||
evm_config.fill_tx_env_system_contract_call(
|
||||
&mut evm.context.evm.env,
|
||||
alloy_eips::eip7002::SYSTEM_ADDRESS,
|
||||
WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS,
|
||||
|
||||
@ -122,7 +122,8 @@ where
|
||||
DB: Database<Error: Into<ProviderError> + std::fmt::Display>,
|
||||
{
|
||||
// apply pre execution changes
|
||||
apply_beacon_root_contract_call::<EvmConfig, _, _>(
|
||||
apply_beacon_root_contract_call(
|
||||
&self.evm_config,
|
||||
&self.chain_spec,
|
||||
block.timestamp,
|
||||
block.number,
|
||||
@ -271,7 +272,7 @@ where
|
||||
fn evm_env_for_block(&self, header: &Header, total_difficulty: U256) -> EnvWithHandlerCfg {
|
||||
let mut cfg = CfgEnvWithHandlerCfg::new(Default::default(), Default::default());
|
||||
let mut block_env = BlockEnv::default();
|
||||
EvmConfig::fill_cfg_and_block_env(
|
||||
self.executor.evm_config.fill_cfg_and_block_env(
|
||||
&mut cfg,
|
||||
&mut block_env,
|
||||
self.chain_spec(),
|
||||
|
||||
@ -40,6 +40,7 @@ impl ConfigureEvmEnv for OptimismEvmConfig {
|
||||
}
|
||||
|
||||
fn fill_tx_env_system_contract_call(
|
||||
&self,
|
||||
env: &mut Env,
|
||||
caller: Address,
|
||||
contract: Address,
|
||||
@ -83,6 +84,7 @@ impl ConfigureEvmEnv for OptimismEvmConfig {
|
||||
}
|
||||
|
||||
fn fill_cfg_env(
|
||||
&self,
|
||||
cfg_env: &mut CfgEnvWithHandlerCfg,
|
||||
chain_spec: &ChainSpec,
|
||||
header: &Header,
|
||||
@ -143,7 +145,7 @@ mod tests {
|
||||
let chain_spec = ChainSpec::default();
|
||||
let total_difficulty = U256::ZERO;
|
||||
|
||||
OptimismEvmConfig::fill_cfg_and_block_env(
|
||||
OptimismEvmConfig::default().fill_cfg_and_block_env(
|
||||
&mut cfg_env,
|
||||
&mut block_env,
|
||||
&chain_spec,
|
||||
|
||||
@ -125,7 +125,7 @@ where
|
||||
// apply eip-4788 pre block contract call
|
||||
pre_block_beacon_root_contract_call(
|
||||
&mut db,
|
||||
self.evm_config.clone(),
|
||||
&self.evm_config,
|
||||
&chain_spec,
|
||||
&initialized_cfg,
|
||||
&initialized_block_env,
|
||||
@ -288,7 +288,7 @@ where
|
||||
// apply eip-4788 pre block contract call
|
||||
pre_block_beacon_root_contract_call(
|
||||
&mut db,
|
||||
evm_config.clone(),
|
||||
&evm_config,
|
||||
&chain_spec,
|
||||
&initialized_cfg,
|
||||
&initialized_block_env,
|
||||
|
||||
@ -235,7 +235,7 @@ pub trait LoadPendingBlock {
|
||||
// parent beacon block root
|
||||
pre_block_beacon_root_contract_call(
|
||||
&mut db,
|
||||
self.evm_config().clone(),
|
||||
self.evm_config(),
|
||||
chain_spec.as_ref(),
|
||||
&cfg,
|
||||
&block_env,
|
||||
|
||||
@ -2040,7 +2040,7 @@ impl<TX: DbTx> EvmEnvProvider for DatabaseProvider<TX> {
|
||||
cfg: &mut CfgEnvWithHandlerCfg,
|
||||
block_env: &mut BlockEnv,
|
||||
header: &Header,
|
||||
_evm_config: EvmConfig,
|
||||
evm_config: EvmConfig,
|
||||
) -> ProviderResult<()>
|
||||
where
|
||||
EvmConfig: ConfigureEvmEnv,
|
||||
@ -2048,7 +2048,7 @@ impl<TX: DbTx> EvmEnvProvider for DatabaseProvider<TX> {
|
||||
let total_difficulty = self
|
||||
.header_td_by_number(header.number)?
|
||||
.ok_or_else(|| ProviderError::HeaderNotFound(header.number.into()))?;
|
||||
EvmConfig::fill_cfg_and_block_env(
|
||||
evm_config.fill_cfg_and_block_env(
|
||||
cfg,
|
||||
block_env,
|
||||
&self.chain_spec,
|
||||
@ -2076,7 +2076,7 @@ impl<TX: DbTx> EvmEnvProvider for DatabaseProvider<TX> {
|
||||
&self,
|
||||
cfg: &mut CfgEnvWithHandlerCfg,
|
||||
header: &Header,
|
||||
_evm_config: EvmConfig,
|
||||
evm_config: EvmConfig,
|
||||
) -> ProviderResult<()>
|
||||
where
|
||||
EvmConfig: ConfigureEvmEnv,
|
||||
@ -2084,7 +2084,7 @@ impl<TX: DbTx> EvmEnvProvider for DatabaseProvider<TX> {
|
||||
let total_difficulty = self
|
||||
.header_td_by_number(header.number)?
|
||||
.ok_or_else(|| ProviderError::HeaderNotFound(header.number.into()))?;
|
||||
EvmConfig::fill_cfg_env(cfg, &self.chain_spec, header, total_difficulty);
|
||||
evm_config.fill_cfg_env(cfg, &self.chain_spec, header, total_difficulty);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@ -68,6 +68,7 @@ impl MyEvmConfig {
|
||||
|
||||
impl ConfigureEvmEnv for MyEvmConfig {
|
||||
fn fill_cfg_env(
|
||||
&self,
|
||||
cfg_env: &mut CfgEnvWithHandlerCfg,
|
||||
chain_spec: &ChainSpec,
|
||||
header: &Header,
|
||||
@ -95,12 +96,13 @@ impl ConfigureEvmEnv for MyEvmConfig {
|
||||
}
|
||||
|
||||
fn fill_tx_env_system_contract_call(
|
||||
&self,
|
||||
env: &mut Env,
|
||||
caller: Address,
|
||||
contract: Address,
|
||||
data: Bytes,
|
||||
) {
|
||||
EthEvmConfig::fill_tx_env_system_contract_call(env, caller, contract, data)
|
||||
EthEvmConfig::default().fill_tx_env_system_contract_call(env, caller, contract, data)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -107,13 +107,7 @@ fn configure_evm<'a>(
|
||||
);
|
||||
|
||||
let mut cfg = CfgEnvWithHandlerCfg::new_with_spec_id(evm.cfg().clone(), evm.spec_id());
|
||||
EthEvmConfig::fill_cfg_and_block_env(
|
||||
&mut cfg,
|
||||
evm.block_mut(),
|
||||
&CHAIN_SPEC,
|
||||
header,
|
||||
U256::ZERO,
|
||||
);
|
||||
config.fill_cfg_and_block_env(&mut cfg, evm.block_mut(), &CHAIN_SPEC, header, U256::ZERO);
|
||||
*evm.cfg_mut() = cfg.cfg_env;
|
||||
|
||||
evm
|
||||
|
||||
@ -143,21 +143,23 @@ impl ConfigureEvmEnv for MyEvmConfig {
|
||||
}
|
||||
|
||||
fn fill_cfg_env(
|
||||
&self,
|
||||
cfg_env: &mut CfgEnvWithHandlerCfg,
|
||||
chain_spec: &ChainSpec,
|
||||
header: &Header,
|
||||
total_difficulty: U256,
|
||||
) {
|
||||
EthEvmConfig::fill_cfg_env(cfg_env, chain_spec, header, total_difficulty)
|
||||
EthEvmConfig::default().fill_cfg_env(cfg_env, chain_spec, header, total_difficulty)
|
||||
}
|
||||
|
||||
fn fill_tx_env_system_contract_call(
|
||||
&self,
|
||||
env: &mut Env,
|
||||
caller: Address,
|
||||
contract: Address,
|
||||
data: Bytes,
|
||||
) {
|
||||
EthEvmConfig::fill_tx_env_system_contract_call(env, caller, contract, data)
|
||||
EthEvmConfig::default().fill_tx_env_system_contract_call(env, caller, contract, data)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user