mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat: add reth-evm crate (#7397)
This commit is contained in:
18
crates/evm/Cargo.toml
Normal file
18
crates/evm/Cargo.toml
Normal file
@ -0,0 +1,18 @@
|
||||
[package]
|
||||
name = "reth-evm"
|
||||
version.workspace = true
|
||||
edition.workspace = true
|
||||
rust-version.workspace = true
|
||||
license.workspace = true
|
||||
homepage.workspace = true
|
||||
repository.workspace = true
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
||||
[dependencies]
|
||||
# reth
|
||||
reth-primitives.workspace = true
|
||||
revm-primitives.workspace = true
|
||||
revm.workspace = true
|
||||
|
||||
72
crates/evm/src/lib.rs
Normal file
72
crates/evm/src/lib.rs
Normal file
@ -0,0 +1,72 @@
|
||||
//! Traits for configuring an EVM specifics.
|
||||
|
||||
#![doc(
|
||||
html_logo_url = "https://raw.githubusercontent.com/paradigmxyz/reth/main/assets/reth-docs.png",
|
||||
html_favicon_url = "https://avatars0.githubusercontent.com/u/97369466?s=256",
|
||||
issue_tracker_base_url = "https://github.com/paradigmxyz/reth/issues/"
|
||||
)]
|
||||
#![cfg_attr(not(test), warn(unused_crate_dependencies))]
|
||||
#![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_primitives::{BlockEnv, CfgEnvWithHandlerCfg, SpecId, TxEnv};
|
||||
|
||||
/// Trait for configuring the EVM for executing full blocks.
|
||||
pub trait ConfigureEvm: ConfigureEvmEnv {
|
||||
/// Returns new EVM with the given database
|
||||
///
|
||||
/// 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<'a, DB: Database + 'a>(&self, db: DB) -> Evm<'a, (), DB> {
|
||||
EvmBuilder::default().with_db(db).build()
|
||||
}
|
||||
|
||||
/// Returns a new EVM with the given inspector.
|
||||
///
|
||||
/// 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()
|
||||
}
|
||||
}
|
||||
|
||||
/// This represents the set of methods used to configure the EVM's environment before block
|
||||
/// execution.
|
||||
pub trait ConfigureEvmEnv: Send + Sync + Unpin + Clone {
|
||||
/// The type of the transaction metadata that should be used to fill fields in the transaction
|
||||
/// environment.
|
||||
///
|
||||
/// On ethereum mainnet, this is `()`, and on optimism these are the L1 fee fields and
|
||||
/// additional L1 block info.
|
||||
type TxMeta;
|
||||
|
||||
/// Fill transaction environment from a [Transaction] and the given sender address.
|
||||
fn fill_tx_env<T>(tx_env: &mut TxEnv, transaction: T, sender: Address, meta: Self::TxMeta)
|
||||
where
|
||||
T: AsRef<Transaction>;
|
||||
|
||||
/// Fill [CfgEnvWithHandlerCfg] fields according to the chain spec and given header
|
||||
fn fill_cfg_env(
|
||||
cfg_env: &mut CfgEnvWithHandlerCfg,
|
||||
chain_spec: &ChainSpec,
|
||||
header: &Header,
|
||||
total_difficulty: U256,
|
||||
);
|
||||
|
||||
/// Convenience function to call both [fill_cfg_env](ConfigureEvmEnv::fill_cfg_env) and
|
||||
/// [fill_block_env].
|
||||
fn fill_cfg_and_block_env(
|
||||
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);
|
||||
let after_merge = cfg.handler_cfg.spec_id >= SpecId::MERGE;
|
||||
fill_block_env(block_env, chain_spec, header, after_merge);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user