From 48acff4a5cff96c27a4d2e1c1b6a3768078e2c87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?rich=CE=9Brd?= Date: Mon, 30 Oct 2023 19:20:13 -0400 Subject: [PATCH] feat: add warning about bootnodes not supporting shards (#848) --- waku/v2/discv5/discover.go | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/waku/v2/discv5/discover.go b/waku/v2/discv5/discover.go index e723d20e..95bb8c78 100644 --- a/waku/v2/discv5/discover.go +++ b/waku/v2/discv5/discover.go @@ -379,9 +379,8 @@ func delayedHasNext(ctx context.Context, iterator enode.Iterator) bool { return true } -// Iterates over the nodes found via discv5 belonging to the node's current shard, and sends them to peerConnector -func (d *DiscoveryV5) peerLoop(ctx context.Context) error { - iterator, err := d.PeerIterator(FilterPredicate(func(n *enode.Node) bool { +func (d *DiscoveryV5) defaultPredicate() Predicate { + return FilterPredicate(func(n *enode.Node) bool { localRS, err := wenr.RelaySharding(d.localnode.Node().Record()) if err != nil { return false @@ -413,7 +412,12 @@ func (d *DiscoveryV5) peerLoop(ctx context.Context) error { } return false - })) + }) +} + +// Iterates over the nodes found via discv5 belonging to the node's current shard, and sends them to peerConnector +func (d *DiscoveryV5) peerLoop(ctx context.Context) error { + iterator, err := d.PeerIterator(d.defaultPredicate()) if err != nil { d.metrics.RecordError(iteratorFailure) return fmt.Errorf("obtaining iterator: %w", err) @@ -441,6 +445,20 @@ func (d *DiscoveryV5) peerLoop(ctx context.Context) error { } func (d *DiscoveryV5) runDiscoveryV5Loop(ctx context.Context) { + if len(d.config.Bootnodes) > 0 { + localRS, err := wenr.RelaySharding(d.localnode.Node().Record()) + if err == nil && localRS != nil { + iterator := d.defaultPredicate()(enode.IterNodes(d.config.Bootnodes)) + validBootCount := 0 + for iterator.Next() { + validBootCount++ + } + + if validBootCount == 0 { + d.log.Warn("no discv5 bootstrap nodes share this node configured shards") + } + } + } restartLoop: for {