feat: add Spec generic for EvmEnv (#13975)

This commit is contained in:
Arsenii Kulikov
2025-01-24 19:59:55 +04:00
committed by GitHub
parent 621b30f037
commit 203fed0f64
19 changed files with 223 additions and 293 deletions

View File

@ -15,7 +15,7 @@ use reth::{
handler::register::EvmHandler,
inspector_handle_register,
precompile::{Precompile, PrecompileOutput, PrecompileSpecId},
primitives::{Env, PrecompileResult, TxEnv},
primitives::{CfgEnvWithHandlerCfg, Env, HandlerCfg, PrecompileResult, SpecId, TxEnv},
ContextPrecompiles, Database, EvmBuilder, GetInspector,
},
rpc::types::engine::PayloadAttributes,
@ -88,6 +88,7 @@ impl ConfigureEvmEnv for MyEvmConfig {
type Transaction = TransactionSigned;
type Error = Infallible;
type TxEnv = TxEnv;
type Spec = SpecId;
fn tx_env(&self, transaction: &Self::Transaction, signer: Address) -> Self::TxEnv {
self.inner.tx_env(transaction, signer)
@ -110,9 +111,13 @@ impl ConfigureEvm for MyEvmConfig {
type Evm<'a, DB: Database + 'a, I: 'a> = EthEvm<'a, I, DB>;
fn evm_with_env<DB: Database>(&self, db: DB, evm_env: EvmEnv) -> Self::Evm<'_, DB, ()> {
let cfg_env_with_handler_cfg = CfgEnvWithHandlerCfg {
cfg_env: evm_env.cfg_env,
handler_cfg: HandlerCfg::new(evm_env.spec),
};
EvmBuilder::default()
.with_db(db)
.with_cfg_env_with_handler_cfg(evm_env.cfg_env_with_handler_cfg)
.with_cfg_env_with_handler_cfg(cfg_env_with_handler_cfg)
.with_block_env(evm_env.block_env)
// add additional precompiles
.append_handler_register(MyEvmConfig::set_precompiles)
@ -130,10 +135,15 @@ impl ConfigureEvm for MyEvmConfig {
DB: Database,
I: GetInspector<DB>,
{
let cfg_env_with_handler_cfg = CfgEnvWithHandlerCfg {
cfg_env: evm_env.cfg_env,
handler_cfg: HandlerCfg::new(evm_env.spec),
};
EvmBuilder::default()
.with_db(db)
.with_external_context(inspector)
.with_cfg_env_with_handler_cfg(evm_env.cfg_env_with_handler_cfg)
.with_cfg_env_with_handler_cfg(cfg_env_with_handler_cfg)
.with_block_env(evm_env.block_env)
// add additional precompiles
.append_handler_register(MyEvmConfig::set_precompiles)

View File

@ -30,7 +30,7 @@ use reth::{
};
use reth_evm::EvmEnv;
use reth_node_ethereum::node::EthereumNode;
use revm_primitives::CfgEnvWithHandlerCfg;
use revm_primitives::HandlerCfg;
fn main() {
Cli::<EthereumChainSpecParser, RethCliTxpoolExt>::parse()
@ -65,13 +65,9 @@ fn main() {
BlockNumberOrTag::Latest.into(),
EvmOverrides::default(),
move |db, evm_env, tx_env| {
let EvmEnv {
cfg_env_with_handler_cfg:
CfgEnvWithHandlerCfg { handler_cfg, cfg_env },
block_env,
} = evm_env;
let EvmEnv { cfg_env, block_env, spec } = evm_env;
let env = EnvWithHandlerCfg {
handler_cfg,
handler_cfg: HandlerCfg::new(spec),
env: Env::boxed(cfg_env, block_env, tx_env),
};
let mut dummy_inspector = DummyInspector::default();

View File

@ -13,7 +13,10 @@ use reth::{
handler::register::EvmHandler,
inspector_handle_register,
precompile::{Precompile, PrecompileSpecId},
primitives::{Env, PrecompileResult, SpecId, StatefulPrecompileMut, TxEnv},
primitives::{
CfgEnvWithHandlerCfg, Env, HandlerCfg, PrecompileResult, SpecId, StatefulPrecompileMut,
TxEnv,
},
ContextPrecompile, ContextPrecompiles, Database, EvmBuilder, GetInspector,
},
tasks::TaskManager,
@ -149,6 +152,7 @@ impl ConfigureEvmEnv for MyEvmConfig {
type Transaction = TransactionSigned;
type Error = Infallible;
type TxEnv = TxEnv;
type Spec = SpecId;
fn tx_env(&self, transaction: &Self::Transaction, signer: Address) -> Self::TxEnv {
self.inner.tx_env(transaction, signer)
@ -171,10 +175,15 @@ impl ConfigureEvm for MyEvmConfig {
type Evm<'a, DB: Database + 'a, I: 'a> = EthEvm<'a, I, DB>;
fn evm_with_env<DB: Database>(&self, db: DB, evm_env: EvmEnv) -> Self::Evm<'_, DB, ()> {
let cfg_env_with_handler_cfg = CfgEnvWithHandlerCfg {
cfg_env: evm_env.cfg_env,
handler_cfg: HandlerCfg::new(evm_env.spec),
};
let new_cache = self.precompile_cache.clone();
EvmBuilder::default()
.with_db(db)
.with_cfg_env_with_handler_cfg(evm_env.cfg_env_with_handler_cfg)
.with_cfg_env_with_handler_cfg(cfg_env_with_handler_cfg)
.with_block_env(evm_env.block_env)
// add additional precompiles
.append_handler_register_box(Box::new(move |handler| {
@ -194,11 +203,15 @@ impl ConfigureEvm for MyEvmConfig {
DB: Database,
I: GetInspector<DB>,
{
let cfg_env_with_handler_cfg = CfgEnvWithHandlerCfg {
cfg_env: evm_env.cfg_env,
handler_cfg: HandlerCfg::new(evm_env.spec),
};
let new_cache = self.precompile_cache.clone();
EvmBuilder::default()
.with_db(db)
.with_external_context(inspector)
.with_cfg_env_with_handler_cfg(evm_env.cfg_env_with_handler_cfg)
.with_cfg_env_with_handler_cfg(cfg_env_with_handler_cfg)
.with_block_env(evm_env.block_env)
// add additional precompiles
.append_handler_register_box(Box::new(move |handler| {