Skip to content

Commit

Permalink
adding temporary support to pubsub topics
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielmer committed Aug 28, 2024
1 parent 240b70a commit 05dafd7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 36 deletions.
7 changes: 7 additions & 0 deletions waku/factory/external_config.nim
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,13 @@ type WakuNodeConf* = object
networkShards* {.desc: "Number of shards in the network", name: "network-shards".}:
uint32

pubsubTopics* {.
desc:
"Deprecated. Default pubsub topic to subscribe to. Argument may be repeated.",
defaultValue: @[],
name: "pubsub-topic"
.}: seq[string]

shards* {.
desc: "Shards index to subscribe to [0..MAX_SHARDS-1]. Argument may be repeated.",
defaultValue:
Expand Down
29 changes: 1 addition & 28 deletions waku/factory/internal_config.nim
Original file line number Diff line number Diff line change
Expand Up @@ -28,35 +28,8 @@ proc enrConfiguration*(

enrBuilder.withMultiaddrs(netConfig.enrMultiaddrs)

var shards = newSeq[uint16]()

# Only for dev purposes. After everything compiles, remove this block and uncomment the one below
let shardsOpt = topicsToRelayShards(@["/waku/2/rs/0/0"]).valueOr:
error "failed to parse pubsub topic, please format according to static shard specification",
error = $error
return err("failed to parse pubsub topic: " & $error)

#[ let shardsOpt = topicsToRelayShards(conf.pubsubTopics).valueOr:
error "failed to parse pubsub topic, please format according to static shard specification",
error = $error
return err("failed to parse pubsub topic: " & $error) ]#

if shardsOpt.isSome():
let relayShards = shardsOpt.get()

if relayShards.clusterid != conf.clusterId:
error "pubsub topic corresponds to different shard than configured",
nodeCluster = conf.clusterId, pubsubCluster = relayShards.clusterid
return err("pubsub topic corresponds to different shard than configured")

shards = relayShards.shardIds
elif conf.shards.len > 0:
shards = toSeq(conf.shards.mapIt(uint16(it)))
else:
info "no pubsub topics specified"

enrBuilder.withWakuRelaySharding(
RelayShards(clusterId: conf.clusterId, shardIds: shards)
RelayShards(clusterId: conf.clusterId, shardIds: conf.shards)
).isOkOr:
return err("could not initialize ENR with shards")

Expand Down
19 changes: 11 additions & 8 deletions waku/factory/waku.nim
Original file line number Diff line number Diff line change
Expand Up @@ -104,18 +104,21 @@ proc init*(T: type Waku, conf: WakuNodeConf): Result[Waku, string] =
logging.setupLog(conf.logLevel, conf.logFormat)

# TODO: remove after pubsubtopic config gets removed
#[ let shards = newSeq[uint16]()
if conf.pubsubTopics.length > 0:
let shardsOpt = topicsToRelayShards(conf.pubsubTopics).valueOr:
var shards = newSeq[uint16]()
if conf.pubsubTopics.len > 0:
let shardsRes = topicsToRelayShards(conf.pubsubTopics)
if shardsRes.isErr():
error "failed to parse pubsub topic, please format according to static shard specification",
error = $error
return err("failed to parse pubsub topic: " & $error)
error = shardsRes.error
return err("failed to parse pubsub topic: " & $shardsRes.error)

let shardsOpt = shardsRes.get()

if shardsOpt.isSome():
let relayShards = shardsOpt.get()
for shard in relayShards:
shards.add(shard.shardId)
confCopy.shards = shards ]#
for shard in relayShards.shardIds:
shards.add(shard)
confCopy.shards = shards

case confCopy.clusterId

Expand Down

0 comments on commit 05dafd7

Please sign in to comment.