Skip to main content

reth_storage_api/
hashing.rs

1use crate::ChangesetEntry;
2use alloc::collections::{BTreeMap, BTreeSet};
3use alloy_primitives::{map::B256Map, Address, BlockNumber, B256};
4use auto_impl::auto_impl;
5use core::ops::RangeBounds;
6use reth_db_api::models::BlockNumberAddress;
7use reth_db_models::AccountBeforeTx;
8use reth_primitives_traits::{Account, StorageEntry};
9use reth_storage_errors::provider::ProviderResult;
10
11/// Hashing Writer
12#[auto_impl(&, Box)]
13pub trait HashingWriter: Send {
14    /// Unwind and clear account hashing.
15    ///
16    /// # Returns
17    ///
18    /// Set of hashed keys of updated accounts.
19    fn unwind_account_hashing<'a>(
20        &self,
21        changesets: impl Iterator<Item = &'a (BlockNumber, AccountBeforeTx)>,
22    ) -> ProviderResult<BTreeMap<B256, Option<Account>>>;
23
24    /// Unwind and clear account hashing in a given block range.
25    ///
26    /// # Returns
27    ///
28    /// Set of hashed keys of updated accounts.
29    fn unwind_account_hashing_range(
30        &self,
31        range: impl RangeBounds<BlockNumber>,
32    ) -> ProviderResult<BTreeMap<B256, Option<Account>>>;
33
34    /// Inserts all accounts into [`AccountsHistory`][reth_db_api::tables::AccountsHistory] table.
35    ///
36    /// # Returns
37    ///
38    /// Set of hashed keys of updated accounts.
39    fn insert_account_for_hashing(
40        &self,
41        accounts: impl IntoIterator<Item = (Address, Option<Account>)>,
42    ) -> ProviderResult<BTreeMap<B256, Option<Account>>>;
43
44    /// Unwind and clear storage hashing.
45    ///
46    /// # Returns
47    ///
48    /// Mapping of hashed keys of updated accounts to their respective updated hashed slots.
49    fn unwind_storage_hashing(
50        &self,
51        changesets: impl Iterator<Item = (BlockNumberAddress, ChangesetEntry)>,
52    ) -> ProviderResult<B256Map<BTreeSet<B256>>>;
53
54    /// Unwind and clear storage hashing in a given block range.
55    ///
56    /// # Returns
57    ///
58    /// Mapping of hashed keys of updated accounts to their respective updated hashed slots.
59    fn unwind_storage_hashing_range(
60        &self,
61        range: impl RangeBounds<BlockNumber>,
62    ) -> ProviderResult<B256Map<BTreeSet<B256>>>;
63
64    /// Iterates over storages and inserts them to hashing table.
65    ///
66    /// # Returns
67    ///
68    /// Mapping of hashed keys of updated accounts to their respective updated hashed slots.
69    fn insert_storage_for_hashing(
70        &self,
71        storages: impl IntoIterator<Item = (Address, impl IntoIterator<Item = StorageEntry>)>,
72    ) -> ProviderResult<B256Map<BTreeSet<B256>>>;
73}