Merge pull request #4068 from mempool/mononaut/electrs-blocks
Get blocks from electrs again
This commit is contained in:
		
						commit
						ed1a892b5b
					
				@ -423,6 +423,7 @@ class Mining {
 | 
			
		||||
    const blocks: any = await BlocksRepository.$getBlocksDifficulty();
 | 
			
		||||
    const genesisBlock: IEsploraApi.Block = await bitcoinApi.$getBlock(await bitcoinApi.$getBlockHash(0));
 | 
			
		||||
    let currentDifficulty = genesisBlock.difficulty;
 | 
			
		||||
    let currentBits = genesisBlock.bits;
 | 
			
		||||
    let totalIndexed = 0;
 | 
			
		||||
 | 
			
		||||
    if (config.MEMPOOL.INDEXING_BLOCKS_AMOUNT === -1 && indexedHeights[0] !== true) {
 | 
			
		||||
@ -436,17 +437,18 @@ class Mining {
 | 
			
		||||
 | 
			
		||||
    const oldestConsecutiveBlock = await BlocksRepository.$getOldestConsecutiveBlock();
 | 
			
		||||
    if (config.MEMPOOL.INDEXING_BLOCKS_AMOUNT !== -1) {
 | 
			
		||||
      currentDifficulty = oldestConsecutiveBlock.difficulty;
 | 
			
		||||
      currentBits = oldestConsecutiveBlock.bits;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    let totalBlockChecked = 0;
 | 
			
		||||
    let timer = new Date().getTime() / 1000;
 | 
			
		||||
 | 
			
		||||
    for (const block of blocks) {
 | 
			
		||||
      if (block.difficulty !== currentDifficulty) {
 | 
			
		||||
      if (block.bits !== currentBits) {
 | 
			
		||||
        if (indexedHeights[block.height] === true) { // Already indexed
 | 
			
		||||
          if (block.height >= oldestConsecutiveBlock.height) {
 | 
			
		||||
            currentDifficulty = block.difficulty;
 | 
			
		||||
            currentBits = block.bits;
 | 
			
		||||
          }
 | 
			
		||||
          continue;          
 | 
			
		||||
        }
 | 
			
		||||
@ -464,6 +466,7 @@ class Mining {
 | 
			
		||||
        totalIndexed++;
 | 
			
		||||
        if (block.height >= oldestConsecutiveBlock.height) {
 | 
			
		||||
          currentDifficulty = block.difficulty;
 | 
			
		||||
          currentBits = block.bits;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -541,7 +541,7 @@ class BlocksRepository {
 | 
			
		||||
   */
 | 
			
		||||
  public async $getBlocksDifficulty(): Promise<object[]> {
 | 
			
		||||
    try {
 | 
			
		||||
      const [rows]: any[] = await DB.query(`SELECT UNIX_TIMESTAMP(blockTimestamp) as time, height, difficulty FROM blocks`);
 | 
			
		||||
      const [rows]: any[] = await DB.query(`SELECT UNIX_TIMESTAMP(blockTimestamp) as time, height, difficulty, bits FROM blocks`);
 | 
			
		||||
      return rows;
 | 
			
		||||
    } catch (e) {
 | 
			
		||||
      logger.err('Cannot get blocks difficulty list from the db. Reason: ' + (e instanceof Error ? e.message : e));
 | 
			
		||||
@ -850,7 +850,7 @@ class BlocksRepository {
 | 
			
		||||
   */
 | 
			
		||||
  public async $getOldestConsecutiveBlock(): Promise<any> {
 | 
			
		||||
    try {
 | 
			
		||||
      const [rows]: any = await DB.query(`SELECT height, UNIX_TIMESTAMP(blockTimestamp) as timestamp, difficulty FROM blocks ORDER BY height DESC`);
 | 
			
		||||
      const [rows]: any = await DB.query(`SELECT height, UNIX_TIMESTAMP(blockTimestamp) as timestamp, difficulty, bits FROM blocks ORDER BY height DESC`);
 | 
			
		||||
      for (let i = 0; i < rows.length - 1; ++i) {
 | 
			
		||||
        if (rows[i].height - rows[i + 1].height > 1) {
 | 
			
		||||
          return rows[i];
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user