diff --git a/vendor/zerokit b/vendor/zerokit index 8a365f0c9e..c6b7a8c0a4 160000 --- a/vendor/zerokit +++ b/vendor/zerokit @@ -1 +1 @@ -Subproject commit 8a365f0c9e5c4a744f70c5dd4904ce8d8f926c34 +Subproject commit c6b7a8c0a401dc9a3f5b0511ebfb8727fc19b53a diff --git a/waku/v2/node/waku_node.nim b/waku/v2/node/waku_node.nim index df8b3b0a5f..57d0d7a848 100644 --- a/waku/v2/node/waku_node.nim +++ b/waku/v2/node/waku_node.nim @@ -828,4 +828,8 @@ proc stop*(node: WakuNode) {.async.} = await node.switch.stop() node.peerManager.stop() + when defined(rln): + if not node.wakuRlnRelay.isNil(): + await node.wakuRlnRelay.stop() + node.started = false diff --git a/waku/v2/waku_rln_relay/group_manager/group_manager_base.nim b/waku/v2/waku_rln_relay/group_manager/group_manager_base.nim index 31878632d1..273d2421f8 100644 --- a/waku/v2/waku_rln_relay/group_manager/group_manager_base.nim +++ b/waku/v2/waku_rln_relay/group_manager/group_manager_base.nim @@ -89,6 +89,9 @@ method withdrawBatch*(g: GroupManager, identitySecretHashes: seq[IdentitySecretH method atomicBatch*(g: GroupManager, idCommitments: seq[IDCommitment], toRemoveIndices: seq[MembershipIndex]): Future[void] {.base,gcsafe.} = raise newException(CatchableError, "atomicBatch proc for " & $g.type & " is not implemented yet") +method close*(g: GroupManager): Future[void] {.base,gcsafe.} = + raise newException(CatchableError, "close proc for " & $g.type & " is not implemented yet") + # This proc is used to set a callback that will be called when an identity commitment is withdrawn # The callback may be called multiple times, and should be used to for any post processing method onWithdraw*(g: GroupManager, cb: OnWithdrawCallback) {.base,gcsafe.} = 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 8f484eca0c..a4c928c779 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 @@ -496,3 +496,10 @@ method init*(g: OnchainGroupManager): Future[void] {.async.} = error "failed to restart group sync", error = getCurrentExceptionMsg() g.initialized = true + +method close*(g: OnchainGroupManager): Future[void] {.async.} = + if g.ethRpc.isSome(): + await g.ethRpc.get().close() + let connClosed = g.rlnInstance.closeDbConnection() + if not connClosed: + error "failed to close the tree db connection" \ No newline at end of file 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 3a3d831230..cf03522700 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 @@ -102,3 +102,10 @@ method onRegister*(g: StaticGroupManager, cb: OnRegisterCallback) {.gcsafe.} = method onWithdraw*(g: StaticGroupManager, cb: OnWithdrawCallback) {.gcsafe.} = g.withdrawCb = some(cb) + +method close*(g: StaticGroupManager): Future[void] = + initializedGuard(g) + # No-op + var retFut = newFuture[void]("StaticGroupManager.close") + retFut.complete() + return retFut diff --git a/waku/v2/waku_rln_relay/rln/rln_interface.nim b/waku/v2/waku_rln_relay/rln/rln_interface.nim index 34def0f289..9195cfd9da 100644 --- a/waku/v2/waku_rln_relay/rln/rln_interface.nim +++ b/waku/v2/waku_rln_relay/rln/rln_interface.nim @@ -188,3 +188,8 @@ proc get_metadata*(ctx: ptr RLN, output_buffer: ptr Buffer): bool {.importc: "ge ## gets the metadata stored by ctx and populates the passed pointer output_buffer with it ## the output_buffer holds the metadata as a byte seq ## the return bool value indicates the success or failure of the operation + +proc close_db_connection*(ctx: ptr RLN): bool {.importc: "close_db_connection".} +## closes the connection to the database +## the return bool value indicates the success or failure of the operation +## This allows more robust and graceful handling of the database connection \ No newline at end of file diff --git a/waku/v2/waku_rln_relay/rln_relay.nim b/waku/v2/waku_rln_relay/rln_relay.nim index 0c04c18a06..13e20074f7 100644 --- a/waku/v2/waku_rln_relay/rln_relay.nim +++ b/waku/v2/waku_rln_relay/rln_relay.nim @@ -90,6 +90,13 @@ type WakuRLNRelay* = ref object of RootObj groupManager*: GroupManager messageBucket*: Option[TokenBucket] +method stop*(rlnPeer: WakuRLNRelay) {.async.} = + ## stops the rln-relay protocol + ## Throws an error if it cannot stop the rln-relay protocol + + # stop the group sync, and flush data to tree db + await rlnPeer.groupManager.close() + proc hasDuplicate*(rlnPeer: WakuRLNRelay, proofMetadata: ProofMetadata): RlnRelayResult[bool] = ## returns true if there is another message in the `nullifierLog` of the `rlnPeer` with the same