Skip to content

Commit

Permalink
add extra logs to debug connected_peers
Browse files Browse the repository at this point in the history
  • Loading branch information
jxs committed Jan 5, 2024
1 parent 037a3c5 commit 6b7e34c
Showing 1 changed file with 26 additions and 29 deletions.
55 changes: 26 additions & 29 deletions protocols/gossipsub/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2914,37 +2914,32 @@ where
} else {
// remove from mesh, topic_peers, peer_topic and the fanout
tracing::debug!(peer=%peer_id, "Peer disconnected");
{
let Some(peer) = self.connected_peers.get(&peer_id) else {
debug_assert!(
self.blacklisted_peers.contains(&peer_id),
"Disconnected node not in connected list"
);
return;
};

// remove peer from all mappings
for topic in &peer.topics {
// check the mesh for the topic
if let Some(mesh_peers) = self.mesh.get_mut(topic) {
// check if the peer is in the mesh and remove it
if mesh_peers.remove(&peer_id) {
if let Some(m) = self.metrics.as_mut() {
m.peers_removed(topic, Churn::Dc, 1);
m.set_mesh_peers(topic, mesh_peers.len());
}
};
}

if let Some(m) = self.metrics.as_mut() {
m.dec_topic_peers(topic);
}
let peer = self
.connected_peers
.get(&peer_id)
.expect("Peer should exist in the connected_peers");

// remove peer from all mappings
for topic in &peer.topics {
// check the mesh for the topic
if let Some(mesh_peers) = self.mesh.get_mut(topic) {
// check if the peer is in the mesh and remove it
if mesh_peers.remove(&peer_id) {
if let Some(m) = self.metrics.as_mut() {
m.peers_removed(topic, Churn::Dc, 1);
m.set_mesh_peers(topic, mesh_peers.len());
}
};
}

// remove from fanout
self.fanout
.get_mut(topic)
.map(|peers| peers.remove(&peer_id));
if let Some(m) = self.metrics.as_mut() {
m.dec_topic_peers(topic);
}

// remove from fanout
self.fanout
.get_mut(topic)
.map(|peers| peers.remove(&peer_id));
}

// Forget px and outbound status for this peer
Expand Down Expand Up @@ -3042,6 +3037,7 @@ where
// Add the new connection
connected_peer.connections.push(connection_id);

tracing::debug!(%peer_id, "Established inbound connection to peer");
Ok(Handler::new(
self.config.protocol_config(),
connected_peer.sender.new_receiver(),
Expand Down Expand Up @@ -3072,6 +3068,7 @@ where
// Add the new connection
connected_peer.connections.push(connection_id);

tracing::debug!(%peer_id, "Established outbound connection to peer");
Ok(Handler::new(
self.config.protocol_config(),
connected_peer.sender.new_receiver(),
Expand Down

0 comments on commit 6b7e34c

Please sign in to comment.