diff --git a/lib/pool.js b/lib/pool.js index b816ed4..aa3a4ca 100644 --- a/lib/pool.js +++ b/lib/pool.js @@ -202,6 +202,7 @@ function Miner(id, login, pass, ipAddress, startingDiff, messageSender, protoVer this.valid_miner = true; this.port = port; this.portType = portType; + this.incremented = false; switch (portType) { case 'pplns': this.poolTypeEnum = global.protos.POOLTYPE.PPLNS; @@ -320,6 +321,8 @@ function Miner(id, login, pass, ipAddress, startingDiff, messageSender, protoVer this.validJobs = global.support.circularBuffer(10); + this.cachedJob = null; + this.invalidShareProto = global.protos.InvalidShare.encode({ paymentAddress: this.address, paymentID: this.paymentID, @@ -432,12 +435,8 @@ function Miner(id, login, pass, ipAddress, startingDiff, messageSender, protoVer }; this.getJob = function () { - if (this.lastBlockHeight === activeBlockTemplate.height && !this.newDiff) { - return { - blob: '', - job_id: '', - target: '' - }; + if (this.lastBlockHeight === activeBlockTemplate.height && !this.newDiff && this.cachedJob !== null) { + return this.cachedJob; } let blob = activeBlockTemplate.nextBlob(); @@ -455,12 +454,12 @@ function Miner(id, login, pass, ipAddress, startingDiff, messageSender, protoVer }; this.validJobs.enq(newJob); - - return { + this.cachedJob = { blob: blob, job_id: newJob.id, target: target }; + return this.cachedJob; }; } } @@ -522,7 +521,13 @@ function processShare(miner, job, blockTemplate, nonce, resultHash) { } if (hash.toString('hex') !== resultHash) { console.error(threadName + "Bad hash from miner " + miner.logString); - miner.newDiff = miner.difficulty + 1; + if (miner.incremented === false){ + miner.newDiff = miner.difficulty + 1; + miner.incremented = true; + } else { + miner.newDiff = miner.difficulty - 1; + miner.incremented = false; + } miner.messageSender('job', miner.getJob()); return false; } @@ -644,7 +649,13 @@ function handleMinerData(method, params, ip, portData, sendReply, pushMessage) { if (!blockTemplate) { console.warn(threadName + 'Block expired, Height: ' + job.height + ' from ' + miner.logString); - miner.newDiff = miner.difficulty + 1; + if (miner.incremented === false){ + miner.newDiff = miner.difficulty + 1; + miner.incremented = true; + } else { + miner.newDiff = miner.difficulty - 1; + miner.incremented = false; + } miner.messageSender('job', miner.getJob()); sendReply('Block expired'); global.database.storeInvalidShare(miner.invalidShareProto);