fix(rln-relay): enforce error callback to remove exception raised from retryWrapper (#2622)

This commit is contained in:
Aaryamann Challani 2024-04-24 17:11:22 +02:00 committed by GitHub
parent 963d79aee7
commit f93e47e9eb
2 changed files with 5 additions and 11 deletions

View File

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

View File

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