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 {