Browse Source

add new method BlockchainProcessor.rescanBlocks() allowing to rescan a range of blocks

umbrel
kenshin-samourai 5 years ago
parent
commit
8d65f91ccc
  1. 33
      tracker/blockchain-processor.js

33
tracker/blockchain-processor.js

@ -320,6 +320,39 @@ class BlockchainProcessor extends AbstractProcessor {
await db.deleteBlocksAfterHeight(height)
}
/**
* Rescan a range of blocks
* @param {integer} fromHeight - height of first block
* @param {integer} toHeight - height of last block
* @returns {Promise}
*/
async rescanBlocks(fromHeight, toHeight) {
// Get highest block processed by the tracker
const highest = await db.getHighestBlock()
const dbMaxHeight = highest.blockHeight
if (toHeight == null)
toHeight = fromHeight
toHeight = Math.min(toHeight, dbMaxHeight)
const blockRange = _.range(fromHeight, toHeight + 1)
Logger.info(`Blocks Rescan : starting a rescan for ${blockRange.length} blocks`)
// Process the blocks
return util.seriesCall(blockRange, async height => {
try {
Logger.info(`Rescanning block ${height}`)
const hash = await this.client.getblockhash(height)
const header = await this.client.getblockheader(hash)
return this.processBlock(header)
} catch(e) {
Logger.error(e, 'BlockchainProcessor.rescan()')
throw e
}
}, 'Tracker rescan', true)
}
/**
* Process a block
* @param {object} header - block header

Loading…
Cancel
Save