Compare commits

..

No commits in common. "19657aa66a84569421fd6774e1ad0ea7bc44adb1" and "8c7f73b099a9d342ec08945ff16fa14d53779686" have entirely different histories.

3 changed files with 5 additions and 28 deletions

View File

@ -13,9 +13,6 @@ var bcoin = require('fcoin');
var _ = require('lodash');
var LRU = require('lru-cache');
const MAX_IGNORED_BLOCK = 5; //Maximum ignored block allowed before trigging sync again
var __TestingCount = 2;
var BlockService = function(options) {
BaseService.call(this, options);
@ -640,7 +637,6 @@ BlockService.prototype._startBlockSubscription = function() {
}
this._subscribedBlock = true;
this._ignoredBlockCount = 0; //SZ: reset the ignored count to 0 when subscription starts
log.info('Block Service: starting p2p block subscription.');
this._bus.on('p2p/block', this._queueBlock.bind(this));
@ -937,30 +933,11 @@ BlockService.prototype._processBlock = function(block, callback) {
log.debug('Block Service: new block: ' + block.rhash());
//Manually ignore a block for testing
__TestingCount--;
console.debug("TESTING: __TestingCount=", __TestingCount);
if(__TestingCount === 0){
console.debug("TESTING: Ignored block");
return callback();
}
// common case
if (!self._detectReorg(block)) {
return self._saveBlock(block, callback);
}
console.debug("TESTING: _ignoredBlockCount=", self._ignoredBlockCount)
//SZ: count the ignored blocks. if many blocks ignored, trigger sync process
if(self._ignoredBlockCount < MAX_IGNORED_BLOCK)
self._ignoredBlockCount++;
else {
console.debug("TESTING: resync is stopped")
self._ignoredBlockCount = 0;
self._removeAllSubscriptions();
self._startSync();
}
// reorg -- in this case, we will not handle the reorg right away
// instead, we will skip the block and wait for the eventual call to
// "onHeaders" function. When the header service calls this function,
@ -976,7 +953,6 @@ BlockService.prototype._saveBlock = function(block, callback) {
var self = this;
block.__height = self._tip.height + 1;
self._ignoredBlockCount = 0; //SZ: a block is saved, reset the ignored count
var services = self.node.services;
@ -1121,7 +1097,7 @@ BlockService.prototype._startSync = function() {
this.on('next block', this._sync.bind(this));
this.on('synced', this._onSynced.bind(this));
clearInterval(this._reportInterval);
this._reportInterval = setInterval(this._logProgress.bind(this), 5000);
this._reportingInterval = setInterval(this._logProgress.bind(this), 5000);
return this._sync();
}

View File

@ -533,10 +533,8 @@ HeaderService.prototype._onHeadersSave = function(callback) {
}
//SZ: clear the interval check as sync is completed
if(self._syncCheckInterval){
if(self._syncCheckInterval)
clearInterval(self._syncCheckInterval);
self._syncCheckInterval = null;
}
self._endHeaderSubscription(); // we don't need headers any more
self._startBlockSubscription(); // we need new blocks coming tu us aynchronuously
@ -723,6 +721,7 @@ HeaderService.prototype._startSync = function() {
self._syncUnresponsive = true;
self._syncCheckInterval = setInterval(() => {
//check the best height
console.debug("bestHeight check", self._bestHeight, self._p2p._bcoin._bcoin.pool.chain.height)
if(self._bestHeight < self._p2p._bcoin._bcoin.pool.chain.height)
self._bestHeight = self._p2p._bcoin._bcoin.pool.chain.height;
//call sync again if unresponsive

View File

@ -97,6 +97,7 @@ P2P.prototype.getHeaders = function(filter) {
var peer = this._getPeer();
var headerFilter = this._setResourceFilter(filter, 'headers');
console.debug("p2p:getHeaders", peer.host, peer.port, peer.bestHeight, JSON.stringify(headerFilter));
peer.sendMessage(this.messages.GetHeaders(headerFilter));
};
@ -233,6 +234,7 @@ P2P.prototype._getBestHeight = function() {
if (this._peers[i].bestHeight > maxHeight) {
maxHeight = this._peers[i].bestHeight;
this._peer = this._peers[i];
console.debug("Swapping best peer", this._peer.host, this._peer.port, maxHeight);
}
}
return maxHeight;