Use core to fetch block because esplora/electrs still return integer difficulty
This commit is contained in:
		
							parent
							
								
									0b77000aab
								
							
						
					
					
						commit
						7ea2d3b808
					
				| @ -6,7 +6,7 @@ import websocketHandler from '../websocket-handler'; | ||||
| import mempool from '../mempool'; | ||||
| import feeApi from '../fee-api'; | ||||
| import mempoolBlocks from '../mempool-blocks'; | ||||
| import bitcoinApi from './bitcoin-api-factory'; | ||||
| import bitcoinApi, { bitcoinCoreApi } from './bitcoin-api-factory'; | ||||
| import { Common } from '../common'; | ||||
| import backendInfo from '../backend-info'; | ||||
| import transactionUtils from '../transaction-utils'; | ||||
| @ -469,7 +469,7 @@ class BitcoinRoutes { | ||||
|           returnBlocks.push(localBlock); | ||||
|           nextHash = localBlock.previousblockhash; | ||||
|         } else { | ||||
|           const block = await bitcoinApi.$getBlock(nextHash); | ||||
|           const block = await bitcoinCoreApi.$getBlock(nextHash); | ||||
|           returnBlocks.push(block); | ||||
|           nextHash = block.previousblockhash; | ||||
|         } | ||||
|  | ||||
| @ -1,5 +1,5 @@ | ||||
| import config from '../config'; | ||||
| import bitcoinApi from './bitcoin/bitcoin-api-factory'; | ||||
| import bitcoinApi, { bitcoinCoreApi } from './bitcoin/bitcoin-api-factory'; | ||||
| import logger from '../logger'; | ||||
| import memPool from './mempool'; | ||||
| import { BlockExtended, BlockExtension, BlockSummary, PoolTag, TransactionExtended, TransactionStripped, TransactionMinerInfo } from '../mempool.interfaces'; | ||||
| @ -484,7 +484,7 @@ class Blocks { | ||||
|             loadingIndicators.setProgress('block-indexing', progress, false); | ||||
|           } | ||||
|           const blockHash = await bitcoinApi.$getBlockHash(blockHeight); | ||||
|           const block: IEsploraApi.Block = await bitcoinApi.$getBlock(blockHash); | ||||
|           const block: IEsploraApi.Block = await bitcoinCoreApi.$getBlock(blockHash); | ||||
|           const transactions = await this.$getTransactionsExtended(blockHash, block.height, true, true); | ||||
|           const blockExtended = await this.$getBlockExtended(block, transactions); | ||||
| 
 | ||||
