Merge pull request #3906 from mempool/simon/mempool-break-limit

Lowering mempool loop break limit
This commit is contained in:
softsimon 2023-07-03 10:08:17 +02:00 committed by GitHub
commit 4cd7561af8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -156,7 +156,7 @@ class Mempool {
} }
}; };
let loggerTimer = new Date().getTime() / 1000; let intervalTimer = Date.now();
for (const txid of transactions) { for (const txid of transactions) {
if (!this.mempoolCache[txid]) { if (!this.mempoolCache[txid]) {
try { try {
@ -179,18 +179,20 @@ class Mempool {
logger.debug(`Error finding transaction '${txid}' in the mempool: ` + (e instanceof Error ? e.message : e)); logger.debug(`Error finding transaction '${txid}' in the mempool: ` + (e instanceof Error ? e.message : e));
} }
} }
const elapsedSeconds = Math.round((new Date().getTime() / 1000) - loggerTimer);
if (elapsedSeconds > 4) { if (Date.now() - intervalTimer > 5_000) {
const progress = (currentMempoolSize + newTransactions.length) / transactions.length * 100;
logger.debug(`Mempool is synchronizing. Processed ${newTransactions.length}/${diff} txs (${Math.round(progress)}%)`); if (this.inSync) {
loadingIndicators.setProgress('mempool', progress); // Break and restart mempool loop if we spend too much time processing
loggerTimer = new Date().getTime() / 1000; // new transactions that may lead to falling behind on block height
} logger.debug('Breaking mempool loop because the 5s time limit exceeded.');
// Break and restart mempool loop if we spend too much time processing break;
// new transactions that may lead to falling behind on block height } else {
if (this.inSync && (new Date().getTime()) - start > 10_000) { const progress = (currentMempoolSize + newTransactions.length) / transactions.length * 100;
logger.debug('Breaking mempool loop because the 10s time limit exceeded.'); logger.debug(`Mempool is synchronizing. Processed ${newTransactions.length}/${diff} txs (${Math.round(progress)}%)`);
break; loadingIndicators.setProgress('mempool', progress);
intervalTimer = Date.now()
}
} }
} }