Added a reorg to block.

This commit is contained in:
Chris Kleeschulte 2017-11-09 21:53:37 -05:00
parent 262cf8b850
commit 18a52c214d
No known key found for this signature in database
GPG Key ID: 33195D27EF6BDB7F

View File

@ -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;