From df04ebee465daf13b7b2a5da26bf0f7d3ab5a481 Mon Sep 17 00:00:00 2001 From: Loocapro Date: Mon, 8 Jul 2024 14:49:11 +0200 Subject: [PATCH] replacing network_handle with peer_info trait object --- bin/reth/src/commands/debug_cmd/execution.rs | 2 +- crates/node/builder/src/launch/mod.rs | 2 +- crates/node/events/src/node.rs | 16 ++++++++-------- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/bin/reth/src/commands/debug_cmd/execution.rs b/bin/reth/src/commands/debug_cmd/execution.rs index f645cd140f6f..3298fe5d6367 100644 --- a/bin/reth/src/commands/debug_cmd/execution.rs +++ b/bin/reth/src/commands/debug_cmd/execution.rs @@ -204,7 +204,7 @@ impl Command { ctx.task_executor.spawn_critical( "events task", reth_node_events::node::handle_events( - Some(network.clone()), + Some(Box::new(network)), latest_block_number, events, provider_factory.db_ref().clone(), diff --git a/crates/node/builder/src/launch/mod.rs b/crates/node/builder/src/launch/mod.rs index 9af5a765c31d..328a77e0db87 100644 --- a/crates/node/builder/src/launch/mod.rs +++ b/crates/node/builder/src/launch/mod.rs @@ -279,7 +279,7 @@ where ctx.task_executor().spawn_critical( "events task", node::handle_events( - Some(ctx.components().network().clone()), + Some(Box::new(ctx.components().network().clone())), Some(ctx.head().number), events, database.clone(), diff --git a/crates/node/events/src/node.rs b/crates/node/events/src/node.rs index 77c8fd4684fc..2a6a55abd871 100644 --- a/crates/node/events/src/node.rs +++ b/crates/node/events/src/node.rs @@ -7,7 +7,7 @@ use reth_beacon_consensus::{ BeaconConsensusEngineEvent, ConsensusEngineLiveSyncProgress, ForkchoiceStatus, }; use reth_db_api::{database::Database, database_metrics::DatabaseMetadata}; -use reth_network::{NetworkEvent, NetworkHandle}; +use reth_network::NetworkEvent; use reth_network_api::PeersInfo; use reth_primitives::{constants, BlockNumber, B256}; use reth_primitives_traits::{format_gas, format_gas_throughput}; @@ -36,8 +36,8 @@ struct NodeState { /// Used for freelist calculation reported in the "Status" log message. /// See [`EventHandler::poll`]. db: DB, - /// Connection to the network. - network: Option, + /// Information about connected peers. + peers_info: Option>, /// The stage currently being executed. current_stage: Option, /// The latest block reached by either pipeline or consensus engine. @@ -55,12 +55,12 @@ struct NodeState { impl NodeState { const fn new( db: DB, - network: Option, + peers_info: Option>, latest_block: Option, ) -> Self { Self { db, - network, + peers_info, current_stage: None, latest_block, latest_block_time: None, @@ -71,7 +71,7 @@ impl NodeState { } fn num_connected_peers(&self) -> usize { - self.network.as_ref().map(|net| net.num_connected_peers()).unwrap_or_default() + self.peers_info.as_ref().map(|info| info.num_connected_peers()).unwrap_or_default() } /// Processes an event emitted by the pipeline @@ -438,7 +438,7 @@ impl From for NodeEvent { /// Displays relevant information to the user from components of the node, and periodically /// displays the high-level status of the node. pub async fn handle_events( - network: Option, + peers_info: Option>, latest_block_number: Option, events: E, db: DB, @@ -446,7 +446,7 @@ pub async fn handle_events( E: Stream + Unpin, DB: DatabaseMetadata + Database + 'static, { - let state = NodeState::new(db, network, latest_block_number); + let state = NodeState::new(db, peers_info, latest_block_number); let start = tokio::time::Instant::now() + Duration::from_secs(3); let mut info_interval = tokio::time::interval_at(start, INFO_MESSAGE_INTERVAL);