diff --git a/crates/stages/src/stages/execution.rs b/crates/stages/src/stages/execution.rs index ac48a2aeb..7f22ecaef 100644 --- a/crates/stages/src/stages/execution.rs +++ b/crates/stages/src/stages/execution.rs @@ -60,7 +60,7 @@ use tracing::*; /// to [tables::PlainStorageState] // false positive, we cannot derive it if !DB: Debug. #[allow(missing_debug_implementations)] -pub struct ExecutionStage { +pub struct ExecutionStage { metrics_tx: Option, /// The stage's internal executor executor_factory: EF, @@ -77,7 +77,7 @@ pub struct ExecutionStage { exex_manager_handle: ExExManagerHandle, } -impl ExecutionStage { +impl ExecutionStage { /// Create new execution stage with specified config. pub fn new( executor_factory: EF, @@ -115,6 +115,37 @@ impl ExecutionStage { self } + /// Adjusts the prune modes related to changesets. + /// + /// This function verifies whether the [`super::MerkleStage`] or Hashing stages will run from + /// scratch. If at least one stage isn't starting anew, it implies that pruning of + /// changesets cannot occur. This is determined by checking the highest clean threshold + /// (`self.external_clean_threshold`) across the stages. + /// + /// Given that `start_block` changes with each checkpoint, it's necessary to inspect + /// [`tables::AccountsTrie`] to ensure that [`super::MerkleStage`] hasn't + /// been previously executed. + fn adjust_prune_modes( + &self, + provider: &DatabaseProviderRW, + start_block: u64, + max_block: u64, + ) -> Result { + let mut prune_modes = self.prune_modes.clone(); + + // If we're not executing MerkleStage from scratch (by threshold or first-sync), then erase + // changeset related pruning configurations + if !(max_block - start_block > self.external_clean_threshold || + provider.count_entries::()?.is_zero()) + { + prune_modes.account_history = None; + prune_modes.storage_history = None; + } + Ok(prune_modes) + } +} + +impl ExecutionStage { /// Execute the stage. pub fn execute_inner( &mut self, @@ -261,35 +292,6 @@ impl ExecutionStage { done, }) } - - /// Adjusts the prune modes related to changesets. - /// - /// This function verifies whether the [`super::MerkleStage`] or Hashing stages will run from - /// scratch. If at least one stage isn't starting anew, it implies that pruning of - /// changesets cannot occur. This is determined by checking the highest clean threshold - /// (`self.external_clean_threshold`) across the stages. - /// - /// Given that `start_block` changes with each checkpoint, it's necessary to inspect - /// [`tables::AccountsTrie`] to ensure that [`super::MerkleStage`] hasn't - /// been previously executed. - fn adjust_prune_modes( - &self, - provider: &DatabaseProviderRW, - start_block: u64, - max_block: u64, - ) -> Result { - let mut prune_modes = self.prune_modes.clone(); - - // If we're not executing MerkleStage from scratch (by threshold or first-sync), then erase - // changeset related pruning configurations - if !(max_block - start_block > self.external_clean_threshold || - provider.count_entries::()?.is_zero()) - { - prune_modes.account_history = None; - prune_modes.storage_history = None; - } - Ok(prune_modes) - } } fn execution_checkpoint(