Skip to content

Commit

Permalink
another startup fix:
Browse files Browse the repository at this point in the history
since we now make an rpc call to get the active chain before bothering with exchange rates, exchange rates were prone to fail to initialize, either due to slow response to getblockchaininfo call or connecting to a node that's not ready to serve traffic (e.g. verifying blocks). with this change, wait to decide about exchange rate status until we have a verified rpc connection.
  • Loading branch information
janoside committed Dec 23, 2019
1 parent 85e2367 commit d6a9e4c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 16 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#### v1.1.5
##### 2019-12-22

* Fix startup issues when connecting to a node that's not ready to serve data (e.g. verifying blocks)

#### v1.1.4
###### 2019-12-04

Expand Down
37 changes: 21 additions & 16 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,17 +186,11 @@ function verifyRpcConnection() {
coreApi.getBlockchainInfo().then(function(getblockchaininfo) {
global.activeBlockchain = getblockchaininfo.chain;

// localservicenames introduced in 0.19
var services = getnetworkinfo.localservicesnames ? ("[" + getnetworkinfo.localservicesnames.join(", ") + "]") : getnetworkinfo.localservices;

debugLog(`RPC Connected: version=${getnetworkinfo.version} (${getnetworkinfo.subversion}), protocolversion=${getnetworkinfo.protocolversion}, chain=${getblockchaininfo.chain}, services=${services}`);

// load historical/fun items for this chain
loadHistoricalDataForChain(global.activeBlockchain);

// we've verified rpc connection, no need to keep trying
clearInterval(global.verifyRpcConnectionIntervalId);

onRpcConnectionVerified(getnetworkinfo, getblockchaininfo);

}).catch(function(err) {
utils.logError("329u0wsdgewg6ed", err);
});
Expand All @@ -206,6 +200,25 @@ function verifyRpcConnection() {
}
}

function onRpcConnectionVerified(getnetworkinfo, getblockchaininfo) {
// localservicenames introduced in 0.19
var services = getnetworkinfo.localservicesnames ? ("[" + getnetworkinfo.localservicesnames.join(", ") + "]") : getnetworkinfo.localservices;

debugLog(`RPC Connected: version=${getnetworkinfo.version} (${getnetworkinfo.subversion}), protocolversion=${getnetworkinfo.protocolversion}, chain=${getblockchaininfo.chain}, services=${services}`);

// load historical/fun items for this chain
loadHistoricalDataForChain(global.activeBlockchain);

if (global.activeBlockchain == "main") {
if (global.exchangeRates == null) {
utils.refreshExchangeRates();
}

// refresh exchange rate periodically
setInterval(utils.refreshExchangeRates, 1800000);
}
}


app.onStartup = function() {
global.config = config;
Expand Down Expand Up @@ -313,14 +326,6 @@ app.continueStartup = function() {
setInterval(getSourcecodeProjectMetadata, 3600000);
}

if (global.activeBlockchain == "main") {
if (global.exchangeRates == null) {
utils.refreshExchangeRates();
}

// refresh exchange rate periodically
setInterval(utils.refreshExchangeRates, 1800000);
}

utils.logMemoryUsage();
setInterval(utils.logMemoryUsage, 5000);
Expand Down

0 comments on commit d6a9e4c

Please sign in to comment.