mirror of https://github.com/waku-org/nwaku.git
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:
parent
e6002032eb
commit
9c0e943166
|
@ -27,6 +27,8 @@ import
|
|||
../../waku/waku_enr,
|
||||
../../waku/waku_discv5,
|
||||
../../waku/waku_dnsdisc,
|
||||
../../waku/waku_rln_relay,
|
||||
../wakunode2/networks_config,
|
||||
./networkmonitor_metrics,
|
||||
./networkmonitor_config,
|
||||
./networkmonitor_utils
|
||||
|
@ -375,6 +377,10 @@ proc initAndStartApp(conf: NetworkMonitorConf): Result[(WakuNode, WakuDiscoveryV
|
|||
udpPort = some(nodeUdpPort),
|
||||
)
|
||||
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 record =
|
||||
|
@ -386,6 +392,9 @@ proc initAndStartApp(conf: NetworkMonitorConf): Result[(WakuNode, WakuDiscoveryV
|
|||
|
||||
nodeBuilder.withNodeKey(key)
|
||||
nodeBuilder.withRecord(record)
|
||||
nodeBuilder.withPeerManagerConfig(
|
||||
maxRelayPeers = none(int),
|
||||
shardAware = true)
|
||||
let res = nodeBuilder.withNetworkConfigurationDetails(bindIp, nodeTcpPort)
|
||||
if res.isErr():
|
||||
return err("node building error" & $res.error)
|
||||
|
@ -475,9 +484,17 @@ when isMainModule:
|
|||
error "could not load cli variables", err=confRes.error
|
||||
quit(1)
|
||||
|
||||
let conf = confRes.get()
|
||||
var conf = confRes.get()
|
||||
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:
|
||||
setLogLevel(conf.logLevel)
|
||||
|
||||
|
@ -519,8 +536,31 @@ when isMainModule:
|
|||
waitFor node.mountRelay()
|
||||
waitFor node.mountLibp2pPing()
|
||||
|
||||
if conf.rlnRelayEthContractAddress != "":
|
||||
|
||||
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, DefaultPubsubTopic, msgPerContentTopic)
|
||||
subscribeAndHandleMessages(node, pubsubTopic, msgPerContentTopic)
|
||||
|
||||
# spawn the routine that crawls the network
|
||||
# TODO: split into 3 routines (discovery, connections, ip2location)
|
||||
|
|
|
@ -32,12 +32,46 @@ type
|
|||
defaultValue: ""
|
||||
name: "dns-discovery-url" }: string
|
||||
|
||||
pubsubTopics* {.
|
||||
desc: "Default pubsub topic to subscribe to. Argument may be repeated."
|
||||
name: "pubsub-topic" .}: seq[string]
|
||||
|
||||
refreshInterval* {.
|
||||
desc: "How often new peers are discovered and connected to (in seconds)",
|
||||
defaultValue: 5,
|
||||
name: "refresh-interval",
|
||||
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
|
||||
metricsServer* {.
|
||||
desc: "Enable the metrics server: true|false"
|
||||
|
|
Loading…
Reference in New Issue