From 58c1b7aefb9c365232716b36c210811feeb628b0 Mon Sep 17 00:00:00 2001 From: Brooks Date: Fri, 23 Feb 2024 16:20:42 -0500 Subject: [PATCH] Replaces ReadAccountMapEntry in more tests (#35308) --- accounts-db/src/accounts_db.rs | 40 +++++++------------------------ accounts-db/src/accounts_index.rs | 23 ++++-------------- 2 files changed, 14 insertions(+), 49 deletions(-) diff --git a/accounts-db/src/accounts_db.rs b/accounts-db/src/accounts_db.rs index ad96a305e..2ff852d1e 100644 --- a/accounts-db/src/accounts_db.rs +++ b/accounts-db/src/accounts_db.rs @@ -9771,9 +9771,7 @@ pub mod tests { account_info::StoredSize, account_storage::meta::{AccountMeta, StoredMeta}, accounts_hash::MERKLE_FANOUT, - accounts_index::{ - tests::*, AccountSecondaryIndexesIncludeExclude, ReadAccountMapEntry, RefCount, - }, + accounts_index::{tests::*, AccountSecondaryIndexesIncludeExclude}, ancient_append_vecs, append_vec::{test_utils::TempFile, AppendVecStoredAccountMeta}, cache_hash_data::CacheHashDataFile, @@ -13366,22 +13364,10 @@ pub mod tests { const UPSERT_POPULATE_RECLAIMS: UpsertReclaim = UpsertReclaim::PopulateReclaims; - // returns the rooted entries and the storage ref count - fn roots_and_ref_count( - index: &AccountsIndex, - locked_account_entry: &ReadAccountMapEntry, - max_inclusive: Option, - ) -> (SlotList, RefCount) { - ( - index.get_rooted_entries(locked_account_entry.slot_list(), max_inclusive), - locked_account_entry.ref_count(), - ) - } - #[test] fn test_delete_dependencies() { solana_logger::setup(); - let accounts_index = AccountsIndex::default_for_tests(); + let accounts_index = AccountsIndex::::default_for_tests(); let key0 = Pubkey::new_from_array([0u8; 32]); let key1 = Pubkey::new_from_array([1u8; 32]); let key2 = Pubkey::new_from_array([2u8; 32]); @@ -13455,21 +13441,13 @@ pub mod tests { accounts_index.add_root(2); accounts_index.add_root(3); let mut purges = HashMap::new(); - let (key0_entry, _) = accounts_index.get_for_tests(&key0, None, None).unwrap(); - purges.insert( - key0, - roots_and_ref_count(&accounts_index, &key0_entry, None), - ); - let (key1_entry, _) = accounts_index.get_for_tests(&key1, None, None).unwrap(); - purges.insert( - key1, - roots_and_ref_count(&accounts_index, &key1_entry, None), - ); - let (key2_entry, _) = accounts_index.get_for_tests(&key2, None, None).unwrap(); - purges.insert( - key2, - roots_and_ref_count(&accounts_index, &key2_entry, None), - ); + for key in [&key0, &key1, &key2] { + let index_entry = accounts_index.get_cloned(key).unwrap(); + let rooted_entries = accounts_index + .get_rooted_entries(index_entry.slot_list.read().unwrap().as_slice(), None); + let ref_count = index_entry.ref_count(); + purges.insert(*key, (rooted_entries, ref_count)); + } for (key, (list, ref_count)) in &purges { info!(" purge {} ref_count {} =>", key, ref_count); for x in list { diff --git a/accounts-db/src/accounts_index.rs b/accounts-db/src/accounts_index.rs index 51a04e3a4..266e9d74e 100644 --- a/accounts-db/src/accounts_index.rs +++ b/accounts-db/src/accounts_index.rs @@ -2333,24 +2333,11 @@ pub mod tests { index.insert_new_if_missing_into_primary_index(slot, items.len(), items.into_iter()); assert_eq!(result.count, 1); index.set_startup(Startup::Normal); - if let AccountIndexGetResult::Found(entry, index) = - // the entry for - index.get_for_tests(pubkey, Some(&ancestors), None) - { - // make sure the one with the correct info is added - assert_eq!(entry.slot_list()[index], (slot, account_info2)); - // make sure it wasn't inserted twice - assert_eq!( - entry - .slot_list() - .iter() - .filter_map(|(entry_slot, _)| (entry_slot == &slot).then_some(true)) - .count(), - 1 - ); - } else { - panic!("failed"); - } + let index_entry = index.get_cloned(pubkey).unwrap(); + let slot_list = index_entry.slot_list.read().unwrap(); + // make sure the one with the correct info is added, and wasn't inserted twice + assert_eq!(slot_list.len(), 1); + assert_eq!(slot_list[0], (slot, account_info2)); } #[test]