Skip to content

Commit

Permalink
fix(rln_keystore_generator): improve error handling for unrecoverable…
Browse files Browse the repository at this point in the history
… failure (#2881)
  • Loading branch information
rymnc authored Jul 10, 2024
1 parent 4ac4ab2 commit 1c9eb27
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
4 changes: 4 additions & 0 deletions tests/waku_rln_relay/test_rln_group_manager_onchain.nim
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ proc setup(): Future[OnchainGroupManager] {.async.} =
chainId: CHAIN_ID,
ethPrivateKey: pk,
rlnInstance: rlnInstance,
onFatalErrorAction: proc (errStr: string) =
raiseAssert errStr
)

return manager
Expand Down Expand Up @@ -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"
Expand Down
8 changes: 8 additions & 0 deletions tools/rln_keystore_generator/rln_keystore_generator.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions waku/waku_rln_relay/group_manager/on_chain/retry_wrapper.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
Expand Down

0 comments on commit 1c9eb27

Please sign in to comment.