AcctIdx: consolidate lock_and_update_slot_list (#20090)

This commit is contained in:
Jeff Washington (jwash)
2021-09-22 13:40:19 -05:00
committed by GitHub
parent 4fb77183ef
commit 0eb0d7f73b
2 changed files with 22 additions and 29 deletions

View File

@@ -283,22 +283,6 @@ impl<T: IndexValue> WriteAccountMapEntry<T> {
AccountMapEntryMeta::new_dirty(storage),
))
}
// Try to update an item in the slot list the given `slot` If an item for the slot
// already exists in the list, remove the older item, add it to `reclaims`, and insert
// the new item.
pub fn update(&mut self, slot: Slot, account_info: T, reclaims: &mut SlotList<T>) {
let mut addref = !account_info.is_cached();
self.slot_list_mut(|list| {
addref =
InMemAccountsIndex::update_slot_list(list, slot, account_info, reclaims, false);
});
if addref {
// If it's the first non-cache insert, also bump the stored ref count
self.borrow_owned_entry().add_un_ref(true);
}
self.borrow_owned_entry().set_dirty(true);
}
}
#[derive(Debug, Default, AbiExample, Clone)]
@@ -1578,9 +1562,15 @@ impl<T: IndexValue> AccountsIndex<T> {
items.into_iter().for_each(|(pubkey, new_item)| {
let already_exists =
w_account_maps.insert_new_entry_if_missing_with_lock(pubkey, new_item);
if let Some((mut w_account_entry, account_info, pubkey)) = already_exists {
if let Some((account_entry, account_info, pubkey)) = already_exists {
let is_zero_lamport = account_info.is_zero_lamport();
w_account_entry.update(slot, account_info, &mut _reclaims);
InMemAccountsIndex::lock_and_update_slot_list(
&account_entry,
(slot, account_info),
&mut _reclaims,
false,
);
if !is_zero_lamport {
// zero lamports were already added to dirty_pubkeys above
dirty_pubkeys.push(pubkey);