diff --git a/ledger/src/blockstore.rs b/ledger/src/blockstore.rs index ca1be6d196..eaf271dccb 100644 --- a/ledger/src/blockstore.rs +++ b/ledger/src/blockstore.rs @@ -4387,6 +4387,99 @@ pub fn make_many_slot_entries( (shreds, entries) } +// test-only: check that all columns are either empty or start at `min_slot` +pub fn test_all_empty_or_min(blockstore: &Blockstore, min_slot: Slot) { + let condition_met = blockstore + .db + .iter::(IteratorMode::Start) + .unwrap() + .next() + .map(|(slot, _)| slot >= min_slot) + .unwrap_or(true) + & blockstore + .db + .iter::(IteratorMode::Start) + .unwrap() + .next() + .map(|(slot, _)| slot >= min_slot) + .unwrap_or(true) + & blockstore + .db + .iter::(IteratorMode::Start) + .unwrap() + .next() + .map(|((slot, _), _)| slot >= min_slot) + .unwrap_or(true) + & blockstore + .db + .iter::(IteratorMode::Start) + .unwrap() + .next() + .map(|((slot, _), _)| slot >= min_slot) + .unwrap_or(true) + & blockstore + .db + .iter::(IteratorMode::Start) + .unwrap() + .next() + .map(|(slot, _)| slot >= min_slot) + .unwrap_or(true) + & blockstore + .db + .iter::(IteratorMode::Start) + .unwrap() + .next() + .map(|(slot, _)| slot >= min_slot) + .unwrap_or(true) + & blockstore + .db + .iter::(IteratorMode::Start) + .unwrap() + .next() + .map(|((slot, _), _)| slot >= min_slot) + .unwrap_or(true) + & blockstore + .db + .iter::(IteratorMode::Start) + .unwrap() + .next() + .map(|(slot, _)| slot >= min_slot) + .unwrap_or(true) + & blockstore + .db + .iter::(IteratorMode::Start) + .unwrap() + .next() + .map(|(slot, _)| slot >= min_slot) + .unwrap_or(true) + & blockstore + .db + .iter::(IteratorMode::Start) + .unwrap() + .next() + .map(|((primary_index, _, slot), _)| { + slot >= min_slot || (primary_index == 2 && slot == 0) + }) + .unwrap_or(true) + & blockstore + .db + .iter::(IteratorMode::Start) + .unwrap() + .next() + .map(|((primary_index, _, slot, _), _)| { + slot >= min_slot || (primary_index == 2 && slot == 0) + }) + .unwrap_or(true) + & blockstore + .db + .iter::(IteratorMode::Start) + .unwrap() + .next() + .map(|(slot, _)| slot >= min_slot) + .unwrap_or(true); + assert!(condition_met); +} + // used for tests only // Create `num_shreds` shreds for [start_slot, start_slot + num_slot) slots pub fn make_many_slot_shreds( diff --git a/ledger/src/blockstore/blockstore_purge.rs b/ledger/src/blockstore/blockstore_purge.rs index 389bc54c8a..5b53dcdbe8 100644 --- a/ledger/src/blockstore/blockstore_purge.rs +++ b/ledger/src/blockstore/blockstore_purge.rs @@ -426,99 +426,6 @@ pub mod tests { }, }; - // check that all columns are either empty or start at `min_slot` - fn test_all_empty_or_min(blockstore: &Blockstore, min_slot: Slot) { - let condition_met = blockstore - .db - .iter::(IteratorMode::Start) - .unwrap() - .next() - .map(|(slot, _)| slot >= min_slot) - .unwrap_or(true) - & blockstore - .db - .iter::(IteratorMode::Start) - .unwrap() - .next() - .map(|(slot, _)| slot >= min_slot) - .unwrap_or(true) - & blockstore - .db - .iter::(IteratorMode::Start) - .unwrap() - .next() - .map(|((slot, _), _)| slot >= min_slot) - .unwrap_or(true) - & blockstore - .db - .iter::(IteratorMode::Start) - .unwrap() - .next() - .map(|((slot, _), _)| slot >= min_slot) - .unwrap_or(true) - & blockstore - .db - .iter::(IteratorMode::Start) - .unwrap() - .next() - .map(|(slot, _)| slot >= min_slot) - .unwrap_or(true) - & blockstore - .db - .iter::(IteratorMode::Start) - .unwrap() - .next() - .map(|(slot, _)| slot >= min_slot) - .unwrap_or(true) - & blockstore - .db - .iter::(IteratorMode::Start) - .unwrap() - .next() - .map(|((slot, _), _)| slot >= min_slot) - .unwrap_or(true) - & blockstore - .db - .iter::(IteratorMode::Start) - .unwrap() - .next() - .map(|(slot, _)| slot >= min_slot) - .unwrap_or(true) - & blockstore - .db - .iter::(IteratorMode::Start) - .unwrap() - .next() - .map(|(slot, _)| slot >= min_slot) - .unwrap_or(true) - & blockstore - .db - .iter::(IteratorMode::Start) - .unwrap() - .next() - .map(|((primary_index, _, slot), _)| { - slot >= min_slot || (primary_index == 2 && slot == 0) - }) - .unwrap_or(true) - & blockstore - .db - .iter::(IteratorMode::Start) - .unwrap() - .next() - .map(|((primary_index, _, slot, _), _)| { - slot >= min_slot || (primary_index == 2 && slot == 0) - }) - .unwrap_or(true) - & blockstore - .db - .iter::(IteratorMode::Start) - .unwrap() - .next() - .map(|(slot, _)| slot >= min_slot) - .unwrap_or(true); - assert!(condition_met); - } - #[test] fn test_purge_slots() { let ledger_path = get_tmp_ledger_path_auto_delete!(); @@ -545,18 +452,6 @@ pub mod tests { }); } - #[test] - fn test_purge_huge() { - let ledger_path = get_tmp_ledger_path_auto_delete!(); - let blockstore = Blockstore::open(ledger_path.path()).unwrap(); - - let (shreds, _) = make_many_slot_entries(0, 5000, 10); - blockstore.insert_shreds(shreds, None, false).unwrap(); - - blockstore.purge_and_compact_slots(0, 4999); - test_all_empty_or_min(&blockstore, 5000); - } - #[test] fn test_purge_front_of_ledger() { let ledger_path = get_tmp_ledger_path_auto_delete!(); diff --git a/ledger/tests/blockstore.rs b/ledger/tests/blockstore.rs index 73d9bd576b..b2268ee3a2 100644 --- a/ledger/tests/blockstore.rs +++ b/ledger/tests/blockstore.rs @@ -1,7 +1,7 @@ use { solana_entry::entry, solana_ledger::{ - blockstore::{self, Blockstore}, + blockstore::{self, make_many_slot_entries, test_all_empty_or_min, Blockstore}, get_tmp_ledger_path_auto_delete, }, solana_sdk::hash::Hash, @@ -46,3 +46,15 @@ fn test_multiple_threads_insert_shred() { blockstore.purge_and_compact_slots(0, num_threads + 1); } } + +#[test] +fn test_purge_huge() { + let ledger_path = get_tmp_ledger_path_auto_delete!(); + let blockstore = Blockstore::open(ledger_path.path()).unwrap(); + + let (shreds, _) = make_many_slot_entries(0, 5000, 10); + blockstore.insert_shreds(shreds, None, false).unwrap(); + + blockstore.purge_and_compact_slots(0, 4999); + test_all_empty_or_min(&blockstore, 5000); +}