Skip to content

Detect block building completion #64

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 19 additions & 6 deletions crates/op-rbuilder/src/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,14 +178,16 @@ where
let deadline = Box::pin(tokio::time::sleep(deadline));
let config = PayloadConfig::new(Arc::new(parent_header.clone()), attributes);

let (tx, rx) = oneshot::channel();
let mut job = BlockPayloadJob {
executor: self.executor.clone(),
builder: self.builder.clone(),
config,
cell: BlockCell::new(),
cancel: cancel_token,
deadline,
build_complete: None,
build_complete_rx: rx,
build_complete_tx: Some(tx),
enable_revert_protection: self.enable_revert_protection,
};

Expand Down Expand Up @@ -218,7 +220,8 @@ where
/// Cancellation token for the running job
pub(crate) cancel: CancellationToken,
pub(crate) deadline: Pin<Box<Sleep>>, // Add deadline
pub(crate) build_complete: Option<oneshot::Receiver<Result<(), PayloadBuilderError>>>,
pub(crate) build_complete_rx: oneshot::Receiver<Result<(), PayloadBuilderError>>,
pub(crate) build_complete_tx: Option<oneshot::Sender<Result<(), PayloadBuilderError>>>,
/// Block building options
pub(crate) enable_revert_protection: bool,
}
Expand Down Expand Up @@ -281,10 +284,7 @@ where
let cell = self.cell.clone();
let cancel = self.cancel.clone();
let enable_revert_protection = self.enable_revert_protection;

let (tx, rx) = oneshot::channel();
self.build_complete = Some(rx);

let tx = self.build_complete_tx.take().expect("already spawned");
self.executor.spawn_blocking(Box::pin(async move {
let args = BuildArguments {
cached_reads: Default::default(),
Expand Down Expand Up @@ -326,6 +326,19 @@ where
return Poll::Ready(Ok(()));
}

// Poll the build_complete_rx receiver
match this.build_complete_rx.poll_unpin(cx) {
Poll::Ready(Ok(result)) => {
tracing::debug!("Build job completed");
return Poll::Ready(result);
}
Poll::Ready(Err(_)) => {
tracing::warn!("Build job sender was dropped");
return Poll::Ready(Ok(()));
}
Poll::Pending => {}
}

Poll::Pending
}
}
Expand Down