vardiff bug fixes
This commit is contained in:
parent
75f7426ee7
commit
1205706ca0
@ -179,6 +179,7 @@ var JobManager = module.exports = function JobManager(options){
|
|||||||
var blockHash;
|
var blockHash;
|
||||||
var blockHex;
|
var blockHex;
|
||||||
|
|
||||||
|
|
||||||
if (job.target.ge(headerBigNum)){
|
if (job.target.ge(headerBigNum)){
|
||||||
blockHex = job.serializeBlock(headerBuffer, coinbaseBuffer).toString('hex');
|
blockHex = job.serializeBlock(headerBuffer, coinbaseBuffer).toString('hex');
|
||||||
blockHash = util.reverseBuffer(util.doublesha(headerBuffer)).toString('hex');
|
blockHash = util.reverseBuffer(util.doublesha(headerBuffer)).toString('hex');
|
||||||
|
|||||||
35
lib/pool.js
35
lib/pool.js
@ -34,13 +34,20 @@ var pool = module.exports = function pool(options, authorizeFn){
|
|||||||
var emitErrorLog = function(key, text) { _this.emit('log', 'error' , key, text); };
|
var emitErrorLog = function(key, text) { _this.emit('log', 'error' , key, text); };
|
||||||
|
|
||||||
(function Init(){
|
(function Init(){
|
||||||
SetupJobManager();
|
//timeout used so onLog event can be hooked before we start initializing
|
||||||
SetupVarDiff();
|
setTimeout(function(){
|
||||||
SetupDaemonInterface();
|
SetupJobManager();
|
||||||
|
SetupVarDiff();
|
||||||
|
SetupDaemonInterface();
|
||||||
|
}, 10);
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
|
||||||
function SetupVarDiff(){
|
function SetupVarDiff(){
|
||||||
|
if (!options.varDiff.enabled){
|
||||||
|
emitLog('system', 'VarDiff has been disabled');
|
||||||
|
return;
|
||||||
|
}
|
||||||
_this.varDiff = new varDiff(options.varDiff, options.difficulty);
|
_this.varDiff = new varDiff(options.varDiff, options.difficulty);
|
||||||
_this.varDiff.on('difficultyRequest', function(){
|
_this.varDiff.on('difficultyRequest', function(){
|
||||||
emitLog('varDiff', 'Difficulty requested for vardiff');
|
emitLog('varDiff', 'Difficulty requested for vardiff');
|
||||||
@ -50,8 +57,10 @@ var pool = module.exports = function pool(options, authorizeFn){
|
|||||||
client.sendDifficulty(newDiff);
|
client.sendDifficulty(newDiff);
|
||||||
client.sendMiningJob(_this.jobManager.currentJob.getJobParams());
|
client.sendMiningJob(_this.jobManager.currentJob.getJobParams());
|
||||||
});
|
});
|
||||||
|
emitLog("system", "VarDiff enabled and setup");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function RequestDifficulty(callback){
|
function RequestDifficulty(callback){
|
||||||
_this.daemon.cmd('getdifficulty',
|
_this.daemon.cmd('getdifficulty',
|
||||||
[],
|
[],
|
||||||
@ -59,7 +68,8 @@ var pool = module.exports = function pool(options, authorizeFn){
|
|||||||
if (error) {
|
if (error) {
|
||||||
emitErrorLog('getdifficulty', 'Error requesting difficulty from daemon for vardiff');
|
emitErrorLog('getdifficulty', 'Error requesting difficulty from daemon for vardiff');
|
||||||
} else {
|
} else {
|
||||||
_this.varDiff.setNetworkDifficulty(result);
|
if (options.varDiff.enabled)
|
||||||
|
_this.varDiff.setNetworkDifficulty(result);
|
||||||
callback(error, result);
|
callback(error, result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -138,7 +148,7 @@ var pool = module.exports = function pool(options, authorizeFn){
|
|||||||
_this.daemon = new daemon.interface(options.daemon);
|
_this.daemon = new daemon.interface(options.daemon);
|
||||||
_this.daemon.on('online', function(){
|
_this.daemon.on('online', function(){
|
||||||
async.parallel({
|
async.parallel({
|
||||||
difficulty: RequestDifficulty,
|
networkDifficulty: RequestDifficulty,
|
||||||
addressInfo: function(callback){
|
addressInfo: function(callback){
|
||||||
_this.daemon.cmd('validateaddress',
|
_this.daemon.cmd('validateaddress',
|
||||||
[options.address],
|
[options.address],
|
||||||
@ -180,6 +190,16 @@ var pool = module.exports = function pool(options, authorizeFn){
|
|||||||
util.script_to_address(results.addressInfo.address) :
|
util.script_to_address(results.addressInfo.address) :
|
||||||
util.script_to_pubkey(results.addressInfo.pubkey);
|
util.script_to_pubkey(results.addressInfo.pubkey);
|
||||||
|
|
||||||
|
if (options.difficulty > results.networkDifficulty && options.difficulty > 16){
|
||||||
|
var newDiff = results.networkDifficulty > 16 ? results.networkDifficulty : 16;
|
||||||
|
emitWarningLog('system', 'pool difficulty was set higher than network difficulty');
|
||||||
|
emitWarningLog('system', 'lowering pool diff from ' + options.difficulty + ' to ' + newDiff);
|
||||||
|
|
||||||
|
options.difficulty = newDiff
|
||||||
|
|
||||||
|
if (options.varDiff.enabled)
|
||||||
|
_this.varDiff.setPoolDifficulty(options.difficulty);
|
||||||
|
}
|
||||||
|
|
||||||
GetBlockTemplate(function(error, result){
|
GetBlockTemplate(function(error, result){
|
||||||
if (error)
|
if (error)
|
||||||
@ -210,7 +230,8 @@ var pool = module.exports = function pool(options, authorizeFn){
|
|||||||
_this.emit('started');
|
_this.emit('started');
|
||||||
}).on('client.connected', function(client){
|
}).on('client.connected', function(client){
|
||||||
|
|
||||||
_this.varDiff.manageClient(client);
|
if (options.varDiff.enabled)
|
||||||
|
_this.varDiff.manageClient(client);
|
||||||
|
|
||||||
client.on('subscription', function(params, resultCallback){
|
client.on('subscription', function(params, resultCallback){
|
||||||
|
|
||||||
@ -268,7 +289,7 @@ var pool = module.exports = function pool(options, authorizeFn){
|
|||||||
});
|
});
|
||||||
|
|
||||||
}, pollingInterval);
|
}, pollingInterval);
|
||||||
emitLog('system', 'Block polling setup for every ' + pollingInterval + ' milliseconds');
|
emitLog('system', 'Block polling every ' + pollingInterval + ' milliseconds');
|
||||||
}
|
}
|
||||||
|
|
||||||
function GetBlockTemplate(callback){
|
function GetBlockTemplate(callback){
|
||||||
|
|||||||
@ -27,10 +27,8 @@ function RingBuffer(maxSize){
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
this.avg = function(){
|
this.avg = function(){
|
||||||
var total = data.reduce(function(a, b){
|
var sum = data.reduce(function(a, b){ return a + b });
|
||||||
return a + b;
|
return sum / (isFull ? maxSize : cursor);
|
||||||
});
|
|
||||||
return total / (isFull ? maxSize : cursor);
|
|
||||||
};
|
};
|
||||||
this.size = function(){
|
this.size = function(){
|
||||||
return isFull ? maxSize : cursor;
|
return isFull ? maxSize : cursor;
|
||||||
@ -47,14 +45,6 @@ var varDiff = module.exports = function varDiff(options, poolDifficulty){
|
|||||||
|
|
||||||
var _this = this;
|
var _this = this;
|
||||||
|
|
||||||
this.setNetworkDifficulty = function(diff){
|
|
||||||
networkDifficulty = diff;
|
|
||||||
};
|
|
||||||
|
|
||||||
if (!options.enabled){
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var networkDifficulty;
|
var networkDifficulty;
|
||||||
var bufferSize = options.retargetTime / options.targetTime * 4;
|
var bufferSize = options.retargetTime / options.targetTime * 4;
|
||||||
var variance = options.targetTime * (options.variancePercent / 100);
|
var variance = options.targetTime * (options.variancePercent / 100);
|
||||||
@ -62,11 +52,19 @@ var varDiff = module.exports = function varDiff(options, poolDifficulty){
|
|||||||
var tMax = options.targetTime + variance;
|
var tMax = options.targetTime + variance;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
setInterval(function(){
|
setInterval(function(){
|
||||||
_this.emit('difficultyRequest');
|
_this.emit('difficultyRequest');
|
||||||
}, options.daemonDiffUpdateFrequency * 1000);
|
}, options.daemonDiffUpdateFrequency * 1000);
|
||||||
|
|
||||||
|
|
||||||
|
this.setNetworkDifficulty = function(diff){
|
||||||
|
networkDifficulty = diff;
|
||||||
|
};
|
||||||
|
this.setPoolDifficulty = function(diff){
|
||||||
|
poolDifficulty = diff;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
this.manageClient = function(client){
|
this.manageClient = function(client){
|
||||||
var lastTs;
|
var lastTs;
|
||||||
var lastRtc;
|
var lastRtc;
|
||||||
@ -80,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('first time share vardiff');
|
//console.log('first time share vardiff');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,7 +86,7 @@ var varDiff = module.exports = function varDiff(options, poolDifficulty){
|
|||||||
lastTs = ts;
|
lastTs = ts;
|
||||||
|
|
||||||
if ((ts - lastRtc) < options.retargetTime && timeBuffer.size() > 0){
|
if ((ts - lastRtc) < options.retargetTime && timeBuffer.size() > 0){
|
||||||
console.log('do not retarget');
|
//console.log('do not retarget');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,10 +99,14 @@ var varDiff = module.exports = function varDiff(options, poolDifficulty){
|
|||||||
var ddiff = (client.difficulty * (options.targetTime / avg)) - client.difficulty;
|
var ddiff = (client.difficulty * (options.targetTime / avg)) - client.difficulty;
|
||||||
|
|
||||||
if (avg > tMax && client.difficulty > options.minDifficulty){
|
if (avg > tMax && client.difficulty > options.minDifficulty){
|
||||||
if (ddiff > -1)
|
|
||||||
|
if (ddiff > -1){
|
||||||
ddiff = -1;
|
ddiff = -1;
|
||||||
|
}
|
||||||
if (ddiff + client.difficulty < poolDifficulty)
|
if (ddiff + client.difficulty < poolDifficulty)
|
||||||
ddiff = options.minDifficulty - client.difficulty;
|
ddiff = options.minDifficulty - client.difficulty;
|
||||||
|
|
||||||
|
//console.log('decreasing difficulty, ddiff: ' + ddiff);
|
||||||
}
|
}
|
||||||
else if (avg < tMin){
|
else if (avg < tMin){
|
||||||
if (ddiff < 1)
|
if (ddiff < 1)
|
||||||
@ -112,16 +114,18 @@ var varDiff = module.exports = function varDiff(options, poolDifficulty){
|
|||||||
var diffMax = networkDifficulty < options.maxDifficulty ? networkDifficulty : options.maxDifficulty;
|
var diffMax = networkDifficulty < options.maxDifficulty ? networkDifficulty : options.maxDifficulty;
|
||||||
if (ddiff + client.difficulty > diffMax)
|
if (ddiff + client.difficulty > diffMax)
|
||||||
ddiff = diffMax - client.difficulty;
|
ddiff = diffMax - client.difficulty;
|
||||||
|
|
||||||
|
//console.log('increasing difficulty, ddiff: ' + ddiff);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
console.log('hashrate in range ' + JSON.stringify({ddiff: ddiff, avg: avg}) );
|
//console.log('hashrate in range ' + JSON.stringify({ddiff: ddiff, avg: avg}) );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var newDiff = client.difficulty * ddiff;
|
var newDiff = client.difficulty * ddiff;
|
||||||
timeBuffer.clear();
|
timeBuffer.clear();
|
||||||
|
|
||||||
console.log('sending new difficutly ' + newDiff);
|
//console.log('sending new difficutly ' + newDiff);
|
||||||
|
|
||||||
_this.emit('newDifficulty', client, newDiff);
|
_this.emit('newDifficulty', client, newDiff);
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "stratum-pool",
|
"name": "stratum-pool",
|
||||||
"version": "0.0.2",
|
"version": "0.0.3",
|
||||||
"author": "Matthew Little",
|
"author": "Matthew Little",
|
||||||
"description": "High performance Stratum poolserver in Node.js",
|
"description": "High performance Stratum poolserver in Node.js",
|
||||||
"contributors": [
|
"contributors": [
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user