From 18dddb0d909609f8dcdea786e7f2729c18bcc263 Mon Sep 17 00:00:00 2001 From: Alexey Shekhirin Date: Tue, 27 Feb 2024 14:37:13 +0000 Subject: [PATCH 1/2] feat(pruner): do not prune on first run if not needed --- crates/prune/src/pruner.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/crates/prune/src/pruner.rs b/crates/prune/src/pruner.rs index df7104b650e9..08e5a0cc1a9e 100644 --- a/crates/prune/src/pruner.rs +++ b/crates/prune/src/pruner.rs @@ -244,13 +244,12 @@ impl Pruner { /// Returns `true` if the pruning is needed at the provided tip block number. /// This determined by the check against minimum pruning interval and last pruned block number. pub fn is_pruning_needed(&self, tip_block_number: BlockNumber) -> bool { - if self.previous_tip_block_number.map_or(true, |previous_tip_block_number| { - // Saturating subtraction is needed for the case when the chain was reverted, meaning - // current block number might be less than the previous tip block number. - // If that's the case, no pruning is needed as outdated data is also reverted. - tip_block_number.saturating_sub(previous_tip_block_number) >= - self.min_block_interval as u64 - }) { + // Saturating subtraction is needed for the case when the chain was reverted, meaning + // current block number might be less than the previous tip block number. + // If that's the case, no pruning is needed as outdated data is also reverted. + if tip_block_number.saturating_sub(self.previous_tip_block_number.unwrap_or_default()) >= + self.min_block_interval as u64 + { debug!( target: "pruner", previous_tip_block_number = ?self.previous_tip_block_number, From 2207920a8a6c9344560d76fbee7e59b3dbf95abe Mon Sep 17 00:00:00 2001 From: Alexey Shekhirin Date: Tue, 27 Feb 2024 14:37:51 +0000 Subject: [PATCH 2/2] test --- crates/prune/src/pruner.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/prune/src/pruner.rs b/crates/prune/src/pruner.rs index 08e5a0cc1a9e..459383204f19 100644 --- a/crates/prune/src/pruner.rs +++ b/crates/prune/src/pruner.rs @@ -280,7 +280,7 @@ mod tests { // No last pruned block number was set before let first_block_number = 1; - assert!(pruner.is_pruning_needed(first_block_number)); + assert!(!pruner.is_pruning_needed(first_block_number)); pruner.previous_tip_block_number = Some(first_block_number); // Tip block number delta is >= than min block interval