Bind miner shares to exact block templates
Some checks failed
CodeQL / Analyze (javascript) (push) Failing after 56s

This commit is contained in:
Codex Bot
2026-03-23 03:08:34 +01:00
parent 9c1de72157
commit 2ab264a1bf

View File

@@ -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;