chore(evm): migrate execution errors back to thiserror (#13097)

This commit is contained in:
Roman Krasiuk
2024-12-03 13:39:29 +01:00
committed by GitHub
parent bfcd98326c
commit bedc68e8f4
4 changed files with 56 additions and 121 deletions

2
Cargo.lock generated
View File

@ -7601,12 +7601,12 @@ dependencies = [
"alloy-eips", "alloy-eips",
"alloy-primitives", "alloy-primitives",
"alloy-rlp", "alloy-rlp",
"derive_more 1.0.0",
"nybbles", "nybbles",
"reth-consensus", "reth-consensus",
"reth-prune-types", "reth-prune-types",
"reth-storage-errors", "reth-storage-errors",
"revm-primitives", "revm-primitives",
"thiserror 2.0.3",
] ]
[[package]] [[package]]

View File

@ -22,7 +22,7 @@ alloy-eips.workspace = true
revm-primitives.workspace = true revm-primitives.workspace = true
nybbles.workspace = true nybbles.workspace = true
derive_more.workspace = true thiserror.workspace = true
[features] [features]
default = ["std"] default = ["std"]
@ -32,6 +32,6 @@ std = [
"alloy-primitives/std", "alloy-primitives/std",
"revm-primitives/std", "revm-primitives/std",
"alloy-rlp/std", "alloy-rlp/std",
"derive_more/std", "thiserror/std",
"nybbles/std" "nybbles/std"
] ]

View File

