Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffwashington committed May 26, 2021
1 parent 9bf43d8 commit c480e35
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 20 deletions.
43 changes: 28 additions & 15 deletions runtime/src/accounts_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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]
Expand All @@ -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]
Expand All @@ -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]
Expand All @@ -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]
Expand All @@ -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)
Expand All @@ -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]
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ impl BankRc {
}

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)
}
}

Expand Down
8 changes: 4 additions & 4 deletions runtime/src/serde_snapshot/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ fn copy_append_vecs<P: AsRef<Path>>(
accounts_db: &AccountsDb,
output_dir: P,
) -> 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();
for storage in storage_entries.iter().flatten() {
let storage_path = storage.get_path();
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit c480e35

Please sign in to comment.