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:
16
src/bank.rs
16
src/bank.rs
@ -759,6 +759,16 @@ impl Bank {
|
|||||||
Ok(accounts)
|
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.
|
/// Execute a transaction.
|
||||||
/// This method calls each instruction in the transaction over the set of loaded Accounts
|
/// 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
|
/// The accounts are committed back to the bank only if every instruction succeeds
|
||||||
@ -768,14 +778,14 @@ impl Bank {
|
|||||||
tx_accounts: &mut [Account],
|
tx_accounts: &mut [Account],
|
||||||
tick_height: u64,
|
tick_height: u64,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
|
let mut loaders = self.load_loaders(tx)?;
|
||||||
for (instruction_index, instruction) in tx.instructions.iter().enumerate() {
|
for (instruction_index, instruction) in tx.instructions.iter().enumerate() {
|
||||||
let program_id = tx.program_id(instruction_index);
|
let ref mut executable_accounts = &mut loaders[instruction.program_ids_index as usize];
|
||||||
let mut executable_accounts = self.load_executable_accounts(*program_id)?;
|
|
||||||
Self::with_subset(tx_accounts, &instruction.accounts, |program_accounts| {
|
Self::with_subset(tx_accounts, &instruction.accounts, |program_accounts| {
|
||||||
runtime::execute_instruction(
|
runtime::execute_instruction(
|
||||||
tx,
|
tx,
|
||||||
instruction_index,
|
instruction_index,
|
||||||
&mut executable_accounts,
|
executable_accounts,
|
||||||
program_accounts,
|
program_accounts,
|
||||||
tick_height,
|
tick_height,
|
||||||
).map_err(|err| BankError::ProgramError(instruction_index as u8, err))?;
|
).map_err(|err| BankError::ProgramError(instruction_index as u8, err))?;
|
||||||
|
Reference in New Issue
Block a user