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(rln-relay): pass in index to keystore credentials #1777

Merged
merged 2 commits into from
Jun 6, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 3 additions & 2 deletions apps/chat2/chat2.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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,
Expand Down
11 changes: 8 additions & 3 deletions apps/chat2/config_chat2.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion apps/wakunode2/app.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 7 additions & 2 deletions apps/wakunode2/config.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
9 changes: 7 additions & 2 deletions docs/tutorial/onchain-rln-relay-chat2.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,16 +164,21 @@ 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.

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
Expand Down
2 changes: 1 addition & 1 deletion tests/v2/waku_rln_relay/test_waku_rln_relay.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
18 changes: 9 additions & 9 deletions tests/v2/waku_rln_relay/test_wakunode_rln_relay.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Copy link
Member

Choose a reason for hiding this comment

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

Would it make sense to also rename the type MembershipIndex?

Copy link
Contributor Author

@rymnc rymnc Jun 6, 2023

Choose a reason for hiding this comment

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

This looks like it fell through the sieve, it should actually be <index>.uint instead. fixed in 956a63c

))

await node1.start()
Expand All @@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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"
Expand Down
3 changes: 0 additions & 3 deletions waku/v2/waku_rln_relay/group_manager/static/group_manager.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions waku/v2/waku_rln_relay/rln_relay.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand Down