Skip to content

Commit

Permalink
fix: allow mixing named and static shards
Browse files Browse the repository at this point in the history
  • Loading branch information
richard-ramos committed Aug 31, 2023
1 parent 229fb7a commit 28e4494
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
11 changes: 10 additions & 1 deletion waku/v2/discv5/discover.go
Original file line number Diff line number Diff line change
Expand Up @@ -452,11 +452,20 @@ func (d *DiscoveryV5) peerLoop(ctx context.Context) error {
return true
}

// TODO: if

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

0 comments on commit 28e4494

Please sign in to comment.