use futures_util::Future; use reth::{ providers::StateProviderFactory, tasks::TaskSpawner, transaction_pool::TransactionPool, }; use reth_basic_payload_builder::{PayloadBuilder, PayloadConfig}; use reth_payload_builder::{error::PayloadBuilderError, KeepPayloadJobAlive, PayloadJob}; use std::{ pin::Pin, task::{Context, Poll}, }; /// A [PayloadJob] that builds empty blocks. pub struct EmptyBlockPayloadJob where Builder: PayloadBuilder, { /// The configuration for how the payload will be created. pub(crate) config: PayloadConfig, /// The client that can interact with the chain. pub(crate) client: Client, /// The transaction pool. pub(crate) _pool: Pool, /// How to spawn building tasks pub(crate) _executor: Tasks, /// The type responsible for building payloads. /// /// See [PayloadBuilder] pub(crate) builder: Builder, } impl PayloadJob for EmptyBlockPayloadJob where Client: StateProviderFactory + Clone + Unpin + 'static, Pool: TransactionPool + Unpin + 'static, Tasks: TaskSpawner + Clone + 'static, Builder: PayloadBuilder + Unpin + 'static, >::Attributes: Unpin + Clone, >::BuiltPayload: Unpin + Clone, { type PayloadAttributes = Builder::Attributes; type ResolvePayloadFuture = futures_util::future::Ready>; type BuiltPayload = Builder::BuiltPayload; fn best_payload(&self) -> Result { let payload = self.builder.build_empty_payload(&self.client, self.config.clone())?; Ok(payload) } fn payload_attributes(&self) -> Result { Ok(self.config.attributes.clone()) } fn resolve(&mut self) -> (Self::ResolvePayloadFuture, KeepPayloadJobAlive) { let payload = self.best_payload(); (futures_util::future::ready(payload), KeepPayloadJobAlive::No) } } /// A [PayloadJob] is a a future that's being polled by the `PayloadBuilderService` impl Future for EmptyBlockPayloadJob where Client: StateProviderFactory + Clone + Unpin + 'static, Pool: TransactionPool + Unpin + 'static, Tasks: TaskSpawner + Clone + 'static, Builder: PayloadBuilder + Unpin + 'static, >::Attributes: Unpin + Clone, >::BuiltPayload: Unpin + Clone, { type Output = Result<(), PayloadBuilderError>; fn poll(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll { Poll::Pending } }