From 710b10c78d50154f08cdf216fc56661648f83f76 Mon Sep 17 00:00:00 2001 From: "Jeff Washington (jwash)" Date: Mon, 24 May 2021 18:47:35 -0500 Subject: [PATCH] fix tests --- runtime/src/accounts.rs | 4 ++- runtime/src/accounts_db.rs | 43 +++++++++++++++++++---------- runtime/src/serde_snapshot/tests.rs | 8 +++--- 3 files changed, 35 insertions(+), 20 deletions(-) diff --git a/runtime/src/accounts.rs b/runtime/src/accounts.rs index 3d7aacd8328ab5..0183d296b7e298 100644 --- a/runtime/src/accounts.rs +++ b/runtime/src/accounts.rs @@ -614,6 +614,7 @@ impl Accounts { } pub fn calculate_capitalization(&self, ancestors: &Ancestors, slot: Slot) -> u64 { + error!("slot: {}, ancestors: {:?}", slot, ancestors); let cap = self .accounts_db .update_accounts_hash_with_index_option(false, false, slot, ancestors, None) @@ -621,7 +622,8 @@ impl Accounts { let cap2 = self.accounts_db.unchecked_scan_accounts( "calculate_capitalization_scan_elapsed", ancestors, - |total_capitalization: &mut u64, (_pubkey, loaded_account, _slot)| { + |total_capitalization: &mut u64, (_pubkey, loaded_account, slot)| { + error!("slot: {}, cached: {}", slot, loaded_account.is_cached()); let lamports = loaded_account.lamports(); if Self::is_loadable(lamports) { *total_capitalization = AccountsDb::checked_iterative_sum_for_capitalization( diff --git a/runtime/src/accounts_db.rs b/runtime/src/accounts_db.rs index 8be4ddf9bf0a51..edf4fb518e013b 100644 --- a/runtime/src/accounts_db.rs +++ b/runtime/src/accounts_db.rs @@ -4126,7 +4126,7 @@ impl AccountsDb { ancestors: &Ancestors, ) -> (Hash, u64) { if !use_index { - let combined_maps = self.get_snapshot_storages(slot); + let combined_maps = self.get_snapshot_storages(slot, Some(ancestors)); Self::calculate_accounts_hash_without_index( &combined_maps, @@ -4220,6 +4220,7 @@ impl AccountsDb { storages: &[SnapshotStorage], thread_pool: Option<&ThreadPool>, ) -> (Hash, u64) { + error!("storages: {}", storages.len()); let scan_and_hash = || { let mut stats = HashStats::default(); // When calculating hashes, it is helpful to break the pubkeys found into bins based on the pubkey value. @@ -4963,13 +4964,25 @@ impl AccountsDb { } } - pub fn get_snapshot_storages(&self, snapshot_slot: Slot) -> SnapshotStorages { + pub fn get_snapshot_storages( + &self, + snapshot_slot: Slot, + ancestors: Option<&Ancestors>, + ) -> SnapshotStorages { self.storage .0 .iter() .filter(|iter_item| { let slot = *iter_item.key(); - slot <= snapshot_slot && self.accounts_index.is_root(slot) + let r = slot <= snapshot_slot + && (self.accounts_index.is_root(slot) + || ancestors + .map(|ancestors| ancestors.contains_key(&slot)) + .unwrap_or_default()); + if !r { + error!("Excluding: {}", slot); + } + r }) .map(|iter_item| { iter_item @@ -5752,7 +5765,7 @@ pub mod tests { ); accounts.add_root(SLOT); - let storages = accounts.get_snapshot_storages(SLOT); + let storages = accounts.get_snapshot_storages(SLOT, None); (storages, raw_expected) } @@ -8044,7 +8057,7 @@ pub mod tests { #[test] fn test_get_snapshot_storages_empty() { let db = AccountsDb::new(Vec::new(), &ClusterType::Development); - assert!(db.get_snapshot_storages(0).is_empty()); + assert!(db.get_snapshot_storages(0, None).is_empty()); } #[test] @@ -8059,10 +8072,10 @@ pub mod tests { db.add_root(base_slot); db.store_uncached(base_slot, &[(&key, &account)]); - assert!(db.get_snapshot_storages(before_slot).is_empty()); + assert!(db.get_snapshot_storages(before_slot, None).is_empty()); - assert_eq!(1, db.get_snapshot_storages(base_slot).len()); - assert_eq!(1, db.get_snapshot_storages(after_slot).len()); + assert_eq!(1, db.get_snapshot_storages(base_slot, None).len()); + assert_eq!(1, db.get_snapshot_storages(after_slot, None).len()); } #[test] @@ -8082,10 +8095,10 @@ pub mod tests { .unwrap() .clear(); db.add_root(base_slot); - assert!(db.get_snapshot_storages(after_slot).is_empty()); + assert!(db.get_snapshot_storages(after_slot, None).is_empty()); db.store_uncached(base_slot, &[(&key, &account)]); - assert_eq!(1, db.get_snapshot_storages(after_slot).len()); + assert_eq!(1, db.get_snapshot_storages(after_slot, None).len()); } #[test] @@ -8098,10 +8111,10 @@ pub mod tests { let after_slot = base_slot + 1; db.store_uncached(base_slot, &[(&key, &account)]); - assert!(db.get_snapshot_storages(after_slot).is_empty()); + assert!(db.get_snapshot_storages(after_slot, None).is_empty()); db.add_root(base_slot); - assert_eq!(1, db.get_snapshot_storages(after_slot).len()); + assert_eq!(1, db.get_snapshot_storages(after_slot, None).len()); } #[test] @@ -8115,7 +8128,7 @@ pub mod tests { db.store_uncached(base_slot, &[(&key, &account)]); db.add_root(base_slot); - assert_eq!(1, db.get_snapshot_storages(after_slot).len()); + assert_eq!(1, db.get_snapshot_storages(after_slot, None).len()); db.storage .get_slot_stores(0) @@ -8126,7 +8139,7 @@ pub mod tests { .next() .unwrap() .remove_account(0, true); - assert!(db.get_snapshot_storages(after_slot).is_empty()); + assert!(db.get_snapshot_storages(after_slot, None).is_empty()); } #[test] @@ -8290,7 +8303,7 @@ pub mod tests { accounts.store_uncached(current_slot, &[(&pubkey2, &zero_lamport_account)]); accounts.store_uncached(current_slot, &[(&pubkey3, &zero_lamport_account)]); - let snapshot_stores = accounts.get_snapshot_storages(current_slot); + let snapshot_stores = accounts.get_snapshot_storages(current_slot, None); let total_accounts: usize = snapshot_stores .iter() .flatten() diff --git a/runtime/src/serde_snapshot/tests.rs b/runtime/src/serde_snapshot/tests.rs index f0604302dbd235..7da8a552207ac1 100644 --- a/runtime/src/serde_snapshot/tests.rs +++ b/runtime/src/serde_snapshot/tests.rs @@ -28,7 +28,7 @@ fn copy_append_vecs>( accounts_db: &AccountsDb, output_dir: P, ) -> std::io::Result { - let storage_entries = accounts_db.get_snapshot_storages(Slot::max_value()); + let storage_entries = accounts_db.get_snapshot_storages(Slot::max_value(), None); let mut unpacked_append_vec_map = UnpackedAppendVecMap::new(); for storage in storage_entries.iter().flatten() { let storage_path = storage.get_path(); @@ -141,7 +141,7 @@ fn test_accounts_serialize_style(serde_style: SerdeStyle) { &mut writer, &*accounts.accounts_db, 0, - &accounts.accounts_db.get_snapshot_storages(0), + &accounts.accounts_db.get_snapshot_storages(0, None), ) .unwrap(); @@ -241,7 +241,7 @@ pub(crate) fn reconstruct_accounts_db_via_serialization( slot: Slot, ) -> AccountsDb { let mut writer = Cursor::new(vec![]); - let snapshot_storages = accounts.get_snapshot_storages(slot); + let snapshot_storages = accounts.get_snapshot_storages(slot, None); accountsdb_to_stream( SerdeStyle::Newer, &mut writer, @@ -299,7 +299,7 @@ mod test_bank_serialize { where S: serde::Serializer, { - let snapshot_storages = bank.rc.accounts.accounts_db.get_snapshot_storages(0); + let snapshot_storages = bank.rc.accounts.accounts_db.get_snapshot_storages(0, None); // ensure there is a single snapshot storage example for ABI digesting assert_eq!(snapshot_storages.len(), 1);