From 15011eaa5a40dc06f18532ec0fb672523b5ee3ad Mon Sep 17 00:00:00 2001 From: Andrew Fitzgerald Date: Fri, 7 Apr 2023 09:04:03 -0700 Subject: [PATCH] separate check_transaction_age from check_age (#30994) --- runtime/src/bank.rs | 41 ++++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index c075507cb..b5865ffb6 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -3936,24 +3936,39 @@ impl Bank { txs.zip(lock_results) .map(|(tx, lock_res)| match lock_res { - Ok(()) => { - let recent_blockhash = tx.message().recent_blockhash(); - if hash_queue.is_hash_valid_for_age(recent_blockhash, max_age) { - (Ok(()), None) - } else if let Some((address, account)) = - self.check_transaction_for_nonce(tx, &next_durable_nonce) - { - (Ok(()), Some(NoncePartial::new(address, account))) - } else { - error_counters.blockhash_not_found += 1; - (Err(TransactionError::BlockhashNotFound), None) - } - } + Ok(()) => self.check_transaction_age( + tx, + max_age, + &next_durable_nonce, + &hash_queue, + error_counters, + ), Err(e) => (Err(e.clone()), None), }) .collect() } + fn check_transaction_age( + &self, + tx: &SanitizedTransaction, + max_age: usize, + next_durable_nonce: &DurableNonce, + hash_queue: &BlockhashQueue, + error_counters: &mut TransactionErrorMetrics, + ) -> TransactionCheckResult { + let recent_blockhash = tx.message().recent_blockhash(); + if hash_queue.is_hash_valid_for_age(recent_blockhash, max_age) { + (Ok(()), None) + } else if let Some((address, account)) = + self.check_transaction_for_nonce(tx, next_durable_nonce) + { + (Ok(()), Some(NoncePartial::new(address, account))) + } else { + error_counters.blockhash_not_found += 1; + (Err(TransactionError::BlockhashNotFound), None) + } + } + fn is_transaction_already_processed( &self, sanitized_tx: &SanitizedTransaction,