From 316d57d5a8711f3600ba9682c7750265a80ad133 Mon Sep 17 00:00:00 2001 From: Pankaj Garg Date: Thu, 4 May 2023 12:13:55 -0700 Subject: [PATCH] Allow replacing tombstone with a non-tombstone --- program-runtime/src/loaded_programs.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/program-runtime/src/loaded_programs.rs b/program-runtime/src/loaded_programs.rs index a286a1f219e753..1b32d6dbceb606 100644 --- a/program-runtime/src/loaded_programs.rs +++ b/program-runtime/src/loaded_programs.rs @@ -328,6 +328,10 @@ impl LoadedPrograms { Ordering::Relaxed, ); second_level.swap_remove(entry_index); + } else if existing.is_tombstone() && !entry.is_tombstone() { + // The old entry is tombstone and the new one is not. Let's give the new entry + // a chance. + second_level.swap_remove(entry_index); } else { return (true, existing.clone()); } @@ -809,6 +813,23 @@ mod tests { }); } + #[test] + fn test_replace_tombstones() { + let mut cache = LoadedPrograms::default(); + let program1 = Pubkey::new_unique(); + set_tombstone( + &mut cache, + program1, + 10, + LoadedProgramType::FailedVerification, + ); + + let loaded_program = new_test_loaded_program(10, 10); + let (existing, program) = cache.replenish(program1, loaded_program.clone()); + assert!(!existing); + assert_eq!(program, loaded_program); + } + #[test] fn test_tombstone() { let tombstone = LoadedProgram::new_tombstone(0, LoadedProgramType::FailedVerification);