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 = [
|
||||
"futures-util",
|
||||
"metrics",
|
||||
"reth-engine-primitives",
|
||||
"reth-errors",
|
||||
"reth-ethereum-engine-primitives",
|
||||
"reth-metrics",
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
@ -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<Engine: EngineTypes> {
|
||||
pub enum Events<Engine: PayloadTypes> {
|
||||
/// The payload attributes as
|
||||
/// they are received from the CL through the engine api.
|
||||
Attributes(Engine::PayloadBuilderAttributes),
|
||||
@ -19,11 +19,11 @@ pub enum Events<Engine: EngineTypes> {
|
||||
|
||||
/// Represents a receiver for various payload events.
|
||||
#[derive(Debug)]
|
||||
pub struct PayloadEvents<Engine: EngineTypes> {
|
||||
pub struct PayloadEvents<Engine: PayloadTypes> {
|
||||
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.
|
||||
pub fn into_stream(self) -> BroadcastStream<Events<Engine>> {
|
||||
BroadcastStream::new(self.receiver)
|
||||
|
||||
@ -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<Engine: EngineTypes> {
|
||||
pub struct NoopPayloadBuilderService<Engine: PayloadTypes> {
|
||||
/// Receiver half of the command channel.
|
||||
command_rx: UnboundedReceiverStream<PayloadServiceCommand<Engine>>,
|
||||
}
|
||||
|
||||
impl<Engine> NoopPayloadBuilderService<Engine>
|
||||
where
|
||||
Engine: EngineTypes + 'static,
|
||||
Engine: PayloadTypes + 'static,
|
||||
{
|
||||
/// Creates a new [`NoopPayloadBuilderService`].
|
||||
pub fn new() -> (Self, PayloadBuilderHandle<Engine>) {
|
||||
@ -35,7 +34,7 @@ where
|
||||
|
||||
impl<Engine> Future for NoopPayloadBuilderService<Engine>
|
||||
where
|
||||
Engine: EngineTypes,
|
||||
Engine: PayloadTypes,
|
||||
{
|
||||
type Output = ();
|
||||
|
||||
|
||||
@ -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<P> = Pin<Box<dyn Future<Output = Result<P, PayloadBuilderErro
|
||||
|
||||
/// A communication channel to the [`PayloadBuilderService`] that can retrieve payloads.
|
||||
#[derive(Debug)]
|
||||
pub struct PayloadStore<Engine: EngineTypes> {
|
||||
pub struct PayloadStore<Engine: PayloadTypes> {
|
||||
inner: PayloadBuilderHandle<Engine>,
|
||||
}
|
||||
|
||||
@ -40,7 +39,7 @@ pub struct PayloadStore<Engine: EngineTypes> {
|
||||
|
||||
impl<Engine> PayloadStore<Engine>
|
||||
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<Engine> Clone for PayloadStore<Engine>
|
||||
where
|
||||
Engine: EngineTypes,
|
||||
Engine: PayloadTypes,
|
||||
{
|
||||
fn clone(&self) -> Self {
|
||||
Self { inner: self.inner.clone() }
|
||||
@ -85,7 +84,7 @@ where
|
||||
|
||||
impl<Engine> From<PayloadBuilderHandle<Engine>> for PayloadStore<Engine>
|
||||
where
|
||||
Engine: EngineTypes,
|
||||
Engine: PayloadTypes,
|
||||
{
|
||||
fn from(inner: PayloadBuilderHandle<Engine>) -> 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<Engine: EngineTypes> {
|
||||
pub struct PayloadBuilderHandle<Engine: PayloadTypes> {
|
||||
/// Sender half of the message channel to the [`PayloadBuilderService`].
|
||||
to_service: mpsc::UnboundedSender<PayloadServiceCommand<Engine>>,
|
||||
}
|
||||
@ -105,7 +104,7 @@ pub struct PayloadBuilderHandle<Engine: EngineTypes> {
|
||||
|
||||
impl<Engine> PayloadBuilderHandle<Engine>
|
||||
where
|
||||
Engine: EngineTypes + 'static,
|
||||
Engine: PayloadTypes + 'static,
|
||||
{
|
||||
/// Creates a new payload builder handle for the given channel.
|
||||
///
|
||||
@ -191,7 +190,7 @@ where
|
||||
|
||||
impl<Engine> Clone for PayloadBuilderHandle<Engine>
|
||||
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<Gen, St, Engine>
|
||||
where
|
||||
Engine: EngineTypes,
|
||||
Engine: PayloadTypes,
|
||||
Gen: PayloadJobGenerator,
|
||||
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>
|
||||
where
|
||||
Engine: EngineTypes + 'static,
|
||||
Engine: PayloadTypes + 'static,
|
||||
Gen: PayloadJobGenerator,
|
||||
Gen::Job: PayloadJob<PayloadAttributes = Engine::PayloadBuilderAttributes>,
|
||||
<Gen::Job as PayloadJob>::BuiltPayload: Into<Engine::BuiltPayload>,
|
||||
@ -327,7 +326,7 @@ where
|
||||
|
||||
impl<Gen, St, Engine> PayloadBuilderService<Gen, St, Engine>
|
||||
where
|
||||
Engine: EngineTypes,
|
||||
Engine: PayloadTypes,
|
||||
Gen: PayloadJobGenerator,
|
||||
Gen::Job: PayloadJob<PayloadAttributes = Engine::PayloadBuilderAttributes>,
|
||||
<Gen::Job as PayloadJob>::BuiltPayload: Into<Engine::BuiltPayload>,
|
||||
@ -353,7 +352,7 @@ where
|
||||
|
||||
impl<Gen, St, Engine> Future for PayloadBuilderService<Gen, St, Engine>
|
||||
where
|
||||
Engine: EngineTypes + 'static,
|
||||
Engine: PayloadTypes + 'static,
|
||||
Gen: PayloadJobGenerator + Unpin + 'static,
|
||||
<Gen as PayloadJobGenerator>::Job: Unpin + 'static,
|
||||
St: Stream<Item = CanonStateNotification> + Send + Unpin + 'static,
|
||||
@ -453,7 +452,7 @@ where
|
||||
}
|
||||
|
||||
/// Message type for the [`PayloadBuilderService`].
|
||||
pub enum PayloadServiceCommand<Engine: EngineTypes> {
|
||||
pub enum PayloadServiceCommand<Engine: PayloadTypes> {
|
||||
/// Start building a new payload.
|
||||
BuildNewPayload(
|
||||
Engine::PayloadBuilderAttributes,
|
||||
@ -477,7 +476,7 @@ pub enum PayloadServiceCommand<Engine: EngineTypes> {
|
||||
|
||||
impl<Engine> fmt::Debug for PayloadServiceCommand<Engine>
|
||||
where
|
||||
Engine: EngineTypes,
|
||||
Engine: PayloadTypes,
|
||||
{
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
|
||||
@ -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<Engine>() -> (
|
||||
PayloadBuilderHandle<Engine>,
|
||||
)
|
||||
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<Engine>() -> PayloadBuilderHandle<Engine>
|
||||
where
|
||||
Engine: EngineTypes<
|
||||
Engine: PayloadTypes<
|
||||
PayloadBuilderAttributes = EthPayloadBuilderAttributes,
|
||||
BuiltPayload = EthBuiltPayload,
|
||||
> + 'static,
|
||||
|
||||
Reference in New Issue
Block a user