Skip to content

Commit

Permalink
feat(networkmonitor): add support for rln (#2401)
Browse files Browse the repository at this point in the history
* feat(networkmonitor): add support for rln

* remove cred index flag

* use wakunode2 waku network config
  • Loading branch information
vpavlin authored Feb 12, 2024
1 parent e600203 commit 9c0e943
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 3 deletions.
46 changes: 43 additions & 3 deletions apps/networkmonitor/networkmonitor.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 =
Expand All @@ -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)
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -519,8 +536,31 @@ when isMainModule:
waitFor node.mountRelay()
waitFor node.mountLibp2pPing()

# Subscribe the node to the default pubsubtopic, to count messages
subscribeAndHandleMessages(node, DefaultPubsubTopic, msgPerContentTopic)
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, pubsubTopic, msgPerContentTopic)

# spawn the routine that crawls the network
# TODO: split into 3 routines (discovery, connections, ip2location)
Expand Down
34 changes: 34 additions & 0 deletions apps/networkmonitor/networkmonitor_config.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 9c0e943

Please sign in to comment.