just use slot to determine alive while shrinking (#29613)

This commit is contained in:
Jeff Washington (jwash) 2023-01-10 11:00:18 -06:00 committed by GitHub
parent 1c862f0b66
commit a5106e110a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 34 deletions

View File

@ -144,13 +144,6 @@ impl AccountInfo {
self.stored_size_mask & !ALL_FLAGS
}
/// true iff store_id and offset match self AND self is not cached
/// If self is cached, then store_id and offset are meaningless.
pub fn matches_storage_location(&self, store_id: AppendVecId, offset: Offset) -> bool {
// order is set for best short circuit
self.store_id == store_id && self.offset() == offset && !self.is_cached()
}
pub fn storage_location(&self) -> StorageLocation {
if self.is_cached() {
StorageLocation::Cached
@ -182,26 +175,4 @@ mod test {
let offset = 1; // not aligned
AccountInfo::new(StorageLocation::AppendVec(0, offset), 0, 0);
}
#[test]
fn test_matches_storage_location() {
let offset = 0;
let id = 0;
let info = AccountInfo::new(StorageLocation::AppendVec(id, offset), 0, 0);
assert!(info.matches_storage_location(id, offset));
// wrong offset
let offset = ALIGN_BOUNDARY_OFFSET;
assert!(!info.matches_storage_location(id, offset));
// wrong id
let offset = 0;
let id = 1;
assert!(!info.matches_storage_location(id, offset));
// is cached
let id = CACHE_VIRTUAL_STORAGE_ID;
let info = AccountInfo::new(StorageLocation::Cached, 0, 0);
assert!(!info.matches_storage_location(id, offset));
}
}

View File

@ -3628,12 +3628,9 @@ impl AccountsDb {
let mut result = AccountsIndexScanResult::None;
if let Some((slot_list, _ref_count)) = slots_refs {
let stored_account = &accounts[index];
let is_alive = slot_list.iter().any(|(slot, acct_info)| {
let is_alive = slot_list.iter().any(|(slot, _acct_info)| {
// if the accounts index contains an entry at this slot, then the append vec we're asking about contains this item and thus, it is alive at this slot
*slot == slot_to_shrink
&& acct_info.matches_storage_location(
acct_info.store_id(),
stored_account.account.offset,
)
});
if !is_alive {
// This pubkey was found in the storage, but no longer exists in the index.