From 35ae67217717e7043f0417aeb797a4674decc8be Mon Sep 17 00:00:00 2001 From: Mononaut Date: Sun, 20 Nov 2022 19:18:33 +0900 Subject: [PATCH] break long-running forensics tasks --- backend/src/tasks/lightning/network-sync.service.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/backend/src/tasks/lightning/network-sync.service.ts b/backend/src/tasks/lightning/network-sync.service.ts index ac7c7a2ca..7ff49f68b 100644 --- a/backend/src/tasks/lightning/network-sync.service.ts +++ b/backend/src/tasks/lightning/network-sync.service.ts @@ -31,6 +31,7 @@ class NetworkSyncService { } private async $runTasks(): Promise { + const taskStartTime = Date.now(); try { logger.info(`Updating nodes and channels`); @@ -57,7 +58,7 @@ class NetworkSyncService { logger.err('$runTasks() error: ' + (e instanceof Error ? e.message : e)); } - setTimeout(() => { this.$runTasks(); }, 1000 * config.LIGHTNING.GRAPH_REFRESH_INTERVAL); + setTimeout(() => { this.$runTasks(); }, Math.max(1, (1000 * config.LIGHTNING.GRAPH_REFRESH_INTERVAL) - (Date.now() - taskStartTime))); } /** @@ -353,9 +354,10 @@ class NetworkSyncService { return 1; } - // If a channel open tx spends funds from a closed channel output, + // If a channel open tx spends funds from a another channel transaction, // we can attribute that output to a specific counterparty private async $runOpenedChannelsForensics(): Promise { + const runTimer = Date.now(); let progress = 0; try { @@ -396,6 +398,9 @@ class NetworkSyncService { logger.info(`Updating opened channel forensics ${progress}/${channels?.length}`); this.loggerTimer = new Date().getTime() / 1000; } + if (Date.now() - runTimer > (config.LIGHTNING.GRAPH_REFRESH_INTERVAL * 1000)) { + break; + } } logger.info(`Open channels forensics scan complete.`);