From 2c1b9b9095cde80c4d1e7e960cf7fad4b2b4898d Mon Sep 17 00:00:00 2001 From: Mononaut Date: Mon, 17 Jul 2023 18:21:44 +0900 Subject: [PATCH] Fix mempool update poll delay --- backend/src/index.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/backend/src/index.ts b/backend/src/index.ts index 81863a208..bbfaa9ff3 100644 --- a/backend/src/index.ts +++ b/backend/src/index.ts @@ -169,6 +169,7 @@ class Server { } async runMainUpdateLoop(): Promise { + const start = Date.now(); try { try { await memPool.$updateMemPoolInfo(); @@ -188,7 +189,9 @@ class Server { indexer.$run(); // rerun immediately if we skipped the mempool update, otherwise wait POLL_RATE_MS - setTimeout(this.runMainUpdateLoop.bind(this), numHandledBlocks > 0 ? 1 : config.MEMPOOL.POLL_RATE_MS); + const elapsed = Date.now() - start; + const remainingTime = Math.max(0, config.MEMPOOL.POLL_RATE_MS - elapsed) + setTimeout(this.runMainUpdateLoop.bind(this), numHandledBlocks > 0 ? 0 : remainingTime); this.backendRetryCount = 0; } catch (e: any) { this.backendRetryCount++;