reth_execution_errors/
lib.rs#![doc(
html_logo_url = "https://raw.githubusercontent.com/paradigmxyz/reth/main/assets/reth-docs.png",
html_favicon_url = "https://avatars0.githubusercontent.com/u/97369466?s=256",
issue_tracker_base_url = "https://github.com/paradigmxyz/reth/issues/"
)]
#![cfg_attr(not(test), warn(unused_crate_dependencies))]
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
#![cfg_attr(not(feature = "std"), no_std)]
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;
pub mod trie;
pub use trie::*;
#[derive(Clone, Debug, Display, Eq, PartialEq)]
pub enum BlockValidationError {
#[display("EVM reported invalid transaction ({hash}): {error}")]
EVM {
hash: B256,
error: Box<EVMError<ProviderError>>,
},
#[display("failed to recover sender for transaction")]
SenderRecoveryError,
#[display("incrementing balance in post execution failed")]
IncrementBalanceFailed,
StateRoot(StateRootError),
#[display(
"transaction gas limit {transaction_gas_limit} is more than blocks available gas {block_available_gas}"
)]
TransactionGasLimitMoreThanAvailableBlockGas {
transaction_gas_limit: u64,
block_available_gas: u64,
},
#[display("block {hash} is pre merge")]
BlockPreMerge {
hash: B256,
},
#[display("missing total difficulty for block {hash}")]
MissingTotalDifficulty {
hash: B256,
},
#[display("EIP-4788 parent beacon block root missing for active Cancun block")]
MissingParentBeaconBlockRoot,
#[display(
"the parent beacon block root is not zero for Cancun genesis block: {parent_beacon_block_root}"
)]
CancunGenesisParentBeaconBlockRootNotZero {
parent_beacon_block_root: B256,
},
#[display(
"failed to apply beacon root contract call at {parent_beacon_block_root}: {message}"
)]
BeaconRootContractCall {
parent_beacon_block_root: Box<B256>,
message: String,
},
#[display("failed to apply blockhash contract call: {message}")]
BlockHashContractCall {
message: String,
},
#[display("failed to apply withdrawal requests contract call: {message}")]
WithdrawalRequestsContractCall {
message: String,
},
#[display("failed to apply consolidation requests contract call: {message}")]
ConsolidationRequestsContractCall {
message: String,
},
#[display("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,
}
}
}
#[derive(Debug, From, Display)]
pub enum BlockExecutionError {
Validation(BlockValidationError),
Consensus(ConsensusError),
Internal(InternalBlockExecutionError),
}
impl BlockExecutionError {
#[cfg(feature = "std")]
pub fn other<E>(error: E) -> Self
where
E: core::error::Error + Send + Sync + 'static,
{
Self::Internal(InternalBlockExecutionError::other(error))
}
#[cfg(feature = "std")]
pub fn msg(msg: impl std::fmt::Display) -> Self {
Self::Internal(InternalBlockExecutionError::msg(msg))
}
pub const fn as_validation(&self) -> Option<&BlockValidationError> {
match self {
Self::Validation(err) => Some(err),
_ => None,
}
}
pub const fn is_state_root_error(&self) -> bool {
matches!(self, Self::Validation(BlockValidationError::StateRoot(_)))
}
}
impl From<ProviderError> for BlockExecutionError {
fn from(error: ProviderError) -> Self {
InternalBlockExecutionError::from(error).into()
}
}
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),
}
}
}
#[derive(Display, Debug, From)]
pub enum InternalBlockExecutionError {
#[from]
Pruning(PruneSegmentError),
#[display(
"appending chain on fork (other_chain_fork:?) is not possible as the tip is {chain_tip:?}"
)]
AppendChainDoesntConnect {
chain_tip: Box<BlockNumHash>,
other_chain_fork: Box<BlockNumHash>,
},
#[from]
LatestBlock(ProviderError),
Other(Box<dyn core::error::Error + Send + Sync>),
}
impl InternalBlockExecutionError {
#[cfg(feature = "std")]
pub fn other<E>(error: E) -> Self
where
E: core::error::Error + Send + Sync + 'static,
{
Self::Other(Box::new(error))
}
#[cfg(feature = "std")]
pub fn msg(msg: impl std::fmt::Display) -> Self {
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,
}
}
}