Skip to content

Commit

Permalink
More gossipsub metrics (#6873)
Browse files Browse the repository at this point in the history
N/A


  Add metrics that tell us if a duplicate message that we received was from a mesh peer or from a non mesh peer that we requested with iwant message.
  • Loading branch information
pawanjay176 authored Jan 29, 2025
1 parent 6973184 commit e7ea696
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
24 changes: 24 additions & 0 deletions beacon_node/lighthouse_network/gossipsub/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1841,6 +1841,30 @@ where
peer_score.duplicated_message(propagation_source, &msg_id, &message.topic);
}
self.mcache.observe_duplicate(&msg_id, propagation_source);
// track metrics for the source of the duplicates
if let Some(metrics) = self.metrics.as_mut() {
if self
.mesh
.get(&message.topic)
.is_some_and(|peers| peers.contains(propagation_source))
{
// duplicate was received from a mesh peer
metrics.mesh_duplicates(&message.topic);
} else if self
.gossip_promises
.contains_peer(&msg_id, propagation_source)
{
// duplicate was received from an iwant request
metrics.iwant_duplicates(&message.topic);
} else {
tracing::warn!(
messsage=%msg_id,
peer=%propagation_source,
topic=%message.topic,
"Peer should not have sent message"
);
}
}
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ impl GossipPromises {
self.promises.contains_key(message)
}

/// Returns true if the message id exists in the promises and contains the given peer.
pub(crate) fn contains_peer(&self, message: &MessageId, peer: &PeerId) -> bool {
self.promises
.get(message)
.is_some_and(|peers| peers.contains_key(peer))
}

///Get the peers we sent IWANT the input message id.
pub(crate) fn peers_for_message(&self, message_id: &MessageId) -> Vec<PeerId> {
self.promises
Expand Down
32 changes: 32 additions & 0 deletions beacon_node/lighthouse_network/gossipsub/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,12 @@ pub(crate) struct Metrics {
/// Number of full messages we received that we previously sent a IDONTWANT for.
idontwant_messages_ignored_per_topic: Family<TopicHash, Counter>,

/// Count of duplicate messages we have received from mesh peers for a given topic.
mesh_duplicates: Family<TopicHash, Counter>,

/// Count of duplicate messages we have received from by requesting them over iwant for a given topic.
iwant_duplicates: Family<TopicHash, Counter>,

/// The size of the priority queue.
priority_queue_size: Histogram,
/// The size of the non-priority queue.
Expand Down Expand Up @@ -359,6 +365,16 @@ impl Metrics {
"IDONTWANT messages that were sent but we received the full message regardless"
);

let mesh_duplicates = register_family!(
"mesh_duplicates_per_topic",
"Count of duplicate messages received from mesh peers per topic"
);

let iwant_duplicates = register_family!(
"iwant_duplicates_per_topic",
"Count of duplicate messages received from non-mesh peers that we sent iwants for"
);

let idontwant_bytes = {
let metric = Counter::default();
registry.register(
Expand Down Expand Up @@ -425,6 +441,8 @@ impl Metrics {
idontwant_msgs_ids,
idontwant_messages_sent_per_topic,
idontwant_messages_ignored_per_topic,
mesh_duplicates,
iwant_duplicates,
priority_queue_size,
non_priority_queue_size,
}
Expand Down Expand Up @@ -597,6 +615,20 @@ impl Metrics {
}
}

/// Register a duplicate message received from a mesh peer.
pub(crate) fn mesh_duplicates(&mut self, topic: &TopicHash) {
if self.register_topic(topic).is_ok() {
self.mesh_duplicates.get_or_create(topic).inc();
}
}

/// Register a duplicate message received from a non-mesh peer on an iwant request.
pub(crate) fn iwant_duplicates(&mut self, topic: &TopicHash) {
if self.register_topic(topic).is_ok() {
self.iwant_duplicates.get_or_create(topic).inc();
}
}

pub(crate) fn register_msg_validation(
&mut self,
topic: &TopicHash,
Expand Down

0 comments on commit e7ea696

Please sign in to comment.