Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow mixing named and static shards #699

Merged
merged 1 commit into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion waku/v2/discv5/discover.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,10 +453,17 @@ func (d *DiscoveryV5) peerLoop(ctx context.Context) error {
}

nodeRS, err := wenr.RelaySharding(n.Record())
if err != nil || nodeRS == nil {
if err != nil {
return false
}

if nodeRS == nil {
// TODO: Node has no shard registered.
// Since for now, status-go uses both mixed static and named shards, we assume the node is valid
// Once status-go uses only static shards, we can't return true anymore.
return true
}

if nodeRS.Cluster != localRS.Cluster {
return false
}
Expand Down
15 changes: 5 additions & 10 deletions waku/v2/node/localnode.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,22 +315,17 @@ func (w *WakuNode) watchTopicShards(ctx context.Context) error {

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"))
w.log.Warn("could not set ENR shard info", zap.String("error", "multiple clusters found, use sharded topics within the same cluster"))
continue
}
}

if len(rs) == 1 {
w.log.Info("updating advertised relay shards in ENR")
if len(rs[0].Indices) != len(topics) {
w.log.Warn("A mix of named and static shards found. ENR shard will contain only the following shards", zap.Any("shards", rs[0]))
}

err = wenr.Update(w.localNode, wenr.WithWakuRelaySharding(rs[0]))
if err != nil {
w.log.Warn("could not set ENR shard info", zap.Error(err))
Expand Down
4 changes: 2 additions & 2 deletions waku/v2/protocol/shard.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ const ClusterIndex = 1
const GenerationZeroShardsCount = 8

type RelayShards struct {
Cluster uint16
Indices []uint16
Cluster uint16 `json:"cluster"`
Indices []uint16 `json:"indices"`
}

func NewRelayShards(cluster uint16, indices ...uint16) (RelayShards, error) {
Expand Down
Loading