From f967f9eb40fe5b753f12f76f1e04a211f502cfb7 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Mon, 17 Jun 2024 19:39:18 +0200 Subject: [PATCH] feat: replace engine types in payload stack (#8893) --- Cargo.lock | 1 - crates/payload/builder/Cargo.toml | 1 - crates/payload/builder/src/events.rs | 8 +++---- crates/payload/builder/src/noop.rs | 9 ++++---- crates/payload/builder/src/service.rs | 29 ++++++++++++------------ crates/payload/builder/src/test_utils.rs | 6 ++--- 6 files changed, 25 insertions(+), 29 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fd04abebe..3bf7e7f4c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7644,7 +7644,6 @@ version = "1.0.0-rc.1" dependencies = [ "futures-util", "metrics", - "reth-engine-primitives", "reth-errors", "reth-ethereum-engine-primitives", "reth-metrics", diff --git a/crates/payload/builder/Cargo.toml b/crates/payload/builder/Cargo.toml index ce82ae7ff..735831e41 100644 --- a/crates/payload/builder/Cargo.toml +++ b/crates/payload/builder/Cargo.toml @@ -18,7 +18,6 @@ reth-rpc-types.workspace = true reth-transaction-pool.workspace = true reth-errors.workspace = true reth-provider.workspace = true -reth-engine-primitives.workspace = true reth-payload-primitives.workspace = true reth-ethereum-engine-primitives.workspace = true diff --git a/crates/payload/builder/src/events.rs b/crates/payload/builder/src/events.rs index 4df81030f..271eb2267 100644 --- a/crates/payload/builder/src/events.rs +++ b/crates/payload/builder/src/events.rs @@ -1,4 +1,4 @@ -use reth_engine_primitives::EngineTypes; +use reth_payload_primitives::PayloadTypes; use tokio::sync::broadcast; use tokio_stream::{ wrappers::{errors::BroadcastStreamRecvError, BroadcastStream}, @@ -7,7 +7,7 @@ use tokio_stream::{ /// Payload builder events. #[derive(Clone, Debug)] -pub enum Events { +pub enum Events { /// The payload attributes as /// they are received from the CL through the engine api. Attributes(Engine::PayloadBuilderAttributes), @@ -19,11 +19,11 @@ pub enum Events { /// Represents a receiver for various payload events. #[derive(Debug)] -pub struct PayloadEvents { +pub struct PayloadEvents { pub receiver: broadcast::Receiver>, } -impl PayloadEvents { +impl PayloadEvents { // Convert this receiver into a stream of PayloadEvents. pub fn into_stream(self) -> BroadcastStream> { BroadcastStream::new(self.receiver) diff --git a/crates/payload/builder/src/noop.rs b/crates/payload/builder/src/noop.rs index ef919ecf7..91ab90732 100644 --- a/crates/payload/builder/src/noop.rs +++ b/crates/payload/builder/src/noop.rs @@ -2,8 +2,7 @@ use crate::{service::PayloadServiceCommand, PayloadBuilderHandle}; use futures_util::{ready, StreamExt}; -use reth_engine_primitives::EngineTypes; -use reth_payload_primitives::PayloadBuilderAttributes; +use reth_payload_primitives::{PayloadBuilderAttributes, PayloadTypes}; use std::{ future::Future, pin::Pin, @@ -14,14 +13,14 @@ use tokio_stream::wrappers::UnboundedReceiverStream; /// A service task that does not build any payloads. #[derive(Debug)] -pub struct NoopPayloadBuilderService { +pub struct NoopPayloadBuilderService { /// Receiver half of the command channel. command_rx: UnboundedReceiverStream>, } impl NoopPayloadBuilderService where - Engine: EngineTypes + 'static, + Engine: PayloadTypes + 'static, { /// Creates a new [`NoopPayloadBuilderService`]. pub fn new() -> (Self, PayloadBuilderHandle) { @@ -35,7 +34,7 @@ where impl Future for NoopPayloadBuilderService where - Engine: EngineTypes, + Engine: PayloadTypes, { type Output = (); diff --git a/crates/payload/builder/src/service.rs b/crates/payload/builder/src/service.rs index 98790ef7d..8946cd587 100644 --- a/crates/payload/builder/src/service.rs +++ b/crates/payload/builder/src/service.rs @@ -11,8 +11,7 @@ use crate::{ KeepPayloadJobAlive, PayloadJob, }; use futures_util::{future::FutureExt, Stream, StreamExt}; -use reth_engine_primitives::EngineTypes; -use reth_payload_primitives::{BuiltPayload, PayloadBuilderAttributes}; +use reth_payload_primitives::{BuiltPayload, PayloadBuilderAttributes, PayloadTypes}; use reth_provider::CanonStateNotification; use reth_rpc_types::engine::PayloadId; use std::{ @@ -32,7 +31,7 @@ type PayloadFuture

= Pin { +pub struct PayloadStore { inner: PayloadBuilderHandle, } @@ -40,7 +39,7 @@ pub struct PayloadStore { impl PayloadStore where - Engine: EngineTypes + 'static, + Engine: PayloadTypes + 'static, { /// Resolves the payload job and returns the best payload that has been built so far. /// @@ -76,7 +75,7 @@ where impl Clone for PayloadStore where - Engine: EngineTypes, + Engine: PayloadTypes, { fn clone(&self) -> Self { Self { inner: self.inner.clone() } @@ -85,7 +84,7 @@ where impl From> for PayloadStore where - Engine: EngineTypes, + Engine: PayloadTypes, { fn from(inner: PayloadBuilderHandle) -> Self { Self { inner } @@ -96,7 +95,7 @@ where /// /// This is the API used to create new payloads and to get the current state of existing ones. #[derive(Debug)] -pub struct PayloadBuilderHandle { +pub struct PayloadBuilderHandle { /// Sender half of the message channel to the [`PayloadBuilderService`]. to_service: mpsc::UnboundedSender>, } @@ -105,7 +104,7 @@ pub struct PayloadBuilderHandle { impl PayloadBuilderHandle where - Engine: EngineTypes + 'static, + Engine: PayloadTypes + 'static, { /// Creates a new payload builder handle for the given channel. /// @@ -191,7 +190,7 @@ where impl Clone for PayloadBuilderHandle where - Engine: EngineTypes, + Engine: PayloadTypes, { fn clone(&self) -> Self { Self { to_service: self.to_service.clone() } @@ -210,7 +209,7 @@ where #[must_use = "futures do nothing unless you `.await` or poll them"] pub struct PayloadBuilderService where - Engine: EngineTypes, + Engine: PayloadTypes, Gen: PayloadJobGenerator, Gen::Job: PayloadJob, { @@ -236,7 +235,7 @@ const PAYLOAD_EVENTS_BUFFER_SIZE: usize = 20; impl PayloadBuilderService where - Engine: EngineTypes + 'static, + Engine: PayloadTypes + 'static, Gen: PayloadJobGenerator, Gen::Job: PayloadJob, ::BuiltPayload: Into, @@ -327,7 +326,7 @@ where impl PayloadBuilderService where - Engine: EngineTypes, + Engine: PayloadTypes, Gen: PayloadJobGenerator, Gen::Job: PayloadJob, ::BuiltPayload: Into, @@ -353,7 +352,7 @@ where impl Future for PayloadBuilderService where - Engine: EngineTypes + 'static, + Engine: PayloadTypes + 'static, Gen: PayloadJobGenerator + Unpin + 'static, ::Job: Unpin + 'static, St: Stream + Send + Unpin + 'static, @@ -453,7 +452,7 @@ where } /// Message type for the [`PayloadBuilderService`]. -pub enum PayloadServiceCommand { +pub enum PayloadServiceCommand { /// Start building a new payload. BuildNewPayload( Engine::PayloadBuilderAttributes, @@ -477,7 +476,7 @@ pub enum PayloadServiceCommand { impl fmt::Debug for PayloadServiceCommand where - Engine: EngineTypes, + Engine: PayloadTypes, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { diff --git a/crates/payload/builder/src/test_utils.rs b/crates/payload/builder/src/test_utils.rs index 26a3fab3f..62f697ddd 100644 --- a/crates/payload/builder/src/test_utils.rs +++ b/crates/payload/builder/src/test_utils.rs @@ -5,7 +5,7 @@ use crate::{ EthPayloadBuilderAttributes, PayloadBuilderHandle, PayloadBuilderService, PayloadJob, PayloadJobGenerator, }; -use reth_engine_primitives::EngineTypes; +use reth_payload_primitives::PayloadTypes; use reth_primitives::{Block, U256}; use reth_provider::CanonStateNotification; use std::{ @@ -24,7 +24,7 @@ pub fn test_payload_service() -> ( PayloadBuilderHandle, ) where - Engine: EngineTypes< + Engine: PayloadTypes< PayloadBuilderAttributes = EthPayloadBuilderAttributes, BuiltPayload = EthBuiltPayload, > + 'static, @@ -35,7 +35,7 @@ where /// Creates a new [`PayloadBuilderService`] for testing purposes and spawns it in the background. pub fn spawn_test_payload_service() -> PayloadBuilderHandle where - Engine: EngineTypes< + Engine: PayloadTypes< PayloadBuilderAttributes = EthPayloadBuilderAttributes, BuiltPayload = EthBuiltPayload, > + 'static,