fix: --topic should be ignore when using --pubsub-topic or --content-topic (#1977)

This commit is contained in:
Simon-Pierre Vivier 2023-08-31 16:13:45 -04:00 committed by GitHub
parent 7d37f2ec28
commit 037b166263
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 20 deletions

View File

@ -128,23 +128,19 @@ proc init*(T: type App, rng: ref HmacDrbgContext, conf: WakuNodeConf): T =
enrBuilder.withMultiaddrs(netConfig.enrMultiaddrs)
let contentTopicsRes = conf.contentTopics.mapIt(NsContentTopic.parse(it))
let topics =
if conf.pubsubTopics.len > 0 or conf.contentTopics.len > 0:
let shardsRes = conf.contentTopics.mapIt(getShard(it))
for res in shardsRes:
if res.isErr():
error "failed to shard content topic", error=res.error
quit(QuitFailure)
for res in contentTopicsRes:
if res.isErr():
error "failed to parse content topic", error=res.error
quit(QuitFailure)
let shards = shardsRes.mapIt(it.get())
let shardsRes = contentTopicsRes.mapIt(getShard(it.get()))
for res in shardsRes:
if res.isErr():
error "failed to shard content topic", error=res.error
quit(QuitFailure)
let shards = shardsRes.mapIt($it.get())
let topics = conf.topics & conf.pubsubTopics & shards
conf.pubsubTopics & shards
else:
conf.topics
let addShardedTopics = enrBuilder.withShardedTopics(topics)
if addShardedTopics.isErr():
@ -360,12 +356,15 @@ proc setupProtocols(node: WakuNode,
peerExchangeHandler = some(handlePeerExchange)
if conf.relay:
# TODO autoshard content topics only once.
# Already checked for errors in app.init
let contentTopics = conf.contentTopics.mapIt(NsContentTopic.parse(it).expect("Parsing"))
let shards = contentTopics.mapIt($(getShard(it).expect("Sharding")))
let pubsubTopics =
if conf.pubsubTopics.len > 0 or conf.contentTopics.len > 0:
# TODO autoshard content topics only once.
# Already checked for errors in app.init
let shards = conf.contentTopics.mapIt(getShard(it).expect("Valid Shard"))
conf.pubsubTopics & shards
else:
conf.topics
let pubsubTopics = conf.topics & conf.pubsubTopics & shards
try:
await mountRelay(node, pubsubTopics, peerExchangeHandler = peerExchangeHandler)
except CatchableError:

View File

@ -47,6 +47,14 @@ proc getShard*(topic: NsContentTopic): Result[NsPubsubTopic, string] =
of 0: return ok(getGenZeroShard(topic, GenerationZeroShardsCount))
else: return err("Generation > 0 are not supported yet")
proc getShard*(topic: ContentTopic): Result[PubsubTopic, string] =
let parsedTopic = NsContentTopic.parse(topic).valueOr:
return err($error)
let shard = ?getShard(parsedTopic)
ok($shard)
proc parseSharding*(pubsubTopic: Option[PubsubTopic], contentTopics: ContentTopic|seq[ContentTopic]): Result[Table[NsPubsubTopic, seq[NsContentTopic]], string] =
var topics: seq[ContentTopic]
when contentTopics is seq[ContentTopic]: