From 91c2729856e2d225d505f5c2bcb6beabf05bc6cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Mei=C3=9Fner?= Date: Thu, 24 Mar 2022 12:57:51 +0100 Subject: [PATCH] Replaces keyed_account get_signers() by InstructionContext::get_signers(). (#23863) --- programs/stake/src/stake_instruction.rs | 6 ++++-- programs/vote/src/vote_processor.rs | 11 ++++++----- runtime/src/system_instruction_processor.rs | 6 ++++-- sdk/src/keyed_account.rs | 4 ++++ 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/programs/stake/src/stake_instruction.rs b/programs/stake/src/stake_instruction.rs index 3f2be50198..e577bdbab7 100644 --- a/programs/stake/src/stake_instruction.rs +++ b/programs/stake/src/stake_instruction.rs @@ -12,7 +12,7 @@ use { solana_sdk::{ feature_set, instruction::InstructionError, - keyed_account::{get_signers, keyed_account_at_index}, + keyed_account::keyed_account_at_index, program_utils::limited_deserialize, stake::{ instruction::StakeInstruction, @@ -28,6 +28,8 @@ pub fn process_instruction( data: &[u8], invoke_context: &mut InvokeContext, ) -> Result<(), InstructionError> { + let transaction_context = &invoke_context.transaction_context; + let instruction_context = transaction_context.get_current_instruction_context()?; let keyed_accounts = invoke_context.get_keyed_accounts()?; trace!("process_instruction: {:?}", data); @@ -38,7 +40,7 @@ pub fn process_instruction( return Err(InstructionError::InvalidAccountOwner); } - let signers = get_signers(&keyed_accounts[first_instruction_account..]); + let signers = instruction_context.get_signers(transaction_context); match limited_deserialize(data)? { StakeInstruction::Initialize(authorized, lockup) => { let rent = get_sysvar_with_account_check::rent( diff --git a/programs/vote/src/vote_processor.rs b/programs/vote/src/vote_processor.rs index 24cc8f0542..e170653133 100644 --- a/programs/vote/src/vote_processor.rs +++ b/programs/vote/src/vote_processor.rs @@ -10,12 +10,10 @@ use { solana_sdk::{ feature_set, instruction::InstructionError, - keyed_account::{get_signers, keyed_account_at_index, KeyedAccount}, + keyed_account::{keyed_account_at_index, KeyedAccount}, program_utils::limited_deserialize, - pubkey::Pubkey, sysvar::rent::Rent, }, - std::collections::HashSet, }; pub fn process_instruction( @@ -23,6 +21,8 @@ pub fn process_instruction( data: &[u8], invoke_context: &mut InvokeContext, ) -> Result<(), InstructionError> { + let transaction_context = &invoke_context.transaction_context; + let instruction_context = transaction_context.get_current_instruction_context()?; let keyed_accounts = invoke_context.get_keyed_accounts()?; trace!("process_instruction: {:?}", data); @@ -33,7 +33,7 @@ pub fn process_instruction( return Err(InstructionError::InvalidAccountOwner); } - let signers: HashSet = get_signers(&keyed_accounts[first_instruction_account..]); + let signers = instruction_context.get_signers(transaction_context); match limited_deserialize(data)? { VoteInstruction::InitializeAccount(vote_init) => { let rent = get_sysvar_with_account_check::rent( @@ -201,9 +201,10 @@ mod tests { feature_set::FeatureSet, hash::Hash, instruction::{AccountMeta, Instruction}, + pubkey::Pubkey, sysvar::{self, clock::Clock, slot_hashes::SlotHashes}, }, - std::str::FromStr, + std::{collections::HashSet, str::FromStr}, }; fn create_default_account() -> AccountSharedData { diff --git a/runtime/src/system_instruction_processor.rs b/runtime/src/system_instruction_processor.rs index 7e676f1542..0454e33777 100644 --- a/runtime/src/system_instruction_processor.rs +++ b/runtime/src/system_instruction_processor.rs @@ -12,7 +12,7 @@ use { account_utils::StateMut, feature_set, instruction::InstructionError, - keyed_account::{get_signers, keyed_account_at_index, KeyedAccount}, + keyed_account::{keyed_account_at_index, KeyedAccount}, nonce, program_utils::limited_deserialize, pubkey::Pubkey, @@ -268,6 +268,8 @@ pub fn process_instruction( instruction_data: &[u8], invoke_context: &mut InvokeContext, ) -> Result<(), InstructionError> { + let transaction_context = &invoke_context.transaction_context; + let instruction_context = transaction_context.get_current_instruction_context()?; let keyed_accounts = invoke_context.get_keyed_accounts()?; let instruction = limited_deserialize(instruction_data)?; @@ -275,7 +277,7 @@ pub fn process_instruction( trace!("keyed_accounts: {:?}", keyed_accounts); let _ = keyed_account_at_index(keyed_accounts, first_instruction_account)?; - let signers = get_signers(&keyed_accounts[first_instruction_account..]); + let signers = instruction_context.get_signers(transaction_context); match instruction { SystemInstruction::CreateAccount { lamports, diff --git a/sdk/src/keyed_account.rs b/sdk/src/keyed_account.rs index 9107009dce..20d5554300 100644 --- a/sdk/src/keyed_account.rs +++ b/sdk/src/keyed_account.rs @@ -198,6 +198,10 @@ pub fn create_keyed_accounts_unified<'a>( .collect() } +#[deprecated( + since = "1.11.0", + note = "Please use InstructionContext::get_signers() instead" +)] /// Return all the signers from a set of KeyedAccounts pub fn get_signers(keyed_accounts: &[KeyedAccount]) -> A where