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