mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-04-30 03:01:58 -04:00
fix: don't starve high priority requests (#2660)
This commit is contained in:
@@ -8,3 +8,15 @@ pub enum Priority {
|
||||
/// Queued from the front for download requests.
|
||||
High,
|
||||
}
|
||||
|
||||
impl Priority {
|
||||
/// Returns `true` if this is [Priority::High]
|
||||
pub fn is_high(&self) -> bool {
|
||||
matches!(self, Priority::High)
|
||||
}
|
||||
|
||||
/// Returns `true` if this is [Priority::Normal]
|
||||
pub fn is_normal(&self) -> bool {
|
||||
matches!(self, Priority::Normal)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,7 +158,14 @@ impl StateFetcher {
|
||||
match self.download_requests_rx.poll_next_unpin(cx) {
|
||||
Poll::Ready(Some(request)) => match request.get_priority() {
|
||||
Priority::High => {
|
||||
self.queued_requests.push_front(request);
|
||||
// find the first normal request and queue before, add this request to
|
||||
// the back of the high-priority queue
|
||||
let pos = self
|
||||
.queued_requests
|
||||
.iter()
|
||||
.position(|req| req.is_normal_priority())
|
||||
.unwrap_or(0);
|
||||
self.queued_requests.insert(pos, request);
|
||||
}
|
||||
Priority::Normal => {
|
||||
self.queued_requests.push_back(request);
|
||||
@@ -377,12 +384,18 @@ impl DownloadRequest {
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the requested priority of this request
|
||||
fn get_priority(&self) -> &Priority {
|
||||
match self {
|
||||
DownloadRequest::GetBlockHeaders { priority, .. } => priority,
|
||||
DownloadRequest::GetBlockBodies { priority, .. } => priority,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns `true` if this request is normal priority.
|
||||
fn is_normal_priority(&self) -> bool {
|
||||
self.get_priority().is_normal()
|
||||
}
|
||||
}
|
||||
|
||||
/// An action the syncer can emit.
|
||||
|
||||
Reference in New Issue
Block a user