From 52da207f83e4ec8f32b8332c73f037ea64996555 Mon Sep 17 00:00:00 2001 From: Michael Vines Date: Sun, 25 Aug 2019 21:33:41 -0700 Subject: [PATCH] test_snapshots_restart_validity now passes (#5644) automerge --- core/src/validator.rs | 99 +++++++++++++--------------- local_cluster/tests/local_cluster.rs | 22 +++++-- 2 files changed, 63 insertions(+), 58 deletions(-) diff --git a/core/src/validator.rs b/core/src/validator.rs index e0ba6f3243..47e5669d9b 100644 --- a/core/src/validator.rs +++ b/core/src/validator.rs @@ -370,65 +370,56 @@ fn get_bank_forks( genesis_block: &GenesisBlock, blocktree: &Blocktree, account_paths: Option, - snapshot_config: Option, + snapshot_config: Option<&SnapshotConfig>, verify_ledger: bool, dev_halt_at_slot: Option, ) -> (BankForks, Vec, LeaderScheduleCache) { - let (mut bank_forks, bank_forks_info, leader_schedule_cache) = { - if let Some(snapshot_config) = snapshot_config.as_ref() { - info!( - "Initializing snapshot path: {:?}", - snapshot_config.snapshot_path - ); - let _ = fs::remove_dir_all(&snapshot_config.snapshot_path); - fs::create_dir_all(&snapshot_config.snapshot_path) - .expect("Couldn't create snapshot directory"); + if let Some(snapshot_config) = snapshot_config.as_ref() { + info!( + "Initializing snapshot path: {:?}", + snapshot_config.snapshot_path + ); + let _ = fs::remove_dir_all(&snapshot_config.snapshot_path); + fs::create_dir_all(&snapshot_config.snapshot_path) + .expect("Couldn't create snapshot directory"); - let tar = snapshot_utils::get_snapshot_tar_path( - &snapshot_config.snapshot_package_output_path, - ); - if tar.exists() { - info!("Loading snapshot package: {:?}", tar); - // Fail hard here if snapshot fails to load, don't silently continue - let deserialized_bank = snapshot_utils::bank_from_archive( - account_paths - .clone() - .expect("Account paths not present when booting from snapshot"), - snapshot_config, - &tar, - ) - .expect("Load from snapshot failed"); + let tar = + snapshot_utils::get_snapshot_tar_path(&snapshot_config.snapshot_package_output_path); + if tar.exists() { + info!("Loading snapshot package: {:?}", tar); + // Fail hard here if snapshot fails to load, don't silently continue + let deserialized_bank = snapshot_utils::bank_from_archive( + account_paths + .clone() + .expect("Account paths not present when booting from snapshot"), + snapshot_config, + &tar, + ) + .expect("Load from snapshot failed"); - return blocktree_processor::process_blocktree_from_root( - blocktree, - Arc::new(deserialized_bank), - verify_ledger, - dev_halt_at_slot, - ) - .expect("processing blocktree after loading snapshot failed"); - } else { - info!("Snapshot package does not exist: {:?}", tar); - } + return blocktree_processor::process_blocktree_from_root( + blocktree, + Arc::new(deserialized_bank), + verify_ledger, + dev_halt_at_slot, + ) + .expect("processing blocktree after loading snapshot failed"); } else { - info!("Snapshots disabled"); + info!("Snapshot package does not exist: {:?}", tar); } - - info!("Processing ledger from genesis"); - blocktree_processor::process_blocktree( - &genesis_block, - &blocktree, - account_paths, - verify_ledger, - dev_halt_at_slot, - ) - .expect("process_blocktree failed") - }; - - if snapshot_config.is_some() { - bank_forks.set_snapshot_config(snapshot_config.unwrap()); + } else { + info!("Snapshots disabled"); } - (bank_forks, bank_forks_info, leader_schedule_cache) + info!("Processing ledger from genesis"); + blocktree_processor::process_blocktree( + &genesis_block, + &blocktree, + account_paths, + verify_ledger, + dev_halt_at_slot, + ) + .expect("process_blocktree failed") } #[cfg(not(unix))] @@ -504,15 +495,19 @@ pub fn new_banks_from_blocktree( let (blocktree, ledger_signal_receiver, completed_slots_receiver) = Blocktree::open_with_signal(blocktree_path).expect("Failed to open ledger database"); - let (bank_forks, bank_forks_info, leader_schedule_cache) = get_bank_forks( + let (mut bank_forks, bank_forks_info, leader_schedule_cache) = get_bank_forks( &genesis_block, &blocktree, account_paths, - snapshot_config, + snapshot_config.as_ref(), verify_ledger, dev_halt_at_slot, ); + if snapshot_config.is_some() { + bank_forks.set_snapshot_config(snapshot_config.unwrap()); + } + ( genesis_blockhash, bank_forks, diff --git a/local_cluster/tests/local_cluster.rs b/local_cluster/tests/local_cluster.rs index 18be28e55d..4507f337af 100644 --- a/local_cluster/tests/local_cluster.rs +++ b/local_cluster/tests/local_cluster.rs @@ -300,10 +300,11 @@ fn test_listener_startup() { #[test] #[serial] fn test_snapshots_restart_validity() { + solana_logger::setup(); let temp_dir = TempDir::new().unwrap(); let snapshot_path = temp_dir.path().join("bank_states"); let snapshot_package_output_path = temp_dir.path().join("tar"); - let snapshot_interval_slots = 25; + let snapshot_interval_slots = 10; // Create the snapshot directories fs::create_dir_all(&snapshot_path).expect("Failed to create snapshots bank state directory"); @@ -334,7 +335,8 @@ fn test_snapshots_restart_validity() { let num_runs = 3; let mut expected_balances = HashMap::new(); let mut cluster = LocalCluster::new(&config); - for _ in 0..num_runs { + for i in 1..num_runs { + info!("run {}", i); // Push transactions to one of the nodes and confirm that transactions were // forwarded to and processed. trace!("Sending transactions"); @@ -356,12 +358,20 @@ fn test_snapshots_restart_validity() { // Wait for a snapshot for a bank >= last_slot to be made so we know that the snapshot // must include the transactions just pushed let tar = snapshot_utils::get_snapshot_tar_path(&snapshot_package_output_path); - trace!("Waiting for tar to be generated"); + trace!( + "Waiting for snapshot tar to be generated with slot > {}", + last_slot + ); loop { - if tar.exists() && snapshot_utils::bank_slot_from_archive(&tar).unwrap() >= last_slot { - break; + if tar.exists() { + trace!("snapshot tar exists"); + let slot = snapshot_utils::bank_slot_from_archive(&tar).unwrap(); + if slot >= last_slot { + break; + } + trace!("snapshot tar slot {} < last_slot {}", slot, last_slot); } - sleep(Duration::from_millis(100)); + sleep(Duration::from_millis(5000)); } // Create new account paths since fullnode exit is not guaranteed to cleanup RPC threads,