Fixed getdifficulty request to rpc
Fixed vardiff (currently not taking into account daemon difficulty since it looks like it's non-sense)
This commit is contained in:
parent
700160fdb9
commit
3054616736
@ -16,10 +16,10 @@ var blockTemplate = require('./blockTemplate.js');
|
||||
var ExtraNonceCounter = function(){
|
||||
var instanceId = 31;
|
||||
var counter = instanceId << 27;
|
||||
var size = util.packUInt32BE(Math.abs(counter)).length;
|
||||
var size = util.packUInt32BE(counter).length; //binpack.packUInt32(counter, 'big').length;
|
||||
|
||||
this.next = function(){
|
||||
var extraNonce = util.packUInt32BE(Math.abs(counter++));
|
||||
var extraNonce = util.packUInt32BE(counter++);//binpack.packUInt32(counter++, 'big');
|
||||
return extraNonce.toString('hex');
|
||||
};
|
||||
this.size = function(){
|
||||
|
||||
@ -59,14 +59,14 @@ var pool = module.exports = function pool(options, authorizeFn){
|
||||
|
||||
|
||||
function RequestDifficulty(callback){
|
||||
_this.daemon.cmd('getdifficulty',
|
||||
_this.daemon.cmd('getmininginfo',
|
||||
[],
|
||||
function(error, result){
|
||||
if (error) {
|
||||
emitErrorLog('getdifficulty', 'Error requesting difficulty from daemon for vardiff');
|
||||
} else {
|
||||
if (options.varDiff.enabled)
|
||||
_this.varDiff.setNetworkDifficulty(result);
|
||||
_this.varDiff.setNetworkDifficulty(result.difficulty);
|
||||
callback(error, result);
|
||||
}
|
||||
}
|
||||
|
||||
@ -42,7 +42,7 @@ function RingBuffer(maxSize){
|
||||
|
||||
|
||||
var varDiff = module.exports = function varDiff(options, poolDifficulty){
|
||||
|
||||
console.log(options);
|
||||
var _this = this;
|
||||
|
||||
var networkDifficulty;
|
||||
@ -72,53 +72,50 @@ var varDiff = module.exports = function varDiff(options, poolDifficulty){
|
||||
|
||||
client.on('submit', function(){
|
||||
|
||||
var ts = Date.now() / 1000;
|
||||
var ts = (Date.now() / 1000) | 0;
|
||||
|
||||
if (!lastRtc){
|
||||
lastRtc = ts - options.retargetTime / 2;
|
||||
lastTs = ts;
|
||||
timeBuffer = new RingBuffer(bufferSize);
|
||||
//console.log('first time share vardiff');
|
||||
console.log(bufferSize+ ' first time share vardiff curdiff: '+client.difficulty);
|
||||
return;
|
||||
}
|
||||
var sinceLast = ts - lastTs;
|
||||
|
||||
timeBuffer.append(ts - lastTs);
|
||||
timeBuffer.append(sinceLast);
|
||||
lastTs = ts;
|
||||
|
||||
if ((ts - lastRtc) < options.retargetTime && timeBuffer.size() > 0){
|
||||
//console.log('do not retarget');
|
||||
console.log('do not retarget');
|
||||
return;
|
||||
}
|
||||
|
||||
lastRtc = ts;
|
||||
var avg = timeBuffer.avg();
|
||||
|
||||
if (avg < 1)
|
||||
avg = 1;
|
||||
|
||||
var ddiff = (client.difficulty * (options.targetTime / avg)) - client.difficulty;
|
||||
var ddiff;
|
||||
|
||||
if (avg > tMax && client.difficulty > options.minDifficulty){
|
||||
|
||||
if (ddiff > -1){
|
||||
ddiff = -1;
|
||||
if (avg > tMax && client.difficulty > options.minDifficulty) {
|
||||
ddiff = 0.5;
|
||||
if (ddiff * client.difficulty < options.minDifficulty) {
|
||||
ddiff = options.minDifficulty / client.difficulty;
|
||||
}
|
||||
if (ddiff + client.difficulty < poolDifficulty)
|
||||
ddiff = options.minDifficulty - client.difficulty;
|
||||
} else if (avg < tMin) {
|
||||
ddiff = 2;
|
||||
|
||||
//console.log('decreasing difficulty, ddiff: ' + ddiff);
|
||||
}
|
||||
else if (avg < tMin){
|
||||
if (ddiff < 1)
|
||||
ddiff = 1;
|
||||
var diffMax = networkDifficulty < options.maxDifficulty ? networkDifficulty : options.maxDifficulty;
|
||||
if (ddiff + client.difficulty > diffMax)
|
||||
ddiff = diffMax - client.difficulty;
|
||||
var diffMax = options.maxDifficulty;
|
||||
console.log("Max & network", diffMax, networkDifficulty);
|
||||
if (ddiff * client.difficulty > diffMax) {
|
||||
ddiff = diffMax / client.difficulty;
|
||||
}
|
||||
|
||||
//console.log('increasing difficulty, ddiff: ' + ddiff);
|
||||
console.log('increasing difficulty, ddiff: ' + ddiff);
|
||||
}
|
||||
else{
|
||||
//console.log('hashrate in range ' + JSON.stringify({ddiff: ddiff, avg: avg}) );
|
||||
console.log('hashrate in range ' + JSON.stringify({ddiff: ddiff, avg: avg}) );
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user