reth_storage_api/
history.rs1use 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#[derive(Debug, Eq, PartialEq)]
11pub enum HistoryInfo {
12 NotYetWritten,
14 InChangeset(BlockNumber),
16 InPlainState,
18 MaybeInPlainState,
20}
21
22#[auto_impl(&, Arc, Box)]
24pub trait HistoryReader: Send {
25 fn account_history_info(
27 &self,
28 address: Address,
29 block_number: BlockNumber,
30 lowest_available_block_number: Option<BlockNumber>,
31 ) -> ProviderResult<HistoryInfo>;
32
33 fn storage_history_info(
35 &self,
36 address: Address,
37 storage_key: B256,
38 block_number: BlockNumber,
39 lowest_available_block_number: Option<BlockNumber>,
40 ) -> ProviderResult<HistoryInfo>;
41}
42
43#[auto_impl(&, Arc, Box)]
45pub trait HistoryWriter: Send {
46 fn unwind_account_history_indices<'a>(
50 &self,
51 changesets: impl Iterator<Item = &'a (BlockNumber, AccountBeforeTx)>,
52 ) -> ProviderResult<usize>;
53
54 fn unwind_account_history_indices_range(
58 &self,
59 range: impl RangeBounds<BlockNumber>,
60 ) -> ProviderResult<usize>;
61
62 fn insert_account_history_index(
64 &self,
65 index_updates: impl IntoIterator<Item = (Address, impl IntoIterator<Item = u64>)>,
66 ) -> ProviderResult<()>;
67
68 fn unwind_storage_history_indices(
72 &self,
73 changesets: impl Iterator<Item = (BlockNumberAddress, StorageEntry)>,
74 ) -> ProviderResult<usize>;
75
76 fn unwind_storage_history_indices_range(
80 &self,
81 range: impl RangeBounds<BlockNumber>,
82 ) -> ProviderResult<usize>;
83
84 fn insert_storage_history_index(
86 &self,
87 storage_transitions: impl IntoIterator<Item = ((Address, B256), impl IntoIterator<Item = u64>)>,
88 ) -> ProviderResult<()>;
89
90 fn update_history_indices(&self, range: RangeInclusive<BlockNumber>) -> ProviderResult<()>;
92}