From 1c9eb274155311c8cc6ae3b449439421d1dc4b6f Mon Sep 17 00:00:00 2001 From: Aaryamann Challani <43716372+rymnc@users.noreply.github.com> Date: Wed, 10 Jul 2024 19:12:49 +0200 Subject: [PATCH] fix(rln_keystore_generator): improve error handling for unrecoverable failure (#2881) --- tests/waku_rln_relay/test_rln_group_manager_onchain.nim | 4 ++++ tools/rln_keystore_generator/rln_keystore_generator.nim | 8 ++++++++ .../group_manager/on_chain/group_manager.nim | 2 +- .../group_manager/on_chain/retry_wrapper.nim | 2 ++ 4 files changed, 15 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 6269e23ae..80c1a2ee3 100644 --- a/tests/waku_rln_relay/test_rln_group_manager_onchain.nim +++ b/tests/waku_rln_relay/test_rln_group_manager_onchain.nim @@ -212,6 +212,8 @@ proc setup(): Future[OnchainGroupManager] {.async.} = chainId: CHAIN_ID, ethPrivateKey: pk, rlnInstance: rlnInstance, + onFatalErrorAction: proc (errStr: string) = + raiseAssert errStr ) return manager @@ -271,6 +273,8 @@ suite "Onchain group manager": ethClientUrl: EthClient, ethContractAddress: $differentContractAddress, rlnInstance: manager.rlnInstance, + onFatalErrorAction: proc (errStr: string) = + raiseAssert errStr ) (await manager2.init()).isErrOr: raiseAssert "Expected error when contract address doesn't match" diff --git a/tools/rln_keystore_generator/rln_keystore_generator.nim b/tools/rln_keystore_generator/rln_keystore_generator.nim index 187b697d8..5e8c5e642 100644 --- a/tools/rln_keystore_generator/rln_keystore_generator.nim +++ b/tools/rln_keystore_generator/rln_keystore_generator.nim @@ -48,14 +48,22 @@ proc doRlnKeystoreGenerator*(conf: WakuNodeConf) = info "not executing, exiting" quit(0) + var onFatalErrorAction = proc(msg: string) {.gcsafe, closure.} = + ## Action to be taken when an internal error occurs during the node run. + ## e.g. the connection with the database is lost and not recovered. + error "Unrecoverable error occurred", error = msg + quit(QuitFailure) + # 4. initialize OnchainGroupManager let groupManager = OnchainGroupManager( ethClientUrl: string(conf.rlnRelayethClientAddress), + chainId: conf.rlnRelayChainId, ethContractAddress: conf.rlnRelayEthContractAddress, rlnInstance: rlnInstance, keystorePath: none(string), keystorePassword: none(string), ethPrivateKey: some(conf.rlnRelayEthPrivateKey), + onFatalErrorAction: onFatalErrorAction ) try: (waitFor groupManager.init()).isOkOr: 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 5cc89a6f7..e1dabc22a 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 @@ -612,7 +612,7 @@ method init*(g: OnchainGroupManager): Future[GroupManagerResult[void]] {.async.} g.validRoots = metadata.validRoots.toDeque() var deployedBlockNumber: Uint256 - g.retryWrapper(deployedBlockNumber, "Failed to get the deployed block number"): + g.retryWrapper(deployedBlockNumber, "Failed to get the deployed block number. Have you set the correct contract address?"): await wakuRlnContract.deployedBlockNumber().call() debug "using rln contract", deployedBlockNumber, rlnContractAddress = contractAddress g.rlnContractDeployedBlockNumber = cast[BlockNumber](deployedBlockNumber) diff --git a/waku/waku_rln_relay/group_manager/on_chain/retry_wrapper.nim b/waku/waku_rln_relay/group_manager/on_chain/retry_wrapper.nim index 9ae000e3c..df8716279 100644 --- a/waku/waku_rln_relay/group_manager/on_chain/retry_wrapper.nim +++ b/waku/waku_rln_relay/group_manager/on_chain/retry_wrapper.nim @@ -17,6 +17,8 @@ template retryWrapper*( errCallback: OnFatalErrorHandler, body: untyped, ): auto = + if errCallback == nil: + raise newException(CatchableError, "Ensure that the errCallback is set") var retryCount = retryStrategy.retryCount var shouldRetry = retryStrategy.shouldRetry var exceptionMessage = ""