Skip to content

Commit

Permalink
Removes unused keyed_accounts parameter in bpf_loader.
Browse files Browse the repository at this point in the history
  • Loading branch information
Lichtso committed Feb 26, 2021
1 parent de74fbe commit dde5ee0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 62 deletions.
81 changes: 20 additions & 61 deletions programs/bpf_loader/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,7 @@ pub fn process_instruction(
instruction_data: &[u8],
invoke_context: &mut dyn InvokeContext,
) -> Result<(), InstructionError> {
process_instruction_common(
program_id,
_keyed_accounts,
instruction_data,
invoke_context,
false,
)
process_instruction_common(program_id, instruction_data, invoke_context, false)
}

pub fn process_instruction_jit(
Expand All @@ -172,26 +166,17 @@ pub fn process_instruction_jit(
instruction_data: &[u8],
invoke_context: &mut dyn InvokeContext,
) -> Result<(), InstructionError> {
process_instruction_common(
program_id,
_keyed_accounts,
instruction_data,
invoke_context,
true,
)
process_instruction_common(program_id, instruction_data, invoke_context, true)
}

fn process_instruction_common(
program_id: &Pubkey,
_keyed_accounts: &[KeyedAccount],
instruction_data: &[u8],
invoke_context: &mut dyn InvokeContext,
use_jit: bool,
) -> Result<(), InstructionError> {
let logger = invoke_context.get_logger();
let keyed_accounts = invoke_context.get_keyed_accounts();
// TODO [KeyedAccounts to InvokeContext refactoring]
assert_eq!(_keyed_accounts, keyed_accounts);

let first_account = keyed_account_at_index(keyed_accounts, 0)?;
if first_account.executable()? {
Expand All @@ -200,32 +185,25 @@ fn process_instruction_common(
return Err(InstructionError::IncorrectProgramId);
}

let (_keyed_accounts, program_data_offset) =
if bpf_loader_upgradeable::check_id(&first_account.owner()?) {
if let UpgradeableLoaderState::Program {
programdata_address,
} = first_account.state()?
{
let programdata = keyed_account_at_index(keyed_accounts, 1)?;
if programdata_address != *programdata.unsigned_key() {
ic_logger_msg!(
logger,
"Wrong ProgramData account for this Program account"
);
return Err(InstructionError::InvalidArgument);
}
invoke_context.pop_first_keyed_account();
(
&_keyed_accounts[1..],
UpgradeableLoaderState::programdata_data_offset()?,
)
} else {
ic_logger_msg!(logger, "Invalid Program account");
return Err(InstructionError::InvalidAccountData);
let program_data_offset = if bpf_loader_upgradeable::check_id(&first_account.owner()?) {
if let UpgradeableLoaderState::Program {
programdata_address,
} = first_account.state()?
{
let programdata = keyed_account_at_index(keyed_accounts, 1)?;
if programdata_address != *programdata.unsigned_key() {
ic_logger_msg!(logger, "Wrong ProgramData account for this Program account");
return Err(InstructionError::InvalidArgument);
}
invoke_context.pop_first_keyed_account();
UpgradeableLoaderState::programdata_data_offset()?
} else {
(_keyed_accounts, 0)
};
ic_logger_msg!(logger, "Invalid Program account");
return Err(InstructionError::InvalidAccountData);
}
} else {
0
};

let keyed_accounts = invoke_context.get_keyed_accounts();
let program = keyed_account_at_index(keyed_accounts, 0)?;
Expand All @@ -247,7 +225,6 @@ fn process_instruction_common(
executor.execute(
loader_id,
program_id,
_keyed_accounts,
instruction_data,
invoke_context,
use_jit,
Expand All @@ -261,35 +238,25 @@ fn process_instruction_common(
if bpf_loader_upgradeable::check_id(program_id) {
process_loader_upgradeable_instruction(
program_id,
_keyed_accounts,
instruction_data,
invoke_context,
use_jit,
)?;
} else {
process_loader_instruction(
program_id,
_keyed_accounts,
instruction_data,
invoke_context,
use_jit,
)?;
process_loader_instruction(program_id, instruction_data, invoke_context, use_jit)?;
}
}
Ok(())
}

fn process_loader_upgradeable_instruction(
program_id: &Pubkey,
_keyed_accounts: &[KeyedAccount],
instruction_data: &[u8],
invoke_context: &mut dyn InvokeContext,
use_jit: bool,
) -> Result<(), InstructionError> {
let logger = invoke_context.get_logger();
let keyed_accounts = invoke_context.get_keyed_accounts();
// TODO [KeyedAccounts to InvokeContext refactoring]
assert_eq!(_keyed_accounts, keyed_accounts);

match limited_deserialize(instruction_data)? {
UpgradeableLoaderInstruction::InitializeBuffer => {
Expand Down Expand Up @@ -677,14 +644,11 @@ fn process_loader_upgradeable_instruction(

fn process_loader_instruction(
program_id: &Pubkey,
_keyed_accounts: &[KeyedAccount],
instruction_data: &[u8],
invoke_context: &mut dyn InvokeContext,
use_jit: bool,
) -> Result<(), InstructionError> {
let keyed_accounts = invoke_context.get_keyed_accounts();
// TODO [KeyedAccounts to InvokeContext refactoring]
assert_eq!(_keyed_accounts, keyed_accounts);
let program = keyed_account_at_index(keyed_accounts, 0)?;
if program.owner()? != *program_id {
ic_msg!(
Expand Down Expand Up @@ -760,15 +724,10 @@ impl Executor for BpfExecutor {
&self,
loader_id: &Pubkey,
program_id: &Pubkey,
_keyed_accounts: &[KeyedAccount],
instruction_data: &[u8],
invoke_context: &mut dyn InvokeContext,
use_jit: bool,
) -> Result<(), InstructionError> {
// TODO [KeyedAccounts to InvokeContext refactoring]
let keyed_accounts = invoke_context.get_keyed_accounts();
assert_eq!(_keyed_accounts, keyed_accounts);

let logger = invoke_context.get_logger();
let invoke_depth = invoke_context.invoke_depth();
invoke_context.pop_first_keyed_account();
Expand Down
1 change: 0 additions & 1 deletion sdk/src/process_instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,6 @@ pub trait Executor: Debug + Send + Sync {
&self,
loader_id: &Pubkey,
program_id: &Pubkey,
keyed_accounts: &[KeyedAccount],
instruction_data: &[u8],
invoke_context: &mut dyn InvokeContext,
use_jit: bool,
Expand Down

0 comments on commit dde5ee0

Please sign in to comment.