Skip to content

Commit

Permalink
Refactor node builder wrt stable 1.79.0
Browse files Browse the repository at this point in the history
  • Loading branch information
emhane committed Aug 16, 2024
1 parent 6ace2fb commit c7b9ec0
Show file tree
Hide file tree
Showing 12 changed files with 90 additions and 59 deletions.
12 changes: 9 additions & 3 deletions crates/e2e-test-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
use std::sync::Arc;

use alloy_network::Network;
use node::NodeTestContext;
use reth::{
args::{DiscoveryArgs, NetworkArgs, RpcServerArgs},
Expand Down Expand Up @@ -51,9 +52,14 @@ pub async fn setup<N>(
) -> eyre::Result<(Vec<NodeHelperType<N, N::AddOns>>, TaskManager, Wallet)>
where
N: Default + Node<TmpNodeAdapter<N>>,
<<N::ComponentsBuilder as NodeComponentsBuilder<TmpNodeAdapter<N>>>::Components as NodeComponents<TmpNodeAdapter<N>>>::Network: PeersHandleProvider,
<N::AddOns as NodeAddOns<Adapter<N>>>::EthApi:
FullEthApiServer + AddDevSigners + EthApiBuilderProvider<Adapter<N>>,
N::ComponentsBuilder: NodeComponentsBuilder<
Adapter<N>,
Components: NodeComponents<TmpNodeAdapter<N>, Network: PeersHandleProvider>,
>,
N::AddOns: NodeAddOns<
Adapter<N>,
EthApi: FullEthApiServer + AddDevSigners + EthApiBuilderProvider<Adapter<N>>,
>,
{
let tasks = TaskManager::current();
let exec = tasks.executor();
Expand Down
30 changes: 17 additions & 13 deletions crates/node/builder/src/builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,17 +317,20 @@ where
>
where
N: Node<RethFullAdapter<DB, N>>,
<N::AddOns as NodeAddOns<
N::AddOns: NodeAddOns<
NodeAdapter<
RethFullAdapter<DB, N>,
<N::ComponentsBuilder as NodeComponentsBuilder<RethFullAdapter<DB, N>>>::Components,
>,
>>::EthApi: EthApiBuilderProvider<
NodeAdapter<
RethFullAdapter<DB, N>,
<N::ComponentsBuilder as NodeComponentsBuilder<RethFullAdapter<DB, N>>>::Components,
>,
> + FullEthApiServer + AddDevSigners,
EthApi: EthApiBuilderProvider<
NodeAdapter<
RethFullAdapter<DB, N>,
<N::ComponentsBuilder as NodeComponentsBuilder<RethFullAdapter<DB, N>>>::Components,
>
>
+ FullEthApiServer
+ AddDevSigners
>,
{
self.node(node).launch().await
}
Expand Down Expand Up @@ -371,8 +374,7 @@ impl<T, CB, AO> WithLaunchContext<NodeBuilderWithComponents<T, CB, AO>>
where
T: FullNodeTypes,
CB: NodeComponentsBuilder<T>,
AO: NodeAddOns<NodeAdapter<T, CB::Components>>,
AO::EthApi: FullEthApiServer + AddDevSigners,
AO: NodeAddOns<NodeAdapter<T, CB::Components>, EthApi: FullEthApiServer + AddDevSigners>,
{
/// Returns a reference to the node builder's config.
pub const fn config(&self) -> &NodeConfig {
Expand Down Expand Up @@ -469,10 +471,12 @@ where
DB: Database + DatabaseMetrics + DatabaseMetadata + Clone + Unpin + 'static,
T: NodeTypes,
CB: NodeComponentsBuilder<RethFullAdapter<DB, T>>,
AO: NodeAddOns<NodeAdapter<RethFullAdapter<DB, T>, CB::Components>>,
AO::EthApi: EthApiBuilderProvider<NodeAdapter<RethFullAdapter<DB, T>, CB::Components>>
+ FullEthApiServer
+ AddDevSigners,
AO: NodeAddOns<
NodeAdapter<RethFullAdapter<DB, T>, CB::Components>,
EthApi: EthApiBuilderProvider<NodeAdapter<RethFullAdapter<DB, T>, CB::Components>>
+ FullEthApiServer
+ AddDevSigners,
>,
{
/// Launches the node with the [`DefaultNodeLauncher`] that sets up engine API consensus and rpc
pub async fn launch(
Expand Down
9 changes: 6 additions & 3 deletions crates/node/builder/src/builder/states.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,9 +273,12 @@ impl<T, CB, AO> NodeBuilderWithComponents<T, CB, AO>
where
T: FullNodeTypes,
CB: NodeComponentsBuilder<T>,
AO: NodeAddOns<NodeAdapter<T, CB::Components>>,
AO::EthApi:
EthApiBuilderProvider<NodeAdapter<T, CB::Components>> + FullEthApiServer + AddDevSigners,
AO: NodeAddOns<
NodeAdapter<T, CB::Components>,
EthApi: EthApiBuilderProvider<NodeAdapter<T, CB::Components>>
+ FullEthApiServer
+ AddDevSigners,
>,
{
/// Launches the node with the given launcher.
pub async fn launch_with<L>(self, launcher: L) -> eyre::Result<L::Node>
Expand Down
6 changes: 4 additions & 2 deletions crates/node/builder/src/components/network.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
//! Network component for the node builder.
use crate::{BuilderContext, FullNodeTypes};
use std::future::Future;

use reth_network::NetworkHandle;
use reth_transaction_pool::TransactionPool;
use std::future::Future;

use crate::{BuilderContext, FullNodeTypes};

/// A type that knows how to build the network implementation.
pub trait NetworkBuilder<Node: FullNodeTypes, Pool: TransactionPool>: Send {
Expand Down
6 changes: 4 additions & 2 deletions crates/node/builder/src/components/payload.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
//! Payload service component for the node builder.
use crate::{BuilderContext, FullNodeTypes};
use std::future::Future;

use reth_payload_builder::PayloadBuilderHandle;
use reth_transaction_pool::TransactionPool;
use std::future::Future;

use crate::{BuilderContext, FullNodeTypes};

/// A type that knows how to spawn the payload service.
pub trait PayloadServiceBuilder<Node: FullNodeTypes, Pool: TransactionPool>: Send {
Expand Down
7 changes: 5 additions & 2 deletions crates/node/builder/src/components/pool.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
//! Pool component for the node builder.
use crate::{BuilderContext, FullNodeTypes};
use reth_transaction_pool::TransactionPool;
use std::future::Future;

use reth_transaction_pool::TransactionPool;

use crate::{BuilderContext, FullNodeTypes};

/// A type that knows how to build the transaction pool.
pub trait PoolBuilder<Node: FullNodeTypes>: Send {
/// The transaction pool to build.
Expand Down
4 changes: 3 additions & 1 deletion crates/node/builder/src/exex.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
//! Types for launching execution extensions (ExEx).
use std::future::Future;

use futures::{future::BoxFuture, FutureExt};
use reth_exex::ExExContext;
use reth_node_api::FullNodeComponents;
use std::future::Future;

/// A trait for launching an `ExEx`.
pub trait LaunchExEx<Node: FullNodeComponents>: Send {
Expand Down
26 changes: 12 additions & 14 deletions crates/node/builder/src/launch/common.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
//! Helper types that can be used by launchers.
use crate::{
components::{NodeComponents, NodeComponentsBuilder},
hooks::OnComponentInitializedHook,
BuilderContext, NodeAdapter,
};
use std::{marker::PhantomData, sync::Arc, thread::available_parallelism};

use eyre::Context;
use rayon::ThreadPoolBuilder;
use reth_auto_seal_consensus::MiningMode;
Expand Down Expand Up @@ -47,12 +44,17 @@ use reth_stages::{sets::DefaultStages, MetricEvent, Pipeline, PipelineTarget, St
use reth_static_file::StaticFileProducer;
use reth_tasks::TaskExecutor;
use reth_tracing::tracing::{debug, error, info, warn};
use std::{marker::PhantomData, sync::Arc, thread::available_parallelism};
use tokio::sync::{
mpsc::{unbounded_channel, Receiver, UnboundedSender},
oneshot, watch,
};

use crate::{
components::{NodeComponents, NodeComponentsBuilder},
hooks::OnComponentInitializedHook,
BuilderContext, NodeAdapter,
};

/// Allows to set a tree viewer for a configured blockchain provider.
// TODO: remove this helper trait once the engine revamp is done, the new
// blockchain provider won't require a TreeViewer.
Expand Down Expand Up @@ -596,8 +598,7 @@ where
impl<DB, T> LaunchContextWith<Attached<WithConfigs, WithMeteredProviders<DB, T>>>
where
DB: Database + DatabaseMetrics + Send + Sync + Clone + 'static,
T: FullNodeTypes,
T::Provider: FullProvider<DB> + WithTree,
T: FullNodeTypes<Provider: FullProvider<DB> + WithTree>,
{
/// Returns access to the underlying database.
pub fn database(&self) -> &DB {
Expand Down Expand Up @@ -716,8 +717,7 @@ where
impl<DB, T, CB> LaunchContextWith<Attached<WithConfigs, WithComponents<DB, T, CB>>>
where
DB: Database + DatabaseMetrics + Send + Sync + Clone + 'static,
T: FullNodeTypes,
T::Provider: FullProvider<DB> + WithTree,
T: FullNodeTypes<Provider: FullProvider<DB> + WithTree>,
CB: NodeComponentsBuilder<T>,
{
/// Returns the configured `ProviderFactory`.
Expand Down Expand Up @@ -915,8 +915,7 @@ pub struct WithMeteredProvider<DB> {
pub struct WithMeteredProviders<DB, T>
where
DB: Database,
T: FullNodeTypes,
T::Provider: FullProvider<DB>,
T: FullNodeTypes<Provider: FullProvider<DB>>,
{
db_provider_container: WithMeteredProvider<DB>,
blockchain_db: T::Provider,
Expand All @@ -932,8 +931,7 @@ where
pub struct WithComponents<DB, T, CB>
where
DB: Database,
T: FullNodeTypes,
T::Provider: FullProvider<DB>,
T: FullNodeTypes<Provider: FullProvider<DB>>,
CB: NodeComponentsBuilder<T>,
{
db_provider_container: WithMeteredProvider<DB>,
Expand Down
28 changes: 16 additions & 12 deletions crates/node/builder/src/launch/engine.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
//! Engine node related functionality.
use crate::{
components::NodeComponents,
hooks::NodeHooks,
launch::{LaunchContext, LaunchNode},
rpc::{launch_rpc_servers, EthApiBuilderProvider},
setup::build_networked_pipeline,
AddOns, ExExLauncher, FullNode, NodeAdapter, NodeBuilderWithComponents, NodeComponentsBuilder,
NodeHandle, NodeTypesAdapter,
};
use futures::{future::Either, stream, stream_select, StreamExt};
use reth_beacon_consensus::{
hooks::{EngineHooks, StaticFileHook},
Expand Down Expand Up @@ -42,6 +33,16 @@ use reth_tracing::tracing::{debug, error, info};
use tokio::sync::{mpsc::unbounded_channel, oneshot};
use tokio_stream::wrappers::UnboundedReceiverStream;

use crate::{
components::NodeComponents,
hooks::NodeHooks,
launch::{LaunchContext, LaunchNode},
rpc::{launch_rpc_servers, EthApiBuilderProvider},
setup::build_networked_pipeline,
AddOns, ExExLauncher, FullNode, NodeAdapter, NodeBuilderWithComponents, NodeComponentsBuilder,
NodeHandle, NodeTypesAdapter,
};

/// The engine node launcher.
#[derive(Debug)]
pub struct EngineNodeLauncher {
Expand All @@ -60,9 +61,12 @@ impl<T, CB, AO> LaunchNode<NodeBuilderWithComponents<T, CB, AO>> for EngineNodeL
where
T: FullNodeTypes<Provider = BlockchainProvider2<<T as FullNodeTypes>::DB>>,
CB: NodeComponentsBuilder<T>,
AO: NodeAddOns<NodeAdapter<T, CB::Components>>,
AO::EthApi:
EthApiBuilderProvider<NodeAdapter<T, CB::Components>> + FullEthApiServer + AddDevSigners,
AO: NodeAddOns<
NodeAdapter<T, CB::Components>,
EthApi: EthApiBuilderProvider<NodeAdapter<T, CB::Components>>
+ FullEthApiServer
+ AddDevSigners,
>,
{
type Node = NodeHandle<NodeAdapter<T, CB::Components>, AO>;

Expand Down
6 changes: 4 additions & 2 deletions crates/node/builder/src/launch/exex.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
//! Support for launching execution extensions.
use crate::{common::WithConfigs, exex::BoxedLaunchExEx};
use std::{fmt, fmt::Debug};

use futures::future;
use reth_exex::{ExExContext, ExExHandle, ExExManager, ExExManagerHandle};
use reth_node_api::FullNodeComponents;
use reth_primitives::Head;
use reth_provider::CanonStateSubscriptions;
use reth_tracing::tracing::{debug, info};
use std::{fmt, fmt::Debug};

use crate::{common::WithConfigs, exex::BoxedLaunchExEx};

/// Can launch execution extensions.
pub struct ExExLauncher<Node: FullNodeComponents> {
Expand Down
12 changes: 8 additions & 4 deletions crates/node/builder/src/launch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ pub(crate) mod engine;
pub use common::LaunchContext;
pub use exex::ExExLauncher;

use std::{future::Future, sync::Arc};

use futures::{future::Either, stream, stream_select, StreamExt};
use reth_beacon_consensus::{
hooks::{EngineHooks, PruneHook, StaticFileHook},
Expand All @@ -33,7 +35,6 @@ use reth_rpc_types::engine::ClientVersionV1;
use reth_tasks::TaskExecutor;
use reth_tracing::tracing::{debug, info};
use reth_transaction_pool::TransactionPool;
use std::{future::Future, sync::Arc};
use tokio::sync::{mpsc::unbounded_channel, oneshot};
use tokio_stream::wrappers::UnboundedReceiverStream;

Expand Down Expand Up @@ -102,9 +103,12 @@ impl<T, CB, AO> LaunchNode<NodeBuilderWithComponents<T, CB, AO>> for DefaultNode
where
T: FullNodeTypes<Provider = BlockchainProvider<<T as FullNodeTypes>::DB>>,
CB: NodeComponentsBuilder<T>,
AO: NodeAddOns<NodeAdapter<T, CB::Components>>,
AO::EthApi:
EthApiBuilderProvider<NodeAdapter<T, CB::Components>> + FullEthApiServer + AddDevSigners,
AO: NodeAddOns<
NodeAdapter<T, CB::Components>,
EthApi: EthApiBuilderProvider<NodeAdapter<T, CB::Components>>
+ FullEthApiServer
+ AddDevSigners,
>,
{
type Node = NodeHandle<NodeAdapter<T, CB::Components>, AO>;

Expand Down
3 changes: 2 additions & 1 deletion crates/node/builder/src/setup.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! Helpers for setting up parts of the node.
use std::sync::Arc;

use reth_config::{config::StageConfig, PruneConfig};
use reth_consensus::Consensus;
use reth_db_api::database::Database;
Expand All @@ -18,7 +20,6 @@ use reth_stages::{prelude::DefaultStages, stages::ExecutionStage, Pipeline, Stag
use reth_static_file::StaticFileProducer;
use reth_tasks::TaskExecutor;
use reth_tracing::tracing::debug;
use std::sync::Arc;
use tokio::sync::watch;

/// Constructs a [Pipeline] that's wired to the network
Expand Down

0 comments on commit c7b9ec0

Please sign in to comment.