mirror of
https://github.com/jwinterm/nodejs-pool.git
synced 2026-10-17 05:21:27 +02:00
Stats are now locked to only being available during a global tz. This should help deal with miners that have stats that run excessively far in comparison to the main system when they go offline for a day or two.
This commit is contained in:
+16
@@ -375,9 +375,11 @@ app.get('/miner/:address/stats', function (req, res) {
|
||||
let address_pt = address_parts[0];
|
||||
let payment_id = address_parts[1];
|
||||
let paidQuery = "SELECT SUM(amount) as amt FROM payments WHERE payment_address = ? AND payment_id = ?";
|
||||
let txnCount = "SELECT count(id) as amt FROM payments WHERE payment_address = ? AND payment_id = ?";
|
||||
let unpaidQuery = "SELECT SUM(amount) as amt FROM balance WHERE payment_address = ? AND payment_id = ?";
|
||||
if (typeof(payment_id) === 'undefined') {
|
||||
paidQuery = "SELECT SUM(amount) as amt FROM payments WHERE payment_address = ? AND payment_id IS ?";
|
||||
txnCount = "SELECT count(id) as amt FROM payments WHERE payment_address = ? AND payment_id IS ?";
|
||||
unpaidQuery = "SELECT SUM(amount) as amt FROM balance WHERE payment_address = ? AND payment_id IS ?";
|
||||
}
|
||||
async.waterfall([
|
||||
@@ -422,6 +424,20 @@ app.get('/miner/:address/stats', function (req, res) {
|
||||
}
|
||||
return callback(true, returnData);
|
||||
});
|
||||
},
|
||||
function (returnData, callback) {
|
||||
debug(threadName + "Checking MySQL total amount unpaid for /miner/address/stats");
|
||||
global.mysql.query(txnCount, [address_pt, payment_id]).then(function (rows) {
|
||||
if (typeof(rows[0]) === 'undefined') {
|
||||
returnData.txnCount = 0;
|
||||
} else {
|
||||
returnData.txnCount = rows[0].amt;
|
||||
if (returnData.txnCount === null) {
|
||||
returnData.txnCount = 0;
|
||||
}
|
||||
}
|
||||
return callback(true, returnData);
|
||||
});
|
||||
}
|
||||
], function (err, result) {
|
||||
debug(threadName + "Result information for " + address + ": " + JSON.stringify(result));
|
||||
|
||||
+41
-31
@@ -132,37 +132,7 @@ function updateShareStats() {
|
||||
if (globalMinerList === false) {
|
||||
globalMinerList = [];
|
||||
}
|
||||
minerList.forEach(function (miner) {
|
||||
if (globalMinerList.indexOf(miner) === -1) {
|
||||
globalMinerList.push(miner);
|
||||
}
|
||||
let cachedData = global.database.getCache(miner);
|
||||
if (cachedData !== false) {
|
||||
cachedData.hash = Math.floor(localStats.miners[miner] / 600);
|
||||
cachedData.lastHash = localTimes.miners[miner];
|
||||
if (!cachedData.hasOwnProperty("hashHistory")) {
|
||||
cachedData.hashHistory = [];
|
||||
}
|
||||
if (cycleCount === 0){
|
||||
cachedData.hashHistory.unshift({ts: currentTime, hs: cachedData.hash});
|
||||
if (cachedData.hashHistory.length > global.config.general.statsBufferLength) {
|
||||
while (cachedData.hashHistory.length > global.config.general.statsBufferLength) {
|
||||
cachedData.hashHistory.pop();
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
cachedData = {
|
||||
hash: Math.floor(localStats.miners[miner] / 600),
|
||||
totalHashes: 0,
|
||||
lastHash: localTimes.miners[miner],
|
||||
hashHistory: [{ts: currentTime, hs: cachedData.hash}],
|
||||
goodShares: 0,
|
||||
badShares: 0
|
||||
};
|
||||
}
|
||||
global.database.setCache(miner, cachedData);
|
||||
});
|
||||
let globalTimes = [];
|
||||
// pplns: 0, pps: 0, solo: 0, prop: 0, global: 0
|
||||
['pplns', 'pps', 'solo', 'prop', 'global'].forEach(function (key) {
|
||||
let cachedData = global.database.getCache(key + "_stats");
|
||||
@@ -188,6 +158,9 @@ function updateShareStats() {
|
||||
}
|
||||
}
|
||||
}
|
||||
cachedData.hashHistory.forEach(function(data){
|
||||
globalTimes.push(data.ts);
|
||||
});
|
||||
} else {
|
||||
cachedData = {
|
||||
hash: Math.floor(localStats[key] / 600),
|
||||
@@ -200,6 +173,43 @@ function updateShareStats() {
|
||||
}
|
||||
global.database.setCache(key + "_stats", cachedData);
|
||||
});
|
||||
minerList.forEach(function (miner) {
|
||||
if (globalMinerList.indexOf(miner) === -1) {
|
||||
globalMinerList.push(miner);
|
||||
}
|
||||
let cachedData = global.database.getCache(miner);
|
||||
if (cachedData !== false) {
|
||||
cachedData.hash = Math.floor(localStats.miners[miner] / 600);
|
||||
cachedData.lastHash = localTimes.miners[miner];
|
||||
if (!cachedData.hasOwnProperty("hashHistory")) {
|
||||
cachedData.hashHistory = [];
|
||||
}
|
||||
if (cycleCount === 0){
|
||||
cachedData.hashHistory.unshift({ts: currentTime, hs: cachedData.hash});
|
||||
if (cachedData.hashHistory.length > global.config.general.statsBufferLength) {
|
||||
while (cachedData.hashHistory.length > global.config.general.statsBufferLength) {
|
||||
cachedData.hashHistory.pop();
|
||||
}
|
||||
}
|
||||
let hashData = cachedData.hashHistory;
|
||||
hashData.forEach(function(data){
|
||||
if (!globalTimes.hasOwnProperty(data.ts)){
|
||||
cachedData.hashHistory.splice(cachedData.hashHistory.indexOf(data), 1);
|
||||
}
|
||||
});
|
||||
}
|
||||
} else {
|
||||
cachedData = {
|
||||
hash: Math.floor(localStats.miners[miner] / 600),
|
||||
totalHashes: 0,
|
||||
lastHash: localTimes.miners[miner],
|
||||
hashHistory: [{ts: currentTime, hs: cachedData.hash}],
|
||||
goodShares: 0,
|
||||
badShares: 0
|
||||
};
|
||||
}
|
||||
global.database.setCache(miner, cachedData);
|
||||
});
|
||||
globalMinerList.forEach(function (miner) {
|
||||
if (minerList.indexOf(miner) === -1) {
|
||||
let minerStats = global.database.getCache(miner);
|
||||
|
||||
Reference in New Issue
Block a user