reth_trie/hashed_cursor/
mod.rs

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