Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

Add executor using the program's id during deploy #19555

Merged
merged 1 commit into from
Sep 2, 2021
Merged
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
19 changes: 11 additions & 8 deletions programs/bpf_loader/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,8 @@ fn process_loader_upgradeable_instruction(
return Err(InstructionError::ExecutableAccountNotRentExempt);
}

let new_program_id = *program.unsigned_key();

// Verify Buffer account

if let UpgradeableLoaderState::Buffer { authority_address } = buffer.state()? {
Expand Down Expand Up @@ -382,7 +384,7 @@ fn process_loader_upgradeable_instruction(
// Create ProgramData account

let (derived_address, bump_seed) =
Pubkey::find_program_address(&[program.unsigned_key().as_ref()], program_id);
Pubkey::find_program_address(&[new_program_id.as_ref()], program_id);
if derived_address != *programdata.unsigned_key() {
ic_logger_msg!(logger, "ProgramData address is not derived");
return Err(InstructionError::InvalidArgument);
Expand All @@ -396,7 +398,7 @@ fn process_loader_upgradeable_instruction(
program_id,
);
let caller_program_id = invoke_context.get_caller()?;
let signers = [&[program.unsigned_key().as_ref(), &[bump_seed]]]
let signers = [&[new_program_id.as_ref(), &[bump_seed]]]
.iter()
.map(|seeds| Pubkey::create_program_address(*seeds, caller_program_id))
.collect::<Result<Vec<Pubkey>, solana_sdk::pubkey::PubkeyError>>()?;
Expand All @@ -409,7 +411,7 @@ fn process_loader_upgradeable_instruction(

// Load and verify the program bits
let executor = create_executor(3, buffer_data_offset, invoke_context, use_jit)?;
invoke_context.add_executor(program_id, executor);
invoke_context.add_executor(&new_program_id, executor);

let keyed_accounts = invoke_context.get_keyed_accounts()?;
let payer = keyed_account_at_index(keyed_accounts, 0)?;
Expand Down Expand Up @@ -438,7 +440,7 @@ fn process_loader_upgradeable_instruction(
.checked_add_lamports(buffer.lamports()?)?;
buffer.try_account_ref_mut()?.set_lamports(0);

ic_logger_msg!(logger, "Deployed program {:?}", program.unsigned_key());
ic_logger_msg!(logger, "Deployed program {:?}", new_program_id);
}
UpgradeableLoaderInstruction::Upgrade => {
let programdata = keyed_account_at_index(keyed_accounts, 0)?;
Expand Down Expand Up @@ -475,6 +477,8 @@ fn process_loader_upgradeable_instruction(
return Err(InstructionError::InvalidAccountData);
}

let new_program_id = *program.unsigned_key();

// Verify Buffer account

if let UpgradeableLoaderState::Buffer { authority_address } = buffer.state()? {
Expand Down Expand Up @@ -537,10 +541,9 @@ fn process_loader_upgradeable_instruction(

// Load and verify the program bits
let executor = create_executor(2, buffer_data_offset, invoke_context, use_jit)?;
let keyed_accounts = invoke_context.get_keyed_accounts()?;
let program = keyed_account_at_index(keyed_accounts, 1)?;
invoke_context.add_executor(program.unsigned_key(), executor);
invoke_context.add_executor(&new_program_id, executor);

let keyed_accounts = invoke_context.get_keyed_accounts()?;
let programdata = keyed_account_at_index(keyed_accounts, 0)?;
let buffer = keyed_account_at_index(keyed_accounts, 2)?;
let spill = keyed_account_at_index(keyed_accounts, 3)?;
Expand Down Expand Up @@ -570,7 +573,7 @@ fn process_loader_upgradeable_instruction(
.try_account_ref_mut()?
.set_lamports(programdata_balance_required);

ic_logger_msg!(logger, "Upgraded program {:?}", program.unsigned_key());
ic_logger_msg!(logger, "Upgraded program {:?}", new_program_id);
}
UpgradeableLoaderInstruction::SetAuthority => {
let account = keyed_account_at_index(keyed_accounts, 0)?;
Expand Down