mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat: replace engine types in payload stack (#8893)
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -7644,7 +7644,6 @@ version = "1.0.0-rc.1"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"futures-util",
|
"futures-util",
|
||||||
"metrics",
|
"metrics",
|
||||||
"reth-engine-primitives",
|
|
||||||
"reth-errors",
|
"reth-errors",
|
||||||
"reth-ethereum-engine-primitives",
|
"reth-ethereum-engine-primitives",
|
||||||
"reth-metrics",
|
"reth-metrics",
|
||||||
|
|||||||
@ -18,7 +18,6 @@ reth-rpc-types.workspace = true
|
|||||||
reth-transaction-pool.workspace = true
|
reth-transaction-pool.workspace = true
|
||||||
reth-errors.workspace = true
|
reth-errors.workspace = true
|
||||||
reth-provider.workspace = true
|
reth-provider.workspace = true
|
||||||
reth-engine-primitives.workspace = true
|
|
||||||
reth-payload-primitives.workspace = true
|
reth-payload-primitives.workspace = true
|
||||||
reth-ethereum-engine-primitives.workspace = true
|
reth-ethereum-engine-primitives.workspace = true
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
use reth_engine_primitives::EngineTypes;
|
use reth_payload_primitives::PayloadTypes;
|
||||||
use tokio::sync::broadcast;
|
use tokio::sync::broadcast;
|
||||||
use tokio_stream::{
|
use tokio_stream::{
|
||||||
wrappers::{errors::BroadcastStreamRecvError, BroadcastStream},
|
wrappers::{errors::BroadcastStreamRecvError, BroadcastStream},
|
||||||
@ -7,7 +7,7 @@ use tokio_stream::{
|
|||||||
|
|
||||||
/// Payload builder events.
|
/// Payload builder events.
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub enum Events<Engine: EngineTypes> {
|
pub enum Events<Engine: PayloadTypes> {
|
||||||
/// The payload attributes as
|
/// The payload attributes as
|
||||||
/// they are received from the CL through the engine api.
|
/// they are received from the CL through the engine api.
|
||||||
Attributes(Engine::PayloadBuilderAttributes),
|
Attributes(Engine::PayloadBuilderAttributes),
|
||||||
@ -19,11 +19,11 @@ pub enum Events<Engine: EngineTypes> {
|
|||||||
|
|
||||||
/// Represents a receiver for various payload events.
|
/// Represents a receiver for various payload events.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct PayloadEvents<Engine: EngineTypes> {
|
pub struct PayloadEvents<Engine: PayloadTypes> {
|
||||||
pub receiver: broadcast::Receiver<Events<Engine>>,
|
pub receiver: broadcast::Receiver<Events<Engine>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Engine: EngineTypes + 'static> PayloadEvents<Engine> {
|
impl<Engine: PayloadTypes + 'static> PayloadEvents<Engine> {
|
||||||
// Convert this receiver into a stream of PayloadEvents.
|
// Convert this receiver into a stream of PayloadEvents.
|
||||||
pub fn into_stream(self) -> BroadcastStream<Events<Engine>> {
|
pub fn into_stream(self) -> BroadcastStream<Events<Engine>> {
|
||||||
BroadcastStream::new(self.receiver)
|
BroadcastStream::new(self.receiver)
|
||||||
|
|||||||
@ -2,8 +2,7 @@
|
|||||||
|
|
||||||
use crate::{service::PayloadServiceCommand, PayloadBuilderHandle};
|
use crate::{service::PayloadServiceCommand, PayloadBuilderHandle};
|
||||||
use futures_util::{ready, StreamExt};
|
use futures_util::{ready, StreamExt};
|
||||||
use reth_engine_primitives::EngineTypes;
|
use reth_payload_primitives::{PayloadBuilderAttributes, PayloadTypes};
|
||||||
use reth_payload_primitives::PayloadBuilderAttributes;
|
|
||||||
use std::{
|
use std::{
|
||||||
future::Future,
|
future::Future,
|
||||||
pin::Pin,
|
pin::Pin,
|
||||||
@ -14,14 +13,14 @@ use tokio_stream::wrappers::UnboundedReceiverStream;
|
|||||||
|
|
||||||
/// A service task that does not build any payloads.
|
/// A service task that does not build any payloads.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct NoopPayloadBuilderService<Engine: EngineTypes> {
|
pub struct NoopPayloadBuilderService<Engine: PayloadTypes> {
|
||||||
/// Receiver half of the command channel.
|
/// Receiver half of the command channel.
|
||||||
command_rx: UnboundedReceiverStream<PayloadServiceCommand<Engine>>,
|
command_rx: UnboundedReceiverStream<PayloadServiceCommand<Engine>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Engine> NoopPayloadBuilderService<Engine>
|
impl<Engine> NoopPayloadBuilderService<Engine>
|
||||||
where
|
where
|
||||||
Engine: EngineTypes + 'static,
|
Engine: PayloadTypes + 'static,
|
||||||
{
|
{
|
||||||
/// Creates a new [`NoopPayloadBuilderService`].
|
/// Creates a new [`NoopPayloadBuilderService`].
|
||||||
pub fn new() -> (Self, PayloadBuilderHandle<Engine>) {
|
pub fn new() -> (Self, PayloadBuilderHandle<Engine>) {
|
||||||
@ -35,7 +34,7 @@ where
|
|||||||
|
|
||||||
impl<Engine> Future for NoopPayloadBuilderService<Engine>
|
impl<Engine> Future for NoopPayloadBuilderService<Engine>
|
||||||
where
|
where
|
||||||
Engine: EngineTypes,
|
Engine: PayloadTypes,
|
||||||
{
|
{
|
||||||
type Output = ();
|
type Output = ();
|
||||||
|
|
||||||
|
|||||||
@ -11,8 +11,7 @@ use crate::{
|
|||||||
KeepPayloadJobAlive, PayloadJob,
|
KeepPayloadJobAlive, PayloadJob,
|
||||||
};
|
};
|
||||||
use futures_util::{future::FutureExt, Stream, StreamExt};
|
use futures_util::{future::FutureExt, Stream, StreamExt};
|
||||||
use reth_engine_primitives::EngineTypes;
|
use reth_payload_primitives::{BuiltPayload, PayloadBuilderAttributes, PayloadTypes};
|
||||||
use reth_payload_primitives::{BuiltPayload, PayloadBuilderAttributes};
|
|
||||||
use reth_provider::CanonStateNotification;
|
use reth_provider::CanonStateNotification;
|
||||||
use reth_rpc_types::engine::PayloadId;
|
use reth_rpc_types::engine::PayloadId;
|
||||||
use std::{
|
use std::{
|
||||||
@ -32,7 +31,7 @@ type PayloadFuture<P> = Pin<Box<dyn Future<Output = Result<P, PayloadBuilderErro
|
|||||||
|
|
||||||
/// A communication channel to the [`PayloadBuilderService`] that can retrieve payloads.
|
/// A communication channel to the [`PayloadBuilderService`] that can retrieve payloads.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct PayloadStore<Engine: EngineTypes> {
|
pub struct PayloadStore<Engine: PayloadTypes> {
|
||||||
inner: PayloadBuilderHandle<Engine>,
|
inner: PayloadBuilderHandle<Engine>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,7 +39,7 @@ pub struct PayloadStore<Engine: EngineTypes> {
|
|||||||
|
|
||||||
impl<Engine> PayloadStore<Engine>
|
impl<Engine> PayloadStore<Engine>
|
||||||
where
|
where
|
||||||
Engine: EngineTypes + 'static,
|
Engine: PayloadTypes + 'static,
|
||||||
{
|
{
|
||||||
/// Resolves the payload job and returns the best payload that has been built so far.
|
/// Resolves the payload job and returns the best payload that has been built so far.
|
||||||
///
|
///
|
||||||
@ -76,7 +75,7 @@ where
|
|||||||
|
|
||||||
impl<Engine> Clone for PayloadStore<Engine>
|
impl<Engine> Clone for PayloadStore<Engine>
|
||||||
where
|
where
|
||||||
Engine: EngineTypes,
|
Engine: PayloadTypes,
|
||||||
{
|
{
|
||||||
fn clone(&self) -> Self {
|
fn clone(&self) -> Self {
|
||||||
Self { inner: self.inner.clone() }
|
Self { inner: self.inner.clone() }
|
||||||
@ -85,7 +84,7 @@ where
|
|||||||
|
|
||||||
impl<Engine> From<PayloadBuilderHandle<Engine>> for PayloadStore<Engine>
|
impl<Engine> From<PayloadBuilderHandle<Engine>> for PayloadStore<Engine>
|
||||||
where
|
where
|
||||||
Engine: EngineTypes,
|
Engine: PayloadTypes,
|
||||||
{
|
{
|
||||||
fn from(inner: PayloadBuilderHandle<Engine>) -> Self {
|
fn from(inner: PayloadBuilderHandle<Engine>) -> Self {
|
||||||
Self { inner }
|
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.
|
/// This is the API used to create new payloads and to get the current state of existing ones.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct PayloadBuilderHandle<Engine: EngineTypes> {
|
pub struct PayloadBuilderHandle<Engine: PayloadTypes> {
|
||||||
/// Sender half of the message channel to the [`PayloadBuilderService`].
|
/// Sender half of the message channel to the [`PayloadBuilderService`].
|
||||||
to_service: mpsc::UnboundedSender<PayloadServiceCommand<Engine>>,
|
to_service: mpsc::UnboundedSender<PayloadServiceCommand<Engine>>,
|
||||||
}
|
}
|
||||||
@ -105,7 +104,7 @@ pub struct PayloadBuilderHandle<Engine: EngineTypes> {
|
|||||||
|
|
||||||
impl<Engine> PayloadBuilderHandle<Engine>
|
impl<Engine> PayloadBuilderHandle<Engine>
|
||||||
where
|
where
|
||||||
Engine: EngineTypes + 'static,
|
Engine: PayloadTypes + 'static,
|
||||||
{
|
{
|
||||||
/// Creates a new payload builder handle for the given channel.
|
/// Creates a new payload builder handle for the given channel.
|
||||||
///
|
///
|
||||||
@ -191,7 +190,7 @@ where
|
|||||||
|
|
||||||
impl<Engine> Clone for PayloadBuilderHandle<Engine>
|
impl<Engine> Clone for PayloadBuilderHandle<Engine>
|
||||||
where
|
where
|
||||||
Engine: EngineTypes,
|
Engine: PayloadTypes,
|
||||||
{
|
{
|
||||||
fn clone(&self) -> Self {
|
fn clone(&self) -> Self {
|
||||||
Self { to_service: self.to_service.clone() }
|
Self { to_service: self.to_service.clone() }
|
||||||
@ -210,7 +209,7 @@ where
|
|||||||
#[must_use = "futures do nothing unless you `.await` or poll them"]
|
#[must_use = "futures do nothing unless you `.await` or poll them"]
|
||||||
pub struct PayloadBuilderService<Gen, St, Engine>
|
pub struct PayloadBuilderService<Gen, St, Engine>
|
||||||
where
|
where
|
||||||
Engine: EngineTypes,
|
Engine: PayloadTypes,
|
||||||
Gen: PayloadJobGenerator,
|
Gen: PayloadJobGenerator,
|
||||||
Gen::Job: PayloadJob<PayloadAttributes = Engine::PayloadBuilderAttributes>,
|
Gen::Job: PayloadJob<PayloadAttributes = Engine::PayloadBuilderAttributes>,
|
||||||
{
|
{
|
||||||
@ -236,7 +235,7 @@ const PAYLOAD_EVENTS_BUFFER_SIZE: usize = 20;
|
|||||||
|
|
||||||
impl<Gen, St, Engine> PayloadBuilderService<Gen, St, Engine>
|
impl<Gen, St, Engine> PayloadBuilderService<Gen, St, Engine>
|
||||||
where
|
where
|
||||||
Engine: EngineTypes + 'static,
|
Engine: PayloadTypes + 'static,
|
||||||
Gen: PayloadJobGenerator,
|
Gen: PayloadJobGenerator,
|
||||||
Gen::Job: PayloadJob<PayloadAttributes = Engine::PayloadBuilderAttributes>,
|
Gen::Job: PayloadJob<PayloadAttributes = Engine::PayloadBuilderAttributes>,
|
||||||
<Gen::Job as PayloadJob>::BuiltPayload: Into<Engine::BuiltPayload>,
|
<Gen::Job as PayloadJob>::BuiltPayload: Into<Engine::BuiltPayload>,
|
||||||
@ -327,7 +326,7 @@ where
|
|||||||
|
|
||||||
impl<Gen, St, Engine> PayloadBuilderService<Gen, St, Engine>
|
impl<Gen, St, Engine> PayloadBuilderService<Gen, St, Engine>
|
||||||
where
|
where
|
||||||
Engine: EngineTypes,
|
Engine: PayloadTypes,
|
||||||
Gen: PayloadJobGenerator,
|
Gen: PayloadJobGenerator,
|
||||||
Gen::Job: PayloadJob<PayloadAttributes = Engine::PayloadBuilderAttributes>,
|
Gen::Job: PayloadJob<PayloadAttributes = Engine::PayloadBuilderAttributes>,
|
||||||
<Gen::Job as PayloadJob>::BuiltPayload: Into<Engine::BuiltPayload>,
|
<Gen::Job as PayloadJob>::BuiltPayload: Into<Engine::BuiltPayload>,
|
||||||
@ -353,7 +352,7 @@ where
|
|||||||
|
|
||||||
impl<Gen, St, Engine> Future for PayloadBuilderService<Gen, St, Engine>
|
impl<Gen, St, Engine> Future for PayloadBuilderService<Gen, St, Engine>
|
||||||
where
|
where
|
||||||
Engine: EngineTypes + 'static,
|
Engine: PayloadTypes + 'static,
|
||||||
Gen: PayloadJobGenerator + Unpin + 'static,
|
Gen: PayloadJobGenerator + Unpin + 'static,
|
||||||
<Gen as PayloadJobGenerator>::Job: Unpin + 'static,
|
<Gen as PayloadJobGenerator>::Job: Unpin + 'static,
|
||||||
St: Stream<Item = CanonStateNotification> + Send + Unpin + 'static,
|
St: Stream<Item = CanonStateNotification> + Send + Unpin + 'static,
|
||||||
@ -453,7 +452,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Message type for the [`PayloadBuilderService`].
|
/// Message type for the [`PayloadBuilderService`].
|
||||||
pub enum PayloadServiceCommand<Engine: EngineTypes> {
|
pub enum PayloadServiceCommand<Engine: PayloadTypes> {
|
||||||
/// Start building a new payload.
|
/// Start building a new payload.
|
||||||
BuildNewPayload(
|
BuildNewPayload(
|
||||||
Engine::PayloadBuilderAttributes,
|
Engine::PayloadBuilderAttributes,
|
||||||
@ -477,7 +476,7 @@ pub enum PayloadServiceCommand<Engine: EngineTypes> {
|
|||||||
|
|
||||||
impl<Engine> fmt::Debug for PayloadServiceCommand<Engine>
|
impl<Engine> fmt::Debug for PayloadServiceCommand<Engine>
|
||||||
where
|
where
|
||||||
Engine: EngineTypes,
|
Engine: PayloadTypes,
|
||||||
{
|
{
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
|
|||||||
@ -5,7 +5,7 @@ use crate::{
|
|||||||
EthPayloadBuilderAttributes, PayloadBuilderHandle, PayloadBuilderService, PayloadJob,
|
EthPayloadBuilderAttributes, PayloadBuilderHandle, PayloadBuilderService, PayloadJob,
|
||||||
PayloadJobGenerator,
|
PayloadJobGenerator,
|
||||||
};
|
};
|
||||||
use reth_engine_primitives::EngineTypes;
|
use reth_payload_primitives::PayloadTypes;
|
||||||
use reth_primitives::{Block, U256};
|
use reth_primitives::{Block, U256};
|
||||||
use reth_provider::CanonStateNotification;
|
use reth_provider::CanonStateNotification;
|
||||||
use std::{
|
use std::{
|
||||||
@ -24,7 +24,7 @@ pub fn test_payload_service<Engine>() -> (
|
|||||||
PayloadBuilderHandle<Engine>,
|
PayloadBuilderHandle<Engine>,
|
||||||
)
|
)
|
||||||
where
|
where
|
||||||
Engine: EngineTypes<
|
Engine: PayloadTypes<
|
||||||
PayloadBuilderAttributes = EthPayloadBuilderAttributes,
|
PayloadBuilderAttributes = EthPayloadBuilderAttributes,
|
||||||
BuiltPayload = EthBuiltPayload,
|
BuiltPayload = EthBuiltPayload,
|
||||||
> + 'static,
|
> + 'static,
|
||||||
@ -35,7 +35,7 @@ where
|
|||||||
/// Creates a new [`PayloadBuilderService`] for testing purposes and spawns it in the background.
|
/// Creates a new [`PayloadBuilderService`] for testing purposes and spawns it in the background.
|
||||||
pub fn spawn_test_payload_service<Engine>() -> PayloadBuilderHandle<Engine>
|
pub fn spawn_test_payload_service<Engine>() -> PayloadBuilderHandle<Engine>
|
||||||
where
|
where
|
||||||
Engine: EngineTypes<
|
Engine: PayloadTypes<
|
||||||
PayloadBuilderAttributes = EthPayloadBuilderAttributes,
|
PayloadBuilderAttributes = EthPayloadBuilderAttributes,
|
||||||
BuiltPayload = EthBuiltPayload,
|
BuiltPayload = EthBuiltPayload,
|
||||||
> + 'static,
|
> + 'static,
|
||||||
|
|||||||
Reference in New Issue
Block a user