Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not overwrite builtin program in the same slot #31718

Merged
merged 2 commits into from
May 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
15 changes: 12 additions & 3 deletions 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 Expand Up @@ -6290,7 +6293,7 @@ fn test_transaction_with_program_ids_passed_to_programs() {
fn test_account_ids_after_program_ids() {
solana_logger::setup();
let (genesis_config, mint_keypair) = create_genesis_config(500);
let mut bank = Bank::new_for_tests(&genesis_config);
let bank = Bank::new_for_tests(&genesis_config);

let from_pubkey = solana_sdk::pubkey::new_rand();
let to_pubkey = solana_sdk::pubkey::new_rand();
Expand All @@ -6310,6 +6313,9 @@ fn test_account_ids_after_program_ids() {

tx.message.account_keys.push(solana_sdk::pubkey::new_rand());

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

bank.add_mockup_builtin(solana_vote_program::id(), process_instruction);
let result = bank.process_transaction(&tx);
assert_eq!(result, Ok(()));
Expand Down Expand Up @@ -6455,7 +6461,7 @@ fn test_program_id_as_payer() {
#[test]
fn test_ref_account_key_after_program_id() {
let (genesis_config, mint_keypair) = create_genesis_config(500);
let mut bank = Bank::new_for_tests(&genesis_config);
let bank = Bank::new_for_tests(&genesis_config);

let from_pubkey = solana_sdk::pubkey::new_rand();
let to_pubkey = solana_sdk::pubkey::new_rand();
Expand All @@ -6465,6 +6471,9 @@ fn test_ref_account_key_after_program_id() {
AccountMeta::new(to_pubkey, false),
];

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

bank.add_mockup_builtin(solana_vote_program::id(), process_instruction);

let instruction = Instruction::new_with_bincode(solana_vote_program::id(), &10, account_metas);
Expand Down