From 92740a4642d113878edc809ba550da646a38b6bd Mon Sep 17 00:00:00 2001 From: Alexander Blair Date: Fri, 30 Jun 2017 14:29:11 -0700 Subject: [PATCH] Cherrypicking a couple of commits, merge-conflicts later, but I'll deal with it then. --- lib/pool.js | 35 +++++++++++++++++++++++++++++++---- lib/remote_comms.js | 9 +++++++++ 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/lib/pool.js b/lib/pool.js index f8c5bc2..0817c6b 100644 --- a/lib/pool.js +++ b/lib/pool.js @@ -23,6 +23,8 @@ let threadName; let minerCount = []; let BlockTemplate = global.coinFuncs.BlockTemplate; let hexMatch = new RegExp("^[0-9a-f]+$"); +let totalShares=0, trustedShares=0, normalShares=0, invalidShares=0; + Buffer.prototype.toByteArray = function () { return Array.prototype.slice.call(this, 0); @@ -31,10 +33,19 @@ Buffer.prototype.toByteArray = function () { if (cluster.isMaster) { threadName = "(Master) "; + setInterval(function(){ + console.log(`Processed ${trustedShares}/${normalShares}/${invalidShares}/${totalShares} Trusted/Validated/Invalid/Total shares in the last 30 seconds`); + totalShares=0; + trustedShares=0; + normalShares=0; + invalidShares=0; + }, 30000); } else { threadName = "(Worker " + cluster.worker.id + " - " + process.pid + ") "; } +global.database.thread_id = threadName; + function registerPool() { global.mysql.query("SELECT * FROM pools WHERE id = ?", [global.config.pool_id]).then(function (rows) { rows.forEach(function (row) { @@ -95,6 +106,17 @@ function messageHandler(message) { global.database.sendQueue.push(Buffer.from(message.data, 'hex')); } break; + case 'trustedShare': + trustedShares += 1; + totalShares += 1; + break; + case 'normalShare': + normalShares += 1; + totalShares += 1; + break; + case 'invalidShare': + invalidShares += 1; + totalShares += 1; } } @@ -116,6 +138,7 @@ function sendToWorkers(data) { function retargetMiners() { debug(threadName + "Performing difficulty check on miners"); + console.log('Performing difficulty update on miners'); for (let minerId in activeMiners) { if (activeMiners.hasOwnProperty(minerId)) { let miner = activeMiners[minerId]; @@ -393,7 +416,7 @@ function Miner(id, login, pass, ipAddress, startingDiff, messageSender, protoVer if (this.newDiff < global.config.pool.minDifficulty) { this.newDiff = global.config.pool.minDifficulty; } - console.log(threadName + "Difficulty change to: " + this.newDiff + " For: " + this.logString); + debug(threadName + "Difficulty change to: " + this.newDiff + " For: " + this.logString); if (this.hashes > 0){ debug(threadName + "Hashes: " + this.hashes + " in: " + Math.floor((Date.now() - this.connectTime)/1000) + " seconds gives: " + Math.floor(this.hashes/(Math.floor((Date.now() - this.connectTime)/1000))) + " hashes/second or: " + @@ -502,9 +525,11 @@ function recordShareData(miner, job, shareDiff, blockCandidate, hashHex, shareTy })); } if (shareType) { - console.log(threadName + "Accepted trusted share at difficulty: " + job.difficulty + "/" + shareDiff + " from: " + miner.logString); + process.send({type: 'trustedShare'}); + debug(threadName + "Accepted trusted share at difficulty: " + job.difficulty + "/" + shareDiff + " from: " + miner.logString); } else { - console.log(threadName + "Accepted valid share at difficulty: " + job.difficulty + "/" + shareDiff + " from: " + miner.logString); + process.send({type: 'normalShare'}); + debug(threadName + "Accepted valid share at difficulty: " + job.difficulty + "/" + shareDiff + " from: " + miner.logString); } } @@ -530,7 +555,8 @@ function processShare(miner, job, blockTemplate, nonce, resultHash) { shareType = false; } if (hash.toString('hex') !== resultHash) { - console.error(threadName + "Bad hash from miner " + miner.logString); + console.error(threadName + "Bad share from miner " + miner.logString); + process.send({type: 'invalidShare'}); if (miner.incremented === false){ miner.newDiff = miner.difficulty + 1; miner.incremented = true; @@ -570,6 +596,7 @@ function processShare(miner, job, blockTemplate, nonce, resultHash) { }); } else if (hashDiff.lt(job.difficulty)) { + process.send({type: 'invalidShare'}); console.warn(threadName + "Rejected low diff share of " + hashDiff.toString() + " from: " + miner.address + " ID: " + miner.identifier + " IP: " + miner.ipAddress); return false; diff --git a/lib/remote_comms.js b/lib/remote_comms.js index 0dff0dc..3c9a69a 100644 --- a/lib/remote_comms.js +++ b/lib/remote_comms.js @@ -4,6 +4,8 @@ const async = require('async'); function Database() { + let thread_id=''; + this.sendQueue = async.queue(function (task, callback) { async.doUntil( function (intCallback) { @@ -52,6 +54,13 @@ function Database() { process.send({type: 'sendRemote', body: wsData.toString('hex')}); }; + setInterval(function(queue_obj){ + if (thread_id === '(Master) '){ + console.log(global.database.thread_id + "Queue debug state: " + queue_obj.length() + " items in the queue " + queue_obj.running() + " items being processed"); + } + }, 5000, this.sendQueue); + + this.initEnv = function(){ this.data = null; };