diff --git a/waku/factory/node_factory.nim b/waku/factory/node_factory.nim index 3833acc2e..beba611cb 100644 --- a/waku/factory/node_factory.nim +++ b/waku/factory/node_factory.nim @@ -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) diff --git a/waku/factory/waku.nim b/waku/factory/waku.nim index e671e7c5a..006d810ed 100644 --- a/waku/factory/waku.nim +++ b/waku/factory/waku.nim @@ -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)