From 5770013bad39ffa8b4694d9a31cc9cb26c76ddef Mon Sep 17 00:00:00 2001 From: Petr Balashov Date: Tue, 7 Mar 2017 14:37:25 +0100 Subject: [PATCH] prevent too many concurrent debug.log i/o in KMD native mode --- assets/scripts/kmd_wallet/KMDInit.js | 68 ++++++++++++++++------------ assets/scripts/lang/en.js | 7 ++- 2 files changed, 43 insertions(+), 32 deletions(-) diff --git a/assets/scripts/kmd_wallet/KMDInit.js b/assets/scripts/kmd_wallet/KMDInit.js index 369f930..3806e03 100644 --- a/assets/scripts/kmd_wallet/KMDInit.js +++ b/assets/scripts/kmd_wallet/KMDInit.js @@ -1,3 +1,13 @@ +var chainActivationLastUpdate, + chainActivationLastUpdateTimeout = 1; + +function checkTimestamp(dateToCheck) { + var currentEpochTime = new Date(Date.now()) / 1000, + secondsElapsed = Number(currentEpochTime) - Number(dateToCheck / 1000); + + return Math.floor(secondsElapsed); +} + function RunKMDInitFunctions() { NProgress.done(true); NProgress.configure({ @@ -87,38 +97,40 @@ function RunKMDInitFunctions() { var currentBestBlockInterval; function startBestBlockInterval() { currentBestBlockInterval = setInterval(function() { - $.ajax({ - type: 'POST', - data: { - 'herdname': 'komodo', - 'lastLines': 1 - }, - url: 'http://127.0.0.1:17777/shepherd/debuglog', - success: function(data, textStatus, jqXHR) { - if (data.indexOf('UpdateTip') > -1) { - var temp = data.split(' '); - - for (var i = 0; i < temp.length; i++) { - if (temp[i].indexOf('height=') > -1) { - var currentBestChain = temp[i].replace('height=', ''); - $('#activating-komodod-tridot').hide(); - $('#activating-komodod-progress').html(': ' + Math.floor(currentBestChain * 100 / totalBlocksInExplorer) + '% (blocks ' + currentBestChain + ' / ' + totalBlocksInExplorer + ')'); - - if (currentBestChain === totalBlocksInExplorer) { - //clearInterval(totalBlocksInExplorerInterval); - clearInterval(currentBestBlockInterval); + if (!chainActivationLastUpdate || checkTimestamp(chainActivationLastUpdate) > chainActivationLastUpdateTimeout) { + $.ajax({ + type: 'POST', + data: { + 'herdname': 'komodo', + 'lastLines': 1 + }, + url: 'http://127.0.0.1:17777/shepherd/debuglog', + success: function(data, textStatus, jqXHR) { + if (data.indexOf('UpdateTip') > -1) { + var temp = data.split(' '); + + for (var i = 0; i < temp.length; i++) { + if (temp[i].indexOf('height=') > -1) { + var currentBestChain = temp[i].replace('height=', ''); + $('#activating-komodod-tridot').hide(); + $('#activating-komodod-progress').html(': ' + Math.floor(currentBestChain * 100 / totalBlocksInExplorer) + '% (blocks ' + currentBestChain + ' / ' + totalBlocksInExplorer + ')'); + chainActivationLastUpdate = Date.now(); + if (currentBestChain === totalBlocksInExplorer) { + //clearInterval(totalBlocksInExplorerInterval); + clearInterval(currentBestBlockInterval); + } } } } + }, + error: function(xhr, textStatus, error) { + console.log('failed getting debug.log'); + console.log(xhr.statusText); + console.log(textStatus); + console.log(error); } - }, - error: function(xhr, textStatus, error) { - console.log('failed getting debug.log'); - console.log(xhr.statusText); - console.log(textStatus); - console.log(error); - } - }); + }); + } }, 2000); } diff --git a/assets/scripts/lang/en.js b/assets/scripts/lang/en.js index 059824d..f70a20c 100644 --- a/assets/scripts/lang/en.js +++ b/assets/scripts/lang/en.js @@ -148,8 +148,8 @@ const _lang = { 'FIAT_CURRENCY': 'Fiat Currency', 'EXPORT_KEYS': 'Export Keys', 'ONLY_ACTIVE_WIF_KEYS': 'Only the active coin wallet wif keys will be shown here.
' + - 'If you don\'t see a wif key for the coin you are looking for please active it by adding it from EasyDEX Dashboard.
' + - 'You can use these wif keys to import to another coin wallets.', + 'If you don\'t see a wif key for the coin you are looking for please active it by adding it from EasyDEX Dashboard.
' + + 'You can use these wif keys to import to another coin wallets.', 'PLEASE_KEEP_KEYS_SAFE': 'Please keep these keys extra safe and secure.', 'PASSPHRASE': 'Passphrase', 'GET_WIF_KEYS': 'Get Wif Keys', @@ -194,7 +194,7 @@ const _lang = { 'FETCHING_DATA': 'Fetching Data. Please wait for a minute to complete this task.', 'LESS_RESPONSES_REQ': 'Less than required responses. Please try again.', 'SWITCHED_TO': 'switched to', - 'MODE': 'Mode', + 'MODE': 'Mode', 'TX_SENT': 'Transaction Sent', 'TX_SEND_ERR': 'Unable to complete transaction', 'LOOKS_LIKE': 'Looks like', @@ -272,7 +272,6 @@ const _lang = { }, 'SETTINGS': { 'PASSPHRASE_REQ': 'Passphrase is required.', - } } }; \ No newline at end of file