Skip to content

Commit

Permalink
Blockstore::get_sigs_for_addr2: ensure lowest_slot >= first_available…
Browse files Browse the repository at this point in the history
…_block (#33556)

* Set empty lowest_slot to first_available_block and remove check in loop

* Ensure get_transaction_status on_with_counter returns slots >= first_available_block

* Actually cleanup ledger
  • Loading branch information
CriesofCarrots authored Oct 6, 2023
1 parent 41ed9ab commit f075867
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions ledger/src/blockstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2325,14 +2325,15 @@ impl Blockstore {
confirmed_unrooted_slots: &HashSet<Slot>,
) -> Result<(Option<(Slot, TransactionStatusMeta)>, u64)> {
let mut counter = 0;
let (lock, lowest_available_slot) = self.ensure_lowest_cleanup_slot();
let (lock, _) = self.ensure_lowest_cleanup_slot();
let first_available_block = self.get_first_available_block()?;

for transaction_status_cf_primary_index in 0..=1 {
let index_iterator = self.transaction_status_cf.iter(IteratorMode::From(
(
transaction_status_cf_primary_index,
signature,
lowest_available_slot,
first_available_block,
),
IteratorDirection::Forward,
))?;
Expand Down Expand Up @@ -2630,16 +2631,17 @@ impl Blockstore {
};
get_before_slot_timer.stop();

let first_available_block = self.get_first_available_block()?;
// Generate a HashSet of signatures that should be excluded from the results based on
// `until` signature
let mut get_until_slot_timer = Measure::start("get_until_slot_timer");
let (lowest_slot, until_excluded_signatures) = match until {
None => (0, HashSet::new()),
None => (first_available_block, HashSet::new()),
Some(until) => {
let transaction_status =
self.get_transaction_status(until, &confirmed_unrooted_slots)?;
match transaction_status {
None => (0, HashSet::new()),
None => (first_available_block, HashSet::new()),
Some((slot, _)) => {
let mut slot_signatures = self.get_sorted_block_signatures(slot)?;
if let Some(pos) = slot_signatures.iter().position(|&x| x == until) {
Expand All @@ -2654,7 +2656,6 @@ impl Blockstore {
get_until_slot_timer.stop();

// Fetch the list of signatures that affect the given address
let first_available_block = self.get_first_available_block()?;
let mut address_signatures = vec![];

// Get signatures in `slot`
Expand Down Expand Up @@ -2695,10 +2696,7 @@ impl Blockstore {
if slot == next_max_slot || slot < lowest_slot {
break;
}
if i == starting_primary_index
&& key_address == address
&& slot >= first_available_block
{
if i == starting_primary_index && key_address == address {
if self.is_root(slot) || confirmed_unrooted_slots.contains(&slot) {
address_signatures.push((slot, signature));
}
Expand Down Expand Up @@ -2733,10 +2731,7 @@ impl Blockstore {
if slot < lowest_slot {
break;
}
if i == next_primary_index
&& key_address == address
&& slot >= first_available_block
{
if i == next_primary_index && key_address == address {
if self.is_root(slot) || confirmed_unrooted_slots.contains(&slot) {
address_signatures.push((slot, signature));
}
Expand Down Expand Up @@ -8017,6 +8012,7 @@ pub mod tests {

if simulate_ledger_cleanup_service {
*blockstore.lowest_cleanup_slot.write().unwrap() = lowest_cleanup_slot;
blockstore.purge_slots(0, lowest_cleanup_slot, PurgeType::CompactionFilter);
}

let are_missing = check_for_missing();
Expand Down

0 comments on commit f075867

Please sign in to comment.