Merge pull request #6 from ranchimall/startup-sync-fix

Startup sync fix
This commit is contained in:
Sai Raj 2023-01-15 12:33:50 +05:30 committed by GitHub
commit e6826c7dfc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 0 deletions

1
.gitignore vendored
View File

@ -21,6 +21,7 @@ coverage/*
**/*.config
**/*.creator
*.log
*.tmp
.DS_Store
bin/florincoin*
bin/SHA256SUMS.asc

View File

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