From 53af223861e9a2876ab8bb131340c9da4a75db49 Mon Sep 17 00:00:00 2001 From: Alessandro Decina Date: Thu, 28 Nov 2024 00:29:17 +1100 Subject: [PATCH] PrioritizationFeeCache: make update() never sleep on the sender channel (#3813) Avoid update() callers having to notify the service_loop() thread by doing an explicit sleep instead of sleeping on channel.recv() when the channel is empty. This avoids the case in which multiple replay/banking threads call update() at the same time and end up... sleeping themselves acquiring the mutex to notify the receiver. --- runtime/src/prioritization_fee_cache.rs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/runtime/src/prioritization_fee_cache.rs b/runtime/src/prioritization_fee_cache.rs index 2ec0716e82e39b..616f4216b0c8c1 100644 --- a/runtime/src/prioritization_fee_cache.rs +++ b/runtime/src/prioritization_fee_cache.rs @@ -1,6 +1,6 @@ use { crate::{bank::Bank, prioritization_fee::*}, - crossbeam_channel::{unbounded, Receiver, Sender}, + crossbeam_channel::{unbounded, Receiver, Sender, TryRecvError}, log::*, solana_accounts_db::account_locks::validate_account_locks, solana_measure::measure_us, @@ -15,7 +15,8 @@ use { atomic::{AtomicU64, Ordering}, Arc, RwLock, }, - thread::{Builder, JoinHandle}, + thread::{sleep, Builder, JoinHandle}, + time::Duration, }, }; @@ -358,7 +359,18 @@ impl PrioritizationFeeCache { // for a slot. The updates are tracked and finalized by bank_id. let mut unfinalized = UnfinalizedPrioritizationFees::new(); - for update in receiver.iter() { + loop { + let update = match receiver.try_recv() { + Ok(update) => update, + Err(TryRecvError::Empty) => { + sleep(Duration::from_millis(5)); + continue; + } + Err(err @ TryRecvError::Disconnected) => { + info!("PrioritizationFeeCache::service_loop() is stopping because: {err}"); + break; + } + }; match update { CacheServiceUpdate::TransactionUpdate { slot,