From a0b04ae376d9cd2c632f00c1edd966874e7e2dc5 Mon Sep 17 00:00:00 2001 From: Tao Zhu Date: Wed, 24 Jan 2024 02:00:04 +0000 Subject: [PATCH] [WIP] immediately un-reserve CU of txs that failed to get lock --- core/src/banking_stage/consumer.rs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/core/src/banking_stage/consumer.rs b/core/src/banking_stage/consumer.rs index e6acbba85eb324..bb29516a817f08 100644 --- a/core/src/banking_stage/consumer.rs +++ b/core/src/banking_stage/consumer.rs @@ -460,7 +460,7 @@ impl Consumer { pre_results: impl Iterator>, ) -> ProcessTransactionBatchOutput { let ( - (transaction_qos_cost_results, cost_model_throttled_transactions_count), + (mut transaction_qos_cost_results, cost_model_throttled_transactions_count), cost_model_us, ) = measure_us!(self.qos_service.select_and_accumulate_transaction_costs( bank, @@ -479,6 +479,29 @@ impl Consumer { }) )); + // Remove reserved block space for transaction failed to acquire lock + let unlocked_cost_results: Vec<_> = + batch.lock_results().iter() + .zip(transaction_qos_cost_results.iter_mut()) + .map(|(lock_result, cost)| { + if let Err(lock_err) = lock_result { + if let Ok(tx_cost) = cost { + // reset cost to lock_err, so it won't be accidentally removed more than once + // TODO *cost = Err(lock_err.clone()); + return Some(tx_cost); + } + } + return None; + }).collect(); + { + let mut cost_tracker = bank.write_cost_tracker().unwrap(); + unlocked_cost_results.iter().for_each(|tx_cost| { + if let Some(tx_cost) = tx_cost { + cost_tracker.remove(tx_cost); + } + }); + } + // retryable_txs includes AccountInUse, WouldExceedMaxBlockCostLimit // WouldExceedMaxAccountCostLimit, WouldExceedMaxVoteCostLimit // and WouldExceedMaxAccountDataCostLimit