1#[cfg(not(feature = "std"))]
2use alloc::{boxed::Box, string::String};
3use ethereum_types::H256;
4use ethrex_rlp::error::RLPDecodeError;
5use thiserror::Error;
6
7use crate::Nibbles;
8
9#[derive(Debug, Error)]
10pub enum TrieError {
11 #[error(transparent)]
12 RLPDecode(#[from] RLPDecodeError),
13 #[error("Verification Error: {0}")]
14 Verify(String),
15 #[error("Inconsistent internal tree structure: {0}")]
16 InconsistentTree(Box<InconsistentTreeError>),
17 #[error("Lock Error: Panicked when trying to acquire a lock")]
19 LockError,
20 #[error("Database error: {0}")]
21 DbError(anyhow::Error),
22 #[error("Invalid trie input")]
23 InvalidInput,
24 #[error("Trie node path does not end at the trie's key length")]
25 KeyLengthMismatch,
26 #[error("Malformed trie node: {0}")]
27 MalformedNode(&'static str),
28}
29
30#[derive(Debug, Error)]
31pub enum InconsistentTreeError {
32 #[error("Child node of {0}, differs from expected")]
33 ExtensionNodeChildDiffers(ExtensionNodeErrorData),
34 #[error("No Child Node found of {0}")]
35 ExtensionNodeChildNotFound(ExtensionNodeErrorData),
36 #[error("Node with hash {0:#x} not found in Branch Node with hash {1:#x} using path {2:?}")]
37 NodeNotFoundOnBranchNode(H256, H256, Nibbles),
38 #[error("Root node with hash {0:#x} not found")]
39 RootNotFound(H256),
40 #[error("Root node not found")]
41 RootNotFoundNoHash,
42}
43
44#[derive(Debug)]
45pub struct ExtensionNodeErrorData {
46 pub node_hash: H256,
47 pub extension_node_hash: H256,
48 pub extension_node_prefix: Nibbles,
49 pub node_path: Nibbles,
50}
51
52impl core::fmt::Display for ExtensionNodeErrorData {
53 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
54 write!(
55 f,
56 "Node with hash {:#x}, child of the Extension Node (hash {:#x}, prefix {:?}) on path {:?}",
57 self.node_hash, self.extension_node_hash, self.extension_node_hash, self.node_path
58 )
59 }
60}