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(evm): migrate execution errors back to thiserror #13097

Merged
merged 1 commit into from
Dec 3, 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
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions crates/evm/execution-errors/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ alloy-eips.workspace = true
revm-primitives.workspace = true
nybbles.workspace = true

derive_more.workspace = true
thiserror.workspace = true

[features]
default = ["std"]
Expand All @@ -32,6 +32,6 @@ std = [
"alloy-primitives/std",
"revm-primitives/std",
"alloy-rlp/std",
"derive_more/std",
"thiserror/std",
"nybbles/std"
]
96 changes: 31 additions & 65 deletions crates/evm/execution-errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,37 +14,37 @@ extern crate alloc;
use alloc::{boxed::Box, string::String};
use alloy_eips::BlockNumHash;
use alloy_primitives::B256;
use derive_more::{Display, From};
use reth_consensus::ConsensusError;
use reth_prune_types::PruneSegmentError;
use reth_storage_errors::provider::ProviderError;
use revm_primitives::EVMError;
use thiserror::Error;

pub mod trie;
pub use trie::*;

/// Transaction validation errors
#[derive(Clone, Debug, Display, Eq, PartialEq)]
#[derive(Error, PartialEq, Eq, Clone, Debug)]
pub enum BlockValidationError {
/// EVM error with transaction hash and message
#[display("EVM reported invalid transaction ({hash}): {error}")]
#[error("EVM reported invalid transaction ({hash}): {error}")]
EVM {
/// The hash of the transaction
hash: B256,
/// The EVM error.
error: Box<EVMError<ProviderError>>,
},
/// Error when recovering the sender for a transaction
#[display("failed to recover sender for transaction")]
#[error("failed to recover sender for transaction")]
SenderRecoveryError,
/// Error when incrementing balance in post execution
#[display("incrementing balance in post execution failed")]
#[error("incrementing balance in post execution failed")]
IncrementBalanceFailed,
/// Error when the state root does not match the expected value.
// #[from(ignore)]
StateRoot(StateRootError),
#[error(transparent)]
StateRoot(#[from] StateRootError),
/// 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}"
)]
TransactionGasLimitMoreThanAvailableBlockGas {
Expand All @@ -54,22 +54,22 @@ pub enum BlockValidationError {
block_available_gas: u64,
},
/// Error for pre-merge block
#[display("block {hash} is pre merge")]
#[error("block {hash} is pre merge")]
BlockPreMerge {
/// The hash of the block
hash: B256,
},
/// Error for missing total difficulty
#[display("missing total difficulty for block {hash}")]
#[error("missing total difficulty for block {hash}")]
MissingTotalDifficulty {
/// The hash of the block
hash: B256,
},
/// 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,
/// 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}"
)]
CancunGenesisParentBeaconBlockRootNotZero {
Expand All @@ -79,9 +79,7 @@ pub enum BlockValidationError {
/// EVM error during [EIP-4788] beacon root contract call.
///
/// [EIP-4788]: https://eips.ethereum.org/EIPS/eip-4788
#[display(
"failed to apply beacon root contract call at {parent_beacon_block_root}: {message}"
)]
#[error("failed to apply beacon root contract call at {parent_beacon_block_root}: {message}")]
BeaconRootContractCall {
/// The beacon block root
parent_beacon_block_root: Box<B256>,
Expand All @@ -91,59 +89,46 @@ pub enum BlockValidationError {
/// EVM error during [EIP-2935] blockhash contract call.
///
/// [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 {
/// The error message.
message: String,
},
/// EVM error during withdrawal requests contract call [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 {
/// The error message.
message: String,
},
/// EVM error during consolidation requests contract call [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 {
/// The error message.
message: String,
},
/// Error when decoding deposit requests from receipts [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),
}

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
#[derive(Debug, From, Display)]
#[derive(Error, Debug)]
pub enum BlockExecutionError {
/// Validation error, transparently wrapping [`BlockValidationError`]
Validation(BlockValidationError),
#[error(transparent)]
Validation(#[from] BlockValidationError),
/// Consensus error, transparently wrapping [`ConsensusError`]
Consensus(ConsensusError),
#[error(transparent)]
Consensus(#[from] ConsensusError),
/// Internal, i.e. non consensus or validation related Block Executor Errors
Internal(InternalBlockExecutionError),
#[error(transparent)]
Internal(#[from] InternalBlockExecutionError),
}

impl BlockExecutionError {
Expand Down Expand Up @@ -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
#[derive(Display, Debug, From)]
#[derive(Error, Debug)]
pub enum InternalBlockExecutionError {
/// Pruning error, transparently wrapping [`PruneSegmentError`]
#[from]
Pruning(PruneSegmentError),
#[error(transparent)]
Pruning(#[from] PruneSegmentError),
/// 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:?}"
)]
AppendChainDoesntConnect {
Expand All @@ -211,9 +186,10 @@ pub enum InternalBlockExecutionError {
other_chain_fork: Box<BlockNumHash>,
},
/// Error when fetching latest block state.
#[from]
LatestBlock(ProviderError),
#[error(transparent)]
LatestBlock(#[from] ProviderError),
/// Arbitrary Block Executor Errors
#[error(transparent)]
Other(Box<dyn core::error::Error + Send + Sync>),
}

Expand All @@ -233,13 +209,3 @@ impl InternalBlockExecutionError {
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,
}
}
}
75 changes: 22 additions & 53 deletions crates/evm/execution-errors/src/trie.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,19 @@

use alloc::string::ToString;
use alloy_primitives::B256;
use derive_more::{Display, From};
use nybbles::Nibbles;
use reth_storage_errors::{db::DatabaseError, provider::ProviderError};
use thiserror::Error;

/// State root errors.
#[derive(Display, Debug, From, PartialEq, Eq, Clone)]
#[derive(Error, PartialEq, Eq, Clone, Debug)]
pub enum StateRootError {
/// Internal database error.
Database(DatabaseError),
#[error(transparent)]
Database(#[from] DatabaseError),
/// Storage root error.
StorageRootError(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),
}
}
#[error(transparent)]
StorageRootError(#[from] StorageRootError),
}

impl From<StateRootError> for DatabaseError {
Expand All @@ -34,10 +27,11 @@ impl From<StateRootError> for DatabaseError {
}

/// Storage root error.
#[derive(Display, From, PartialEq, Eq, Clone, Debug)]
#[derive(Error, PartialEq, Eq, Clone, Debug)]
pub enum StorageRootError {
/// Internal database error.
Database(DatabaseError),
#[error(transparent)]
Database(#[from] DatabaseError),
}

impl From<StorageRootError> for DatabaseError {
Expand All @@ -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.
#[derive(Display, From, Debug, PartialEq, Eq, Clone)]
#[derive(Error, PartialEq, Eq, Clone, Debug)]
pub enum StateProofError {
/// Internal database error.
Database(DatabaseError),
#[error(transparent)]
Database(#[from] DatabaseError),
/// RLP decoding error.
Rlp(alloy_rlp::Error),
#[error(transparent)]
Rlp(#[from] alloy_rlp::Error),
}

impl From<StateProofError> for ProviderError {
Expand All @@ -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.
#[derive(Display, From, Debug, PartialEq, Eq, Clone)]
#[derive(Error, PartialEq, Eq, Clone, Debug)]
pub enum TrieWitnessError {
/// Error gather proofs.
#[from]
Proof(StateProofError),
#[error(transparent)]
Proof(#[from] StateProofError),
/// RLP decoding error.
#[from]
Rlp(alloy_rlp::Error),
#[error(transparent)]
Rlp(#[from] alloy_rlp::Error),
/// Missing account.
#[display("missing account {_0}")]
#[error("missing account {_0}")]
MissingAccount(B256),
/// Missing target node.
#[display("target node missing from proof {_0:?}")]
#[error("target node missing from proof {_0:?}")]
MissingTargetNode(Nibbles),
/// Unexpected empty root.
#[display("unexpected empty root: {_0:?}")]
#[error("unexpected empty root: {_0:?}")]
UnexpectedEmptyRoot(Nibbles),
}

Expand All @@ -108,13 +87,3 @@ impl From<TrieWitnessError> for ProviderError {
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,
}
}
}
Loading