From e35eadb77e6d51e3f8e3100b65bb06da4802b2c8 Mon Sep 17 00:00:00 2001 From: rymnc <43716372+rymnc@users.noreply.github.com> Date: Fri, 2 Jun 2023 10:15:44 +0530 Subject: [PATCH 1/2] feat(rln-relay): pass in index to keystore credentials --- apps/chat2/chat2.nim | 5 +++-- apps/chat2/config_chat2.nim | 11 ++++++++--- apps/wakunode2/app.nim | 3 ++- apps/wakunode2/config.nim | 9 +++++++-- docs/tutorial/onchain-rln-relay-chat2.md | 9 +++++++-- .../v2/waku_rln_relay/test_waku_rln_relay.nim | 2 +- .../waku_rln_relay/test_wakunode_rln_relay.nim | 18 +++++++++--------- .../group_manager/on_chain/group_manager.nim | 7 ++++--- .../group_manager/static/group_manager.nim | 3 --- waku/v2/waku_rln_relay/rln_relay.nim | 7 +++++-- 10 files changed, 46 insertions(+), 28 deletions(-) diff --git a/apps/chat2/chat2.nim b/apps/chat2/chat2.nim index 875e781a8c..5512515e2c 100644 --- a/apps/chat2/chat2.nim +++ b/apps/chat2/chat2.nim @@ -539,7 +539,7 @@ proc processInput(rfd: AsyncFD, rng: ref HmacDrbgContext) {.async.} = let peerInfo = parsePeerInfo(conf.lightpushnode) if peerInfo.isOk(): await mountLightPush(node) - node.mountLightPushClient() + node.mountLightPushClient() node.peerManager.addServicePeer(peerInfo.value, WakuLightpushCodec) else: error "LightPush not mounted. Couldn't parse conf.lightpushnode", @@ -600,7 +600,8 @@ proc processInput(rfd: AsyncFD, rng: ref HmacDrbgContext) {.async.} = rlnRelayDynamic: conf.rlnRelayDynamic, rlnRelayPubsubTopic: conf.rlnRelayPubsubTopic, rlnRelayContentTopic: conf.rlnRelayContentTopic, - rlnRelayMembershipIndex: some(conf.rlnRelayMembershipIndex), + rlnRelayCredIndex: conf.rlnRelayCredIndex, + rlnRelayMembershipGroupIndex: conf.rlnRelayMembershipGroupIndex, rlnRelayEthContractAddress: conf.rlnRelayEthContractAddress, rlnRelayEthClientAddress: conf.rlnRelayEthClientAddress, rlnRelayEthAccountPrivateKey: conf.rlnRelayEthAccountPrivateKey, diff --git a/apps/chat2/config_chat2.nim b/apps/chat2/config_chat2.nim index 2984f79f9f..4ecf739408 100644 --- a/apps/chat2/config_chat2.nim +++ b/apps/chat2/config_chat2.nim @@ -232,10 +232,15 @@ type defaultValue: "" name: "rln-relay-cred-path" }: string - rlnRelayMembershipIndex* {. - desc: "(experimental) the index of node in the rln-relay group: a value between 0-99 inclusive", + rlnRelayCredIndex* {. + desc: "the index of credentials to use", defaultValue: 0 - name: "rln-relay-membership-index" }: uint + name: "rln-relay-cred-index" }: uint + + rlnRelayMembershipGroupIndex* {. + desc: "the index of credentials to use, within a specific rln membership set", + defaultValue: 0 + name: "rln-relay-membership-group-index" }: uint rlnRelayContentTopic* {. desc: "the content topic for which rln-relay gets enabled", diff --git a/apps/wakunode2/app.nim b/apps/wakunode2/app.nim index e8cbdbf154..f3a6d2bb88 100644 --- a/apps/wakunode2/app.nim +++ b/apps/wakunode2/app.nim @@ -545,7 +545,8 @@ proc setupProtocols(node: WakuNode, conf: WakuNodeConf, rlnRelayDynamic: conf.rlnRelayDynamic, rlnRelayPubsubTopic: conf.rlnRelayPubsubTopic, rlnRelayContentTopic: conf.rlnRelayContentTopic, - rlnRelayMembershipIndex: some(conf.rlnRelayMembershipIndex), + rlnRelayCredIndex: conf.rlnRelayCredIndex, + rlnRelayMembershipGroupIndex: conf.rlnRelayMembershipGroupIndex, rlnRelayEthContractAddress: conf.rlnRelayEthContractAddress, rlnRelayEthClientAddress: conf.rlnRelayEthClientAddress, rlnRelayEthAccountPrivateKey: conf.rlnRelayEthAccountPrivateKey, diff --git a/apps/wakunode2/config.nim b/apps/wakunode2/config.nim index 5196e11a7f..cdcc6b1ea4 100644 --- a/apps/wakunode2/config.nim +++ b/apps/wakunode2/config.nim @@ -140,11 +140,16 @@ type defaultValue: "" name: "rln-relay-cred-path" }: string - rlnRelayMembershipIndex* {. - desc: "(experimental) the index of node in the rln-relay group: a value between 0-99 inclusive", + rlnRelayCredIndex* {. + desc: "the index of credentials to use", defaultValue: 0 name: "rln-relay-membership-index" }: uint + rlnRelayMembershipGroupIndex* {. + desc: "the index of credentials to use, within a specific rln membership set", + defaultValue: 0 + name: "rln-relay-membership-group-index" }: uint + rlnRelayPubsubTopic* {. desc: "the pubsub topic for which rln-relay gets enabled", defaultValue: "/waku/2/default-waku/proto" diff --git a/docs/tutorial/onchain-rln-relay-chat2.md b/docs/tutorial/onchain-rln-relay-chat2.md index 31be759dec..4857e3820a 100644 --- a/docs/tutorial/onchain-rln-relay-chat2.md +++ b/docs/tutorial/onchain-rln-relay-chat2.md @@ -164,8 +164,12 @@ You may pass the `rln-relay-cred-path` config option to specify a path to a file If the keystore exists in the path provided, it is used, and will default to the 0th element in the credential array. If the keystore does not exist in the path provided, a new keystore will be created and added to the directory it was supposed to be in. +You may provide an index to the credential you wish to use by passing the `rln-relay-cred-index` config option. + +You may provide an index to the membership you wish to use (within the same membership set) by passing the `rln-relay-membership-group-index` config option. + ```bash -./build/chat2 --fleet:test --content-topic:/toy-chat/3/mingde/proto --rln-relay:true --rln-relay-dynamic:true --rln-relay-eth-contract-address:0x9C09146844C1326c2dBC41c451766C7138F88155 --rln-relay-eth-account-private-key:your_private_key --rln-relay-eth-client-address:your_sepolia_node --ports-shift=1 --rln-relay-cred-path:./rlnKeystore.json --rln-relay-cred-password:your_password +./build/chat2 --fleet:test --content-topic:/toy-chat/3/mingde/proto --rln-relay:true --rln-relay-dynamic:true --rln-relay-eth-contract-address:0x9C09146844C1326c2dBC41c451766C7138F88155 --rln-relay-eth-account-private-key:your_private_key --rln-relay-eth-client-address:your_sepolia_node --ports-shift=1 --rln-relay-cred-path:./rlnKeystore.json --rln-relay-cred-password:your_password --rln-relay-membership-index:0 --rln-relay-membership-group-index:0 ``` Note: If you are reusing credentials, you can omit the `rln-relay-eth-account-private-key` flag. @@ -173,7 +177,8 @@ Note: If you are reusing credentials, you can omit the `rln-relay-eth-account-pr Therefore, the command to start chat2 would be - ```bash -./build/chat2 --fleet:test --content-topic:/toy-chat/3/mingde/proto --rln-relay:true --rln-relay-dynamic:true --rln-relay-eth-contract-address:0x9C09146844C1326c2dBC41c451766C7138F88155 --rln-relay-eth-client-address:your_sepolia_node --ports-shift=1 --rln-relay-cred-path:./rlnKeystore.json --rln-relay-cred-password:your_password +./build/chat2 --fleet:test --content-topic:/toy-chat/3/mingde/proto --rln-relay:true --rln-relay-dynamic:true --rln-relay-eth-contract-address:0x9C09146844C1326c2dBC41c451766C7138F88155 --rln-relay-eth-client-address:your_sepolia_node --ports-shift=1 --rln-relay-cred-path:./rlnKeystore.json --rln-relay-cred-password:your_password --rln-relay-cred-index:0 --rln-relay-membership-group-index:0 +``` ``` # Sample test output diff --git a/tests/v2/waku_rln_relay/test_waku_rln_relay.nim b/tests/v2/waku_rln_relay/test_waku_rln_relay.nim index 73ff90bcde..12ad887941 100644 --- a/tests/v2/waku_rln_relay/test_waku_rln_relay.nim +++ b/tests/v2/waku_rln_relay/test_waku_rln_relay.nim @@ -596,7 +596,7 @@ suite "Waku rln relay": let rlnConf = WakuRlnConfig(rlnRelayDynamic: false, rlnRelayPubsubTopic: RlnRelayPubsubTopic, rlnRelayContentTopic: RlnRelayContentTopic, - rlnRelayMembershipIndex: some(index.uint)) + rlnRelayCredIndex: index.uint) let wakuRlnRelayRes = await WakuRlnRelay.new(rlnConf) require: wakuRlnRelayRes.isOk() diff --git a/tests/v2/waku_rln_relay/test_wakunode_rln_relay.nim b/tests/v2/waku_rln_relay/test_wakunode_rln_relay.nim index 1839478be9..07fe182480 100644 --- a/tests/v2/waku_rln_relay/test_wakunode_rln_relay.nim +++ b/tests/v2/waku_rln_relay/test_wakunode_rln_relay.nim @@ -51,7 +51,7 @@ procSuite "WakuNode - RLN relay": await node1.mountRlnRelay(WakuRlnConfig(rlnRelayDynamic: false, rlnRelayPubsubTopic: rlnRelayPubSubTopic, rlnRelayContentTopic: contentTopic, - rlnRelayMembershipIndex: some(MembershipIndex(1)), + rlnRelayCredIndex: MembershipIndex(1), )) await node1.start() @@ -62,7 +62,7 @@ procSuite "WakuNode - RLN relay": await node2.mountRlnRelay(WakuRlnConfig(rlnRelayDynamic: false, rlnRelayPubsubTopic: rlnRelayPubSubTopic, rlnRelayContentTopic: contentTopic, - rlnRelayMembershipIndex: some(MembershipIndex(2)), + rlnRelayCredIndex: MembershipIndex(2), )) await node2.start() @@ -73,7 +73,7 @@ procSuite "WakuNode - RLN relay": await node3.mountRlnRelay(WakuRlnConfig(rlnRelayDynamic: false, rlnRelayPubsubTopic: rlnRelayPubSubTopic, rlnRelayContentTopic: contentTopic, - rlnRelayMembershipIndex: some(MembershipIndex(3)), + rlnRelayCredIndex: MembershipIndex(3), )) await node3.start() @@ -139,7 +139,7 @@ procSuite "WakuNode - RLN relay": await node1.mountRlnRelay(WakuRlnConfig(rlnRelayDynamic: false, rlnRelayPubsubTopic: rlnRelayPubSubTopic, rlnRelayContentTopic: contentTopic, - rlnRelayMembershipIndex: some(MembershipIndex(1)), + rlnRelayCredIndex: MembershipIndex(1), )) await node1.start() @@ -150,7 +150,7 @@ procSuite "WakuNode - RLN relay": await node2.mountRlnRelay(WakuRlnConfig(rlnRelayDynamic: false, rlnRelayPubsubTopic: rlnRelayPubSubTopic, rlnRelayContentTopic: contentTopic, - rlnRelayMembershipIndex: some(MembershipIndex(2)), + rlnRelayCredIndex: MembershipIndex(2), )) await node2.start() @@ -161,7 +161,7 @@ procSuite "WakuNode - RLN relay": await node3.mountRlnRelay(WakuRlnConfig(rlnRelayDynamic: false, rlnRelayPubsubTopic: rlnRelayPubSubTopic, rlnRelayContentTopic: contentTopic, - rlnRelayMembershipIndex: some(MembershipIndex(3)), + rlnRelayCredIndex: MembershipIndex(3), )) await node3.start() @@ -244,7 +244,7 @@ procSuite "WakuNode - RLN relay": await node1.mountRlnRelay(WakuRlnConfig(rlnRelayDynamic: false, rlnRelayPubsubTopic: rlnRelayPubSubTopic, rlnRelayContentTopic: contentTopic, - rlnRelayMembershipIndex: some(MembershipIndex(1)), + rlnRelayCredIndex: MembershipIndex(1), )) await node1.start() @@ -256,7 +256,7 @@ procSuite "WakuNode - RLN relay": await node2.mountRlnRelay(WakuRlnConfig(rlnRelayDynamic: false, rlnRelayPubsubTopic: rlnRelayPubSubTopic, rlnRelayContentTopic: contentTopic, - rlnRelayMembershipIndex: some(MembershipIndex(2)), + rlnRelayCredIndex: MembershipIndex(2), )) await node2.start() @@ -268,7 +268,7 @@ procSuite "WakuNode - RLN relay": await node3.mountRlnRelay(WakuRlnConfig(rlnRelayDynamic: false, rlnRelayPubsubTopic: rlnRelayPubSubTopic, rlnRelayContentTopic: contentTopic, - rlnRelayMembershipIndex: some(MembershipIndex(3)), + rlnRelayCredIndex: MembershipIndex(3), )) await node3.start() diff --git a/waku/v2/waku_rln_relay/group_manager/on_chain/group_manager.nim b/waku/v2/waku_rln_relay/group_manager/on_chain/group_manager.nim index 1436363b5e..69cddd5dad 100644 --- a/waku/v2/waku_rln_relay/group_manager/on_chain/group_manager.nim +++ b/waku/v2/waku_rln_relay/group_manager/on_chain/group_manager.nim @@ -49,6 +49,8 @@ type registrationTxHash*: Option[TxHash] chainId*: Option[Quantity] keystorePath*: Option[string] + keystoreIndex*: uint + membershipGroupIndex*: uint keystorePassword*: Option[string] saveKeystore*: bool registrationHandler*: Option[RegistrationHandler] @@ -440,9 +442,8 @@ method init*(g: OnchainGroupManager): Future[void] {.async.} = let parsedCreds = parsedCredsRes.get() if parsedCreds.len == 0: raise newException(ValueError, "keystore is empty") - # TODO: accept an index from the config (related: https://github.com/waku-org/nwaku/pull/1466) - g.idCredentials = some(parsedCreds[0].identityCredential) - g.membershipIndex = some(parsedCreds[0].membershipGroups[0].treeIndex) + g.idCredentials = some(parsedCreds[g.keystoreIndex].identityCredential) + g.membershipIndex = some(parsedCreds[g.keystoreIndex].membershipGroups[g.membershipGroupIndex].treeIndex) ethRpc.ondisconnect = proc() = error "Ethereum client disconnected" diff --git a/waku/v2/waku_rln_relay/group_manager/static/group_manager.nim b/waku/v2/waku_rln_relay/group_manager/static/group_manager.nim index 757364bb2b..3a3d831230 100644 --- a/waku/v2/waku_rln_relay/group_manager/static/group_manager.nim +++ b/waku/v2/waku_rln_relay/group_manager/static/group_manager.nim @@ -16,9 +16,6 @@ template initializedGuard*(g: StaticGroupManager): untyped = raise newException(ValueError, "StaticGroupManager is not initialized") method init*(g: StaticGroupManager): Future[void] {.async,gcsafe.} = - if g.membershipIndex.isNone(): - raise newException(ValueError, "Membership index is not set") - let groupSize = g.groupSize groupKeys = g.groupKeys diff --git a/waku/v2/waku_rln_relay/rln_relay.nim b/waku/v2/waku_rln_relay/rln_relay.nim index 831d1c64c7..4ccf121dbb 100644 --- a/waku/v2/waku_rln_relay/rln_relay.nim +++ b/waku/v2/waku_rln_relay/rln_relay.nim @@ -32,7 +32,8 @@ type WakuRlnConfig* = object rlnRelayDynamic*: bool rlnRelayPubsubTopic*: PubsubTopic rlnRelayContentTopic*: ContentTopic - rlnRelayMembershipIndex*: Option[uint] + rlnRelayCredIndex*: uint + rlnRelayMembershipGroupIndex*: uint rlnRelayEthContractAddress*: string rlnRelayEthClientAddress*: string rlnRelayEthAccountPrivateKey*: string @@ -348,7 +349,7 @@ proc mount(conf: WakuRlnConfig, raise newException(ValueError, "Static group keys are not valid") groupManager = StaticGroupManager(groupSize: StaticGroupSize, groupKeys: parsedGroupKeysRes.get(), - membershipIndex: conf.rlnRelayMembershipIndex, + membershipIndex: some(conf.rlnRelayCredIndex), rlnInstance: rlnInstance) # we don't persist credentials in static mode since they exist in ./constants.nim else: @@ -366,6 +367,8 @@ proc mount(conf: WakuRlnConfig, registrationHandler: registrationHandler, keystorePath: rlnRelayCredPath, keystorePassword: rlnRelayCredentialsPassword, + keystoreIndex: conf.rlnRelayCredIndex, + membershipGroupIndex: conf.rlnRelayMembershipGroupIndex, saveKeystore: true) # Initialize the groupManager From 956a63c8e20bd326626b1e16e2d938c696e28c1d Mon Sep 17 00:00:00 2001 From: rymnc <43716372+rymnc@users.noreply.github.com> Date: Tue, 6 Jun 2023 22:44:08 +0530 Subject: [PATCH 2/2] fix(rln-relay): s/MembershipIndex/uint --- .../waku_rln_relay/test_wakunode_rln_relay.nim | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/v2/waku_rln_relay/test_wakunode_rln_relay.nim b/tests/v2/waku_rln_relay/test_wakunode_rln_relay.nim index 07fe182480..739070a168 100644 --- a/tests/v2/waku_rln_relay/test_wakunode_rln_relay.nim +++ b/tests/v2/waku_rln_relay/test_wakunode_rln_relay.nim @@ -51,7 +51,7 @@ procSuite "WakuNode - RLN relay": await node1.mountRlnRelay(WakuRlnConfig(rlnRelayDynamic: false, rlnRelayPubsubTopic: rlnRelayPubSubTopic, rlnRelayContentTopic: contentTopic, - rlnRelayCredIndex: MembershipIndex(1), + rlnRelayCredIndex: 1.uint, )) await node1.start() @@ -62,7 +62,7 @@ procSuite "WakuNode - RLN relay": await node2.mountRlnRelay(WakuRlnConfig(rlnRelayDynamic: false, rlnRelayPubsubTopic: rlnRelayPubSubTopic, rlnRelayContentTopic: contentTopic, - rlnRelayCredIndex: MembershipIndex(2), + rlnRelayCredIndex: 2.uint, )) await node2.start() @@ -73,7 +73,7 @@ procSuite "WakuNode - RLN relay": await node3.mountRlnRelay(WakuRlnConfig(rlnRelayDynamic: false, rlnRelayPubsubTopic: rlnRelayPubSubTopic, rlnRelayContentTopic: contentTopic, - rlnRelayCredIndex: MembershipIndex(3), + rlnRelayCredIndex: 3.uint, )) await node3.start() @@ -139,7 +139,7 @@ procSuite "WakuNode - RLN relay": await node1.mountRlnRelay(WakuRlnConfig(rlnRelayDynamic: false, rlnRelayPubsubTopic: rlnRelayPubSubTopic, rlnRelayContentTopic: contentTopic, - rlnRelayCredIndex: MembershipIndex(1), + rlnRelayCredIndex: 1.uint, )) await node1.start() @@ -150,7 +150,7 @@ procSuite "WakuNode - RLN relay": await node2.mountRlnRelay(WakuRlnConfig(rlnRelayDynamic: false, rlnRelayPubsubTopic: rlnRelayPubSubTopic, rlnRelayContentTopic: contentTopic, - rlnRelayCredIndex: MembershipIndex(2), + rlnRelayCredIndex: 2.uint, )) await node2.start() @@ -161,7 +161,7 @@ procSuite "WakuNode - RLN relay": await node3.mountRlnRelay(WakuRlnConfig(rlnRelayDynamic: false, rlnRelayPubsubTopic: rlnRelayPubSubTopic, rlnRelayContentTopic: contentTopic, - rlnRelayCredIndex: MembershipIndex(3), + rlnRelayCredIndex: 3.uint, )) await node3.start() @@ -244,7 +244,7 @@ procSuite "WakuNode - RLN relay": await node1.mountRlnRelay(WakuRlnConfig(rlnRelayDynamic: false, rlnRelayPubsubTopic: rlnRelayPubSubTopic, rlnRelayContentTopic: contentTopic, - rlnRelayCredIndex: MembershipIndex(1), + rlnRelayCredIndex: 1.uint, )) await node1.start() @@ -256,7 +256,7 @@ procSuite "WakuNode - RLN relay": await node2.mountRlnRelay(WakuRlnConfig(rlnRelayDynamic: false, rlnRelayPubsubTopic: rlnRelayPubSubTopic, rlnRelayContentTopic: contentTopic, - rlnRelayCredIndex: MembershipIndex(2), + rlnRelayCredIndex: 2.uint, )) await node2.start() @@ -268,7 +268,7 @@ procSuite "WakuNode - RLN relay": await node3.mountRlnRelay(WakuRlnConfig(rlnRelayDynamic: false, rlnRelayPubsubTopic: rlnRelayPubSubTopic, rlnRelayContentTopic: contentTopic, - rlnRelayCredIndex: MembershipIndex(3), + rlnRelayCredIndex: 3.uint, )) await node3.start()