diff --git a/lib/services/block/index.js b/lib/services/block/index.js index 1ffab141..58cbd832 100644 --- a/lib/services/block/index.js +++ b/lib/services/block/index.js @@ -36,6 +36,7 @@ var BlockService = function(options) { this._recentBlockHashes = new LRU(this._recentBlockHashesCount); this._readAheadBlockCount = options.readAheadBlockCount || 2; // this is the number of blocks to direct the p2p service to read aheead this._pauseSync = options.pause; + this._reorgToBlock = options.reorgToBlock; }; inherits(BlockService, BaseService); @@ -201,7 +202,7 @@ BlockService.prototype._checkTip = function(callback) { header = header || self._header.getLastHeader(); - if (header.hash === self._tip.hash) { + if (header.hash === self._tip.hash && !self._reorgToBlock) { log.info('Block Service: saved tip is good to go.'); return callback(); } @@ -652,6 +653,15 @@ BlockService.prototype._findLatestValidBlockHeader = function(callback) { var self = this; + if (self._reorgToBlock) { + return self._header.getBlockHeader(self._reorgToBlock, function(err, header) { + if (err || !header) { + return callback(err || new Error('Block Service: header not found to reorg to.')); + } + callback(null, header); + }); + } + var blockServiceHash = self._tip.hash; var blockServiceHeight = self._tip.height; var iterCount = 0;