mirror of
https://github.com/status-im/go-waku.git
synced 2025-01-13 23:34:54 +00:00
fix: noisy peer exchange log (#881)
This commit is contained in:
parent
286f760c97
commit
70cb6de576
@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user