Skip to content

Commit

Permalink
Removes first_instruction_account parameter from process_instruction().
Browse files Browse the repository at this point in the history
  • Loading branch information
Lichtso committed Mar 3, 2023
1 parent ca0fb96 commit 2c8be3f
Show file tree
Hide file tree
Showing 15 changed files with 36 additions and 108 deletions.
24 changes: 9 additions & 15 deletions program-runtime/src/invoke_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ use {
},
};

pub type ProcessInstructionWithContext =
fn(IndexOfAccount, &mut InvokeContext) -> Result<(), InstructionError>;
pub type ProcessInstructionWithContext = fn(&mut InvokeContext) -> Result<(), InstructionError>;

#[derive(Clone)]
pub struct BuiltinProgram {
Expand All @@ -50,7 +49,7 @@ impl std::fmt::Debug for BuiltinProgram {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
// These are just type aliases for work around of Debug-ing above pointers
type ErasedProcessInstructionWithContext =
fn(IndexOfAccount, &'static mut InvokeContext<'static>) -> Result<(), InstructionError>;
fn(&'static mut InvokeContext<'static>) -> Result<(), InstructionError>;

// rustc doesn't compile due to bug without this work around
// https://github.com/rust-lang/rust/issues/50280
Expand Down Expand Up @@ -733,15 +732,15 @@ impl<'a> InvokeContext<'a> {
let instruction_context = self.transaction_context.get_current_instruction_context()?;
let mut process_executable_chain_time = Measure::start("process_executable_chain_time");

let (first_instruction_account, builtin_id) = {
let builtin_id = {
let borrowed_root_account = instruction_context
.try_borrow_program_account(self.transaction_context, 0)
.map_err(|_| InstructionError::UnsupportedProgramId)?;
let owner_id = borrowed_root_account.get_owner();
if native_loader::check_id(owner_id) {
(1, *borrowed_root_account.get_key())
*borrowed_root_account.get_key()
} else {
(0, *owner_id)
*owner_id
}
};

Expand All @@ -756,7 +755,7 @@ impl<'a> InvokeContext<'a> {
let result = if builtin_id == program_id {
let logger = self.get_log_collector();
stable_log::program_invoke(&logger, &program_id, self.get_stack_height());
(entry.process_instruction)(first_instruction_account, self)
(entry.process_instruction)(self)
.map(|()| {
stable_log::program_success(&logger, &program_id);
})
Expand All @@ -765,7 +764,7 @@ impl<'a> InvokeContext<'a> {
err
})
} else {
(entry.process_instruction)(first_instruction_account, self)
(entry.process_instruction)(self)
};
let post_remaining_units = self.get_remaining();
*compute_units_consumed = pre_remaining_units.saturating_sub(post_remaining_units);
Expand Down Expand Up @@ -1023,7 +1022,7 @@ pub fn mock_process_instruction(
);
let result = invoke_context
.push()
.and_then(|_| process_instruction(1, &mut invoke_context));
.and_then(|_| process_instruction(&mut invoke_context));
let pop_result = invoke_context.pop();
assert_eq!(result.and(pop_result), expected_result);
let mut transaction_accounts = transaction_context.deconstruct_without_keys().unwrap();
Expand Down Expand Up @@ -1062,16 +1061,12 @@ mod tests {
fn test_program_entry_debug() {
#[allow(clippy::unnecessary_wraps)]
fn mock_process_instruction(
_first_instruction_account: IndexOfAccount,
_invoke_context: &mut InvokeContext,
) -> Result<(), InstructionError> {
Ok(())
}
#[allow(clippy::unnecessary_wraps)]
fn mock_ix_processor(
_first_instruction_account: IndexOfAccount,
_invoke_context: &mut InvokeContext,
) -> Result<(), InstructionError> {
fn mock_ix_processor(_invoke_context: &mut InvokeContext) -> Result<(), InstructionError> {
Ok(())
}
let builtin_programs = &[
Expand All @@ -1089,7 +1084,6 @@ mod tests {

#[allow(clippy::integer_arithmetic)]
fn mock_process_instruction(
_first_instruction_account: IndexOfAccount,
invoke_context: &mut InvokeContext,
) -> Result<(), InstructionError> {
let transaction_context = &invoke_context.transaction_context;
Expand Down
14 changes: 3 additions & 11 deletions program-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ fn get_invoke_context<'a, 'b>() -> &'a mut InvokeContext<'b> {

pub fn builtin_process_instruction(
process_instruction: solana_sdk::entrypoint::ProcessInstruction,
_first_instruction_account: IndexOfAccount,
invoke_context: &mut InvokeContext,
) -> Result<(), InstructionError> {
set_invoke_context(invoke_context);
Expand Down Expand Up @@ -181,16 +180,9 @@ pub fn builtin_process_instruction(
#[macro_export]
macro_rules! processor {
($process_instruction:expr) => {
Some(
|first_instruction_account: $crate::IndexOfAccount,
invoke_context: &mut solana_program_test::InvokeContext| {
$crate::builtin_process_instruction(
$process_instruction,
first_instruction_account,
invoke_context,
)
},
)
Some(|invoke_context: &mut solana_program_test::InvokeContext| {
$crate::builtin_process_instruction($process_instruction, invoke_context)
})
};
}

Expand Down
6 changes: 1 addition & 5 deletions programs/address-lookup-table/src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,11 @@ use {
program_utils::limited_deserialize,
pubkey::{Pubkey, PUBKEY_BYTES},
system_instruction,
transaction_context::IndexOfAccount,
},
std::convert::TryFrom,
};

pub fn process_instruction(
_first_instruction_account: IndexOfAccount,
invoke_context: &mut InvokeContext,
) -> Result<(), InstructionError> {
pub fn process_instruction(invoke_context: &mut InvokeContext) -> Result<(), InstructionError> {
let transaction_context = &invoke_context.transaction_context;
let instruction_context = transaction_context.get_current_instruction_context()?;
let instruction_data = instruction_context.get_instruction_data();
Expand Down
14 changes: 4 additions & 10 deletions programs/bpf_loader/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,17 +381,11 @@ pub fn create_vm<'a, 'b>(
result
}

pub fn process_instruction(
_first_instruction_account: IndexOfAccount,
invoke_context: &mut InvokeContext,
) -> Result<(), InstructionError> {
pub fn process_instruction(invoke_context: &mut InvokeContext) -> Result<(), InstructionError> {
process_instruction_common(invoke_context, false)
}

pub fn process_instruction_jit(
_first_instruction_account: IndexOfAccount,
invoke_context: &mut InvokeContext,
) -> Result<(), InstructionError> {
pub fn process_instruction_jit(invoke_context: &mut InvokeContext) -> Result<(), InstructionError> {
process_instruction_common(invoke_context, true)
}

Expand Down Expand Up @@ -1904,9 +1898,9 @@ mod tests {
None,
None,
Err(InstructionError::ProgramFailedToComplete),
|first_instruction_account: IndexOfAccount, invoke_context: &mut InvokeContext| {
|invoke_context: &mut InvokeContext| {
invoke_context.mock_set_remaining(0);
super::process_instruction(first_instruction_account, invoke_context)
super::process_instruction(invoke_context)
},
);

Expand Down
7 changes: 2 additions & 5 deletions programs/compute-budget/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
use {
solana_program_runtime::invoke_context::InvokeContext,
solana_sdk::{instruction::InstructionError, transaction_context::IndexOfAccount},
solana_sdk::instruction::InstructionError,
};

pub fn process_instruction(
_first_instruction_account: IndexOfAccount,
_invoke_context: &mut InvokeContext,
) -> Result<(), InstructionError> {
pub fn process_instruction(_invoke_context: &mut InvokeContext) -> Result<(), InstructionError> {
// Do nothing, compute budget instructions handled by the runtime
Ok(())
}
5 changes: 1 addition & 4 deletions programs/config/src/config_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ use {
std::collections::BTreeSet,
};

pub fn process_instruction(
_first_instruction_account: IndexOfAccount,
invoke_context: &mut InvokeContext,
) -> Result<(), InstructionError> {
pub fn process_instruction(invoke_context: &mut InvokeContext) -> Result<(), InstructionError> {
let transaction_context = &invoke_context.transaction_context;
let instruction_context = transaction_context.get_current_instruction_context()?;
let data = instruction_context.get_instruction_data();
Expand Down
9 changes: 3 additions & 6 deletions programs/stake/src/stake_instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,7 @@ fn get_optional_pubkey<'a>(
)
}

pub fn process_instruction(
_first_instruction_account: IndexOfAccount,
invoke_context: &mut InvokeContext,
) -> Result<(), InstructionError> {
pub fn process_instruction(invoke_context: &mut InvokeContext) -> Result<(), InstructionError> {
let transaction_context = &invoke_context.transaction_context;
let instruction_context = transaction_context.get_current_instruction_context()?;
let data = instruction_context.get_instruction_data();
Expand Down Expand Up @@ -6475,8 +6472,8 @@ mod tests {
None,
Some(Arc::new(feature_set)),
Ok(()),
|first_instruction_account, invoke_context| {
super::process_instruction(first_instruction_account, invoke_context)?;
|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 =
Expand Down
3 changes: 1 addition & 2 deletions programs/vote/benches/process_vote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,7 @@ fn bench_process_vote_instruction(
.configure(&[0], &instruction_accounts, &instruction_data);
invoke_context.push().unwrap();
assert!(
solana_vote_program::vote_processor::process_instruction(1, &mut invoke_context)
.is_ok()
solana_vote_program::vote_processor::process_instruction(&mut invoke_context).is_ok()
);
invoke_context.pop().unwrap();
});
Expand Down
9 changes: 2 additions & 7 deletions programs/vote/src/vote_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ use {
instruction::InstructionError,
program_utils::limited_deserialize,
pubkey::Pubkey,
transaction_context::{
BorrowedAccount, IndexOfAccount, InstructionContext, TransactionContext,
},
transaction_context::{BorrowedAccount, InstructionContext, TransactionContext},
},
std::collections::HashSet,
};
Expand Down Expand Up @@ -57,10 +55,7 @@ fn process_authorize_with_seed_instruction(
)
}

pub fn process_instruction(
_first_instruction_account: IndexOfAccount,
invoke_context: &mut InvokeContext,
) -> Result<(), InstructionError> {
pub fn process_instruction(invoke_context: &mut InvokeContext) -> Result<(), InstructionError> {
let transaction_context = &invoke_context.transaction_context;
let instruction_context = transaction_context.get_current_instruction_context()?;
let data = instruction_context.get_instruction_data();
Expand Down
10 changes: 2 additions & 8 deletions programs/zk-token-proof/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
use {
bytemuck::Pod,
solana_program_runtime::{ic_msg, invoke_context::InvokeContext},
solana_sdk::{
instruction::{InstructionError, TRANSACTION_LEVEL_STACK_HEIGHT},
transaction_context::IndexOfAccount,
},
solana_sdk::instruction::{InstructionError, TRANSACTION_LEVEL_STACK_HEIGHT},
solana_zk_token_sdk::zk_token_proof_instruction::*,
std::result::Result,
};
Expand All @@ -28,10 +25,7 @@ fn verify<T: Pod + Verifiable>(invoke_context: &mut InvokeContext) -> Result<(),
})
}

pub fn process_instruction(
_first_instruction_account: IndexOfAccount,
invoke_context: &mut InvokeContext,
) -> Result<(), InstructionError> {
pub fn process_instruction(invoke_context: &mut InvokeContext) -> Result<(), InstructionError> {
if invoke_context.get_stack_height() != TRANSACTION_LEVEL_STACK_HEIGHT {
// Not supported as an inner instruction
return Err(InstructionError::UnsupportedProgramId);
Expand Down
6 changes: 1 addition & 5 deletions runtime/benches/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use {
pubkey::Pubkey,
signature::{Keypair, Signer},
transaction::Transaction,
transaction_context::IndexOfAccount,
},
std::{sync::Arc, thread::sleep, time::Duration},
test::Bencher,
Expand All @@ -37,10 +36,7 @@ const NOOP_PROGRAM_ID: [u8; 32] = [
];

#[allow(clippy::unnecessary_wraps)]
fn process_instruction(
_first_instruction_account: IndexOfAccount,
_invoke_context: &mut InvokeContext,
) -> Result<(), InstructionError> {
fn process_instruction(_invoke_context: &mut InvokeContext) -> Result<(), InstructionError> {
Ok(())
}

Expand Down
Loading

0 comments on commit 2c8be3f

Please sign in to comment.