Accept low shares within a threshold - not finished

This commit is contained in:
Matt 2014-04-03 12:31:48 -06:00
parent b77398c5e2
commit d8abc4008d
4 changed files with 28 additions and 17 deletions

View File

@ -169,7 +169,6 @@ function ShiftMax256Right(shiftRight){
} }
//return in form of buffer
return new Buffer(octets);; return new Buffer(octets);;
} }
@ -202,8 +201,6 @@ function ConvertBitsToBuff(bitsBuff){
buff256.fill(0); buff256.fill(0);
resultBuff.copy(buff256, buff256.length - resultBuff.length); resultBuff.copy(buff256, buff256.length - resultBuff.length);
//var hexResult = buff256.toString('hex');
//return hexResult;
return buff256; return buff256;
} }
@ -216,5 +213,6 @@ for (var algo in algos){
algos[algo].bits = compactBits; algos[algo].bits = compactBits;
algos[algo].diff = truncatedDiff; algos[algo].diff = truncatedDiff;
algos[algo].nonTruncatedDiff = nonTruncatedDiff; algos[algo].nonTruncatedDiff = nonTruncatedDiff;
algos[algo].diff = nonTruncatedDiff;
} }
} }

View File

@ -182,7 +182,7 @@ var JobManager = module.exports = function JobManager(maxDifficulty, hashDigest,
var blockHash; var blockHash;
var blockHex; var blockHex;
var shareDiff = maxDifficulty.div(headerBigNum).toString();
if (job.target.ge(headerBigNum)){ if (job.target.ge(headerBigNum)){
blockHex = job.serializeBlock(headerBuffer, coinbaseBuffer).toString('hex'); blockHex = job.serializeBlock(headerBuffer, coinbaseBuffer).toString('hex');
@ -199,9 +199,15 @@ var JobManager = module.exports = function JobManager(maxDifficulty, hashDigest,
difficulty = previousDifficulty; difficulty = previousDifficulty;
} }
else{ else{
var shareDiff = maxDifficulty.div(headerBigNum).toString(); var offPercent = targetUser.div(headerBigNum).toNumber() * 100;
if (offPercent > options.shareVariancePercent){
return shareError([23, 'low difficulty share of ' + shareDiff]); return shareError([23, 'low difficulty share of ' + shareDiff]);
} }
else{
_this.emit('log', 'warning', 'Share accepted a low diff ' + shareDiff + ' off by ' + (100 - offPercent).toFixed(2) + '%');
}
}
} }
} }
@ -212,6 +218,7 @@ var JobManager = module.exports = function JobManager(maxDifficulty, hashDigest,
ip: ipAddress, ip: ipAddress,
worker: workerName, worker: workerName,
difficulty: difficulty, difficulty: difficulty,
shareDiff: shareDiff,
height: job.rpcData.height, height: job.rpcData.height,
reward: job.rpcData.coinbasevalue, reward: job.rpcData.coinbasevalue,
networkDifficulty : job.difficulty.toString(), networkDifficulty : job.difficulty.toString(),

View File

@ -296,6 +296,8 @@ var pool = module.exports = function pool(options, authorizeFn){
}); });
}); });
} }
}).on('log', function(severity, message){
_this.emit('log', severity, message);
}).on('debugBlockShare', function(debugData) { }).on('debugBlockShare', function(debugData) {
//emitLog(JSON.stringify(debugData)); //emitLog(JSON.stringify(debugData));
}); });
@ -559,20 +561,21 @@ var pool = module.exports = function pool(options, authorizeFn){
params.extraNonce2, params.extraNonce2,
params.nTime, params.nTime,
params.nonce, params.nonce,
client.socket.remoteAddress, client.remoteAddress,
params.name params.name
); );
resultCallback(result.error, result.result ? true : null); resultCallback(result.error, result.result ? true : null);
}).on('malformedMessage', function (message) { }).on('malformedMessage', function (message) {
emitWarningLog((client.workerName || ('Unauthorized miner [' + client.socket.remoteAddress + ']')) + " has sent us a malformed message: " + message); emitWarningLog((client.workerName || ('Unauthorized miner [' + client.remoteAddress + ']')) + " has sent us a malformed message: " + message);
}).on('socketError', function(err) { }).on('socketError', function(err) {
emitWarningLog(client.workerName + " has somehow had a socket error: " + JSON.stringify(err)); emitWarningLog(client.workerName + " has somehow had a socket error: " + JSON.stringify(err));
}).on('socketDisconnect', function(){ }).on('socketDisconnect', function(){
emitLog("Client '" + client.workerName + "' disconnected!"); var clientTitle = client.workerName ? ("'" + client.workerName + '"') : '(unauthorized)';
emitLog("Client " + clientTitle + ' [' + client.remoteAddress + "] disconnected");
}).on('unknownStratumMethod', function(fullMessage) { }).on('unknownStratumMethod', function(fullMessage) {
emitLog("Client '" + client.workerName + "' has sent us an unknown stratum method: " + fullMessage.method); emitLog("Client '" + client.workerName + "' has sent us an unknown stratum method: " + fullMessage.method);

View File

@ -28,6 +28,8 @@ var StratumClient = function(options){
//private members //private members
this.socket = options.socket; this.socket = options.socket;
this.remoteAddress = options.remoteAddress;
var banning = options.banning; var banning = options.banning;
var _this = this; var _this = this;
@ -219,7 +221,7 @@ var StratumClient = function(options){
}); });
socket.on('error', function(err){ socket.on('error', function(err){
if (err.code === 'ECONNRESET') if (err.code === 'ECONNRESET')
_this.emit('socketDisconnect') _this.emit('socketDisconnect');
else else
_this.emit('socketError', err); _this.emit('socketError', err);
}); });
@ -332,7 +334,8 @@ var StratumServer = exports.Server = function StratumServer(ports, connectionTim
socket: socket, socket: socket,
authorizeFn: authorizeFn, authorizeFn: authorizeFn,
banning: banning, banning: banning,
socketTimeout : socketTimeout socketTimeout: socketTimeout,
remoteAddress: socket.remoteAddress
} }
); );
stratumClients[subscriptionId] = client; stratumClients[subscriptionId] = client;