From da16f760021b49f060c9a72e541f48cade169775 Mon Sep 17 00:00:00 2001 From: Gabriel mermelstein Date: Tue, 13 Feb 2024 15:35:41 +0200 Subject: [PATCH 1/9] checking for file existence and debug print --- .../group_manager/on_chain/group_manager.nim | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/waku/waku_rln_relay/group_manager/on_chain/group_manager.nim b/waku/waku_rln_relay/group_manager/on_chain/group_manager.nim index d393b4ec13..225b0dfb2b 100644 --- a/waku/waku_rln_relay/group_manager/on_chain/group_manager.nim +++ b/waku/waku_rln_relay/group_manager/on_chain/group_manager.nim @@ -4,6 +4,7 @@ else: {.push raises: [].} import + os, web3, web3/ethtypes, eth/keys as keys, @@ -622,7 +623,11 @@ method init*(g: OnchainGroupManager): Future[void] {.async.} = g.rlnContract = some(rlnContract) g.registryContract = some(registryContract) - if g.keystorePath.isSome() and g.keystorePassword.isSome(): + # debug + if g.keystorePath.isSome(): + echo "------------------- g.keystorePath.get(): ", g.keystorePath.get() + # + if g.keystorePath.isSome() and existsFile(g.keystorePath.get()) g.keystorePassword.isSome(): var keystoreQuery = KeystoreMembership( membershipContract: MembershipContract( chainId: $g.chainId.get(), From 25867667057a411397ae5bc0bc4688e402d019e0 Mon Sep 17 00:00:00 2001 From: Gabriel mermelstein Date: Tue, 13 Feb 2024 15:38:45 +0200 Subject: [PATCH 2/9] add missing and --- waku/waku_rln_relay/group_manager/on_chain/group_manager.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/waku/waku_rln_relay/group_manager/on_chain/group_manager.nim b/waku/waku_rln_relay/group_manager/on_chain/group_manager.nim index 225b0dfb2b..e99c37240c 100644 --- a/waku/waku_rln_relay/group_manager/on_chain/group_manager.nim +++ b/waku/waku_rln_relay/group_manager/on_chain/group_manager.nim @@ -627,7 +627,7 @@ method init*(g: OnchainGroupManager): Future[void] {.async.} = if g.keystorePath.isSome(): echo "------------------- g.keystorePath.get(): ", g.keystorePath.get() # - if g.keystorePath.isSome() and existsFile(g.keystorePath.get()) g.keystorePassword.isSome(): + if g.keystorePath.isSome() and existsFile(g.keystorePath.get()) and g.keystorePassword.isSome(): var keystoreQuery = KeystoreMembership( membershipContract: MembershipContract( chainId: $g.chainId.get(), From 64ef1af16b2841fb2dd253d6cab11e3b91f89e3e Mon Sep 17 00:00:00 2001 From: Gabriel mermelstein Date: Tue, 13 Feb 2024 16:15:52 +0200 Subject: [PATCH 3/9] remove debug logs --- waku/waku_rln_relay/group_manager/on_chain/group_manager.nim | 4 ---- 1 file changed, 4 deletions(-) diff --git a/waku/waku_rln_relay/group_manager/on_chain/group_manager.nim b/waku/waku_rln_relay/group_manager/on_chain/group_manager.nim index e99c37240c..46a516dd03 100644 --- a/waku/waku_rln_relay/group_manager/on_chain/group_manager.nim +++ b/waku/waku_rln_relay/group_manager/on_chain/group_manager.nim @@ -623,10 +623,6 @@ method init*(g: OnchainGroupManager): Future[void] {.async.} = g.rlnContract = some(rlnContract) g.registryContract = some(registryContract) - # debug - if g.keystorePath.isSome(): - echo "------------------- g.keystorePath.get(): ", g.keystorePath.get() - # if g.keystorePath.isSome() and existsFile(g.keystorePath.get()) and g.keystorePassword.isSome(): var keystoreQuery = KeystoreMembership( membershipContract: MembershipContract( From fcfd700808adbe3ee09cacd8110b43d316837504 Mon Sep 17 00:00:00 2001 From: Gabriel mermelstein Date: Wed, 14 Feb 2024 10:07:31 +0200 Subject: [PATCH 4/9] logging when keystore path is provided but file doesn't exist --- .../group_manager/on_chain/group_manager.nim | 65 ++++++++++--------- 1 file changed, 34 insertions(+), 31 deletions(-) diff --git a/waku/waku_rln_relay/group_manager/on_chain/group_manager.nim b/waku/waku_rln_relay/group_manager/on_chain/group_manager.nim index 46a516dd03..8fbe5f70b5 100644 --- a/waku/waku_rln_relay/group_manager/on_chain/group_manager.nim +++ b/waku/waku_rln_relay/group_manager/on_chain/group_manager.nim @@ -623,38 +623,41 @@ method init*(g: OnchainGroupManager): Future[void] {.async.} = g.rlnContract = some(rlnContract) g.registryContract = some(registryContract) - if g.keystorePath.isSome() and existsFile(g.keystorePath.get()) and g.keystorePassword.isSome(): - var keystoreQuery = KeystoreMembership( - membershipContract: MembershipContract( - chainId: $g.chainId.get(), - address: g.ethContractAddress + if g.keystorePath.isSome() and g.keystorePassword.isSome(): + if existsFile(g.keystorePath.get()): + var keystoreQuery = KeystoreMembership( + membershipContract: MembershipContract( + chainId: $g.chainId.get(), + address: g.ethContractAddress + ) ) - ) - if g.membershipIndex.isSome(): - keystoreQuery.treeIndex = MembershipIndex(g.membershipIndex.get()) - waku_rln_membership_credentials_import_duration_seconds.nanosecondTime: - let keystoreCredRes = getMembershipCredentials(path = g.keystorePath.get(), - password = g.keystorePassword.get(), - query = keystoreQuery, - appInfo = RLNAppInfo) - if keystoreCredRes.isErr(): - raise newException(CatchableError, "could not parse the keystore: " & $keystoreCredRes.error) - let keystoreCred = keystoreCredRes.get() - g.membershipIndex = some(keystoreCred.treeIndex) - when defined(rln_v2): - g.userMessageLimit = some(keystoreCred.userMessageLimit) - # now we check on the contract if the commitment actually has a membership - try: - let membershipExists = await rlnContract.memberExists(keystoreCred - .identityCredential - .idCommitment.toUInt256()).call() - if membershipExists == 0: - raise newException(CatchableError, "the provided commitment does not have a membership") - except CatchableError: - raise newException(CatchableError, "could not check if the commitment exists on the contract: " & - getCurrentExceptionMsg()) - - g.idCredentials = some(keystoreCred.identityCredential) + if g.membershipIndex.isSome(): + keystoreQuery.treeIndex = MembershipIndex(g.membershipIndex.get()) + waku_rln_membership_credentials_import_duration_seconds.nanosecondTime: + let keystoreCredRes = getMembershipCredentials(path = g.keystorePath.get(), + password = g.keystorePassword.get(), + query = keystoreQuery, + appInfo = RLNAppInfo) + if keystoreCredRes.isErr(): + raise newException(CatchableError, "could not parse the keystore: " & $keystoreCredRes.error) + let keystoreCred = keystoreCredRes.get() + g.membershipIndex = some(keystoreCred.treeIndex) + when defined(rln_v2): + g.userMessageLimit = some(keystoreCred.userMessageLimit) + # now we check on the contract if the commitment actually has a membership + try: + let membershipExists = await rlnContract.memberExists(keystoreCred + .identityCredential + .idCommitment.toUInt256()).call() + if membershipExists == 0: + raise newException(CatchableError, "the provided commitment does not have a membership") + except CatchableError: + raise newException(CatchableError, "could not check if the commitment exists on the contract: " & + getCurrentExceptionMsg()) + + g.idCredentials = some(keystoreCred.identityCredential) + else: + warn "File provided as keystore path does not exist", path=g.keystorePath.get() let metadataGetRes = g.rlnInstance.getMetadata() if metadataGetRes.isErr(): From ea608d71afdad59b5d47f9a33b0b371b394c779c Mon Sep 17 00:00:00 2001 From: Gabriel mermelstein Date: Wed, 14 Feb 2024 14:27:17 +0200 Subject: [PATCH 5/9] Raising exception, added test case --- tests/waku_rln_relay/test_rln_group_manager_onchain.nim | 7 +++++++ .../group_manager/on_chain/group_manager.nim | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/waku_rln_relay/test_rln_group_manager_onchain.nim b/tests/waku_rln_relay/test_rln_group_manager_onchain.nim index 7c95ee763a..9087aef5fb 100644 --- a/tests/waku_rln_relay/test_rln_group_manager_onchain.nim +++ b/tests/waku_rln_relay/test_rln_group_manager_onchain.nim @@ -223,6 +223,13 @@ suite "Onchain group manager": rlnInstance: manager.rlnInstance) expect(ValueError): await manager2.init() + asyncTest "should error when keystore path and password are provided but file doesn't exist": + let manager = await setup() + manager.keystorePath = some("/inexistent/file") + manager.keystorePassword = some("password") + + expect(CatchableError): await manager.init() + asyncTest "startGroupSync: should start group sync": let manager = await setup() diff --git a/waku/waku_rln_relay/group_manager/on_chain/group_manager.nim b/waku/waku_rln_relay/group_manager/on_chain/group_manager.nim index 8fbe5f70b5..11854b63fc 100644 --- a/waku/waku_rln_relay/group_manager/on_chain/group_manager.nim +++ b/waku/waku_rln_relay/group_manager/on_chain/group_manager.nim @@ -657,7 +657,8 @@ method init*(g: OnchainGroupManager): Future[void] {.async.} = g.idCredentials = some(keystoreCred.identityCredential) else: - warn "File provided as keystore path does not exist", path=g.keystorePath.get() + error "File provided as keystore path does not exist", path=g.keystorePath.get() + raise newException(CatchableError, "missing keystore") let metadataGetRes = g.rlnInstance.getMetadata() if metadataGetRes.isErr(): From 194f64102215e9269e80c573c2fc18d4e7f16341 Mon Sep 17 00:00:00 2001 From: Gabriel mermelstein Date: Wed, 14 Feb 2024 16:18:41 +0200 Subject: [PATCH 6/9] refactor --- .../group_manager/on_chain/group_manager.nim | 66 +++++++++---------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/waku/waku_rln_relay/group_manager/on_chain/group_manager.nim b/waku/waku_rln_relay/group_manager/on_chain/group_manager.nim index 11854b63fc..625a2e99e8 100644 --- a/waku/waku_rln_relay/group_manager/on_chain/group_manager.nim +++ b/waku/waku_rln_relay/group_manager/on_chain/group_manager.nim @@ -624,41 +624,41 @@ method init*(g: OnchainGroupManager): Future[void] {.async.} = g.registryContract = some(registryContract) if g.keystorePath.isSome() and g.keystorePassword.isSome(): - if existsFile(g.keystorePath.get()): - var keystoreQuery = KeystoreMembership( - membershipContract: MembershipContract( - chainId: $g.chainId.get(), - address: g.ethContractAddress - ) - ) - if g.membershipIndex.isSome(): - keystoreQuery.treeIndex = MembershipIndex(g.membershipIndex.get()) - waku_rln_membership_credentials_import_duration_seconds.nanosecondTime: - let keystoreCredRes = getMembershipCredentials(path = g.keystorePath.get(), - password = g.keystorePassword.get(), - query = keystoreQuery, - appInfo = RLNAppInfo) - if keystoreCredRes.isErr(): - raise newException(CatchableError, "could not parse the keystore: " & $keystoreCredRes.error) - let keystoreCred = keystoreCredRes.get() - g.membershipIndex = some(keystoreCred.treeIndex) - when defined(rln_v2): - g.userMessageLimit = some(keystoreCred.userMessageLimit) - # now we check on the contract if the commitment actually has a membership - try: - let membershipExists = await rlnContract.memberExists(keystoreCred - .identityCredential - .idCommitment.toUInt256()).call() - if membershipExists == 0: - raise newException(CatchableError, "the provided commitment does not have a membership") - except CatchableError: - raise newException(CatchableError, "could not check if the commitment exists on the contract: " & - getCurrentExceptionMsg()) - - g.idCredentials = some(keystoreCred.identityCredential) - else: + if not existsFile(g.keystorePath.get()): error "File provided as keystore path does not exist", path=g.keystorePath.get() raise newException(CatchableError, "missing keystore") + + var keystoreQuery = KeystoreMembership( + membershipContract: MembershipContract( + chainId: $g.chainId.get(), + address: g.ethContractAddress + ) + ) + if g.membershipIndex.isSome(): + keystoreQuery.treeIndex = MembershipIndex(g.membershipIndex.get()) + waku_rln_membership_credentials_import_duration_seconds.nanosecondTime: + let keystoreCredRes = getMembershipCredentials(path = g.keystorePath.get(), + password = g.keystorePassword.get(), + query = keystoreQuery, + appInfo = RLNAppInfo) + if keystoreCredRes.isErr(): + raise newException(CatchableError, "could not parse the keystore: " & $keystoreCredRes.error) + let keystoreCred = keystoreCredRes.get() + g.membershipIndex = some(keystoreCred.treeIndex) + when defined(rln_v2): + g.userMessageLimit = some(keystoreCred.userMessageLimit) + # now we check on the contract if the commitment actually has a membership + try: + let membershipExists = await rlnContract.memberExists(keystoreCred + .identityCredential + .idCommitment.toUInt256()).call() + if membershipExists == 0: + raise newException(CatchableError, "the provided commitment does not have a membership") + except CatchableError: + raise newException(CatchableError, "could not check if the commitment exists on the contract: " & + getCurrentExceptionMsg()) + + g.idCredentials = some(keystoreCred.identityCredential) let metadataGetRes = g.rlnInstance.getMetadata() if metadataGetRes.isErr(): From dd1db7933e17fd5b7e15c3d6c43f7b156e10a5ce Mon Sep 17 00:00:00 2001 From: Gabriel mermelstein Date: Wed, 14 Feb 2024 16:22:07 +0200 Subject: [PATCH 7/9] fix spaces --- .../group_manager/on_chain/group_manager.nim | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/waku/waku_rln_relay/group_manager/on_chain/group_manager.nim b/waku/waku_rln_relay/group_manager/on_chain/group_manager.nim index 625a2e99e8..2a26adc325 100644 --- a/waku/waku_rln_relay/group_manager/on_chain/group_manager.nim +++ b/waku/waku_rln_relay/group_manager/on_chain/group_manager.nim @@ -638,9 +638,9 @@ method init*(g: OnchainGroupManager): Future[void] {.async.} = keystoreQuery.treeIndex = MembershipIndex(g.membershipIndex.get()) waku_rln_membership_credentials_import_duration_seconds.nanosecondTime: let keystoreCredRes = getMembershipCredentials(path = g.keystorePath.get(), - password = g.keystorePassword.get(), - query = keystoreQuery, - appInfo = RLNAppInfo) + password = g.keystorePassword.get(), + query = keystoreQuery, + appInfo = RLNAppInfo) if keystoreCredRes.isErr(): raise newException(CatchableError, "could not parse the keystore: " & $keystoreCredRes.error) let keystoreCred = keystoreCredRes.get() @@ -656,8 +656,7 @@ method init*(g: OnchainGroupManager): Future[void] {.async.} = raise newException(CatchableError, "the provided commitment does not have a membership") except CatchableError: raise newException(CatchableError, "could not check if the commitment exists on the contract: " & - getCurrentExceptionMsg()) - + getCurrentExceptionMsg()) g.idCredentials = some(keystoreCred.identityCredential) let metadataGetRes = g.rlnInstance.getMetadata() From d7e0047e335dcd6cfe702492fd3b773002992055 Mon Sep 17 00:00:00 2001 From: Gabriel mermelstein Date: Wed, 14 Feb 2024 16:23:43 +0200 Subject: [PATCH 8/9] restoring new line --- waku/waku_rln_relay/group_manager/on_chain/group_manager.nim | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/waku/waku_rln_relay/group_manager/on_chain/group_manager.nim b/waku/waku_rln_relay/group_manager/on_chain/group_manager.nim index 2a26adc325..a6572f030c 100644 --- a/waku/waku_rln_relay/group_manager/on_chain/group_manager.nim +++ b/waku/waku_rln_relay/group_manager/on_chain/group_manager.nim @@ -656,7 +656,8 @@ method init*(g: OnchainGroupManager): Future[void] {.async.} = raise newException(CatchableError, "the provided commitment does not have a membership") except CatchableError: raise newException(CatchableError, "could not check if the commitment exists on the contract: " & - getCurrentExceptionMsg()) + getCurrentExceptionMsg()) + g.idCredentials = some(keystoreCred.identityCredential) let metadataGetRes = g.rlnInstance.getMetadata() From 85b4553e2dc35fe19b5a7961200edab697e0218e Mon Sep 17 00:00:00 2001 From: Gabriel mermelstein Date: Wed, 14 Feb 2024 16:24:53 +0200 Subject: [PATCH 9/9] more spaces --- waku/waku_rln_relay/group_manager/on_chain/group_manager.nim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/waku/waku_rln_relay/group_manager/on_chain/group_manager.nim b/waku/waku_rln_relay/group_manager/on_chain/group_manager.nim index a6572f030c..e4be3cd262 100644 --- a/waku/waku_rln_relay/group_manager/on_chain/group_manager.nim +++ b/waku/waku_rln_relay/group_manager/on_chain/group_manager.nim @@ -656,8 +656,8 @@ method init*(g: OnchainGroupManager): Future[void] {.async.} = raise newException(CatchableError, "the provided commitment does not have a membership") except CatchableError: raise newException(CatchableError, "could not check if the commitment exists on the contract: " & - getCurrentExceptionMsg()) - + getCurrentExceptionMsg()) + g.idCredentials = some(keystoreCred.identityCredential) let metadataGetRes = g.rlnInstance.getMetadata()