diff --git a/.gitignore b/.gitignore index 744a842f..b4d08d78 100644 --- a/.gitignore +++ b/.gitignore @@ -21,6 +21,7 @@ coverage/* **/*.config **/*.creator *.log +*.tmp .DS_Store bin/florincoin* bin/SHA256SUMS.asc diff --git a/lib/services/header/index.js b/lib/services/header/index.js index 51eae75f..5a586919 100644 --- a/lib/services/header/index.js +++ b/lib/services/header/index.js @@ -14,6 +14,8 @@ var assert = require('assert'); var constants = require('../../constants'); var bcoin = require('fcoin'); +const SYNC_CHECK_INTERVAL = 1000 * 60 * 15; //15 mins + var HeaderService = function(options) { BaseService.call(this, options); @@ -522,6 +524,7 @@ HeaderService.prototype._saveHeaders = function(dbOps, callback) { HeaderService.prototype._onHeadersSave = function(callback) { var self = this; + self._syncUnresponsive = false; //SZ: got response from peer self._logProgress(); if (!self._syncComplete()) { @@ -529,6 +532,10 @@ HeaderService.prototype._onHeadersSave = function(callback) { return callback(); } + //SZ: clear the interval check as sync is completed + if(self._syncCheckInterval) + clearInterval(self._syncCheckInterval); + self._endHeaderSubscription(); // we don't need headers any more self._startBlockSubscription(); // we need new blocks coming tu us aynchronuously @@ -707,6 +714,23 @@ HeaderService.prototype._startSync = function() { // common case if (numNeeded > 0) { 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 + //(only if fcoin is started by flocore) + if(self._p2p._bcoin){ + self._syncUnresponsive = true; + self._syncCheckInterval = setInterval(() => { + //check the best 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 + if(self._syncUnresponsive) + self._sync(); + else //reset unresponsive as true + self._syncUnresponsive = true; + }, SYNC_CHECK_INTERVAL); + } + return self._sync(); }