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 28, 2021
1 parent 05eef8f commit 4dc62ad
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 20 deletions.
42 changes: 27 additions & 15 deletions runtime/src/accounts_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4244,7 +4244,7 @@ impl AccountsDb {
check_hash: bool,
) -> Result<(Hash, u64), BankHashVerificationError> {
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 @@ -5131,13 +5131,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 @@ -5728,7 +5740,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 @@ -8108,7 +8120,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 @@ -8123,10 +8135,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 @@ -8146,10 +8158,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 @@ -8162,10 +8174,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 @@ -8179,7 +8191,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 @@ -8190,7 +8202,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 @@ -8354,7 +8366,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 @@ -444,7 +444,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 @@ -142,7 +142,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 @@ -243,7 +243,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 @@ -301,7 +301,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 4dc62ad

Please sign in to comment.