reth_trie_sparse/errors.rs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
//! Errors for sparse trie.
use alloy_primitives::{Bytes, B256};
use reth_trie::Nibbles;
use thiserror::Error;
use crate::SparseNode;
/// Result type with [`SparseStateTrieError`] as error.
pub type SparseStateTrieResult<Ok> = Result<Ok, SparseStateTrieError>;
/// Error encountered in [`crate::SparseStateTrie`].
#[derive(Error, Debug)]
pub enum SparseStateTrieError {
/// Encountered invalid root node.
#[error("invalid root node at {path:?}: {node:?}")]
InvalidRootNode {
/// Path to first proof node.
path: Nibbles,
/// Encoded first proof node.
node: Bytes,
},
/// Sparse trie error.
#[error(transparent)]
Sparse(#[from] SparseTrieError),
/// RLP error.
#[error(transparent)]
Rlp(#[from] alloy_rlp::Error),
}
/// Result type with [`SparseTrieError`] as error.
pub type SparseTrieResult<Ok> = Result<Ok, SparseTrieError>;
/// Error encountered in [`crate::SparseTrie`].
#[derive(Error, Debug)]
pub enum SparseTrieError {
/// Sparse trie is still blind. Thrown on attempt to update it.
#[error("sparse trie is blind")]
Blind,
/// Encountered blinded node on update.
#[error("attempted to update blind node at {path:?}: {hash}")]
BlindedNode {
/// Blind node path.
path: Nibbles,
/// Node hash
hash: B256,
},
/// Encountered unexpected node at path when revealing.
#[error("encountered an invalid node at path {path:?} when revealing: {node:?}")]
Reveal {
/// Path to the node.
path: Nibbles,
/// Node that was at the path when revealing.
node: Box<SparseNode>,
},
/// RLP error.
#[error(transparent)]
Rlp(#[from] alloy_rlp::Error),
}