Return appropriate error for invalid program account (#9047)

automerge
This commit is contained in:
Justin Starry 2020-03-26 04:23:05 +08:00 committed by GitHub
parent 9dc69d9843
commit ef3af104ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 8 deletions

View File

@ -230,9 +230,9 @@ impl Accounts {
return Err(TransactionError::ProgramAccountNotFound);
}
};
if !program.executable || program.owner == Pubkey::default() {
error_counters.account_not_found += 1;
return Err(TransactionError::AccountNotFound);
if !program.executable {
error_counters.invalid_program_for_execution += 1;
return Err(TransactionError::InvalidProgramForExecution);
}
// add loader to chain
@ -1154,12 +1154,12 @@ mod tests {
let loaded_accounts = load_accounts(tx, &accounts, &mut error_counters);
assert_eq!(error_counters.account_not_found, 1);
assert_eq!(error_counters.invalid_program_for_execution, 1);
assert_eq!(loaded_accounts.len(), 1);
assert_eq!(
loaded_accounts[0],
(
Err(TransactionError::AccountNotFound),
Err(TransactionError::InvalidProgramForExecution),
Some(HashAgeKind::Extant)
)
);
@ -1197,7 +1197,7 @@ mod tests {
assert_eq!(
loaded_accounts[0],
(
Err(TransactionError::AccountNotFound),
Err(TransactionError::ProgramAccountNotFound),
Some(HashAgeKind::Extant)
)
);
@ -1229,12 +1229,12 @@ mod tests {
let loaded_accounts = load_accounts(tx, &accounts, &mut error_counters);
assert_eq!(error_counters.account_not_found, 1);
assert_eq!(error_counters.invalid_program_for_execution, 1);
assert_eq!(loaded_accounts.len(), 1);
assert_eq!(
loaded_accounts[0],
(
Err(TransactionError::AccountNotFound),
Err(TransactionError::InvalidProgramForExecution),
Some(HashAgeKind::Extant)
)
);

View File

@ -77,6 +77,7 @@ pub struct ErrorCounters {
pub insufficient_funds: usize,
pub invalid_account_for_fee: usize,
pub invalid_account_index: usize,
pub invalid_program_for_execution: usize,
}
#[derive(Default, Debug, PartialEq, Clone)]

View File

@ -60,6 +60,9 @@ pub enum TransactionError {
/// Transaction did not pass signature verification
SignatureFailure,
/// This program may not be used for executing instructions
InvalidProgramForExecution,
}
pub type Result<T> = result::Result<T, TransactionError>;