From 7489d3360a1c20a029f094d82bc23be685ab572f Mon Sep 17 00:00:00 2001 From: softsimon Date: Sun, 14 Feb 2021 20:32:00 +0700 Subject: [PATCH] Make clear protection timeout configurable. fixes #335 --- backend/mempool-config.sample.json | 3 ++- backend/src/api/mempool.ts | 3 +-- backend/src/config.ts | 4 +++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/backend/mempool-config.sample.json b/backend/mempool-config.sample.json index d0d2f486c..82bcfbe56 100644 --- a/backend/mempool-config.sample.json +++ b/backend/mempool-config.sample.json @@ -6,7 +6,8 @@ "SPAWN_CLUSTER_PROCS": 0, "API_URL_PREFIX": "/api/v1/", "POLL_RATE_MS": 2000, - "CACHE_DIR": "./cache" + "CACHE_DIR": "./cache", + "CLEAR_PROTECTION_MINUTES": 20 }, "CORE_RPC": { "HOST": "127.0.0.1", diff --git a/backend/src/api/mempool.ts b/backend/src/api/mempool.ts index 641825577..83367a6ac 100644 --- a/backend/src/api/mempool.ts +++ b/backend/src/api/mempool.ts @@ -10,7 +10,6 @@ import loadingIndicators from './loading-indicators'; class Mempool { private static WEBSOCKET_REFRESH_RATE_MS = 10000; - private static CLEAR_PROTECTION_MINUTES = 10; private inSync: boolean = false; private mempoolCache: { [txId: string]: TransactionExtended } = {}; private mempoolInfo: IBitcoinApi.MempoolInfo = { loaded: false, size: 0, bytes: 0, usage: 0, @@ -143,7 +142,7 @@ class Mempool { setTimeout(() => { this.mempoolProtection = 2; logger.warn('Mempool clear protection resumed.'); - }, 1000 * 60 * Mempool.CLEAR_PROTECTION_MINUTES); + }, 1000 * 60 * config.MEMPOOL.CLEAR_PROTECTION_MINUTES); } let newMempool = {}; diff --git a/backend/src/config.ts b/backend/src/config.ts index 0037da6d2..1b3db8142 100644 --- a/backend/src/config.ts +++ b/backend/src/config.ts @@ -9,6 +9,7 @@ interface IConfig { API_URL_PREFIX: string; POLL_RATE_MS: number; CACHE_DIR: string; + CLEAR_PROTECTION_MINUTES: number; }; ESPLORA: { REST_API_URL: string; @@ -61,7 +62,8 @@ const defaults: IConfig = { 'SPAWN_CLUSTER_PROCS': 0, 'API_URL_PREFIX': '/api/v1/', 'POLL_RATE_MS': 2000, - 'CACHE_DIR': './cache' + 'CACHE_DIR': './cache', + 'CLEAR_PROTECTION_MINUTES': 20, }, 'ESPLORA': { 'REST_API_URL': 'http://127.0.0.1:3000',