Improve account unlock performance (#18442)

* Improve account unlock performance

* fix clippy
This commit is contained in:
Justin Starry
2021-07-06 14:11:54 -05:00
committed by GitHub
parent d451363dc9
commit 6319e8811a

View File

@ -831,26 +831,15 @@ impl Accounts {
fn unlock_account( fn unlock_account(
&self, &self,
tx: &Transaction, account_locks: &mut AccountLocks,
result: &Result<()>, writable_keys: Vec<&Pubkey>,
locks: &mut AccountLocks, readonly_keys: Vec<&Pubkey>,
demote_sysvar_write_locks: bool,
) { ) {
match result {
Err(TransactionError::AccountInUse) => (),
Err(TransactionError::SanitizeFailure) => (),
Err(TransactionError::AccountLoadedTwice) => (),
_ => {
let (writable_keys, readonly_keys) = &tx
.message()
.get_account_keys_by_lock_type(demote_sysvar_write_locks);
for k in writable_keys { for k in writable_keys {
locks.unlock_write(k); account_locks.unlock_write(k);
} }
for k in readonly_keys { for k in readonly_keys {
locks.unlock_readonly(k); account_locks.unlock_readonly(k);
}
}
} }
} }
@ -904,22 +893,30 @@ impl Accounts {
} }
/// Once accounts are unlocked, new transactions that modify that state can enter the pipeline /// Once accounts are unlocked, new transactions that modify that state can enter the pipeline
#[allow(clippy::needless_collect)]
pub fn unlock_accounts<'a>( pub fn unlock_accounts<'a>(
&self, &self,
txs: impl Iterator<Item = &'a Transaction>, txs: impl Iterator<Item = &'a Transaction>,
results: &[Result<()>], results: &[Result<()>],
demote_sysvar_write_locks: bool, demote_sysvar_write_locks: bool,
) { ) {
let keys: Vec<_> = txs
.zip(results)
.filter_map(|(tx, res)| match res {
Err(TransactionError::AccountInUse) => None,
Err(TransactionError::SanitizeFailure) => None,
Err(TransactionError::AccountLoadedTwice) => None,
_ => Some(
tx.message
.get_account_keys_by_lock_type(demote_sysvar_write_locks),
),
})
.collect();
let mut account_locks = self.account_locks.lock().unwrap(); let mut account_locks = self.account_locks.lock().unwrap();
debug!("bank unlock accounts"); debug!("bank unlock accounts");
for (tx, lock_result) in txs.zip(results) { keys.into_iter().for_each(|(writable_keys, readonly_keys)| {
self.unlock_account( self.unlock_account(&mut account_locks, writable_keys, readonly_keys);
tx, });
lock_result,
&mut account_locks,
demote_sysvar_write_locks,
);
}
} }
/// Store the accounts into the DB /// Store the accounts into the DB