diff --git a/crates/net/network-api/src/noop.rs b/crates/net/network-api/src/noop.rs index c650db0afc4..2aaa0093568 100644 --- a/crates/net/network-api/src/noop.rs +++ b/crates/net/network-api/src/noop.rs @@ -31,6 +31,7 @@ use tokio_stream::wrappers::UnboundedReceiverStream; #[derive(Debug, Clone)] #[non_exhaustive] pub struct NoopNetwork { + chain_id: u64, peers_handle: PeersHandle, _marker: PhantomData, } @@ -40,15 +41,23 @@ impl NoopNetwork { 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 { fn default() -> Self { - let (tx, _) = mpsc::unbounded_channel(); - - Self { peers_handle: PeersHandle::new(tx), _marker: PhantomData } + Self::new() } } @@ -77,8 +86,7 @@ where } fn chain_id(&self) -> u64 { - // mainnet - 1 + self.chain_id } fn is_syncing(&self) -> bool { diff --git a/crates/node/builder/src/components/builder.rs b/crates/node/builder/src/components/builder.rs index bd1a9fda718..c54cc0e37f1 100644 --- a/crates/node/builder/src/components/builder.rs +++ b/crates/node/builder/src/components/builder.rs @@ -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}; @@ -515,10 +516,10 @@ where async fn build_network( self, - _ctx: &BuilderContext, + ctx: &BuilderContext, _pool: Pool, ) -> eyre::Result { - Ok(NoopNetwork::new()) + Ok(NoopNetwork::new().with_chain_id(ctx.chain_spec().chain_id())) } }