diff --git a/program-runtime/src/invoke_context.rs b/program-runtime/src/invoke_context.rs index 2df47155f13760..9a124167bfb1cd 100644 --- a/program-runtime/src/invoke_context.rs +++ b/program-runtime/src/invoke_context.rs @@ -924,7 +924,7 @@ macro_rules! with_mock_invoke_context { }; } -pub fn mock_process_instruction( +pub fn mock_process_instruction( loader_id: &Pubkey, mut program_indices: Vec, instruction_data: &[u8], @@ -933,6 +933,7 @@ pub fn mock_process_instruction( expected_result: Result<(), InstructionError>, process_instruction: ProcessInstructionWithContext, mut pre_adjustments: F, + mut post_adjustments: G, ) -> Vec { let mut instruction_accounts: Vec = Vec::with_capacity(instruction_account_metas.len()); @@ -976,6 +977,7 @@ pub fn mock_process_instruction( &mut ExecuteTimings::default(), ); assert_eq!(result, expected_result); + post_adjustments(&mut invoke_context); let mut transaction_accounts = transaction_context.deconstruct_without_keys().unwrap(); transaction_accounts.pop(); transaction_accounts diff --git a/programs/bpf_loader/src/lib.rs b/programs/bpf_loader/src/lib.rs index 2855bcae03eaec..6a259ee64106eb 100644 --- a/programs/bpf_loader/src/lib.rs +++ b/programs/bpf_loader/src/lib.rs @@ -1696,6 +1696,7 @@ mod tests { expected_result, super::process_instruction, |_invoke_context| {}, + |_invoke_context| {}, ) } @@ -1982,6 +1983,7 @@ mod tests { |invoke_context| { invoke_context.mock_set_remaining(0); }, + |_invoke_context| {}, ); // Case: Account not a program @@ -2524,6 +2526,7 @@ mod tests { expected_result, super::process_instruction, |_invoke_context| {}, + |_invoke_context| {}, ) } diff --git a/programs/config/src/config_processor.rs b/programs/config/src/config_processor.rs index 72d0b6545b6152..1431b314ad217e 100644 --- a/programs/config/src/config_processor.rs +++ b/programs/config/src/config_processor.rs @@ -165,6 +165,7 @@ mod tests { expected_result, super::process_instruction, |_invoke_context| {}, + |_invoke_context| {}, ) } diff --git a/programs/loader-v3/src/lib.rs b/programs/loader-v3/src/lib.rs index 35513977cfb26b..a4c59288716e13 100644 --- a/programs/loader-v3/src/lib.rs +++ b/programs/loader-v3/src/lib.rs @@ -655,6 +655,7 @@ mod tests { expected_result, super::process_instruction, |_invoke_context| {}, + |_invoke_context| {}, ) } diff --git a/programs/sbf/tests/programs.rs b/programs/sbf/tests/programs.rs index a0604789b1afd0..a06363a947680d 100644 --- a/programs/sbf/tests/programs.rs +++ b/programs/sbf/tests/programs.rs @@ -19,9 +19,7 @@ use { parse_bpf_upgradeable_loader, BpfUpgradeableLoaderAccountType, }, solana_ledger::token_balances::collect_token_balances, - solana_program_runtime::{ - compute_budget::ComputeBudget, invoke_context::InvokeContext, timings::ExecuteTimings, - }, + solana_program_runtime::{compute_budget::ComputeBudget, timings::ExecuteTimings}, solana_rbpf::vm::ContextObject, solana_runtime::{ bank::{ @@ -86,7 +84,7 @@ use { system_program, transaction::{SanitizedTransaction, Transaction, TransactionError}, }, - std::{str::FromStr, sync::Arc, time::Duration}, + std::{cell::RefCell, str::FromStr, sync::Arc, time::Duration}, }; #[cfg(feature = "sbf_rust")] @@ -1370,8 +1368,8 @@ fn assert_instruction_count() { ("noop++", 5), ("relative_call", 210), ("return_data", 980), - ("sanity", 3259), - ("sanity++", 3159), + ("sanity", 2377), + ("sanity++", 2277), ("secp256k1_recover", 25383), ("sha", 1355), ("struct_pass", 108), @@ -1385,7 +1383,6 @@ fn assert_instruction_count() { ("solana_sbf_rust_alloc", 5067), ("solana_sbf_rust_custom_heap", 398), ("solana_sbf_rust_dep_crate", 2), - ("solana_sbf_rust_external_spend", 288), ("solana_sbf_rust_iter", 1013), ("solana_sbf_rust_many_args", 1289), ("solana_sbf_rust_mem", 2067), @@ -1393,7 +1390,7 @@ fn assert_instruction_count() { ("solana_sbf_rust_noop", 275), ("solana_sbf_rust_param_passing", 146), ("solana_sbf_rust_rand", 378), - ("solana_sbf_rust_sanity", 10759), + ("solana_sbf_rust_sanity", 51931), ("solana_sbf_rust_secp256k1_recover", 91185), ("solana_sbf_rust_sha", 24059), ]); @@ -1407,7 +1404,7 @@ fn assert_instruction_count() { (program_key, AccountSharedData::new(0, 0, &loader_id)), ( Pubkey::new_unique(), - AccountSharedData::new(0, 8, &program_key), + AccountSharedData::new(0, 0, &program_key), ), ]; let instruction_accounts = vec![AccountMeta { @@ -1419,11 +1416,8 @@ fn assert_instruction_count() { .1 .set_data_from_slice(&load_program_from_file(program_name)); transaction_accounts[0].1.set_executable(true); - transaction_accounts[1] - .1 - .set_state(expected_consumption) - .unwrap(); + let prev_compute_meter = RefCell::new(0); print!(" {:36} {:8}", program_name, *expected_consumption); mock_process_instruction( &loader_id, @@ -1432,29 +1426,23 @@ fn assert_instruction_count() { transaction_accounts, instruction_accounts, Ok(()), - |invoke_context: &mut InvokeContext| { - let expected_consumption: u64 = invoke_context - .transaction_context - .get_current_instruction_context() - .unwrap() - .try_borrow_instruction_account(&invoke_context.transaction_context, 0) - .unwrap() - .get_state() - .unwrap(); - let prev_compute_meter = invoke_context.get_remaining(); - let _result = solana_bpf_loader_program::process_instruction(invoke_context); - let consumption = prev_compute_meter.saturating_sub(invoke_context.get_remaining()); - let diff: i64 = consumption as i64 - expected_consumption as i64; + solana_bpf_loader_program::process_instruction, + |invoke_context| { + *prev_compute_meter.borrow_mut() = invoke_context.get_remaining(); + }, + |invoke_context| { + let consumption = prev_compute_meter + .borrow() + .saturating_sub(invoke_context.get_remaining()); + let diff: i64 = consumption as i64 - *expected_consumption as i64; println!( "{:6} {:+5} ({:+3.0}%)", consumption, diff, - 100.0_f64 * consumption as f64 / expected_consumption as f64 - 100.0_f64, + 100.0_f64 * consumption as f64 / *expected_consumption as f64 - 100.0_f64, ); - assert_eq!(consumption, expected_consumption); - Ok(()) + assert_eq!(consumption, *expected_consumption); }, - |_invoke_context| {}, ); } } diff --git a/programs/stake/src/stake_instruction.rs b/programs/stake/src/stake_instruction.rs index e08a7f04521476..f9c7e87d27d61b 100644 --- a/programs/stake/src/stake_instruction.rs +++ b/programs/stake/src/stake_instruction.rs @@ -591,6 +591,7 @@ mod tests { |invoke_context| { invoke_context.feature_set = Arc::clone(&feature_set); }, + |_invoke_context| {}, ) } @@ -6340,17 +6341,16 @@ mod tests { transaction_accounts, instruction_accounts, Ok(()), + super::process_instruction, + |invoke_context| { + invoke_context.feature_set = Arc::clone(&feature_set); + }, |invoke_context| { - super::process_instruction(invoke_context)?; let expected_minimum_delegation = crate::get_minimum_delegation(&invoke_context.feature_set).to_le_bytes(); let actual_minimum_delegation = invoke_context.transaction_context.get_return_data().1; assert_eq!(expected_minimum_delegation, actual_minimum_delegation); - Ok(()) - }, - |invoke_context| { - invoke_context.feature_set = Arc::clone(&feature_set); }, ); } diff --git a/programs/vote/src/vote_processor.rs b/programs/vote/src/vote_processor.rs index 87ddeaf5437d2c..b9a26847715f19 100644 --- a/programs/vote/src/vote_processor.rs +++ b/programs/vote/src/vote_processor.rs @@ -322,6 +322,7 @@ mod tests { expected_result, super::process_instruction, |_invoke_context| {}, + |_invoke_context| {}, ) } @@ -342,6 +343,7 @@ mod tests { |invoke_context| { invoke_context.feature_set = std::sync::Arc::new(FeatureSet::default()); }, + |_invoke_context| {}, ) } diff --git a/runtime/src/bank/tests.rs b/runtime/src/bank/tests.rs index 37ceeb646c578a..89e84049ec9bb9 100644 --- a/runtime/src/bank/tests.rs +++ b/runtime/src/bank/tests.rs @@ -7988,6 +7988,7 @@ fn test_bpf_loader_upgradeable_deploy_with_max_len() { Ok(()), solana_bpf_loader_program::process_instruction, |_invoke_context| {}, + |_invoke_context| {}, ); // Test initialized program account diff --git a/runtime/src/system_instruction_processor.rs b/runtime/src/system_instruction_processor.rs index 5469455ecde814..367238b747d6e2 100644 --- a/runtime/src/system_instruction_processor.rs +++ b/runtime/src/system_instruction_processor.rs @@ -640,6 +640,7 @@ mod tests { expected_result, super::process_instruction, |_invoke_context| {}, + |_invoke_context| {}, ) } @@ -1831,6 +1832,7 @@ mod tests { |invoke_context: &mut InvokeContext| { invoke_context.blockhash = hash(&serialize(&0).unwrap()); }, + |_invoke_context| {}, ); } @@ -2181,6 +2183,7 @@ mod tests { |invoke_context: &mut InvokeContext| { invoke_context.blockhash = hash(&serialize(&0).unwrap()); }, + |_invoke_context| {}, ); }