reth_storage_api/
history.rs

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