Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(rln_keystore_generator): improve error handling for unrecoverable failure #2881

Merged
merged 2 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -197,6 +197,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 @@ -256,6 +258,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 @@ -46,14 +46,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
Loading