Bind miner shares to exact block templates
Some checks failed
CodeQL / Analyze (javascript) (push) Failing after 56s
Some checks failed
CodeQL / Analyze (javascript) (push) Failing after 56s
This commit is contained in:
11
lib/pool.js
11
lib/pool.js
@@ -113,6 +113,7 @@ function Create2DArray (rows) {
|
|||||||
// Block templates
|
// Block templates
|
||||||
let validBlockTemplates = Create2DArray(1);
|
let validBlockTemplates = Create2DArray(1);
|
||||||
let currentBlockTemplate = [];
|
let currentBlockTemplate = [];
|
||||||
|
let templateSequence = 0;
|
||||||
|
|
||||||
|
|
||||||
// Difficulty buffer
|
// Difficulty buffer
|
||||||
@@ -219,6 +220,7 @@ process.on('message', function (message) {
|
|||||||
* Block template
|
* Block template
|
||||||
**/
|
**/
|
||||||
function BlockTemplate (template) {
|
function BlockTemplate (template) {
|
||||||
|
this.templateId = ++templateSequence;
|
||||||
this.difficulty = template.difficulty;
|
this.difficulty = template.difficulty;
|
||||||
this.height;
|
this.height;
|
||||||
try {
|
try {
|
||||||
@@ -427,13 +429,16 @@ Miner.prototype = {
|
|||||||
let newJob = {
|
let newJob = {
|
||||||
id: utils.uid(),
|
id: utils.uid(),
|
||||||
height: blockTemplate.height,
|
height: blockTemplate.height,
|
||||||
|
templateId: blockTemplate.templateId,
|
||||||
|
blockTemplate: blockTemplate,
|
||||||
submissions: []
|
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;
|
return this.cachedJob;
|
||||||
}
|
}
|
||||||
let blob = this.proxy ? blockTemplate.nextBlobWithChildNonce() : blockTemplate.nextBlob();
|
let blob = this.proxy ? blockTemplate.nextBlobWithChildNonce() : blockTemplate.nextBlob();
|
||||||
this.lastBlockHeight = blockTemplate.height;
|
this.lastBlockHeight = blockTemplate.height;
|
||||||
|
this.lastTemplateId = blockTemplate.templateId;
|
||||||
let target = this.getTargetHex();
|
let target = this.getTargetHex();
|
||||||
|
|
||||||
newJob.difficulty = this.difficulty;
|
newJob.difficulty = this.difficulty;
|
||||||
@@ -740,10 +745,10 @@ function handleMinerMethod (method, params, ip, portData, sendReply, pushMessage
|
|||||||
}
|
}
|
||||||
|
|
||||||
let isJobBlock = function (b) {
|
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) {
|
if (!blockTemplate) {
|
||||||
sendReply('Block expired');
|
sendReply('Block expired');
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user