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);
if (nTimeInt < job.rpcData.curtime || nTime > submitTime + 7200) {
if (nTimeInt < job.rpcData.curtime || nTimeInt > submitTime + 7200) {
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){
var result =_this.jobManager.processShare(
params.jobId,
client.currentDifficulty,
client.difficulty,
client.extraNonce1,
params.extraNonce2,
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.
* returns boolean
**/
this.sendDifficulty = function(difficulty){
this.sendDifficulty = function(difficulty, sendImmediately){
if (typeof(difficulty) != 'number') {
console.error('[StratumClient.sendDifficulty] given difficulty parameter is not a number: ['+difficulty+']');
return false;
}
if (difficulty !== this.difficulty) {
_this.latestDifficulty = difficulty;
if (difficulty === this.difficulty)
return false;
if (sendImmediately){
_this.pendingDifficulty = null;
_this.difficulty = difficulty;
sendJson({
id : null,
method: "mining.set_difficulty",
params: [difficulty]//[512],
});
return true;
} else {
return false;
}
else{
_this.pendingDifficulty = difficulty;
}
};
this.sendMiningJob = function(jobParams){
if (_this.pendingDifficulty){
_this.sendDifficulty(_this.pendingDifficulty, true);
}
sendJson({
id : null,
method: "mining.notify",
params: jobParams
});
_this.currentDifficulty = _this.latestDifficulty
};
};
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;
lastTs = ts;
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;
}
var sinceLast = ts - lastTs;
@ -97,10 +97,10 @@ var varDiff = module.exports = function varDiff(options, poolDifficulty){
var ddiff;
if (avg > tMax && client.currentDifficulty > options.minDifficulty) {
if (avg > tMax && client.difficulty > options.minDifficulty) {
ddiff = 0.5;
if (ddiff * client.currentDifficulty < options.minDifficulty) {
ddiff = options.minDifficulty / client.currentDifficulty;
if (ddiff * client.difficulty < options.minDifficulty) {
ddiff = options.minDifficulty / client.difficulty;
}
} else if (avg < tMin) {
ddiff = 2;
@ -119,7 +119,7 @@ var varDiff = module.exports = function varDiff(options, poolDifficulty){
return;
}
var newDiff = client.currentDifficulty * ddiff;
var newDiff = client.difficulty * ddiff;
timeBuffer.clear();
//console.log('sending new difficutly ' + newDiff);