Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(networkmonitor): add support for rln #2401

Merged
merged 3 commits into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I just imported the config from wakunode2 - I don't like it, but it's a reasonable start, if this gets moved to more general location, we can change this. But I felt like this is a better approach than to copy it to networkmonitor app

# 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
Loading