node: revise NodeTypes trait (#10665)

This commit is contained in:
Thomas Coratger
2024-09-03 05:52:53 -07:00
committed by GitHub
parent 020597da32
commit d30e3a4888
11 changed files with 140 additions and 62 deletions

View File

@@ -21,7 +21,7 @@ use reth_exex::ExExContext;
use reth_network::{
NetworkBuilder, NetworkConfig, NetworkConfigBuilder, NetworkHandle, NetworkManager,
};
use reth_node_api::{FullNodeTypes, FullNodeTypesAdapter, NodeAddOns, NodeTypes};
use reth_node_api::{FullNodeTypes, FullNodeTypesAdapter, NodeAddOns, NodeTypesWithEngine};
use reth_node_core::{
cli::config::{PayloadBuilderConfig, RethTransactionPoolConfig},
dirs::{ChainPath, DataDirPath},
@@ -58,8 +58,8 @@ pub type RethFullAdapter<DB, Types> = FullNodeTypesAdapter<Types, DB, Blockchain
/// ## Order
///
/// Configuring a node starts out with a [`NodeConfig`] (this can be obtained from cli arguments for
/// example) and then proceeds to configure the core static types of the node: [`NodeTypes`], these
/// include the node's primitive types and the node's engine types.
/// example) and then proceeds to configure the core static types of the node:
/// [`NodeTypesWithEngine`], these include the node's primitive types and the node's engine types.
///
/// Next all stateful components of the node are configured, these include all the
/// components of the node that are downstream of those types, these include:
@@ -125,10 +125,10 @@ pub type RethFullAdapter<DB, Types> = FullNodeTypesAdapter<Types, DB, Blockchain
///
/// ## Internals
///
/// The node builder is fully type safe, it uses the [`NodeTypes`] trait to enforce that all
/// components are configured with the correct types. However the database types and with that the
/// provider trait implementations are currently created by the builder itself during the launch
/// process, hence the database type is not part of the [`NodeTypes`] trait and the node's
/// The node builder is fully type safe, it uses the [`NodeTypesWithEngine`] trait to enforce that
/// all components are configured with the correct types. However the database types and with that
/// the provider trait implementations are currently created by the builder itself during the launch
/// process, hence the database type is not part of the [`NodeTypesWithEngine`] trait and the node's
/// components, that depend on the database, are configured separately. In order to have a nice
/// trait that encapsulates the entire node the
/// [`FullNodeComponents`](reth_node_api::FullNodeComponents) trait was introduced. This
@@ -208,7 +208,7 @@ where
/// Configures the types of the node.
pub fn with_types<T>(self) -> NodeBuilderWithTypes<RethFullAdapter<DB, T>>
where
T: NodeTypes<ChainSpec = ChainSpec>,
T: NodeTypesWithEngine<ChainSpec = ChainSpec>,
{
self.with_types_and_provider()
}
@@ -218,7 +218,7 @@ where
self,
) -> NodeBuilderWithTypes<FullNodeTypesAdapter<T, DB, P>>
where
T: NodeTypes<ChainSpec = ChainSpec>,
T: NodeTypesWithEngine<ChainSpec = ChainSpec>,
P: FullProvider<DB, T::ChainSpec>,
{
NodeBuilderWithTypes::new(self.config, self.database)
@@ -266,7 +266,7 @@ where
/// Configures the types of the node.
pub fn with_types<T>(self) -> WithLaunchContext<NodeBuilderWithTypes<RethFullAdapter<DB, T>>>
where
T: NodeTypes<ChainSpec = ChainSpec>,
T: NodeTypesWithEngine<ChainSpec = ChainSpec>,
{
WithLaunchContext { builder: self.builder.with_types(), task_executor: self.task_executor }
}
@@ -276,7 +276,7 @@ where
self,
) -> WithLaunchContext<NodeBuilderWithTypes<FullNodeTypesAdapter<T, DB, P>>>
where
T: NodeTypes<ChainSpec = ChainSpec>,
T: NodeTypesWithEngine<ChainSpec = ChainSpec>,
P: FullProvider<DB, T::ChainSpec>,
{
WithLaunchContext {
@@ -475,7 +475,7 @@ where
impl<T, DB, CB, AO> WithLaunchContext<NodeBuilderWithComponents<RethFullAdapter<DB, T>, CB, AO>>
where
DB: Database + DatabaseMetrics + DatabaseMetadata + Clone + Unpin + 'static,
T: NodeTypes<ChainSpec = ChainSpec>,
T: NodeTypesWithEngine<ChainSpec = ChainSpec>,
CB: NodeComponentsBuilder<RethFullAdapter<DB, T>>,
AO: NodeAddOns<
NodeAdapter<RethFullAdapter<DB, T>, CB::Components>,

View File

@@ -8,7 +8,9 @@
use std::{fmt, future::Future, marker::PhantomData};
use reth_exex::ExExContext;
use reth_node_api::{FullNodeComponents, FullNodeTypes, NodeAddOns, NodeTypes};
use reth_node_api::{
FullNodeComponents, FullNodeTypes, NodeAddOns, NodeTypes, NodeTypesWithEngine,
};
use reth_node_core::{
node_config::NodeConfig,
rpc::eth::{helpers::AddDevSigners, FullEthApiServer},
@@ -90,10 +92,13 @@ pub struct NodeAdapter<T: FullNodeTypes, C: NodeComponents<T>> {
impl<T: FullNodeTypes, C: NodeComponents<T>> NodeTypes for NodeAdapter<T, C> {
type Primitives = T::Primitives;
type Engine = T::Engine;
type ChainSpec = T::ChainSpec;
}
impl<T: FullNodeTypes, C: NodeComponents<T>> NodeTypesWithEngine for NodeAdapter<T, C> {
type Engine = T::Engine;
}
impl<T: FullNodeTypes, C: NodeComponents<T>> FullNodeTypes for NodeAdapter<T, C> {
type DB = T::DB;
type Provider = T::Provider;

View File

@@ -35,7 +35,9 @@ use crate::{ConfigureEvm, FullNodeTypes};
/// - transaction pool
/// - network
/// - payload builder.
pub trait NodeComponents<NodeTypes: FullNodeTypes>: Clone + Unpin + Send + Sync + 'static {
pub trait NodeComponents<NodeTypesWithEngine: FullNodeTypes>:
Clone + Unpin + Send + Sync + 'static
{
/// The transaction pool of the node.
type Pool: TransactionPool + Unpin;
@@ -67,7 +69,7 @@ pub trait NodeComponents<NodeTypes: FullNodeTypes>: Clone + Unpin + Send + Sync
fn network(&self) -> &Self::Network;
/// Returns the handle to the payload builder service.
fn payload_builder(&self) -> &PayloadBuilderHandle<NodeTypes::Engine>;
fn payload_builder(&self) -> &PayloadBuilderHandle<NodeTypesWithEngine::Engine>;
}
/// All the components of the node.

View File

@@ -1,5 +1,5 @@
// re-export the node api types
pub use reth_node_api::{FullNodeTypes, NodeTypes};
pub use reth_node_api::{FullNodeTypes, NodeTypes, NodeTypesWithEngine};
use std::{marker::PhantomData, sync::Arc};
@@ -20,10 +20,10 @@ use crate::{
NodeAdapter, NodeAddOns,
};
/// A [`crate::Node`] is a [`NodeTypes`] that comes with preconfigured components.
/// A [`crate::Node`] is a [`NodeTypesWithEngine`] that comes with preconfigured components.
///
/// This can be used to configure the builder with a preset of components.
pub trait Node<N: FullNodeTypes>: NodeTypes + Clone {
pub trait Node<N: FullNodeTypes>: NodeTypesWithEngine + Clone {
/// The type that builds the node's components.
type ComponentsBuilder: NodeComponentsBuilder<N>;
@@ -60,11 +60,18 @@ where
{
type Primitives = N::Primitives;
type Engine = N::Engine;
type ChainSpec = N::ChainSpec;
}
impl<N, C, AO> NodeTypesWithEngine for AnyNode<N, C, AO>
where
N: FullNodeTypes,
C: Send + Sync + Unpin + 'static,
AO: Send + Sync + Unpin + Clone + 'static,
{
type Engine = N::Engine;
}
impl<N, C, AO> Node<N> for AnyNode<N, C, AO>
where
N: FullNodeTypes + Clone,