reth_trie/trie_cursor/
mod.rs

1use crate::{BranchNodeCompact, Nibbles};
2use alloy_primitives::B256;
3use reth_storage_errors::db::DatabaseError;
4
5/// In-memory implementations of trie cursors.
6mod in_memory;
7
8/// Cursor for iterating over a subtrie.
9mod subnode;
10
11/// Noop trie cursor implementations.
12pub mod noop;
13
14pub use self::{in_memory::*, subnode::CursorSubNode};
15
16/// Factory for creating trie cursors.
17pub trait TrieCursorFactory {
18    /// The account trie cursor type.
19    type AccountTrieCursor: TrieCursor;
20    /// The storage trie cursor type.
21    type StorageTrieCursor: TrieCursor;
22
23    /// Create an account trie cursor.
24    fn account_trie_cursor(&self) -> Result<Self::AccountTrieCursor, DatabaseError>;
25
26    /// Create a storage tries cursor.
27    fn storage_trie_cursor(
28        &self,
29        hashed_address: B256,
30    ) -> Result<Self::StorageTrieCursor, DatabaseError>;
31}
32
33/// A cursor for navigating a trie that works with both Tables and DupSort tables.
34#[auto_impl::auto_impl(&mut, Box)]
35pub trait TrieCursor: Send + Sync {
36    /// Move the cursor to the key and return if it is an exact match.
37    fn seek_exact(
38        &mut self,
39        key: Nibbles,
40    ) -> Result<Option<(Nibbles, BranchNodeCompact)>, DatabaseError>;
41
42    /// Move the cursor to the key and return a value matching of greater than the key.
43    fn seek(&mut self, key: Nibbles)
44        -> Result<Option<(Nibbles, BranchNodeCompact)>, DatabaseError>;
45
46    /// Move the cursor to the next key.
47    fn next(&mut self) -> Result<Option<(Nibbles, BranchNodeCompact)>, DatabaseError>;
48
49    /// Get the current entry.
50    fn current(&mut self) -> Result<Option<Nibbles>, DatabaseError>;
51}