diff --git a/program-runtime/src/invoke_context.rs b/program-runtime/src/invoke_context.rs index 7fcf67d9868576..2c0c6e9d2a641f 100644 --- a/program-runtime/src/invoke_context.rs +++ b/program-runtime/src/invoke_context.rs @@ -197,7 +197,7 @@ pub struct InvokeContext<'a> { pub timings: ExecuteDetailsTimings, pub blockhash: Hash, pub lamports_per_signature: u64, - pub sibling_instructions: Vec, + pub processed_inner_instructions: Vec, } impl<'a> InvokeContext<'a> { @@ -234,7 +234,7 @@ impl<'a> InvokeContext<'a> { timings: ExecuteDetailsTimings::default(), blockhash, lamports_per_signature, - sibling_instructions: Vec::new(), + processed_inner_instructions: Vec::new(), } } @@ -817,7 +817,7 @@ impl<'a> InvokeContext<'a> { if let Some(instruction_recorder) = &self.instruction_recorder { instruction_recorder.borrow_mut().begin_next_recording(); } - self.sibling_instructions.clear(); + self.processed_inner_instructions.clear(); } else { // Verify the calling program hasn't misbehaved let mut verify_caller_time = Measure::start("verify_caller_time"); @@ -1016,19 +1016,19 @@ impl<'a> InvokeContext<'a> { &self.sysvar_cache } - // Push a sibling instruction - pub fn add_sibling_instruction(&mut self, instruction: Instruction) { - self.sibling_instructions.push(instruction); + // Push a processed inner instruction + pub fn add_processed_inner_instruction(&mut self, instruction: Instruction) { + self.processed_inner_instructions.push(instruction); } - /// Get a sibling instruction, reverse ordered or last added is index 0 - pub fn get_sibling_instruction(&self, index: usize) -> Option<&Instruction> { + /// Get a processed inner instruction, reverse ordered list, where last added is index 0 + pub fn get_processed_inner_instruction(&self, index: usize) -> Option<&Instruction> { let index = self - .sibling_instructions + .processed_inner_instructions .len() .checked_sub(1)? .checked_sub(index)?; - self.sibling_instructions.get(index) + self.processed_inner_instructions.get(index) } } diff --git a/programs/bpf/Cargo.lock b/programs/bpf/Cargo.lock index f6dcd06d545518..992b850bf0762c 100644 --- a/programs/bpf/Cargo.lock +++ b/programs/bpf/Cargo.lock @@ -2819,6 +2819,13 @@ dependencies = [ "solana-program 1.10.0", ] +[[package]] +name = "solana-bpf-rust-inner-instructions" +version = "1.10.0" +dependencies = [ + "solana-program 1.10.0", +] + [[package]] name = "solana-bpf-rust-instruction-introspection" version = "1.10.0" @@ -3001,13 +3008,6 @@ dependencies = [ "solana-program 1.10.0", ] -[[package]] -name = "solana-bpf-rust-sibling-instructions" -version = "1.10.0" -dependencies = [ - "solana-program 1.10.0", -] - [[package]] name = "solana-bpf-rust-spoof1" version = "1.10.0" diff --git a/programs/bpf/Cargo.toml b/programs/bpf/Cargo.toml index a1934801b0e412..b255daeb783255 100644 --- a/programs/bpf/Cargo.toml +++ b/programs/bpf/Cargo.toml @@ -58,6 +58,7 @@ members = [ "rust/log_data", "rust/external_spend", "rust/finalize", + "rust/inner_instruction", "rust/instruction_introspection", "rust/invoke", "rust/invoke_and_error", @@ -81,7 +82,6 @@ members = [ "rust/sanity", "rust/secp256k1_recover", "rust/sha", - "rust/sibling_instruction", "rust/spoof1", "rust/spoof1_system", "rust/sysvar", diff --git a/programs/bpf/build.rs b/programs/bpf/build.rs index 398b933807ee4f..96c6c9ae781470 100644 --- a/programs/bpf/build.rs +++ b/programs/bpf/build.rs @@ -70,6 +70,7 @@ fn main() { "log_data", "external_spend", "finalize", + "inner_instruction", "instruction_introspection", "invoke", "invoke_and_error", @@ -91,7 +92,6 @@ fn main() { "sanity", "secp256k1_recover", "sha", - "sibling_instruction", "spoof1", "spoof1_system", "upgradeable", diff --git a/programs/bpf/rust/sibling_instruction/Cargo.toml b/programs/bpf/rust/inner_instruction/Cargo.toml similarity index 92% rename from programs/bpf/rust/sibling_instruction/Cargo.toml rename to programs/bpf/rust/inner_instruction/Cargo.toml index 951a3f799fdbda..cbe3c8477be7a0 100644 --- a/programs/bpf/rust/sibling_instruction/Cargo.toml +++ b/programs/bpf/rust/inner_instruction/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "solana-bpf-rust-sibling-instructions" +name = "solana-bpf-rust-inner-instructions" version = "1.10.0" description = "Solana BPF test program written in Rust" authors = ["Solana Maintainers "] diff --git a/programs/bpf/rust/sibling_instruction/src/lib.rs b/programs/bpf/rust/inner_instruction/src/lib.rs similarity index 71% rename from programs/bpf/rust/sibling_instruction/src/lib.rs rename to programs/bpf/rust/inner_instruction/src/lib.rs index a0e871dce759e5..c517a31c1ed1d6 100644 --- a/programs/bpf/rust/sibling_instruction/src/lib.rs +++ b/programs/bpf/rust/inner_instruction/src/lib.rs @@ -1,4 +1,4 @@ -//! Example Rust-based BPF program that uses sol_get_sibling_instruction syscall +//! Example Rust-based BPF program that uses sol_get_processed_inner_instruction syscall #![cfg(feature = "program")] @@ -6,7 +6,7 @@ use solana_program::{ account_info::AccountInfo, entrypoint, entrypoint::ProgramResult, - instruction::{get_sibling_instruction, AccountMeta, Instruction}, + instruction::{get_processed_inner_instruction, AccountMeta, Instruction}, msg, program::invoke, pubkey::Pubkey, @@ -18,7 +18,7 @@ fn process_instruction( accounts: &[AccountInfo], instruction_data: &[u8], ) -> ProgramResult { - msg!("sibling"); + msg!("inner"); // account 0 is mint // account 1 is noop @@ -51,11 +51,11 @@ fn process_instruction( invoke(&instruction1, accounts)?; invoke(&instruction0, accounts)?; - assert_eq!(Some(instruction0), get_sibling_instruction(0)); - assert_eq!(Some(instruction1), get_sibling_instruction(1)); - assert_eq!(Some(instruction2), get_sibling_instruction(2)); - assert_eq!(Some(instruction3), get_sibling_instruction(3)); - assert!(get_sibling_instruction(4).is_none()); + assert_eq!(Some(instruction0), get_processed_inner_instruction(0)); + assert_eq!(Some(instruction1), get_processed_inner_instruction(1)); + assert_eq!(Some(instruction2), get_processed_inner_instruction(2)); + assert_eq!(Some(instruction3), get_processed_inner_instruction(3)); + assert!(get_processed_inner_instruction(4).is_none()); Ok(()) } diff --git a/programs/bpf/tests/programs.rs b/programs/bpf/tests/programs.rs index cd86f12af0600a..9279eecc99f00a 100644 --- a/programs/bpf/tests/programs.rs +++ b/programs/bpf/tests/programs.rs @@ -3331,7 +3331,7 @@ fn test_program_bpf_realloc_invoke() { #[test] #[cfg(any(feature = "bpf_rust"))] -fn test_program_bpf_sibling_instruction() { +fn test_program_bpf_processed_inner_instruction() { solana_logger::setup(); let GenesisConfigInfo { @@ -3349,7 +3349,7 @@ fn test_program_bpf_sibling_instruction() { &bank_client, &bpf_loader::id(), &mint_keypair, - "solana_bpf_rust_sibling_instructions", + "solana_bpf_rust_inner_instructions", ); let noop_program_id = load_bpf_program( &bank_client, diff --git a/programs/bpf_loader/src/syscalls.rs b/programs/bpf_loader/src/syscalls.rs index aa70b1605d742a..48e9c669970ec0 100644 --- a/programs/bpf_loader/src/syscalls.rs +++ b/programs/bpf_loader/src/syscalls.rs @@ -22,14 +22,14 @@ use { blake3, bpf_loader, bpf_loader_deprecated, bpf_loader_upgradeable, entrypoint::{BPF_ALIGN_OF_U128, MAX_PERMITTED_DATA_INCREASE, SUCCESS}, feature_set::{ - self, blake3_syscall_enabled, disable_fees_sysvar, do_support_realloc, - fixed_memcpy_nonoverlapping_check, libsecp256k1_0_5_upgrade_enabled, - prevent_calling_precompiles_as_programs, return_data_syscall_enabled, - secp256k1_recover_syscall_enabled, sol_log_data_syscall_enabled, - update_syscall_base_costs, add_get_sibling_instruction_syscall + self, add_get_processed_inner_instruction_syscall, blake3_syscall_enabled, + disable_fees_sysvar, do_support_realloc, fixed_memcpy_nonoverlapping_check, + libsecp256k1_0_5_upgrade_enabled, prevent_calling_precompiles_as_programs, + return_data_syscall_enabled, secp256k1_recover_syscall_enabled, + sol_log_data_syscall_enabled, update_syscall_base_costs, }, hash::{Hasher, HASH_BYTES}, - instruction::{AccountMeta, Instruction, InstructionError, SiblingLengths}, + instruction::{AccountMeta, InnerLengths, Instruction, InstructionError}, keccak, native_loader, precompiles::is_precompile, program::MAX_RETURN_DATA, @@ -224,11 +224,11 @@ pub fn register_syscalls( if invoke_context .feature_set - .is_active(&add_get_sibling_instruction_syscall::id()) + .is_active(&add_get_processed_inner_instruction_syscall::id()) { syscall_registry.register_syscall_by_name( - b"sol_get_sibling_instruction", - SyscallGetSiblingInstruction::call, + b"sol_get_processed_inner_instruction", + SyscallGetProcessedInnerInstruction::call, )?; } @@ -272,9 +272,9 @@ pub fn bind_syscall_context_objects<'a, 'b>( let is_zk_token_sdk_enabled = invoke_context .feature_set .is_active(&feature_set::zk_token_sdk_enabled::id()); - let add_get_sibling_instruction_syscall = invoke_context + let add_get_processed_inner_instruction_syscall = invoke_context .feature_set - .is_active(&add_get_sibling_instruction_syscall::id()); + .is_active(&add_get_processed_inner_instruction_syscall::id()); let loader_id = invoke_context .transaction_context @@ -457,11 +457,11 @@ pub fn bind_syscall_context_objects<'a, 'b>( }), ); - // sibling instructions + // processed inner instructions bind_feature_gated_syscall_context_object!( vm, - add_get_sibling_instruction_syscall, - Box::new(SyscallGetSiblingInstruction { + add_get_processed_inner_instruction_syscall, + Box::new(SyscallGetProcessedInnerInstruction { invoke_context: invoke_context.clone(), }), ); @@ -2632,7 +2632,6 @@ fn check_authorized_program( } Ok(()) } - /// Call process instruction, common to both Rust and C fn call<'a, 'b: 'a>( syscall: &mut dyn SyscallInvokeSigned<'a, 'b>, @@ -2699,7 +2698,7 @@ fn call<'a, 'b: 'a>( ) .map_err(SyscallError::InstructionError)?; - invoke_context.add_sibling_instruction(instruction); + invoke_context.add_processed_inner_instruction(instruction); // Copy results back to caller for (callee_account_index, caller_account) in accounts.iter_mut() { @@ -2979,10 +2978,10 @@ impl<'a, 'b> SyscallObject for SyscallLogData<'a, 'b> { } } -pub struct SyscallGetSiblingInstruction<'a, 'b> { +pub struct SyscallGetProcessedInnerInstruction<'a, 'b> { invoke_context: Rc>>, } -impl<'a, 'b> SyscallObject for SyscallGetSiblingInstruction<'a, 'b> { +impl<'a, 'b> SyscallObject for SyscallGetProcessedInnerInstruction<'a, 'b> { fn call( &mut self, index: u64, @@ -3015,12 +3014,12 @@ impl<'a, 'b> SyscallObject for SyscallGetSiblingInstruction<'a, 'b> { result ); - if let Some(instruction) = invoke_context.get_sibling_instruction(index as usize) { - let SiblingLengths { + if let Some(instruction) = invoke_context.get_processed_inner_instruction(index as usize) { + let InnerLengths { data_len, accounts_len, } = question_mark!( - translate_type_mut::(memory_mapping, lengths_addr, &loader_id), + translate_type_mut::(memory_mapping, lengths_addr, &loader_id), result ); if *data_len >= instruction.data.len() as u64 diff --git a/sdk/program/src/instruction.rs b/sdk/program/src/instruction.rs index 2de72749044e95..56a956fe00a134 100644 --- a/sdk/program/src/instruction.rs +++ b/sdk/program/src/instruction.rs @@ -646,44 +646,44 @@ impl CompiledInstruction { } } -/// Use to query and convey the lengths of the sibling instruction components +/// Use to query and convey the lengths of the inner instruction components /// when calling the syscall #[repr(C)] #[derive(Default, Debug, Clone, Copy)] -pub struct SiblingLengths { +pub struct InnerLengths { pub data_len: u64, pub accounts_len: u64, } -/// Returns a sibling instruction from the sibling instruction list. +/// Returns a inner instruction from the processed inner instruction list. +/// +/// The processed inner instruction list is a reverse-ordered list of +/// successfully processed inner instructions. For example, given the call flow: /// -/// The Sibling instruction list is a reverse-ordered list of successfully -/// processed inner instructions. For example, given the call flow: -/// ``` /// A /// B -> C -> D /// B -> E /// B -> F -/// ``` -/// Then B's sibling instruction list is: [F, E, D, C] -pub fn get_sibling_instruction(index: usize) -> Option { +/// +/// Then B's processed inner instruction list is: [F, E, D, C] +pub fn get_processed_inner_instruction(index: usize) -> Option { #[cfg(target_arch = "bpf")] { extern "C" { - fn sol_get_sibling_instruction( + fn sol_get_processed_inner_instruction( index: u64, - lengths: *mut SiblingLengths, + lengths: *mut InnerLengths, program_id: *mut Pubkey, data: *mut u8, accounts: *mut AccountMeta, ) -> u64; } - let mut lengths = SiblingLengths::default(); + let mut lengths = InnerLengths::default(); let mut program_id = Pubkey::default(); if 1 == unsafe { - sol_get_sibling_instruction( + sol_get_processed_inner_instruction( index as u64, &mut lengths, &mut program_id, @@ -697,7 +697,7 @@ pub fn get_sibling_instruction(index: usize) -> Option { accounts.resize_with(lengths.accounts_len as usize, AccountMeta::default); let _ = unsafe { - sol_get_sibling_instruction( + sol_get_processed_inner_instruction( index as u64, &mut lengths, &mut program_id, @@ -713,7 +713,7 @@ pub fn get_sibling_instruction(index: usize) -> Option { } #[cfg(not(target_arch = "bpf"))] - crate::program_stubs::get_sibling_instruction(index) + crate::program_stubs::get_processed_inner_instruction(index) } #[test] diff --git a/sdk/program/src/program_stubs.rs b/sdk/program/src/program_stubs.rs index 88a0f1ffb753f9..7a673acda17d6c 100644 --- a/sdk/program/src/program_stubs.rs +++ b/sdk/program/src/program_stubs.rs @@ -91,7 +91,7 @@ pub trait SyscallStubs: Sync + Send { fn sol_log_data(&self, fields: &[&[u8]]) { println!("data: {}", fields.iter().map(base64::encode).join(" ")); } - fn get_sibling_instruction(&self, _index: usize) -> Option { + fn get_processed_inner_instruction(&self, _index: usize) -> Option { None } } @@ -180,8 +180,11 @@ pub(crate) fn sol_log_data(data: &[&[u8]]) { SYSCALL_STUBS.read().unwrap().sol_log_data(data) } -pub(crate) fn get_sibling_instruction(index: usize) -> Option { - SYSCALL_STUBS.read().unwrap().get_sibling_instruction(index) +pub(crate) fn get_processed_inner_instruction(index: usize) -> Option { + SYSCALL_STUBS + .read() + .unwrap() + .get_processed_inner_instruction(index) } /// Check that two regions do not overlap. diff --git a/sdk/src/feature_set.rs b/sdk/src/feature_set.rs index d6ebee045cb552..213f86907ddcf0 100644 --- a/sdk/src/feature_set.rs +++ b/sdk/src/feature_set.rs @@ -307,7 +307,7 @@ pub mod update_syscall_base_costs { solana_sdk::declare_id!("2h63t332mGCCsWK2nqqqHhN4U9ayyqhLVFvczznHDoTZ"); } -pub mod add_get_sibling_instruction_syscall { +pub mod add_get_processed_inner_instruction_syscall { solana_sdk::declare_id!("CFK1hRCNy8JJuAAY8Pb2GjLFNdCThS2qwZNe3izzBMgn"); } @@ -382,7 +382,7 @@ lazy_static! { (require_rent_exempt_accounts::id(), "require all new transaction accounts with data to be rent-exempt"), (filter_votes_outside_slot_hashes::id(), "filter vote slots older than the slot hashes history"), (update_syscall_base_costs::id(), "Update syscall base costs"), - (add_get_sibling_instruction_syscall::id(), "add get_sibling_instruction_syscall"), + (add_get_processed_inner_instruction_syscall::id(), "add add_get_processed_inner_instruction_syscall"), /*************** ADD NEW FEATURES HERE ***************/ ] .iter()