(cherry picked from commit 622a6fba7f
)
Co-authored-by: Jack May <jack@solana.com>
This commit is contained in:
@ -344,6 +344,8 @@ fn process_loader_upgradeable_instruction(
|
|||||||
return Err(InstructionError::ExecutableAccountNotRentExempt);
|
return Err(InstructionError::ExecutableAccountNotRentExempt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let new_program_id = *program.unsigned_key();
|
||||||
|
|
||||||
// Verify Buffer account
|
// Verify Buffer account
|
||||||
|
|
||||||
if let UpgradeableLoaderState::Buffer { authority_address } = buffer.state()? {
|
if let UpgradeableLoaderState::Buffer { authority_address } = buffer.state()? {
|
||||||
@ -383,7 +385,7 @@ fn process_loader_upgradeable_instruction(
|
|||||||
// Create ProgramData account
|
// Create ProgramData account
|
||||||
|
|
||||||
let (derived_address, bump_seed) =
|
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() {
|
if derived_address != *programdata.unsigned_key() {
|
||||||
ic_logger_msg!(logger, "ProgramData address is not derived");
|
ic_logger_msg!(logger, "ProgramData address is not derived");
|
||||||
return Err(InstructionError::InvalidArgument);
|
return Err(InstructionError::InvalidArgument);
|
||||||
@ -397,7 +399,7 @@ fn process_loader_upgradeable_instruction(
|
|||||||
program_id,
|
program_id,
|
||||||
);
|
);
|
||||||
let caller_program_id = invoke_context.get_caller()?;
|
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()
|
.iter()
|
||||||
.map(|seeds| Pubkey::create_program_address(*seeds, caller_program_id))
|
.map(|seeds| Pubkey::create_program_address(*seeds, caller_program_id))
|
||||||
.collect::<Result<Vec<Pubkey>, solana_sdk::pubkey::PubkeyError>>()?;
|
.collect::<Result<Vec<Pubkey>, solana_sdk::pubkey::PubkeyError>>()?;
|
||||||
@ -410,7 +412,7 @@ fn process_loader_upgradeable_instruction(
|
|||||||
|
|
||||||
// Load and verify the program bits
|
// Load and verify the program bits
|
||||||
let executor = create_executor(3, buffer_data_offset, invoke_context, use_jit)?;
|
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 keyed_accounts = invoke_context.get_keyed_accounts()?;
|
||||||
let payer = keyed_account_at_index(keyed_accounts, 0)?;
|
let payer = keyed_account_at_index(keyed_accounts, 0)?;
|
||||||
@ -439,7 +441,7 @@ fn process_loader_upgradeable_instruction(
|
|||||||
.checked_add_lamports(buffer.lamports()?)?;
|
.checked_add_lamports(buffer.lamports()?)?;
|
||||||
buffer.try_account_ref_mut()?.set_lamports(0);
|
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 => {
|
UpgradeableLoaderInstruction::Upgrade => {
|
||||||
let programdata = keyed_account_at_index(keyed_accounts, 0)?;
|
let programdata = keyed_account_at_index(keyed_accounts, 0)?;
|
||||||
@ -476,6 +478,8 @@ fn process_loader_upgradeable_instruction(
|
|||||||
return Err(InstructionError::InvalidAccountData);
|
return Err(InstructionError::InvalidAccountData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let new_program_id = *program.unsigned_key();
|
||||||
|
|
||||||
// Verify Buffer account
|
// Verify Buffer account
|
||||||
|
|
||||||
if let UpgradeableLoaderState::Buffer { authority_address } = buffer.state()? {
|
if let UpgradeableLoaderState::Buffer { authority_address } = buffer.state()? {
|
||||||
@ -538,10 +542,9 @@ fn process_loader_upgradeable_instruction(
|
|||||||
|
|
||||||
// Load and verify the program bits
|
// Load and verify the program bits
|
||||||
let executor = create_executor(2, buffer_data_offset, invoke_context, use_jit)?;
|
let executor = create_executor(2, buffer_data_offset, invoke_context, use_jit)?;
|
||||||
let keyed_accounts = invoke_context.get_keyed_accounts()?;
|
invoke_context.add_executor(&new_program_id, executor);
|
||||||
let program = keyed_account_at_index(keyed_accounts, 1)?;
|
|
||||||
invoke_context.add_executor(program.unsigned_key(), executor);
|
|
||||||
|
|
||||||
|
let keyed_accounts = invoke_context.get_keyed_accounts()?;
|
||||||
let programdata = keyed_account_at_index(keyed_accounts, 0)?;
|
let programdata = keyed_account_at_index(keyed_accounts, 0)?;
|
||||||
let buffer = keyed_account_at_index(keyed_accounts, 2)?;
|
let buffer = keyed_account_at_index(keyed_accounts, 2)?;
|
||||||
let spill = keyed_account_at_index(keyed_accounts, 3)?;
|
let spill = keyed_account_at_index(keyed_accounts, 3)?;
|
||||||
@ -571,7 +574,7 @@ fn process_loader_upgradeable_instruction(
|
|||||||
.try_account_ref_mut()?
|
.try_account_ref_mut()?
|
||||||
.set_lamports(programdata_balance_required);
|
.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 => {
|
UpgradeableLoaderInstruction::SetAuthority => {
|
||||||
let account = keyed_account_at_index(keyed_accounts, 0)?;
|
let account = keyed_account_at_index(keyed_accounts, 0)?;
|
||||||
|
Reference in New Issue
Block a user