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:
+47
-37
@@ -23,7 +23,7 @@ let threadName;
|
|||||||
let minerCount = [];
|
let minerCount = [];
|
||||||
let BlockTemplate = global.coinFuncs.BlockTemplate;
|
let BlockTemplate = global.coinFuncs.BlockTemplate;
|
||||||
let hexMatch = new RegExp("^[0-9a-f]+$");
|
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 () {
|
Buffer.prototype.toByteArray = function () {
|
||||||
@@ -33,12 +33,12 @@ Buffer.prototype.toByteArray = function () {
|
|||||||
|
|
||||||
if (cluster.isMaster) {
|
if (cluster.isMaster) {
|
||||||
threadName = "(Master) ";
|
threadName = "(Master) ";
|
||||||
setInterval(function(){
|
setInterval(function () {
|
||||||
console.log(`Processed ${trustedShares}/${normalShares}/${invalidShares}/${totalShares} Trusted/Validated/Invalid/Total shares in the last 30 seconds`);
|
console.log(`Processed ${trustedShares}/${normalShares}/${invalidShares}/${totalShares} Trusted/Validated/Invalid/Total shares in the last 30 seconds`);
|
||||||
totalShares=0;
|
totalShares = 0;
|
||||||
trustedShares=0;
|
trustedShares = 0;
|
||||||
normalShares=0;
|
normalShares = 0;
|
||||||
invalidShares=0;
|
invalidShares = 0;
|
||||||
}, 30000);
|
}, 30000);
|
||||||
} else {
|
} else {
|
||||||
threadName = "(Worker " + cluster.worker.id + " - " + process.pid + ") ";
|
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.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.mysql.query("DELETE FROM ports WHERE pool_id = ?", [global.config.pool_id]).then(function () {
|
||||||
global.config.ports.forEach(function (port) {
|
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.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]);
|
[global.config.pool_id, port.port, port.difficulty, port.portType, port.desc, port.hidden, global.config.bind_ip]);
|
||||||
} else {
|
} else {
|
||||||
@@ -171,7 +171,7 @@ function templateUpdate(repeating) {
|
|||||||
newBlockTemplate(rpcResponse);
|
newBlockTemplate(rpcResponse);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (repeating !== false){
|
if (repeating !== false) {
|
||||||
setTimeout(templateUpdate, 300);
|
setTimeout(templateUpdate, 300);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -216,10 +216,10 @@ function Miner(id, login, pass, ipAddress, startingDiff, messageSender, protoVer
|
|||||||
this.error = "";
|
this.error = "";
|
||||||
this.identifier = pass_split[0];
|
this.identifier = pass_split[0];
|
||||||
this.proxy = false;
|
this.proxy = false;
|
||||||
if (agent && agent.includes('MinerGate')){
|
if (agent && agent.includes('MinerGate')) {
|
||||||
this.identifier = "MinerGate";
|
this.identifier = "MinerGate";
|
||||||
}
|
}
|
||||||
if (agent && agent.includes('xmr-node-proxy')){
|
if (agent && agent.includes('xmr-node-proxy')) {
|
||||||
this.proxy = true;
|
this.proxy = true;
|
||||||
}
|
}
|
||||||
this.paymentID = null;
|
this.paymentID = null;
|
||||||
@@ -248,7 +248,7 @@ function Miner(id, login, pass, ipAddress, startingDiff, messageSender, protoVer
|
|||||||
this.fixed_diff = false;
|
this.fixed_diff = false;
|
||||||
this.difficulty = startingDiff;
|
this.difficulty = startingDiff;
|
||||||
this.connectTime = Date.now();
|
this.connectTime = Date.now();
|
||||||
if (agent && agent.includes('NiceHash')){
|
if (agent && agent.includes('NiceHash')) {
|
||||||
this.fixed_diff = true;
|
this.fixed_diff = true;
|
||||||
this.difficulty = global.coinFuncs.niceHashDiff;
|
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.error = "Exchange addresses need payment IDs";
|
||||||
this.valid_miner = false;
|
this.valid_miner = false;
|
||||||
}
|
}
|
||||||
if (!activeBlockTemplate){
|
if (!activeBlockTemplate) {
|
||||||
this.error = "No active block template";
|
this.error = "No active block template";
|
||||||
this.valid_miner = false;
|
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;
|
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) {
|
if (this.hashes > 0) {
|
||||||
let newDiff = 0;
|
let newDiff = 0;
|
||||||
if (this.proxy){
|
if (this.proxy) {
|
||||||
newDiff = Math.floor(Math.floor(this.hashes / (Math.floor((Date.now() - this.connectTime) / 1000))));
|
newDiff = Math.floor(Math.floor(this.hashes / (Math.floor((Date.now() - this.connectTime) / 1000))));
|
||||||
} else {
|
} else {
|
||||||
newDiff = Math.floor(this.hashes / (Math.floor((Date.now() - this.connectTime) / 1000))) * global.config.pool.targetTime;
|
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;
|
this.newDiff = global.config.pool.minDifficulty;
|
||||||
}
|
}
|
||||||
debug(threadName + "Difficulty change to: " + this.newDiff + " For: " + this.logString);
|
debug(threadName + "Difficulty change to: " + this.newDiff + " For: " + this.logString);
|
||||||
if (this.hashes > 0){
|
if (this.hashes > 0) {
|
||||||
debug(threadName + "Hashes: " + this.hashes + " in: " + Math.floor((Date.now() - this.connectTime)/1000) + " seconds gives: " +
|
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))) + " hashes/second or: " +
|
||||||
Math.floor(this.hashes/(Math.floor((Date.now() - this.connectTime)/1000))) * global.config.pool.targetTime + " difficulty versus: " + this.newDiff);
|
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.messageSender('job', this.getJob());
|
||||||
};
|
};
|
||||||
@@ -473,7 +473,7 @@ function Miner(id, login, pass, ipAddress, startingDiff, messageSender, protoVer
|
|||||||
return this.cachedJob;
|
return this.cachedJob;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.proxy){
|
if (!this.proxy) {
|
||||||
let blob = activeBlockTemplate.nextBlob();
|
let blob = activeBlockTemplate.nextBlob();
|
||||||
let target = this.getTargetHex();
|
let target = this.getTargetHex();
|
||||||
this.lastBlockHeight = activeBlockTemplate.height;
|
this.lastBlockHeight = activeBlockTemplate.height;
|
||||||
@@ -573,7 +573,7 @@ function processShare(miner, job, blockTemplate, params) {
|
|||||||
let nonce = params.nonce;
|
let nonce = params.nonce;
|
||||||
let resultHash = params.result;
|
let resultHash = params.result;
|
||||||
let template = new Buffer(blockTemplate.buffer.length);
|
let template = new Buffer(blockTemplate.buffer.length);
|
||||||
if (!miner.proxy){
|
if (!miner.proxy) {
|
||||||
blockTemplate.buffer.copy(template);
|
blockTemplate.buffer.copy(template);
|
||||||
template.writeUInt32BE(job.extraNonce, blockTemplate.reserveOffset);
|
template.writeUInt32BE(job.extraNonce, blockTemplate.reserveOffset);
|
||||||
} else {
|
} else {
|
||||||
@@ -601,7 +601,7 @@ function processShare(miner, job, blockTemplate, params) {
|
|||||||
if (hash.toString('hex') !== resultHash) {
|
if (hash.toString('hex') !== resultHash) {
|
||||||
console.error(threadName + "Bad share from miner " + miner.logString);
|
console.error(threadName + "Bad share from miner " + miner.logString);
|
||||||
process.send({type: 'invalidShare'});
|
process.send({type: 'invalidShare'});
|
||||||
if (miner.incremented === false){
|
if (miner.incremented === false) {
|
||||||
miner.newDiff = miner.difficulty + 1;
|
miner.newDiff = miner.difficulty + 1;
|
||||||
miner.incremented = true;
|
miner.incremented = true;
|
||||||
} else {
|
} else {
|
||||||
@@ -713,24 +713,34 @@ function handleMinerData(method, params, ip, portData, sendReply, pushMessage) {
|
|||||||
global.database.storeInvalidShare(miner.invalidShareProto);
|
global.database.storeInvalidShare(miner.invalidShareProto);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (!miner.proxy) {
|
||||||
if (job.submissions.indexOf(params.nonce) !== -1) {
|
if (job.submissions.indexOf(params.nonce) !== -1) {
|
||||||
console.warn(threadName + 'Duplicate share: ' + JSON.stringify(params) + ' from ' + miner.logString);
|
console.warn(threadName + 'Duplicate share: ' + JSON.stringify(params) + ' from ' + miner.logString);
|
||||||
miner.checkBan(false);
|
miner.checkBan(false);
|
||||||
sendReply('Duplicate share');
|
sendReply('Duplicate share');
|
||||||
global.database.storeInvalidShare(miner.invalidShareProto);
|
global.database.storeInvalidShare(miner.invalidShareProto);
|
||||||
return;
|
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) {
|
let blockTemplate = activeBlockTemplate.height === job.height ? activeBlockTemplate : pastBlockTemplates.toarray().filter(function (t) {
|
||||||
return t.height === job.height;
|
return t.height === job.height;
|
||||||
})[0];
|
})[0];
|
||||||
|
|
||||||
if (!blockTemplate) {
|
if (!blockTemplate) {
|
||||||
console.warn(threadName + 'Block expired, Height: ' + job.height + ' from ' + miner.logString);
|
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.newDiff = miner.difficulty + 1;
|
||||||
miner.incremented = true;
|
miner.incremented = true;
|
||||||
} else {
|
} else {
|
||||||
@@ -820,7 +830,7 @@ if (cluster.isMaster) {
|
|||||||
workerList.push(worker);
|
workerList.push(worker);
|
||||||
});
|
});
|
||||||
templateUpdate();
|
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 {
|
} else {
|
||||||
setInterval(checkAliveMiners, 30000);
|
setInterval(checkAliveMiners, 30000);
|
||||||
setInterval(retargetMiners, global.config.pool.retargetTime * 1000);
|
setInterval(retargetMiners, global.config.pool.retargetTime * 1000);
|
||||||
@@ -830,7 +840,7 @@ if (cluster.isMaster) {
|
|||||||
templateUpdate(false);
|
templateUpdate(false);
|
||||||
}, 60000);
|
}, 60000);
|
||||||
async.each(global.config.ports, function (portData) {
|
async.each(global.config.ports, function (portData) {
|
||||||
if (global.config[portData.portType].enable !== true){
|
if (global.config[portData.portType].enable !== true) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let handleMessage = function (socket, jsonData, pushMessage) {
|
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({
|
tls.createServer({
|
||||||
key: fs.readFileSync('cert.key'),
|
key: fs.readFileSync('cert.key'),
|
||||||
cert: fs.readFileSync('cert.pem')
|
cert: fs.readFileSync('cert.pem')
|
||||||
|
|||||||
Reference in New Issue
Block a user