From a088b962d3a1a6bb17585177facd1ebbfa1e9d86 Mon Sep 17 00:00:00 2001 From: lukas Date: Tue, 16 Jan 2024 17:40:43 +0100 Subject: [PATCH] fix: add max-attempts for finalize --- src/service/sol/finalize.ts | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/service/sol/finalize.ts b/src/service/sol/finalize.ts index 4ee508cf..def79fb0 100644 --- a/src/service/sol/finalize.ts +++ b/src/service/sol/finalize.ts @@ -2,13 +2,15 @@ import { logger } from '../../logger' import { connection } from './const' -// eslint-disable-next-line promise/avoid-new -const sleep = (ms: number) => new Promise((resolve) => { - setTimeout(resolve, ms) -}) +const sleep = (ms: number) => + // eslint-disable-next-line promise/avoid-new + new Promise((resolve) => { + setTimeout(resolve, ms) + }) export const finalize = async (sig: string): Promise => { let finalized = false + let attempts = 0 do { // eslint-disable-next-line no-await-in-loop @@ -21,8 +23,11 @@ export const finalize = async (sig: string): Promise => { finalized = true } else { - logger.info(`Waiting for finalization: ${status.value?.confirmations}`) + logger.info( + `(${++attempts}) Waiting for finalization: ${status.value + ?.confirmations}`, + ) } - } while (!finalized) + } while (!finalized || attempts > 25) logger.info(`finalized ${sig}`) }