Revert: KeyedAccount
refactoings in builtin programs (#23649)
* Revert "Replaces KeyedAccount by BorrowedAccount in the BPF loader. (#23056)"6c56eb9663
* Revert "Replaces `KeyedAccount` by `BorrowedAccount` in `system_instruction_processor`. (#23217)"ee7e411d68
* Revert "Replaces `KeyedAccount` by `BorrowedAccount` in `nonce_keyed_account`. (#23214)"1a68f81f89
* Revert "Replaces KeyedAccount by BorrowedAccount in the config processor. (#23302)"a14c7c37ee
* Revert "Replaces `KeyedAccount` by `BorrowedAccount` in vote processor (#23348)"e2fa6a0f7a
* Revert "Refactor: Prepare stake_instruction.rs to remove `KeyedAccount`s (#23375)"ee3fc39f1c
This commit is contained in:
committed by
GitHub
parent
44ab660172
commit
584ac80b1e
@@ -5,29 +5,33 @@ use {
|
||||
bincode::deserialize,
|
||||
solana_program_runtime::{ic_msg, invoke_context::InvokeContext},
|
||||
solana_sdk::{
|
||||
feature_set, instruction::InstructionError, program_utils::limited_deserialize,
|
||||
account::{ReadableAccount, WritableAccount},
|
||||
feature_set,
|
||||
instruction::InstructionError,
|
||||
keyed_account::keyed_account_at_index,
|
||||
program_utils::limited_deserialize,
|
||||
pubkey::Pubkey,
|
||||
},
|
||||
std::collections::BTreeSet,
|
||||
};
|
||||
|
||||
pub fn process_instruction(
|
||||
_first_instruction_account: usize,
|
||||
first_instruction_account: usize,
|
||||
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 key_list: ConfigKeys = limited_deserialize(data)?;
|
||||
let config_keyed_account =
|
||||
&mut keyed_account_at_index(keyed_accounts, first_instruction_account)?;
|
||||
let current_data: ConfigKeys = {
|
||||
let config_account =
|
||||
instruction_context.try_borrow_instruction_account(transaction_context, 0)?;
|
||||
if config_account.get_owner() != &crate::id() {
|
||||
let config_account = config_keyed_account.try_account_ref_mut()?;
|
||||
if config_account.owner() != &crate::id() {
|
||||
return Err(InstructionError::InvalidAccountOwner);
|
||||
}
|
||||
|
||||
deserialize(config_account.get_data()).map_err(|err| {
|
||||
deserialize(config_account.data()).map_err(|err| {
|
||||
ic_msg!(
|
||||
invoke_context,
|
||||
"Unable to deserialize config account: {}",
|
||||
@@ -46,7 +50,7 @@ pub fn process_instruction(
|
||||
if current_signer_keys.is_empty() {
|
||||
// Config account keypair must be a signer on account initialization,
|
||||
// or when no signers specified in Config data
|
||||
if !instruction_context.is_signer(instruction_context.get_number_of_program_accounts())? {
|
||||
if config_keyed_account.signer_key().is_none() {
|
||||
return Err(InstructionError::MissingRequiredSignature);
|
||||
}
|
||||
}
|
||||
@@ -54,10 +58,9 @@ pub fn process_instruction(
|
||||
let mut counter = 0;
|
||||
for (signer, _) in key_list.keys.iter().filter(|(_, is_signer)| *is_signer) {
|
||||
counter += 1;
|
||||
if signer != instruction_context.get_instruction_account_key(transaction_context, 0)? {
|
||||
let is_signer = instruction_context
|
||||
.is_signer(instruction_context.get_number_of_program_accounts() + counter)
|
||||
.map_err(|_| {
|
||||
if signer != config_keyed_account.unsigned_key() {
|
||||
let signer_account =
|
||||
keyed_account_at_index(keyed_accounts, counter + 1).map_err(|_| {
|
||||
ic_msg!(
|
||||
invoke_context,
|
||||
"account {:?} is not in account list",
|
||||
@@ -65,7 +68,8 @@ pub fn process_instruction(
|
||||
);
|
||||
InstructionError::MissingRequiredSignature
|
||||
})?;
|
||||
if !is_signer {
|
||||
let signer_key = signer_account.signer_key();
|
||||
if signer_key.is_none() {
|
||||
ic_msg!(
|
||||
invoke_context,
|
||||
"account {:?} signer_key().is_none()",
|
||||
@@ -73,9 +77,7 @@ pub fn process_instruction(
|
||||
);
|
||||
return Err(InstructionError::MissingRequiredSignature);
|
||||
}
|
||||
if instruction_context.get_instruction_account_key(transaction_context, counter)?
|
||||
!= signer
|
||||
{
|
||||
if signer_key.unwrap() != signer {
|
||||
ic_msg!(
|
||||
invoke_context,
|
||||
"account[{:?}].signer_key() does not match Config data)",
|
||||
@@ -94,9 +96,7 @@ pub fn process_instruction(
|
||||
);
|
||||
return Err(InstructionError::MissingRequiredSignature);
|
||||
}
|
||||
} else if !instruction_context
|
||||
.is_signer(instruction_context.get_number_of_program_accounts())?
|
||||
{
|
||||
} else if config_keyed_account.signer_key().is_none() {
|
||||
ic_msg!(invoke_context, "account[0].signer_key().is_none()");
|
||||
return Err(InstructionError::MissingRequiredSignature);
|
||||
}
|
||||
@@ -125,13 +125,15 @@ pub fn process_instruction(
|
||||
return Err(InstructionError::MissingRequiredSignature);
|
||||
}
|
||||
|
||||
let mut config_account =
|
||||
instruction_context.try_borrow_instruction_account(transaction_context, 0)?;
|
||||
if config_account.get_data().len() < data.len() {
|
||||
if config_keyed_account.data_len()? < data.len() {
|
||||
ic_msg!(invoke_context, "instruction data too large");
|
||||
return Err(InstructionError::InvalidInstructionData);
|
||||
}
|
||||
config_account.get_data_mut()[..data.len()].copy_from_slice(data);
|
||||
|
||||
config_keyed_account
|
||||
.try_account_ref_mut()?
|
||||
.data_as_mut_slice()[..data.len()]
|
||||
.copy_from_slice(data);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -144,7 +146,7 @@ mod tests {
|
||||
serde_derive::{Deserialize, Serialize},
|
||||
solana_program_runtime::invoke_context::mock_process_instruction,
|
||||
solana_sdk::{
|
||||
account::{AccountSharedData, ReadableAccount},
|
||||
account::AccountSharedData,
|
||||
instruction::AccountMeta,
|
||||
pubkey::Pubkey,
|
||||
signature::{Keypair, Signer},
|
||||
|
Reference in New Issue
Block a user