reth_payload_builder/
noop.rs
1use crate::{service::PayloadServiceCommand, PayloadBuilderHandle};
4use futures_util::{ready, StreamExt};
5use reth_payload_primitives::{PayloadBuilderAttributes, PayloadTypes};
6use std::{
7 future::Future,
8 pin::Pin,
9 task::{Context, Poll},
10};
11use tokio::sync::mpsc;
12use tokio_stream::wrappers::UnboundedReceiverStream;
13
14#[derive(Debug)]
16pub struct NoopPayloadBuilderService<T: PayloadTypes> {
17 command_rx: UnboundedReceiverStream<PayloadServiceCommand<T>>,
19}
20
21impl<T> NoopPayloadBuilderService<T>
22where
23 T: PayloadTypes,
24{
25 pub fn new() -> (Self, PayloadBuilderHandle<T>) {
27 let (service_tx, command_rx) = mpsc::unbounded_channel();
28 (
29 Self { command_rx: UnboundedReceiverStream::new(command_rx) },
30 PayloadBuilderHandle::new(service_tx),
31 )
32 }
33}
34
35impl<T> Future for NoopPayloadBuilderService<T>
36where
37 T: PayloadTypes,
38{
39 type Output = ();
40
41 fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
42 let this = self.get_mut();
43 loop {
44 let Some(cmd) = ready!(this.command_rx.poll_next_unpin(cx)) else {
45 return Poll::Ready(())
46 };
47 match cmd {
48 PayloadServiceCommand::BuildNewPayload(attr, tx) => {
49 let id = attr.payload_id();
50 tx.send(Ok(id)).ok()
51 }
52 PayloadServiceCommand::BestPayload(_, tx) => tx.send(None).ok(),
53 PayloadServiceCommand::PayloadAttributes(_, tx) => tx.send(None).ok(),
54 PayloadServiceCommand::Resolve(_, _, tx) => tx.send(None).ok(),
55 PayloadServiceCommand::Subscribe(_) => None,
56 };
57 }
58 }
59}