Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Commit

Permalink
Log more info on runtime account verification errors (#17861)
Browse files Browse the repository at this point in the history
  • Loading branch information
jackcmay authored Jun 9, 2021
1 parent ae27fcb commit a1fab0c
Showing 1 changed file with 31 additions and 17 deletions.
48 changes: 31 additions & 17 deletions runtime/src/message_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use solana_sdk::{
account_utils::StateMut,
bpf_loader_upgradeable::{self, UpgradeableLoaderState},
feature_set::{demote_sysvar_write_locks, instructions_sysvar_enabled, FeatureSet},
ic_msg,
ic_logger_msg, ic_msg,
instruction::{CompiledInstruction, Instruction, InstructionError},
keyed_account::{create_keyed_accounts_unified, keyed_account_at_index, KeyedAccount},
message::Message,
Expand Down Expand Up @@ -403,6 +403,7 @@ impl<'a> InvokeContext for ThisInvokeContext<'a> {
.invoke_stack
.last()
.ok_or(InstructionError::CallDepth)?;
let logger = self.get_logger();
MessageProcessor::verify_and_update(
message,
instruction,
Expand All @@ -413,6 +414,7 @@ impl<'a> InvokeContext for ThisInvokeContext<'a> {
caller_write_privileges,
&mut self.timings,
self.feature_set.is_active(&demote_sysvar_write_locks::id()),
logger,
)
}
fn get_caller(&self) -> Result<&Pubkey, InstructionError> {
Expand Down Expand Up @@ -1015,6 +1017,7 @@ impl MessageProcessor {
rent: &Rent,
timings: &mut ExecuteDetailsTimings,
demote_sysvar_write_locks: bool,
logger: Rc<RefCell<dyn Logger>>,
) -> Result<(), InstructionError> {
// Verify all executable accounts have zero outstanding refs
Self::verify_account_references(executable_accounts)?;
Expand All @@ -1031,14 +1034,24 @@ impl MessageProcessor {
.map_err(|_| InstructionError::AccountBorrowOutstanding)?;
}
let account = accounts[account_index].borrow();
pre_accounts[unique_index].verify(
&program_id,
message.is_writable(account_index, demote_sysvar_write_locks),
rent,
&account,
timings,
true,
)?;
pre_accounts[unique_index]
.verify(
&program_id,
message.is_writable(account_index, demote_sysvar_write_locks),
rent,
&account,
timings,
true,
)
.map_err(|err| {
ic_logger_msg!(
logger,
"failed to verify account {}: {}",
pre_accounts[unique_index].key,
err
);
err
})?;
pre_sum += u128::from(pre_accounts[unique_index].lamports());
post_sum += u128::from(account.lamports());
Ok(())
Expand All @@ -1054,6 +1067,7 @@ impl MessageProcessor {
}

/// Verify the results of a cross-program instruction
#[allow(clippy::too_many_arguments)]
fn verify_and_update(
message: &Message,
instruction: &CompiledInstruction,
Expand All @@ -1064,6 +1078,7 @@ impl MessageProcessor {
caller_write_privileges: Option<&[bool]>,
timings: &mut ExecuteDetailsTimings,
demote_sysvar_write_locks: bool,
logger: Rc<RefCell<dyn Logger>>,
) -> Result<(), InstructionError> {
// Verify the per-account instruction results
let (mut pre_sum, mut post_sum) = (0_u128, 0_u128);
Expand All @@ -1086,14 +1101,12 @@ impl MessageProcessor {
.map_err(|_| InstructionError::AccountBorrowOutstanding)?;
}
let account = account.borrow();
pre_account.verify(
&program_id,
is_writable,
&rent,
&account,
timings,
false,
)?;
pre_account
.verify(&program_id, is_writable, &rent, &account, timings, false)
.map_err(|err| {
ic_logger_msg!(logger, "failed to verify account {}: {}", key, err);
err
})?;
pre_sum += u128::from(pre_account.lamports());
post_sum += u128::from(account.lamports());
if is_writable && !account.executable() {
Expand Down Expand Up @@ -1182,6 +1195,7 @@ impl MessageProcessor {
&rent_collector.rent,
timings,
demote_sysvar_write_locks,
invoke_context.get_logger(),
)?;

timings.accumulate(&invoke_context.timings);
Expand Down

0 comments on commit a1fab0c

Please sign in to comment.