From 5b6c3ba81b92edd7d8213e00216e90967c40467e Mon Sep 17 00:00:00 2001 From: Ryo Onodera Date: Thu, 29 Jun 2023 11:20:42 +0900 Subject: [PATCH] Make prepare_simulation_batch() more usable (#32304) * Make prepare_simulation_batch() more usable * Rename * Use `use` --- runtime/src/bank.rs | 18 +++++++++++------- runtime/src/transaction_batch.rs | 4 ++-- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index 534f8d008..30d4795de 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -180,6 +180,7 @@ use { ops::{AddAssign, RangeInclusive}, path::PathBuf, rc::Rc, + slice, sync::{ atomic::{ AtomicBool, AtomicI64, AtomicU64, AtomicUsize, @@ -4811,17 +4812,20 @@ impl Bank { TransactionBatch::new(lock_results, self, Cow::Borrowed(transactions)) } - /// Prepare a transaction batch without locking accounts for transaction simulation. - pub(crate) fn prepare_simulation_batch( - &self, - transaction: SanitizedTransaction, + /// Prepare a transaction batch from a single transaction without locking accounts + pub(crate) fn prepare_unlocked_batch_from_single_tx<'a>( + &'a self, + transaction: &'a SanitizedTransaction, ) -> TransactionBatch<'_, '_> { let tx_account_lock_limit = self.get_transaction_account_lock_limit(); let lock_result = transaction .get_account_locks(tx_account_lock_limit) .map(|_| ()); - let mut batch = - TransactionBatch::new(vec![lock_result], self, Cow::Owned(vec![transaction])); + let mut batch = TransactionBatch::new( + vec![lock_result], + self, + Cow::Borrowed(slice::from_ref(transaction)), + ); batch.set_needs_unlock(false); batch } @@ -4845,7 +4849,7 @@ impl Bank { let account_keys = transaction.message().account_keys(); let number_of_accounts = account_keys.len(); 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 LoadAndExecuteTransactionsOutput { diff --git a/runtime/src/transaction_batch.rs b/runtime/src/transaction_batch.rs index 5d55acb2e..66711fd5a 100644 --- a/runtime/src/transaction_batch.rs +++ b/runtime/src/transaction_batch.rs @@ -90,7 +90,7 @@ mod tests { let (bank, txs) = setup(); // 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())); // Grab locks @@ -98,7 +98,7 @@ mod tests { assert!(batch2.lock_results().iter().all(|x| x.is_ok())); // 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())); }