Skip to content

Commit

Permalink
v2.1: PrioritizationFeeCache: make update() never sleep on the sender…
Browse files Browse the repository at this point in the history
… channel (backport of #3813) (#3818)

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.

(cherry picked from commit 53af223)

Co-authored-by: Alessandro Decina <[email protected]>
  • Loading branch information
2 people authored and KirillLykov committed Dec 9, 2024
1 parent 719c3d3 commit 2a08475
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions runtime/src/prioritization_fee_cache.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -17,7 +17,8 @@ use {
atomic::{AtomicU64, Ordering},
Arc, RwLock,
},
thread::{Builder, JoinHandle},
thread::{sleep, Builder, JoinHandle},
time::Duration,
},
};

Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 2a08475

Please sign in to comment.