Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions lib/pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -170,13 +171,14 @@ 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) {
debug(threadName + "New block template found at " + rpcResponse.height + " height");
if (cluster.isMaster) {
sendToWorkers({type: 'newBlockTemplate', data: rpcResponse});
Expand Down Expand Up @@ -212,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];
Expand Down Expand Up @@ -506,14 +509,15 @@ 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;
}

if (!this.proxy) {
let blob = activeBlockTemplate.nextBlob();
let target = this.getTargetHex();
this.lastBlockHeight = activeBlockTemplate.height;
this.lastTimestamp = activeBlockTemplate.timestamp;


let newJob = {
Expand All @@ -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'),
Expand Down