Blur the line between Bank and Runtime

This commit is contained in:
Greg Fitzgerald 2019-03-13 13:51:40 -06:00
parent 6fd0d4dcf5
commit 150cd31ec0
2 changed files with 5 additions and 15 deletions

View File

@ -5,7 +5,7 @@
use crate::accounts::{Accounts, ErrorCounters, InstructionAccounts, InstructionLoaders};
use crate::hash_queue::HashQueue;
use crate::runtime::{self, InstructionError, TransactionError};
use crate::runtime::{self, InstructionError};
use crate::status_cache::StatusCache;
use bincode::serialize;
use hashbrown::HashMap;
@ -569,11 +569,7 @@ impl Bank {
.map(|(accs, tx)| match accs {
Err(e) => Err(e.clone()),
Ok((ref mut accounts, ref mut loaders)) => {
runtime::execute_transaction(tx, loaders, accounts, tick_height).map_err(
|TransactionError::InstructionError(index, err)| {
BankError::InstructionError(index, err)
},
)
runtime::execute_transaction(tx, loaders, accounts, tick_height)
}
})
.collect();

View File

@ -1,3 +1,4 @@
use crate::bank::BankError;
use crate::native_loader;
use crate::system_program::SystemError;
use solana_sdk::account::{create_keyed_accounts, Account, KeyedAccount};
@ -33,13 +34,6 @@ impl InstructionError {
}
}
/// Reasons the runtime might have rejected a transaction.
#[derive(Debug, PartialEq, Eq, Clone)]
pub enum TransactionError {
/// Executing the instruction at the given index produced an error.
InstructionError(u8, InstructionError),
}
/// Process an instruction
/// This method calls the instruction's program entrypoint method
fn process_instruction(
@ -202,7 +196,7 @@ pub fn execute_transaction(
loaders: &mut [Vec<(Pubkey, Account)>],
tx_accounts: &mut [Account],
tick_height: u64,
) -> Result<(), TransactionError> {
) -> Result<(), BankError> {
for (instruction_index, instruction) in tx.instructions.iter().enumerate() {
let executable_accounts = &mut (&mut loaders[instruction.program_ids_index as usize]);
let mut program_accounts = get_subset_unchecked_mut(tx_accounts, &instruction.accounts);
@ -213,7 +207,7 @@ pub fn execute_transaction(
&mut program_accounts,
tick_height,
)
.map_err(|err| TransactionError::InstructionError(instruction_index as u8, err))?;
.map_err(|err| BankError::InstructionError(instruction_index as u8, err))?;
}
Ok(())
}