diff --git a/backend/mempool-config.sample.json b/backend/mempool-config.sample.json index 781f90698..0f265047f 100644 --- a/backend/mempool-config.sample.json +++ b/backend/mempool-config.sample.json @@ -9,7 +9,9 @@ "CACHE_DIR": "./cache", "CLEAR_PROTECTION_MINUTES": 20, "RECOMMENDED_FEE_PERCENTILE": 50, - "BLOCK_WEIGHT_UNITS": 4000000 + "BLOCK_WEIGHT_UNITS": 4000000, + "INITIAL_BLOCKS_AMOUNT": 8, + "MEMPOOL_BLOCKS_AMOUNT": 8 }, "CORE_RPC": { "HOST": "127.0.0.1", diff --git a/backend/src/api/blocks.ts b/backend/src/api/blocks.ts index fbfcc2828..32ad325ac 100644 --- a/backend/src/api/blocks.ts +++ b/backend/src/api/blocks.ts @@ -8,7 +8,6 @@ import diskCache from './disk-cache'; import transactionUtils from './transaction-utils'; class Blocks { - private static INITIAL_BLOCK_AMOUNT = 8; private blocks: BlockExtended[] = []; private currentBlockHeight = 0; private currentDifficulty = 0; @@ -34,14 +33,14 @@ class Blocks { const blockHeightTip = await bitcoinApi.$getBlockHeightTip(); if (this.blocks.length === 0) { - this.currentBlockHeight = blockHeightTip - Blocks.INITIAL_BLOCK_AMOUNT; + this.currentBlockHeight = blockHeightTip - config.MEMPOOL.INITIAL_BLOCKS_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 > config.MEMPOOL.INITIAL_BLOCKS_AMOUNT * 2) { + logger.info(`${blockHeightTip - this.currentBlockHeight} blocks since tip. Fast forwarding to the ${config.MEMPOOL.INITIAL_BLOCKS_AMOUNT} recent blocks`); + this.currentBlockHeight = blockHeightTip - config.MEMPOOL.INITIAL_BLOCKS_AMOUNT; } if (!this.lastDifficultyAdjustmentTime) { @@ -114,8 +113,8 @@ class Blocks { } this.blocks.push(blockExtended); - if (this.blocks.length > Blocks.INITIAL_BLOCK_AMOUNT * 4) { - this.blocks = this.blocks.slice(-Blocks.INITIAL_BLOCK_AMOUNT * 4); + if (this.blocks.length > config.MEMPOOL.INITIAL_BLOCKS_AMOUNT * 4) { + this.blocks = this.blocks.slice(-config.MEMPOOL.INITIAL_BLOCKS_AMOUNT * 4); } if (this.newBlockCallbacks.length) { diff --git a/backend/src/api/mempool-blocks.ts b/backend/src/api/mempool-blocks.ts index 592da2877..1550298a7 100644 --- a/backend/src/api/mempool-blocks.ts +++ b/backend/src/api/mempool-blocks.ts @@ -4,7 +4,6 @@ import { Common } from './common'; import config from '../config'; class MempoolBlocks { - private static DEFAULT_PROJECTED_BLOCKS_AMOUNT = 8; private mempoolBlocks: MempoolBlockWithTransactions[] = []; constructor() {} @@ -76,7 +75,7 @@ class MempoolBlocks { let blockSize = 0; let transactions: TransactionExtended[] = []; transactionsSorted.forEach((tx) => { - if (blockVSize + tx.weight <= config.MEMPOOL.BLOCK_WEIGHT_UNITS || mempoolBlocks.length === MempoolBlocks.DEFAULT_PROJECTED_BLOCKS_AMOUNT - 1) { + if (blockVSize + tx.weight <= config.MEMPOOL.BLOCK_WEIGHT_UNITS || mempoolBlocks.length === config.MEMPOOL.MEMPOOL_BLOCKS_AMOUNT - 1) { blockVSize += tx.vsize; blockSize += tx.size; transactions.push(tx); diff --git a/backend/src/api/websocket-handler.ts b/backend/src/api/websocket-handler.ts index eb2b90ccc..9a758f731 100644 --- a/backend/src/api/websocket-handler.ts +++ b/backend/src/api/websocket-handler.ts @@ -90,7 +90,7 @@ class WebsocketHandler { } if (parsedMessage.action === 'init') { - const _blocks = blocks.getBlocks().slice(-8); + const _blocks = blocks.getBlocks().slice(-config.MEMPOOL.INITIAL_BLOCKS_AMOUNT); if (!_blocks) { return; } @@ -166,7 +166,7 @@ class WebsocketHandler { getInitData(_blocks?: BlockExtended[]) { if (!_blocks) { - _blocks = blocks.getBlocks().slice(-8); + _blocks = blocks.getBlocks().slice(-config.MEMPOOL.INITIAL_BLOCKS_AMOUNT); } return { 'mempoolInfo': memPool.getMempoolInfo(), diff --git a/backend/src/config.ts b/backend/src/config.ts index ee811979c..399beff60 100644 --- a/backend/src/config.ts +++ b/backend/src/config.ts @@ -12,6 +12,8 @@ interface IConfig { CLEAR_PROTECTION_MINUTES: number; RECOMMENDED_FEE_PERCENTILE: number; BLOCK_WEIGHT_UNITS: number; + INITIAL_BLOCKS_AMOUNT: number; + MEMPOOL_BLOCKS_AMOUNT: number; }; ESPLORA: { REST_API_URL: string; @@ -71,6 +73,8 @@ const defaults: IConfig = { 'CLEAR_PROTECTION_MINUTES': 20, 'RECOMMENDED_FEE_PERCENTILE': 50, 'BLOCK_WEIGHT_UNITS': 4000000, + 'INITIAL_BLOCKS_AMOUNT': 8, + 'MEMPOOL_BLOCKS_AMOUNT': 8, }, 'ESPLORA': { 'REST_API_URL': 'http://127.0.0.1:3000', diff --git a/frontend/mempool-frontend-config.sample.json b/frontend/mempool-frontend-config.sample.json index a5c9d1c07..80e8ae4cb 100644 --- a/frontend/mempool-frontend-config.sample.json +++ b/frontend/mempool-frontend-config.sample.json @@ -9,6 +9,7 @@ "NGINX_PROTOCOL": "http", "NGINX_HOSTNAME": "127.0.0.1", "NGINX_PORT": "80", + "MEMPOOL_BLOCKS_AMOUNT": 8, "BLOCK_WEIGHT_UNITS": 4000000, "BASE_MODULE": "mempool" } diff --git a/frontend/src/app/components/blockchain-blocks/blockchain-blocks.component.ts b/frontend/src/app/components/blockchain-blocks/blockchain-blocks.component.ts index 9af5d9e4c..e227cb8cd 100644 --- a/frontend/src/app/components/blockchain-blocks/blockchain-blocks.component.ts +++ b/frontend/src/app/components/blockchain-blocks/blockchain-blocks.component.ts @@ -183,7 +183,7 @@ export class BlockchainBlocksComponent implements OnInit, OnDestroy { } mountEmptyBlocks() { const emptyBlocks = []; - for (let i = 0; i < 9; i++) { + for (let i = 0; i < this.stateService.env.KEEP_BLOCKS_AMOUNT; i++) { emptyBlocks.push({ id: '', height: 0, diff --git a/frontend/src/app/components/mempool-blocks/mempool-blocks.component.ts b/frontend/src/app/components/mempool-blocks/mempool-blocks.component.ts index 607bcce61..da94d59a6 100644 --- a/frontend/src/app/components/mempool-blocks/mempool-blocks.component.ts +++ b/frontend/src/app/components/mempool-blocks/mempool-blocks.component.ts @@ -144,7 +144,7 @@ export class MempoolBlocksComponent implements OnInit, OnDestroy { this.router.navigate([(this.network ? '/' + this.network : '') + '/mempool-block/', this.markIndex - 1]); } else { this.stateService.blocks$ - .pipe(take(8)) + .pipe(take(this.stateService.env.MEMPOOL_BLOCKS_AMOUNT)) .subscribe(([block]) => { if (this.stateService.latestBlockHeight === block.height) { this.router.navigate([(this.network ? '/' + this.network : '') + '/block/', block.id], { state: { data: { block } }}); @@ -275,8 +275,8 @@ export class MempoolBlocksComponent implements OnInit, OnDestroy { mountEmptyBlocks() { const emptyBlocks = []; - const numberOfBlocks = 8; - for (let i = 0; i <= numberOfBlocks; i++) { + const numberOfBlocks = this.stateService.env.MEMPOOL_BLOCKS_AMOUNT; + for (let i = 0; i < numberOfBlocks; i++) { emptyBlocks.push({ blockSize: 0, blockVSize: 0, diff --git a/frontend/src/app/services/state.service.ts b/frontend/src/app/services/state.service.ts index 00934ba5f..20b28f2e5 100644 --- a/frontend/src/app/services/state.service.ts +++ b/frontend/src/app/services/state.service.ts @@ -29,6 +29,7 @@ export interface Env { NGINX_HOSTNAME?: string; NGINX_PORT?: string; BLOCK_WEIGHT_UNITS: number; + MEMPOOL_BLOCKS_AMOUNT: number; GIT_COMMIT_HASH: string; PACKAGE_JSON_VERSION: string; } @@ -47,6 +48,7 @@ const defaultEnv: Env = { 'NGINX_HOSTNAME': '127.0.0.1', 'NGINX_PORT': '80', 'BLOCK_WEIGHT_UNITS': 4000000, + 'MEMPOOL_BLOCKS_AMOUNT': 8, 'GIT_COMMIT_HASH': '', 'PACKAGE_JSON_VERSION': '', };