From 7158178063ba5f57f822df566a90277e1db480b7 Mon Sep 17 00:00:00 2001 From: brooks Date: Mon, 26 Feb 2024 16:42:13 -0500 Subject: [PATCH] AccountsIndex::get_cloned() *must* add entry to in-mem cache --- 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 3ddbb8e535e2fb..5ac5d9a7a14908 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?