Upgradeable programs called same as non-upgradeable (#14239)
* Upgradeable programs called same as non-upgradeable * nudge
This commit is contained in:
@@ -2,8 +2,8 @@
|
||||
//! uses the instruction data provided and all the accounts
|
||||
|
||||
use solana_program::{
|
||||
account_info::AccountInfo, bpf_loader_upgradeable, entrypoint, entrypoint::ProgramResult,
|
||||
instruction::AccountMeta, instruction::Instruction, program::invoke, pubkey::Pubkey,
|
||||
account_info::AccountInfo, entrypoint, entrypoint::ProgramResult, instruction::AccountMeta,
|
||||
instruction::Instruction, program::invoke, pubkey::Pubkey,
|
||||
};
|
||||
|
||||
entrypoint!(process_instruction);
|
||||
@@ -15,13 +15,8 @@ fn process_instruction(
|
||||
) -> ProgramResult {
|
||||
let to_call = accounts[0].key;
|
||||
let infos = accounts;
|
||||
let last = if bpf_loader_upgradeable::check_id(accounts[0].owner) {
|
||||
accounts.len() - 1
|
||||
} else {
|
||||
accounts.len()
|
||||
};
|
||||
let instruction = Instruction {
|
||||
accounts: accounts[1..last]
|
||||
accounts: accounts[1..]
|
||||
.iter()
|
||||
.map(|acc| AccountMeta {
|
||||
pubkey: *acc.key,
|
||||
|
@@ -21,9 +21,7 @@ use solana_runtime::{
|
||||
};
|
||||
use solana_sdk::{
|
||||
account::Account,
|
||||
account_utils::StateMut,
|
||||
bpf_loader, bpf_loader_deprecated,
|
||||
bpf_loader_upgradeable::UpgradeableLoaderState,
|
||||
client::SyncClient,
|
||||
clock::{DEFAULT_SLOTS_PER_EPOCH, MAX_PROCESSING_AGE},
|
||||
entrypoint::{MAX_PERMITTED_DATA_INCREASE, SUCCESS},
|
||||
@@ -1479,11 +1477,11 @@ fn test_program_bpf_upgrade() {
|
||||
bank.add_builtin(&name, id, entrypoint);
|
||||
let bank_client = BankClient::new(bank);
|
||||
|
||||
// deploy upgrade program
|
||||
// Deploy upgrade program
|
||||
let (program_id, authority_keypair) =
|
||||
load_upgradeable_bpf_program(&bank_client, &mint_keypair, "solana_bpf_rust_upgradeable");
|
||||
|
||||
// call upgrade program
|
||||
// Call upgrade program
|
||||
nonce += 1;
|
||||
let instruction = Instruction::new(
|
||||
program_id,
|
||||
@@ -1499,7 +1497,7 @@ fn test_program_bpf_upgrade() {
|
||||
TransactionError::InstructionError(0, InstructionError::Custom(42))
|
||||
);
|
||||
|
||||
// upgrade program
|
||||
// Upgrade program
|
||||
upgrade_bpf_program(
|
||||
&bank_client,
|
||||
&mint_keypair,
|
||||
@@ -1508,7 +1506,7 @@ fn test_program_bpf_upgrade() {
|
||||
"solana_bpf_rust_upgraded",
|
||||
);
|
||||
|
||||
// call upgraded program
|
||||
// Call upgraded program
|
||||
nonce += 1;
|
||||
let instruction = Instruction::new(
|
||||
program_id,
|
||||
@@ -1524,7 +1522,7 @@ fn test_program_bpf_upgrade() {
|
||||
TransactionError::InstructionError(0, InstructionError::Custom(43))
|
||||
);
|
||||
|
||||
// upgrade back to the original program
|
||||
// Set a new authority
|
||||
let new_authority_keypair = Keypair::new();
|
||||
set_upgrade_authority(
|
||||
&bank_client,
|
||||
@@ -1534,7 +1532,7 @@ fn test_program_bpf_upgrade() {
|
||||
Some(&new_authority_keypair.pubkey()),
|
||||
);
|
||||
|
||||
// upgrade back to the original program
|
||||
// Upgrade back to the original program
|
||||
upgrade_bpf_program(
|
||||
&bank_client,
|
||||
&mint_keypair,
|
||||
@@ -1543,7 +1541,7 @@ fn test_program_bpf_upgrade() {
|
||||
"solana_bpf_rust_upgradeable",
|
||||
);
|
||||
|
||||
// call original program
|
||||
// Call original program
|
||||
nonce += 1;
|
||||
let instruction = Instruction::new(
|
||||
program_id,
|
||||
@@ -1562,9 +1560,10 @@ fn test_program_bpf_upgrade() {
|
||||
|
||||
#[cfg(feature = "bpf_rust")]
|
||||
#[test]
|
||||
fn test_program_bpf_invoke_upgradeable() {
|
||||
fn test_program_bpf_invoke_upgradeable_via_cpi() {
|
||||
solana_logger::setup();
|
||||
|
||||
let mut nonce = 0;
|
||||
let GenesisConfigInfo {
|
||||
genesis_config,
|
||||
mint_keypair,
|
||||
@@ -1583,29 +1582,81 @@ fn test_program_bpf_invoke_upgradeable() {
|
||||
"solana_bpf_rust_invoke_and_return",
|
||||
);
|
||||
|
||||
// deploy upgrade program
|
||||
let (program_id, _) =
|
||||
// Deploy upgrade program
|
||||
let (program_id, authority_keypair) =
|
||||
load_upgradeable_bpf_program(&bank_client, &mint_keypair, "solana_bpf_rust_upgradeable");
|
||||
|
||||
let data = bank_client.get_account(&program_id).unwrap().unwrap();
|
||||
let programdata_address = if let UpgradeableLoaderState::Program {
|
||||
programdata_address,
|
||||
} = data.state().unwrap()
|
||||
{
|
||||
programdata_address
|
||||
} else {
|
||||
panic!("Not a program");
|
||||
};
|
||||
|
||||
// call invoker program to invoke the upgradeable program
|
||||
// Call invoker program to invoke the upgradeable program
|
||||
nonce += 1;
|
||||
let instruction = Instruction::new(
|
||||
invoke_and_return,
|
||||
&[0],
|
||||
&[nonce],
|
||||
vec![
|
||||
AccountMeta::new(program_id, false),
|
||||
AccountMeta::new(clock::id(), false),
|
||||
AccountMeta::new(fees::id(), false),
|
||||
],
|
||||
);
|
||||
let result = bank_client.send_and_confirm_instruction(&mint_keypair, instruction);
|
||||
assert_eq!(
|
||||
result.unwrap_err().unwrap(),
|
||||
TransactionError::InstructionError(0, InstructionError::Custom(42))
|
||||
);
|
||||
|
||||
// Upgrade program
|
||||
upgrade_bpf_program(
|
||||
&bank_client,
|
||||
&mint_keypair,
|
||||
&program_id,
|
||||
&authority_keypair,
|
||||
"solana_bpf_rust_upgraded",
|
||||
);
|
||||
|
||||
// Call the upgraded program
|
||||
nonce += 1;
|
||||
let instruction = Instruction::new(
|
||||
invoke_and_return,
|
||||
&[nonce],
|
||||
vec![
|
||||
AccountMeta::new(program_id, false),
|
||||
AccountMeta::new(clock::id(), false),
|
||||
AccountMeta::new(fees::id(), false),
|
||||
],
|
||||
);
|
||||
let result = bank_client.send_and_confirm_instruction(&mint_keypair, instruction);
|
||||
assert_eq!(
|
||||
result.unwrap_err().unwrap(),
|
||||
TransactionError::InstructionError(0, InstructionError::Custom(43))
|
||||
);
|
||||
|
||||
// Set a new authority
|
||||
let new_authority_keypair = Keypair::new();
|
||||
set_upgrade_authority(
|
||||
&bank_client,
|
||||
&mint_keypair,
|
||||
&program_id,
|
||||
&authority_keypair,
|
||||
Some(&new_authority_keypair.pubkey()),
|
||||
);
|
||||
|
||||
// Upgrade back to the original program
|
||||
upgrade_bpf_program(
|
||||
&bank_client,
|
||||
&mint_keypair,
|
||||
&program_id,
|
||||
&new_authority_keypair,
|
||||
"solana_bpf_rust_upgradeable",
|
||||
);
|
||||
|
||||
// Call original program
|
||||
nonce += 1;
|
||||
let instruction = Instruction::new(
|
||||
invoke_and_return,
|
||||
&[nonce],
|
||||
vec![
|
||||
AccountMeta::new(program_id, false),
|
||||
AccountMeta::new(clock::id(), false),
|
||||
AccountMeta::new(fees::id(), false),
|
||||
AccountMeta::new(programdata_address, false),
|
||||
],
|
||||
);
|
||||
let result = bank_client.send_and_confirm_instruction(&mint_keypair, instruction);
|
||||
|
@@ -993,6 +993,7 @@ mod tests {
|
||||
Rent::default(),
|
||||
vec![],
|
||||
&[],
|
||||
&[],
|
||||
None,
|
||||
BpfComputeBudget {
|
||||
max_units: 1,
|
||||
|
@@ -1389,18 +1389,19 @@ fn call<'a>(
|
||||
.ok_or(SyscallError::InstructionError(
|
||||
InstructionError::MissingAccount,
|
||||
))?;
|
||||
if !program_account.executable {
|
||||
if !program_account.borrow().executable {
|
||||
return Err(SyscallError::InstructionError(InstructionError::AccountNotExecutable).into());
|
||||
}
|
||||
let programdata_executable = if program_account.owner == bpf_loader_upgradeable::id() {
|
||||
let programdata_executable = if program_account.borrow().owner == bpf_loader_upgradeable::id() {
|
||||
if let UpgradeableLoaderState::Program {
|
||||
programdata_address,
|
||||
} = program_account
|
||||
.borrow()
|
||||
.state()
|
||||
.map_err(SyscallError::InstructionError)?
|
||||
{
|
||||
if let Some(account) = invoke_context.get_account(&programdata_address) {
|
||||
Some((programdata_address, RefCell::new(account)))
|
||||
Some((programdata_address, account))
|
||||
} else {
|
||||
return Err(
|
||||
SyscallError::InstructionError(InstructionError::MissingAccount).into(),
|
||||
@@ -1412,7 +1413,7 @@ fn call<'a>(
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let mut executable_accounts = vec![(callee_program_id, RefCell::new(program_account))];
|
||||
let mut executable_accounts = vec![(callee_program_id, program_account)];
|
||||
if let Some(programdata) = programdata_executable {
|
||||
executable_accounts.push(programdata);
|
||||
}
|
||||
|
Reference in New Issue
Block a user