mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat: add NetworkPrimitives to NetworkBuilder (#13169)
Co-authored-by: Arsenii Kulikov <klkvrr@gmail.com>
This commit is contained in:
@ -61,7 +61,6 @@ reth-transaction-pool.workspace = true
|
||||
## ethereum
|
||||
alloy-primitives.workspace = true
|
||||
alloy-rpc-types = { workspace = true, features = ["engine"] }
|
||||
alloy-consensus.workspace = true
|
||||
revm-primitives.workspace = true
|
||||
|
||||
## async
|
||||
|
||||
@ -20,7 +20,7 @@ use reth_db_api::{
|
||||
use reth_exex::ExExContext;
|
||||
use reth_network::{
|
||||
transactions::TransactionsManagerConfig, NetworkBuilder, NetworkConfig, NetworkConfigBuilder,
|
||||
NetworkHandle, NetworkManager,
|
||||
NetworkHandle, NetworkManager, NetworkPrimitives,
|
||||
};
|
||||
use reth_node_api::{
|
||||
FullNodePrimitives, FullNodeTypes, FullNodeTypesAdapter, NodeAddOns, NodeTypes,
|
||||
@ -648,19 +648,24 @@ impl<Node: FullNodeTypes> BuilderContext<Node> {
|
||||
///
|
||||
/// Spawns the configured network and associated tasks and returns the [`NetworkHandle`]
|
||||
/// connected to that network.
|
||||
pub fn start_network<Pool>(&self, builder: NetworkBuilder<(), ()>, pool: Pool) -> NetworkHandle
|
||||
pub fn start_network<N, Pool>(
|
||||
&self,
|
||||
builder: NetworkBuilder<(), (), N>,
|
||||
pool: Pool,
|
||||
) -> NetworkHandle<N>
|
||||
where
|
||||
N: NetworkPrimitives,
|
||||
Pool: TransactionPool<
|
||||
Transaction: PoolTransaction<
|
||||
Consensus = reth_primitives::TransactionSigned,
|
||||
Pooled = reth_primitives::PooledTransactionsElement,
|
||||
Consensus = N::BroadcastedTransaction,
|
||||
Pooled = N::PooledTransaction,
|
||||
>,
|
||||
> + Unpin
|
||||
+ 'static,
|
||||
Node::Provider: BlockReader<
|
||||
Block = reth_primitives::Block,
|
||||
Receipt = reth_primitives::Receipt,
|
||||
Header = reth_primitives::Header,
|
||||
Block = N::Block,
|
||||
Header = N::BlockHeader,
|
||||
>,
|
||||
{
|
||||
self.start_network_with(builder, pool, Default::default())
|
||||
@ -672,24 +677,25 @@ impl<Node: FullNodeTypes> BuilderContext<Node> {
|
||||
///
|
||||
/// Spawns the configured network and associated tasks and returns the [`NetworkHandle`]
|
||||
/// connected to that network.
|
||||
pub fn start_network_with<Pool>(
|
||||
pub fn start_network_with<Pool, N>(
|
||||
&self,
|
||||
builder: NetworkBuilder<(), ()>,
|
||||
builder: NetworkBuilder<(), (), N>,
|
||||
pool: Pool,
|
||||
tx_config: TransactionsManagerConfig,
|
||||
) -> NetworkHandle
|
||||
) -> NetworkHandle<N>
|
||||
where
|
||||
N: NetworkPrimitives,
|
||||
Pool: TransactionPool<
|
||||
Transaction: PoolTransaction<
|
||||
Consensus = reth_primitives::TransactionSigned,
|
||||
Pooled = reth_primitives::PooledTransactionsElement,
|
||||
Consensus = N::BroadcastedTransaction,
|
||||
Pooled = N::PooledTransaction,
|
||||
>,
|
||||
> + Unpin
|
||||
+ 'static,
|
||||
Node::Provider: BlockReader<
|
||||
Block = reth_primitives::Block,
|
||||
Receipt = reth_primitives::Receipt,
|
||||
Header = reth_primitives::Header,
|
||||
Block = N::Block,
|
||||
Header = N::BlockHeader,
|
||||
>,
|
||||
{
|
||||
let (handle, network, txpool, eth) = builder
|
||||
|
||||
@ -9,7 +9,8 @@ use crate::{
|
||||
};
|
||||
use reth_consensus::FullConsensus;
|
||||
use reth_evm::execute::BlockExecutorProvider;
|
||||
use reth_node_api::{HeaderTy, NodeTypes, NodeTypesWithEngine, TxTy};
|
||||
use reth_network::NetworkPrimitives;
|
||||
use reth_node_api::{BodyTy, HeaderTy, NodeTypes, NodeTypesWithEngine, TxTy};
|
||||
use reth_payload_builder::PayloadBuilderHandle;
|
||||
use reth_transaction_pool::{PoolTransaction, TransactionPool};
|
||||
use std::{future::Future, marker::PhantomData};
|
||||
@ -295,13 +296,34 @@ impl<Node, PoolB, PayloadB, NetworkB, ExecB, ConsB> NodeComponentsBuilder<Node>
|
||||
for ComponentsBuilder<Node, PoolB, PayloadB, NetworkB, ExecB, ConsB>
|
||||
where
|
||||
Node: FullNodeTypes,
|
||||
PoolB: PoolBuilder<Node>,
|
||||
NetworkB: NetworkBuilder<Node, PoolB::Pool>,
|
||||
PoolB: PoolBuilder<
|
||||
Node,
|
||||
Pool: TransactionPool<
|
||||
Transaction: PoolTransaction<
|
||||
Pooled = <NetworkB::Primitives as NetworkPrimitives>::PooledTransaction,
|
||||
>,
|
||||
>,
|
||||
>,
|
||||
NetworkB: NetworkBuilder<
|
||||
Node,
|
||||
PoolB::Pool,
|
||||
Primitives: NetworkPrimitives<
|
||||
BlockHeader = HeaderTy<Node::Types>,
|
||||
BlockBody = BodyTy<Node::Types>,
|
||||
>,
|
||||
>,
|
||||
PayloadB: PayloadServiceBuilder<Node, PoolB::Pool>,
|
||||
ExecB: ExecutorBuilder<Node>,
|
||||
ConsB: ConsensusBuilder<Node>,
|
||||
{
|
||||
type Components = Components<Node, PoolB::Pool, ExecB::EVM, ExecB::Executor, ConsB::Consensus>;
|
||||
type Components = Components<
|
||||
Node,
|
||||
NetworkB::Primitives,
|
||||
PoolB::Pool,
|
||||
ExecB::EVM,
|
||||
ExecB::Executor,
|
||||
ConsB::Consensus,
|
||||
>;
|
||||
|
||||
async fn build_components(
|
||||
self,
|
||||
@ -369,11 +391,12 @@ pub trait NodeComponentsBuilder<Node: FullNodeTypes>: Send {
|
||||
) -> impl Future<Output = eyre::Result<Self::Components>> + Send;
|
||||
}
|
||||
|
||||
impl<Node, F, Fut, Pool, EVM, Executor, Cons> NodeComponentsBuilder<Node> for F
|
||||
impl<Node, N, F, Fut, Pool, EVM, Executor, Cons> NodeComponentsBuilder<Node> for F
|
||||
where
|
||||
N: NetworkPrimitives<BlockHeader = HeaderTy<Node::Types>, BlockBody = BodyTy<Node::Types>>,
|
||||
Node: FullNodeTypes,
|
||||
F: FnOnce(&BuilderContext<Node>) -> Fut + Send,
|
||||
Fut: Future<Output = eyre::Result<Components<Node, Pool, EVM, Executor, Cons>>> + Send,
|
||||
Fut: Future<Output = eyre::Result<Components<Node, N, Pool, EVM, Executor, Cons>>> + Send,
|
||||
Pool: TransactionPool<Transaction: PoolTransaction<Consensus = TxTy<Node::Types>>>
|
||||
+ Unpin
|
||||
+ 'static,
|
||||
@ -381,7 +404,7 @@ where
|
||||
Executor: BlockExecutorProvider<Primitives = <Node::Types as NodeTypes>::Primitives>,
|
||||
Cons: FullConsensus<<Node::Types as NodeTypes>::Primitives> + Clone + Unpin + 'static,
|
||||
{
|
||||
type Components = Components<Node, Pool, EVM, Executor, Cons>;
|
||||
type Components = Components<Node, N, Pool, EVM, Executor, Cons>;
|
||||
|
||||
fn build_components(
|
||||
self,
|
||||
|
||||
@ -20,13 +20,14 @@ pub use execute::*;
|
||||
pub use network::*;
|
||||
pub use payload::*;
|
||||
pub use pool::*;
|
||||
use reth_network_p2p::BlockClient;
|
||||
|
||||
use crate::{ConfigureEvm, FullNodeTypes};
|
||||
use reth_consensus::FullConsensus;
|
||||
use reth_evm::execute::BlockExecutorProvider;
|
||||
use reth_network::NetworkHandle;
|
||||
use reth_network::{NetworkHandle, NetworkPrimitives};
|
||||
use reth_network_api::FullNetwork;
|
||||
use reth_node_api::{HeaderTy, NodeTypes, NodeTypesWithEngine, PayloadBuilder, TxTy};
|
||||
use reth_node_api::{BodyTy, HeaderTy, NodeTypes, NodeTypesWithEngine, PayloadBuilder, TxTy};
|
||||
use reth_payload_builder::PayloadBuilderHandle;
|
||||
use reth_transaction_pool::{PoolTransaction, TransactionPool};
|
||||
|
||||
@ -49,7 +50,9 @@ pub trait NodeComponents<T: FullNodeTypes>: Clone + Unpin + Send + Sync + 'stati
|
||||
type Consensus: FullConsensus<<T::Types as NodeTypes>::Primitives> + Clone + Unpin + 'static;
|
||||
|
||||
/// Network API.
|
||||
type Network: FullNetwork;
|
||||
type Network: FullNetwork<
|
||||
Client: BlockClient<Header = HeaderTy<T::Types>, Body = BodyTy<T::Types>>,
|
||||
>;
|
||||
|
||||
/// Builds new blocks.
|
||||
type PayloadBuilder: PayloadBuilder<PayloadType = <T::Types as NodeTypesWithEngine>::Engine>
|
||||
@ -78,7 +81,7 @@ pub trait NodeComponents<T: FullNodeTypes>: Clone + Unpin + Send + Sync + 'stati
|
||||
///
|
||||
/// This provides access to all the components of the node.
|
||||
#[derive(Debug)]
|
||||
pub struct Components<Node: FullNodeTypes, Pool, EVM, Executor, Consensus> {
|
||||
pub struct Components<Node: FullNodeTypes, N: NetworkPrimitives, Pool, EVM, Executor, Consensus> {
|
||||
/// The transaction pool of the node.
|
||||
pub transaction_pool: Pool,
|
||||
/// The node's EVM configuration, defining settings for the Ethereum Virtual Machine.
|
||||
@ -88,14 +91,15 @@ pub struct Components<Node: FullNodeTypes, Pool, EVM, Executor, Consensus> {
|
||||
/// The consensus implementation of the node.
|
||||
pub consensus: Consensus,
|
||||
/// The network implementation of the node.
|
||||
pub network: NetworkHandle,
|
||||
pub network: NetworkHandle<N>,
|
||||
/// The handle to the payload builder service.
|
||||
pub payload_builder: PayloadBuilderHandle<<Node::Types as NodeTypesWithEngine>::Engine>,
|
||||
}
|
||||
|
||||
impl<Node, Pool, EVM, Executor, Cons> NodeComponents<Node>
|
||||
for Components<Node, Pool, EVM, Executor, Cons>
|
||||
impl<Node, Pool, EVM, Executor, Cons, N> NodeComponents<Node>
|
||||
for Components<Node, N, Pool, EVM, Executor, Cons>
|
||||
where
|
||||
N: NetworkPrimitives<BlockHeader = HeaderTy<Node::Types>, BlockBody = BodyTy<Node::Types>>,
|
||||
Node: FullNodeTypes,
|
||||
Pool: TransactionPool<Transaction: PoolTransaction<Consensus = TxTy<Node::Types>>>
|
||||
+ Unpin
|
||||
@ -108,7 +112,7 @@ where
|
||||
type Evm = EVM;
|
||||
type Executor = Executor;
|
||||
type Consensus = Cons;
|
||||
type Network = NetworkHandle;
|
||||
type Network = NetworkHandle<N>;
|
||||
type PayloadBuilder = PayloadBuilderHandle<<Node::Types as NodeTypesWithEngine>::Engine>;
|
||||
|
||||
fn pool(&self) -> &Self::Pool {
|
||||
@ -136,8 +140,9 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<Node, Pool, EVM, Executor, Cons> Clone for Components<Node, Pool, EVM, Executor, Cons>
|
||||
impl<Node, N, Pool, EVM, Executor, Cons> Clone for Components<Node, N, Pool, EVM, Executor, Cons>
|
||||
where
|
||||
N: NetworkPrimitives,
|
||||
Node: FullNodeTypes,
|
||||
Pool: TransactionPool,
|
||||
EVM: ConfigureEvm<Header = HeaderTy<Node::Types>, Transaction = TxTy<Node::Types>>,
|
||||
|
||||
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@ -29,6 +29,7 @@ use reth_node_core::{
|
||||
args::InvalidBlockHookType,
|
||||
dirs::{ChainPath, DataDirPath},
|
||||
node_config::NodeConfig,
|
||||
primitives::BlockHeader,
|
||||
version::{
|
||||
BUILD_PROFILE_NAME, CARGO_PKG_VERSION, VERGEN_BUILD_TIMESTAMP, VERGEN_CARGO_FEATURES,
|
||||
VERGEN_CARGO_TARGET_TRIPLE, VERGEN_GIT_SHA,
|
||||
@ -719,7 +720,7 @@ where
|
||||
/// necessary
|
||||
pub async fn max_block<C>(&self, client: C) -> eyre::Result<Option<BlockNumber>>
|
||||
where
|
||||
C: HeadersClient<Header = alloy_consensus::Header>,
|
||||
C: HeadersClient<Header: BlockHeader>,
|
||||
{
|
||||
self.node_config().max_block(client, self.provider_factory().clone()).await
|
||||
}
|
||||
|
||||
@ -14,7 +14,7 @@ use reth_exex::ExExManagerHandle;
|
||||
use reth_network_p2p::{
|
||||
bodies::downloader::BodyDownloader, headers::downloader::HeaderDownloader, BlockClient,
|
||||
};
|
||||
use reth_node_api::{BodyTy, HeaderTy, NodePrimitives};
|
||||
use reth_node_api::{BodyTy, HeaderTy};
|
||||
use reth_provider::{providers::ProviderNodeTypes, ProviderFactory};
|
||||
use reth_stages::{prelude::DefaultStages, stages::ExecutionStage, Pipeline, StageSet};
|
||||
use reth_static_file::StaticFileProducer;
|
||||
@ -41,7 +41,6 @@ where
|
||||
N: ProviderNodeTypes,
|
||||
Client: BlockClient<Header = HeaderTy<N>, Body = BodyTy<N>> + 'static,
|
||||
Executor: BlockExecutorProvider<Primitives = N::Primitives>,
|
||||
N::Primitives: NodePrimitives<BlockHeader = reth_primitives::Header>,
|
||||
{
|
||||
// building network downloaders using the fetch client
|
||||
let header_downloader = ReverseHeadersDownloaderBuilder::new(config.headers)
|
||||
@ -89,7 +88,6 @@ where
|
||||
H: HeaderDownloader<Header = HeaderTy<N>> + 'static,
|
||||
B: BodyDownloader<Header = HeaderTy<N>, Body = BodyTy<N>> + 'static,
|
||||
Executor: BlockExecutorProvider<Primitives = N::Primitives>,
|
||||
N::Primitives: NodePrimitives<BlockHeader = reth_primitives::Header>,
|
||||
{
|
||||
let mut builder = Pipeline::<N>::builder();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user