Adding Blockchain refresh interval
- Added blockchain refresh interval - Updating some constants - Disabled various console.debug
This commit is contained in:
parent
1fcd62f2e5
commit
4416ab5ad3
@ -1,6 +1,7 @@
|
||||
module.exports = {
|
||||
app: {
|
||||
REFRESH_INTERVAL: 1 * 60 * 1000 // 1 min
|
||||
BLOCKCHAIN_REFRESH_INTERVAL: 1 * 60 * 60 * 1000, // 1 hr
|
||||
PERIOD_INTERVAL: 15 * 60 * 1000 // 15 min
|
||||
},
|
||||
request: {
|
||||
MAX_SESSION_TIMEOUT: 60 * 24 * 60 * 60 * 1000, //60 days
|
||||
@ -16,14 +17,14 @@ module.exports = {
|
||||
MAX_DOWN_PER_DAY: 4.8 / 100, //max 4.8% dec
|
||||
MAX_UP_PER_DAY: 12 / 100, //max 12% inc
|
||||
TOP_RANGE: 10 / 100, //top 10%
|
||||
REC_HISTORY_INTERVAL: 30 * 60 * 1000 //30 mins
|
||||
REC_HISTORY_INTERVAL: 1 * 60 * 60 * 1000, // 1 hr
|
||||
},
|
||||
backup: {
|
||||
SHARE_THRESHOLD: 50 / 100, // 50%
|
||||
HASH_N_ROW: 100,
|
||||
SINK_KEY_INDICATOR: '$$$',
|
||||
BACKUP_INTERVAL: 1 * 60 * 1000, //1 min
|
||||
BACKUP_INTERVAL: 5 * 60 * 1000, //5 min
|
||||
BACKUP_SYNC_TIMEOUT: 10 * 60 * 1000, //10 mins
|
||||
CHECKSUM_INTERVAL: 15, //times of BACKUP_INTERVAL
|
||||
CHECKSUM_INTERVAL: 100, //times of BACKUP_INTERVAL
|
||||
}
|
||||
}
|
||||
@ -5,7 +5,7 @@ const express = require('express');
|
||||
const Request = require('./request');
|
||||
|
||||
const {
|
||||
REFRESH_INTERVAL
|
||||
PERIOD_INTERVAL
|
||||
} = require("./_constants")["app"];
|
||||
|
||||
module.exports = function App(secret, DB) {
|
||||
@ -141,7 +141,7 @@ module.exports = function App(secret, DB) {
|
||||
Request.resume();
|
||||
Request.periodicProcess();
|
||||
if (periodInstance === null)
|
||||
periodInstance = setInterval(Request.periodicProcess, REFRESH_INTERVAL);
|
||||
periodInstance = setInterval(Request.periodicProcess, PERIOD_INTERVAL);
|
||||
}
|
||||
|
||||
Object.defineProperty(self, "periodInstance", {
|
||||
|
||||
@ -107,13 +107,13 @@ collectShares.retrive = function(floID, sinkID, share) {
|
||||
return console.error("Something is wrong! Slaves are sending different sinkID");
|
||||
if (share.startsWith(SINK_KEY_INDICATOR)) {
|
||||
let sinkKey = share.substring(SINK_KEY_INDICATOR.length);
|
||||
console.debug("Received sinkKey:", sinkID, sinkKey);
|
||||
//console.debug("Received sinkKey:", sinkID, sinkKey);
|
||||
self.verify(sinkKey);
|
||||
} else
|
||||
self.shares[floID] = share.split("|");
|
||||
try {
|
||||
let sinkKey = floCrypto.retrieveShamirSecret([].concat(...Object.values(self.shares)));
|
||||
console.debug("Retrived sinkKey:", sinkID, sinkKey);
|
||||
//console.debug("Retrived sinkKey:", sinkID, sinkKey);
|
||||
self.verify(sinkKey);
|
||||
} catch {
|
||||
//Unable to retrive sink private key. Waiting for more shares! Do nothing for now
|
||||
@ -212,7 +212,7 @@ function informLiveNodes(init) {
|
||||
console.warn("sinkID and sinkKey in DB are not pair!");
|
||||
storeSink(global.sinkID, global.sinkPrivKey);
|
||||
}
|
||||
console.debug("Loaded sinkKey:", global.sinkID, global.sinkPrivKey)
|
||||
//console.debug("Loaded sinkKey:", global.sinkID, global.sinkPrivKey)
|
||||
sendSharesToNodes(global.sinkID, generateShares(global.sinkPrivKey))
|
||||
} else {
|
||||
//Share is present in DB, try to collect remaining shares and retrive sinkKey
|
||||
@ -280,7 +280,7 @@ function startBackupTransmitter(server) {
|
||||
try {
|
||||
let invalid = null,
|
||||
request = JSON.parse(message);
|
||||
console.debug(request);
|
||||
//console.debug(request);
|
||||
if (!nodeList.includes(request.floID))
|
||||
invalid = `floID ${request.floID} not in nodeList`;
|
||||
else if (request.floID !== floCrypto.getFloID(request.pubKey))
|
||||
|
||||
@ -146,7 +146,7 @@ function processDataFromMaster(message) {
|
||||
|
||||
function storeSinkShare(sinkID, keyShare) {
|
||||
let encryptedShare = Crypto.AES.encrypt(floCrypto.decryptData(keyShare, global.myPrivKey), global.myPrivKey);
|
||||
console.debug(Date.now(), '|sinkID:', sinkID, '|EnShare:', encryptedShare);
|
||||
console.log(Date.now(), '|sinkID:', sinkID, '|EnShare:', encryptedShare);
|
||||
DB.query("INSERT INTO sinkShares (floID, share) VALUE (?, ?) AS new ON DUPLICATE KEY UPDATE share=new.share", [sinkID, encryptedShare])
|
||||
.then(_ => null).catch(error => console.error(error));
|
||||
}
|
||||
@ -333,7 +333,7 @@ function verifyChecksum(checksum_ref) {
|
||||
for (let table in checksum)
|
||||
if (checksum[table] != checksum_ref[table])
|
||||
mismatch.push(table);
|
||||
console.debug("Checksum-mismatch:", mismatch);
|
||||
//console.debug("Checksum-mismatch:", mismatch);
|
||||
if (!mismatch.length) //Checksum of every table is verified.
|
||||
resolve(true);
|
||||
else { //If one or more tables checksum is not correct, re-request the table data
|
||||
@ -398,7 +398,7 @@ function verifyHash(hashes) {
|
||||
.then(_ => null);
|
||||
} else
|
||||
console.error(result[t].reason);
|
||||
console.debug("Hash-mismatch", mismatch);
|
||||
//console.debug("Hash-mismatch", mismatch);
|
||||
resolve(mismatch);
|
||||
}).catch(error => reject(error))
|
||||
})
|
||||
|
||||
@ -17,8 +17,8 @@ function processCoupling(bestPairQueue) {
|
||||
bestPairQueue.get().then(pair_result => {
|
||||
let buyer_best = pair_result.buyOrder,
|
||||
seller_best = pair_result.sellOrder;
|
||||
console.debug("Sell:", seller_best);
|
||||
console.debug("Buy:", buyer_best);
|
||||
//console.debug("Sell:", seller_best);
|
||||
//console.debug("Buy:", buyer_best);
|
||||
spendAsset(bestPairQueue.asset, buyer_best, seller_best, pair_result.null_base).then(spent => {
|
||||
if (!spent.quantity) {
|
||||
//Happens when there are only Null-base assets
|
||||
|
||||
@ -11,6 +11,10 @@ const App = require('./app');
|
||||
|
||||
const backup = require('./backup/head');
|
||||
|
||||
const {
|
||||
BLOCKCHAIN_REFRESH_INTERVAL
|
||||
} = require("./_constants")["app"];
|
||||
|
||||
var DB, app;
|
||||
|
||||
function refreshData(startup = false) {
|
||||
@ -81,7 +85,7 @@ function refreshDataFromBlockchain() {
|
||||
promises.push(DB.query("INSERT INTO LastTx (floID, num) VALUE (?, ?) AS new ON DUPLICATE KEY UPDATE num=new.num", [floGlobals.adminID, result.totalTxs]));
|
||||
//Check if all save process were successful
|
||||
Promise.allSettled(promises).then(results => {
|
||||
console.debug(results.filter(r => r.status === "rejected"));
|
||||
//console.debug(results.filter(r => r.status === "rejected"));
|
||||
if (results.reduce((a, r) => r.status === "rejected" ? ++a : a, 0))
|
||||
console.warn("Some data might not have been saved in database correctly");
|
||||
});
|
||||
@ -176,7 +180,7 @@ module.exports = function startServer(public_dir) {
|
||||
}
|
||||
|
||||
global.PUBLIC_DIR = public_dir;
|
||||
console.debug(PUBLIC_DIR, global.myFloID);
|
||||
console.log("Logged in as", global.myFloID);
|
||||
|
||||
Database(config["sql_user"], config["sql_pwd"], config["sql_db"], config["sql_host"]).then(db => {
|
||||
setDB(db);
|
||||
@ -185,6 +189,7 @@ module.exports = function startServer(public_dir) {
|
||||
app.start(config['port']).then(result => {
|
||||
console.log(result);
|
||||
backup.init(app);
|
||||
setInterval(refreshData, BLOCKCHAIN_REFRESH_INTERVAL)
|
||||
}).catch(error => console.error(error))
|
||||
}).catch(error => console.error(error))
|
||||
}).catch(error => console.error(error));
|
||||
|
||||
@ -254,7 +254,7 @@ function withdrawFLO(floID, amount) {
|
||||
.then(_ => null).catch(error => console.error(error))
|
||||
.finally(_ => resolve("Withdrawal was successful"));
|
||||
}).catch(error => {
|
||||
console.debug(error);
|
||||
console.error(error);
|
||||
DB.query("INSERT INTO OutputFLO (floID, amount, status) VALUES (?, ?, ?)", [floID, amount, "PENDING"])
|
||||
.then(_ => null).catch(error => console.error(error))
|
||||
.finally(_ => resolve("Withdrawal request is in process"));
|
||||
@ -393,7 +393,7 @@ function withdrawToken(floID, token, amount) {
|
||||
.then(_ => null).catch(error => console.error(error))
|
||||
.finally(_ => resolve("Withdrawal was successful"));
|
||||
}).catch(error => {
|
||||
console.debug(error);
|
||||
console.error(error);
|
||||
DB.query("INSERT INTO OutputToken (floID, token, amount, status) VALUES (?, ?, ?, ?)", [floID, token, amount, "PENDING"])
|
||||
.then(_ => null).catch(error => console.error(error))
|
||||
.finally(_ => resolve("Withdrawal request is in process"));
|
||||
|
||||
@ -97,7 +97,7 @@ fetchRates.USD_INR = function() {
|
||||
function getRates(asset) {
|
||||
return new Promise((resolve, reject) => {
|
||||
loadRate(asset).then(_ => {
|
||||
console.debug(asset, currentRate[asset]);
|
||||
//console.debug(asset, currentRate[asset]);
|
||||
let cur_time = Date.now();
|
||||
if (cur_time - lastTime[asset] < MIN_TIME) //Minimum time to update not crossed: No update required
|
||||
resolve(currentRate[asset]);
|
||||
|
||||
@ -57,7 +57,7 @@ function validateRequest(request, sign, pubKey) {
|
||||
}
|
||||
|
||||
function storeRequest(floID, req_str, sign) {
|
||||
console.debug(floID, req_str);
|
||||
//console.debug(floID, req_str);
|
||||
DB.query("INSERT INTO RequestLog (floID, request, sign) VALUES (?,?,?)", [floID, req_str, sign])
|
||||
.then(_ => null).catch(error => console.error(error));
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user