Compare commits
11 Commits
8c7f73b099
...
19657aa66a
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
19657aa66a | ||
|
|
816e377586 | ||
|
|
4335d6f8ce | ||
|
|
9f72d3dd79 | ||
|
|
269f3f1bd8 | ||
|
|
1fa3d45445 | ||
|
|
ba08acb6ae | ||
|
|
ca54b05618 | ||
|
|
700abe0500 | ||
|
|
0572ee6b35 | ||
|
|
e6826c7dfc |
@ -13,6 +13,9 @@ 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);
|
||||
@ -637,6 +640,7 @@ 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));
|
||||
@ -933,11 +937,30 @@ 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,
|
||||
@ -953,6 +976,7 @@ 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;
|
||||
|
||||
@ -1097,7 +1121,7 @@ BlockService.prototype._startSync = function() {
|
||||
this.on('next block', this._sync.bind(this));
|
||||
this.on('synced', this._onSynced.bind(this));
|
||||
clearInterval(this._reportInterval);
|
||||
this._reportingInterval = setInterval(this._logProgress.bind(this), 5000);
|
||||
this._reportInterval = setInterval(this._logProgress.bind(this), 5000);
|
||||
return this._sync();
|
||||
}
|
||||
|
||||
|
||||
@ -533,8 +533,10 @@ 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
|
||||
@ -721,7 +723,6 @@ 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
|
||||
|
||||
@ -97,7 +97,6 @@ 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));
|
||||
|
||||
};
|
||||
@ -234,7 +233,6 @@ 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;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user