Consensys / teku

Open-source Ethereum consensus client written in Java
https://consensys.io/teku
Apache License 2.0
680 stars 286 forks source link

Expose p2p mesh gauge metric #8769

Open tbenr opened 1 month ago

tbenr commented 1 month ago

It could be interesting to have a metric(s) to track how many peers are in the p2p mesh of each subscribed topic. An addition to that could be to track how many peers "left" the mesh and how many peers "joined" the mesh between two sampling periods.

The problem is that currently the mesh is exposed gossipRouter.mesh() and it gives back the underlining mutable Map. Since that is a LinkedHashMap created via:

val mesh: MutableMap<Topic, MutableSet<PeerHandler>> = linkedMapOf()

and is not thread safe we can't safely access it to collect the data we want.

We need a more secure way of accessing the information (it could require a libp2p change)

Nashatyrev commented 4 weeks ago

Yep it would be good to have. I would even go further and log explanation whenever a peer score drops below some threshold(s). Here is the corresponding feature request: https://github.com/libp2p/jvm-libp2p/issues/393