reth_storage_errors/
provider.rs1use crate::{db::DatabaseError, lockfile::StorageLockError, writer::UnifiedStorageWriterError};
2use alloc::{boxed::Box, string::String};
3use alloy_eips::{BlockHashOrNumber, HashOrNumber};
4use alloy_primitives::{Address, BlockHash, BlockNumber, TxNumber, B256};
5use derive_more::Display;
6use reth_enclave::EnclaveError;
7use reth_primitives_traits::GotExpected;
8use reth_static_file_types::StaticFileSegment;
9
10pub type ProviderResult<Ok> = Result<Ok, ProviderError>;
12
13#[derive(Clone, Debug, Display, PartialEq, Eq)]
15pub enum ProviderError {
16 Database(DatabaseError),
18 Rlp(alloy_rlp::Error),
20 #[display("{_0}")]
22 FsPathError(String),
23 #[display("nippy jar error: {_0}")]
25 NippyJar(String),
26 #[display("trie witness error: {_0}")]
28 TrieWitnessError(String),
29 #[display("failed to recover sender for transaction")]
31 SenderRecoveryError,
32 #[display("block hash {_0} does not exist in Headers table")]
34 BlockHashNotFound(BlockHash),
35 #[display("block meta not found for block #{_0}")]
37 BlockBodyIndicesNotFound(BlockNumber),
38 #[display(
41 "storage change set for address {address} and key {storage_key} at block #{block_number} does not exist"
42 )]
43 StorageChangesetNotFound {
44 block_number: BlockNumber,
46 address: Address,
48 storage_key: Box<B256>,
52 },
53 #[display("account change set for address {address} at block #{block_number} does not exist")]
55 AccountChangesetNotFound {
56 block_number: BlockNumber,
58 address: Address,
60 },
61 #[display("total difficulty not found for block #{_0}")]
63 TotalDifficultyNotFound(BlockNumber),
64 #[display("no header found for {_0:?}")]
66 HeaderNotFound(BlockHashOrNumber),
67 #[display("no transaction found for {_0:?}")]
69 TransactionNotFound(HashOrNumber),
70 #[display("no receipt found for {_0:?}")]
72 ReceiptNotFound(HashOrNumber),
73 #[display("best block does not exist")]
75 BestBlockNotFound,
76 #[display("finalized block does not exist")]
78 FinalizedBlockNotFound,
79 #[display("safe block does not exist")]
81 SafeBlockNotFound,
82 #[display("cache service task stopped")]
84 CacheServiceUnavailable,
85 #[display("unknown block {_0}")]
87 UnknownBlockHash(B256),
88 #[display("no state found for block {_0}")]
90 StateForHashNotFound(B256),
91 #[display("no state found for block number {_0}")]
93 StateForNumberNotFound(u64),
94 #[display("unable to find the block number for a given transaction index")]
96 BlockNumberForTransactionIndexNotFound,
97 #[display("merkle trie {_0}")]
99 StateRootMismatch(Box<RootMismatch>),
100 #[display("unwind merkle trie {_0}")]
102 UnwindStateRootMismatch(Box<RootMismatch>),
103 #[display("state at block #{_0} is pruned")]
105 StateAtBlockPruned(BlockNumber),
106 #[display("this provider does not support this request")]
108 UnsupportedProvider,
109 #[cfg(feature = "std")]
111 #[display("not able to find {_0} static file at {_1:?}")]
112 MissingStaticFilePath(StaticFileSegment, std::path::PathBuf),
113 #[display("not able to find {_0} static file for block number {_1}")]
115 MissingStaticFileBlock(StaticFileSegment, BlockNumber),
116 #[display("unable to find {_0} static file for transaction id {_1}")]
118 MissingStaticFileTx(StaticFileSegment, TxNumber),
119 #[display("unable to write block #{_1} to finalized static file {_0}")]
121 FinalizedStaticFile(StaticFileSegment, BlockNumber),
122 #[display("trying to append data to {_0} as block #{_1} but expected block #{_2}")]
124 UnexpectedStaticFileBlockNumber(StaticFileSegment, BlockNumber, BlockNumber),
125 #[display("trying to append row to {_0} at index #{_1} but expected index #{_2}")]
127 UnexpectedStaticFileTxNumber(StaticFileSegment, TxNumber, TxNumber),
128 #[display("cannot get a writer on a read-only environment.")]
130 ReadOnlyStaticFileAccess,
131 #[display("failed to initialize consistent view: {_0}")]
133 ConsistentView(Box<ConsistentViewError>),
134 StorageLockError(StorageLockError),
136 UnifiedStorageWriterError(UnifiedStorageWriterError),
138 InvalidStorageOutput,
140 EnclaveError(EnclaveError),
142}
143
144impl From<EnclaveError> for ProviderError {
145 fn from(err: EnclaveError) -> Self {
146 Self::EnclaveError(err)
147 }
148}
149
150impl From<DatabaseError> for ProviderError {
151 fn from(error: DatabaseError) -> Self {
152 Self::Database(error)
153 }
154}
155
156impl From<alloy_rlp::Error> for ProviderError {
157 fn from(error: alloy_rlp::Error) -> Self {
158 Self::Rlp(error)
159 }
160}
161
162impl From<StorageLockError> for ProviderError {
163 fn from(error: StorageLockError) -> Self {
164 Self::StorageLockError(error)
165 }
166}
167
168impl From<UnifiedStorageWriterError> for ProviderError {
169 fn from(error: UnifiedStorageWriterError) -> Self {
170 Self::UnifiedStorageWriterError(error)
171 }
172}
173
174impl core::error::Error for ProviderError {
175 fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
176 match self {
177 Self::Database(source) => core::error::Error::source(source),
178 Self::StorageLockError(source) => core::error::Error::source(source),
179 Self::UnifiedStorageWriterError(source) => core::error::Error::source(source),
180 _ => Option::None,
181 }
182 }
183}
184
185#[derive(Clone, Debug, PartialEq, Eq, Display)]
187#[display("root mismatch at #{block_number} ({block_hash}): {root}")]
188pub struct RootMismatch {
189 pub root: GotExpected<B256>,
191 pub block_number: BlockNumber,
193 pub block_hash: BlockHash,
195}
196
197#[derive(Clone, Debug, PartialEq, Eq, Display)]
199pub enum ConsistentViewError {
200 #[display("node is syncing. best block: {best_block:?}")]
202 Syncing {
203 best_block: GotExpected<BlockNumber>,
205 },
206 #[display("inconsistent database state: {tip:?}")]
208 Inconsistent {
209 tip: GotExpected<Option<B256>>,
211 },
212}
213
214impl From<ConsistentViewError> for ProviderError {
215 fn from(error: ConsistentViewError) -> Self {
216 Self::ConsistentView(Box::new(error))
217 }
218}