From b31642e554d53709881a8ebc93035c4a70183a19 Mon Sep 17 00:00:00 2001 From: softsimon Date: Tue, 23 Aug 2022 20:25:29 +0400 Subject: [PATCH 1/5] Disable mempool config fixes #2090 --- backend/mempool-config.sample.json | 1 + backend/src/config.ts | 10 +++++--- backend/src/index.ts | 39 ++++++++++++++++++------------ 3 files changed, 30 insertions(+), 20 deletions(-) diff --git a/backend/mempool-config.sample.json b/backend/mempool-config.sample.json index 86d226154..c4227adce 100644 --- a/backend/mempool-config.sample.json +++ b/backend/mempool-config.sample.json @@ -2,6 +2,7 @@ "MEMPOOL": { "NETWORK": "mainnet", "BACKEND": "electrum", + "ENABLED": true, "HTTP_PORT": 8999, "SPAWN_CLUSTER_PROCS": 0, "API_URL_PREFIX": "/api/v1/", diff --git a/backend/src/config.ts b/backend/src/config.ts index 43ba16cb3..052affb45 100644 --- a/backend/src/config.ts +++ b/backend/src/config.ts @@ -4,6 +4,7 @@ const configFromFile = require( interface IConfig { MEMPOOL: { + ENABLED: boolean; NETWORK: 'mainnet' | 'testnet' | 'signet' | 'liquid' | 'liquidtestnet'; BACKEND: 'esplora' | 'electrum' | 'none'; HTTP_PORT: number; @@ -119,6 +120,7 @@ interface IConfig { const defaults: IConfig = { 'MEMPOOL': { + 'ENABLED': true, 'NETWORK': 'mainnet', 'BACKEND': 'none', 'HTTP_PORT': 8999, @@ -224,11 +226,11 @@ const defaults: IConfig = { 'BISQ_URL': 'https://bisq.markets/api', 'BISQ_ONION': 'http://bisqmktse2cabavbr2xjq7xw3h6g5ottemo5rolfcwt6aly6tp5fdryd.onion/api' }, - "MAXMIND": { + 'MAXMIND': { 'ENABLED': false, - "GEOLITE2_CITY": "/usr/local/share/GeoIP/GeoLite2-City.mmdb", - "GEOLITE2_ASN": "/usr/local/share/GeoIP/GeoLite2-ASN.mmdb", - "GEOIP2_ISP": "/usr/local/share/GeoIP/GeoIP2-ISP.mmdb" + 'GEOLITE2_CITY': '/usr/local/share/GeoIP/GeoLite2-City.mmdb', + 'GEOLITE2_ASN': '/usr/local/share/GeoIP/GeoLite2-ASN.mmdb', + 'GEOIP2_ISP': '/usr/local/share/GeoIP/GeoIP2-ISP.mmdb' }, }; diff --git a/backend/src/index.ts b/backend/src/index.ts index d1e3cee8d..2bcb98de1 100644 --- a/backend/src/index.ts +++ b/backend/src/index.ts @@ -1,4 +1,4 @@ -import express from "express"; +import express from 'express'; import { Application, Request, Response, NextFunction } from 'express'; import * as http from 'http'; import * as WebSocket from 'ws'; @@ -34,7 +34,7 @@ import miningRoutes from './api/mining/mining-routes'; import bisqRoutes from './api/bisq/bisq.routes'; import liquidRoutes from './api/liquid/liquid.routes'; import bitcoinRoutes from './api/bitcoin/bitcoin.routes'; -import fundingTxFetcher from "./tasks/lightning/sync-tasks/funding-tx-fetcher"; +import fundingTxFetcher from './tasks/lightning/sync-tasks/funding-tx-fetcher'; class Server { private wss: WebSocket.Server | undefined; @@ -74,7 +74,7 @@ class Server { } } - async startServer(worker = false) { + async startServer(worker = false): Promise { logger.notice(`Starting Mempool Server${worker ? ' (worker)' : ''}... (${backendInfo.getShortCommitHash()})`); this.app @@ -92,7 +92,9 @@ class Server { this.setUpWebsocketHandling(); await syncAssets.syncAssets$(); - diskCache.loadMempoolCache(); + if (config.MEMPOOL.ENABLED) { + diskCache.loadMempoolCache(); + } if (config.DATABASE.ENABLED) { await DB.checkDbConnection(); @@ -127,7 +129,10 @@ class Server { fiatConversion.startService(); this.setUpHttpApiRoutes(); - this.runMainUpdateLoop(); + + if (config.MEMPOOL.ENABLED) { + this.runMainUpdateLoop(); + } if (config.BISQ.ENABLED) { bisq.startBisqService(); @@ -149,7 +154,7 @@ class Server { }); } - async runMainUpdateLoop() { + async runMainUpdateLoop(): Promise { try { try { await memPool.$updateMemPoolInfo(); @@ -183,7 +188,7 @@ class Server { } } - async $runLightningBackend() { + async $runLightningBackend(): Promise { try { await fundingTxFetcher.$init(); await networkSyncService.$startService(); @@ -195,7 +200,7 @@ class Server { }; } - setUpWebsocketHandling() { + setUpWebsocketHandling(): void { if (this.wss) { websocketHandler.setWebsocketServer(this.wss); } @@ -209,19 +214,21 @@ class Server { }); } websocketHandler.setupConnectionHandling(); - statistics.setNewStatisticsEntryCallback(websocketHandler.handleNewStatistic.bind(websocketHandler)); - blocks.setNewBlockCallback(websocketHandler.handleNewBlock.bind(websocketHandler)); - memPool.setMempoolChangedCallback(websocketHandler.handleMempoolChange.bind(websocketHandler)); + if (config.MEMPOOL.ENABLED) { + statistics.setNewStatisticsEntryCallback(websocketHandler.handleNewStatistic.bind(websocketHandler)); + blocks.setNewBlockCallback(websocketHandler.handleNewBlock.bind(websocketHandler)); + memPool.setMempoolChangedCallback(websocketHandler.handleMempoolChange.bind(websocketHandler)); + } fiatConversion.setProgressChangedCallback(websocketHandler.handleNewConversionRates.bind(websocketHandler)); loadingIndicators.setProgressChangedCallback(websocketHandler.handleLoadingChanged.bind(websocketHandler)); } - - setUpHttpApiRoutes() { + + setUpHttpApiRoutes(): void { bitcoinRoutes.initRoutes(this.app); - if (config.STATISTICS.ENABLED && config.DATABASE.ENABLED) { + if (config.STATISTICS.ENABLED && config.DATABASE.ENABLED && config.MEMPOOL.ENABLED) { statisticsRoutes.initRoutes(this.app); } - if (Common.indexingEnabled()) { + if (Common.indexingEnabled() && config.MEMPOOL.ENABLED) { miningRoutes.initRoutes(this.app); } if (config.BISQ.ENABLED) { @@ -238,4 +245,4 @@ class Server { } } -const server = new Server(); +((): Server => new Server())(); From 0e0ac363cf7641c844566b7887a44c3942e488d4 Mon Sep 17 00:00:00 2001 From: softsimon Date: Tue, 23 Aug 2022 21:15:26 +0400 Subject: [PATCH 2/5] Updating unit test --- backend/src/__fixtures__/mempool-config.template.json | 1 + backend/src/__tests__/config.test.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/backend/src/__fixtures__/mempool-config.template.json b/backend/src/__fixtures__/mempool-config.template.json index a42426249..ca0ec1c2a 100644 --- a/backend/src/__fixtures__/mempool-config.template.json +++ b/backend/src/__fixtures__/mempool-config.template.json @@ -1,5 +1,6 @@ { "MEMPOOL": { + "ENABLED": true, "NETWORK": "__MEMPOOL_NETWORK__", "BACKEND": "__MEMPOOL_BACKEND__", "BLOCKS_SUMMARIES_INDEXING": true, diff --git a/backend/src/__tests__/config.test.ts b/backend/src/__tests__/config.test.ts index 7314fde6f..650beaac1 100644 --- a/backend/src/__tests__/config.test.ts +++ b/backend/src/__tests__/config.test.ts @@ -13,6 +13,7 @@ describe('Mempool Backend Config', () => { const config = jest.requireActual('../config').default; expect(config.MEMPOOL).toStrictEqual({ + ENABLED: true, NETWORK: 'mainnet', BACKEND: 'none', BLOCKS_SUMMARIES_INDEXING: false, From 601a5597846a63e0896de3006ffb98b8f8caadda Mon Sep 17 00:00:00 2001 From: softsimon Date: Sun, 28 Aug 2022 15:47:56 +0200 Subject: [PATCH 3/5] Adding MEMPOOL.ENABLED config to Docker --- backend/src/__fixtures__/mempool-config.template.json | 1 + docker/backend/mempool-config.json | 1 + docker/backend/start.sh | 2 ++ 3 files changed, 4 insertions(+) diff --git a/backend/src/__fixtures__/mempool-config.template.json b/backend/src/__fixtures__/mempool-config.template.json index ca0ec1c2a..e6c5428e5 100644 --- a/backend/src/__fixtures__/mempool-config.template.json +++ b/backend/src/__fixtures__/mempool-config.template.json @@ -3,6 +3,7 @@ "ENABLED": true, "NETWORK": "__MEMPOOL_NETWORK__", "BACKEND": "__MEMPOOL_BACKEND__", + "ENABLED": true, "BLOCKS_SUMMARIES_INDEXING": true, "HTTP_PORT": 1, "SPAWN_CLUSTER_PROCS": 2, diff --git a/docker/backend/mempool-config.json b/docker/backend/mempool-config.json index 930430127..378bba8db 100644 --- a/docker/backend/mempool-config.json +++ b/docker/backend/mempool-config.json @@ -2,6 +2,7 @@ "MEMPOOL": { "NETWORK": "__MEMPOOL_NETWORK__", "BACKEND": "__MEMPOOL_BACKEND__", + "ENABLED": __MEMPOOL_ENABLED__, "HTTP_PORT": __MEMPOOL_HTTP_PORT__, "SPAWN_CLUSTER_PROCS": __MEMPOOL_SPAWN_CLUSTER_PROCS__, "API_URL_PREFIX": "__MEMPOOL_API_URL_PREFIX__", diff --git a/docker/backend/start.sh b/docker/backend/start.sh index 4933dc2ee..c8e2a1502 100755 --- a/docker/backend/start.sh +++ b/docker/backend/start.sh @@ -3,6 +3,7 @@ # MEMPOOL __MEMPOOL_NETWORK__=${MEMPOOL_NETWORK:=mainnet} __MEMPOOL_BACKEND__=${MEMPOOL_BACKEND:=electrum} +__MEMPOOL_ENABLED__=${MEMPOOL_ENABLED:=true} __MEMPOOL_HTTP_PORT__=${BACKEND_HTTP_PORT:=8999} __MEMPOOL_SPAWN_CLUSTER_PROCS__=${MEMPOOL_SPAWN_CLUSTER_PROCS:=0} __MEMPOOL_API_URL_PREFIX__=${MEMPOOL_API_URL_PREFIX:=/api/v1/} @@ -111,6 +112,7 @@ mkdir -p "${__MEMPOOL_CACHE_DIR__}" sed -i "s/__MEMPOOL_NETWORK__/${__MEMPOOL_NETWORK__}/g" mempool-config.json sed -i "s/__MEMPOOL_BACKEND__/${__MEMPOOL_BACKEND__}/g" mempool-config.json +sed -i "s/__MEMPOOL_ENABLED__/${__MEMPOOL_ENABLED__}/g" mempool-config.json sed -i "s/__MEMPOOL_HTTP_PORT__/${__MEMPOOL_HTTP_PORT__}/g" mempool-config.json sed -i "s/__MEMPOOL_SPAWN_CLUSTER_PROCS__/${__MEMPOOL_SPAWN_CLUSTER_PROCS__}/g" mempool-config.json sed -i "s!__MEMPOOL_API_URL_PREFIX__!${__MEMPOOL_API_URL_PREFIX__}!g" mempool-config.json From 9e0a91efd2f3dd11d188aa987a37544d015f6c35 Mon Sep 17 00:00:00 2001 From: softsimon Date: Tue, 30 Aug 2022 11:12:49 +0200 Subject: [PATCH 4/5] Updating Docker README --- docker/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docker/README.md b/docker/README.md index 92cc1df6d..4061f420c 100644 --- a/docker/README.md +++ b/docker/README.md @@ -89,6 +89,7 @@ Below we list all settings from `mempool-config.json` and the corresponding over "MEMPOOL": { "NETWORK": "mainnet", "BACKEND": "electrum", + "ENABLED": true, "HTTP_PORT": 8999, "SPAWN_CLUSTER_PROCS": 0, "API_URL_PREFIX": "/api/v1/", From 67cbbda04b596190c0f12b7efc6ac8a48ff25cb4 Mon Sep 17 00:00:00 2001 From: softsimon Date: Mon, 21 Nov 2022 17:26:56 +0900 Subject: [PATCH 5/5] Set mempool enabled to false in production. --- production/mempool-config.mainnet-lightning.json | 1 + production/mempool-config.signet-lightning.json | 1 + production/mempool-config.testnet-lightning.json | 1 + 3 files changed, 3 insertions(+) diff --git a/production/mempool-config.mainnet-lightning.json b/production/mempool-config.mainnet-lightning.json index 99ce8d518..785a55ae6 100644 --- a/production/mempool-config.mainnet-lightning.json +++ b/production/mempool-config.mainnet-lightning.json @@ -1,5 +1,6 @@ { "MEMPOOL": { + "ENABLED": false, "NETWORK": "mainnet", "BACKEND": "esplora", "HTTP_PORT": 8993, diff --git a/production/mempool-config.signet-lightning.json b/production/mempool-config.signet-lightning.json index 08250ffbd..5e3daa625 100644 --- a/production/mempool-config.signet-lightning.json +++ b/production/mempool-config.signet-lightning.json @@ -1,5 +1,6 @@ { "MEMPOOL": { + "ENABLED": false, "NETWORK": "signet", "BACKEND": "esplora", "HTTP_PORT": 8991, diff --git a/production/mempool-config.testnet-lightning.json b/production/mempool-config.testnet-lightning.json index c2a42e4bc..e6f954385 100644 --- a/production/mempool-config.testnet-lightning.json +++ b/production/mempool-config.testnet-lightning.json @@ -1,5 +1,6 @@ { "MEMPOOL": { + "ENABLED": false, "NETWORK": "testnet", "BACKEND": "esplora", "HTTP_PORT": 8992,