Hoist loading of loaders

This might cause a TPS boost in batched BPF transactions, since
now it'll only clone its account once per transaction instead of
once per instruction.
This commit is contained in:
Greg Fitzgerald 2018-11-26 22:35:26 -07:00
parent 1ac7536286
commit f549d8ac74
1 changed files with 13 additions and 3 deletions

View File

@ -759,6 +759,16 @@ impl Bank {
Ok(accounts)
}
/// For each program_id in the transaction, load its loaders.
fn load_loaders(&self, tx: &Transaction) -> Result<Vec<Vec<(Pubkey, Account)>>> {
tx.instructions
.iter()
.map(|ix| {
let program_id = tx.program_ids[ix.program_ids_index as usize];
self.load_executable_accounts(program_id)
}).collect()
}
/// Execute a transaction.
/// This method calls each instruction in the transaction over the set of loaded Accounts
/// The accounts are committed back to the bank only if every instruction succeeds
@ -768,14 +778,14 @@ impl Bank {
tx_accounts: &mut [Account],
tick_height: u64,
) -> Result<()> {
let mut loaders = self.load_loaders(tx)?;
for (instruction_index, instruction) in tx.instructions.iter().enumerate() {
let program_id = tx.program_id(instruction_index);
let mut executable_accounts = self.load_executable_accounts(*program_id)?;
let ref mut executable_accounts = &mut loaders[instruction.program_ids_index as usize];
Self::with_subset(tx_accounts, &instruction.accounts, |program_accounts| {
runtime::execute_instruction(
tx,
instruction_index,
&mut executable_accounts,
executable_accounts,
program_accounts,
tick_height,
).map_err(|err| BankError::ProgramError(instruction_index as u8, err))?;