From a0bb6c04e174d60aa8d3f33585d47a01eaec0ef6 Mon Sep 17 00:00:00 2001 From: pallas1 Date: Mon, 21 May 2018 17:29:41 +0200 Subject: [PATCH 1/2] Tentative block template refresh timeout Untested: I have no pool setup to verify it. --- lib/pool.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/pool.js b/lib/pool.js index 7661007e..f5fb6332 100644 --- a/lib/pool.js +++ b/lib/pool.js @@ -18,6 +18,7 @@ let pastBlockTemplates = global.support.circularBuffer(4); let activeMiners = []; let activeMinerCount = []; let activeBlockTemplate; +let activeBlockTemplateAge; let workerList = []; let httpResponse = ' 200 OK\nContent-Type: text/plain\nContent-Length: 18\n\nMining Pool Online'; let threadName; @@ -170,13 +171,15 @@ function templateUpdate(repeating) { }); }, function (currentBlockHeight, callback) { - if (activeBlockTemplate && activeBlockTemplate.height === currentBlockHeight) { + let templateAgeThreshold = Date.now() - (global.config.coin.blockTargetTime * 1000); + if (activeBlockTemplate && activeBlockTemplate.height === currentBlockHeight && activeBlockTemplateAge >= templateAgeThreshold) { callback(null, activeBlockTemplate.height); } else { global.coinFuncs.getBlockTemplate(global.config.pool.address, function (rpcResponse) { if (rpcResponse && typeof rpcResponse.result !== 'undefined') { rpcResponse = rpcResponse.result; - if (!activeBlockTemplate || rpcResponse.height > activeBlockTemplate.height) { + if (!activeBlockTemplate || rpcResponse.height > activeBlockTemplate.height || activeBlockTemplateAge < templateAgeThreshold) { + activeBlockTemplateAge = Date.now(); debug(threadName + "New block template found at " + rpcResponse.height + " height"); if (cluster.isMaster) { sendToWorkers({type: 'newBlockTemplate', data: rpcResponse}); @@ -506,7 +509,7 @@ function Miner(id, login, pass, ipAddress, startingDiff, messageSender, protoVer }; this.getJob = function () { - if (this.lastBlockHeight === activeBlockTemplate.height && activeBlockTemplate.idHash === this.validJobs.get(0).blockHash && !this.newDiff && this.cachedJob !== null) { + if (this.lastBlockHeight === activeBlockTemplate.height && this.lastTimestamp === activeBlockTemplate.timestamp && activeBlockTemplate.idHash === this.validJobs.get(0).blockHash && !this.newDiff && this.cachedJob !== null) { return this.cachedJob; } @@ -514,6 +517,7 @@ function Miner(id, login, pass, ipAddress, startingDiff, messageSender, protoVer let blob = activeBlockTemplate.nextBlob(); let target = this.getTargetHex(); this.lastBlockHeight = activeBlockTemplate.height; + this.lastTimestamp = activeBlockTemplate.timestamp; let newJob = { @@ -540,6 +544,7 @@ function Miner(id, login, pass, ipAddress, startingDiff, messageSender, protoVer this.newDiff = null; } this.lastBlockHeight = activeBlockTemplate.height; + this.lastTimestamp = activeBlockTemplate.timestamp; let newJob = { id: crypto.pseudoRandomBytes(21).toString('base64'), From c401232991c4f53890a118bad4e4eba4aa9abccf Mon Sep 17 00:00:00 2001 From: pallas1 Date: Thu, 24 May 2018 16:32:33 +0200 Subject: [PATCH 2/2] Tentative fix 2 --- lib/pool.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pool.js b/lib/pool.js index f5fb6332..e1d04f51 100644 --- a/lib/pool.js +++ b/lib/pool.js @@ -179,7 +179,6 @@ function templateUpdate(repeating) { if (rpcResponse && typeof rpcResponse.result !== 'undefined') { rpcResponse = rpcResponse.result; if (!activeBlockTemplate || rpcResponse.height > activeBlockTemplate.height || activeBlockTemplateAge < templateAgeThreshold) { - activeBlockTemplateAge = Date.now(); debug(threadName + "New block template found at " + rpcResponse.height + " height"); if (cluster.isMaster) { sendToWorkers({type: 'newBlockTemplate', data: rpcResponse}); @@ -215,6 +214,7 @@ function newBlockTemplate(template) { pastBlockTemplates.enq(activeBlockTemplate); } activeBlockTemplate = new BlockTemplate(template); + activeBlockTemplateAge = Date.now(); for (let minerId in activeMiners) { if (activeMiners.hasOwnProperty(minerId)) { let miner = activeMiners[minerId];