add validator option --accounts-db-skip-shrink (#19028)

* add validator option --accounts-db-skip-shrink

* typo
This commit is contained in:
Jeff Washington (jwash) 2021-08-04 17:28:33 -05:00 committed by GitHub
parent 68cc71409e
commit 3280ae3e9f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 31 additions and 6 deletions

View File

@ -138,6 +138,7 @@ pub struct ValidatorConfig {
pub accounts_db_caching_enabled: bool,
pub warp_slot: Option<Slot>,
pub accounts_db_test_hash_calculation: bool,
pub accounts_db_skip_shrink: bool,
pub accounts_db_use_index_hash_calculation: bool,
pub tpu_coalesce_ms: u64,
pub validator_exit: Arc<RwLock<Exit>>,
@ -194,6 +195,7 @@ impl Default for ValidatorConfig {
accounts_db_caching_enabled: false,
warp_slot: None,
accounts_db_test_hash_calculation: false,
accounts_db_skip_shrink: false,
accounts_db_use_index_hash_calculation: true,
tpu_coalesce_ms: DEFAULT_TPU_COALESCE_MS,
validator_exit: Arc::new(RwLock::new(Exit::default())),
@ -1131,6 +1133,8 @@ fn new_banks_from_ledger(
account_indexes: config.account_indexes.clone(),
accounts_db_caching_enabled: config.accounts_db_caching_enabled,
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,
..blockstore_processor::ProcessOptions::default()
};

View File

@ -186,6 +186,7 @@ mod tests {
accounts_db::AccountShrinkThreshold::default(),
check_hash_calculation,
false,
false,
)
.unwrap();
@ -842,6 +843,7 @@ mod tests {
accounts_db::AccountShrinkThreshold::default(),
false,
false,
false,
)?;
Ok((

View File

@ -143,6 +143,7 @@ fn load_from_snapshot(
process_options.limit_load_slot_count_from_snapshot,
process_options.shrink_ratio,
process_options.accounts_db_test_hash_calculation,
process_options.accounts_db_skip_shrink,
process_options.verify_index,
)
.expect("Load from snapshot failed");

View File

@ -384,6 +384,7 @@ pub struct ProcessOptions {
pub limit_load_slot_count_from_snapshot: Option<usize>,
pub allow_dead_slots: bool,
pub accounts_db_test_hash_calculation: bool,
pub accounts_db_skip_shrink: bool,
pub verify_index: bool,
pub shrink_ratio: AccountShrinkThreshold,
}

View File

@ -50,6 +50,7 @@ pub fn safe_clone_config(config: &ValidatorConfig) -> ValidatorConfig {
accounts_db_caching_enabled: config.accounts_db_caching_enabled,
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_use_index_hash_calculation: config.accounts_db_use_index_hash_calculation,
tpu_coalesce_ms: config.tpu_coalesce_ms,
validator_exit: Arc::new(RwLock::new(Exit::default())),

View File

@ -126,6 +126,7 @@ fn initialize_from_snapshot(
process_options.limit_load_slot_count_from_snapshot,
process_options.shrink_ratio,
process_options.accounts_db_test_hash_calculation,
false,
process_options.verify_index,
)
.unwrap();

View File

@ -4876,7 +4876,11 @@ impl Bank {
/// A snapshot bank should be purged of 0 lamport accounts which are not part of the hash
/// calculation and could shield other real accounts.
pub fn verify_snapshot_bank(&self, test_hash_calculation: bool) -> bool {
pub fn verify_snapshot_bank(
&self,
test_hash_calculation: bool,
accounts_db_skip_shrink: bool,
) -> bool {
info!("cleaning..");
let mut clean_time = Measure::start("clean");
if self.slot() > 0 {
@ -4884,9 +4888,9 @@ impl Bank {
}
clean_time.stop();
info!("shrinking..");
let mut shrink_all_slots_time = Measure::start("shrink_all_slots");
if self.slot() > 0 {
if !accounts_db_skip_shrink && self.slot() > 0 {
info!("shrinking..");
self.shrink_all_slots(true);
}
shrink_all_slots_time.stop();
@ -8674,11 +8678,11 @@ pub(crate) mod tests {
bank.transfer(1_000, &mint_keypair, &pubkey).unwrap();
bank.freeze();
bank.update_accounts_hash();
assert!(bank.verify_snapshot_bank(true));
assert!(bank.verify_snapshot_bank(true, false));
// tamper the bank after freeze!
bank.increment_signature_count(1);
assert!(!bank.verify_snapshot_bank(true));
assert!(!bank.verify_snapshot_bank(true, false));
}
// Test that two bank forks with the same accounts should not hash to the same value.

View File

@ -844,6 +844,7 @@ pub fn bank_from_snapshot_archives<P>(
limit_load_slot_count_from_snapshot: Option<usize>,
shrink_ratio: AccountShrinkThreshold,
test_hash_calculation: bool,
accounts_db_skip_shrink: bool,
verify_index: bool,
) -> Result<(Bank, BankFromArchiveTimings)>
where
@ -916,7 +917,7 @@ where
info!("{}", measure_rebuild);
let mut measure_verify = Measure::start("verify");
if !bank.verify_snapshot_bank(test_hash_calculation)
if !bank.verify_snapshot_bank(test_hash_calculation, accounts_db_skip_shrink)
&& limit_load_slot_count_from_snapshot.is_none()
{
panic!("Snapshot bank for slot {} failed to verify", bank.slot());
@ -2497,6 +2498,7 @@ mod tests {
AccountShrinkThreshold::default(),
false,
false,
false,
)
.unwrap();
@ -2587,6 +2589,7 @@ mod tests {
AccountShrinkThreshold::default(),
false,
false,
false,
)
.unwrap();
@ -2696,6 +2699,7 @@ mod tests {
AccountShrinkThreshold::default(),
false,
false,
false,
)
.unwrap();

View File

@ -1812,6 +1812,12 @@ pub fn main() {
.long("no-accounts-db-caching")
.help("Disables accounts caching"),
)
.arg(
Arg::with_name("accounts_db_skip_shrink")
.long("accounts-db-skip-shrink")
.help("Enables faster starting of validators by skipping shrink. \
This option is for use during testing."),
)
.arg(
Arg::with_name("accounts_db_test_hash_calculation")
.long("accounts-db-test-hash-calculation")
@ -2379,6 +2385,7 @@ pub fn main() {
account_indexes,
accounts_db_caching_enabled: !matches.is_present("no_accounts_db_caching"),
accounts_db_test_hash_calculation: matches.is_present("accounts_db_test_hash_calculation"),
accounts_db_skip_shrink: matches.is_present("accounts_db_skip_shrink"),
accounts_db_use_index_hash_calculation: matches.is_present("accounts_db_index_hashing"),
tpu_coalesce_ms,
no_wait_for_vote_to_start_leader: matches.is_present("no_wait_for_vote_to_start_leader"),