Skip to content

Commit

Permalink
litep2p: Increment random walk metrics (paritytech#4929)
Browse files Browse the repository at this point in the history
This PR exposes the `RandomKademliaStarted` event from the litep2p
network backend, and then increments the appropriate metrics.

This is part of: paritytech#4681.
However, it is more of an effort to debug low peer count 

### Testing Done
- Started a node and fetched queries:
`substrate_sub_libp2p_kademlia_random_queries_total` produces results
for litep2p backend

cc @paritytech/networking

---------

Signed-off-by: Alexandru Vasile <[email protected]>
  • Loading branch information
lexnv authored and TomaszWaszczyk committed Jul 7, 2024
1 parent 5b88256 commit b77d20b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions substrate/client/network/src/litep2p/discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ pub enum DiscoveryEvent {
/// Record.
record: Record,
},

/// Started a random Kademlia query.
RandomKademliaStarted,
}

/// Discovery.
Expand Down Expand Up @@ -456,6 +459,7 @@ impl Stream for Discovery {
match this.kademlia_handle.try_find_node(peer) {
Ok(query_id) => {
this.find_node_query_id = Some(query_id);
return Poll::Ready(Some(DiscoveryEvent::RandomKademliaStarted))
},
Err(()) => {
this.duration_to_next_find_query = cmp::min(
Expand Down
6 changes: 6 additions & 0 deletions substrate/client/network/src/litep2p/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,12 @@ impl<B: BlockT + 'static, H: ExHashT> NetworkBackend<B, H> for Litep2pNetworkBac
expires,
)
));
},

Some(DiscoveryEvent::RandomKademliaStarted) => {
if let Some(metrics) = self.metrics.as_ref() {
metrics.kademlia_random_queries_total.inc();
}
}
},
event = self.litep2p.next_event() => match event {
Expand Down

0 comments on commit b77d20b

Please sign in to comment.