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