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

Commit

Permalink
Adjust test_purge_transaction_status_exact to test slots that cross p…
Browse files Browse the repository at this point in the history
…rimary indexes
  • Loading branch information
Tyera Eulberg committed Oct 3, 2023
1 parent 3008cd8 commit 2900fe2
Showing 1 changed file with 45 additions and 2 deletions.
47 changes: 45 additions & 2 deletions ledger/src/blockstore/blockstore_purge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ pub mod tests {
blockstore.initialize_transaction_status_index().unwrap();
*blockstore.active_transaction_status_index.write().unwrap() = 0;

for x in 0..index0_max_slot + 1 {
for x in 0..index0_max_slot {
let entries = make_slot_entries_with_transactions(1);
let shreds = entries_to_test_shreds(
&entries,
Expand Down Expand Up @@ -731,6 +731,36 @@ pub mod tests {
)
.unwrap();
}

// Add slot that crosses primary indexes
let entries = make_slot_entries_with_transactions(2);
let shreds = entries_to_test_shreds(
&entries,
index0_max_slot, // slot
index0_max_slot.saturating_sub(1), // parent_slot
true, // is_full_slot
0, // version
true, // merkle_variant
);
blockstore.insert_shreds(shreds, None, false).unwrap();
let signatures = entries
.iter()
.filter(|entry| !entry.is_tick())
.cloned()
.flat_map(|entry| entry.transactions)
.map(|transaction| transaction.signatures[0])
.collect::<Vec<Signature>>();
let random_bytes: Vec<u8> = (0..64).map(|_| rand::random::<u8>()).collect();
blockstore
.write_transaction_status(
index0_max_slot,
signatures[0],
vec![&Pubkey::try_from(&random_bytes[..32]).unwrap()],
vec![&Pubkey::try_from(&random_bytes[32..]).unwrap()],
TransactionStatusMeta::default(),
)
.unwrap();

// Freeze index 0
let mut write_batch = blockstore.db.batch().unwrap();
let mut w_active_transaction_status_index =
Expand All @@ -745,6 +775,19 @@ pub mod tests {
drop(w_active_transaction_status_index);
blockstore.db.write(write_batch).unwrap();

let random_bytes: Vec<u8> = (0..64).map(|_| rand::random::<u8>()).collect();
blockstore
.write_transaction_status(
index0_max_slot,
signatures[1],
vec![&Pubkey::try_from(&random_bytes[..32]).unwrap()],
vec![&Pubkey::try_from(&random_bytes[32..]).unwrap()],
TransactionStatusMeta::default(),
)
.unwrap();

// Note: index0_max_slot exists in both indexes

for x in index0_max_slot + 1..index1_max_slot + 1 {
let entries = make_slot_entries_with_transactions(1);
let shreds = entries_to_test_shreds(
Expand Down Expand Up @@ -998,7 +1041,7 @@ pub mod tests {
for _ in 13..index1_max_slot + 1 {
let entry = status_entry_iterator.next().unwrap().0;
assert_eq!(entry.0, 1);
assert!(entry.2 > 12);
assert!(entry.2 == index0_max_slot || entry.2 > 12);
}
drop(status_entry_iterator);

Expand Down

0 comments on commit 2900fe2

Please sign in to comment.