mirror of https://github.com/waku-org/nwaku.git
feat: autosharding content topics in config (#1856)
- added content topic to config. - updated ENR building to include content topics.
This commit is contained in:
parent
bbff1ac138
commit
afb93e2995
|
@ -127,9 +127,27 @@ proc init*(T: type App, rng: ref HmacDrbgContext, conf: WakuNodeConf): T =
|
||||||
|
|
||||||
enrBuilder.withMultiaddrs(netConfig.enrMultiaddrs)
|
enrBuilder.withMultiaddrs(netConfig.enrMultiaddrs)
|
||||||
|
|
||||||
let addShardedTopics = enrBuilder.withShardedTopics(conf.topics)
|
let contentTopicsRes = conf.contentTopics.mapIt(NsContentTopic.parse(it))
|
||||||
|
|
||||||
|
for res in contentTopicsRes:
|
||||||
|
if res.isErr():
|
||||||
|
error "failed to parse content topic", error=res.error
|
||||||
|
quit(QuitFailure)
|
||||||
|
|
||||||
|
let pubsubTopicsRes = contentTopicsRes.mapIt(singleHighestWeigthShard(it.get()))
|
||||||
|
|
||||||
|
for res in pubsubTopicsRes:
|
||||||
|
if res.isErr():
|
||||||
|
error "failed to shard content topic", error=res.error
|
||||||
|
quit(QuitFailure)
|
||||||
|
|
||||||
|
let pubsubTopics = pubsubTopicsRes.mapIt($it.get())
|
||||||
|
|
||||||
|
let topics = pubsubTopics & conf.pubsubTopics
|
||||||
|
|
||||||
|
let addShardedTopics = enrBuilder.withShardedTopics(topics)
|
||||||
if addShardedTopics.isErr():
|
if addShardedTopics.isErr():
|
||||||
error "failed to add sharded topics", error=addShardedTopics.error
|
error "failed to add sharded topics to ENR", error=addShardedTopics.error
|
||||||
quit(QuitFailure)
|
quit(QuitFailure)
|
||||||
|
|
||||||
let recordRes = enrBuilder.build()
|
let recordRes = enrBuilder.build()
|
||||||
|
@ -341,7 +359,7 @@ proc setupProtocols(node: WakuNode,
|
||||||
peerExchangeHandler = some(handlePeerExchange)
|
peerExchangeHandler = some(handlePeerExchange)
|
||||||
|
|
||||||
if conf.relay:
|
if conf.relay:
|
||||||
let pubsubTopics = conf.topics
|
let pubsubTopics = conf.pubsubTopics
|
||||||
try:
|
try:
|
||||||
await mountRelay(node, pubsubTopics, peerExchangeHandler = peerExchangeHandler)
|
await mountRelay(node, pubsubTopics, peerExchangeHandler = peerExchangeHandler)
|
||||||
except CatchableError:
|
except CatchableError:
|
||||||
|
|
|
@ -225,10 +225,14 @@ type
|
||||||
defaultValue: false
|
defaultValue: false
|
||||||
name: "keep-alive" }: bool
|
name: "keep-alive" }: bool
|
||||||
|
|
||||||
topics* {.
|
pubsubTopics* {.
|
||||||
desc: "Default topic to subscribe to. Argument may be repeated."
|
desc: "Default pubsub topic to subscribe to. Argument may be repeated."
|
||||||
defaultValue: @["/waku/2/default-waku/proto"]
|
defaultValue: @["/waku/2/default-waku/proto"]
|
||||||
name: "topic" .}: seq[string]
|
name: "pubsub-topic" .}: seq[string]
|
||||||
|
|
||||||
|
contentTopics* {.
|
||||||
|
desc: "Default content topic to subscribe to. Argument may be repeated."
|
||||||
|
name: "content-topic" .}: seq[string]
|
||||||
|
|
||||||
## Store and message store config
|
## Store and message store config
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ proc defaultTestWakuNodeConf(): WakuNodeConf =
|
||||||
metricsServerAddress: ValidIpAddress.init("127.0.0.1"),
|
metricsServerAddress: ValidIpAddress.init("127.0.0.1"),
|
||||||
nat: "any",
|
nat: "any",
|
||||||
maxConnections: 50,
|
maxConnections: 50,
|
||||||
topics: @["/waku/2/default-waku/proto"],
|
pubsubTopics: @["/waku/2/default-waku/proto"],
|
||||||
relay: true
|
relay: true
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue