reth_storage_api/
state_writer.rs

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