From d6f594b95af5e3210f4075306458937c8161b11a Mon Sep 17 00:00:00 2001 From: nymkappa Date: Tue, 14 Jun 2022 10:58:17 +0200 Subject: [PATCH] Don't run the indexer unless Bitcoin Core is fully synced --- backend/src/api/blocks.ts | 6 +----- backend/src/indexer.ts | 7 +++++++ 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/backend/src/api/blocks.ts b/backend/src/api/blocks.ts index b1a2da18f..07ef9a669 100644 --- a/backend/src/api/blocks.ts +++ b/backend/src/api/blocks.ts @@ -300,12 +300,8 @@ class Blocks { * [INDEXING] Index all blocks metadata for the mining dashboard */ public async $generateBlockDatabase(): Promise { - const blockchainInfo = await bitcoinClient.getBlockchainInfo(); - if (blockchainInfo.blocks !== blockchainInfo.headers) { // Wait for node to sync - return false; - } - try { + const blockchainInfo = await bitcoinClient.getBlockchainInfo(); let currentBlockHeight = blockchainInfo.blocks; let indexingBlockAmount = Math.min(config.MEMPOOL.INDEXING_BLOCKS_AMOUNT, blockchainInfo.blocks); diff --git a/backend/src/indexer.ts b/backend/src/indexer.ts index 96cca9f7f..6ebba5bc4 100644 --- a/backend/src/indexer.ts +++ b/backend/src/indexer.ts @@ -4,6 +4,7 @@ import mempool from './api/mempool'; import mining from './api/mining'; import logger from './logger'; import HashratesRepository from './repositories/HashratesRepository'; +import bitcoinClient from './api/bitcoin/bitcoin-client'; class Indexer { runIndexer = true; @@ -25,6 +26,12 @@ class Indexer { return; } + // Do not attempt to index anything unless Bitcoin Core is fully synced + const blockchainInfo = await bitcoinClient.getBlockchainInfo(); + if (blockchainInfo.blocks !== blockchainInfo.headers) { + return; + } + this.runIndexer = false; this.indexerRunning = true;