Merge pull request #6 from ranchimall/startup-sync-fix
Startup sync fix
This commit is contained in:
commit
e6826c7dfc
1
.gitignore
vendored
1
.gitignore
vendored
@ -21,6 +21,7 @@ coverage/*
|
|||||||
**/*.config
|
**/*.config
|
||||||
**/*.creator
|
**/*.creator
|
||||||
*.log
|
*.log
|
||||||
|
*.tmp
|
||||||
.DS_Store
|
.DS_Store
|
||||||
bin/florincoin*
|
bin/florincoin*
|
||||||
bin/SHA256SUMS.asc
|
bin/SHA256SUMS.asc
|
||||||
|
|||||||
@ -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);
|
||||||
@ -522,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()) {
|
||||||
@ -529,6 +532,10 @@ HeaderService.prototype._onHeadersSave = function(callback) {
|
|||||||
return 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._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
|
||||||
|
|
||||||
@ -707,6 +714,23 @@ 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
|
||||||
|
//(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();
|
return self._sync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user