diff --git a/crates/net/network/src/manager.rs b/crates/net/network/src/manager.rs index dc9a32ece9..ed536cb669 100644 --- a/crates/net/network/src/manager.rs +++ b/crates/net/network/src/manager.rs @@ -39,6 +39,7 @@ use reth_eth_wire::{ DisconnectReason, Status, }; use reth_net_common::bandwidth_meter::BandwidthMeter; +use reth_network_api::{EthProtocolInfo, NetworkStatus}; use reth_primitives::{PeerId, H256}; use reth_provider::BlockProvider; use std::{ @@ -307,9 +308,20 @@ where self.swarm.state().fetch_client() } - /// Returns the current [`Status`] for the local node. - pub fn status(&self) -> Status { - self.swarm.sessions().status() + /// Returns the current [`NetworkStatus`] for the local node. + pub fn status(&self) -> NetworkStatus { + let sessions = self.swarm.sessions(); + let status = sessions.status(); + + NetworkStatus { + client_version: sessions.hello_message().client_version, + eth_protocol_info: EthProtocolInfo { + difficulty: status.total_difficulty, + head: status.blockhash, + network: status.chain.id(), + genesis: status.genesis, + }, + } } /// Event hook for an unexpected message from the peer. diff --git a/crates/net/network/src/network.rs b/crates/net/network/src/network.rs index e5f5153bf0..2ac9837c70 100644 --- a/crates/net/network/src/network.rs +++ b/crates/net/network/src/network.rs @@ -8,15 +8,13 @@ use crate::{ }; use async_trait::async_trait; use parking_lot::Mutex; -use reth_eth_wire::{ - DisconnectReason, NewBlock, NewPooledTransactionHashes, SharedTransactions, Status, -}; +use reth_eth_wire::{DisconnectReason, NewBlock, NewPooledTransactionHashes, SharedTransactions}; use reth_interfaces::{ p2p::headers::client::StatusUpdater, sync::{SyncState, SyncStateProvider, SyncStateUpdater}, }; use reth_net_common::bandwidth_meter::BandwidthMeter; -use reth_network_api::{EthProtocolInfo, NetworkError, NetworkInfo, NetworkStatus, PeersInfo}; +use reth_network_api::{NetworkError, NetworkInfo, NetworkStatus, PeersInfo}; use reth_primitives::{NodeRecord, PeerId, TransactionSigned, TxHash, H256, U256}; use std::{ net::SocketAddr, @@ -129,13 +127,6 @@ impl NetworkHandle { self.send_message(NetworkHandleMessage::StatusUpdate { height, hash, total_difficulty }); } - /// Get the current status of the node. - pub async fn get_status(&self) -> Result { - let (tx, rx) = oneshot::channel(); - let _ = self.manager().send(NetworkHandleMessage::GetStatus(tx)); - rx.await - } - /// Announce a block over devp2p /// /// Caution: in PoS this is a noop, since new block propagation will happen over devp2p @@ -232,17 +223,9 @@ impl NetworkInfo for NetworkHandle { } async fn network_status(&self) -> Result { - let status = self.get_status().await?; - - Ok(NetworkStatus { - client_version: "Reth".to_string(), - eth_protocol_info: EthProtocolInfo { - difficulty: status.total_difficulty, - head: status.blockhash, - network: status.chain.id(), - genesis: status.genesis, - }, - }) + let (tx, rx) = oneshot::channel(); + let _ = self.manager().send(NetworkHandleMessage::GetStatus(tx)); + rx.await.map_err(Into::into) } } @@ -317,7 +300,7 @@ pub(crate) enum NetworkHandleMessage { /// Apply a status update. StatusUpdate { height: u64, hash: H256, total_difficulty: U256 }, /// Get the currenet status - GetStatus(oneshot::Sender), + GetStatus(oneshot::Sender), /// Get PeerInfo from all the peers GetPeerInfo(oneshot::Sender>), /// Get PeerInfo for a specific peer diff --git a/crates/net/network/src/session/mod.rs b/crates/net/network/src/session/mod.rs index 2490bc54b3..523f276f26 100644 --- a/crates/net/network/src/session/mod.rs +++ b/crates/net/network/src/session/mod.rs @@ -148,6 +148,11 @@ impl SessionManager { self.status } + /// Returns the session hello message. + pub(crate) fn hello_message(&self) -> HelloMessage { + self.hello_message.clone() + } + /// Spawns the given future onto a new task that is tracked in the `spawned_tasks` [`JoinSet`]. fn spawn(&self, f: F) where