Files
reth/crates/node/builder/src/components/network.rs
Emilia Hane 623950bb7e chore(sdk): allow NoopNetwork in NodeAdapater (#16037)
Co-authored-by: Arsenii Kulikov <klkvrr@gmail.com>
2025-05-06 17:59:30 +00:00

41 lines
1.2 KiB
Rust

//! Network component for the node builder.
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<Node: FullNodeTypes, Pool: TransactionPool>: Send {
/// The network built.
type Network: FullNetwork<Primitives: NetPrimitivesFor<PrimitivesTy<Node::Types>>>;
/// Launches the network implementation and returns the handle to it.
fn build_network(
self,
ctx: &BuilderContext<Node>,
pool: Pool,
) -> impl Future<Output = eyre::Result<Self::Network>> + Send;
}
impl<Node, Net, F, Fut, Pool> NetworkBuilder<Node, Pool> for F
where
Node: FullNodeTypes,
Net: FullNetwork<Primitives: NetPrimitivesFor<PrimitivesTy<Node::Types>>>,
Pool: TransactionPool,
F: Fn(&BuilderContext<Node>, Pool) -> Fut + Send,
Fut: Future<Output = eyre::Result<Net>> + Send,
{
type Network = Net;
fn build_network(
self,
ctx: &BuilderContext<Node>,
pool: Pool,
) -> impl Future<Output = eyre::Result<Net>> + Send {
self(ctx, pool)
}
}