Skip to content

Commit

Permalink
Merge pull request #249 from ralexstokes/rollback-job-deadline
Browse files Browse the repository at this point in the history
restore deadline priority for payload jobs
  • Loading branch information
ralexstokes authored May 6, 2024
2 parents 86bd5fe + 39d10df commit 0cb5c36
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 19 deletions.
5 changes: 3 additions & 2 deletions mev-build-rs/src/bidder/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{
use reth::{primitives::U256, tasks::TaskExecutor};
use std::sync::Arc;
use tokio::sync::{mpsc::Receiver, oneshot};
use tracing::warn;
use tracing::trace;

pub type RevenueUpdate = (U256, oneshot::Sender<Option<U256>>);

Expand Down Expand Up @@ -33,7 +33,8 @@ impl Service {
while let Some((current_revenue, dispatch)) = revenue_updates.recv().await {
let value = strategy.run(&auction, current_revenue).await;
if dispatch.send(value).is_err() {
warn!("could not send bid value to builder");
trace!("channel closed; could not send bid value to builder");
break
}
}
});
Expand Down
23 changes: 6 additions & 17 deletions mev-build-rs/src/payload/job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,18 +139,19 @@ where
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
let this = self.get_mut();

// check if the deadline is reached
if this.deadline.as_mut().poll(cx).is_ready() {
trace!(target: "payload_builder", "payload building deadline reached");
return Poll::Ready(Ok(()))
}

// poll for pending bids
// NOTE: this should happen before anything else to ensure synchronization
// invariants the bidding task relies on
let mut pending_bid = false;
if let Some(mut fut) = this.pending_bid_update.take() {
pending_bid = true;
match fut.poll_unpin(cx) {
Poll::Pending => {
this.pending_bid_update = Some(fut);
}
Poll::Ready(Ok(maybe_dispatch)) => {
pending_bid = false;
if let Some((payload, value_to_bid)) = maybe_dispatch {
// TODO: handle the pending block, esp if this is the last bid
if let Some(proposal) = this.config.attributes.proposal.as_ref() {
Expand Down Expand Up @@ -182,18 +183,6 @@ where
}
}

// check if the deadline is reached
if this.deadline.as_mut().poll(cx).is_ready() {
trace!(target: "payload_builder", "payload building deadline reached");
if pending_bid {
// if we have reached the deadline, but still have a pending bid outstanding,
// return `Pending` to keep the job alive until we can settle the final bid update.
return Poll::Pending
} else {
return Poll::Ready(Ok(()))
}
}

// check if the interval is reached
while this.interval.poll_tick(cx).is_ready() {
// start a new job if there is no pending block and we haven't reached the deadline
Expand Down

0 comments on commit 0cb5c36

Please sign in to comment.