From bf2e8ee32f2280692f94f1f21d6fe2cb82700852 Mon Sep 17 00:00:00 2001 From: Brooks Date: Mon, 26 Feb 2024 18:20:21 -0500 Subject: [PATCH] AccountsIndex::get_cloned() *must* add entry to in-mem cache (#35322) --- accounts-db/src/accounts_index.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/accounts-db/src/accounts_index.rs b/accounts-db/src/accounts_index.rs index 3ddbb8e53..5ac5d9a7a 100644 --- a/accounts-db/src/accounts_index.rs +++ b/accounts-db/src/accounts_index.rs @@ -1158,9 +1158,11 @@ impl + Into> AccountsIndex { /// 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> { - 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?