Skip to content

Commit

Permalink
Adds more assertions of invoke_context.get_keyed_accounts() being equ…
Browse files Browse the repository at this point in the history
…al to the keyed_accounts parameter.
  • Loading branch information
Lichtso committed Mar 2, 2021
1 parent a08095d commit 0f9652c
Show file tree
Hide file tree
Showing 12 changed files with 65 additions and 18 deletions.
3 changes: 3 additions & 0 deletions program-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ pub fn builtin_process_instruction(
) -> Result<(), InstructionError> {
set_invoke_context(invoke_context);

// TODO [KeyedAccounts to InvokeContext refactoring]
assert_eq!(invoke_context.get_keyed_accounts(), keyed_accounts);

// Copy all the accounts into a HashMap to ensure there are no duplicates
let mut accounts: HashMap<Pubkey, Account> = keyed_accounts
.iter()
Expand Down
5 changes: 4 additions & 1 deletion programs/budget/src/budget_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,11 @@ pub fn process_instruction(
_program_id: &Pubkey,
keyed_accounts: &[KeyedAccount],
data: &[u8],
_invoke_context: &mut dyn InvokeContext,
invoke_context: &mut dyn InvokeContext,
) -> Result<(), InstructionError> {
// TODO [KeyedAccounts to InvokeContext refactoring]
assert_eq!(keyed_accounts, invoke_context.get_keyed_accounts());

let instruction = limited_deserialize(data)?;

trace!("process_instruction: {:?}", instruction);
Expand Down
3 changes: 3 additions & 0 deletions programs/config/src/config_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ pub fn process_instruction(
data: &[u8],
invoke_context: &mut dyn InvokeContext,
) -> Result<(), InstructionError> {
// TODO [KeyedAccounts to InvokeContext refactoring]
assert_eq!(keyed_accounts, invoke_context.get_keyed_accounts());

let key_list: ConfigKeys = limited_deserialize(data)?;
let config_keyed_account = &mut keyed_account_at_index(keyed_accounts, 0)?;
let current_data: ConfigKeys = {
Expand Down
5 changes: 4 additions & 1 deletion programs/exchange/src/exchange_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,10 +464,13 @@ pub fn process_instruction(
_program_id: &Pubkey,
keyed_accounts: &[KeyedAccount],
data: &[u8],
_invoke_context: &mut dyn InvokeContext,
invoke_context: &mut dyn InvokeContext,
) -> Result<(), InstructionError> {
solana_logger::setup();

// TODO [KeyedAccounts to InvokeContext refactoring]
assert_eq!(keyed_accounts, invoke_context.get_keyed_accounts());

match limited_deserialize::<ExchangeInstruction>(data)? {
ExchangeInstruction::AccountRequest => {
ExchangeProcessor::do_account_request(keyed_accounts)
Expand Down
4 changes: 3 additions & 1 deletion programs/ownable/src/ownable_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ pub fn process_instruction(
_program_id: &Pubkey,
keyed_accounts: &[KeyedAccount],
data: &[u8],
_invoke_context: &mut dyn InvokeContext,
invoke_context: &mut dyn InvokeContext,
) -> Result<(), InstructionError> {
// TODO [KeyedAccounts to InvokeContext refactoring]
assert_eq!(keyed_accounts, invoke_context.get_keyed_accounts());
let new_owner_pubkey: Pubkey = limited_deserialize(data)?;
let account_keyed_account = &mut keyed_account_at_index(keyed_accounts, 0)?;
let mut account_owner_pubkey: Pubkey =
Expand Down
2 changes: 2 additions & 0 deletions programs/stake/src/stake_instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,8 @@ pub fn process_instruction(
data: &[u8],
invoke_context: &mut dyn InvokeContext,
) -> Result<(), InstructionError> {
// TODO [KeyedAccounts to InvokeContext refactoring]
assert_eq!(keyed_accounts, invoke_context.get_keyed_accounts());
trace!("process_instruction: {:?}", data);
trace!("keyed_accounts: {:?}", keyed_accounts);

Expand Down
3 changes: 3 additions & 0 deletions programs/vest/src/vest_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ pub fn process_instruction(
data: &[u8],
invoke_context: &mut dyn InvokeContext,
) -> Result<(), InstructionError> {
// TODO [KeyedAccounts to InvokeContext refactoring]
assert_eq!(keyed_accounts, invoke_context.get_keyed_accounts());

let contract_account = &mut keyed_account_at_index(keyed_accounts, 0)?.try_account_ref_mut()?;
if invoke_context.is_feature_active(&feature_set::check_program_owner::id())
&& contract_account.owner != crate::id()
Expand Down
3 changes: 3 additions & 0 deletions programs/vote/src/vote_instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,9 @@ pub fn process_instruction(
data: &[u8],
invoke_context: &mut dyn InvokeContext,
) -> Result<(), InstructionError> {
// TODO [KeyedAccounts to InvokeContext refactoring]
assert_eq!(keyed_accounts, invoke_context.get_keyed_accounts());

trace!("process_instruction: {:?}", data);
trace!("keyed_accounts: {:?}", keyed_accounts);

Expand Down
30 changes: 21 additions & 9 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5350,8 +5350,10 @@ pub(crate) mod tests {
_program_id: &Pubkey,
keyed_accounts: &[KeyedAccount],
data: &[u8],
_invoke_context: &mut dyn InvokeContext,
invoke_context: &mut dyn InvokeContext,
) -> result::Result<(), InstructionError> {
// TODO [KeyedAccounts to InvokeContext refactoring]
assert_eq!(invoke_context.get_keyed_accounts(), keyed_accounts);
if let Ok(instruction) = bincode::deserialize(data) {
match instruction {
MockInstruction::Deduction => {
Expand Down Expand Up @@ -8905,10 +8907,12 @@ pub(crate) mod tests {
}
fn mock_vote_processor(
program_id: &Pubkey,
_keyed_accounts: &[KeyedAccount],
keyed_accounts: &[KeyedAccount],
_instruction_data: &[u8],
_invoke_context: &mut dyn InvokeContext,
invoke_context: &mut dyn InvokeContext,
) -> std::result::Result<(), InstructionError> {
// TODO [KeyedAccounts to InvokeContext refactoring]
assert_eq!(invoke_context.get_keyed_accounts(), keyed_accounts);
if mock_vote_program_id() != *program_id {
return Err(InstructionError::IncorrectProgramId);
}
Expand Down Expand Up @@ -9751,8 +9755,10 @@ pub(crate) mod tests {
_program_id: &Pubkey,
keyed_accounts: &[KeyedAccount],
data: &[u8],
_invoke_context: &mut dyn InvokeContext,
invoke_context: &mut dyn InvokeContext,
) -> result::Result<(), InstructionError> {
// TODO [KeyedAccounts to InvokeContext refactoring]
assert_eq!(invoke_context.get_keyed_accounts(), keyed_accounts);
let lamports = data[0] as u64;
{
let mut to_account = keyed_accounts[1].try_account_ref_mut()?;
Expand Down Expand Up @@ -9803,10 +9809,12 @@ pub(crate) mod tests {
#[allow(clippy::unnecessary_wraps)]
fn mock_process_instruction(
_program_id: &Pubkey,
_keyed_accounts: &[KeyedAccount],
keyed_accounts: &[KeyedAccount],
_data: &[u8],
_invoke_context: &mut dyn InvokeContext,
invoke_context: &mut dyn InvokeContext,
) -> result::Result<(), InstructionError> {
// TODO [KeyedAccounts to InvokeContext refactoring]
assert_eq!(invoke_context.get_keyed_accounts(), keyed_accounts);
Ok(())
}

Expand Down Expand Up @@ -10239,8 +10247,10 @@ pub(crate) mod tests {
_program_id: &Pubkey,
keyed_accounts: &[KeyedAccount],
_data: &[u8],
_invoke_context: &mut dyn InvokeContext,
invoke_context: &mut dyn InvokeContext,
) -> result::Result<(), InstructionError> {
// TODO [KeyedAccounts to InvokeContext refactoring]
assert_eq!(invoke_context.get_keyed_accounts(), keyed_accounts);
assert_eq!(42, keyed_accounts[0].lamports().unwrap());
let mut account = keyed_accounts[0].try_account_ref_mut()?;
account.lamports += 1;
Expand Down Expand Up @@ -11216,10 +11226,12 @@ pub(crate) mod tests {
#[allow(clippy::unnecessary_wraps)]
fn mock_process_instruction(
_program_id: &Pubkey,
_keyed_accounts: &[KeyedAccount],
keyed_accounts: &[KeyedAccount],
_data: &[u8],
_invoke_context: &mut dyn InvokeContext,
invoke_context: &mut dyn InvokeContext,
) -> std::result::Result<(), solana_sdk::instruction::InstructionError> {
// TODO [KeyedAccounts to InvokeContext refactoring]
assert_eq!(invoke_context.get_keyed_accounts(), keyed_accounts);
Ok(())
}
let builtins = Builtins {
Expand Down
3 changes: 3 additions & 0 deletions runtime/src/builtins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ fn process_instruction_with_program_logging(
instruction_data: &[u8],
invoke_context: &mut dyn InvokeContext,
) -> Result<(), InstructionError> {
// TODO [KeyedAccounts to InvokeContext refactoring]
assert_eq!(keyed_accounts, invoke_context.get_keyed_accounts());

let logger = invoke_context.get_logger();
stable_log::program_invoke(&logger, program_id, invoke_context.invoke_depth());

Expand Down
18 changes: 13 additions & 5 deletions runtime/src/message_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1625,8 +1625,10 @@ mod tests {
_program_id: &Pubkey,
keyed_accounts: &[KeyedAccount],
data: &[u8],
_invoke_context: &mut dyn InvokeContext,
invoke_context: &mut dyn InvokeContext,
) -> Result<(), InstructionError> {
// TODO [KeyedAccounts to InvokeContext refactoring]
assert_eq!(keyed_accounts, invoke_context.get_keyed_accounts());
if let Ok(instruction) = bincode::deserialize(data) {
match instruction {
MockSystemInstruction::Correct => Ok(()),
Expand Down Expand Up @@ -1766,8 +1768,10 @@ mod tests {
_program_id: &Pubkey,
keyed_accounts: &[KeyedAccount],
data: &[u8],
_invoke_context: &mut dyn InvokeContext,
invoke_context: &mut dyn InvokeContext,
) -> Result<(), InstructionError> {
// TODO [KeyedAccounts to InvokeContext refactoring]
assert_eq!(keyed_accounts, invoke_context.get_keyed_accounts());
if let Ok(instruction) = bincode::deserialize(data) {
match instruction {
MockSystemInstruction::BorrowFail => {
Expand Down Expand Up @@ -1932,8 +1936,10 @@ mod tests {
program_id: &Pubkey,
keyed_accounts: &[KeyedAccount],
data: &[u8],
_invoke_context: &mut dyn InvokeContext,
invoke_context: &mut dyn InvokeContext,
) -> Result<(), InstructionError> {
// TODO [KeyedAccounts to InvokeContext refactoring]
assert_eq!(keyed_accounts, invoke_context.get_keyed_accounts());
assert_eq!(*program_id, keyed_accounts[0].owner()?);
assert_ne!(
keyed_accounts[1].owner()?,
Expand Down Expand Up @@ -2070,10 +2076,12 @@ mod tests {
#[allow(clippy::unnecessary_wraps)]
fn mock_process_instruction(
_program_id: &Pubkey,
_keyed_accounts: &[KeyedAccount],
keyed_accounts: &[KeyedAccount],
_data: &[u8],
_invoke_context: &mut dyn InvokeContext,
invoke_context: &mut dyn InvokeContext,
) -> Result<(), InstructionError> {
// TODO [KeyedAccounts to InvokeContext refactoring]
assert_eq!(keyed_accounts, invoke_context.get_keyed_accounts());
Ok(())
}
#[allow(clippy::unnecessary_wraps)]
Expand Down
4 changes: 3 additions & 1 deletion runtime/src/system_instruction_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,10 @@ pub fn process_instruction(
_owner: &Pubkey,
keyed_accounts: &[KeyedAccount],
instruction_data: &[u8],
_invoke_context: &mut dyn InvokeContext,
invoke_context: &mut dyn InvokeContext,
) -> Result<(), InstructionError> {
// TODO [KeyedAccounts to InvokeContext refactoring]
assert_eq!(keyed_accounts, invoke_context.get_keyed_accounts());
let instruction = limited_deserialize(instruction_data)?;

trace!("process_instruction: {:?}", instruction);
Expand Down

0 comments on commit 0f9652c

Please sign in to comment.