From f66f33307d3d0ef319b03a256da4057837fcb619 Mon Sep 17 00:00:00 2001 From: einhornimmond Date: Thu, 13 Nov 2025 08:36:09 +0100 Subject: [PATCH] hotfix restart gradido node if it don't get new transaction after 1 second --- .../client/GradidoNode/GradidoNodeProcess.ts | 4 ++ dlt-connector/src/client/hiero/HieroClient.ts | 24 +++++++++++ dlt-connector/src/utils/time.ts | 42 +++++++++++++++++++ 3 files changed, 70 insertions(+) create mode 100644 dlt-connector/src/utils/time.ts diff --git a/dlt-connector/src/client/GradidoNode/GradidoNodeProcess.ts b/dlt-connector/src/client/GradidoNode/GradidoNodeProcess.ts index eb2bf6b66..bedbedf38 100644 --- a/dlt-connector/src/client/GradidoNode/GradidoNodeProcess.ts +++ b/dlt-connector/src/client/GradidoNode/GradidoNodeProcess.ts @@ -97,6 +97,10 @@ export class GradidoNodeProcess { } } + public getLastStarted(): Date | null { + return this.lastStarted + } + public async exit(): Promise { this.exitCalled = true if (this.proc) { diff --git a/dlt-connector/src/client/hiero/HieroClient.ts b/dlt-connector/src/client/hiero/HieroClient.ts index 33a208b78..0ed375d62 100644 --- a/dlt-connector/src/client/hiero/HieroClient.ts +++ b/dlt-connector/src/client/hiero/HieroClient.ts @@ -22,6 +22,9 @@ import { CONFIG } from '../../config' import { LOG4JS_BASE_CATEGORY } from '../../config/const' import { HieroId, hieroIdSchema } from '../../schemas/typeGuard.schema' import { type TopicInfoOutput, topicInfoSchema } from './output.schema' +import { GradidoNodeClient } from '../GradidoNode/GradidoNodeClient' +import { GradidoNodeProcess } from '../GradidoNode/GradidoNodeProcess' +import { printTimeDuration } from '../../utils/time' // https://docs.hedera.com/hedera/sdks-and-apis/hedera-api/consensus/consensusupdatetopic export const MIN_AUTORENEW_PERIOD = 6999999 //seconds @@ -95,6 +98,27 @@ export class HieroClient { logger.info( `message sent to topic ${topicId}, transaction id: ${sendResponse.transactionId.toString()}`, ) + // TODO: fix issue in GradidoNode + // hot fix, when gradido node is running some time, the hiero listener stop working, so we check if our new transaction is received + // after 1 second, else restart GradidoNode + setTimeout(async () => { + const transaction = await GradidoNodeClient.getInstance().getTransaction({ + topic: topicId, + hieroTransactionId: sendResponse.transactionId.toString(), + }) + if (!transaction) { + const process = GradidoNodeProcess.getInstance() + const lastStarted = process.getLastStarted() + if (lastStarted) { + const serverRunTime = printTimeDuration(new Date().getTime() - lastStarted.getTime()) + this.logger.error(`transaction not found, restart GradidoNode after ${serverRunTime}`) + await GradidoNodeProcess.getInstance().restart() + } else { + this.logger.error('transaction not found, GradidoNode not running, start it') + GradidoNodeProcess.getInstance().start() + } + } + }, 1000) if (logger.isInfoEnabled()) { // only for logging sendResponse.getReceiptWithSigner(this.wallet).then((receipt) => { diff --git a/dlt-connector/src/utils/time.ts b/dlt-connector/src/utils/time.ts new file mode 100644 index 000000000..ccbb91c07 --- /dev/null +++ b/dlt-connector/src/utils/time.ts @@ -0,0 +1,42 @@ +/** + * @param {number} time - in minutes + */ +export const getTimeDurationObject = ( + time: number, +): { + hours?: number + minutes: number +} => { + if (time > 60) { + return { + hours: Math.floor(time / 60), + minutes: time % 60, + } + } + return { minutes: time } +} + +/** + * @param startDate + * @param endDate + * @returns duration in minutes + */ +export const durationInMinutesFromDates = (startDate: Date, endDate: Date): number => { + const diff = endDate.getTime() - startDate.getTime() + return Math.floor(diff / (1000 * 60)) +} + +/** + * @param duration in minutes + */ +export const printTimeDuration = (duration: number): string => { + const time = getTimeDurationObject(duration) + const result = time.minutes > 0 ? `${time.minutes} minutes` : '' + if (time.hours) { + return `${time.hours} hours` + (result !== '' ? ` and ${result}` : '') + } + if (result === '') { + return '0 minutes' + } + return result +}