feat(networkmonitor): add support for rln (#2401)

* feat(networkmonitor): add support for rln

* remove cred index flag

* use wakunode2 waku network config
This commit is contained in:
Vaclav Pavlin 2024-02-12 09:58:55 +01:00 committed by GitHub
parent e6002032eb
commit 9c0e943166
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 77 additions and 3 deletions

View File

@ -27,6 +27,8 @@ import
../../waku/waku_enr, ../../waku/waku_enr,
../../waku/waku_discv5, ../../waku/waku_discv5,
../../waku/waku_dnsdisc, ../../waku/waku_dnsdisc,
../../waku/waku_rln_relay,
../wakunode2/networks_config,
./networkmonitor_metrics, ./networkmonitor_metrics,
./networkmonitor_config, ./networkmonitor_config,
./networkmonitor_utils ./networkmonitor_utils
@ -375,6 +377,10 @@ proc initAndStartApp(conf: NetworkMonitorConf): Result[(WakuNode, WakuDiscoveryV
udpPort = some(nodeUdpPort), udpPort = some(nodeUdpPort),
) )
builder.withWakuCapabilities(flags) builder.withWakuCapabilities(flags)
let addShardedTopics = builder.withShardedTopics(conf.pubsubTopics)
if addShardedTopics.isErr():
error "failed to add sharded topics to ENR", error=addShardedTopics.error
return err($addShardedTopics.error)
let recordRes = builder.build() let recordRes = builder.build()
let record = let record =
@ -386,6 +392,9 @@ proc initAndStartApp(conf: NetworkMonitorConf): Result[(WakuNode, WakuDiscoveryV
nodeBuilder.withNodeKey(key) nodeBuilder.withNodeKey(key)
nodeBuilder.withRecord(record) nodeBuilder.withRecord(record)
nodeBuilder.withPeerManagerConfig(
maxRelayPeers = none(int),
shardAware = true)
let res = nodeBuilder.withNetworkConfigurationDetails(bindIp, nodeTcpPort) let res = nodeBuilder.withNetworkConfigurationDetails(bindIp, nodeTcpPort)
if res.isErr(): if res.isErr():
return err("node building error" & $res.error) return err("node building error" & $res.error)
@ -475,9 +484,17 @@ when isMainModule:
error "could not load cli variables", err=confRes.error error "could not load cli variables", err=confRes.error
quit(1) quit(1)
let conf = confRes.get() var conf = confRes.get()
info "cli flags", conf=conf info "cli flags", conf=conf
if conf.clusterId == 1:
let twnClusterConf = ClusterConf.TheWakuNetworkConf()
conf.bootstrapNodes = twnClusterConf.discv5BootstrapNodes
conf.pubsubTopics = twnClusterConf.pubsubTopics
conf.rlnRelayDynamic = twnClusterConf.rlnRelayDynamic
conf.rlnRelayEthContractAddress = twnClusterConf.rlnRelayEthContractAddress
if conf.logLevel != LogLevel.NONE: if conf.logLevel != LogLevel.NONE:
setLogLevel(conf.logLevel) setLogLevel(conf.logLevel)
@ -519,8 +536,31 @@ when isMainModule:
waitFor node.mountRelay() waitFor node.mountRelay()
waitFor node.mountLibp2pPing() waitFor node.mountLibp2pPing()
# Subscribe the node to the default pubsubtopic, to count messages if conf.rlnRelayEthContractAddress != "":
subscribeAndHandleMessages(node, DefaultPubsubTopic, msgPerContentTopic)
let rlnConf = WakuRlnConfig(
rlnRelayDynamic: conf.rlnRelayDynamic,
rlnRelayCredIndex: some(uint(0)),
rlnRelayEthContractAddress: conf.rlnRelayEthContractAddress,
rlnRelayEthClientAddress: conf.rlnRelayEthClientAddress,
rlnRelayCredPath: "",
rlnRelayCredPassword: "",
rlnRelayTreePath: conf.rlnRelayTreePath,
)
try:
waitFor node.mountRlnRelay(rlnConf)
except CatchableError:
error "failed to setup RLN", err=getCurrentExceptionMsg()
quit 1
node.mountMetadata(conf.clusterId).isOkOr:
error "failed to mount waku metadata protocol: ", err=error
quit 1
for pubsubTopic in conf.pubsubTopics:
# Subscribe the node to the default pubsubtopic, to count messages
subscribeAndHandleMessages(node, pubsubTopic, msgPerContentTopic)
# spawn the routine that crawls the network # spawn the routine that crawls the network
# TODO: split into 3 routines (discovery, connections, ip2location) # TODO: split into 3 routines (discovery, connections, ip2location)

View File

@ -32,12 +32,46 @@ type
defaultValue: "" defaultValue: ""
name: "dns-discovery-url" }: string name: "dns-discovery-url" }: string
pubsubTopics* {.
desc: "Default pubsub topic to subscribe to. Argument may be repeated."
name: "pubsub-topic" .}: seq[string]
refreshInterval* {. refreshInterval* {.
desc: "How often new peers are discovered and connected to (in seconds)", desc: "How often new peers are discovered and connected to (in seconds)",
defaultValue: 5, defaultValue: 5,
name: "refresh-interval", name: "refresh-interval",
abbr: "r" }: int abbr: "r" }: int
clusterId* {.
desc: "Cluster id that the node is running in. Node in a different cluster id is disconnected."
defaultValue: 1
name: "cluster-id" }: uint32
rlnRelay* {.
desc: "Enable spam protection through rln-relay: true|false",
defaultValue: true
name: "rln-relay" }: bool
rlnRelayDynamic* {.
desc: "Enable waku-rln-relay with on-chain dynamic group management: true|false",
defaultValue: true
name: "rln-relay-dynamic" }: bool
rlnRelayTreePath* {.
desc: "Path to the RLN merkle tree sled db (https://github.com/spacejam/sled)",
defaultValue: ""
name: "rln-relay-tree-path" }: string
rlnRelayEthClientAddress* {.
desc: "WebSocket address of an Ethereum testnet client e.g., http://localhost:8540/",
defaultValue: "http://localhost:8540/",
name: "rln-relay-eth-client-address" }: string
rlnRelayEthContractAddress* {.
desc: "Address of membership contract on an Ethereum testnet",
defaultValue: "",
name: "rln-relay-eth-contract-address" }: string
## Prometheus metrics config ## Prometheus metrics config
metricsServer* {. metricsServer* {.
desc: "Enable the metrics server: true|false" desc: "Enable the metrics server: true|false"