reth_trie/hashed_cursor/
mod.rs

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