Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(reth-execution-errors): use derive_more::From when possible #10897

Merged
merged 1 commit into from
Sep 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 5 additions & 33 deletions crates/evm/execution-errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -181,24 +181,6 @@ impl BlockExecutionError {
}
}

impl From<BlockValidationError> for BlockExecutionError {
fn from(error: BlockValidationError) -> Self {
Self::Validation(error)
}
}

impl From<ConsensusError> for BlockExecutionError {
fn from(error: ConsensusError) -> Self {
Self::Consensus(error)
}
}

impl From<InternalBlockExecutionError> for BlockExecutionError {
fn from(error: InternalBlockExecutionError) -> Self {
Self::Internal(error)
}
}

impl From<ProviderError> for BlockExecutionError {
fn from(error: ProviderError) -> Self {
InternalBlockExecutionError::from(error).into()
Expand All @@ -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(
Expand All @@ -232,6 +215,7 @@ pub enum InternalBlockExecutionError {
other_chain_fork: Box<BlockNumHash>,
},
/// Error when fetching latest block state.
#[from]
LatestBlock(ProviderError),
/// Arbitrary Block Executor Errors
#[cfg(feature = "std")]
Expand All @@ -255,18 +239,6 @@ impl InternalBlockExecutionError {
}
}

impl From<PruneSegmentError> for InternalBlockExecutionError {
fn from(error: PruneSegmentError) -> Self {
Self::Pruning(error)
}
}

impl From<ProviderError> 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)> {
Expand Down
54 changes: 7 additions & 47 deletions crates/evm/execution-errors/src/trie.rs
Original file line number Diff line number Diff line change
@@ -1,34 +1,22 @@
//! 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};

#[cfg(not(feature = "std"))]
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),
/// Storage root error.
StorageRootError(StorageRootError),
}

impl From<DatabaseError> for StateRootError {
fn from(error: DatabaseError) -> Self {
Self::Database(error)
}
}

impl From<StorageRootError> 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)> {
Expand All @@ -49,18 +37,12 @@ impl From<StateRootError> 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<DatabaseError> for StorageRootError {
fn from(error: DatabaseError) -> Self {
Self::Database(error)
}
}

impl From<StorageRootError> for DatabaseError {
fn from(err: StorageRootError) -> Self {
match err {
Expand All @@ -79,26 +61,14 @@ 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),
/// RLP decoding error.
Rlp(alloy_rlp::Error),
}

impl From<DatabaseError> for StateProofError {
fn from(error: DatabaseError) -> Self {
Self::Database(error)
}
}

impl From<alloy_rlp::Error> for StateProofError {
fn from(error: alloy_rlp::Error) -> Self {
Self::Rlp(error)
}
}

impl From<StateProofError> for ProviderError {
fn from(value: StateProofError) -> Self {
match value {
Expand All @@ -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}")]
Expand All @@ -133,18 +105,6 @@ pub enum TrieWitnessError {
MissingTargetNode(Nibbles),
}

impl From<StateProofError> for TrieWitnessError {
fn from(error: StateProofError) -> Self {
Self::Proof(error)
}
}

impl From<alloy_rlp::Error> for TrieWitnessError {
fn from(error: alloy_rlp::Error) -> Self {
Self::Rlp(error)
}
}

impl From<TrieWitnessError> for ProviderError {
fn from(error: TrieWitnessError) -> Self {
Self::TrieWitnessError(error.to_string())
Expand Down
Loading