diff --git a/crates/evm/execution-errors/src/lib.rs b/crates/evm/execution-errors/src/lib.rs index 1c3c8fa4d091..40aad62bb3a6 100644 --- a/crates/evm/execution-errors/src/lib.rs +++ b/crates/evm/execution-errors/src/lib.rs @@ -16,7 +16,7 @@ use alloc::{boxed::Box, string::String}; use alloy_eips::BlockNumHash; use alloy_primitives::B256; -use derive_more::Display; +use derive_more::{Display, From}; use reth_consensus::ConsensusError; use reth_prune_types::PruneSegmentError; use reth_storage_errors::provider::ProviderError; @@ -139,7 +139,7 @@ impl std::error::Error for BlockValidationError { } /// `BlockExecutor` Errors -#[derive(Debug, Display)] +#[derive(Debug, From, Display)] pub enum BlockExecutionError { /// Validation error, transparently wrapping [`BlockValidationError`] Validation(BlockValidationError), @@ -181,24 +181,6 @@ impl BlockExecutionError { } } -impl From for BlockExecutionError { - fn from(error: BlockValidationError) -> Self { - Self::Validation(error) - } -} - -impl From for BlockExecutionError { - fn from(error: ConsensusError) -> Self { - Self::Consensus(error) - } -} - -impl From for BlockExecutionError { - fn from(error: InternalBlockExecutionError) -> Self { - Self::Internal(error) - } -} - impl From for BlockExecutionError { fn from(error: ProviderError) -> Self { InternalBlockExecutionError::from(error).into() @@ -217,9 +199,10 @@ impl std::error::Error for BlockExecutionError { } /// Internal (i.e., not validation or consensus related) `BlockExecutor` Errors -#[derive(Display, Debug)] +#[derive(Display, Debug, From)] pub enum InternalBlockExecutionError { /// Pruning error, transparently wrapping [`PruneSegmentError`] + #[from] Pruning(PruneSegmentError), /// Error when appending chain on fork is not possible #[display( @@ -232,6 +215,7 @@ pub enum InternalBlockExecutionError { other_chain_fork: Box, }, /// Error when fetching latest block state. + #[from] LatestBlock(ProviderError), /// Arbitrary Block Executor Errors #[cfg(feature = "std")] @@ -255,18 +239,6 @@ impl InternalBlockExecutionError { } } -impl From for InternalBlockExecutionError { - fn from(error: PruneSegmentError) -> Self { - Self::Pruning(error) - } -} - -impl From for InternalBlockExecutionError { - fn from(error: ProviderError) -> Self { - Self::LatestBlock(error) - } -} - #[cfg(feature = "std")] impl std::error::Error for InternalBlockExecutionError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { diff --git a/crates/evm/execution-errors/src/trie.rs b/crates/evm/execution-errors/src/trie.rs index b95af1ef6dde..4667e681f7ed 100644 --- a/crates/evm/execution-errors/src/trie.rs +++ b/crates/evm/execution-errors/src/trie.rs @@ -1,7 +1,7 @@ //! Errors when computing the state root. use alloy_primitives::B256; -use derive_more::Display; +use derive_more::{Display, From}; use nybbles::Nibbles; use reth_storage_errors::{db::DatabaseError, provider::ProviderError}; @@ -9,7 +9,7 @@ use reth_storage_errors::{db::DatabaseError, provider::ProviderError}; use alloc::string::ToString; /// State root errors. -#[derive(Display, Debug, PartialEq, Eq, Clone)] +#[derive(Display, Debug, From, PartialEq, Eq, Clone)] pub enum StateRootError { /// Internal database error. Database(DatabaseError), @@ -17,18 +17,6 @@ pub enum StateRootError { StorageRootError(StorageRootError), } -impl From for StateRootError { - fn from(error: DatabaseError) -> Self { - Self::Database(error) - } -} - -impl From for StateRootError { - fn from(error: StorageRootError) -> Self { - Self::StorageRootError(error) - } -} - #[cfg(feature = "std")] impl std::error::Error for StateRootError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { @@ -49,18 +37,12 @@ impl From for DatabaseError { } /// Storage root error. -#[derive(Display, PartialEq, Eq, Clone, Debug)] +#[derive(Display, From, PartialEq, Eq, Clone, Debug)] pub enum StorageRootError { /// Internal database error. Database(DatabaseError), } -impl From for StorageRootError { - fn from(error: DatabaseError) -> Self { - Self::Database(error) - } -} - impl From for DatabaseError { fn from(err: StorageRootError) -> Self { match err { @@ -79,7 +61,7 @@ impl std::error::Error for StorageRootError { } /// State proof errors. -#[derive(Display, Debug, PartialEq, Eq, Clone)] +#[derive(Display, From, Debug, PartialEq, Eq, Clone)] pub enum StateProofError { /// Internal database error. Database(DatabaseError), @@ -87,18 +69,6 @@ pub enum StateProofError { Rlp(alloy_rlp::Error), } -impl From for StateProofError { - fn from(error: DatabaseError) -> Self { - Self::Database(error) - } -} - -impl From for StateProofError { - fn from(error: alloy_rlp::Error) -> Self { - Self::Rlp(error) - } -} - impl From for ProviderError { fn from(value: StateProofError) -> Self { match value { @@ -119,11 +89,13 @@ impl std::error::Error for StateProofError { } /// Trie witness errors. -#[derive(Display, Debug, PartialEq, Eq, Clone)] +#[derive(Display, From, Debug, PartialEq, Eq, Clone)] pub enum TrieWitnessError { /// Error gather proofs. + #[from] Proof(StateProofError), /// RLP decoding error. + #[from] Rlp(alloy_rlp::Error), /// Missing account. #[display("missing account {_0}")] @@ -133,18 +105,6 @@ pub enum TrieWitnessError { MissingTargetNode(Nibbles), } -impl From for TrieWitnessError { - fn from(error: StateProofError) -> Self { - Self::Proof(error) - } -} - -impl From for TrieWitnessError { - fn from(error: alloy_rlp::Error) -> Self { - Self::Rlp(error) - } -} - impl From for ProviderError { fn from(error: TrieWitnessError) -> Self { Self::TrieWitnessError(error.to_string())