@ -14,20 +14,20 @@ extern crate alloc;
use alloc::{boxed::Box, string::String}; use alloc::{boxed::Box, string::String};
use alloy_eips::BlockNumHash; use alloy_eips::BlockNumHash;
use alloy_primitives::B256; use alloy_primitives::B256;
use derive_more::{Display, From};
use reth_consensus::ConsensusError; use reth_consensus::ConsensusError;
use reth_prune_types::PruneSegmentError; use reth_prune_types::PruneSegmentError;
use reth_storage_errors::provider::ProviderError; use reth_storage_errors::provider::ProviderError;
use revm_primitives::EVMError; use revm_primitives::EVMError;
use thiserror::Error;
pub mod trie; pub mod trie;
pub use trie::*; pub use trie::*;
/// Transaction validation errors /// Transaction validation errors
#[derive(Clone, Debug, Display, Eq, PartialEq)] #[derive(Error, PartialEq, Eq, Clone, Debug)]
pub enum BlockValidationError { pub enum BlockValidationError {
/// EVM error with transaction hash and message /// EVM error with transaction hash and message
#[display("EVM reported invalid transaction ({hash}): {error}")] #[error("EVM reported invalid transaction ({hash}): {error}")]
EVM { EVM {
/// The hash of the transaction /// The hash of the transaction
hash: B256, hash: B256,
@ -35,16 +35,16 @@ pub enum BlockValidationError {
error: Box<EVMError<ProviderError>>, error: Box<EVMError<ProviderError>>,
}, },
/// Error when recovering the sender for a transaction /// Error when recovering the sender for a transaction
#[display("failed to recover sender for transaction")] #[error("failed to recover sender for transaction")]
SenderRecoveryError, SenderRecoveryError,
/// Error when incrementing balance in post execution /// Error when incrementing balance in post execution
#[display("incrementing balance in post execution failed")] #[error("incrementing balance in post execution failed")]
IncrementBalanceFailed, IncrementBalanceFailed,
/// Error when the state root does not match the expected value. /// Error when the state root does not match the expected value.
// #[from(ignore)] #[error(transparent)]
StateRoot(StateRootError), StateRoot(#[from] StateRootError),
/// Error when transaction gas limit exceeds available block gas /// Error when transaction gas limit exceeds available block gas
#[display( #[error(
"transaction gas limit {transaction_gas_limit} is more than blocks available gas {block_available_gas}" "transaction gas limit {transaction_gas_limit} is more than blocks available gas {block_available_gas}"
)] )]
TransactionGasLimitMoreThanAvailableBlockGas { TransactionGasLimitMoreThanAvailableBlockGas {
@ -54,22 +54,22 @@ pub enum BlockValidationError {
block_available_gas: u64, block_available_gas: u64,
}, },
/// Error for pre-merge block /// Error for pre-merge block
#[display("block {hash} is pre merge")] #[error("block {hash} is pre merge")]
BlockPreMerge { BlockPreMerge {
/// The hash of the block /// The hash of the block
hash: B256, hash: B256,
}, },
/// Error for missing total difficulty /// Error for missing total difficulty
#[display("missing total difficulty for block {hash}")] #[error("missing total difficulty for block {hash}")]
MissingTotalDifficulty { MissingTotalDifficulty {
/// The hash of the block /// The hash of the block
hash: B256, hash: B256,
}, },
/// Error for EIP-4788 when parent beacon block root is missing /// Error for EIP-4788 when parent beacon block root is missing
#[display("EIP-4788 parent beacon block root missing for active Cancun block")] #[error("EIP-4788 parent beacon block root missing for active Cancun block")]
MissingParentBeaconBlockRoot, MissingParentBeaconBlockRoot,
/// Error for Cancun genesis block when parent beacon block root is not zero /// Error for Cancun genesis block when parent beacon block root is not zero
#[display( #[error(
"the parent beacon block root is not zero for Cancun genesis block: {parent_beacon_block_root}" "the parent beacon block root is not zero for Cancun genesis block: {parent_beacon_block_root}"
)] )]
CancunGenesisParentBeaconBlockRootNotZero { CancunGenesisParentBeaconBlockRootNotZero {
@ -79,9 +79,7 @@ pub enum BlockValidationError {
/// EVM error during [EIP-4788] beacon root contract call. /// EVM error during [EIP-4788] beacon root contract call.
/// ///
/// [EIP-4788]: https://eips.ethereum.org/EIPS/eip-4788 /// [EIP-4788]: https://eips.ethereum.org/EIPS/eip-4788
#[display( #[error("failed to apply beacon root contract call at {parent_beacon_block_root}: {message}")]
"failed to apply beacon root contract call at {parent_beacon_block_root}: {message}"
)]
BeaconRootContractCall { BeaconRootContractCall {
/// The beacon block root /// The beacon block root
parent_beacon_block_root: Box<B256>, parent_beacon_block_root: Box<B256>,
@ -91,7 +89,7 @@ pub enum BlockValidationError {
/// EVM error during [EIP-2935] blockhash contract call. /// EVM error during [EIP-2935] blockhash contract call.
/// ///
/// [EIP-2935]: https://eips.ethereum.org/EIPS/eip-2935 /// [EIP-2935]: https://eips.ethereum.org/EIPS/eip-2935
#[display("failed to apply blockhash contract call: {message}")] #[error("failed to apply blockhash contract call: {message}")]
BlockHashContractCall { BlockHashContractCall {
/// The error message. /// The error message.
message: String, message: String,
@ -99,7 +97,7 @@ pub enum BlockValidationError {
/// EVM error during withdrawal requests contract call [EIP-7002] /// EVM error during withdrawal requests contract call [EIP-7002]
/// ///
/// [EIP-7002]: https://eips.ethereum.org/EIPS/eip-7002 /// [EIP-7002]: https://eips.ethereum.org/EIPS/eip-7002
#[display("failed to apply withdrawal requests contract call: {message}")] #[error("failed to apply withdrawal requests contract call: {message}")]
WithdrawalRequestsContractCall { WithdrawalRequestsContractCall {
/// The error message. /// The error message.
message: String, message: String,
@ -107,7 +105,7 @@ pub enum BlockValidationError {
/// EVM error during consolidation requests contract call [EIP-7251] /// EVM error during consolidation requests contract call [EIP-7251]
/// ///
/// [EIP-7251]: https://eips.ethereum.org/EIPS/eip-7251 /// [EIP-7251]: https://eips.ethereum.org/EIPS/eip-7251
#[display("failed to apply consolidation requests contract call: {message}")] #[error("failed to apply consolidation requests contract call: {message}")]
ConsolidationRequestsContractCall { ConsolidationRequestsContractCall {
/// The error message. /// The error message.
message: String, message: String,
@ -115,35 +113,22 @@ pub enum BlockValidationError {
/// Error when decoding deposit requests from receipts [EIP-6110] /// Error when decoding deposit requests from receipts [EIP-6110]
/// ///
/// [EIP-6110]: https://eips.ethereum.org/EIPS/eip-6110 /// [EIP-6110]: https://eips.ethereum.org/EIPS/eip-6110
#[display("failed to decode deposit requests from receipts: {_0}")] #[error("failed to decode deposit requests from receipts: {_0}")]
DepositRequestDecode(String), DepositRequestDecode(String),
} }
impl From<StateRootError> for BlockValidationError {
fn from(error: StateRootError) -> Self {
Self::StateRoot(error)
}
}
impl core::error::Error for BlockValidationError {
fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
match self {
Self::EVM { error, .. } => core::error::Error::source(error),
Self::StateRoot(source) => core::error::Error::source(source),
_ => Option::None,
}
}
}
/// `BlockExecutor` Errors /// `BlockExecutor` Errors
#[derive(Debug, From, Display)] #[derive(Error, Debug)]
pub enum BlockExecutionError { pub enum BlockExecutionError {
/// Validation error, transparently wrapping [`BlockValidationError`] /// Validation error, transparently wrapping [`BlockValidationError`]
Validation(BlockValidationError), #[error(transparent)]
Validation(#[from] BlockValidationError),
/// Consensus error, transparently wrapping [`ConsensusError`] /// Consensus error, transparently wrapping [`ConsensusError`]
Consensus(ConsensusError), #[error(transparent)]
Consensus(#[from] ConsensusError),
/// Internal, i.e. non consensus or validation related Block Executor Errors /// Internal, i.e. non consensus or validation related Block Executor Errors
Internal(InternalBlockExecutionError), #[error(transparent)]
Internal(#[from] InternalBlockExecutionError),
} }
impl BlockExecutionError { impl BlockExecutionError {
@ -184,24 +169,14 @@ impl From<ProviderError> for BlockExecutionError {
} }
} }
impl core::error::Error for BlockExecutionError {
fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
match self {
Self::Validation(source) => core::error::Error::source(source),
Self::Consensus(source) => core::error::Error::source(source),
Self::Internal(source) => core::error::Error::source(source),
}
}
}
/// Internal (i.e., not validation or consensus related) `BlockExecutor` Errors /// Internal (i.e., not validation or consensus related) `BlockExecutor` Errors
#[derive(Display, Debug, From)] #[derive(Error, Debug)]
pub enum InternalBlockExecutionError { pub enum InternalBlockExecutionError {
/// Pruning error, transparently wrapping [`PruneSegmentError`] /// Pruning error, transparently wrapping [`PruneSegmentError`]
#[from] #[error(transparent)]
Pruning(PruneSegmentError), Pruning(#[from] PruneSegmentError),
/// Error when appending chain on fork is not possible /// Error when appending chain on fork is not possible
#[display( #[error(
"appending chain on fork (other_chain_fork:?) is not possible as the tip is {chain_tip:?}" "appending chain on fork (other_chain_fork:?) is not possible as the tip is {chain_tip:?}"
)] )]
AppendChainDoesntConnect { AppendChainDoesntConnect {
@ -211,9 +186,10 @@ pub enum InternalBlockExecutionError {
other_chain_fork: Box<BlockNumHash>, other_chain_fork: Box<BlockNumHash>,
}, },
/// Error when fetching latest block state. /// Error when fetching latest block state.
#[from] #[error(transparent)]
LatestBlock(ProviderError), LatestBlock(#[from] ProviderError),
/// Arbitrary Block Executor Errors /// Arbitrary Block Executor Errors
#[error(transparent)]
Other(Box<dyn core::error::Error + Send + Sync>), Other(Box<dyn core::error::Error + Send + Sync>),
} }
@ -233,13 +209,3 @@ impl InternalBlockExecutionError {
Self::Other(msg.to_string().into()) Self::Other(msg.to_string().into())
} }
} }
impl core::error::Error for InternalBlockExecutionError {
fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
match self {
Self::Pruning(source) => core::error::Error::source(source),
Self::LatestBlock(source) => core::error::Error::source(source),
_ => Option::None,
}
}
}

View File

@ -2,26 +2,19 @@
use alloc::string::ToString; use alloc::string::ToString;
use alloy_primitives::B256; use alloy_primitives::B256;
use derive_more::{Display, From};
use nybbles::Nibbles; use nybbles::Nibbles;
use reth_storage_errors::{db::DatabaseError, provider::ProviderError}; use reth_storage_errors::{db::DatabaseError, provider::ProviderError};
use thiserror::Error;
/// State root errors. /// State root errors.
#[derive(Display, Debug, From, PartialEq, Eq, Clone)] #[derive(Error, PartialEq, Eq, Clone, Debug)]
pub enum StateRootError { pub enum StateRootError {
/// Internal database error. /// Internal database error.
Database(DatabaseError), #[error(transparent)]
Database(#[from] DatabaseError),
/// Storage root error. /// Storage root error.
StorageRootError(StorageRootError), #[error(transparent)]
} StorageRootError(#[from] StorageRootError),
impl core::error::Error for StateRootError {
fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
match self {
Self::Database(source) => core::error::Error::source(source),
Self::StorageRootError(source) => core::error::Error::source(source),
}
}
} }
impl From<StateRootError> for DatabaseError { impl From<StateRootError> for DatabaseError {
@ -34,10 +27,11 @@ impl From<StateRootError> for DatabaseError {
} }
/// Storage root error. /// Storage root error.
#[derive(Display, From, PartialEq, Eq, Clone, Debug)] #[derive(Error, PartialEq, Eq, Clone, Debug)]
pub enum StorageRootError { pub enum StorageRootError {
/// Internal database error. /// Internal database error.
Database(DatabaseError), #[error(transparent)]
Database(#[from] DatabaseError),
} }
impl From<StorageRootError> for DatabaseError { impl From<StorageRootError> for DatabaseError {
@ -48,21 +42,15 @@ impl From<StorageRootError> for DatabaseError {
} }
} }
impl core::error::Error for StorageRootError {
fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
match self {
Self::Database(source) => core::error::Error::source(source),
}
}
}
/// State proof errors. /// State proof errors.
#[derive(Display, From, Debug, PartialEq, Eq, Clone)] #[derive(Error, PartialEq, Eq, Clone, Debug)]
pub enum StateProofError { pub enum StateProofError {
/// Internal database error. /// Internal database error.
Database(DatabaseError), #[error(transparent)]
Database(#[from] DatabaseError),
/// RLP decoding error. /// RLP decoding error.
Rlp(alloy_rlp::Error), #[error(transparent)]
Rlp(#[from] alloy_rlp::Error),
} }
impl From<StateProofError> for ProviderError { impl From<StateProofError> for ProviderError {
@ -74,32 +62,23 @@ impl From<StateProofError> for ProviderError {
} }
} }
impl core::error::Error for StateProofError {
fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
match self {
Self::Database(source) => core::error::Error::source(source),
Self::Rlp(source) => core::error::Error::source(source),
}
}
}
/// Trie witness errors. /// Trie witness errors.
#[derive(Display, From, Debug, PartialEq, Eq, Clone)] #[derive(Error, PartialEq, Eq, Clone, Debug)]
pub enum TrieWitnessError { pub enum TrieWitnessError {
/// Error gather proofs. /// Error gather proofs.
#[from] #[error(transparent)]
Proof(StateProofError), Proof(#[from] StateProofError),
/// RLP decoding error. /// RLP decoding error.
#[from] #[error(transparent)]
Rlp(alloy_rlp::Error), Rlp(#[from] alloy_rlp::Error),
/// Missing account. /// Missing account.
#[display("missing account {_0}")] #[error("missing account {_0}")]
MissingAccount(B256), MissingAccount(B256),
/// Missing target node. /// Missing target node.
#[display("target node missing from proof {_0:?}")] #[error("target node missing from proof {_0:?}")]
MissingTargetNode(Nibbles), MissingTargetNode(Nibbles),
/// Unexpected empty root. /// Unexpected empty root.
#[display("unexpected empty root: {_0:?}")] #[error("unexpected empty root: {_0:?}")]
UnexpectedEmptyRoot(Nibbles), UnexpectedEmptyRoot(Nibbles),
} }
@ -108,13 +87,3 @@ impl From<TrieWitnessError> for ProviderError {
Self::TrieWitnessError(error.to_string()) Self::TrieWitnessError(error.to_string())
} }
} }
impl core::error::Error for TrieWitnessError {
fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
match self {
Self::Proof(source) => core::error::Error::source(source),
Self::Rlp(source) => core::error::Error::source(source),
_ => Option::None,
}
}
}