Skip to content

Commit e7ea696

Browse files
authored
More gossipsub metrics (#6873)
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.
1 parent 6973184 commit e7ea696

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

beacon_node/lighthouse_network/gossipsub/src/behaviour.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1841,6 +1841,30 @@ where
18411841
peer_score.duplicated_message(propagation_source, &msg_id, &message.topic);
18421842
}
18431843
self.mcache.observe_duplicate(&msg_id, propagation_source);
1844+
// track metrics for the source of the duplicates
1845+
if let Some(metrics) = self.metrics.as_mut() {
1846+
if self
1847+
.mesh
1848+
.get(&message.topic)
1849+
.is_some_and(|peers| peers.contains(propagation_source))
1850+
{
1851+
// duplicate was received from a mesh peer
1852+
metrics.mesh_duplicates(&message.topic);
1853+
} else if self
1854+
.gossip_promises
1855+
.contains_peer(&msg_id, propagation_source)
1856+
{
1857+
// duplicate was received from an iwant request
1858+
metrics.iwant_duplicates(&message.topic);
1859+
} else {
1860+
tracing::warn!(
1861+
messsage=%msg_id,
1862+
peer=%propagation_source,
1863+
topic=%message.topic,
1864+
"Peer should not have sent message"
1865+
);
1866+
}
1867+
}
18441868
return;
18451869
}
18461870

beacon_node/lighthouse_network/gossipsub/src/gossip_promises.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ impl GossipPromises {
4141
self.promises.contains_key(message)
4242
}
4343

44+
/// Returns true if the message id exists in the promises and contains the given peer.
45+
pub(crate) fn contains_peer(&self, message: &MessageId, peer: &PeerId) -> bool {
46+
self.promises
47+
.get(message)
48+
.is_some_and(|peers| peers.contains_key(peer))
49+
}
50+
4451
///Get the peers we sent IWANT the input message id.
4552
pub(crate) fn peers_for_message(&self, message_id: &MessageId) -> Vec<PeerId> {
4653
self.promises

beacon_node/lighthouse_network/gossipsub/src/metrics.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,12 @@ pub(crate) struct Metrics {
194194
/// Number of full messages we received that we previously sent a IDONTWANT for.
195195
idontwant_messages_ignored_per_topic: Family<TopicHash, Counter>,
196196

197+
/// Count of duplicate messages we have received from mesh peers for a given topic.
198+
mesh_duplicates: Family<TopicHash, Counter>,
199+
200+
/// Count of duplicate messages we have received from by requesting them over iwant for a given topic.
201+
iwant_duplicates: Family<TopicHash, Counter>,
202+
197203
/// The size of the priority queue.
198204
priority_queue_size: Histogram,
199205
/// The size of the non-priority queue.
@@ -359,6 +365,16 @@ impl Metrics {
359365
"IDONTWANT messages that were sent but we received the full message regardless"
360366
);
361367

368+
let mesh_duplicates = register_family!(
369+
"mesh_duplicates_per_topic",
370+
"Count of duplicate messages received from mesh peers per topic"
371+
);
372+
373+
let iwant_duplicates = register_family!(
374+
"iwant_duplicates_per_topic",
375+
"Count of duplicate messages received from non-mesh peers that we sent iwants for"
376+
);
377+
362378
let idontwant_bytes = {
363379
let metric = Counter::default();
364380
registry.register(
@@ -425,6 +441,8 @@ impl Metrics {
425441
idontwant_msgs_ids,
426442
idontwant_messages_sent_per_topic,
427443
idontwant_messages_ignored_per_topic,
444+
mesh_duplicates,
445+
iwant_duplicates,
428446
priority_queue_size,
429447
non_priority_queue_size,
430448
}
@@ -597,6 +615,20 @@ impl Metrics {
597615
}
598616
}
599617

618+
/// Register a duplicate message received from a mesh peer.
619+
pub(crate) fn mesh_duplicates(&mut self, topic: &TopicHash) {
620+
if self.register_topic(topic).is_ok() {
621+
self.mesh_duplicates.get_or_create(topic).inc();
622+
}
623+
}
624+
625+
/// Register a duplicate message received from a non-mesh peer on an iwant request.
626+
pub(crate) fn iwant_duplicates(&mut self, topic: &TopicHash) {
627+
if self.register_topic(topic).is_ok() {
628+
self.iwant_duplicates.get_or_create(topic).inc();
629+
}
630+
}
631+
600632
pub(crate) fn register_msg_validation(
601633
&mut self,
602634
topic: &TopicHash,

0 commit comments

Comments
 (0)