Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion crates/exex/exex/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 4 additions & 9 deletions crates/exex/exex/src/context.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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()
}

Expand Down
1 change: 0 additions & 1 deletion crates/node/api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 7 additions & 8 deletions crates/node/api/src/node.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
//! 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;
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.
Expand Down Expand Up @@ -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;

Expand All @@ -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;
Expand Down
25 changes: 13 additions & 12 deletions crates/node/builder/src/builder/states.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,20 @@
//! 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,
launch::LaunchNode,
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> {
Expand Down Expand Up @@ -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()
Expand All @@ -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()
}

Expand Down
19 changes: 11 additions & 8 deletions crates/node/builder/src/components/builder.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
//! 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,
PayloadServiceBuilder, PoolBuilder,
},
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.
///
Expand Down Expand Up @@ -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>,
>;
mattsse marked this conversation as resolved.
Show resolved Hide resolved

/// Consumes the type and returns the created components.
fn build_components(
Expand Down
13 changes: 7 additions & 6 deletions crates/node/builder/src/components/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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;

Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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
}
}
Expand Down
11 changes: 6 additions & 5 deletions crates/node/builder/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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()
}
}
Expand Down Expand Up @@ -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>,
{
Expand Down
12 changes: 9 additions & 3 deletions crates/optimism/node/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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>>;
Expand All @@ -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>;
Expand Down
Loading