From 4f27d014e1ffd414a5e8cff3ed1d338ed1eefd52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Mei=C3=9Fner?= Date: Tue, 2 Mar 2021 08:44:35 +0100 Subject: [PATCH] Adds more assertions of invoke_context.get_keyed_accounts() being equal to the keyed_accounts parameter. --- program-test/src/lib.rs | 3 +++ programs/budget/src/budget_processor.rs | 5 +++- programs/config/src/config_processor.rs | 3 +++ programs/exchange/src/exchange_processor.rs | 5 +++- programs/noop/src/lib.rs | 4 ++- programs/ownable/src/ownable_processor.rs | 4 ++- programs/stake/src/stake_instruction.rs | 2 ++ programs/vest/src/vest_processor.rs | 3 +++ programs/vote/src/vote_instruction.rs | 3 +++ runtime/src/bank.rs | 30 ++++++++++++++------- runtime/src/builtins.rs | 3 +++ runtime/src/message_processor.rs | 18 +++++++++---- runtime/src/system_instruction_processor.rs | 4 ++- 13 files changed, 68 insertions(+), 19 deletions(-) diff --git a/program-test/src/lib.rs b/program-test/src/lib.rs index e55fe3cb915750..94646dace98910 100644 --- a/program-test/src/lib.rs +++ b/program-test/src/lib.rs @@ -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 = keyed_accounts .iter() diff --git a/programs/budget/src/budget_processor.rs b/programs/budget/src/budget_processor.rs index 409dad1b2926a1..3975c9b36b003b 100644 --- a/programs/budget/src/budget_processor.rs +++ b/programs/budget/src/budget_processor.rs @@ -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); diff --git a/programs/config/src/config_processor.rs b/programs/config/src/config_processor.rs index 327e547aaf466e..3adb5ea87033e5 100644 --- a/programs/config/src/config_processor.rs +++ b/programs/config/src/config_processor.rs @@ -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 = { diff --git a/programs/exchange/src/exchange_processor.rs b/programs/exchange/src/exchange_processor.rs index 2cf146ee72b698..6bcb21c754d941 100644 --- a/programs/exchange/src/exchange_processor.rs +++ b/programs/exchange/src/exchange_processor.rs @@ -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::(data)? { ExchangeInstruction::AccountRequest => { ExchangeProcessor::do_account_request(keyed_accounts) diff --git a/programs/noop/src/lib.rs b/programs/noop/src/lib.rs index 8bfc2d9d6de522..0f59fe78c169d4 100644 --- a/programs/noop/src/lib.rs +++ b/programs/noop/src/lib.rs @@ -14,9 +14,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> { solana_logger::setup(); + // TODO [KeyedAccounts to InvokeContext refactoring] + assert_eq!(keyed_accounts, invoke_context.get_keyed_accounts()); trace!("noop: program_id: {:?}", program_id); trace!("noop: keyed_accounts: {:#?}", keyed_accounts); trace!("noop: data: {:?}", data); diff --git a/programs/ownable/src/ownable_processor.rs b/programs/ownable/src/ownable_processor.rs index b072b4e5f91a24..f78eb0c7fccb53 100644 --- a/programs/ownable/src/ownable_processor.rs +++ b/programs/ownable/src/ownable_processor.rs @@ -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 = diff --git a/programs/stake/src/stake_instruction.rs b/programs/stake/src/stake_instruction.rs index 53b074fe3d06bb..887832202116da 100644 --- a/programs/stake/src/stake_instruction.rs +++ b/programs/stake/src/stake_instruction.rs @@ -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); diff --git a/programs/vest/src/vest_processor.rs b/programs/vest/src/vest_processor.rs index 572c831f4668c6..af5136bd0a31e1 100644 --- a/programs/vest/src/vest_processor.rs +++ b/programs/vest/src/vest_processor.rs @@ -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() diff --git a/programs/vote/src/vote_instruction.rs b/programs/vote/src/vote_instruction.rs index a436f8701b1674..fa3b321d53c205 100644 --- a/programs/vote/src/vote_instruction.rs +++ b/programs/vote/src/vote_instruction.rs @@ -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); diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index 44c6cff1785c8a..287945ef10cb71 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -5351,8 +5351,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 => { @@ -8906,10 +8908,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); } @@ -9752,8 +9756,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()?; @@ -9804,10 +9810,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(()) } @@ -10240,8 +10248,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; @@ -11217,10 +11227,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 { diff --git a/runtime/src/builtins.rs b/runtime/src/builtins.rs index 03a9dfc7ec1ede..b7917e20894472 100644 --- a/runtime/src/builtins.rs +++ b/runtime/src/builtins.rs @@ -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()); diff --git a/runtime/src/message_processor.rs b/runtime/src/message_processor.rs index 7c2524d6c4b413..d620298347cb89 100644 --- a/runtime/src/message_processor.rs +++ b/runtime/src/message_processor.rs @@ -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(()), @@ -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 => { @@ -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()?, @@ -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)] diff --git a/runtime/src/system_instruction_processor.rs b/runtime/src/system_instruction_processor.rs index a4b66bd9ba1c29..73ded631ed136c 100644 --- a/runtime/src/system_instruction_processor.rs +++ b/runtime/src/system_instruction_processor.rs @@ -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);