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},
7OriginalValuesKnown,
8};
910use super::StorageLocation;
1112/// A trait specifically for writing state changes or reverts
13pub trait StateWriter {
14/// Receipt type included into [`ExecutionOutcome`].
15type Receipt;
1617/// 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.
19fn write_state(
20&self,
21 execution_outcome: &ExecutionOutcome<Self::Receipt>,
22 is_value_known: OriginalValuesKnown,
23 write_receipts_to: StorageLocation,
24 ) -> ProviderResult<()>;
2526/// Write state reverts to the database.
27 ///
28 /// NOTE: Reverts will delete all wiped storage from plain state.
29fn write_state_reverts(
30&self,
31 reverts: PlainStateReverts,
32 first_block: BlockNumber,
33 ) -> ProviderResult<()>;
3435/// Write state changes to the database.
36fn write_state_changes(&self, changes: StateChangeset) -> ProviderResult<()>;
3738/// Writes the hashed state changes to the database
39fn write_hashed_state(&self, hashed_state: &HashedPostStateSorted) -> ProviderResult<()>;
4041/// Remove the block range of state above the given block. The state of the passed block is not
42 /// removed.
43fn remove_state_above(
44&self,
45 block: BlockNumber,
46 remove_receipts_from: StorageLocation,
47 ) -> ProviderResult<()>;
4849/// Take the block range of state, recreating the [`ExecutionOutcome`]. The state of the passed
50 /// block is not removed.
51fn take_state_above(
52&self,
53 block: BlockNumber,
54 remove_receipts_from: StorageLocation,
55 ) -> ProviderResult<ExecutionOutcome<Self::Receipt>>;
56}