Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replacing network_handle with peer_info trait object #9367

Merged
merged 1 commit into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/reth/src/commands/debug_cmd/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion crates/node/builder/src/launch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
16 changes: 8 additions & 8 deletions crates/node/events/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -36,8 +36,8 @@ struct NodeState<DB> {
/// Used for freelist calculation reported in the "Status" log message.
/// See [`EventHandler::poll`].
db: DB,
/// Connection to the network.
network: Option<NetworkHandle>,
/// Information about connected peers.
peers_info: Option<Box<dyn PeersInfo>>,
/// The stage currently being executed.
current_stage: Option<CurrentStage>,
/// The latest block reached by either pipeline or consensus engine.
Expand All @@ -55,12 +55,12 @@ struct NodeState<DB> {
impl<DB> NodeState<DB> {
const fn new(
db: DB,
network: Option<NetworkHandle>,
peers_info: Option<Box<dyn PeersInfo>>,
latest_block: Option<BlockNumber>,
) -> Self {
Self {
db,
network,
peers_info,
current_stage: None,
latest_block,
latest_block_time: None,
Expand All @@ -71,7 +71,7 @@ impl<DB> NodeState<DB> {
}

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
Expand Down Expand Up @@ -438,15 +438,15 @@ impl From<StaticFileProducerEvent> 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<E, DB>(
network: Option<NetworkHandle>,
peers_info: Option<Box<dyn PeersInfo>>,
latest_block_number: Option<BlockNumber>,
events: E,
db: DB,
) where
E: Stream<Item = NodeEvent> + 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);
Expand Down
Loading