fixed misconfigured network shards

This commit is contained in:
Gabriel mermelstein 2024-06-06 18:34:08 +02:00
parent 54cc122801
commit 2e3dd360f2
No known key found for this signature in database
GPG Key ID: 82B8134785FEAE0D
2 changed files with 11 additions and 6 deletions

View File

@ -110,6 +110,12 @@ proc initNode(
## Mount protocols
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)
proc setupProtocols(
node: WakuNode, conf: WakuNodeConf, nodeKey: crypto.PrivateKey
): Future[Result[void, string]] {.async.} =
@ -121,9 +127,7 @@ proc setupProtocols(
return err("failed to mount waku metadata protocol: " & error)
# If conf.networkShards is not set, use the number of shards configured as networkShards
var networkShards = conf.networkShards
if networkShards == uint32(0):
networkShards = uint32(conf.shards.len)
let networkShards = getNetworkShards(conf)
node.mountSharding(conf.clusterId, networkShards).isOkOr:
return err("failed to mount waku sharding: " & error)

View File

@ -87,10 +87,11 @@ func version*(waku: Waku): string =
waku.version
proc validateShards(conf: WakuNodeConf): Result[void, string] =
let networkShards = getNetworkShards(conf)
for shard in conf.shards:
if shard >= conf.networkShards:
let msg =
"Invalid shard: " & $shard & " when networkShards: " & $conf.networkShards
if shard >= networkShards:
let msg = "Invalid shard: " & $shard & " when networkShards: " & $networkShards
# fmt doesn't work
error "validateShards failed", error = msg
return err(msg)