reth_payload_builder/
noop.rs1use crate::{service::PayloadServiceCommand, PayloadBuilderHandle};
4use futures_util::{ready, StreamExt};
5use reth_payload_primitives::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(input, _, tx) => {
49 tx.send(Ok(input.payload_id())).ok()
50 }
51 PayloadServiceCommand::BestPayload(_, tx) => tx.send(None).ok(),
52 PayloadServiceCommand::PayloadTimestamp(_, tx) => tx.send(None).ok(),
53 PayloadServiceCommand::Resolve(_, _, tx) => tx.send(None).ok(),
54 PayloadServiceCommand::Subscribe(_) => None,
55 };
56 }
57 }
58}
59
60impl<T: PayloadTypes> Default for NoopPayloadBuilderService<T> {
61 fn default() -> Self {
62 let (service, _) = Self::new();
63 service
64 }
65}
66
67impl<T: PayloadTypes> PayloadBuilderHandle<T> {
68 pub fn noop() -> Self {
70 Self::new(mpsc::unbounded_channel().0)
71 }
72}