You can enable periodic inspection of peer scores in a GossipSub router using the WithPeerScoreInspect option. This is useful for debugging how peers are being scored and identifying potential issues with peer behavior or scoring parameters.
There are two ways to provide an inspector:
- Simple Inspection: Provide a function with the signature
PeerScoreInspectFn, which receives a map[peer.ID]float64 containing the current score for each peer. - Extended Inspection: Provide a function with the signature
ExtendedPeerScoreInspectFn, which receives a map[peer.ID]*PeerScoreSnapshot. This allows you to inspect individual components of the score, such as topic-specific stats, IP colocation factors, and behavioral penalties.
Note: WithPeerScoreInspect must be passed after the WithPeerScore option in your router configuration.
// Example using ExtendedPeerScoreInspectFn
inspector := func(scores map[peer.ID]*pubsub.PeerScoreSnapshot) {
for id, snapshot := range scores {
fmt.Printf("Peer %s score: %f (IP Colocation: %f)\n", id, snapshot.Score, snapshot.IPColocationFactor)
}
}
// When initializing your PubSub/GossipSub router:
// ps, err := pubsub.NewGossipSub(host,
// pubsub.WithPeerScore(params),
// pubsub.WithPeerScoreInspect(inspector, 10*time.Second),
// )