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

add AccountStorage.is_empty #29478

Merged
merged 1 commit into from
Jan 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions runtime/src/account_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ 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 = 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