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?