Skip to content

Commit

Permalink
changing networkShards to numShardsInNetwork
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielmer committed Aug 29, 2024
1 parent ddd03bb commit a5a10b5
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 20 deletions.
4 changes: 2 additions & 2 deletions apps/networkmonitor/networkmonitor.nim
Original file line number Diff line number Diff line change
Expand Up @@ -567,10 +567,10 @@ when isMainModule:
conf.rlnRelayEthContractAddress = twnClusterConf.rlnRelayEthContractAddress
conf.rlnEpochSizeSec = twnClusterConf.rlnEpochSizeSec
conf.rlnRelayUserMessageLimit = twnClusterConf.rlnRelayUserMessageLimit
conf.networkShards = twnClusterConf.networkShards
conf.numShardsInNetwork = twnClusterConf.numShardsInNetwork

if conf.shards.len == 0:
conf.shards = toSeq(uint16(0) .. uint16(twnClusterConf.networkShards - 1))
conf.shards = toSeq(uint16(0) .. uint16(twnClusterConf.numShardsInNetwork - 1))

if conf.logLevel != LogLevel.NONE:
setLogLevel(conf.logLevel)
Expand Down
5 changes: 3 additions & 2 deletions apps/networkmonitor/networkmonitor_config.nim
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ type NetworkMonitorConf* = object
name: "shard"
.}: seq[uint16]

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

refreshInterval* {.
desc: "How often new peers are discovered and connected to (in seconds)",
Expand Down
7 changes: 5 additions & 2 deletions waku/factory/external_config.nim
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,11 @@ type WakuNodeConf* = object
name: "keep-alive"
.}: bool

networkShards* {.
desc: "Number of shards in the network", defaultValue: 0, name: "network-shards"
# If numShardsInNetwork is not set, we use the number of shards configured as numShardsInNetwork
numShardsInNetwork* {.
desc: "Number of shards in the network",
defaultValue: 0,
name: "num-shards-in-network"
.}: uint32

pubsubTopics* {.
Expand Down
4 changes: 2 additions & 2 deletions waku/factory/networks_config.nim
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type ClusterConf* = object
rlnRelayBandwidthThreshold*: int
rlnEpochSizeSec*: uint64
rlnRelayUserMessageLimit*: uint64
networkShards*: uint32
numShardsInNetwork*: uint32
discv5Discovery*: bool
discv5BootstrapNodes*: seq[string]

Expand All @@ -28,7 +28,7 @@ proc TheWakuNetworkConf*(T: type ClusterConf): ClusterConf =
rlnRelayBandwidthThreshold: 0,
rlnEpochSizeSec: 600,
rlnRelayUserMessageLimit: 100,
networkShards: 8,
numShardsInNetwork: 8,
discv5Discovery: true,
discv5BootstrapNodes:
@[
Expand Down
14 changes: 7 additions & 7 deletions waku/factory/node_factory.nim
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,10 @@ 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
proc getNumShardsInNetwork*(conf: WakuNodeConf): uint32 =
if conf.numShardsInNetwork != 0:
return conf.numShardsInNetwork
# If conf.numShardsInNetwork is not set, use the number of shards configured as numShardsInNetwork
return uint32(max(conf.shards) + 1)

proc setupProtocols(
Expand All @@ -133,10 +133,10 @@ proc setupProtocols(
node.mountMetadata(conf.clusterId).isOkOr:
return err("failed to mount waku metadata protocol: " & error)

# If conf.networkShards is not set, use the number of shards configured as networkShards
let networkShards = getNetworkShards(conf)
# If conf.numShardsInNetwork is not set, use the number of shards configured as numShardsInNetwork
let numShardsInNetwork = getNumShardsInNetwork(conf)

node.mountSharding(conf.clusterId, networkShards).isOkOr:
node.mountSharding(conf.clusterId, numShardsInNetwork).isOkOr:
return err("failed to mount waku sharding: " & error)

# Mount relay on all nodes
Expand Down
10 changes: 5 additions & 5 deletions waku/factory/waku.nim
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,13 @@ func version*(waku: Waku): string =
waku.version

proc validateShards(conf: WakuNodeConf): Result[void, string] =
let networkShards = getNetworkShards(conf)
let numShardsInNetwork = getNumShardsInNetwork(conf)

for shard in conf.shards:
if shard >= networkShards:
if shard >= numShardsInNetwork:
let msg =
"validateShards invalid shard: " & $shard & " when networkShards: " &
$networkShards # fmt doesn't work
"validateShards invalid shard: " & $shard & " when numShardsInNetwork: " &
$numShardsInNetwork # fmt doesn't work
error "validateShards failed", error = msg
return err(msg)

Expand Down Expand Up @@ -149,7 +149,7 @@ proc init*(T: type Waku, conf: WakuNodeConf): Result[Waku, string] =
confCopy.discv5BootstrapNodes & twnClusterConf.discv5BootstrapNodes
confCopy.rlnEpochSizeSec = twnClusterConf.rlnEpochSizeSec
confCopy.rlnRelayUserMessageLimit = twnClusterConf.rlnRelayUserMessageLimit
confCopy.networkShards = twnClusterConf.networkShards
confCopy.numShardsInNetwork = twnClusterConf.numShardsInNetwork

# Only set rlnRelay to true if relay is configured
if confCopy.relay:
Expand Down

0 comments on commit a5a10b5

Please sign in to comment.