mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-01-26 07:38:59 -05:00
make PayloadStore operate on PayloadBuilder (#12460)
Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
@@ -17,6 +17,7 @@ use reth_node_core::{
|
||||
version::{CARGO_PKG_VERSION, CLIENT_CODE, NAME_CLIENT, VERGEN_GIT_SHA},
|
||||
};
|
||||
use reth_payload_builder::PayloadStore;
|
||||
use reth_payload_primitives::PayloadBuilder;
|
||||
use reth_provider::providers::ProviderNodeTypes;
|
||||
use reth_rpc::{
|
||||
eth::{EthApiTypes, FullEthApiServer},
|
||||
@@ -402,7 +403,7 @@ impl<N, EthApi, EV> NodeAddOns<N> for RpcAddOns<N, EthApi, EV>
|
||||
where
|
||||
N: FullNodeComponents<
|
||||
Types: ProviderNodeTypes,
|
||||
PayloadBuilder: Into<PayloadStore<<N::Types as NodeTypesWithEngine>::Engine>>,
|
||||
PayloadBuilder: PayloadBuilder<PayloadType = <N::Types as NodeTypesWithEngine>::Engine>,
|
||||
>,
|
||||
EthApi: EthApiTypes + FullEthApiServer + AddDevSigners + Unpin + 'static,
|
||||
EV: EngineValidatorBuilder<N>,
|
||||
@@ -426,7 +427,7 @@ where
|
||||
node.provider().clone(),
|
||||
config.chain.clone(),
|
||||
beacon_engine_handle,
|
||||
node.payload_builder().clone().into(),
|
||||
PayloadStore::new(node.payload_builder().clone()),
|
||||
node.pool().clone(),
|
||||
Box::new(node.task_executor().clone()),
|
||||
client,
|
||||
|
||||
@@ -7,7 +7,7 @@ use reth_chainspec::{EthChainSpec, Hardforks};
|
||||
use reth_evm::{execute::BasicBlockExecutorProvider, ConfigureEvm};
|
||||
use reth_network::{NetworkConfig, NetworkHandle, NetworkManager, PeersInfo};
|
||||
use reth_node_api::{
|
||||
AddOnsContext, EngineValidator, FullNodeComponents, NodeAddOns, NodePrimitives,
|
||||
AddOnsContext, EngineValidator, FullNodeComponents, NodeAddOns, NodePrimitives, PayloadBuilder,
|
||||
};
|
||||
use reth_node_builder::{
|
||||
components::{
|
||||
@@ -23,7 +23,7 @@ use reth_optimism_consensus::OpBeaconConsensus;
|
||||
use reth_optimism_evm::{OpEvmConfig, OpExecutionStrategyFactory};
|
||||
use reth_optimism_payload_builder::builder::OpPayloadTransactions;
|
||||
use reth_optimism_rpc::OpEthApi;
|
||||
use reth_payload_builder::{PayloadBuilderHandle, PayloadBuilderService, PayloadStore};
|
||||
use reth_payload_builder::{PayloadBuilderHandle, PayloadBuilderService};
|
||||
use reth_primitives::{Block, Header, Receipt, TransactionSigned, TxType};
|
||||
use reth_provider::CanonStateSubscriptions;
|
||||
use reth_tracing::tracing::{debug, info};
|
||||
@@ -152,7 +152,7 @@ impl<N> NodeAddOns<N> for OpAddOns<N>
|
||||
where
|
||||
N: FullNodeComponents<
|
||||
Types: NodeTypes<ChainSpec = OpChainSpec>,
|
||||
PayloadBuilder: Into<PayloadStore<<N::Types as NodeTypesWithEngine>::Engine>>,
|
||||
PayloadBuilder: PayloadBuilder<PayloadType = <N::Types as NodeTypesWithEngine>::Engine>,
|
||||
>,
|
||||
OpEngineValidator: EngineValidator<<N::Types as NodeTypesWithEngine>::Engine>,
|
||||
{
|
||||
@@ -170,7 +170,7 @@ impl<N> RethRpcAddOns<N> for OpAddOns<N>
|
||||
where
|
||||
N: FullNodeComponents<
|
||||
Types: NodeTypes<ChainSpec = OpChainSpec>,
|
||||
PayloadBuilder: Into<PayloadStore<<N::Types as NodeTypesWithEngine>::Engine>>,
|
||||
PayloadBuilder: PayloadBuilder<PayloadType = <N::Types as NodeTypesWithEngine>::Engine>,
|
||||
>,
|
||||
OpEngineValidator: EngineValidator<<N::Types as NodeTypesWithEngine>::Engine>,
|
||||
{
|
||||
|
||||
@@ -12,12 +12,13 @@ use futures_util::{future::FutureExt, Stream, StreamExt};
|
||||
use reth_chain_state::CanonStateNotification;
|
||||
use reth_payload_primitives::{
|
||||
BuiltPayload, Events, PayloadBuilder, PayloadBuilderAttributes, PayloadBuilderError,
|
||||
PayloadEvents, PayloadKind, PayloadTypes,
|
||||
PayloadEvents, PayloadKind, PayloadStoreExt, PayloadTypes,
|
||||
};
|
||||
use std::{
|
||||
fmt,
|
||||
future::Future,
|
||||
pin::Pin,
|
||||
sync::Arc,
|
||||
task::{Context, Poll},
|
||||
};
|
||||
use tokio::sync::{
|
||||
@@ -30,13 +31,14 @@ use tracing::{debug, info, trace, warn};
|
||||
type PayloadFuture<P> = Pin<Box<dyn Future<Output = Result<P, PayloadBuilderError>> + Send + Sync>>;
|
||||
|
||||
/// A communication channel to the [`PayloadBuilderService`] that can retrieve payloads.
|
||||
///
|
||||
/// This type is intended to be used to retrieve payloads from the service (e.g. from the engine
|
||||
/// API).
|
||||
#[derive(Debug)]
|
||||
pub struct PayloadStore<T: PayloadTypes> {
|
||||
inner: PayloadBuilderHandle<T>,
|
||||
inner: Arc<dyn PayloadStoreExt<T>>,
|
||||
}
|
||||
|
||||
// === impl PayloadStore ===
|
||||
|
||||
impl<T> PayloadStore<T>
|
||||
where
|
||||
T: PayloadTypes,
|
||||
@@ -82,12 +84,16 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Clone for PayloadStore<T>
|
||||
impl<T> PayloadStore<T>
|
||||
where
|
||||
T: PayloadTypes,
|
||||
{
|
||||
fn clone(&self) -> Self {
|
||||
Self { inner: self.inner.clone() }
|
||||
/// Create a new instance
|
||||
pub fn new<P>(inner: P) -> Self
|
||||
where
|
||||
P: PayloadStoreExt<T> + 'static,
|
||||
{
|
||||
Self { inner: Arc::new(inner) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,7 +102,7 @@ where
|
||||
T: PayloadTypes,
|
||||
{
|
||||
fn from(inner: PayloadBuilderHandle<T>) -> Self {
|
||||
Self { inner }
|
||||
Self::new(inner)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ pub use crate::events::{Events, PayloadEvents};
|
||||
mod traits;
|
||||
pub use traits::{
|
||||
BuiltPayload, PayloadAttributes, PayloadAttributesBuilder, PayloadBuilder,
|
||||
PayloadBuilderAttributes,
|
||||
PayloadBuilderAttributes, PayloadStoreExt,
|
||||
};
|
||||
|
||||
mod payload;
|
||||
|
||||
@@ -7,11 +7,12 @@ use alloy_primitives::{Address, B256, U256};
|
||||
use alloy_rpc_types_engine::{PayloadAttributes as EthPayloadAttributes, PayloadId};
|
||||
use reth_chain_state::ExecutedBlock;
|
||||
use reth_primitives::SealedBlock;
|
||||
use std::fmt::Debug;
|
||||
use tokio::sync::oneshot;
|
||||
|
||||
/// A type that can request, subscribe to and resolve payloads.
|
||||
#[async_trait::async_trait]
|
||||
pub trait PayloadBuilder: Send + Sync + Unpin {
|
||||
pub trait PayloadBuilder: Debug + Send + Sync + Unpin {
|
||||
/// The Payload type for the builder.
|
||||
type PayloadType: PayloadTypes;
|
||||
/// The error type returned by the builder.
|
||||
@@ -58,6 +59,63 @@ pub trait PayloadBuilder: Send + Sync + Unpin {
|
||||
) -> Option<Result<<Self::PayloadType as PayloadTypes>::PayloadBuilderAttributes, Self::Error>>;
|
||||
}
|
||||
|
||||
/// A helper trait for internal usage to retrieve and resolve payloads.
|
||||
#[async_trait::async_trait]
|
||||
pub trait PayloadStoreExt<T: PayloadTypes>: Debug + Send + Sync + Unpin {
|
||||
/// Resolves the payload job and returns the best payload that has been built so far.
|
||||
async fn resolve_kind(
|
||||
&self,
|
||||
id: PayloadId,
|
||||
kind: PayloadKind,
|
||||
) -> Option<Result<T::BuiltPayload, PayloadBuilderError>>;
|
||||
|
||||
/// Resolves the payload job as fast and possible and returns the best payload that has been
|
||||
/// built so far.
|
||||
async fn resolve(&self, id: PayloadId) -> Option<Result<T::BuiltPayload, PayloadBuilderError>> {
|
||||
self.resolve_kind(id, PayloadKind::Earliest).await
|
||||
}
|
||||
|
||||
/// Returns the best payload for the given identifier.
|
||||
async fn best_payload(
|
||||
&self,
|
||||
id: PayloadId,
|
||||
) -> Option<Result<T::BuiltPayload, PayloadBuilderError>>;
|
||||
|
||||
/// Returns the payload attributes associated with the given identifier.
|
||||
async fn payload_attributes(
|
||||
&self,
|
||||
id: PayloadId,
|
||||
) -> Option<Result<T::PayloadBuilderAttributes, PayloadBuilderError>>;
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl<T: PayloadTypes, P> PayloadStoreExt<T> for P
|
||||
where
|
||||
P: PayloadBuilder<PayloadType = T>,
|
||||
{
|
||||
async fn resolve_kind(
|
||||
&self,
|
||||
id: PayloadId,
|
||||
kind: PayloadKind,
|
||||
) -> Option<Result<T::BuiltPayload, PayloadBuilderError>> {
|
||||
Some(PayloadBuilder::resolve_kind(self, id, kind).await?.map_err(Into::into))
|
||||
}
|
||||
|
||||
async fn best_payload(
|
||||
&self,
|
||||
id: PayloadId,
|
||||
) -> Option<Result<T::BuiltPayload, PayloadBuilderError>> {
|
||||
Some(PayloadBuilder::best_payload(self, id).await?.map_err(Into::into))
|
||||
}
|
||||
|
||||
async fn payload_attributes(
|
||||
&self,
|
||||
id: PayloadId,
|
||||
) -> Option<Result<T::PayloadBuilderAttributes, PayloadBuilderError>> {
|
||||
Some(PayloadBuilder::payload_attributes(self, id).await?.map_err(Into::into))
|
||||
}
|
||||
}
|
||||
|
||||
/// Represents a built payload type that contains a built [`SealedBlock`] and can be converted into
|
||||
/// engine API execution payloads.
|
||||
pub trait BuiltPayload: Send + Sync + std::fmt::Debug {
|
||||
|
||||
Reference in New Issue
Block a user