Revert "feat(evm): use RethEvmBuilder inside ConfigureEvm" (#9805)

This commit is contained in:
Matthias Seitz
2024-07-25 17:40:05 +02:00
committed by GitHub
parent c1b5410867
commit abdbc44c9b
6 changed files with 21 additions and 27 deletions

View File

@ -116,8 +116,6 @@ impl ConfigureEvm for EthEvmConfig {
) -> reth_revm::Evm<'_, Self::DefaultExternalContext<'_>, DB> { ) -> reth_revm::Evm<'_, Self::DefaultExternalContext<'_>, DB> {
EvmBuilder::default().with_db(db).build() EvmBuilder::default().with_db(db).build()
} }
fn default_external_context<'a>(&self) -> Self::DefaultExternalContext<'a> {}
} }
#[cfg(test)] #[cfg(test)]

View File

@ -1,7 +1,7 @@
//! Builder for creating an EVM with a database and environment. //! Builder for creating an EVM with a database and environment.
use revm::{inspector_handle_register, Database, Evm, EvmBuilder, GetInspector}; use revm::{inspector_handle_register, Database, Evm, EvmBuilder, GetInspector};
use revm_primitives::EnvWithHandlerCfg; use revm_primitives::{Env, EnvWithHandlerCfg};
/// Builder for creating an EVM with a database and environment. /// Builder for creating an EVM with a database and environment.
/// ///
@ -14,7 +14,7 @@ pub struct RethEvmBuilder<DB: Database, EXT = ()> {
/// The database to use for the EVM. /// The database to use for the EVM.
db: DB, db: DB,
/// The environment to use for the EVM. /// The environment to use for the EVM.
env: Option<Box<EnvWithHandlerCfg>>, env: Option<Box<Env>>,
/// The external context for the EVM. /// The external context for the EVM.
external_context: EXT, external_context: EXT,
} }
@ -29,7 +29,7 @@ where
} }
/// Set the environment for the EVM. /// Set the environment for the EVM.
pub fn with_env(mut self, env: Box<EnvWithHandlerCfg>) -> Self { pub fn with_env(mut self, env: Box<Env>) -> Self {
self.env = Some(env); self.env = Some(env);
self self
} }
@ -44,8 +44,7 @@ where
let mut builder = let mut builder =
EvmBuilder::default().with_db(self.db).with_external_context(self.external_context); EvmBuilder::default().with_db(self.db).with_external_context(self.external_context);
if let Some(env) = self.env { if let Some(env) = self.env {
builder = builder.with_spec_id(env.clone().spec_id()); builder = builder.with_env(env);
builder = builder.with_env(env.env);
} }
builder.build() builder.build()
@ -60,8 +59,7 @@ where
let mut builder = let mut builder =
EvmBuilder::default().with_db(self.db).with_external_context(self.external_context); EvmBuilder::default().with_db(self.db).with_external_context(self.external_context);
if let Some(env) = self.env { if let Some(env) = self.env {
builder = builder.with_spec_id(env.clone().spec_id()); builder = builder.with_env(env);
builder = builder.with_env(env.env);
} }
builder builder
.with_external_context(inspector) .with_external_context(inspector)
@ -105,7 +103,7 @@ pub trait EvmFactory {
db: DB, db: DB,
env: EnvWithHandlerCfg, env: EnvWithHandlerCfg,
) -> Evm<'a, Self::DefaultExternalContext<'a>, DB> { ) -> Evm<'a, Self::DefaultExternalContext<'a>, DB> {
RethEvmBuilder::new(db, self.default_external_context()).with_env(env.into()).build() RethEvmBuilder::new(db, self.default_external_context()).with_env(env.env).build()
} }
/// Returns a new EVM with the given database configured with the given environment settings, /// Returns a new EVM with the given database configured with the given environment settings,
@ -125,7 +123,7 @@ pub trait EvmFactory {
I: GetInspector<DB>, I: GetInspector<DB>,
{ {
RethEvmBuilder::new(db, self.default_external_context()) RethEvmBuilder::new(db, self.default_external_context())
.with_env(env.into()) .with_env(env.env)
.build_with_inspector(inspector) .build_with_inspector(inspector)
} }

View File

@ -14,10 +14,9 @@ extern crate alloc;
use core::ops::Deref; use core::ops::Deref;
use crate::builder::RethEvmBuilder;
use reth_chainspec::ChainSpec; use reth_chainspec::ChainSpec;
use reth_primitives::{Address, Header, TransactionSigned, TransactionSignedEcRecovered, U256}; use reth_primitives::{Address, Header, TransactionSigned, TransactionSignedEcRecovered, U256};
use revm::{Database, Evm, GetInspector}; use revm::{inspector_handle_register, Database, Evm, EvmBuilder, GetInspector};
use revm_primitives::{ use revm_primitives::{
BlockEnv, Bytes, CfgEnvWithHandlerCfg, Env, EnvWithHandlerCfg, SpecId, TxEnv, BlockEnv, Bytes, CfgEnvWithHandlerCfg, Env, EnvWithHandlerCfg, SpecId, TxEnv,
}; };
@ -55,7 +54,10 @@ pub trait ConfigureEvm: ConfigureEvmEnv {
db: DB, db: DB,
env: EnvWithHandlerCfg, env: EnvWithHandlerCfg,
) -> Evm<'_, Self::DefaultExternalContext<'_>, DB> { ) -> Evm<'_, Self::DefaultExternalContext<'_>, DB> {
RethEvmBuilder::new(db, self.default_external_context()).with_env(env.into()).build() let mut evm = self.evm(db);
evm.modify_spec_id(env.spec_id());
evm.context.evm.env = env.env;
evm
} }
/// Returns a new EVM with the given database configured with the given environment settings, /// Returns a new EVM with the given database configured with the given environment settings,
@ -74,9 +76,10 @@ pub trait ConfigureEvm: ConfigureEvmEnv {
DB: Database, DB: Database,
I: GetInspector<DB>, I: GetInspector<DB>,
{ {
RethEvmBuilder::new(db, self.default_external_context()) let mut evm = self.evm_with_inspector(db, inspector);
.with_env(env.into()) evm.modify_spec_id(env.spec_id());
.build_with_inspector(inspector) evm.context.evm.env = env.env;
evm
} }
/// Returns a new EVM with the given inspector. /// Returns a new EVM with the given inspector.
@ -89,11 +92,12 @@ pub trait ConfigureEvm: ConfigureEvmEnv {
DB: Database, DB: Database,
I: GetInspector<DB>, I: GetInspector<DB>,
{ {
RethEvmBuilder::new(db, self.default_external_context()).build_with_inspector(inspector) EvmBuilder::default()
.with_db(db)
.with_external_context(inspector)
.append_handler_register(inspector_handle_register)
.build()
} }
/// Provides the default external context.
fn default_external_context<'a>(&self) -> Self::DefaultExternalContext<'a>;
} }
/// This represents the set of methods used to configure the EVM's environment before block /// This represents the set of methods used to configure the EVM's environment before block

View File

@ -129,8 +129,6 @@ impl ConfigureEvm for OptimismEvmConfig {
.append_handler_register(inspector_handle_register) .append_handler_register(inspector_handle_register)
.build() .build()
} }
fn default_external_context<'a>(&self) -> Self::DefaultExternalContext<'a> {}
} }
#[cfg(test)] #[cfg(test)]

View File

@ -130,8 +130,6 @@ impl ConfigureEvm for MyEvmConfig {
.append_handler_register(inspector_handle_register) .append_handler_register(inspector_handle_register)
.build() .build()
} }
fn default_external_context<'a>(&self) -> Self::DefaultExternalContext<'a> {}
} }
/// Builds a regular ethereum block executor that uses the custom EVM. /// Builds a regular ethereum block executor that uses the custom EVM.

View File

@ -193,8 +193,6 @@ impl ConfigureEvm for MyEvmConfig {
.append_handler_register(inspector_handle_register) .append_handler_register(inspector_handle_register)
.build() .build()
} }
fn default_external_context<'a>(&self) -> Self::DefaultExternalContext<'a> {}
} }
/// Builds a regular ethereum block executor that uses the custom EVM. /// Builds a regular ethereum block executor that uses the custom EVM.