From de4265a6d1b616555d271540ff899fb4db9919e6 Mon Sep 17 00:00:00 2001 From: Mononaut Date: Mon, 24 Jul 2023 16:19:19 +0900 Subject: [PATCH] More conservative mempool inSync status --- backend/src/api/mempool.ts | 15 ++++++++------- backend/src/api/websocket-handler.ts | 4 ++-- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/backend/src/api/mempool.ts b/backend/src/api/mempool.ts index 88533365e..9239d6b3b 100644 --- a/backend/src/api/mempool.ts +++ b/backend/src/api/mempool.ts @@ -124,7 +124,7 @@ class Mempool { } else { done = true; } - if (count < expectedCount) { + if (Math.floor(count / expectedCount) < 1) { loadingIndicators.setProgress('mempool', count / expectedCount * 100); } } else { @@ -199,6 +199,7 @@ class Mempool { let loaded = false; if (config.MEMPOOL.BACKEND === 'esplora' && currentMempoolSize < transactions.length * 0.5 && transactions.length > 20_000) { + this.inSync = false; logger.info(`Missing ${transactions.length - currentMempoolSize} mempool transactions, attempting to reload in bulk from esplora`); try { await this.$reloadMempool(transactions.length); @@ -293,12 +294,6 @@ class Mempool { const newTransactionsStripped = newTransactions.map((tx) => Common.stripTransaction(tx)); this.latestTransactions = newTransactionsStripped.concat(this.latestTransactions).slice(0, 6); - if (!this.inSync && transactions.length === newMempoolSize) { - this.inSync = true; - logger.notice('The mempool is now in sync!'); - loadingIndicators.setProgress('mempool', 100); - } - this.mempoolCacheDelta = Math.abs(transactions.length - newMempoolSize); if (this.mempoolChangedCallback && (hasChange || deletedTransactions.length)) { @@ -310,6 +305,12 @@ class Mempool { this.updateTimerProgress(timer, 'completed async mempool callback'); } + if (!this.inSync && transactions.length === newMempoolSize) { + this.inSync = true; + logger.notice('The mempool is now in sync!'); + loadingIndicators.setProgress('mempool', 100); + } + const end = new Date().getTime(); const time = end - start; logger.debug(`Mempool updated in ${time / 1000} seconds. New size: ${Object.keys(this.mempoolCache).length} (${diff > 0 ? '+' + diff : diff})`); diff --git a/backend/src/api/websocket-handler.ts b/backend/src/api/websocket-handler.ts index a0c031175..ccaeb4a8b 100644 --- a/backend/src/api/websocket-handler.ts +++ b/backend/src/api/websocket-handler.ts @@ -644,7 +644,7 @@ class WebsocketHandler { memPool.handleMinedRbfTransactions(rbfTransactions); memPool.removeFromSpendMap(transactions); - if (config.MEMPOOL.AUDIT) { + if (config.MEMPOOL.AUDIT && memPool.isInSync()) { let projectedBlocks; let auditMempool = _memPool; // template calculation functions have mempool side effects, so calculate audits using @@ -665,7 +665,7 @@ class WebsocketHandler { projectedBlocks = mempoolBlocks.getMempoolBlocksWithTransactions(); } - if (Common.indexingEnabled() && memPool.isInSync()) { + if (Common.indexingEnabled()) { const { censored, added, fresh, sigop, fullrbf, score, similarity } = Audit.auditBlock(transactions, projectedBlocks, auditMempool); const matchRate = Math.round(score * 100 * 100) / 100;