chore(rpc): reth-eth-api crate (#8887)

Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
Emilia Hane
2024-06-27 13:37:52 +02:00
committed by GitHub
parent acc07537bc
commit 933a1dea39
109 changed files with 5433 additions and 4464 deletions

View File

@ -13,9 +13,17 @@
extern crate alloc;
use reth_chainspec::ChainSpec;
use reth_primitives::{revm::env::fill_block_env, Address, Header, TransactionSigned, U256};
use reth_primitives::{
revm::{
config::revm_spec,
env::{fill_block_env, fill_tx_env},
},
Address, Head, Header, TransactionSigned, U256,
};
use revm::{inspector_handle_register, Database, Evm, EvmBuilder, GetInspector};
use revm_primitives::{BlockEnv, CfgEnvWithHandlerCfg, EnvWithHandlerCfg, SpecId, TxEnv};
use revm_primitives::{
AnalysisKind, BlockEnv, CfgEnvWithHandlerCfg, EnvWithHandlerCfg, SpecId, TxEnv,
};
pub mod either;
pub mod execute;
@ -27,6 +35,7 @@ pub mod provider;
pub mod test_utils;
/// Trait for configuring the EVM for executing full blocks.
#[auto_impl::auto_impl(&, Arc)]
pub trait ConfigureEvm: ConfigureEvmEnv {
/// Associated type for the default external context that should be configured for the EVM.
type DefaultExternalContext<'a>;
@ -98,9 +107,14 @@ pub trait ConfigureEvm: ConfigureEvmEnv {
/// This represents the set of methods used to configure the EVM's environment before block
/// execution.
///
/// Default trait method implementation is done w.r.t. L1.
#[auto_impl::auto_impl(&, Arc)]
pub trait ConfigureEvmEnv: Send + Sync + Unpin + Clone + 'static {
/// Fill transaction environment from a [`TransactionSigned`] and the given sender address.
fn fill_tx_env(tx_env: &mut TxEnv, transaction: &TransactionSigned, sender: Address);
fn fill_tx_env(&self, tx_env: &mut TxEnv, transaction: &TransactionSigned, sender: Address) {
fill_tx_env(tx_env, transaction, sender)
}
/// Fill [`CfgEnvWithHandlerCfg`] fields according to the chain spec and given header
fn fill_cfg_env(
@ -108,7 +122,23 @@ pub trait ConfigureEvmEnv: Send + Sync + Unpin + Clone + 'static {
chain_spec: &ChainSpec,
header: &Header,
total_difficulty: U256,
);
) {
let spec_id = revm_spec(
chain_spec,
Head {
number: header.number,
timestamp: header.timestamp,
difficulty: header.difficulty,
total_difficulty,
hash: Default::default(),
},
);
cfg_env.chain_id = chain_spec.chain().id();
cfg_env.perf_analyse_created_bytecodes = AnalysisKind::Analyse;
cfg_env.handler_cfg.spec_id = spec_id;
}
/// Convenience function to call both [`fill_cfg_env`](ConfigureEvmEnv::fill_cfg_env) and
/// [`fill_block_env`].

View File

@ -6,13 +6,13 @@ use reth_storage_errors::provider::ProviderResult;
use revm::primitives::{BlockEnv, CfgEnv, CfgEnvWithHandlerCfg, SpecId};
/// A provider type that knows chain specific information required to configure a
/// [CfgEnvWithHandlerCfg].
/// [`CfgEnvWithHandlerCfg`].
///
/// This type is mainly used to provide required data to configure the EVM environment that is
/// usually stored on disk.
#[auto_impl::auto_impl(&, Arc)]
pub trait EvmEnvProvider: Send + Sync {
/// Fills the [CfgEnvWithHandlerCfg] and [BlockEnv] fields with values specific to the given
/// Fills the [`CfgEnvWithHandlerCfg`] and [BlockEnv] fields with values specific to the given
/// [BlockHashOrNumber].
fn fill_env_at<EvmConfig>(
&self,
@ -24,7 +24,7 @@ pub trait EvmEnvProvider: Send + Sync {
where
EvmConfig: ConfigureEvmEnv;
/// Fills the default [CfgEnvWithHandlerCfg] and [BlockEnv] fields with values specific to the
/// Fills the default [`CfgEnvWithHandlerCfg`] and [BlockEnv] fields with values specific to the
/// given [Header].
fn env_with_header<EvmConfig>(
&self,
@ -40,7 +40,7 @@ pub trait EvmEnvProvider: Send + Sync {
Ok((cfg, block_env))
}
/// Fills the [CfgEnvWithHandlerCfg] and [BlockEnv] fields with values specific to the given
/// Fills the [`CfgEnvWithHandlerCfg`] and [BlockEnv] fields with values specific to the given
/// [Header].
fn fill_env_with_header<EvmConfig>(
&self,
@ -66,7 +66,7 @@ pub trait EvmEnvProvider: Send + Sync {
header: &Header,
) -> ProviderResult<()>;
/// Fills the [CfgEnvWithHandlerCfg] fields with values specific to the given
/// Fills the [`CfgEnvWithHandlerCfg`] fields with values specific to the given
/// [BlockHashOrNumber].
fn fill_cfg_env_at<EvmConfig>(
&self,
@ -77,7 +77,7 @@ pub trait EvmEnvProvider: Send + Sync {
where
EvmConfig: ConfigureEvmEnv;
/// Fills the [CfgEnvWithHandlerCfg] fields with values specific to the given [Header].
/// Fills the [`CfgEnvWithHandlerCfg`] fields with values specific to the given [Header].
fn fill_cfg_env_with_header<EvmConfig>(
&self,
cfg: &mut CfgEnvWithHandlerCfg,