From 70cb6de5765e51b4388e50250df87fecf794ece8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?rich=CE=9Brd?= Date: Wed, 8 Nov 2023 12:03:08 -0400 Subject: [PATCH] fix: noisy peer exchange log (#881) --- waku/v2/protocol/peer_exchange/enr_cache.go | 6 +++++- waku/v2/protocol/peer_exchange/protocol.go | 13 +++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/waku/v2/protocol/peer_exchange/enr_cache.go b/waku/v2/protocol/peer_exchange/enr_cache.go index 470d6845..06538d2b 100644 --- a/waku/v2/protocol/peer_exchange/enr_cache.go +++ b/waku/v2/protocol/peer_exchange/enr_cache.go @@ -9,6 +9,7 @@ import ( "github.com/ethereum/go-ethereum/p2p/enode" "github.com/hashicorp/golang-lru/simplelru" "github.com/waku-org/go-waku/waku/v2/protocol/peer_exchange/pb" + "go.uber.org/zap" ) // simpleLRU internal uses container/list, which is ring buffer(double linked list) @@ -17,14 +18,16 @@ type enrCache struct { data *simplelru.LRU rng *rand.Rand mu sync.RWMutex + log *zap.Logger } // err on negative size -func newEnrCache(size int) (*enrCache, error) { +func newEnrCache(size int, log *zap.Logger) (*enrCache, error) { inner, err := simplelru.NewLRU(size, nil) return &enrCache{ data: inner, rng: rand.New(rand.NewSource(rand.Int63())), + log: log.Named("enr-cache"), }, err } @@ -35,6 +38,7 @@ func (c *enrCache) updateCache(node *enode.Node) { currNode, ok := c.data.Get(node.ID()) if !ok || node.Seq() > currNode.(*enode.Node).Seq() { c.data.Add(node.ID(), node) + c.log.Debug("discovered px peer via discv5", zap.Stringer("enr", node)) } } diff --git a/waku/v2/protocol/peer_exchange/protocol.go b/waku/v2/protocol/peer_exchange/protocol.go index 5b1834f1..e8af91c5 100644 --- a/waku/v2/protocol/peer_exchange/protocol.go +++ b/waku/v2/protocol/peer_exchange/protocol.go @@ -53,19 +53,21 @@ type WakuPeerExchange struct { // Takes an optional peermanager if WakuPeerExchange is being created along with WakuNode. // If using libp2p host, then pass peermanager as nil func NewWakuPeerExchange(disc *discv5.DiscoveryV5, peerConnector PeerConnector, pm *peermanager.PeerManager, reg prometheus.Registerer, log *zap.Logger) (*WakuPeerExchange, error) { - newEnrCache, err := newEnrCache(MaxCacheSize) - if err != nil { - return nil, err - } wakuPX := new(WakuPeerExchange) wakuPX.disc = disc wakuPX.metrics = newMetrics(reg) wakuPX.log = log.Named("wakupx") - wakuPX.enrCache = newEnrCache wakuPX.peerConnector = peerConnector wakuPX.pm = pm wakuPX.CommonService = service.NewCommonService() + newEnrCache, err := newEnrCache(MaxCacheSize, wakuPX.log) + if err != nil { + return nil, err + } + + wakuPX.enrCache = newEnrCache + return wakuPX, nil } @@ -159,7 +161,6 @@ func (wakuPX *WakuPeerExchange) iterate(ctx context.Context) error { continue } - wakuPX.log.Debug("Discovered px peers via discv5") wakuPX.enrCache.updateCache(iterator.Node()) select {