From 244d3a406d53f0d7b6dc8d946337867162074fda Mon Sep 17 00:00:00 2001 From: Matt Date: Sun, 30 Mar 2014 17:03:23 -0600 Subject: [PATCH] 1) Updated x11 to more accurate diff. 2) Low diff shares report percent off now - to detect if diff is too hard or you just have abusing miners. 3) Only 1 thread does the rpc calls to generate blockchain sync status --- lib/algoProperties.js | 38 +++++++++++++++++++++++++------------- lib/daemon.js | 2 +- lib/jobManager.js | 3 ++- lib/pool.js | 12 ++++++------ 4 files changed, 34 insertions(+), 21 deletions(-) diff --git a/lib/algoProperties.js b/lib/algoProperties.js index 2c0f811..d40f287 100644 --- a/lib/algoProperties.js +++ b/lib/algoProperties.js @@ -1,11 +1,6 @@ -var bignum = require('bignum'); - var multiHashing = require('multi-hashing'); var util = require('./util.js'); -var maxInt256 = global.maxDiff = bignum('ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', 16); - - var algos = module.exports = global.algos = { sha256: { @@ -38,7 +33,7 @@ var algos = module.exports = global.algos = { }, x11: { shift: 20, - multiplier: Math.pow(2, 30), + multiplier: Math.pow(2, 32.3), hash: function(){ return multiHashing.x11.apply(this, arguments); } @@ -66,7 +61,7 @@ var algos = module.exports = global.algos = { shift: 24, multiplier: Math.pow(2, 8), hash: function(){ - return multiHashing.bcrypt.apply(this, arguments); + return multiHashing.keccak.apply(this, arguments); } }, blake: { @@ -95,24 +90,41 @@ var algos = module.exports = global.algos = { } }; +//Creates a non-truncated max difficulty (diff1) by bitwise right-shifting the max value of a uint256 function ShiftMax256Right(shiftRight){ + + //Max value uint256 (an array of ones representing 256 enabled bits) var arr256 = Array.apply(null, new Array(256)).map(Number.prototype.valueOf, 1); + + //An array of zero bits for how far the max uint256 is shifted right var arrLeft = Array.apply(null, new Array(shiftRight)).map(Number.prototype.valueOf, 0); - var preShift = arrLeft.concat(arr256); - var trimmed = preShift.slice(0, 256); + + //Add zero bits to uint256 and remove the bits shifted out + arr256 = arrLeft.concat(arr256).slice(0, 256); + + //An array of bytes to convert the bits to, 8 bits in a byte so length will be 32 var octets = []; + for (var i = 0; i < 32; i++){ + octets[i] = 0; - var bits = trimmed.slice(i * 8, i * 8 + 8); + + //The 8 bits for this byte + var bits = arr256.slice(i * 8, i * 8 + 8); + + //Bit math to add the bits into a byte for (var f = 0; f < bits.length; f++){ var multiplier = Math.pow(2, f); octets[i] += bits[f] * multiplier; } + } - var buff = new Buffer(octets); - return buff; + + //return in form of buffer + return new Buffer(octets);; } for (var algo in algos){ - algos[algo].diff = ShiftMax256Right(algos[algo].shift); + if (!algos[algo].diff) + algos[algo].diff = ShiftMax256Right(algos[algo].shift); } \ No newline at end of file diff --git a/lib/daemon.js b/lib/daemon.js index 9646aa4..621e355 100644 --- a/lib/daemon.js +++ b/lib/daemon.js @@ -31,7 +31,7 @@ function DaemonInterface(options){ if (online) _this.emit('online'); }); - }; + } function isOnline(callback){ cmd('getinfo', [], function(results){ diff --git a/lib/jobManager.js b/lib/jobManager.js index 114e0f3..ff3383e 100644 --- a/lib/jobManager.js +++ b/lib/jobManager.js @@ -188,7 +188,8 @@ var JobManager = module.exports = function JobManager(maxDifficulty, hashDigest, else { var targetUser = maxDifficulty.div(difficulty); if (headerBigNum.gt(targetUser)){ - return shareError([23, 'low difficulty share']); + var lowPercent = targetUser.div(headerBigNum).mul(100).toNumber().toFixed(2); + return shareError([23, 'low difficulty share, need to be ' + lowPercent + ' higher']); } } if (!!blockHex) { diff --git a/lib/pool.js b/lib/pool.js index 02c2b26..b96ff00 100644 --- a/lib/pool.js +++ b/lib/pool.js @@ -142,7 +142,10 @@ var pool = module.exports = function pool(options, authorizeFn){ else{ if (displayNotSynced) displayNotSynced(); setTimeout(checkSynced, 5000); - generateProgress(); + + //Only let the first fork show synced status or the log wil look flooded with it + if (!process.env.forkId || process.env.forkId === '0') + generateProgress(); } }); @@ -166,14 +169,11 @@ var pool = module.exports = function pool(options, authorizeFn){ var peers = results[0].response; var totalBlocks = peers.sort(function(a, b){ - return a.startingheight - b.startingheight; + return b.startingheight - a.startingheight; })[0].startingheight; var percent = (blockCount / totalBlocks * 100).toFixed(2); - - //Only let the first fork show synced status or the log wil look flooded with it - if (!process.env.forkId || process.env.forkId === '0') - emitWarningLog('Downloaded ' + percent + '% of blockchain from ' + peers.length + ' peers'); + emitWarningLog('Downloaded ' + percent + '% of blockchain from ' + peers.length + ' peers'); }); });