reth_trie_db/
commitment.rs

1use crate::{
2    DatabaseHashedCursorFactory, DatabaseProof, DatabaseStateRoot, DatabaseStorageRoot,
3    DatabaseTrieCursorFactory, DatabaseTrieWitness,
4};
5use reth_db_api::transaction::DbTx;
6use reth_trie::{
7    proof::Proof, witness::TrieWitness, KeccakKeyHasher, KeyHasher, StateRoot, StorageRoot,
8};
9
10/// The `StateCommitment` trait provides associated types for state commitment operations.
11pub trait StateCommitment: std::fmt::Debug + Send + Sync + Unpin + 'static {
12    /// The state root type.
13    type StateRoot<'a, TX: DbTx + 'a>: DatabaseStateRoot<'a, TX>;
14    /// The storage root type.
15    type StorageRoot<'a, TX: DbTx + 'a>: DatabaseStorageRoot<'a, TX>;
16    /// The state proof type.
17    type StateProof<'a, TX: DbTx + 'a>: DatabaseProof<'a, TX>;
18    /// The state witness type.
19    type StateWitness<'a, TX: DbTx + 'a>: DatabaseTrieWitness<'a, TX>;
20    /// The key hasher type.
21    type KeyHasher: KeyHasher;
22}
23
24/// The state commitment type for Ethereum's Merkle Patricia Trie.
25#[derive(Debug)]
26#[non_exhaustive]
27pub struct MerklePatriciaTrie;
28
29impl StateCommitment for MerklePatriciaTrie {
30    type StateRoot<'a, TX: DbTx + 'a> =
31        StateRoot<DatabaseTrieCursorFactory<'a, TX>, DatabaseHashedCursorFactory<'a, TX>>;
32    type StorageRoot<'a, TX: DbTx + 'a> =
33        StorageRoot<DatabaseTrieCursorFactory<'a, TX>, DatabaseHashedCursorFactory<'a, TX>>;
34    type StateProof<'a, TX: DbTx + 'a> =
35        Proof<DatabaseTrieCursorFactory<'a, TX>, DatabaseHashedCursorFactory<'a, TX>>;
36    type StateWitness<'a, TX: DbTx + 'a> =
37        TrieWitness<DatabaseTrieCursorFactory<'a, TX>, DatabaseHashedCursorFactory<'a, TX>>;
38    type KeyHasher = KeccakKeyHasher;
39}