Skip to content

Commit

Permalink
logs/metrics adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
iurii-ssv committed Dec 2, 2024
1 parent 9a2a4df commit 8d38f87
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
6 changes: 5 additions & 1 deletion network/discovery/dv5_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ import (
"github.com/ssvlabs/ssv/networkconfig"
)

// metrics to keep track of discovered/connected/disconnected peers (per subnet)
// metrics to keep track of discovered/connected/disconnected peers (per subnet), note
// these hold stats across all 128 subnets (not just the ones we are interested in).
// For example, if ConnectedSubnets will contain/maintain a list of peers even for subnets
// that are irrelevant for us (they are just there to reflect what subnets each peer
// we connected to offers)
var (
Discovered1stTimeSubnets = hashmap.New[int, int64]()
Connected1stTimeSubnets = hashmap.New[int, int64]()
Expand Down
7 changes: 5 additions & 2 deletions network/p2p/p2p.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,8 @@ func (n *p2pNetwork) Start(logger *zap.Logger) error {
go n.startDiscovery(logger, connector)

async.Interval(n.ctx, 1*time.Minute, func() {
logger.Debug("discovered subnets 1st", zap.Int("total", discovery.Discovered1stTimeSubnets.SlowLen()))
logger.Debug("connected subnets 1st", zap.Int("total", discovery.Connected1stTimeSubnets.SlowLen()))
logger.Debug("discovered subnets 1st time", zap.Int("total", discovery.Discovered1stTimeSubnets.SlowLen()))
logger.Debug("connected subnets 1st time", zap.Int("total", discovery.Connected1stTimeSubnets.SlowLen()))

// check how peer-discovery is doing
discovery.DiscoveredSubnets.Range(func(subnet int, peerIDs []peer.ID) bool {
Expand All @@ -282,6 +282,9 @@ func (n *p2pNetwork) Start(logger *zap.Logger) error {
// internet not working on the routes we are trying to use)
// - us deliberately choosing peers we connect to in suboptimal manner due to max peer limit
// we have (dropping those that are needed for this subnet to work)
// - if (assuming peer handshake happens before a connection is considered "established") peer
// no longer has subnets we are interested in as per the check done during handshake (even
// though he advertised)
connectedPeerIDs, ok := discovery.ConnectedSubnets.Get(subnet)
if !ok || len(connectedPeerIDs) < 2 {
logger.Debug(
Expand Down
4 changes: 4 additions & 0 deletions network/peers/connections/conn_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ func (ch *connHandler) Handle(logger *zap.Logger) *libp2pnetwork.NotifyBundle {
// unexpectedPeer helps us track whether the peer connection we are making is due
// to us discovering this peer previously (due to looking for peers with subnets
// we are interested in), or whether we are connecting to some "unexpected" peer
// TODO - we should also account for `trustedPeers` here, I need to check how this
// list is derived - but it seems to always be 0 (based on what logs report)
unexpectedPeer := true
discovery.DiscoveredSubnets.Range(func(subnet int, peerIDs []peer.ID) bool {
otherPeers := make([]peer.ID, 0, len(peerIDs))
Expand Down Expand Up @@ -301,6 +303,8 @@ func (ch *connHandler) Handle(logger *zap.Logger) *libp2pnetwork.NotifyBundle {
// unexpectedPeer helps us track whether the peer we've disconnected is a peer
// that's been connected previously through the process of subnet-discovery,
// it's just a sanity check
// TODO - we should also account for `trustedPeers` here, I need to check how this
// list is derived - but it seems to always be 0 (based on what logs report)
unexpectedPeer := true
discovery.ConnectedSubnets.Range(func(subnet int, peerIDs []peer.ID) bool {
otherPeers := make([]peer.ID, 0, len(peerIDs))
Expand Down

0 comments on commit 8d38f87

Please sign in to comment.