reth_trie/hashed_cursor/
mod.rs

1use alloy_primitives::{B256, U256};
2use reth_primitives_traits::Account;
3use reth_storage_errors::db::DatabaseError;
4
5/// Implementation of hashed state cursor traits for the post state.
6mod post_state;
7pub use post_state::*;
8
9/// Implementation of noop hashed state cursor.
10pub mod noop;
11
12/// Mock trie cursor implementations.
13#[cfg(test)]
14pub mod mock;
15
16/// The factory trait for creating cursors over the hashed state.
17#[auto_impl::auto_impl(&)]
18pub trait HashedCursorFactory {
19    /// The hashed account cursor type.
20    type AccountCursor<'a>: HashedCursor<Value = Account>
21    where
22        Self: 'a;
23    /// The hashed storage cursor type.
24    type StorageCursor<'a>: HashedStorageCursor<Value = U256>
25    where
26        Self: 'a;
27
28    /// Returns a cursor for iterating over all hashed accounts in the state.
29    fn hashed_account_cursor(&self) -> Result<Self::AccountCursor<'_>, DatabaseError>;
30
31    /// Returns a cursor for iterating over all hashed storage entries in the state.
32    fn hashed_storage_cursor(
33        &self,
34        hashed_address: B256,
35    ) -> Result<Self::StorageCursor<'_>, DatabaseError>;
36}
37
38/// The cursor for iterating over hashed entries.
39#[auto_impl::auto_impl(&mut)]
40pub trait HashedCursor {
41    /// Value returned by the cursor.
42    type Value: std::fmt::Debug;
43
44    /// Seek an entry greater than or equal to the given key and position the cursor there.
45    /// Returns the first entry with the key greater than or equal to the sought key.
46    fn seek(&mut self, key: B256) -> Result<Option<(B256, Self::Value)>, DatabaseError>;
47
48    /// Move the cursor to the next entry and return it.
49    fn next(&mut self) -> Result<Option<(B256, Self::Value)>, DatabaseError>;
50}
51
52/// The cursor for iterating over hashed storage entries.
53#[auto_impl::auto_impl(&mut)]
54pub trait HashedStorageCursor: HashedCursor {
55    /// Returns `true` if there are no entries for a given key.
56    fn is_storage_empty(&mut self) -> Result<bool, DatabaseError>;
57}