From 4b4aa2a911fbbdc10a477ab080c0e331d36499f6 Mon Sep 17 00:00:00 2001 From: Ryo Onodera Date: Sat, 30 May 2020 23:40:55 +0900 Subject: [PATCH 01/12] Support opening an in-use rocksdb as secondary --- core/src/validator.rs | 4 +- genesis/src/main.rs | 5 +- ledger-tool/src/main.rs | 88 +++++++++++++++++++++--------- ledger/src/blockstore.rs | 31 ++++++++--- ledger/src/blockstore_db.rs | 79 +++++++++++++++++++++------ ledger/src/blockstore_processor.rs | 8 ++- 6 files changed, 157 insertions(+), 58 deletions(-) diff --git a/core/src/validator.rs b/core/src/validator.rs index 5e4e1466fd3427..59e190d0741bb7 100644 --- a/core/src/validator.rs +++ b/core/src/validator.rs @@ -27,6 +27,7 @@ use solana_ledger::{ bank_forks::{BankForks, SnapshotConfig}, bank_forks_utils, blockstore::{Blockstore, CompletedSlotsReceiver}, + blockstore_db::AccessType, blockstore_processor, create_new_tmp_ledger, hardened_unpack::{open_genesis_config, MAX_GENESIS_ARCHIVE_UNPACKED_SIZE}, leader_schedule::FixedSchedule, @@ -583,7 +584,8 @@ fn new_banks_from_blockstore( } let (mut blockstore, ledger_signal_receiver, completed_slots_receiver) = - Blockstore::open_with_signal(blockstore_path).expect("Failed to open ledger database"); + Blockstore::open_with_signal(blockstore_path, AccessType::OnlyPrimary) + .expect("Failed to open ledger database"); blockstore.set_no_compaction(config.no_rocksdb_compaction); let process_options = blockstore_processor::ProcessOptions { diff --git a/genesis/src/main.rs b/genesis/src/main.rs index 54f6cb18c01311..0fe4f0e5ec5bc5 100644 --- a/genesis/src/main.rs +++ b/genesis/src/main.rs @@ -7,8 +7,8 @@ use solana_clap_utils::{ }; use solana_genesis::{genesis_accounts::add_genesis_accounts, Base64Account}; use solana_ledger::{ - blockstore::create_new_ledger, hardened_unpack::MAX_GENESIS_ARCHIVE_UNPACKED_SIZE, - poh::compute_hashes_per_tick, + blockstore::create_new_ledger, blockstore_db::AccessType, + hardened_unpack::MAX_GENESIS_ARCHIVE_UNPACKED_SIZE, poh::compute_hashes_per_tick, }; use solana_sdk::{ account::Account, @@ -540,6 +540,7 @@ fn main() -> Result<(), Box> { &ledger_path, &genesis_config, max_genesis_archive_unpacked_size, + AccessType::OnlyPrimary, )?; println!("{}", genesis_config); diff --git a/ledger-tool/src/main.rs b/ledger-tool/src/main.rs index 123029f4fbabd4..946d74493fa1f0 100644 --- a/ledger-tool/src/main.rs +++ b/ledger-tool/src/main.rs @@ -9,7 +9,7 @@ use solana_ledger::{ bank_forks::{BankForks, SnapshotConfig}, bank_forks_utils, blockstore::Blockstore, - blockstore_db::{self, Column, Database}, + blockstore_db::{self, AccessType, Column, Database}, blockstore_processor::ProcessOptions, hardened_unpack::{open_genesis_config, MAX_GENESIS_ARCHIVE_UNPACKED_SIZE}, rooted_slot_iterator::RootedSlotIterator, @@ -519,8 +519,8 @@ fn analyze_storage(database: &Database) -> Result<(), String> { Ok(()) } -fn open_blockstore(ledger_path: &Path) -> Blockstore { - match Blockstore::open(ledger_path) { +fn open_blockstore(ledger_path: &Path, access_type: AccessType) -> Blockstore { + match Blockstore::open(ledger_path, access_type) { Ok(blockstore) => blockstore, Err(err) => { eprintln!("Failed to open ledger at {:?}: {:?}", ledger_path, err); @@ -529,8 +529,8 @@ fn open_blockstore(ledger_path: &Path) -> Blockstore { } } -fn open_database(ledger_path: &Path) -> Database { - match Database::open(&ledger_path.join("rocksdb")) { +fn open_database(ledger_path: &Path, access_type: AccessType) -> Database { + match Database::open(&ledger_path.join("rocksdb"), access_type) { Ok(database) => database, Err(err) => { eprintln!("Unable to read the Ledger rocksdb: {:?}", err); @@ -553,6 +553,7 @@ fn load_bank_forks( ledger_path: &PathBuf, genesis_config: &GenesisConfig, process_options: ProcessOptions, + access_type: AccessType, ) -> bank_forks_utils::LoadResult { let snapshot_config = if arg_matches.is_present("no_snapshot") { None @@ -564,15 +565,22 @@ fn load_bank_forks( compression: CompressionType::Bzip2, }) }; + let blockstore = open_blockstore(&ledger_path, access_type); let account_paths = if let Some(account_paths) = arg_matches.value_of("account_paths") { account_paths.split(',').map(PathBuf::from).collect() } else { - vec![ledger_path.join("accounts")] + if blockstore.is_primary_access() { + vec![ledger_path.join("accounts")] + } else { + let non_primary_accounts_path = ledger_path.join("accounts.ledger-tool"); + eprintln!("Default accounts path is switched aligning with Blockstore's non-primary access: {:?}", non_primary_accounts_path); + vec![non_primary_accounts_path] + } }; bank_forks_utils::load( &genesis_config, - &open_blockstore(&ledger_path), + &blockstore, account_paths, snapshot_config.as_ref(), process_options, @@ -862,7 +870,7 @@ fn main() { let starting_slot = value_t_or_exit!(arg_matches, "starting_slot", Slot); let allow_dead_slots = arg_matches.is_present("allow_dead_slots"); output_ledger( - open_blockstore(&ledger_path), + open_blockstore(&ledger_path, AccessType::AllowSecondary), starting_slot, allow_dead_slots, LedgerOutputMethod::Print, @@ -885,7 +893,13 @@ fn main() { ..ProcessOptions::default() }; let genesis_config = open_genesis_config_by(&ledger_path, arg_matches); - match load_bank_forks(arg_matches, &ledger_path, &genesis_config, process_options) { + match load_bank_forks( + arg_matches, + &ledger_path, + &genesis_config, + process_options, + AccessType::AllowSecondary, + ) { Ok((bank_forks, _leader_schedule_cache, _snapshot_hash)) => { println!( "{}", @@ -904,7 +918,7 @@ fn main() { ("slot", Some(arg_matches)) => { let slots = values_t_or_exit!(arg_matches, "slots", Slot); let allow_dead_slots = arg_matches.is_present("allow_dead_slots"); - let blockstore = open_blockstore(&ledger_path); + let blockstore = open_blockstore(&ledger_path, AccessType::AllowSecondary); for slot in slots { println!("Slot {}", slot); if let Err(err) = output_slot( @@ -921,7 +935,7 @@ fn main() { let starting_slot = value_t_or_exit!(arg_matches, "starting_slot", Slot); let allow_dead_slots = arg_matches.is_present("allow_dead_slots"); output_ledger( - open_blockstore(&ledger_path), + open_blockstore(&ledger_path, AccessType::AllowSecondary), starting_slot, allow_dead_slots, LedgerOutputMethod::Json, @@ -929,7 +943,7 @@ fn main() { } ("set-dead-slot", Some(arg_matches)) => { let slots = values_t_or_exit!(arg_matches, "slots", Slot); - let blockstore = open_blockstore(&ledger_path); + let blockstore = open_blockstore(&ledger_path, AccessType::OnlyPrimary); for slot in slots { match blockstore.set_dead_slot(slot) { Ok(_) => println!("Slot {} dead", slot), @@ -954,6 +968,7 @@ fn main() { &ledger_path, &open_genesis_config_by(&ledger_path, arg_matches), process_options, + AccessType::AllowSecondary, ) .unwrap_or_else(|err| { eprintln!("Ledger verification failed: {:?}", err); @@ -976,6 +991,7 @@ fn main() { &ledger_path, &open_genesis_config_by(&ledger_path, arg_matches), process_options, + AccessType::AllowSecondary, ) { Ok((bank_forks, _leader_schedule_cache, _snapshot_hash)) => { let dot = graph_forks(&bank_forks, arg_matches.is_present("include_all_votes")); @@ -1012,7 +1028,13 @@ fn main() { ..ProcessOptions::default() }; let genesis_config = open_genesis_config_by(&ledger_path, arg_matches); - match load_bank_forks(arg_matches, &ledger_path, &genesis_config, process_options) { + match load_bank_forks( + arg_matches, + &ledger_path, + &genesis_config, + process_options, + AccessType::AllowSecondary, + ) { Ok((bank_forks, _leader_schedule_cache, _snapshot_hash)) => { let bank = bank_forks.get(snapshot_slot).unwrap_or_else(|| { eprintln!("Error: Slot {} is not available", snapshot_slot); @@ -1079,7 +1101,13 @@ fn main() { }; let genesis_config = open_genesis_config_by(&ledger_path, arg_matches); let include_sysvars = arg_matches.is_present("include_sysvars"); - match load_bank_forks(arg_matches, &ledger_path, &genesis_config, process_options) { + match load_bank_forks( + arg_matches, + &ledger_path, + &genesis_config, + process_options, + AccessType::AllowSecondary, + ) { Ok((bank_forks, _leader_schedule_cache, _snapshot_hash)) => { let slot = bank_forks.working_bank().slot(); let bank = bank_forks.get(slot).unwrap_or_else(|| { @@ -1121,7 +1149,13 @@ fn main() { ..ProcessOptions::default() }; let genesis_config = open_genesis_config_by(&ledger_path, arg_matches); - match load_bank_forks(arg_matches, &ledger_path, &genesis_config, process_options) { + match load_bank_forks( + arg_matches, + &ledger_path, + &genesis_config, + process_options, + AccessType::AllowSecondary, + ) { Ok((bank_forks, _leader_schedule_cache, _snapshot_hash)) => { let slot = bank_forks.working_bank().slot(); let bank = bank_forks.get(slot).unwrap_or_else(|| { @@ -1185,12 +1219,12 @@ fn main() { ("purge", Some(arg_matches)) => { let start_slot = value_t_or_exit!(arg_matches, "start_slot", Slot); let end_slot = value_t_or_exit!(arg_matches, "end_slot", Slot); - let blockstore = open_blockstore(&ledger_path); + let blockstore = open_blockstore(&ledger_path, AccessType::OnlyPrimary); blockstore.purge_slots(start_slot, end_slot); blockstore.purge_from_next_slots(start_slot, end_slot); } ("list-roots", Some(arg_matches)) => { - let blockstore = open_blockstore(&ledger_path); + let blockstore = open_blockstore(&ledger_path, AccessType::AllowSecondary); let max_height = if let Some(height) = arg_matches.value_of("max_height") { usize::from_str(height).expect("Maximum height must be a number") } else { @@ -1243,7 +1277,7 @@ fn main() { }); } ("bounds", Some(arg_matches)) => { - match open_blockstore(&ledger_path).slot_meta_iterator(0) { + match open_blockstore(&ledger_path, AccessType::AllowSecondary).slot_meta_iterator(0) { Ok(metas) => { let all = arg_matches.is_present("all"); @@ -1269,15 +1303,17 @@ fn main() { } } } - ("analyze-storage", _) => match analyze_storage(&open_database(&ledger_path)) { - Ok(()) => { - println!("Ok."); - } - Err(err) => { - eprintln!("Unable to read the Ledger: {:?}", err); - exit(1); + ("analyze-storage", _) => { + match analyze_storage(&open_database(&ledger_path, AccessType::AllowSecondary)) { + Ok(()) => { + println!("Ok."); + } + Err(err) => { + eprintln!("Unable to read the Ledger: {:?}", err); + exit(1); + } } - }, + } ("", _) => { eprintln!("{}", matches.usage()); exit(1); diff --git a/ledger/src/blockstore.rs b/ledger/src/blockstore.rs index f838c61c4438ea..989b8e901a8c45 100644 --- a/ledger/src/blockstore.rs +++ b/ledger/src/blockstore.rs @@ -4,8 +4,8 @@ pub use crate::{blockstore_db::BlockstoreError, blockstore_meta::SlotMeta}; use crate::{ blockstore_db::{ - columns as cf, Column, Database, IteratorDirection, IteratorMode, LedgerColumn, Result, - WriteBatch, + columns as cf, AccessType, Column, Database, IteratorDirection, IteratorMode, LedgerColumn, + Result, WriteBatch, }, blockstore_meta::*, entry::{create_ticks, Entry}, @@ -176,7 +176,7 @@ impl Blockstore { } /// Opens a Ledger in directory, provides "infinite" window of shreds - pub fn open(ledger_path: &Path) -> Result { + pub fn open(ledger_path: &Path, access_type: AccessType) -> Result { fs::create_dir_all(&ledger_path)?; let blockstore_path = ledger_path.join(BLOCKSTORE_DIRECTORY); @@ -185,7 +185,7 @@ impl Blockstore { // Open the database let mut measure = Measure::start("open"); info!("Opening database at {:?}", blockstore_path); - let db = Database::open(&blockstore_path)?; + let db = Database::open(&blockstore_path, access_type)?; // Create the metadata column family let meta_cf = db.column(); @@ -266,8 +266,9 @@ impl Blockstore { pub fn open_with_signal( ledger_path: &Path, + access_type: AccessType, ) -> Result<(Self, Receiver, CompletedSlotsReceiver)> { - let mut blockstore = Self::open(ledger_path)?; + let mut blockstore = Self::open(ledger_path, access_type)?; let (signal_sender, signal_receiver) = sync_channel(1); let (completed_slots_sender, completed_slots_receiver) = sync_channel(MAX_COMPLETED_SLOTS_IN_CHANNEL); @@ -2355,6 +2356,10 @@ impl Blockstore { pub fn storage_size(&self) -> Result { self.db.storage_size() } + + pub fn is_primary_access(&self) -> bool { + self.db.is_primary_access() + } } fn update_slot_meta( @@ -2787,12 +2792,13 @@ pub fn create_new_ledger( ledger_path: &Path, genesis_config: &GenesisConfig, max_genesis_archive_unpacked_size: u64, + access_type: AccessType, ) -> Result { Blockstore::destroy(ledger_path)?; genesis_config.write(&ledger_path)?; // Fill slot 0 with ticks that link back to the genesis_config to bootstrap the ledger. - let blockstore = Blockstore::open(ledger_path)?; + let blockstore = Blockstore::open(ledger_path, access_type)?; let ticks_per_slot = genesis_config.ticks_per_slot; let hashes_per_tick = genesis_config.poh_config.hashes_per_tick.unwrap_or(0); let entries = create_ticks(ticks_per_slot, hashes_per_tick, genesis_config.hash()); @@ -2923,7 +2929,11 @@ pub fn get_ledger_path_from_name(name: &str) -> PathBuf { #[macro_export] macro_rules! create_new_tmp_ledger { ($genesis_config:expr) => { - $crate::blockstore::create_new_ledger_from_name($crate::tmp_ledger_name!(), $genesis_config) + $crate::blockstore::create_new_ledger_from_name( + $crate::tmp_ledger_name!(), + $genesis_config, + AccessType::OnlyPrimary, + ) }; } @@ -2949,12 +2959,17 @@ pub fn verify_shred_slots(slot: Slot, parent_slot: Slot, last_root: Slot) -> boo // // Note: like `create_new_ledger` the returned ledger will have slot 0 full of ticks (and only // ticks) -pub fn create_new_ledger_from_name(name: &str, genesis_config: &GenesisConfig) -> (PathBuf, Hash) { +pub fn create_new_ledger_from_name( + name: &str, + genesis_config: &GenesisConfig, + access_type: AccessType, +) -> (PathBuf, Hash) { let ledger_path = get_ledger_path_from_name(name); let blockhash = create_new_ledger( &ledger_path, genesis_config, MAX_GENESIS_ARCHIVE_UNPACKED_SIZE, + access_type, ) .unwrap(); (ledger_path, blockhash) diff --git a/ledger/src/blockstore_db.rs b/ledger/src/blockstore_db.rs index 58e9c7378b748a..7ca28c47705905 100644 --- a/ledger/src/blockstore_db.rs +++ b/ledger/src/blockstore_db.rs @@ -126,11 +126,22 @@ pub mod columns { pub struct Rewards; } +pub enum AccessType { + OnlyPrimary, + AllowSecondary, +} + +#[derive(Debug, PartialEq)] +pub enum ActualAccessType { + Primary, + Secondary, +} + #[derive(Debug)] -struct Rocks(rocksdb::DB); +struct Rocks(rocksdb::DB, ActualAccessType); impl Rocks { - fn open(path: &Path) -> Result { + fn open(path: &Path, access_type: AccessType) -> Result { use columns::{ AddressSignatures, DeadSlots, DuplicateSlots, ErasureMeta, Index, Orphans, Rewards, Root, ShredCode, ShredData, SlotMeta, TransactionStatus, TransactionStatusIndex, @@ -165,23 +176,47 @@ impl Rocks { let rewards_cf_descriptor = ColumnFamilyDescriptor::new(Rewards::NAME, get_cf_options()); let cfs = vec![ - meta_cf_descriptor, - dead_slots_cf_descriptor, - duplicate_slots_cf_descriptor, - erasure_meta_cf_descriptor, - orphans_cf_descriptor, - root_cf_descriptor, - index_cf_descriptor, - shred_data_cf_descriptor, - shred_code_cf_descriptor, - transaction_status_cf_descriptor, - address_signatures_cf_descriptor, - transaction_status_index_cf_descriptor, - rewards_cf_descriptor, + (SlotMeta::NAME, meta_cf_descriptor), + (DeadSlots::NAME, dead_slots_cf_descriptor), + (DuplicateSlots::NAME, duplicate_slots_cf_descriptor), + (ErasureMeta::NAME, erasure_meta_cf_descriptor), + (Orphans::NAME, orphans_cf_descriptor), + (Root::NAME, root_cf_descriptor), + (Index::NAME, index_cf_descriptor), + (ShredData::NAME, shred_data_cf_descriptor), + (ShredCode::NAME, shred_code_cf_descriptor), + (TransactionStatus::NAME, transaction_status_cf_descriptor), + (AddressSignatures::NAME, address_signatures_cf_descriptor), + ( + TransactionStatusIndex::NAME, + transaction_status_index_cf_descriptor, + ), + (Rewards::NAME, rewards_cf_descriptor), ]; // Open the database - let db = Rocks(DB::open_cf_descriptors(&db_options, path, cfs)?); + let db = match access_type { + AccessType::OnlyPrimary => Rocks( + DB::open_cf_descriptors(&db_options, path, cfs.into_iter().map(|c| c.1))?, + ActualAccessType::Primary, + ), + AccessType::AllowSecondary => { + let secondary_path = path.join("solana-secondary"); + let names: Vec<&str> = cfs.iter().map(|c| c.0).collect(); + match DB::open_cf_descriptors(&db_options, path, cfs.into_iter().map(|c| c.1)) { + Ok(db) => Rocks(db, ActualAccessType::Primary), + Err(err) => { + warn!("Error when opening as primary: {}", err); + warn!("Trying as secondary at : {:?}", secondary_path); + warn!("This active secondary db use may temporarily cause the performance of another db use (like by validator) to degrade"); + Rocks( + DB::open_cf_as_secondary(&db_options, path, &secondary_path, names)?, + ActualAccessType::Secondary, + ) + } + } + } + }; Ok(db) } @@ -266,6 +301,10 @@ impl Rocks { self.0.write(batch)?; Ok(()) } + + fn is_primary_access(&self) -> bool { + self.1 == ActualAccessType::Primary + } } pub trait Column { @@ -577,8 +616,8 @@ pub struct WriteBatch<'a> { } impl Database { - pub fn open(path: &Path) -> Result { - let backend = Arc::new(Rocks::open(path)?); + pub fn open(path: &Path, access_type: AccessType) -> Result { + let backend = Arc::new(Rocks::open(path, access_type)?); Ok(Database { backend, @@ -678,6 +717,10 @@ impl Database { let end = max_slot <= to; result.map(|_| end) } + + pub fn is_primary_access(&self) -> bool { + self.backend.is_primary_access() + } } impl LedgerColumn diff --git a/ledger/src/blockstore_processor.rs b/ledger/src/blockstore_processor.rs index d3837cc98ec45a..5556b4ee4125d0 100644 --- a/ledger/src/blockstore_processor.rs +++ b/ledger/src/blockstore_processor.rs @@ -336,9 +336,11 @@ pub fn process_blockstore_from_root( } } - blockstore - .set_roots(&[start_slot]) - .expect("Couldn't set root slot on startup"); + if blockstore.is_primary_access() { + blockstore + .set_roots(&[start_slot]) + .expect("Couldn't set root slot on startup"); + } if let Ok(metas) = blockstore.slot_meta_iterator(start_slot) { if let Some((slot, _meta)) = metas.last() { From fbd820b4a4ca27d2b48f8b6bae17c8d79c578427 Mon Sep 17 00:00:00 2001 From: Ryo Onodera Date: Mon, 25 May 2020 10:43:22 +0900 Subject: [PATCH 02/12] Fix build? --- banking-bench/src/main.rs | 3 +- core/benches/banking_stage.rs | 6 +- core/benches/blockstore.rs | 20 +-- core/src/banking_stage.rs | 18 +-- core/src/broadcast_stage.rs | 4 +- .../broadcast_stage/standard_broadcast_run.rs | 3 +- core/src/cluster_info_vote_listener.rs | 4 +- core/src/commitment.rs | 6 +- core/src/ledger_cleanup_service.rs | 4 +- core/src/poh_recorder.rs | 42 +++--- core/src/poh_service.rs | 2 +- core/src/repair_service.rs | 20 +-- core/src/replay_stage.rs | 8 +- core/src/retransmit_stage.rs | 2 +- core/src/rpc.rs | 12 +- core/src/rpc_pubsub.rs | 20 +-- core/src/rpc_pubsub_service.rs | 2 +- core/src/rpc_service.rs | 2 +- core/src/rpc_subscriptions.rs | 12 +- core/src/serve_repair.rs | 6 +- core/src/tvu.rs | 4 +- core/src/window_service.rs | 4 +- core/tests/client.rs | 2 +- core/tests/ledger_cleanup.rs | 4 +- ledger/src/blockstore.rs | 126 ++++++++++-------- ledger/src/blockstore_db.rs | 2 +- ledger/src/blockstore_processor.rs | 46 +++---- ledger/src/leader_schedule_cache.rs | 2 +- ledger/src/next_slots_iterator.rs | 2 +- ledger/src/rooted_slot_iterator.rs | 4 +- ledger/tests/blockstore.rs | 2 +- local-cluster/src/cluster_tests.rs | 2 +- local-cluster/tests/local_cluster.rs | 6 +- 33 files changed, 207 insertions(+), 195 deletions(-) diff --git a/banking-bench/src/main.rs b/banking-bench/src/main.rs index 824237da887815..c0ef00e0fa566d 100644 --- a/banking-bench/src/main.rs +++ b/banking-bench/src/main.rs @@ -213,7 +213,8 @@ fn main() { let ledger_path = get_tmp_ledger_path!(); { let blockstore = Arc::new( - Blockstore::open(&ledger_path).expect("Expected to be able to open database ledger"), + Blockstore::open_as_primary(&ledger_path) + .expect("Expected to be able to open database ledger"), ); let (exit, poh_recorder, poh_service, signal_receiver) = create_test_recorder(&bank, &blockstore, None); diff --git a/core/benches/banking_stage.rs b/core/benches/banking_stage.rs index 9336b370492d19..7ee4108a4e45e5 100644 --- a/core/benches/banking_stage.rs +++ b/core/benches/banking_stage.rs @@ -58,7 +58,8 @@ fn bench_consume_buffered(bencher: &mut Bencher) { let my_pubkey = Pubkey::new_rand(); { let blockstore = Arc::new( - Blockstore::open(&ledger_path).expect("Expected to be able to open database ledger"), + Blockstore::open_as_primary(&ledger_path) + .expect("Expected to be able to open database ledger"), ); let (exit, poh_recorder, poh_service, _signal_receiver) = create_test_recorder(&bank, &blockstore, None); @@ -185,7 +186,8 @@ fn bench_banking(bencher: &mut Bencher, tx_type: TransactionType) { let ledger_path = get_tmp_ledger_path!(); { let blockstore = Arc::new( - Blockstore::open(&ledger_path).expect("Expected to be able to open database ledger"), + Blockstore::open_as_primary(&ledger_path) + .expect("Expected to be able to open database ledger"), ); let (exit, poh_recorder, poh_service, signal_receiver) = create_test_recorder(&bank, &blockstore, None); diff --git a/core/benches/blockstore.rs b/core/benches/blockstore.rs index aac755a952c245..9c81d99049dd57 100644 --- a/core/benches/blockstore.rs +++ b/core/benches/blockstore.rs @@ -16,8 +16,8 @@ use test::Bencher; // Given some shreds and a ledger at ledger_path, benchmark writing the shreds to the ledger fn bench_write_shreds(bench: &mut Bencher, entries: Vec, ledger_path: &Path) { - let blockstore = - Blockstore::open(ledger_path).expect("Expected to be able to open database ledger"); + let blockstore = Blockstore::open_as_primary(ledger_path) + .expect("Expected to be able to open database ledger"); bench.iter(move || { let shreds = entries_to_test_shreds(entries.clone(), 0, 0, true, 0); blockstore.insert_shreds(shreds, None, false).unwrap(); @@ -71,8 +71,8 @@ fn bench_write_big(bench: &mut Bencher) { #[ignore] fn bench_read_sequential(bench: &mut Bencher) { let ledger_path = get_tmp_ledger_path!(); - let mut blockstore = - Blockstore::open(&ledger_path).expect("Expected to be able to open database ledger"); + let mut blockstore = Blockstore::open_as_primary(&ledger_path) + .expect("Expected to be able to open database ledger"); // Insert some big and small shreds into the ledger let num_small_shreds = 32 * 1024; @@ -98,8 +98,8 @@ fn bench_read_sequential(bench: &mut Bencher) { #[ignore] fn bench_read_random(bench: &mut Bencher) { let ledger_path = get_tmp_ledger_path!(); - let mut blockstore = - Blockstore::open(&ledger_path).expect("Expected to be able to open database ledger"); + let mut blockstore = Blockstore::open_as_primary(&ledger_path) + .expect("Expected to be able to open database ledger"); // Insert some big and small shreds into the ledger let num_small_shreds = 32 * 1024; @@ -129,8 +129,8 @@ fn bench_read_random(bench: &mut Bencher) { #[ignore] fn bench_insert_data_shred_small(bench: &mut Bencher) { let ledger_path = get_tmp_ledger_path!(); - let blockstore = - Blockstore::open(&ledger_path).expect("Expected to be able to open database ledger"); + let blockstore = Blockstore::open_as_primary(&ledger_path) + .expect("Expected to be able to open database ledger"); let num_entries = 32 * 1024; let entries = create_ticks(num_entries, 0, Hash::default()); bench.iter(move || { @@ -144,8 +144,8 @@ fn bench_insert_data_shred_small(bench: &mut Bencher) { #[ignore] fn bench_insert_data_shred_big(bench: &mut Bencher) { let ledger_path = get_tmp_ledger_path!(); - let blockstore = - Blockstore::open(&ledger_path).expect("Expected to be able to open database ledger"); + let blockstore = Blockstore::open_as_primary(&ledger_path) + .expect("Expected to be able to open database ledger"); let num_entries = 32 * 1024; let entries = create_ticks(num_entries, 0, Hash::default()); bench.iter(move || { diff --git a/core/src/banking_stage.rs b/core/src/banking_stage.rs index 4feffefbaeb3c4..c6c28cb251aa9c 100644 --- a/core/src/banking_stage.rs +++ b/core/src/banking_stage.rs @@ -1046,7 +1046,7 @@ mod tests { let ledger_path = get_tmp_ledger_path!(); { let blockstore = Arc::new( - Blockstore::open(&ledger_path) + Blockstore::open_as_primary(&ledger_path) .expect("Expected to be able to open database ledger"), ); let (exit, poh_recorder, poh_service, _entry_receiever) = @@ -1084,7 +1084,7 @@ mod tests { let ledger_path = get_tmp_ledger_path!(); { let blockstore = Arc::new( - Blockstore::open(&ledger_path) + Blockstore::open_as_primary(&ledger_path) .expect("Expected to be able to open database ledger"), ); let mut poh_config = PohConfig::default(); @@ -1146,7 +1146,7 @@ mod tests { let ledger_path = get_tmp_ledger_path!(); { let blockstore = Arc::new( - Blockstore::open(&ledger_path) + Blockstore::open_as_primary(&ledger_path) .expect("Expected to be able to open database ledger"), ); let mut poh_config = PohConfig::default(); @@ -1286,7 +1286,7 @@ mod tests { // start a banking_stage to eat verified receiver let bank = Arc::new(Bank::new(&genesis_config)); let blockstore = Arc::new( - Blockstore::open(&ledger_path) + Blockstore::open_as_primary(&ledger_path) .expect("Expected to be able to open database ledger"), ); let mut poh_config = PohConfig::default(); @@ -1354,7 +1354,7 @@ mod tests { }; let ledger_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open(&ledger_path) + let blockstore = Blockstore::open_as_primary(&ledger_path) .expect("Expected to be able to open database ledger"); let (poh_recorder, entry_receiver) = PohRecorder::new( bank.tick_height(), @@ -1665,7 +1665,7 @@ mod tests { }; let ledger_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open(&ledger_path) + let blockstore = Blockstore::open_as_primary(&ledger_path) .expect("Expected to be able to open database ledger"); let (poh_recorder, entry_receiver) = PohRecorder::new( bank.tick_height(), @@ -1758,7 +1758,7 @@ mod tests { }; let ledger_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open(&ledger_path) + let blockstore = Blockstore::open_as_primary(&ledger_path) .expect("Expected to be able to open database ledger"); let (poh_recorder, _entry_receiver) = PohRecorder::new( bank.tick_height(), @@ -1846,7 +1846,7 @@ mod tests { let ledger_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open(&ledger_path) + let blockstore = Blockstore::open_as_primary(&ledger_path) .expect("Expected to be able to open database ledger"); let (poh_recorder, _entry_receiver) = PohRecorder::new( bank.tick_height(), @@ -1913,7 +1913,7 @@ mod tests { }; let ledger_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open(&ledger_path) + let blockstore = Blockstore::open_as_primary(&ledger_path) .expect("Expected to be able to open database ledger"); let blockstore = Arc::new(blockstore); let (poh_recorder, _entry_receiver) = PohRecorder::new( diff --git a/core/src/broadcast_stage.rs b/core/src/broadcast_stage.rs index 9e9e6c31bec8dc..2d6f0783e626a6 100644 --- a/core/src/broadcast_stage.rs +++ b/core/src/broadcast_stage.rs @@ -526,7 +526,7 @@ pub mod test { fn test_duplicate_retransmit_signal() { // Setup let ledger_path = get_tmp_ledger_path!(); - let blockstore = Arc::new(Blockstore::open(&ledger_path).unwrap()); + let blockstore = Arc::new(Blockstore::open_as_primary(&ledger_path).unwrap()); let (transmit_sender, transmit_receiver) = channel(); let (retransmit_slots_sender, retransmit_slots_receiver) = unbounded(); let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(100_000); @@ -585,7 +585,7 @@ pub mod test { retransmit_slots_receiver: RetransmitSlotsReceiver, ) -> MockBroadcastStage { // Make the database ledger - let blockstore = Arc::new(Blockstore::open(ledger_path).unwrap()); + let blockstore = Arc::new(Blockstore::open_as_primary(ledger_path).unwrap()); // Make the leader node and scheduler let leader_info = Node::new_localhost_with_pubkey(leader_pubkey); diff --git a/core/src/broadcast_stage/standard_broadcast_run.rs b/core/src/broadcast_stage/standard_broadcast_run.rs index 3f3a888da1c60a..502dc4cd649309 100644 --- a/core/src/broadcast_stage/standard_broadcast_run.rs +++ b/core/src/broadcast_stage/standard_broadcast_run.rs @@ -420,7 +420,8 @@ mod test { // Setup let ledger_path = get_tmp_ledger_path!(); let blockstore = Arc::new( - Blockstore::open(&ledger_path).expect("Expected to be able to open database ledger"), + Blockstore::open_as_primary(&ledger_path) + .expect("Expected to be able to open database ledger"), ); let leader_keypair = Arc::new(Keypair::new()); let leader_pubkey = leader_keypair.pubkey(); diff --git a/core/src/cluster_info_vote_listener.rs b/core/src/cluster_info_vote_listener.rs index fc1f1f3c884138..7937ab6cf25401 100644 --- a/core/src/cluster_info_vote_listener.rs +++ b/core/src/cluster_info_vote_listener.rs @@ -952,7 +952,7 @@ mod tests { let bank = bank_forks.get(0).unwrap().clone(); let vote_tracker = VoteTracker::new(&bank); let ledger_path = get_tmp_ledger_path!(); - let blockstore = Arc::new(Blockstore::open(&ledger_path).unwrap()); + let blockstore = Arc::new(Blockstore::open_as_primary(&ledger_path).unwrap()); let subscriptions = Arc::new(RpcSubscriptions::new( &exit, Arc::new(RwLock::new(bank_forks)), @@ -1067,7 +1067,7 @@ mod tests { let bank_forks = BankForks::new(0, bank); let bank = bank_forks.get(0).unwrap().clone(); let ledger_path = get_tmp_ledger_path!(); - let blockstore = Arc::new(Blockstore::open(&ledger_path).unwrap()); + let blockstore = Arc::new(Blockstore::open_as_primary(&ledger_path).unwrap()); let subscriptions = Arc::new(RpcSubscriptions::new( &exit, Arc::new(RwLock::new(bank_forks)), diff --git a/core/src/commitment.rs b/core/src/commitment.rs index a26be76655e9fd..1abaea00f37c48 100644 --- a/core/src/commitment.rs +++ b/core/src/commitment.rs @@ -450,7 +450,7 @@ mod tests { fn test_get_confirmations() { let bank = Arc::new(Bank::default()); let ledger_path = get_tmp_ledger_path!(); - let blockstore = Arc::new(Blockstore::open(&ledger_path).unwrap()); + let blockstore = Arc::new(Blockstore::open_as_primary(&ledger_path).unwrap()); // Build BlockCommitmentCache with votes at depths 0 and 1 for 2 slots let mut cache0 = BlockCommitment::default(); cache0.increase_confirmation_stake(1, 5); @@ -481,7 +481,7 @@ mod tests { fn test_is_confirmed_rooted() { let bank = Arc::new(Bank::default()); let ledger_path = get_tmp_ledger_path!(); - let blockstore = Arc::new(Blockstore::open(&ledger_path).unwrap()); + let blockstore = Arc::new(Blockstore::open_as_primary(&ledger_path).unwrap()); blockstore.set_roots(&[0, 1]).unwrap(); // Build BlockCommitmentCache with rooted slots let mut cache0 = BlockCommitment::default(); @@ -532,7 +532,7 @@ mod tests { let bank = Arc::new(Bank::new(&GenesisConfig::default())); let bank_slot_5 = Arc::new(Bank::new_from_parent(&bank, &Pubkey::default(), 5)); let ledger_path = get_tmp_ledger_path!(); - let blockstore = Arc::new(Blockstore::open(&ledger_path).unwrap()); + let blockstore = Arc::new(Blockstore::open_as_primary(&ledger_path).unwrap()); let total_stake = 50; // Build cache with confirmation_count 2 given total_stake diff --git a/core/src/ledger_cleanup_service.rs b/core/src/ledger_cleanup_service.rs index 50345745e089ca..af35780d855440 100644 --- a/core/src/ledger_cleanup_service.rs +++ b/core/src/ledger_cleanup_service.rs @@ -225,7 +225,7 @@ mod tests { fn test_cleanup() { solana_logger::setup(); let blockstore_path = get_tmp_ledger_path!(); - let blockstore = Blockstore::open(&blockstore_path).unwrap(); + let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); let (shreds, _) = make_many_slot_entries(0, 50, 5); blockstore.insert_shreds(shreds, None, false).unwrap(); let blockstore = Arc::new(blockstore); @@ -258,7 +258,7 @@ mod tests { fn test_cleanup_speed() { solana_logger::setup(); let blockstore_path = get_tmp_ledger_path!(); - let mut blockstore = Blockstore::open(&blockstore_path).unwrap(); + let mut blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); blockstore.set_no_compaction(true); let blockstore = Arc::new(blockstore); let (sender, receiver) = channel(); diff --git a/core/src/poh_recorder.rs b/core/src/poh_recorder.rs index 5653ca3b8cc274..314e200fd76d45 100644 --- a/core/src/poh_recorder.rs +++ b/core/src/poh_recorder.rs @@ -524,7 +524,7 @@ mod tests { let prev_hash = Hash::default(); let ledger_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open(&ledger_path) + let blockstore = Blockstore::open_as_primary(&ledger_path) .expect("Expected to be able to open database ledger"); let (mut poh_recorder, _entry_receiver) = PohRecorder::new( @@ -551,7 +551,7 @@ mod tests { let prev_hash = Hash::default(); let ledger_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open(&ledger_path) + let blockstore = Blockstore::open_as_primary(&ledger_path) .expect("Expected to be able to open database ledger"); let (mut poh_recorder, _entry_receiver) = PohRecorder::new( @@ -578,7 +578,7 @@ mod tests { fn test_poh_recorder_reset_clears_cache() { let ledger_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open(&ledger_path) + let blockstore = Blockstore::open_as_primary(&ledger_path) .expect("Expected to be able to open database ledger"); let (mut poh_recorder, _entry_receiver) = PohRecorder::new( 0, @@ -603,7 +603,7 @@ mod tests { fn test_poh_recorder_clear() { let ledger_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open(&ledger_path) + let blockstore = Blockstore::open_as_primary(&ledger_path) .expect("Expected to be able to open database ledger"); let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(2); let bank = Arc::new(Bank::new(&genesis_config)); @@ -637,7 +637,7 @@ mod tests { fn test_poh_recorder_tick_sent_after_min() { let ledger_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open(&ledger_path) + let blockstore = Blockstore::open_as_primary(&ledger_path) .expect("Expected to be able to open database ledger"); let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(2); let bank = Arc::new(Bank::new(&genesis_config)); @@ -686,7 +686,7 @@ mod tests { fn test_poh_recorder_tick_sent_upto_and_including_max() { let ledger_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open(&ledger_path) + let blockstore = Blockstore::open_as_primary(&ledger_path) .expect("Expected to be able to open database ledger"); let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(2); let bank = Arc::new(Bank::new(&genesis_config)); @@ -733,7 +733,7 @@ mod tests { fn test_poh_recorder_record_to_early() { let ledger_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open(&ledger_path) + let blockstore = Blockstore::open_as_primary(&ledger_path) .expect("Expected to be able to open database ledger"); let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(2); let bank = Arc::new(Bank::new(&genesis_config)); @@ -769,7 +769,7 @@ mod tests { fn test_poh_recorder_record_bad_slot() { let ledger_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open(&ledger_path) + let blockstore = Blockstore::open_as_primary(&ledger_path) .expect("Expected to be able to open database ledger"); let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(2); let bank = Arc::new(Bank::new(&genesis_config)); @@ -809,7 +809,7 @@ mod tests { fn test_poh_recorder_record_at_min_passes() { let ledger_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open(&ledger_path) + let blockstore = Blockstore::open_as_primary(&ledger_path) .expect("Expected to be able to open database ledger"); let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(2); let bank = Arc::new(Bank::new(&genesis_config)); @@ -853,7 +853,7 @@ mod tests { fn test_poh_recorder_record_at_max_fails() { let ledger_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open(&ledger_path) + let blockstore = Blockstore::open_as_primary(&ledger_path) .expect("Expected to be able to open database ledger"); let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(2); let bank = Arc::new(Bank::new(&genesis_config)); @@ -895,7 +895,7 @@ mod tests { fn test_poh_cache_on_disconnect() { let ledger_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open(&ledger_path) + let blockstore = Blockstore::open_as_primary(&ledger_path) .expect("Expected to be able to open database ledger"); let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(2); let bank = Arc::new(Bank::new(&genesis_config)); @@ -933,7 +933,7 @@ mod tests { fn test_reset_current() { let ledger_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open(&ledger_path) + let blockstore = Blockstore::open_as_primary(&ledger_path) .expect("Expected to be able to open database ledger"); let (mut poh_recorder, _entry_receiver) = PohRecorder::new( 0, @@ -960,7 +960,7 @@ mod tests { fn test_reset_with_cached() { let ledger_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open(&ledger_path) + let blockstore = Blockstore::open_as_primary(&ledger_path) .expect("Expected to be able to open database ledger"); let (mut poh_recorder, _entry_receiver) = PohRecorder::new( 0, @@ -988,7 +988,7 @@ mod tests { let ledger_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open(&ledger_path) + let blockstore = Blockstore::open_as_primary(&ledger_path) .expect("Expected to be able to open database ledger"); let (mut poh_recorder, _entry_receiver) = PohRecorder::new( 0, @@ -1019,7 +1019,7 @@ mod tests { fn test_reset_clear_bank() { let ledger_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open(&ledger_path) + let blockstore = Blockstore::open_as_primary(&ledger_path) .expect("Expected to be able to open database ledger"); let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(2); let bank = Arc::new(Bank::new(&genesis_config)); @@ -1050,7 +1050,7 @@ mod tests { pub fn test_clear_signal() { let ledger_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open(&ledger_path) + let blockstore = Blockstore::open_as_primary(&ledger_path) .expect("Expected to be able to open database ledger"); let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(2); let bank = Arc::new(Bank::new(&genesis_config)); @@ -1079,7 +1079,7 @@ mod tests { solana_logger::setup(); let ledger_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open(&ledger_path) + let blockstore = Blockstore::open_as_primary(&ledger_path) .expect("Expected to be able to open database ledger"); let ticks_per_slot = 5; let GenesisConfigInfo { @@ -1130,7 +1130,7 @@ mod tests { let ledger_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open(&ledger_path) + let blockstore = Blockstore::open_as_primary(&ledger_path) .expect("Expected to be able to open database ledger"); let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(2); let bank = Arc::new(Bank::new(&genesis_config)); @@ -1192,7 +1192,7 @@ mod tests { let ledger_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open(&ledger_path) + let blockstore = Blockstore::open_as_primary(&ledger_path) .expect("Expected to be able to open database ledger"); let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(2); let bank = Arc::new(Bank::new(&genesis_config)); @@ -1319,7 +1319,7 @@ mod tests { fn test_would_be_leader_soon() { let ledger_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open(&ledger_path) + let blockstore = Blockstore::open_as_primary(&ledger_path) .expect("Expected to be able to open database ledger"); let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(2); let bank = Arc::new(Bank::new(&genesis_config)); @@ -1386,7 +1386,7 @@ mod tests { let ledger_path = get_tmp_ledger_path!(); { // test that virtual ticks are flushed into a newly set bank asap - let blockstore = Blockstore::open(&ledger_path) + let blockstore = Blockstore::open_as_primary(&ledger_path) .expect("Expected to be able to open database ledger"); let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(2); let bank = Arc::new(Bank::new(&genesis_config)); diff --git a/core/src/poh_service.rs b/core/src/poh_service.rs index 740a7ca6f42318..fcda1b4bd4fed8 100644 --- a/core/src/poh_service.rs +++ b/core/src/poh_service.rs @@ -135,7 +135,7 @@ mod tests { let prev_hash = bank.last_blockhash(); let ledger_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open(&ledger_path) + let blockstore = Blockstore::open_as_primary(&ledger_path) .expect("Expected to be able to open database ledger"); let poh_config = Arc::new(PohConfig { hashes_per_tick: Some(2), diff --git a/core/src/repair_service.rs b/core/src/repair_service.rs index 01ec5cb705ae8c..7f8bba6d88fd9f 100644 --- a/core/src/repair_service.rs +++ b/core/src/repair_service.rs @@ -603,7 +603,7 @@ mod test { pub fn test_repair_orphan() { let blockstore_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open(&blockstore_path).unwrap(); + let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); // Create some orphan slots let (mut shreds, _) = make_slot_entries(1, 0, 1); @@ -623,7 +623,7 @@ mod test { pub fn test_repair_empty_slot() { let blockstore_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open(&blockstore_path).unwrap(); + let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); let (shreds, _) = make_slot_entries(2, 0, 1); @@ -644,7 +644,7 @@ mod test { pub fn test_generate_repairs() { let blockstore_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open(&blockstore_path).unwrap(); + let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); let nth = 3; let num_slots = 2; @@ -702,7 +702,7 @@ mod test { pub fn test_generate_highest_repair() { let blockstore_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open(&blockstore_path).unwrap(); + let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); let num_entries_per_slot = 100; @@ -732,7 +732,7 @@ mod test { pub fn test_repair_range() { let blockstore_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open(&blockstore_path).unwrap(); + let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); let slots: Vec = vec![1, 3, 5, 7, 8]; let num_entries_per_slot = max_ticks_per_n_shreds(1, None) + 1; @@ -781,7 +781,7 @@ mod test { pub fn test_repair_range_highest() { let blockstore_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open(&blockstore_path).unwrap(); + let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); let num_entries_per_slot = 10; @@ -836,7 +836,7 @@ mod test { #[test] pub fn test_generate_duplicate_repairs_for_slot() { let blockstore_path = get_tmp_ledger_path!(); - let blockstore = Blockstore::open(&blockstore_path).unwrap(); + let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); let dead_slot = 9; // SlotMeta doesn't exist, should make no repairs @@ -866,7 +866,7 @@ mod test { #[test] pub fn test_generate_and_send_duplicate_repairs() { let blockstore_path = get_tmp_ledger_path!(); - let blockstore = Blockstore::open(&blockstore_path).unwrap(); + let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); let cluster_slots = ClusterSlots::default(); let serve_repair = ServeRepair::new_with_invalid_keypair(Node::new_localhost().info); let mut duplicate_slot_repair_statuses = HashMap::new(); @@ -997,7 +997,7 @@ mod test { #[test] pub fn test_process_new_duplicate_slots() { let blockstore_path = get_tmp_ledger_path!(); - let blockstore = Blockstore::open(&blockstore_path).unwrap(); + let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); let cluster_slots = ClusterSlots::default(); let serve_repair = ServeRepair::new_with_invalid_keypair(Node::new_localhost().info); let mut duplicate_slot_repair_statuses = HashMap::new(); @@ -1071,7 +1071,7 @@ mod test { #[test] pub fn test_find_new_duplicate_slots() { let blockstore_path = get_tmp_ledger_path!(); - let blockstore = Blockstore::open(&blockstore_path).unwrap(); + let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); let cluster_slots = ClusterSlots::default(); let duplicate_slot_repair_statuses = HashMap::new(); let keypairs = ValidatorVoteKeypairs::new_rand(); diff --git a/core/src/replay_stage.rs b/core/src/replay_stage.rs index b8d81735ab1a83..b8ff2f1d0a96ff 100644 --- a/core/src/replay_stage.rs +++ b/core/src/replay_stage.rs @@ -2161,7 +2161,7 @@ pub(crate) mod tests { { // Setup let blockstore = Arc::new( - Blockstore::open(&ledger_path) + Blockstore::open_as_primary(&ledger_path) .expect("Expected to be able to open database ledger"), ); let validator_authorized_voter_keypairs: Vec<_> = (0..20) @@ -2590,7 +2590,7 @@ pub(crate) mod tests { let ledger_path = get_tmp_ledger_path!(); let res = { let blockstore = Arc::new( - Blockstore::open(&ledger_path) + Blockstore::open_as_primary(&ledger_path) .expect("Expected to be able to open database ledger"), ); let GenesisConfigInfo { @@ -2641,7 +2641,7 @@ pub(crate) mod tests { } let ledger_path = get_tmp_ledger_path!(); - let blockstore = Arc::new(Blockstore::open(&ledger_path).unwrap()); + let blockstore = Arc::new(Blockstore::open_as_primary(&ledger_path).unwrap()); let leader_pubkey = Pubkey::new_rand(); let leader_lamports = 3; @@ -2809,7 +2809,7 @@ pub(crate) mod tests { } = create_genesis_config(1000); let (ledger_path, _) = create_new_tmp_ledger!(&genesis_config); { - let blockstore = Blockstore::open(&ledger_path) + let blockstore = Blockstore::open_as_primary(&ledger_path) .expect("Expected to successfully open database ledger"); let blockstore = Arc::new(blockstore); diff --git a/core/src/retransmit_stage.rs b/core/src/retransmit_stage.rs index f3c0fbac816bda..b67c02c61d2690 100644 --- a/core/src/retransmit_stage.rs +++ b/core/src/retransmit_stage.rs @@ -419,7 +419,7 @@ mod tests { fn test_skip_repair() { let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(123); let (ledger_path, _blockhash) = create_new_tmp_ledger!(&genesis_config); - let blockstore = Blockstore::open(&ledger_path).unwrap(); + let blockstore = Blockstore::open_as_primary(&ledger_path).unwrap(); let opts = ProcessOptions { full_leader_cache: true, ..ProcessOptions::default() diff --git a/core/src/rpc.rs b/core/src/rpc.rs index 4078fe9a44cc97..34d46c969c5bbc 100644 --- a/core/src/rpc.rs +++ b/core/src/rpc.rs @@ -1693,7 +1693,7 @@ pub mod tests { let (bank_forks, alice, leader_vote_keypair) = new_bank_forks(); let bank = bank_forks.read().unwrap().working_bank(); let ledger_path = get_tmp_ledger_path!(); - let blockstore = Blockstore::open(&ledger_path).unwrap(); + let blockstore = Blockstore::open_as_primary(&ledger_path).unwrap(); let blockstore = Arc::new(blockstore); let keypair1 = Keypair::new(); @@ -1835,7 +1835,7 @@ pub mod tests { let (bank_forks, alice, _) = new_bank_forks(); let bank = bank_forks.read().unwrap().working_bank(); let ledger_path = get_tmp_ledger_path!(); - let blockstore = Arc::new(Blockstore::open(&ledger_path).unwrap()); + let blockstore = Arc::new(Blockstore::open_as_primary(&ledger_path).unwrap()); let block_commitment_cache = Arc::new(RwLock::new( BlockCommitmentCache::default_with_blockstore(blockstore.clone()), )); @@ -2773,7 +2773,7 @@ pub mod tests { let exit = Arc::new(AtomicBool::new(false)); let validator_exit = create_validator_exit(&exit); let ledger_path = get_tmp_ledger_path!(); - let blockstore = Arc::new(Blockstore::open(&ledger_path).unwrap()); + let blockstore = Arc::new(Blockstore::open_as_primary(&ledger_path).unwrap()); let block_commitment_cache = Arc::new(RwLock::new( BlockCommitmentCache::default_with_blockstore(blockstore.clone()), )); @@ -2871,7 +2871,7 @@ pub mod tests { let exit = Arc::new(AtomicBool::new(false)); let validator_exit = create_validator_exit(&exit); let ledger_path = get_tmp_ledger_path!(); - let blockstore = Arc::new(Blockstore::open(&ledger_path).unwrap()); + let blockstore = Arc::new(Blockstore::open_as_primary(&ledger_path).unwrap()); let block_commitment_cache = Arc::new(RwLock::new( BlockCommitmentCache::default_with_blockstore(blockstore.clone()), )); @@ -2891,7 +2891,7 @@ pub mod tests { let exit = Arc::new(AtomicBool::new(false)); let validator_exit = create_validator_exit(&exit); let ledger_path = get_tmp_ledger_path!(); - let blockstore = Arc::new(Blockstore::open(&ledger_path).unwrap()); + let blockstore = Arc::new(Blockstore::open_as_primary(&ledger_path).unwrap()); let block_commitment_cache = Arc::new(RwLock::new( BlockCommitmentCache::default_with_blockstore(blockstore.clone()), )); @@ -2956,7 +2956,7 @@ pub mod tests { let validator_exit = create_validator_exit(&exit); let bank_forks = new_bank_forks().0; let ledger_path = get_tmp_ledger_path!(); - let blockstore = Arc::new(Blockstore::open(&ledger_path).unwrap()); + let blockstore = Arc::new(Blockstore::open_as_primary(&ledger_path).unwrap()); let commitment_slot0 = BlockCommitment::new([8; MAX_LOCKOUT_HISTORY + 1]); let commitment_slot1 = BlockCommitment::new([9; MAX_LOCKOUT_HISTORY + 1]); diff --git a/core/src/rpc_pubsub.rs b/core/src/rpc_pubsub.rs index 80c429f69d436b..3a41c1053e3563 100644 --- a/core/src/rpc_pubsub.rs +++ b/core/src/rpc_pubsub.rs @@ -422,7 +422,7 @@ mod tests { let blockhash = bank.last_blockhash(); let bank_forks = Arc::new(RwLock::new(BankForks::new(0, bank))); let ledger_path = get_tmp_ledger_path!(); - let blockstore = Arc::new(Blockstore::open(&ledger_path).unwrap()); + let blockstore = Arc::new(Blockstore::open_as_primary(&ledger_path).unwrap()); let rpc = RpcSolPubSubImpl { subscriptions: Arc::new(RpcSubscriptions::new( &Arc::new(AtomicBool::new(false)), @@ -473,7 +473,7 @@ mod tests { let blockhash = bank.last_blockhash(); let bank_forks = Arc::new(RwLock::new(BankForks::new(0, bank))); let ledger_path = get_tmp_ledger_path!(); - let blockstore = Arc::new(Blockstore::open(&ledger_path).unwrap()); + let blockstore = Arc::new(Blockstore::open_as_primary(&ledger_path).unwrap()); let session = create_session(); @@ -533,7 +533,7 @@ mod tests { let bank1 = Bank::new_from_parent(&bank0, &Pubkey::default(), 1); bank_forks.write().unwrap().insert(bank1); let ledger_path = get_tmp_ledger_path!(); - let blockstore = Arc::new(Blockstore::open(&ledger_path).unwrap()); + let blockstore = Arc::new(Blockstore::open_as_primary(&ledger_path).unwrap()); let rpc = RpcSolPubSubImpl { subscriptions: Arc::new(RpcSubscriptions::new( @@ -636,7 +636,7 @@ mod tests { let bob_pubkey = Pubkey::new_rand(); let session = create_session(); let ledger_path = get_tmp_ledger_path!(); - let blockstore = Arc::new(Blockstore::open(&ledger_path).unwrap()); + let blockstore = Arc::new(Blockstore::open_as_primary(&ledger_path).unwrap()); let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(10_000); let bank_forks = Arc::new(RwLock::new(BankForks::new(0, Bank::new(&genesis_config)))); @@ -682,7 +682,7 @@ mod tests { let blockhash = bank.last_blockhash(); let bank_forks = Arc::new(RwLock::new(BankForks::new(1, bank))); let ledger_path = get_tmp_ledger_path!(); - let blockstore = Arc::new(Blockstore::open(&ledger_path).unwrap()); + let blockstore = Arc::new(Blockstore::open_as_primary(&ledger_path).unwrap()); let bob = Keypair::new(); let mut rpc = RpcSolPubSubImpl::default_with_blockstore_bank_forks( @@ -736,7 +736,7 @@ mod tests { let bank1 = Bank::new_from_parent(&bank0, &Pubkey::default(), 1); bank_forks.write().unwrap().insert(bank1); let ledger_path = get_tmp_ledger_path!(); - let blockstore = Arc::new(Blockstore::open(&ledger_path).unwrap()); + let blockstore = Arc::new(Blockstore::open_as_primary(&ledger_path).unwrap()); let bob = Keypair::new(); let mut rpc = RpcSolPubSubImpl::default_with_blockstore_bank_forks( @@ -804,7 +804,7 @@ mod tests { #[serial] fn test_slot_subscribe() { let ledger_path = get_tmp_ledger_path!(); - let blockstore = Arc::new(Blockstore::open(&ledger_path).unwrap()); + let blockstore = Arc::new(Blockstore::open_as_primary(&ledger_path).unwrap()); let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(10_000); let bank = Bank::new(&genesis_config); let bank_forks = Arc::new(RwLock::new(BankForks::new(0, bank))); @@ -834,7 +834,7 @@ mod tests { #[serial] fn test_slot_unsubscribe() { let ledger_path = get_tmp_ledger_path!(); - let blockstore = Arc::new(Blockstore::open(&ledger_path).unwrap()); + let blockstore = Arc::new(Blockstore::open_as_primary(&ledger_path).unwrap()); let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(10_000); let bank = Bank::new(&genesis_config); let bank_forks = Arc::new(RwLock::new(BankForks::new(0, bank))); @@ -872,7 +872,7 @@ mod tests { #[serial] fn test_vote_subscribe() { let ledger_path = get_tmp_ledger_path!(); - let blockstore = Arc::new(Blockstore::open(&ledger_path).unwrap()); + let blockstore = Arc::new(Blockstore::open_as_primary(&ledger_path).unwrap()); let block_commitment_cache = Arc::new(RwLock::new( BlockCommitmentCache::new_for_tests_with_blockstore(blockstore.clone()), )); @@ -942,7 +942,7 @@ mod tests { #[serial] fn test_vote_unsubscribe() { let ledger_path = get_tmp_ledger_path!(); - let blockstore = Arc::new(Blockstore::open(&ledger_path).unwrap()); + let blockstore = Arc::new(Blockstore::open_as_primary(&ledger_path).unwrap()); let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(10_000); let bank = Bank::new(&genesis_config); let bank_forks = Arc::new(RwLock::new(BankForks::new(0, bank))); diff --git a/core/src/rpc_pubsub_service.rs b/core/src/rpc_pubsub_service.rs index 68e542ae8335c7..ecde0eef64658c 100644 --- a/core/src/rpc_pubsub_service.rs +++ b/core/src/rpc_pubsub_service.rs @@ -90,7 +90,7 @@ mod tests { let pubsub_addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), 0); let exit = Arc::new(AtomicBool::new(false)); let ledger_path = get_tmp_ledger_path!(); - let blockstore = Arc::new(Blockstore::open(&ledger_path).unwrap()); + let blockstore = Arc::new(Blockstore::open_as_primary(&ledger_path).unwrap()); let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(10_000); let bank = Bank::new(&genesis_config); let bank_forks = Arc::new(RwLock::new(BankForks::new(0, bank))); diff --git a/core/src/rpc_service.rs b/core/src/rpc_service.rs index b1b90d200ab98d..1070ff7193bff3 100644 --- a/core/src/rpc_service.rs +++ b/core/src/rpc_service.rs @@ -423,7 +423,7 @@ mod tests { ); let bank_forks = Arc::new(RwLock::new(BankForks::new(bank.slot(), bank))); let ledger_path = get_tmp_ledger_path!(); - let blockstore = Arc::new(Blockstore::open(&ledger_path).unwrap()); + let blockstore = Arc::new(Blockstore::open_as_primary(&ledger_path).unwrap()); let block_commitment_cache = Arc::new(RwLock::new( BlockCommitmentCache::default_with_blockstore(blockstore.clone()), )); diff --git a/core/src/rpc_subscriptions.rs b/core/src/rpc_subscriptions.rs index 9cf553df29eff1..ead20457f15018 100644 --- a/core/src/rpc_subscriptions.rs +++ b/core/src/rpc_subscriptions.rs @@ -877,7 +877,7 @@ pub(crate) mod tests { .. } = create_genesis_config(100); let ledger_path = get_tmp_ledger_path!(); - let blockstore = Arc::new(Blockstore::open(&ledger_path).unwrap()); + let blockstore = Arc::new(Blockstore::open_as_primary(&ledger_path).unwrap()); let bank = Bank::new(&genesis_config); let blockhash = bank.last_blockhash(); let bank_forks = Arc::new(RwLock::new(BankForks::new(0, bank))); @@ -971,7 +971,7 @@ pub(crate) mod tests { .. } = create_genesis_config(100); let ledger_path = get_tmp_ledger_path!(); - let blockstore = Arc::new(Blockstore::open(&ledger_path).unwrap()); + let blockstore = Arc::new(Blockstore::open_as_primary(&ledger_path).unwrap()); let bank = Bank::new(&genesis_config); let blockhash = bank.last_blockhash(); let bank_forks = Arc::new(RwLock::new(BankForks::new(0, bank))); @@ -1059,7 +1059,7 @@ pub(crate) mod tests { .. } = create_genesis_config(100); let ledger_path = get_tmp_ledger_path!(); - let blockstore = Arc::new(Blockstore::open(&ledger_path).unwrap()); + let blockstore = Arc::new(Blockstore::open_as_primary(&ledger_path).unwrap()); let bank = Bank::new(&genesis_config); let blockhash = bank.last_blockhash(); let mut bank_forks = BankForks::new(0, bank); @@ -1215,7 +1215,7 @@ pub(crate) mod tests { let sub_id = SubscriptionId::Number(0 as u64); let exit = Arc::new(AtomicBool::new(false)); let ledger_path = get_tmp_ledger_path!(); - let blockstore = Arc::new(Blockstore::open(&ledger_path).unwrap()); + let blockstore = Arc::new(Blockstore::open_as_primary(&ledger_path).unwrap()); let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(10_000); let bank = Bank::new(&genesis_config); let bank_forks = Arc::new(RwLock::new(BankForks::new(0, bank))); @@ -1267,7 +1267,7 @@ pub(crate) mod tests { let sub_id = SubscriptionId::Number(0 as u64); let exit = Arc::new(AtomicBool::new(false)); let ledger_path = get_tmp_ledger_path!(); - let blockstore = Arc::new(Blockstore::open(&ledger_path).unwrap()); + let blockstore = Arc::new(Blockstore::open_as_primary(&ledger_path).unwrap()); let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(10_000); let bank = Bank::new(&genesis_config); let bank_forks = Arc::new(RwLock::new(BankForks::new(0, bank))); @@ -1365,7 +1365,7 @@ pub(crate) mod tests { .. } = create_genesis_config(100); let ledger_path = get_tmp_ledger_path!(); - let blockstore = Arc::new(Blockstore::open(&ledger_path).unwrap()); + let blockstore = Arc::new(Blockstore::open_as_primary(&ledger_path).unwrap()); let bank = Bank::new(&genesis_config); let blockhash = bank.last_blockhash(); let bank_forks = Arc::new(RwLock::new(BankForks::new(0, bank))); diff --git a/core/src/serve_repair.rs b/core/src/serve_repair.rs index 0610333e2ec28f..879297a2ab84fc 100644 --- a/core/src/serve_repair.rs +++ b/core/src/serve_repair.rs @@ -574,7 +574,7 @@ mod tests { solana_logger::setup(); let ledger_path = get_tmp_ledger_path!(); { - let blockstore = Arc::new(Blockstore::open(&ledger_path).unwrap()); + let blockstore = Arc::new(Blockstore::open_as_primary(&ledger_path).unwrap()); let rv = ServeRepair::run_highest_window_request( &recycler, &socketaddr_any!(), @@ -642,7 +642,7 @@ mod tests { solana_logger::setup(); let ledger_path = get_tmp_ledger_path!(); { - let blockstore = Arc::new(Blockstore::open(&ledger_path).unwrap()); + let blockstore = Arc::new(Blockstore::open_as_primary(&ledger_path).unwrap()); let me = ContactInfo { id: Pubkey::new_rand(), gossip: socketaddr!("127.0.0.1:1234"), @@ -802,7 +802,7 @@ mod tests { let recycler = PacketsRecycler::default(); let ledger_path = get_tmp_ledger_path!(); { - let blockstore = Arc::new(Blockstore::open(&ledger_path).unwrap()); + let blockstore = Arc::new(Blockstore::open_as_primary(&ledger_path).unwrap()); let rv = ServeRepair::run_orphan( &recycler, &socketaddr_any!(), diff --git a/core/src/tvu.rs b/core/src/tvu.rs index cc03e609353443..ad2c2264c2ae5a 100644 --- a/core/src/tvu.rs +++ b/core/src/tvu.rs @@ -239,8 +239,8 @@ pub mod tests { use crate::banking_stage::create_test_recorder; use crate::cluster_info::{ClusterInfo, Node}; use serial_test_derive::serial; - use solana_ledger::create_new_tmp_ledger; use solana_ledger::genesis_utils::{create_genesis_config, GenesisConfigInfo}; + use solana_ledger::{blockstore_db::AccessType, create_new_tmp_ledger}; use solana_runtime::bank::Bank; use std::sync::atomic::Ordering; @@ -265,7 +265,7 @@ pub mod tests { let (blockstore_path, _) = create_new_tmp_ledger!(&genesis_config); let (blockstore, l_receiver, completed_slots_receiver) = - Blockstore::open_with_signal(&blockstore_path) + Blockstore::open_with_signal(&blockstore_path, AccessType::OnlyPrimary) .expect("Expected to successfully open ledger"); let blockstore = Arc::new(blockstore); let bank = bank_forks.working_bank(); diff --git a/core/src/window_service.rs b/core/src/window_service.rs index 16628ab7ce6a10..dc211c1654909e 100644 --- a/core/src/window_service.rs +++ b/core/src/window_service.rs @@ -560,7 +560,7 @@ mod test { #[test] fn test_process_shred() { let blockstore_path = get_tmp_ledger_path!(); - let blockstore = Arc::new(Blockstore::open(&blockstore_path).unwrap()); + let blockstore = Arc::new(Blockstore::open_as_primary(&blockstore_path).unwrap()); let num_entries = 10; let original_entries = create_ticks(num_entries, 0, Hash::default()); let mut shreds = local_entries_to_shred(&original_entries, 0, 0, &Arc::new(Keypair::new())); @@ -650,7 +650,7 @@ mod test { #[test] fn test_run_check_duplicate() { let blockstore_path = get_tmp_ledger_path!(); - let blockstore = Arc::new(Blockstore::open(&blockstore_path).unwrap()); + let blockstore = Arc::new(Blockstore::open_as_primary(&blockstore_path).unwrap()); let (sender, receiver) = unbounded(); let (shreds, _) = make_many_slot_entries(5, 5, 10); blockstore diff --git a/core/tests/client.rs b/core/tests/client.rs index a16c269ddf67e1..1d8338ef11152a 100644 --- a/core/tests/client.rs +++ b/core/tests/client.rs @@ -93,7 +93,7 @@ fn test_slot_subscription() { ); let exit = Arc::new(AtomicBool::new(false)); let ledger_path = get_tmp_ledger_path!(); - let blockstore = Arc::new(Blockstore::open(&ledger_path).unwrap()); + let blockstore = Arc::new(Blockstore::open_as_primary(&ledger_path).unwrap()); let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(10_000); let bank = Bank::new(&genesis_config); let bank_forks = Arc::new(RwLock::new(BankForks::new(0, bank))); diff --git a/core/tests/ledger_cleanup.rs b/core/tests/ledger_cleanup.rs index d7f8a2ad061bff..d920bdf6fcec60 100644 --- a/core/tests/ledger_cleanup.rs +++ b/core/tests/ledger_cleanup.rs @@ -207,7 +207,7 @@ mod tests { #[test] fn test_ledger_cleanup_compaction() { let blockstore_path = get_tmp_ledger_path!(); - let blockstore = Arc::new(Blockstore::open(&blockstore_path).unwrap()); + let blockstore = Arc::new(Blockstore::open_as_primary(&blockstore_path).unwrap()); let config = get_benchmark_config(); eprintln!("BENCHMARK CONFIG: {:?}", config); eprintln!("LEDGER_PATH: {:?}", &blockstore_path); @@ -357,7 +357,7 @@ mod tests { #[test] fn test_compaction() { let blockstore_path = get_tmp_ledger_path!(); - let blockstore = Arc::new(Blockstore::open(&blockstore_path).unwrap()); + let blockstore = Arc::new(Blockstore::open_as_primary(&blockstore_path).unwrap()); let n = 10_000; let batch_size = 100; diff --git a/ledger/src/blockstore.rs b/ledger/src/blockstore.rs index 989b8e901a8c45..9d2a2ef9f9d114 100644 --- a/ledger/src/blockstore.rs +++ b/ledger/src/blockstore.rs @@ -264,6 +264,10 @@ impl Blockstore { Ok(blockstore) } + pub fn open_as_primary(ledger_path: &Path) -> Result { + Self::open(ledger_path, AccessType::OnlyPrimary) + } + pub fn open_with_signal( ledger_path: &Path, access_type: AccessType, @@ -2932,7 +2936,7 @@ macro_rules! create_new_tmp_ledger { $crate::blockstore::create_new_ledger_from_name( $crate::tmp_ledger_name!(), $genesis_config, - AccessType::OnlyPrimary, + $crate::blockstore_db::AccessType::OnlyPrimary, ) }; } @@ -3228,7 +3232,7 @@ pub mod tests { let mint_total = 1_000_000_000_000; let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(mint_total); let (ledger_path, _blockhash) = create_new_tmp_ledger!(&genesis_config); - let ledger = Blockstore::open(&ledger_path).unwrap(); + let ledger = Blockstore::open_as_primary(&ledger_path).unwrap(); let ticks = create_ticks(genesis_config.ticks_per_slot, 0, genesis_config.hash()); let entries = ledger.get_slot_entries(0, 0).unwrap(); @@ -3249,7 +3253,7 @@ pub mod tests { let (mut shreds, _) = make_slot_entries(0, 0, num_entries); let ledger_path = get_tmp_ledger_path!(); - let ledger = Blockstore::open(&ledger_path).unwrap(); + let ledger = Blockstore::open_as_primary(&ledger_path).unwrap(); // Insert last shred, test we can retrieve it let last_shred = shreds.pop().unwrap(); @@ -3278,7 +3282,7 @@ pub mod tests { { let ticks_per_slot = 10; let num_slots = 10; - let ledger = Blockstore::open(&ledger_path).unwrap(); + let ledger = Blockstore::open_as_primary(&ledger_path).unwrap(); let mut ticks = vec![]; //let mut shreds_per_slot = 0 as u64; let mut shreds_per_slot = vec![]; @@ -3373,7 +3377,7 @@ pub mod tests { #[test] fn test_put_get_simple() { let ledger_path = get_tmp_ledger_path!(); - let ledger = Blockstore::open(&ledger_path).unwrap(); + let ledger = Blockstore::open_as_primary(&ledger_path).unwrap(); // Test meta column family let meta = SlotMeta::new(0, 1); @@ -3428,7 +3432,7 @@ pub mod tests { let shred_bufs: Vec<_> = shreds.iter().map(|shred| shred.payload.clone()).collect(); let ledger_path = get_tmp_ledger_path!(); - let ledger = Blockstore::open(&ledger_path).unwrap(); + let ledger = Blockstore::open_as_primary(&ledger_path).unwrap(); ledger.insert_shreds(shreds, None, false).unwrap(); let mut buf = [0; 4096]; @@ -3486,7 +3490,7 @@ pub mod tests { let (shreds, _) = make_slot_entries(slot, 0, 100); let ledger_path = get_tmp_ledger_path!(); - let ledger = Blockstore::open(&ledger_path).unwrap(); + let ledger = Blockstore::open_as_primary(&ledger_path).unwrap(); ledger.insert_shreds(shreds, None, false).unwrap(); let mut buf = [0; 4096]; @@ -3510,7 +3514,7 @@ pub mod tests { let num_shreds = shreds.len() as u64; let ledger_path = get_tmp_ledger_path!(); - let ledger = Blockstore::open(&ledger_path).unwrap(); + let ledger = Blockstore::open_as_primary(&ledger_path).unwrap(); // Insert last shred, we're missing the other shreds, so no consecutive // shreds starting from slot 0, index 0 should exist. @@ -3555,7 +3559,7 @@ pub mod tests { let num_shreds = shreds.len() as u64; let ledger_path = get_tmp_ledger_path!(); - let ledger = Blockstore::open(&ledger_path).unwrap(); + let ledger = Blockstore::open_as_primary(&ledger_path).unwrap(); // Insert shreds in reverse, check for consecutive returned shreds for i in (0..num_shreds).rev() { @@ -3595,7 +3599,7 @@ pub mod tests { let slot = 0; let blockstore_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open(&blockstore_path).unwrap(); + let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); // Write entries let num_entries = 8; @@ -3634,7 +3638,7 @@ pub mod tests { pub fn test_get_slot_entries1() { let blockstore_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open(&blockstore_path).unwrap(); + let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); let entries = create_ticks(8, 0, Hash::default()); let shreds = entries_to_test_shreds(entries[0..4].to_vec(), 1, 0, false, 0); blockstore @@ -3664,7 +3668,7 @@ pub mod tests { pub fn test_get_slot_entries2() { let blockstore_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open(&blockstore_path).unwrap(); + let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); // Write entries let num_slots = 5 as u64; @@ -3698,7 +3702,7 @@ pub mod tests { // Test inserting/fetching shreds which contain multiple entries per shred let blockstore_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open(&blockstore_path).unwrap(); + let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); let num_slots = 5 as u64; let shreds_per_slot = 5 as u64; let entry_serialized_size = @@ -3725,7 +3729,7 @@ pub mod tests { pub fn test_insert_data_shreds_consecutive() { let blockstore_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open(&blockstore_path).unwrap(); + let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); // Create enough entries to ensure there are at least two shreds created let min_entries = max_ticks_per_n_shreds(1, None) + 1; for i in 0..4 { @@ -3789,7 +3793,7 @@ pub mod tests { // Create RocksDb ledger let blockstore_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open(&blockstore_path).unwrap(); + let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); // Make duplicate entries and shreds let num_unique_entries = 10; @@ -3826,7 +3830,8 @@ pub mod tests { pub fn test_new_shreds_signal() { // Initialize ledger let ledger_path = get_tmp_ledger_path!(); - let (ledger, recvr, _) = Blockstore::open_with_signal(&ledger_path).unwrap(); + let (ledger, recvr, _) = + Blockstore::open_with_signal(&ledger_path, AccessType::OnlyPrimary).unwrap(); let ledger = Arc::new(ledger); let entries_per_slot = 50; @@ -3906,7 +3911,8 @@ pub mod tests { pub fn test_completed_shreds_signal() { // Initialize ledger let ledger_path = get_tmp_ledger_path!(); - let (ledger, _, recvr) = Blockstore::open_with_signal(&ledger_path).unwrap(); + let (ledger, _, recvr) = + Blockstore::open_with_signal(&ledger_path, AccessType::OnlyPrimary).unwrap(); let ledger = Arc::new(ledger); let entries_per_slot = 10; @@ -3928,7 +3934,8 @@ pub mod tests { pub fn test_completed_shreds_signal_orphans() { // Initialize ledger let ledger_path = get_tmp_ledger_path!(); - let (ledger, _, recvr) = Blockstore::open_with_signal(&ledger_path).unwrap(); + let (ledger, _, recvr) = + Blockstore::open_with_signal(&ledger_path, AccessType::OnlyPrimary).unwrap(); let ledger = Arc::new(ledger); let entries_per_slot = 10; @@ -3968,7 +3975,8 @@ pub mod tests { pub fn test_completed_shreds_signal_many() { // Initialize ledger let ledger_path = get_tmp_ledger_path!(); - let (ledger, _, recvr) = Blockstore::open_with_signal(&ledger_path).unwrap(); + let (ledger, _, recvr) = + Blockstore::open_with_signal(&ledger_path, AccessType::OnlyPrimary).unwrap(); let ledger = Arc::new(ledger); let entries_per_slot = 10; @@ -4001,7 +4009,7 @@ pub mod tests { { let entries_per_slot = 5; let num_slots = 3; - let blockstore = Blockstore::open(&blockstore_path).unwrap(); + let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); // Construct the shreds let (mut shreds, _) = make_many_slot_entries(0, num_slots, entries_per_slot); @@ -4064,7 +4072,7 @@ pub mod tests { pub fn test_handle_chaining_missing_slots() { let blockstore_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open(&blockstore_path).unwrap(); + let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); let num_slots = 30; let entries_per_slot = 5; @@ -4149,7 +4157,7 @@ pub mod tests { pub fn test_forward_chaining_is_connected() { let blockstore_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open(&blockstore_path).unwrap(); + let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); let num_slots = 15; // Create enough entries to ensure there are at least two shreds created let entries_per_slot = max_ticks_per_n_shreds(1, None) + 1; @@ -4240,7 +4248,7 @@ pub mod tests { pub fn test_chaining_tree() { let blockstore_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open(&blockstore_path).unwrap(); + let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); let num_tree_levels = 6; assert!(num_tree_levels > 1); let branching_factor: u64 = 4; @@ -4342,7 +4350,7 @@ pub mod tests { let blockstore_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open(&blockstore_path).unwrap(); + let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); // Slot doesn't exist assert!(blockstore.get_slots_since(&[0]).unwrap().is_empty()); @@ -4378,7 +4386,7 @@ pub mod tests { fn test_orphans() { let blockstore_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open(&blockstore_path).unwrap(); + let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); // Create shreds and entries let entries_per_slot = 1; @@ -4451,7 +4459,7 @@ pub mod tests { fn test_insert_data_shreds_slots(name: &str, should_bulk_write: bool) { let blockstore_path = get_ledger_path_from_name(name); { - let blockstore = Blockstore::open(&blockstore_path).unwrap(); + let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); // Create shreds and entries let num_entries = 20 as u64; @@ -4513,7 +4521,7 @@ pub mod tests { fn test_find_missing_data_indexes() { let slot = 0; let blockstore_path = get_tmp_ledger_path!(); - let blockstore = Blockstore::open(&blockstore_path).unwrap(); + let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); // Write entries let gap: u64 = 10; @@ -4603,7 +4611,7 @@ pub mod tests { fn test_find_missing_data_indexes_timeout() { let slot = 0; let blockstore_path = get_tmp_ledger_path!(); - let blockstore = Blockstore::open(&blockstore_path).unwrap(); + let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); // Write entries let gap: u64 = 10; @@ -4644,7 +4652,7 @@ pub mod tests { let slot = 0; let blockstore_path = get_tmp_ledger_path!(); - let blockstore = Blockstore::open(&blockstore_path).unwrap(); + let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); // Early exit conditions let empty: Vec = vec![]; @@ -4703,7 +4711,7 @@ pub mod tests { pub fn test_no_missing_shred_indexes() { let slot = 0; let blockstore_path = get_tmp_ledger_path!(); - let blockstore = Blockstore::open(&blockstore_path).unwrap(); + let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); // Write entries let num_entries = 10; @@ -4732,7 +4740,7 @@ pub mod tests { let (mut shreds, _) = make_slot_entries(0, 0, 200); let blockstore_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open(&blockstore_path).unwrap(); + let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); let last_root = RwLock::new(0); // Insert the first 5 shreds, we don't have a "is_last" shred yet @@ -4784,7 +4792,7 @@ pub mod tests { let (shreds, _) = make_slot_entries(0, 0, 200); let blockstore_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open(&blockstore_path).unwrap(); + let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); let index_cf = blockstore.db.column::(); blockstore @@ -4820,7 +4828,7 @@ pub mod tests { pub fn test_should_insert_coding_shred() { let blockstore_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open(&blockstore_path).unwrap(); + let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); let index_cf = blockstore.db.column::(); let last_root = RwLock::new(0); @@ -4977,7 +4985,7 @@ pub mod tests { let (shreds, _) = make_slot_entries(0, 0, 20); let num_shreds = shreds.len() as u64; let blockstore_path = get_tmp_ledger_path!(); - let blockstore = Blockstore::open(&blockstore_path).unwrap(); + let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); blockstore.insert_shreds(shreds, None, false).unwrap(); let slot_meta = blockstore.meta(0).unwrap().unwrap(); @@ -5004,7 +5012,7 @@ pub mod tests { fn test_slot_data_iterator() { // Construct the shreds let blockstore_path = get_tmp_ledger_path!(); - let blockstore = Blockstore::open(&blockstore_path).unwrap(); + let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); let shreds_per_slot = 10; let slots = vec![2, 4, 8, 12]; let all_shreds = make_chaining_slot_entries(&slots, shreds_per_slot); @@ -5033,7 +5041,7 @@ pub mod tests { #[test] fn test_set_roots() { let blockstore_path = get_tmp_ledger_path!(); - let blockstore = Blockstore::open(&blockstore_path).unwrap(); + let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); let chained_slots = vec![0, 2, 4, 7, 12, 15]; assert_eq!(blockstore.last_root(), 0); @@ -5052,7 +5060,7 @@ pub mod tests { #[test] fn test_purge_slots() { let blockstore_path = get_tmp_ledger_path!(); - let blockstore = Blockstore::open(&blockstore_path).unwrap(); + let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); let (shreds, _) = make_many_slot_entries(0, 50, 5); blockstore.insert_shreds(shreds, None, false).unwrap(); @@ -5080,7 +5088,7 @@ pub mod tests { #[test] fn test_purge_huge() { let blockstore_path = get_tmp_ledger_path!(); - let blockstore = Blockstore::open(&blockstore_path).unwrap(); + let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); let (shreds, _) = make_many_slot_entries(0, 5000, 10); blockstore.insert_shreds(shreds, None, false).unwrap(); @@ -5095,7 +5103,7 @@ pub mod tests { #[test] fn test_iter_bounds() { let blockstore_path = get_tmp_ledger_path!(); - let blockstore = Blockstore::open(&blockstore_path).unwrap(); + let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); // slot 5 does not exist, iter should be ok and should be a noop blockstore @@ -5171,7 +5179,7 @@ pub mod tests { fn test_get_slot_entries_with_shred_count_corruption() { let blockstore_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open(&blockstore_path).unwrap(); + let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); let num_ticks = 8; let entries = create_ticks(num_ticks, 0, Hash::default()); let slot = 1; @@ -5215,7 +5223,7 @@ pub mod tests { let (shreds0, _) = make_slot_entries(0, 0, 200); let blockstore_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open(&blockstore_path).unwrap(); + let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); // Insert the first 5 shreds, we don't have a "is_last" shred yet blockstore @@ -5246,7 +5254,7 @@ pub mod tests { let blockstore_path = get_tmp_ledger_path!(); let last_root = 100; { - let blockstore = Blockstore::open(&blockstore_path).unwrap(); + let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); blockstore.set_roots(&[last_root]).unwrap(); // Insert will fail, slot < root @@ -5273,7 +5281,7 @@ pub mod tests { Build a blockstore with < TIMESTAMP_SLOT_RANGE roots */ let blockstore_path = get_tmp_ledger_path!(); - let blockstore = Blockstore::open(&blockstore_path).unwrap(); + let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); blockstore.set_roots(&[0]).unwrap(); let mut last_entry_hash = Hash::default(); for slot in 0..=3 { @@ -5312,7 +5320,7 @@ pub mod tests { */ let blockstore_path = get_tmp_ledger_path!(); - let blockstore = Blockstore::open(&blockstore_path).unwrap(); + let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); blockstore.set_roots(&[0]).unwrap(); let desired_roots = vec![1, 2, 3, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14, 16, 17, 18, 19]; let mut last_entry_hash = Hash::default(); @@ -5368,7 +5376,7 @@ pub mod tests { let shreds = entries_to_test_shreds(entries.clone(), slot, slot - 1, true, 0); let more_shreds = entries_to_test_shreds(entries.clone(), slot + 1, slot, true, 0); let ledger_path = get_tmp_ledger_path!(); - let ledger = Blockstore::open(&ledger_path).unwrap(); + let ledger = Blockstore::open_as_primary(&ledger_path).unwrap(); ledger.insert_shreds(shreds, None, false).unwrap(); ledger.insert_shreds(more_shreds, None, false).unwrap(); ledger.set_roots(&[slot - 1, slot, slot + 1]).unwrap(); @@ -5513,7 +5521,7 @@ pub mod tests { } let shreds = entries_to_test_shreds(vote_entries, 1, 0, true, 0); let ledger_path = get_tmp_ledger_path!(); - let blockstore = Blockstore::open(&ledger_path).unwrap(); + let blockstore = Blockstore::open_as_primary(&ledger_path).unwrap(); blockstore.insert_shreds(shreds, None, false).unwrap(); // Populate slot 2 with ticks only fill_blockstore_slot_with_ticks(&blockstore, 6, 2, 1, Hash::default()); @@ -5667,7 +5675,7 @@ pub mod tests { fn test_persist_transaction_status() { let blockstore_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open(&blockstore_path).unwrap(); + let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); let transaction_status_cf = blockstore.db.column::(); let pre_balances_vec = vec![1, 2, 3]; @@ -5747,11 +5755,11 @@ pub mod tests { fn test_transaction_status_index() { let blockstore_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open(&blockstore_path).unwrap(); + let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); let transaction_status_index_cf = blockstore.db.column::(); let slot0 = 10; - // Primary index column is initialized on Blockstore::open + // Primary index column is initialized on Blockstore::open_as_primary assert!(transaction_status_index_cf.get(0).unwrap().is_some()); assert!(transaction_status_index_cf.get(1).unwrap().is_some()); @@ -5952,7 +5960,7 @@ pub mod tests { fn test_purge_transaction_status() { let blockstore_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open(&blockstore_path).unwrap(); + let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); let transaction_status_index_cf = blockstore.db.column::(); let slot = 10; for _ in 0..5 { @@ -6114,7 +6122,7 @@ pub mod tests { fn test_get_transaction_status() { let blockstore_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open(&blockstore_path).unwrap(); + let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); // TransactionStatus column opens initialized with one entry at index 2 let transaction_status_cf = blockstore.db.column::(); @@ -6238,7 +6246,7 @@ pub mod tests { let entries = make_slot_entries_with_transactions(5); let shreds = entries_to_test_shreds(entries.clone(), slot, slot - 1, true, 0); let ledger_path = get_tmp_ledger_path!(); - let blockstore = Blockstore::open(&ledger_path).unwrap(); + let blockstore = Blockstore::open_as_primary(&ledger_path).unwrap(); blockstore.insert_shreds(shreds, None, false).unwrap(); blockstore.set_roots(&[slot - 1, slot]).unwrap(); @@ -6318,7 +6326,7 @@ pub mod tests { fn test_get_confirmed_signatures_for_address() { let blockstore_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open(&blockstore_path).unwrap(); + let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); let address0 = Pubkey::new_rand(); let address1 = Pubkey::new_rand(); @@ -6472,7 +6480,7 @@ pub mod tests { fn test_map_transactions_to_statuses() { let blockstore_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open(&blockstore_path).unwrap(); + let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); let transaction_status_cf = blockstore.db.column::(); let slot = 0; @@ -6527,7 +6535,7 @@ pub mod tests { fn test_lowest_slot() { let blockstore_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open(&blockstore_path).unwrap(); + let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); for i in 0..10 { let slot = i; let (shreds, _) = make_slot_entries(slot, 0, 1); @@ -6547,7 +6555,7 @@ pub mod tests { setup_erasure_shreds(slot, 0, 100, 1.0); let blockstore_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open(&blockstore_path).unwrap(); + let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); blockstore .insert_shreds(coding_shreds, Some(&leader_schedule_cache), false) .unwrap(); @@ -6582,7 +6590,7 @@ pub mod tests { assert!(coding_shreds.len() > 3); let blockstore_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open(&blockstore_path).unwrap(); + let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); // Test inserting all the shreds let all_shreds: Vec<_> = data_shreds .iter() @@ -6788,7 +6796,7 @@ pub mod tests { let blockstore_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open(&blockstore_path).unwrap(); + let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); blockstore .insert_shreds(vec![shred.clone()], None, false) .unwrap(); @@ -6826,7 +6834,7 @@ pub mod tests { fn test_clear_unconfirmed_slot() { let blockstore_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open(&blockstore_path).unwrap(); + let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); let unconfirmed_slot = 9; let unconfirmed_child_slot = 10; let slots = vec![2, unconfirmed_slot, unconfirmed_child_slot]; diff --git a/ledger/src/blockstore_db.rs b/ledger/src/blockstore_db.rs index 7ca28c47705905..5f7b4859faf98c 100644 --- a/ledger/src/blockstore_db.rs +++ b/ledger/src/blockstore_db.rs @@ -207,7 +207,7 @@ impl Rocks { Ok(db) => Rocks(db, ActualAccessType::Primary), Err(err) => { warn!("Error when opening as primary: {}", err); - warn!("Trying as secondary at : {:?}", secondary_path); + warn!("Trying to open as secondary with: {:?}", secondary_path); warn!("This active secondary db use may temporarily cause the performance of another db use (like by validator) to degrade"); Rocks( DB::open_cf_as_secondary(&db_options, path, &secondary_path, names)?, diff --git a/ledger/src/blockstore_processor.rs b/ledger/src/blockstore_processor.rs index 5556b4ee4125d0..0afa6eee3ef3cb 100644 --- a/ledger/src/blockstore_processor.rs +++ b/ledger/src/blockstore_processor.rs @@ -895,8 +895,8 @@ pub mod tests { let ticks_per_slot = genesis_config.ticks_per_slot; let (ledger_path, blockhash) = create_new_tmp_ledger!(&genesis_config); - let blockstore = - Blockstore::open(&ledger_path).expect("Expected to successfully open database ledger"); + let blockstore = Blockstore::open_as_primary(&ledger_path) + .expect("Expected to successfully open database ledger"); let parent_slot = 0; let slot = 1; @@ -938,7 +938,7 @@ pub mod tests { // Create a new ledger with slot 0 full of ticks let (ledger_path, blockhash) = create_new_tmp_ledger!(&genesis_config); - let blockstore = Blockstore::open(&ledger_path).unwrap(); + let blockstore = Blockstore::open_as_primary(&ledger_path).unwrap(); // Write slot 1 with one tick missing let parent_slot = 0; @@ -1005,7 +1005,7 @@ pub mod tests { let ticks_per_slot = genesis_config.ticks_per_slot; let (ledger_path, blockhash) = create_new_tmp_ledger!(&genesis_config); - let blockstore = Blockstore::open(&ledger_path).unwrap(); + let blockstore = Blockstore::open_as_primary(&ledger_path).unwrap(); let mut entries = create_ticks(ticks_per_slot, 0, blockhash); let trailing_entry = { @@ -1066,8 +1066,8 @@ pub mod tests { let (ledger_path, mut blockhash) = create_new_tmp_ledger!(&genesis_config); debug!("ledger_path: {:?}", ledger_path); - let blockstore = - Blockstore::open(&ledger_path).expect("Expected to successfully open database ledger"); + let blockstore = Blockstore::open_as_primary(&ledger_path) + .expect("Expected to successfully open database ledger"); // Write slot 1 // slot 1, points at slot 0. Missing one tick @@ -1155,8 +1155,8 @@ pub mod tests { slot 4 <-- set_root(true) */ - let blockstore = - Blockstore::open(&ledger_path).expect("Expected to successfully open database ledger"); + let blockstore = Blockstore::open_as_primary(&ledger_path) + .expect("Expected to successfully open database ledger"); // Fork 1, ending at slot 3 let last_slot1_entry_hash = @@ -1234,8 +1234,8 @@ pub mod tests { slot 4 */ - let blockstore = - Blockstore::open(&ledger_path).expect("Expected to successfully open database ledger"); + let blockstore = Blockstore::open_as_primary(&ledger_path) + .expect("Expected to successfully open database ledger"); // Fork 1, ending at slot 3 let last_slot1_entry_hash = @@ -1317,7 +1317,7 @@ pub mod tests { \ slot 3 */ - let blockstore = Blockstore::open(&ledger_path).unwrap(); + let blockstore = Blockstore::open_as_primary(&ledger_path).unwrap(); let slot1_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); @@ -1364,7 +1364,7 @@ pub mod tests { / \ slot 4 (dead) slot 3 */ - let blockstore = Blockstore::open(&ledger_path).unwrap(); + let blockstore = Blockstore::open_as_primary(&ledger_path).unwrap(); let slot1_blockhash = fill_blockstore_slot_with_ticks(&blockstore, ticks_per_slot, 1, 0, blockhash); let slot2_blockhash = @@ -1420,7 +1420,7 @@ pub mod tests { / \ slot 1 (dead) slot 2 (dead) */ - let blockstore = Blockstore::open(&ledger_path).unwrap(); + let blockstore = Blockstore::open_as_primary(&ledger_path).unwrap(); fill_blockstore_slot_with_ticks(&blockstore, ticks_per_slot, 1, 0, blockhash); fill_blockstore_slot_with_ticks(&blockstore, ticks_per_slot, 2, 0, blockhash); blockstore.set_dead_slot(1).unwrap(); @@ -1449,8 +1449,8 @@ pub mod tests { let (ledger_path, blockhash) = create_new_tmp_ledger!(&genesis_config); let mut last_entry_hash = blockhash; - let blockstore = - Blockstore::open(&ledger_path).expect("Expected to successfully open database ledger"); + let blockstore = Blockstore::open_as_primary(&ledger_path) + .expect("Expected to successfully open database ledger"); // Let last_slot be the number of slots in the first two epochs let epoch_schedule = get_epoch_schedule(&genesis_config, Vec::new()); @@ -1603,8 +1603,8 @@ pub mod tests { )); let last_blockhash = entries.last().unwrap().hash; - let blockstore = - Blockstore::open(&ledger_path).expect("Expected to successfully open database ledger"); + let blockstore = Blockstore::open_as_primary(&ledger_path) + .expect("Expected to successfully open database ledger"); blockstore .write_entries( 1, @@ -1646,7 +1646,7 @@ pub mod tests { genesis_config.ticks_per_slot = 1; let (ledger_path, _blockhash) = create_new_tmp_ledger!(&genesis_config); - let blockstore = Blockstore::open(&ledger_path).unwrap(); + let blockstore = Blockstore::open_as_primary(&ledger_path).unwrap(); let opts = ProcessOptions { poh_verify: true, ..ProcessOptions::default() @@ -1664,7 +1664,7 @@ pub mod tests { let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(123); let (ledger_path, _blockhash) = create_new_tmp_ledger!(&genesis_config); - let blockstore = Blockstore::open(&ledger_path).unwrap(); + let blockstore = Blockstore::open_as_primary(&ledger_path).unwrap(); let opts = ProcessOptions { override_num_threads: Some(1), ..ProcessOptions::default() @@ -1680,7 +1680,7 @@ pub mod tests { let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(123); let (ledger_path, _blockhash) = create_new_tmp_ledger!(&genesis_config); - let blockstore = Blockstore::open(&ledger_path).unwrap(); + let blockstore = Blockstore::open_as_primary(&ledger_path).unwrap(); let opts = ProcessOptions { full_leader_cache: true, ..ProcessOptions::default() @@ -1698,8 +1698,8 @@ pub mod tests { .. } = create_genesis_config(100); let (ledger_path, last_entry_hash) = create_new_tmp_ledger!(&genesis_config); - let blockstore = - Blockstore::open(&ledger_path).expect("Expected to successfully open database ledger"); + let blockstore = Blockstore::open_as_primary(&ledger_path) + .expect("Expected to successfully open database ledger"); let blockhash = genesis_config.hash(); let keypairs = [Keypair::new(), Keypair::new(), Keypair::new()]; @@ -2367,7 +2367,7 @@ pub mod tests { let ticks_per_slot = 1; genesis_config.ticks_per_slot = ticks_per_slot; let (ledger_path, blockhash) = create_new_tmp_ledger!(&genesis_config); - let blockstore = Blockstore::open(&ledger_path).unwrap(); + let blockstore = Blockstore::open_as_primary(&ledger_path).unwrap(); /* Build a blockstore in the ledger with the following fork structure: diff --git a/ledger/src/leader_schedule_cache.rs b/ledger/src/leader_schedule_cache.rs index 104f890379e1c9..6a7c386fc76ef3 100644 --- a/ledger/src/leader_schedule_cache.rs +++ b/ledger/src/leader_schedule_cache.rs @@ -445,7 +445,7 @@ mod tests { let ledger_path = get_tmp_ledger_path!(); { let blockstore = Arc::new( - Blockstore::open(&ledger_path) + Blockstore::open_as_primary(&ledger_path) .expect("Expected to be able to open database ledger"), ); diff --git a/ledger/src/next_slots_iterator.rs b/ledger/src/next_slots_iterator.rs index 945cdfab337201..f56f96f7b89d90 100644 --- a/ledger/src/next_slots_iterator.rs +++ b/ledger/src/next_slots_iterator.rs @@ -42,7 +42,7 @@ mod tests { #[test] fn test_next_slots_iterator() { let blockstore_path = get_tmp_ledger_path!(); - let blockstore = Blockstore::open(&blockstore_path).unwrap(); + let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); blockstore.set_roots(&[0]).unwrap(); let ticks_per_slot = 5; /* diff --git a/ledger/src/rooted_slot_iterator.rs b/ledger/src/rooted_slot_iterator.rs index 202a1b8b67f947..7a8a7f4910d440 100644 --- a/ledger/src/rooted_slot_iterator.rs +++ b/ledger/src/rooted_slot_iterator.rs @@ -83,7 +83,7 @@ mod tests { #[test] fn test_rooted_slot_iterator() { let blockstore_path = get_tmp_ledger_path!(); - let blockstore = Blockstore::open(&blockstore_path).unwrap(); + let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); blockstore.set_roots(&[0]).unwrap(); let ticks_per_slot = 5; /* @@ -158,7 +158,7 @@ mod tests { #[test] fn test_skipping_rooted_slot_iterator() { let blockstore_path = get_tmp_ledger_path!(); - let blockstore = Blockstore::open(&blockstore_path).unwrap(); + let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); let ticks_per_slot = 5; /* Build a blockstore in the ledger with the following fork structure: diff --git a/ledger/tests/blockstore.rs b/ledger/tests/blockstore.rs index 4fa73002a6ed2e..5caeb7f06b6bb2 100644 --- a/ledger/tests/blockstore.rs +++ b/ledger/tests/blockstore.rs @@ -10,7 +10,7 @@ use std::thread::Builder; #[test] fn test_multiple_threads_insert_shred() { let blockstore_path = get_tmp_ledger_path!(); - let blockstore = Arc::new(Blockstore::open(&blockstore_path).unwrap()); + let blockstore = Arc::new(Blockstore::open_as_primary(&blockstore_path).unwrap()); for _ in 0..100 { let num_threads = 10; diff --git a/local-cluster/src/cluster_tests.rs b/local-cluster/src/cluster_tests.rs index 0b47ef48df87ea..25fd71ab214978 100644 --- a/local-cluster/src/cluster_tests.rs +++ b/local-cluster/src/cluster_tests.rs @@ -140,7 +140,7 @@ pub fn validator_exit(entry_point_info: &ContactInfo, nodes: usize) { } pub fn verify_ledger_ticks(ledger_path: &Path, ticks_per_slot: usize) { - let ledger = Blockstore::open(ledger_path).unwrap(); + let ledger = Blockstore::open_as_primary(ledger_path).unwrap(); let zeroth_slot = ledger.get_slot_entries(0, 0).unwrap(); let last_id = zeroth_slot.last().unwrap().hash; let next_slots = ledger.get_slots_since(&[0]).unwrap().remove(&0).unwrap(); diff --git a/local-cluster/tests/local_cluster.rs b/local-cluster/tests/local_cluster.rs index 9ef8e3f3bdb46b..481ba70f2cccbe 100644 --- a/local-cluster/tests/local_cluster.rs +++ b/local-cluster/tests/local_cluster.rs @@ -69,7 +69,7 @@ fn test_ledger_cleanup_service() { //check everyone's ledgers and make sure only ~100 slots are stored for info in cluster.validators.values() { let mut slots = 0; - let blockstore = Blockstore::open(&info.info.ledger_path).unwrap(); + let blockstore = Blockstore::open_as_primary(&info.info.ledger_path).unwrap(); blockstore .slot_meta_iterator(0) .unwrap() @@ -991,7 +991,7 @@ fn test_snapshots_blockstore_floor() { // Check the validator ledger doesn't contain any slots < slot_floor cluster.close_preserve_ledgers(); let validator_ledger_path = &cluster.validators[&validator_id]; - let blockstore = Blockstore::open(&validator_ledger_path.info.ledger_path).unwrap(); + let blockstore = Blockstore::open_as_primary(&validator_ledger_path.info.ledger_path).unwrap(); // Skip the zeroth slot in blockstore that the ledger is initialized with let (first_slot, _) = blockstore.slot_meta_iterator(1).unwrap().next().unwrap(); @@ -1152,7 +1152,7 @@ fn test_no_voting() { cluster.close_preserve_ledgers(); let leader_pubkey = cluster.entry_point_info.id; let ledger_path = cluster.validators[&leader_pubkey].info.ledger_path.clone(); - let ledger = Blockstore::open(&ledger_path).unwrap(); + let ledger = Blockstore::open_as_primary(&ledger_path).unwrap(); for i in 0..2 * VOTE_THRESHOLD_DEPTH { let meta = ledger.meta(i as u64).unwrap().unwrap(); let parent = meta.parent_slot; From 64e06823639a9bd8f00c57009f6e454df8e6d47e Mon Sep 17 00:00:00 2001 From: Ryo Onodera Date: Mon, 25 May 2020 11:02:39 +0900 Subject: [PATCH 03/12] Another clippy fix --- ledger-tool/src/main.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/ledger-tool/src/main.rs b/ledger-tool/src/main.rs index 946d74493fa1f0..a1e69b1576cf0d 100644 --- a/ledger-tool/src/main.rs +++ b/ledger-tool/src/main.rs @@ -568,14 +568,15 @@ fn load_bank_forks( let blockstore = open_blockstore(&ledger_path, access_type); let account_paths = if let Some(account_paths) = arg_matches.value_of("account_paths") { account_paths.split(',').map(PathBuf::from).collect() + } else if blockstore.is_primary_access() { + vec![ledger_path.join("accounts")] } else { - if blockstore.is_primary_access() { - vec![ledger_path.join("accounts")] - } else { - let non_primary_accounts_path = ledger_path.join("accounts.ledger-tool"); - eprintln!("Default accounts path is switched aligning with Blockstore's non-primary access: {:?}", non_primary_accounts_path); - vec![non_primary_accounts_path] - } + let non_primary_accounts_path = ledger_path.join("accounts.ledger-tool"); + eprintln!( + "Default accounts path is switched aligning with Blockstore's non-primary access: {:?}", + non_primary_accounts_path + ); + vec![non_primary_accounts_path] }; bank_forks_utils::load( From 7949a606002392dd0c06130e94b3161b6b5acc08 Mon Sep 17 00:00:00 2001 From: Ryo Onodera Date: Sat, 30 May 2020 19:55:05 +0900 Subject: [PATCH 04/12] Revert "Fix build?" This reverts commit 71e4c8c8b666ddcc35d0e70920eb36e5f3a3286b. --- banking-bench/src/main.rs | 3 +- core/benches/banking_stage.rs | 6 +- core/benches/blockstore.rs | 20 +-- core/src/banking_stage.rs | 18 +-- core/src/broadcast_stage.rs | 4 +- .../broadcast_stage/standard_broadcast_run.rs | 3 +- core/src/cluster_info_vote_listener.rs | 4 +- core/src/commitment.rs | 6 +- core/src/ledger_cleanup_service.rs | 4 +- core/src/poh_recorder.rs | 42 +++--- core/src/poh_service.rs | 2 +- core/src/repair_service.rs | 20 +-- core/src/replay_stage.rs | 8 +- core/src/retransmit_stage.rs | 2 +- core/src/rpc.rs | 12 +- core/src/rpc_pubsub.rs | 20 +-- core/src/rpc_pubsub_service.rs | 2 +- core/src/rpc_service.rs | 2 +- core/src/rpc_subscriptions.rs | 12 +- core/src/serve_repair.rs | 6 +- core/src/tvu.rs | 4 +- core/src/window_service.rs | 4 +- core/tests/client.rs | 2 +- core/tests/ledger_cleanup.rs | 4 +- ledger/src/blockstore.rs | 126 ++++++++---------- ledger/src/blockstore_db.rs | 2 +- ledger/src/blockstore_processor.rs | 46 +++---- ledger/src/leader_schedule_cache.rs | 2 +- ledger/src/next_slots_iterator.rs | 2 +- ledger/src/rooted_slot_iterator.rs | 4 +- ledger/tests/blockstore.rs | 2 +- local-cluster/src/cluster_tests.rs | 2 +- local-cluster/tests/local_cluster.rs | 6 +- 33 files changed, 195 insertions(+), 207 deletions(-) diff --git a/banking-bench/src/main.rs b/banking-bench/src/main.rs index c0ef00e0fa566d..824237da887815 100644 --- a/banking-bench/src/main.rs +++ b/banking-bench/src/main.rs @@ -213,8 +213,7 @@ fn main() { let ledger_path = get_tmp_ledger_path!(); { let blockstore = Arc::new( - Blockstore::open_as_primary(&ledger_path) - .expect("Expected to be able to open database ledger"), + Blockstore::open(&ledger_path).expect("Expected to be able to open database ledger"), ); let (exit, poh_recorder, poh_service, signal_receiver) = create_test_recorder(&bank, &blockstore, None); diff --git a/core/benches/banking_stage.rs b/core/benches/banking_stage.rs index 7ee4108a4e45e5..9336b370492d19 100644 --- a/core/benches/banking_stage.rs +++ b/core/benches/banking_stage.rs @@ -58,8 +58,7 @@ fn bench_consume_buffered(bencher: &mut Bencher) { let my_pubkey = Pubkey::new_rand(); { let blockstore = Arc::new( - Blockstore::open_as_primary(&ledger_path) - .expect("Expected to be able to open database ledger"), + Blockstore::open(&ledger_path).expect("Expected to be able to open database ledger"), ); let (exit, poh_recorder, poh_service, _signal_receiver) = create_test_recorder(&bank, &blockstore, None); @@ -186,8 +185,7 @@ fn bench_banking(bencher: &mut Bencher, tx_type: TransactionType) { let ledger_path = get_tmp_ledger_path!(); { let blockstore = Arc::new( - Blockstore::open_as_primary(&ledger_path) - .expect("Expected to be able to open database ledger"), + Blockstore::open(&ledger_path).expect("Expected to be able to open database ledger"), ); let (exit, poh_recorder, poh_service, signal_receiver) = create_test_recorder(&bank, &blockstore, None); diff --git a/core/benches/blockstore.rs b/core/benches/blockstore.rs index 9c81d99049dd57..aac755a952c245 100644 --- a/core/benches/blockstore.rs +++ b/core/benches/blockstore.rs @@ -16,8 +16,8 @@ use test::Bencher; // Given some shreds and a ledger at ledger_path, benchmark writing the shreds to the ledger fn bench_write_shreds(bench: &mut Bencher, entries: Vec, ledger_path: &Path) { - let blockstore = Blockstore::open_as_primary(ledger_path) - .expect("Expected to be able to open database ledger"); + let blockstore = + Blockstore::open(ledger_path).expect("Expected to be able to open database ledger"); bench.iter(move || { let shreds = entries_to_test_shreds(entries.clone(), 0, 0, true, 0); blockstore.insert_shreds(shreds, None, false).unwrap(); @@ -71,8 +71,8 @@ fn bench_write_big(bench: &mut Bencher) { #[ignore] fn bench_read_sequential(bench: &mut Bencher) { let ledger_path = get_tmp_ledger_path!(); - let mut blockstore = Blockstore::open_as_primary(&ledger_path) - .expect("Expected to be able to open database ledger"); + let mut blockstore = + Blockstore::open(&ledger_path).expect("Expected to be able to open database ledger"); // Insert some big and small shreds into the ledger let num_small_shreds = 32 * 1024; @@ -98,8 +98,8 @@ fn bench_read_sequential(bench: &mut Bencher) { #[ignore] fn bench_read_random(bench: &mut Bencher) { let ledger_path = get_tmp_ledger_path!(); - let mut blockstore = Blockstore::open_as_primary(&ledger_path) - .expect("Expected to be able to open database ledger"); + let mut blockstore = + Blockstore::open(&ledger_path).expect("Expected to be able to open database ledger"); // Insert some big and small shreds into the ledger let num_small_shreds = 32 * 1024; @@ -129,8 +129,8 @@ fn bench_read_random(bench: &mut Bencher) { #[ignore] fn bench_insert_data_shred_small(bench: &mut Bencher) { let ledger_path = get_tmp_ledger_path!(); - let blockstore = Blockstore::open_as_primary(&ledger_path) - .expect("Expected to be able to open database ledger"); + let blockstore = + Blockstore::open(&ledger_path).expect("Expected to be able to open database ledger"); let num_entries = 32 * 1024; let entries = create_ticks(num_entries, 0, Hash::default()); bench.iter(move || { @@ -144,8 +144,8 @@ fn bench_insert_data_shred_small(bench: &mut Bencher) { #[ignore] fn bench_insert_data_shred_big(bench: &mut Bencher) { let ledger_path = get_tmp_ledger_path!(); - let blockstore = Blockstore::open_as_primary(&ledger_path) - .expect("Expected to be able to open database ledger"); + let blockstore = + Blockstore::open(&ledger_path).expect("Expected to be able to open database ledger"); let num_entries = 32 * 1024; let entries = create_ticks(num_entries, 0, Hash::default()); bench.iter(move || { diff --git a/core/src/banking_stage.rs b/core/src/banking_stage.rs index c6c28cb251aa9c..4feffefbaeb3c4 100644 --- a/core/src/banking_stage.rs +++ b/core/src/banking_stage.rs @@ -1046,7 +1046,7 @@ mod tests { let ledger_path = get_tmp_ledger_path!(); { let blockstore = Arc::new( - Blockstore::open_as_primary(&ledger_path) + Blockstore::open(&ledger_path) .expect("Expected to be able to open database ledger"), ); let (exit, poh_recorder, poh_service, _entry_receiever) = @@ -1084,7 +1084,7 @@ mod tests { let ledger_path = get_tmp_ledger_path!(); { let blockstore = Arc::new( - Blockstore::open_as_primary(&ledger_path) + Blockstore::open(&ledger_path) .expect("Expected to be able to open database ledger"), ); let mut poh_config = PohConfig::default(); @@ -1146,7 +1146,7 @@ mod tests { let ledger_path = get_tmp_ledger_path!(); { let blockstore = Arc::new( - Blockstore::open_as_primary(&ledger_path) + Blockstore::open(&ledger_path) .expect("Expected to be able to open database ledger"), ); let mut poh_config = PohConfig::default(); @@ -1286,7 +1286,7 @@ mod tests { // start a banking_stage to eat verified receiver let bank = Arc::new(Bank::new(&genesis_config)); let blockstore = Arc::new( - Blockstore::open_as_primary(&ledger_path) + Blockstore::open(&ledger_path) .expect("Expected to be able to open database ledger"), ); let mut poh_config = PohConfig::default(); @@ -1354,7 +1354,7 @@ mod tests { }; let ledger_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open_as_primary(&ledger_path) + let blockstore = Blockstore::open(&ledger_path) .expect("Expected to be able to open database ledger"); let (poh_recorder, entry_receiver) = PohRecorder::new( bank.tick_height(), @@ -1665,7 +1665,7 @@ mod tests { }; let ledger_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open_as_primary(&ledger_path) + let blockstore = Blockstore::open(&ledger_path) .expect("Expected to be able to open database ledger"); let (poh_recorder, entry_receiver) = PohRecorder::new( bank.tick_height(), @@ -1758,7 +1758,7 @@ mod tests { }; let ledger_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open_as_primary(&ledger_path) + let blockstore = Blockstore::open(&ledger_path) .expect("Expected to be able to open database ledger"); let (poh_recorder, _entry_receiver) = PohRecorder::new( bank.tick_height(), @@ -1846,7 +1846,7 @@ mod tests { let ledger_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open_as_primary(&ledger_path) + let blockstore = Blockstore::open(&ledger_path) .expect("Expected to be able to open database ledger"); let (poh_recorder, _entry_receiver) = PohRecorder::new( bank.tick_height(), @@ -1913,7 +1913,7 @@ mod tests { }; let ledger_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open_as_primary(&ledger_path) + let blockstore = Blockstore::open(&ledger_path) .expect("Expected to be able to open database ledger"); let blockstore = Arc::new(blockstore); let (poh_recorder, _entry_receiver) = PohRecorder::new( diff --git a/core/src/broadcast_stage.rs b/core/src/broadcast_stage.rs index 2d6f0783e626a6..9e9e6c31bec8dc 100644 --- a/core/src/broadcast_stage.rs +++ b/core/src/broadcast_stage.rs @@ -526,7 +526,7 @@ pub mod test { fn test_duplicate_retransmit_signal() { // Setup let ledger_path = get_tmp_ledger_path!(); - let blockstore = Arc::new(Blockstore::open_as_primary(&ledger_path).unwrap()); + let blockstore = Arc::new(Blockstore::open(&ledger_path).unwrap()); let (transmit_sender, transmit_receiver) = channel(); let (retransmit_slots_sender, retransmit_slots_receiver) = unbounded(); let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(100_000); @@ -585,7 +585,7 @@ pub mod test { retransmit_slots_receiver: RetransmitSlotsReceiver, ) -> MockBroadcastStage { // Make the database ledger - let blockstore = Arc::new(Blockstore::open_as_primary(ledger_path).unwrap()); + let blockstore = Arc::new(Blockstore::open(ledger_path).unwrap()); // Make the leader node and scheduler let leader_info = Node::new_localhost_with_pubkey(leader_pubkey); diff --git a/core/src/broadcast_stage/standard_broadcast_run.rs b/core/src/broadcast_stage/standard_broadcast_run.rs index 502dc4cd649309..3f3a888da1c60a 100644 --- a/core/src/broadcast_stage/standard_broadcast_run.rs +++ b/core/src/broadcast_stage/standard_broadcast_run.rs @@ -420,8 +420,7 @@ mod test { // Setup let ledger_path = get_tmp_ledger_path!(); let blockstore = Arc::new( - Blockstore::open_as_primary(&ledger_path) - .expect("Expected to be able to open database ledger"), + Blockstore::open(&ledger_path).expect("Expected to be able to open database ledger"), ); let leader_keypair = Arc::new(Keypair::new()); let leader_pubkey = leader_keypair.pubkey(); diff --git a/core/src/cluster_info_vote_listener.rs b/core/src/cluster_info_vote_listener.rs index 7937ab6cf25401..fc1f1f3c884138 100644 --- a/core/src/cluster_info_vote_listener.rs +++ b/core/src/cluster_info_vote_listener.rs @@ -952,7 +952,7 @@ mod tests { let bank = bank_forks.get(0).unwrap().clone(); let vote_tracker = VoteTracker::new(&bank); let ledger_path = get_tmp_ledger_path!(); - let blockstore = Arc::new(Blockstore::open_as_primary(&ledger_path).unwrap()); + let blockstore = Arc::new(Blockstore::open(&ledger_path).unwrap()); let subscriptions = Arc::new(RpcSubscriptions::new( &exit, Arc::new(RwLock::new(bank_forks)), @@ -1067,7 +1067,7 @@ mod tests { let bank_forks = BankForks::new(0, bank); let bank = bank_forks.get(0).unwrap().clone(); let ledger_path = get_tmp_ledger_path!(); - let blockstore = Arc::new(Blockstore::open_as_primary(&ledger_path).unwrap()); + let blockstore = Arc::new(Blockstore::open(&ledger_path).unwrap()); let subscriptions = Arc::new(RpcSubscriptions::new( &exit, Arc::new(RwLock::new(bank_forks)), diff --git a/core/src/commitment.rs b/core/src/commitment.rs index 1abaea00f37c48..a26be76655e9fd 100644 --- a/core/src/commitment.rs +++ b/core/src/commitment.rs @@ -450,7 +450,7 @@ mod tests { fn test_get_confirmations() { let bank = Arc::new(Bank::default()); let ledger_path = get_tmp_ledger_path!(); - let blockstore = Arc::new(Blockstore::open_as_primary(&ledger_path).unwrap()); + let blockstore = Arc::new(Blockstore::open(&ledger_path).unwrap()); // Build BlockCommitmentCache with votes at depths 0 and 1 for 2 slots let mut cache0 = BlockCommitment::default(); cache0.increase_confirmation_stake(1, 5); @@ -481,7 +481,7 @@ mod tests { fn test_is_confirmed_rooted() { let bank = Arc::new(Bank::default()); let ledger_path = get_tmp_ledger_path!(); - let blockstore = Arc::new(Blockstore::open_as_primary(&ledger_path).unwrap()); + let blockstore = Arc::new(Blockstore::open(&ledger_path).unwrap()); blockstore.set_roots(&[0, 1]).unwrap(); // Build BlockCommitmentCache with rooted slots let mut cache0 = BlockCommitment::default(); @@ -532,7 +532,7 @@ mod tests { let bank = Arc::new(Bank::new(&GenesisConfig::default())); let bank_slot_5 = Arc::new(Bank::new_from_parent(&bank, &Pubkey::default(), 5)); let ledger_path = get_tmp_ledger_path!(); - let blockstore = Arc::new(Blockstore::open_as_primary(&ledger_path).unwrap()); + let blockstore = Arc::new(Blockstore::open(&ledger_path).unwrap()); let total_stake = 50; // Build cache with confirmation_count 2 given total_stake diff --git a/core/src/ledger_cleanup_service.rs b/core/src/ledger_cleanup_service.rs index af35780d855440..50345745e089ca 100644 --- a/core/src/ledger_cleanup_service.rs +++ b/core/src/ledger_cleanup_service.rs @@ -225,7 +225,7 @@ mod tests { fn test_cleanup() { solana_logger::setup(); let blockstore_path = get_tmp_ledger_path!(); - let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); + let blockstore = Blockstore::open(&blockstore_path).unwrap(); let (shreds, _) = make_many_slot_entries(0, 50, 5); blockstore.insert_shreds(shreds, None, false).unwrap(); let blockstore = Arc::new(blockstore); @@ -258,7 +258,7 @@ mod tests { fn test_cleanup_speed() { solana_logger::setup(); let blockstore_path = get_tmp_ledger_path!(); - let mut blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); + let mut blockstore = Blockstore::open(&blockstore_path).unwrap(); blockstore.set_no_compaction(true); let blockstore = Arc::new(blockstore); let (sender, receiver) = channel(); diff --git a/core/src/poh_recorder.rs b/core/src/poh_recorder.rs index 314e200fd76d45..5653ca3b8cc274 100644 --- a/core/src/poh_recorder.rs +++ b/core/src/poh_recorder.rs @@ -524,7 +524,7 @@ mod tests { let prev_hash = Hash::default(); let ledger_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open_as_primary(&ledger_path) + let blockstore = Blockstore::open(&ledger_path) .expect("Expected to be able to open database ledger"); let (mut poh_recorder, _entry_receiver) = PohRecorder::new( @@ -551,7 +551,7 @@ mod tests { let prev_hash = Hash::default(); let ledger_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open_as_primary(&ledger_path) + let blockstore = Blockstore::open(&ledger_path) .expect("Expected to be able to open database ledger"); let (mut poh_recorder, _entry_receiver) = PohRecorder::new( @@ -578,7 +578,7 @@ mod tests { fn test_poh_recorder_reset_clears_cache() { let ledger_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open_as_primary(&ledger_path) + let blockstore = Blockstore::open(&ledger_path) .expect("Expected to be able to open database ledger"); let (mut poh_recorder, _entry_receiver) = PohRecorder::new( 0, @@ -603,7 +603,7 @@ mod tests { fn test_poh_recorder_clear() { let ledger_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open_as_primary(&ledger_path) + let blockstore = Blockstore::open(&ledger_path) .expect("Expected to be able to open database ledger"); let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(2); let bank = Arc::new(Bank::new(&genesis_config)); @@ -637,7 +637,7 @@ mod tests { fn test_poh_recorder_tick_sent_after_min() { let ledger_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open_as_primary(&ledger_path) + let blockstore = Blockstore::open(&ledger_path) .expect("Expected to be able to open database ledger"); let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(2); let bank = Arc::new(Bank::new(&genesis_config)); @@ -686,7 +686,7 @@ mod tests { fn test_poh_recorder_tick_sent_upto_and_including_max() { let ledger_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open_as_primary(&ledger_path) + let blockstore = Blockstore::open(&ledger_path) .expect("Expected to be able to open database ledger"); let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(2); let bank = Arc::new(Bank::new(&genesis_config)); @@ -733,7 +733,7 @@ mod tests { fn test_poh_recorder_record_to_early() { let ledger_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open_as_primary(&ledger_path) + let blockstore = Blockstore::open(&ledger_path) .expect("Expected to be able to open database ledger"); let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(2); let bank = Arc::new(Bank::new(&genesis_config)); @@ -769,7 +769,7 @@ mod tests { fn test_poh_recorder_record_bad_slot() { let ledger_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open_as_primary(&ledger_path) + let blockstore = Blockstore::open(&ledger_path) .expect("Expected to be able to open database ledger"); let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(2); let bank = Arc::new(Bank::new(&genesis_config)); @@ -809,7 +809,7 @@ mod tests { fn test_poh_recorder_record_at_min_passes() { let ledger_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open_as_primary(&ledger_path) + let blockstore = Blockstore::open(&ledger_path) .expect("Expected to be able to open database ledger"); let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(2); let bank = Arc::new(Bank::new(&genesis_config)); @@ -853,7 +853,7 @@ mod tests { fn test_poh_recorder_record_at_max_fails() { let ledger_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open_as_primary(&ledger_path) + let blockstore = Blockstore::open(&ledger_path) .expect("Expected to be able to open database ledger"); let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(2); let bank = Arc::new(Bank::new(&genesis_config)); @@ -895,7 +895,7 @@ mod tests { fn test_poh_cache_on_disconnect() { let ledger_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open_as_primary(&ledger_path) + let blockstore = Blockstore::open(&ledger_path) .expect("Expected to be able to open database ledger"); let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(2); let bank = Arc::new(Bank::new(&genesis_config)); @@ -933,7 +933,7 @@ mod tests { fn test_reset_current() { let ledger_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open_as_primary(&ledger_path) + let blockstore = Blockstore::open(&ledger_path) .expect("Expected to be able to open database ledger"); let (mut poh_recorder, _entry_receiver) = PohRecorder::new( 0, @@ -960,7 +960,7 @@ mod tests { fn test_reset_with_cached() { let ledger_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open_as_primary(&ledger_path) + let blockstore = Blockstore::open(&ledger_path) .expect("Expected to be able to open database ledger"); let (mut poh_recorder, _entry_receiver) = PohRecorder::new( 0, @@ -988,7 +988,7 @@ mod tests { let ledger_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open_as_primary(&ledger_path) + let blockstore = Blockstore::open(&ledger_path) .expect("Expected to be able to open database ledger"); let (mut poh_recorder, _entry_receiver) = PohRecorder::new( 0, @@ -1019,7 +1019,7 @@ mod tests { fn test_reset_clear_bank() { let ledger_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open_as_primary(&ledger_path) + let blockstore = Blockstore::open(&ledger_path) .expect("Expected to be able to open database ledger"); let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(2); let bank = Arc::new(Bank::new(&genesis_config)); @@ -1050,7 +1050,7 @@ mod tests { pub fn test_clear_signal() { let ledger_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open_as_primary(&ledger_path) + let blockstore = Blockstore::open(&ledger_path) .expect("Expected to be able to open database ledger"); let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(2); let bank = Arc::new(Bank::new(&genesis_config)); @@ -1079,7 +1079,7 @@ mod tests { solana_logger::setup(); let ledger_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open_as_primary(&ledger_path) + let blockstore = Blockstore::open(&ledger_path) .expect("Expected to be able to open database ledger"); let ticks_per_slot = 5; let GenesisConfigInfo { @@ -1130,7 +1130,7 @@ mod tests { let ledger_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open_as_primary(&ledger_path) + let blockstore = Blockstore::open(&ledger_path) .expect("Expected to be able to open database ledger"); let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(2); let bank = Arc::new(Bank::new(&genesis_config)); @@ -1192,7 +1192,7 @@ mod tests { let ledger_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open_as_primary(&ledger_path) + let blockstore = Blockstore::open(&ledger_path) .expect("Expected to be able to open database ledger"); let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(2); let bank = Arc::new(Bank::new(&genesis_config)); @@ -1319,7 +1319,7 @@ mod tests { fn test_would_be_leader_soon() { let ledger_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open_as_primary(&ledger_path) + let blockstore = Blockstore::open(&ledger_path) .expect("Expected to be able to open database ledger"); let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(2); let bank = Arc::new(Bank::new(&genesis_config)); @@ -1386,7 +1386,7 @@ mod tests { let ledger_path = get_tmp_ledger_path!(); { // test that virtual ticks are flushed into a newly set bank asap - let blockstore = Blockstore::open_as_primary(&ledger_path) + let blockstore = Blockstore::open(&ledger_path) .expect("Expected to be able to open database ledger"); let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(2); let bank = Arc::new(Bank::new(&genesis_config)); diff --git a/core/src/poh_service.rs b/core/src/poh_service.rs index fcda1b4bd4fed8..740a7ca6f42318 100644 --- a/core/src/poh_service.rs +++ b/core/src/poh_service.rs @@ -135,7 +135,7 @@ mod tests { let prev_hash = bank.last_blockhash(); let ledger_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open_as_primary(&ledger_path) + let blockstore = Blockstore::open(&ledger_path) .expect("Expected to be able to open database ledger"); let poh_config = Arc::new(PohConfig { hashes_per_tick: Some(2), diff --git a/core/src/repair_service.rs b/core/src/repair_service.rs index 7f8bba6d88fd9f..01ec5cb705ae8c 100644 --- a/core/src/repair_service.rs +++ b/core/src/repair_service.rs @@ -603,7 +603,7 @@ mod test { pub fn test_repair_orphan() { let blockstore_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); + let blockstore = Blockstore::open(&blockstore_path).unwrap(); // Create some orphan slots let (mut shreds, _) = make_slot_entries(1, 0, 1); @@ -623,7 +623,7 @@ mod test { pub fn test_repair_empty_slot() { let blockstore_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); + let blockstore = Blockstore::open(&blockstore_path).unwrap(); let (shreds, _) = make_slot_entries(2, 0, 1); @@ -644,7 +644,7 @@ mod test { pub fn test_generate_repairs() { let blockstore_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); + let blockstore = Blockstore::open(&blockstore_path).unwrap(); let nth = 3; let num_slots = 2; @@ -702,7 +702,7 @@ mod test { pub fn test_generate_highest_repair() { let blockstore_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); + let blockstore = Blockstore::open(&blockstore_path).unwrap(); let num_entries_per_slot = 100; @@ -732,7 +732,7 @@ mod test { pub fn test_repair_range() { let blockstore_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); + let blockstore = Blockstore::open(&blockstore_path).unwrap(); let slots: Vec = vec![1, 3, 5, 7, 8]; let num_entries_per_slot = max_ticks_per_n_shreds(1, None) + 1; @@ -781,7 +781,7 @@ mod test { pub fn test_repair_range_highest() { let blockstore_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); + let blockstore = Blockstore::open(&blockstore_path).unwrap(); let num_entries_per_slot = 10; @@ -836,7 +836,7 @@ mod test { #[test] pub fn test_generate_duplicate_repairs_for_slot() { let blockstore_path = get_tmp_ledger_path!(); - let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); + let blockstore = Blockstore::open(&blockstore_path).unwrap(); let dead_slot = 9; // SlotMeta doesn't exist, should make no repairs @@ -866,7 +866,7 @@ mod test { #[test] pub fn test_generate_and_send_duplicate_repairs() { let blockstore_path = get_tmp_ledger_path!(); - let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); + let blockstore = Blockstore::open(&blockstore_path).unwrap(); let cluster_slots = ClusterSlots::default(); let serve_repair = ServeRepair::new_with_invalid_keypair(Node::new_localhost().info); let mut duplicate_slot_repair_statuses = HashMap::new(); @@ -997,7 +997,7 @@ mod test { #[test] pub fn test_process_new_duplicate_slots() { let blockstore_path = get_tmp_ledger_path!(); - let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); + let blockstore = Blockstore::open(&blockstore_path).unwrap(); let cluster_slots = ClusterSlots::default(); let serve_repair = ServeRepair::new_with_invalid_keypair(Node::new_localhost().info); let mut duplicate_slot_repair_statuses = HashMap::new(); @@ -1071,7 +1071,7 @@ mod test { #[test] pub fn test_find_new_duplicate_slots() { let blockstore_path = get_tmp_ledger_path!(); - let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); + let blockstore = Blockstore::open(&blockstore_path).unwrap(); let cluster_slots = ClusterSlots::default(); let duplicate_slot_repair_statuses = HashMap::new(); let keypairs = ValidatorVoteKeypairs::new_rand(); diff --git a/core/src/replay_stage.rs b/core/src/replay_stage.rs index b8ff2f1d0a96ff..b8d81735ab1a83 100644 --- a/core/src/replay_stage.rs +++ b/core/src/replay_stage.rs @@ -2161,7 +2161,7 @@ pub(crate) mod tests { { // Setup let blockstore = Arc::new( - Blockstore::open_as_primary(&ledger_path) + Blockstore::open(&ledger_path) .expect("Expected to be able to open database ledger"), ); let validator_authorized_voter_keypairs: Vec<_> = (0..20) @@ -2590,7 +2590,7 @@ pub(crate) mod tests { let ledger_path = get_tmp_ledger_path!(); let res = { let blockstore = Arc::new( - Blockstore::open_as_primary(&ledger_path) + Blockstore::open(&ledger_path) .expect("Expected to be able to open database ledger"), ); let GenesisConfigInfo { @@ -2641,7 +2641,7 @@ pub(crate) mod tests { } let ledger_path = get_tmp_ledger_path!(); - let blockstore = Arc::new(Blockstore::open_as_primary(&ledger_path).unwrap()); + let blockstore = Arc::new(Blockstore::open(&ledger_path).unwrap()); let leader_pubkey = Pubkey::new_rand(); let leader_lamports = 3; @@ -2809,7 +2809,7 @@ pub(crate) mod tests { } = create_genesis_config(1000); let (ledger_path, _) = create_new_tmp_ledger!(&genesis_config); { - let blockstore = Blockstore::open_as_primary(&ledger_path) + let blockstore = Blockstore::open(&ledger_path) .expect("Expected to successfully open database ledger"); let blockstore = Arc::new(blockstore); diff --git a/core/src/retransmit_stage.rs b/core/src/retransmit_stage.rs index b67c02c61d2690..f3c0fbac816bda 100644 --- a/core/src/retransmit_stage.rs +++ b/core/src/retransmit_stage.rs @@ -419,7 +419,7 @@ mod tests { fn test_skip_repair() { let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(123); let (ledger_path, _blockhash) = create_new_tmp_ledger!(&genesis_config); - let blockstore = Blockstore::open_as_primary(&ledger_path).unwrap(); + let blockstore = Blockstore::open(&ledger_path).unwrap(); let opts = ProcessOptions { full_leader_cache: true, ..ProcessOptions::default() diff --git a/core/src/rpc.rs b/core/src/rpc.rs index 34d46c969c5bbc..4078fe9a44cc97 100644 --- a/core/src/rpc.rs +++ b/core/src/rpc.rs @@ -1693,7 +1693,7 @@ pub mod tests { let (bank_forks, alice, leader_vote_keypair) = new_bank_forks(); let bank = bank_forks.read().unwrap().working_bank(); let ledger_path = get_tmp_ledger_path!(); - let blockstore = Blockstore::open_as_primary(&ledger_path).unwrap(); + let blockstore = Blockstore::open(&ledger_path).unwrap(); let blockstore = Arc::new(blockstore); let keypair1 = Keypair::new(); @@ -1835,7 +1835,7 @@ pub mod tests { let (bank_forks, alice, _) = new_bank_forks(); let bank = bank_forks.read().unwrap().working_bank(); let ledger_path = get_tmp_ledger_path!(); - let blockstore = Arc::new(Blockstore::open_as_primary(&ledger_path).unwrap()); + let blockstore = Arc::new(Blockstore::open(&ledger_path).unwrap()); let block_commitment_cache = Arc::new(RwLock::new( BlockCommitmentCache::default_with_blockstore(blockstore.clone()), )); @@ -2773,7 +2773,7 @@ pub mod tests { let exit = Arc::new(AtomicBool::new(false)); let validator_exit = create_validator_exit(&exit); let ledger_path = get_tmp_ledger_path!(); - let blockstore = Arc::new(Blockstore::open_as_primary(&ledger_path).unwrap()); + let blockstore = Arc::new(Blockstore::open(&ledger_path).unwrap()); let block_commitment_cache = Arc::new(RwLock::new( BlockCommitmentCache::default_with_blockstore(blockstore.clone()), )); @@ -2871,7 +2871,7 @@ pub mod tests { let exit = Arc::new(AtomicBool::new(false)); let validator_exit = create_validator_exit(&exit); let ledger_path = get_tmp_ledger_path!(); - let blockstore = Arc::new(Blockstore::open_as_primary(&ledger_path).unwrap()); + let blockstore = Arc::new(Blockstore::open(&ledger_path).unwrap()); let block_commitment_cache = Arc::new(RwLock::new( BlockCommitmentCache::default_with_blockstore(blockstore.clone()), )); @@ -2891,7 +2891,7 @@ pub mod tests { let exit = Arc::new(AtomicBool::new(false)); let validator_exit = create_validator_exit(&exit); let ledger_path = get_tmp_ledger_path!(); - let blockstore = Arc::new(Blockstore::open_as_primary(&ledger_path).unwrap()); + let blockstore = Arc::new(Blockstore::open(&ledger_path).unwrap()); let block_commitment_cache = Arc::new(RwLock::new( BlockCommitmentCache::default_with_blockstore(blockstore.clone()), )); @@ -2956,7 +2956,7 @@ pub mod tests { let validator_exit = create_validator_exit(&exit); let bank_forks = new_bank_forks().0; let ledger_path = get_tmp_ledger_path!(); - let blockstore = Arc::new(Blockstore::open_as_primary(&ledger_path).unwrap()); + let blockstore = Arc::new(Blockstore::open(&ledger_path).unwrap()); let commitment_slot0 = BlockCommitment::new([8; MAX_LOCKOUT_HISTORY + 1]); let commitment_slot1 = BlockCommitment::new([9; MAX_LOCKOUT_HISTORY + 1]); diff --git a/core/src/rpc_pubsub.rs b/core/src/rpc_pubsub.rs index 3a41c1053e3563..80c429f69d436b 100644 --- a/core/src/rpc_pubsub.rs +++ b/core/src/rpc_pubsub.rs @@ -422,7 +422,7 @@ mod tests { let blockhash = bank.last_blockhash(); let bank_forks = Arc::new(RwLock::new(BankForks::new(0, bank))); let ledger_path = get_tmp_ledger_path!(); - let blockstore = Arc::new(Blockstore::open_as_primary(&ledger_path).unwrap()); + let blockstore = Arc::new(Blockstore::open(&ledger_path).unwrap()); let rpc = RpcSolPubSubImpl { subscriptions: Arc::new(RpcSubscriptions::new( &Arc::new(AtomicBool::new(false)), @@ -473,7 +473,7 @@ mod tests { let blockhash = bank.last_blockhash(); let bank_forks = Arc::new(RwLock::new(BankForks::new(0, bank))); let ledger_path = get_tmp_ledger_path!(); - let blockstore = Arc::new(Blockstore::open_as_primary(&ledger_path).unwrap()); + let blockstore = Arc::new(Blockstore::open(&ledger_path).unwrap()); let session = create_session(); @@ -533,7 +533,7 @@ mod tests { let bank1 = Bank::new_from_parent(&bank0, &Pubkey::default(), 1); bank_forks.write().unwrap().insert(bank1); let ledger_path = get_tmp_ledger_path!(); - let blockstore = Arc::new(Blockstore::open_as_primary(&ledger_path).unwrap()); + let blockstore = Arc::new(Blockstore::open(&ledger_path).unwrap()); let rpc = RpcSolPubSubImpl { subscriptions: Arc::new(RpcSubscriptions::new( @@ -636,7 +636,7 @@ mod tests { let bob_pubkey = Pubkey::new_rand(); let session = create_session(); let ledger_path = get_tmp_ledger_path!(); - let blockstore = Arc::new(Blockstore::open_as_primary(&ledger_path).unwrap()); + let blockstore = Arc::new(Blockstore::open(&ledger_path).unwrap()); let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(10_000); let bank_forks = Arc::new(RwLock::new(BankForks::new(0, Bank::new(&genesis_config)))); @@ -682,7 +682,7 @@ mod tests { let blockhash = bank.last_blockhash(); let bank_forks = Arc::new(RwLock::new(BankForks::new(1, bank))); let ledger_path = get_tmp_ledger_path!(); - let blockstore = Arc::new(Blockstore::open_as_primary(&ledger_path).unwrap()); + let blockstore = Arc::new(Blockstore::open(&ledger_path).unwrap()); let bob = Keypair::new(); let mut rpc = RpcSolPubSubImpl::default_with_blockstore_bank_forks( @@ -736,7 +736,7 @@ mod tests { let bank1 = Bank::new_from_parent(&bank0, &Pubkey::default(), 1); bank_forks.write().unwrap().insert(bank1); let ledger_path = get_tmp_ledger_path!(); - let blockstore = Arc::new(Blockstore::open_as_primary(&ledger_path).unwrap()); + let blockstore = Arc::new(Blockstore::open(&ledger_path).unwrap()); let bob = Keypair::new(); let mut rpc = RpcSolPubSubImpl::default_with_blockstore_bank_forks( @@ -804,7 +804,7 @@ mod tests { #[serial] fn test_slot_subscribe() { let ledger_path = get_tmp_ledger_path!(); - let blockstore = Arc::new(Blockstore::open_as_primary(&ledger_path).unwrap()); + let blockstore = Arc::new(Blockstore::open(&ledger_path).unwrap()); let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(10_000); let bank = Bank::new(&genesis_config); let bank_forks = Arc::new(RwLock::new(BankForks::new(0, bank))); @@ -834,7 +834,7 @@ mod tests { #[serial] fn test_slot_unsubscribe() { let ledger_path = get_tmp_ledger_path!(); - let blockstore = Arc::new(Blockstore::open_as_primary(&ledger_path).unwrap()); + let blockstore = Arc::new(Blockstore::open(&ledger_path).unwrap()); let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(10_000); let bank = Bank::new(&genesis_config); let bank_forks = Arc::new(RwLock::new(BankForks::new(0, bank))); @@ -872,7 +872,7 @@ mod tests { #[serial] fn test_vote_subscribe() { let ledger_path = get_tmp_ledger_path!(); - let blockstore = Arc::new(Blockstore::open_as_primary(&ledger_path).unwrap()); + let blockstore = Arc::new(Blockstore::open(&ledger_path).unwrap()); let block_commitment_cache = Arc::new(RwLock::new( BlockCommitmentCache::new_for_tests_with_blockstore(blockstore.clone()), )); @@ -942,7 +942,7 @@ mod tests { #[serial] fn test_vote_unsubscribe() { let ledger_path = get_tmp_ledger_path!(); - let blockstore = Arc::new(Blockstore::open_as_primary(&ledger_path).unwrap()); + let blockstore = Arc::new(Blockstore::open(&ledger_path).unwrap()); let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(10_000); let bank = Bank::new(&genesis_config); let bank_forks = Arc::new(RwLock::new(BankForks::new(0, bank))); diff --git a/core/src/rpc_pubsub_service.rs b/core/src/rpc_pubsub_service.rs index ecde0eef64658c..68e542ae8335c7 100644 --- a/core/src/rpc_pubsub_service.rs +++ b/core/src/rpc_pubsub_service.rs @@ -90,7 +90,7 @@ mod tests { let pubsub_addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), 0); let exit = Arc::new(AtomicBool::new(false)); let ledger_path = get_tmp_ledger_path!(); - let blockstore = Arc::new(Blockstore::open_as_primary(&ledger_path).unwrap()); + let blockstore = Arc::new(Blockstore::open(&ledger_path).unwrap()); let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(10_000); let bank = Bank::new(&genesis_config); let bank_forks = Arc::new(RwLock::new(BankForks::new(0, bank))); diff --git a/core/src/rpc_service.rs b/core/src/rpc_service.rs index 1070ff7193bff3..b1b90d200ab98d 100644 --- a/core/src/rpc_service.rs +++ b/core/src/rpc_service.rs @@ -423,7 +423,7 @@ mod tests { ); let bank_forks = Arc::new(RwLock::new(BankForks::new(bank.slot(), bank))); let ledger_path = get_tmp_ledger_path!(); - let blockstore = Arc::new(Blockstore::open_as_primary(&ledger_path).unwrap()); + let blockstore = Arc::new(Blockstore::open(&ledger_path).unwrap()); let block_commitment_cache = Arc::new(RwLock::new( BlockCommitmentCache::default_with_blockstore(blockstore.clone()), )); diff --git a/core/src/rpc_subscriptions.rs b/core/src/rpc_subscriptions.rs index ead20457f15018..9cf553df29eff1 100644 --- a/core/src/rpc_subscriptions.rs +++ b/core/src/rpc_subscriptions.rs @@ -877,7 +877,7 @@ pub(crate) mod tests { .. } = create_genesis_config(100); let ledger_path = get_tmp_ledger_path!(); - let blockstore = Arc::new(Blockstore::open_as_primary(&ledger_path).unwrap()); + let blockstore = Arc::new(Blockstore::open(&ledger_path).unwrap()); let bank = Bank::new(&genesis_config); let blockhash = bank.last_blockhash(); let bank_forks = Arc::new(RwLock::new(BankForks::new(0, bank))); @@ -971,7 +971,7 @@ pub(crate) mod tests { .. } = create_genesis_config(100); let ledger_path = get_tmp_ledger_path!(); - let blockstore = Arc::new(Blockstore::open_as_primary(&ledger_path).unwrap()); + let blockstore = Arc::new(Blockstore::open(&ledger_path).unwrap()); let bank = Bank::new(&genesis_config); let blockhash = bank.last_blockhash(); let bank_forks = Arc::new(RwLock::new(BankForks::new(0, bank))); @@ -1059,7 +1059,7 @@ pub(crate) mod tests { .. } = create_genesis_config(100); let ledger_path = get_tmp_ledger_path!(); - let blockstore = Arc::new(Blockstore::open_as_primary(&ledger_path).unwrap()); + let blockstore = Arc::new(Blockstore::open(&ledger_path).unwrap()); let bank = Bank::new(&genesis_config); let blockhash = bank.last_blockhash(); let mut bank_forks = BankForks::new(0, bank); @@ -1215,7 +1215,7 @@ pub(crate) mod tests { let sub_id = SubscriptionId::Number(0 as u64); let exit = Arc::new(AtomicBool::new(false)); let ledger_path = get_tmp_ledger_path!(); - let blockstore = Arc::new(Blockstore::open_as_primary(&ledger_path).unwrap()); + let blockstore = Arc::new(Blockstore::open(&ledger_path).unwrap()); let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(10_000); let bank = Bank::new(&genesis_config); let bank_forks = Arc::new(RwLock::new(BankForks::new(0, bank))); @@ -1267,7 +1267,7 @@ pub(crate) mod tests { let sub_id = SubscriptionId::Number(0 as u64); let exit = Arc::new(AtomicBool::new(false)); let ledger_path = get_tmp_ledger_path!(); - let blockstore = Arc::new(Blockstore::open_as_primary(&ledger_path).unwrap()); + let blockstore = Arc::new(Blockstore::open(&ledger_path).unwrap()); let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(10_000); let bank = Bank::new(&genesis_config); let bank_forks = Arc::new(RwLock::new(BankForks::new(0, bank))); @@ -1365,7 +1365,7 @@ pub(crate) mod tests { .. } = create_genesis_config(100); let ledger_path = get_tmp_ledger_path!(); - let blockstore = Arc::new(Blockstore::open_as_primary(&ledger_path).unwrap()); + let blockstore = Arc::new(Blockstore::open(&ledger_path).unwrap()); let bank = Bank::new(&genesis_config); let blockhash = bank.last_blockhash(); let bank_forks = Arc::new(RwLock::new(BankForks::new(0, bank))); diff --git a/core/src/serve_repair.rs b/core/src/serve_repair.rs index 879297a2ab84fc..0610333e2ec28f 100644 --- a/core/src/serve_repair.rs +++ b/core/src/serve_repair.rs @@ -574,7 +574,7 @@ mod tests { solana_logger::setup(); let ledger_path = get_tmp_ledger_path!(); { - let blockstore = Arc::new(Blockstore::open_as_primary(&ledger_path).unwrap()); + let blockstore = Arc::new(Blockstore::open(&ledger_path).unwrap()); let rv = ServeRepair::run_highest_window_request( &recycler, &socketaddr_any!(), @@ -642,7 +642,7 @@ mod tests { solana_logger::setup(); let ledger_path = get_tmp_ledger_path!(); { - let blockstore = Arc::new(Blockstore::open_as_primary(&ledger_path).unwrap()); + let blockstore = Arc::new(Blockstore::open(&ledger_path).unwrap()); let me = ContactInfo { id: Pubkey::new_rand(), gossip: socketaddr!("127.0.0.1:1234"), @@ -802,7 +802,7 @@ mod tests { let recycler = PacketsRecycler::default(); let ledger_path = get_tmp_ledger_path!(); { - let blockstore = Arc::new(Blockstore::open_as_primary(&ledger_path).unwrap()); + let blockstore = Arc::new(Blockstore::open(&ledger_path).unwrap()); let rv = ServeRepair::run_orphan( &recycler, &socketaddr_any!(), diff --git a/core/src/tvu.rs b/core/src/tvu.rs index ad2c2264c2ae5a..cc03e609353443 100644 --- a/core/src/tvu.rs +++ b/core/src/tvu.rs @@ -239,8 +239,8 @@ pub mod tests { use crate::banking_stage::create_test_recorder; use crate::cluster_info::{ClusterInfo, Node}; use serial_test_derive::serial; + use solana_ledger::create_new_tmp_ledger; use solana_ledger::genesis_utils::{create_genesis_config, GenesisConfigInfo}; - use solana_ledger::{blockstore_db::AccessType, create_new_tmp_ledger}; use solana_runtime::bank::Bank; use std::sync::atomic::Ordering; @@ -265,7 +265,7 @@ pub mod tests { let (blockstore_path, _) = create_new_tmp_ledger!(&genesis_config); let (blockstore, l_receiver, completed_slots_receiver) = - Blockstore::open_with_signal(&blockstore_path, AccessType::OnlyPrimary) + Blockstore::open_with_signal(&blockstore_path) .expect("Expected to successfully open ledger"); let blockstore = Arc::new(blockstore); let bank = bank_forks.working_bank(); diff --git a/core/src/window_service.rs b/core/src/window_service.rs index dc211c1654909e..16628ab7ce6a10 100644 --- a/core/src/window_service.rs +++ b/core/src/window_service.rs @@ -560,7 +560,7 @@ mod test { #[test] fn test_process_shred() { let blockstore_path = get_tmp_ledger_path!(); - let blockstore = Arc::new(Blockstore::open_as_primary(&blockstore_path).unwrap()); + let blockstore = Arc::new(Blockstore::open(&blockstore_path).unwrap()); let num_entries = 10; let original_entries = create_ticks(num_entries, 0, Hash::default()); let mut shreds = local_entries_to_shred(&original_entries, 0, 0, &Arc::new(Keypair::new())); @@ -650,7 +650,7 @@ mod test { #[test] fn test_run_check_duplicate() { let blockstore_path = get_tmp_ledger_path!(); - let blockstore = Arc::new(Blockstore::open_as_primary(&blockstore_path).unwrap()); + let blockstore = Arc::new(Blockstore::open(&blockstore_path).unwrap()); let (sender, receiver) = unbounded(); let (shreds, _) = make_many_slot_entries(5, 5, 10); blockstore diff --git a/core/tests/client.rs b/core/tests/client.rs index 1d8338ef11152a..a16c269ddf67e1 100644 --- a/core/tests/client.rs +++ b/core/tests/client.rs @@ -93,7 +93,7 @@ fn test_slot_subscription() { ); let exit = Arc::new(AtomicBool::new(false)); let ledger_path = get_tmp_ledger_path!(); - let blockstore = Arc::new(Blockstore::open_as_primary(&ledger_path).unwrap()); + let blockstore = Arc::new(Blockstore::open(&ledger_path).unwrap()); let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(10_000); let bank = Bank::new(&genesis_config); let bank_forks = Arc::new(RwLock::new(BankForks::new(0, bank))); diff --git a/core/tests/ledger_cleanup.rs b/core/tests/ledger_cleanup.rs index d920bdf6fcec60..d7f8a2ad061bff 100644 --- a/core/tests/ledger_cleanup.rs +++ b/core/tests/ledger_cleanup.rs @@ -207,7 +207,7 @@ mod tests { #[test] fn test_ledger_cleanup_compaction() { let blockstore_path = get_tmp_ledger_path!(); - let blockstore = Arc::new(Blockstore::open_as_primary(&blockstore_path).unwrap()); + let blockstore = Arc::new(Blockstore::open(&blockstore_path).unwrap()); let config = get_benchmark_config(); eprintln!("BENCHMARK CONFIG: {:?}", config); eprintln!("LEDGER_PATH: {:?}", &blockstore_path); @@ -357,7 +357,7 @@ mod tests { #[test] fn test_compaction() { let blockstore_path = get_tmp_ledger_path!(); - let blockstore = Arc::new(Blockstore::open_as_primary(&blockstore_path).unwrap()); + let blockstore = Arc::new(Blockstore::open(&blockstore_path).unwrap()); let n = 10_000; let batch_size = 100; diff --git a/ledger/src/blockstore.rs b/ledger/src/blockstore.rs index 9d2a2ef9f9d114..989b8e901a8c45 100644 --- a/ledger/src/blockstore.rs +++ b/ledger/src/blockstore.rs @@ -264,10 +264,6 @@ impl Blockstore { Ok(blockstore) } - pub fn open_as_primary(ledger_path: &Path) -> Result { - Self::open(ledger_path, AccessType::OnlyPrimary) - } - pub fn open_with_signal( ledger_path: &Path, access_type: AccessType, @@ -2936,7 +2932,7 @@ macro_rules! create_new_tmp_ledger { $crate::blockstore::create_new_ledger_from_name( $crate::tmp_ledger_name!(), $genesis_config, - $crate::blockstore_db::AccessType::OnlyPrimary, + AccessType::OnlyPrimary, ) }; } @@ -3232,7 +3228,7 @@ pub mod tests { let mint_total = 1_000_000_000_000; let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(mint_total); let (ledger_path, _blockhash) = create_new_tmp_ledger!(&genesis_config); - let ledger = Blockstore::open_as_primary(&ledger_path).unwrap(); + let ledger = Blockstore::open(&ledger_path).unwrap(); let ticks = create_ticks(genesis_config.ticks_per_slot, 0, genesis_config.hash()); let entries = ledger.get_slot_entries(0, 0).unwrap(); @@ -3253,7 +3249,7 @@ pub mod tests { let (mut shreds, _) = make_slot_entries(0, 0, num_entries); let ledger_path = get_tmp_ledger_path!(); - let ledger = Blockstore::open_as_primary(&ledger_path).unwrap(); + let ledger = Blockstore::open(&ledger_path).unwrap(); // Insert last shred, test we can retrieve it let last_shred = shreds.pop().unwrap(); @@ -3282,7 +3278,7 @@ pub mod tests { { let ticks_per_slot = 10; let num_slots = 10; - let ledger = Blockstore::open_as_primary(&ledger_path).unwrap(); + let ledger = Blockstore::open(&ledger_path).unwrap(); let mut ticks = vec![]; //let mut shreds_per_slot = 0 as u64; let mut shreds_per_slot = vec![]; @@ -3377,7 +3373,7 @@ pub mod tests { #[test] fn test_put_get_simple() { let ledger_path = get_tmp_ledger_path!(); - let ledger = Blockstore::open_as_primary(&ledger_path).unwrap(); + let ledger = Blockstore::open(&ledger_path).unwrap(); // Test meta column family let meta = SlotMeta::new(0, 1); @@ -3432,7 +3428,7 @@ pub mod tests { let shred_bufs: Vec<_> = shreds.iter().map(|shred| shred.payload.clone()).collect(); let ledger_path = get_tmp_ledger_path!(); - let ledger = Blockstore::open_as_primary(&ledger_path).unwrap(); + let ledger = Blockstore::open(&ledger_path).unwrap(); ledger.insert_shreds(shreds, None, false).unwrap(); let mut buf = [0; 4096]; @@ -3490,7 +3486,7 @@ pub mod tests { let (shreds, _) = make_slot_entries(slot, 0, 100); let ledger_path = get_tmp_ledger_path!(); - let ledger = Blockstore::open_as_primary(&ledger_path).unwrap(); + let ledger = Blockstore::open(&ledger_path).unwrap(); ledger.insert_shreds(shreds, None, false).unwrap(); let mut buf = [0; 4096]; @@ -3514,7 +3510,7 @@ pub mod tests { let num_shreds = shreds.len() as u64; let ledger_path = get_tmp_ledger_path!(); - let ledger = Blockstore::open_as_primary(&ledger_path).unwrap(); + let ledger = Blockstore::open(&ledger_path).unwrap(); // Insert last shred, we're missing the other shreds, so no consecutive // shreds starting from slot 0, index 0 should exist. @@ -3559,7 +3555,7 @@ pub mod tests { let num_shreds = shreds.len() as u64; let ledger_path = get_tmp_ledger_path!(); - let ledger = Blockstore::open_as_primary(&ledger_path).unwrap(); + let ledger = Blockstore::open(&ledger_path).unwrap(); // Insert shreds in reverse, check for consecutive returned shreds for i in (0..num_shreds).rev() { @@ -3599,7 +3595,7 @@ pub mod tests { let slot = 0; let blockstore_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); + let blockstore = Blockstore::open(&blockstore_path).unwrap(); // Write entries let num_entries = 8; @@ -3638,7 +3634,7 @@ pub mod tests { pub fn test_get_slot_entries1() { let blockstore_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); + let blockstore = Blockstore::open(&blockstore_path).unwrap(); let entries = create_ticks(8, 0, Hash::default()); let shreds = entries_to_test_shreds(entries[0..4].to_vec(), 1, 0, false, 0); blockstore @@ -3668,7 +3664,7 @@ pub mod tests { pub fn test_get_slot_entries2() { let blockstore_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); + let blockstore = Blockstore::open(&blockstore_path).unwrap(); // Write entries let num_slots = 5 as u64; @@ -3702,7 +3698,7 @@ pub mod tests { // Test inserting/fetching shreds which contain multiple entries per shred let blockstore_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); + let blockstore = Blockstore::open(&blockstore_path).unwrap(); let num_slots = 5 as u64; let shreds_per_slot = 5 as u64; let entry_serialized_size = @@ -3729,7 +3725,7 @@ pub mod tests { pub fn test_insert_data_shreds_consecutive() { let blockstore_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); + let blockstore = Blockstore::open(&blockstore_path).unwrap(); // Create enough entries to ensure there are at least two shreds created let min_entries = max_ticks_per_n_shreds(1, None) + 1; for i in 0..4 { @@ -3793,7 +3789,7 @@ pub mod tests { // Create RocksDb ledger let blockstore_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); + let blockstore = Blockstore::open(&blockstore_path).unwrap(); // Make duplicate entries and shreds let num_unique_entries = 10; @@ -3830,8 +3826,7 @@ pub mod tests { pub fn test_new_shreds_signal() { // Initialize ledger let ledger_path = get_tmp_ledger_path!(); - let (ledger, recvr, _) = - Blockstore::open_with_signal(&ledger_path, AccessType::OnlyPrimary).unwrap(); + let (ledger, recvr, _) = Blockstore::open_with_signal(&ledger_path).unwrap(); let ledger = Arc::new(ledger); let entries_per_slot = 50; @@ -3911,8 +3906,7 @@ pub mod tests { pub fn test_completed_shreds_signal() { // Initialize ledger let ledger_path = get_tmp_ledger_path!(); - let (ledger, _, recvr) = - Blockstore::open_with_signal(&ledger_path, AccessType::OnlyPrimary).unwrap(); + let (ledger, _, recvr) = Blockstore::open_with_signal(&ledger_path).unwrap(); let ledger = Arc::new(ledger); let entries_per_slot = 10; @@ -3934,8 +3928,7 @@ pub mod tests { pub fn test_completed_shreds_signal_orphans() { // Initialize ledger let ledger_path = get_tmp_ledger_path!(); - let (ledger, _, recvr) = - Blockstore::open_with_signal(&ledger_path, AccessType::OnlyPrimary).unwrap(); + let (ledger, _, recvr) = Blockstore::open_with_signal(&ledger_path).unwrap(); let ledger = Arc::new(ledger); let entries_per_slot = 10; @@ -3975,8 +3968,7 @@ pub mod tests { pub fn test_completed_shreds_signal_many() { // Initialize ledger let ledger_path = get_tmp_ledger_path!(); - let (ledger, _, recvr) = - Blockstore::open_with_signal(&ledger_path, AccessType::OnlyPrimary).unwrap(); + let (ledger, _, recvr) = Blockstore::open_with_signal(&ledger_path).unwrap(); let ledger = Arc::new(ledger); let entries_per_slot = 10; @@ -4009,7 +4001,7 @@ pub mod tests { { let entries_per_slot = 5; let num_slots = 3; - let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); + let blockstore = Blockstore::open(&blockstore_path).unwrap(); // Construct the shreds let (mut shreds, _) = make_many_slot_entries(0, num_slots, entries_per_slot); @@ -4072,7 +4064,7 @@ pub mod tests { pub fn test_handle_chaining_missing_slots() { let blockstore_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); + let blockstore = Blockstore::open(&blockstore_path).unwrap(); let num_slots = 30; let entries_per_slot = 5; @@ -4157,7 +4149,7 @@ pub mod tests { pub fn test_forward_chaining_is_connected() { let blockstore_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); + let blockstore = Blockstore::open(&blockstore_path).unwrap(); let num_slots = 15; // Create enough entries to ensure there are at least two shreds created let entries_per_slot = max_ticks_per_n_shreds(1, None) + 1; @@ -4248,7 +4240,7 @@ pub mod tests { pub fn test_chaining_tree() { let blockstore_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); + let blockstore = Blockstore::open(&blockstore_path).unwrap(); let num_tree_levels = 6; assert!(num_tree_levels > 1); let branching_factor: u64 = 4; @@ -4350,7 +4342,7 @@ pub mod tests { let blockstore_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); + let blockstore = Blockstore::open(&blockstore_path).unwrap(); // Slot doesn't exist assert!(blockstore.get_slots_since(&[0]).unwrap().is_empty()); @@ -4386,7 +4378,7 @@ pub mod tests { fn test_orphans() { let blockstore_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); + let blockstore = Blockstore::open(&blockstore_path).unwrap(); // Create shreds and entries let entries_per_slot = 1; @@ -4459,7 +4451,7 @@ pub mod tests { fn test_insert_data_shreds_slots(name: &str, should_bulk_write: bool) { let blockstore_path = get_ledger_path_from_name(name); { - let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); + let blockstore = Blockstore::open(&blockstore_path).unwrap(); // Create shreds and entries let num_entries = 20 as u64; @@ -4521,7 +4513,7 @@ pub mod tests { fn test_find_missing_data_indexes() { let slot = 0; let blockstore_path = get_tmp_ledger_path!(); - let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); + let blockstore = Blockstore::open(&blockstore_path).unwrap(); // Write entries let gap: u64 = 10; @@ -4611,7 +4603,7 @@ pub mod tests { fn test_find_missing_data_indexes_timeout() { let slot = 0; let blockstore_path = get_tmp_ledger_path!(); - let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); + let blockstore = Blockstore::open(&blockstore_path).unwrap(); // Write entries let gap: u64 = 10; @@ -4652,7 +4644,7 @@ pub mod tests { let slot = 0; let blockstore_path = get_tmp_ledger_path!(); - let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); + let blockstore = Blockstore::open(&blockstore_path).unwrap(); // Early exit conditions let empty: Vec = vec![]; @@ -4711,7 +4703,7 @@ pub mod tests { pub fn test_no_missing_shred_indexes() { let slot = 0; let blockstore_path = get_tmp_ledger_path!(); - let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); + let blockstore = Blockstore::open(&blockstore_path).unwrap(); // Write entries let num_entries = 10; @@ -4740,7 +4732,7 @@ pub mod tests { let (mut shreds, _) = make_slot_entries(0, 0, 200); let blockstore_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); + let blockstore = Blockstore::open(&blockstore_path).unwrap(); let last_root = RwLock::new(0); // Insert the first 5 shreds, we don't have a "is_last" shred yet @@ -4792,7 +4784,7 @@ pub mod tests { let (shreds, _) = make_slot_entries(0, 0, 200); let blockstore_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); + let blockstore = Blockstore::open(&blockstore_path).unwrap(); let index_cf = blockstore.db.column::(); blockstore @@ -4828,7 +4820,7 @@ pub mod tests { pub fn test_should_insert_coding_shred() { let blockstore_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); + let blockstore = Blockstore::open(&blockstore_path).unwrap(); let index_cf = blockstore.db.column::(); let last_root = RwLock::new(0); @@ -4985,7 +4977,7 @@ pub mod tests { let (shreds, _) = make_slot_entries(0, 0, 20); let num_shreds = shreds.len() as u64; let blockstore_path = get_tmp_ledger_path!(); - let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); + let blockstore = Blockstore::open(&blockstore_path).unwrap(); blockstore.insert_shreds(shreds, None, false).unwrap(); let slot_meta = blockstore.meta(0).unwrap().unwrap(); @@ -5012,7 +5004,7 @@ pub mod tests { fn test_slot_data_iterator() { // Construct the shreds let blockstore_path = get_tmp_ledger_path!(); - let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); + let blockstore = Blockstore::open(&blockstore_path).unwrap(); let shreds_per_slot = 10; let slots = vec![2, 4, 8, 12]; let all_shreds = make_chaining_slot_entries(&slots, shreds_per_slot); @@ -5041,7 +5033,7 @@ pub mod tests { #[test] fn test_set_roots() { let blockstore_path = get_tmp_ledger_path!(); - let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); + let blockstore = Blockstore::open(&blockstore_path).unwrap(); let chained_slots = vec![0, 2, 4, 7, 12, 15]; assert_eq!(blockstore.last_root(), 0); @@ -5060,7 +5052,7 @@ pub mod tests { #[test] fn test_purge_slots() { let blockstore_path = get_tmp_ledger_path!(); - let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); + let blockstore = Blockstore::open(&blockstore_path).unwrap(); let (shreds, _) = make_many_slot_entries(0, 50, 5); blockstore.insert_shreds(shreds, None, false).unwrap(); @@ -5088,7 +5080,7 @@ pub mod tests { #[test] fn test_purge_huge() { let blockstore_path = get_tmp_ledger_path!(); - let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); + let blockstore = Blockstore::open(&blockstore_path).unwrap(); let (shreds, _) = make_many_slot_entries(0, 5000, 10); blockstore.insert_shreds(shreds, None, false).unwrap(); @@ -5103,7 +5095,7 @@ pub mod tests { #[test] fn test_iter_bounds() { let blockstore_path = get_tmp_ledger_path!(); - let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); + let blockstore = Blockstore::open(&blockstore_path).unwrap(); // slot 5 does not exist, iter should be ok and should be a noop blockstore @@ -5179,7 +5171,7 @@ pub mod tests { fn test_get_slot_entries_with_shred_count_corruption() { let blockstore_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); + let blockstore = Blockstore::open(&blockstore_path).unwrap(); let num_ticks = 8; let entries = create_ticks(num_ticks, 0, Hash::default()); let slot = 1; @@ -5223,7 +5215,7 @@ pub mod tests { let (shreds0, _) = make_slot_entries(0, 0, 200); let blockstore_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); + let blockstore = Blockstore::open(&blockstore_path).unwrap(); // Insert the first 5 shreds, we don't have a "is_last" shred yet blockstore @@ -5254,7 +5246,7 @@ pub mod tests { let blockstore_path = get_tmp_ledger_path!(); let last_root = 100; { - let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); + let blockstore = Blockstore::open(&blockstore_path).unwrap(); blockstore.set_roots(&[last_root]).unwrap(); // Insert will fail, slot < root @@ -5281,7 +5273,7 @@ pub mod tests { Build a blockstore with < TIMESTAMP_SLOT_RANGE roots */ let blockstore_path = get_tmp_ledger_path!(); - let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); + let blockstore = Blockstore::open(&blockstore_path).unwrap(); blockstore.set_roots(&[0]).unwrap(); let mut last_entry_hash = Hash::default(); for slot in 0..=3 { @@ -5320,7 +5312,7 @@ pub mod tests { */ let blockstore_path = get_tmp_ledger_path!(); - let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); + let blockstore = Blockstore::open(&blockstore_path).unwrap(); blockstore.set_roots(&[0]).unwrap(); let desired_roots = vec![1, 2, 3, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14, 16, 17, 18, 19]; let mut last_entry_hash = Hash::default(); @@ -5376,7 +5368,7 @@ pub mod tests { let shreds = entries_to_test_shreds(entries.clone(), slot, slot - 1, true, 0); let more_shreds = entries_to_test_shreds(entries.clone(), slot + 1, slot, true, 0); let ledger_path = get_tmp_ledger_path!(); - let ledger = Blockstore::open_as_primary(&ledger_path).unwrap(); + let ledger = Blockstore::open(&ledger_path).unwrap(); ledger.insert_shreds(shreds, None, false).unwrap(); ledger.insert_shreds(more_shreds, None, false).unwrap(); ledger.set_roots(&[slot - 1, slot, slot + 1]).unwrap(); @@ -5521,7 +5513,7 @@ pub mod tests { } let shreds = entries_to_test_shreds(vote_entries, 1, 0, true, 0); let ledger_path = get_tmp_ledger_path!(); - let blockstore = Blockstore::open_as_primary(&ledger_path).unwrap(); + let blockstore = Blockstore::open(&ledger_path).unwrap(); blockstore.insert_shreds(shreds, None, false).unwrap(); // Populate slot 2 with ticks only fill_blockstore_slot_with_ticks(&blockstore, 6, 2, 1, Hash::default()); @@ -5675,7 +5667,7 @@ pub mod tests { fn test_persist_transaction_status() { let blockstore_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); + let blockstore = Blockstore::open(&blockstore_path).unwrap(); let transaction_status_cf = blockstore.db.column::(); let pre_balances_vec = vec![1, 2, 3]; @@ -5755,11 +5747,11 @@ pub mod tests { fn test_transaction_status_index() { let blockstore_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); + let blockstore = Blockstore::open(&blockstore_path).unwrap(); let transaction_status_index_cf = blockstore.db.column::(); let slot0 = 10; - // Primary index column is initialized on Blockstore::open_as_primary + // Primary index column is initialized on Blockstore::open assert!(transaction_status_index_cf.get(0).unwrap().is_some()); assert!(transaction_status_index_cf.get(1).unwrap().is_some()); @@ -5960,7 +5952,7 @@ pub mod tests { fn test_purge_transaction_status() { let blockstore_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); + let blockstore = Blockstore::open(&blockstore_path).unwrap(); let transaction_status_index_cf = blockstore.db.column::(); let slot = 10; for _ in 0..5 { @@ -6122,7 +6114,7 @@ pub mod tests { fn test_get_transaction_status() { let blockstore_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); + let blockstore = Blockstore::open(&blockstore_path).unwrap(); // TransactionStatus column opens initialized with one entry at index 2 let transaction_status_cf = blockstore.db.column::(); @@ -6246,7 +6238,7 @@ pub mod tests { let entries = make_slot_entries_with_transactions(5); let shreds = entries_to_test_shreds(entries.clone(), slot, slot - 1, true, 0); let ledger_path = get_tmp_ledger_path!(); - let blockstore = Blockstore::open_as_primary(&ledger_path).unwrap(); + let blockstore = Blockstore::open(&ledger_path).unwrap(); blockstore.insert_shreds(shreds, None, false).unwrap(); blockstore.set_roots(&[slot - 1, slot]).unwrap(); @@ -6326,7 +6318,7 @@ pub mod tests { fn test_get_confirmed_signatures_for_address() { let blockstore_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); + let blockstore = Blockstore::open(&blockstore_path).unwrap(); let address0 = Pubkey::new_rand(); let address1 = Pubkey::new_rand(); @@ -6480,7 +6472,7 @@ pub mod tests { fn test_map_transactions_to_statuses() { let blockstore_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); + let blockstore = Blockstore::open(&blockstore_path).unwrap(); let transaction_status_cf = blockstore.db.column::(); let slot = 0; @@ -6535,7 +6527,7 @@ pub mod tests { fn test_lowest_slot() { let blockstore_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); + let blockstore = Blockstore::open(&blockstore_path).unwrap(); for i in 0..10 { let slot = i; let (shreds, _) = make_slot_entries(slot, 0, 1); @@ -6555,7 +6547,7 @@ pub mod tests { setup_erasure_shreds(slot, 0, 100, 1.0); let blockstore_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); + let blockstore = Blockstore::open(&blockstore_path).unwrap(); blockstore .insert_shreds(coding_shreds, Some(&leader_schedule_cache), false) .unwrap(); @@ -6590,7 +6582,7 @@ pub mod tests { assert!(coding_shreds.len() > 3); let blockstore_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); + let blockstore = Blockstore::open(&blockstore_path).unwrap(); // Test inserting all the shreds let all_shreds: Vec<_> = data_shreds .iter() @@ -6796,7 +6788,7 @@ pub mod tests { let blockstore_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); + let blockstore = Blockstore::open(&blockstore_path).unwrap(); blockstore .insert_shreds(vec![shred.clone()], None, false) .unwrap(); @@ -6834,7 +6826,7 @@ pub mod tests { fn test_clear_unconfirmed_slot() { let blockstore_path = get_tmp_ledger_path!(); { - let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); + let blockstore = Blockstore::open(&blockstore_path).unwrap(); let unconfirmed_slot = 9; let unconfirmed_child_slot = 10; let slots = vec![2, unconfirmed_slot, unconfirmed_child_slot]; diff --git a/ledger/src/blockstore_db.rs b/ledger/src/blockstore_db.rs index 5f7b4859faf98c..7ca28c47705905 100644 --- a/ledger/src/blockstore_db.rs +++ b/ledger/src/blockstore_db.rs @@ -207,7 +207,7 @@ impl Rocks { Ok(db) => Rocks(db, ActualAccessType::Primary), Err(err) => { warn!("Error when opening as primary: {}", err); - warn!("Trying to open as secondary with: {:?}", secondary_path); + warn!("Trying as secondary at : {:?}", secondary_path); warn!("This active secondary db use may temporarily cause the performance of another db use (like by validator) to degrade"); Rocks( DB::open_cf_as_secondary(&db_options, path, &secondary_path, names)?, diff --git a/ledger/src/blockstore_processor.rs b/ledger/src/blockstore_processor.rs index 0afa6eee3ef3cb..5556b4ee4125d0 100644 --- a/ledger/src/blockstore_processor.rs +++ b/ledger/src/blockstore_processor.rs @@ -895,8 +895,8 @@ pub mod tests { let ticks_per_slot = genesis_config.ticks_per_slot; let (ledger_path, blockhash) = create_new_tmp_ledger!(&genesis_config); - let blockstore = Blockstore::open_as_primary(&ledger_path) - .expect("Expected to successfully open database ledger"); + let blockstore = + Blockstore::open(&ledger_path).expect("Expected to successfully open database ledger"); let parent_slot = 0; let slot = 1; @@ -938,7 +938,7 @@ pub mod tests { // Create a new ledger with slot 0 full of ticks let (ledger_path, blockhash) = create_new_tmp_ledger!(&genesis_config); - let blockstore = Blockstore::open_as_primary(&ledger_path).unwrap(); + let blockstore = Blockstore::open(&ledger_path).unwrap(); // Write slot 1 with one tick missing let parent_slot = 0; @@ -1005,7 +1005,7 @@ pub mod tests { let ticks_per_slot = genesis_config.ticks_per_slot; let (ledger_path, blockhash) = create_new_tmp_ledger!(&genesis_config); - let blockstore = Blockstore::open_as_primary(&ledger_path).unwrap(); + let blockstore = Blockstore::open(&ledger_path).unwrap(); let mut entries = create_ticks(ticks_per_slot, 0, blockhash); let trailing_entry = { @@ -1066,8 +1066,8 @@ pub mod tests { let (ledger_path, mut blockhash) = create_new_tmp_ledger!(&genesis_config); debug!("ledger_path: {:?}", ledger_path); - let blockstore = Blockstore::open_as_primary(&ledger_path) - .expect("Expected to successfully open database ledger"); + let blockstore = + Blockstore::open(&ledger_path).expect("Expected to successfully open database ledger"); // Write slot 1 // slot 1, points at slot 0. Missing one tick @@ -1155,8 +1155,8 @@ pub mod tests { slot 4 <-- set_root(true) */ - let blockstore = Blockstore::open_as_primary(&ledger_path) - .expect("Expected to successfully open database ledger"); + let blockstore = + Blockstore::open(&ledger_path).expect("Expected to successfully open database ledger"); // Fork 1, ending at slot 3 let last_slot1_entry_hash = @@ -1234,8 +1234,8 @@ pub mod tests { slot 4 */ - let blockstore = Blockstore::open_as_primary(&ledger_path) - .expect("Expected to successfully open database ledger"); + let blockstore = + Blockstore::open(&ledger_path).expect("Expected to successfully open database ledger"); // Fork 1, ending at slot 3 let last_slot1_entry_hash = @@ -1317,7 +1317,7 @@ pub mod tests { \ slot 3 */ - let blockstore = Blockstore::open_as_primary(&ledger_path).unwrap(); + let blockstore = Blockstore::open(&ledger_path).unwrap(); let slot1_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); @@ -1364,7 +1364,7 @@ pub mod tests { / \ slot 4 (dead) slot 3 */ - let blockstore = Blockstore::open_as_primary(&ledger_path).unwrap(); + let blockstore = Blockstore::open(&ledger_path).unwrap(); let slot1_blockhash = fill_blockstore_slot_with_ticks(&blockstore, ticks_per_slot, 1, 0, blockhash); let slot2_blockhash = @@ -1420,7 +1420,7 @@ pub mod tests { / \ slot 1 (dead) slot 2 (dead) */ - let blockstore = Blockstore::open_as_primary(&ledger_path).unwrap(); + let blockstore = Blockstore::open(&ledger_path).unwrap(); fill_blockstore_slot_with_ticks(&blockstore, ticks_per_slot, 1, 0, blockhash); fill_blockstore_slot_with_ticks(&blockstore, ticks_per_slot, 2, 0, blockhash); blockstore.set_dead_slot(1).unwrap(); @@ -1449,8 +1449,8 @@ pub mod tests { let (ledger_path, blockhash) = create_new_tmp_ledger!(&genesis_config); let mut last_entry_hash = blockhash; - let blockstore = Blockstore::open_as_primary(&ledger_path) - .expect("Expected to successfully open database ledger"); + let blockstore = + 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 epoch_schedule = get_epoch_schedule(&genesis_config, Vec::new()); @@ -1603,8 +1603,8 @@ pub mod tests { )); let last_blockhash = entries.last().unwrap().hash; - let blockstore = Blockstore::open_as_primary(&ledger_path) - .expect("Expected to successfully open database ledger"); + let blockstore = + Blockstore::open(&ledger_path).expect("Expected to successfully open database ledger"); blockstore .write_entries( 1, @@ -1646,7 +1646,7 @@ pub mod tests { genesis_config.ticks_per_slot = 1; let (ledger_path, _blockhash) = create_new_tmp_ledger!(&genesis_config); - let blockstore = Blockstore::open_as_primary(&ledger_path).unwrap(); + let blockstore = Blockstore::open(&ledger_path).unwrap(); let opts = ProcessOptions { poh_verify: true, ..ProcessOptions::default() @@ -1664,7 +1664,7 @@ pub mod tests { let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(123); let (ledger_path, _blockhash) = create_new_tmp_ledger!(&genesis_config); - let blockstore = Blockstore::open_as_primary(&ledger_path).unwrap(); + let blockstore = Blockstore::open(&ledger_path).unwrap(); let opts = ProcessOptions { override_num_threads: Some(1), ..ProcessOptions::default() @@ -1680,7 +1680,7 @@ pub mod tests { let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(123); let (ledger_path, _blockhash) = create_new_tmp_ledger!(&genesis_config); - let blockstore = Blockstore::open_as_primary(&ledger_path).unwrap(); + let blockstore = Blockstore::open(&ledger_path).unwrap(); let opts = ProcessOptions { full_leader_cache: true, ..ProcessOptions::default() @@ -1698,8 +1698,8 @@ pub mod tests { .. } = create_genesis_config(100); let (ledger_path, last_entry_hash) = create_new_tmp_ledger!(&genesis_config); - let blockstore = Blockstore::open_as_primary(&ledger_path) - .expect("Expected to successfully open database ledger"); + let blockstore = + Blockstore::open(&ledger_path).expect("Expected to successfully open database ledger"); let blockhash = genesis_config.hash(); let keypairs = [Keypair::new(), Keypair::new(), Keypair::new()]; @@ -2367,7 +2367,7 @@ pub mod tests { let ticks_per_slot = 1; genesis_config.ticks_per_slot = ticks_per_slot; let (ledger_path, blockhash) = create_new_tmp_ledger!(&genesis_config); - let blockstore = Blockstore::open_as_primary(&ledger_path).unwrap(); + let blockstore = Blockstore::open(&ledger_path).unwrap(); /* Build a blockstore in the ledger with the following fork structure: diff --git a/ledger/src/leader_schedule_cache.rs b/ledger/src/leader_schedule_cache.rs index 6a7c386fc76ef3..104f890379e1c9 100644 --- a/ledger/src/leader_schedule_cache.rs +++ b/ledger/src/leader_schedule_cache.rs @@ -445,7 +445,7 @@ mod tests { let ledger_path = get_tmp_ledger_path!(); { let blockstore = Arc::new( - Blockstore::open_as_primary(&ledger_path) + Blockstore::open(&ledger_path) .expect("Expected to be able to open database ledger"), ); diff --git a/ledger/src/next_slots_iterator.rs b/ledger/src/next_slots_iterator.rs index f56f96f7b89d90..945cdfab337201 100644 --- a/ledger/src/next_slots_iterator.rs +++ b/ledger/src/next_slots_iterator.rs @@ -42,7 +42,7 @@ mod tests { #[test] fn test_next_slots_iterator() { let blockstore_path = get_tmp_ledger_path!(); - let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); + let blockstore = Blockstore::open(&blockstore_path).unwrap(); blockstore.set_roots(&[0]).unwrap(); let ticks_per_slot = 5; /* diff --git a/ledger/src/rooted_slot_iterator.rs b/ledger/src/rooted_slot_iterator.rs index 7a8a7f4910d440..202a1b8b67f947 100644 --- a/ledger/src/rooted_slot_iterator.rs +++ b/ledger/src/rooted_slot_iterator.rs @@ -83,7 +83,7 @@ mod tests { #[test] fn test_rooted_slot_iterator() { let blockstore_path = get_tmp_ledger_path!(); - let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); + let blockstore = Blockstore::open(&blockstore_path).unwrap(); blockstore.set_roots(&[0]).unwrap(); let ticks_per_slot = 5; /* @@ -158,7 +158,7 @@ mod tests { #[test] fn test_skipping_rooted_slot_iterator() { let blockstore_path = get_tmp_ledger_path!(); - let blockstore = Blockstore::open_as_primary(&blockstore_path).unwrap(); + let blockstore = Blockstore::open(&blockstore_path).unwrap(); let ticks_per_slot = 5; /* Build a blockstore in the ledger with the following fork structure: diff --git a/ledger/tests/blockstore.rs b/ledger/tests/blockstore.rs index 5caeb7f06b6bb2..4fa73002a6ed2e 100644 --- a/ledger/tests/blockstore.rs +++ b/ledger/tests/blockstore.rs @@ -10,7 +10,7 @@ use std::thread::Builder; #[test] fn test_multiple_threads_insert_shred() { let blockstore_path = get_tmp_ledger_path!(); - let blockstore = Arc::new(Blockstore::open_as_primary(&blockstore_path).unwrap()); + let blockstore = Arc::new(Blockstore::open(&blockstore_path).unwrap()); for _ in 0..100 { let num_threads = 10; diff --git a/local-cluster/src/cluster_tests.rs b/local-cluster/src/cluster_tests.rs index 25fd71ab214978..0b47ef48df87ea 100644 --- a/local-cluster/src/cluster_tests.rs +++ b/local-cluster/src/cluster_tests.rs @@ -140,7 +140,7 @@ pub fn validator_exit(entry_point_info: &ContactInfo, nodes: usize) { } pub fn verify_ledger_ticks(ledger_path: &Path, ticks_per_slot: usize) { - let ledger = Blockstore::open_as_primary(ledger_path).unwrap(); + let ledger = Blockstore::open(ledger_path).unwrap(); let zeroth_slot = ledger.get_slot_entries(0, 0).unwrap(); let last_id = zeroth_slot.last().unwrap().hash; let next_slots = ledger.get_slots_since(&[0]).unwrap().remove(&0).unwrap(); diff --git a/local-cluster/tests/local_cluster.rs b/local-cluster/tests/local_cluster.rs index 481ba70f2cccbe..9ef8e3f3bdb46b 100644 --- a/local-cluster/tests/local_cluster.rs +++ b/local-cluster/tests/local_cluster.rs @@ -69,7 +69,7 @@ fn test_ledger_cleanup_service() { //check everyone's ledgers and make sure only ~100 slots are stored for info in cluster.validators.values() { let mut slots = 0; - let blockstore = Blockstore::open_as_primary(&info.info.ledger_path).unwrap(); + let blockstore = Blockstore::open(&info.info.ledger_path).unwrap(); blockstore .slot_meta_iterator(0) .unwrap() @@ -991,7 +991,7 @@ fn test_snapshots_blockstore_floor() { // Check the validator ledger doesn't contain any slots < slot_floor cluster.close_preserve_ledgers(); let validator_ledger_path = &cluster.validators[&validator_id]; - let blockstore = Blockstore::open_as_primary(&validator_ledger_path.info.ledger_path).unwrap(); + let blockstore = Blockstore::open(&validator_ledger_path.info.ledger_path).unwrap(); // Skip the zeroth slot in blockstore that the ledger is initialized with let (first_slot, _) = blockstore.slot_meta_iterator(1).unwrap().next().unwrap(); @@ -1152,7 +1152,7 @@ fn test_no_voting() { cluster.close_preserve_ledgers(); let leader_pubkey = cluster.entry_point_info.id; let ledger_path = cluster.validators[&leader_pubkey].info.ledger_path.clone(); - let ledger = Blockstore::open_as_primary(&ledger_path).unwrap(); + let ledger = Blockstore::open(&ledger_path).unwrap(); for i in 0..2 * VOTE_THRESHOLD_DEPTH { let meta = ledger.meta(i as u64).unwrap().unwrap(); let parent = meta.parent_slot; From d3fcfb82733756fb5340ec5545e71af2174cf798 Mon Sep 17 00:00:00 2001 From: Ryo Onodera Date: Sat, 30 May 2020 20:03:23 +0900 Subject: [PATCH 05/12] Solidify some edge cases --- Cargo.lock | 1 + core/src/validator.rs | 4 +--- ledger-tool/Cargo.toml | 1 + ledger-tool/src/main.rs | 13 +++++++++--- ledger/src/blockstore.rs | 32 ++++++++++++++++++++++++++---- ledger/src/blockstore_processor.rs | 5 +++++ 6 files changed, 46 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3175f4586cb634..2816780ecb667f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4226,6 +4226,7 @@ dependencies = [ "bytecount", "clap", "histogram", + "log 0.4.8", "serde_json", "serde_yaml", "solana-clap-utils", diff --git a/core/src/validator.rs b/core/src/validator.rs index 59e190d0741bb7..5e4e1466fd3427 100644 --- a/core/src/validator.rs +++ b/core/src/validator.rs @@ -27,7 +27,6 @@ use solana_ledger::{ bank_forks::{BankForks, SnapshotConfig}, bank_forks_utils, blockstore::{Blockstore, CompletedSlotsReceiver}, - blockstore_db::AccessType, blockstore_processor, create_new_tmp_ledger, hardened_unpack::{open_genesis_config, MAX_GENESIS_ARCHIVE_UNPACKED_SIZE}, leader_schedule::FixedSchedule, @@ -584,8 +583,7 @@ fn new_banks_from_blockstore( } let (mut blockstore, ledger_signal_receiver, completed_slots_receiver) = - Blockstore::open_with_signal(blockstore_path, AccessType::OnlyPrimary) - .expect("Failed to open ledger database"); + Blockstore::open_with_signal(blockstore_path).expect("Failed to open ledger database"); blockstore.set_no_compaction(config.no_rocksdb_compaction); let process_options = blockstore_processor::ProcessOptions { diff --git a/ledger-tool/Cargo.toml b/ledger-tool/Cargo.toml index 82a9ea683ce039..0d3f210e9e3395 100644 --- a/ledger-tool/Cargo.toml +++ b/ledger-tool/Cargo.toml @@ -13,6 +13,7 @@ bs58 = "0.3.1" bytecount = "0.6.0" clap = "2.33.1" histogram = "*" +log = { version = "0.4.8" } serde_json = "1.0.53" serde_yaml = "0.8.12" solana-clap-utils = { path = "../clap-utils", version = "1.3.0" } diff --git a/ledger-tool/src/main.rs b/ledger-tool/src/main.rs index a1e69b1576cf0d..9551f95c3e39b2 100644 --- a/ledger-tool/src/main.rs +++ b/ledger-tool/src/main.rs @@ -31,6 +31,8 @@ use std::{ str::FromStr, }; +use log::*; + #[derive(PartialEq)] enum LedgerOutputMethod { Print, @@ -520,7 +522,7 @@ fn analyze_storage(database: &Database) -> Result<(), String> { } fn open_blockstore(ledger_path: &Path, access_type: AccessType) -> Blockstore { - match Blockstore::open(ledger_path, access_type) { + match Blockstore::open_with_access_type(ledger_path, access_type) { Ok(blockstore) => blockstore, Err(err) => { eprintln!("Failed to open ledger at {:?}: {:?}", ledger_path, err); @@ -567,13 +569,18 @@ fn load_bank_forks( }; let blockstore = open_blockstore(&ledger_path, access_type); let account_paths = if let Some(account_paths) = arg_matches.value_of("account_paths") { + if !blockstore.is_primary_access() { + // Be defenstive, when default account dir is explicitly specified, it's still possible + // to wipe the dir possibly shared by the running validator! + panic!("custom accounts path is not supported under secondary access"); + } account_paths.split(',').map(PathBuf::from).collect() } else if blockstore.is_primary_access() { vec![ledger_path.join("accounts")] } else { let non_primary_accounts_path = ledger_path.join("accounts.ledger-tool"); - eprintln!( - "Default accounts path is switched aligning with Blockstore's non-primary access: {:?}", + warn!( + "Default accounts path is switched aligning with Blockstore's secondary access: {:?}", non_primary_accounts_path ); vec![non_primary_accounts_path] diff --git a/ledger/src/blockstore.rs b/ledger/src/blockstore.rs index 989b8e901a8c45..1393b97c772916 100644 --- a/ledger/src/blockstore.rs +++ b/ledger/src/blockstore.rs @@ -176,7 +176,18 @@ impl Blockstore { } /// Opens a Ledger in directory, provides "infinite" window of shreds - pub fn open(ledger_path: &Path, access_type: AccessType) -> Result { + pub fn open(ledger_path: &Path) -> Result { + Self::do_open(ledger_path, AccessType::OnlyPrimary) + } + + pub fn open_with_access_type( + ledger_path: &Path, + access_type: AccessType, + ) -> Result { + Self::do_open(ledger_path, access_type) + } + + pub fn do_open(ledger_path: &Path, access_type: AccessType) -> Result { fs::create_dir_all(&ledger_path)?; let blockstore_path = ledger_path.join(BLOCKSTORE_DIRECTORY); @@ -266,9 +277,22 @@ impl Blockstore { pub fn open_with_signal( ledger_path: &Path, + ) -> Result<(Self, Receiver, CompletedSlotsReceiver)> { + Self::do_open_with_signal(ledger_path, AccessType::OnlyPrimary) + } + + pub fn open_with_signal_with_access_type( + ledger_path: &Path, + access_type: AccessType, + ) -> Result<(Self, Receiver, CompletedSlotsReceiver)> { + Self::do_open_with_signal(ledger_path, access_type) + } + + pub fn do_open_with_signal( + ledger_path: &Path, access_type: AccessType, ) -> Result<(Self, Receiver, CompletedSlotsReceiver)> { - let mut blockstore = Self::open(ledger_path, access_type)?; + let mut blockstore = Self::open_with_access_type(ledger_path, access_type)?; let (signal_sender, signal_receiver) = sync_channel(1); let (completed_slots_sender, completed_slots_receiver) = sync_channel(MAX_COMPLETED_SLOTS_IN_CHANNEL); @@ -2798,7 +2822,7 @@ pub fn create_new_ledger( genesis_config.write(&ledger_path)?; // Fill slot 0 with ticks that link back to the genesis_config to bootstrap the ledger. - let blockstore = Blockstore::open(ledger_path, access_type)?; + let blockstore = Blockstore::open_with_access_type(ledger_path, access_type)?; let ticks_per_slot = genesis_config.ticks_per_slot; let hashes_per_tick = genesis_config.poh_config.hashes_per_tick.unwrap_or(0); let entries = create_ticks(ticks_per_slot, hashes_per_tick, genesis_config.hash()); @@ -2932,7 +2956,7 @@ macro_rules! create_new_tmp_ledger { $crate::blockstore::create_new_ledger_from_name( $crate::tmp_ledger_name!(), $genesis_config, - AccessType::OnlyPrimary, + $crate::blockstore_db::AccessType::OnlyPrimary, ) }; } diff --git a/ledger/src/blockstore_processor.rs b/ledger/src/blockstore_processor.rs index 5556b4ee4125d0..a09453cfbf0dd1 100644 --- a/ledger/src/blockstore_processor.rs +++ b/ledger/src/blockstore_processor.rs @@ -6,6 +6,7 @@ use crate::{ blockstore_meta::SlotMeta, entry::{create_ticks, Entry, EntrySlice, EntryVerificationStatus, VerifyRecyclers}, leader_schedule_cache::LeaderScheduleCache, + rooted_slot_iterator::RootedSlotIterator, }; use crossbeam_channel::Sender; use itertools::Itertools; @@ -336,10 +337,14 @@ pub fn process_blockstore_from_root( } } + // ensure start_slot is rooted for correct replay if blockstore.is_primary_access() { blockstore .set_roots(&[start_slot]) .expect("Couldn't set root slot on startup"); + } else { + let mut roots = RootedSlotIterator::new(0, &blockstore).expect("Failed to get rooted slot"); + roots.find(|(s, _)| *s == start_slot).unwrap_or_else(|| panic!("starting slot isn't root and can't update due to being secondary blockstore access: {}", start_slot)); } if let Ok(metas) = blockstore.slot_meta_iterator(start_slot) { From 890e8237fbdd63aaf7fea69d2844da305a5b3531 Mon Sep 17 00:00:00 2001 From: Ryo Onodera Date: Sat, 30 May 2020 23:27:26 +0900 Subject: [PATCH 06/12] Set recommended option --- ledger/src/blockstore_db.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ledger/src/blockstore_db.rs b/ledger/src/blockstore_db.rs index 7ca28c47705905..56d449c905cb41 100644 --- a/ledger/src/blockstore_db.rs +++ b/ledger/src/blockstore_db.rs @@ -150,7 +150,7 @@ impl Rocks { fs::create_dir_all(&path)?; // Use default database options - let db_options = get_db_options(); + let mut db_options = get_db_options(); // Column family names let meta_cf_descriptor = ColumnFamilyDescriptor::new(SlotMeta::NAME, get_cf_options()); @@ -209,6 +209,10 @@ impl Rocks { warn!("Error when opening as primary: {}", err); warn!("Trying as secondary at : {:?}", secondary_path); warn!("This active secondary db use may temporarily cause the performance of another db use (like by validator) to degrade"); + + // This is needed according to https://github.com/facebook/rocksdb/wiki/Secondary-instance + db_options.set_max_open_files(-1); + Rocks( DB::open_cf_as_secondary(&db_options, path, &secondary_path, names)?, ActualAccessType::Secondary, From 6b1891d7aa77bf1da75ca732a500edce844fc85f Mon Sep 17 00:00:00 2001 From: Ryo Onodera Date: Mon, 1 Jun 2020 15:51:27 +0900 Subject: [PATCH 07/12] Use process:exit, not panic! on user input Co-authored-by: Michael Vines --- ledger-tool/src/main.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ledger-tool/src/main.rs b/ledger-tool/src/main.rs index 9551f95c3e39b2..db42248b3611a3 100644 --- a/ledger-tool/src/main.rs +++ b/ledger-tool/src/main.rs @@ -572,7 +572,8 @@ fn load_bank_forks( if !blockstore.is_primary_access() { // Be defenstive, when default account dir is explicitly specified, it's still possible // to wipe the dir possibly shared by the running validator! - panic!("custom accounts path is not supported under secondary access"); + eprintln!("Error: custom accounts path is not supported under secondary access"); + process::exit(1) } account_paths.split(',').map(PathBuf::from).collect() } else if blockstore.is_primary_access() { From ec41c34ac71649549d89d33bc4d6f49ba0a0af9d Mon Sep 17 00:00:00 2001 From: Ryo Onodera Date: Mon, 1 Jun 2020 15:58:39 +0900 Subject: [PATCH 08/12] Remove unneeded wrapper anymore and compile fix --- ledger-tool/src/main.rs | 2 +- ledger/src/blockstore.rs | 16 +--------------- 2 files changed, 2 insertions(+), 16 deletions(-) diff --git a/ledger-tool/src/main.rs b/ledger-tool/src/main.rs index db42248b3611a3..854d600f4e6e1c 100644 --- a/ledger-tool/src/main.rs +++ b/ledger-tool/src/main.rs @@ -573,7 +573,7 @@ fn load_bank_forks( // Be defenstive, when default account dir is explicitly specified, it's still possible // to wipe the dir possibly shared by the running validator! eprintln!("Error: custom accounts path is not supported under secondary access"); - process::exit(1) + exit(1); } account_paths.split(',').map(PathBuf::from).collect() } else if blockstore.is_primary_access() { diff --git a/ledger/src/blockstore.rs b/ledger/src/blockstore.rs index 1393b97c772916..26c385b4891ed7 100644 --- a/ledger/src/blockstore.rs +++ b/ledger/src/blockstore.rs @@ -278,21 +278,7 @@ impl Blockstore { pub fn open_with_signal( ledger_path: &Path, ) -> Result<(Self, Receiver, CompletedSlotsReceiver)> { - Self::do_open_with_signal(ledger_path, AccessType::OnlyPrimary) - } - - pub fn open_with_signal_with_access_type( - ledger_path: &Path, - access_type: AccessType, - ) -> Result<(Self, Receiver, CompletedSlotsReceiver)> { - Self::do_open_with_signal(ledger_path, access_type) - } - - pub fn do_open_with_signal( - ledger_path: &Path, - access_type: AccessType, - ) -> Result<(Self, Receiver, CompletedSlotsReceiver)> { - let mut blockstore = Self::open_with_access_type(ledger_path, access_type)?; + let mut blockstore = Self::open_with_access_type(ledger_path, AccessType::OnlyPrimary)?; let (signal_sender, signal_receiver) = sync_channel(1); let (completed_slots_sender, completed_slots_receiver) = sync_channel(MAX_COMPLETED_SLOTS_IN_CHANNEL); From 18c5d6b70bfa7832c7b8c7eb57bdc0146bd6b7a2 Mon Sep 17 00:00:00 2001 From: Ryo Onodera Date: Mon, 1 Jun 2020 16:14:40 +0900 Subject: [PATCH 09/12] Clean ups --- ledger/src/blockstore.rs | 2 +- ledger/src/blockstore_db.rs | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/ledger/src/blockstore.rs b/ledger/src/blockstore.rs index 26c385b4891ed7..8016beb1fac26b 100644 --- a/ledger/src/blockstore.rs +++ b/ledger/src/blockstore.rs @@ -187,7 +187,7 @@ impl Blockstore { Self::do_open(ledger_path, access_type) } - pub fn do_open(ledger_path: &Path, access_type: AccessType) -> Result { + fn do_open(ledger_path: &Path, access_type: AccessType) -> Result { fs::create_dir_all(&ledger_path)?; let blockstore_path = ledger_path.join(BLOCKSTORE_DIRECTORY); diff --git a/ledger/src/blockstore_db.rs b/ledger/src/blockstore_db.rs index 56d449c905cb41..9b50fd369a1085 100644 --- a/ledger/src/blockstore_db.rs +++ b/ledger/src/blockstore_db.rs @@ -201,11 +201,13 @@ impl Rocks { ActualAccessType::Primary, ), AccessType::AllowSecondary => { - let secondary_path = path.join("solana-secondary"); - let names: Vec<&str> = cfs.iter().map(|c| c.0).collect(); + let names: Vec<_> = cfs.iter().map(|c| c.0).collect(); + match DB::open_cf_descriptors(&db_options, path, cfs.into_iter().map(|c| c.1)) { Ok(db) => Rocks(db, ActualAccessType::Primary), Err(err) => { + let secondary_path = path.join("solana-secondary"); + warn!("Error when opening as primary: {}", err); warn!("Trying as secondary at : {:?}", secondary_path); warn!("This active secondary db use may temporarily cause the performance of another db use (like by validator) to degrade"); From e532f53cafa45198f421bfa08202692c99975028 Mon Sep 17 00:00:00 2001 From: Ryo Onodera Date: Tue, 2 Jun 2020 12:59:07 +0900 Subject: [PATCH 10/12] Reword enum for clarity --- genesis/src/main.rs | 2 +- ledger-tool/src/main.rs | 33 +++++++++++++++++++-------------- ledger/src/blockstore.rs | 6 +++--- ledger/src/blockstore_db.rs | 8 ++++---- 4 files changed, 27 insertions(+), 22 deletions(-) diff --git a/genesis/src/main.rs b/genesis/src/main.rs index 0fe4f0e5ec5bc5..1d277d8eedb382 100644 --- a/genesis/src/main.rs +++ b/genesis/src/main.rs @@ -540,7 +540,7 @@ fn main() -> Result<(), Box> { &ledger_path, &genesis_config, max_genesis_archive_unpacked_size, - AccessType::OnlyPrimary, + AccessType::PrimaryOnly, )?; println!("{}", genesis_config); diff --git a/ledger-tool/src/main.rs b/ledger-tool/src/main.rs index 854d600f4e6e1c..10d6d1db925a9a 100644 --- a/ledger-tool/src/main.rs +++ b/ledger-tool/src/main.rs @@ -879,7 +879,7 @@ fn main() { let starting_slot = value_t_or_exit!(arg_matches, "starting_slot", Slot); let allow_dead_slots = arg_matches.is_present("allow_dead_slots"); output_ledger( - open_blockstore(&ledger_path, AccessType::AllowSecondary), + open_blockstore(&ledger_path, AccessType::TryPrimaryThenSecondary), starting_slot, allow_dead_slots, LedgerOutputMethod::Print, @@ -907,7 +907,7 @@ fn main() { &ledger_path, &genesis_config, process_options, - AccessType::AllowSecondary, + AccessType::TryPrimaryThenSecondary, ) { Ok((bank_forks, _leader_schedule_cache, _snapshot_hash)) => { println!( @@ -927,7 +927,7 @@ fn main() { ("slot", Some(arg_matches)) => { let slots = values_t_or_exit!(arg_matches, "slots", Slot); let allow_dead_slots = arg_matches.is_present("allow_dead_slots"); - let blockstore = open_blockstore(&ledger_path, AccessType::AllowSecondary); + let blockstore = open_blockstore(&ledger_path, AccessType::TryPrimaryThenSecondary); for slot in slots { println!("Slot {}", slot); if let Err(err) = output_slot( @@ -944,7 +944,7 @@ fn main() { let starting_slot = value_t_or_exit!(arg_matches, "starting_slot", Slot); let allow_dead_slots = arg_matches.is_present("allow_dead_slots"); output_ledger( - open_blockstore(&ledger_path, AccessType::AllowSecondary), + open_blockstore(&ledger_path, AccessType::TryPrimaryThenSecondary), starting_slot, allow_dead_slots, LedgerOutputMethod::Json, @@ -952,7 +952,7 @@ fn main() { } ("set-dead-slot", Some(arg_matches)) => { let slots = values_t_or_exit!(arg_matches, "slots", Slot); - let blockstore = open_blockstore(&ledger_path, AccessType::OnlyPrimary); + let blockstore = open_blockstore(&ledger_path, AccessType::PrimaryOnly); for slot in slots { match blockstore.set_dead_slot(slot) { Ok(_) => println!("Slot {} dead", slot), @@ -977,7 +977,7 @@ fn main() { &ledger_path, &open_genesis_config_by(&ledger_path, arg_matches), process_options, - AccessType::AllowSecondary, + AccessType::TryPrimaryThenSecondary, ) .unwrap_or_else(|err| { eprintln!("Ledger verification failed: {:?}", err); @@ -1000,7 +1000,7 @@ fn main() { &ledger_path, &open_genesis_config_by(&ledger_path, arg_matches), process_options, - AccessType::AllowSecondary, + AccessType::TryPrimaryThenSecondary, ) { Ok((bank_forks, _leader_schedule_cache, _snapshot_hash)) => { let dot = graph_forks(&bank_forks, arg_matches.is_present("include_all_votes")); @@ -1042,7 +1042,7 @@ fn main() { &ledger_path, &genesis_config, process_options, - AccessType::AllowSecondary, + AccessType::TryPrimaryThenSecondary, ) { Ok((bank_forks, _leader_schedule_cache, _snapshot_hash)) => { let bank = bank_forks.get(snapshot_slot).unwrap_or_else(|| { @@ -1115,7 +1115,7 @@ fn main() { &ledger_path, &genesis_config, process_options, - AccessType::AllowSecondary, + AccessType::TryPrimaryThenSecondary, ) { Ok((bank_forks, _leader_schedule_cache, _snapshot_hash)) => { let slot = bank_forks.working_bank().slot(); @@ -1163,7 +1163,7 @@ fn main() { &ledger_path, &genesis_config, process_options, - AccessType::AllowSecondary, + AccessType::TryPrimaryThenSecondary, ) { Ok((bank_forks, _leader_schedule_cache, _snapshot_hash)) => { let slot = bank_forks.working_bank().slot(); @@ -1228,12 +1228,12 @@ fn main() { ("purge", Some(arg_matches)) => { let start_slot = value_t_or_exit!(arg_matches, "start_slot", Slot); let end_slot = value_t_or_exit!(arg_matches, "end_slot", Slot); - let blockstore = open_blockstore(&ledger_path, AccessType::OnlyPrimary); + let blockstore = open_blockstore(&ledger_path, AccessType::PrimaryOnly); blockstore.purge_slots(start_slot, end_slot); blockstore.purge_from_next_slots(start_slot, end_slot); } ("list-roots", Some(arg_matches)) => { - let blockstore = open_blockstore(&ledger_path, AccessType::AllowSecondary); + let blockstore = open_blockstore(&ledger_path, AccessType::TryPrimaryThenSecondary); let max_height = if let Some(height) = arg_matches.value_of("max_height") { usize::from_str(height).expect("Maximum height must be a number") } else { @@ -1286,7 +1286,9 @@ fn main() { }); } ("bounds", Some(arg_matches)) => { - match open_blockstore(&ledger_path, AccessType::AllowSecondary).slot_meta_iterator(0) { + match open_blockstore(&ledger_path, AccessType::TryPrimaryThenSecondary) + .slot_meta_iterator(0) + { Ok(metas) => { let all = arg_matches.is_present("all"); @@ -1313,7 +1315,10 @@ fn main() { } } ("analyze-storage", _) => { - match analyze_storage(&open_database(&ledger_path, AccessType::AllowSecondary)) { + match analyze_storage(&open_database( + &ledger_path, + AccessType::TryPrimaryThenSecondary, + )) { Ok(()) => { println!("Ok."); } diff --git a/ledger/src/blockstore.rs b/ledger/src/blockstore.rs index 8016beb1fac26b..9f3c549db3b824 100644 --- a/ledger/src/blockstore.rs +++ b/ledger/src/blockstore.rs @@ -177,7 +177,7 @@ impl Blockstore { /// Opens a Ledger in directory, provides "infinite" window of shreds pub fn open(ledger_path: &Path) -> Result { - Self::do_open(ledger_path, AccessType::OnlyPrimary) + Self::do_open(ledger_path, AccessType::PrimaryOnly) } pub fn open_with_access_type( @@ -278,7 +278,7 @@ impl Blockstore { pub fn open_with_signal( ledger_path: &Path, ) -> Result<(Self, Receiver, CompletedSlotsReceiver)> { - let mut blockstore = Self::open_with_access_type(ledger_path, AccessType::OnlyPrimary)?; + let mut blockstore = Self::open_with_access_type(ledger_path, AccessType::PrimaryOnly)?; let (signal_sender, signal_receiver) = sync_channel(1); let (completed_slots_sender, completed_slots_receiver) = sync_channel(MAX_COMPLETED_SLOTS_IN_CHANNEL); @@ -2942,7 +2942,7 @@ macro_rules! create_new_tmp_ledger { $crate::blockstore::create_new_ledger_from_name( $crate::tmp_ledger_name!(), $genesis_config, - $crate::blockstore_db::AccessType::OnlyPrimary, + $crate::blockstore_db::AccessType::PrimaryOnly, ) }; } diff --git a/ledger/src/blockstore_db.rs b/ledger/src/blockstore_db.rs index 9b50fd369a1085..70d8eaf6b945f4 100644 --- a/ledger/src/blockstore_db.rs +++ b/ledger/src/blockstore_db.rs @@ -127,8 +127,8 @@ pub mod columns { } pub enum AccessType { - OnlyPrimary, - AllowSecondary, + PrimaryOnly, + TryPrimaryThenSecondary, } #[derive(Debug, PartialEq)] @@ -196,11 +196,11 @@ impl Rocks { // Open the database let db = match access_type { - AccessType::OnlyPrimary => Rocks( + AccessType::PrimaryOnly => Rocks( DB::open_cf_descriptors(&db_options, path, cfs.into_iter().map(|c| c.1))?, ActualAccessType::Primary, ), - AccessType::AllowSecondary => { + AccessType::TryPrimaryThenSecondary => { let names: Vec<_> = cfs.iter().map(|c| c.0).collect(); match DB::open_cf_descriptors(&db_options, path, cfs.into_iter().map(|c| c.1)) { From 768e77643e4e4e49f26312d00d0996a6d6fa6088 Mon Sep 17 00:00:00 2001 From: Ryo Onodera Date: Wed, 3 Jun 2020 10:32:57 +0900 Subject: [PATCH 11/12] Adoid failed slot writes under secondary --- ledger/src/blockstore_processor.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/ledger/src/blockstore_processor.rs b/ledger/src/blockstore_processor.rs index a09453cfbf0dd1..29cf66afa4d378 100644 --- a/ledger/src/blockstore_processor.rs +++ b/ledger/src/blockstore_processor.rs @@ -793,10 +793,14 @@ fn process_single_slot( // see DuplicateSignature errors later in ReplayStage confirm_full_slot(blockstore, bank, opts, recyclers, progress).map_err(|err| { let slot = bank.slot(); - blockstore - .set_dead_slot(slot) - .expect("Failed to mark slot as dead in blockstore"); warn!("slot {} failed to verify: {}", slot, err); + if blockstore.is_primary_access() { + blockstore + .set_dead_slot(slot) + .expect("Failed to mark slot as dead in blockstore"); + } else if !blockstore.is_dead(slot) { + panic!("Failed slot isn't dead and can't update due to being secondary blockstore access: {}", slot); + } err })?; From 1465638d53e512df7e5ec657729071ef7111f80f Mon Sep 17 00:00:00 2001 From: Ryo Onodera Date: Wed, 3 Jun 2020 11:42:38 +0900 Subject: [PATCH 12/12] Just use is_root --- ledger/src/blockstore_processor.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/ledger/src/blockstore_processor.rs b/ledger/src/blockstore_processor.rs index 29cf66afa4d378..5469fb20765e46 100644 --- a/ledger/src/blockstore_processor.rs +++ b/ledger/src/blockstore_processor.rs @@ -6,7 +6,6 @@ use crate::{ blockstore_meta::SlotMeta, entry::{create_ticks, Entry, EntrySlice, EntryVerificationStatus, VerifyRecyclers}, leader_schedule_cache::LeaderScheduleCache, - rooted_slot_iterator::RootedSlotIterator, }; use crossbeam_channel::Sender; use itertools::Itertools; @@ -342,9 +341,8 @@ pub fn process_blockstore_from_root( blockstore .set_roots(&[start_slot]) .expect("Couldn't set root slot on startup"); - } else { - let mut roots = RootedSlotIterator::new(0, &blockstore).expect("Failed to get rooted slot"); - roots.find(|(s, _)| *s == start_slot).unwrap_or_else(|| panic!("starting slot isn't root and can't update due to being secondary blockstore access: {}", start_slot)); + } else if !blockstore.is_root(start_slot) { + panic!("starting slot isn't root and can't update due to being secondary blockstore access: {}", start_slot); } if let Ok(metas) = blockstore.slot_meta_iterator(start_slot) {