Merge pull request #4 from ranchimall/dev2

test:hotfix
This commit is contained in:
Sai Raj 2023-01-11 03:41:56 +05:30 committed by GitHub
commit af8e939d40
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -14,6 +14,8 @@ var assert = require('assert');
var constants = require('../../constants'); var constants = require('../../constants');
var bcoin = require('fcoin'); var bcoin = require('fcoin');
const SYNC_CHECK_INTERVAL = 1000 * 60 * 15; //15 mins
var HeaderService = function(options) { var HeaderService = function(options) {
BaseService.call(this, options); BaseService.call(this, options);
@ -495,7 +497,8 @@ HeaderService.prototype._onHeaders = function(headers) {
}; };
HeaderService.prototype._handleError = function(err) { HeaderService.prototype._handleError = function(err) {
log.error('Error in Header Service: ' + err); log.error('Error in Header Service: ' + err);
return;
//this.node.stop(); //this.node.stop();
}; };
@ -521,6 +524,7 @@ HeaderService.prototype._saveHeaders = function(dbOps, callback) {
HeaderService.prototype._onHeadersSave = function(callback) { HeaderService.prototype._onHeadersSave = function(callback) {
var self = this; var self = this;
self._syncUnresponsive = false; //SZ: got response from peer
self._logProgress(); self._logProgress();
if (!self._syncComplete()) { if (!self._syncComplete()) {
@ -528,6 +532,8 @@ HeaderService.prototype._onHeadersSave = function(callback) {
return callback(); return callback();
} }
clearInterval(self._syncCheckInterval); //SZ: clear the interval check as sync is completed
self._endHeaderSubscription(); // we don't need headers any more self._endHeaderSubscription(); // we don't need headers any more
self._startBlockSubscription(); // we need new blocks coming tu us aynchronuously self._startBlockSubscription(); // we need new blocks coming tu us aynchronuously
@ -706,6 +712,16 @@ HeaderService.prototype._startSync = function() {
// common case // common case
if (numNeeded > 0) { if (numNeeded > 0) {
log.info('Header Service: Gathering: ' + numNeeded + ' ' + 'header(s) from the peer-to-peer network.'); log.info('Header Service: Gathering: ' + numNeeded + ' ' + 'header(s) from the peer-to-peer network.');
//SZ: Adding interval check for sync with peer is responsive or not
self._syncUnresponsive = true;
self._syncCheckInterval = setInterval(() => {
if(self._syncUnresponsive)
self._sync();
else //reset unresponsive as true
self._syncUnresponsive = true;
}, SYNC_CHECK_INTERVAL);
return self._sync(); return self._sync();
} }