From 2ab264a1bf8578d38689c336b2999eade2cdf10c Mon Sep 17 00:00:00 2001 From: Codex Bot Date: Mon, 23 Mar 2026 03:08:34 +0100 Subject: [PATCH] Bind miner shares to exact block templates --- lib/pool.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/pool.js b/lib/pool.js index 90574f3..5b23ddd 100644 --- a/lib/pool.js +++ b/lib/pool.js @@ -113,6 +113,7 @@ function Create2DArray (rows) { // Block templates let validBlockTemplates = Create2DArray(1); let currentBlockTemplate = []; +let templateSequence = 0; // Difficulty buffer @@ -219,6 +220,7 @@ process.on('message', function (message) { * Block template **/ function BlockTemplate (template) { + this.templateId = ++templateSequence; this.difficulty = template.difficulty; this.height; try { @@ -427,13 +429,16 @@ Miner.prototype = { let newJob = { id: utils.uid(), height: blockTemplate.height, + templateId: blockTemplate.templateId, + blockTemplate: blockTemplate, submissions: [] }; - if (this.lastBlockHeight === blockTemplate.height && !this.pendingDifficulty && this.cachedJob !== null && !miningBackends.getActiveMiningBackend().alwaysPoll) { + if (this.lastBlockHeight === blockTemplate.height && this.lastTemplateId === blockTemplate.templateId && !this.pendingDifficulty && this.cachedJob !== null && !miningBackends.getActiveMiningBackend().alwaysPoll) { return this.cachedJob; } let blob = this.proxy ? blockTemplate.nextBlobWithChildNonce() : blockTemplate.nextBlob(); this.lastBlockHeight = blockTemplate.height; + this.lastTemplateId = blockTemplate.templateId; let target = this.getTargetHex(); newJob.difficulty = this.difficulty; @@ -740,10 +745,10 @@ function handleMinerMethod (method, params, ip, portData, sendReply, pushMessage } let isJobBlock = function (b) { - return b.height === job.height; + return b && b.templateId === job.templateId; }; - let blockTemplate = isJobBlock(currentBlockTemplate[0]) ? currentBlockTemplate[0] : validBlockTemplates[0].filter(isJobBlock)[0]; + let blockTemplate = job.blockTemplate || (isJobBlock(currentBlockTemplate[0]) ? currentBlockTemplate[0] : validBlockTemplates[0].filter(isJobBlock)[0]); if (!blockTemplate) { sendReply('Block expired'); return;