feat: integrate evm in rpc (#7470)

This commit is contained in:
Matthias Seitz
2024-04-05 09:26:11 +02:00
committed by GitHub
parent fa4c663239
commit e20c524452
9 changed files with 51 additions and 37 deletions

View File

@ -9,7 +9,7 @@
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
use reth_primitives::{revm::env::fill_block_env, Address, ChainSpec, Header, Transaction, U256};
use revm::{Database, Evm, EvmBuilder};
use revm::{inspector_handle_register, Database, Evm, EvmBuilder, GetInspector};
use revm_primitives::{BlockEnv, CfgEnvWithHandlerCfg, EnvWithHandlerCfg, SpecId, TxEnv};
/// Trait for configuring the EVM for executing full blocks.
@ -42,12 +42,16 @@ pub trait ConfigureEvm: ConfigureEvmEnv {
/// including the spec id.
///
/// This will preserve any handler modifications
fn evm_with_env_and_inspector<'a, DB: Database + 'a, I>(
fn evm_with_env_and_inspector<'a, DB, I>(
&self,
db: DB,
env: EnvWithHandlerCfg,
inspector: I,
) -> Evm<'a, I, DB> {
) -> Evm<'a, I, DB>
where
DB: Database + 'a,
I: GetInspector<DB>,
{
let mut evm = self.evm_with_inspector(db, inspector);
evm.modify_spec_id(env.spec_id());
evm.context.evm.env = env.env;
@ -59,8 +63,16 @@ pub trait ConfigureEvm: ConfigureEvmEnv {
/// Caution: This does not automatically configure the EVM with [ConfigureEvmEnv] methods. It is
/// up to the caller to call an appropriate method to fill the transaction and block
/// environment before executing any transactions using the provided EVM.
fn evm_with_inspector<'a, DB: Database + 'a, I>(&self, db: DB, inspector: I) -> Evm<'a, I, DB> {
EvmBuilder::default().with_db(db).with_external_context(inspector).build()
fn evm_with_inspector<'a, DB, I>(&self, db: DB, inspector: I) -> Evm<'a, I, DB>
where
DB: Database + 'a,
I: GetInspector<DB>,
{
EvmBuilder::default()
.with_db(db)
.with_external_context(inspector)
.append_handler_register(inspector_handle_register)
.build()
}
}