v1.6: Use blake3 message hash in status cache (#16507)
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
use crate::bank::Bank;
|
||||
use crate::hashed_transaction::HashedTransaction;
|
||||
use solana_sdk::transaction::{Result, Transaction};
|
||||
use std::borrow::Cow;
|
||||
|
||||
// Represents the results of trying to lock a set of accounts
|
||||
pub struct TransactionBatch<'a, 'b> {
|
||||
lock_results: Vec<Result<()>>,
|
||||
bank: &'a Bank,
|
||||
transactions: &'b [Transaction],
|
||||
hashed_txs: Cow<'b, [HashedTransaction<'b>]>,
|
||||
pub(crate) needs_unlock: bool,
|
||||
}
|
||||
|
||||
@@ -13,13 +15,13 @@ impl<'a, 'b> TransactionBatch<'a, 'b> {
|
||||
pub fn new(
|
||||
lock_results: Vec<Result<()>>,
|
||||
bank: &'a Bank,
|
||||
transactions: &'b [Transaction],
|
||||
hashed_txs: Cow<'b, [HashedTransaction<'b>]>,
|
||||
) -> Self {
|
||||
assert_eq!(lock_results.len(), transactions.len());
|
||||
assert_eq!(lock_results.len(), hashed_txs.len());
|
||||
Self {
|
||||
lock_results,
|
||||
bank,
|
||||
transactions,
|
||||
hashed_txs,
|
||||
needs_unlock: true,
|
||||
}
|
||||
}
|
||||
@@ -28,8 +30,12 @@ impl<'a, 'b> TransactionBatch<'a, 'b> {
|
||||
&self.lock_results
|
||||
}
|
||||
|
||||
pub fn transactions(&self) -> &[Transaction] {
|
||||
self.transactions
|
||||
pub fn hashed_transactions(&self) -> &[HashedTransaction] {
|
||||
&self.hashed_txs
|
||||
}
|
||||
|
||||
pub fn transactions_iter(&self) -> impl Iterator<Item = &Transaction> {
|
||||
self.hashed_txs.iter().map(|h| h.transaction())
|
||||
}
|
||||
|
||||
pub fn bank(&self) -> &Bank {
|
||||
@@ -55,20 +61,20 @@ mod tests {
|
||||
let (bank, txs) = setup();
|
||||
|
||||
// Test getting locked accounts
|
||||
let batch = bank.prepare_batch(&txs);
|
||||
let batch = bank.prepare_batch(txs.iter());
|
||||
|
||||
// Grab locks
|
||||
assert!(batch.lock_results().iter().all(|x| x.is_ok()));
|
||||
|
||||
// Trying to grab locks again should fail
|
||||
let batch2 = bank.prepare_batch(&txs);
|
||||
let batch2 = bank.prepare_batch(txs.iter());
|
||||
assert!(batch2.lock_results().iter().all(|x| x.is_err()));
|
||||
|
||||
// Drop the first set of locks
|
||||
drop(batch);
|
||||
|
||||
// Now grabbing locks should work again
|
||||
let batch2 = bank.prepare_batch(&txs);
|
||||
let batch2 = bank.prepare_batch(txs.iter());
|
||||
assert!(batch2.lock_results().iter().all(|x| x.is_ok()));
|
||||
}
|
||||
|
||||
@@ -81,7 +87,7 @@ mod tests {
|
||||
assert!(batch.lock_results().iter().all(|x| x.is_ok()));
|
||||
|
||||
// Grab locks
|
||||
let batch2 = bank.prepare_batch(&txs);
|
||||
let batch2 = bank.prepare_batch(txs.iter());
|
||||
assert!(batch2.lock_results().iter().all(|x| x.is_ok()));
|
||||
|
||||
// Prepare another batch without locks
|
||||
|
Reference in New Issue
Block a user