reth_storage_errors/
provider.rsuse crate::{db::DatabaseError, lockfile::StorageLockError, writer::UnifiedStorageWriterError};
use alloc::{boxed::Box, string::String};
use alloy_eips::{BlockHashOrNumber, HashOrNumber};
use alloy_primitives::{Address, BlockHash, BlockNumber, TxNumber, B256};
use derive_more::Display;
use reth_primitives_traits::GotExpected;
use reth_static_file_types::StaticFileSegment;
pub type ProviderResult<Ok> = Result<Ok, ProviderError>;
#[derive(Clone, Debug, PartialEq, Eq, thiserror::Error)]
pub enum ProviderError {
#[error(transparent)]
Database(#[from] DatabaseError),
#[error("{_0}")]
Rlp(alloy_rlp::Error),
#[error("{_0}")]
FsPathError(String),
#[error("nippy jar error: {_0}")]
NippyJar(String),
#[error("trie witness error: {_0}")]
TrieWitnessError(String),
#[error("failed to recover sender for transaction")]
SenderRecoveryError,
#[error("block hash {_0} does not exist in Headers table")]
BlockHashNotFound(BlockHash),
#[error("block meta not found for block #{_0}")]
BlockBodyIndicesNotFound(BlockNumber),
#[error("storage change set for address {address} and key {storage_key} at block #{block_number} does not exist")]
StorageChangesetNotFound {
block_number: BlockNumber,
address: Address,
storage_key: Box<B256>,
},
#[error("account change set for address {address} at block #{block_number} does not exist")]
AccountChangesetNotFound {
block_number: BlockNumber,
address: Address,
},
#[error("total difficulty not found for block #{_0}")]
TotalDifficultyNotFound(BlockNumber),
#[error("no header found for {_0:?}")]
HeaderNotFound(BlockHashOrNumber),
#[error("no transaction found for {_0:?}")]
TransactionNotFound(HashOrNumber),
#[error("no receipt found for {_0:?}")]
ReceiptNotFound(HashOrNumber),
#[error("best block does not exist")]
BestBlockNotFound,
#[error("finalized block does not exist")]
FinalizedBlockNotFound,
#[error("safe block does not exist")]
SafeBlockNotFound,
#[error("cache service task stopped")]
CacheServiceUnavailable,
#[error("unknown block {_0}")]
UnknownBlockHash(B256),
#[error("no state found for block {_0}")]
StateForHashNotFound(B256),
#[error("no state found for block number {_0}")]
StateForNumberNotFound(u64),
#[error("unable to find the block number for a given transaction index")]
BlockNumberForTransactionIndexNotFound,
#[error("merkle trie {_0}")]
StateRootMismatch(Box<RootMismatch>),
#[error("unwind merkle trie {_0}")]
UnwindStateRootMismatch(Box<RootMismatch>),
#[error("state at block #{_0} is pruned")]
StateAtBlockPruned(BlockNumber),
#[error("this provider does not support this request")]
UnsupportedProvider,
#[cfg(feature = "std")]
#[error("not able to find {_0} static file at {_1:?}")]
MissingStaticFilePath(StaticFileSegment, std::path::PathBuf),
#[error("not able to find {_0} static file for block number {_1}")]
MissingStaticFileBlock(StaticFileSegment, BlockNumber),
#[error("unable to find {_0} static file for transaction id {_1}")]
MissingStaticFileTx(StaticFileSegment, TxNumber),
#[error("unable to write block #{_1} to finalized static file {_0}")]
FinalizedStaticFile(StaticFileSegment, BlockNumber),
#[error("trying to append data to {_0} as block #{_1} but expected block #{_2}")]
UnexpectedStaticFileBlockNumber(StaticFileSegment, BlockNumber, BlockNumber),
#[error("trying to append row to {_0} at index #{_1} but expected index #{_2}")]
UnexpectedStaticFileTxNumber(StaticFileSegment, TxNumber, TxNumber),
#[error("cannot get a writer on a read-only environment.")]
ReadOnlyStaticFileAccess,
#[error("failed to initialize consistent view: {_0}")]
ConsistentView(Box<ConsistentViewError>),
#[error(transparent)]
StorageLockError(#[from] StorageLockError),
#[error(transparent)]
UnifiedStorageWriterError(#[from] UnifiedStorageWriterError),
#[error("received invalid output from storage")]
InvalidStorageOutput,
}
impl From<alloy_rlp::Error> for ProviderError {
fn from(error: alloy_rlp::Error) -> Self {
Self::Rlp(error)
}
}
#[derive(Clone, Debug, PartialEq, Eq, Display)]
#[display("root mismatch at #{block_number} ({block_hash}): {root}")]
pub struct RootMismatch {
pub root: GotExpected<B256>,
pub block_number: BlockNumber,
pub block_hash: BlockHash,
}
#[derive(Clone, Debug, PartialEq, Eq, Display)]
pub enum ConsistentViewError {
#[display("node is syncing. best block: {best_block:?}")]
Syncing {
best_block: GotExpected<BlockNumber>,
},
#[display("inconsistent database state: {tip:?}")]
Inconsistent {
tip: GotExpected<Option<B256>>,
},
}
impl From<ConsistentViewError> for ProviderError {
fn from(error: ConsistentViewError) -> Self {
Self::ConsistentView(Box::new(error))
}
}