diff --git a/ledger/src/blockstore_processor.rs b/ledger/src/blockstore_processor.rs index 76c72e65eb6152..b3b7966170e879 100644 --- a/ledger/src/blockstore_processor.rs +++ b/ledger/src/blockstore_processor.rs @@ -1809,7 +1809,7 @@ pub mod tests { matches::assert_matches, rand::{thread_rng, Rng}, solana_entry::entry::{create_ticks, next_entry, next_entry_mut}, - solana_program_runtime::declare_process_instruction, + solana_program_runtime::{builtin_program::create_builtin, declare_process_instruction}, solana_runtime::{ genesis_utils::{ self, create_genesis_config_with_vote_accounts, ValidatorVoteKeypairs, @@ -2971,7 +2971,10 @@ pub mod tests { let mock_program_id = solana_sdk::pubkey::new_rand(); let mut bank = Bank::new_for_tests(&genesis_config); - bank.add_builtin("mock_processor", &mock_program_id, mock_processor_ok); + bank.add_builtin( + mock_program_id, + create_builtin("mockup".to_string(), mock_processor_ok), + ); let tx = Transaction::new_signed_with_payer( &[Instruction::new_with_bincode( @@ -3012,7 +3015,10 @@ pub mod tests { (0..get_instruction_errors().len()).for_each(|err| { let mut bank = Bank::new_for_tests(&genesis_config); - bank.add_builtin("mock_processor", &mock_program_id, mock_processor_err); + bank.add_builtin( + mock_program_id, + create_builtin("mockup".to_string(), mock_processor_err), + ); let tx = Transaction::new_signed_with_payer( &[Instruction::new_with_bincode( diff --git a/program-test/src/lib.rs b/program-test/src/lib.rs index f93088f0d80f65..43d8dc7e7120bf 100644 --- a/program-test/src/lib.rs +++ b/program-test/src/lib.rs @@ -11,7 +11,7 @@ use { solana_banks_server::banks_server::start_local_server, solana_bpf_loader_program::serialization::serialize_parameters, solana_program_runtime::{ - builtin_program::{BuiltinProgram, BuiltinPrograms, ProcessInstructionWithContext}, + builtin_program::{create_builtin, BuiltinPrograms, ProcessInstructionWithContext}, compute_budget::ComputeBudget, ic_msg, stable_log, timings::ExecuteTimings, @@ -692,11 +692,10 @@ impl ProgramTest { process_instruction: ProcessInstructionWithContext, ) { info!("\"{}\" builtin program", program_name); - self.builtin_programs.vec.push(BuiltinProgram { - name: program_name.to_string(), + self.builtin_programs.vec.push(( program_id, - process_instruction, - }); + create_builtin(program_name.to_string(), process_instruction), + )); } /// Deactivate a runtime feature. @@ -791,12 +790,8 @@ impl ProgramTest { } // User-supplied additional builtins - for builtin in self.builtin_programs.vec.iter() { - bank.add_builtin( - &builtin.name, - &builtin.program_id, - builtin.process_instruction, - ); + for (program_id, builtin) in self.builtin_programs.vec.iter() { + bank.add_builtin(*program_id, builtin.clone()); } for (address, account) in self.accounts.iter() { diff --git a/runtime/benches/bank.rs b/runtime/benches/bank.rs index b30f2309a53554..add7b2ede26e1f 100644 --- a/runtime/benches/bank.rs +++ b/runtime/benches/bank.rs @@ -5,7 +5,7 @@ extern crate test; use { log::*, - solana_program_runtime::declare_process_instruction, + solana_program_runtime::{builtin_program::create_builtin, declare_process_instruction}, solana_runtime::{ bank::{test_utils::goto_end_of_slot, *}, bank_client::BankClient, @@ -132,9 +132,8 @@ fn do_bench_transactions( let mut bank = Bank::new_from_parent(&Arc::new(bank), &Pubkey::default(), 1); bank.add_builtin( - "builtin_program", - &Pubkey::from(BUILTIN_PROGRAM_ID), - process_instruction, + Pubkey::from(BUILTIN_PROGRAM_ID), + create_builtin("mockup".to_string(), process_instruction), ); bank.add_builtin_account("solana_noop_program", &Pubkey::from(NOOP_PROGRAM_ID), false); let bank = Arc::new(bank); diff --git a/runtime/src/bank/tests.rs b/runtime/src/bank/tests.rs index d3a53214af064f..86e202a0cb6c3f 100644 --- a/runtime/src/bank/tests.rs +++ b/runtime/src/bank/tests.rs @@ -33,6 +33,7 @@ use { serde::{Deserialize, Serialize}, solana_logger, solana_program_runtime::{ + builtin_program::create_builtin, compute_budget::{self, ComputeBudget, MAX_COMPUTE_UNIT_LIMIT}, declare_process_instruction, executor_cache::TransactionExecutorCache, @@ -1380,7 +1381,10 @@ fn test_rent_complex() { root_bank.restore_old_behavior_for_fragile_tests(); let root_bank = Arc::new(root_bank); let mut bank = create_child_bank_for_rent_test(&root_bank, &genesis_config); - bank.add_builtin("mock_program", &mock_program_id, process_instruction); + bank.add_builtin( + mock_program_id, + create_builtin("mockup".to_string(), process_instruction), + ); assert_eq!(bank.last_blockhash(), genesis_config.hash()); @@ -4817,9 +4821,8 @@ fn test_add_builtin() { assert!(bank.get_account(&mock_vote_program_id()).is_none()); bank.add_builtin( - "mock_vote_program", - &mock_vote_program_id(), - process_instruction, + mock_vote_program_id(), + create_builtin("mockup".to_string(), process_instruction), ); assert!(bank.get_account(&mock_vote_program_id()).is_some()); @@ -4894,9 +4897,8 @@ fn test_add_duplicate_static_program() { let vote_loader_account = bank.get_account(&solana_vote_program::id()).unwrap(); bank.add_builtin( - "solana_vote_program", - &solana_vote_program::id(), - process_instruction, + solana_vote_program::id(), + create_builtin("mockup".to_string(), process_instruction), ); let new_vote_loader_account = bank.get_account(&solana_vote_program::id()).unwrap(); // Vote loader account should not be updated since it was included in the genesis config. @@ -4948,8 +4950,14 @@ fn test_add_instruction_processor_for_existing_unrelated_accounts() { continue; } - bank.add_builtin("mock_program1", &vote_id, process_instruction); - bank.add_builtin("mock_program2", &stake_id, process_instruction); + bank.add_builtin( + vote_id, + create_builtin("mock_program1".to_string(), process_instruction), + ); + bank.add_builtin( + stake_id, + create_builtin("mock_program2".to_string(), process_instruction), + ); { let stakes = bank.stakes_cache.stakes(); assert!(stakes.vote_accounts().as_ref().is_empty()); @@ -4972,8 +4980,14 @@ fn test_add_instruction_processor_for_existing_unrelated_accounts() { // Re-adding builtin programs should be no-op bank.update_accounts_hash_for_tests(); let old_hash = bank.get_accounts_hash().unwrap(); - bank.add_builtin("mock_program1", &vote_id, process_instruction); - bank.add_builtin("mock_program2", &stake_id, process_instruction); + bank.add_builtin( + vote_id, + create_builtin("mockup".to_string(), process_instruction), + ); + bank.add_builtin( + stake_id, + create_builtin("mockup".to_string(), process_instruction), + ); add_root_and_flush_write_cache(&bank); bank.update_accounts_hash_for_tests(); let new_hash = bank.get_accounts_hash().unwrap(); @@ -6224,7 +6238,10 @@ fn test_transaction_with_duplicate_accounts_in_instruction() { }); let mock_program_id = Pubkey::from([2u8; 32]); - bank.add_builtin("mock_program", &mock_program_id, process_instruction); + bank.add_builtin( + mock_program_id, + create_builtin("mockup".to_string(), process_instruction), + ); let from_pubkey = solana_sdk::pubkey::new_rand(); let to_pubkey = solana_sdk::pubkey::new_rand(); @@ -6260,7 +6277,10 @@ fn test_transaction_with_program_ids_passed_to_programs() { let mut bank = Bank::new_for_tests(&genesis_config); let mock_program_id = Pubkey::from([2u8; 32]); - bank.add_builtin("mock_program", &mock_program_id, process_instruction); + bank.add_builtin( + mock_program_id, + create_builtin("mockup".to_string(), process_instruction), + ); let from_pubkey = solana_sdk::pubkey::new_rand(); let to_pubkey = solana_sdk::pubkey::new_rand(); @@ -6312,7 +6332,10 @@ fn test_account_ids_after_program_ids() { tx.message.account_keys.push(solana_sdk::pubkey::new_rand()); - bank.add_builtin("mock_vote", &solana_vote_program::id(), process_instruction); + bank.add_builtin( + solana_vote_program::id(), + create_builtin("mockup".to_string(), process_instruction), + ); let result = bank.process_transaction(&tx); assert_eq!(result, Ok(())); let account = bank.get_account(&solana_vote_program::id()).unwrap(); @@ -6362,7 +6385,10 @@ fn test_duplicate_account_key() { AccountMeta::new(to_pubkey, false), ]; - bank.add_builtin("mock_vote", &solana_vote_program::id(), process_instruction); + bank.add_builtin( + solana_vote_program::id(), + create_builtin("mockup".to_string(), process_instruction), + ); let instruction = Instruction::new_with_bincode(solana_vote_program::id(), &10, account_metas); let mut tx = Transaction::new_signed_with_payer( @@ -6391,7 +6417,10 @@ fn test_process_transaction_with_too_many_account_locks() { AccountMeta::new(to_pubkey, false), ]; - bank.add_builtin("mock_vote", &solana_vote_program::id(), process_instruction); + bank.add_builtin( + solana_vote_program::id(), + create_builtin("mockup".to_string(), process_instruction), + ); let instruction = Instruction::new_with_bincode(solana_vote_program::id(), &10, account_metas); let mut tx = Transaction::new_signed_with_payer( @@ -6424,7 +6453,10 @@ fn test_program_id_as_payer() { AccountMeta::new(to_pubkey, false), ]; - bank.add_builtin("mock_vote", &solana_vote_program::id(), process_instruction); + bank.add_builtin( + solana_vote_program::id(), + create_builtin("mockup".to_string(), process_instruction), + ); let instruction = Instruction::new_with_bincode(solana_vote_program::id(), &10, account_metas); let mut tx = Transaction::new_signed_with_payer( @@ -6467,7 +6499,10 @@ fn test_ref_account_key_after_program_id() { AccountMeta::new(to_pubkey, false), ]; - bank.add_builtin("mock_vote", &solana_vote_program::id(), process_instruction); + bank.add_builtin( + solana_vote_program::id(), + create_builtin("mockup".to_string(), process_instruction), + ); let instruction = Instruction::new_with_bincode(solana_vote_program::id(), &10, account_metas); let mut tx = Transaction::new_signed_with_payer( @@ -6498,7 +6533,7 @@ fn test_fuzz_instructions() { .map(|i| { let key = solana_sdk::pubkey::new_rand(); let name = format!("program{i:?}"); - bank.add_builtin(&name, &key, process_instruction); + bank.add_builtin(key, create_builtin(name.clone(), process_instruction)); (key, name.as_bytes().to_vec()) }) .collect(); @@ -6704,7 +6739,10 @@ fn test_same_program_id_uses_unqiue_executable_accounts() { // Add a new program let program1_pubkey = solana_sdk::pubkey::new_rand(); - bank.add_builtin("program", &program1_pubkey, process_instruction); + bank.add_builtin( + program1_pubkey, + create_builtin("mockup".to_string(), process_instruction), + ); // Add a new program owned by the first let program2_pubkey = solana_sdk::pubkey::new_rand(); @@ -6919,15 +6957,17 @@ fn test_add_builtin_no_overwrite() { )); assert_eq!(bank.get_account_modified_slot(&program_id), None); - Arc::get_mut(&mut bank) - .unwrap() - .add_builtin("mock_program", &program_id, process_instruction); + Arc::get_mut(&mut bank).unwrap().add_builtin( + program_id, + create_builtin("mockup".to_string(), process_instruction), + ); assert_eq!(bank.get_account_modified_slot(&program_id).unwrap().1, slot); let mut bank = Arc::new(new_from_parent(&bank)); - Arc::get_mut(&mut bank) - .unwrap() - .add_builtin("mock_program", &program_id, process_instruction); + Arc::get_mut(&mut bank).unwrap().add_builtin( + program_id, + create_builtin("mockup".to_string(), process_instruction), + ); assert_eq!(bank.get_account_modified_slot(&program_id).unwrap().1, slot); } @@ -6943,15 +6983,17 @@ fn test_add_builtin_loader_no_overwrite() { )); assert_eq!(bank.get_account_modified_slot(&loader_id), None); - Arc::get_mut(&mut bank) - .unwrap() - .add_builtin("mock_program", &loader_id, process_instruction); + Arc::get_mut(&mut bank).unwrap().add_builtin( + loader_id, + create_builtin("mockup".to_string(), process_instruction), + ); assert_eq!(bank.get_account_modified_slot(&loader_id).unwrap().1, slot); let mut bank = Arc::new(new_from_parent(&bank)); - Arc::get_mut(&mut bank) - .unwrap() - .add_builtin("mock_program", &loader_id, process_instruction); + Arc::get_mut(&mut bank).unwrap().add_builtin( + loader_id, + create_builtin("mockup".to_string(), process_instruction), + ); assert_eq!(bank.get_account_modified_slot(&loader_id).unwrap().1, slot); } @@ -9694,7 +9736,10 @@ fn test_tx_return_data() { let mock_program_id = Pubkey::from([2u8; 32]); let blockhash = bank.last_blockhash(); - bank.add_builtin("mock_program", &mock_program_id, process_instruction); + bank.add_builtin( + mock_program_id, + create_builtin("mockup".to_string(), process_instruction), + ); for index in [ None, @@ -9883,7 +9928,10 @@ fn test_transfer_sysvar() { }); let program_id = solana_sdk::pubkey::new_rand(); - bank.add_builtin("mock_program1", &program_id, process_instruction); + bank.add_builtin( + program_id, + create_builtin("mockup".to_string(), process_instruction), + ); let blockhash = bank.last_blockhash(); #[allow(deprecated)] @@ -10095,7 +10143,10 @@ fn test_compute_budget_program_noop() { Ok(()) }); let program_id = solana_sdk::pubkey::new_rand(); - bank.add_builtin("mock_program", &program_id, process_instruction); + bank.add_builtin( + program_id, + create_builtin("mockup".to_string(), process_instruction), + ); let message = Message::new( &[ @@ -10138,7 +10189,10 @@ fn test_compute_request_instruction() { Ok(()) }); let program_id = solana_sdk::pubkey::new_rand(); - bank.add_builtin("mock_program", &program_id, process_instruction); + bank.add_builtin( + program_id, + create_builtin("mockup".to_string(), process_instruction), + ); let message = Message::new( &[ @@ -10188,7 +10242,10 @@ fn test_failed_compute_request_instruction() { Ok(()) }); let program_id = solana_sdk::pubkey::new_rand(); - bank.add_builtin("mock_program", &program_id, process_instruction); + bank.add_builtin( + program_id, + create_builtin("mockup".to_string(), process_instruction), + ); // This message will not be executed because the compute budget request is invalid let message0 = Message::new( @@ -10863,9 +10920,8 @@ fn test_invalid_rent_state_changes_existing_accounts() { let mut bank = Bank::new_for_tests(&genesis_config); bank.add_builtin( - "mock_program", - &mock_program_id, - mock_transfer_process_instruction, + mock_program_id, + create_builtin("mockup".to_string(), mock_transfer_process_instruction), ); let recent_blockhash = bank.last_blockhash(); @@ -10950,9 +11006,8 @@ fn test_invalid_rent_state_changes_new_accounts() { let mut bank = Bank::new_for_tests(&genesis_config); bank.add_builtin( - "mock_program", - &mock_program_id, - mock_transfer_process_instruction, + mock_program_id, + create_builtin("mockup".to_string(), mock_transfer_process_instruction), ); let recent_blockhash = bank.last_blockhash(); @@ -11013,9 +11068,8 @@ fn test_drained_created_account() { let mut bank = Bank::new_for_tests(&genesis_config); bank.add_builtin( - "mock_program", - &mock_program_id, - mock_transfer_process_instruction, + mock_program_id, + create_builtin("mockup".to_string(), mock_transfer_process_instruction), ); let recent_blockhash = bank.last_blockhash(); @@ -11668,9 +11722,8 @@ fn test_resize_and_rent() { let mock_program_id = Pubkey::new_unique(); bank.add_builtin( - "mock_realloc_program", - &mock_program_id, - mock_realloc_process_instruction, + mock_program_id, + create_builtin("mockup".to_string(), mock_realloc_process_instruction), ); let recent_blockhash = bank.last_blockhash(); @@ -11943,9 +11996,8 @@ fn test_accounts_data_size_and_resize_transactions() { let mut bank = Bank::new_for_tests(&genesis_config); let mock_program_id = Pubkey::new_unique(); bank.add_builtin( - "mock_realloc_program", - &mock_program_id, - mock_realloc_process_instruction, + mock_program_id, + create_builtin("mockup".to_string(), mock_realloc_process_instruction), ); let recent_blockhash = bank.last_blockhash();