diff --git a/core/src/validator.rs b/core/src/validator.rs index b206cf87b30d8c..011d63924328c0 100644 --- a/core/src/validator.rs +++ b/core/src/validator.rs @@ -246,6 +246,7 @@ pub struct ValidatorConfig { pub warp_slot: Option, pub accounts_db_test_hash_calculation: bool, pub accounts_db_skip_shrink: bool, + pub accounts_db_force_initial_clean: bool, pub tpu_coalesce: Duration, pub staked_nodes_overrides: Arc>>, pub validator_exit: Arc>, @@ -313,6 +314,7 @@ impl Default for ValidatorConfig { warp_slot: None, accounts_db_test_hash_calculation: false, accounts_db_skip_shrink: false, + accounts_db_force_initial_clean: false, tpu_coalesce: DEFAULT_TPU_COALESCE, staked_nodes_overrides: Arc::new(RwLock::new(HashMap::new())), validator_exit: Arc::new(RwLock::new(Exit::default())), @@ -1759,6 +1761,7 @@ fn load_blockstore( shrink_ratio: config.accounts_shrink_ratio, accounts_db_test_hash_calculation: config.accounts_db_test_hash_calculation, accounts_db_skip_shrink: config.accounts_db_skip_shrink, + accounts_db_force_initial_clean: config.accounts_db_force_initial_clean, runtime_config: config.runtime_config.clone(), use_snapshot_archives_at_startup: config.use_snapshot_archives_at_startup, ..blockstore_processor::ProcessOptions::default() diff --git a/core/tests/epoch_accounts_hash.rs b/core/tests/epoch_accounts_hash.rs index 718e62688b8c4c..8fa6919e99db1f 100755 --- a/core/tests/epoch_accounts_hash.rs +++ b/core/tests/epoch_accounts_hash.rs @@ -461,6 +461,7 @@ fn test_snapshots_have_expected_epoch_accounts_hash() { AccountShrinkThreshold::default(), true, true, + false, true, None, None, diff --git a/core/tests/snapshots.rs b/core/tests/snapshots.rs index 3b689a8423e8b7..1520a410c0268c 100644 --- a/core/tests/snapshots.rs +++ b/core/tests/snapshots.rs @@ -171,6 +171,7 @@ fn restore_from_snapshot( check_hash_calculation, false, false, + false, Some(ACCOUNTS_DB_CONFIG_FOR_TESTING), None, Arc::default(), @@ -893,6 +894,7 @@ fn restore_from_snapshots_and_check_banks_are_equal( false, false, false, + false, Some(ACCOUNTS_DB_CONFIG_FOR_TESTING), None, Arc::default(), @@ -1113,6 +1115,7 @@ fn test_snapshots_with_background_services( false, false, false, + false, Some(ACCOUNTS_DB_CONFIG_FOR_TESTING), None, exit.clone(), diff --git a/ledger/src/bank_forks_utils.rs b/ledger/src/bank_forks_utils.rs index b46d950adba28a..0be01e9bde975b 100644 --- a/ledger/src/bank_forks_utils.rs +++ b/ledger/src/bank_forks_utils.rs @@ -264,6 +264,7 @@ fn bank_forks_from_snapshot( process_options.shrink_ratio, process_options.accounts_db_test_hash_calculation, process_options.accounts_db_skip_shrink, + process_options.accounts_db_force_initial_clean, process_options.verify_index, process_options.accounts_db_config.clone(), accounts_update_notifier, diff --git a/ledger/src/blockstore_processor.rs b/ledger/src/blockstore_processor.rs index 219fa4c62ed3d4..618fe4a2c4a2c3 100644 --- a/ledger/src/blockstore_processor.rs +++ b/ledger/src/blockstore_processor.rs @@ -610,6 +610,7 @@ pub struct ProcessOptions { pub allow_dead_slots: bool, pub accounts_db_test_hash_calculation: bool, pub accounts_db_skip_shrink: bool, + pub accounts_db_force_initial_clean: bool, pub accounts_db_config: Option, pub verify_index: bool, pub shrink_ratio: AccountShrinkThreshold, diff --git a/local-cluster/src/validator_configs.rs b/local-cluster/src/validator_configs.rs index d480dc2653567e..3479422c2f5147 100644 --- a/local-cluster/src/validator_configs.rs +++ b/local-cluster/src/validator_configs.rs @@ -51,6 +51,7 @@ pub fn safe_clone_config(config: &ValidatorConfig) -> ValidatorConfig { warp_slot: config.warp_slot, accounts_db_test_hash_calculation: config.accounts_db_test_hash_calculation, accounts_db_skip_shrink: config.accounts_db_skip_shrink, + accounts_db_force_initial_clean: config.accounts_db_force_initial_clean, tpu_coalesce: config.tpu_coalesce, staked_nodes_overrides: config.staked_nodes_overrides.clone(), validator_exit: Arc::new(RwLock::new(Exit::default())), diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index b31a9cb2a46f44..1a46feabfd5945 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -7609,12 +7609,13 @@ impl Bank { pub fn verify_snapshot_bank( &self, test_hash_calculation: bool, - accounts_db_skip_shrink: bool, + skip_shrink: bool, + force_clean: bool, last_full_snapshot_slot: Slot, base: Option<(Slot, /*capitalization*/ u64)>, ) -> bool { let (_, clean_time_us) = measure_us!({ - let should_clean = !accounts_db_skip_shrink && self.slot() > 0; + let should_clean = force_clean || (!skip_shrink && self.slot() > 0); if should_clean { info!("Cleaning..."); // We cannot clean past the last full snapshot's slot because we are about to @@ -7634,7 +7635,7 @@ impl Bank { }); let (_, shrink_time_us) = measure_us!({ - let should_shrink = !accounts_db_skip_shrink && self.slot() > 0; + let should_shrink = !skip_shrink && self.slot() > 0; if should_shrink { info!("Shrinking..."); self.rc.accounts.accounts_db.shrink_all_slots( diff --git a/runtime/src/bank/serde_snapshot.rs b/runtime/src/bank/serde_snapshot.rs index 671a6dc6d738e5..17bba5638f2d47 100644 --- a/runtime/src/bank/serde_snapshot.rs +++ b/runtime/src/bank/serde_snapshot.rs @@ -496,6 +496,7 @@ mod tests { false, false, false, + false, Some(solana_accounts_db::accounts_db::ACCOUNTS_DB_CONFIG_FOR_TESTING), None, Arc::default(), diff --git a/runtime/src/bank/tests.rs b/runtime/src/bank/tests.rs index 9dd27bfd3254bf..190cd15a1278c8 100644 --- a/runtime/src/bank/tests.rs +++ b/runtime/src/bank/tests.rs @@ -3608,11 +3608,11 @@ fn test_verify_snapshot_bank() { bank.freeze(); add_root_and_flush_write_cache(&bank); bank.update_accounts_hash_for_tests(); - assert!(bank.verify_snapshot_bank(true, false, bank.slot(), None)); + assert!(bank.verify_snapshot_bank(true, false, false, bank.slot(), None)); // tamper the bank after freeze! bank.increment_signature_count(1); - assert!(!bank.verify_snapshot_bank(true, false, bank.slot(), None)); + assert!(!bank.verify_snapshot_bank(true, false, false, bank.slot(), None)); } // Test that two bank forks with the same accounts should not hash to the same value. diff --git a/runtime/src/snapshot_bank_utils.rs b/runtime/src/snapshot_bank_utils.rs index e538b07677630f..1757c00a9aadf5 100644 --- a/runtime/src/snapshot_bank_utils.rs +++ b/runtime/src/snapshot_bank_utils.rs @@ -271,6 +271,7 @@ pub fn bank_from_snapshot_archives( shrink_ratio: AccountShrinkThreshold, test_hash_calculation: bool, accounts_db_skip_shrink: bool, + accounts_db_force_initial_clean: bool, verify_index: bool, accounts_db_config: Option, accounts_update_notifier: Option, @@ -365,6 +366,7 @@ pub fn bank_from_snapshot_archives( if !bank.verify_snapshot_bank( test_hash_calculation, accounts_db_skip_shrink || !full_snapshot_archive_info.is_remote(), + accounts_db_force_initial_clean, full_snapshot_archive_info.slot(), base, ) && limit_load_slot_count_from_snapshot.is_none() @@ -427,6 +429,7 @@ pub fn bank_from_latest_snapshot_archives( shrink_ratio: AccountShrinkThreshold, test_hash_calculation: bool, accounts_db_skip_shrink: bool, + accounts_db_force_initial_clean: bool, verify_index: bool, accounts_db_config: Option, accounts_update_notifier: Option, @@ -459,6 +462,7 @@ pub fn bank_from_latest_snapshot_archives( shrink_ratio, test_hash_calculation, accounts_db_skip_shrink, + accounts_db_force_initial_clean, verify_index, accounts_db_config, accounts_update_notifier, @@ -1326,6 +1330,7 @@ mod tests { false, false, false, + false, Some(ACCOUNTS_DB_CONFIG_FOR_TESTING), None, Arc::default(), @@ -1437,6 +1442,7 @@ mod tests { false, false, false, + false, Some(ACCOUNTS_DB_CONFIG_FOR_TESTING), None, Arc::default(), @@ -1568,6 +1574,7 @@ mod tests { false, false, false, + false, Some(ACCOUNTS_DB_CONFIG_FOR_TESTING), None, Arc::default(), @@ -1689,6 +1696,7 @@ mod tests { false, false, false, + false, Some(ACCOUNTS_DB_CONFIG_FOR_TESTING), None, Arc::default(), @@ -1826,6 +1834,7 @@ mod tests { false, false, false, + false, Some(ACCOUNTS_DB_CONFIG_FOR_TESTING), None, Arc::default(), @@ -1891,6 +1900,7 @@ mod tests { false, false, false, + false, Some(ACCOUNTS_DB_CONFIG_FOR_TESTING), None, Arc::default(), @@ -2255,6 +2265,7 @@ mod tests { false, false, false, + false, Some(ACCOUNTS_DB_CONFIG_FOR_TESTING), None, Arc::default(), diff --git a/validator/src/cli.rs b/validator/src/cli.rs index d9b974426bb2a8..0dcafe309eb5d9 100644 --- a/validator/src/cli.rs +++ b/validator/src/cli.rs @@ -1196,6 +1196,13 @@ pub fn app<'a>(version: &'a str, default_args: &'a DefaultArgs) -> App<'a, 'a> { .help("Debug option to scan all append vecs and verify account index refcounts prior to clean") .hidden(hidden_unless_forced()) ) + .arg( + Arg::with_name("no_skip_initial_accounts_db_clean") + .long("no-skip-initial-accounts-db-clean") + .help("Do not skip the initial cleaning of accounts when verifying snapshot bank") + .hidden(hidden_unless_forced()) + .conflicts_with("accounts_db_skip_shrink") + ) .arg( Arg::with_name("accounts_db_create_ancient_storage_packed") .long("accounts-db-create-ancient-storage-packed") diff --git a/validator/src/main.rs b/validator/src/main.rs index 0c998b91c30309..abfe6e2009bc45 100644 --- a/validator/src/main.rs +++ b/validator/src/main.rs @@ -1390,6 +1390,7 @@ pub fn main() { accounts_db_test_hash_calculation: matches.is_present("accounts_db_test_hash_calculation"), accounts_db_config, accounts_db_skip_shrink: true, + accounts_db_force_initial_clean: matches.is_present("no_skip_initial_accounts_db_clean"), tpu_coalesce, no_wait_for_vote_to_start_leader: matches.is_present("no_wait_for_vote_to_start_leader"), accounts_shrink_ratio,