Skip to content

Commit

Permalink
height checking related fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
taeguscromis committed Jul 22, 2020
1 parent ec431fb commit e92c896
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 16 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nodeguard",
"version": "0.5.5",
"version": "0.5.6",
"description": "Conceal Node Guard",
"main": "index.js",
"scripts": {
Expand Down
12 changes: 4 additions & 8 deletions units/comms.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ module.exports = {
var lastTS = moment();

this.stop = function () {
clearInterval(checkInterval);
IsRunning = false;
};

Expand All @@ -36,11 +37,6 @@ module.exports = {
}, 30000);
};

function reportError(reason) {
clearInterval(checkInterval);
errorCallback(reason);
}

function checkAliveAndWell() {
if (IsRunning) {
CCXApi.info().then(data => {
Expand All @@ -55,14 +51,14 @@ module.exports = {
var duration = moment.duration(moment().diff(lastTS));

if (duration.asSeconds() > (configOpts.restart.maxBlockTime || 1800)) {
reportError(vsprintf("No new block has be seen for more then %d minutes", [(configOpts.restart.maxBlockTime || 1800) / 60]));
errorCallback(vsprintf("No new block has be seen for more then %d minutes", [(configOpts.restart.maxBlockTime || 1800) / 60]));
heightIsOK = false;
}
}

if (heightIsOK) {
if (data.status !== "OK") {
reportError("Status is: " + data.status);
errorCallback("Status is: " + data.status);
} else {
// reset counter
timeoutCount = 0;
Expand All @@ -72,7 +68,7 @@ module.exports = {
if (IsRunning) {
timeoutCount++;
if (timeoutCount >= 3) {
reportError(err);
errorCallback(err);
}
}
});
Expand Down
10 changes: 3 additions & 7 deletions units/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ exports.NodeGuard = function (cmdOptions, configOpts, rootPath, guardVersion) {
var starupTime = moment();
var errorCount = 0;
var isStoping = false;
var initChecking = false;
var initInterval = null;
var poolInterval = null;
var locationData = null;
Expand Down Expand Up @@ -171,21 +170,18 @@ exports.NodeGuard = function (cmdOptions, configOpts, rootPath, guardVersion) {
// periodically check if the core has initialized
//*************************************************************//
function waitForCoreToInitialize() {
if (!initialized && !initChecking) {
if (!initialized) {
var duration = moment.duration(moment().diff(starupTime));
initChecking = true;

if (duration.asSeconds() > (configOpts.restart.maxInitTime || 900)) {
restartDaemonProcess("Initialization is taking to long, restarting", true);
} else {
request.get({
url: `http://127.0.0.1:${configOpts.node.port}/getinfo`,
headers: { 'User-Agent': 'Conceal Node Guardian' },
timeout: 3000,
timeout: 5000,
json: true
}, (err, res, release) => {
initChecking = false;

if ((!err) && (res.body.status === "OK")) {
logMessage("Core is initialized, starting the periodic checking...", "info", false);
clearInterval(initInterval);
Expand Down Expand Up @@ -265,7 +261,7 @@ exports.NodeGuard = function (cmdOptions, configOpts, rootPath, guardVersion) {
// start the initilize checking
initInterval = setInterval(function () {
waitForCoreToInitialize();
}, 5000);
}, 10000);
}
}

Expand Down

0 comments on commit e92c896

Please sign in to comment.