mirror of https://github.com/waku-org/nwaku.git
feat(rln-relay): pass in index to keystore credentials (#1777)
* feat(rln-relay): pass in index to keystore credentials * fix(rln-relay): s/MembershipIndex/uint
This commit is contained in:
parent
34a9263191
commit
a00aa8cc59
|
@ -595,7 +595,8 @@ proc processInput(rfd: AsyncFD, rng: ref HmacDrbgContext) {.async.} =
|
||||||
rlnRelayDynamic: conf.rlnRelayDynamic,
|
rlnRelayDynamic: conf.rlnRelayDynamic,
|
||||||
rlnRelayPubsubTopic: conf.rlnRelayPubsubTopic,
|
rlnRelayPubsubTopic: conf.rlnRelayPubsubTopic,
|
||||||
rlnRelayContentTopic: conf.rlnRelayContentTopic,
|
rlnRelayContentTopic: conf.rlnRelayContentTopic,
|
||||||
rlnRelayMembershipIndex: some(conf.rlnRelayMembershipIndex),
|
rlnRelayCredIndex: conf.rlnRelayCredIndex,
|
||||||
|
rlnRelayMembershipGroupIndex: conf.rlnRelayMembershipGroupIndex,
|
||||||
rlnRelayEthContractAddress: conf.rlnRelayEthContractAddress,
|
rlnRelayEthContractAddress: conf.rlnRelayEthContractAddress,
|
||||||
rlnRelayEthClientAddress: conf.rlnRelayEthClientAddress,
|
rlnRelayEthClientAddress: conf.rlnRelayEthClientAddress,
|
||||||
rlnRelayEthAccountPrivateKey: conf.rlnRelayEthAccountPrivateKey,
|
rlnRelayEthAccountPrivateKey: conf.rlnRelayEthAccountPrivateKey,
|
||||||
|
|
|
@ -232,10 +232,15 @@ type
|
||||||
defaultValue: ""
|
defaultValue: ""
|
||||||
name: "rln-relay-cred-path" }: string
|
name: "rln-relay-cred-path" }: string
|
||||||
|
|
||||||
rlnRelayMembershipIndex* {.
|
rlnRelayCredIndex* {.
|
||||||
desc: "(experimental) the index of node in the rln-relay group: a value between 0-99 inclusive",
|
desc: "the index of credentials to use",
|
||||||
defaultValue: 0
|
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* {.
|
rlnRelayContentTopic* {.
|
||||||
desc: "the content topic for which rln-relay gets enabled",
|
desc: "the content topic for which rln-relay gets enabled",
|
||||||
|
|
|
@ -545,7 +545,8 @@ proc setupProtocols(node: WakuNode, conf: WakuNodeConf,
|
||||||
rlnRelayDynamic: conf.rlnRelayDynamic,
|
rlnRelayDynamic: conf.rlnRelayDynamic,
|
||||||
rlnRelayPubsubTopic: conf.rlnRelayPubsubTopic,
|
rlnRelayPubsubTopic: conf.rlnRelayPubsubTopic,
|
||||||
rlnRelayContentTopic: conf.rlnRelayContentTopic,
|
rlnRelayContentTopic: conf.rlnRelayContentTopic,
|
||||||
rlnRelayMembershipIndex: some(conf.rlnRelayMembershipIndex),
|
rlnRelayCredIndex: conf.rlnRelayCredIndex,
|
||||||
|
rlnRelayMembershipGroupIndex: conf.rlnRelayMembershipGroupIndex,
|
||||||
rlnRelayEthContractAddress: conf.rlnRelayEthContractAddress,
|
rlnRelayEthContractAddress: conf.rlnRelayEthContractAddress,
|
||||||
rlnRelayEthClientAddress: conf.rlnRelayEthClientAddress,
|
rlnRelayEthClientAddress: conf.rlnRelayEthClientAddress,
|
||||||
rlnRelayEthAccountPrivateKey: conf.rlnRelayEthAccountPrivateKey,
|
rlnRelayEthAccountPrivateKey: conf.rlnRelayEthAccountPrivateKey,
|
||||||
|
|
|
@ -140,11 +140,16 @@ type
|
||||||
defaultValue: ""
|
defaultValue: ""
|
||||||
name: "rln-relay-cred-path" }: string
|
name: "rln-relay-cred-path" }: string
|
||||||
|
|
||||||
rlnRelayMembershipIndex* {.
|
rlnRelayCredIndex* {.
|
||||||
desc: "(experimental) the index of node in the rln-relay group: a value between 0-99 inclusive",
|
desc: "the index of credentials to use",
|
||||||
defaultValue: 0
|
defaultValue: 0
|
||||||
name: "rln-relay-membership-index" }: uint
|
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* {.
|
rlnRelayPubsubTopic* {.
|
||||||
desc: "the pubsub topic for which rln-relay gets enabled",
|
desc: "the pubsub topic for which rln-relay gets enabled",
|
||||||
defaultValue: "/waku/2/default-waku/proto"
|
defaultValue: "/waku/2/default-waku/proto"
|
||||||
|
|
|
@ -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 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.
|
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
|
```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.
|
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 -
|
Therefore, the command to start chat2 would be -
|
||||||
|
|
||||||
```bash
|
```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
|
# Sample test output
|
||||||
|
|
|
@ -596,7 +596,7 @@ suite "Waku rln relay":
|
||||||
let rlnConf = WakuRlnConfig(rlnRelayDynamic: false,
|
let rlnConf = WakuRlnConfig(rlnRelayDynamic: false,
|
||||||
rlnRelayPubsubTopic: RlnRelayPubsubTopic,
|
rlnRelayPubsubTopic: RlnRelayPubsubTopic,
|
||||||
rlnRelayContentTopic: RlnRelayContentTopic,
|
rlnRelayContentTopic: RlnRelayContentTopic,
|
||||||
rlnRelayMembershipIndex: some(index.uint))
|
rlnRelayCredIndex: index.uint)
|
||||||
let wakuRlnRelayRes = await WakuRlnRelay.new(rlnConf)
|
let wakuRlnRelayRes = await WakuRlnRelay.new(rlnConf)
|
||||||
require:
|
require:
|
||||||
wakuRlnRelayRes.isOk()
|
wakuRlnRelayRes.isOk()
|
||||||
|
|
|
@ -51,7 +51,7 @@ procSuite "WakuNode - RLN relay":
|
||||||
await node1.mountRlnRelay(WakuRlnConfig(rlnRelayDynamic: false,
|
await node1.mountRlnRelay(WakuRlnConfig(rlnRelayDynamic: false,
|
||||||
rlnRelayPubsubTopic: rlnRelayPubSubTopic,
|
rlnRelayPubsubTopic: rlnRelayPubSubTopic,
|
||||||
rlnRelayContentTopic: contentTopic,
|
rlnRelayContentTopic: contentTopic,
|
||||||
rlnRelayMembershipIndex: some(MembershipIndex(1)),
|
rlnRelayCredIndex: 1.uint,
|
||||||
))
|
))
|
||||||
|
|
||||||
await node1.start()
|
await node1.start()
|
||||||
|
@ -62,7 +62,7 @@ procSuite "WakuNode - RLN relay":
|
||||||
await node2.mountRlnRelay(WakuRlnConfig(rlnRelayDynamic: false,
|
await node2.mountRlnRelay(WakuRlnConfig(rlnRelayDynamic: false,
|
||||||
rlnRelayPubsubTopic: rlnRelayPubSubTopic,
|
rlnRelayPubsubTopic: rlnRelayPubSubTopic,
|
||||||
rlnRelayContentTopic: contentTopic,
|
rlnRelayContentTopic: contentTopic,
|
||||||
rlnRelayMembershipIndex: some(MembershipIndex(2)),
|
rlnRelayCredIndex: 2.uint,
|
||||||
))
|
))
|
||||||
|
|
||||||
await node2.start()
|
await node2.start()
|
||||||
|
@ -73,7 +73,7 @@ procSuite "WakuNode - RLN relay":
|
||||||
await node3.mountRlnRelay(WakuRlnConfig(rlnRelayDynamic: false,
|
await node3.mountRlnRelay(WakuRlnConfig(rlnRelayDynamic: false,
|
||||||
rlnRelayPubsubTopic: rlnRelayPubSubTopic,
|
rlnRelayPubsubTopic: rlnRelayPubSubTopic,
|
||||||
rlnRelayContentTopic: contentTopic,
|
rlnRelayContentTopic: contentTopic,
|
||||||
rlnRelayMembershipIndex: some(MembershipIndex(3)),
|
rlnRelayCredIndex: 3.uint,
|
||||||
))
|
))
|
||||||
|
|
||||||
await node3.start()
|
await node3.start()
|
||||||
|
@ -137,7 +137,7 @@ procSuite "WakuNode - RLN relay":
|
||||||
await node1.mountRlnRelay(WakuRlnConfig(rlnRelayDynamic: false,
|
await node1.mountRlnRelay(WakuRlnConfig(rlnRelayDynamic: false,
|
||||||
rlnRelayPubsubTopic: rlnRelayPubSubTopic,
|
rlnRelayPubsubTopic: rlnRelayPubSubTopic,
|
||||||
rlnRelayContentTopic: contentTopic,
|
rlnRelayContentTopic: contentTopic,
|
||||||
rlnRelayMembershipIndex: some(MembershipIndex(1)),
|
rlnRelayCredIndex: 1.uint,
|
||||||
))
|
))
|
||||||
|
|
||||||
await node1.start()
|
await node1.start()
|
||||||
|
@ -148,7 +148,7 @@ procSuite "WakuNode - RLN relay":
|
||||||
await node2.mountRlnRelay(WakuRlnConfig(rlnRelayDynamic: false,
|
await node2.mountRlnRelay(WakuRlnConfig(rlnRelayDynamic: false,
|
||||||
rlnRelayPubsubTopic: rlnRelayPubSubTopic,
|
rlnRelayPubsubTopic: rlnRelayPubSubTopic,
|
||||||
rlnRelayContentTopic: contentTopic,
|
rlnRelayContentTopic: contentTopic,
|
||||||
rlnRelayMembershipIndex: some(MembershipIndex(2)),
|
rlnRelayCredIndex: 2.uint,
|
||||||
))
|
))
|
||||||
|
|
||||||
await node2.start()
|
await node2.start()
|
||||||
|
@ -159,7 +159,7 @@ procSuite "WakuNode - RLN relay":
|
||||||
await node3.mountRlnRelay(WakuRlnConfig(rlnRelayDynamic: false,
|
await node3.mountRlnRelay(WakuRlnConfig(rlnRelayDynamic: false,
|
||||||
rlnRelayPubsubTopic: rlnRelayPubSubTopic,
|
rlnRelayPubsubTopic: rlnRelayPubSubTopic,
|
||||||
rlnRelayContentTopic: contentTopic,
|
rlnRelayContentTopic: contentTopic,
|
||||||
rlnRelayMembershipIndex: some(MembershipIndex(3)),
|
rlnRelayCredIndex: 3.uint,
|
||||||
))
|
))
|
||||||
|
|
||||||
await node3.start()
|
await node3.start()
|
||||||
|
@ -240,7 +240,7 @@ procSuite "WakuNode - RLN relay":
|
||||||
await node1.mountRlnRelay(WakuRlnConfig(rlnRelayDynamic: false,
|
await node1.mountRlnRelay(WakuRlnConfig(rlnRelayDynamic: false,
|
||||||
rlnRelayPubsubTopic: rlnRelayPubSubTopic,
|
rlnRelayPubsubTopic: rlnRelayPubSubTopic,
|
||||||
rlnRelayContentTopic: contentTopic,
|
rlnRelayContentTopic: contentTopic,
|
||||||
rlnRelayMembershipIndex: some(MembershipIndex(1)),
|
rlnRelayCredIndex: 1.uint,
|
||||||
))
|
))
|
||||||
|
|
||||||
await node1.start()
|
await node1.start()
|
||||||
|
@ -252,7 +252,7 @@ procSuite "WakuNode - RLN relay":
|
||||||
await node2.mountRlnRelay(WakuRlnConfig(rlnRelayDynamic: false,
|
await node2.mountRlnRelay(WakuRlnConfig(rlnRelayDynamic: false,
|
||||||
rlnRelayPubsubTopic: rlnRelayPubSubTopic,
|
rlnRelayPubsubTopic: rlnRelayPubSubTopic,
|
||||||
rlnRelayContentTopic: contentTopic,
|
rlnRelayContentTopic: contentTopic,
|
||||||
rlnRelayMembershipIndex: some(MembershipIndex(2)),
|
rlnRelayCredIndex: 2.uint,
|
||||||
))
|
))
|
||||||
|
|
||||||
await node2.start()
|
await node2.start()
|
||||||
|
@ -264,7 +264,7 @@ procSuite "WakuNode - RLN relay":
|
||||||
await node3.mountRlnRelay(WakuRlnConfig(rlnRelayDynamic: false,
|
await node3.mountRlnRelay(WakuRlnConfig(rlnRelayDynamic: false,
|
||||||
rlnRelayPubsubTopic: rlnRelayPubSubTopic,
|
rlnRelayPubsubTopic: rlnRelayPubSubTopic,
|
||||||
rlnRelayContentTopic: contentTopic,
|
rlnRelayContentTopic: contentTopic,
|
||||||
rlnRelayMembershipIndex: some(MembershipIndex(3)),
|
rlnRelayCredIndex: 3.uint,
|
||||||
))
|
))
|
||||||
|
|
||||||
await node3.start()
|
await node3.start()
|
||||||
|
|
|
@ -49,6 +49,8 @@ type
|
||||||
registrationTxHash*: Option[TxHash]
|
registrationTxHash*: Option[TxHash]
|
||||||
chainId*: Option[Quantity]
|
chainId*: Option[Quantity]
|
||||||
keystorePath*: Option[string]
|
keystorePath*: Option[string]
|
||||||
|
keystoreIndex*: uint
|
||||||
|
membershipGroupIndex*: uint
|
||||||
keystorePassword*: Option[string]
|
keystorePassword*: Option[string]
|
||||||
saveKeystore*: bool
|
saveKeystore*: bool
|
||||||
registrationHandler*: Option[RegistrationHandler]
|
registrationHandler*: Option[RegistrationHandler]
|
||||||
|
@ -440,9 +442,8 @@ method init*(g: OnchainGroupManager): Future[void] {.async.} =
|
||||||
let parsedCreds = parsedCredsRes.get()
|
let parsedCreds = parsedCredsRes.get()
|
||||||
if parsedCreds.len == 0:
|
if parsedCreds.len == 0:
|
||||||
raise newException(ValueError, "keystore is empty")
|
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[g.keystoreIndex].identityCredential)
|
||||||
g.idCredentials = some(parsedCreds[0].identityCredential)
|
g.membershipIndex = some(parsedCreds[g.keystoreIndex].membershipGroups[g.membershipGroupIndex].treeIndex)
|
||||||
g.membershipIndex = some(parsedCreds[0].membershipGroups[0].treeIndex)
|
|
||||||
|
|
||||||
ethRpc.ondisconnect = proc() =
|
ethRpc.ondisconnect = proc() =
|
||||||
error "Ethereum client disconnected"
|
error "Ethereum client disconnected"
|
||||||
|
|
|
@ -16,9 +16,6 @@ template initializedGuard*(g: StaticGroupManager): untyped =
|
||||||
raise newException(ValueError, "StaticGroupManager is not initialized")
|
raise newException(ValueError, "StaticGroupManager is not initialized")
|
||||||
|
|
||||||
method init*(g: StaticGroupManager): Future[void] {.async,gcsafe.} =
|
method init*(g: StaticGroupManager): Future[void] {.async,gcsafe.} =
|
||||||
if g.membershipIndex.isNone():
|
|
||||||
raise newException(ValueError, "Membership index is not set")
|
|
||||||
|
|
||||||
let
|
let
|
||||||
groupSize = g.groupSize
|
groupSize = g.groupSize
|
||||||
groupKeys = g.groupKeys
|
groupKeys = g.groupKeys
|
||||||
|
|
|
@ -32,7 +32,8 @@ type WakuRlnConfig* = object
|
||||||
rlnRelayDynamic*: bool
|
rlnRelayDynamic*: bool
|
||||||
rlnRelayPubsubTopic*: PubsubTopic
|
rlnRelayPubsubTopic*: PubsubTopic
|
||||||
rlnRelayContentTopic*: ContentTopic
|
rlnRelayContentTopic*: ContentTopic
|
||||||
rlnRelayMembershipIndex*: Option[uint]
|
rlnRelayCredIndex*: uint
|
||||||
|
rlnRelayMembershipGroupIndex*: uint
|
||||||
rlnRelayEthContractAddress*: string
|
rlnRelayEthContractAddress*: string
|
||||||
rlnRelayEthClientAddress*: string
|
rlnRelayEthClientAddress*: string
|
||||||
rlnRelayEthAccountPrivateKey*: string
|
rlnRelayEthAccountPrivateKey*: string
|
||||||
|
@ -348,7 +349,7 @@ proc mount(conf: WakuRlnConfig,
|
||||||
raise newException(ValueError, "Static group keys are not valid")
|
raise newException(ValueError, "Static group keys are not valid")
|
||||||
groupManager = StaticGroupManager(groupSize: StaticGroupSize,
|
groupManager = StaticGroupManager(groupSize: StaticGroupSize,
|
||||||
groupKeys: parsedGroupKeysRes.get(),
|
groupKeys: parsedGroupKeysRes.get(),
|
||||||
membershipIndex: conf.rlnRelayMembershipIndex,
|
membershipIndex: some(conf.rlnRelayCredIndex),
|
||||||
rlnInstance: rlnInstance)
|
rlnInstance: rlnInstance)
|
||||||
# we don't persist credentials in static mode since they exist in ./constants.nim
|
# we don't persist credentials in static mode since they exist in ./constants.nim
|
||||||
else:
|
else:
|
||||||
|
@ -366,6 +367,8 @@ proc mount(conf: WakuRlnConfig,
|
||||||
registrationHandler: registrationHandler,
|
registrationHandler: registrationHandler,
|
||||||
keystorePath: rlnRelayCredPath,
|
keystorePath: rlnRelayCredPath,
|
||||||
keystorePassword: rlnRelayCredentialsPassword,
|
keystorePassword: rlnRelayCredentialsPassword,
|
||||||
|
keystoreIndex: conf.rlnRelayCredIndex,
|
||||||
|
membershipGroupIndex: conf.rlnRelayMembershipGroupIndex,
|
||||||
saveKeystore: true)
|
saveKeystore: true)
|
||||||
|
|
||||||
# Initialize the groupManager
|
# Initialize the groupManager
|
||||||
|
|
Loading…
Reference in New Issue