feat: add NetworkPrimitives to NetworkBuilder (#13169)

Co-authored-by: Arsenii Kulikov <klkvrr@gmail.com>
This commit is contained in:
Dan Cline
2024-12-10 15:56:32 -05:00
committed by GitHub
parent 73f1583455
commit 37f3933db2
26 changed files with 201 additions and 143 deletions

View File

@@ -2,33 +2,39 @@
use std::future::Future;
use reth_network::NetworkHandle;
use reth_network::{NetworkHandle, NetworkPrimitives};
use reth_transaction_pool::TransactionPool;
use crate::{BuilderContext, FullNodeTypes};
/// A type that knows how to build the network implementation.
pub trait NetworkBuilder<Node: FullNodeTypes, Pool: TransactionPool>: Send {
/// The primitive types to use for the network.
type Primitives: NetworkPrimitives;
/// Launches the network implementation and returns the handle to it.
fn build_network(
self,
ctx: &BuilderContext<Node>,
pool: Pool,
) -> impl Future<Output = eyre::Result<NetworkHandle>> + Send;
) -> impl Future<Output = eyre::Result<NetworkHandle<Self::Primitives>>> + Send;
}
impl<Node, F, Fut, Pool> NetworkBuilder<Node, Pool> for F
impl<Node, P, F, Fut, Pool> NetworkBuilder<Node, Pool> for F
where
Node: FullNodeTypes,
P: NetworkPrimitives,
Pool: TransactionPool,
F: Fn(&BuilderContext<Node>, Pool) -> Fut + Send,
Fut: Future<Output = eyre::Result<NetworkHandle>> + Send,
Fut: Future<Output = eyre::Result<NetworkHandle<P>>> + Send,
{
type Primitives = P;
fn build_network(
self,
ctx: &BuilderContext<Node>,
pool: Pool,
) -> impl Future<Output = eyre::Result<NetworkHandle>> + Send {
) -> impl Future<Output = eyre::Result<NetworkHandle<P>>> + Send {
self(ctx, pool)
}
}