From ca766bf40d53c0f839eb1cc8f41163db3ec7b7ff Mon Sep 17 00:00:00 2001 From: nymkappa Date: Tue, 15 Feb 2022 16:02:30 +0900 Subject: [PATCH] Provide a way to completely disable block indexing and mining menu --- backend/src/api/blocks.ts | 24 +++++-------------- backend/src/api/common.ts | 8 +++++++ frontend/mempool-frontend-config.sample.json | 3 ++- .../master-page/master-page.component.html | 5 +++- .../master-page/master-page.component.ts | 2 +- frontend/src/app/services/state.service.ts | 2 ++ 6 files changed, 23 insertions(+), 21 deletions(-) diff --git a/backend/src/api/blocks.ts b/backend/src/api/blocks.ts index affbf0049..7513f259e 100644 --- a/backend/src/api/blocks.ts +++ b/backend/src/api/blocks.ts @@ -116,10 +116,7 @@ class Blocks { blockExtended.extras.feeRange = transactionsTmp.length > 0 ? Common.getFeesInRange(transactionsTmp, 8) : [0, 0]; - const indexingAvailable = - ['mainnet', 'testnet', 'signet'].includes(config.MEMPOOL.NETWORK) && - config.DATABASE.ENABLED === true; - if (indexingAvailable) { + if (Common.indexingEnabled()) { let pool: PoolTag; if (blockExtended.extras?.coinbaseTx !== undefined) { pool = await this.$findBlockMiner(blockExtended.extras?.coinbaseTx); @@ -173,11 +170,9 @@ class Blocks { * Index all blocks metadata for the mining dashboard */ public async $generateBlockDatabase() { - if (['mainnet', 'testnet', 'signet'].includes(config.MEMPOOL.NETWORK) === false || // Bitcoin only - config.MEMPOOL.INDEXING_BLOCKS_AMOUNT === 0 || // Indexing of older blocks must be enabled - memPool.hasPriority() || // We sync the mempool first - this.blockIndexingStarted === true || // Indexing must not already be in progress - config.DATABASE.ENABLED === false + if (this.blockIndexingStarted === true || + !Common.indexingEnabled() || + memPool.hasPriority() ) { return; } @@ -293,10 +288,7 @@ class Blocks { const transactions = await this.$getTransactionsExtended(blockHash, block.height, false); const blockExtended: BlockExtended = await this.$getBlockExtended(block, transactions); - const indexingAvailable = - ['mainnet', 'testnet', 'signet'].includes(config.MEMPOOL.NETWORK) && - config.DATABASE.ENABLED === true; - if (indexingAvailable) { + if (Common.indexingEnabled()) { await blocksRepository.$saveBlockInDatabase(blockExtended); } @@ -340,10 +332,6 @@ class Blocks { } public async $getBlocksExtras(fromHeight: number): Promise { - const indexingAvailable = - ['mainnet', 'testnet', 'signet'].includes(config.MEMPOOL.NETWORK) && - config.DATABASE.ENABLED === true; - try { loadingIndicators.setProgress('blocks', 0); @@ -366,7 +354,7 @@ class Blocks { let nextHash = startFromHash; for (let i = 0; i < 10 && currentHeight >= 0; i++) { let block = this.getBlocks().find((b) => b.height === currentHeight); - if (!block && indexingAvailable) { + if (!block && Common.indexingEnabled()) { block = this.prepareBlock(await this.$indexBlock(currentHeight)); } else if (!block) { block = this.prepareBlock(await bitcoinApi.$getBlock(nextHash)); diff --git a/backend/src/api/common.ts b/backend/src/api/common.ts index 5e99e870c..3ab5c4b9f 100644 --- a/backend/src/api/common.ts +++ b/backend/src/api/common.ts @@ -154,4 +154,12 @@ export class Common { }); return parents; } + + static indexingEnabled(): boolean { + return ( + ['mainnet', 'testnet', 'signet'].includes(config.MEMPOOL.NETWORK) && + config.DATABASE.ENABLED === true && + config.MEMPOOL.INDEXING_BLOCKS_AMOUNT != 0 + ); + } } diff --git a/frontend/mempool-frontend-config.sample.json b/frontend/mempool-frontend-config.sample.json index 0715cb0bd..231f1c7c8 100644 --- a/frontend/mempool-frontend-config.sample.json +++ b/frontend/mempool-frontend-config.sample.json @@ -15,5 +15,6 @@ "BASE_MODULE": "mempool", "MEMPOOL_WEBSITE_URL": "https://mempool.space", "LIQUID_WEBSITE_URL": "https://liquid.network", - "BISQ_WEBSITE_URL": "https://bisq.markets" + "BISQ_WEBSITE_URL": "https://bisq.markets", + "MINING_DASHBOARD": true } diff --git a/frontend/src/app/components/master-page/master-page.component.html b/frontend/src/app/components/master-page/master-page.component.html index 4624340d3..af47b75c2 100644 --- a/frontend/src/app/components/master-page/master-page.component.html +++ b/frontend/src/app/components/master-page/master-page.component.html @@ -31,9 +31,12 @@ - + diff --git a/frontend/src/app/components/master-page/master-page.component.ts b/frontend/src/app/components/master-page/master-page.component.ts index fcff5629c..23a73178f 100644 --- a/frontend/src/app/components/master-page/master-page.component.ts +++ b/frontend/src/app/components/master-page/master-page.component.ts @@ -18,7 +18,7 @@ export class MasterPageComponent implements OnInit { urlLanguage: string; constructor( - private stateService: StateService, + public stateService: StateService, private languageService: LanguageService, ) { } diff --git a/frontend/src/app/services/state.service.ts b/frontend/src/app/services/state.service.ts index 230c9b150..14d67e765 100644 --- a/frontend/src/app/services/state.service.ts +++ b/frontend/src/app/services/state.service.ts @@ -36,6 +36,7 @@ export interface Env { MEMPOOL_WEBSITE_URL: string; LIQUID_WEBSITE_URL: string; BISQ_WEBSITE_URL: string; + MINING_DASHBOARD: boolean; } const defaultEnv: Env = { @@ -59,6 +60,7 @@ const defaultEnv: Env = { 'MEMPOOL_WEBSITE_URL': 'https://mempool.space', 'LIQUID_WEBSITE_URL': 'https://liquid.network', 'BISQ_WEBSITE_URL': 'https://bisq.markets', + 'MINING_DASHBOARD': true }; @Injectable({