Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Get the correct number of connected peers in SyncState (#13700)
Browse files Browse the repository at this point in the history
`Protocol` is not a reliable source for the information of connected
peers because it doesn't have real-time information of the actual
connectivity state because it's not resposible for accepting/rejecting
connections and gets that information with delay from `SyncinEngine`.
  • Loading branch information
altonen authored and coderobe committed Apr 4, 2023
1 parent 76fed9b commit 9db2286
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion client/informant/src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl<B: BlockT> InformantDisplay<B> {
let best_number = info.chain.best_number;
let best_hash = info.chain.best_hash;
let finalized_number = info.chain.finalized_number;
let num_connected_peers = net_status.num_connected_peers;
let num_connected_peers = sync_status.num_connected_peers;
let speed = speed::<B>(best_number, self.last_number, self.last_update);
let total_bytes_inbound = net_status.total_bytes_inbound;
let total_bytes_outbound = net_status.total_bytes_outbound;
Expand Down
2 changes: 2 additions & 0 deletions client/network/common/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ pub struct SyncStatus<Block: BlockT> {
pub best_seen_block: Option<NumberFor<Block>>,
/// Number of peers participating in syncing.
pub num_peers: u32,
/// Number of peers known to `SyncingEngine` (both full and light).
pub num_connected_peers: u32,
/// Number of blocks queued for import
pub queued_blocks: u32,
/// State sync status in progress, if any.
Expand Down
4 changes: 3 additions & 1 deletion client/network/sync/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,9 @@ where
ToServiceCommand::NewBestBlockImported(hash, number) =>
self.new_best_block_imported(hash, number),
ToServiceCommand::Status(tx) => {
let _ = tx.send(self.chain_sync.status());
let mut status = self.chain_sync.status();
status.num_connected_peers = self.peers.len() as u32;
let _ = tx.send(status);
},
ToServiceCommand::NumActivePeers(tx) => {
let _ = tx.send(self.chain_sync.num_active_peers());
Expand Down
1 change: 1 addition & 0 deletions client/network/sync/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,7 @@ where
state: sync_state,
best_seen_block,
num_peers: self.peers.len() as u32,
num_connected_peers: 0u32,
queued_blocks: self.queue_blocks.len() as u32,
state_sync: self.state_sync.as_ref().map(|s| s.progress()),
warp_sync: warp_sync_progress,
Expand Down

0 comments on commit 9db2286

Please sign in to comment.