Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions crates/net/network-api/src/noop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ use tokio_stream::wrappers::UnboundedReceiverStream;
#[derive(Debug, Clone)]
#[non_exhaustive]
pub struct NoopNetwork<Net = EthNetworkPrimitives> {
chain_id: u64,
peers_handle: PeersHandle,
_marker: PhantomData<Net>,
}
Expand All @@ -40,15 +41,23 @@ impl<Net> NoopNetwork<Net> {
pub fn new() -> Self {
let (tx, _) = mpsc::unbounded_channel();

Self { peers_handle: PeersHandle::new(tx), _marker: PhantomData }
Self {
chain_id: 1, // mainnet
peers_handle: PeersHandle::new(tx),
_marker: PhantomData,
}
}

/// Creates a new [`NoopNetwork`] from an existing one but with a new chain id.
pub const fn with_chain_id(mut self, chain_id: u64) -> Self {
self.chain_id = chain_id;
self
}
}

impl Default for NoopNetwork<EthNetworkPrimitives> {
fn default() -> Self {
let (tx, _) = mpsc::unbounded_channel();

Self { peers_handle: PeersHandle::new(tx), _marker: PhantomData }
Self::new()
}
}

Expand Down Expand Up @@ -77,8 +86,7 @@ where
}

fn chain_id(&self) -> u64 {
// mainnet
1
self.chain_id
}

fn is_syncing(&self) -> bool {
Expand Down
5 changes: 3 additions & 2 deletions crates/node/builder/src/components/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::{
},
BuilderContext, ConfigureEvm, FullNodeTypes,
};
use reth_chainspec::EthChainSpec;
use reth_consensus::{noop::NoopConsensus, ConsensusError, FullConsensus};
use reth_network::{types::NetPrimitivesFor, EthNetworkPrimitives, NetworkPrimitives};
use reth_network_api::{noop::NoopNetwork, FullNetwork};
Expand Down Expand Up @@ -515,10 +516,10 @@ where

async fn build_network(
self,
_ctx: &BuilderContext<N>,
ctx: &BuilderContext<N>,
_pool: Pool,
) -> eyre::Result<Self::Network> {
Ok(NoopNetwork::new())
Ok(NoopNetwork::new().with_chain_id(ctx.chain_spec().chain_id()))
}
}

Expand Down
Loading