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

This commit is contained in:
Aaryamann Challani 2024-07-10 19:12:49 +02:00 committed by GitHub
parent 4ac4ab2a41
commit 1c9eb27415
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 15 additions and 1 deletions

View File

@ -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"

View File

@ -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:

View File

@ -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)

View File

@ -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 = ""