From 6a083229b9c2306330de6a316513daab9da85c6a Mon Sep 17 00:00:00 2001 From: Alexander Blair Date: Wed, 13 Dec 2017 08:24:27 -0800 Subject: [PATCH 1/2] Update to fix duplicate job ID's being sent from the pool. If a duped job ID is sent, this should throw an error. --- lib/pool.js | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/lib/pool.js b/lib/pool.js index b0e1e46..d5f938a 100644 --- a/lib/pool.js +++ b/lib/pool.js @@ -193,7 +193,7 @@ function newBlockTemplate(template) { if (activeMiners.hasOwnProperty(minerId)) { let miner = activeMiners[minerId]; debug(threadName + "Updating worker " + miner.payout + " With new work at height: " + template.height); - miner.messageSender('job', miner.getJob()); + miner.sendNewJob(); } } } @@ -350,6 +350,7 @@ function Miner(id, login, pass, ipAddress, startingDiff, messageSender, protoVer } this.validJobs = global.support.circularBuffer(4); + this.sentJobs = global.support.circularBuffer(8); this.cachedJob = null; @@ -426,7 +427,7 @@ function Miner(id, login, pass, ipAddress, startingDiff, messageSender, protoVer Math.floor(this.hashes / (Math.floor((Date.now() - this.connectTime) / 1000))) + " hashes/second or: " + Math.floor(this.hashes / (Math.floor((Date.now() - this.connectTime) / 1000))) * global.config.pool.targetTime + " difficulty versus: " + this.newDiff); } - this.messageSender('job', this.getJob()); + this.sendNewJob(); }; this.checkBan = function (validShare) { @@ -532,6 +533,20 @@ function Miner(id, login, pass, ipAddress, startingDiff, messageSender, protoVer } return this.cachedJob; }; + + this.sendNewJob = function() { + let job = this.getJob(); + let tempJob = this.sentJobs.toarray().filter(function (intJob) { + return intJob.id === job.job_id; + })[0]; + + if (tempJob) { + console.error(`Tried sending a duped job to: ${this.address}, stopped by Snipa!`); + return; + } + this.sentJobs.enq(job); + return this.messageSender('job', job); + }; } } @@ -611,7 +626,7 @@ function processShare(miner, job, blockTemplate, params) { miner.newDiff = miner.difficulty - 1; miner.incremented = false; } - miner.messageSender('job', miner.getJob()); + miner.sendNewJob(); return false; } @@ -691,7 +706,7 @@ function handleMinerData(method, params, ip, portData, sendReply, pushMessage) { return; } miner.heartbeat(); - sendReply(null, miner.getJob()); + miner.sendNewJob(); break; case 'submit': if (!miner) { @@ -758,7 +773,7 @@ function handleMinerData(method, params, ip, portData, sendReply, pushMessage) { miner.newDiff = miner.difficulty - 1; miner.incremented = false; } - miner.messageSender('job', miner.getJob()); + miner.sendNewJob(); sendReply('Block expired'); global.database.storeInvalidShare(miner.invalidShareProto); return; From 2821fc477a223ca9d39de65287bdc7b2a99a71db Mon Sep 17 00:00:00 2001 From: Alexander Blair Date: Wed, 13 Dec 2017 08:29:49 -0800 Subject: [PATCH 2/2] Fix for the 300 msec template bug identified by Mayday30. Thanks for the catch! --- lib/pool.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/pool.js b/lib/pool.js index d5f938a..c61c911 100644 --- a/lib/pool.js +++ b/lib/pool.js @@ -171,11 +171,10 @@ function templateUpdate(repeating) { newBlockTemplate(rpcResponse); } } - if (repeating !== false) { + } else { + if (repeating !== true) { setTimeout(templateUpdate, 300); } - } else { - setTimeout(templateUpdate, 300, false); } }); } @@ -644,14 +643,14 @@ function processShare(miner, job, blockTemplate, params) { console.error(threadName + "Error submitting block at height " + job.height + " from " + miner.logString + ", share type: " + shareType + " error: " + JSON.stringify(rpcResult.error)); recordShareData(miner, job, hashDiff.toString(), false, null, shareType); // Error on submit, so we'll submit a sanity check for good measure. - templateUpdate(false); + templateUpdate(); } else if (rpcResult) { //Success! Submitted a block without an issue. let blockFastHash = global.coinFuncs.getBlockID(shareBuffer).toString('hex'); console.log(threadName + "Block " + blockFastHash.substr(0, 6) + " found at height " + job.height + " by " + miner.logString + ", share type: " + shareType + " - submit result: " + JSON.stringify(rpcResult.result)); recordShareData(miner, job, hashDiff.toString(), true, blockFastHash, shareType, blockTemplate); - templateUpdate(false); + templateUpdate(); } else { // RPC bombed out massively. console.error(threadName + "RPC Error. Please check logs for details"); @@ -856,14 +855,15 @@ if (cluster.isMaster) { workerList.push(worker); }); templateUpdate(); + setInterval(templateUpdate, 300, true); global.support.sendEmail(global.config.general.adminEmail, "Pool server " + global.config.hostname + " online", "The pool server: " + global.config.hostname + " with IP: " + global.config.bind_ip + " is online"); } else { setInterval(checkAliveMiners, 30000); setInterval(retargetMiners, global.config.pool.retargetTime * 1000); - templateUpdate(false); + templateUpdate(); setInterval(function () { bannedIPs = []; - templateUpdate(false); + templateUpdate(); }, 60000); async.each(global.config.ports, function (portData) { if (global.config[portData.portType].enable !== true) {