Transition config program over to ic_msg() logging (#15481)
(cherry picked from commit 8680a46458
)
Co-authored-by: Michael Vines <mvines@gmail.com>
This commit is contained in:
@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
use crate::ConfigKeys;
|
use crate::ConfigKeys;
|
||||||
use bincode::deserialize;
|
use bincode::deserialize;
|
||||||
use log::*;
|
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
|
ic_msg,
|
||||||
instruction::InstructionError,
|
instruction::InstructionError,
|
||||||
keyed_account::{next_keyed_account, KeyedAccount},
|
keyed_account::{next_keyed_account, KeyedAccount},
|
||||||
process_instruction::InvokeContext,
|
process_instruction::InvokeContext,
|
||||||
@ -15,7 +15,7 @@ pub fn process_instruction(
|
|||||||
_program_id: &Pubkey,
|
_program_id: &Pubkey,
|
||||||
keyed_accounts: &[KeyedAccount],
|
keyed_accounts: &[KeyedAccount],
|
||||||
data: &[u8],
|
data: &[u8],
|
||||||
_invoke_context: &mut dyn InvokeContext,
|
invoke_context: &mut dyn InvokeContext,
|
||||||
) -> Result<(), InstructionError> {
|
) -> Result<(), InstructionError> {
|
||||||
let key_list: ConfigKeys = limited_deserialize(data)?;
|
let key_list: ConfigKeys = limited_deserialize(data)?;
|
||||||
let keyed_accounts_iter = &mut keyed_accounts.iter();
|
let keyed_accounts_iter = &mut keyed_accounts.iter();
|
||||||
@ -23,10 +23,9 @@ pub fn process_instruction(
|
|||||||
let current_data: ConfigKeys = {
|
let current_data: ConfigKeys = {
|
||||||
let config_account = config_keyed_account.try_account_ref_mut()?;
|
let config_account = config_keyed_account.try_account_ref_mut()?;
|
||||||
deserialize(&config_account.data).map_err(|err| {
|
deserialize(&config_account.data).map_err(|err| {
|
||||||
error!(
|
ic_msg!(
|
||||||
"Unable to deserialize account[0]: {:?} (len={}): {:?}",
|
invoke_context,
|
||||||
config_account.data,
|
"Unable to deserialize config account: {}",
|
||||||
config_account.data.len(),
|
|
||||||
err
|
err
|
||||||
);
|
);
|
||||||
InstructionError::InvalidAccountData
|
InstructionError::InvalidAccountData
|
||||||
@ -43,7 +42,6 @@ pub fn process_instruction(
|
|||||||
// Config account keypair must be a signer on account initialization,
|
// Config account keypair must be a signer on account initialization,
|
||||||
// or when no signers specified in Config data
|
// or when no signers specified in Config data
|
||||||
if config_keyed_account.signer_key().is_none() {
|
if config_keyed_account.signer_key().is_none() {
|
||||||
error!("account[0].signer_key().is_none()");
|
|
||||||
return Err(InstructionError::MissingRequiredSignature);
|
return Err(InstructionError::MissingRequiredSignature);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -54,16 +52,25 @@ pub fn process_instruction(
|
|||||||
if signer != config_keyed_account.unsigned_key() {
|
if signer != config_keyed_account.unsigned_key() {
|
||||||
let signer_account = keyed_accounts_iter.next();
|
let signer_account = keyed_accounts_iter.next();
|
||||||
if signer_account.is_none() {
|
if signer_account.is_none() {
|
||||||
error!("account {:?} is not in account list", signer);
|
ic_msg!(
|
||||||
|
invoke_context,
|
||||||
|
"account {:?} is not in account list",
|
||||||
|
signer
|
||||||
|
);
|
||||||
return Err(InstructionError::MissingRequiredSignature);
|
return Err(InstructionError::MissingRequiredSignature);
|
||||||
}
|
}
|
||||||
let signer_key = signer_account.unwrap().signer_key();
|
let signer_key = signer_account.unwrap().signer_key();
|
||||||
if signer_key.is_none() {
|
if signer_key.is_none() {
|
||||||
error!("account {:?} signer_key().is_none()", signer);
|
ic_msg!(
|
||||||
|
invoke_context,
|
||||||
|
"account {:?} signer_key().is_none()",
|
||||||
|
signer
|
||||||
|
);
|
||||||
return Err(InstructionError::MissingRequiredSignature);
|
return Err(InstructionError::MissingRequiredSignature);
|
||||||
}
|
}
|
||||||
if signer_key.unwrap() != signer {
|
if signer_key.unwrap() != signer {
|
||||||
error!(
|
ic_msg!(
|
||||||
|
invoke_context,
|
||||||
"account[{:?}].signer_key() does not match Config data)",
|
"account[{:?}].signer_key() does not match Config data)",
|
||||||
counter + 1
|
counter + 1
|
||||||
);
|
);
|
||||||
@ -76,18 +83,23 @@ pub fn process_instruction(
|
|||||||
.find(|&pubkey| pubkey == signer)
|
.find(|&pubkey| pubkey == signer)
|
||||||
.is_none()
|
.is_none()
|
||||||
{
|
{
|
||||||
error!("account {:?} is not in stored signer list", signer);
|
ic_msg!(
|
||||||
|
invoke_context,
|
||||||
|
"account {:?} is not in stored signer list",
|
||||||
|
signer
|
||||||
|
);
|
||||||
return Err(InstructionError::MissingRequiredSignature);
|
return Err(InstructionError::MissingRequiredSignature);
|
||||||
}
|
}
|
||||||
} else if config_keyed_account.signer_key().is_none() {
|
} else if config_keyed_account.signer_key().is_none() {
|
||||||
error!("account[0].signer_key().is_none()");
|
ic_msg!(invoke_context, "account[0].signer_key().is_none()");
|
||||||
return Err(InstructionError::MissingRequiredSignature);
|
return Err(InstructionError::MissingRequiredSignature);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for Config data signers not present in incoming account update
|
// Check for Config data signers not present in incoming account update
|
||||||
if current_signer_keys.len() > counter {
|
if current_signer_keys.len() > counter {
|
||||||
error!(
|
ic_msg!(
|
||||||
|
invoke_context,
|
||||||
"too few signers: {:?}; expected: {:?}",
|
"too few signers: {:?}; expected: {:?}",
|
||||||
counter,
|
counter,
|
||||||
current_signer_keys.len()
|
current_signer_keys.len()
|
||||||
@ -96,7 +108,7 @@ pub fn process_instruction(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if config_keyed_account.data_len()? < data.len() {
|
if config_keyed_account.data_len()? < data.len() {
|
||||||
error!("instruction data too large");
|
ic_msg!(invoke_context, "instruction data too large");
|
||||||
return Err(InstructionError::InvalidInstructionData);
|
return Err(InstructionError::InvalidInstructionData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user