Avoid AccountInUse errors when simulating transactions (#10391)

automerge
This commit is contained in:
Justin Starry
2020-06-05 10:06:01 +08:00
committed by GitHub
parent 68f95c791a
commit 754f25ae99
3 changed files with 31 additions and 7 deletions

View File

@ -1058,6 +1058,15 @@ impl Bank {
TransactionBatch::new(results, &self, txs, iteration_order)
}
pub fn prepare_simulation_batch<'a, 'b>(
&'a self,
txs: &'b [Transaction],
) -> TransactionBatch<'a, 'b> {
let mut batch = TransactionBatch::new(vec![Ok(()); txs.len()], &self, txs, None);
batch.needs_unlock = false;
batch
}
pub fn unlock_accounts(&self, batch: &mut TransactionBatch) {
if batch.needs_unlock {
batch.needs_unlock = false;

View File

@ -81,6 +81,23 @@ mod tests {
assert!(batch2.lock_results().iter().all(|x| x.is_ok()));
}
#[test]
fn test_simulation_batch() {
let (bank, txs) = setup();
// Prepare batch without locks
let batch = bank.prepare_simulation_batch(&txs);
assert!(batch.lock_results().iter().all(|x| x.is_ok()));
// Grab locks
let batch2 = bank.prepare_batch(&txs, None);
assert!(batch2.lock_results().iter().all(|x| x.is_ok()));
// Prepare another batch without locks
let batch3 = bank.prepare_simulation_batch(&txs);
assert!(batch3.lock_results().iter().all(|x| x.is_ok()));
}
fn setup() -> (Bank, Vec<Transaction>) {
let dummy_leader_pubkey = Pubkey::new_rand();
let GenesisConfigInfo {