mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-04-30 03:01:58 -04:00
chore(sdk): allow NoopNetwork in NodeAdapater (#16037)
Co-authored-by: Arsenii Kulikov <klkvrr@gmail.com>
This commit is contained in:
@@ -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<Node, PoolB, PayloadB, NetworkB, ExecB, ConsB> NodeComponentsBuilder<Node>
|
||||
for ComponentsBuilder<Node, PoolB, PayloadB, NetworkB, ExecB, ConsB>
|
||||
where
|
||||
Node: FullNodeTypes,
|
||||
PoolB: PoolBuilder<
|
||||
Node,
|
||||
Pool: TransactionPool<
|
||||
Transaction: PoolTransaction<
|
||||
Pooled = <NetworkB::Primitives as NetworkPrimitives>::PooledTransaction,
|
||||
>,
|
||||
>,
|
||||
>,
|
||||
PoolB: PoolBuilder<Node, Pool: TransactionPool>,
|
||||
NetworkB: NetworkBuilder<
|
||||
Node,
|
||||
PoolB::Pool,
|
||||
Primitives: NetworkPrimitives<
|
||||
BlockHeader = HeaderTy<Node::Types>,
|
||||
BlockBody = BodyTy<Node::Types>,
|
||||
Block = BlockTy<Node::Types>,
|
||||
Network: FullNetwork<
|
||||
Primitives: NetPrimitivesFor<
|
||||
PrimitivesTy<Node::Types>,
|
||||
PooledTransaction = PoolPooledTx<PoolB::Pool>,
|
||||
>,
|
||||
>,
|
||||
>,
|
||||
PayloadB: PayloadServiceBuilder<Node, PoolB::Pool, ExecB::EVM>,
|
||||
@@ -317,7 +312,7 @@ where
|
||||
ConsB: ConsensusBuilder<Node>,
|
||||
{
|
||||
type Components =
|
||||
Components<Node, NetworkB::Primitives, PoolB::Pool, ExecB::EVM, ConsB::Consensus>;
|
||||
Components<Node, NetworkB::Network, PoolB::Pool, ExecB::EVM, ConsB::Consensus>;
|
||||
|
||||
async fn build_components(
|
||||
self,
|
||||
@@ -383,16 +378,17 @@ pub trait NodeComponentsBuilder<Node: FullNodeTypes>: Send {
|
||||
) -> impl Future<Output = eyre::Result<Self::Components>> + Send;
|
||||
}
|
||||
|
||||
impl<Node, N, F, Fut, Pool, EVM, Cons> NodeComponentsBuilder<Node> for F
|
||||
impl<Node, Net, F, Fut, Pool, EVM, Cons> NodeComponentsBuilder<Node> for F
|
||||
where
|
||||
N: NetworkPrimitives<
|
||||
BlockHeader = HeaderTy<Node::Types>,
|
||||
BlockBody = BodyTy<Node::Types>,
|
||||
Block = BlockTy<Node::Types>,
|
||||
Net: FullNetwork<
|
||||
Primitives: NetPrimitivesFor<
|
||||
PrimitivesTy<Node::Types>,
|
||||
PooledTransaction = PoolPooledTx<Pool>,
|
||||
>,
|
||||
>,
|
||||
Node: FullNodeTypes,
|
||||
F: FnOnce(&BuilderContext<Node>) -> Fut + Send,
|
||||
Fut: Future<Output = eyre::Result<Components<Node, N, Pool, EVM, Cons>>> + Send,
|
||||
Fut: Future<Output = eyre::Result<Components<Node, Net, Pool, EVM, Cons>>> + Send,
|
||||
Pool: TransactionPool<Transaction: PoolTransaction<Consensus = TxTy<Node::Types>>>
|
||||
+ Unpin
|
||||
+ 'static,
|
||||
@@ -400,7 +396,7 @@ where
|
||||
Cons:
|
||||
FullConsensus<PrimitivesTy<Node::Types>, Error = ConsensusError> + Clone + Unpin + 'static,
|
||||
{
|
||||
type Components = Components<Node, N, Pool, EVM, Cons>;
|
||||
type Components = Components<Node, Net, Pool, EVM, Cons>;
|
||||
|
||||
fn build_components(
|
||||
self,
|
||||
|
||||
@@ -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<T: FullNodeTypes>: Clone + Debug + Unpin + Send + Sync
|
||||
+ 'static;
|
||||
|
||||
/// Network API.
|
||||
type Network: FullNetwork<Client: BlockClient<Block = BlockTy<T::Types>>>;
|
||||
type Network: FullNetwork<Primitives: NetPrimitivesFor<<T::Types as NodeTypes>::Primitives>>;
|
||||
|
||||
/// Returns the transaction pool of the node.
|
||||
fn pool(&self) -> &Self::Pool;
|
||||
@@ -74,7 +72,7 @@ pub trait NodeComponents<T: FullNodeTypes>: Clone + Debug + Unpin + Send + Sync
|
||||
///
|
||||
/// This provides access to all the components of the node.
|
||||
#[derive(Debug)]
|
||||
pub struct Components<Node: FullNodeTypes, N: NetworkPrimitives, Pool, EVM, Consensus> {
|
||||
pub struct Components<Node: FullNodeTypes, Network, Pool, EVM, Consensus> {
|
||||
/// 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<Node: FullNodeTypes, N: NetworkPrimitives, Pool, EVM, Cons
|
||||
/// The consensus implementation of the node.
|
||||
pub consensus: Consensus,
|
||||
/// The network implementation of the node.
|
||||
pub network: NetworkHandle<N>,
|
||||
pub network: Network,
|
||||
/// The handle to the payload builder service.
|
||||
pub payload_builder_handle: PayloadBuilderHandle<<Node::Types as NodeTypes>::Payload>,
|
||||
}
|
||||
|
||||
impl<Node, Pool, EVM, Cons, N> NodeComponents<Node> for Components<Node, N, Pool, EVM, Cons>
|
||||
impl<Node, Pool, EVM, Cons, Network> NodeComponents<Node>
|
||||
for Components<Node, Network, Pool, EVM, Cons>
|
||||
where
|
||||
Node: FullNodeTypes,
|
||||
N: NetworkPrimitives<
|
||||
BlockHeader = HeaderTy<Node::Types>,
|
||||
BlockBody = BodyTy<Node::Types>,
|
||||
Block = BlockTy<Node::Types>,
|
||||
Network: FullNetwork<
|
||||
Primitives: NetPrimitivesFor<
|
||||
PrimitivesTy<Node::Types>,
|
||||
PooledTransaction = PoolPooledTx<Pool>,
|
||||
>,
|
||||
>,
|
||||
Pool: TransactionPool<Transaction: PoolTransaction<Consensus = TxTy<Node::Types>>>
|
||||
+ Unpin
|
||||
@@ -105,7 +105,7 @@ where
|
||||
type Pool = Pool;
|
||||
type Evm = EVM;
|
||||
type Consensus = Cons;
|
||||
type Network = NetworkHandle<N>;
|
||||
type Network = Network;
|
||||
|
||||
fn pool(&self) -> &Self::Pool {
|
||||
&self.transaction_pool
|
||||
@@ -130,7 +130,7 @@ where
|
||||
|
||||
impl<Node, N, Pool, EVM, Cons> Clone for Components<Node, N, Pool, EVM, Cons>
|
||||
where
|
||||
N: NetworkPrimitives,
|
||||
N: Clone,
|
||||
Node: FullNodeTypes,
|
||||
Pool: TransactionPool,
|
||||
EVM: ConfigureEvm,
|
||||
|
||||
@@ -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<Node: FullNodeTypes, Pool: TransactionPool>: Send {
|
||||
/// The primitive types to use for the network.
|
||||
type Primitives: NetworkPrimitives;
|
||||
/// 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<NetworkHandle<Self::Primitives>>> + Send;
|
||||
) -> impl Future<Output = eyre::Result<Self::Network>> + Send;
|
||||
}
|
||||
|
||||
impl<Node, P, F, Fut, Pool> NetworkBuilder<Node, Pool> for F
|
||||
impl<Node, Net, F, Fut, Pool> NetworkBuilder<Node, Pool> for F
|
||||
where
|
||||
Node: FullNodeTypes,
|
||||
P: NetworkPrimitives,
|
||||
Net: FullNetwork<Primitives: NetPrimitivesFor<PrimitivesTy<Node::Types>>>,
|
||||
Pool: TransactionPool,
|
||||
F: Fn(&BuilderContext<Node>, Pool) -> Fut + Send,
|
||||
Fut: Future<Output = eyre::Result<NetworkHandle<P>>> + Send,
|
||||
Fut: Future<Output = eyre::Result<Net>> + Send,
|
||||
{
|
||||
type Primitives = P;
|
||||
type Network = Net;
|
||||
|
||||
fn build_network(
|
||||
self,
|
||||
ctx: &BuilderContext<Node>,
|
||||
pool: Pool,
|
||||
) -> impl Future<Output = eyre::Result<NetworkHandle<P>>> + Send {
|
||||
) -> impl Future<Output = eyre::Result<Net>> + Send {
|
||||
self(ctx, pool)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user