mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat: add Evm trait (#13823)
This commit is contained in:
@ -17,16 +17,14 @@ use alloy_rpc_types_eth::{
|
||||
};
|
||||
use futures::Future;
|
||||
use reth_chainspec::EthChainSpec;
|
||||
use reth_evm::{env::EvmEnv, ConfigureEvm, ConfigureEvmEnv};
|
||||
use reth_evm::{env::EvmEnv, ConfigureEvm, ConfigureEvmEnv, Evm};
|
||||
use reth_node_api::BlockBody;
|
||||
use reth_primitives_traits::SignedTransaction;
|
||||
use reth_provider::{BlockIdReader, ChainSpecProvider, ProviderHeader};
|
||||
use reth_revm::{
|
||||
database::StateProviderDatabase,
|
||||
db::CacheDB,
|
||||
primitives::{
|
||||
BlockEnv, CfgEnvWithHandlerCfg, EnvWithHandlerCfg, ExecutionResult, ResultAndState, TxEnv,
|
||||
},
|
||||
primitives::{BlockEnv, ExecutionResult, ResultAndState, TxEnv},
|
||||
DatabaseRef,
|
||||
};
|
||||
use reth_rpc_eth_types::{
|
||||
@ -41,7 +39,6 @@ use reth_rpc_eth_types::{
|
||||
};
|
||||
use revm::{Database, DatabaseCommit, GetInspector};
|
||||
use revm_inspectors::{access_list::AccessListInspector, transfer::TransferInspector};
|
||||
use revm_primitives::Env;
|
||||
use tracing::trace;
|
||||
|
||||
/// Result type for `eth_simulateV1` RPC method.
|
||||
@ -493,7 +490,7 @@ pub trait Call:
|
||||
f(StateProviderTraitObjWrapper(&state))
|
||||
}
|
||||
|
||||
/// Executes the [`EnvWithHandlerCfg`] against the given [Database] without committing state
|
||||
/// Executes the [`TxEnv`] against the given [Database] without committing state
|
||||
/// changes.
|
||||
fn transact<DB>(
|
||||
&self,
|
||||
@ -505,21 +502,14 @@ pub trait Call:
|
||||
DB: Database,
|
||||
EthApiError: From<DB::Error>,
|
||||
{
|
||||
let mut evm = self.evm_config().evm_with_env(db, evm_env, tx_env);
|
||||
let res = evm.transact().map_err(Self::Error::from_evm_err)?;
|
||||
let (_, env) = evm.into_db_and_env_with_handler_cfg();
|
||||
let mut evm = self.evm_config().evm_with_env(db, evm_env, Default::default());
|
||||
let res = evm.transact(tx_env.clone()).map_err(Self::Error::from_evm_err)?;
|
||||
let evm_env = evm.into_env();
|
||||
|
||||
let EnvWithHandlerCfg { env, handler_cfg } = env;
|
||||
let Env { cfg, block, tx } = *env;
|
||||
let evm_env = EvmEnv {
|
||||
cfg_env_with_handler_cfg: CfgEnvWithHandlerCfg { cfg_env: cfg, handler_cfg },
|
||||
block_env: block,
|
||||
};
|
||||
|
||||
Ok((res, (evm_env, tx)))
|
||||
Ok((res, (evm_env, tx_env)))
|
||||
}
|
||||
|
||||
/// Executes the [`EnvWithHandlerCfg`] against the given [Database] without committing state
|
||||
/// Executes the [`EvmEnv`] against the given [Database] without committing state
|
||||
/// changes.
|
||||
fn transact_with_inspector<DB>(
|
||||
&self,
|
||||
@ -532,18 +522,16 @@ pub trait Call:
|
||||
DB: Database,
|
||||
EthApiError: From<DB::Error>,
|
||||
{
|
||||
let mut evm = self.evm_config().evm_with_env_and_inspector(db, evm_env, tx_env, inspector);
|
||||
let res = evm.transact().map_err(Self::Error::from_evm_err)?;
|
||||
let (_, env) = evm.into_db_and_env_with_handler_cfg();
|
||||
let mut evm = self.evm_config().evm_with_env_and_inspector(
|
||||
db,
|
||||
evm_env,
|
||||
Default::default(),
|
||||
inspector,
|
||||
);
|
||||
let res = evm.transact(tx_env.clone()).map_err(Self::Error::from_evm_err)?;
|
||||
let evm_env = evm.into_env();
|
||||
|
||||
let EnvWithHandlerCfg { env, handler_cfg } = env;
|
||||
let Env { cfg, block, tx } = *env;
|
||||
let evm_env = EvmEnv {
|
||||
cfg_env_with_handler_cfg: CfgEnvWithHandlerCfg { cfg_env: cfg, handler_cfg },
|
||||
block_env: block,
|
||||
};
|
||||
|
||||
Ok((res, (evm_env, tx)))
|
||||
Ok((res, (evm_env, tx_env)))
|
||||
}
|
||||
|
||||
/// Executes the call request at the given [`BlockId`].
|
||||
@ -581,7 +569,7 @@ pub trait Call:
|
||||
/// Prepares the state and env for the given [`TransactionRequest`] at the given [`BlockId`] and
|
||||
/// executes the closure on a new task returning the result of the closure.
|
||||
///
|
||||
/// This returns the configured [`EnvWithHandlerCfg`] for the given [`TransactionRequest`] at
|
||||
/// This returns the configured [`EvmEnv`] for the given [`TransactionRequest`] at
|
||||
/// the given [`BlockId`] and with configured call settings: `prepare_call_env`.
|
||||
///
|
||||
/// This is primarily used by `eth_call`.
|
||||
@ -704,8 +692,8 @@ pub trait Call:
|
||||
break
|
||||
}
|
||||
|
||||
self.evm_config().fill_tx_env(evm.tx_mut(), tx, *sender);
|
||||
evm.transact_commit().map_err(Self::Error::from_evm_err)?;
|
||||
let tx_env = self.evm_config().tx_env(tx, *sender);
|
||||
evm.transact_commit(tx_env).map_err(Self::Error::from_evm_err)?;
|
||||
index += 1;
|
||||
}
|
||||
Ok(index)
|
||||
@ -790,7 +778,7 @@ pub trait Call:
|
||||
Ok(env)
|
||||
}
|
||||
|
||||
/// Prepares the [`EnvWithHandlerCfg`] for execution of calls.
|
||||
/// Prepares the [`EvmEnv`] for execution of calls.
|
||||
///
|
||||
/// Does not commit any changes to the underlying database.
|
||||
///
|
||||
|
||||
@ -13,7 +13,7 @@ use reth_chainspec::{EthChainSpec, EthereumHardforks};
|
||||
use reth_errors::RethError;
|
||||
use reth_evm::{
|
||||
env::EvmEnv, state_change::post_block_withdrawals_balance_increments,
|
||||
system_calls::SystemCaller, ConfigureEvm, ConfigureEvmEnv, NextBlockEnvAttributes,
|
||||
system_calls::SystemCaller, ConfigureEvm, ConfigureEvmEnv, Evm, NextBlockEnvAttributes,
|
||||
};
|
||||
use reth_primitives::{InvalidTransactionError, RecoveredBlock};
|
||||
use reth_primitives_traits::Receipt;
|
||||
@ -325,9 +325,10 @@ pub trait LoadPendingBlock:
|
||||
}
|
||||
|
||||
let tx_env = self.evm_config().tx_env(tx.tx(), tx.signer());
|
||||
let mut evm = self.evm_config().evm_with_env(&mut db, evm_env.clone(), tx_env);
|
||||
let mut evm =
|
||||
self.evm_config().evm_with_env(&mut db, evm_env.clone(), Default::default());
|
||||
|
||||
let ResultAndState { result, state } = match evm.transact() {
|
||||
let ResultAndState { result, state } = match evm.transact(tx_env) {
|
||||
Ok(res) => res,
|
||||
Err(err) => {
|
||||
match err {
|
||||
|
||||
@ -7,7 +7,7 @@ use alloy_primitives::B256;
|
||||
use alloy_rpc_types_eth::{BlockId, TransactionInfo};
|
||||
use futures::Future;
|
||||
use reth_chainspec::ChainSpecProvider;
|
||||
use reth_evm::{env::EvmEnv, system_calls::SystemCaller, ConfigureEvm, ConfigureEvmEnv};
|
||||
use reth_evm::{env::EvmEnv, system_calls::SystemCaller, ConfigureEvm, ConfigureEvmEnv, Evm};
|
||||
use reth_primitives::RecoveredBlock;
|
||||
use reth_primitives_traits::{BlockBody, SignedTransaction};
|
||||
use reth_provider::{BlockReader, ProviderBlock, ProviderHeader, ProviderTx};
|
||||
@ -18,9 +18,7 @@ use reth_rpc_eth_types::{
|
||||
};
|
||||
use revm::{db::CacheDB, Database, DatabaseCommit, GetInspector, Inspector};
|
||||
use revm_inspectors::tracing::{TracingInspector, TracingInspectorConfig};
|
||||
use revm_primitives::{
|
||||
CfgEnvWithHandlerCfg, Env, EnvWithHandlerCfg, EvmState, ExecutionResult, ResultAndState, TxEnv,
|
||||
};
|
||||
use revm_primitives::{EvmState, ExecutionResult, ResultAndState, TxEnv};
|
||||
use std::{fmt::Display, sync::Arc};
|
||||
|
||||
/// Executes CPU heavy tasks.
|
||||
@ -33,7 +31,7 @@ pub trait Trace:
|
||||
>,
|
||||
>
|
||||
{
|
||||
/// Executes the [`EnvWithHandlerCfg`] against the given [Database] without committing state
|
||||
/// Executes the [`EvmEnv`] against the given [Database] without committing state
|
||||
/// changes.
|
||||
fn inspect<DB, I>(
|
||||
&self,
|
||||
@ -47,23 +45,22 @@ pub trait Trace:
|
||||
EthApiError: From<DB::Error>,
|
||||
I: GetInspector<DB>,
|
||||
{
|
||||
let mut evm = self.evm_config().evm_with_env_and_inspector(db, evm_env, tx_env, inspector);
|
||||
let res = evm.transact().map_err(Self::Error::from_evm_err)?;
|
||||
let (_, env) = evm.into_db_and_env_with_handler_cfg();
|
||||
let EnvWithHandlerCfg { env, handler_cfg } = env;
|
||||
let Env { cfg, block, tx } = *env;
|
||||
let evm_env = EvmEnv {
|
||||
cfg_env_with_handler_cfg: CfgEnvWithHandlerCfg { cfg_env: cfg, handler_cfg },
|
||||
block_env: block,
|
||||
};
|
||||
Ok((res, (evm_env, tx)))
|
||||
let mut evm = self.evm_config().evm_with_env_and_inspector(
|
||||
db,
|
||||
evm_env,
|
||||
Default::default(),
|
||||
inspector,
|
||||
);
|
||||
let res = evm.transact(tx_env.clone()).map_err(Self::Error::from_evm_err)?;
|
||||
let evm_env = evm.into_env();
|
||||
Ok((res, (evm_env, tx_env)))
|
||||
}
|
||||
|
||||
/// Executes the transaction on top of the given [`BlockId`] with a tracer configured by the
|
||||
/// config.
|
||||
///
|
||||
/// The callback is then called with the [`TracingInspector`] and the [`ResultAndState`] after
|
||||
/// the configured [`EnvWithHandlerCfg`] was inspected.
|
||||
/// the configured [`EvmEnv`] was inspected.
|
||||
///
|
||||
/// Caution: this is blocking
|
||||
fn trace_at<F, R>(
|
||||
@ -92,7 +89,7 @@ pub trait Trace:
|
||||
/// config.
|
||||
///
|
||||
/// The callback is then called with the [`TracingInspector`] and the [`ResultAndState`] after
|
||||
/// the configured [`EnvWithHandlerCfg`] was inspected.
|
||||
/// the configured [`EvmEnv`] was inspected.
|
||||
fn spawn_trace_at_with_state<F, R>(
|
||||
&self,
|
||||
evm_env: EvmEnv,
|
||||
|
||||
Reference in New Issue
Block a user