Skip to content

Commit

Permalink
AccountsIndex::get_cloned() *must* add entry to in-mem cache (solana-…
Browse files Browse the repository at this point in the history
  • Loading branch information
brooksprumo authored Feb 26, 2024
1 parent 8143fc3 commit bf2e8ee
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions accounts-db/src/accounts_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down

0 comments on commit bf2e8ee

Please sign in to comment.