Demote write locks on transaction program ids (#19593)
* Add feature * Demote write lock on program ids * Fixup bpf tests * Update MappedMessage::is_writable * Comma nit * Review comments
This commit is contained in:
@@ -1796,7 +1796,7 @@ fn test_program_bpf_upgrade_and_invoke_in_same_tx() {
|
||||
"solana_bpf_rust_panic",
|
||||
);
|
||||
|
||||
// Invoke, then upgrade the program, and then invoke again in same tx
|
||||
// Attempt to invoke, then upgrade the program in same tx
|
||||
let message = Message::new(
|
||||
&[
|
||||
invoke_instruction.clone(),
|
||||
@@ -1815,10 +1815,12 @@ fn test_program_bpf_upgrade_and_invoke_in_same_tx() {
|
||||
message.clone(),
|
||||
bank.last_blockhash(),
|
||||
);
|
||||
// program_id is automatically demoted to readonly, preventing the upgrade, which requires
|
||||
// writeability
|
||||
let (result, _) = process_transaction_and_record_inner(&bank, tx);
|
||||
assert_eq!(
|
||||
result.unwrap_err(),
|
||||
TransactionError::InstructionError(2, InstructionError::ProgramFailedToComplete)
|
||||
TransactionError::InstructionError(1, InstructionError::InvalidArgument)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2114,96 +2116,6 @@ fn test_program_bpf_upgrade_via_cpi() {
|
||||
assert_ne!(programdata, original_programdata);
|
||||
}
|
||||
|
||||
#[cfg(feature = "bpf_rust")]
|
||||
#[test]
|
||||
fn test_program_bpf_upgrade_self_via_cpi() {
|
||||
solana_logger::setup();
|
||||
|
||||
let GenesisConfigInfo {
|
||||
genesis_config,
|
||||
mint_keypair,
|
||||
..
|
||||
} = create_genesis_config(50);
|
||||
let mut bank = Bank::new_for_tests(&genesis_config);
|
||||
let (name, id, entrypoint) = solana_bpf_loader_program!();
|
||||
bank.add_builtin(&name, id, entrypoint);
|
||||
let (name, id, entrypoint) = solana_bpf_loader_upgradeable_program!();
|
||||
bank.add_builtin(&name, id, entrypoint);
|
||||
let bank = Arc::new(bank);
|
||||
let bank_client = BankClient::new_shared(&bank);
|
||||
let noop_program_id = load_bpf_program(
|
||||
&bank_client,
|
||||
&bpf_loader::id(),
|
||||
&mint_keypair,
|
||||
"solana_bpf_rust_noop",
|
||||
);
|
||||
|
||||
// Deploy upgradeable program
|
||||
let buffer_keypair = Keypair::new();
|
||||
let program_keypair = Keypair::new();
|
||||
let program_id = program_keypair.pubkey();
|
||||
let authority_keypair = Keypair::new();
|
||||
load_upgradeable_bpf_program(
|
||||
&bank_client,
|
||||
&mint_keypair,
|
||||
&buffer_keypair,
|
||||
&program_keypair,
|
||||
&authority_keypair,
|
||||
"solana_bpf_rust_invoke_and_return",
|
||||
);
|
||||
|
||||
let mut invoke_instruction = Instruction::new_with_bytes(
|
||||
program_id,
|
||||
&[0],
|
||||
vec![
|
||||
AccountMeta::new(noop_program_id, false),
|
||||
AccountMeta::new(noop_program_id, false),
|
||||
AccountMeta::new(clock::id(), false),
|
||||
],
|
||||
);
|
||||
|
||||
// Call the upgraded program
|
||||
invoke_instruction.data[0] += 1;
|
||||
let result =
|
||||
bank_client.send_and_confirm_instruction(&mint_keypair, invoke_instruction.clone());
|
||||
assert!(result.is_ok());
|
||||
|
||||
// Prepare for upgrade
|
||||
let buffer_keypair = Keypair::new();
|
||||
load_upgradeable_buffer(
|
||||
&bank_client,
|
||||
&mint_keypair,
|
||||
&buffer_keypair,
|
||||
&authority_keypair,
|
||||
"solana_bpf_rust_panic",
|
||||
);
|
||||
|
||||
// Invoke, then upgrade the program, and then invoke again in same tx
|
||||
let message = Message::new(
|
||||
&[
|
||||
invoke_instruction.clone(),
|
||||
bpf_loader_upgradeable::upgrade(
|
||||
&program_id,
|
||||
&buffer_keypair.pubkey(),
|
||||
&authority_keypair.pubkey(),
|
||||
&mint_keypair.pubkey(),
|
||||
),
|
||||
invoke_instruction,
|
||||
],
|
||||
Some(&mint_keypair.pubkey()),
|
||||
);
|
||||
let tx = Transaction::new(
|
||||
&[&mint_keypair, &authority_keypair],
|
||||
message.clone(),
|
||||
bank.last_blockhash(),
|
||||
);
|
||||
let (result, _) = process_transaction_and_record_inner(&bank, tx);
|
||||
assert_eq!(
|
||||
result.unwrap_err(),
|
||||
TransactionError::InstructionError(2, InstructionError::ProgramFailedToComplete)
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg(feature = "bpf_rust")]
|
||||
#[test]
|
||||
fn test_program_bpf_set_upgrade_authority_via_cpi() {
|
||||
|
@@ -21,9 +21,9 @@ use solana_sdk::{
|
||||
entrypoint::{MAX_PERMITTED_DATA_INCREASE, SUCCESS},
|
||||
epoch_schedule::EpochSchedule,
|
||||
feature_set::{
|
||||
blake3_syscall_enabled, close_upgradeable_program_accounts, disable_fees_sysvar,
|
||||
enforce_aligned_host_addrs, libsecp256k1_0_5_upgrade_enabled, mem_overlap_fix,
|
||||
secp256k1_recover_syscall_enabled,
|
||||
blake3_syscall_enabled, close_upgradeable_program_accounts, demote_program_write_locks,
|
||||
disable_fees_sysvar, enforce_aligned_host_addrs, libsecp256k1_0_5_upgrade_enabled,
|
||||
mem_overlap_fix, secp256k1_recover_syscall_enabled,
|
||||
},
|
||||
hash::{Hasher, HASH_BYTES},
|
||||
ic_msg,
|
||||
@@ -2293,7 +2293,14 @@ fn call<'a>(
|
||||
signers_seeds_len: u64,
|
||||
memory_mapping: &MemoryMapping,
|
||||
) -> Result<u64, EbpfError<BpfError>> {
|
||||
let (message, executables, accounts, account_refs, caller_write_privileges) = {
|
||||
let (
|
||||
message,
|
||||
executables,
|
||||
accounts,
|
||||
account_refs,
|
||||
caller_write_privileges,
|
||||
demote_program_write_locks,
|
||||
) = {
|
||||
let invoke_context = syscall.get_context()?;
|
||||
|
||||
invoke_context
|
||||
@@ -2388,6 +2395,7 @@ fn call<'a>(
|
||||
accounts,
|
||||
account_refs,
|
||||
caller_write_privileges,
|
||||
invoke_context.is_feature_active(&demote_program_write_locks::id()),
|
||||
)
|
||||
};
|
||||
|
||||
@@ -2413,7 +2421,7 @@ fn call<'a>(
|
||||
for (i, ((_key, account), account_ref)) in accounts.iter().zip(account_refs).enumerate() {
|
||||
let account = account.borrow();
|
||||
if let Some(mut account_ref) = account_ref {
|
||||
if message.is_writable(i) && !account.executable() {
|
||||
if message.is_writable(i, demote_program_write_locks) && !account.executable() {
|
||||
*account_ref.lamports = account.lamports();
|
||||
*account_ref.owner = *account.owner();
|
||||
if account_ref.data.len() != account.data().len() {
|
||||
|
Reference in New Issue
Block a user