Merge pull request #4079 from mempool/simon/mempool-break-poll-limit

Base mempool break limit of current poll rate
This commit is contained in:
softsimon 2023-08-01 16:00:42 +09:00 committed by GitHub
commit 22e57ae95c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 5 deletions

View file

@ -182,7 +182,7 @@ class Mempool {
return txTimes; return txTimes;
} }
public async $updateMempool(transactions: string[]): Promise<void> { public async $updateMempool(transactions: string[], pollRate: number): Promise<void> {
logger.debug(`Updating mempool...`); logger.debug(`Updating mempool...`);
// warn if this run stalls the main loop for more than 2 minutes // warn if this run stalls the main loop for more than 2 minutes
@ -258,7 +258,7 @@ class Mempool {
} }
} }
if (Date.now() - intervalTimer > 5_000) { if (Date.now() - intervalTimer > Math.max(pollRate * 2, 5_000)) {
if (this.inSync) { if (this.inSync) {
// Break and restart mempool loop if we spend too much time processing // Break and restart mempool loop if we spend too much time processing
// new transactions that may lead to falling behind on block height // new transactions that may lead to falling behind on block height
@ -270,7 +270,7 @@ class Mempool {
if (Math.floor(progress) < 100) { if (Math.floor(progress) < 100) {
loadingIndicators.setProgress('mempool', progress); loadingIndicators.setProgress('mempool', progress);
} }
intervalTimer = Date.now() intervalTimer = Date.now();
} }
} }
} }

View file

@ -188,14 +188,14 @@ class Server {
} }
const newMempool = await bitcoinApi.$getRawMempool(); const newMempool = await bitcoinApi.$getRawMempool();
const numHandledBlocks = await blocks.$updateBlocks(); const numHandledBlocks = await blocks.$updateBlocks();
const pollRate = config.MEMPOOL.POLL_RATE_MS * (indexer.indexerRunning ? 10 : 1);
if (numHandledBlocks === 0) { if (numHandledBlocks === 0) {
await memPool.$updateMempool(newMempool); await memPool.$updateMempool(newMempool, pollRate);
} }
indexer.$run(); indexer.$run();
// rerun immediately if we skipped the mempool update, otherwise wait POLL_RATE_MS // rerun immediately if we skipped the mempool update, otherwise wait POLL_RATE_MS
const elapsed = Date.now() - start; const elapsed = Date.now() - start;
const pollRate = config.MEMPOOL.POLL_RATE_MS * (indexer.indexerRunning ? 10 : 1);
const remainingTime = Math.max(0, pollRate - elapsed); const remainingTime = Math.max(0, pollRate - elapsed);
setTimeout(this.runMainUpdateLoop.bind(this), numHandledBlocks > 0 ? 0 : remainingTime); setTimeout(this.runMainUpdateLoop.bind(this), numHandledBlocks > 0 ? 0 : remainingTime);
this.backendRetryCount = 0; this.backendRetryCount = 0;