Skip to content

Commit 9b81c22

Browse files
authored
feat(pruner): do not prune on first run if not needed (#6823)
1 parent 7249fff commit 9b81c22

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

crates/prune/src/pruner.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -244,15 +244,12 @@ impl<DB: Database> Pruner<DB> {
244244
/// Returns `true` if the pruning is needed at the provided tip block number.
245245
/// This determined by the check against minimum pruning interval and last pruned block number.
246246
pub fn is_pruning_needed(&self, tip_block_number: BlockNumber) -> bool {
247-
if tip_block_number < self.min_block_interval as u64 {
248-
false
249-
} else if self.previous_tip_block_number.map_or(true, |previous_tip_block_number| {
250-
// Saturating subtraction is needed for the case when the chain was reverted, meaning
251-
// current block number might be less than the previous tip block number.
252-
// If that's the case, no pruning is needed as outdated data is also reverted.
253-
tip_block_number.saturating_sub(previous_tip_block_number) >=
254-
self.min_block_interval as u64
255-
}) {
247+
// Saturating subtraction is needed for the case when the chain was reverted, meaning
248+
// current block number might be less than the previous tip block number.
249+
// If that's the case, no pruning is needed as outdated data is also reverted.
250+
if tip_block_number.saturating_sub(self.previous_tip_block_number.unwrap_or_default()) >=
251+
self.min_block_interval as u64
252+
{
256253
debug!(
257254
target: "pruner",
258255
previous_tip_block_number = ?self.previous_tip_block_number,
@@ -283,7 +280,7 @@ mod tests {
283280

284281
// No last pruned block number was set before
285282
let first_block_number = 1;
286-
assert!(pruner.is_pruning_needed(first_block_number));
283+
assert!(!pruner.is_pruning_needed(first_block_number));
287284
pruner.previous_tip_block_number = Some(first_block_number);
288285

289286
// Tip block number delta is >= than min block interval

0 commit comments

Comments
 (0)