| @ -532,13 +532,13 @@ class Blocks { | ||||
|       if (blockchainInfo.blocks === blockchainInfo.headers) { | ||||
|         const heightDiff = blockHeightTip % 2016; | ||||
|         const blockHash = await bitcoinApi.$getBlockHash(blockHeightTip - heightDiff); | ||||
|         const block: IEsploraApi.Block = await bitcoinApi.$getBlock(blockHash); | ||||
|         const block: IEsploraApi.Block = await bitcoinCoreApi.$getBlock(blockHash); | ||||
|         this.lastDifficultyAdjustmentTime = block.timestamp; | ||||
|         this.currentDifficulty = block.difficulty; | ||||
| 
 | ||||
|         if (blockHeightTip >= 2016) { | ||||
|           const previousPeriodBlockHash = await bitcoinApi.$getBlockHash(blockHeightTip - heightDiff - 2016); | ||||
|           const previousPeriodBlock: IEsploraApi.Block = await bitcoinApi.$getBlock(previousPeriodBlockHash); | ||||
|           const previousPeriodBlock: IEsploraApi.Block = await bitcoinCoreApi.$getBlock(previousPeriodBlockHash); | ||||
|           this.previousDifficultyRetarget = (block.difficulty - previousPeriodBlock.difficulty) / previousPeriodBlock.difficulty * 100; | ||||
|           logger.debug(`Initial difficulty adjustment data set.`); | ||||
|         } | ||||
| @ -662,7 +662,7 @@ class Blocks { | ||||
|     } | ||||
| 
 | ||||
|     const blockHash = await bitcoinApi.$getBlockHash(height); | ||||
|     const block: IEsploraApi.Block = await bitcoinApi.$getBlock(blockHash); | ||||
|     const block: IEsploraApi.Block = await bitcoinCoreApi.$getBlock(blockHash); | ||||
|     const transactions = await this.$getTransactionsExtended(blockHash, block.height, true); | ||||
|     const blockExtended = await this.$getBlockExtended(block, transactions); | ||||
| 
 | ||||
| @ -685,11 +685,11 @@ class Blocks { | ||||
| 
 | ||||
|     // Not Bitcoin network, return the block as it from the bitcoin backend
 | ||||
|     if (['mainnet', 'testnet', 'signet'].includes(config.MEMPOOL.NETWORK) === false) { | ||||
|       return await bitcoinApi.$getBlock(hash); | ||||
|       return await bitcoinCoreApi.$getBlock(hash); | ||||
|     } | ||||
| 
 | ||||
|     // Bitcoin network, add our custom data on top
 | ||||
|     const block: IEsploraApi.Block = await bitcoinApi.$getBlock(hash); | ||||
|     const block: IEsploraApi.Block = await bitcoinCoreApi.$getBlock(hash); | ||||
|     return await this.$indexBlock(block.height); | ||||
|   } | ||||
| 
 | ||||
|  | ||||
| @ -1023,6 +1023,7 @@ class DatabaseMigration { | ||||
| 
 | ||||
|     await this.$executeQuery(`TRUNCATE blocks`); | ||||
|     await this.$executeQuery(`TRUNCATE hashrates`); | ||||
|     await this.$executeQuery(`TRUNCATE difficulty_adjustments`); | ||||
|     await this.$executeQuery('DELETE FROM `pools`'); | ||||
|     await this.$executeQuery('ALTER TABLE pools AUTO_INCREMENT = 1'); | ||||
|     await this.$executeQuery(`UPDATE state SET string = NULL WHERE name = 'pools_json_sha'`); | ||||
|  | ||||
| @ -11,7 +11,7 @@ import DifficultyAdjustmentsRepository from '../../repositories/DifficultyAdjust | ||||
| import config from '../../config'; | ||||
| import BlocksAuditsRepository from '../../repositories/BlocksAuditsRepository'; | ||||
| import PricesRepository from '../../repositories/PricesRepository'; | ||||
| import bitcoinApiFactory from '../bitcoin/bitcoin-api-factory'; | ||||
| import { bitcoinCoreApi } from '../bitcoin/bitcoin-api-factory'; | ||||
| import { IEsploraApi } from '../bitcoin/esplora-api.interface'; | ||||
| 
 | ||||
| class Mining { | ||||
| @ -191,7 +191,7 @@ class Mining { | ||||
|     try { | ||||
|       const oldestConsecutiveBlockTimestamp = 1000 * (await BlocksRepository.$getOldestConsecutiveBlock()).timestamp; | ||||
| 
 | ||||
|       const genesisBlock: IEsploraApi.Block = await bitcoinApiFactory.$getBlock(await bitcoinClient.getBlockHash(0)); | ||||
|       const genesisBlock: IEsploraApi.Block = await bitcoinCoreApi.$getBlock(await bitcoinClient.getBlockHash(0)); | ||||
|       const genesisTimestamp = genesisBlock.timestamp * 1000; | ||||
| 
 | ||||
|       const indexedTimestamp = await HashratesRepository.$getWeeklyHashrateTimestamps(); | ||||
| @ -294,7 +294,7 @@ class Mining { | ||||
|     const oldestConsecutiveBlockTimestamp = 1000 * (await BlocksRepository.$getOldestConsecutiveBlock()).timestamp; | ||||
| 
 | ||||
|     try { | ||||
|       const genesisBlock: IEsploraApi.Block = await bitcoinApiFactory.$getBlock(await bitcoinClient.getBlockHash(0)); | ||||
|       const genesisBlock: IEsploraApi.Block = await bitcoinCoreApi.$getBlock(await bitcoinClient.getBlockHash(0)); | ||||
|       const genesisTimestamp = genesisBlock.timestamp * 1000; | ||||
|       const indexedTimestamp = (await HashratesRepository.$getRawNetworkDailyHashrate(null)).map(hashrate => hashrate.timestamp); | ||||
|       const lastMidnight = this.getDateMidnight(new Date()); | ||||
| @ -396,7 +396,7 @@ class Mining { | ||||
|     } | ||||
| 
 | ||||
|     const blocks: any = await BlocksRepository.$getBlocksDifficulty(); | ||||
|     const genesisBlock: IEsploraApi.Block = await bitcoinApiFactory.$getBlock(await bitcoinClient.getBlockHash(0)); | ||||
|     const genesisBlock: IEsploraApi.Block = await bitcoinCoreApi.$getBlock(await bitcoinClient.getBlockHash(0)); | ||||
|     let currentDifficulty = genesisBlock.difficulty; | ||||
|     let totalIndexed = 0; | ||||
| 
 | ||||
|  | ||||
| @ -1,5 +1,4 @@ | ||||
| import { Common } from '../api/common'; | ||||
| import config from '../config'; | ||||
| import DB from '../database'; | ||||
| import logger from '../logger'; | ||||
| import { IndexedDifficultyAdjustment } from '../mempool.interfaces'; | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user