diff --git a/crates/net/network/src/manager.rs b/crates/net/network/src/manager.rs index c63f5025b560..6f10a95dceb0 100644 --- a/crates/net/network/src/manager.rs +++ b/crates/net/network/src/manager.rs @@ -142,7 +142,25 @@ pub struct NetworkManager { disconnect_metrics: DisconnectMetrics, } -// === impl NetworkManager === +impl NetworkManager { + /// Creates the manager of a new network with [`EthNetworkPrimitives`] types. + /// + /// ```no_run + /// # async fn f() { + /// use reth_chainspec::MAINNET; + /// use reth_network::{NetworkConfig, NetworkManager}; + /// let config = + /// NetworkConfig::builder_with_rng_secret_key().build_with_noop_provider(MAINNET.clone()); + /// let manager = NetworkManager::eth(config).await; + /// # } + /// ``` + pub async fn eth( + config: NetworkConfig, + ) -> Result { + Self::new(config).await + } +} + impl NetworkManager { /// Sets the dedicated channel for events indented for the /// [`TransactionsManager`](crate::transactions::TransactionsManager). diff --git a/examples/bsc-p2p/src/main.rs b/examples/bsc-p2p/src/main.rs index a2dec469591b..d0ea0f6d9eb5 100644 --- a/examples/bsc-p2p/src/main.rs +++ b/examples/bsc-p2p/src/main.rs @@ -14,9 +14,7 @@ use chainspec::{boot_nodes, bsc_chain_spec}; use reth_discv4::Discv4ConfigBuilder; -use reth_network::{ - EthNetworkPrimitives, NetworkConfig, NetworkEvent, NetworkEventListenerProvider, NetworkManager, -}; +use reth_network::{NetworkConfig, NetworkEvent, NetworkEventListenerProvider, NetworkManager}; use reth_network_api::{ events::{PeerEvent, SessionInfo}, PeersInfo, @@ -69,7 +67,7 @@ async fn main() { // latest BSC forkId, we need to override this to allow connections from BSC nodes let fork_id = ForkId { hash: ForkHash([0x07, 0xb5, 0x43, 0x28]), next: 0 }; net_cfg.fork_filter.set_current_fork_id(fork_id); - let net_manager = NetworkManager::::new(net_cfg).await.unwrap(); + let net_manager = NetworkManager::eth(net_cfg).await.unwrap(); // The network handle is our entrypoint into the network. let net_handle = net_manager.handle().clone(); diff --git a/examples/custom-rlpx-subprotocol/src/main.rs b/examples/custom-rlpx-subprotocol/src/main.rs index 702d0e8cf5ef..7b52dd75056e 100644 --- a/examples/custom-rlpx-subprotocol/src/main.rs +++ b/examples/custom-rlpx-subprotocol/src/main.rs @@ -14,8 +14,8 @@ use std::net::{Ipv4Addr, SocketAddr, SocketAddrV4}; use reth::builder::NodeHandle; use reth_network::{ - config::SecretKey, protocol::IntoRlpxSubProtocol, EthNetworkPrimitives, NetworkConfig, - NetworkManager, NetworkProtocols, + config::SecretKey, protocol::IntoRlpxSubProtocol, NetworkConfig, NetworkManager, + NetworkProtocols, }; use reth_network_api::{test_utils::PeersHandleProvider, NetworkInfo}; use reth_node_ethereum::EthereumNode; @@ -53,7 +53,7 @@ fn main() -> eyre::Result<()> { .build_with_noop_provider(node.chain_spec()); // spawn the second network instance - let subnetwork = NetworkManager::::new(net_cfg).await?; + let subnetwork = NetworkManager::eth(net_cfg).await?; let subnetwork_peer_id = *subnetwork.peer_id(); let subnetwork_peer_addr = subnetwork.local_addr(); let subnetwork_handle = subnetwork.peers_handle(); diff --git a/examples/network/src/main.rs b/examples/network/src/main.rs index bd4f232a754c..ba3b46e53767 100644 --- a/examples/network/src/main.rs +++ b/examples/network/src/main.rs @@ -8,8 +8,7 @@ use futures::StreamExt; use reth_network::{ - config::rng_secret_key, EthNetworkPrimitives, NetworkConfig, NetworkEventListenerProvider, - NetworkManager, + config::rng_secret_key, NetworkConfig, NetworkEventListenerProvider, NetworkManager, }; use reth_provider::test_utils::NoopProvider; @@ -25,7 +24,7 @@ async fn main() -> eyre::Result<()> { let config = NetworkConfig::builder(local_key).mainnet_boot_nodes().build(client); // create the network instance - let network = NetworkManager::::new(config).await?; + let network = NetworkManager::eth(config).await?; // get a handle to the network to interact with it let handle = network.handle().clone(); diff --git a/examples/polygon-p2p/src/main.rs b/examples/polygon-p2p/src/main.rs index bae5399d9cd6..b4ff9b59d370 100644 --- a/examples/polygon-p2p/src/main.rs +++ b/examples/polygon-p2p/src/main.rs @@ -12,8 +12,7 @@ use chain_cfg::{boot_nodes, head, polygon_chain_spec}; use reth_discv4::Discv4ConfigBuilder; use reth_network::{ - config::NetworkMode, EthNetworkPrimitives, NetworkConfig, NetworkEvent, - NetworkEventListenerProvider, NetworkManager, + config::NetworkMode, NetworkConfig, NetworkEvent, NetworkEventListenerProvider, NetworkManager, }; use reth_network_api::events::SessionInfo; use reth_tracing::{ @@ -59,7 +58,7 @@ async fn main() { discv4_cfg.add_boot_nodes(boot_nodes()).lookup_interval(interval); let net_cfg = net_cfg.set_discovery_v4(discv4_cfg.build()); - let net_manager = NetworkManager::::new(net_cfg).await.unwrap(); + let net_manager = NetworkManager::eth(net_cfg).await.unwrap(); // The network handle is our entrypoint into the network. let net_handle = net_manager.handle();