diff --git a/crates/ethereum/node/src/node.rs b/crates/ethereum/node/src/node.rs index 902b765ad4..037fe47351 100644 --- a/crates/ethereum/node/src/node.rs +++ b/crates/ethereum/node/src/node.rs @@ -435,13 +435,13 @@ where > + Unpin + 'static, { - type Primitives = EthNetworkPrimitives; + type Network = NetworkHandle; async fn build_network( self, ctx: &BuilderContext, pool: Pool, - ) -> eyre::Result { + ) -> eyre::Result { let network = ctx.network_builder().await?; let handle = ctx.start_network(network, pool); info!(target: "reth::cli", enode=%handle.local_node_record(), "P2P networking initialized"); diff --git a/crates/net/eth-wire-types/src/primitives.rs b/crates/net/eth-wire-types/src/primitives.rs index 4531e176ca..ea7813422e 100644 --- a/crates/net/eth-wire-types/src/primitives.rs +++ b/crates/net/eth-wire-types/src/primitives.rs @@ -7,9 +7,7 @@ use reth_primitives_traits::{Block, BlockBody, BlockHeader, NodePrimitives, Sign /// Abstraction over primitive types which might appear in network messages. See /// [`crate::EthMessage`] for more context. -pub trait NetworkPrimitives: - Send + Sync + Unpin + Clone + Debug + PartialEq + Eq + 'static -{ +pub trait NetworkPrimitives: Send + Sync + Unpin + Clone + Debug + 'static { /// The block header type. type BlockHeader: BlockHeader + 'static; diff --git a/crates/net/network-api/src/lib.rs b/crates/net/network-api/src/lib.rs index 1370f83ba1..662abc164c 100644 --- a/crates/net/network-api/src/lib.rs +++ b/crates/net/network-api/src/lib.rs @@ -24,7 +24,6 @@ pub mod test_utils; use test_utils::PeersHandleProvider; pub use alloy_rpc_types_admin::EthProtocolInfo; -use reth_network_p2p::sync::NetworkSyncUpdater; pub use reth_network_p2p::{BlockClient, HeadersClient}; pub use reth_network_types::{PeerKind, Reputation, ReputationChangeKind}; @@ -35,37 +34,41 @@ pub use events::{ PeerRequestSender, }; -use std::{future::Future, net::SocketAddr, sync::Arc, time::Instant}; - -use reth_eth_wire_types::{capability::Capabilities, DisconnectReason, EthVersion, Status}; +use reth_eth_wire_types::{ + capability::Capabilities, DisconnectReason, EthVersion, NetworkPrimitives, Status, +}; +use reth_network_p2p::sync::NetworkSyncUpdater; use reth_network_peers::NodeRecord; +use std::{future::Future, net::SocketAddr, sync::Arc, time::Instant}; /// The `PeerId` type. pub type PeerId = alloy_primitives::B512; /// Helper trait that unifies network API needed to launch node. pub trait FullNetwork: - BlockDownloaderProvider - + NetworkSyncUpdater + BlockDownloaderProvider< + Client: BlockClient::Block>, + > + NetworkSyncUpdater + NetworkInfo + NetworkEventListenerProvider - + PeersInfo + Peers + PeersHandleProvider + Clone + + Unpin + 'static { } impl FullNetwork for T where - T: BlockDownloaderProvider - + NetworkSyncUpdater + T: BlockDownloaderProvider< + Client: BlockClient::Block>, + > + NetworkSyncUpdater + NetworkInfo + NetworkEventListenerProvider - + PeersInfo + Peers + PeersHandleProvider + Clone + + Unpin + 'static { } diff --git a/crates/net/network/src/lib.rs b/crates/net/network/src/lib.rs index 9122405e68..13352893a1 100644 --- a/crates/net/network/src/lib.rs +++ b/crates/net/network/src/lib.rs @@ -146,9 +146,9 @@ mod swarm; mod trusted_peers_resolver; pub use reth_eth_wire::{DisconnectReason, HelloMessageWithProtocols}; -pub use reth_eth_wire_types::{EthNetworkPrimitives, NetworkPrimitives}; +pub use reth_eth_wire_types::{primitives, EthNetworkPrimitives, NetworkPrimitives}; pub use reth_network_api::{ - BlockDownloaderProvider, DiscoveredEvent, DiscoveryEvent, NetworkEvent, + events, BlockDownloaderProvider, DiscoveredEvent, DiscoveryEvent, NetworkEvent, NetworkEventListenerProvider, NetworkInfo, PeerRequest, PeerRequestSender, Peers, PeersInfo, }; pub use reth_network_p2p::sync::{NetworkSyncUpdater, SyncState}; diff --git a/crates/node/builder/src/components/builder.rs b/crates/node/builder/src/components/builder.rs index bf60610623..57a200617d 100644 --- a/crates/node/builder/src/components/builder.rs +++ b/crates/node/builder/src/components/builder.rs @@ -8,9 +8,10 @@ use crate::{ BuilderContext, ConfigureEvm, FullNodeTypes, }; use reth_consensus::{ConsensusError, FullConsensus}; -use reth_network::NetworkPrimitives; -use reth_node_api::{BlockTy, BodyTy, HeaderTy, PrimitivesTy, TxTy}; -use reth_transaction_pool::{PoolTransaction, TransactionPool}; +use reth_network::types::NetPrimitivesFor; +use reth_network_api::FullNetwork; +use reth_node_api::{PrimitivesTy, TxTy}; +use reth_transaction_pool::{PoolPooledTx, PoolTransaction, TransactionPool}; use std::{future::Future, marker::PhantomData}; /// A generic, general purpose and customizable [`NodeComponentsBuilder`] implementation. @@ -295,21 +296,15 @@ impl NodeComponentsBuilder for ComponentsBuilder where Node: FullNodeTypes, - PoolB: PoolBuilder< - Node, - Pool: TransactionPool< - Transaction: PoolTransaction< - Pooled = ::PooledTransaction, - >, - >, - >, + PoolB: PoolBuilder, NetworkB: NetworkBuilder< Node, PoolB::Pool, - Primitives: NetworkPrimitives< - BlockHeader = HeaderTy, - BlockBody = BodyTy, - Block = BlockTy, + Network: FullNetwork< + Primitives: NetPrimitivesFor< + PrimitivesTy, + PooledTransaction = PoolPooledTx, + >, >, >, PayloadB: PayloadServiceBuilder, @@ -317,7 +312,7 @@ where ConsB: ConsensusBuilder, { type Components = - Components; + Components; async fn build_components( self, @@ -383,16 +378,17 @@ pub trait NodeComponentsBuilder: Send { ) -> impl Future> + Send; } -impl NodeComponentsBuilder for F +impl NodeComponentsBuilder for F where - N: NetworkPrimitives< - BlockHeader = HeaderTy, - BlockBody = BodyTy, - Block = BlockTy, + Net: FullNetwork< + Primitives: NetPrimitivesFor< + PrimitivesTy, + PooledTransaction = PoolPooledTx, + >, >, Node: FullNodeTypes, F: FnOnce(&BuilderContext) -> Fut + Send, - Fut: Future>> + Send, + Fut: Future>> + Send, Pool: TransactionPool>> + Unpin + 'static, @@ -400,7 +396,7 @@ where Cons: FullConsensus, Error = ConsensusError> + Clone + Unpin + 'static, { - type Components = Components; + type Components = Components; fn build_components( self, diff --git a/crates/node/builder/src/components/mod.rs b/crates/node/builder/src/components/mod.rs index 28ea66d6ad..af823f9463 100644 --- a/crates/node/builder/src/components/mod.rs +++ b/crates/node/builder/src/components/mod.rs @@ -21,16 +21,14 @@ pub use network::*; pub use payload::*; pub use pool::*; -use reth_network_p2p::BlockClient; -use reth_payload_builder::PayloadBuilderHandle; -use std::fmt::Debug; - use crate::{ConfigureEvm, FullNodeTypes}; use reth_consensus::{ConsensusError, FullConsensus}; -use reth_network::{NetworkHandle, NetworkPrimitives}; +use reth_network::types::NetPrimitivesFor; use reth_network_api::FullNetwork; -use reth_node_api::{BlockTy, BodyTy, HeaderTy, NodeTypes, PrimitivesTy, TxTy}; -use reth_transaction_pool::{PoolTransaction, TransactionPool}; +use reth_node_api::{NodeTypes, PrimitivesTy, TxTy}; +use reth_payload_builder::PayloadBuilderHandle; +use reth_transaction_pool::{PoolPooledTx, PoolTransaction, TransactionPool}; +use std::fmt::Debug; /// An abstraction over the components of a node, consisting of: /// - evm and executor @@ -51,7 +49,7 @@ pub trait NodeComponents: Clone + Debug + Unpin + Send + Sync + 'static; /// Network API. - type Network: FullNetwork>>; + type Network: FullNetwork::Primitives>>; /// Returns the transaction pool of the node. fn pool(&self) -> &Self::Pool; @@ -74,7 +72,7 @@ pub trait NodeComponents: Clone + Debug + Unpin + Send + Sync /// /// This provides access to all the components of the node. #[derive(Debug)] -pub struct Components { +pub struct Components { /// The transaction pool of the node. pub transaction_pool: Pool, /// The node's EVM configuration, defining settings for the Ethereum Virtual Machine. @@ -82,18 +80,20 @@ pub struct Components, + pub network: Network, /// The handle to the payload builder service. pub payload_builder_handle: PayloadBuilderHandle<::Payload>, } -impl NodeComponents for Components +impl NodeComponents + for Components where Node: FullNodeTypes, - N: NetworkPrimitives< - BlockHeader = HeaderTy, - BlockBody = BodyTy, - Block = BlockTy, + Network: FullNetwork< + Primitives: NetPrimitivesFor< + PrimitivesTy, + PooledTransaction = PoolPooledTx, + >, >, Pool: TransactionPool>> + Unpin @@ -105,7 +105,7 @@ where type Pool = Pool; type Evm = EVM; type Consensus = Cons; - type Network = NetworkHandle; + type Network = Network; fn pool(&self) -> &Self::Pool { &self.transaction_pool @@ -130,7 +130,7 @@ where impl Clone for Components where - N: NetworkPrimitives, + N: Clone, Node: FullNodeTypes, Pool: TransactionPool, EVM: ConfigureEvm, diff --git a/crates/node/builder/src/components/network.rs b/crates/node/builder/src/components/network.rs index 33f128a697..c48048f8b5 100644 --- a/crates/node/builder/src/components/network.rs +++ b/crates/node/builder/src/components/network.rs @@ -1,40 +1,40 @@ //! Network component for the node builder. -use std::future::Future; - -use reth_network::{NetworkHandle, NetworkPrimitives}; -use reth_transaction_pool::TransactionPool; - use crate::{BuilderContext, FullNodeTypes}; +use reth_network::types::NetPrimitivesFor; +use reth_network_api::FullNetwork; +use reth_node_api::PrimitivesTy; +use reth_transaction_pool::TransactionPool; +use std::future::Future; /// A type that knows how to build the network implementation. pub trait NetworkBuilder: Send { - /// The primitive types to use for the network. - type Primitives: NetworkPrimitives; + /// The network built. + type Network: FullNetwork>>; /// Launches the network implementation and returns the handle to it. fn build_network( self, ctx: &BuilderContext, pool: Pool, - ) -> impl Future>> + Send; + ) -> impl Future> + Send; } -impl NetworkBuilder for F +impl NetworkBuilder for F where Node: FullNodeTypes, - P: NetworkPrimitives, + Net: FullNetwork>>, Pool: TransactionPool, F: Fn(&BuilderContext, Pool) -> Fut + Send, - Fut: Future>> + Send, + Fut: Future> + Send, { - type Primitives = P; + type Network = Net; fn build_network( self, ctx: &BuilderContext, pool: Pool, - ) -> impl Future>> + Send { + ) -> impl Future> + Send { self(ctx, pool) } } diff --git a/crates/optimism/node/src/node.rs b/crates/optimism/node/src/node.rs index 5d03d0ab7b..09e59c1493 100644 --- a/crates/optimism/node/src/node.rs +++ b/crates/optimism/node/src/node.rs @@ -819,13 +819,13 @@ where > + Unpin + 'static, { - type Primitives = OpNetworkPrimitives; + type Network = NetworkHandle; async fn build_network( self, ctx: &BuilderContext, pool: Pool, - ) -> eyre::Result> { + ) -> eyre::Result { let network_config = self.network_config(ctx)?; let network = NetworkManager::builder(network_config).await?; let handle = ctx.start_network(network, pool); diff --git a/examples/custom-node/src/network.rs b/examples/custom-node/src/network.rs index d611d0f21e..b77018cf60 100644 --- a/examples/custom-node/src/network.rs +++ b/examples/custom-node/src/network.rs @@ -82,13 +82,9 @@ where > + Unpin + 'static, { - type Primitives = CustomNetworkPrimitives; + type Network = NetworkHandle; - async fn build_network( - self, - ctx: &BuilderContext, - pool: Pool, - ) -> Result> { + async fn build_network(self, ctx: &BuilderContext, pool: Pool) -> Result { let network_config = self.network_config(ctx)?; let network = NetworkManager::builder(network_config).await?; let handle = ctx.start_network(network, pool);