Skip to content

Commit

Permalink
Fix off-by-one bug in Blockstore::purge_exact() (solana-labs#33463)
Browse files Browse the repository at this point in the history
  • Loading branch information
steviez authored Sep 29, 2023
1 parent ec2e124 commit 4866789
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions ledger/src/blockstore/blockstore_purge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,7 @@ impl Blockstore {
) -> Result<()> {
let mut index0 = self.transaction_status_index_cf.get(0)?.unwrap_or_default();
let mut index1 = self.transaction_status_index_cf.get(1)?.unwrap_or_default();
let to_slot = to_slot.saturating_add(1);
for slot in from_slot..to_slot {
for slot in from_slot..=to_slot {
let slot_entries = self.get_any_valid_slot_entries(slot, 0);
let transactions = slot_entries
.into_iter()
Expand Down Expand Up @@ -1100,6 +1099,27 @@ pub mod tests {
assert_eq!(entry.0, 2); // Buffer entry, no index 1 entries remaining
drop(status_entry_iterator);

// Purge up to but not including index0_max_slot
clear_and_repopulate_transaction_statuses_for_test(
&blockstore,
index0_max_slot,
index1_max_slot,
);
blockstore
.run_purge(0, index0_max_slot - 1, PurgeType::Exact)
.unwrap();
assert_eq!(
blockstore
.transaction_status_index_cf
.get(0)
.unwrap()
.unwrap(),
TransactionStatusIndexMeta {
max_slot: index0_max_slot,
frozen: true,
}
);

// Test purge all
clear_and_repopulate_transaction_statuses_for_test(
&blockstore,
Expand Down

0 comments on commit 4866789

Please sign in to comment.