More conservative mempool inSync status

This commit is contained in:
Mononaut
2023-07-24 16:19:19 +09:00
parent e59c961f25
commit de4265a6d1
2 changed files with 10 additions and 9 deletions

View File

@@ -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})`);