reth_node_builder/components/
network.rs

1//! Network component for the node builder.
2
3use std::future::Future;
4
5use reth_network::{NetworkHandle, NetworkPrimitives};
6use reth_transaction_pool::TransactionPool;
7
8use crate::{BuilderContext, FullNodeTypes};
9
10/// A type that knows how to build the network implementation.
11pub trait NetworkBuilder<Node: FullNodeTypes, Pool: TransactionPool>: Send {
12    /// The primitive types to use for the network.
13    type Primitives: NetworkPrimitives;
14
15    /// Launches the network implementation and returns the handle to it.
16    fn build_network(
17        self,
18        ctx: &BuilderContext<Node>,
19        pool: Pool,
20    ) -> impl Future<Output = eyre::Result<NetworkHandle<Self::Primitives>>> + Send;
21}
22
23impl<Node, P, F, Fut, Pool> NetworkBuilder<Node, Pool> for F
24where
25    Node: FullNodeTypes,
26    P: NetworkPrimitives,
27    Pool: TransactionPool,
28    F: Fn(&BuilderContext<Node>, Pool) -> Fut + Send,
29    Fut: Future<Output = eyre::Result<NetworkHandle<P>>> + Send,
30{
31    type Primitives = P;
32
33    fn build_network(
34        self,
35        ctx: &BuilderContext<Node>,
36        pool: Pool,
37    ) -> impl Future<Output = eyre::Result<NetworkHandle<P>>> + Send {
38        self(ctx, pool)
39    }
40}