From 9160d94ded06136e6eb602aadbce2e28f1a1d065 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] Disables new deployments on loader-v3 when the feature enable_loader_v4 is enabled. --- cli/tests/program.rs | 148 ++++++++++++++++++++++++++++----- programs/bpf_loader/src/lib.rs | 12 +++ runtime/src/bank/tests.rs | 10 ++- 3 files changed, 145 insertions(+), 25 deletions(-) diff --git a/cli/tests/program.rs b/cli/tests/program.rs index 6bec3bcc28b36f..230e7bfb85722e 100644 --- a/cli/tests/program.rs +++ b/cli/tests/program.rs @@ -23,7 +23,7 @@ use { bpf_loader_upgradeable::{self, UpgradeableLoaderState}, commitment_config::CommitmentConfig, compute_budget::{self, ComputeBudgetInstruction}, - feature_set::enable_alt_bn128_syscall, + feature_set::{enable_alt_bn128_syscall, enable_loader_v4}, fee_calculator::FeeRateGovernor, pubkey::Pubkey, rent::Rent, @@ -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()); @@ -2835,6 +2936,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/programs/bpf_loader/src/lib.rs b/programs/bpf_loader/src/lib.rs index 400806bb4c98bd..26e26506c6b738 100644 --- a/programs/bpf_loader/src/lib.rs +++ b/programs/bpf_loader/src/lib.rs @@ -36,6 +36,7 @@ use { entrypoint::{MAX_PERMITTED_DATA_INCREASE, SUCCESS}, feature_set::{ bpf_account_data_direct_mapping, enable_bpf_loader_set_authority_checked_ix, + enable_loader_v4, }, instruction::{AccountMeta, InstructionError}, loader_upgradeable_instruction::UpgradeableLoaderInstruction, @@ -525,6 +526,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)?, @@ -1614,6 +1623,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| {}, diff --git a/runtime/src/bank/tests.rs b/runtime/src/bank/tests.rs index dc8175cebd9550..7ddd32d775e695 100644 --- a/runtime/src/bank/tests.rs +++ b/runtime/src/bank/tests.rs @@ -322,7 +322,11 @@ fn test_bank_new() { } pub(crate) fn create_simple_test_bank(lamports: u64) -> Bank { - let (genesis_config, _mint_keypair) = create_genesis_config(lamports); + let (mut genesis_config, _mint_keypair) = create_genesis_config(lamports); + genesis_config + .accounts + .remove(&feature_set::enable_loader_v4::id()) + .unwrap(); Bank::new_for_tests(&genesis_config) } @@ -7010,7 +7014,9 @@ fn test_bank_load_program() { 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 feature_set = FeatureSet::all_enabled(); + feature_set.deactivate(&feature_set::enable_loader_v4::id()); + bank.feature_set = Arc::new(feature_set); let (bank, bank_forks) = bank.wrap_with_bank_forks_for_tests(); let mut bank_client = BankClient::new_shared(bank.clone());