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

Commit

Permalink
Hoist loading of loaders
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
garious committed Nov 27, 2018
1 parent 71530b6 commit ffd4426
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))?;
Expand Down

0 comments on commit ffd4426

Please sign in to comment.