mirror of
https://github.com/jwinterm/nodejs-pool.git
synced 2026-10-17 05:21:27 +02:00
Slow down some of the network updates.
This commit is contained in:
+26
-14
@@ -105,14 +105,20 @@ sock.on('message', function(topic, message) {
|
||||
case 'miner_hash_graph':
|
||||
message = JSON.parse(message);
|
||||
message.forEach(function(address){
|
||||
io.sockets.in('hash_chart_'+address).emit('message', JSON.stringify(getAllWorkerHashCharts(address)));
|
||||
getAllWorkerHashCharts(address, function(err, data){
|
||||
return io.sockets.in('hash_chart_'+address).emit('message', JSON.stringify(data));
|
||||
});
|
||||
});
|
||||
break;
|
||||
case 'miner_hash_stats':
|
||||
message = JSON.parse(message);
|
||||
message.forEach(function(address){
|
||||
io.sockets.in('address_stats_'+address).emit('message', JSON.stringify(getAddressStats(address)));
|
||||
io.sockets.in('worker_stats_'+address).emit('message', JSON.stringify(getAllWorkerStats(address)));
|
||||
getAddressStats(address, function(err,data){
|
||||
io.sockets.in('address_stats_'+address).emit('message', JSON.stringify(data));
|
||||
});
|
||||
getAllWorkerStats(address, function(err, data){
|
||||
io.sockets.in('worker_stats_'+address).emit('message', JSON.stringify(data));
|
||||
});
|
||||
io.sockets.in('worker_ids_'+address).emit('message', JSON.stringify(global.database.getCache(address + '_identifiers')));
|
||||
});
|
||||
break;
|
||||
@@ -155,7 +161,7 @@ sock.on('message', function(topic, message) {
|
||||
});
|
||||
|
||||
// Support Functions that are reused now
|
||||
function getAllWorkerHashCharts(address){
|
||||
function getAllWorkerHashCharts(address, callback){
|
||||
let identifiers = global.database.getCache(address + '_identifiers');
|
||||
let returnData = {global: global.database.getCache(address)['hashHistory']};
|
||||
if (identifiers !== false){
|
||||
@@ -168,12 +174,12 @@ function getAllWorkerHashCharts(address){
|
||||
returnData[identifier] = global.database.getCache(address+"_"+identifier)['hashHistory'];
|
||||
intCounter += 1;
|
||||
if (intCounter === identifiers.length){
|
||||
return returnData;
|
||||
return callback(null, returnData);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function getAllWorkerStats(address){
|
||||
function getAllWorkerStats(address, callback){
|
||||
let identifiers = global.database.getCache(address + '_identifiers');
|
||||
let globalCache = global.database.getCache(address);
|
||||
let returnData = {global: {
|
||||
@@ -184,7 +190,7 @@ function getAllWorkerStats(address){
|
||||
}};
|
||||
let intCounter = 0;
|
||||
if (identifiers === false){
|
||||
return returnData;
|
||||
return callback(null, returnData);
|
||||
}
|
||||
identifiers.sort().forEach(function(identifier){
|
||||
let cachedData = global.database.getCache(address+"_"+identifier);
|
||||
@@ -196,12 +202,12 @@ function getAllWorkerStats(address){
|
||||
};
|
||||
intCounter += 1;
|
||||
if (intCounter === identifiers.length){
|
||||
return returnData;
|
||||
return callback(null, returnData);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function getAddressStats(address){
|
||||
function getAddressStats(address, extCallback){
|
||||
let address_parts = address.split('.');
|
||||
let address_pt = address_parts[0];
|
||||
let payment_id = address_parts[1];
|
||||
@@ -265,11 +271,11 @@ function getAddressStats(address){
|
||||
], function (err, result) {
|
||||
debug(threadName + "Result information for " + address + ": " + JSON.stringify(result));
|
||||
if (err === true) {
|
||||
return result;
|
||||
return extCallback(null, result);
|
||||
}
|
||||
if (err) {
|
||||
console.error(threadName + "Error within the miner stats identifier func");
|
||||
return {'error': err.toString()};
|
||||
return extCallback(err.toString());
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -537,7 +543,9 @@ app.get('/miner/:address/payments', function (req, res) {
|
||||
});
|
||||
|
||||
app.get('/miner/:address/stats/allWorkers', function (req, res) {
|
||||
return res.json(getAllWorkerStats(req.params.address));
|
||||
getAllWorkerStats(req.params.address, function(err, data){
|
||||
return res.json(data);
|
||||
});
|
||||
});
|
||||
|
||||
app.get('/miner/:address/stats/:identifier', function (req, res) {
|
||||
@@ -565,7 +573,9 @@ app.get('/miner/:address/chart/hashrate', function (req, res) {
|
||||
});
|
||||
|
||||
app.get('/miner/:address/chart/hashrate/allWorkers', function (req, res) {
|
||||
return res.json(getAllWorkerHashCharts(req.params.address));
|
||||
getAllWorkerHashCharts(req.params.address, function(err, data){
|
||||
return res.json(data);
|
||||
});
|
||||
});
|
||||
|
||||
app.get('/miner/:address/chart/hashrate/:identifier', function (req, res) {
|
||||
@@ -573,7 +583,9 @@ app.get('/miner/:address/chart/hashrate/:identifier', function (req, res) {
|
||||
});
|
||||
|
||||
app.get('/miner/:address/stats', function (req, res) {
|
||||
return res.json(getAddressStats(req.params.address));
|
||||
getAddressStats(req.params.address, function(err, data){
|
||||
return res.json(data);
|
||||
});
|
||||
});
|
||||
|
||||
// Authentication
|
||||
|
||||
+3
-1
@@ -8,6 +8,7 @@ const sock = zmq.socket('pub');
|
||||
let threadName = "Worker Server ";
|
||||
let cycleCount = 0;
|
||||
sock.bindSync('tcp://127.0.0.1:3000');
|
||||
let lastBlockHash = null;
|
||||
|
||||
function updateShareStats() {
|
||||
// This is an omni-worker to deal with all things share-stats related
|
||||
@@ -432,7 +433,8 @@ function updatePoolInformation() {
|
||||
|
||||
function updateBlockHeader() {
|
||||
global.support.rpcDaemon('getlastblockheader', [], function (body) {
|
||||
if (body.result) {
|
||||
if (body.result && body.result.block_header.hash !== lastBlockHash) {
|
||||
lastBlockHash = body.result.block_header.hash;
|
||||
global.database.setCache('networkBlockInfo', {
|
||||
difficulty: body.result.block_header.difficulty,
|
||||
hash: body.result.block_header.hash,
|
||||
|
||||
Reference in New Issue
Block a user