Blockstore test cleanup (#19656)
* Use auto-deleting macro for ledger path
This commit is contained in:
@ -79,8 +79,8 @@ mod tests {
|
|||||||
use std::{collections::HashMap, path::Path};
|
use std::{collections::HashMap, path::Path};
|
||||||
use trees::tr;
|
use trees::tr;
|
||||||
|
|
||||||
fn setup_forks(blockstore_path: &Path) -> Blockstore {
|
fn setup_forks(ledger_path: &Path) -> Blockstore {
|
||||||
let blockstore = Blockstore::open(blockstore_path).unwrap();
|
let blockstore = Blockstore::open(ledger_path).unwrap();
|
||||||
/*
|
/*
|
||||||
Build fork structure:
|
Build fork structure:
|
||||||
|
|
||||||
@ -102,9 +102,8 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_ancestor_iterator() {
|
fn test_ancestor_iterator() {
|
||||||
let blockstore_path = get_tmp_ledger_path!();
|
let ledger_path = get_tmp_ledger_path_auto_delete!();
|
||||||
{
|
let blockstore = setup_forks(ledger_path.path());
|
||||||
let blockstore = setup_forks(&blockstore_path);
|
|
||||||
|
|
||||||
// Test correctness
|
// Test correctness
|
||||||
assert!(AncestorIterator::new(0, &blockstore).next().is_none());
|
assert!(AncestorIterator::new(0, &blockstore).next().is_none());
|
||||||
@ -117,13 +116,11 @@ mod tests {
|
|||||||
vec![2, 1, 0]
|
vec![2, 1, 0]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Blockstore::destroy(&blockstore_path).unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_ancestor_iterator_inclusive() {
|
fn test_ancestor_iterator_inclusive() {
|
||||||
let blockstore_path = get_tmp_ledger_path!();
|
let ledger_path = get_tmp_ledger_path_auto_delete!();
|
||||||
let blockstore = Blockstore::open(&blockstore_path).unwrap();
|
let blockstore = Blockstore::open(ledger_path.path()).unwrap();
|
||||||
|
|
||||||
let (shreds, _) = make_slot_entries(0, 0, 42);
|
let (shreds, _) = make_slot_entries(0, 0, 42);
|
||||||
blockstore.insert_shreds(shreds, None, false).unwrap();
|
blockstore.insert_shreds(shreds, None, false).unwrap();
|
||||||
@ -151,9 +148,8 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_ancestor_iterator_with_hash() {
|
fn test_ancestor_iterator_with_hash() {
|
||||||
let blockstore_path = get_tmp_ledger_path!();
|
let ledger_path = get_tmp_ledger_path_auto_delete!();
|
||||||
{
|
let blockstore = setup_forks(ledger_path.path());
|
||||||
let blockstore = setup_forks(&blockstore_path);
|
|
||||||
|
|
||||||
// Insert frozen hashes
|
// Insert frozen hashes
|
||||||
let mut slot_to_bank_hash = HashMap::new();
|
let mut slot_to_bank_hash = HashMap::new();
|
||||||
@ -184,6 +180,4 @@ mod tests {
|
|||||||
]
|
]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Blockstore::destroy(&blockstore_path).unwrap();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -393,7 +393,9 @@ impl Blockstore {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub mod tests {
|
pub mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::{blockstore::tests::make_slot_entries_with_transactions, get_tmp_ledger_path};
|
use crate::{
|
||||||
|
blockstore::tests::make_slot_entries_with_transactions, get_tmp_ledger_path_auto_delete,
|
||||||
|
};
|
||||||
use bincode::serialize;
|
use bincode::serialize;
|
||||||
use solana_entry::entry::next_entry_mut;
|
use solana_entry::entry::next_entry_mut;
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
@ -497,8 +499,9 @@ pub mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_purge_slots() {
|
fn test_purge_slots() {
|
||||||
let blockstore_path = get_tmp_ledger_path!();
|
let ledger_path = get_tmp_ledger_path_auto_delete!();
|
||||||
let blockstore = Blockstore::open(&blockstore_path).unwrap();
|
let blockstore = Blockstore::open(ledger_path.path()).unwrap();
|
||||||
|
|
||||||
let (shreds, _) = make_many_slot_entries(0, 50, 5);
|
let (shreds, _) = make_many_slot_entries(0, 50, 5);
|
||||||
blockstore.insert_shreds(shreds, None, false).unwrap();
|
blockstore.insert_shreds(shreds, None, false).unwrap();
|
||||||
|
|
||||||
@ -518,31 +521,25 @@ pub mod tests {
|
|||||||
.for_each(|(_, _)| {
|
.for_each(|(_, _)| {
|
||||||
panic!();
|
panic!();
|
||||||
});
|
});
|
||||||
|
|
||||||
drop(blockstore);
|
|
||||||
Blockstore::destroy(&blockstore_path).expect("Expected successful database destruction");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_purge_huge() {
|
fn test_purge_huge() {
|
||||||
let blockstore_path = get_tmp_ledger_path!();
|
let ledger_path = get_tmp_ledger_path_auto_delete!();
|
||||||
let blockstore = Blockstore::open(&blockstore_path).unwrap();
|
let blockstore = Blockstore::open(ledger_path.path()).unwrap();
|
||||||
|
|
||||||
let (shreds, _) = make_many_slot_entries(0, 5000, 10);
|
let (shreds, _) = make_many_slot_entries(0, 5000, 10);
|
||||||
blockstore.insert_shreds(shreds, None, false).unwrap();
|
blockstore.insert_shreds(shreds, None, false).unwrap();
|
||||||
|
|
||||||
blockstore.purge_and_compact_slots(0, 4999);
|
blockstore.purge_and_compact_slots(0, 4999);
|
||||||
|
|
||||||
test_all_empty_or_min(&blockstore, 5000);
|
test_all_empty_or_min(&blockstore, 5000);
|
||||||
|
|
||||||
drop(blockstore);
|
|
||||||
Blockstore::destroy(&blockstore_path).expect("Expected successful database destruction");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_purge_front_of_ledger() {
|
fn test_purge_front_of_ledger() {
|
||||||
let blockstore_path = get_tmp_ledger_path!();
|
let ledger_path = get_tmp_ledger_path_auto_delete!();
|
||||||
{
|
let blockstore = Blockstore::open(ledger_path.path()).unwrap();
|
||||||
let blockstore = Blockstore::open(&blockstore_path).unwrap();
|
|
||||||
let max_slot = 10;
|
let max_slot = 10;
|
||||||
for x in 0..max_slot {
|
for x in 0..max_slot {
|
||||||
let random_bytes: Vec<u8> = (0..64).map(|_| rand::random::<u8>()).collect();
|
let random_bytes: Vec<u8> = (0..64).map(|_| rand::random::<u8>()).collect();
|
||||||
@ -585,16 +582,14 @@ pub mod tests {
|
|||||||
let entry = status_entry_iterator.next().unwrap().0;
|
let entry = status_entry_iterator.next().unwrap().0;
|
||||||
assert_eq!(entry.0, 0);
|
assert_eq!(entry.0, 0);
|
||||||
}
|
}
|
||||||
Blockstore::destroy(&blockstore_path).expect("Expected successful database destruction");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[allow(clippy::cognitive_complexity)]
|
#[allow(clippy::cognitive_complexity)]
|
||||||
fn test_purge_transaction_status() {
|
fn test_purge_transaction_status() {
|
||||||
let blockstore_path = get_tmp_ledger_path!();
|
let ledger_path = get_tmp_ledger_path_auto_delete!();
|
||||||
{
|
let blockstore = Blockstore::open(ledger_path.path()).unwrap();
|
||||||
let blockstore = Blockstore::open(&blockstore_path).unwrap();
|
|
||||||
let transaction_status_index_cf = blockstore.db.column::<cf::TransactionStatusIndex>();
|
let transaction_status_index_cf = &blockstore.transaction_status_index_cf;
|
||||||
let slot = 10;
|
let slot = 10;
|
||||||
for _ in 0..5 {
|
for _ in 0..5 {
|
||||||
let random_bytes: Vec<u8> = (0..64).map(|_| rand::random::<u8>()).collect();
|
let random_bytes: Vec<u8> = (0..64).map(|_| rand::random::<u8>()).collect();
|
||||||
@ -641,6 +636,8 @@ pub mod tests {
|
|||||||
frozen: true,
|
frozen: true,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
drop(status_entry_iterator);
|
||||||
|
drop(address_transactions_iterator);
|
||||||
|
|
||||||
// Low purge should not affect state
|
// Low purge should not affect state
|
||||||
blockstore.run_purge(0, 5, PurgeType::PrimaryIndex).unwrap();
|
blockstore.run_purge(0, 5, PurgeType::PrimaryIndex).unwrap();
|
||||||
@ -675,6 +672,8 @@ pub mod tests {
|
|||||||
frozen: true,
|
frozen: true,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
drop(status_entry_iterator);
|
||||||
|
drop(address_transactions_iterator);
|
||||||
|
|
||||||
// Test boundary conditions: < slot should not purge statuses; <= slot should
|
// Test boundary conditions: < slot should not purge statuses; <= slot should
|
||||||
blockstore.run_purge(0, 9, PurgeType::PrimaryIndex).unwrap();
|
blockstore.run_purge(0, 9, PurgeType::PrimaryIndex).unwrap();
|
||||||
@ -709,6 +708,8 @@ pub mod tests {
|
|||||||
frozen: true,
|
frozen: true,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
drop(status_entry_iterator);
|
||||||
|
drop(address_transactions_iterator);
|
||||||
|
|
||||||
blockstore
|
blockstore
|
||||||
.run_purge(0, 10, PurgeType::PrimaryIndex)
|
.run_purge(0, 10, PurgeType::PrimaryIndex)
|
||||||
@ -750,8 +751,6 @@ pub mod tests {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Blockstore::destroy(&blockstore_path).expect("Expected successful database destruction");
|
|
||||||
}
|
|
||||||
|
|
||||||
fn clear_and_repopulate_transaction_statuses(
|
fn clear_and_repopulate_transaction_statuses(
|
||||||
blockstore: &mut Blockstore,
|
blockstore: &mut Blockstore,
|
||||||
@ -860,9 +859,9 @@ pub mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
#[allow(clippy::cognitive_complexity)]
|
#[allow(clippy::cognitive_complexity)]
|
||||||
fn test_purge_transaction_status_exact() {
|
fn test_purge_transaction_status_exact() {
|
||||||
let blockstore_path = get_tmp_ledger_path!();
|
let ledger_path = get_tmp_ledger_path_auto_delete!();
|
||||||
{
|
let mut blockstore = Blockstore::open(ledger_path.path()).unwrap();
|
||||||
let mut blockstore = Blockstore::open(&blockstore_path).unwrap();
|
|
||||||
let index0_max_slot = 9;
|
let index0_max_slot = 9;
|
||||||
let index1_max_slot = 19;
|
let index1_max_slot = 19;
|
||||||
|
|
||||||
@ -1197,16 +1196,12 @@ pub mod tests {
|
|||||||
);
|
);
|
||||||
let entry = status_entry_iterator.next().unwrap().0;
|
let entry = status_entry_iterator.next().unwrap().0;
|
||||||
assert_eq!(entry.0, 2); // Buffer entry, no index 0 or index 1 entries remaining
|
assert_eq!(entry.0, 2); // Buffer entry, no index 0 or index 1 entries remaining
|
||||||
drop(status_entry_iterator);
|
|
||||||
}
|
|
||||||
Blockstore::destroy(&blockstore_path).expect("Expected successful database destruction");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_purge_special_columns_exact_no_sigs() {
|
fn test_purge_special_columns_exact_no_sigs() {
|
||||||
let blockstore_path = get_tmp_ledger_path!();
|
let ledger_path = get_tmp_ledger_path_auto_delete!();
|
||||||
{
|
let blockstore = Blockstore::open(ledger_path.path()).unwrap();
|
||||||
let blockstore = Blockstore::open(&blockstore_path).unwrap();
|
|
||||||
|
|
||||||
let slot = 1;
|
let slot = 1;
|
||||||
let mut entries: Vec<Entry> = vec![];
|
let mut entries: Vec<Entry> = vec![];
|
||||||
@ -1225,6 +1220,4 @@ pub mod tests {
|
|||||||
.purge_special_columns_exact(&mut write_batch, slot, slot + 1)
|
.purge_special_columns_exact(&mut write_batch, slot, slot + 1)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
Blockstore::destroy(&blockstore_path).expect("Expected successful database destruction");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1522,9 +1522,8 @@ pub mod tests {
|
|||||||
genesis_config.poh_config.hashes_per_tick = Some(hashes_per_tick);
|
genesis_config.poh_config.hashes_per_tick = Some(hashes_per_tick);
|
||||||
let ticks_per_slot = genesis_config.ticks_per_slot;
|
let ticks_per_slot = genesis_config.ticks_per_slot;
|
||||||
|
|
||||||
let (ledger_path, blockhash) = create_new_tmp_ledger!(&genesis_config);
|
let (ledger_path, blockhash) = create_new_tmp_ledger_auto_delete!(&genesis_config);
|
||||||
let blockstore =
|
let blockstore = Blockstore::open(ledger_path.path()).unwrap();
|
||||||
Blockstore::open(&ledger_path).expect("Expected to successfully open database ledger");
|
|
||||||
|
|
||||||
let parent_slot = 0;
|
let parent_slot = 0;
|
||||||
let slot = 1;
|
let slot = 1;
|
||||||
@ -1563,8 +1562,8 @@ pub mod tests {
|
|||||||
let ticks_per_slot = genesis_config.ticks_per_slot;
|
let ticks_per_slot = genesis_config.ticks_per_slot;
|
||||||
|
|
||||||
// Create a new ledger with slot 0 full of ticks
|
// Create a new ledger with slot 0 full of ticks
|
||||||
let (ledger_path, blockhash) = create_new_tmp_ledger!(&genesis_config);
|
let (ledger_path, blockhash) = create_new_tmp_ledger_auto_delete!(&genesis_config);
|
||||||
let blockstore = Blockstore::open(&ledger_path).unwrap();
|
let blockstore = Blockstore::open(ledger_path.path()).unwrap();
|
||||||
|
|
||||||
// Write slot 1 with one tick missing
|
// Write slot 1 with one tick missing
|
||||||
let parent_slot = 0;
|
let parent_slot = 0;
|
||||||
@ -1626,8 +1625,8 @@ pub mod tests {
|
|||||||
} = create_genesis_config(10_000);
|
} = create_genesis_config(10_000);
|
||||||
let ticks_per_slot = genesis_config.ticks_per_slot;
|
let ticks_per_slot = genesis_config.ticks_per_slot;
|
||||||
|
|
||||||
let (ledger_path, blockhash) = create_new_tmp_ledger!(&genesis_config);
|
let (ledger_path, blockhash) = create_new_tmp_ledger_auto_delete!(&genesis_config);
|
||||||
let blockstore = Blockstore::open(&ledger_path).unwrap();
|
let blockstore = Blockstore::open(ledger_path.path()).unwrap();
|
||||||
|
|
||||||
let mut entries = create_ticks(ticks_per_slot, 0, blockhash);
|
let mut entries = create_ticks(ticks_per_slot, 0, blockhash);
|
||||||
let trailing_entry = {
|
let trailing_entry = {
|
||||||
@ -1685,11 +1684,10 @@ pub mod tests {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// Create a new ledger with slot 0 full of ticks
|
// Create a new ledger with slot 0 full of ticks
|
||||||
let (ledger_path, mut blockhash) = create_new_tmp_ledger!(&genesis_config);
|
let (ledger_path, mut blockhash) = create_new_tmp_ledger_auto_delete!(&genesis_config);
|
||||||
debug!("ledger_path: {:?}", ledger_path);
|
debug!("ledger_path: {:?}", ledger_path);
|
||||||
|
|
||||||
let blockstore =
|
let blockstore = Blockstore::open(ledger_path.path()).unwrap();
|
||||||
Blockstore::open(&ledger_path).expect("Expected to successfully open database ledger");
|
|
||||||
|
|
||||||
// Write slot 1
|
// Write slot 1
|
||||||
// slot 1, points at slot 0. Missing one tick
|
// slot 1, points at slot 0. Missing one tick
|
||||||
@ -1759,7 +1757,7 @@ pub mod tests {
|
|||||||
let ticks_per_slot = genesis_config.ticks_per_slot;
|
let ticks_per_slot = genesis_config.ticks_per_slot;
|
||||||
|
|
||||||
// Create a new ledger with slot 0 full of ticks
|
// Create a new ledger with slot 0 full of ticks
|
||||||
let (ledger_path, blockhash) = create_new_tmp_ledger!(&genesis_config);
|
let (ledger_path, blockhash) = create_new_tmp_ledger_auto_delete!(&genesis_config);
|
||||||
debug!("ledger_path: {:?}", ledger_path);
|
debug!("ledger_path: {:?}", ledger_path);
|
||||||
let mut last_entry_hash = blockhash;
|
let mut last_entry_hash = blockhash;
|
||||||
|
|
||||||
@ -1777,8 +1775,7 @@ pub mod tests {
|
|||||||
slot 4 <-- set_root(true)
|
slot 4 <-- set_root(true)
|
||||||
|
|
||||||
*/
|
*/
|
||||||
let blockstore =
|
let blockstore = Blockstore::open(ledger_path.path()).unwrap();
|
||||||
Blockstore::open(&ledger_path).expect("Expected to successfully open database ledger");
|
|
||||||
|
|
||||||
// Fork 1, ending at slot 3
|
// Fork 1, ending at slot 3
|
||||||
let last_slot1_entry_hash =
|
let last_slot1_entry_hash =
|
||||||
@ -1838,7 +1835,7 @@ pub mod tests {
|
|||||||
let ticks_per_slot = genesis_config.ticks_per_slot;
|
let ticks_per_slot = genesis_config.ticks_per_slot;
|
||||||
|
|
||||||
// Create a new ledger with slot 0 full of ticks
|
// Create a new ledger with slot 0 full of ticks
|
||||||
let (ledger_path, blockhash) = create_new_tmp_ledger!(&genesis_config);
|
let (ledger_path, blockhash) = create_new_tmp_ledger_auto_delete!(&genesis_config);
|
||||||
debug!("ledger_path: {:?}", ledger_path);
|
debug!("ledger_path: {:?}", ledger_path);
|
||||||
let mut last_entry_hash = blockhash;
|
let mut last_entry_hash = blockhash;
|
||||||
|
|
||||||
@ -1856,8 +1853,7 @@ pub mod tests {
|
|||||||
slot 4
|
slot 4
|
||||||
|
|
||||||
*/
|
*/
|
||||||
let blockstore =
|
let blockstore = Blockstore::open(ledger_path.path()).unwrap();
|
||||||
Blockstore::open(&ledger_path).expect("Expected to successfully open database ledger");
|
|
||||||
|
|
||||||
// Fork 1, ending at slot 3
|
// Fork 1, ending at slot 3
|
||||||
let last_slot1_entry_hash =
|
let last_slot1_entry_hash =
|
||||||
@ -1926,7 +1922,7 @@ pub mod tests {
|
|||||||
|
|
||||||
let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(10_000);
|
let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(10_000);
|
||||||
let ticks_per_slot = genesis_config.ticks_per_slot;
|
let ticks_per_slot = genesis_config.ticks_per_slot;
|
||||||
let (ledger_path, blockhash) = create_new_tmp_ledger!(&genesis_config);
|
let (ledger_path, blockhash) = create_new_tmp_ledger_auto_delete!(&genesis_config);
|
||||||
debug!("ledger_path: {:?}", ledger_path);
|
debug!("ledger_path: {:?}", ledger_path);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1939,7 +1935,7 @@ pub mod tests {
|
|||||||
\
|
\
|
||||||
slot 3
|
slot 3
|
||||||
*/
|
*/
|
||||||
let blockstore = Blockstore::open(&ledger_path).unwrap();
|
let blockstore = Blockstore::open(ledger_path.path()).unwrap();
|
||||||
let slot1_blockhash =
|
let slot1_blockhash =
|
||||||
fill_blockstore_slot_with_ticks(&blockstore, ticks_per_slot, 1, 0, blockhash);
|
fill_blockstore_slot_with_ticks(&blockstore, ticks_per_slot, 1, 0, blockhash);
|
||||||
fill_blockstore_slot_with_ticks(&blockstore, ticks_per_slot, 2, 1, slot1_blockhash);
|
fill_blockstore_slot_with_ticks(&blockstore, ticks_per_slot, 2, 1, slot1_blockhash);
|
||||||
@ -1968,7 +1964,7 @@ pub mod tests {
|
|||||||
|
|
||||||
let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(10_000);
|
let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(10_000);
|
||||||
let ticks_per_slot = genesis_config.ticks_per_slot;
|
let ticks_per_slot = genesis_config.ticks_per_slot;
|
||||||
let (ledger_path, blockhash) = create_new_tmp_ledger!(&genesis_config);
|
let (ledger_path, blockhash) = create_new_tmp_ledger_auto_delete!(&genesis_config);
|
||||||
debug!("ledger_path: {:?}", ledger_path);
|
debug!("ledger_path: {:?}", ledger_path);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1981,7 +1977,7 @@ pub mod tests {
|
|||||||
/ \
|
/ \
|
||||||
slot 4 (dead) slot 3
|
slot 4 (dead) slot 3
|
||||||
*/
|
*/
|
||||||
let blockstore = Blockstore::open(&ledger_path).unwrap();
|
let blockstore = Blockstore::open(ledger_path.path()).unwrap();
|
||||||
let slot1_blockhash =
|
let slot1_blockhash =
|
||||||
fill_blockstore_slot_with_ticks(&blockstore, ticks_per_slot, 1, 0, blockhash);
|
fill_blockstore_slot_with_ticks(&blockstore, ticks_per_slot, 1, 0, blockhash);
|
||||||
let slot2_blockhash =
|
let slot2_blockhash =
|
||||||
@ -2023,7 +2019,7 @@ pub mod tests {
|
|||||||
|
|
||||||
let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(10_000);
|
let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(10_000);
|
||||||
let ticks_per_slot = genesis_config.ticks_per_slot;
|
let ticks_per_slot = genesis_config.ticks_per_slot;
|
||||||
let (ledger_path, blockhash) = create_new_tmp_ledger!(&genesis_config);
|
let (ledger_path, blockhash) = create_new_tmp_ledger_auto_delete!(&genesis_config);
|
||||||
debug!("ledger_path: {:?}", ledger_path);
|
debug!("ledger_path: {:?}", ledger_path);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -2032,7 +2028,7 @@ pub mod tests {
|
|||||||
/ \
|
/ \
|
||||||
slot 1 (dead) slot 2 (dead)
|
slot 1 (dead) slot 2 (dead)
|
||||||
*/
|
*/
|
||||||
let blockstore = Blockstore::open(&ledger_path).unwrap();
|
let blockstore = Blockstore::open(ledger_path.path()).unwrap();
|
||||||
fill_blockstore_slot_with_ticks(&blockstore, ticks_per_slot, 1, 0, blockhash);
|
fill_blockstore_slot_with_ticks(&blockstore, ticks_per_slot, 1, 0, blockhash);
|
||||||
fill_blockstore_slot_with_ticks(&blockstore, ticks_per_slot, 2, 0, blockhash);
|
fill_blockstore_slot_with_ticks(&blockstore, ticks_per_slot, 2, 0, blockhash);
|
||||||
blockstore.set_dead_slot(1).unwrap();
|
blockstore.set_dead_slot(1).unwrap();
|
||||||
@ -2053,11 +2049,10 @@ pub mod tests {
|
|||||||
let ticks_per_slot = genesis_config.ticks_per_slot;
|
let ticks_per_slot = genesis_config.ticks_per_slot;
|
||||||
|
|
||||||
// Create a new ledger with slot 0 full of ticks
|
// Create a new ledger with slot 0 full of ticks
|
||||||
let (ledger_path, blockhash) = create_new_tmp_ledger!(&genesis_config);
|
let (ledger_path, blockhash) = create_new_tmp_ledger_auto_delete!(&genesis_config);
|
||||||
let mut last_entry_hash = blockhash;
|
let mut last_entry_hash = blockhash;
|
||||||
|
|
||||||
let blockstore =
|
let blockstore = Blockstore::open(ledger_path.path()).unwrap();
|
||||||
Blockstore::open(&ledger_path).expect("Expected to successfully open database ledger");
|
|
||||||
|
|
||||||
// Let `last_slot` be the number of slots in the first two epochs
|
// Let `last_slot` be the number of slots in the first two epochs
|
||||||
let epoch_schedule = get_epoch_schedule(&genesis_config, Vec::new());
|
let epoch_schedule = get_epoch_schedule(&genesis_config, Vec::new());
|
||||||
@ -2178,7 +2173,8 @@ pub mod tests {
|
|||||||
..
|
..
|
||||||
} = create_genesis_config_with_leader(mint, &leader_pubkey, 50);
|
} = create_genesis_config_with_leader(mint, &leader_pubkey, 50);
|
||||||
genesis_config.poh_config.hashes_per_tick = Some(hashes_per_tick);
|
genesis_config.poh_config.hashes_per_tick = Some(hashes_per_tick);
|
||||||
let (ledger_path, mut last_entry_hash) = create_new_tmp_ledger!(&genesis_config);
|
let (ledger_path, mut last_entry_hash) =
|
||||||
|
create_new_tmp_ledger_auto_delete!(&genesis_config);
|
||||||
debug!("ledger_path: {:?}", ledger_path);
|
debug!("ledger_path: {:?}", ledger_path);
|
||||||
|
|
||||||
let deducted_from_mint = 3;
|
let deducted_from_mint = 3;
|
||||||
@ -2212,8 +2208,7 @@ pub mod tests {
|
|||||||
));
|
));
|
||||||
let last_blockhash = entries.last().unwrap().hash;
|
let last_blockhash = entries.last().unwrap().hash;
|
||||||
|
|
||||||
let blockstore =
|
let blockstore = Blockstore::open(ledger_path.path()).unwrap();
|
||||||
Blockstore::open(&ledger_path).expect("Expected to successfully open database ledger");
|
|
||||||
blockstore
|
blockstore
|
||||||
.write_entries(
|
.write_entries(
|
||||||
1,
|
1,
|
||||||
@ -2253,9 +2248,9 @@ pub mod tests {
|
|||||||
mut genesis_config, ..
|
mut genesis_config, ..
|
||||||
} = create_genesis_config(123);
|
} = create_genesis_config(123);
|
||||||
genesis_config.ticks_per_slot = 1;
|
genesis_config.ticks_per_slot = 1;
|
||||||
let (ledger_path, _blockhash) = create_new_tmp_ledger!(&genesis_config);
|
let (ledger_path, _blockhash) = create_new_tmp_ledger_auto_delete!(&genesis_config);
|
||||||
|
|
||||||
let blockstore = Blockstore::open(&ledger_path).unwrap();
|
let blockstore = Blockstore::open(ledger_path.path()).unwrap();
|
||||||
let opts = ProcessOptions {
|
let opts = ProcessOptions {
|
||||||
poh_verify: true,
|
poh_verify: true,
|
||||||
accounts_db_test_hash_calculation: true,
|
accounts_db_test_hash_calculation: true,
|
||||||
@ -2271,9 +2266,9 @@ pub mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_process_ledger_options_override_threads() {
|
fn test_process_ledger_options_override_threads() {
|
||||||
let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(123);
|
let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(123);
|
||||||
let (ledger_path, _blockhash) = create_new_tmp_ledger!(&genesis_config);
|
let (ledger_path, _blockhash) = create_new_tmp_ledger_auto_delete!(&genesis_config);
|
||||||
|
|
||||||
let blockstore = Blockstore::open(&ledger_path).unwrap();
|
let blockstore = Blockstore::open(ledger_path.path()).unwrap();
|
||||||
let opts = ProcessOptions {
|
let opts = ProcessOptions {
|
||||||
override_num_threads: Some(1),
|
override_num_threads: Some(1),
|
||||||
accounts_db_test_hash_calculation: true,
|
accounts_db_test_hash_calculation: true,
|
||||||
@ -2288,9 +2283,9 @@ pub mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_process_ledger_options_full_leader_cache() {
|
fn test_process_ledger_options_full_leader_cache() {
|
||||||
let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(123);
|
let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(123);
|
||||||
let (ledger_path, _blockhash) = create_new_tmp_ledger!(&genesis_config);
|
let (ledger_path, _blockhash) = create_new_tmp_ledger_auto_delete!(&genesis_config);
|
||||||
|
|
||||||
let blockstore = Blockstore::open(&ledger_path).unwrap();
|
let blockstore = Blockstore::open(ledger_path.path()).unwrap();
|
||||||
let opts = ProcessOptions {
|
let opts = ProcessOptions {
|
||||||
full_leader_cache: true,
|
full_leader_cache: true,
|
||||||
accounts_db_test_hash_calculation: true,
|
accounts_db_test_hash_calculation: true,
|
||||||
@ -2308,9 +2303,8 @@ pub mod tests {
|
|||||||
mint_keypair,
|
mint_keypair,
|
||||||
..
|
..
|
||||||
} = create_genesis_config(100);
|
} = create_genesis_config(100);
|
||||||
let (ledger_path, last_entry_hash) = create_new_tmp_ledger!(&genesis_config);
|
let (ledger_path, last_entry_hash) = create_new_tmp_ledger_auto_delete!(&genesis_config);
|
||||||
let blockstore =
|
let blockstore = Blockstore::open(ledger_path.path()).unwrap();
|
||||||
Blockstore::open(&ledger_path).expect("Expected to successfully open database ledger");
|
|
||||||
let blockhash = genesis_config.hash();
|
let blockhash = genesis_config.hash();
|
||||||
let keypairs = [Keypair::new(), Keypair::new(), Keypair::new()];
|
let keypairs = [Keypair::new(), Keypair::new(), Keypair::new()];
|
||||||
|
|
||||||
@ -2988,8 +2982,8 @@ pub mod tests {
|
|||||||
|
|
||||||
// Create roots at slots 0, 1
|
// Create roots at slots 0, 1
|
||||||
let forks = tr(0) / tr(1);
|
let forks = tr(0) / tr(1);
|
||||||
let ledger_path = get_tmp_ledger_path!();
|
let ledger_path = get_tmp_ledger_path_auto_delete!();
|
||||||
let blockstore = Blockstore::open(&ledger_path).unwrap();
|
let blockstore = Blockstore::open(ledger_path.path()).unwrap();
|
||||||
blockstore.add_tree(
|
blockstore.add_tree(
|
||||||
forks,
|
forks,
|
||||||
false,
|
false,
|
||||||
@ -3021,8 +3015,8 @@ pub mod tests {
|
|||||||
|
|
||||||
let ticks_per_slot = 1;
|
let ticks_per_slot = 1;
|
||||||
genesis_config.ticks_per_slot = ticks_per_slot;
|
genesis_config.ticks_per_slot = ticks_per_slot;
|
||||||
let (ledger_path, blockhash) = create_new_tmp_ledger!(&genesis_config);
|
let (ledger_path, blockhash) = create_new_tmp_ledger_auto_delete!(&genesis_config);
|
||||||
let blockstore = Blockstore::open(&ledger_path).unwrap();
|
let blockstore = Blockstore::open(ledger_path.path()).unwrap();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Build a blockstore in the ledger with the following fork structure:
|
Build a blockstore in the ledger with the following fork structure:
|
||||||
@ -3615,8 +3609,8 @@ pub mod tests {
|
|||||||
vec![100],
|
vec![100],
|
||||||
);
|
);
|
||||||
let ticks_per_slot = genesis_config.ticks_per_slot();
|
let ticks_per_slot = genesis_config.ticks_per_slot();
|
||||||
let ledger_path = get_tmp_ledger_path!();
|
let ledger_path = get_tmp_ledger_path_auto_delete!();
|
||||||
let blockstore = Blockstore::open(&ledger_path).unwrap();
|
let blockstore = Blockstore::open(ledger_path.path()).unwrap();
|
||||||
blockstore.add_tree(forks, false, true, ticks_per_slot, genesis_config.hash());
|
blockstore.add_tree(forks, false, true, ticks_per_slot, genesis_config.hash());
|
||||||
|
|
||||||
if let Some(blockstore_root) = blockstore_root {
|
if let Some(blockstore_root) = blockstore_root {
|
||||||
|
@ -255,7 +255,7 @@ mod tests {
|
|||||||
bootstrap_validator_stake_lamports, create_genesis_config,
|
bootstrap_validator_stake_lamports, create_genesis_config,
|
||||||
create_genesis_config_with_leader, GenesisConfigInfo,
|
create_genesis_config_with_leader, GenesisConfigInfo,
|
||||||
},
|
},
|
||||||
get_tmp_ledger_path,
|
get_tmp_ledger_path_auto_delete,
|
||||||
staking_utils::tests::setup_vote_and_stake_accounts,
|
staking_utils::tests::setup_vote_and_stake_accounts,
|
||||||
};
|
};
|
||||||
use solana_runtime::bank::Bank;
|
use solana_runtime::bank::Bank;
|
||||||
@ -428,12 +428,10 @@ mod tests {
|
|||||||
|
|
||||||
let bank = Bank::new_for_tests(&genesis_config);
|
let bank = Bank::new_for_tests(&genesis_config);
|
||||||
let cache = Arc::new(LeaderScheduleCache::new_from_bank(&bank));
|
let cache = Arc::new(LeaderScheduleCache::new_from_bank(&bank));
|
||||||
let ledger_path = get_tmp_ledger_path!();
|
let ledger_path = get_tmp_ledger_path_auto_delete!();
|
||||||
{
|
|
||||||
let blockstore = Arc::new(
|
let blockstore = Blockstore::open(ledger_path.path())
|
||||||
Blockstore::open(&ledger_path)
|
.expect("Expected to be able to open database ledger");
|
||||||
.expect("Expected to be able to open database ledger"),
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
cache.slot_leader_at(bank.slot(), Some(&bank)).unwrap(),
|
cache.slot_leader_at(bank.slot(), Some(&bank)).unwrap(),
|
||||||
@ -496,8 +494,6 @@ mod tests {
|
|||||||
None
|
None
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Blockstore::destroy(&ledger_path).unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_next_leader_slot_next_epoch() {
|
fn test_next_leader_slot_next_epoch() {
|
||||||
|
@ -41,8 +41,8 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_next_slots_iterator() {
|
fn test_next_slots_iterator() {
|
||||||
let blockstore_path = get_tmp_ledger_path!();
|
let ledger_path = get_tmp_ledger_path_auto_delete!();
|
||||||
let blockstore = Blockstore::open(&blockstore_path).unwrap();
|
let blockstore = Blockstore::open(ledger_path.path()).unwrap();
|
||||||
blockstore.set_roots(std::iter::once(&0)).unwrap();
|
blockstore.set_roots(std::iter::once(&0)).unwrap();
|
||||||
let ticks_per_slot = 5;
|
let ticks_per_slot = 5;
|
||||||
/*
|
/*
|
||||||
@ -107,8 +107,5 @@ mod tests {
|
|||||||
.collect();
|
.collect();
|
||||||
let expected = vec![4].into_iter().collect();
|
let expected = vec![4].into_iter().collect();
|
||||||
assert_eq!(result, expected);
|
assert_eq!(result, expected);
|
||||||
|
|
||||||
drop(blockstore);
|
|
||||||
Blockstore::destroy(&blockstore_path).expect("Expected successful database destruction");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -82,8 +82,8 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_rooted_slot_iterator() {
|
fn test_rooted_slot_iterator() {
|
||||||
let blockstore_path = get_tmp_ledger_path!();
|
let ledger_path = get_tmp_ledger_path_auto_delete!();
|
||||||
let blockstore = Blockstore::open(&blockstore_path).unwrap();
|
let blockstore = Blockstore::open(ledger_path.path()).unwrap();
|
||||||
blockstore.set_roots(std::iter::once(&0)).unwrap();
|
blockstore.set_roots(std::iter::once(&0)).unwrap();
|
||||||
let ticks_per_slot = 5;
|
let ticks_per_slot = 5;
|
||||||
/*
|
/*
|
||||||
@ -150,15 +150,12 @@ mod tests {
|
|||||||
.collect();
|
.collect();
|
||||||
let expected = vec![0, 1, 2, 3];
|
let expected = vec![0, 1, 2, 3];
|
||||||
assert_eq!(result, expected);
|
assert_eq!(result, expected);
|
||||||
|
|
||||||
drop(blockstore);
|
|
||||||
Blockstore::destroy(&blockstore_path).expect("Expected successful database destruction");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_skipping_rooted_slot_iterator() {
|
fn test_skipping_rooted_slot_iterator() {
|
||||||
let blockstore_path = get_tmp_ledger_path!();
|
let ledger_path = get_tmp_ledger_path_auto_delete!();
|
||||||
let blockstore = Blockstore::open(&blockstore_path).unwrap();
|
let blockstore = Blockstore::open(ledger_path.path()).unwrap();
|
||||||
let ticks_per_slot = 5;
|
let ticks_per_slot = 5;
|
||||||
/*
|
/*
|
||||||
Build a blockstore in the ledger with the following fork structure:
|
Build a blockstore in the ledger with the following fork structure:
|
||||||
@ -229,8 +226,5 @@ mod tests {
|
|||||||
(11, true),
|
(11, true),
|
||||||
];
|
];
|
||||||
assert_eq!(result, expected);
|
assert_eq!(result, expected);
|
||||||
|
|
||||||
drop(blockstore);
|
|
||||||
Blockstore::destroy(&blockstore_path).expect("Expected successful database destruction");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use solana_entry::entry;
|
use solana_entry::entry;
|
||||||
use solana_ledger::{
|
use solana_ledger::{
|
||||||
blockstore::{self, Blockstore},
|
blockstore::{self, Blockstore},
|
||||||
get_tmp_ledger_path,
|
get_tmp_ledger_path_auto_delete,
|
||||||
};
|
};
|
||||||
use solana_sdk::hash::Hash;
|
use solana_sdk::hash::Hash;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
@ -9,8 +9,8 @@ use std::thread::Builder;
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_multiple_threads_insert_shred() {
|
fn test_multiple_threads_insert_shred() {
|
||||||
let blockstore_path = get_tmp_ledger_path!();
|
let ledger_path = get_tmp_ledger_path_auto_delete!();
|
||||||
let blockstore = Arc::new(Blockstore::open(&blockstore_path).unwrap());
|
let blockstore = Arc::new(Blockstore::open(ledger_path.path()).unwrap());
|
||||||
|
|
||||||
for _ in 0..100 {
|
for _ in 0..100 {
|
||||||
let num_threads = 10;
|
let num_threads = 10;
|
||||||
@ -44,8 +44,4 @@ fn test_multiple_threads_insert_shred() {
|
|||||||
// Delete slots for next iteration
|
// Delete slots for next iteration
|
||||||
blockstore.purge_and_compact_slots(0, num_threads + 1);
|
blockstore.purge_and_compact_slots(0, num_threads + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cleanup
|
|
||||||
drop(blockstore);
|
|
||||||
Blockstore::destroy(&blockstore_path).expect("Expected successful database destruction");
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user