Compare commits

...

11 Commits

Author SHA1 Message Date
sairajzero
19657aa66a configure testing parameters 2023-01-18 00:12:23 +05:30
sairajzero
816e377586 configure testing parameters 2023-01-17 23:08:45 +05:30
sairajzero
4335d6f8ce Test: adding __TestingCount log 2023-01-17 22:45:23 +05:30
sairajzero
9f72d3dd79 fix: added missing callback on testing code 2023-01-17 22:43:33 +05:30
sairajzero
269f3f1bd8 reduce MAX_IGNORED_BLOCK for testing 2023-01-17 22:20:02 +05:30
sairajzero
1fa3d45445 Adding test case and logging 2023-01-17 22:11:11 +05:30
sairajzero
ba08acb6ae remove testing-debug logging 2023-01-17 22:02:47 +05:30
Sai Raj
ca54b05618
Merge pull request #7 from ranchimall/dev2
Dev2
2023-01-17 21:56:20 +05:30
sairajzero
700abe0500 hotfix: block subscription getting stuck
- Issue: Block subscription getting stuck when a (missing) block wasn't received by block service.
- Solution: Re-trigger the sync process when too many blocks ignored

- Others: fixed a typo in _reportInterval property
2023-01-17 21:54:48 +05:30
sairajzero
0572ee6b35 header: clear _syncCheckInterval upon synced
Header service: clear _syncCheckInterval to null when clearing interval after sync completed
2023-01-17 16:44:42 +05:30
Sai Raj
e6826c7dfc
Merge pull request #6 from ranchimall/startup-sync-fix
Startup sync fix
2023-01-15 12:33:50 +05:30
3 changed files with 28 additions and 5 deletions

View File

@ -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();
}

View File

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

View File

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