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

Commit

Permalink
add AccountStorage.is_empty
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffwashington committed Jan 3, 2023
1 parent 71ba409 commit 94646b3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
5 changes: 5 additions & 0 deletions runtime/src/account_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ impl AccountStorage {
self.map.iter().map(|iter_item| *iter_item.key()).collect()
}

/// returns true if there are no append vecs for 'slot'
pub(crate) fn is_empty(&self, slot: Slot) -> bool {
self.get_slot_stores(slot).map(|storages| storages.read().unwrap().is_empty()).unwrap_or(true)
}

/// initialize the storage map to 'all_storages'
pub(crate) fn initialize(&mut self, all_storages: AccountStorageMap) {
assert!(self.map.is_empty());
Expand Down
8 changes: 2 additions & 6 deletions runtime/src/accounts_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8861,11 +8861,7 @@ impl AccountsDb {
.take(per_pass)
.collect::<Vec<_>>();
roots_in_this_pass.into_par_iter().for_each(|slot| {
let storage_maps: SnapshotStorage = self
.storage
.get_slot_storage_entries(*slot)
.unwrap_or_default();
if storage_maps.is_empty() {
if self.storage.is_empty(*slot) {
return;
}

Expand Down Expand Up @@ -14375,7 +14371,7 @@ pub mod tests {
db.store_cached((0, &[(&other_account_key, &slot0_account)][..]), None);
db.add_root(0);
db.flush_accounts_cache(true, None);
assert!(!db.storage.get_slot_storage_entries(0).unwrap().is_empty());
assert!(!db.storage.is_empty(0));

// Store into slot 1, a dummy slot that will be dead and purged before flush
db.store_cached(
Expand Down

0 comments on commit 94646b3

Please sign in to comment.