feat: make NetworkConfigBuilder independent of concrete ChainSpec (#11176)

This commit is contained in:
Arsenii Kulikov
2024-09-26 14:37:20 +03:00
committed by GitHub
parent f2a508df34
commit 65f2664471
21 changed files with 130 additions and 84 deletions

View File

@ -8,7 +8,7 @@ use reth_primitives_traits::Header;
/// Trait representing type configuring a chain spec.
#[auto_impl::auto_impl(&, Arc)]
pub trait EthChainSpec: Send + Sync + Unpin + Debug + 'static {
pub trait EthChainSpec: Send + Sync + Unpin + Debug {
// todo: make chain spec type generic over hardfork
//type Hardfork: Clone + Copy + 'static;

View File

@ -411,10 +411,7 @@ impl ChainSpec {
/// Returns the hardfork display helper.
pub fn display_hardforks(&self) -> DisplayHardforks {
DisplayHardforks::new(
&self.hardforks,
self.paris_block_and_final_difficulty.map(|(block, _)| block),
)
DisplayHardforks::new(&self, self.paris_block_and_final_difficulty.map(|(block, _)| block))
}
/// Get the fork id for the given hardfork.
@ -613,6 +610,18 @@ impl Hardforks for ChainSpec {
fn forks_iter(&self) -> impl Iterator<Item = (&dyn Hardfork, ForkCondition)> {
self.hardforks.forks_iter()
}
fn fork_id(&self, head: &Head) -> ForkId {
self.fork_id(head)
}
fn latest_fork_id(&self) -> ForkId {
self.latest_fork_id()
}
fn fork_filter(&self, head: Head) -> ForkFilter {
self.fork_filter(head)
}
}
impl EthereumHardforks for ChainSpec {
@ -820,7 +829,7 @@ fn into_optimism_chain_spec(genesis: Genesis) -> ChainSpec {
#[auto_impl::auto_impl(&, Arc)]
pub trait ChainSpecProvider: Send + Sync {
/// The chain spec type.
type ChainSpec: EthChainSpec;
type ChainSpec: EthChainSpec + 'static;
/// Get an [`Arc`] to the [`ChainSpec`].
fn chain_spec(&self) -> Arc<Self::ChainSpec>;

View File

@ -100,13 +100,12 @@ impl<C: ChainSpecParser<ChainSpec = ChainSpec>> Command<C> {
let net = NetworkConfigBuilder::new(p2p_secret_key)
.peer_config(config.peers_config_with_basic_nodes_from_file(None))
.external_ip_resolver(self.network.nat)
.chain_spec(self.chain.clone())
.disable_discv4_discovery_if(self.chain.chain.is_optimism())
.boot_nodes(boot_nodes.clone())
.apply(|builder| {
self.network.discovery.apply_to_builder(builder, rlpx_socket, boot_nodes)
})
.build_with_noop_provider()
.build_with_noop_provider(self.chain)
.manager()
.await?;
let network = net.handle().clone();

View File

@ -86,7 +86,7 @@ where
Pool: TransactionPool + Unpin + 'static,
Engine: EngineTypes,
Executor: BlockExecutorProvider,
ChainSpec: EthChainSpec + EthereumHardforks,
ChainSpec: EthChainSpec + EthereumHardforks + 'static,
{
type Output = ();

View File

@ -2,7 +2,7 @@
mod ethereum;
pub use ethereum::EthereumHardforks;
use crate::{ForkCondition, Hardfork};
use crate::{ForkCondition, ForkFilter, ForkId, Hardfork, Head};
#[cfg(feature = "std")]
use rustc_hash::FxHashMap;
#[cfg(feature = "std")]
@ -31,6 +31,15 @@ pub trait Hardforks: Clone {
fn is_fork_active_at_block<H: Hardfork>(&self, fork: H, block_number: u64) -> bool {
self.fork(fork).active_at_block(block_number)
}
/// Compute the [`ForkId`] for the given [`Head`] following eip-6122 spec
fn fork_id(&self, head: &Head) -> ForkId;
/// Returns the [`ForkId`] for the last fork.
fn latest_fork_id(&self) -> ForkId;
/// Creates a [`ForkFilter`] for the block described by [Head].
fn fork_filter(&self, head: Head) -> ForkFilter;
}
/// Ordered list of a chain hardforks that implement [`Hardfork`].
@ -129,16 +138,6 @@ impl ChainHardforks {
}
}
impl Hardforks for ChainHardforks {
fn fork<H: Hardfork>(&self, fork: H) -> ForkCondition {
self.fork(fork)
}
fn forks_iter(&self) -> impl Iterator<Item = (&dyn Hardfork, ForkCondition)> {
self.forks_iter()
}
}
impl core::fmt::Debug for ChainHardforks {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.debug_struct("ChainHardforks")

View File

@ -1,7 +1,7 @@
//! Keys of ENR [`ForkId`](reth_ethereum_forks::ForkId) kv-pair. Identifies which network stack a
//! node belongs to.
use reth_chainspec::ChainSpec;
use reth_chainspec::EthChainSpec;
/// Identifies which Ethereum network stack a node belongs to, on the discovery network.
#[derive(Debug)]
@ -21,11 +21,11 @@ impl NetworkStackId {
pub const OPSTACK: &'static [u8] = b"opstack";
#[allow(clippy::missing_const_for_fn)]
/// Returns the [`NetworkStackId`] that matches the given [`ChainSpec`].
pub fn id(chain: &ChainSpec) -> Option<&'static [u8]> {
if chain.is_optimism() {
/// Returns the [`NetworkStackId`] that matches the given chain spec.
pub fn id(chain: impl EthChainSpec) -> Option<&'static [u8]> {
if chain.chain().is_optimism() {
return Some(Self::OPEL)
} else if chain.is_ethereum() {
} else if chain.chain().is_ethereum() {
return Some(Self::ETH)
}

View File

@ -3,7 +3,7 @@ use alloy_chains::{Chain, NamedChain};
use alloy_genesis::Genesis;
use alloy_primitives::{hex, B256, U256};
use alloy_rlp::{RlpDecodable, RlpEncodable};
use reth_chainspec::{ChainSpec, MAINNET};
use reth_chainspec::{ChainSpec, EthChainSpec, Hardforks, MAINNET};
use reth_codecs_derive::add_arbitrary_tests;
use reth_primitives::{EthereumHardfork, ForkId, Head};
use std::fmt::{Debug, Display};
@ -75,9 +75,12 @@ impl Status {
///
/// Sets the `chain` and `genesis`, `blockhash`, and `forkid` fields based on the [`ChainSpec`]
/// and head.
pub fn spec_builder(spec: &ChainSpec, head: &Head) -> StatusBuilder {
pub fn spec_builder<Spec>(spec: Spec, head: &Head) -> StatusBuilder
where
Spec: EthChainSpec + Hardforks,
{
Self::builder()
.chain(spec.chain)
.chain(spec.chain())
.genesis(spec.genesis_hash())
.blockhash(head.hash)
.total_difficulty(head.total_difficulty)

View File

@ -2,7 +2,7 @@
use std::{collections::HashSet, net::SocketAddr, sync::Arc};
use reth_chainspec::{ChainSpec, MAINNET};
use reth_chainspec::{ChainSpecProvider, EthChainSpec, Hardforks};
use reth_discv4::{Discv4Config, Discv4ConfigBuilder, NatResolver, DEFAULT_DISCOVERY_ADDRESS};
use reth_discv5::NetworkStackId;
use reth_dns_discovery::DnsDiscoveryConfig;
@ -10,7 +10,7 @@ use reth_eth_wire::{HelloMessage, HelloMessageWithProtocols, Status};
use reth_network_peers::{mainnet_nodes, pk2id, sepolia_nodes, PeerId, TrustedPeer};
use reth_network_types::{PeersConfig, SessionsConfig};
use reth_primitives::{ForkFilter, Head};
use reth_storage_api::{BlockNumReader, BlockReader, HeaderProvider};
use reth_storage_api::{noop::NoopBlockReader, BlockNumReader, BlockReader, HeaderProvider};
use reth_tasks::{TaskSpawner, TokioTaskExecutor};
use secp256k1::SECP256K1;
@ -56,8 +56,8 @@ pub struct NetworkConfig<C> {
pub peers_config: PeersConfig,
/// How to configure the [`SessionManager`](crate::session::SessionManager).
pub sessions_config: SessionsConfig,
/// The chain spec
pub chain_spec: Arc<ChainSpec>,
/// The chain id
pub chain_id: u64,
/// The [`ForkFilter`] to use at launch for authenticating sessions.
///
/// See also <https://github.com/ethereum/EIPs/blob/master/EIPS/eip-2124.md#stale-software-examples>
@ -99,7 +99,10 @@ impl NetworkConfig<()> {
impl<C> NetworkConfig<C> {
/// Create a new instance with all mandatory fields set, rest is field with defaults.
pub fn new(client: C, secret_key: SecretKey) -> Self {
pub fn new(client: C, secret_key: SecretKey) -> Self
where
C: ChainSpecProvider<ChainSpec: Hardforks>,
{
NetworkConfig::builder(secret_key).build(client)
}
@ -170,8 +173,6 @@ pub struct NetworkConfigBuilder {
peers_config: Option<PeersConfig>,
/// How to configure the sessions manager
sessions_config: Option<SessionsConfig>,
/// The network's chain spec
chain_spec: Arc<ChainSpec>,
/// The default mode of the network.
network_mode: NetworkMode,
/// The executor to use for spawning tasks.
@ -211,7 +212,6 @@ impl NetworkConfigBuilder {
listener_addr: None,
peers_config: None,
sessions_config: None,
chain_spec: MAINNET.clone(),
network_mode: Default::default(),
executor: None,
hello_message: None,
@ -241,12 +241,6 @@ impl NetworkConfigBuilder {
&self.secret_key
}
/// Sets the chain spec.
pub fn chain_spec(mut self, chain_spec: Arc<ChainSpec>) -> Self {
self.chain_spec = chain_spec;
self
}
/// Sets the [`NetworkMode`].
pub const fn network_mode(mut self, network_mode: NetworkMode) -> Self {
self.network_mode = network_mode;
@ -461,10 +455,14 @@ impl NetworkConfigBuilder {
/// Convenience function for creating a [`NetworkConfig`] with a noop provider that does
/// nothing.
pub fn build_with_noop_provider(
pub fn build_with_noop_provider<ChainSpec>(
self,
) -> NetworkConfig<reth_storage_api::noop::NoopBlockReader> {
self.build(Default::default())
chain_spec: Arc<ChainSpec>,
) -> NetworkConfig<NoopBlockReader<ChainSpec>>
where
ChainSpec: EthChainSpec + Hardforks + 'static,
{
self.build(NoopBlockReader::new(chain_spec))
}
/// Consumes the type and creates the actual [`NetworkConfig`]
@ -473,8 +471,12 @@ impl NetworkConfigBuilder {
/// The given client is to be used for interacting with the chain, for example fetching the
/// corresponding block for a given block hash we receive from a peer in the status message when
/// establishing a connection.
pub fn build<C>(self, client: C) -> NetworkConfig<C> {
pub fn build<C>(self, client: C) -> NetworkConfig<C>
where
C: ChainSpecProvider<ChainSpec: Hardforks>,
{
let peer_id = self.get_peer_id();
let chain_spec = client.chain_spec();
let Self {
secret_key,
mut dns_discovery_config,
@ -485,7 +487,6 @@ impl NetworkConfigBuilder {
listener_addr,
peers_config,
sessions_config,
chain_spec,
network_mode,
executor,
hello_message,
@ -514,9 +515,9 @@ impl NetworkConfigBuilder {
let head = head.unwrap_or_else(|| Head {
hash: chain_spec.genesis_hash(),
number: 0,
timestamp: chain_spec.genesis.timestamp,
difficulty: chain_spec.genesis.difficulty,
total_difficulty: chain_spec.genesis.difficulty,
timestamp: chain_spec.genesis().timestamp,
difficulty: chain_spec.genesis().difficulty,
total_difficulty: chain_spec.genesis().difficulty,
});
// set the status
@ -525,6 +526,9 @@ impl NetworkConfigBuilder {
// set a fork filter based on the chain spec and head
let fork_filter = chain_spec.fork_filter(head);
// get the chain id
let chain_id = chain_spec.chain().id();
// If default DNS config is used then we add the known dns network to bootstrap from
if let Some(dns_networks) =
dns_discovery_config.as_mut().and_then(|c| c.bootstrap_dns_networks.as_mut())
@ -547,7 +551,7 @@ impl NetworkConfigBuilder {
listener_addr,
peers_config: peers_config.unwrap_or_default(),
sessions_config: sessions_config.unwrap_or_default(),
chain_spec,
chain_id,
block_import: block_import.unwrap_or_else(|| Box::<ProofOfStakeBlockImport>::default()),
network_mode,
executor: executor.unwrap_or_else(|| Box::<TokioTaskExecutor>::default()),
@ -587,9 +591,11 @@ impl NetworkMode {
#[cfg(test)]
mod tests {
use std::sync::Arc;
use super::*;
use rand::thread_rng;
use reth_chainspec::Chain;
use reth_chainspec::{Chain, MAINNET};
use reth_dns_discovery::tree::LinkEntry;
use reth_primitives::ForkHash;
use reth_provider::test_utils::NoopProvider;
@ -622,7 +628,7 @@ mod tests {
let genesis_fork_hash = ForkHash::from(chain_spec.genesis_hash());
// enforce that the fork_id set in the status is consistent with the generated fork filter
let config = builder().chain_spec(chain_spec).build(NoopProvider::default());
let config = builder().build_with_noop_provider(chain_spec);
let status = config.status;
let fork_filter = config.fork_filter;

View File

@ -178,7 +178,7 @@ impl NetworkManager {
listener_addr,
peers_config,
sessions_config,
chain_spec,
chain_id,
block_import,
network_mode,
boot_nodes,
@ -264,7 +264,7 @@ impl NetworkManager {
local_peer_id,
peers_handle,
network_mode,
Arc::new(AtomicU64::new(chain_spec.chain.id())),
Arc::new(AtomicU64::new(chain_id)),
tx_gossip_disabled,
discv4,
discv5,

View File

@ -10,14 +10,14 @@ use std::{
use futures::{FutureExt, StreamExt};
use pin_project::pin_project;
use reth_chainspec::MAINNET;
use reth_chainspec::{Hardforks, MAINNET};
use reth_eth_wire::{protocol::Protocol, DisconnectReason, HelloMessageWithProtocols};
use reth_network_api::{
test_utils::{PeersHandle, PeersHandleProvider},
NetworkEvent, NetworkEventListenerProvider, NetworkInfo, Peers,
};
use reth_network_peers::PeerId;
use reth_provider::test_utils::NoopProvider;
use reth_provider::{test_utils::NoopProvider, ChainSpecProvider};
use reth_storage_api::{BlockReader, BlockReaderIdExt, HeaderProvider, StateProviderFactory};
use reth_tasks::TokioTaskExecutor;
use reth_tokio_util::EventStream;
@ -54,7 +54,7 @@ pub struct Testnet<C, Pool> {
impl<C> Testnet<C, TestPool>
where
C: BlockReader + HeaderProvider + Clone + 'static,
C: BlockReader + HeaderProvider + Clone + 'static + ChainSpecProvider<ChainSpec: Hardforks>,
{
/// Same as [`Self::try_create_with`] but panics on error
pub async fn create_with(num_peers: usize, provider: C) -> Self {
@ -548,7 +548,10 @@ where
/// Initialize the network with a random secret key, allowing the devp2p and discovery to bind
/// to any available IP and port.
pub fn new(client: C) -> Self {
pub fn new(client: C) -> Self
where
C: ChainSpecProvider<ChainSpec: Hardforks>,
{
let secret_key = SecretKey::new(&mut rand::thread_rng());
let config = Self::network_config_builder(secret_key).build(client.clone());
Self { config, client, secret_key }
@ -556,13 +559,19 @@ where
/// Initialize the network with a given secret key, allowing devp2p and discovery to bind any
/// available IP and port.
pub fn with_secret_key(client: C, secret_key: SecretKey) -> Self {
pub fn with_secret_key(client: C, secret_key: SecretKey) -> Self
where
C: ChainSpecProvider<ChainSpec: Hardforks>,
{
let config = Self::network_config_builder(secret_key).build(client.clone());
Self { config, client, secret_key }
}
/// Initialize the network with a given capabilities.
pub fn with_protocols(client: C, protocols: impl IntoIterator<Item = Protocol>) -> Self {
pub fn with_protocols(client: C, protocols: impl IntoIterator<Item = Protocol>) -> Self
where
C: ChainSpecProvider<ChainSpec: Hardforks>,
{
let secret_key = SecretKey::new(&mut rand::thread_rng());
let builder = Self::network_config_builder(secret_key);

View File

@ -5,6 +5,7 @@ use std::{collections::HashSet, net::SocketAddr, time::Duration};
use alloy_node_bindings::Geth;
use alloy_provider::{ext::AdminApi, ProviderBuilder};
use futures::StreamExt;
use reth_chainspec::MAINNET;
use reth_discv4::Discv4Config;
use reth_eth_wire::{DisconnectReason, HeadersDirection};
use reth_net_banlist::BanList;
@ -688,7 +689,7 @@ async fn new_random_peer(max_in_bound: usize, trusted_nodes: Vec<TrustedPeer>) -
.listener_port(0)
.disable_discovery()
.peer_config(peers_config)
.build_with_noop_provider();
.build_with_noop_provider(MAINNET.clone());
NetworkManager::new(config).await.unwrap()
}

View File

@ -3,6 +3,7 @@ use std::{
net::{Ipv4Addr, SocketAddr, SocketAddrV4},
};
use reth_chainspec::MAINNET;
use reth_discv4::Discv4Config;
use reth_network::{
error::{NetworkError, ServiceKind},
@ -74,7 +75,7 @@ async fn test_tcp_port_node_record_no_discovery() {
let config = NetworkConfigBuilder::new(secret_key)
.listener_port(0)
.disable_discovery()
.build_with_noop_provider();
.build_with_noop_provider(MAINNET.clone());
let network = NetworkManager::new(config).await.unwrap();
let local_addr = network.local_addr();
@ -93,7 +94,7 @@ async fn test_tcp_port_node_record_discovery() {
.listener_port(0)
.discovery_port(0)
.disable_dns_discovery()
.build_with_noop_provider();
.build_with_noop_provider(MAINNET.clone());
let network = NetworkManager::new(config).await.unwrap();
let local_addr = network.local_addr();

View File

@ -10,7 +10,7 @@ pub use states::*;
use std::sync::Arc;
use futures::Future;
use reth_chainspec::{ChainSpec, EthChainSpec, EthereumHardforks};
use reth_chainspec::{ChainSpec, EthChainSpec, EthereumHardforks, Hardforks};
use reth_cli_util::get_secret_key;
use reth_db_api::{
database::Database,
@ -633,7 +633,10 @@ impl<Node: FullNodeTypes> BuilderContext<Node> {
pub fn build_network_config(
&self,
network_builder: NetworkConfigBuilder,
) -> NetworkConfig<Node::Provider> {
) -> NetworkConfig<Node::Provider>
where
Node::Types: NodeTypes<ChainSpec: Hardforks>,
{
network_builder.build(self.provider.clone())
}
}

View File

@ -400,7 +400,7 @@ impl<R, ChainSpec: EthChainSpec> LaunchContextWith<Attached<WithConfigs<ChainSpe
impl<DB, ChainSpec> LaunchContextWith<Attached<WithConfigs<ChainSpec>, DB>>
where
DB: Database + Clone + 'static,
ChainSpec: EthChainSpec + EthereumHardforks,
ChainSpec: EthChainSpec + EthereumHardforks + 'static,
{
/// Returns the [`ProviderFactory`] for the attached storage after executing a consistent check
/// between the database and static files. **It may execute a pipeline unwind if it fails this

View File

@ -240,7 +240,6 @@ impl NetworkArgs {
)
.peer_config(peers_config)
.boot_nodes(chain_bootnodes.clone())
.chain_spec(chain_spec)
.transactions_manager_config(transactions_manager_config)
// Configure node identity
.apply(|builder| {

View File

@ -121,7 +121,7 @@ impl<P, C> AnyNodeTypes<P, C> {
impl<P, C> NodeTypes for AnyNodeTypes<P, C>
where
P: NodePrimitives + Send + Sync + Unpin + 'static,
C: EthChainSpec,
C: EthChainSpec + 'static,
{
type Primitives = P;
type ChainSpec = C;
@ -157,7 +157,7 @@ impl<P, E, C> NodeTypes for AnyNodeTypesWithEngine<P, E, C>
where
P: NodePrimitives + Send + Sync + Unpin + 'static,
E: EngineTypes + Send + Sync + Unpin,
C: EthChainSpec,
C: EthChainSpec + 'static,
{
type Primitives = P;
type ChainSpec = C;
@ -167,7 +167,7 @@ impl<P, E, C> NodeTypesWithEngine for AnyNodeTypesWithEngine<P, E, C>
where
P: NodePrimitives + Send + Sync + Unpin + 'static,
E: EngineTypes + Send + Sync + Unpin,
C: EthChainSpec,
C: EthChainSpec + 'static,
{
type Engine = E;
}

View File

@ -151,7 +151,9 @@ impl<TX, Spec> StaticFileProviderFactory for DatabaseProvider<TX, Spec> {
}
}
impl<TX: Send + Sync, Spec: EthChainSpec> ChainSpecProvider for DatabaseProvider<TX, Spec> {
impl<TX: Send + Sync, Spec: EthChainSpec + 'static> ChainSpecProvider
for DatabaseProvider<TX, Spec>
{
type ChainSpec = Spec;
fn chain_spec(&self) -> Arc<Self::ChainSpec> {

View File

@ -1,17 +1,28 @@
//! Various noop implementations for traits.
use std::sync::Arc;
use crate::{BlockHashReader, BlockNumReader};
use alloy_primitives::{BlockNumber, B256};
use reth_chainspec::ChainInfo;
use reth_chainspec::{ChainInfo, ChainSpecProvider, EthChainSpec};
use reth_storage_errors::provider::ProviderResult;
/// Supports various api interfaces for testing purposes.
#[derive(Debug, Clone, Default, Copy)]
#[derive(Debug, Clone)]
#[non_exhaustive]
pub struct NoopBlockReader;
pub struct NoopBlockReader<ChainSpec> {
chain_spec: Arc<ChainSpec>,
}
impl<ChainSpec> NoopBlockReader<ChainSpec> {
/// Create a new instance of the `NoopBlockReader`.
pub const fn new(chain_spec: Arc<ChainSpec>) -> Self {
Self { chain_spec }
}
}
/// Noop implementation for testing purposes
impl BlockHashReader for NoopBlockReader {
impl<ChainSpec: Send + Sync> BlockHashReader for NoopBlockReader<ChainSpec> {
fn block_hash(&self, _number: u64) -> ProviderResult<Option<B256>> {
Ok(None)
}
@ -25,7 +36,7 @@ impl BlockHashReader for NoopBlockReader {
}
}
impl BlockNumReader for NoopBlockReader {
impl<ChainSpec: Send + Sync> BlockNumReader for NoopBlockReader<ChainSpec> {
fn chain_info(&self) -> ProviderResult<ChainInfo> {
Ok(ChainInfo::default())
}
@ -42,3 +53,11 @@ impl BlockNumReader for NoopBlockReader {
Ok(None)
}
}
impl<ChainSpec: EthChainSpec + 'static> ChainSpecProvider for NoopBlockReader<ChainSpec> {
type ChainSpec = ChainSpec;
fn chain_spec(&self) -> Arc<Self::ChainSpec> {
self.chain_spec.clone()
}
}

View File

@ -49,9 +49,8 @@ async fn main() {
// The network configuration
let mut net_cfg = NetworkConfig::builder(secret_key)
.chain_spec(bsc_chain_spec())
.listener_addr(local_addr)
.build_with_noop_provider()
.build_with_noop_provider(bsc_chain_spec())
.set_discovery_v4(
Discv4ConfigBuilder::default()
.add_boot_nodes(boot_nodes())

View File

@ -19,7 +19,6 @@ use reth_network::{
};
use reth_network_api::{test_utils::PeersHandleProvider, NetworkInfo};
use reth_node_ethereum::EthereumNode;
use reth_provider::test_utils::NoopProvider;
use subprotocol::{
connection::CustomCommand,
protocol::{
@ -51,7 +50,7 @@ fn main() -> eyre::Result<()> {
.listener_addr(SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::UNSPECIFIED, 0)))
.disable_discovery()
.add_rlpx_sub_protocol(custom_rlpx_handler_2.into_rlpx_sub_protocol())
.build(NoopProvider::default());
.build_with_noop_provider(node.chain_spec());
// spawn the second network instance
let subnetwork = NetworkManager::new(net_cfg).await?;

View File

@ -14,7 +14,6 @@ use reth_discv4::Discv4ConfigBuilder;
use reth_network::{
config::NetworkMode, NetworkConfig, NetworkEvent, NetworkEventListenerProvider, NetworkManager,
};
use reth_provider::test_utils::NoopProvider;
use reth_tracing::{
tracing::info, tracing_subscriber::filter::LevelFilter, LayerInfo, LogFormat, RethTracer,
Tracer,
@ -47,11 +46,10 @@ async fn main() {
// The network configuration
let net_cfg = NetworkConfig::builder(secret_key)
.chain_spec(polygon_chain_spec())
.set_head(head())
.network_mode(NetworkMode::Work)
.listener_addr(local_addr)
.build(NoopProvider::default());
.build_with_noop_provider(polygon_chain_spec());
// Set Discv4 lookup interval to 1 second
let mut discv4_cfg = Discv4ConfigBuilder::default();