Slow down retries on Electrs errors in the main mempool loop.

This commit is contained in:
softsimon
2020-10-18 21:47:47 +07:00
parent 2ba7cd9ebd
commit 49f70ca28a
4 changed files with 161 additions and 165 deletions

View File

@@ -27,6 +27,7 @@ class Server {
private wss: WebSocket.Server | undefined;
private server: https.Server | http.Server | undefined;
private app: Express;
private retryOnElectrsErrorAfterSeconds = 5;
constructor() {
this.app = express();
@@ -114,10 +115,18 @@ class Server {
}
async runMempoolIntervalFunctions() {
await memPool.updateMemPoolInfo();
await blocks.updateBlocks();
await memPool.updateMempool();
setTimeout(this.runMempoolIntervalFunctions.bind(this), config.ELECTRS_POLL_RATE_MS);
try {
await memPool.$updateMemPoolInfo();
await blocks.$updateBlocks();
await memPool.$updateMempool();
setTimeout(this.runMempoolIntervalFunctions.bind(this), config.ELECTRS_POLL_RATE_MS);
this.retryOnElectrsErrorAfterSeconds = 5;
} catch (e) {
this.retryOnElectrsErrorAfterSeconds *= 2;
this.retryOnElectrsErrorAfterSeconds = Math.min(this.retryOnElectrsErrorAfterSeconds, 3600);
logger.warn(`runMempoolIntervalFunctions error: ${(e.message || e)}. Retrying in ${this.retryOnElectrsErrorAfterSeconds} sec.`);
setTimeout(this.runMempoolIntervalFunctions.bind(this), 1000 * this.retryOnElectrsErrorAfterSeconds);
}
}
setUpWebsocketHandling() {