Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions program-runtime/src/instruction_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ impl std::fmt::Debug for InstructionProcessor {
// These are just type aliases for work around of Debug-ing above pointers
type ErasedProcessInstructionWithContext = fn(
&'static Pubkey,
usize,
&'static [u8],
&'static mut dyn InvokeContext,
) -> Result<(), InstructionError>;
Expand Down Expand Up @@ -361,15 +362,20 @@ impl InstructionProcessor {
if solana_sdk::native_loader::check_id(&root_account.owner()?) {
for (id, process_instruction) in &self.programs {
if id == root_id {
invoke_context.remove_first_keyed_account()?;
// Call the builtin program
return process_instruction(program_id, instruction_data, invoke_context);
return process_instruction(
program_id,
1, // root_id to be skipped
instruction_data,
invoke_context,
);
}
}
if !invoke_context.is_feature_active(&remove_native_loader::id()) {
// Call the program via the native loader
return self.native_loader.process_instruction(
&solana_sdk::native_loader::id(),
0,
instruction_data,
invoke_context,
);
Expand All @@ -379,7 +385,12 @@ impl InstructionProcessor {
for (id, process_instruction) in &self.programs {
if id == owner_id {
// Call the program via a builtin loader
return process_instruction(program_id, instruction_data, invoke_context);
return process_instruction(
program_id,
0, // no root_id was provided
instruction_data,
invoke_context,
);
}
}
}
Expand Down Expand Up @@ -1074,6 +1085,7 @@ mod tests {
#[allow(clippy::unnecessary_wraps)]
fn mock_process_instruction(
_program_id: &Pubkey,
_first_instruction_account: usize,
_data: &[u8],
_invoke_context: &mut dyn InvokeContext,
) -> Result<(), InstructionError> {
Expand All @@ -1082,6 +1094,7 @@ mod tests {
#[allow(clippy::unnecessary_wraps)]
fn mock_ix_processor(
_pubkey: &Pubkey,
_first_instruction_account: usize,
_data: &[u8],
_context: &mut dyn InvokeContext,
) -> Result<(), InstructionError> {
Expand Down
4 changes: 3 additions & 1 deletion program-runtime/src/native_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,13 @@ impl NativeLoader {
pub fn process_instruction(
&self,
program_id: &Pubkey,
first_instruction_account: usize,
instruction_data: &[u8],
invoke_context: &mut dyn InvokeContext,
) -> Result<(), InstructionError> {
let (program_id, name_vec) = {
let keyed_accounts = invoke_context.get_keyed_accounts()?;
let program = keyed_account_at_index(keyed_accounts, 0)?;
let program = keyed_account_at_index(keyed_accounts, first_instruction_account)?;
if native_loader::id() != *program_id {
error!("Program id mismatch");
return Err(InstructionError::IncorrectProgramId);
Expand Down Expand Up @@ -173,6 +174,7 @@ impl NativeLoader {
return Err(NativeLoaderError::InvalidAccountData.into());
}
trace!("Call native {:?}", name);
#[allow(deprecated)]
invoke_context.remove_first_keyed_account()?;
if name.ends_with("loader_program") {
let entrypoint =
Expand Down
6 changes: 5 additions & 1 deletion program-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ fn get_invoke_context<'a>() -> &'a mut dyn InvokeContext {
pub fn builtin_process_instruction(
process_instruction: solana_sdk::entrypoint::ProcessInstruction,
program_id: &Pubkey,
_first_instruction_account: usize,
input: &[u8],
invoke_context: &mut dyn InvokeContext,
) -> Result<(), InstructionError> {
Expand All @@ -109,7 +110,8 @@ pub fn builtin_process_instruction(
let logger = invoke_context.get_logger();
stable_log::program_invoke(&logger, program_id, invoke_context.invoke_depth());

let keyed_accounts = invoke_context.get_keyed_accounts()?;
// Skip the processor account
let keyed_accounts = &invoke_context.get_keyed_accounts()?[1..];

// Copy all the accounts into a HashMap to ensure there are no duplicates
let mut accounts: HashMap<Pubkey, Account> = keyed_accounts
Expand Down Expand Up @@ -183,11 +185,13 @@ macro_rules! processor {
($process_instruction:expr) => {
Some(
|program_id: &Pubkey,
first_instruction_account: usize,
input: &[u8],
invoke_context: &mut dyn solana_sdk::process_instruction::InvokeContext| {
$crate::builtin_process_instruction(
$process_instruction,
program_id,
first_instruction_account,
input,
invoke_context,
)
Expand Down
Loading