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;