diff --git a/crates/ethereum/evm/src/execute.rs b/crates/ethereum/evm/src/execute.rs index 149fbc9557b9..e4c89dd778dd 100644 --- a/crates/ethereum/evm/src/execute.rs +++ b/crates/ethereum/evm/src/execute.rs @@ -4,6 +4,8 @@ use crate::{ dao_fork::{DAO_HARDFORK_BENEFICIARY, DAO_HARDKFORK_ACCOUNTS}, EthEvmConfig, }; +#[cfg(not(feature = "std"))] +use alloc::{sync::Arc, vec, vec::Vec}; use reth_chainspec::{ChainSpec, MAINNET}; use reth_ethereum_consensus::validate_block_post_execution; use reth_evm::{ @@ -29,15 +31,11 @@ use reth_revm::{ }; use revm_primitives::{ db::{Database, DatabaseCommit}, - BlockEnv, CfgEnvWithHandlerCfg, EnvWithHandlerCfg, ResultAndState, + BlockEnv, CfgEnvWithHandlerCfg, EVMError, EnvWithHandlerCfg, ResultAndState, }; -#[cfg(not(feature = "std"))] -use alloc::{sync::Arc, vec, vec::Vec}; - #[cfg(feature = "std")] -use std::sync::Arc; - +use std::{fmt::Display, sync::Arc}; /// Provides executors to execute regular ethereum blocks #[derive(Debug, Clone)] pub struct EthExecutorProvider { @@ -70,7 +68,7 @@ where { fn eth_executor(&self, db: DB) -> EthBlockExecutor where - DB: Database, + DB: Database>, { EthBlockExecutor::new( self.chain_spec.clone(), @@ -84,20 +82,22 @@ impl BlockExecutorProvider for EthExecutorProvider where EvmConfig: ConfigureEvm, { - type Executor> = EthBlockExecutor; + type Executor + Display>> = + EthBlockExecutor; - type BatchExecutor> = EthBatchExecutor; + type BatchExecutor + Display>> = + EthBatchExecutor; fn executor(&self, db: DB) -> Self::Executor where - DB: Database, + DB: Database + Display>, { self.eth_executor(db) } fn batch_executor(&self, db: DB, prune_modes: PruneModes) -> Self::BatchExecutor where - DB: Database, + DB: Database + Display>, { let executor = self.eth_executor(db); EthBatchExecutor { @@ -145,7 +145,8 @@ where mut evm: Evm<'_, Ext, &mut State>, ) -> Result where - DB: Database, + DB: Database, + DB::Error: Into + std::fmt::Display, { // apply pre execution changes apply_beacon_root_contract_call( @@ -182,10 +183,17 @@ where // Execute transaction. let ResultAndState { result, state } = evm.transact().map_err(move |err| { + let new_err = match err { + EVMError::Transaction(e) => EVMError::Transaction(e), + EVMError::Header(e) => EVMError::Header(e), + EVMError::Database(e) => EVMError::Database(e.into()), + EVMError::Custom(e) => EVMError::Custom(e), + EVMError::Precompile(e) => EVMError::Precompile(e), + }; // Ensure hash is calculated for error log, if not already done BlockValidationError::EVM { hash: transaction.recalculate_hash(), - error: err.into(), + error: Box::new(new_err), } })?; evm.db_mut().commit(state); @@ -260,7 +268,7 @@ impl EthBlockExecutor { impl EthBlockExecutor where EvmConfig: ConfigureEvm, - DB: Database, + DB: Database + Display>, { /// Configures a new evm configuration and block environment for the given block. /// @@ -358,7 +366,7 @@ where impl Executor for EthBlockExecutor where EvmConfig: ConfigureEvm, - DB: Database, + DB: Database + std::fmt::Display>, { type Input<'a> = BlockExecutionInput<'a, BlockWithSenders>; type Output = BlockExecutionOutput; @@ -408,7 +416,7 @@ impl EthBatchExecutor { impl BatchExecutor for EthBatchExecutor where EvmConfig: ConfigureEvm, - DB: Database, + DB: Database + Display>, { type Input<'a> = BlockExecutionInput<'a, BlockWithSenders>; type Output = ExecutionOutcome; diff --git a/crates/evm/src/either.rs b/crates/evm/src/either.rs index 2c8edfd29265..2f55f1668923 100644 --- a/crates/evm/src/either.rs +++ b/crates/evm/src/either.rs @@ -1,5 +1,7 @@ //! Helper type that represents one of two possible executor types +use std::fmt::Display; + use crate::execute::{ BatchExecutor, BlockExecutionInput, BlockExecutionOutput, BlockExecutorProvider, Executor, }; @@ -18,13 +20,15 @@ where A: BlockExecutorProvider, B: BlockExecutorProvider, { - type Executor> = Either, B::Executor>; - type BatchExecutor> = + type Executor + Display>> = + Either, B::Executor>; + + type BatchExecutor + Display>> = Either, B::BatchExecutor>; fn executor(&self, db: DB) -> Self::Executor where - DB: Database, + DB: Database + Display>, { match self { Self::Left(a) => Either::Left(a.executor(db)), @@ -34,7 +38,7 @@ where fn batch_executor(&self, db: DB, prune_modes: PruneModes) -> Self::BatchExecutor where - DB: Database, + DB: Database + Display>, { match self { Self::Left(a) => Either::Left(a.batch_executor(db, prune_modes)), @@ -57,7 +61,7 @@ where Output = BlockExecutionOutput, Error = BlockExecutionError, >, - DB: Database, + DB: Database + Display>, { type Input<'a> = BlockExecutionInput<'a, BlockWithSenders>; type Output = BlockExecutionOutput; @@ -85,7 +89,7 @@ where Output = ExecutionOutcome, Error = BlockExecutionError, >, - DB: Database, + DB: Database + Display>, { type Input<'a> = BlockExecutionInput<'a, BlockWithSenders>; type Output = ExecutionOutcome; diff --git a/crates/evm/src/execute.rs b/crates/evm/src/execute.rs index ea8b7abb0779..6d076fd45303 100644 --- a/crates/evm/src/execute.rs +++ b/crates/evm/src/execute.rs @@ -5,6 +5,7 @@ use reth_primitives::{BlockNumber, BlockWithSenders, Receipt, Request, U256}; use reth_prune_types::PruneModes; use revm::db::BundleState; use revm_primitives::db::Database; +use std::fmt::Display; #[cfg(not(feature = "std"))] use alloc::vec::Vec; @@ -142,7 +143,7 @@ pub trait BlockExecutorProvider: Send + Sync + Clone + Unpin + 'static { /// /// It is not expected to validate the state trie root, this must be done by the caller using /// the returned state. - type Executor>: for<'a> Executor< + type Executor + Display>>: for<'a> Executor< DB, Input<'a> = BlockExecutionInput<'a, BlockWithSenders>, Output = BlockExecutionOutput, @@ -150,7 +151,7 @@ pub trait BlockExecutorProvider: Send + Sync + Clone + Unpin + 'static { >; /// An executor that can execute a batch of blocks given a database. - type BatchExecutor>: for<'a> BatchExecutor< + type BatchExecutor + Display>>: for<'a> BatchExecutor< DB, Input<'a> = BlockExecutionInput<'a, BlockWithSenders>, Output = ExecutionOutcome, @@ -162,7 +163,7 @@ pub trait BlockExecutorProvider: Send + Sync + Clone + Unpin + 'static { /// This is used to execute a single block and get the changed state. fn executor(&self, db: DB) -> Self::Executor where - DB: Database; + DB: Database + Display>; /// Creates a new batch executor with the given database and pruning modes. /// @@ -173,7 +174,7 @@ pub trait BlockExecutorProvider: Send + Sync + Clone + Unpin + 'static { /// execution. fn batch_executor(&self, db: DB, prune_modes: PruneModes) -> Self::BatchExecutor where - DB: Database; + DB: Database + Display>; } #[cfg(test)] @@ -187,19 +188,19 @@ mod tests { struct TestExecutorProvider; impl BlockExecutorProvider for TestExecutorProvider { - type Executor> = TestExecutor; - type BatchExecutor> = TestExecutor; + type Executor + Display>> = TestExecutor; + type BatchExecutor + Display>> = TestExecutor; fn executor(&self, _db: DB) -> Self::Executor where - DB: Database, + DB: Database + Display>, { TestExecutor(PhantomData) } fn batch_executor(&self, _db: DB, _prune_modes: PruneModes) -> Self::BatchExecutor where - DB: Database, + DB: Database + Display>, { TestExecutor(PhantomData) } diff --git a/crates/evm/src/noop.rs b/crates/evm/src/noop.rs index fdee35239369..d393f66d566d 100644 --- a/crates/evm/src/noop.rs +++ b/crates/evm/src/noop.rs @@ -1,5 +1,7 @@ //! A no operation block executor implementation. +use std::fmt::Display; + use reth_execution_errors::BlockExecutionError; use reth_execution_types::ExecutionOutcome; use reth_primitives::{BlockNumber, BlockWithSenders, Receipt}; @@ -19,20 +21,20 @@ const UNAVAILABLE_FOR_NOOP: &str = "execution unavailable for noop"; pub struct NoopBlockExecutorProvider; impl BlockExecutorProvider for NoopBlockExecutorProvider { - type Executor> = Self; + type Executor + Display>> = Self; - type BatchExecutor> = Self; + type BatchExecutor + Display>> = Self; fn executor(&self, _: DB) -> Self::Executor where - DB: Database, + DB: Database + Display>, { Self } fn batch_executor(&self, _: DB, _: PruneModes) -> Self::BatchExecutor where - DB: Database, + DB: Database + Display>, { Self } diff --git a/crates/evm/src/test_utils.rs b/crates/evm/src/test_utils.rs index c9627933a7fc..a4d098f0b3aa 100644 --- a/crates/evm/src/test_utils.rs +++ b/crates/evm/src/test_utils.rs @@ -10,7 +10,7 @@ use reth_primitives::{BlockNumber, BlockWithSenders, Receipt}; use reth_prune_types::PruneModes; use reth_storage_errors::provider::ProviderError; use revm_primitives::db::Database; -use std::sync::Arc; +use std::{fmt::Display, sync::Arc}; /// A [`BlockExecutorProvider`] that returns mocked execution results. #[derive(Clone, Debug, Default)] @@ -26,20 +26,20 @@ impl MockExecutorProvider { } impl BlockExecutorProvider for MockExecutorProvider { - type Executor> = Self; + type Executor + Display>> = Self; - type BatchExecutor> = Self; + type BatchExecutor + Display>> = Self; fn executor(&self, _: DB) -> Self::Executor where - DB: Database, + DB: Database + Display>, { self.clone() } fn batch_executor(&self, _: DB, _: PruneModes) -> Self::BatchExecutor where - DB: Database, + DB: Database + Display>, { self.clone() } diff --git a/crates/optimism/evm/src/execute.rs b/crates/optimism/evm/src/execute.rs index e6130295f455..12edb225fe43 100644 --- a/crates/optimism/evm/src/execute.rs +++ b/crates/optimism/evm/src/execute.rs @@ -23,7 +23,7 @@ use reth_revm::{ }; use revm_primitives::{ db::{Database, DatabaseCommit}, - BlockEnv, CfgEnvWithHandlerCfg, EnvWithHandlerCfg, ResultAndState, + BlockEnv, CfgEnvWithHandlerCfg, EVMError, EnvWithHandlerCfg, ResultAndState, }; use std::sync::Arc; use tracing::trace; @@ -55,7 +55,7 @@ where { fn op_executor(&self, db: DB) -> OpBlockExecutor where - DB: Database, + DB: Database + std::fmt::Display>, { OpBlockExecutor::new( self.chain_spec.clone(), @@ -69,19 +69,21 @@ impl BlockExecutorProvider for OpExecutorProvider where EvmConfig: ConfigureEvm, { - type Executor> = OpBlockExecutor; + type Executor + std::fmt::Display>> = + OpBlockExecutor; - type BatchExecutor> = OpBatchExecutor; + type BatchExecutor + std::fmt::Display>> = + OpBatchExecutor; fn executor(&self, db: DB) -> Self::Executor where - DB: Database, + DB: Database + std::fmt::Display>, { self.op_executor(db) } fn batch_executor(&self, db: DB, prune_modes: PruneModes) -> Self::BatchExecutor where - DB: Database, + DB: Database + std::fmt::Display>, { let executor = self.op_executor(db); OpBatchExecutor { @@ -118,7 +120,7 @@ where mut evm: Evm<'_, Ext, &mut State>, ) -> Result<(Vec, u64), BlockExecutionError> where - DB: Database, + DB: Database + std::fmt::Display>, { // apply pre execution changes apply_beacon_root_contract_call( @@ -179,10 +181,17 @@ where // Execute transaction. let ResultAndState { result, state } = evm.transact().map_err(move |err| { + let new_err = match err { + EVMError::Transaction(e) => EVMError::Transaction(e), + EVMError::Header(e) => EVMError::Header(e), + EVMError::Database(e) => EVMError::Database(e.into()), + EVMError::Custom(e) => EVMError::Custom(e), + EVMError::Precompile(e) => EVMError::Precompile(e), + }; // Ensure hash is calculated for error log, if not already done BlockValidationError::EVM { hash: transaction.recalculate_hash(), - error: err.into(), + error: Box::new(new_err), } })?; @@ -255,7 +264,7 @@ impl OpBlockExecutor { impl OpBlockExecutor where EvmConfig: ConfigureEvm, - DB: Database, + DB: Database + std::fmt::Display>, { /// Configures a new evm configuration and block environment for the given block. /// @@ -337,7 +346,7 @@ where impl Executor for OpBlockExecutor where EvmConfig: ConfigureEvm, - DB: Database, + DB: Database + std::fmt::Display>, { type Input<'a> = BlockExecutionInput<'a, BlockWithSenders>; type Output = BlockExecutionOutput; @@ -394,7 +403,7 @@ impl OpBatchExecutor { impl BatchExecutor for OpBatchExecutor where EvmConfig: ConfigureEvm, - DB: Database, + DB: Database + std::fmt::Display>, { type Input<'a> = BlockExecutionInput<'a, BlockWithSenders>; type Output = ExecutionOutcome; diff --git a/crates/revm/src/state_change.rs b/crates/revm/src/state_change.rs index b9fba6b2578e..4505d2ee9761 100644 --- a/crates/revm/src/state_change.rs +++ b/crates/revm/src/state_change.rs @@ -86,7 +86,7 @@ pub fn post_block_balance_increments( /// /// [EIP-2935]: https://eips.ethereum.org/EIPS/eip-2935 #[inline] -pub fn apply_blockhashes_update + DatabaseCommit>( +pub fn apply_blockhashes_update> + DatabaseCommit>( db: &mut DB, chain_spec: &ChainSpec, block_timestamp: u64, @@ -108,7 +108,7 @@ where // nonce of 1, so it does not get deleted. let mut account: Account = db .basic(HISTORY_STORAGE_ADDRESS) - .map_err(BlockValidationError::BlockHashAccountLoadingFailed)? + .map_err(|err| BlockValidationError::BlockHashAccountLoadingFailed(err.into()))? .unwrap_or_else(|| AccountInfo { nonce: 1, code: Some(Bytecode::new_raw(HISTORY_STORAGE_CODE.clone())), @@ -132,7 +132,7 @@ where /// /// This calculates the correct storage slot in the `BLOCKHASH` history storage address, fetches the /// blockhash and creates a [`EvmStorageSlot`] with appropriate previous and new values. -fn eip2935_block_hash_slot>( +fn eip2935_block_hash_slot>>( db: &mut DB, block_number: u64, block_hash: B256, @@ -140,7 +140,7 @@ fn eip2935_block_hash_slot>( let slot = U256::from(block_number % BLOCKHASH_SERVE_WINDOW as u64); let current_hash = db .storage(HISTORY_STORAGE_ADDRESS, slot) - .map_err(BlockValidationError::BlockHashAccountLoadingFailed)?; + .map_err(|err| BlockValidationError::BlockHashAccountLoadingFailed(err.into()))?; Ok((slot, EvmStorageSlot::new_changed(current_hash, block_hash.into()))) }