From 86c654f22fd0096b6edd21d830e21551f83cb9a0 Mon Sep 17 00:00:00 2001 From: softsimon Date: Thu, 15 Oct 2020 11:07:53 +0700 Subject: [PATCH] New backend config "NETWORK". Only activate mempool protection. Log network to fixes #140 --- backend/mempool-config.sample.json | 2 +- backend/src/api/fee-api.ts | 2 +- backend/src/api/mempool.ts | 3 ++- backend/src/logger.ts | 6 ++++-- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/backend/mempool-config.sample.json b/backend/mempool-config.sample.json index 018c079d2..fa989d6b1 100644 --- a/backend/mempool-config.sample.json +++ b/backend/mempool-config.sample.json @@ -8,7 +8,7 @@ "DB_DISABLED": false, "API_ENDPOINT": "/api/v1/", "ELECTRS_POLL_RATE_MS": 2000, - "LIQUID": true, + "NETWORK": "mainnet", "MEMPOOL_REFRESH_RATE_MS": 2000, "DEFAULT_PROJECTED_BLOCKS_AMOUNT": 8, "KEEP_BLOCK_AMOUNT": 24, diff --git a/backend/src/api/fee-api.ts b/backend/src/api/fee-api.ts index d593bb2bb..336252dc5 100644 --- a/backend/src/api/fee-api.ts +++ b/backend/src/api/fee-api.ts @@ -5,7 +5,7 @@ import projectedBlocks from './mempool-blocks'; class FeeApi { constructor() { } - defaultFee = config.LIQUID ? 0.1 : 1; + defaultFee = config.NETWORK === 'liquid' ? 0.1 : 1; public getRecommendedFee() { const pBlocks = projectedBlocks.getMempoolBlocks(); diff --git a/backend/src/api/mempool.ts b/backend/src/api/mempool.ts index 4967c0ffd..915fdb783 100644 --- a/backend/src/api/mempool.ts +++ b/backend/src/api/mempool.ts @@ -135,7 +135,8 @@ class Mempool { } // Prevent mempool from clear on bitcoind restart by delaying the deletion - if (this.mempoolProtection === 0 && transactions.length / currentMempoolSize <= 0.80) { + if ((config.NETWORK === 'mainnet' || !config.NETWORK) + && this.mempoolProtection === 0 && transactions.length / currentMempoolSize <= 0.80) { this.mempoolProtection = 1; this.inSync = false; logger.warn(`Mempool clear protection triggered because transactions.length: ${transactions.length} and currentMempoolSize: ${currentMempoolSize}.`); diff --git a/backend/src/logger.ts b/backend/src/logger.ts index aae6fc5a5..2721301a0 100644 --- a/backend/src/logger.ts +++ b/backend/src/logger.ts @@ -1,3 +1,4 @@ +const config = require('../mempool-config.json'); import * as dgram from 'dgram'; class Logger { @@ -82,9 +83,10 @@ class Logger { msg = msg.slice(0, msg.length - 1); } } + const network = (config.NETWORK === 'mainnet' || !config.NETWORK) ? '' : ' <' + config.NETWORK + '>'; prionum = Logger.priorities[priority] || Logger.priorities.info; - syslogmsg = `<${(this.fac * 8 + prionum)}> ${this.name}[${process.pid}]: ${priority.toUpperCase()} ${msg}`; - consolemsg = `${this.ts()} [${process.pid}] ${priority.toUpperCase()}: ${msg}`; + syslogmsg = `<${(this.fac * 8 + prionum)}> ${this.name}[${process.pid}]: ${priority.toUpperCase()}${network} ${msg}`; + consolemsg = `${this.ts()} [${process.pid}] ${priority.toUpperCase()}:${network} ${msg}`; this.syslog(syslogmsg); if (priority === 'warning') {