diff --git a/runtime/src/accounts_db.rs b/runtime/src/accounts_db.rs index ac3511ec6..4a97d9f36 100644 --- a/runtime/src/accounts_db.rs +++ b/runtime/src/accounts_db.rs @@ -11253,7 +11253,8 @@ pub mod tests { solana_logger::setup(); let unrooted_slot = 9; let unrooted_bank_id = 9; - let db = AccountsDb::new(Vec::new(), &ClusterType::Development); + let mut db = AccountsDb::new(Vec::new(), &ClusterType::Development); + db.caching_enabled = true; let key = solana_sdk::pubkey::new_rand(); let account0 = AccountSharedData::new(1, 0, &key); db.store_for_tests(unrooted_slot, &[(&key, &account0)]); @@ -11265,7 +11266,7 @@ pub mod tests { let key2 = solana_sdk::pubkey::new_rand(); let new_root = unrooted_slot + 1; db.store_for_tests(new_root, &[(&key2, &account0)]); - db.add_root(new_root); + db.add_root_and_flush_write_cache(new_root); // Simulate reconstruction from snapshot let db = reconstruct_accounts_db_via_serialization(&db, new_root); @@ -11806,7 +11807,8 @@ pub mod tests { fn test_clean_old_with_normal_account() { solana_logger::setup(); - let accounts = AccountsDb::new(Vec::new(), &ClusterType::Development); + let mut accounts = AccountsDb::new(Vec::new(), &ClusterType::Development); + accounts.caching_enabled = true; let pubkey = solana_sdk::pubkey::new_rand(); let account = AccountSharedData::new(1, 0, AccountSharedData::default().owner()); //store an account @@ -11815,9 +11817,9 @@ pub mod tests { // simulate slots are rooted after while accounts.get_accounts_delta_hash(0); - accounts.add_root(0); + accounts.add_root_and_flush_write_cache(0); accounts.get_accounts_delta_hash(1); - accounts.add_root(1); + accounts.add_root_and_flush_write_cache(1); //even if rooted, old state isn't cleaned up assert_eq!(accounts.alive_account_count_in_slot(0), 1); @@ -11834,7 +11836,8 @@ pub mod tests { fn test_clean_old_with_zero_lamport_account() { solana_logger::setup(); - let accounts = AccountsDb::new(Vec::new(), &ClusterType::Development); + let mut accounts = AccountsDb::new(Vec::new(), &ClusterType::Development); + accounts.caching_enabled = true; let pubkey1 = solana_sdk::pubkey::new_rand(); let pubkey2 = solana_sdk::pubkey::new_rand(); let normal_account = AccountSharedData::new(1, 0, AccountSharedData::default().owner()); @@ -11847,9 +11850,9 @@ pub mod tests { //simulate slots are rooted after while accounts.get_accounts_delta_hash(0); - accounts.add_root(0); + accounts.add_root_and_flush_write_cache(0); accounts.get_accounts_delta_hash(1); - accounts.add_root(1); + accounts.add_root_and_flush_write_cache(1); //even if rooted, old state isn't cleaned up assert_eq!(accounts.alive_account_count_in_slot(0), 2); @@ -11872,7 +11875,7 @@ pub mod tests { Vec::new(), &ClusterType::Development, spl_token_mint_index_enabled(), - false, + true, AccountShrinkThreshold::default(), ); let pubkey1 = solana_sdk::pubkey::new_rand(); @@ -11899,11 +11902,11 @@ pub mod tests { //simulate slots are rooted after while accounts.get_accounts_delta_hash(0); - accounts.add_root(0); + accounts.add_root_and_flush_write_cache(0); accounts.get_accounts_delta_hash(1); - accounts.add_root(1); + accounts.add_root_and_flush_write_cache(1); accounts.get_accounts_delta_hash(2); - accounts.add_root(2); + accounts.add_root_and_flush_write_cache(2); //even if rooted, old state isn't cleaned up assert_eq!(accounts.alive_account_count_in_slot(0), 2); @@ -12012,7 +12015,8 @@ pub mod tests { fn test_clean_max_slot_zero_lamport_account() { solana_logger::setup(); - let accounts = AccountsDb::new(Vec::new(), &ClusterType::Development); + let mut accounts = AccountsDb::new(Vec::new(), &ClusterType::Development); + accounts.caching_enabled = true; let pubkey = solana_sdk::pubkey::new_rand(); let account = AccountSharedData::new(1, 0, AccountSharedData::default().owner()); let zero_account = AccountSharedData::new(0, 0, AccountSharedData::default().owner()); @@ -12023,8 +12027,10 @@ pub mod tests { accounts.store_for_tests(1, &[(&pubkey, &zero_account)]); // simulate slots are rooted after while - accounts.add_root(0); - accounts.add_root(1); + accounts.get_accounts_delta_hash(0); + accounts.add_root_and_flush_write_cache(0); + accounts.get_accounts_delta_hash(1); + accounts.add_root_and_flush_write_cache(1); // Only clean up to account 0, should not purge slot 0 based on // updates in later slots in slot 1 @@ -13112,7 +13118,8 @@ pub mod tests { #[test] fn test_get_snapshot_storages_only_older_than_or_equal_to_snapshot_slot() { - let db = AccountsDb::new(Vec::new(), &ClusterType::Development); + let mut db = AccountsDb::new(Vec::new(), &ClusterType::Development); + db.caching_enabled = true; let key = Pubkey::default(); let account = AccountSharedData::new(1, 0, &key); @@ -13120,8 +13127,8 @@ pub mod tests { let base_slot = before_slot + 1; let after_slot = base_slot + 1; - db.add_root(base_slot); db.store_for_tests(base_slot, &[(&key, &account)]); + db.add_root_and_flush_write_cache(base_slot); assert!(db.get_snapshot_storages(..=before_slot, None).0.is_empty()); assert_eq!(1, db.get_snapshot_storages(..=base_slot, None).0.len()); @@ -13153,7 +13160,8 @@ pub mod tests { #[test] fn test_get_snapshot_storages_only_roots() { - let db = AccountsDb::new(Vec::new(), &ClusterType::Development); + let mut db = AccountsDb::new(Vec::new(), &ClusterType::Development); + db.caching_enabled = true; let key = Pubkey::default(); let account = AccountSharedData::new(1, 0, &key); @@ -13163,13 +13171,14 @@ pub mod tests { db.store_for_tests(base_slot, &[(&key, &account)]); assert!(db.get_snapshot_storages(..=after_slot, None).0.is_empty()); - db.add_root(base_slot); + db.add_root_and_flush_write_cache(base_slot); assert_eq!(1, db.get_snapshot_storages(..=after_slot, None).0.len()); } #[test] fn test_get_snapshot_storages_exclude_empty() { - let db = AccountsDb::new(Vec::new(), &ClusterType::Development); + let mut db = AccountsDb::new(Vec::new(), &ClusterType::Development); + db.caching_enabled = true; let key = Pubkey::default(); let account = AccountSharedData::new(1, 0, &key); @@ -13177,7 +13186,7 @@ pub mod tests { let after_slot = base_slot + 1; db.store_for_tests(base_slot, &[(&key, &account)]); - db.add_root(base_slot); + db.add_root_and_flush_write_cache(base_slot); assert_eq!(1, db.get_snapshot_storages(..=after_slot, None).0.len()); db.storage @@ -13194,14 +13203,15 @@ pub mod tests { #[test] fn test_get_snapshot_storages_with_base_slot() { - let db = AccountsDb::new(Vec::new(), &ClusterType::Development); + let mut db = AccountsDb::new(Vec::new(), &ClusterType::Development); + db.caching_enabled = true; let key = Pubkey::default(); let account = AccountSharedData::new(1, 0, &key); let slot = 10; db.store_for_tests(slot, &[(&key, &account)]); - db.add_root(slot); + db.add_root_and_flush_write_cache(slot); assert_eq!( 0, db.get_snapshot_storages(slot + 1..=slot + 1, None).0.len() @@ -16290,11 +16300,13 @@ pub mod tests { #[test] fn test_calculate_storage_count_and_alive_bytes() { - let accounts = AccountsDb::new_single_for_tests(); + let mut accounts = AccountsDb::new_single_for_tests(); + accounts.caching_enabled = true; let shared_key = solana_sdk::pubkey::new_rand(); let account = AccountSharedData::new(1, 1, AccountSharedData::default().owner()); let slot0 = 0; accounts.store_for_tests(slot0, &[(&shared_key, &account)]); + accounts.add_root_and_flush_write_cache(slot0); let storage_maps = accounts .storage @@ -16324,7 +16336,8 @@ pub mod tests { #[test] fn test_calculate_storage_count_and_alive_bytes_2_accounts() { - let accounts = AccountsDb::new_single_for_tests(); + let mut accounts = AccountsDb::new_single_for_tests(); + accounts.caching_enabled = true; let keys = [ solana_sdk::pubkey::Pubkey::new(&[0; 32]), solana_sdk::pubkey::Pubkey::new(&[255; 32]), @@ -16346,6 +16359,7 @@ pub mod tests { let slot0 = 0; accounts.store_for_tests(slot0, &[(&keys[0], &account)]); accounts.store_for_tests(slot0, &[(&keys[1], &account_big)]); + accounts.add_root_and_flush_write_cache(slot0); let storage_maps = accounts .storage @@ -16402,7 +16416,8 @@ pub mod tests { #[test] fn test_purge_alive_unrooted_slots_after_clean() { - let accounts = AccountsDb::new_single_for_tests(); + let mut accounts = AccountsDb::new_single_for_tests(); + accounts.caching_enabled = true; // Key shared between rooted and nonrooted slot let shared_key = solana_sdk::pubkey::new_rand(); @@ -16427,7 +16442,7 @@ pub mod tests { // Simulate adding dirty pubkeys on bank freeze, set root accounts.get_accounts_delta_hash(slot1); - accounts.add_root(slot1); + accounts.add_root_and_flush_write_cache(slot1); // The later rooted zero-lamport update to `shared_key` cannot be cleaned // because it is kept alive by the unrooted slot.