From 69feb04da125c60563103fc95484188c20ed2737 Mon Sep 17 00:00:00 2001 From: Matthew Little Date: Fri, 21 Feb 2014 23:09:02 -0700 Subject: [PATCH] Convert diff dividend to bignum only on init. --- lib/jobManager.js | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/lib/jobManager.js b/lib/jobManager.js index 5a27be9..9e692fb 100644 --- a/lib/jobManager.js +++ b/lib/jobManager.js @@ -55,7 +55,7 @@ var JobManager = module.exports = function JobManager(options){ var _this = this; var jobCounter = new JobCounter(); - //var jobs = {}; + /** * It only checks if the blockTemplate is already in our jobs list. @@ -70,20 +70,11 @@ var JobManager = module.exports = function JobManager(options){ } else { return false; } - - /*var newBlock = true; - for(var job in jobs){ - if (jobs[job].rpcData.previousblockhash === prevBlockHash) { - newBlock = false; - } - } - return newBlock;*/ - } //Which number to use as dividend when converting difficulty to target - var diffDividend = (function(){ + var diffDividend = bignum((function(){ switch(options.algorithm){ case 'sha256': return '00000000ffff0000000000000000000000000000000000000000000000000000'; @@ -94,7 +85,7 @@ var JobManager = module.exports = function JobManager(options){ case 'x11': return '000000ffff000000000000000000000000000000000000000000000000000000'; } - })(); + })(), 16); //On initialization lets figure out which hashing algorithm to use @@ -144,7 +135,6 @@ var JobManager = module.exports = function JobManager(options){ options.txMessages ); - //jobs[tmpBlockTemplate.jobId] = tmpBlockTemplate; this.currentJob = tmpBlockTemplate; _this.emit('newBlock', tmpBlockTemplate); @@ -169,7 +159,6 @@ var JobManager = module.exports = function JobManager(options){ return shareError([20, 'incorrect size of extranonce2']); var job = this.currentJob; - //var job = jobs[jobId]; if (typeof job === 'undefined' || job.jobId != jobId ) { return shareError([21, 'job not found']); @@ -214,7 +203,7 @@ var JobManager = module.exports = function JobManager(options){ blockHash = util.reverseBuffer(util.doublesha(headerBuffer)).toString('hex'); } else { - var targetUser = bignum(diffDividend, 16).div(difficulty); + var targetUser = diffDividend.div(difficulty); if (headerBigNum.gt(targetUser)){ return shareError([23, 'low difficulty share']); }