From 7180345ee1320796b30ab58f4ba00b6d44a98108 Mon Sep 17 00:00:00 2001 From: "Jeff Washington (jwash)" Date: Tue, 6 Dec 2022 12:24:43 -0600 Subject: [PATCH] test_verify_bank_capitalization works with write cache (#29107) --- runtime/src/accounts_db.rs | 102 ++++++++++++++++++++----------------- 1 file changed, 54 insertions(+), 48 deletions(-) diff --git a/runtime/src/accounts_db.rs b/runtime/src/accounts_db.rs index e528b715de..1a5d2a29aa 100644 --- a/runtime/src/accounts_db.rs +++ b/runtime/src/accounts_db.rs @@ -12948,58 +12948,64 @@ pub mod tests { #[test] fn test_verify_bank_capitalization() { - use BankHashVerificationError::*; - solana_logger::setup(); - let db = AccountsDb::new(Vec::new(), &ClusterType::Development); + for pass in 0..2 { + use BankHashVerificationError::*; + solana_logger::setup(); + let db = AccountsDb::new(Vec::new(), &ClusterType::Development); - let key = solana_sdk::pubkey::new_rand(); - let some_data_len = 0; - let some_slot: Slot = 0; - let account = AccountSharedData::new(1, some_data_len, &key); - let ancestors = vec![(some_slot, 0)].into_iter().collect(); + let key = solana_sdk::pubkey::new_rand(); + let some_data_len = 0; + let some_slot: Slot = 0; + let account = AccountSharedData::new(1, some_data_len, &key); + let ancestors = vec![(some_slot, 0)].into_iter().collect(); - db.store_for_tests(some_slot, &[(&key, &account)]); - db.add_root(some_slot); - db.update_accounts_hash_for_tests(some_slot, &ancestors, true, true); - assert_matches!( - db.verify_bank_hash_and_lamports( + db.store_for_tests(some_slot, &[(&key, &account)]); + if pass == 0 { + db.add_root_and_flush_write_cache(some_slot); + db.update_accounts_hash_for_tests(some_slot, &ancestors, true, true); + assert_matches!( + db.verify_bank_hash_and_lamports( + some_slot, + &ancestors, + 1, + true, + &EpochSchedule::default(), + &RentCollector::default(), + false, + ), + Ok(_) + ); + continue; + } + + let native_account_pubkey = solana_sdk::pubkey::new_rand(); + db.store_for_tests( some_slot, - &ancestors, - 1, - true, - &EpochSchedule::default(), - &RentCollector::default(), - false, - ), - Ok(_) - ); + &[( + &native_account_pubkey, + &solana_sdk::native_loader::create_loadable_account_for_test("foo"), + )], + ); + db.add_root_and_flush_write_cache(some_slot); + db.update_accounts_hash_for_tests(some_slot, &ancestors, true, true); + assert_matches!( + db.verify_bank_hash_and_lamports( + some_slot, + &ancestors, + 2, + true, + &EpochSchedule::default(), + &RentCollector::default(), + false, + ), + Ok(_) + ); - let native_account_pubkey = solana_sdk::pubkey::new_rand(); - db.store_for_tests( - some_slot, - &[( - &native_account_pubkey, - &solana_sdk::native_loader::create_loadable_account_for_test("foo"), - )], - ); - db.update_accounts_hash_for_tests(some_slot, &ancestors, true, true); - assert_matches!( - db.verify_bank_hash_and_lamports( - some_slot, - &ancestors, - 2, - true, - &EpochSchedule::default(), - &RentCollector::default(), - false, - ), - Ok(_) - ); - - assert_matches!( - db.verify_bank_hash_and_lamports(some_slot, &ancestors, 10, true, &EpochSchedule::default(), &RentCollector::default(), false,), - Err(MismatchedTotalLamports(expected, actual)) if expected == 2 && actual == 10 - ); + assert_matches!( + db.verify_bank_hash_and_lamports(some_slot, &ancestors, 10, true, &EpochSchedule::default(), &RentCollector::default(), false,), + Err(MismatchedTotalLamports(expected, actual)) if expected == 2 && actual == 10 + ); + } } #[test]