Merge pull request #205 from Snipa22/altcoins

Altcoins
This commit is contained in:
Snipa22
2017-12-13 08:34:28 -08:00
committed by GitHub
+27 -12
View File
@@ -171,11 +171,10 @@ function templateUpdate(repeating) {
newBlockTemplate(rpcResponse);
}
}
if (repeating !== false) {
} else {
if (repeating !== true) {
setTimeout(templateUpdate, 300);
}
} else {
setTimeout(templateUpdate, 300, false);
}
});
}
@@ -193,7 +192,7 @@ function newBlockTemplate(template) {
if (activeMiners.hasOwnProperty(minerId)) {
let miner = activeMiners[minerId];
debug(threadName + "Updating worker " + miner.payout + " With new work at height: " + template.height);
miner.messageSender('job', miner.getJob());
miner.sendNewJob();
}
}
}
@@ -350,6 +349,7 @@ function Miner(id, login, pass, ipAddress, startingDiff, messageSender, protoVer
}
this.validJobs = global.support.circularBuffer(4);
this.sentJobs = global.support.circularBuffer(8);
this.cachedJob = null;
@@ -426,7 +426,7 @@ function Miner(id, login, pass, ipAddress, startingDiff, messageSender, protoVer
Math.floor(this.hashes / (Math.floor((Date.now() - this.connectTime) / 1000))) + " hashes/second or: " +
Math.floor(this.hashes / (Math.floor((Date.now() - this.connectTime) / 1000))) * global.config.pool.targetTime + " difficulty versus: " + this.newDiff);
}
this.messageSender('job', this.getJob());
this.sendNewJob();
};
this.checkBan = function (validShare) {
@@ -532,6 +532,20 @@ function Miner(id, login, pass, ipAddress, startingDiff, messageSender, protoVer
}
return this.cachedJob;
};
this.sendNewJob = function() {
let job = this.getJob();
let tempJob = this.sentJobs.toarray().filter(function (intJob) {
return intJob.id === job.job_id;
})[0];
if (tempJob) {
console.error(`Tried sending a duped job to: ${this.address}, stopped by Snipa!`);
return;
}
this.sentJobs.enq(job);
return this.messageSender('job', job);
};
}
}
@@ -611,7 +625,7 @@ function processShare(miner, job, blockTemplate, params) {
miner.newDiff = miner.difficulty - 1;
miner.incremented = false;
}
miner.messageSender('job', miner.getJob());
miner.sendNewJob();
return false;
}
@@ -629,14 +643,14 @@ function processShare(miner, job, blockTemplate, params) {
console.error(threadName + "Error submitting block at height " + job.height + " from " + miner.logString + ", share type: " + shareType + " error: " + JSON.stringify(rpcResult.error));
recordShareData(miner, job, hashDiff.toString(), false, null, shareType);
// Error on submit, so we'll submit a sanity check for good measure.
templateUpdate(false);
templateUpdate();
} else if (rpcResult) {
//Success! Submitted a block without an issue.
let blockFastHash = global.coinFuncs.getBlockID(shareBuffer).toString('hex');
console.log(threadName + "Block " + blockFastHash.substr(0, 6) + " found at height " + job.height + " by " + miner.logString +
", share type: " + shareType + " - submit result: " + JSON.stringify(rpcResult.result));
recordShareData(miner, job, hashDiff.toString(), true, blockFastHash, shareType, blockTemplate);
templateUpdate(false);
templateUpdate();
} else {
// RPC bombed out massively.
console.error(threadName + "RPC Error. Please check logs for details");
@@ -691,7 +705,7 @@ function handleMinerData(method, params, ip, portData, sendReply, pushMessage) {
return;
}
miner.heartbeat();
sendReply(null, miner.getJob());
miner.sendNewJob();
break;
case 'submit':
if (!miner) {
@@ -758,7 +772,7 @@ function handleMinerData(method, params, ip, portData, sendReply, pushMessage) {
miner.newDiff = miner.difficulty - 1;
miner.incremented = false;
}
miner.messageSender('job', miner.getJob());
miner.sendNewJob();
sendReply('Block expired');
global.database.storeInvalidShare(miner.invalidShareProto);
return;
@@ -841,14 +855,15 @@ if (cluster.isMaster) {
workerList.push(worker);
});
templateUpdate();
setInterval(templateUpdate, 300, true);
global.support.sendEmail(global.config.general.adminEmail, "Pool server " + global.config.hostname + " online", "The pool server: " + global.config.hostname + " with IP: " + global.config.bind_ip + " is online");
} else {
setInterval(checkAliveMiners, 30000);
setInterval(retargetMiners, global.config.pool.retargetTime * 1000);
templateUpdate(false);
templateUpdate();
setInterval(function () {
bannedIPs = [];
templateUpdate(false);
templateUpdate();
}, 60000);
async.each(global.config.ports, function (portData) {
if (global.config[portData.portType].enable !== true) {