From 8cac406a4c64e300710c4d104644ca806ba4e7db Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Thu, 6 Jul 2023 14:21:23 -0400 Subject: [PATCH] fix: warning message format when using static shards and named shards at same time --- waku/v2/node/localnode.go | 20 ++++++++++++++++---- waku/v2/protocol/shard.go | 5 +++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/waku/v2/node/localnode.go b/waku/v2/node/localnode.go index 93c1303e..22113125 100644 --- a/waku/v2/node/localnode.go +++ b/waku/v2/node/localnode.go @@ -305,15 +305,27 @@ func (w *WakuNode) watchTopicShards(ctx context.Context) error { return case <-evtRelayUnsubscribed.Out(): case <-evtRelaySubscribed.Out(): - rs, err := protocol.TopicsToRelayShards(w.Relay().Topics()...) + topics := w.Relay().Topics() + rs, err := protocol.TopicsToRelayShards(topics...) if err != nil { w.log.Warn("could not set ENR shard info", zap.Error(err)) continue } - if len(rs) > 1 { - w.log.Warn("use sharded topics within the same cluster") - continue + if len(rs) > 0 { + if len(rs) > 1 { + w.log.Warn("could not set ENR shard info", zap.String("error", "use sharded topics within the same cluster")) + continue + } + + tcount := 0 + for _, r := range rs { + tcount += len(r.Indices) + } + if tcount != len(topics) { + w.log.Warn("could not set ENR shard info", zap.String("error", "can't use a mix of static shards and named shards")) + continue + } } if len(rs) == 1 { diff --git a/waku/v2/protocol/shard.go b/waku/v2/protocol/shard.go index 5e0bc64c..4795524b 100644 --- a/waku/v2/protocol/shard.go +++ b/waku/v2/protocol/shard.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" "math" + "strings" ) const MaxShardIndex = uint16(1023) @@ -76,6 +77,10 @@ func TopicsToRelayShards(topic ...string) ([]RelayShards, error) { result := make([]RelayShards, 0) dict := make(map[uint16]map[uint16]struct{}) for _, t := range topic { + if !strings.HasPrefix(t, StaticShardingPubsubTopicPrefix) { + continue + } + var ps StaticShardingPubsubTopic err := ps.Parse(t) if err != nil {