Skip to content

Commit

Permalink
rename
Browse files Browse the repository at this point in the history
  • Loading branch information
jackcmay committed Jan 15, 2022
1 parent 29c2df0 commit b58222f
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 71 deletions.
20 changes: 10 additions & 10 deletions program-runtime/src/invoke_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ pub struct InvokeContext<'a> {
pub timings: ExecuteDetailsTimings,
pub blockhash: Hash,
pub lamports_per_signature: u64,
pub sibling_instructions: Vec<Instruction>,
pub processed_inner_instructions: Vec<Instruction>,
}

impl<'a> InvokeContext<'a> {
Expand Down Expand Up @@ -234,7 +234,7 @@ impl<'a> InvokeContext<'a> {
timings: ExecuteDetailsTimings::default(),
blockhash,
lamports_per_signature,
sibling_instructions: Vec::new(),
processed_inner_instructions: Vec::new(),
}
}

Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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)
}
}

Expand Down
14 changes: 7 additions & 7 deletions programs/bpf/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion programs/bpf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -81,7 +82,6 @@ members = [
"rust/sanity",
"rust/secp256k1_recover",
"rust/sha",
"rust/sibling_instruction",
"rust/spoof1",
"rust/spoof1_system",
"rust/sysvar",
Expand Down
2 changes: 1 addition & 1 deletion programs/bpf/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ fn main() {
"log_data",
"external_spend",
"finalize",
"inner_instruction",
"instruction_introspection",
"invoke",
"invoke_and_error",
Expand All @@ -91,7 +92,6 @@ fn main() {
"sanity",
"secp256k1_recover",
"sha",
"sibling_instruction",
"spoof1",
"spoof1_system",
"upgradeable",
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>"]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
//! 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")]

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,
Expand All @@ -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
Expand Down Expand Up @@ -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(())
}
4 changes: 2 additions & 2 deletions programs/bpf/tests/programs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
Expand Down
41 changes: 20 additions & 21 deletions programs/bpf_loader/src/syscalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
)?;
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(),
}),
);
Expand Down Expand Up @@ -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>,
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -2979,10 +2978,10 @@ impl<'a, 'b> SyscallObject<BpfError> for SyscallLogData<'a, 'b> {
}
}

pub struct SyscallGetSiblingInstruction<'a, 'b> {
pub struct SyscallGetProcessedInnerInstruction<'a, 'b> {
invoke_context: Rc<RefCell<&'a mut InvokeContext<'b>>>,
}
impl<'a, 'b> SyscallObject<BpfError> for SyscallGetSiblingInstruction<'a, 'b> {
impl<'a, 'b> SyscallObject<BpfError> for SyscallGetProcessedInnerInstruction<'a, 'b> {
fn call(
&mut self,
index: u64,
Expand Down Expand Up @@ -3015,12 +3014,12 @@ impl<'a, 'b> SyscallObject<BpfError> 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::<SiblingLengths>(memory_mapping, lengths_addr, &loader_id),
translate_type_mut::<InnerLengths>(memory_mapping, lengths_addr, &loader_id),
result
);
if *data_len >= instruction.data.len() as u64
Expand Down
30 changes: 15 additions & 15 deletions sdk/program/src/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Instruction> {
///
/// Then B's processed inner instruction list is: [F, E, D, C]
pub fn get_processed_inner_instruction(index: usize) -> Option<Instruction> {
#[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,
Expand All @@ -697,7 +697,7 @@ pub fn get_sibling_instruction(index: usize) -> Option<Instruction> {
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,
Expand All @@ -713,7 +713,7 @@ pub fn get_sibling_instruction(index: usize) -> Option<Instruction> {
}

#[cfg(not(target_arch = "bpf"))]
crate::program_stubs::get_sibling_instruction(index)
crate::program_stubs::get_processed_inner_instruction(index)
}

#[test]
Expand Down
9 changes: 6 additions & 3 deletions sdk/program/src/program_stubs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Instruction> {
fn get_processed_inner_instruction(&self, _index: usize) -> Option<Instruction> {
None
}
}
Expand Down Expand Up @@ -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<Instruction> {
SYSCALL_STUBS.read().unwrap().get_sibling_instruction(index)
pub(crate) fn get_processed_inner_instruction(index: usize) -> Option<Instruction> {
SYSCALL_STUBS
.read()
.unwrap()
.get_processed_inner_instruction(index)
}

/// Check that two regions do not overlap.
Expand Down
Loading

0 comments on commit b58222f

Please sign in to comment.