From ef3af104ae016b0bc6fedbc47a2150da95d0fd26 Mon Sep 17 00:00:00 2001 From: Justin Starry Date: Thu, 26 Mar 2020 04:23:05 +0800 Subject: [PATCH] Return appropriate error for invalid program account (#9047) automerge --- runtime/src/accounts.rs | 16 ++++++++-------- runtime/src/accounts_db.rs | 1 + sdk/src/transaction.rs | 3 +++ 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/runtime/src/accounts.rs b/runtime/src/accounts.rs index a794fdd12a..140ea707da 100644 --- a/runtime/src/accounts.rs +++ b/runtime/src/accounts.rs @@ -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) ) ); diff --git a/runtime/src/accounts_db.rs b/runtime/src/accounts_db.rs index 80f6e0462d..26e772480d 100644 --- a/runtime/src/accounts_db.rs +++ b/runtime/src/accounts_db.rs @@ -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)] diff --git a/sdk/src/transaction.rs b/sdk/src/transaction.rs index 01972e292d..054f18f799 100644 --- a/sdk/src/transaction.rs +++ b/sdk/src/transaction.rs @@ -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 = result::Result;