From 356b46fb7255a57966b3d55665d05971a317022f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Mei=C3=9Fner?= Date: Tue, 27 Aug 2024 14:04:03 +0200 Subject: [PATCH 1/6] Rekeys feature. --- .../src/bank/builtins/core_bpf_migration/target_builtin.rs | 5 +---- runtime/src/bank/builtins/mod.rs | 2 +- sdk/feature-set/src/lib.rs | 6 +++--- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/runtime/src/bank/builtins/core_bpf_migration/target_builtin.rs b/runtime/src/bank/builtins/core_bpf_migration/target_builtin.rs index ad565909ccee7b..7b7d62f91b2c94 100644 --- a/runtime/src/bank/builtins/core_bpf_migration/target_builtin.rs +++ b/runtime/src/bank/builtins/core_bpf_migration/target_builtin.rs @@ -113,10 +113,7 @@ mod tests { #[test_case(solana_stake_program::id(), None)] #[test_case(solana_system_program::id(), None)] #[test_case(solana_vote_program::id(), None)] - #[test_case( - solana_sdk::loader_v4::id(), - Some(feature_set::enable_program_runtime_v2_and_loader_v4::id()) - )] + #[test_case(solana_sdk::loader_v4::id(), Some(feature_set::enable_loader_v4::id()))] #[test_case( solana_zk_token_sdk::zk_token_proof_program::id(), Some(feature_set::zk_token_sdk_enabled::id()) diff --git a/runtime/src/bank/builtins/mod.rs b/runtime/src/bank/builtins/mod.rs index 99dfa5a0cfa836..ab82c01799d6f3 100644 --- a/runtime/src/bank/builtins/mod.rs +++ b/runtime/src/bank/builtins/mod.rs @@ -117,7 +117,7 @@ pub static BUILTINS: &[BuiltinPrototype] = &[ testable_prototype!(BuiltinPrototype { core_bpf_migration_config: None, name: loader_v4, - enable_feature_id: Some(feature_set::enable_program_runtime_v2_and_loader_v4::id()), + enable_feature_id: Some(feature_set::enable_loader_v4::id()), program_id: solana_sdk::loader_v4::id(), entrypoint: solana_loader_v4_program::Entrypoint::vm, }), diff --git a/sdk/feature-set/src/lib.rs b/sdk/feature-set/src/lib.rs index e27cabe6f3cbcd..9b7ad42c91f065 100644 --- a/sdk/feature-set/src/lib.rs +++ b/sdk/feature-set/src/lib.rs @@ -689,8 +689,8 @@ pub mod remaining_compute_units_syscall_enabled { solana_pubkey::declare_id!("5TuppMutoyzhUSfuYdhgzD47F92GL1g89KpCZQKqedxP"); } -pub mod enable_program_runtime_v2_and_loader_v4 { - solana_pubkey::declare_id!("8oBxsYqnCvUTGzgEpxPcnVf7MLbWWPYddE33PftFeBBd"); +pub mod enable_loader_v4 { + solana_pubkey::declare_id!("8Cb77yHjPWe9wuWUfXeh6iszFGCDGNCoFk3tprViYHNm"); } pub mod require_rent_exempt_split_destination { @@ -1037,7 +1037,7 @@ lazy_static! { (enable_poseidon_syscall::id(), "Enable Poseidon syscall"), (timely_vote_credits::id(), "use timeliness of votes in determining credits to award"), (remaining_compute_units_syscall_enabled::id(), "enable the remaining_compute_units syscall"), - (enable_program_runtime_v2_and_loader_v4::id(), "Enable Program-Runtime-v2 and Loader-v4 #33293"), + (enable_loader_v4::id(), "Enable Loader-v4 SIMD-0167"), (require_rent_exempt_split_destination::id(), "Require stake split destination account to be rent exempt"), (better_error_codes_for_tx_lamport_check::id(), "better error codes for tx lamport check #33353"), (enable_alt_bn128_compression_syscall::id(), "add alt_bn128 compression syscalls"), From eaa26b438d4bba42c484060d49f69fff9831b610 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Mei=C3=9Fner?= Date: Tue, 27 Aug 2024 16:54:44 +0200 Subject: [PATCH 2/6] Disables new deployments on loader-v3 when the feature enable_loader_v4 is enabled. --- programs/bpf_loader/src/lib.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/programs/bpf_loader/src/lib.rs b/programs/bpf_loader/src/lib.rs index 883f0d2548aef0..00079754d104c9 100644 --- a/programs/bpf_loader/src/lib.rs +++ b/programs/bpf_loader/src/lib.rs @@ -8,7 +8,7 @@ use { solana_compute_budget::compute_budget::MAX_INSTRUCTION_STACK_DEPTH, solana_feature_set::{ bpf_account_data_direct_mapping, enable_bpf_loader_set_authority_checked_ix, - remove_accounts_executable_flag_checks, + enable_loader_v4, remove_accounts_executable_flag_checks, }, solana_log_collector::{ic_logger_msg, ic_msg, LogCollector}, solana_measure::measure::Measure, @@ -565,6 +565,14 @@ fn process_loader_upgradeable_instruction( )?; } UpgradeableLoaderInstruction::DeployWithMaxDataLen { max_data_len } => { + if invoke_context + .get_feature_set() + .is_active(&enable_loader_v4::id()) + { + ic_logger_msg!(log_collector, "Unsupported instruction"); + return Err(InstructionError::InvalidInstructionData); + } + instruction_context.check_number_of_instruction_accounts(4)?; let payer_key = *transaction_context.get_key_of_account_at_index( instruction_context.get_index_of_instruction_account_in_transaction(0)?, @@ -1666,6 +1674,9 @@ mod tests { expected_result, Entrypoint::vm, |invoke_context| { + let mut feature_set = invoke_context.get_feature_set().clone(); + feature_set.deactivate(&enable_loader_v4::id()); + invoke_context.mock_set_feature_set(Arc::new(feature_set)); test_utils::load_all_invoked_programs(invoke_context); }, |_invoke_context| {}, From bb9d023032a4084120b49926010695c4e7efbb21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Mei=C3=9Fner?= Date: Tue, 5 Nov 2024 12:38:03 +0000 Subject: [PATCH 3/6] Removes program account check in loader-v4 execution. --- programs/loader-v4/src/lib.rs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/programs/loader-v4/src/lib.rs b/programs/loader-v4/src/lib.rs index 7f77636bcc60a5..8ceb62f8caa149 100644 --- a/programs/loader-v4/src/lib.rs +++ b/programs/loader-v4/src/lib.rs @@ -488,11 +488,6 @@ pub fn process_instruction_inner( .map_err(|err| Box::new(err) as Box) } else { let program = instruction_context.try_borrow_last_program_account(transaction_context)?; - let state = get_state(program.get_data())?; - if matches!(state.status, LoaderV4Status::Retracted) { - ic_logger_msg!(log_collector, "Program is retracted"); - return Err(Box::new(InstructionError::UnsupportedProgramId)); - } let mut get_or_create_executor_time = Measure::start("get_or_create_executor_time"); let loaded_program = invoke_context .program_cache_for_tx_batch From 6db93da164969a0edee0b2de8bf870374e5a4d57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Mei=C3=9Fner?= Date: Tue, 5 Nov 2024 13:47:45 +0000 Subject: [PATCH 4/6] Loader-v4 needs to use the same verification logic during deployment as is in loader-v3. --- programs/bpf_loader/src/lib.rs | 185 +++++++++--------- programs/loader-v4/src/lib.rs | 69 +------ .../bank/builtins/core_bpf_migration/mod.rs | 7 +- sdk/program/src/loader_v4.rs | 2 +- 4 files changed, 104 insertions(+), 159 deletions(-) diff --git a/programs/bpf_loader/src/lib.rs b/programs/bpf_loader/src/lib.rs index 00079754d104c9..60390995289a2f 100644 --- a/programs/bpf_loader/src/lib.rs +++ b/programs/bpf_loader/src/lib.rs @@ -16,7 +16,7 @@ use { invoke_context::{BpfAllocator, InvokeContext, SerializedAccountMetadata, SyscallContext}, loaded_programs::{ LoadProgramMetrics, ProgramCacheEntry, ProgramCacheEntryOwner, ProgramCacheEntryType, - DELAY_VISIBILITY_SLOT_OFFSET, + ProgramCacheForTxBatch, ProgramRuntimeEnvironment, DELAY_VISIBILITY_SLOT_OFFSET, }, mem_pool::VmMemoryPool, stable_log, @@ -103,94 +103,96 @@ pub fn load_program_from_bytes( Ok(loaded_program) } -macro_rules! deploy_program { - ($invoke_context:expr, $program_id:expr, $loader_key:expr, - $account_size:expr, $slot:expr, $drop:expr, $new_programdata:expr $(,)?) => {{ - let mut load_program_metrics = LoadProgramMetrics::default(); - let mut register_syscalls_time = Measure::start("register_syscalls_time"); - let deployment_slot: Slot = $slot; - let environments = $invoke_context.get_environments_for_slot( - deployment_slot.saturating_add(DELAY_VISIBILITY_SLOT_OFFSET) - ).map_err(|e| { - // This will never fail since the epoch schedule is already configured. - ic_msg!($invoke_context, "Failed to get runtime environment: {}", e); - InstructionError::ProgramEnvironmentSetupFailure - })?; - let deployment_program_runtime_environment = morph_into_deployment_environment_v1( - environments.program_runtime_v1.clone(), - ).map_err(|e| { - ic_msg!($invoke_context, "Failed to register syscalls: {}", e); - InstructionError::ProgramEnvironmentSetupFailure - })?; - register_syscalls_time.stop(); - load_program_metrics.register_syscalls_us = register_syscalls_time.as_us(); - // Verify using stricter deployment_program_runtime_environment - let mut load_elf_time = Measure::start("load_elf_time"); - let executable = Executable::::load( - $new_programdata, - Arc::new(deployment_program_runtime_environment), - ).map_err(|err| { - ic_logger_msg!($invoke_context.get_log_collector(), "{}", err); - InstructionError::InvalidAccountData - })?; - load_elf_time.stop(); - load_program_metrics.load_elf_us = load_elf_time.as_us(); - let mut verify_code_time = Measure::start("verify_code_time"); - executable.verify::().map_err(|err| { - ic_logger_msg!($invoke_context.get_log_collector(), "{}", err); - InstructionError::InvalidAccountData - })?; - verify_code_time.stop(); - load_program_metrics.verify_code_us = verify_code_time.as_us(); - // Reload but with environments.program_runtime_v1 - let executor = load_program_from_bytes( - $invoke_context.get_log_collector(), - &mut load_program_metrics, - $new_programdata, - $loader_key, - $account_size, - $slot, - environments.program_runtime_v1.clone(), - true, - )?; - if let Some(old_entry) = $invoke_context.program_cache_for_tx_batch.find(&$program_id) { - executor.tx_usage_counter.store( - old_entry.tx_usage_counter.load(Ordering::Relaxed), - Ordering::Relaxed - ); - executor.ix_usage_counter.store( - old_entry.ix_usage_counter.load(Ordering::Relaxed), - Ordering::Relaxed - ); - } - $drop - load_program_metrics.program_id = $program_id.to_string(); - load_program_metrics.submit_datapoint(&mut $invoke_context.timings); - $invoke_context.program_cache_for_tx_batch.store_modified_entry($program_id, Arc::new(executor)); - }}; -} - /// Directly deploy a program using a provided invoke context. /// This function should only be invoked from the runtime, since it does not /// provide any account loads or checks. -pub fn direct_deploy_program( - invoke_context: &mut InvokeContext, +pub fn deploy_program_internal( + log_collector: Option>>, + program_cache_for_tx_batch: &mut ProgramCacheForTxBatch, + program_runtime_environment: ProgramRuntimeEnvironment, program_id: &Pubkey, loader_key: &Pubkey, account_size: usize, - elf: &[u8], - slot: Slot, -) -> Result<(), InstructionError> { - deploy_program!( - invoke_context, - *program_id, + programdata: &[u8], + deployment_slot: Slot, +) -> Result { + let mut load_program_metrics = LoadProgramMetrics::default(); + let mut register_syscalls_time = Measure::start("register_syscalls_time"); + let deployment_program_runtime_environment = + morph_into_deployment_environment_v1(program_runtime_environment.clone()).map_err(|e| { + ic_logger_msg!(log_collector, "Failed to register syscalls: {}", e); + InstructionError::ProgramEnvironmentSetupFailure + })?; + register_syscalls_time.stop(); + load_program_metrics.register_syscalls_us = register_syscalls_time.as_us(); + // Verify using stricter deployment_program_runtime_environment + let mut load_elf_time = Measure::start("load_elf_time"); + let executable = Executable::::load( + programdata, + Arc::new(deployment_program_runtime_environment), + ) + .map_err(|err| { + ic_logger_msg!(log_collector, "{}", err); + InstructionError::InvalidAccountData + })?; + load_elf_time.stop(); + load_program_metrics.load_elf_us = load_elf_time.as_us(); + let mut verify_code_time = Measure::start("verify_code_time"); + executable.verify::().map_err(|err| { + ic_logger_msg!(log_collector, "{}", err); + InstructionError::InvalidAccountData + })?; + verify_code_time.stop(); + load_program_metrics.verify_code_us = verify_code_time.as_us(); + // Reload but with program_runtime_environment + let executor = load_program_from_bytes( + log_collector, + &mut load_program_metrics, + programdata, loader_key, account_size, - slot, - {}, - elf, - ); - Ok(()) + deployment_slot, + program_runtime_environment, + true, + )?; + if let Some(old_entry) = program_cache_for_tx_batch.find(&program_id) { + executor.tx_usage_counter.store( + old_entry.tx_usage_counter.load(Ordering::Relaxed), + Ordering::Relaxed, + ); + executor.ix_usage_counter.store( + old_entry.ix_usage_counter.load(Ordering::Relaxed), + Ordering::Relaxed, + ); + } + load_program_metrics.program_id = program_id.to_string(); + program_cache_for_tx_batch.store_modified_entry(*program_id, Arc::new(executor)); + Ok(load_program_metrics) +} + +#[macro_export] +macro_rules! deploy_program { + ($invoke_context:expr, $program_id:expr, $loader_key:expr, $account_size:expr, $programdata:expr, $deployment_slot:expr $(,)?) => { + let environments = $invoke_context + .get_environments_for_slot($deployment_slot.saturating_add( + solana_program_runtime::loaded_programs::DELAY_VISIBILITY_SLOT_OFFSET, + )) + .map_err(|_err| { + // This will never fail since the epoch schedule is already configured. + InstructionError::ProgramEnvironmentSetupFailure + })?; + let load_program_metrics = deploy_program_internal( + $invoke_context.get_log_collector(), + $invoke_context.program_cache_for_tx_batch, + environments.program_runtime_v1.clone(), + $program_id, + $loader_key, + $account_size, + $programdata, + $deployment_slot, + )?; + load_program_metrics.submit_datapoint(&mut $invoke_context.timings); + }; } fn write_program_data( @@ -697,17 +699,14 @@ fn process_loader_upgradeable_instruction( instruction_context.try_borrow_instruction_account(transaction_context, 3)?; deploy_program!( invoke_context, - new_program_id, + &new_program_id, &owner_id, UpgradeableLoaderState::size_of_program().saturating_add(programdata_len), - clock.slot, - { - drop(buffer); - }, buffer .get_data() .get(buffer_data_offset..) .ok_or(InstructionError::AccountDataTooSmall)?, + clock.slot, ); let transaction_context = &invoke_context.transaction_context; @@ -881,17 +880,14 @@ fn process_loader_upgradeable_instruction( instruction_context.try_borrow_instruction_account(transaction_context, 2)?; deploy_program!( invoke_context, - new_program_id, + &new_program_id, program_id, UpgradeableLoaderState::size_of_program().saturating_add(programdata_len), - clock.slot, - { - drop(buffer); - }, buffer .get_data() .get(buffer_data_offset..) .ok_or(InstructionError::AccountDataTooSmall)?, + clock.slot, ); let transaction_context = &invoke_context.transaction_context; @@ -1320,17 +1316,14 @@ fn process_loader_upgradeable_instruction( deploy_program!( invoke_context, - program_key, + &program_key, &program_id, UpgradeableLoaderState::size_of_program().saturating_add(new_len), - clock_slot, - { - drop(programdata_account); - }, programdata_account .get_data() .get(programdata_data_offset..) .ok_or(InstructionError::AccountDataTooSmall)?, + clock_slot, ); let mut programdata_account = instruction_context diff --git a/programs/loader-v4/src/lib.rs b/programs/loader-v4/src/lib.rs index 8ceb62f8caa149..9adb828f28da53 100644 --- a/programs/loader-v4/src/lib.rs +++ b/programs/loader-v4/src/lib.rs @@ -1,13 +1,10 @@ use { - solana_bpf_loader_program::execute, + solana_bpf_loader_program::{deploy_program, deploy_program_internal, execute}, solana_log_collector::{ic_logger_msg, LogCollector}, solana_measure::measure::Measure, solana_program_runtime::{ invoke_context::InvokeContext, - loaded_programs::{ - LoadProgramMetrics, ProgramCacheEntry, ProgramCacheEntryOwner, ProgramCacheEntryType, - DELAY_VISIBILITY_SLOT_OFFSET, - }, + loaded_programs::{ProgramCacheEntry, ProgramCacheEntryOwner, ProgramCacheEntryType}, }, solana_rbpf::{declare_builtin_function, memory_region::MemoryMapping}, solana_sdk::{ @@ -263,65 +260,18 @@ pub fn process_instruction_deploy( .get_data() .get(LoaderV4State::program_data_offset()..) .ok_or(InstructionError::AccountDataTooSmall)?; - - let deployment_slot = state.slot; - let effective_slot = deployment_slot.saturating_add(DELAY_VISIBILITY_SLOT_OFFSET); - - let environments = invoke_context - .get_environments_for_slot(effective_slot) - .map_err(|err| { - // This will never fail since the epoch schedule is already configured. - ic_logger_msg!(log_collector, "Failed to get runtime environment {}", err); - InstructionError::InvalidArgument - })?; - - let mut load_program_metrics = LoadProgramMetrics { - program_id: buffer.get_key().to_string(), - ..LoadProgramMetrics::default() - }; - let executor = ProgramCacheEntry::new( + deploy_program!( + invoke_context, + program.get_key(), &loader_v4::id(), - environments.program_runtime_v1.clone(), - deployment_slot, - effective_slot, - programdata, buffer.get_data().len(), - &mut load_program_metrics, - ) - .map_err(|err| { - ic_logger_msg!(log_collector, "{}", err); - InstructionError::InvalidAccountData - })?; - load_program_metrics.submit_datapoint(&mut invoke_context.timings); - if let Some(mut source_program) = source_program { - let rent = invoke_context.get_sysvar_cache().get_rent()?; - let required_lamports = rent.minimum_balance(source_program.get_data().len()); - let transfer_lamports = required_lamports.saturating_sub(program.get_lamports()); - program.set_data_from_slice(source_program.get_data())?; - source_program.set_data_length(0)?; - source_program.checked_sub_lamports(transfer_lamports)?; - program.checked_add_lamports(transfer_lamports)?; - } + programdata, + current_slot, + ); + let state = get_state_mut(program.get_data_mut()?)?; state.slot = current_slot; state.status = LoaderV4Status::Deployed; - - if let Some(old_entry) = invoke_context - .program_cache_for_tx_batch - .find(program.get_key()) - { - executor.tx_usage_counter.store( - old_entry.tx_usage_counter.load(Ordering::Relaxed), - Ordering::Relaxed, - ); - executor.ix_usage_counter.store( - old_entry.ix_usage_counter.load(Ordering::Relaxed), - Ordering::Relaxed, - ); - } - invoke_context - .program_cache_for_tx_batch - .store_modified_entry(*program.get_key(), Arc::new(executor)); Ok(()) } @@ -496,6 +446,7 @@ pub fn process_instruction_inner( ic_logger_msg!(log_collector, "Program is not cached"); InstructionError::UnsupportedProgramId })?; + println!("loaded_program {:?}", loaded_program); get_or_create_executor_time.stop(); saturating_add_assign!( invoke_context.timings.get_or_create_executor_us, diff --git a/runtime/src/bank/builtins/core_bpf_migration/mod.rs b/runtime/src/bank/builtins/core_bpf_migration/mod.rs index 023f27ec8e0794..ea6e55edd7bdb5 100644 --- a/runtime/src/bank/builtins/core_bpf_migration/mod.rs +++ b/runtime/src/bank/builtins/core_bpf_migration/mod.rs @@ -211,14 +211,15 @@ impl Bank { compute_budget, ); - solana_bpf_loader_program::direct_deploy_program( - &mut dummy_invoke_context, + use solana_bpf_loader_program::deploy_program_internal; + solana_bpf_loader_program::deploy_program!( + dummy_invoke_context, program_id, &bpf_loader_upgradeable::id(), data_len, elf, self.slot, - )? + ); } // Update the program cache by merging with `programs_modified`, which diff --git a/sdk/program/src/loader_v4.rs b/sdk/program/src/loader_v4.rs index 4d5b0934534db7..47bf9ddf542bfd 100644 --- a/sdk/program/src/loader_v4.rs +++ b/sdk/program/src/loader_v4.rs @@ -12,7 +12,7 @@ use crate::{ crate::declare_id!("LoaderV411111111111111111111111111111111111"); /// Cooldown before a program can be un-/redeployed again -pub const DEPLOYMENT_COOLDOWN_IN_SLOTS: u64 = 750; +pub const DEPLOYMENT_COOLDOWN_IN_SLOTS: u64 = 1; #[repr(u64)] #[cfg_attr(feature = "frozen-abi", derive(AbiExample))] From 0a493c325c34b2ee0f50402dd83a5a888044dc2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Mei=C3=9Fner?= Date: Tue, 5 Nov 2024 13:48:49 +0000 Subject: [PATCH 5/6] Adds loader-v4 to write lock demotion exemptions. --- sdk/program/src/message/legacy.rs | 3 ++- sdk/program/src/message/versions/v0/loaded.rs | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/sdk/program/src/message/legacy.rs b/sdk/program/src/message/legacy.rs index f225e5a646b654..8889c12803ee94 100644 --- a/sdk/program/src/message/legacy.rs +++ b/sdk/program/src/message/legacy.rs @@ -20,6 +20,7 @@ use { bpf_loader, bpf_loader_deprecated, bpf_loader_upgradeable, hash::Hash, instruction::{CompiledInstruction, Instruction}, + loader_v4, message::{compiled_keys::CompiledKeys, MessageHeader}, pubkey::Pubkey, system_instruction, system_program, sysvar, @@ -691,7 +692,7 @@ impl Message { pub fn is_upgradeable_loader_present(&self) -> bool { self.account_keys .iter() - .any(|&key| key == bpf_loader_upgradeable::id()) + .any(|key| bpf_loader_upgradeable::check_id(key) || loader_v4::check_id(key)) } } diff --git a/sdk/program/src/message/versions/v0/loaded.rs b/sdk/program/src/message/versions/v0/loaded.rs index 1825c5e748e3f4..be067667d7c195 100644 --- a/sdk/program/src/message/versions/v0/loaded.rs +++ b/sdk/program/src/message/versions/v0/loaded.rs @@ -1,6 +1,6 @@ use { crate::{ - bpf_loader_upgradeable, + bpf_loader_upgradeable, loader_v4, message::{v0, AccountKeys}, pubkey::Pubkey, }, @@ -179,7 +179,7 @@ impl<'a> LoadedMessage<'a> { pub fn is_upgradeable_loader_present(&self) -> bool { self.account_keys() .iter() - .any(|&key| key == bpf_loader_upgradeable::id()) + .any(|key| bpf_loader_upgradeable::check_id(key) || loader_v4::check_id(key)) } } From d7d6783e5ff3312cbfc4d3bb2b7cc4e253bb1d16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Mei=C3=9Fner?= Date: Tue, 5 Nov 2024 17:29:19 +0000 Subject: [PATCH 6/6] Adjusts tests. --- cli/tests/program.rs | 163 +++++++-- log-collector/src/lib.rs | 6 +- programs/sbf/benches/bpf_loader.rs | 6 +- programs/sbf/tests/programs.rs | 561 +++++++++++++---------------- programs/sbf/tests/simulation.rs | 4 +- programs/sbf/tests/sysvar.rs | 4 +- runtime/src/bank/tests.rs | 13 +- 7 files changed, 402 insertions(+), 355 deletions(-) diff --git a/cli/tests/program.rs b/cli/tests/program.rs index f1c441a8654ea4..5a6431e08a7e34 100644 --- a/cli/tests/program.rs +++ b/cli/tests/program.rs @@ -12,7 +12,7 @@ use { }, solana_cli_output::{parse_sign_only_reply_string, OutputFormat}, solana_faucet::faucet::run_local_faucet, - solana_feature_set::enable_alt_bn128_syscall, + solana_feature_set::{enable_alt_bn128_syscall, enable_loader_v4}, solana_rpc::rpc::JsonRpcConfig, solana_rpc_client::rpc_client::{GetConfirmedSignaturesForAddress2Config, RpcClient}, solana_rpc_client_api::config::RpcTransactionConfig, @@ -32,7 +32,7 @@ use { transaction::Transaction, }, solana_streamer::socket::SocketAddrSpace, - solana_test_validator::{TestValidator, TestValidatorGenesis}, + solana_test_validator::TestValidatorGenesis, solana_transaction_status::UiTransactionEncoding, std::{ env, @@ -81,8 +81,17 @@ fn test_cli_program_deploy_non_upgradeable() { let mint_keypair = Keypair::new(); let mint_pubkey = mint_keypair.pubkey(); let faucet_addr = run_local_faucet(mint_keypair, None); - let test_validator = - TestValidator::with_no_fees(mint_pubkey, Some(faucet_addr), SocketAddrSpace::Unspecified); + let test_validator = TestValidatorGenesis::default() + .fee_rate_governor(FeeRateGovernor::new(0, 0)) + .rent(Rent { + lamports_per_byte_year: 1, + exemption_threshold: 1.0, + ..Rent::default() + }) + .faucet_addr(Some(faucet_addr)) + .deactivate_features(&[enable_loader_v4::id()]) + .start_with_mint_address(mint_pubkey, SocketAddrSpace::Unspecified) + .expect("validator start failed"); let rpc_client = RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::processed()); @@ -286,8 +295,17 @@ fn test_cli_program_deploy_no_authority() { let mint_keypair = Keypair::new(); let mint_pubkey = mint_keypair.pubkey(); let faucet_addr = run_local_faucet(mint_keypair, None); - let test_validator = - TestValidator::with_no_fees(mint_pubkey, Some(faucet_addr), SocketAddrSpace::Unspecified); + let test_validator = TestValidatorGenesis::default() + .fee_rate_governor(FeeRateGovernor::new(0, 0)) + .rent(Rent { + lamports_per_byte_year: 1, + exemption_threshold: 1.0, + ..Rent::default() + }) + .faucet_addr(Some(faucet_addr)) + .deactivate_features(&[enable_loader_v4::id()]) + .start_with_mint_address(mint_pubkey, SocketAddrSpace::Unspecified) + .expect("validator start failed"); let rpc_client = RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::processed()); @@ -403,6 +421,7 @@ fn test_cli_program_deploy_feature(enable_feature: bool) { test_validator_builder.deactivate_features(&[enable_alt_bn128_syscall::id()]); } + test_validator_builder = test_validator_builder.deactivate_features(&[enable_loader_v4::id()]); let test_validator = test_validator_builder .start_with_mint_address(mint_pubkey, SocketAddrSpace::Unspecified) .expect("validator start failed"); @@ -530,6 +549,7 @@ fn test_cli_program_upgrade_with_feature(enable_feature: bool) { test_validator_builder.deactivate_features(&[enable_alt_bn128_syscall::id()]); } + test_validator_builder = test_validator_builder.deactivate_features(&[enable_loader_v4::id()]); let test_validator = test_validator_builder .start_with_mint_address(mint_pubkey, SocketAddrSpace::Unspecified) .expect("validator start failed"); @@ -678,8 +698,17 @@ fn test_cli_program_deploy_with_authority() { let mint_keypair = Keypair::new(); let mint_pubkey = mint_keypair.pubkey(); let faucet_addr = run_local_faucet(mint_keypair, None); - let test_validator = - TestValidator::with_no_fees(mint_pubkey, Some(faucet_addr), SocketAddrSpace::Unspecified); + let test_validator = TestValidatorGenesis::default() + .fee_rate_governor(FeeRateGovernor::new(0, 0)) + .rent(Rent { + lamports_per_byte_year: 1, + exemption_threshold: 1.0, + ..Rent::default() + }) + .faucet_addr(Some(faucet_addr)) + .deactivate_features(&[enable_loader_v4::id()]) + .start_with_mint_address(mint_pubkey, SocketAddrSpace::Unspecified) + .expect("validator start failed"); let rpc_client = RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::processed()); @@ -1079,8 +1108,17 @@ fn test_cli_program_upgrade_auto_extend() { let mint_keypair = Keypair::new(); let mint_pubkey = mint_keypair.pubkey(); let faucet_addr = run_local_faucet(mint_keypair, None); - let test_validator = - TestValidator::with_no_fees(mint_pubkey, Some(faucet_addr), SocketAddrSpace::Unspecified); + let test_validator = TestValidatorGenesis::default() + .fee_rate_governor(FeeRateGovernor::new(0, 0)) + .rent(Rent { + lamports_per_byte_year: 1, + exemption_threshold: 1.0, + ..Rent::default() + }) + .faucet_addr(Some(faucet_addr)) + .deactivate_features(&[enable_loader_v4::id()]) + .start_with_mint_address(mint_pubkey, SocketAddrSpace::Unspecified) + .expect("validator start failed"); let rpc_client = RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::processed()); @@ -1232,8 +1270,17 @@ fn test_cli_program_close_program() { let mint_keypair = Keypair::new(); let mint_pubkey = mint_keypair.pubkey(); let faucet_addr = run_local_faucet(mint_keypair, None); - let test_validator = - TestValidator::with_no_fees(mint_pubkey, Some(faucet_addr), SocketAddrSpace::Unspecified); + let test_validator = TestValidatorGenesis::default() + .fee_rate_governor(FeeRateGovernor::new(0, 0)) + .rent(Rent { + lamports_per_byte_year: 1, + exemption_threshold: 1.0, + ..Rent::default() + }) + .faucet_addr(Some(faucet_addr)) + .deactivate_features(&[enable_loader_v4::id()]) + .start_with_mint_address(mint_pubkey, SocketAddrSpace::Unspecified) + .expect("validator start failed"); let rpc_client = RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::processed()); @@ -1351,8 +1398,17 @@ fn test_cli_program_extend_program() { let mint_keypair = Keypair::new(); let mint_pubkey = mint_keypair.pubkey(); let faucet_addr = run_local_faucet(mint_keypair, None); - let test_validator = - TestValidator::with_no_fees(mint_pubkey, Some(faucet_addr), SocketAddrSpace::Unspecified); + let test_validator = TestValidatorGenesis::default() + .fee_rate_governor(FeeRateGovernor::new(0, 0)) + .rent(Rent { + lamports_per_byte_year: 1, + exemption_threshold: 1.0, + ..Rent::default() + }) + .faucet_addr(Some(faucet_addr)) + .deactivate_features(&[enable_loader_v4::id()]) + .start_with_mint_address(mint_pubkey, SocketAddrSpace::Unspecified) + .expect("validator start failed"); let rpc_client = RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::processed()); @@ -1521,8 +1577,17 @@ fn test_cli_program_write_buffer() { let mint_keypair = Keypair::new(); let mint_pubkey = mint_keypair.pubkey(); let faucet_addr = run_local_faucet(mint_keypair, None); - let test_validator = - TestValidator::with_no_fees(mint_pubkey, Some(faucet_addr), SocketAddrSpace::Unspecified); + let test_validator = TestValidatorGenesis::default() + .fee_rate_governor(FeeRateGovernor::new(0, 0)) + .rent(Rent { + lamports_per_byte_year: 1, + exemption_threshold: 1.0, + ..Rent::default() + }) + .faucet_addr(Some(faucet_addr)) + .deactivate_features(&[enable_loader_v4::id()]) + .start_with_mint_address(mint_pubkey, SocketAddrSpace::Unspecified) + .expect("validator start failed"); let rpc_client = RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::processed()); @@ -2008,8 +2073,17 @@ fn test_cli_program_set_buffer_authority() { let mint_keypair = Keypair::new(); let mint_pubkey = mint_keypair.pubkey(); let faucet_addr = run_local_faucet(mint_keypair, None); - let test_validator = - TestValidator::with_no_fees(mint_pubkey, Some(faucet_addr), SocketAddrSpace::Unspecified); + let test_validator = TestValidatorGenesis::default() + .fee_rate_governor(FeeRateGovernor::new(0, 0)) + .rent(Rent { + lamports_per_byte_year: 1, + exemption_threshold: 1.0, + ..Rent::default() + }) + .faucet_addr(Some(faucet_addr)) + .deactivate_features(&[enable_loader_v4::id()]) + .start_with_mint_address(mint_pubkey, SocketAddrSpace::Unspecified) + .expect("validator start failed"); let rpc_client = RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::processed()); @@ -2180,8 +2254,17 @@ fn test_cli_program_mismatch_buffer_authority() { let mint_keypair = Keypair::new(); let mint_pubkey = mint_keypair.pubkey(); let faucet_addr = run_local_faucet(mint_keypair, None); - let test_validator = - TestValidator::with_no_fees(mint_pubkey, Some(faucet_addr), SocketAddrSpace::Unspecified); + let test_validator = TestValidatorGenesis::default() + .fee_rate_governor(FeeRateGovernor::new(0, 0)) + .rent(Rent { + lamports_per_byte_year: 1, + exemption_threshold: 1.0, + ..Rent::default() + }) + .faucet_addr(Some(faucet_addr)) + .deactivate_features(&[enable_loader_v4::id()]) + .start_with_mint_address(mint_pubkey, SocketAddrSpace::Unspecified) + .expect("validator start failed"); let rpc_client = RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::processed()); @@ -2306,8 +2389,17 @@ fn test_cli_program_deploy_with_offline_signing(use_offline_signer_as_fee_payer: let mint_keypair = Keypair::new(); let mint_pubkey = mint_keypair.pubkey(); let faucet_addr = run_local_faucet(mint_keypair, None); - let test_validator = - TestValidator::with_no_fees(mint_pubkey, Some(faucet_addr), SocketAddrSpace::Unspecified); + let test_validator = TestValidatorGenesis::default() + .fee_rate_governor(FeeRateGovernor::new(0, 0)) + .rent(Rent { + lamports_per_byte_year: 1, + exemption_threshold: 1.0, + ..Rent::default() + }) + .faucet_addr(Some(faucet_addr)) + .deactivate_features(&[enable_loader_v4::id()]) + .start_with_mint_address(mint_pubkey, SocketAddrSpace::Unspecified) + .expect("validator start failed"); let rpc_client = RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::processed()); @@ -2499,8 +2591,17 @@ fn test_cli_program_show() { let mint_keypair = Keypair::new(); let mint_pubkey = mint_keypair.pubkey(); let faucet_addr = run_local_faucet(mint_keypair, None); - let test_validator = - TestValidator::with_no_fees(mint_pubkey, Some(faucet_addr), SocketAddrSpace::Unspecified); + let test_validator = TestValidatorGenesis::default() + .fee_rate_governor(FeeRateGovernor::new(0, 0)) + .rent(Rent { + lamports_per_byte_year: 1, + exemption_threshold: 1.0, + ..Rent::default() + }) + .faucet_addr(Some(faucet_addr)) + .deactivate_features(&[enable_loader_v4::id()]) + .start_with_mint_address(mint_pubkey, SocketAddrSpace::Unspecified) + .expect("validator start failed"); let rpc_client = RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::processed()); @@ -2696,8 +2797,17 @@ fn test_cli_program_dump() { let mint_keypair = Keypair::new(); let mint_pubkey = mint_keypair.pubkey(); let faucet_addr = run_local_faucet(mint_keypair, None); - let test_validator = - TestValidator::with_no_fees(mint_pubkey, Some(faucet_addr), SocketAddrSpace::Unspecified); + let test_validator = TestValidatorGenesis::default() + .fee_rate_governor(FeeRateGovernor::new(0, 0)) + .rent(Rent { + lamports_per_byte_year: 1, + exemption_threshold: 1.0, + ..Rent::default() + }) + .faucet_addr(Some(faucet_addr)) + .deactivate_features(&[enable_loader_v4::id()]) + .start_with_mint_address(mint_pubkey, SocketAddrSpace::Unspecified) + .expect("validator start failed"); let rpc_client = RpcClient::new_with_commitment(test_validator.rpc_url(), CommitmentConfig::processed()); @@ -2835,6 +2945,7 @@ fn test_cli_program_deploy_with_args(compute_unit_price: Option, use_rpc: b exemption_threshold: 1.0, ..Rent::default() }) + .deactivate_features(&[enable_loader_v4::id()]) .rpc_config(JsonRpcConfig { enable_rpc_transaction_history: true, faucet_addr: Some(faucet_addr), diff --git a/log-collector/src/lib.rs b/log-collector/src/lib.rs index 612300f8e94bfc..60d3cb5b6fde93 100644 --- a/log-collector/src/lib.rs +++ b/log-collector/src/lib.rs @@ -64,8 +64,7 @@ impl LogCollector { #[macro_export] macro_rules! ic_logger_msg { ($log_collector:expr, $message:expr) => { - $crate::log::debug!( - target: "solana_runtime::message_processor::stable_log", + println!( "{}", $message ); @@ -76,8 +75,7 @@ macro_rules! ic_logger_msg { } }; ($log_collector:expr, $fmt:expr, $($arg:tt)*) => { - $crate::log::debug!( - target: "solana_runtime::message_processor::stable_log", + println!( $fmt, $($arg)* ); diff --git a/programs/sbf/benches/bpf_loader.rs b/programs/sbf/benches/bpf_loader.rs index 7475e9ea2d0f53..d2c98719c0f6b6 100644 --- a/programs/sbf/benches/bpf_loader.rs +++ b/programs/sbf/benches/bpf_loader.rs @@ -32,7 +32,7 @@ use { bank::Bank, bank_client::BankClient, genesis_utils::{create_genesis_config, GenesisConfigInfo}, - loader_utils::{load_program_from_file, load_upgradeable_program_and_advance_slot}, + loader_utils::{load_program_from_file, load_program_of_loader_v4}, }, solana_sdk::{ account::AccountSharedData, @@ -201,9 +201,9 @@ fn bench_program_execute_noop(bencher: &mut Bencher) { let authority_keypair = Keypair::new(); let mint_pubkey = mint_keypair.pubkey(); - let (_, invoke_program_id) = load_upgradeable_program_and_advance_slot( + let (_bank, invoke_program_id) = load_program_of_loader_v4( &mut bank_client, - bank_forks.as_ref(), + &bank_forks, &mint_keypair, &authority_keypair, "noop", diff --git a/programs/sbf/tests/programs.rs b/programs/sbf/tests/programs.rs index 991d7a8695444c..19adbc93439bf7 100644 --- a/programs/sbf/tests/programs.rs +++ b/programs/sbf/tests/programs.rs @@ -28,9 +28,9 @@ use { create_genesis_config_with_leader_ex, GenesisConfigInfo, }, loader_utils::{ - create_program, load_program_from_file, load_upgradeable_buffer, - load_upgradeable_program, load_upgradeable_program_and_advance_slot, - load_upgradeable_program_wrapper, set_upgrade_authority, upgrade_program, + create_program, instructions_to_load_program_of_loader_v4, load_program_from_file, + load_program_of_loader_v4, load_upgradeable_buffer, load_upgradeable_program, + set_upgrade_authority, upgrade_program, }, }, solana_runtime_transaction::{ @@ -53,6 +53,7 @@ use { genesis_config::ClusterType, hash::Hash, instruction::{AccountMeta, Instruction, InstructionError}, + loader_v4, message::{v0::LoadedAddresses, Message, SanitizedMessage}, pubkey::Pubkey, rent::Rent, @@ -290,9 +291,9 @@ fn test_program_sbf_sanity() { let authority_keypair = Keypair::new(); // Call user program - let (_, program_id) = load_upgradeable_program_and_advance_slot( + let (_bank, program_id) = load_program_of_loader_v4( &mut bank_client, - bank_forks.as_ref(), + &bank_forks, &mint_keypair, &authority_keypair, program.0, @@ -356,7 +357,7 @@ fn test_program_sbf_loader_deprecated() { #[test] #[cfg(feature = "sbf_rust")] #[should_panic( - expected = "called `Result::unwrap()` on an `Err` value: TransactionError(InstructionError(1, InvalidAccountData))" + expected = "called `Result::unwrap()` on an `Err` value: TransactionError(InstructionError(0, InvalidAccountData))" )] fn test_sol_alloc_free_no_longer_deployable_with_upgradeable_loader() { solana_logger::setup(); @@ -384,9 +385,9 @@ fn test_sol_alloc_free_no_longer_deployable_with_upgradeable_loader() { // in elf inside syscall table. In this case, `sol_alloc_free_` can't be // found in syscall table. Hence, the verification fails and the deployment // fails. - let (_bank, _program_id) = load_upgradeable_program_and_advance_slot( + let (_bank, _program_id) = load_program_of_loader_v4( &mut bank_client, - bank_forks.as_ref(), + &bank_forks, &mint_keypair, &authority_keypair, "solana_sbf_rust_deprecated_loader", @@ -421,9 +422,9 @@ fn test_program_sbf_duplicate_accounts() { let mut bank_client = BankClient::new_shared(bank.clone()); let authority_keypair = Keypair::new(); - let (bank, program_id) = load_upgradeable_program_and_advance_slot( + let (bank, program_id) = load_program_of_loader_v4( &mut bank_client, - bank_forks.as_ref(), + &bank_forks, &mint_keypair, &authority_keypair, program, @@ -528,9 +529,9 @@ fn test_program_sbf_error_handling() { let mut bank_client = BankClient::new_shared(bank); let authority_keypair = Keypair::new(); - let (_bank, program_id) = load_upgradeable_program_and_advance_slot( + let (_bank, program_id) = load_program_of_loader_v4( &mut bank_client, - bank_forks.as_ref(), + &bank_forks, &mint_keypair, &authority_keypair, program, @@ -638,9 +639,9 @@ fn test_return_data_and_log_data_syscall() { let mut bank_client = BankClient::new_shared(bank.clone()); let authority_keypair = Keypair::new(); - let (bank, program_id) = load_upgradeable_program_and_advance_slot( + let (bank, program_id) = load_program_of_loader_v4( &mut bank_client, - bank_forks.as_ref(), + &bank_forks, &mint_keypair, &authority_keypair, program, @@ -707,23 +708,23 @@ fn test_program_sbf_invoke_sanity() { let mut bank_client = BankClient::new_shared(bank.clone()); let authority_keypair = Keypair::new(); - let invoke_program_id = load_upgradeable_program_wrapper( - &bank_client, + let (_bank, invoke_program_id) = load_program_of_loader_v4( + &mut bank_client, + &bank_forks, &mint_keypair, &authority_keypair, program.1, ); - - let invoked_program_id = load_upgradeable_program_wrapper( - &bank_client, + let (_bank, invoked_program_id) = load_program_of_loader_v4( + &mut bank_client, + &bank_forks, &mint_keypair, &authority_keypair, program.2, ); - - let (bank, noop_program_id) = load_upgradeable_program_and_advance_slot( + let (bank, noop_program_id) = load_program_of_loader_v4( &mut bank_client, - bank_forks.as_ref(), + &bank_forks, &mint_keypair, &authority_keypair, program.3, @@ -1128,16 +1129,16 @@ fn test_program_sbf_program_id_spoofing() { let mut bank_client = BankClient::new_shared(bank.clone()); let authority_keypair = Keypair::new(); - let malicious_swap_pubkey = load_upgradeable_program_wrapper( - &bank_client, + let (_bank, malicious_swap_pubkey) = load_program_of_loader_v4( + &mut bank_client, + &bank_forks, &mint_keypair, &authority_keypair, "solana_sbf_rust_spoof1", ); - - let (bank, malicious_system_pubkey) = load_upgradeable_program_and_advance_slot( + let (bank, malicious_system_pubkey) = load_program_of_loader_v4( &mut bank_client, - bank_forks.as_ref(), + &bank_forks, &mint_keypair, &authority_keypair, "solana_sbf_rust_spoof1_system", @@ -1182,16 +1183,16 @@ fn test_program_sbf_caller_has_access_to_cpi_program() { let mut bank_client = BankClient::new_shared(bank.clone()); let authority_keypair = Keypair::new(); - let caller_pubkey = load_upgradeable_program_wrapper( - &bank_client, + let (_bank, caller_pubkey) = load_program_of_loader_v4( + &mut bank_client, + &bank_forks, &mint_keypair, &authority_keypair, "solana_sbf_rust_caller_access", ); - - let (_bank, caller2_pubkey) = load_upgradeable_program_and_advance_slot( + let (_bank, caller2_pubkey) = load_program_of_loader_v4( &mut bank_client, - bank_forks.as_ref(), + &bank_forks, &mint_keypair, &authority_keypair, "solana_sbf_rust_caller_access", @@ -1224,9 +1225,9 @@ fn test_program_sbf_ro_modify() { let mut bank_client = BankClient::new_shared(bank.clone()); let authority_keypair = Keypair::new(); - let (bank, program_pubkey) = load_upgradeable_program_and_advance_slot( + let (bank, program_pubkey) = load_program_of_loader_v4( &mut bank_client, - bank_forks.as_ref(), + &bank_forks, &mint_keypair, &authority_keypair, "solana_sbf_rust_ro_modify", @@ -1281,9 +1282,9 @@ fn test_program_sbf_call_depth() { let mut bank_client = BankClient::new_shared(bank); let authority_keypair = Keypair::new(); - let (_, program_id) = load_upgradeable_program_and_advance_slot( + let (_bank, program_id) = load_program_of_loader_v4( &mut bank_client, - bank_forks.as_ref(), + &bank_forks, &mint_keypair, &authority_keypair, "solana_sbf_rust_call_depth", @@ -1318,9 +1319,9 @@ fn test_program_sbf_compute_budget() { let mut bank_client = BankClient::new_shared(bank); let authority_keypair = Keypair::new(); - let (_, program_id) = load_upgradeable_program_and_advance_slot( + let (_bank, program_id) = load_program_of_loader_v4( &mut bank_client, - bank_forks.as_ref(), + &bank_forks, &mint_keypair, &authority_keypair, "solana_sbf_rust_noop", @@ -1449,9 +1450,9 @@ fn test_program_sbf_instruction_introspection() { let mut bank_client = BankClient::new_shared(bank.clone()); let authority_keypair = Keypair::new(); - let (bank, program_id) = load_upgradeable_program_and_advance_slot( + let (_bank, program_id) = load_program_of_loader_v4( &mut bank_client, - bank_forks.as_ref(), + &bank_forks, &mint_keypair, &authority_keypair, "solana_sbf_rust_instruction_introspection", @@ -1508,21 +1509,14 @@ fn test_program_sbf_upgrade() { let mut bank_client = BankClient::new_shared(bank); // Deploy upgrade program - let buffer_keypair = Keypair::new(); - let program_keypair = Keypair::new(); - let program_id = program_keypair.pubkey(); let authority_keypair = Keypair::new(); - load_upgradeable_program( - &bank_client, + let (_bank, program_id) = load_program_of_loader_v4( + &mut bank_client, + &bank_forks, &mint_keypair, - &buffer_keypair, - &program_keypair, &authority_keypair, "solana_sbf_rust_upgradeable", ); - bank_client - .advance_slot(1, bank_forks.as_ref(), &Pubkey::default()) - .expect("Failed to advance the slot"); let mut instruction = Instruction::new_with_bytes(program_id, &[0], vec![AccountMeta::new(clock::id(), false)]); @@ -1639,10 +1633,13 @@ fn test_program_sbf_invoke_stable_genesis_and_bank() { solana_logger::setup(); let GenesisConfigInfo { - genesis_config, + mut genesis_config, mint_keypair, .. } = get_stable_genesis_config(); + genesis_config + .accounts + .remove(&feature_set::enable_loader_v4::id()); let bank = Bank::new_for_tests(&genesis_config); let bank = Arc::new(bank); let bank_client = BankClient::new_shared(bank.clone()); @@ -1821,26 +1818,46 @@ fn test_program_sbf_invoke_in_same_tx_as_deployment() { let mut bank_client = BankClient::new_shared(bank.clone()); // Deploy upgradeable program - let buffer_keypair = Keypair::new(); - let program_keypair = Keypair::new(); - let program_id = program_keypair.pubkey(); let authority_keypair = Keypair::new(); + let (program_keypair, mut deployment_instructions) = instructions_to_load_program_of_loader_v4( + &bank_client, + &mint_keypair, + &authority_keypair, + "solana_sbf_rust_noop", + None, + None, + ); + let program_id = program_keypair.pubkey(); + let deployment_instruction = deployment_instructions.pop().unwrap(); + let signers: &[&[&Keypair]] = &[ + &[&mint_keypair, &program_keypair], + &[&mint_keypair, &program_keypair, &authority_keypair], + &[&mint_keypair, &authority_keypair], + ]; + let signers = std::iter::once(signers[0]) + .chain(std::iter::once(signers[1])) + .chain(std::iter::repeat(signers[2])); + for (instruction, signers) in deployment_instructions.into_iter().zip(signers) { + let message = Message::new(&[instruction], Some(&mint_keypair.pubkey())); + bank_client + .send_and_confirm_message(signers, message) + .unwrap(); + } // Deploy indirect invocation program - let indirect_program_keypair = Keypair::new(); - load_upgradeable_program( - &bank_client, + let (bank, indirect_program_id) = load_program_of_loader_v4( + &mut bank_client, + &bank_forks, &mint_keypair, - &buffer_keypair, - &indirect_program_keypair, &authority_keypair, "solana_sbf_rust_invoke_and_return", ); + // Prepare invocations let invoke_instruction = Instruction::new_with_bytes(program_id, &[0], vec![AccountMeta::new(clock::id(), false)]); let indirect_invoke_instruction = Instruction::new_with_bytes( - indirect_program_keypair.pubkey(), + indirect_program_id, &[0], vec![ AccountMeta::new_readonly(program_id, false), @@ -1848,57 +1865,29 @@ fn test_program_sbf_invoke_in_same_tx_as_deployment() { ], ); - // Prepare deployment - let program = load_upgradeable_buffer( - &bank_client, - &mint_keypair, - &buffer_keypair, - &authority_keypair, - "solana_sbf_rust_noop", - ); - let deployment_instructions = bpf_loader_upgradeable::deploy_with_max_program_len( - &mint_keypair.pubkey(), - &program_keypair.pubkey(), - &buffer_keypair.pubkey(), - &authority_keypair.pubkey(), - 1.max( - bank_client - .get_minimum_balance_for_rent_exemption( - bpf_loader_upgradeable::UpgradeableLoaderState::size_of_program(), - ) - .unwrap(), - ), - program.len() * 2, - ) - .unwrap(); - - let bank = bank_client - .advance_slot(1, bank_forks.as_ref(), &Pubkey::default()) - .expect("Failed to advance slot"); - // Deployment is invisible to both top-level-instructions and CPI instructions for (index, invoke_instruction) in [invoke_instruction, indirect_invoke_instruction] .into_iter() .enumerate() { - let mut instructions = deployment_instructions.clone(); - instructions.push(invoke_instruction); let tx = Transaction::new( - &[&mint_keypair, &program_keypair, &authority_keypair], - Message::new(&instructions, Some(&mint_keypair.pubkey())), + &[&mint_keypair, &authority_keypair], + Message::new( + &[deployment_instruction.clone(), invoke_instruction], + Some(&mint_keypair.pubkey()), + ), bank.last_blockhash(), ); + let (result, _, _) = process_transaction_and_record_inner(&bank, tx); if index == 0 { - let result = load_execute_and_commit_transaction(&bank, tx); assert_eq!( - result.unwrap().status, - Err(TransactionError::ProgramAccountNotFound), + result.unwrap_err(), + TransactionError::ProgramAccountNotFound, ); } else { - let (result, _, _) = process_transaction_and_record_inner(&bank, tx); assert_eq!( result.unwrap_err(), - TransactionError::InstructionError(2, InstructionError::UnsupportedProgramId), + TransactionError::InstructionError(1, InstructionError::UnsupportedProgramId), ); } } @@ -1918,45 +1907,54 @@ fn test_program_sbf_invoke_in_same_tx_as_redeployment() { let mut bank_client = BankClient::new_shared(bank.clone()); // 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_program( - &bank_client, + let (_bank, program_id) = load_program_of_loader_v4( + &mut bank_client, + &bank_forks, &mint_keypair, - &buffer_keypair, - &program_keypair, &authority_keypair, "solana_sbf_rust_noop", ); + let (source_program_keypair, mut deployment_instructions) = + instructions_to_load_program_of_loader_v4( + &bank_client, + &mint_keypair, + &authority_keypair, + "solana_sbf_rust_panic", + None, + Some(&program_id), + ); + let undeployment_instruction = loader_v4::retract(&program_id, &authority_keypair.pubkey()); + let deployment_instruction = deployment_instructions.pop().unwrap(); + let signers: &[&[&Keypair]] = &[ + &[&mint_keypair, &source_program_keypair], + &[&mint_keypair, &source_program_keypair, &authority_keypair], + &[&mint_keypair, &authority_keypair], + ]; + let signers = std::iter::once(signers[0]) + .chain(std::iter::once(signers[1])) + .chain(std::iter::repeat(signers[2])); + for (instruction, signers) in deployment_instructions.into_iter().zip(signers) { + let message = Message::new(&[instruction], Some(&mint_keypair.pubkey())); + bank_client + .send_and_confirm_message(signers, message) + .unwrap(); + } // Deploy indirect invocation program - let indirect_program_keypair = Keypair::new(); - load_upgradeable_program( - &bank_client, + let (bank, indirect_program_id) = load_program_of_loader_v4( + &mut bank_client, + &bank_forks, &mint_keypair, - &buffer_keypair, - &indirect_program_keypair, &authority_keypair, "solana_sbf_rust_invoke_and_return", ); - // Deploy panic program - let panic_program_keypair = Keypair::new(); - load_upgradeable_program( - &bank_client, - &mint_keypair, - &buffer_keypair, - &panic_program_keypair, - &authority_keypair, - "solana_sbf_rust_panic", - ); - + // Prepare invocations let invoke_instruction = Instruction::new_with_bytes(program_id, &[0], vec![AccountMeta::new(clock::id(), false)]); let indirect_invoke_instruction = Instruction::new_with_bytes( - indirect_program_keypair.pubkey(), + indirect_program_id, &[0], vec![ AccountMeta::new_readonly(program_id, false), @@ -1964,31 +1962,6 @@ fn test_program_sbf_invoke_in_same_tx_as_redeployment() { ], ); - // load_upgradeable_program sets clock sysvar to 1, which causes the program to be effective - // after 2 slots. They need to be called individually to create the correct fork graph in between. - bank_client - .advance_slot(1, bank_forks.as_ref(), &Pubkey::default()) - .unwrap(); - let bank = bank_client - .advance_slot(1, bank_forks.as_ref(), &Pubkey::default()) - .unwrap(); - - // Prepare redeployment - let buffer_keypair = Keypair::new(); - load_upgradeable_buffer( - &bank_client, - &mint_keypair, - &buffer_keypair, - &authority_keypair, - "solana_sbf_rust_panic", - ); - let redeployment_instruction = bpf_loader_upgradeable::upgrade( - &program_id, - &buffer_keypair.pubkey(), - &authority_keypair.pubkey(), - &mint_keypair.pubkey(), - ); - // Redeployment causes programs to be unavailable to both top-level-instructions and CPI instructions for invoke_instruction in [invoke_instruction, indirect_invoke_instruction] { // Call upgradeable program @@ -1998,7 +1971,11 @@ fn test_program_sbf_invoke_in_same_tx_as_redeployment() { // Upgrade the program and invoke in same tx let message = Message::new( - &[redeployment_instruction.clone(), invoke_instruction], + &[ + undeployment_instruction.clone(), + deployment_instruction.clone(), + invoke_instruction, + ], Some(&mint_keypair.pubkey()), ); let tx = Transaction::new( @@ -2009,7 +1986,7 @@ fn test_program_sbf_invoke_in_same_tx_as_redeployment() { let (result, _, _) = process_transaction_and_record_inner(&bank, tx); assert_eq!( result.unwrap_err(), - TransactionError::InstructionError(1, InstructionError::UnsupportedProgramId), + TransactionError::InstructionError(2, InstructionError::UnsupportedProgramId), ); } } @@ -2028,34 +2005,29 @@ fn test_program_sbf_invoke_in_same_tx_as_undeployment() { let mut bank_client = BankClient::new_shared(bank.clone()); // 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_program( - &bank_client, + let (_bank, program_id) = load_program_of_loader_v4( + &mut bank_client, + &bank_forks, &mint_keypair, - &buffer_keypair, - &program_keypair, &authority_keypair, "solana_sbf_rust_noop", ); // Deploy indirect invocation program - let indirect_program_keypair = Keypair::new(); - load_upgradeable_program( - &bank_client, + let (bank, indirect_program_id) = load_program_of_loader_v4( + &mut bank_client, + &bank_forks, &mint_keypair, - &buffer_keypair, - &indirect_program_keypair, &authority_keypair, "solana_sbf_rust_invoke_and_return", ); + // Prepare invocations let invoke_instruction = Instruction::new_with_bytes(program_id, &[0], vec![AccountMeta::new(clock::id(), false)]); let indirect_invoke_instruction = Instruction::new_with_bytes( - indirect_program_keypair.pubkey(), + indirect_program_id, &[0], vec![ AccountMeta::new_readonly(program_id, false), @@ -2063,26 +2035,8 @@ fn test_program_sbf_invoke_in_same_tx_as_undeployment() { ], ); - // load_upgradeable_program sets clock sysvar to 1, which causes the program to be effective - // after 2 slots. They need to be called individually to create the correct fork graph in between. - bank_client - .advance_slot(1, bank_forks.as_ref(), &Pubkey::default()) - .unwrap(); - let bank = bank_client - .advance_slot(1, bank_forks.as_ref(), &Pubkey::default()) - .unwrap(); - // Prepare undeployment - let (programdata_address, _) = Pubkey::find_program_address( - &[program_keypair.pubkey().as_ref()], - &bpf_loader_upgradeable::id(), - ); - let undeployment_instruction = bpf_loader_upgradeable::close_any( - &programdata_address, - &mint_keypair.pubkey(), - Some(&authority_keypair.pubkey()), - Some(&program_id), - ); + let undeployment_instruction = loader_v4::retract(&program_id, &authority_keypair.pubkey()); // Undeployment is visible to both top-level-instructions and CPI instructions for invoke_instruction in [invoke_instruction, indirect_invoke_instruction] { @@ -2124,29 +2078,22 @@ fn test_program_sbf_invoke_upgradeable_via_cpi() { let mut bank_client = BankClient::new_shared(bank); let authority_keypair = Keypair::new(); - let (_bank, invoke_and_return) = load_upgradeable_program_and_advance_slot( + let (_bank, invoke_and_return) = load_program_of_loader_v4( &mut bank_client, - bank_forks.as_ref(), + &bank_forks, &mint_keypair, &authority_keypair, "solana_sbf_rust_invoke_and_return", ); // Deploy upgradeable program - let program_id = load_upgradeable_program_wrapper( - &bank_client, + let (_bank, program_id) = load_program_of_loader_v4( + &mut bank_client, + &bank_forks, &mint_keypair, &authority_keypair, "solana_sbf_rust_upgradeable", ); - bank_client.set_sysvar_for_tests(&clock::Clock { - slot: 2, - ..clock::Clock::default() - }); - - bank_client - .advance_slot(1, bank_forks.as_ref(), &Pubkey::default()) - .expect("Failed to advance slot"); let mut instruction = Instruction::new_with_bytes( invoke_and_return, @@ -2252,9 +2199,9 @@ fn test_program_sbf_disguised_as_sbf_loader() { let mut bank_client = BankClient::new_shared(bank); let authority_keypair = Keypair::new(); - let (_bank, program_id) = load_upgradeable_program_and_advance_slot( + let (_bank, program_id) = load_program_of_loader_v4( &mut bank_client, - bank_forks.as_ref(), + &bank_forks, &mint_keypair, &authority_keypair, program, @@ -2285,9 +2232,9 @@ fn test_program_reads_from_program_account() { let mut bank_client = BankClient::new_shared(bank); let authority_keypair = Keypair::new(); - let (_bank, program_id) = load_upgradeable_program_and_advance_slot( + let (_bank, program_id) = load_program_of_loader_v4( &mut bank_client, - bank_forks.as_ref(), + &bank_forks, &mint_keypair, &authority_keypair, "read_program", @@ -2318,9 +2265,9 @@ fn test_program_sbf_c_dup() { let mut bank_client = BankClient::new_shared(bank); let authority_keypair = Keypair::new(); - let (_, program_id) = load_upgradeable_program_and_advance_slot( + let (_bank, program_id) = load_program_of_loader_v4( &mut bank_client, - bank_forks.as_ref(), + &bank_forks, &mint_keypair, &authority_keypair, "ser", @@ -2350,30 +2297,23 @@ fn test_program_sbf_upgrade_via_cpi() { let mut bank_client = BankClient::new_shared(bank); let authority_keypair = Keypair::new(); - let (_bank, invoke_and_return) = load_upgradeable_program_and_advance_slot( + let (_bank, invoke_and_return) = load_program_of_loader_v4( &mut bank_client, - bank_forks.as_ref(), + &bank_forks, &mint_keypair, &authority_keypair, "solana_sbf_rust_invoke_and_return", ); // 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_program( - &bank_client, + let (_bank, program_id) = load_program_of_loader_v4( + &mut bank_client, + &bank_forks, &mint_keypair, - &buffer_keypair, - &program_keypair, &authority_keypair, "solana_sbf_rust_upgradeable", ); - bank_client - .advance_slot(1, bank_forks.as_ref(), &Pubkey::default()) - .expect("Failed to advance the slot"); let program_account = bank_client.get_account(&program_id).unwrap().unwrap(); let Ok(bpf_loader_upgradeable::UpgradeableLoaderState::Program { programdata_address, @@ -2459,31 +2399,28 @@ fn test_program_sbf_set_upgrade_authority_via_cpi() { mint_keypair, .. } = create_genesis_config(50); - let (bank, bank_forks) = Bank::new_with_bank_forks_for_tests(&genesis_config); let mut bank_client = BankClient::new_shared(bank); let authority_keypair = Keypair::new(); // Deploy CPI invoker program - let invoke_and_return = load_upgradeable_program_wrapper( - &bank_client, + let (_bank, invoke_and_return) = load_program_of_loader_v4( + &mut bank_client, + &bank_forks, &mint_keypair, &authority_keypair, "solana_sbf_rust_invoke_and_return", ); // Deploy upgradeable program - let program_id = load_upgradeable_program_wrapper( - &bank_client, + let (_bank, program_id) = load_program_of_loader_v4( + &mut bank_client, + &bank_forks, &mint_keypair, &authority_keypair, "solana_sbf_rust_upgradeable", ); - bank_client - .advance_slot(1, bank_forks.as_ref(), &Pubkey::default()) - .expect("Failed to advance the slot"); - // Set program upgrade authority instruction to invoke via CPI let new_upgrade_authority_key = Keypair::new().pubkey(); let mut set_upgrade_authority_instruction = bpf_loader_upgradeable::set_upgrade_authority( @@ -2537,12 +2474,13 @@ fn test_program_sbf_set_upgrade_authority_via_cpi() { #[cfg(feature = "sbf_rust")] fn test_program_upgradeable_locks() { fn setup_program_upgradeable_locks( - payer_keypair: &Keypair, - buffer_keypair: &Keypair, - program_keypair: &Keypair, ) -> (Arc, Arc>, Transaction, Transaction) { solana_logger::setup(); + let payer_keypair = keypair_from_seed(&[56u8; 32]).unwrap(); + let buffer_keypair = keypair_from_seed(&[11; 32]).unwrap(); + let program_keypair = keypair_from_seed(&[77u8; 32]).unwrap(); + let GenesisConfigInfo { genesis_config, mint_keypair, @@ -2551,26 +2489,30 @@ fn test_program_upgradeable_locks() { let (bank, bank_forks) = Bank::new_with_bank_forks_for_tests(&genesis_config); let mut bank_client = BankClient::new_shared(bank.clone()); - load_upgradeable_program( + let (program_keypair, instructions) = instructions_to_load_program_of_loader_v4( &bank_client, - &mint_keypair, - buffer_keypair, - program_keypair, - payer_keypair, - "solana_sbf_rust_panic", - ); - - // Load the buffer account - load_upgradeable_buffer( - &bank_client, - &mint_keypair, - buffer_keypair, &payer_keypair, - "solana_sbf_rust_noop", + &payer_keypair, + "solana_sbf_rust_panic", + Some(program_keypair), + None, ); - + let signers: &[&[&Keypair]] = &[ + &[&payer_keypair, &program_keypair], + &[&payer_keypair, &program_keypair], + &[&payer_keypair], + ]; + let signers = std::iter::once(signers[0]) + .chain(std::iter::once(signers[1])) + .chain(std::iter::repeat(signers[2])); + for (instruction, signers) in instructions.into_iter().zip(signers) { + let message = Message::new(&[instruction], Some(&payer_keypair.pubkey())); + bank_client + .send_and_confirm_message(signers, message) + .unwrap(); + } let bank = bank_client - .advance_slot(1, bank_forks.as_ref(), &Pubkey::default()) + .advance_slot(1, &bank_forks, &Pubkey::default()) .expect("Failed to advance the slot"); bank_client @@ -2585,7 +2527,7 @@ fn test_program_upgradeable_locks() { .unwrap(); let invoke_tx = Transaction::new( - &[payer_keypair], + &[&payer_keypair], Message::new( &[Instruction::new_with_bytes( program_keypair.pubkey(), @@ -2597,7 +2539,7 @@ fn test_program_upgradeable_locks() { bank.last_blockhash(), ); let upgrade_tx = Transaction::new( - &[payer_keypair], + &[&payer_keypair], Message::new( &[bpf_loader_upgradeable::upgrade( &program_keypair.pubkey(), @@ -2613,19 +2555,13 @@ fn test_program_upgradeable_locks() { (bank, bank_forks, invoke_tx, upgrade_tx) } - let payer_keypair = keypair_from_seed(&[56u8; 32]).unwrap(); - let buffer_keypair = keypair_from_seed(&[11; 32]).unwrap(); - let program_keypair = keypair_from_seed(&[77u8; 32]).unwrap(); - let results1 = { - let (bank, _bank_forks, invoke_tx, upgrade_tx) = - setup_program_upgradeable_locks(&payer_keypair, &buffer_keypair, &program_keypair); + let (bank, _bank_forks, invoke_tx, upgrade_tx) = setup_program_upgradeable_locks(); execute_transactions(&bank, vec![upgrade_tx, invoke_tx]) }; let results2 = { - let (bank, _bank_forks, invoke_tx, upgrade_tx) = - setup_program_upgradeable_locks(&payer_keypair, &buffer_keypair, &program_keypair); + let (bank, _bank_forks, invoke_tx, upgrade_tx) = setup_program_upgradeable_locks(); execute_transactions(&bank, vec![invoke_tx, upgrade_tx]) }; @@ -2675,9 +2611,9 @@ fn test_program_sbf_ro_account_modify() { let mut bank_client = BankClient::new_shared(bank.clone()); let authority_keypair = Keypair::new(); - let (bank, program_id) = load_upgradeable_program_and_advance_slot( + let (bank, program_id) = load_program_of_loader_v4( &mut bank_client, - bank_forks.as_ref(), + &bank_forks, &mint_keypair, &authority_keypair, "solana_sbf_rust_ro_account_modify", @@ -2749,9 +2685,9 @@ fn test_program_sbf_realloc() { let mut bank_client = BankClient::new_shared(bank.clone()); let authority_keypair = Keypair::new(); - let (bank, program_id) = load_upgradeable_program_and_advance_slot( + let (bank, program_id) = load_program_of_loader_v4( &mut bank_client, - bank_forks.as_ref(), + &bank_forks, &mint_keypair, &authority_keypair, "solana_sbf_rust_realloc", @@ -3166,16 +3102,16 @@ fn test_program_sbf_realloc_invoke() { let mut bank_client = BankClient::new_shared(bank.clone()); let authority_keypair = Keypair::new(); - let realloc_program_id = load_upgradeable_program_wrapper( - &bank_client, + let (_bank, realloc_program_id) = load_program_of_loader_v4( + &mut bank_client, + &bank_forks, &mint_keypair, &authority_keypair, "solana_sbf_rust_realloc", ); - - let (bank, realloc_invoke_program_id) = load_upgradeable_program_and_advance_slot( + let (bank, realloc_invoke_program_id) = load_program_of_loader_v4( &mut bank_client, - bank_forks.as_ref(), + &bank_forks, &mint_keypair, &authority_keypair, "solana_sbf_rust_realloc_invoke", @@ -3779,27 +3715,30 @@ fn test_program_sbf_processed_inner_instruction() { let mut bank_client = BankClient::new_shared(bank.clone()); let authority_keypair = Keypair::new(); - let sibling_program_id = load_upgradeable_program_wrapper( - &bank_client, + let (_bank, sibling_program_id) = load_program_of_loader_v4( + &mut bank_client, + &bank_forks, &mint_keypair, &authority_keypair, "solana_sbf_rust_sibling_instructions", ); - let sibling_inner_program_id = load_upgradeable_program_wrapper( - &bank_client, + let (_bank, sibling_inner_program_id) = load_program_of_loader_v4( + &mut bank_client, + &bank_forks, &mint_keypair, &authority_keypair, "solana_sbf_rust_sibling_inner_instructions", ); - let noop_program_id = load_upgradeable_program_wrapper( - &bank_client, + let (_bank, noop_program_id) = load_program_of_loader_v4( + &mut bank_client, + &bank_forks, &mint_keypair, &authority_keypair, - "solana_sbf_rust_noop", + "noop_program_id", ); - let (_, invoke_and_return_program_id) = load_upgradeable_program_and_advance_slot( + let (_bank, invoke_and_return_program_id) = load_program_of_loader_v4( &mut bank_client, - bank_forks.as_ref(), + &bank_forks, &mint_keypair, &authority_keypair, "solana_sbf_rust_invoke_and_return", @@ -3862,9 +3801,9 @@ fn test_program_fees() { let mut bank_client = BankClient::new_shared(bank); let authority_keypair = Keypair::new(); - let (_bank, program_id) = load_upgradeable_program_and_advance_slot( + let (_bank, program_id) = load_program_of_loader_v4( &mut bank_client, - bank_forks.as_ref(), + &bank_forks, &mint_keypair, &authority_keypair, "solana_sbf_rust_noop", @@ -3949,9 +3888,9 @@ fn test_get_minimum_delegation() { let mut bank_client = BankClient::new_shared(bank.clone()); let authority_keypair = Keypair::new(); - let (_bank, program_id) = load_upgradeable_program_and_advance_slot( + let (_bank, program_id) = load_program_of_loader_v4( &mut bank_client, - bank_forks.as_ref(), + &bank_forks, &mint_keypair, &authority_keypair, "solana_sbf_rust_get_minimum_delegation", @@ -4024,23 +3963,23 @@ fn test_cpi_account_ownership_writability() { let mut bank_client = BankClient::new_shared(bank); let authority_keypair = Keypair::new(); - let invoke_program_id = load_upgradeable_program_wrapper( - &bank_client, + let (_bank, invoke_program_id) = load_program_of_loader_v4( + &mut bank_client, + &bank_forks, &mint_keypair, &authority_keypair, "solana_sbf_rust_invoke", ); - - let invoked_program_id = load_upgradeable_program_wrapper( - &bank_client, + let (_bank, invoked_program_id) = load_program_of_loader_v4( + &mut bank_client, + &bank_forks, &mint_keypair, &authority_keypair, "solana_sbf_rust_invoked", ); - - let (bank, realloc_program_id) = load_upgradeable_program_and_advance_slot( + let (bank, realloc_program_id) = load_program_of_loader_v4( &mut bank_client, - bank_forks.as_ref(), + &bank_forks, &mint_keypair, &authority_keypair, "solana_sbf_rust_realloc", @@ -4208,16 +4147,16 @@ fn test_cpi_account_data_updates() { let mut bank_client = BankClient::new_shared(bank); let authority_keypair = Keypair::new(); - let invoke_program_id = load_upgradeable_program_wrapper( - &bank_client, + let (_bank, invoke_program_id) = load_program_of_loader_v4( + &mut bank_client, + &bank_forks, &mint_keypair, &authority_keypair, "solana_sbf_rust_invoke", ); - - let (bank, realloc_program_id) = load_upgradeable_program_and_advance_slot( + let (bank, realloc_program_id) = load_program_of_loader_v4( &mut bank_client, - bank_forks.as_ref(), + &bank_forks, &mint_keypair, &authority_keypair, "solana_sbf_rust_realloc", @@ -4366,9 +4305,9 @@ fn test_cpi_deprecated_loader_realloc() { let mut bank_client = BankClient::new_shared(bank); let authority_keypair = Keypair::new(); - let (bank, invoke_program_id) = load_upgradeable_program_and_advance_slot( + let (bank, invoke_program_id) = load_program_of_loader_v4( &mut bank_client, - bank_forks.as_ref(), + &bank_forks, &mint_keypair, &authority_keypair, "solana_sbf_rust_invoke", @@ -4511,9 +4450,9 @@ fn test_cpi_change_account_data_memory_allocation() { let mut bank_client = BankClient::new_shared(bank); let authority_keypair = Keypair::new(); - let (bank, invoke_program_id) = load_upgradeable_program_and_advance_slot( + let (bank, invoke_program_id) = load_program_of_loader_v4( &mut bank_client, - bank_forks.as_ref(), + &bank_forks, &mint_keypair, &authority_keypair, "solana_sbf_rust_invoke", @@ -4556,12 +4495,16 @@ fn test_cpi_invalid_account_info_pointers() { let mut bank_client = BankClient::new_shared(bank); let authority_keypair = Keypair::new(); - let c_invoke_program_id = - load_upgradeable_program_wrapper(&bank_client, &mint_keypair, &authority_keypair, "invoke"); - - let (bank, invoke_program_id) = load_upgradeable_program_and_advance_slot( + let (_bank, c_invoke_program_id) = load_program_of_loader_v4( &mut bank_client, - bank_forks.as_ref(), + &bank_forks, + &mint_keypair, + &authority_keypair, + "invoke", + ); + let (bank, invoke_program_id) = load_program_of_loader_v4( + &mut bank_client, + &bank_forks, &mint_keypair, &authority_keypair, "solana_sbf_rust_invoke", @@ -4626,9 +4569,9 @@ fn test_deny_executable_write() { let mut bank_client = BankClient::new_shared(bank); let authority_keypair = Keypair::new(); - let (_bank, invoke_program_id) = load_upgradeable_program_and_advance_slot( + let (_bank, invoke_program_id) = load_program_of_loader_v4( &mut bank_client, - bank_forks.as_ref(), + &bank_forks, &mint_keypair, &authority_keypair, "solana_sbf_rust_invoke", @@ -4681,9 +4624,9 @@ fn test_update_callee_account() { let mut bank_client = BankClient::new_shared(bank.clone()); let authority_keypair = Keypair::new(); - let (bank, invoke_program_id) = load_upgradeable_program_and_advance_slot( + let (bank, invoke_program_id) = load_program_of_loader_v4( &mut bank_client, - bank_forks.as_ref(), + &bank_forks, &mint_keypair, &authority_keypair, "solana_sbf_rust_invoke", @@ -4966,9 +4909,9 @@ fn test_account_info_in_account() { let mut bank_client = BankClient::new_shared(bank.clone()); let authority_keypair = Keypair::new(); - let (bank, invoke_program_id) = load_upgradeable_program_and_advance_slot( + let (bank, invoke_program_id) = load_program_of_loader_v4( &mut bank_client, - bank_forks.as_ref(), + &bank_forks, &mint_keypair, &authority_keypair, program, @@ -5024,27 +4967,21 @@ fn test_clone_account_data() { let mut bank_client = BankClient::new_shared(bank.clone()); let authority_keypair = Keypair::new(); - let (_, invoke_program_id) = load_upgradeable_program_and_advance_slot( + let (_bank, invoke_program_id) = load_program_of_loader_v4( &mut bank_client, - bank_forks.as_ref(), + &bank_forks, &mint_keypair, &authority_keypair, "solana_sbf_rust_invoke", ); - - let (bank, invoke_program_id2) = load_upgradeable_program_and_advance_slot( + let (bank, invoke_program_id2) = load_program_of_loader_v4( &mut bank_client, - bank_forks.as_ref(), + &bank_forks, &mint_keypair, &authority_keypair, "solana_sbf_rust_invoke", ); - assert_ne!(invoke_program_id, invoke_program_id2); - - println!("invoke_program_id:{invoke_program_id}"); - println!("invoke_program_id2:{invoke_program_id2}"); - let account_keypair = Keypair::new(); let mint_pubkey = mint_keypair.pubkey(); @@ -5159,9 +5096,9 @@ fn test_stack_heap_zeroed() { let mut bank_client = BankClient::new_shared(bank); let authority_keypair = Keypair::new(); - let (bank, invoke_program_id) = load_upgradeable_program_and_advance_slot( + let (bank, invoke_program_id) = load_program_of_loader_v4( &mut bank_client, - bank_forks.as_ref(), + &bank_forks, &mint_keypair, &authority_keypair, "solana_sbf_rust_invoke", @@ -5225,9 +5162,9 @@ fn test_function_call_args() { let mut bank_client = BankClient::new_shared(bank); let authority_keypair = Keypair::new(); - let (bank, program_id) = load_upgradeable_program_and_advance_slot( + let (bank, program_id) = load_program_of_loader_v4( &mut bank_client, - bank_forks.as_ref(), + &bank_forks, &mint_keypair, &authority_keypair, "solana_sbf_rust_call_args", diff --git a/programs/sbf/tests/simulation.rs b/programs/sbf/tests/simulation.rs index 62732531065915..e16d25eee2910f 100644 --- a/programs/sbf/tests/simulation.rs +++ b/programs/sbf/tests/simulation.rs @@ -6,7 +6,7 @@ use { bank::Bank, bank_client::BankClient, genesis_utils::{create_genesis_config, GenesisConfigInfo}, - loader_utils::load_upgradeable_program_and_advance_slot, + loader_utils::load_program_of_loader_v4, }, solana_runtime_transaction::runtime_transaction::RuntimeTransaction, solana_sdk::{ @@ -31,7 +31,7 @@ fn test_no_panic_banks_client() { let (bank, bank_forks) = Bank::new_with_bank_forks_for_tests(&genesis_config); let mut bank_client = BankClient::new_shared(bank.clone()); let authority_keypair = Keypair::new(); - let (bank, program_id) = load_upgradeable_program_and_advance_slot( + let (bank, program_id) = load_program_of_loader_v4( &mut bank_client, bank_forks.as_ref(), &mint_keypair, diff --git a/programs/sbf/tests/sysvar.rs b/programs/sbf/tests/sysvar.rs index 41a3d7016daffa..a54c89158bffc6 100644 --- a/programs/sbf/tests/sysvar.rs +++ b/programs/sbf/tests/sysvar.rs @@ -6,7 +6,7 @@ use { bank::Bank, bank_client::BankClient, genesis_utils::{create_genesis_config, GenesisConfigInfo}, - loader_utils::load_upgradeable_program_and_advance_slot, + loader_utils::load_program_of_loader_v4, }, solana_runtime_transaction::runtime_transaction::RuntimeTransaction, solana_sdk::{ @@ -62,7 +62,7 @@ fn test_sysvar_syscalls() { let (bank, bank_forks) = bank.wrap_with_bank_forks_for_tests(); let mut bank_client = BankClient::new_shared(bank); let authority_keypair = Keypair::new(); - let (bank, program_id) = load_upgradeable_program_and_advance_slot( + let (bank, program_id) = load_program_of_loader_v4( &mut bank_client, bank_forks.as_ref(), &mint_keypair, diff --git a/runtime/src/bank/tests.rs b/runtime/src/bank/tests.rs index 70e730affa745d..3914a1cde42295 100644 --- a/runtime/src/bank/tests.rs +++ b/runtime/src/bank/tests.rs @@ -7127,9 +7127,11 @@ fn test_bank_load_program() { #[test] fn test_bpf_loader_upgradeable_deploy_with_max_len() { - let (genesis_config, mint_keypair) = create_genesis_config_no_tx_fee(1_000_000_000); - let mut bank = Bank::new_for_tests(&genesis_config); - bank.feature_set = Arc::new(FeatureSet::all_enabled()); + let (mut genesis_config, mint_keypair) = create_genesis_config_no_tx_fee(1_000_000_000); + genesis_config + .accounts + .remove(&solana_feature_set::enable_loader_v4::id()); + let bank = Bank::new_for_tests(&genesis_config); let (bank, bank_forks) = bank.wrap_with_bank_forks_for_tests(); let mut bank_client = BankClient::new_shared(bank.clone()); @@ -13100,9 +13102,8 @@ fn test_deploy_last_epoch_slot() { let (mut genesis_config, mint_keypair) = create_genesis_config(1_000_000 * LAMPORTS_PER_SOL); genesis_config .accounts - .remove(&feature_set::disable_fees_sysvar::id()); - let mut bank = Bank::new_for_tests(&genesis_config); - bank.activate_feature(&feature_set::disable_fees_sysvar::id()); + .remove(&solana_feature_set::enable_loader_v4::id()); + let bank = Bank::new_for_tests(&genesis_config); // go to the last slot in the epoch let (bank, bank_forks) = bank.wrap_with_bank_forks_for_tests();