mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
refactor: use EvmEnv when setting up Evm (#13800)
This commit is contained in:
@ -211,7 +211,7 @@ mod tests {
|
||||
primitives::{AccountInfo, BlockEnv, CfgEnv, SpecId},
|
||||
JournaledState,
|
||||
};
|
||||
use revm_primitives::{EnvWithHandlerCfg, HandlerCfg};
|
||||
use revm_primitives::HandlerCfg;
|
||||
use std::sync::Arc;
|
||||
|
||||
fn test_evm_config() -> OpEvmConfig {
|
||||
@ -291,12 +291,12 @@ mod tests {
|
||||
|
||||
let db = CacheDB::<EmptyDBTyped<ProviderError>>::default();
|
||||
|
||||
let env_with_handler = EnvWithHandlerCfg::default();
|
||||
let evm_env = EvmEnv::default();
|
||||
|
||||
let evm = evm_config.evm_with_env(db, env_with_handler.clone());
|
||||
let evm = evm_config.evm_with_env(db, evm_env.clone(), Default::default());
|
||||
|
||||
// Check that the EVM environment
|
||||
assert_eq!(evm.context.evm.env, env_with_handler.env);
|
||||
assert_eq!(evm.context.evm.env.cfg, evm_env.cfg_env_with_handler_cfg.cfg_env);
|
||||
|
||||
// Default spec ID
|
||||
assert_eq!(evm.handler.spec_id(), SpecId::LATEST);
|
||||
@ -314,16 +314,15 @@ mod tests {
|
||||
// Create a custom configuration environment with a chain ID of 111
|
||||
let cfg = CfgEnv::default().with_chain_id(111);
|
||||
|
||||
let env_with_handler = EnvWithHandlerCfg {
|
||||
env: Box::new(Env {
|
||||
cfg: cfg.clone(),
|
||||
block: BlockEnv::default(),
|
||||
tx: TxEnv::default(),
|
||||
}),
|
||||
handler_cfg: Default::default(),
|
||||
let evm_env = EvmEnv {
|
||||
cfg_env_with_handler_cfg: CfgEnvWithHandlerCfg {
|
||||
cfg_env: cfg.clone(),
|
||||
handler_cfg: Default::default(),
|
||||
},
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let evm = evm_config.evm_with_env(db, env_with_handler);
|
||||
let evm = evm_config.evm_with_env(db, evm_env, Default::default());
|
||||
|
||||
// Check that the EVM environment is initialized with the custom environment
|
||||
assert_eq!(evm.context.evm.inner.env.cfg, cfg);
|
||||
@ -350,16 +349,13 @@ mod tests {
|
||||
};
|
||||
let tx = TxEnv { gas_limit: 5_000_000, gas_price: U256::from(50), ..Default::default() };
|
||||
|
||||
let env_with_handler = EnvWithHandlerCfg {
|
||||
env: Box::new(Env { cfg: CfgEnv::default(), block, tx }),
|
||||
handler_cfg: Default::default(),
|
||||
};
|
||||
let evm_env = EvmEnv { block_env: block, ..Default::default() };
|
||||
|
||||
let evm = evm_config.evm_with_env(db, env_with_handler.clone());
|
||||
let evm = evm_config.evm_with_env(db, evm_env.clone(), tx.clone());
|
||||
|
||||
// Verify that the block and transaction environments are set correctly
|
||||
assert_eq!(evm.context.evm.env.block, env_with_handler.env.block);
|
||||
assert_eq!(evm.context.evm.env.tx, env_with_handler.env.tx);
|
||||
assert_eq!(evm.context.evm.env.block, evm_env.block_env);
|
||||
assert_eq!(evm.context.evm.env.tx, tx);
|
||||
|
||||
// Default spec ID
|
||||
assert_eq!(evm.handler.spec_id(), SpecId::LATEST);
|
||||
@ -376,9 +372,15 @@ mod tests {
|
||||
|
||||
let handler_cfg = HandlerCfg { spec_id: SpecId::ECOTONE, ..Default::default() };
|
||||
|
||||
let env_with_handler = EnvWithHandlerCfg { env: Box::new(Env::default()), handler_cfg };
|
||||
let evm_env = EvmEnv {
|
||||
cfg_env_with_handler_cfg: CfgEnvWithHandlerCfg {
|
||||
handler_cfg,
|
||||
cfg_env: Default::default(),
|
||||
},
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let evm = evm_config.evm_with_env(db, env_with_handler);
|
||||
let evm = evm_config.evm_with_env(db, evm_env, Default::default());
|
||||
|
||||
// Check that the spec ID is setup properly
|
||||
assert_eq!(evm.handler.spec_id(), SpecId::ECOTONE);
|
||||
@ -436,13 +438,25 @@ mod tests {
|
||||
let evm_config = test_evm_config();
|
||||
let db = CacheDB::<EmptyDBTyped<ProviderError>>::default();
|
||||
|
||||
let env_with_handler = EnvWithHandlerCfg::default();
|
||||
let evm_env = EvmEnv {
|
||||
cfg_env_with_handler_cfg: CfgEnvWithHandlerCfg {
|
||||
cfg_env: Default::default(),
|
||||
handler_cfg: HandlerCfg { is_optimism: true, ..Default::default() },
|
||||
},
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let evm =
|
||||
evm_config.evm_with_env_and_inspector(db, env_with_handler.clone(), NoOpInspector);
|
||||
let evm = evm_config.evm_with_env_and_inspector(
|
||||
db,
|
||||
evm_env.clone(),
|
||||
Default::default(),
|
||||
NoOpInspector,
|
||||
);
|
||||
|
||||
// Check that the EVM environment is set to default values
|
||||
assert_eq!(evm.context.evm.env, env_with_handler.env);
|
||||
assert_eq!(evm.context.evm.env.block, evm_env.block_env);
|
||||
assert_eq!(evm.context.evm.env.cfg, evm_env.cfg_env_with_handler_cfg.cfg_env);
|
||||
assert_eq!(evm.context.evm.env.tx, Default::default());
|
||||
assert_eq!(evm.context.external, NoOpInspector);
|
||||
assert_eq!(evm.handler.spec_id(), SpecId::LATEST);
|
||||
|
||||
@ -458,15 +472,21 @@ mod tests {
|
||||
let cfg = CfgEnv::default().with_chain_id(111);
|
||||
let block = BlockEnv::default();
|
||||
let tx = TxEnv::default();
|
||||
let env_with_handler = EnvWithHandlerCfg {
|
||||
env: Box::new(Env { cfg: cfg.clone(), block, tx }),
|
||||
handler_cfg: Default::default(),
|
||||
let evm_env = EvmEnv {
|
||||
block_env: block,
|
||||
cfg_env_with_handler_cfg: CfgEnvWithHandlerCfg {
|
||||
cfg_env: cfg.clone(),
|
||||
handler_cfg: Default::default(),
|
||||
},
|
||||
};
|
||||
|
||||
let evm = evm_config.evm_with_env_and_inspector(db, env_with_handler, NoOpInspector);
|
||||
let evm =
|
||||
evm_config.evm_with_env_and_inspector(db, evm_env.clone(), tx.clone(), NoOpInspector);
|
||||
|
||||
// Check that the EVM environment is set with custom configuration
|
||||
assert_eq!(evm.context.evm.env.cfg, cfg);
|
||||
assert_eq!(evm.context.evm.env.block, evm_env.block_env);
|
||||
assert_eq!(evm.context.evm.env.tx, tx);
|
||||
assert_eq!(evm.context.external, NoOpInspector);
|
||||
assert_eq!(evm.handler.spec_id(), SpecId::LATEST);
|
||||
|
||||
@ -487,17 +507,14 @@ mod tests {
|
||||
..Default::default()
|
||||
};
|
||||
let tx = TxEnv { gas_limit: 5_000_000, gas_price: U256::from(50), ..Default::default() };
|
||||
let env_with_handler = EnvWithHandlerCfg {
|
||||
env: Box::new(Env { cfg: CfgEnv::default(), block, tx }),
|
||||
handler_cfg: Default::default(),
|
||||
};
|
||||
let evm_env = EvmEnv { block_env: block, ..Default::default() };
|
||||
|
||||
let evm =
|
||||
evm_config.evm_with_env_and_inspector(db, env_with_handler.clone(), NoOpInspector);
|
||||
evm_config.evm_with_env_and_inspector(db, evm_env.clone(), tx.clone(), NoOpInspector);
|
||||
|
||||
// Verify that the block and transaction environments are set correctly
|
||||
assert_eq!(evm.context.evm.env.block, env_with_handler.env.block);
|
||||
assert_eq!(evm.context.evm.env.tx, env_with_handler.env.tx);
|
||||
assert_eq!(evm.context.evm.env.block, evm_env.block_env);
|
||||
assert_eq!(evm.context.evm.env.tx, tx);
|
||||
assert_eq!(evm.context.external, NoOpInspector);
|
||||
assert_eq!(evm.handler.spec_id(), SpecId::LATEST);
|
||||
|
||||
@ -511,14 +528,25 @@ mod tests {
|
||||
let db = CacheDB::<EmptyDBTyped<ProviderError>>::default();
|
||||
|
||||
let handler_cfg = HandlerCfg { spec_id: SpecId::ECOTONE, ..Default::default() };
|
||||
let env_with_handler = EnvWithHandlerCfg { env: Box::new(Env::default()), handler_cfg };
|
||||
let evm_env = EvmEnv {
|
||||
cfg_env_with_handler_cfg: CfgEnvWithHandlerCfg {
|
||||
cfg_env: Default::default(),
|
||||
handler_cfg,
|
||||
},
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let evm =
|
||||
evm_config.evm_with_env_and_inspector(db, env_with_handler.clone(), NoOpInspector);
|
||||
let evm = evm_config.evm_with_env_and_inspector(
|
||||
db,
|
||||
evm_env.clone(),
|
||||
Default::default(),
|
||||
NoOpInspector,
|
||||
);
|
||||
|
||||
// Check that the spec ID is set properly
|
||||
assert_eq!(evm.handler.spec_id(), SpecId::ECOTONE);
|
||||
assert_eq!(evm.context.evm.env, env_with_handler.env);
|
||||
assert_eq!(evm.context.evm.env.cfg, evm_env.cfg_env_with_handler_cfg.cfg_env);
|
||||
assert_eq!(evm.context.evm.env.block, evm_env.block_env);
|
||||
assert_eq!(evm.context.external, NoOpInspector);
|
||||
|
||||
// Check that the spec ID is setup properly
|
||||
|
||||
@ -38,10 +38,7 @@ use reth_transaction_pool::{
|
||||
};
|
||||
use revm::{
|
||||
db::{states::bundle_state::BundleRetention, State},
|
||||
primitives::{
|
||||
BlockEnv, CfgEnvWithHandlerCfg, EVMError, EnvWithHandlerCfg, InvalidTransaction,
|
||||
ResultAndState, TxEnv,
|
||||
},
|
||||
primitives::{EVMError, InvalidTransaction, ResultAndState},
|
||||
Database, DatabaseCommit,
|
||||
};
|
||||
use std::{fmt::Display, sync::Arc};
|
||||
@ -127,7 +124,6 @@ where
|
||||
let evm_env = self
|
||||
.cfg_and_block_env(&args.config.attributes, &args.config.parent_header)
|
||||
.map_err(PayloadBuilderError::other)?;
|
||||
let EvmEnv { cfg_env_with_handler_cfg, block_env } = evm_env;
|
||||
|
||||
let BuildArguments { client, pool: _, mut cached_reads, config, cancel, best_payload } =
|
||||
args;
|
||||
@ -136,8 +132,7 @@ where
|
||||
evm_config: self.evm_config.clone(),
|
||||
chain_spec: client.chain_spec(),
|
||||
config,
|
||||
initialized_cfg: cfg_env_with_handler_cfg,
|
||||
initialized_block_env: block_env,
|
||||
evm_env,
|
||||
cancel,
|
||||
best_payload,
|
||||
};
|
||||
@ -192,15 +187,13 @@ where
|
||||
|
||||
let evm_env =
|
||||
self.cfg_and_block_env(&attributes, &parent).map_err(PayloadBuilderError::other)?;
|
||||
let EvmEnv { cfg_env_with_handler_cfg, block_env } = evm_env;
|
||||
|
||||
let config = PayloadConfig { parent_header: Arc::new(parent), attributes };
|
||||
let ctx = OpPayloadBuilderCtx {
|
||||
evm_config: self.evm_config.clone(),
|
||||
chain_spec: client.chain_spec(),
|
||||
config,
|
||||
initialized_cfg: cfg_env_with_handler_cfg,
|
||||
initialized_block_env: block_env,
|
||||
evm_env,
|
||||
cancel: Default::default(),
|
||||
best_payload: Default::default(),
|
||||
};
|
||||
@ -402,7 +395,7 @@ where
|
||||
let header = Header {
|
||||
parent_hash: ctx.parent().hash(),
|
||||
ommers_hash: EMPTY_OMMER_ROOT_HASH,
|
||||
beneficiary: ctx.initialized_block_env.coinbase,
|
||||
beneficiary: ctx.evm_env.block_env.coinbase,
|
||||
state_root,
|
||||
transactions_root,
|
||||
receipts_root,
|
||||
@ -557,9 +550,7 @@ pub struct OpPayloadBuilderCtx<EvmConfig> {
|
||||
/// How to build the payload.
|
||||
pub config: PayloadConfig<OpPayloadBuilderAttributes>,
|
||||
/// Evm Settings
|
||||
pub initialized_cfg: CfgEnvWithHandlerCfg,
|
||||
/// Block config
|
||||
pub initialized_block_env: BlockEnv,
|
||||
pub evm_env: EvmEnv,
|
||||
/// Marker to check whether the job has been cancelled.
|
||||
pub cancel: Cancelled,
|
||||
/// The currently best payload.
|
||||
@ -588,22 +579,22 @@ impl<EvmConfig> OpPayloadBuilderCtx<EvmConfig> {
|
||||
pub fn block_gas_limit(&self) -> u64 {
|
||||
self.attributes()
|
||||
.gas_limit
|
||||
.unwrap_or_else(|| self.initialized_block_env.gas_limit.saturating_to())
|
||||
.unwrap_or_else(|| self.evm_env.block_env.gas_limit.saturating_to())
|
||||
}
|
||||
|
||||
/// Returns the block number for the block.
|
||||
pub fn block_number(&self) -> u64 {
|
||||
self.initialized_block_env.number.to()
|
||||
self.evm_env.block_env.number.to()
|
||||
}
|
||||
|
||||
/// Returns the current base fee
|
||||
pub fn base_fee(&self) -> u64 {
|
||||
self.initialized_block_env.basefee.to()
|
||||
self.evm_env.block_env.basefee.to()
|
||||
}
|
||||
|
||||
/// Returns the current blob gas price.
|
||||
pub fn get_blob_gasprice(&self) -> Option<u64> {
|
||||
self.initialized_block_env.get_blob_gasprice().map(|gasprice| gasprice as u64)
|
||||
self.evm_env.block_env.get_blob_gasprice().map(|gasprice| gasprice as u64)
|
||||
}
|
||||
|
||||
/// Returns the blob fields for the header.
|
||||
@ -722,8 +713,8 @@ where
|
||||
SystemCaller::new(self.evm_config.clone(), self.chain_spec.clone())
|
||||
.pre_block_beacon_root_contract_call(
|
||||
db,
|
||||
&self.initialized_cfg,
|
||||
&self.initialized_block_env,
|
||||
&self.evm_env.cfg_env_with_handler_cfg,
|
||||
&self.evm_env.block_env,
|
||||
self.attributes().payload_attributes.parent_beacon_block_root,
|
||||
)
|
||||
.map_err(|err| {
|
||||
@ -747,13 +738,8 @@ where
|
||||
DB: Database<Error = ProviderError>,
|
||||
{
|
||||
let mut info = ExecutionInfo::with_capacity(self.attributes().transactions.len());
|
||||
|
||||
let env = EnvWithHandlerCfg::new_with_cfg_env(
|
||||
self.initialized_cfg.clone(),
|
||||
self.initialized_block_env.clone(),
|
||||
TxEnv::default(),
|
||||
);
|
||||
let mut evm = self.evm_config.evm_with_env(&mut *db, env);
|
||||
let mut evm =
|
||||
self.evm_config.evm_with_env(&mut *db, self.evm_env.clone(), Default::default());
|
||||
|
||||
for sequencer_tx in &self.attributes().transactions {
|
||||
// A sequencer's block should never contain blob transactions.
|
||||
@ -862,12 +848,8 @@ where
|
||||
let block_gas_limit = self.block_gas_limit();
|
||||
let base_fee = self.base_fee();
|
||||
|
||||
let env = EnvWithHandlerCfg::new_with_cfg_env(
|
||||
self.initialized_cfg.clone(),
|
||||
self.initialized_block_env.clone(),
|
||||
TxEnv::default(),
|
||||
);
|
||||
let mut evm = self.evm_config.evm_with_env(&mut *db, env);
|
||||
let mut evm =
|
||||
self.evm_config.evm_with_env(&mut *db, self.evm_env.clone(), Default::default());
|
||||
|
||||
while let Some(tx) = best_txs.next(()) {
|
||||
// ensure we still have capacity for this transaction
|
||||
|
||||
Reference in New Issue
Block a user