More rich runtime logging (#14938) (#14967)

This commit is contained in:
mergify[bot]
2021-02-01 14:26:31 -08:00
committed by GitHub
parent 95cbfce900
commit bdd19c09d1
2 changed files with 32 additions and 22 deletions

View File

@ -60,7 +60,7 @@ pub enum SyscallError {
MalformedSignerSeed(Utf8Error, Vec<u8>), MalformedSignerSeed(Utf8Error, Vec<u8>),
#[error("Could not create program address with signer seeds: {0}")] #[error("Could not create program address with signer seeds: {0}")]
BadSeeds(PubkeyError), BadSeeds(PubkeyError),
#[error("Program {0} supported by inner instructions")] #[error("Program {0} not supported by inner instructions")]
ProgramNotSupported(Pubkey), ProgramNotSupported(Pubkey),
#[error("{0}")] #[error("{0}")]
InstructionError(InstructionError), InstructionError(InstructionError),
@ -68,8 +68,8 @@ pub enum SyscallError {
UnalignedPointer, UnalignedPointer,
#[error("Too many signers")] #[error("Too many signers")]
TooManySigners, TooManySigners,
#[error("Instruction passed to inner instruction is too large")] #[error("Instruction passed to inner instruction is too large ({0} > {1})")]
InstructionTooLarge, InstructionTooLarge(usize, usize),
#[error("Too many accounts passed to inner instruction")] #[error("Too many accounts passed to inner instruction")]
TooManyAccounts, TooManyAccounts,
} }
@ -1424,7 +1424,7 @@ where
let account = invoke_context.get_account(&account_key).ok_or_else(|| { let account = invoke_context.get_account(&account_key).ok_or_else(|| {
ic_msg!( ic_msg!(
invoke_context, invoke_context,
"Instruction references an unknown account {:?}", "Instruction references an unknown account {}",
account_key account_key
); );
SyscallError::InstructionError(InstructionError::MissingAccount) SyscallError::InstructionError(InstructionError::MissingAccount)
@ -1456,7 +1456,7 @@ where
} else { } else {
ic_msg!( ic_msg!(
invoke_context, invoke_context,
"Instruction references an unknown account {:?}", "Instruction references an unknown account {}",
account_key account_key
); );
return Err(SyscallError::InstructionError(InstructionError::MissingAccount).into()); return Err(SyscallError::InstructionError(InstructionError::MissingAccount).into());
@ -1471,12 +1471,12 @@ fn check_instruction_size(
data_len: usize, data_len: usize,
invoke_context: &Ref<&mut dyn InvokeContext>, invoke_context: &Ref<&mut dyn InvokeContext>,
) -> Result<(), EbpfError<BPFError>> { ) -> Result<(), EbpfError<BPFError>> {
if invoke_context let size = num_accounts * size_of::<AccountMeta>() + data_len;
let max_size = invoke_context
.get_bpf_compute_budget() .get_bpf_compute_budget()
.max_cpi_instruction_size .max_cpi_instruction_size;
< num_accounts * size_of::<AccountMeta>() + data_len if size > max_size {
{ return Err(SyscallError::InstructionTooLarge(size, max_size).into());
return Err(SyscallError::InstructionTooLarge.into());
} }
Ok(()) Ok(())
} }
@ -1528,7 +1528,7 @@ fn get_upgradeable_executable(
} else { } else {
ic_msg!( ic_msg!(
invoke_context, invoke_context,
"Unknown upgradeable programdata account {:?}", "Unknown upgradeable programdata account {}",
programdata_address, programdata_address,
); );
Err(SyscallError::InstructionError(InstructionError::MissingAccount).into()) Err(SyscallError::InstructionError(InstructionError::MissingAccount).into())
@ -1537,7 +1537,7 @@ fn get_upgradeable_executable(
_ => { _ => {
ic_msg!( ic_msg!(
invoke_context, invoke_context,
"Invalid upgradeable program account {:?}", "Invalid upgradeable program account {}",
callee_program_id, callee_program_id,
); );
Err(SyscallError::InstructionError(InstructionError::InvalidAccountData).into()) Err(SyscallError::InstructionError(InstructionError::InvalidAccountData).into())
@ -1625,7 +1625,7 @@ fn call<'a>(
// Construct executables // Construct executables
let program_account = (**accounts.get(callee_program_id_index).ok_or_else(|| { let program_account = (**accounts.get(callee_program_id_index).ok_or_else(|| {
ic_msg!(invoke_context, "Unknown program {:?}", callee_program_id,); ic_msg!(invoke_context, "Unknown program {}", callee_program_id,);
SyscallError::InstructionError(InstructionError::MissingAccount) SyscallError::InstructionError(InstructionError::MissingAccount)
})?) })?)
.clone(); .clone();
@ -1699,7 +1699,7 @@ fn call<'a>(
{ {
ic_msg!( ic_msg!(
invoke_context, invoke_context,
"SystemProgram::CreateAccount data size limited to {:?} in inner instructions", "SystemProgram::CreateAccount data size limited to {} in inner instructions",
MAX_PERMITTED_DATA_INCREASE MAX_PERMITTED_DATA_INCREASE
); );
return Err(SyscallError::InstructionError( return Err(SyscallError::InstructionError(

View File

@ -547,7 +547,7 @@ impl MessageProcessor {
.ok_or_else(|| { .ok_or_else(|| {
ic_msg!( ic_msg!(
invoke_context, invoke_context,
"Instruction references an unknown account {:?}", "Instruction references an unknown account {}",
account.pubkey account.pubkey
); );
InstructionError::MissingAccount InstructionError::MissingAccount
@ -556,7 +556,7 @@ impl MessageProcessor {
if account.is_writable && !keyed_account.is_writable() { if account.is_writable && !keyed_account.is_writable() {
ic_msg!( ic_msg!(
invoke_context, invoke_context,
"{:?}'s writable priviledge escalated ", "{}'s writable privilege escalated",
account.pubkey account.pubkey
); );
return Err(InstructionError::PrivilegeEscalation); return Err(InstructionError::PrivilegeEscalation);
@ -569,7 +569,7 @@ impl MessageProcessor {
) { ) {
ic_msg!( ic_msg!(
invoke_context, invoke_context,
"{:?}'s signer priviledge escalated ", "{}'s signer priviledge escalated",
account.pubkey account.pubkey
); );
return Err(InstructionError::PrivilegeEscalation); return Err(InstructionError::PrivilegeEscalation);
@ -584,11 +584,16 @@ impl MessageProcessor {
{ {
Some(keyed_account) => { Some(keyed_account) => {
if !keyed_account.executable()? { if !keyed_account.executable()? {
ic_msg!(
invoke_context,
"Account {} is not executable",
keyed_account.unsigned_key()
);
return Err(InstructionError::AccountNotExecutable); return Err(InstructionError::AccountNotExecutable);
} }
} }
None => { None => {
ic_msg!(invoke_context, "Unknown program {:?}", program_id); ic_msg!(invoke_context, "Unknown program {}", program_id);
return Err(InstructionError::MissingAccount); return Err(InstructionError::MissingAccount);
} }
} }
@ -638,7 +643,7 @@ impl MessageProcessor {
} }
ic_msg!( ic_msg!(
invoke_context, invoke_context,
"Instruction references an unknown account {:?}", "Instruction references an unknown account {}",
account_key account_key
); );
return Err(InstructionError::MissingAccount); return Err(InstructionError::MissingAccount);
@ -652,10 +657,15 @@ impl MessageProcessor {
invoke_context invoke_context
.get_account(&callee_program_id) .get_account(&callee_program_id)
.ok_or_else(|| { .ok_or_else(|| {
ic_msg!(invoke_context, "Unknown program {:?}", callee_program_id); ic_msg!(invoke_context, "Unknown program {}", callee_program_id);
InstructionError::MissingAccount InstructionError::MissingAccount
})?; })?;
if !program_account.borrow().executable { if !program_account.borrow().executable {
ic_msg!(
invoke_context,
"Account {} is not executable",
callee_program_id
);
return Err(InstructionError::AccountNotExecutable); return Err(InstructionError::AccountNotExecutable);
} }
let programdata_executable = let programdata_executable =
@ -669,7 +679,7 @@ impl MessageProcessor {
} else { } else {
ic_msg!( ic_msg!(
invoke_context, invoke_context,
"Unknown upgradeable programdata account {:?}", "Unknown upgradeable programdata account {}",
programdata_address, programdata_address,
); );
return Err(InstructionError::MissingAccount); return Err(InstructionError::MissingAccount);
@ -677,7 +687,7 @@ impl MessageProcessor {
} else { } else {
ic_msg!( ic_msg!(
invoke_context, invoke_context,
"Upgradeable program account state not valid {:?}", "Upgradeable program account state not valid {}",
callee_program_id, callee_program_id,
); );
return Err(InstructionError::MissingAccount); return Err(InstructionError::MissingAccount);