refactor shard parsing (#2699)

This commit is contained in:
gabrielmer 2024-05-14 20:17:17 +02:00 committed by GitHub
parent 840e012294
commit 3a2caaec6f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 13 additions and 15 deletions

View File

@ -29,23 +29,21 @@ proc enrConfiguration*(
enrBuilder.withMultiaddrs(netConfig.enrMultiaddrs)
let shards: seq[uint16] =
# no shards configured
if conf.shards.len == 0:
var shardsLocal = newSeq[uint16]()
let shardsRes = topicsToRelayShards(conf.pubsubTopics)
if shardsRes.isOk() and shardsRes.get().isSome():
shardsLocal = shardsRes.get().get().shardIds
elif shardsRes.get().isNone():
info "no pubsub topics specified or pubsubtopic is of type Named sharding "
else:
error "failed to parse pubsub topic, please format according to static shard specification",
error = shardsRes.error
shardsLocal
var shards = newSeq[uint16]()
# some shards configured
# no shards configured
if conf.shards.len == 0:
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():
shards = shardsOpt.get().shardIds
else:
toSeq(conf.shards.mapIt(uint16(it)))
info "no pubsub topics specified or pubsubtopic is of type Named sharding "
# some shards configured
else:
shards = toSeq(conf.shards.mapIt(uint16(it)))
enrBuilder.withWakuRelaySharding(
RelayShards(clusterId: uint16(conf.clusterId), shardIds: shards)