Skip to content

Commit

Permalink
fixing shards validation
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielmer committed Aug 28, 2024
1 parent 05dafd7 commit 471bb6d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
5 changes: 3 additions & 2 deletions waku/factory/external_config.nim
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,9 @@ type WakuNodeConf* = object
name: "keep-alive"
.}: bool

networkShards* {.desc: "Number of shards in the network", name: "network-shards".}:
uint32
networkShards* {.
desc: "Number of shards in the network", defaultValue: 0, name: "network-shards"
.}: uint32

pubsubTopics* {.
desc:
Expand Down
2 changes: 1 addition & 1 deletion waku/factory/node_factory.nim
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ proc getNetworkShards*(conf: WakuNodeConf): uint32 =
if conf.networkShards != 0:
return conf.networkShards
# If conf.networkShards is not set, use the number of shards configured as networkShards
return uint32(conf.shards.len)
return uint32(max(conf.shards) + 1)

proc setupProtocols(
node: WakuNode, conf: WakuNodeConf, nodeKey: crypto.PrivateKey
Expand Down
7 changes: 6 additions & 1 deletion waku/factory/waku.nim
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ proc init*(T: type Waku, conf: WakuNodeConf): Result[Waku, string] =

if shardsOpt.isSome():
let relayShards = shardsOpt.get()
if relayShards.clusterId != conf.clusterId:
error "clusterId of the pubsub topic should match the node's cluster",
nodeCluster = conf.clusterId, pubsubCluster = relayShards.clusterId
return err("clusterId of the pubsub topic should match the node's cluster")

for shard in relayShards.shardIds:
shards.add(shard)
confCopy.shards = shards
Expand Down Expand Up @@ -149,7 +154,7 @@ proc init*(T: type Waku, conf: WakuNodeConf): Result[Waku, string] =
info "Running nwaku node", version = git_version
logConfig(confCopy)

let validateShardsRes = validateShards(conf)
let validateShardsRes = validateShards(confCopy)
if validateShardsRes.isErr():
error "Failed validating shards", error = $validateShardsRes.error
return err("Failed validating shards: " & $validateShardsRes.error)
Expand Down

0 comments on commit 471bb6d

Please sign in to comment.