mirror of
https://github.com/jwinterm/nodejs-pool.git
synced 2026-10-17 05:21:27 +02:00
Update to patch the number of Valid Jobs and to lock in the new code to properly support the proxy.
This commit is contained in:
+48
-38
@@ -23,7 +23,7 @@ let threadName;
|
||||
let minerCount = [];
|
||||
let BlockTemplate = global.coinFuncs.BlockTemplate;
|
||||
let hexMatch = new RegExp("^[0-9a-f]+$");
|
||||
let totalShares=0, trustedShares=0, normalShares=0, invalidShares=0;
|
||||
let totalShares = 0, trustedShares = 0, normalShares = 0, invalidShares = 0;
|
||||
|
||||
|
||||
Buffer.prototype.toByteArray = function () {
|
||||
@@ -33,12 +33,12 @@ Buffer.prototype.toByteArray = function () {
|
||||
|
||||
if (cluster.isMaster) {
|
||||
threadName = "(Master) ";
|
||||
setInterval(function(){
|
||||
setInterval(function () {
|
||||
console.log(`Processed ${trustedShares}/${normalShares}/${invalidShares}/${totalShares} Trusted/Validated/Invalid/Total shares in the last 30 seconds`);
|
||||
totalShares=0;
|
||||
trustedShares=0;
|
||||
normalShares=0;
|
||||
invalidShares=0;
|
||||
totalShares = 0;
|
||||
trustedShares = 0;
|
||||
normalShares = 0;
|
||||
invalidShares = 0;
|
||||
}, 30000);
|
||||
} else {
|
||||
threadName = "(Worker " + cluster.worker.id + " - " + process.pid + ") ";
|
||||
@@ -59,7 +59,7 @@ function registerPool() {
|
||||
[global.config.pool_id, global.config.bind_ip, true, global.config.hostname, true]);
|
||||
global.mysql.query("DELETE FROM ports WHERE pool_id = ?", [global.config.pool_id]).then(function () {
|
||||
global.config.ports.forEach(function (port) {
|
||||
if ('ssl' in port && port['ssl'] === true) {
|
||||
if ('ssl' in port && port.ssl === true) {
|
||||
global.mysql.query("INSERT INTO ports (pool_id, network_port, starting_diff, port_type, description, hidden, ip_address, ssl_port) values (?, ?, ?, ?, ?, ?, ?, 1)",
|
||||
[global.config.pool_id, port.port, port.difficulty, port.portType, port.desc, port.hidden, global.config.bind_ip]);
|
||||
} else {
|
||||
@@ -171,7 +171,7 @@ function templateUpdate(repeating) {
|
||||
newBlockTemplate(rpcResponse);
|
||||
}
|
||||
}
|
||||
if (repeating !== false){
|
||||
if (repeating !== false) {
|
||||
setTimeout(templateUpdate, 300);
|
||||
}
|
||||
}
|
||||
@@ -216,10 +216,10 @@ function Miner(id, login, pass, ipAddress, startingDiff, messageSender, protoVer
|
||||
this.error = "";
|
||||
this.identifier = pass_split[0];
|
||||
this.proxy = false;
|
||||
if (agent && agent.includes('MinerGate')){
|
||||
if (agent && agent.includes('MinerGate')) {
|
||||
this.identifier = "MinerGate";
|
||||
}
|
||||
if (agent && agent.includes('xmr-node-proxy')){
|
||||
if (agent && agent.includes('xmr-node-proxy')) {
|
||||
this.proxy = true;
|
||||
}
|
||||
this.paymentID = null;
|
||||
@@ -248,7 +248,7 @@ function Miner(id, login, pass, ipAddress, startingDiff, messageSender, protoVer
|
||||
this.fixed_diff = false;
|
||||
this.difficulty = startingDiff;
|
||||
this.connectTime = Date.now();
|
||||
if (agent && agent.includes('NiceHash')){
|
||||
if (agent && agent.includes('NiceHash')) {
|
||||
this.fixed_diff = true;
|
||||
this.difficulty = global.coinFuncs.niceHashDiff;
|
||||
}
|
||||
@@ -316,7 +316,7 @@ function Miner(id, login, pass, ipAddress, startingDiff, messageSender, protoVer
|
||||
this.error = "Exchange addresses need payment IDs";
|
||||
this.valid_miner = false;
|
||||
}
|
||||
if (!activeBlockTemplate){
|
||||
if (!activeBlockTemplate) {
|
||||
this.error = "No active block template";
|
||||
this.valid_miner = false;
|
||||
}
|
||||
@@ -347,7 +347,7 @@ function Miner(id, login, pass, ipAddress, startingDiff, messageSender, protoVer
|
||||
};
|
||||
}
|
||||
|
||||
this.validJobs = global.support.circularBuffer(10);
|
||||
this.validJobs = global.support.circularBuffer(4);
|
||||
|
||||
this.cachedJob = null;
|
||||
|
||||
@@ -392,10 +392,10 @@ function Miner(id, login, pass, ipAddress, startingDiff, messageSender, protoVer
|
||||
}
|
||||
};
|
||||
|
||||
this.updateDifficulty = function(){
|
||||
this.updateDifficulty = function () {
|
||||
if (this.hashes > 0) {
|
||||
let newDiff = 0;
|
||||
if (this.proxy){
|
||||
if (this.proxy) {
|
||||
newDiff = Math.floor(Math.floor(this.hashes / (Math.floor((Date.now() - this.connectTime) / 1000))));
|
||||
} else {
|
||||
newDiff = Math.floor(this.hashes / (Math.floor((Date.now() - this.connectTime) / 1000))) * global.config.pool.targetTime;
|
||||
@@ -419,10 +419,10 @@ function Miner(id, login, pass, ipAddress, startingDiff, messageSender, protoVer
|
||||
this.newDiff = global.config.pool.minDifficulty;
|
||||
}
|
||||
debug(threadName + "Difficulty change to: " + this.newDiff + " For: " + this.logString);
|
||||
if (this.hashes > 0){
|
||||
debug(threadName + "Hashes: " + this.hashes + " in: " + Math.floor((Date.now() - this.connectTime)/1000) + " seconds gives: " +
|
||||
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);
|
||||
if (this.hashes > 0) {
|
||||
debug(threadName + "Hashes: " + this.hashes + " in: " + Math.floor((Date.now() - this.connectTime) / 1000) + " seconds gives: " +
|
||||
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());
|
||||
};
|
||||
@@ -468,12 +468,12 @@ function Miner(id, login, pass, ipAddress, startingDiff, messageSender, protoVer
|
||||
return buffReversed.toString('hex');
|
||||
};
|
||||
this.getJob = function () {
|
||||
|
||||
|
||||
if (this.lastBlockHeight === activeBlockTemplate.height && !this.newDiff && this.cachedJob !== null) {
|
||||
return this.cachedJob;
|
||||
}
|
||||
|
||||
if (!this.proxy){
|
||||
if (!this.proxy) {
|
||||
let blob = activeBlockTemplate.nextBlob();
|
||||
let target = this.getTargetHex();
|
||||
this.lastBlockHeight = activeBlockTemplate.height;
|
||||
@@ -573,7 +573,7 @@ function processShare(miner, job, blockTemplate, params) {
|
||||
let nonce = params.nonce;
|
||||
let resultHash = params.result;
|
||||
let template = new Buffer(blockTemplate.buffer.length);
|
||||
if (!miner.proxy){
|
||||
if (!miner.proxy) {
|
||||
blockTemplate.buffer.copy(template);
|
||||
template.writeUInt32BE(job.extraNonce, blockTemplate.reserveOffset);
|
||||
} else {
|
||||
@@ -601,7 +601,7 @@ function processShare(miner, job, blockTemplate, params) {
|
||||
if (hash.toString('hex') !== resultHash) {
|
||||
console.error(threadName + "Bad share from miner " + miner.logString);
|
||||
process.send({type: 'invalidShare'});
|
||||
if (miner.incremented === false){
|
||||
if (miner.incremented === false) {
|
||||
miner.newDiff = miner.difficulty + 1;
|
||||
miner.incremented = true;
|
||||
} else {
|
||||
@@ -713,24 +713,34 @@ function handleMinerData(method, params, ip, portData, sendReply, pushMessage) {
|
||||
global.database.storeInvalidShare(miner.invalidShareProto);
|
||||
return;
|
||||
}
|
||||
|
||||
if (job.submissions.indexOf(params.nonce) !== -1) {
|
||||
console.warn(threadName + 'Duplicate share: ' + JSON.stringify(params) + ' from ' + miner.logString);
|
||||
miner.checkBan(false);
|
||||
sendReply('Duplicate share');
|
||||
global.database.storeInvalidShare(miner.invalidShareProto);
|
||||
return;
|
||||
if (!miner.proxy) {
|
||||
if (job.submissions.indexOf(params.nonce) !== -1) {
|
||||
console.warn(threadName + 'Duplicate share: ' + JSON.stringify(params) + ' from ' + miner.logString);
|
||||
miner.checkBan(false);
|
||||
sendReply('Duplicate share');
|
||||
global.database.storeInvalidShare(miner.invalidShareProto);
|
||||
return;
|
||||
}
|
||||
job.submissions.push(params.nonce);
|
||||
} else {
|
||||
let nonce_test = `${params.nonce}_${params.poolNonce}_${params.workerNonce}`;
|
||||
if (job.submissions.indexOf(nonce_test) !== -1) {
|
||||
console.warn(threadName + 'Duplicate share: ' + JSON.stringify(params) + ' from ' + miner.logString);
|
||||
miner.checkBan(false);
|
||||
sendReply('Duplicate share');
|
||||
global.database.storeInvalidShare(miner.invalidShareProto);
|
||||
return;
|
||||
}
|
||||
job.submissions.push(nonce_test);
|
||||
}
|
||||
|
||||
job.submissions.push(params.nonce);
|
||||
|
||||
let blockTemplate = activeBlockTemplate.height === job.height ? activeBlockTemplate : pastBlockTemplates.toarray().filter(function (t) {
|
||||
return t.height === job.height;
|
||||
})[0];
|
||||
return t.height === job.height;
|
||||
})[0];
|
||||
|
||||
if (!blockTemplate) {
|
||||
console.warn(threadName + 'Block expired, Height: ' + job.height + ' from ' + miner.logString);
|
||||
if (miner.incremented === false){
|
||||
if (miner.incremented === false) {
|
||||
miner.newDiff = miner.difficulty + 1;
|
||||
miner.incremented = true;
|
||||
} else {
|
||||
@@ -820,7 +830,7 @@ if (cluster.isMaster) {
|
||||
workerList.push(worker);
|
||||
});
|
||||
templateUpdate();
|
||||
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");
|
||||
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);
|
||||
@@ -830,7 +840,7 @@ if (cluster.isMaster) {
|
||||
templateUpdate(false);
|
||||
}, 60000);
|
||||
async.each(global.config.ports, function (portData) {
|
||||
if (global.config[portData.portType].enable !== true){
|
||||
if (global.config[portData.portType].enable !== true) {
|
||||
return;
|
||||
}
|
||||
let handleMessage = function (socket, jsonData, pushMessage) {
|
||||
@@ -931,7 +941,7 @@ if (cluster.isMaster) {
|
||||
});
|
||||
}
|
||||
|
||||
if ('ssl' in portData && portData['ssl'] === true) {
|
||||
if ('ssl' in portData && portData.ssl === true) {
|
||||
tls.createServer({
|
||||
key: fs.readFileSync('cert.key'),
|
||||
cert: fs.readFileSync('cert.pem')
|
||||
|
||||
Reference in New Issue
Block a user