Skip to content

Commit

Permalink
Do not overwrite builtin program in the same slot
Browse files Browse the repository at this point in the history
  • Loading branch information
pgarg66 committed May 18, 2023
1 parent a0850a7 commit c13b1cb
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
5 changes: 1 addition & 4 deletions program-runtime/src/loaded_programs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,10 +427,7 @@ impl LoadedPrograms {
if existing.deployment_slot == entry.deployment_slot
&& existing.effective_slot == entry.effective_slot
{
if matches!(existing.program, LoadedProgramType::Builtin(_)) {
// Allow built-ins to be overwritten
second_level.swap_remove(entry_index);
} else if matches!(existing.program, LoadedProgramType::Unloaded) {
if matches!(existing.program, LoadedProgramType::Unloaded) {
// The unloaded program is getting reloaded
// Copy over the usage counter to the new entry
entry.usage_counter.store(
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7315,7 +7315,7 @@ impl Bank {
self.add_builtin(
program_id,
"mockup".to_string(),
LoadedProgram::new_builtin(0, 0, entrypoint),
LoadedProgram::new_builtin(self.slot, 0, entrypoint),
);
}

Expand Down
5 changes: 4 additions & 1 deletion runtime/src/bank/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4857,7 +4857,7 @@ fn test_add_duplicate_static_program() {
mint_keypair,
..
} = create_genesis_config_with_leader(500, &solana_sdk::pubkey::new_rand(), 0);
let mut bank = Bank::new_for_tests(&genesis_config);
let bank = Bank::new_for_tests(&genesis_config);

declare_process_instruction!(process_instruction, 1, |_invoke_context| {
Err(InstructionError::Custom(42))
Expand Down Expand Up @@ -4886,6 +4886,9 @@ fn test_add_duplicate_static_program() {
bank.last_blockhash(),
);

let slot = bank.slot().saturating_add(1);
let mut bank = Bank::new_from_parent(&Arc::new(bank), &Pubkey::default(), slot);

let vote_loader_account = bank.get_account(&solana_vote_program::id()).unwrap();
bank.add_mockup_builtin(solana_vote_program::id(), process_instruction);
let new_vote_loader_account = bank.get_account(&solana_vote_program::id()).unwrap();
Expand Down

0 comments on commit c13b1cb

Please sign in to comment.