Refactor: Remove program_id from process_instruction() (#20540)

* Replaces usage of program_id parameter by invoke_context.get_caller()?.

* Removes "pubkey: &Pubkey" parameter from "process_instruction()".
This commit is contained in:
Alexander Meißner
2021-10-10 22:29:18 +02:00
committed by GitHub
parent c16510152e
commit f30f3bddbb
23 changed files with 110 additions and 175 deletions

View File

@ -79,7 +79,6 @@ macro_rules! declare_builtin_name {
/// use solana_sdk::declare_builtin;
///
/// fn my_process_instruction(
/// program_id: &Pubkey,
/// first_instruction_account: usize,
/// keyed_accounts: &[KeyedAccount],
/// instruction_data: &[u8],
@ -111,7 +110,6 @@ macro_rules! declare_builtin_name {
/// use solana_sdk::declare_builtin;
///
/// fn my_process_instruction(
/// program_id: &Pubkey,
/// first_instruction_account: usize,
/// keyed_accounts: &[KeyedAccount],
/// instruction_data: &[u8],

View File

@ -94,7 +94,6 @@ macro_rules! declare_name {
/// };
///
/// fn my_process_instruction(
/// program_id: &Pubkey,
/// first_instruction_account: usize,
/// instruction_data: &[u8],
/// invoke_context: &mut dyn InvokeContext,
@ -128,7 +127,6 @@ macro_rules! declare_name {
/// };
///
/// fn my_process_instruction(
/// program_id: &Pubkey,
/// first_instruction_account: usize,
/// instruction_data: &[u8],
/// invoke_context: &mut dyn InvokeContext,
@ -155,12 +153,11 @@ macro_rules! declare_program(
#[no_mangle]
pub extern "C" fn $name(
program_id: &$crate::pubkey::Pubkey,
first_instruction_account: usize,
instruction_data: &[u8],
invoke_context: &mut dyn $crate::process_instruction::InvokeContext,
) -> Result<(), $crate::instruction::InstructionError> {
$entrypoint(program_id, first_instruction_account, instruction_data, invoke_context)
$entrypoint(first_instruction_account, instruction_data, invoke_context)
}
)
);

View File

@ -289,7 +289,7 @@ mod test {
}
fn create_invoke_context_with_blockhash<'a>(seed: usize) -> MockInvokeContext<'a> {
let mut invoke_context = MockInvokeContext::new(vec![]);
let mut invoke_context = MockInvokeContext::new(&Pubkey::default(), vec![]);
let (blockhash, fee_calculator) = create_test_blockhash(seed);
invoke_context.blockhash = blockhash;
invoke_context.fee_calculator = fee_calculator;
@ -979,7 +979,7 @@ mod test {
let min_lamports = rent.minimum_balance(State::size());
with_test_keyed_account(min_lamports + 42, true, |nonce_account| {
let mut signers = HashSet::new();
let invoke_context = MockInvokeContext::new(vec![]);
let invoke_context = MockInvokeContext::new(&Pubkey::default(), vec![]);
signers.insert(*nonce_account.signer_key().unwrap());
let result = nonce_account.authorize_nonce_account(
&Pubkey::default(),

View File

@ -28,7 +28,7 @@ pub type LoaderEntrypoint = unsafe extern "C" fn(
) -> Result<(), InstructionError>;
pub type ProcessInstructionWithContext =
fn(&Pubkey, usize, &[u8], &mut dyn InvokeContext) -> Result<(), InstructionError>;
fn(usize, &[u8], &mut dyn InvokeContext) -> Result<(), InstructionError>;
pub struct InvokeContextStackFrame<'a> {
pub key: Pubkey,
@ -400,7 +400,6 @@ pub trait Executor: Debug + Send + Sync {
/// Execute the program
fn execute(
&self,
program_id: &Pubkey,
first_instruction_account: usize,
instruction_data: &[u8],
invoke_context: &mut dyn InvokeContext,
@ -456,7 +455,7 @@ pub struct MockInvokeContext<'a> {
}
impl<'a> MockInvokeContext<'a> {
pub fn new(keyed_accounts: Vec<KeyedAccount<'a>>) -> Self {
pub fn new(program_id: &Pubkey, keyed_accounts: Vec<KeyedAccount<'a>>) -> Self {
let compute_budget = ComputeBudget::default();
let mut invoke_context = MockInvokeContext {
invoke_stack: Vec::with_capacity(compute_budget.max_invoke_depth),
@ -476,10 +475,7 @@ impl<'a> MockInvokeContext<'a> {
};
invoke_context
.invoke_stack
.push(InvokeContextStackFrame::new(
Pubkey::default(),
keyed_accounts,
));
.push(InvokeContextStackFrame::new(*program_id, keyed_accounts));
invoke_context
}
}