Uses pendingDifficulty

This commit is contained in:
Matt 2014-02-19 16:32:38 -07:00
parent 9d8255a620
commit 25df42692c
4 changed files with 21 additions and 13 deletions

View File

@ -181,7 +181,7 @@ var JobManager = module.exports = function JobManager(options){
} }
var nTimeInt = parseInt(nTime, 16); var nTimeInt = parseInt(nTime, 16);
if (nTimeInt < job.rpcData.curtime || nTime > submitTime + 7200) { if (nTimeInt < job.rpcData.curtime || nTimeInt > submitTime + 7200) {
return shareError([20, 'ntime out of range']); return shareError([20, 'ntime out of range']);
} }

View File

@ -284,7 +284,7 @@ var pool = module.exports = function pool(options, authorizeFn){
}).on('submit', function(params, resultCallback){ }).on('submit', function(params, resultCallback){
var result =_this.jobManager.processShare( var result =_this.jobManager.processShare(
params.jobId, params.jobId,
client.currentDifficulty, client.difficulty,
client.extraNonce1, client.extraNonce1,
params.extraNonce2, params.extraNonce2,
params.nTime, params.nTime,

View File

@ -200,33 +200,41 @@ var StratumClient = function(options){
* IF the given difficulty is valid and new it'll send it to the client. * IF the given difficulty is valid and new it'll send it to the client.
* returns boolean * returns boolean
**/ **/
this.sendDifficulty = function(difficulty){ this.sendDifficulty = function(difficulty, sendImmediately){
if (typeof(difficulty) != 'number') { if (typeof(difficulty) != 'number') {
console.error('[StratumClient.sendDifficulty] given difficulty parameter is not a number: ['+difficulty+']'); console.error('[StratumClient.sendDifficulty] given difficulty parameter is not a number: ['+difficulty+']');
return false; return false;
} }
if (difficulty !== this.difficulty) { if (difficulty === this.difficulty)
_this.latestDifficulty = difficulty; return false;
if (sendImmediately){
_this.pendingDifficulty = null;
_this.difficulty = difficulty;
sendJson({ sendJson({
id : null, id : null,
method: "mining.set_difficulty", method: "mining.set_difficulty",
params: [difficulty]//[512], params: [difficulty]//[512],
}); });
return true; return true;
} else { }
return false; else{
_this.pendingDifficulty = difficulty;
} }
}; };
this.sendMiningJob = function(jobParams){ this.sendMiningJob = function(jobParams){
if (_this.pendingDifficulty){
_this.sendDifficulty(_this.pendingDifficulty, true);
}
sendJson({ sendJson({
id : null, id : null,
method: "mining.notify", method: "mining.notify",
params: jobParams params: jobParams
}); });
_this.currentDifficulty = _this.latestDifficulty
}; };
}; };
StratumClient.prototype.__proto__ = events.EventEmitter.prototype; StratumClient.prototype.__proto__ = events.EventEmitter.prototype;

View File

@ -78,7 +78,7 @@ var varDiff = module.exports = function varDiff(options, poolDifficulty){
lastRtc = ts - options.retargetTime / 2; lastRtc = ts - options.retargetTime / 2;
lastTs = ts; lastTs = ts;
timeBuffer = new RingBuffer(bufferSize); timeBuffer = new RingBuffer(bufferSize);
console.log(bufferSize+ ' first time share vardiff curdiff: '+client.currentDifficulty); console.log(bufferSize+ ' first time share vardiff curdiff: '+client.difficulty);
return; return;
} }
var sinceLast = ts - lastTs; var sinceLast = ts - lastTs;
@ -97,10 +97,10 @@ var varDiff = module.exports = function varDiff(options, poolDifficulty){
var ddiff; var ddiff;
if (avg > tMax && client.currentDifficulty > options.minDifficulty) { if (avg > tMax && client.difficulty > options.minDifficulty) {
ddiff = 0.5; ddiff = 0.5;
if (ddiff * client.currentDifficulty < options.minDifficulty) { if (ddiff * client.difficulty < options.minDifficulty) {
ddiff = options.minDifficulty / client.currentDifficulty; ddiff = options.minDifficulty / client.difficulty;
} }
} else if (avg < tMin) { } else if (avg < tMin) {
ddiff = 2; ddiff = 2;
@ -119,7 +119,7 @@ var varDiff = module.exports = function varDiff(options, poolDifficulty){
return; return;
} }
var newDiff = client.currentDifficulty * ddiff; var newDiff = client.difficulty * ddiff;
timeBuffer.clear(); timeBuffer.clear();
//console.log('sending new difficutly ' + newDiff); //console.log('sending new difficutly ' + newDiff);