chore(sdk): payload builder AT on NodeComponents and FullNodeComponents (#11529)

Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
Emilia Hane
2024-11-09 10:53:33 +01:00
committed by GitHub
parent 430fe0de18
commit a299f501ce
10 changed files with 57 additions and 55 deletions

2
Cargo.lock generated
View File

@@ -7540,7 +7540,6 @@ dependencies = [
"reth-metrics",
"reth-node-api",
"reth-node-core",
"reth-payload-builder",
"reth-primitives",
"reth-primitives-traits",
"reth-provider",
@@ -7885,7 +7884,6 @@ dependencies = [
"reth-network-api",
"reth-node-core",
"reth-node-types",
"reth-payload-builder",
"reth-payload-primitives",
"reth-primitives",
"reth-provider",

View File

@@ -25,7 +25,6 @@ reth-fs-util.workspace = true
reth-metrics.workspace = true
reth-node-api.workspace = true
reth-node-core.workspace = true
reth-payload-builder.workspace = true
reth-primitives = { workspace = true, features = ["secp256k1"] }
reth-primitives-traits.workspace = true
reth-provider.workspace = true

View File

@@ -1,14 +1,12 @@
use std::fmt::Debug;
use crate::{ExExContextDyn, ExExEvent, ExExNotifications, ExExNotificationsStream};
use reth_exex_types::ExExHead;
use reth_node_api::{FullNodeComponents, NodeTypes, NodeTypesWithEngine};
use reth_node_api::{FullNodeComponents, NodeTypes};
use reth_node_core::node_config::NodeConfig;
use reth_primitives::Head;
use reth_tasks::TaskExecutor;
use std::fmt::Debug;
use tokio::sync::mpsc::UnboundedSender;
use crate::{ExExContextDyn, ExExEvent, ExExNotifications, ExExNotificationsStream};
/// Captures the context that an `ExEx` has access to.
pub struct ExExContext<Node: FullNodeComponents> {
/// The current head of the blockchain at launch.
@@ -97,10 +95,7 @@ where
}
/// Returns the handle to the payload builder service.
pub fn payload_builder(
&self,
) -> &reth_payload_builder::PayloadBuilderHandle<<Node::Types as NodeTypesWithEngine>::Engine>
{
pub fn payload_builder(&self) -> &Node::PayloadBuilder {
self.components.payload_builder()
}

View File

@@ -18,7 +18,6 @@ reth-evm.workspace = true
reth-provider.workspace = true
reth-engine-primitives.workspace = true
reth-transaction-pool.workspace = true
reth-payload-builder.workspace = true
reth-payload-primitives.workspace = true
reth-tasks.workspace = true
reth-network-api.workspace = true

View File

@@ -1,7 +1,6 @@
//! Traits for configuring a node.
use std::{future::Future, marker::PhantomData};
use crate::ConfigureEvm;
use alloy_rpc_types_engine::JwtSecret;
use reth_beacon_consensus::BeaconConsensusEngineHandle;
use reth_consensus::Consensus;
@@ -9,13 +8,12 @@ use reth_evm::execute::BlockExecutorProvider;
use reth_network_api::FullNetwork;
use reth_node_core::node_config::NodeConfig;
use reth_node_types::{NodeTypes, NodeTypesWithDB, NodeTypesWithEngine};
use reth_payload_builder::PayloadBuilderHandle;
use reth_payload_primitives::PayloadBuilder;
use reth_primitives::Header;
use reth_provider::FullProvider;
use reth_tasks::TaskExecutor;
use reth_transaction_pool::TransactionPool;
use crate::ConfigureEvm;
use std::{future::Future, marker::PhantomData};
/// A helper trait that is downstream of the [`NodeTypesWithEngine`] trait and adds stateful
/// components to the node.
@@ -63,6 +61,9 @@ pub trait FullNodeComponents: FullNodeTypes + Clone + 'static {
/// Network API.
type Network: FullNetwork;
/// Builds new blocks.
type PayloadBuilder: PayloadBuilder + Clone;
/// Returns the transaction pool of the node.
fn pool(&self) -> &Self::Pool;
@@ -79,9 +80,7 @@ pub trait FullNodeComponents: FullNodeTypes + Clone + 'static {
fn network(&self) -> &Self::Network;
/// Returns the handle to the payload builder service.
fn payload_builder(
&self,
) -> &PayloadBuilderHandle<<Self::Types as NodeTypesWithEngine>::Engine>;
fn payload_builder(&self) -> &Self::PayloadBuilder;
/// Returns the provider of the node.
fn provider(&self) -> &Self::Provider;

View File

@@ -5,16 +5,6 @@
//! The node builder process is essentially a state machine that transitions through various states
//! before the node can be launched.
use std::{fmt, future::Future};
use reth_exex::ExExContext;
use reth_node_api::{
FullNodeComponents, FullNodeTypes, NodeAddOns, NodeTypes, NodeTypesWithDB, NodeTypesWithEngine,
};
use reth_node_core::node_config::NodeConfig;
use reth_payload_builder::PayloadBuilderHandle;
use reth_tasks::TaskExecutor;
use crate::{
components::{NodeComponents, NodeComponentsBuilder},
hooks::NodeHooks,
@@ -22,6 +12,13 @@ use crate::{
rpc::{RethRpcAddOns, RethRpcServerHandles, RpcContext},
AddOns, FullNode,
};
use reth_exex::ExExContext;
use reth_node_api::{
FullNodeComponents, FullNodeTypes, NodeAddOns, NodeTypes, NodeTypesWithDB, PayloadBuilder,
};
use reth_node_core::node_config::NodeConfig;
use reth_tasks::TaskExecutor;
use std::{fmt, future::Future};
/// A node builder that also has the configured types.
pub struct NodeBuilderWithTypes<T: FullNodeTypes> {
@@ -91,12 +88,16 @@ impl<T: FullNodeTypes, C: NodeComponents<T>> FullNodeTypes for NodeAdapter<T, C>
type Provider = T::Provider;
}
impl<T: FullNodeTypes, C: NodeComponents<T>> FullNodeComponents for NodeAdapter<T, C> {
impl<T: FullNodeTypes, C: NodeComponents<T>> FullNodeComponents for NodeAdapter<T, C>
where
C::PayloadBuilder: PayloadBuilder,
{
type Pool = C::Pool;
type Evm = C::Evm;
type Executor = C::Executor;
type Consensus = C::Consensus;
type Network = C::Network;
type PayloadBuilder = C::PayloadBuilder;
fn pool(&self) -> &Self::Pool {
self.components.pool()
@@ -118,7 +119,7 @@ impl<T: FullNodeTypes, C: NodeComponents<T>> FullNodeComponents for NodeAdapter<
self.components.network()
}
fn payload_builder(&self) -> &PayloadBuilderHandle<<T::Types as NodeTypesWithEngine>::Engine> {
fn payload_builder(&self) -> &Self::PayloadBuilder {
self.components.payload_builder()
}

View File

@@ -1,12 +1,5 @@
//! A generic [`NodeComponentsBuilder`]
use std::{future::Future, marker::PhantomData};
use reth_consensus::Consensus;
use reth_evm::execute::BlockExecutorProvider;
use reth_primitives::Header;
use reth_transaction_pool::TransactionPool;
use crate::{
components::{
Components, ConsensusBuilder, ExecutorBuilder, NetworkBuilder, NodeComponents,
@@ -14,6 +7,13 @@ use crate::{
},
BuilderContext, ConfigureEvm, FullNodeTypes,
};
use reth_consensus::Consensus;
use reth_evm::execute::BlockExecutorProvider;
use reth_node_api::NodeTypesWithEngine;
use reth_payload_builder::PayloadBuilderHandle;
use reth_primitives::Header;
use reth_transaction_pool::TransactionPool;
use std::{future::Future, marker::PhantomData};
/// A generic, general purpose and customizable [`NodeComponentsBuilder`] implementation.
///
@@ -358,7 +358,10 @@ impl Default for ComponentsBuilder<(), (), (), (), (), ()> {
/// A type that's responsible for building the components of the node.
pub trait NodeComponentsBuilder<Node: FullNodeTypes>: Send {
/// The components for the node with the given types
type Components: NodeComponents<Node>;
type Components: NodeComponents<
Node,
PayloadBuilder = PayloadBuilderHandle<<Node::Types as NodeTypesWithEngine>::Engine>,
>;
/// Consumes the type and returns the created components.
fn build_components(

View File

@@ -21,6 +21,7 @@ pub use network::*;
pub use payload::*;
pub use pool::*;
use crate::{ConfigureEvm, FullNodeTypes};
use reth_consensus::Consensus;
use reth_evm::execute::BlockExecutorProvider;
use reth_network::NetworkHandle;
@@ -30,8 +31,6 @@ use reth_payload_builder::PayloadBuilderHandle;
use reth_primitives::Header;
use reth_transaction_pool::TransactionPool;
use crate::{ConfigureEvm, FullNodeTypes};
/// An abstraction over the components of a node, consisting of:
/// - evm and executor
/// - transaction pool
@@ -53,6 +52,9 @@ pub trait NodeComponents<T: FullNodeTypes>: Clone + Unpin + Send + Sync + 'stati
/// Network API.
type Network: FullNetwork;
/// Builds new blocks.
type PayloadBuilder: Clone;
/// Returns the transaction pool of the node.
fn pool(&self) -> &Self::Pool;
@@ -69,7 +71,7 @@ pub trait NodeComponents<T: FullNodeTypes>: Clone + Unpin + Send + Sync + 'stati
fn network(&self) -> &Self::Network;
/// Returns the handle to the payload builder service.
fn payload_builder(&self) -> &PayloadBuilderHandle<<T::Types as NodeTypesWithEngine>::Engine>;
fn payload_builder(&self) -> &Self::PayloadBuilder;
}
/// All the components of the node.
@@ -105,6 +107,7 @@ where
type Executor = Executor;
type Consensus = Cons;
type Network = NetworkHandle;
type PayloadBuilder = PayloadBuilderHandle<<Node::Types as NodeTypesWithEngine>::Engine>;
fn pool(&self) -> &Self::Pool {
&self.transaction_pool
@@ -126,9 +129,7 @@ where
&self.network
}
fn payload_builder(
&self,
) -> &PayloadBuilderHandle<<Node::Types as NodeTypesWithEngine>::Engine> {
fn payload_builder(&self) -> &Self::PayloadBuilder {
&self.payload_builder
}
}

View File

@@ -16,7 +16,7 @@ use reth_node_core::{
node_config::NodeConfig,
version::{CARGO_PKG_VERSION, CLIENT_CODE, NAME_CLIENT, VERGEN_GIT_SHA},
};
use reth_payload_builder::PayloadBuilderHandle;
use reth_payload_builder::PayloadStore;
use reth_provider::providers::ProviderNodeTypes;
use reth_rpc::{
eth::{EthApiTypes, FullEthApiServer},
@@ -294,9 +294,7 @@ where
}
/// Returns the handle to the payload builder service
pub fn payload_builder(
&self,
) -> &PayloadBuilderHandle<<Node::Types as NodeTypesWithEngine>::Engine> {
pub fn payload_builder(&self) -> &Node::PayloadBuilder {
self.node.payload_builder()
}
}
@@ -402,7 +400,10 @@ where
impl<N, EthApi, EV> NodeAddOns<N> for RpcAddOns<N, EthApi, EV>
where
N: FullNodeComponents<Types: ProviderNodeTypes>,
N: FullNodeComponents<
Types: ProviderNodeTypes,
PayloadBuilder: Into<PayloadStore<<N::Types as NodeTypesWithEngine>::Engine>>,
>,
EthApi: EthApiTypes + FullEthApiServer + AddDevSigners + Unpin + 'static,
EV: EngineValidatorBuilder<N>,
{

View File

@@ -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};
use reth_payload_builder::{PayloadBuilderHandle, PayloadBuilderService, PayloadStore};
use reth_primitives::{Block, Header, Receipt, TransactionSigned};
use reth_provider::CanonStateSubscriptions;
use reth_tracing::tracing::{debug, info};
@@ -149,7 +149,10 @@ impl<N: FullNodeComponents> OpAddOns<N> {
impl<N> NodeAddOns<N> for OpAddOns<N>
where
N: FullNodeComponents<Types: NodeTypes<ChainSpec = OpChainSpec>>,
N: FullNodeComponents<
Types: NodeTypes<ChainSpec = OpChainSpec>,
PayloadBuilder: Into<PayloadStore<<N::Types as NodeTypesWithEngine>::Engine>>,
>,
OpEngineValidator: EngineValidator<<N::Types as NodeTypesWithEngine>::Engine>,
{
type Handle = RpcHandle<N, OpEthApi<N>>;
@@ -164,7 +167,10 @@ where
impl<N> RethRpcAddOns<N> for OpAddOns<N>
where
N: FullNodeComponents<Types: NodeTypes<ChainSpec = OpChainSpec>>,
N: FullNodeComponents<
Types: NodeTypes<ChainSpec = OpChainSpec>,
PayloadBuilder: Into<PayloadStore<<N::Types as NodeTypesWithEngine>::Engine>>,
>,
OpEngineValidator: EngineValidator<<N::Types as NodeTypesWithEngine>::Engine>,
{
type EthApi = OpEthApi<N>;