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}
27
28#[derive(Debug, Error)]
29pub enum InconsistentTreeError {
30 #[error("Child node of {0}, differs from expected")]
31 ExtensionNodeChildDiffers(ExtensionNodeErrorData),
32 #[error("No Child Node found of {0}")]
33 ExtensionNodeChildNotFound(ExtensionNodeErrorData),
34 #[error("Node with hash {0:#x} not found in Branch Node with hash {1:#x} using path {2:?}")]
35 NodeNotFoundOnBranchNode(H256, H256, Nibbles),
36 #[error("Root node with hash {0:#x} not found")]
37 RootNotFound(H256),
38 #[error("Root node not found")]
39 RootNotFoundNoHash,
40}
41
42#[derive(Debug)]
43pub struct ExtensionNodeErrorData {
44 pub node_hash: H256,
45 pub extension_node_hash: H256,
46 pub extension_node_prefix: Nibbles,
47 pub node_path: Nibbles,
48}
49
50impl core::fmt::Display for ExtensionNodeErrorData {
51 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
52 write!(
53 f,
54 "Node with hash {:#x}, child of the Extension Node (hash {:#x}, prefix {:?}) on path {:?}",
55 self.node_hash, self.extension_node_hash, self.extension_node_hash, self.node_path
56 )
57 }
58}