Skip to content

Commit

Permalink
get_account_storage_entry handles missing shrink in progress entry co…
Browse files Browse the repository at this point in the history
…rrectly (#29682)
  • Loading branch information
jeffwashington authored Jan 13, 2023
1 parent 05594c6 commit 064f163
Showing 1 changed file with 42 additions and 3 deletions.
45 changes: 42 additions & 3 deletions runtime/src/account_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ impl AccountStorage {
self.get_slot_stores_shrinking_in_progress_ok(slot)
.and_then(|storage_map| storage_map.read().unwrap().get(&store_id).cloned())
.or_else(|| {
self.shrink_in_progress_map
.get(&slot)
.map(|entry| Arc::clone(entry.value()))
self.shrink_in_progress_map.get(&slot).and_then(|entry| {
(entry.value().append_vec_id() == store_id).then(|| Arc::clone(entry.value()))
})
})
}

Expand Down Expand Up @@ -485,4 +485,43 @@ pub(crate) mod tests {
let sample = storage.get_test_storage();
storage.shrinking_in_progress(0, sample);
}

#[test]
fn test_missing() {
// already called 'shrink_in_progress' on this slot, but it finished, so we succeed
// verify data structures during and after shrink and then with subsequent shrink call
let storage = AccountStorage::default();
let sample = storage.get_test_storage();
let id = sample.append_vec_id();
let slot_stores = SlotStores::default();
slot_stores.write().unwrap().insert(id, sample.clone());
let missing_id = 9999;
let slot = sample.slot();
// id is missing since not in maps at all
assert!(storage.get_account_storage_entry(slot, id).is_none());
// missing should always be missing
assert!(storage
.get_account_storage_entry(slot, missing_id)
.is_none());
storage.map.insert(slot, slot_stores.clone());
// id is found in map
assert!(storage.get_account_storage_entry(slot, id).is_some());
assert!(storage
.get_account_storage_entry(slot, missing_id)
.is_none());
storage
.shrink_in_progress_map
.insert(slot, Arc::clone(&sample));
// id is found in map
assert!(storage
.get_account_storage_entry(slot, missing_id)
.is_none());
assert!(storage.get_account_storage_entry(slot, id).is_some());
slot_stores.write().unwrap().clear();
// id is found in shrink_in_progress_map
assert!(storage
.get_account_storage_entry(slot, missing_id)
.is_none());
assert!(storage.get_account_storage_entry(slot, id).is_some());
}
}

0 comments on commit 064f163

Please sign in to comment.