Skip to content

Commit

Permalink
Remove all support for deprecated keys from Blockstore::get_signature…
Browse files Browse the repository at this point in the history
…s_for_address2
  • Loading branch information
Tyera Eulberg committed Oct 4, 2023
1 parent 4432621 commit 2a51033
Showing 1 changed file with 30 additions and 147 deletions.
177 changes: 30 additions & 147 deletions ledger/src/blockstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2523,46 +2523,6 @@ impl Blockstore {
Ok(signatures)
}

// Returns all signatures for an address in a particular slot, regardless of whether that slot
// has been rooted. The transactions will be ordered by signature, and NOT by the order in
// which the transactions exist in the block
fn find_address_signatures_for_slot_with_primary_index(
&self,
pubkey: Pubkey,
slot: Slot,
) -> Result<Vec<(Slot, Signature)>> {
let (lock, lowest_available_slot) = self.ensure_lowest_cleanup_slot();
let mut signatures: Vec<(Slot, Signature)> = vec![];
if slot < lowest_available_slot {
return Ok(signatures);
}
for transaction_status_cf_primary_index in 0..=1 {
let index_iterator =
self.address_signatures_cf
.iter_deprecated_index_filtered(IteratorMode::From(
(
transaction_status_cf_primary_index,
pubkey,
slot,
Signature::default(),
),
IteratorDirection::Forward,
))?;
for ((i, address, transaction_slot, signature), _) in index_iterator {
if i != transaction_status_cf_primary_index
|| transaction_slot > slot
|| address != pubkey
{
break;
}
signatures.push((slot, signature));
}
}
drop(lock);
signatures.sort_by(|a, b| a.0.partial_cmp(&b.0).unwrap().then(a.1.cmp(&b.1)));
Ok(signatures)
}

// Returns all signatures for an address in a particular slot, regardless of whether that slot
// has been rooted. The transactions will be ordered by their occurrence in the block
fn find_address_signatures_for_slot(
Expand Down Expand Up @@ -2746,21 +2706,6 @@ impl Blockstore {
}
address_signatures_iter_timer.stop();

let mut deprecated_address_signatures_timer =
Measure::start("deprecated_address_signatures_timer");
if address_signatures.len() < limit {
self.find_deprecated_address_signatures(
&mut address_signatures,
&address,
slot,
lowest_slot,
&confirmed_unrooted_slots,
first_available_block,
limit,
)?;
}
deprecated_address_signatures_timer.stop();

let mut address_signatures: Vec<(Slot, Signature)> = address_signatures
.into_iter()
.filter(|(_, signature)| !until_excluded_signatures.contains(signature))
Expand Down Expand Up @@ -2803,11 +2748,6 @@ impl Blockstore {
address_signatures_iter_timer.as_us() as i64,
i64
),
(
"deprecated_address_signatures_us",
deprecated_address_signatures_timer.as_us() as i64,
i64
),
(
"get_status_info_us",
get_status_info_timer.as_us() as i64,
Expand All @@ -2826,93 +2766,6 @@ impl Blockstore {
})
}

fn find_deprecated_address_signatures(
&self,
address_signatures: &mut Vec<(Slot, Signature)>,
address: &Pubkey,
slot: Slot,
lowest_slot: Slot,
confirmed_unrooted_slots: &HashSet<Slot>,
first_available_block: Slot,
limit: usize,
) -> Result<()> {
// Check the active_transaction_status_index to see if it contains slot. If so, start with
// that index, as it will contain higher slots
let starting_primary_index = *self.active_transaction_status_index.read().unwrap();
let next_primary_index = u64::from(starting_primary_index == 0);
let next_max_slot = self
.transaction_status_index_cf
.get(next_primary_index)?
.unwrap()
.max_slot;

if slot > next_max_slot {
let mut starting_iterator =
self.address_signatures_cf
.iter_deprecated_index_filtered(IteratorMode::From(
(starting_primary_index, *address, slot, Signature::default()),
IteratorDirection::Reverse,
))?;

// Iterate through starting_iterator until limit is reached
while address_signatures.len() < limit {
if let Some(((i, key_address, slot, signature), _)) = starting_iterator.next() {
if slot == next_max_slot || slot < lowest_slot {
break;
}
if i == starting_primary_index
&& key_address == *address
&& slot >= first_available_block
{
if self.is_root(slot) || confirmed_unrooted_slots.contains(&slot) {
address_signatures.push((slot, signature));
}
continue;
}
}
break;
}

// Handle slots that cross primary indexes
if next_max_slot >= lowest_slot {
let mut signatures = self
.find_address_signatures_for_slot_with_primary_index(*address, next_max_slot)?;
signatures.reverse();
address_signatures.append(&mut signatures);
}
}

// Iterate through next_iterator until limit is reached
let mut next_iterator =
self.address_signatures_cf
.iter_deprecated_index_filtered(IteratorMode::From(
(next_primary_index, *address, slot, Signature::default()),
IteratorDirection::Reverse,
))?;
while address_signatures.len() < limit {
if let Some(((i, key_address, slot, signature), _)) = next_iterator.next() {
// Skip next_max_slot, which is already included
if slot == next_max_slot {
continue;
}
if slot < lowest_slot {
break;
}
if i == next_primary_index
&& key_address == *address
&& slot >= first_available_block
{
if self.is_root(slot) || confirmed_unrooted_slots.contains(&slot) {
address_signatures.push((slot, signature));
}
continue;
}
}
break;
}
Ok(())
}

pub fn read_rewards(&self, index: Slot) -> Result<Option<Rewards>> {
self.rewards_cf
.get_protobuf_or_bincode::<Rewards>(index)
Expand Down Expand Up @@ -8618,6 +8471,36 @@ pub mod tests {
let address0 = solana_sdk::pubkey::new_rand();
let address1 = solana_sdk::pubkey::new_rand();

// Add some entries with deprecated keys to demonstrate that `get_signatures_for_address2`
// ignores them
let entries =
make_slot_entries_with_transaction_addresses(&[address0, address1, address0, address1]);
let slot = 1;
let shreds = entries_to_test_shreds(
&entries,
slot,
slot - 1, // parent_slot
true, // is_full_slot
0, // version
true, // merkle_variant
);
blockstore.insert_shreds(shreds, None, false).unwrap();
for entry in entries.into_iter() {
for transaction in entry.transactions {
assert_eq!(transaction.signatures.len(), 1);
blockstore
.write_deprecated_transaction_status(
0,
slot,
transaction.signatures[0],
transaction.message.static_account_keys().iter().collect(),
vec![],
TransactionStatusMeta::default(),
)
.unwrap();
}
}

for slot in 2..=8 {
let entries = make_slot_entries_with_transaction_addresses(&[
address0, address1, address0, address1,
Expand Down

0 comments on commit 2a51033

Please sign in to comment.