AccountsIndex::get_cloned() *must* add entry to in-mem cache (#35322)

This commit is contained in:
Brooks 2024-02-26 18:20:21 -05:00 committed by GitHub
parent 8143fc3f4a
commit bf2e8ee32f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 4 additions and 2 deletions

View File

@ -1158,9 +1158,11 @@ impl<T: IndexValue, U: DiskIndexValue + From<T> + Into<T>> AccountsIndex<T, U> {
/// Gets the index's entry for `pubkey` and clones it
///
/// Prefer `get_and_then()` whenever possible.
/// NOTE: The entry is *not* added to the in-mem cache.
pub fn get_cloned(&self, pubkey: &Pubkey) -> Option<AccountMapEntry<T>> {
self.get_and_then(pubkey, |entry| (false, entry.cloned()))
// We *must* add the index entry to the in-mem cache!
// If the index entry is only on-disk, returning a clone would allow the entry
// to be modified, but those modifications would be lost on drop!
self.get_and_then(pubkey, |entry| (true, entry.cloned()))
}
/// Is `pubkey` in the index?