Fixed difficulty not being correct for anything not scrypt. Fixed maxDiff for x11 hash.
This commit is contained in:
parent
63336fc531
commit
1ae82cb21b
@ -5,13 +5,12 @@ var transactions = require('./transactions.js');
|
|||||||
var util = require('./util.js');
|
var util = require('./util.js');
|
||||||
|
|
||||||
|
|
||||||
var maxDifficulty = 0x00000000ffff0000000000000000000000000000000000000000000000000000;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The BlockTemplate class holds a single job.
|
* The BlockTemplate class holds a single job.
|
||||||
* and provides several methods to validate and submit it to the daemon coin
|
* and provides several methods to validate and submit it to the daemon coin
|
||||||
**/
|
**/
|
||||||
var BlockTemplate = module.exports = function BlockTemplate(jobId, rpcData, publicKey, extraNoncePlaceholder, reward, txMessages){
|
var BlockTemplate = module.exports = function BlockTemplate(maxDifficulty, jobId, rpcData, publicKey, extraNoncePlaceholder, reward, txMessages){
|
||||||
|
|
||||||
//private members
|
//private members
|
||||||
|
|
||||||
@ -44,7 +43,7 @@ var BlockTemplate = module.exports = function BlockTemplate(jobId, rpcData, publ
|
|||||||
bignum.fromBuffer(new Buffer(rpcData.target, 'hex')) :
|
bignum.fromBuffer(new Buffer(rpcData.target, 'hex')) :
|
||||||
util.bignumFromBits(rpcData.bits);
|
util.bignumFromBits(rpcData.bits);
|
||||||
|
|
||||||
this.difficulty = (maxDifficulty / this.target.toNumber()) * 65536;
|
this.difficulty = maxDifficulty.div(this.target).toNumber();
|
||||||
|
|
||||||
this.prevHashReversed = util.reverseByteOrder(new Buffer(rpcData.previousblockhash, 'hex')).toString('hex');
|
this.prevHashReversed = util.reverseByteOrder(new Buffer(rpcData.previousblockhash, 'hex')).toString('hex');
|
||||||
this.transactionData = Buffer.concat(rpcData.transactions.map(function(tx){
|
this.transactionData = Buffer.concat(rpcData.transactions.map(function(tx){
|
||||||
|
|||||||
@ -56,25 +56,25 @@ var JobManager = module.exports = function JobManager(options){
|
|||||||
var _this = this;
|
var _this = this;
|
||||||
var jobCounter = new JobCounter();
|
var jobCounter = new JobCounter();
|
||||||
|
|
||||||
|
|
||||||
//Which number to use as dividend when converting difficulty to target
|
//Which number to use as dividend when converting difficulty to target
|
||||||
var diffDividend = bignum((function(){
|
var maxDifficulty = bignum((function(){
|
||||||
switch(options.coin.algorithm){
|
switch(options.coin.algorithm){
|
||||||
case 'sha256':
|
case 'sha256':
|
||||||
case 'skein':
|
case 'skein':
|
||||||
return '00000000ffff0000000000000000000000000000000000000000000000000000';
|
return '00000000ffff0000000000000000000000000000000000000000000000000000';
|
||||||
case 'scrypt':
|
case 'scrypt':
|
||||||
case 'scrypt-jane':
|
case 'scrypt-jane':
|
||||||
|
case 'x11':
|
||||||
return '0000ffff00000000000000000000000000000000000000000000000000000000';
|
return '0000ffff00000000000000000000000000000000000000000000000000000000';
|
||||||
case 'quark':
|
case 'quark':
|
||||||
case 'x11':
|
return '0000ffff00000000000000000000000000000000000000000000000000000000';
|
||||||
return '000000ffff000000000000000000000000000000000000000000000000000000';
|
|
||||||
case 'max':
|
case 'max':
|
||||||
return 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000000'
|
return 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000000'
|
||||||
}
|
}
|
||||||
})(), 16);
|
})(), 16);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//On initialization lets figure out which hashing algorithm to use
|
//On initialization lets figure out which hashing algorithm to use
|
||||||
var hashDigest = (function(){
|
var hashDigest = (function(){
|
||||||
switch(options.coin.algorithm){
|
switch(options.coin.algorithm){
|
||||||
@ -168,6 +168,7 @@ var JobManager = module.exports = function JobManager(options){
|
|||||||
if (isNewBlock || updatedTransactions){
|
if (isNewBlock || updatedTransactions){
|
||||||
|
|
||||||
var tmpBlockTemplate = new blockTemplate(
|
var tmpBlockTemplate = new blockTemplate(
|
||||||
|
maxDifficulty,
|
||||||
jobCounter.next(),
|
jobCounter.next(),
|
||||||
rpcData,
|
rpcData,
|
||||||
publicKey,
|
publicKey,
|
||||||
@ -257,7 +258,7 @@ var JobManager = module.exports = function JobManager(options){
|
|||||||
blockHash = util.reverseBuffer(util.doublesha(headerBuffer)).toString('hex');
|
blockHash = util.reverseBuffer(util.doublesha(headerBuffer)).toString('hex');
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
var targetUser = diffDividend.div(difficulty);
|
var targetUser = maxDifficulty.div(difficulty);
|
||||||
if (headerBigNum.gt(targetUser)){
|
if (headerBigNum.gt(targetUser)){
|
||||||
return shareError([23, 'low difficulty share']);
|
return shareError([23, 'low difficulty share']);
|
||||||
}
|
}
|
||||||
|
|||||||
23
lib/pool.js
23
lib/pool.js
@ -274,7 +274,7 @@ var pool = module.exports = function pool(options, authorizeFn){
|
|||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
if (couldNotDetectMethod){
|
if (couldNotDetectMethod){
|
||||||
emitErrorLog('Could not detect block submission RPC method');
|
emitErrorLog('Could not detect block submission RPC method, ' + JSON.stringify(results));
|
||||||
callback('block submission detection failed');
|
callback('block submission detection failed');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -295,13 +295,9 @@ var pool = module.exports = function pool(options, authorizeFn){
|
|||||||
util.script_to_address(results.addressInfo.address) :
|
util.script_to_address(results.addressInfo.address) :
|
||||||
util.script_to_pubkey(results.addressInfo.pubkey);
|
util.script_to_pubkey(results.addressInfo.pubkey);
|
||||||
|
|
||||||
var networkDifficulty = Math.round(results.info.difficulty * 65536);
|
var networkType = results.info.testnet ? 'testnet' : 'live blockchain';
|
||||||
var network = results.info.testnet ? 'testnet' : 'live blockchain';
|
|
||||||
|
|
||||||
emitLog('Connected to ' + network +
|
|
||||||
'; detected ' + options.coin.reward +
|
|
||||||
' reward type; block height of ' + results.info.blocks +
|
|
||||||
'; difficulty of ' + networkDifficulty);
|
|
||||||
|
|
||||||
GetBlockTemplate(function(error, result){
|
GetBlockTemplate(function(error, result){
|
||||||
if (error) {
|
if (error) {
|
||||||
@ -315,11 +311,16 @@ var pool = module.exports = function pool(options, authorizeFn){
|
|||||||
} else {
|
} else {
|
||||||
Object.keys(options.ports).forEach(function(port){
|
Object.keys(options.ports).forEach(function(port){
|
||||||
var portDiff = options.ports[port].diff;
|
var portDiff = options.ports[port].diff;
|
||||||
if (portDiff > networkDifficulty)
|
if (portDiff > _this.jobManager.currentJob.difficulty)
|
||||||
emitWarningLog('Pool difficulty of ' + portDiff + ' on port ' + port +
|
emitWarningLog('Pool difficulty of ' + portDiff + ' on port ' + port +
|
||||||
' was set higher than network difficulty of ' + networkDifficulty);
|
' was set higher than network difficulty of ' + _this.jobManager.currentJob.difficulty);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
emitLog('Connected to ' + networkType +
|
||||||
|
'; detected ' + options.coin.reward +
|
||||||
|
' reward type; block height of ' + results.info.blocks +
|
||||||
|
'; difficulty of ' + _this.jobManager.currentJob.difficulty);
|
||||||
|
|
||||||
SetupBlockPolling();
|
SetupBlockPolling();
|
||||||
StartStratumServer();
|
StartStratumServer();
|
||||||
SetupPeer();
|
SetupPeer();
|
||||||
@ -366,7 +367,7 @@ var pool = module.exports = function pool(options, authorizeFn){
|
|||||||
|
|
||||||
_this.daemon.cmd('getblocktemplate', [], function(results){
|
_this.daemon.cmd('getblocktemplate', [], function(results){
|
||||||
var synced = results.every(function(r){
|
var synced = results.every(function(r){
|
||||||
return r.error.code !== -10;
|
return !r.error || r.error.code !== -10;
|
||||||
});
|
});
|
||||||
if (synced){
|
if (synced){
|
||||||
SetupDaemonInterface();
|
SetupDaemonInterface();
|
||||||
@ -435,7 +436,7 @@ var pool = module.exports = function pool(options, authorizeFn){
|
|||||||
resultCallback(result.error, result.result ? true : null);
|
resultCallback(result.error, result.result ? true : null);
|
||||||
|
|
||||||
}).on('malformedMessage', function (message) {
|
}).on('malformedMessage', function (message) {
|
||||||
emitWarningLog(client.workerName + " has sent us a malformed message: " + message);
|
emitWarningLog((client.workerName || ('Unauthorized miner [' + client.socket.remoteAddress + ']')) + " has sent us a malformed message: " + message);
|
||||||
|
|
||||||
}).on('socketError', function(err) {
|
}).on('socketError', function(err) {
|
||||||
emitWarningLog(client.workerName + " has somehow had a socket error: " + JSON.stringify(err));
|
emitWarningLog(client.workerName + " has somehow had a socket error: " + JSON.stringify(err));
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user