Make prepare_simulation_batch() more usable (#32304)

* Make prepare_simulation_batch() more usable

* Rename

* Use `use`
This commit is contained in:
Ryo Onodera 2023-06-29 11:20:42 +09:00 committed by GitHub
parent b8222b230c
commit 5b6c3ba81b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 9 deletions

View File

@ -180,6 +180,7 @@ use {
ops::{AddAssign, RangeInclusive}, ops::{AddAssign, RangeInclusive},
path::PathBuf, path::PathBuf,
rc::Rc, rc::Rc,
slice,
sync::{ sync::{
atomic::{ atomic::{
AtomicBool, AtomicI64, AtomicU64, AtomicUsize, AtomicBool, AtomicI64, AtomicU64, AtomicUsize,
@ -4811,17 +4812,20 @@ impl Bank {
TransactionBatch::new(lock_results, self, Cow::Borrowed(transactions)) TransactionBatch::new(lock_results, self, Cow::Borrowed(transactions))
} }
/// Prepare a transaction batch without locking accounts for transaction simulation. /// Prepare a transaction batch from a single transaction without locking accounts
pub(crate) fn prepare_simulation_batch( pub(crate) fn prepare_unlocked_batch_from_single_tx<'a>(
&self, &'a self,
transaction: SanitizedTransaction, transaction: &'a SanitizedTransaction,
) -> TransactionBatch<'_, '_> { ) -> TransactionBatch<'_, '_> {
let tx_account_lock_limit = self.get_transaction_account_lock_limit(); let tx_account_lock_limit = self.get_transaction_account_lock_limit();
let lock_result = transaction let lock_result = transaction
.get_account_locks(tx_account_lock_limit) .get_account_locks(tx_account_lock_limit)
.map(|_| ()); .map(|_| ());
let mut batch = let mut batch = TransactionBatch::new(
TransactionBatch::new(vec![lock_result], self, Cow::Owned(vec![transaction])); vec![lock_result],
self,
Cow::Borrowed(slice::from_ref(transaction)),
);
batch.set_needs_unlock(false); batch.set_needs_unlock(false);
batch batch
} }
@ -4845,7 +4849,7 @@ impl Bank {
let account_keys = transaction.message().account_keys(); let account_keys = transaction.message().account_keys();
let number_of_accounts = account_keys.len(); let number_of_accounts = account_keys.len();
let account_overrides = self.get_account_overrides_for_simulation(&account_keys); let account_overrides = self.get_account_overrides_for_simulation(&account_keys);
let batch = self.prepare_simulation_batch(transaction); let batch = self.prepare_unlocked_batch_from_single_tx(&transaction);
let mut timings = ExecuteTimings::default(); let mut timings = ExecuteTimings::default();
let LoadAndExecuteTransactionsOutput { let LoadAndExecuteTransactionsOutput {

View File

@ -90,7 +90,7 @@ mod tests {
let (bank, txs) = setup(); let (bank, txs) = setup();
// Prepare batch without locks // Prepare batch without locks
let batch = bank.prepare_simulation_batch(txs[0].clone()); let batch = bank.prepare_unlocked_batch_from_single_tx(&txs[0]);
assert!(batch.lock_results().iter().all(|x| x.is_ok())); assert!(batch.lock_results().iter().all(|x| x.is_ok()));
// Grab locks // Grab locks
@ -98,7 +98,7 @@ mod tests {
assert!(batch2.lock_results().iter().all(|x| x.is_ok())); assert!(batch2.lock_results().iter().all(|x| x.is_ok()));
// Prepare another batch without locks // Prepare another batch without locks
let batch3 = bank.prepare_simulation_batch(txs[0].clone()); let batch3 = bank.prepare_unlocked_batch_from_single_tx(&txs[0]);
assert!(batch3.lock_results().iter().all(|x| x.is_ok())); assert!(batch3.lock_results().iter().all(|x| x.is_ok()));
} }