add Ancestors to get_snapshot_storages to prepare for the future (#17591)

This commit is contained in:
Jeff Washington (jwash) 2021-06-01 15:14:35 -05:00 committed by GitHub
parent ef5169ff24
commit c8fdf0762c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 19 deletions

View File

@ -4251,7 +4251,7 @@ impl AccountsDb {
) -> Result<(Hash, u64), BankHashVerificationError> { ) -> Result<(Hash, u64), BankHashVerificationError> {
if !use_index { if !use_index {
let mut time = Measure::start("collect"); let mut time = Measure::start("collect");
let combined_maps = self.get_snapshot_storages(slot); let combined_maps = self.get_snapshot_storages(slot, Some(ancestors));
time.stop(); time.stop();
let timings = HashStats { let timings = HashStats {
@ -5144,7 +5144,11 @@ 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 self.storage
.0 .0
.iter() .iter()
@ -5743,7 +5747,7 @@ pub mod tests {
accounts.store_uncached(slot, &to_store[..]); accounts.store_uncached(slot, &to_store[..]);
accounts.add_root(slot); accounts.add_root(slot);
let storages = accounts.get_snapshot_storages(slot); let storages = accounts.get_snapshot_storages(slot, None);
(storages, raw_expected) (storages, raw_expected)
} }
@ -8153,7 +8157,7 @@ pub mod tests {
#[test] #[test]
fn test_get_snapshot_storages_empty() { fn test_get_snapshot_storages_empty() {
let db = AccountsDb::new(Vec::new(), &ClusterType::Development); 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] #[test]
@ -8168,10 +8172,10 @@ pub mod tests {
db.add_root(base_slot); db.add_root(base_slot);
db.store_uncached(base_slot, &[(&key, &account)]); 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(base_slot, None).len());
assert_eq!(1, db.get_snapshot_storages(after_slot).len()); assert_eq!(1, db.get_snapshot_storages(after_slot, None).len());
} }
#[test] #[test]
@ -8191,10 +8195,10 @@ pub mod tests {
.unwrap() .unwrap()
.clear(); .clear();
db.add_root(base_slot); 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)]); 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] #[test]
@ -8207,10 +8211,10 @@ pub mod tests {
let after_slot = base_slot + 1; let after_slot = base_slot + 1;
db.store_uncached(base_slot, &[(&key, &account)]); 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); 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] #[test]
@ -8224,7 +8228,7 @@ pub mod tests {
db.store_uncached(base_slot, &[(&key, &account)]); db.store_uncached(base_slot, &[(&key, &account)]);
db.add_root(base_slot); 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 db.storage
.get_slot_stores(0) .get_slot_stores(0)
@ -8235,7 +8239,7 @@ pub mod tests {
.next() .next()
.unwrap() .unwrap()
.remove_account(0, true); .remove_account(0, true);
assert!(db.get_snapshot_storages(after_slot).is_empty()); assert!(db.get_snapshot_storages(after_slot, None).is_empty());
} }
#[test] #[test]
@ -8399,7 +8403,7 @@ pub mod tests {
accounts.store_uncached(current_slot, &[(&pubkey2, &zero_lamport_account)]); accounts.store_uncached(current_slot, &[(&pubkey2, &zero_lamport_account)]);
accounts.store_uncached(current_slot, &[(&pubkey3, &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 let total_accounts: usize = snapshot_stores
.iter() .iter()
.flatten() .flatten()

View File

@ -444,7 +444,7 @@ impl BankRc {
} }
pub fn get_snapshot_storages(&self, slot: Slot) -> SnapshotStorages { pub fn get_snapshot_storages(&self, slot: Slot) -> SnapshotStorages {
self.accounts.accounts_db.get_snapshot_storages(slot) self.accounts.accounts_db.get_snapshot_storages(slot, None)
} }
} }

View File

@ -28,7 +28,7 @@ fn copy_append_vecs<P: AsRef<Path>>(
accounts_db: &AccountsDb, accounts_db: &AccountsDb,
output_dir: P, output_dir: P,
) -> std::io::Result<UnpackedAppendVecMap> { ) -> std::io::Result<UnpackedAppendVecMap> {
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(); let mut unpacked_append_vec_map = UnpackedAppendVecMap::new();
for storage in storage_entries.iter().flatten() { for storage in storage_entries.iter().flatten() {
let storage_path = storage.get_path(); let storage_path = storage.get_path();
@ -142,7 +142,7 @@ fn test_accounts_serialize_style(serde_style: SerdeStyle) {
&mut writer, &mut writer,
&*accounts.accounts_db, &*accounts.accounts_db,
0, 0,
&accounts.accounts_db.get_snapshot_storages(0), &accounts.accounts_db.get_snapshot_storages(0, None),
) )
.unwrap(); .unwrap();
@ -243,7 +243,7 @@ pub(crate) fn reconstruct_accounts_db_via_serialization(
slot: Slot, slot: Slot,
) -> AccountsDb { ) -> AccountsDb {
let mut writer = Cursor::new(vec![]); 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( accountsdb_to_stream(
SerdeStyle::Newer, SerdeStyle::Newer,
&mut writer, &mut writer,
@ -301,7 +301,7 @@ mod test_bank_serialize {
where where
S: serde::Serializer, 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 // ensure there is a single snapshot storage example for ABI digesting
assert_eq!(snapshot_storages.len(), 1); assert_eq!(snapshot_storages.len(), 1);