Skip to content

Commit

Permalink
Allow replacing tombstone with a non-tombstone (#31494)
Browse files Browse the repository at this point in the history
  • Loading branch information
pgarg66 authored May 4, 2023
1 parent 555520b commit de43ac4
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions program-runtime/src/loaded_programs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit de43ac4

Please sign in to comment.