reth_storage_api/
history.rs

1use alloy_primitives::{Address, BlockNumber, B256};
2use auto_impl::auto_impl;
3use core::ops::{RangeBounds, RangeInclusive};
4use reth_db_api::models::BlockNumberAddress;
5use reth_db_models::AccountBeforeTx;
6use reth_primitives_traits::StorageEntry;
7use reth_storage_errors::provider::ProviderResult;
8
9/// History Writer
10#[auto_impl(&, Arc, Box)]
11pub trait HistoryWriter: Send + Sync {
12    /// Unwind and clear account history indices.
13    ///
14    /// Returns number of changesets walked.
15    fn unwind_account_history_indices<'a>(
16        &self,
17        changesets: impl Iterator<Item = &'a (BlockNumber, AccountBeforeTx)>,
18    ) -> ProviderResult<usize>;
19
20    /// Unwind and clear account history indices in a given block range.
21    ///
22    /// Returns number of changesets walked.
23    fn unwind_account_history_indices_range(
24        &self,
25        range: impl RangeBounds<BlockNumber>,
26    ) -> ProviderResult<usize>;
27
28    /// Insert account change index to database. Used inside AccountHistoryIndex stage
29    fn insert_account_history_index(
30        &self,
31        index_updates: impl IntoIterator<Item = (Address, impl IntoIterator<Item = u64>)>,
32    ) -> ProviderResult<()>;
33
34    /// Unwind and clear storage history indices.
35    ///
36    /// Returns number of changesets walked.
37    fn unwind_storage_history_indices(
38        &self,
39        changesets: impl Iterator<Item = (BlockNumberAddress, StorageEntry)>,
40    ) -> ProviderResult<usize>;
41
42    /// Unwind and clear storage history indices in a given block range.
43    ///
44    /// Returns number of changesets walked.
45    fn unwind_storage_history_indices_range(
46        &self,
47        range: impl RangeBounds<BlockNumberAddress>,
48    ) -> ProviderResult<usize>;
49
50    /// Insert storage change index to database. Used inside StorageHistoryIndex stage
51    fn insert_storage_history_index(
52        &self,
53        storage_transitions: impl IntoIterator<Item = ((Address, B256), impl IntoIterator<Item = u64>)>,
54    ) -> ProviderResult<()>;
55
56    /// Read account/storage changesets and update account/storage history indices.
57    fn update_history_indices(&self, range: RangeInclusive<BlockNumber>) -> ProviderResult<()>;
58}