Skip to content

Commit d5d2243

Browse files
authored
fix: bring back default topic in config (#1902)
* fix: bring back default topic in config * fix * Fix a bug * Fix enr creation
1 parent b785b6b commit d5d2243

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

apps/wakunode2/app.nim

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,16 +135,16 @@ proc init*(T: type App, rng: ref HmacDrbgContext, conf: WakuNodeConf): T =
135135
error "failed to parse content topic", error=res.error
136136
quit(QuitFailure)
137137

138-
let pubsubTopicsRes = contentTopicsRes.mapIt(singleHighestWeigthShard(it.get()))
138+
let shardsRes = contentTopicsRes.mapIt(singleHighestWeigthShard(it.get()))
139139

140-
for res in pubsubTopicsRes:
140+
for res in shardsRes:
141141
if res.isErr():
142142
error "failed to shard content topic", error=res.error
143143
quit(QuitFailure)
144144

145-
let pubsubTopics = pubsubTopicsRes.mapIt($it.get())
145+
let shards = shardsRes.mapIt($it.get())
146146

147-
let topics = pubsubTopics & conf.pubsubTopics
147+
let topics = conf.topics & conf.pubsubTopics & shards
148148

149149
let addShardedTopics = enrBuilder.withShardedTopics(topics)
150150
if addShardedTopics.isErr():
@@ -360,7 +360,12 @@ proc setupProtocols(node: WakuNode,
360360
peerExchangeHandler = some(handlePeerExchange)
361361

362362
if conf.relay:
363-
let pubsubTopics = conf.pubsubTopics
363+
# TODO autoshard content topics only once.
364+
# Already checked for errors in app.init
365+
let contentTopics = conf.contentTopics.mapIt(NsContentTopic.parse(it).expect("Parsing"))
366+
let shards = contentTopics.mapIt($(singleHighestWeigthShard(it).expect("Sharding")))
367+
368+
let pubsubTopics = conf.topics & conf.pubsubTopics & shards
364369
try:
365370
await mountRelay(node, pubsubTopics, peerExchangeHandler = peerExchangeHandler)
366371
except CatchableError:

apps/wakunode2/external_config.nim

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,13 @@ type
225225
defaultValue: false
226226
name: "keep-alive" }: bool
227227

228+
topics* {.
229+
desc: "Default topic to subscribe to. Argument may be repeated. Deprecated! Please use pubsub-topic and/or content-topic instead."
230+
defaultValue: @["/waku/2/default-waku/proto"]
231+
name: "topic" .}: seq[string]
232+
228233
pubsubTopics* {.
229234
desc: "Default pubsub topic to subscribe to. Argument may be repeated."
230-
defaultValue: @["/waku/2/default-waku/proto"]
231235
name: "pubsub-topic" .}: seq[string]
232236

233237
contentTopics* {.

tests/wakunode2/test_app.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ proc defaultTestWakuNodeConf(): WakuNodeConf =
2323
metricsServerAddress: ValidIpAddress.init("127.0.0.1"),
2424
nat: "any",
2525
maxConnections: 50,
26-
pubsubTopics: @["/waku/2/default-waku/proto"],
26+
topics: @["/waku/2/default-waku/proto"],
2727
relay: true
2828
)
2929

0 commit comments

Comments
 (0)