Don't run the indexer unless Bitcoin Core is fully synced
This commit is contained in:
		
							parent
							
								
									24300eeac5
								
							
						
					
					
						commit
						d6f594b95a
					
				@ -300,12 +300,8 @@ class Blocks {
 | 
				
			|||||||
   * [INDEXING] Index all blocks metadata for the mining dashboard
 | 
					   * [INDEXING] Index all blocks metadata for the mining dashboard
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  public async $generateBlockDatabase(): Promise<boolean> {
 | 
					  public async $generateBlockDatabase(): Promise<boolean> {
 | 
				
			||||||
    const blockchainInfo = await bitcoinClient.getBlockchainInfo();
 | 
					 | 
				
			||||||
    if (blockchainInfo.blocks !== blockchainInfo.headers) { // Wait for node to sync
 | 
					 | 
				
			||||||
      return false;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    try {
 | 
					    try {
 | 
				
			||||||
 | 
					      const blockchainInfo = await bitcoinClient.getBlockchainInfo();
 | 
				
			||||||
      let currentBlockHeight = blockchainInfo.blocks;
 | 
					      let currentBlockHeight = blockchainInfo.blocks;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      let indexingBlockAmount = Math.min(config.MEMPOOL.INDEXING_BLOCKS_AMOUNT, blockchainInfo.blocks);
 | 
					      let indexingBlockAmount = Math.min(config.MEMPOOL.INDEXING_BLOCKS_AMOUNT, blockchainInfo.blocks);
 | 
				
			||||||
 | 
				
			|||||||
@ -4,6 +4,7 @@ import mempool from './api/mempool';
 | 
				
			|||||||
import mining from './api/mining';
 | 
					import mining from './api/mining';
 | 
				
			||||||
import logger from './logger';
 | 
					import logger from './logger';
 | 
				
			||||||
import HashratesRepository from './repositories/HashratesRepository';
 | 
					import HashratesRepository from './repositories/HashratesRepository';
 | 
				
			||||||
 | 
					import bitcoinClient from './api/bitcoin/bitcoin-client';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class Indexer {
 | 
					class Indexer {
 | 
				
			||||||
  runIndexer = true;
 | 
					  runIndexer = true;
 | 
				
			||||||
@ -25,6 +26,12 @@ class Indexer {
 | 
				
			|||||||
      return;
 | 
					      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.runIndexer = false;
 | 
				
			||||||
    this.indexerRunning = true;
 | 
					    this.indexerRunning = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user