Convert diff dividend to bignum only on init.

This commit is contained in:
Matthew Little 2014-02-21 23:09:02 -07:00
parent b26312cf73
commit 69feb04da1

View File

@ -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']);
}