Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Commit

Permalink
Only delete once by checking the primary-index range
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyera Eulberg committed Oct 3, 2023
1 parent 3eae980 commit 1407813
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions ledger/src/blockstore/blockstore_purge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,15 +354,30 @@ 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 slot_in_index = |slot: Slot| -> Option<u64> {
if slot <= index0.max_slot && (index0.frozen || slot > index1.max_slot) {
Some(0)
} else if slot <= index1.max_slot && (index1.frozen || slot > index0.max_slot) {
Some(1)
} else {
None
}
};

for slot in from_slot..=to_slot {
let primary_index = slot_in_index(slot);
if primary_index.is_none() {
continue;
}
let primary_index = primary_index.unwrap();

let slot_entries = self.get_any_valid_slot_entries(slot, 0);
let transactions = slot_entries
.into_iter()
.flat_map(|entry| entry.transactions);
for transaction in transactions {
if let Some(&signature) = transaction.signatures.get(0) {
batch.delete::<cf::TransactionStatus>((0, signature, slot))?;
batch.delete::<cf::TransactionStatus>((1, signature, slot))?;
batch.delete::<cf::TransactionStatus>((primary_index, signature, slot))?;

let meta = self.read_transaction_status((signature, slot))?;
let loaded_addresses = meta.map(|meta| meta.loaded_addresses);
Expand All @@ -372,8 +387,12 @@ impl Blockstore {
);

for pubkey in account_keys.iter() {
batch.delete::<cf::AddressSignatures>((0, *pubkey, slot, signature))?;
batch.delete::<cf::AddressSignatures>((1, *pubkey, slot, signature))?;
batch.delete::<cf::AddressSignatures>((
primary_index,
*pubkey,
slot,
signature,
))?;
}
}
}
Expand Down

0 comments on commit 1407813

Please sign in to comment.