Skip to content

Commit

Permalink
chore: preempt single block downloading (#11647)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse authored Oct 10, 2024
1 parent fca1cd8 commit 250785f
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions crates/net/p2p/src/full_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@ where
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
let this = self.get_mut();

// preemptive yield point
let mut budget = 4;

loop {
match ready!(this.request.poll(cx)) {
ResponseResult::Header(res) => {
Expand Down Expand Up @@ -232,6 +235,14 @@ where
if let Some(res) = this.take_block() {
return Poll::Ready(res)
}

// ensure we still have enough budget for another iteration
budget -= 1;
if budget == 0 {
// make sure we're woken up again
cx.waker().wake_by_ref();
return Poll::Pending
}
}
}
}
Expand Down

0 comments on commit 250785f

Please sign in to comment.