Refactor: Use InstructionContext::get_instruction_data()
(#24014)
* Adds transaction_context and instruction_context where invoke_context.get_keyed_accounts() is used. * Use instruction_context.get_instruction_data() instead of an explicit parameter. * Removes instruction_data parameter from Executor::execute(). * Removes instruction_data parameter from ProcessInstructionWithContext.
This commit is contained in:
committed by
GitHub
parent
cf59c000d9
commit
1b45c509c3
@ -257,33 +257,20 @@ pub fn create_vm<'a, 'b>(
|
||||
|
||||
pub fn process_instruction(
|
||||
first_instruction_account: usize,
|
||||
instruction_data: &[u8],
|
||||
invoke_context: &mut InvokeContext,
|
||||
) -> Result<(), InstructionError> {
|
||||
process_instruction_common(
|
||||
first_instruction_account,
|
||||
instruction_data,
|
||||
invoke_context,
|
||||
false,
|
||||
)
|
||||
process_instruction_common(first_instruction_account, invoke_context, false)
|
||||
}
|
||||
|
||||
pub fn process_instruction_jit(
|
||||
first_instruction_account: usize,
|
||||
instruction_data: &[u8],
|
||||
invoke_context: &mut InvokeContext,
|
||||
) -> Result<(), InstructionError> {
|
||||
process_instruction_common(
|
||||
first_instruction_account,
|
||||
instruction_data,
|
||||
invoke_context,
|
||||
true,
|
||||
)
|
||||
process_instruction_common(first_instruction_account, invoke_context, true)
|
||||
}
|
||||
|
||||
fn process_instruction_common(
|
||||
first_instruction_account: usize,
|
||||
instruction_data: &[u8],
|
||||
invoke_context: &mut InvokeContext,
|
||||
use_jit: bool,
|
||||
) -> Result<(), InstructionError> {
|
||||
@ -394,7 +381,7 @@ fn process_instruction_common(
|
||||
get_or_create_executor_time.as_us()
|
||||
);
|
||||
|
||||
executor.execute(program_account_index, instruction_data, invoke_context)
|
||||
executor.execute(program_account_index, invoke_context)
|
||||
} else {
|
||||
drop(program);
|
||||
debug_assert_eq!(first_instruction_account, 1);
|
||||
@ -404,19 +391,13 @@ fn process_instruction_common(
|
||||
if bpf_loader_upgradeable::check_id(program_id) {
|
||||
process_loader_upgradeable_instruction(
|
||||
first_instruction_account,
|
||||
instruction_data,
|
||||
invoke_context,
|
||||
use_jit,
|
||||
)
|
||||
} else if bpf_loader::check_id(program_id)
|
||||
|| (!disable_deprecated_loader && bpf_loader_deprecated::check_id(program_id))
|
||||
{
|
||||
process_loader_instruction(
|
||||
first_instruction_account,
|
||||
instruction_data,
|
||||
invoke_context,
|
||||
use_jit,
|
||||
)
|
||||
process_loader_instruction(first_instruction_account, invoke_context, use_jit)
|
||||
} else if disable_deprecated_loader && bpf_loader_deprecated::check_id(program_id) {
|
||||
ic_logger_msg!(log_collector, "Deprecated loader is no longer supported");
|
||||
Err(InstructionError::UnsupportedProgramId)
|
||||
@ -429,13 +410,13 @@ fn process_instruction_common(
|
||||
|
||||
fn process_loader_upgradeable_instruction(
|
||||
first_instruction_account: usize,
|
||||
instruction_data: &[u8],
|
||||
invoke_context: &mut InvokeContext,
|
||||
use_jit: bool,
|
||||
) -> Result<(), InstructionError> {
|
||||
let log_collector = invoke_context.get_log_collector();
|
||||
let transaction_context = &invoke_context.transaction_context;
|
||||
let instruction_context = transaction_context.get_current_instruction_context()?;
|
||||
let instruction_data = instruction_context.get_instruction_data();
|
||||
let program_id = instruction_context.get_program_key(transaction_context)?;
|
||||
let keyed_accounts = invoke_context.get_keyed_accounts()?;
|
||||
|
||||
@ -1062,12 +1043,12 @@ fn common_close_account(
|
||||
|
||||
fn process_loader_instruction(
|
||||
first_instruction_account: usize,
|
||||
instruction_data: &[u8],
|
||||
invoke_context: &mut InvokeContext,
|
||||
use_jit: bool,
|
||||
) -> 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();
|
||||
let program_id = instruction_context.get_program_key(transaction_context)?;
|
||||
let keyed_accounts = invoke_context.get_keyed_accounts()?;
|
||||
let program = keyed_account_at_index(keyed_accounts, first_instruction_account)?;
|
||||
@ -1148,11 +1129,10 @@ impl Debug for BpfExecutor {
|
||||
}
|
||||
|
||||
impl Executor for BpfExecutor {
|
||||
fn execute<'a, 'b>(
|
||||
fn execute(
|
||||
&self,
|
||||
_first_instruction_account: usize,
|
||||
_instruction_data: &[u8],
|
||||
invoke_context: &'a mut InvokeContext<'b>,
|
||||
invoke_context: &mut InvokeContext,
|
||||
) -> Result<(), InstructionError> {
|
||||
let log_collector = invoke_context.get_log_collector();
|
||||
let compute_meter = invoke_context.get_compute_meter();
|
||||
@ -1588,18 +1568,12 @@ mod tests {
|
||||
Vec::new(),
|
||||
None,
|
||||
Err(InstructionError::ProgramFailedToComplete),
|
||||
|first_instruction_account: usize,
|
||||
instruction_data: &[u8],
|
||||
invoke_context: &mut InvokeContext| {
|
||||
|first_instruction_account: usize, invoke_context: &mut InvokeContext| {
|
||||
invoke_context
|
||||
.get_compute_meter()
|
||||
.borrow_mut()
|
||||
.mock_set_remaining(0);
|
||||
super::process_instruction(
|
||||
first_instruction_account,
|
||||
instruction_data,
|
||||
invoke_context,
|
||||
)
|
||||
super::process_instruction(first_instruction_account, invoke_context)
|
||||
},
|
||||
);
|
||||
|
||||
|
Reference in New Issue
Block a user