From 9c9883a6304ea110198588e12825672013c73200 Mon Sep 17 00:00:00 2001 From: Aaryamann Challani <43716372+rymnc@users.noreply.github.com> Date: Wed, 24 Apr 2024 17:11:22 +0200 Subject: [PATCH] fix(rln-relay): enforce error callback to remove exception raised from retryWrapper (#2622) --- .../group_manager/on_chain/group_manager.nim | 5 ++--- .../group_manager/on_chain/retry_wrapper.nim | 11 +++-------- 2 files changed, 5 insertions(+), 11 deletions(-) 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 118e6c5abe..f85145ad6a 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 @@ -637,7 +637,7 @@ proc startOnchainSync( var currentLatestBlock: BlockNumber g.retryWrapper(currentLatestBlock, "Failed to get the latest block number"): cast[BlockNumber](await ethRpc.provider.eth_blockNumber()) - + try: # we always want to sync from last processed block => latest # chunk events @@ -646,11 +646,10 @@ proc startOnchainSync( # then fetch the new toBlock if fromBlock >= currentLatestBlock: break - + if fromBlock + blockChunkSize.uint > currentLatestBlock.uint: g.retryWrapper(currentLatestBlock, "Failed to get the latest block number"): cast[BlockNumber](await ethRpc.provider.eth_blockNumber()) - let toBlock = min(fromBlock + BlockNumber(blockChunkSize), currentLatestBlock) debug "fetching events", fromBlock = fromBlock, toBlock = toBlock 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 74c744ab2c..1391599bcc 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 @@ -13,7 +13,7 @@ template retryWrapper*( res: auto, retryStrategy: RetryStrategy, errStr: string, - errCallback: OnFatalErrorHandler = nil, + errCallback: OnFatalErrorHandler, body: untyped, ): auto = var retryCount = retryStrategy.retryCount @@ -29,10 +29,5 @@ template retryWrapper*( exceptionMessage = getCurrentExceptionMsg() await sleepAsync(retryStrategy.retryDelay) if shouldRetry: - if errCallback == nil: - raise newException( - CatchableError, errStr & " errCallback == nil: " & exceptionMessage - ) - else: - errCallback(errStr & ": " & exceptionMessage) - return + errCallback(errStr & ": " & exceptionMessage) + return