reth_provider/traits/
state.rs

1use alloy_primitives::BlockNumber;
2use reth_execution_types::ExecutionOutcome;
3use reth_storage_errors::provider::ProviderResult;
4use reth_trie::HashedPostStateSorted;
5use revm_database::{
6    states::{PlainStateReverts, StateChangeset},
7    OriginalValuesKnown,
8};
9
10use super::StorageLocation;
11
12/// A trait specifically for writing state changes or reverts
13pub trait StateWriter {
14    /// Receipt type included into [`ExecutionOutcome`].
15    type Receipt;
16
17    /// Write the state and receipts to the database or static files if `static_file_producer` is
18    /// `Some`. It should be `None` if there is any kind of pruning/filtering over the receipts.
19    fn write_state(
20        &self,
21        execution_outcome: &ExecutionOutcome<Self::Receipt>,
22        is_value_known: OriginalValuesKnown,
23        write_receipts_to: StorageLocation,
24    ) -> ProviderResult<()>;
25
26    /// Write state reverts to the database.
27    ///
28    /// NOTE: Reverts will delete all wiped storage from plain state.
29    fn write_state_reverts(
30        &self,
31        reverts: PlainStateReverts,
32        first_block: BlockNumber,
33    ) -> ProviderResult<()>;
34
35    /// Write state changes to the database.
36    fn write_state_changes(&self, changes: StateChangeset) -> ProviderResult<()>;
37
38    /// Writes the hashed state changes to the database
39    fn write_hashed_state(&self, hashed_state: &HashedPostStateSorted) -> ProviderResult<()>;
40
41    /// Remove the block range of state above the given block. The state of the passed block is not
42    /// removed.
43    fn remove_state_above(
44        &self,
45        block: BlockNumber,
46        remove_receipts_from: StorageLocation,
47    ) -> ProviderResult<()>;
48
49    /// Take the block range of state, recreating the [`ExecutionOutcome`]. The state of the passed
50    /// block is not removed.
51    fn take_state_above(
52        &self,
53        block: BlockNumber,
54        remove_receipts_from: StorageLocation,
55    ) -> ProviderResult<ExecutionOutcome<Self::Receipt>>;
56}