reth_execution_errors/
trie.rsuse alloc::{boxed::Box, string::ToString};
use alloy_primitives::{Bytes, B256};
use nybbles::Nibbles;
use reth_storage_errors::{db::DatabaseError, provider::ProviderError};
use thiserror::Error;
#[derive(Error, PartialEq, Eq, Clone, Debug)]
pub enum StateRootError {
#[error(transparent)]
Database(#[from] DatabaseError),
#[error(transparent)]
StorageRootError(#[from] StorageRootError),
}
impl From<StateRootError> for DatabaseError {
fn from(err: StateRootError) -> Self {
match err {
StateRootError::Database(err) |
StateRootError::StorageRootError(StorageRootError::Database(err)) => err,
}
}
}
#[derive(Error, PartialEq, Eq, Clone, Debug)]
pub enum StorageRootError {
#[error(transparent)]
Database(#[from] DatabaseError),
}
impl From<StorageRootError> for DatabaseError {
fn from(err: StorageRootError) -> Self {
match err {
StorageRootError::Database(err) => err,
}
}
}
#[derive(Error, PartialEq, Eq, Clone, Debug)]
pub enum StateProofError {
#[error(transparent)]
Database(#[from] DatabaseError),
#[error(transparent)]
Rlp(#[from] alloy_rlp::Error),
}
impl From<StateProofError> for ProviderError {
fn from(value: StateProofError) -> Self {
match value {
StateProofError::Database(error) => Self::Database(error),
StateProofError::Rlp(error) => Self::Rlp(error),
}
}
}
pub type SparseStateTrieResult<Ok> = Result<Ok, SparseStateTrieError>;
#[derive(Error, Debug)]
#[error(transparent)]
pub struct SparseStateTrieError(#[from] Box<SparseStateTrieErrorKind>);
impl<T: Into<SparseStateTrieErrorKind>> From<T> for SparseStateTrieError {
#[cold]
fn from(value: T) -> Self {
Self(Box::new(value.into()))
}
}
impl From<SparseTrieError> for SparseStateTrieErrorKind {
#[cold]
fn from(value: SparseTrieError) -> Self {
Self::Sparse(*value.0)
}
}
impl SparseStateTrieError {
pub const fn kind(&self) -> &SparseStateTrieErrorKind {
&self.0
}
pub fn into_kind(self) -> SparseStateTrieErrorKind {
*self.0
}
}
#[derive(Error, Debug)]
pub enum SparseStateTrieErrorKind {
#[error("invalid root node at {path:?}: {node:?}")]
InvalidRootNode {
path: Nibbles,
node: Bytes,
},
#[error(transparent)]
Sparse(#[from] SparseTrieErrorKind),
#[error(transparent)]
Rlp(#[from] alloy_rlp::Error),
}
pub type SparseTrieResult<Ok> = Result<Ok, SparseTrieError>;
#[derive(Error, Debug)]
#[error(transparent)]
pub struct SparseTrieError(#[from] Box<SparseTrieErrorKind>);
impl<T: Into<SparseTrieErrorKind>> From<T> for SparseTrieError {
#[cold]
fn from(value: T) -> Self {
Self(Box::new(value.into()))
}
}
impl SparseTrieError {
pub const fn kind(&self) -> &SparseTrieErrorKind {
&self.0
}
pub fn into_kind(self) -> SparseTrieErrorKind {
*self.0
}
}
#[derive(Error, Debug)]
pub enum SparseTrieErrorKind {
#[error("sparse trie is blind")]
Blind,
#[error("attempted to update blind node at {path:?}: {hash}")]
BlindedNode {
path: Nibbles,
hash: B256,
},
#[error("encountered an invalid node at path {path:?} when revealing: {node:?}")]
Reveal {
path: Nibbles,
node: Box<dyn core::fmt::Debug + Send>,
},
#[error(transparent)]
Rlp(#[from] alloy_rlp::Error),
#[error(transparent)]
Other(#[from] Box<dyn core::error::Error + Send>),
}
#[derive(Error, Debug)]
pub enum TrieWitnessError {
#[error(transparent)]
Proof(#[from] StateProofError),
#[error(transparent)]
Rlp(#[from] alloy_rlp::Error),
#[error(transparent)]
Sparse(#[from] SparseStateTrieError),
#[error("missing account {_0}")]
MissingAccount(B256),
}
impl From<SparseStateTrieErrorKind> for TrieWitnessError {
fn from(error: SparseStateTrieErrorKind) -> Self {
Self::Sparse(error.into())
}
}
impl From<TrieWitnessError> for ProviderError {
fn from(error: TrieWitnessError) -> Self {
Self::TrieWitnessError(error.to_string())
}
}