Skip to content

Commit

Permalink
fix: return correct prune_target_block when syncing (#14181)
Browse files Browse the repository at this point in the history
  • Loading branch information
klkvr authored Feb 4, 2025
1 parent b479b34 commit 740bf04
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions crates/prune/types/src/mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ impl PruneMode {
}
Self::Before(n) if *n == tip + 1 && purpose.is_static_file() => Some((tip, *self)),
Self::Before(n) if *n > tip => None, // Nothing to prune yet
Self::Before(n) if tip - n >= segment.min_blocks(purpose) => {
Some(((*n).saturating_sub(1), *self))
Self::Before(n) => {
(tip - n >= segment.min_blocks(purpose)).then(|| ((*n).saturating_sub(1), *self))
}
_ => return Err(PruneSegmentError::Configuration(segment)),
};
Expand Down Expand Up @@ -113,7 +113,8 @@ mod tests {
PruneMode::Before(tip - MINIMUM_PRUNING_DISTANCE - 1),
Ok(Some(tip - MINIMUM_PRUNING_DISTANCE - 2)),
),
(PruneMode::Before(tip - 1), Err(PruneSegmentError::Configuration(segment))),
// Nothing to prune
(PruneMode::Before(tip - 1), Ok(None)),
];

for (index, (mode, expected_result)) in tests.into_iter().enumerate() {
Expand Down

0 comments on commit 740bf04

Please sign in to comment.