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 2a69ba4 commit c2b15a0
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 27 deletions.
6 changes: 3 additions & 3 deletions program-runtime/src/invoke_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1017,12 +1017,12 @@ impl<'a> InvokeContext<'a> {
}

// Push a sibling instruction
pub fn add_sibling_instruction(&mut self, instruction: Instruction) {
pub fn add_processed_sibling_instruction(&mut self, instruction: Instruction) {
self.sibling_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 sibling instruction, reverse ordered list, where last added is index 0
pub fn get_processed_sibling_instruction(&self, index: usize) -> Option<&Instruction> {
let index = self
.sibling_instructions
.len()
Expand Down
12 changes: 6 additions & 6 deletions programs/bpf/rust/sibling_instruction/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use solana_program::{
account_info::AccountInfo,
entrypoint,
entrypoint::ProgramResult,
instruction::{get_sibling_instruction, AccountMeta, Instruction},
instruction::{get_processed_sibling_instruction, AccountMeta, Instruction},
msg,
program::invoke,
pubkey::Pubkey,
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_sibling_instruction(0));
assert_eq!(Some(instruction1), get_processed_sibling_instruction(1));
assert_eq!(Some(instruction2), get_processed_sibling_instruction(2));
assert_eq!(Some(instruction3), get_processed_sibling_instruction(3));
assert!(get_processed_sibling_instruction(4).is_none());

Ok(())
}
9 changes: 5 additions & 4 deletions programs/bpf_loader/src/syscalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ pub fn register_syscalls(
.is_active(&add_get_sibling_instruction_syscall::id())
{
syscall_registry.register_syscall_by_name(
b"sol_get_sibling_instruction",
b"sol_get_processed_sibling_instruction",
SyscallGetSiblingInstruction::call,
)?;
}
Expand Down Expand Up @@ -2591,8 +2591,8 @@ fn check_authorized_program(
return Err(SyscallError::ProgramNotSupported(*program_id).into());
}
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 @@ -2659,7 +2659,7 @@ fn call<'a, 'b: 'a>(
)
.map_err(SyscallError::InstructionError)?;

invoke_context.add_sibling_instruction(instruction);
invoke_context.add_processed_sibling_instruction(instruction);

// Copy results back to caller
for (callee_account_index, caller_account) in accounts.iter_mut() {
Expand Down Expand Up @@ -2975,7 +2975,8 @@ impl<'a, 'b> SyscallObject<BpfError> for SyscallGetSiblingInstruction<'a, 'b> {
result
);

if let Some(instruction) = invoke_context.get_sibling_instruction(index as usize) {
if let Some(instruction) = invoke_context.get_processed_sibling_instruction(index as usize)
{
let SiblingLengths {
data_len,
accounts_len,
Expand Down
9 changes: 5 additions & 4 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3666,13 +3666,14 @@ impl Bank {
let pre_account_state_info =
self.get_transaction_account_state_info(&transaction_context, tx.message());

let instruction_recorder = if enable_cpi_recording {
let instruction_recorder = //if enable_cpi_recording {
Some(InstructionRecorder::new_ref(
tx.message().instructions().len(),
))
} else {
None
};
// } else {
// None
// }
;

let log_collector = if enable_log_recording {
Some(LogCollector::new_ref())
Expand Down
14 changes: 7 additions & 7 deletions sdk/program/src/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -659,18 +659,18 @@ pub struct SiblingLengths {
///
/// 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> {
pub fn get_processed_sibling_instruction(index: usize) -> Option<Instruction> {
#[cfg(target_arch = "bpf")]
{
extern "C" {
fn sol_get_sibling_instruction(
fn sol_get_processed_sibling_instruction(
index: u64,
lengths: *mut SiblingLengths,
program_id: *mut Pubkey,
Expand All @@ -683,7 +683,7 @@ pub fn get_sibling_instruction(index: usize) -> Option<Instruction> {
let mut program_id = Pubkey::default();

if 1 == unsafe {
sol_get_sibling_instruction(
sol_get_processed_sibling_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_sibling_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_sibling_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_sibling_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_sibling_instruction(index: usize) -> Option<Instruction> {
SYSCALL_STUBS
.read()
.unwrap()
.get_processed_sibling_instruction(index)
}

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

0 comments on commit c2b15a0

Please sign in to comment.