From b21016efef49568d1fb5c304eb5718715294c4fa Mon Sep 17 00:00:00 2001 From: softsimon Date: Sat, 31 Oct 2020 18:58:34 +0700 Subject: [PATCH] Removing unnused config MINED_BLOCKS_CACHE. --- backend/mempool-config.sample.json | 1 - backend/src/api/blocks.ts | 11 +++++------ backend/src/api/websocket-handler.ts | 3 +-- backend/src/config.ts | 2 -- 4 files changed, 6 insertions(+), 11 deletions(-) diff --git a/backend/mempool-config.sample.json b/backend/mempool-config.sample.json index e22afbe41..2e7e09316 100644 --- a/backend/mempool-config.sample.json +++ b/backend/mempool-config.sample.json @@ -2,7 +2,6 @@ "MEMPOOL": { "NETWORK": "mainnet", "HTTP_PORT": 8999, - "MINED_BLOCKS_CACHE": 144, "SPAWN_CLUSTER_PROCS": 0, "API_URL_PREFIX": "/api/v1/", "WEBSOCKET_REFRESH_RATE_MS": 2000 diff --git a/backend/src/api/blocks.ts b/backend/src/api/blocks.ts index c792d745c..0c6837cf5 100644 --- a/backend/src/api/blocks.ts +++ b/backend/src/api/blocks.ts @@ -6,8 +6,7 @@ import { Common } from './common'; import diskCache from './disk-cache'; class Blocks { - private static INITIAL_BLOCK_AMOUNT = 8; - private static KEEP_BLOCK_AMOUNT = 24; + private static KEEP_BLOCK_AMOUNT = 8; private blocks: Block[] = []; private currentBlockHeight = 0; private lastDifficultyAdjustmentTime = 0; @@ -31,14 +30,14 @@ class Blocks { const blockHeightTip = await bitcoinApi.getBlockHeightTip(); if (this.blocks.length === 0) { - this.currentBlockHeight = blockHeightTip - Blocks.INITIAL_BLOCK_AMOUNT; + this.currentBlockHeight = blockHeightTip - Blocks.KEEP_BLOCK_AMOUNT; } else { this.currentBlockHeight = this.blocks[this.blocks.length - 1].height; } - if (blockHeightTip - this.currentBlockHeight > Blocks.INITIAL_BLOCK_AMOUNT * 2) { - logger.info(`${blockHeightTip - this.currentBlockHeight} blocks since tip. Fast forwarding to the ${Blocks.INITIAL_BLOCK_AMOUNT} recent blocks`); - this.currentBlockHeight = blockHeightTip - Blocks.INITIAL_BLOCK_AMOUNT; + if (blockHeightTip - this.currentBlockHeight > Blocks.KEEP_BLOCK_AMOUNT * 2) { + logger.info(`${blockHeightTip - this.currentBlockHeight} blocks since tip. Fast forwarding to the ${Blocks.KEEP_BLOCK_AMOUNT} recent blocks`); + this.currentBlockHeight = blockHeightTip - Blocks.KEEP_BLOCK_AMOUNT; } if (!this.lastDifficultyAdjustmentTime) { diff --git a/backend/src/api/websocket-handler.ts b/backend/src/api/websocket-handler.ts index fdaaf0ee1..67de2bbbd 100644 --- a/backend/src/api/websocket-handler.ts +++ b/backend/src/api/websocket-handler.ts @@ -9,7 +9,6 @@ import fiatConversion from './fiat-conversion'; import { Common } from './common'; class WebsocketHandler { - private static INITIAL_BLOCK_AMOUNT = 8; private wss: WebSocket.Server | undefined; private nativeAssetId = '6f0279e9ed041c3d710a9f57d0c02928416460c4b722ae3457a11eec381c526d'; private extraInitProperties = {}; @@ -85,7 +84,7 @@ class WebsocketHandler { 'mempoolInfo': memPool.getMempoolInfo(), 'vBytesPerSecond': memPool.getVBytesPerSecond(), 'lastDifficultyAdjustment': blocks.getLastDifficultyAdjustmentTime(), - 'blocks': _blocks.slice(Math.max(_blocks.length - WebsocketHandler.INITIAL_BLOCK_AMOUNT, 0)), + 'blocks': _blocks, 'conversions': fiatConversion.getTickers()['BTCUSD'], 'mempool-blocks': mempoolBlocks.getMempoolBlocks(), 'transactions': memPool.getLatestTransactions(), diff --git a/backend/src/config.ts b/backend/src/config.ts index 2452e10f8..7aa1d2a84 100644 --- a/backend/src/config.ts +++ b/backend/src/config.ts @@ -4,7 +4,6 @@ interface IConfig { MEMPOOL: { NETWORK: 'mainnet' | 'testnet' | 'liquid'; HTTP_PORT: number; - MINED_BLOCKS_CACHE: number; SPAWN_CLUSTER_PROCS: number; API_URL_PREFIX: string; WEBSOCKET_REFRESH_RATE_MS: number; @@ -46,7 +45,6 @@ const defaults: IConfig = { 'MEMPOOL': { 'NETWORK': 'mainnet', 'HTTP_PORT': 8999, - 'MINED_BLOCKS_CACHE': 144, 'SPAWN_CLUSTER_PROCS': 0, 'API_URL_PREFIX': '/api/v1/', 'WEBSOCKET_REFRESH_RATE_MS': 2000