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:
parent
c16510152e
commit
f30f3bddbb
@ -1993,7 +1993,7 @@ fn read_and_verify_elf(program_location: &str) -> Result<Vec<u8>, Box<dyn std::e
|
|||||||
let mut program_data = Vec::new();
|
let mut program_data = Vec::new();
|
||||||
file.read_to_end(&mut program_data)
|
file.read_to_end(&mut program_data)
|
||||||
.map_err(|err| format!("Unable to read program file: {}", err))?;
|
.map_err(|err| format!("Unable to read program file: {}", err))?;
|
||||||
let mut invoke_context = MockInvokeContext::new(vec![]);
|
let mut invoke_context = MockInvokeContext::new(&Pubkey::default(), vec![]);
|
||||||
|
|
||||||
// Verify the program
|
// Verify the program
|
||||||
<dyn Executable<BpfError, ThisInstructionMeter>>::from_elf(
|
<dyn Executable<BpfError, ThisInstructionMeter>>::from_elf(
|
||||||
|
@ -282,7 +282,6 @@ impl std::fmt::Debug for InstructionProcessor {
|
|||||||
|
|
||||||
// These are just type aliases for work around of Debug-ing above pointers
|
// These are just type aliases for work around of Debug-ing above pointers
|
||||||
type ErasedProcessInstructionWithContext = fn(
|
type ErasedProcessInstructionWithContext = fn(
|
||||||
&'static Pubkey,
|
|
||||||
usize,
|
usize,
|
||||||
&'static [u8],
|
&'static [u8],
|
||||||
&'static mut dyn InvokeContext,
|
&'static mut dyn InvokeContext,
|
||||||
@ -353,18 +352,17 @@ impl InstructionProcessor {
|
|||||||
/// This method calls the instruction's program entrypoint method
|
/// This method calls the instruction's program entrypoint method
|
||||||
pub fn process_instruction(
|
pub fn process_instruction(
|
||||||
&self,
|
&self,
|
||||||
program_id: &Pubkey,
|
|
||||||
instruction_data: &[u8],
|
instruction_data: &[u8],
|
||||||
invoke_context: &mut dyn InvokeContext,
|
invoke_context: &mut dyn InvokeContext,
|
||||||
) -> Result<(), InstructionError> {
|
) -> Result<(), InstructionError> {
|
||||||
if let Some(root_account) = invoke_context.get_keyed_accounts()?.iter().next() {
|
if let Some(root_account) = invoke_context.get_keyed_accounts()?.iter().next() {
|
||||||
let root_id = root_account.unsigned_key();
|
let root_id = root_account.unsigned_key();
|
||||||
if solana_sdk::native_loader::check_id(&root_account.owner()?) {
|
let owner_id = &root_account.owner()?;
|
||||||
|
if solana_sdk::native_loader::check_id(owner_id) {
|
||||||
for (id, process_instruction) in &self.programs {
|
for (id, process_instruction) in &self.programs {
|
||||||
if id == root_id {
|
if id == root_id {
|
||||||
// Call the builtin program
|
// Call the builtin program
|
||||||
return process_instruction(
|
return process_instruction(
|
||||||
program_id,
|
|
||||||
1, // root_id to be skipped
|
1, // root_id to be skipped
|
||||||
instruction_data,
|
instruction_data,
|
||||||
invoke_context,
|
invoke_context,
|
||||||
@ -374,19 +372,16 @@ impl InstructionProcessor {
|
|||||||
if !invoke_context.is_feature_active(&remove_native_loader::id()) {
|
if !invoke_context.is_feature_active(&remove_native_loader::id()) {
|
||||||
// Call the program via the native loader
|
// Call the program via the native loader
|
||||||
return self.native_loader.process_instruction(
|
return self.native_loader.process_instruction(
|
||||||
&solana_sdk::native_loader::id(),
|
|
||||||
0,
|
0,
|
||||||
instruction_data,
|
instruction_data,
|
||||||
invoke_context,
|
invoke_context,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let owner_id = &root_account.owner()?;
|
|
||||||
for (id, process_instruction) in &self.programs {
|
for (id, process_instruction) in &self.programs {
|
||||||
if id == owner_id {
|
if id == owner_id {
|
||||||
// Call the program via a builtin loader
|
// Call the program via a builtin loader
|
||||||
return process_instruction(
|
return process_instruction(
|
||||||
program_id,
|
|
||||||
0, // no root_id was provided
|
0, // no root_id was provided
|
||||||
instruction_data,
|
instruction_data,
|
||||||
invoke_context,
|
invoke_context,
|
||||||
@ -620,11 +615,8 @@ impl InstructionProcessor {
|
|||||||
instruction_processor.add_program(program_id, *process_instruction);
|
instruction_processor.add_program(program_id, *process_instruction);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut result = instruction_processor.process_instruction(
|
let mut result =
|
||||||
program_id,
|
instruction_processor.process_instruction(&instruction.data, invoke_context);
|
||||||
&instruction.data,
|
|
||||||
invoke_context,
|
|
||||||
);
|
|
||||||
if result.is_ok() {
|
if result.is_ok() {
|
||||||
// Verify the called program has not misbehaved
|
// Verify the called program has not misbehaved
|
||||||
let demote_program_write_locks =
|
let demote_program_write_locks =
|
||||||
@ -1084,7 +1076,6 @@ mod tests {
|
|||||||
let mut instruction_processor = InstructionProcessor::default();
|
let mut instruction_processor = InstructionProcessor::default();
|
||||||
#[allow(clippy::unnecessary_wraps)]
|
#[allow(clippy::unnecessary_wraps)]
|
||||||
fn mock_process_instruction(
|
fn mock_process_instruction(
|
||||||
_program_id: &Pubkey,
|
|
||||||
_first_instruction_account: usize,
|
_first_instruction_account: usize,
|
||||||
_data: &[u8],
|
_data: &[u8],
|
||||||
_invoke_context: &mut dyn InvokeContext,
|
_invoke_context: &mut dyn InvokeContext,
|
||||||
@ -1093,7 +1084,6 @@ mod tests {
|
|||||||
}
|
}
|
||||||
#[allow(clippy::unnecessary_wraps)]
|
#[allow(clippy::unnecessary_wraps)]
|
||||||
fn mock_ix_processor(
|
fn mock_ix_processor(
|
||||||
_pubkey: &Pubkey,
|
|
||||||
_first_instruction_account: usize,
|
_first_instruction_account: usize,
|
||||||
_data: &[u8],
|
_data: &[u8],
|
||||||
_context: &mut dyn InvokeContext,
|
_context: &mut dyn InvokeContext,
|
||||||
|
@ -14,7 +14,6 @@ use solana_sdk::{
|
|||||||
keyed_account::keyed_account_at_index,
|
keyed_account::keyed_account_at_index,
|
||||||
native_loader,
|
native_loader,
|
||||||
process_instruction::{InvokeContext, LoaderEntrypoint},
|
process_instruction::{InvokeContext, LoaderEntrypoint},
|
||||||
pubkey::Pubkey,
|
|
||||||
};
|
};
|
||||||
use std::{
|
use std::{
|
||||||
collections::HashMap,
|
collections::HashMap,
|
||||||
@ -137,12 +136,12 @@ impl NativeLoader {
|
|||||||
|
|
||||||
pub fn process_instruction(
|
pub fn process_instruction(
|
||||||
&self,
|
&self,
|
||||||
program_id: &Pubkey,
|
|
||||||
first_instruction_account: usize,
|
first_instruction_account: usize,
|
||||||
instruction_data: &[u8],
|
instruction_data: &[u8],
|
||||||
invoke_context: &mut dyn InvokeContext,
|
invoke_context: &mut dyn InvokeContext,
|
||||||
) -> Result<(), InstructionError> {
|
) -> Result<(), InstructionError> {
|
||||||
let (program_id, name_vec) = {
|
let (program_id, name_vec) = {
|
||||||
|
let program_id = invoke_context.get_caller()?;
|
||||||
let keyed_accounts = invoke_context.get_keyed_accounts()?;
|
let keyed_accounts = invoke_context.get_keyed_accounts()?;
|
||||||
let program = keyed_account_at_index(keyed_accounts, first_instruction_account)?;
|
let program = keyed_account_at_index(keyed_accounts, first_instruction_account)?;
|
||||||
if native_loader::id() != *program_id {
|
if native_loader::id() != *program_id {
|
||||||
|
@ -100,7 +100,6 @@ fn get_invoke_context<'a>() -> &'a mut dyn InvokeContext {
|
|||||||
|
|
||||||
pub fn builtin_process_instruction(
|
pub fn builtin_process_instruction(
|
||||||
process_instruction: solana_sdk::entrypoint::ProcessInstruction,
|
process_instruction: solana_sdk::entrypoint::ProcessInstruction,
|
||||||
program_id: &Pubkey,
|
|
||||||
_first_instruction_account: usize,
|
_first_instruction_account: usize,
|
||||||
input: &[u8],
|
input: &[u8],
|
||||||
invoke_context: &mut dyn InvokeContext,
|
invoke_context: &mut dyn InvokeContext,
|
||||||
@ -108,6 +107,7 @@ pub fn builtin_process_instruction(
|
|||||||
set_invoke_context(invoke_context);
|
set_invoke_context(invoke_context);
|
||||||
|
|
||||||
let logger = invoke_context.get_logger();
|
let logger = invoke_context.get_logger();
|
||||||
|
let program_id = invoke_context.get_caller()?;
|
||||||
stable_log::program_invoke(&logger, program_id, invoke_context.invoke_depth());
|
stable_log::program_invoke(&logger, program_id, invoke_context.invoke_depth());
|
||||||
|
|
||||||
// Skip the processor account
|
// Skip the processor account
|
||||||
@ -184,13 +184,11 @@ pub fn builtin_process_instruction(
|
|||||||
macro_rules! processor {
|
macro_rules! processor {
|
||||||
($process_instruction:expr) => {
|
($process_instruction:expr) => {
|
||||||
Some(
|
Some(
|
||||||
|program_id: &Pubkey,
|
|first_instruction_account: usize,
|
||||||
first_instruction_account: usize,
|
|
||||||
input: &[u8],
|
input: &[u8],
|
||||||
invoke_context: &mut dyn solana_sdk::process_instruction::InvokeContext| {
|
invoke_context: &mut dyn solana_sdk::process_instruction::InvokeContext| {
|
||||||
$crate::builtin_process_instruction(
|
$crate::builtin_process_instruction(
|
||||||
$process_instruction,
|
$process_instruction,
|
||||||
program_id,
|
|
||||||
first_instruction_account,
|
first_instruction_account,
|
||||||
input,
|
input,
|
||||||
invoke_context,
|
invoke_context,
|
||||||
|
@ -95,7 +95,7 @@ fn bench_program_alu(bencher: &mut Bencher) {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
inner_iter.write_u64::<LittleEndian>(0).unwrap();
|
inner_iter.write_u64::<LittleEndian>(0).unwrap();
|
||||||
let loader_id = bpf_loader::id();
|
let loader_id = bpf_loader::id();
|
||||||
let mut invoke_context = MockInvokeContext::new(vec![]);
|
let mut invoke_context = MockInvokeContext::new(&Pubkey::default(), vec![]);
|
||||||
|
|
||||||
let elf = load_elf("bench_alu").unwrap();
|
let elf = load_elf("bench_alu").unwrap();
|
||||||
let mut executable = <dyn Executable<BpfError, ThisInstructionMeter>>::from_elf(
|
let mut executable = <dyn Executable<BpfError, ThisInstructionMeter>>::from_elf(
|
||||||
@ -216,13 +216,13 @@ fn bench_instruction_count_tuner(_bencher: &mut Bencher) {
|
|||||||
.collect();
|
.collect();
|
||||||
let instruction_data = vec![0u8];
|
let instruction_data = vec![0u8];
|
||||||
|
|
||||||
let mut invoke_context = MockInvokeContext::new(keyed_accounts);
|
let mut invoke_context = MockInvokeContext::new(&loader_id, keyed_accounts);
|
||||||
invoke_context.compute_meter.remaining = BUDGET;
|
invoke_context.compute_meter.remaining = BUDGET;
|
||||||
|
|
||||||
// Serialize account data
|
// Serialize account data
|
||||||
let keyed_accounts = invoke_context.get_keyed_accounts().unwrap();
|
let keyed_accounts = invoke_context.get_keyed_accounts().unwrap();
|
||||||
let (mut serialized, account_lengths) = serialize_parameters(
|
let (mut serialized, account_lengths) = serialize_parameters(
|
||||||
&bpf_loader::id(),
|
&loader_id,
|
||||||
&solana_sdk::pubkey::new_rand(),
|
&solana_sdk::pubkey::new_rand(),
|
||||||
keyed_accounts,
|
keyed_accounts,
|
||||||
&instruction_data,
|
&instruction_data,
|
||||||
|
@ -203,13 +203,13 @@ fn run_program(
|
|||||||
file.read_to_end(&mut data).unwrap();
|
file.read_to_end(&mut data).unwrap();
|
||||||
let loader_id = bpf_loader::id();
|
let loader_id = bpf_loader::id();
|
||||||
let (parameter_bytes, account_lengths) = serialize_parameters(
|
let (parameter_bytes, account_lengths) = serialize_parameters(
|
||||||
&bpf_loader::id(),
|
&loader_id,
|
||||||
program_id,
|
program_id,
|
||||||
¶meter_accounts,
|
¶meter_accounts,
|
||||||
&instruction_data,
|
&instruction_data,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let mut invoke_context = MockInvokeContext::new(parameter_accounts);
|
let mut invoke_context = MockInvokeContext::new(&loader_id, parameter_accounts);
|
||||||
let compute_meter = invoke_context.get_compute_meter();
|
let compute_meter = invoke_context.get_compute_meter();
|
||||||
let mut instruction_meter = ThisInstructionMeter { compute_meter };
|
let mut instruction_meter = ThisInstructionMeter { compute_meter };
|
||||||
|
|
||||||
@ -284,7 +284,7 @@ fn run_program(
|
|||||||
}
|
}
|
||||||
let parameter_accounts = invoke_context.get_keyed_accounts().unwrap();
|
let parameter_accounts = invoke_context.get_keyed_accounts().unwrap();
|
||||||
deserialize_parameters(
|
deserialize_parameters(
|
||||||
&bpf_loader::id(),
|
&loader_id,
|
||||||
parameter_accounts,
|
parameter_accounts,
|
||||||
parameter_bytes.as_slice(),
|
parameter_bytes.as_slice(),
|
||||||
&account_lengths,
|
&account_lengths,
|
||||||
|
@ -167,13 +167,11 @@ pub fn create_vm<'a>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn process_instruction(
|
pub fn process_instruction(
|
||||||
program_id: &Pubkey,
|
|
||||||
first_instruction_account: usize,
|
first_instruction_account: usize,
|
||||||
instruction_data: &[u8],
|
instruction_data: &[u8],
|
||||||
invoke_context: &mut dyn InvokeContext,
|
invoke_context: &mut dyn InvokeContext,
|
||||||
) -> Result<(), InstructionError> {
|
) -> Result<(), InstructionError> {
|
||||||
process_instruction_common(
|
process_instruction_common(
|
||||||
program_id,
|
|
||||||
first_instruction_account,
|
first_instruction_account,
|
||||||
instruction_data,
|
instruction_data,
|
||||||
invoke_context,
|
invoke_context,
|
||||||
@ -182,13 +180,11 @@ pub fn process_instruction(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn process_instruction_jit(
|
pub fn process_instruction_jit(
|
||||||
program_id: &Pubkey,
|
|
||||||
first_instruction_account: usize,
|
first_instruction_account: usize,
|
||||||
instruction_data: &[u8],
|
instruction_data: &[u8],
|
||||||
invoke_context: &mut dyn InvokeContext,
|
invoke_context: &mut dyn InvokeContext,
|
||||||
) -> Result<(), InstructionError> {
|
) -> Result<(), InstructionError> {
|
||||||
process_instruction_common(
|
process_instruction_common(
|
||||||
program_id,
|
|
||||||
first_instruction_account,
|
first_instruction_account,
|
||||||
instruction_data,
|
instruction_data,
|
||||||
invoke_context,
|
invoke_context,
|
||||||
@ -197,7 +193,6 @@ pub fn process_instruction_jit(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn process_instruction_common(
|
fn process_instruction_common(
|
||||||
program_id: &Pubkey,
|
|
||||||
first_instruction_account: usize,
|
first_instruction_account: usize,
|
||||||
instruction_data: &[u8],
|
instruction_data: &[u8],
|
||||||
invoke_context: &mut dyn InvokeContext,
|
invoke_context: &mut dyn InvokeContext,
|
||||||
@ -213,6 +208,7 @@ fn process_instruction_common(
|
|||||||
1 - (invoke_context.invoke_depth() > 1) as usize,
|
1 - (invoke_context.invoke_depth() > 1) as usize,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let program_id = invoke_context.get_caller()?;
|
||||||
if first_account.unsigned_key() != program_id {
|
if first_account.unsigned_key() != program_id {
|
||||||
ic_logger_msg!(logger, "Program id mismatch");
|
ic_logger_msg!(logger, "Program id mismatch");
|
||||||
return Err(InstructionError::IncorrectProgramId);
|
return Err(InstructionError::IncorrectProgramId);
|
||||||
@ -273,12 +269,12 @@ fn process_instruction_common(
|
|||||||
invoke_context,
|
invoke_context,
|
||||||
use_jit,
|
use_jit,
|
||||||
)?;
|
)?;
|
||||||
|
let program_id = invoke_context.get_caller()?;
|
||||||
invoke_context.add_executor(program_id, executor.clone());
|
invoke_context.add_executor(program_id, executor.clone());
|
||||||
executor
|
executor
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
executor.execute(
|
executor.execute(
|
||||||
program_id,
|
|
||||||
first_instruction_account,
|
first_instruction_account,
|
||||||
instruction_data,
|
instruction_data,
|
||||||
invoke_context,
|
invoke_context,
|
||||||
@ -286,6 +282,8 @@ fn process_instruction_common(
|
|||||||
)?
|
)?
|
||||||
} else {
|
} else {
|
||||||
debug_assert_eq!(first_instruction_account, 1);
|
debug_assert_eq!(first_instruction_account, 1);
|
||||||
|
|
||||||
|
let program_id = invoke_context.get_caller()?;
|
||||||
if !check_loader_id(program_id) {
|
if !check_loader_id(program_id) {
|
||||||
ic_logger_msg!(logger, "Invalid BPF loader id");
|
ic_logger_msg!(logger, "Invalid BPF loader id");
|
||||||
return Err(InstructionError::IncorrectProgramId);
|
return Err(InstructionError::IncorrectProgramId);
|
||||||
@ -293,7 +291,6 @@ fn process_instruction_common(
|
|||||||
|
|
||||||
if bpf_loader_upgradeable::check_id(program_id) {
|
if bpf_loader_upgradeable::check_id(program_id) {
|
||||||
process_loader_upgradeable_instruction(
|
process_loader_upgradeable_instruction(
|
||||||
program_id,
|
|
||||||
first_instruction_account,
|
first_instruction_account,
|
||||||
instruction_data,
|
instruction_data,
|
||||||
invoke_context,
|
invoke_context,
|
||||||
@ -301,7 +298,6 @@ fn process_instruction_common(
|
|||||||
)?;
|
)?;
|
||||||
} else {
|
} else {
|
||||||
process_loader_instruction(
|
process_loader_instruction(
|
||||||
program_id,
|
|
||||||
first_instruction_account,
|
first_instruction_account,
|
||||||
instruction_data,
|
instruction_data,
|
||||||
invoke_context,
|
invoke_context,
|
||||||
@ -313,13 +309,13 @@ fn process_instruction_common(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn process_loader_upgradeable_instruction(
|
fn process_loader_upgradeable_instruction(
|
||||||
program_id: &Pubkey,
|
|
||||||
first_instruction_account: usize,
|
first_instruction_account: usize,
|
||||||
instruction_data: &[u8],
|
instruction_data: &[u8],
|
||||||
invoke_context: &mut dyn InvokeContext,
|
invoke_context: &mut dyn InvokeContext,
|
||||||
use_jit: bool,
|
use_jit: bool,
|
||||||
) -> Result<(), InstructionError> {
|
) -> Result<(), InstructionError> {
|
||||||
let logger = invoke_context.get_logger();
|
let logger = invoke_context.get_logger();
|
||||||
|
let program_id = invoke_context.get_caller()?;
|
||||||
let keyed_accounts = invoke_context.get_keyed_accounts()?;
|
let keyed_accounts = invoke_context.get_keyed_accounts()?;
|
||||||
|
|
||||||
match limited_deserialize(instruction_data)? {
|
match limited_deserialize(instruction_data)? {
|
||||||
@ -867,12 +863,12 @@ fn common_close_account(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn process_loader_instruction(
|
fn process_loader_instruction(
|
||||||
program_id: &Pubkey,
|
|
||||||
first_instruction_account: usize,
|
first_instruction_account: usize,
|
||||||
instruction_data: &[u8],
|
instruction_data: &[u8],
|
||||||
invoke_context: &mut dyn InvokeContext,
|
invoke_context: &mut dyn InvokeContext,
|
||||||
use_jit: bool,
|
use_jit: bool,
|
||||||
) -> Result<(), InstructionError> {
|
) -> Result<(), InstructionError> {
|
||||||
|
let program_id = invoke_context.get_caller()?;
|
||||||
let keyed_accounts = invoke_context.get_keyed_accounts()?;
|
let keyed_accounts = invoke_context.get_keyed_accounts()?;
|
||||||
let program = keyed_account_at_index(keyed_accounts, first_instruction_account)?;
|
let program = keyed_account_at_index(keyed_accounts, first_instruction_account)?;
|
||||||
if program.owner()? != *program_id {
|
if program.owner()? != *program_id {
|
||||||
@ -947,7 +943,6 @@ impl Debug for BpfExecutor {
|
|||||||
impl Executor for BpfExecutor {
|
impl Executor for BpfExecutor {
|
||||||
fn execute(
|
fn execute(
|
||||||
&self,
|
&self,
|
||||||
program_id: &Pubkey,
|
|
||||||
first_instruction_account: usize,
|
first_instruction_account: usize,
|
||||||
instruction_data: &[u8],
|
instruction_data: &[u8],
|
||||||
invoke_context: &mut dyn InvokeContext,
|
invoke_context: &mut dyn InvokeContext,
|
||||||
@ -962,6 +957,7 @@ impl Executor for BpfExecutor {
|
|||||||
let keyed_accounts = invoke_context.get_keyed_accounts()?;
|
let keyed_accounts = invoke_context.get_keyed_accounts()?;
|
||||||
let program = keyed_account_at_index(keyed_accounts, first_instruction_account)?;
|
let program = keyed_account_at_index(keyed_accounts, first_instruction_account)?;
|
||||||
let loader_id = &program.owner()?;
|
let loader_id = &program.owner()?;
|
||||||
|
let program_id = invoke_context.get_caller()?;
|
||||||
let (mut parameter_bytes, account_lengths) = serialize_parameters(
|
let (mut parameter_bytes, account_lengths) = serialize_parameters(
|
||||||
loader_id,
|
loader_id,
|
||||||
program_id,
|
program_id,
|
||||||
@ -972,6 +968,7 @@ impl Executor for BpfExecutor {
|
|||||||
let mut create_vm_time = Measure::start("create_vm");
|
let mut create_vm_time = Measure::start("create_vm");
|
||||||
let mut execute_time;
|
let mut execute_time;
|
||||||
{
|
{
|
||||||
|
let program_id = &invoke_context.get_caller()?.clone();
|
||||||
let compute_meter = invoke_context.get_compute_meter();
|
let compute_meter = invoke_context.get_compute_meter();
|
||||||
let mut vm = match create_vm(
|
let mut vm = match create_vm(
|
||||||
loader_id,
|
loader_id,
|
||||||
@ -1064,6 +1061,7 @@ impl Executor for BpfExecutor {
|
|||||||
execute_time.as_us(),
|
execute_time.as_us(),
|
||||||
deserialize_time.as_us(),
|
deserialize_time.as_us(),
|
||||||
);
|
);
|
||||||
|
let program_id = invoke_context.get_caller()?;
|
||||||
stable_log::program_success(&logger, program_id);
|
stable_log::program_success(&logger, program_id);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -1121,10 +1119,9 @@ mod tests {
|
|||||||
let mut keyed_accounts = keyed_accounts.to_vec();
|
let mut keyed_accounts = keyed_accounts.to_vec();
|
||||||
keyed_accounts.insert(0, (false, false, owner, &processor_account));
|
keyed_accounts.insert(0, (false, false, owner, &processor_account));
|
||||||
super::process_instruction(
|
super::process_instruction(
|
||||||
owner,
|
|
||||||
1,
|
1,
|
||||||
instruction_data,
|
instruction_data,
|
||||||
&mut MockInvokeContext::new(create_keyed_accounts_unified(&keyed_accounts)),
|
&mut MockInvokeContext::new(owner, create_keyed_accounts_unified(&keyed_accounts)),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1315,11 +1312,11 @@ mod tests {
|
|||||||
let mut keyed_accounts = keyed_accounts.clone();
|
let mut keyed_accounts = keyed_accounts.clone();
|
||||||
keyed_accounts.insert(0, (false, false, &program_key, &processor_account));
|
keyed_accounts.insert(0, (false, false, &program_key, &processor_account));
|
||||||
let mut invoke_context =
|
let mut invoke_context =
|
||||||
MockInvokeContext::new(create_keyed_accounts_unified(&keyed_accounts));
|
MockInvokeContext::new(&program_key, create_keyed_accounts_unified(&keyed_accounts));
|
||||||
invoke_context.compute_meter = MockComputeMeter::default();
|
invoke_context.compute_meter = MockComputeMeter::default();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
Err(InstructionError::ProgramFailedToComplete),
|
Err(InstructionError::ProgramFailedToComplete),
|
||||||
super::process_instruction(&program_key, 1, &[], &mut invoke_context)
|
super::process_instruction(1, &[], &mut invoke_context)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3331,7 +3331,7 @@ mod tests {
|
|||||||
leader_schedule_epoch: 4,
|
leader_schedule_epoch: 4,
|
||||||
unix_timestamp: 5,
|
unix_timestamp: 5,
|
||||||
};
|
};
|
||||||
let mut invoke_context = MockInvokeContext::new(vec![]);
|
let mut invoke_context = MockInvokeContext::new(&Pubkey::default(), vec![]);
|
||||||
let mut data = vec![];
|
let mut data = vec![];
|
||||||
bincode::serialize_into(&mut data, &src_clock).unwrap();
|
bincode::serialize_into(&mut data, &src_clock).unwrap();
|
||||||
invoke_context
|
invoke_context
|
||||||
@ -3376,7 +3376,7 @@ mod tests {
|
|||||||
first_normal_epoch: 3,
|
first_normal_epoch: 3,
|
||||||
first_normal_slot: 4,
|
first_normal_slot: 4,
|
||||||
};
|
};
|
||||||
let mut invoke_context = MockInvokeContext::new(vec![]);
|
let mut invoke_context = MockInvokeContext::new(&Pubkey::default(), vec![]);
|
||||||
let mut data = vec![];
|
let mut data = vec![];
|
||||||
bincode::serialize_into(&mut data, &src_epochschedule).unwrap();
|
bincode::serialize_into(&mut data, &src_epochschedule).unwrap();
|
||||||
invoke_context
|
invoke_context
|
||||||
@ -3428,7 +3428,7 @@ mod tests {
|
|||||||
lamports_per_signature: 1,
|
lamports_per_signature: 1,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
let mut invoke_context = MockInvokeContext::new(vec![]);
|
let mut invoke_context = MockInvokeContext::new(&Pubkey::default(), vec![]);
|
||||||
let mut data = vec![];
|
let mut data = vec![];
|
||||||
bincode::serialize_into(&mut data, &src_fees).unwrap();
|
bincode::serialize_into(&mut data, &src_fees).unwrap();
|
||||||
invoke_context
|
invoke_context
|
||||||
@ -3471,7 +3471,7 @@ mod tests {
|
|||||||
exemption_threshold: 2.0,
|
exemption_threshold: 2.0,
|
||||||
burn_percent: 3,
|
burn_percent: 3,
|
||||||
};
|
};
|
||||||
let mut invoke_context = MockInvokeContext::new(vec![]);
|
let mut invoke_context = MockInvokeContext::new(&Pubkey::default(), vec![]);
|
||||||
let mut data = vec![];
|
let mut data = vec![];
|
||||||
bincode::serialize_into(&mut data, &src_rent).unwrap();
|
bincode::serialize_into(&mut data, &src_rent).unwrap();
|
||||||
invoke_context
|
invoke_context
|
||||||
|
@ -1,9 +1,6 @@
|
|||||||
use solana_sdk::{
|
use solana_sdk::{instruction::InstructionError, process_instruction::InvokeContext};
|
||||||
instruction::InstructionError, process_instruction::InvokeContext, pubkey::Pubkey,
|
|
||||||
};
|
|
||||||
|
|
||||||
pub fn process_instruction(
|
pub fn process_instruction(
|
||||||
_program_id: &Pubkey,
|
|
||||||
_first_instruction_account: usize,
|
_first_instruction_account: usize,
|
||||||
_data: &[u8],
|
_data: &[u8],
|
||||||
_invoke_context: &mut dyn InvokeContext,
|
_invoke_context: &mut dyn InvokeContext,
|
||||||
|
@ -14,7 +14,6 @@ use solana_sdk::{
|
|||||||
use std::collections::BTreeSet;
|
use std::collections::BTreeSet;
|
||||||
|
|
||||||
pub fn process_instruction(
|
pub fn process_instruction(
|
||||||
_program_id: &Pubkey,
|
|
||||||
first_instruction_account: usize,
|
first_instruction_account: usize,
|
||||||
data: &[u8],
|
data: &[u8],
|
||||||
invoke_context: &mut dyn InvokeContext,
|
invoke_context: &mut dyn InvokeContext,
|
||||||
@ -144,6 +143,7 @@ mod tests {
|
|||||||
account::{Account, AccountSharedData},
|
account::{Account, AccountSharedData},
|
||||||
keyed_account::create_keyed_accounts_unified,
|
keyed_account::create_keyed_accounts_unified,
|
||||||
process_instruction::MockInvokeContext,
|
process_instruction::MockInvokeContext,
|
||||||
|
pubkey::Pubkey,
|
||||||
signature::{Keypair, Signer},
|
signature::{Keypair, Signer},
|
||||||
system_instruction::SystemInstruction,
|
system_instruction::SystemInstruction,
|
||||||
};
|
};
|
||||||
@ -158,10 +158,9 @@ mod tests {
|
|||||||
let mut keyed_accounts = keyed_accounts.to_vec();
|
let mut keyed_accounts = keyed_accounts.to_vec();
|
||||||
keyed_accounts.insert(0, (false, false, owner, &processor_account));
|
keyed_accounts.insert(0, (false, false, owner, &processor_account));
|
||||||
super::process_instruction(
|
super::process_instruction(
|
||||||
owner,
|
|
||||||
1,
|
1,
|
||||||
instruction_data,
|
instruction_data,
|
||||||
&mut MockInvokeContext::new(create_keyed_accounts_unified(&keyed_accounts)),
|
&mut MockInvokeContext::new(owner, create_keyed_accounts_unified(&keyed_accounts)),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,7 +7,6 @@ use {
|
|||||||
keyed_account::{from_keyed_account, get_signers, keyed_account_at_index},
|
keyed_account::{from_keyed_account, get_signers, keyed_account_at_index},
|
||||||
process_instruction::{get_sysvar, InvokeContext},
|
process_instruction::{get_sysvar, InvokeContext},
|
||||||
program_utils::limited_deserialize,
|
program_utils::limited_deserialize,
|
||||||
pubkey::Pubkey,
|
|
||||||
stake::{
|
stake::{
|
||||||
instruction::StakeInstruction,
|
instruction::StakeInstruction,
|
||||||
program::id,
|
program::id,
|
||||||
@ -24,7 +23,6 @@ use {
|
|||||||
pub use solana_sdk::stake::instruction::*;
|
pub use solana_sdk::stake::instruction::*;
|
||||||
|
|
||||||
pub fn process_instruction(
|
pub fn process_instruction(
|
||||||
_program_id: &Pubkey,
|
|
||||||
first_instruction_account: usize,
|
first_instruction_account: usize,
|
||||||
data: &[u8],
|
data: &[u8],
|
||||||
invoke_context: &mut dyn InvokeContext,
|
invoke_context: &mut dyn InvokeContext,
|
||||||
@ -333,6 +331,7 @@ mod tests {
|
|||||||
instruction::{AccountMeta, Instruction},
|
instruction::{AccountMeta, Instruction},
|
||||||
keyed_account::create_keyed_accounts_unified,
|
keyed_account::create_keyed_accounts_unified,
|
||||||
process_instruction::{mock_set_sysvar, MockInvokeContext},
|
process_instruction::{mock_set_sysvar, MockInvokeContext},
|
||||||
|
pubkey::Pubkey,
|
||||||
rent::Rent,
|
rent::Rent,
|
||||||
stake::{
|
stake::{
|
||||||
config as stake_config,
|
config as stake_config,
|
||||||
@ -379,10 +378,9 @@ mod tests {
|
|||||||
let mut keyed_accounts = keyed_accounts.to_vec();
|
let mut keyed_accounts = keyed_accounts.to_vec();
|
||||||
keyed_accounts.insert(0, (false, false, owner, &processor_account));
|
keyed_accounts.insert(0, (false, false, owner, &processor_account));
|
||||||
super::process_instruction(
|
super::process_instruction(
|
||||||
owner,
|
|
||||||
1,
|
1,
|
||||||
instruction_data,
|
instruction_data,
|
||||||
&mut MockInvokeContext::new(create_keyed_accounts_unified(&keyed_accounts)),
|
&mut MockInvokeContext::new(owner, create_keyed_accounts_unified(&keyed_accounts)),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -440,20 +438,17 @@ mod tests {
|
|||||||
.collect();
|
.collect();
|
||||||
let processor_id = id();
|
let processor_id = id();
|
||||||
keyed_accounts.insert(0, (false, false, &processor_id, &processor_account));
|
keyed_accounts.insert(0, (false, false, &processor_id, &processor_account));
|
||||||
let mut invoke_context =
|
let mut invoke_context = MockInvokeContext::new(
|
||||||
MockInvokeContext::new(create_keyed_accounts_unified(&keyed_accounts));
|
&processor_id,
|
||||||
|
create_keyed_accounts_unified(&keyed_accounts),
|
||||||
|
);
|
||||||
mock_set_sysvar(
|
mock_set_sysvar(
|
||||||
&mut invoke_context,
|
&mut invoke_context,
|
||||||
sysvar::clock::id(),
|
sysvar::clock::id(),
|
||||||
sysvar::clock::Clock::default(),
|
sysvar::clock::Clock::default(),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
super::process_instruction(
|
super::process_instruction(1, &instruction.data, &mut invoke_context)
|
||||||
&Pubkey::default(),
|
|
||||||
1,
|
|
||||||
&instruction.data,
|
|
||||||
&mut invoke_context,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1104,7 +1099,7 @@ mod tests {
|
|||||||
(true, false, &custodian, &custodian_account),
|
(true, false, &custodian, &custodian_account),
|
||||||
];
|
];
|
||||||
let mut invoke_context =
|
let mut invoke_context =
|
||||||
MockInvokeContext::new(create_keyed_accounts_unified(&keyed_accounts));
|
MockInvokeContext::new(&id(), create_keyed_accounts_unified(&keyed_accounts));
|
||||||
let clock = Clock::default();
|
let clock = Clock::default();
|
||||||
let mut data = vec![];
|
let mut data = vec![];
|
||||||
bincode::serialize_into(&mut data, &clock).unwrap();
|
bincode::serialize_into(&mut data, &clock).unwrap();
|
||||||
@ -1114,7 +1109,6 @@ mod tests {
|
|||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
super::process_instruction(
|
super::process_instruction(
|
||||||
&Pubkey::default(),
|
|
||||||
1,
|
1,
|
||||||
&serialize(&StakeInstruction::SetLockupChecked(LockupCheckedArgs {
|
&serialize(&StakeInstruction::SetLockupChecked(LockupCheckedArgs {
|
||||||
unix_timestamp: None,
|
unix_timestamp: None,
|
||||||
|
@ -5075,7 +5075,7 @@ mod tests {
|
|||||||
let stake_lamports = 42;
|
let stake_lamports = 42;
|
||||||
|
|
||||||
let signers = vec![authorized_pubkey].into_iter().collect();
|
let signers = vec![authorized_pubkey].into_iter().collect();
|
||||||
let invoke_context = MockInvokeContext::new(vec![]);
|
let invoke_context = MockInvokeContext::new(&Pubkey::default(), vec![]);
|
||||||
|
|
||||||
for state in &[
|
for state in &[
|
||||||
StakeState::Initialized(Meta::auto(&authorized_pubkey)),
|
StakeState::Initialized(Meta::auto(&authorized_pubkey)),
|
||||||
@ -5179,7 +5179,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_merge_self_fails() {
|
fn test_merge_self_fails() {
|
||||||
let invoke_context = MockInvokeContext::new(vec![]);
|
let invoke_context = MockInvokeContext::new(&Pubkey::default(), vec![]);
|
||||||
let stake_address = Pubkey::new_unique();
|
let stake_address = Pubkey::new_unique();
|
||||||
let authority_pubkey = Pubkey::new_unique();
|
let authority_pubkey = Pubkey::new_unique();
|
||||||
let signers = HashSet::from_iter(vec![authority_pubkey]);
|
let signers = HashSet::from_iter(vec![authority_pubkey]);
|
||||||
@ -5232,7 +5232,7 @@ mod tests {
|
|||||||
|
|
||||||
let signers = vec![authorized_pubkey].into_iter().collect();
|
let signers = vec![authorized_pubkey].into_iter().collect();
|
||||||
let wrong_signers = vec![wrong_authorized_pubkey].into_iter().collect();
|
let wrong_signers = vec![wrong_authorized_pubkey].into_iter().collect();
|
||||||
let invoke_context = MockInvokeContext::new(vec![]);
|
let invoke_context = MockInvokeContext::new(&Pubkey::default(), vec![]);
|
||||||
|
|
||||||
for state in &[
|
for state in &[
|
||||||
StakeState::Initialized(Meta::auto(&authorized_pubkey)),
|
StakeState::Initialized(Meta::auto(&authorized_pubkey)),
|
||||||
@ -5298,7 +5298,7 @@ mod tests {
|
|||||||
let authorized_pubkey = solana_sdk::pubkey::new_rand();
|
let authorized_pubkey = solana_sdk::pubkey::new_rand();
|
||||||
let stake_lamports = 42;
|
let stake_lamports = 42;
|
||||||
let signers = vec![authorized_pubkey].into_iter().collect();
|
let signers = vec![authorized_pubkey].into_iter().collect();
|
||||||
let invoke_context = MockInvokeContext::new(vec![]);
|
let invoke_context = MockInvokeContext::new(&Pubkey::default(), vec![]);
|
||||||
|
|
||||||
for state in &[
|
for state in &[
|
||||||
StakeState::Uninitialized,
|
StakeState::Uninitialized,
|
||||||
@ -5368,7 +5368,7 @@ mod tests {
|
|||||||
.expect("source_stake_account");
|
.expect("source_stake_account");
|
||||||
let source_stake_keyed_account =
|
let source_stake_keyed_account =
|
||||||
KeyedAccount::new(&source_stake_pubkey, true, &source_stake_account);
|
KeyedAccount::new(&source_stake_pubkey, true, &source_stake_account);
|
||||||
let invoke_context = MockInvokeContext::new(vec![]);
|
let invoke_context = MockInvokeContext::new(&Pubkey::default(), vec![]);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
stake_keyed_account.merge(
|
stake_keyed_account.merge(
|
||||||
@ -5438,7 +5438,7 @@ mod tests {
|
|||||||
|
|
||||||
let mut clock = Clock::default();
|
let mut clock = Clock::default();
|
||||||
let mut stake_history = StakeHistory::default();
|
let mut stake_history = StakeHistory::default();
|
||||||
let invoke_context = MockInvokeContext::new(vec![]);
|
let invoke_context = MockInvokeContext::new(&Pubkey::default(), vec![]);
|
||||||
|
|
||||||
clock.epoch = 0;
|
clock.epoch = 0;
|
||||||
let mut effective = base_lamports;
|
let mut effective = base_lamports;
|
||||||
@ -6016,7 +6016,7 @@ mod tests {
|
|||||||
..Delegation::default()
|
..Delegation::default()
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
let invoke_context = MockInvokeContext::new(vec![]);
|
let invoke_context = MockInvokeContext::new(&Pubkey::default(), vec![]);
|
||||||
|
|
||||||
let identical = good_stake;
|
let identical = good_stake;
|
||||||
assert!(
|
assert!(
|
||||||
@ -6105,7 +6105,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_metas_can_merge_pre_v4() {
|
fn test_metas_can_merge_pre_v4() {
|
||||||
let invoke_context = MockInvokeContext::new(vec![]);
|
let invoke_context = MockInvokeContext::new(&Pubkey::default(), vec![]);
|
||||||
// Identical Metas can merge
|
// Identical Metas can merge
|
||||||
assert!(MergeKind::metas_can_merge(
|
assert!(MergeKind::metas_can_merge(
|
||||||
&invoke_context,
|
&invoke_context,
|
||||||
@ -6191,7 +6191,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_metas_can_merge_v4() {
|
fn test_metas_can_merge_v4() {
|
||||||
let invoke_context = MockInvokeContext::new(vec![]);
|
let invoke_context = MockInvokeContext::new(&Pubkey::default(), vec![]);
|
||||||
// Identical Metas can merge
|
// Identical Metas can merge
|
||||||
assert!(MergeKind::metas_can_merge(
|
assert!(MergeKind::metas_can_merge(
|
||||||
&invoke_context,
|
&invoke_context,
|
||||||
@ -6357,7 +6357,7 @@ mod tests {
|
|||||||
let stake_keyed_account = KeyedAccount::new(&authority_pubkey, true, &stake_account);
|
let stake_keyed_account = KeyedAccount::new(&authority_pubkey, true, &stake_account);
|
||||||
let mut clock = Clock::default();
|
let mut clock = Clock::default();
|
||||||
let mut stake_history = StakeHistory::default();
|
let mut stake_history = StakeHistory::default();
|
||||||
let invoke_context = MockInvokeContext::new(vec![]);
|
let invoke_context = MockInvokeContext::new(&Pubkey::default(), vec![]);
|
||||||
|
|
||||||
// Uninitialized state fails
|
// Uninitialized state fails
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
@ -6584,7 +6584,7 @@ mod tests {
|
|||||||
let inactive = MergeKind::Inactive(Meta::default(), lamports);
|
let inactive = MergeKind::Inactive(Meta::default(), lamports);
|
||||||
let activation_epoch = MergeKind::ActivationEpoch(meta, stake);
|
let activation_epoch = MergeKind::ActivationEpoch(meta, stake);
|
||||||
let fully_active = MergeKind::FullyActive(meta, stake);
|
let fully_active = MergeKind::FullyActive(meta, stake);
|
||||||
let invoke_context = MockInvokeContext::new(vec![]);
|
let invoke_context = MockInvokeContext::new(&Pubkey::default(), vec![]);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
inactive
|
inactive
|
||||||
@ -6670,7 +6670,7 @@ mod tests {
|
|||||||
credits_observed: credits_a,
|
credits_observed: credits_a,
|
||||||
};
|
};
|
||||||
|
|
||||||
let invoke_context = MockInvokeContext::new(vec![]);
|
let invoke_context = MockInvokeContext::new(&Pubkey::default(), vec![]);
|
||||||
|
|
||||||
// activating stake merge, match credits observed
|
// activating stake merge, match credits observed
|
||||||
let activation_epoch_a = MergeKind::ActivationEpoch(meta, stake_a);
|
let activation_epoch_a = MergeKind::ActivationEpoch(meta, stake_a);
|
||||||
|
@ -308,7 +308,6 @@ fn verify_rent_exemption(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn process_instruction(
|
pub fn process_instruction(
|
||||||
_program_id: &Pubkey,
|
|
||||||
first_instruction_account: usize,
|
first_instruction_account: usize,
|
||||||
data: &[u8],
|
data: &[u8],
|
||||||
invoke_context: &mut dyn InvokeContext,
|
invoke_context: &mut dyn InvokeContext,
|
||||||
@ -428,10 +427,9 @@ mod tests {
|
|||||||
let mut keyed_accounts = keyed_accounts.to_vec();
|
let mut keyed_accounts = keyed_accounts.to_vec();
|
||||||
keyed_accounts.insert(0, (false, false, owner, &processor_account));
|
keyed_accounts.insert(0, (false, false, owner, &processor_account));
|
||||||
super::process_instruction(
|
super::process_instruction(
|
||||||
owner,
|
|
||||||
1,
|
1,
|
||||||
instruction_data,
|
instruction_data,
|
||||||
&mut MockInvokeContext::new(create_keyed_accounts_unified(&keyed_accounts)),
|
&mut MockInvokeContext::new(owner, create_keyed_accounts_unified(&keyed_accounts)),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -175,7 +175,7 @@ native machine code before execting it in the virtual machine.",
|
|||||||
(Vec::from(bytes.as_slice_mut()), account_lengths)
|
(Vec::from(bytes.as_slice_mut()), account_lengths)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let mut invoke_context = MockInvokeContext::new(accounts);
|
let mut invoke_context = MockInvokeContext::new(&bpf_loader::id(), accounts);
|
||||||
let logger = invoke_context.logger.clone();
|
let logger = invoke_context.logger.clone();
|
||||||
let compute_meter = invoke_context.get_compute_meter();
|
let compute_meter = invoke_context.get_compute_meter();
|
||||||
let mut instruction_meter = ThisInstructionMeter { compute_meter };
|
let mut instruction_meter = ThisInstructionMeter { compute_meter };
|
||||||
|
@ -32,7 +32,6 @@ const NOOP_PROGRAM_ID: [u8; 32] = [
|
|||||||
|
|
||||||
#[allow(clippy::unnecessary_wraps)]
|
#[allow(clippy::unnecessary_wraps)]
|
||||||
fn process_instruction(
|
fn process_instruction(
|
||||||
_program_id: &Pubkey,
|
|
||||||
_first_instruction_account: usize,
|
_first_instruction_account: usize,
|
||||||
_data: &[u8],
|
_data: &[u8],
|
||||||
_invoke_context: &mut dyn InvokeContext,
|
_invoke_context: &mut dyn InvokeContext,
|
||||||
|
@ -6685,7 +6685,6 @@ pub(crate) mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn mock_process_instruction(
|
fn mock_process_instruction(
|
||||||
_program_id: &Pubkey,
|
|
||||||
first_instruction_account: usize,
|
first_instruction_account: usize,
|
||||||
data: &[u8],
|
data: &[u8],
|
||||||
invoke_context: &mut dyn InvokeContext,
|
invoke_context: &mut dyn InvokeContext,
|
||||||
@ -10333,11 +10332,11 @@ pub(crate) mod tests {
|
|||||||
Pubkey::new(&[42u8; 32])
|
Pubkey::new(&[42u8; 32])
|
||||||
}
|
}
|
||||||
fn mock_vote_processor(
|
fn mock_vote_processor(
|
||||||
program_id: &Pubkey,
|
|
||||||
_first_instruction_account: usize,
|
_first_instruction_account: usize,
|
||||||
_instruction_data: &[u8],
|
_instruction_data: &[u8],
|
||||||
_invoke_context: &mut dyn InvokeContext,
|
invoke_context: &mut dyn InvokeContext,
|
||||||
) -> std::result::Result<(), InstructionError> {
|
) -> std::result::Result<(), InstructionError> {
|
||||||
|
let program_id = invoke_context.get_caller()?;
|
||||||
if mock_vote_program_id() != *program_id {
|
if mock_vote_program_id() != *program_id {
|
||||||
return Err(InstructionError::IncorrectProgramId);
|
return Err(InstructionError::IncorrectProgramId);
|
||||||
}
|
}
|
||||||
@ -10391,7 +10390,6 @@ pub(crate) mod tests {
|
|||||||
let mut bank = Bank::new_for_tests(&genesis_config);
|
let mut bank = Bank::new_for_tests(&genesis_config);
|
||||||
|
|
||||||
fn mock_vote_processor(
|
fn mock_vote_processor(
|
||||||
_pubkey: &Pubkey,
|
|
||||||
_first_instruction_account: usize,
|
_first_instruction_account: usize,
|
||||||
_data: &[u8],
|
_data: &[u8],
|
||||||
_invoke_context: &mut dyn InvokeContext,
|
_invoke_context: &mut dyn InvokeContext,
|
||||||
@ -10442,7 +10440,6 @@ pub(crate) mod tests {
|
|||||||
let mut bank = Bank::new_for_tests(&genesis_config);
|
let mut bank = Bank::new_for_tests(&genesis_config);
|
||||||
|
|
||||||
fn mock_ix_processor(
|
fn mock_ix_processor(
|
||||||
_pubkey: &Pubkey,
|
|
||||||
_first_instruction_account: usize,
|
_first_instruction_account: usize,
|
||||||
_data: &[u8],
|
_data: &[u8],
|
||||||
_invoke_context: &mut dyn InvokeContext,
|
_invoke_context: &mut dyn InvokeContext,
|
||||||
@ -11284,7 +11281,6 @@ pub(crate) mod tests {
|
|||||||
let mut bank = Bank::new_for_tests(&genesis_config);
|
let mut bank = Bank::new_for_tests(&genesis_config);
|
||||||
|
|
||||||
fn mock_process_instruction(
|
fn mock_process_instruction(
|
||||||
_program_id: &Pubkey,
|
|
||||||
first_instruction_account: usize,
|
first_instruction_account: usize,
|
||||||
data: &[u8],
|
data: &[u8],
|
||||||
invoke_context: &mut dyn InvokeContext,
|
invoke_context: &mut dyn InvokeContext,
|
||||||
@ -11345,7 +11341,6 @@ pub(crate) mod tests {
|
|||||||
|
|
||||||
#[allow(clippy::unnecessary_wraps)]
|
#[allow(clippy::unnecessary_wraps)]
|
||||||
fn mock_process_instruction(
|
fn mock_process_instruction(
|
||||||
_program_id: &Pubkey,
|
|
||||||
_first_instruction_account: usize,
|
_first_instruction_account: usize,
|
||||||
_data: &[u8],
|
_data: &[u8],
|
||||||
_invoke_context: &mut dyn InvokeContext,
|
_invoke_context: &mut dyn InvokeContext,
|
||||||
@ -11532,7 +11527,6 @@ pub(crate) mod tests {
|
|||||||
|
|
||||||
#[allow(clippy::unnecessary_wraps)]
|
#[allow(clippy::unnecessary_wraps)]
|
||||||
fn mock_ok_vote_processor(
|
fn mock_ok_vote_processor(
|
||||||
_pubkey: &Pubkey,
|
|
||||||
_first_instruction_account: usize,
|
_first_instruction_account: usize,
|
||||||
_data: &[u8],
|
_data: &[u8],
|
||||||
_invoke_context: &mut dyn InvokeContext,
|
_invoke_context: &mut dyn InvokeContext,
|
||||||
@ -11783,7 +11777,6 @@ pub(crate) mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_same_program_id_uses_unqiue_executable_accounts() {
|
fn test_same_program_id_uses_unqiue_executable_accounts() {
|
||||||
fn nested_processor(
|
fn nested_processor(
|
||||||
_program_id: &Pubkey,
|
|
||||||
first_instruction_account: usize,
|
first_instruction_account: usize,
|
||||||
_data: &[u8],
|
_data: &[u8],
|
||||||
invoke_context: &mut dyn InvokeContext,
|
invoke_context: &mut dyn InvokeContext,
|
||||||
@ -12155,7 +12148,6 @@ pub(crate) mod tests {
|
|||||||
|
|
||||||
#[allow(clippy::unnecessary_wraps)]
|
#[allow(clippy::unnecessary_wraps)]
|
||||||
fn mock_ix_processor(
|
fn mock_ix_processor(
|
||||||
_pubkey: &Pubkey,
|
|
||||||
_first_instruction_account: usize,
|
_first_instruction_account: usize,
|
||||||
_data: &[u8],
|
_data: &[u8],
|
||||||
_invoke_context: &mut dyn InvokeContext,
|
_invoke_context: &mut dyn InvokeContext,
|
||||||
@ -12205,7 +12197,6 @@ pub(crate) mod tests {
|
|||||||
|
|
||||||
#[allow(clippy::unnecessary_wraps)]
|
#[allow(clippy::unnecessary_wraps)]
|
||||||
fn mock_ix_processor(
|
fn mock_ix_processor(
|
||||||
_pubkey: &Pubkey,
|
|
||||||
_first_instruction_account: usize,
|
_first_instruction_account: usize,
|
||||||
_data: &[u8],
|
_data: &[u8],
|
||||||
_context: &mut dyn InvokeContext,
|
_context: &mut dyn InvokeContext,
|
||||||
@ -12593,7 +12584,6 @@ pub(crate) mod tests {
|
|||||||
impl Executor for TestExecutor {
|
impl Executor for TestExecutor {
|
||||||
fn execute(
|
fn execute(
|
||||||
&self,
|
&self,
|
||||||
_program_id: &Pubkey,
|
|
||||||
_first_instruction_account: usize,
|
_first_instruction_account: usize,
|
||||||
_instruction_data: &[u8],
|
_instruction_data: &[u8],
|
||||||
_invoke_context: &mut dyn InvokeContext,
|
_invoke_context: &mut dyn InvokeContext,
|
||||||
@ -13097,7 +13087,6 @@ pub(crate) mod tests {
|
|||||||
// intentionally create bogus native programs
|
// intentionally create bogus native programs
|
||||||
#[allow(clippy::unnecessary_wraps)]
|
#[allow(clippy::unnecessary_wraps)]
|
||||||
fn mock_process_instruction(
|
fn mock_process_instruction(
|
||||||
_program_id: &Pubkey,
|
|
||||||
_first_instruction_account: usize,
|
_first_instruction_account: usize,
|
||||||
_data: &[u8],
|
_data: &[u8],
|
||||||
_invoke_context: &mut dyn InvokeContext,
|
_invoke_context: &mut dyn InvokeContext,
|
||||||
@ -14595,7 +14584,6 @@ pub(crate) mod tests {
|
|||||||
let mut bank = Bank::new_for_tests(&genesis_config);
|
let mut bank = Bank::new_for_tests(&genesis_config);
|
||||||
|
|
||||||
fn mock_ix_processor(
|
fn mock_ix_processor(
|
||||||
_pubkey: &Pubkey,
|
|
||||||
first_instruction_account: usize,
|
first_instruction_account: usize,
|
||||||
_data: &[u8],
|
_data: &[u8],
|
||||||
invoke_context: &mut dyn InvokeContext,
|
invoke_context: &mut dyn InvokeContext,
|
||||||
@ -14805,7 +14793,6 @@ pub(crate) mod tests {
|
|||||||
let mut bank = Bank::new_for_tests(&genesis_config);
|
let mut bank = Bank::new_for_tests(&genesis_config);
|
||||||
|
|
||||||
fn mock_ix_processor(
|
fn mock_ix_processor(
|
||||||
_pubkey: &Pubkey,
|
|
||||||
_first_instruction_account: usize,
|
_first_instruction_account: usize,
|
||||||
_data: &[u8],
|
_data: &[u8],
|
||||||
invoke_context: &mut dyn InvokeContext,
|
invoke_context: &mut dyn InvokeContext,
|
||||||
|
@ -13,7 +13,6 @@ use solana_frozen_abi::abi_example::AbiExample;
|
|||||||
|
|
||||||
fn process_instruction_with_program_logging(
|
fn process_instruction_with_program_logging(
|
||||||
process_instruction: ProcessInstructionWithContext,
|
process_instruction: ProcessInstructionWithContext,
|
||||||
program_id: &Pubkey,
|
|
||||||
first_instruction_account: usize,
|
first_instruction_account: usize,
|
||||||
instruction_data: &[u8],
|
instruction_data: &[u8],
|
||||||
invoke_context: &mut dyn InvokeContext,
|
invoke_context: &mut dyn InvokeContext,
|
||||||
@ -21,15 +20,12 @@ fn process_instruction_with_program_logging(
|
|||||||
debug_assert_eq!(first_instruction_account, 1);
|
debug_assert_eq!(first_instruction_account, 1);
|
||||||
|
|
||||||
let logger = invoke_context.get_logger();
|
let logger = invoke_context.get_logger();
|
||||||
|
let program_id = invoke_context.get_caller()?;
|
||||||
stable_log::program_invoke(&logger, program_id, invoke_context.invoke_depth());
|
stable_log::program_invoke(&logger, program_id, invoke_context.invoke_depth());
|
||||||
|
|
||||||
let result = process_instruction(
|
let result = process_instruction(first_instruction_account, instruction_data, invoke_context);
|
||||||
program_id,
|
|
||||||
first_instruction_account,
|
|
||||||
instruction_data,
|
|
||||||
invoke_context,
|
|
||||||
);
|
|
||||||
|
|
||||||
|
let program_id = invoke_context.get_caller()?;
|
||||||
match &result {
|
match &result {
|
||||||
Ok(()) => stable_log::program_success(&logger, program_id),
|
Ok(()) => stable_log::program_success(&logger, program_id),
|
||||||
Err(err) => stable_log::program_failure(&logger, program_id, err),
|
Err(err) => stable_log::program_failure(&logger, program_id, err),
|
||||||
@ -39,13 +35,11 @@ fn process_instruction_with_program_logging(
|
|||||||
|
|
||||||
macro_rules! with_program_logging {
|
macro_rules! with_program_logging {
|
||||||
($process_instruction:expr) => {
|
($process_instruction:expr) => {
|
||||||
|program_id: &Pubkey,
|
|first_instruction_account: usize,
|
||||||
first_instruction_account: usize,
|
|
||||||
instruction_data: &[u8],
|
instruction_data: &[u8],
|
||||||
invoke_context: &mut dyn InvokeContext| {
|
invoke_context: &mut dyn InvokeContext| {
|
||||||
process_instruction_with_program_logging(
|
process_instruction_with_program_logging(
|
||||||
$process_instruction,
|
$process_instruction,
|
||||||
program_id,
|
|
||||||
first_instruction_account,
|
first_instruction_account,
|
||||||
instruction_data,
|
instruction_data,
|
||||||
invoke_context,
|
invoke_context,
|
||||||
@ -94,7 +88,7 @@ impl AbiExample for Builtin {
|
|||||||
Self {
|
Self {
|
||||||
name: String::default(),
|
name: String::default(),
|
||||||
id: Pubkey::default(),
|
id: Pubkey::default(),
|
||||||
process_instruction_with_context: |_, _, _, _| Ok(()),
|
process_instruction_with_context: |_, _, _| Ok(()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -141,7 +135,6 @@ fn genesis_builtins() -> Vec<Builtin> {
|
|||||||
|
|
||||||
/// place holder for secp256k1, remove when the precompile program is deactivated via feature activation
|
/// place holder for secp256k1, remove when the precompile program is deactivated via feature activation
|
||||||
fn dummy_process_instruction(
|
fn dummy_process_instruction(
|
||||||
_program_id: &Pubkey,
|
|
||||||
_first_instruction_account: usize,
|
_first_instruction_account: usize,
|
||||||
_data: &[u8],
|
_data: &[u8],
|
||||||
_invoke_context: &mut dyn InvokeContext,
|
_invoke_context: &mut dyn InvokeContext,
|
||||||
|
@ -550,11 +550,8 @@ impl MessageProcessor {
|
|||||||
let result = invoke_context
|
let result = invoke_context
|
||||||
.push(program_id, message, instruction, program_indices, None)
|
.push(program_id, message, instruction, program_indices, None)
|
||||||
.and_then(|_| {
|
.and_then(|_| {
|
||||||
instruction_processor.process_instruction(
|
instruction_processor
|
||||||
program_id,
|
.process_instruction(&instruction.data, &mut invoke_context)?;
|
||||||
&instruction.data,
|
|
||||||
&mut invoke_context,
|
|
||||||
)?;
|
|
||||||
invoke_context.verify(message, instruction, program_indices)?;
|
invoke_context.verify(message, instruction, program_indices)?;
|
||||||
timings.accumulate(&invoke_context.timings);
|
timings.accumulate(&invoke_context.timings);
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -598,11 +595,11 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn mock_process_instruction(
|
fn mock_process_instruction(
|
||||||
program_id: &Pubkey,
|
|
||||||
first_instruction_account: usize,
|
first_instruction_account: usize,
|
||||||
data: &[u8],
|
data: &[u8],
|
||||||
invoke_context: &mut dyn InvokeContext,
|
invoke_context: &mut dyn InvokeContext,
|
||||||
) -> Result<(), InstructionError> {
|
) -> Result<(), InstructionError> {
|
||||||
|
let program_id = invoke_context.get_caller()?;
|
||||||
let keyed_accounts = invoke_context.get_keyed_accounts()?;
|
let keyed_accounts = invoke_context.get_keyed_accounts()?;
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*program_id,
|
*program_id,
|
||||||
@ -821,7 +818,6 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn mock_system_process_instruction(
|
fn mock_system_process_instruction(
|
||||||
_program_id: &Pubkey,
|
|
||||||
first_instruction_account: usize,
|
first_instruction_account: usize,
|
||||||
data: &[u8],
|
data: &[u8],
|
||||||
invoke_context: &mut dyn InvokeContext,
|
invoke_context: &mut dyn InvokeContext,
|
||||||
@ -995,7 +991,6 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn mock_system_process_instruction(
|
fn mock_system_process_instruction(
|
||||||
_program_id: &Pubkey,
|
|
||||||
first_instruction_account: usize,
|
first_instruction_account: usize,
|
||||||
data: &[u8],
|
data: &[u8],
|
||||||
invoke_context: &mut dyn InvokeContext,
|
invoke_context: &mut dyn InvokeContext,
|
||||||
@ -1523,7 +1518,6 @@ mod tests {
|
|||||||
fn test_precompile() {
|
fn test_precompile() {
|
||||||
let mock_program_id = Pubkey::new_unique();
|
let mock_program_id = Pubkey::new_unique();
|
||||||
fn mock_process_instruction(
|
fn mock_process_instruction(
|
||||||
_program_id: &Pubkey,
|
|
||||||
_first_instruction_account: usize,
|
_first_instruction_account: usize,
|
||||||
_data: &[u8],
|
_data: &[u8],
|
||||||
_invoke_context: &mut dyn InvokeContext,
|
_invoke_context: &mut dyn InvokeContext,
|
||||||
|
@ -263,7 +263,6 @@ fn transfer_with_seed(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn process_instruction(
|
pub fn process_instruction(
|
||||||
_owner: &Pubkey,
|
|
||||||
first_instruction_account: usize,
|
first_instruction_account: usize,
|
||||||
instruction_data: &[u8],
|
instruction_data: &[u8],
|
||||||
invoke_context: &mut dyn InvokeContext,
|
invoke_context: &mut dyn InvokeContext,
|
||||||
@ -522,13 +521,11 @@ mod tests {
|
|||||||
..Account::default()
|
..Account::default()
|
||||||
}));
|
}));
|
||||||
let mut keyed_accounts = keyed_accounts.to_vec();
|
let mut keyed_accounts = keyed_accounts.to_vec();
|
||||||
let processor_id = Pubkey::default();
|
keyed_accounts.insert(0, (false, false, owner, &processor_account));
|
||||||
keyed_accounts.insert(0, (false, false, &processor_id, &processor_account));
|
|
||||||
super::process_instruction(
|
super::process_instruction(
|
||||||
owner,
|
|
||||||
1,
|
1,
|
||||||
instruction_data,
|
instruction_data,
|
||||||
&mut MockInvokeContext::new(create_keyed_accounts_unified(&keyed_accounts)),
|
&mut MockInvokeContext::new(owner, create_keyed_accounts_unified(&keyed_accounts)),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -661,7 +658,7 @@ mod tests {
|
|||||||
Address::create(
|
Address::create(
|
||||||
&to,
|
&to,
|
||||||
Some((&from, seed, &owner)),
|
Some((&from, seed, &owner)),
|
||||||
&MockInvokeContext::new(vec![]),
|
&MockInvokeContext::new(&Pubkey::default(), vec![]),
|
||||||
),
|
),
|
||||||
Err(SystemError::AddressWithSeedMismatch.into())
|
Err(SystemError::AddressWithSeedMismatch.into())
|
||||||
);
|
);
|
||||||
@ -679,7 +676,7 @@ mod tests {
|
|||||||
let to_address = Address::create(
|
let to_address = Address::create(
|
||||||
&to,
|
&to,
|
||||||
Some((&from, seed, &new_owner)),
|
Some((&from, seed, &new_owner)),
|
||||||
&MockInvokeContext::new(vec![]),
|
&MockInvokeContext::new(&Pubkey::default(), vec![]),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
@ -692,7 +689,7 @@ mod tests {
|
|||||||
2,
|
2,
|
||||||
&new_owner,
|
&new_owner,
|
||||||
&HashSet::new(),
|
&HashSet::new(),
|
||||||
&MockInvokeContext::new(vec![]),
|
&MockInvokeContext::new(&Pubkey::default(), vec![]),
|
||||||
),
|
),
|
||||||
Err(InstructionError::MissingRequiredSignature)
|
Err(InstructionError::MissingRequiredSignature)
|
||||||
);
|
);
|
||||||
@ -719,7 +716,7 @@ mod tests {
|
|||||||
2,
|
2,
|
||||||
&new_owner,
|
&new_owner,
|
||||||
&[from, to].iter().cloned().collect::<HashSet<_>>(),
|
&[from, to].iter().cloned().collect::<HashSet<_>>(),
|
||||||
&MockInvokeContext::new(vec![]),
|
&MockInvokeContext::new(&Pubkey::default(), vec![]),
|
||||||
),
|
),
|
||||||
Ok(())
|
Ok(())
|
||||||
);
|
);
|
||||||
@ -751,7 +748,7 @@ mod tests {
|
|||||||
2,
|
2,
|
||||||
&new_owner,
|
&new_owner,
|
||||||
&[from, to].iter().cloned().collect::<HashSet<_>>(),
|
&[from, to].iter().cloned().collect::<HashSet<_>>(),
|
||||||
&MockInvokeContext::new(vec![]),
|
&MockInvokeContext::new(&Pubkey::default(), vec![]),
|
||||||
);
|
);
|
||||||
assert_eq!(result, Err(SystemError::ResultWithNegativeLamports.into()));
|
assert_eq!(result, Err(SystemError::ResultWithNegativeLamports.into()));
|
||||||
}
|
}
|
||||||
@ -775,7 +772,7 @@ mod tests {
|
|||||||
MAX_PERMITTED_DATA_LENGTH + 1,
|
MAX_PERMITTED_DATA_LENGTH + 1,
|
||||||
&system_program::id(),
|
&system_program::id(),
|
||||||
signers,
|
signers,
|
||||||
&MockInvokeContext::new(vec![]),
|
&MockInvokeContext::new(&Pubkey::default(), vec![]),
|
||||||
);
|
);
|
||||||
assert!(result.is_err());
|
assert!(result.is_err());
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
@ -792,7 +789,7 @@ mod tests {
|
|||||||
MAX_PERMITTED_DATA_LENGTH,
|
MAX_PERMITTED_DATA_LENGTH,
|
||||||
&system_program::id(),
|
&system_program::id(),
|
||||||
signers,
|
signers,
|
||||||
&MockInvokeContext::new(vec![]),
|
&MockInvokeContext::new(&Pubkey::default(), vec![]),
|
||||||
);
|
);
|
||||||
assert!(result.is_ok());
|
assert!(result.is_ok());
|
||||||
assert_eq!(to_account.borrow().lamports(), 50);
|
assert_eq!(to_account.borrow().lamports(), 50);
|
||||||
@ -825,7 +822,7 @@ mod tests {
|
|||||||
2,
|
2,
|
||||||
&new_owner,
|
&new_owner,
|
||||||
signers,
|
signers,
|
||||||
&MockInvokeContext::new(vec![]),
|
&MockInvokeContext::new(&Pubkey::default(), vec![]),
|
||||||
);
|
);
|
||||||
assert_eq!(result, Err(SystemError::AccountAlreadyInUse.into()));
|
assert_eq!(result, Err(SystemError::AccountAlreadyInUse.into()));
|
||||||
|
|
||||||
@ -844,7 +841,7 @@ mod tests {
|
|||||||
2,
|
2,
|
||||||
&new_owner,
|
&new_owner,
|
||||||
signers,
|
signers,
|
||||||
&MockInvokeContext::new(vec![]),
|
&MockInvokeContext::new(&Pubkey::default(), vec![]),
|
||||||
);
|
);
|
||||||
assert_eq!(result, Err(SystemError::AccountAlreadyInUse.into()));
|
assert_eq!(result, Err(SystemError::AccountAlreadyInUse.into()));
|
||||||
let from_lamports = from_account.borrow().lamports();
|
let from_lamports = from_account.borrow().lamports();
|
||||||
@ -862,7 +859,7 @@ mod tests {
|
|||||||
2,
|
2,
|
||||||
&new_owner,
|
&new_owner,
|
||||||
signers,
|
signers,
|
||||||
&MockInvokeContext::new(vec![]),
|
&MockInvokeContext::new(&Pubkey::default(), vec![]),
|
||||||
);
|
);
|
||||||
assert_eq!(result, Err(SystemError::AccountAlreadyInUse.into()));
|
assert_eq!(result, Err(SystemError::AccountAlreadyInUse.into()));
|
||||||
assert_eq!(from_lamports, 100);
|
assert_eq!(from_lamports, 100);
|
||||||
@ -890,7 +887,7 @@ mod tests {
|
|||||||
2,
|
2,
|
||||||
&new_owner,
|
&new_owner,
|
||||||
&[owned_key].iter().cloned().collect::<HashSet<_>>(),
|
&[owned_key].iter().cloned().collect::<HashSet<_>>(),
|
||||||
&MockInvokeContext::new(vec![]),
|
&MockInvokeContext::new(&Pubkey::default(), vec![]),
|
||||||
);
|
);
|
||||||
assert_eq!(result, Err(InstructionError::MissingRequiredSignature));
|
assert_eq!(result, Err(InstructionError::MissingRequiredSignature));
|
||||||
|
|
||||||
@ -904,7 +901,7 @@ mod tests {
|
|||||||
2,
|
2,
|
||||||
&new_owner,
|
&new_owner,
|
||||||
&[from].iter().cloned().collect::<HashSet<_>>(),
|
&[from].iter().cloned().collect::<HashSet<_>>(),
|
||||||
&MockInvokeContext::new(vec![]),
|
&MockInvokeContext::new(&Pubkey::default(), vec![]),
|
||||||
);
|
);
|
||||||
assert_eq!(result, Err(InstructionError::MissingRequiredSignature));
|
assert_eq!(result, Err(InstructionError::MissingRequiredSignature));
|
||||||
|
|
||||||
@ -918,7 +915,7 @@ mod tests {
|
|||||||
2,
|
2,
|
||||||
&new_owner,
|
&new_owner,
|
||||||
&[owned_key].iter().cloned().collect::<HashSet<_>>(),
|
&[owned_key].iter().cloned().collect::<HashSet<_>>(),
|
||||||
&MockInvokeContext::new(vec![]),
|
&MockInvokeContext::new(&Pubkey::default(), vec![]),
|
||||||
);
|
);
|
||||||
assert_eq!(result, Err(InstructionError::MissingRequiredSignature));
|
assert_eq!(result, Err(InstructionError::MissingRequiredSignature));
|
||||||
}
|
}
|
||||||
@ -944,7 +941,7 @@ mod tests {
|
|||||||
2,
|
2,
|
||||||
&sysvar::id(),
|
&sysvar::id(),
|
||||||
&signers,
|
&signers,
|
||||||
&MockInvokeContext::new(vec![]),
|
&MockInvokeContext::new(&Pubkey::default(), vec![]),
|
||||||
);
|
);
|
||||||
assert_eq!(result, Ok(()));
|
assert_eq!(result, Ok(()));
|
||||||
}
|
}
|
||||||
@ -973,7 +970,7 @@ mod tests {
|
|||||||
disabled_features: vec![feature_set::rent_for_sysvars::id()]
|
disabled_features: vec![feature_set::rent_for_sysvars::id()]
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.collect(),
|
.collect(),
|
||||||
..MockInvokeContext::new(vec![])
|
..MockInvokeContext::new(&Pubkey::default(), vec![])
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
assert_eq!(result, Err(SystemError::InvalidProgramId.into()));
|
assert_eq!(result, Err(SystemError::InvalidProgramId.into()));
|
||||||
@ -1007,7 +1004,7 @@ mod tests {
|
|||||||
2,
|
2,
|
||||||
&new_owner,
|
&new_owner,
|
||||||
&signers,
|
&signers,
|
||||||
&MockInvokeContext::new(vec![]),
|
&MockInvokeContext::new(&Pubkey::default(), vec![]),
|
||||||
);
|
);
|
||||||
assert_eq!(result, Err(SystemError::AccountAlreadyInUse.into()));
|
assert_eq!(result, Err(SystemError::AccountAlreadyInUse.into()));
|
||||||
}
|
}
|
||||||
@ -1041,7 +1038,7 @@ mod tests {
|
|||||||
0,
|
0,
|
||||||
&solana_sdk::pubkey::new_rand(),
|
&solana_sdk::pubkey::new_rand(),
|
||||||
&signers,
|
&signers,
|
||||||
&MockInvokeContext::new(vec![]),
|
&MockInvokeContext::new(&Pubkey::default(), vec![]),
|
||||||
),
|
),
|
||||||
Err(InstructionError::InvalidArgument),
|
Err(InstructionError::InvalidArgument),
|
||||||
);
|
);
|
||||||
@ -1059,7 +1056,7 @@ mod tests {
|
|||||||
&pubkey.into(),
|
&pubkey.into(),
|
||||||
&new_owner,
|
&new_owner,
|
||||||
&HashSet::new(),
|
&HashSet::new(),
|
||||||
&MockInvokeContext::new(vec![]),
|
&MockInvokeContext::new(&Pubkey::default(), vec![]),
|
||||||
),
|
),
|
||||||
Err(InstructionError::MissingRequiredSignature)
|
Err(InstructionError::MissingRequiredSignature)
|
||||||
);
|
);
|
||||||
@ -1071,7 +1068,7 @@ mod tests {
|
|||||||
&pubkey.into(),
|
&pubkey.into(),
|
||||||
&system_program::id(),
|
&system_program::id(),
|
||||||
&HashSet::new(),
|
&HashSet::new(),
|
||||||
&MockInvokeContext::new(vec![]),
|
&MockInvokeContext::new(&Pubkey::default(), vec![]),
|
||||||
),
|
),
|
||||||
Ok(())
|
Ok(())
|
||||||
);
|
);
|
||||||
@ -1100,7 +1097,7 @@ mod tests {
|
|||||||
&from.into(),
|
&from.into(),
|
||||||
&new_owner,
|
&new_owner,
|
||||||
&[from].iter().cloned().collect::<HashSet<_>>(),
|
&[from].iter().cloned().collect::<HashSet<_>>(),
|
||||||
&MockInvokeContext::new(vec![]),
|
&MockInvokeContext::new(&Pubkey::default(), vec![]),
|
||||||
),
|
),
|
||||||
Ok(())
|
Ok(())
|
||||||
);
|
);
|
||||||
@ -1123,7 +1120,7 @@ mod tests {
|
|||||||
disabled_features: vec![feature_set::rent_for_sysvars::id()]
|
disabled_features: vec![feature_set::rent_for_sysvars::id()]
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.collect(),
|
.collect(),
|
||||||
..MockInvokeContext::new(vec![])
|
..MockInvokeContext::new(&Pubkey::default(), vec![])
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
Err(SystemError::InvalidProgramId.into())
|
Err(SystemError::InvalidProgramId.into())
|
||||||
@ -1165,7 +1162,7 @@ mod tests {
|
|||||||
&from_keyed_account,
|
&from_keyed_account,
|
||||||
&to_keyed_account,
|
&to_keyed_account,
|
||||||
50,
|
50,
|
||||||
&MockInvokeContext::new(vec![]),
|
&MockInvokeContext::new(&Pubkey::default(), vec![]),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let from_lamports = from_keyed_account.account.borrow().lamports();
|
let from_lamports = from_keyed_account.account.borrow().lamports();
|
||||||
@ -1179,7 +1176,7 @@ mod tests {
|
|||||||
&from_keyed_account,
|
&from_keyed_account,
|
||||||
&to_keyed_account,
|
&to_keyed_account,
|
||||||
100,
|
100,
|
||||||
&MockInvokeContext::new(vec![]),
|
&MockInvokeContext::new(&Pubkey::default(), vec![]),
|
||||||
);
|
);
|
||||||
assert_eq!(result, Err(SystemError::ResultWithNegativeLamports.into()));
|
assert_eq!(result, Err(SystemError::ResultWithNegativeLamports.into()));
|
||||||
assert_eq!(from_keyed_account.account.borrow().lamports(), 50);
|
assert_eq!(from_keyed_account.account.borrow().lamports(), 50);
|
||||||
@ -1190,7 +1187,7 @@ mod tests {
|
|||||||
&from_keyed_account,
|
&from_keyed_account,
|
||||||
&to_keyed_account,
|
&to_keyed_account,
|
||||||
0,
|
0,
|
||||||
&MockInvokeContext::new(vec![]),
|
&MockInvokeContext::new(&Pubkey::default(), vec![]),
|
||||||
)
|
)
|
||||||
.is_ok());
|
.is_ok());
|
||||||
assert_eq!(from_keyed_account.account.borrow().lamports(), 50);
|
assert_eq!(from_keyed_account.account.borrow().lamports(), 50);
|
||||||
@ -1204,7 +1201,7 @@ mod tests {
|
|||||||
&from_keyed_account,
|
&from_keyed_account,
|
||||||
&to_keyed_account,
|
&to_keyed_account,
|
||||||
0,
|
0,
|
||||||
&MockInvokeContext::new(vec![]),
|
&MockInvokeContext::new(&Pubkey::default(), vec![]),
|
||||||
),
|
),
|
||||||
Err(InstructionError::MissingRequiredSignature)
|
Err(InstructionError::MissingRequiredSignature)
|
||||||
);
|
);
|
||||||
@ -1232,7 +1229,7 @@ mod tests {
|
|||||||
&from_owner,
|
&from_owner,
|
||||||
&to_keyed_account,
|
&to_keyed_account,
|
||||||
50,
|
50,
|
||||||
&MockInvokeContext::new(vec![]),
|
&MockInvokeContext::new(&Pubkey::default(), vec![]),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let from_lamports = from_keyed_account.account.borrow().lamports();
|
let from_lamports = from_keyed_account.account.borrow().lamports();
|
||||||
@ -1249,7 +1246,7 @@ mod tests {
|
|||||||
&from_owner,
|
&from_owner,
|
||||||
&to_keyed_account,
|
&to_keyed_account,
|
||||||
100,
|
100,
|
||||||
&MockInvokeContext::new(vec![]),
|
&MockInvokeContext::new(&Pubkey::default(), vec![]),
|
||||||
);
|
);
|
||||||
assert_eq!(result, Err(SystemError::ResultWithNegativeLamports.into()));
|
assert_eq!(result, Err(SystemError::ResultWithNegativeLamports.into()));
|
||||||
assert_eq!(from_keyed_account.account.borrow().lamports(), 50);
|
assert_eq!(from_keyed_account.account.borrow().lamports(), 50);
|
||||||
@ -1264,7 +1261,7 @@ mod tests {
|
|||||||
&from_owner,
|
&from_owner,
|
||||||
&to_keyed_account,
|
&to_keyed_account,
|
||||||
0,
|
0,
|
||||||
&MockInvokeContext::new(vec![]),
|
&MockInvokeContext::new(&Pubkey::default(), vec![]),
|
||||||
)
|
)
|
||||||
.is_ok());
|
.is_ok());
|
||||||
assert_eq!(from_keyed_account.account.borrow().lamports(), 50);
|
assert_eq!(from_keyed_account.account.borrow().lamports(), 50);
|
||||||
@ -1295,7 +1292,7 @@ mod tests {
|
|||||||
&KeyedAccount::new(&from, true, &from_account),
|
&KeyedAccount::new(&from, true, &from_account),
|
||||||
&KeyedAccount::new(&to, false, &to_account),
|
&KeyedAccount::new(&to, false, &to_account),
|
||||||
50,
|
50,
|
||||||
&MockInvokeContext::new(vec![]),
|
&MockInvokeContext::new(&Pubkey::default(), vec![]),
|
||||||
),
|
),
|
||||||
Err(InstructionError::InvalidArgument),
|
Err(InstructionError::InvalidArgument),
|
||||||
)
|
)
|
||||||
@ -1610,12 +1607,13 @@ mod tests {
|
|||||||
(true, false, &owner, &nonce_acc),
|
(true, false, &owner, &nonce_acc),
|
||||||
(false, false, &blockhash_id, &new_recent_blockhashes_account),
|
(false, false, &blockhash_id, &new_recent_blockhashes_account),
|
||||||
];
|
];
|
||||||
let mut invoke_context =
|
let mut invoke_context = &mut MockInvokeContext::new(
|
||||||
&mut MockInvokeContext::new(create_keyed_accounts_unified(&keyed_accounts));
|
&Pubkey::default(),
|
||||||
|
create_keyed_accounts_unified(&keyed_accounts),
|
||||||
|
);
|
||||||
invoke_context.blockhash = *blockhash;
|
invoke_context.blockhash = *blockhash;
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
super::process_instruction(
|
super::process_instruction(
|
||||||
&Pubkey::default(),
|
|
||||||
1,
|
1,
|
||||||
&serialize(&SystemInstruction::AdvanceNonceAccount).unwrap(),
|
&serialize(&SystemInstruction::AdvanceNonceAccount).unwrap(),
|
||||||
invoke_context,
|
invoke_context,
|
||||||
@ -2034,12 +2032,13 @@ mod tests {
|
|||||||
(true, false, &owner, &nonce_acc),
|
(true, false, &owner, &nonce_acc),
|
||||||
(false, false, &blockhash_id, &new_recent_blockhashes_account),
|
(false, false, &blockhash_id, &new_recent_blockhashes_account),
|
||||||
];
|
];
|
||||||
let mut invoke_context =
|
let mut invoke_context = &mut MockInvokeContext::new(
|
||||||
&mut MockInvokeContext::new(create_keyed_accounts_unified(&keyed_accounts));
|
&Pubkey::default(),
|
||||||
|
create_keyed_accounts_unified(&keyed_accounts),
|
||||||
|
);
|
||||||
invoke_context.blockhash = *blockhash;
|
invoke_context.blockhash = *blockhash;
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
super::process_instruction(
|
super::process_instruction(
|
||||||
&Pubkey::default(),
|
|
||||||
1,
|
1,
|
||||||
&serialize(&SystemInstruction::AdvanceNonceAccount).unwrap(),
|
&serialize(&SystemInstruction::AdvanceNonceAccount).unwrap(),
|
||||||
invoke_context,
|
invoke_context,
|
||||||
|
@ -79,7 +79,6 @@ macro_rules! declare_builtin_name {
|
|||||||
/// use solana_sdk::declare_builtin;
|
/// use solana_sdk::declare_builtin;
|
||||||
///
|
///
|
||||||
/// fn my_process_instruction(
|
/// fn my_process_instruction(
|
||||||
/// program_id: &Pubkey,
|
|
||||||
/// first_instruction_account: usize,
|
/// first_instruction_account: usize,
|
||||||
/// keyed_accounts: &[KeyedAccount],
|
/// keyed_accounts: &[KeyedAccount],
|
||||||
/// instruction_data: &[u8],
|
/// instruction_data: &[u8],
|
||||||
@ -111,7 +110,6 @@ macro_rules! declare_builtin_name {
|
|||||||
/// use solana_sdk::declare_builtin;
|
/// use solana_sdk::declare_builtin;
|
||||||
///
|
///
|
||||||
/// fn my_process_instruction(
|
/// fn my_process_instruction(
|
||||||
/// program_id: &Pubkey,
|
|
||||||
/// first_instruction_account: usize,
|
/// first_instruction_account: usize,
|
||||||
/// keyed_accounts: &[KeyedAccount],
|
/// keyed_accounts: &[KeyedAccount],
|
||||||
/// instruction_data: &[u8],
|
/// instruction_data: &[u8],
|
||||||
|
@ -94,7 +94,6 @@ macro_rules! declare_name {
|
|||||||
/// };
|
/// };
|
||||||
///
|
///
|
||||||
/// fn my_process_instruction(
|
/// fn my_process_instruction(
|
||||||
/// program_id: &Pubkey,
|
|
||||||
/// first_instruction_account: usize,
|
/// first_instruction_account: usize,
|
||||||
/// instruction_data: &[u8],
|
/// instruction_data: &[u8],
|
||||||
/// invoke_context: &mut dyn InvokeContext,
|
/// invoke_context: &mut dyn InvokeContext,
|
||||||
@ -128,7 +127,6 @@ macro_rules! declare_name {
|
|||||||
/// };
|
/// };
|
||||||
///
|
///
|
||||||
/// fn my_process_instruction(
|
/// fn my_process_instruction(
|
||||||
/// program_id: &Pubkey,
|
|
||||||
/// first_instruction_account: usize,
|
/// first_instruction_account: usize,
|
||||||
/// instruction_data: &[u8],
|
/// instruction_data: &[u8],
|
||||||
/// invoke_context: &mut dyn InvokeContext,
|
/// invoke_context: &mut dyn InvokeContext,
|
||||||
@ -155,12 +153,11 @@ macro_rules! declare_program(
|
|||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn $name(
|
pub extern "C" fn $name(
|
||||||
program_id: &$crate::pubkey::Pubkey,
|
|
||||||
first_instruction_account: usize,
|
first_instruction_account: usize,
|
||||||
instruction_data: &[u8],
|
instruction_data: &[u8],
|
||||||
invoke_context: &mut dyn $crate::process_instruction::InvokeContext,
|
invoke_context: &mut dyn $crate::process_instruction::InvokeContext,
|
||||||
) -> Result<(), $crate::instruction::InstructionError> {
|
) -> Result<(), $crate::instruction::InstructionError> {
|
||||||
$entrypoint(program_id, first_instruction_account, instruction_data, invoke_context)
|
$entrypoint(first_instruction_account, instruction_data, invoke_context)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -289,7 +289,7 @@ mod test {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn create_invoke_context_with_blockhash<'a>(seed: usize) -> MockInvokeContext<'a> {
|
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);
|
let (blockhash, fee_calculator) = create_test_blockhash(seed);
|
||||||
invoke_context.blockhash = blockhash;
|
invoke_context.blockhash = blockhash;
|
||||||
invoke_context.fee_calculator = fee_calculator;
|
invoke_context.fee_calculator = fee_calculator;
|
||||||
@ -979,7 +979,7 @@ mod test {
|
|||||||
let min_lamports = rent.minimum_balance(State::size());
|
let min_lamports = rent.minimum_balance(State::size());
|
||||||
with_test_keyed_account(min_lamports + 42, true, |nonce_account| {
|
with_test_keyed_account(min_lamports + 42, true, |nonce_account| {
|
||||||
let mut signers = HashSet::new();
|
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());
|
signers.insert(*nonce_account.signer_key().unwrap());
|
||||||
let result = nonce_account.authorize_nonce_account(
|
let result = nonce_account.authorize_nonce_account(
|
||||||
&Pubkey::default(),
|
&Pubkey::default(),
|
||||||
|
@ -28,7 +28,7 @@ pub type LoaderEntrypoint = unsafe extern "C" fn(
|
|||||||
) -> Result<(), InstructionError>;
|
) -> Result<(), InstructionError>;
|
||||||
|
|
||||||
pub type ProcessInstructionWithContext =
|
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 struct InvokeContextStackFrame<'a> {
|
||||||
pub key: Pubkey,
|
pub key: Pubkey,
|
||||||
@ -400,7 +400,6 @@ pub trait Executor: Debug + Send + Sync {
|
|||||||
/// Execute the program
|
/// Execute the program
|
||||||
fn execute(
|
fn execute(
|
||||||
&self,
|
&self,
|
||||||
program_id: &Pubkey,
|
|
||||||
first_instruction_account: usize,
|
first_instruction_account: usize,
|
||||||
instruction_data: &[u8],
|
instruction_data: &[u8],
|
||||||
invoke_context: &mut dyn InvokeContext,
|
invoke_context: &mut dyn InvokeContext,
|
||||||
@ -456,7 +455,7 @@ pub struct MockInvokeContext<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> 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 compute_budget = ComputeBudget::default();
|
||||||
let mut invoke_context = MockInvokeContext {
|
let mut invoke_context = MockInvokeContext {
|
||||||
invoke_stack: Vec::with_capacity(compute_budget.max_invoke_depth),
|
invoke_stack: Vec::with_capacity(compute_budget.max_invoke_depth),
|
||||||
@ -476,10 +475,7 @@ impl<'a> MockInvokeContext<'a> {
|
|||||||
};
|
};
|
||||||
invoke_context
|
invoke_context
|
||||||
.invoke_stack
|
.invoke_stack
|
||||||
.push(InvokeContextStackFrame::new(
|
.push(InvokeContextStackFrame::new(*program_id, keyed_accounts));
|
||||||
Pubkey::default(),
|
|
||||||
keyed_accounts,
|
|
||||||
));
|
|
||||||
invoke_context
|
invoke_context
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user