Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
64d832e1a2
|
@ -40,6 +40,10 @@ function RingBuffer(maxSize){
|
|||
};
|
||||
}
|
||||
|
||||
// Truncate a number to a fixed amount of decimal places
|
||||
function toFixed(num, len) {
|
||||
return parseFloat(num.toFixed(len));
|
||||
}
|
||||
|
||||
var varDiff = module.exports = function varDiff(port, varDiffOptions){
|
||||
var _this = this;
|
||||
|
@ -96,16 +100,19 @@ var varDiff = module.exports = function varDiff(port, varDiffOptions){
|
|||
|
||||
lastRtc = ts;
|
||||
var avg = timeBuffer.avg();
|
||||
var ddiff;
|
||||
var ddiff = options.targetTime / avg;
|
||||
|
||||
if (avg > tMax && client.difficulty > options.minDiff) {
|
||||
ddiff = 0.5;
|
||||
if (options.x2mode) {
|
||||
ddiff = 0.5;
|
||||
}
|
||||
if (ddiff * client.difficulty < options.minDiff) {
|
||||
ddiff = options.minDiff / client.difficulty;
|
||||
}
|
||||
} else if (avg < tMin) {
|
||||
ddiff = 2;
|
||||
|
||||
if (options.x2mode) {
|
||||
ddiff = 2;
|
||||
}
|
||||
//var diffMax = networkDifficulty < options.maxDiff ? networkDifficulty : options.maxDiff;
|
||||
var diffMax = options.maxDiff;
|
||||
if (ddiff * client.difficulty > diffMax) {
|
||||
|
@ -116,7 +123,7 @@ var varDiff = module.exports = function varDiff(port, varDiffOptions){
|
|||
return;
|
||||
}
|
||||
|
||||
var newDiff = client.difficulty * ddiff;
|
||||
var newDiff = toFixed(client.difficulty * ddiff, 8);
|
||||
timeBuffer.clear();
|
||||
_this.emit('newDifficulty', client, newDiff);
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue