Change diffs to stay in buffer or bignum format rather than hex or js number
This commit is contained in:
parent
7d5c7ed277
commit
78f6a8c2e6
@ -186,7 +186,7 @@ function BufferToCompact(startingBuff){
|
||||
}
|
||||
|
||||
|
||||
function ConvertBitsToHex(bitsBuff){
|
||||
function ConvertBitsToBuff(bitsBuff){
|
||||
var numBytes = bitsBuff.readUInt8(0);
|
||||
var bigBits = bignum.fromBuffer(bitsBuff.slice(1));
|
||||
var target = bigBits.mul(
|
||||
@ -202,17 +202,19 @@ function ConvertBitsToHex(bitsBuff){
|
||||
buff256.fill(0);
|
||||
resultBuff.copy(buff256, buff256.length - resultBuff.length);
|
||||
|
||||
var hexResult = buff256.toString('hex');
|
||||
|
||||
return hexResult;
|
||||
//var hexResult = buff256.toString('hex');
|
||||
//return hexResult;
|
||||
return buff256;
|
||||
}
|
||||
|
||||
for (var algo in algos){
|
||||
if (!algos[algo].diff) {
|
||||
var nonTruncatedDiff = ShiftMax256Right(algos[algo].shift);
|
||||
var compactBits = BufferToCompact(nonTruncatedDiff);
|
||||
var truncatedDiff = ConvertBitsToHex(compactBits);
|
||||
var truncatedDiff = ConvertBitsToBuff(compactBits);
|
||||
|
||||
algos[algo].bits = compactBits;
|
||||
algos[algo].diff = truncatedDiff;
|
||||
algos[algo].nonTruncatedDiff = nonTruncatedDiff;
|
||||
}
|
||||
}
|
||||
@ -43,7 +43,7 @@ var BlockTemplate = module.exports = function BlockTemplate(maxDifficulty, jobId
|
||||
bignum.fromBuffer(new Buffer(rpcData.target, 'hex')) :
|
||||
util.bignumFromBits(rpcData.bits);
|
||||
|
||||
this.difficulty = maxDifficulty.div(this.target).toNumber();
|
||||
this.difficulty = maxDifficulty.div(this.target);
|
||||
|
||||
this.prevHashReversed = util.reverseByteOrder(new Buffer(rpcData.previousblockhash, 'hex')).toString('hex');
|
||||
this.transactionData = Buffer.concat(rpcData.transactions.map(function(tx){
|
||||
|
||||
@ -201,6 +201,7 @@ var JobManager = module.exports = function JobManager(maxDifficulty, hashDigest,
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (!!blockHex) {
|
||||
_this.emit('debugBlockShare',
|
||||
{
|
||||
@ -217,14 +218,14 @@ var JobManager = module.exports = function JobManager(maxDifficulty, hashDigest,
|
||||
}
|
||||
|
||||
_this.emit('share', {
|
||||
job : jobId,
|
||||
ip : ipAddress,
|
||||
worker : workerName,
|
||||
difficulty : difficulty,
|
||||
height : job.rpcData.height,
|
||||
reward : job.rpcData.coinbasevalue,
|
||||
networkDifficulty : job.difficulty,
|
||||
solution : blockHash
|
||||
job: jobId,
|
||||
ip: ipAddress,
|
||||
worker: workerName,
|
||||
difficulty: difficulty,
|
||||
height: job.rpcData.height,
|
||||
reward: job.rpcData.coinbasevalue,
|
||||
networkDifficulty : job.difficulty.toString(),
|
||||
solution: blockHash
|
||||
}, blockHex);
|
||||
|
||||
return {result: true, error: null, solution: blockHash};
|
||||
|
||||
@ -83,14 +83,14 @@ var pool = module.exports = function pool(options, authorizeFn){
|
||||
|
||||
Object.keys(options.ports).forEach(function(port){
|
||||
var portDiff = options.ports[port].diff;
|
||||
if (portDiff > _this.jobManager.currentJob.difficulty)
|
||||
if (_this.jobManager.currentJob.difficulty.le(portDiff))
|
||||
portWarnings.push('port ' + port + ' w/ difficulty ' + portDiff);
|
||||
|
||||
});
|
||||
|
||||
//Only let the first fork show synced status or the log wil look flooded with it
|
||||
if (portWarnings.length > 0 && (!process.env.forkId || process.env.forkId === '0')) {
|
||||
var warnMessage = 'Network difficulty of ' + _this.jobManager.currentJob.difficulty + ' is lower than '
|
||||
var warnMessage = 'Network difficulty of ' + _this.jobManager.currentJob.difficulty.toString() + ' is lower than '
|
||||
+ portWarnings.join(' and ');
|
||||
emitWarningLog(warnMessage);
|
||||
}
|
||||
@ -115,7 +115,7 @@ var pool = module.exports = function pool(options, authorizeFn){
|
||||
'Current Block Height:\t' + _this.jobManager.currentJob.rpcData.height,
|
||||
'Current Connect Peers:\t' + options.initStats.connections,
|
||||
'Network Hash Rate:\t' + (options.initStats.networkHashRate / 1e3).toFixed(6) + ' KH/s',
|
||||
'Network Difficulty:\t' + _this.jobManager.currentJob.difficulty,
|
||||
'Network Difficulty:\t' + _this.jobManager.currentJob.difficulty.toString(),
|
||||
'Listening Port(s):\t' + _this.options.initStats.stratumPorts.join(', ')
|
||||
];
|
||||
|
||||
@ -442,7 +442,7 @@ var pool = module.exports = function pool(options, authorizeFn){
|
||||
|
||||
options.testnet = infoResult.testnet;
|
||||
|
||||
options.initStats = { connections: infoResult.connections};
|
||||
options.initStats = { connections: infoResult.connections, difficulty: infoResult.difficulty };
|
||||
|
||||
callback(null);
|
||||
|
||||
|
||||
@ -106,7 +106,7 @@ var varDiff = module.exports = function varDiff(port, varDiffOptions){
|
||||
} else if (avg < tMin) {
|
||||
ddiff = 2;
|
||||
|
||||
var diffMax = networkDifficulty < options.maxDiff ? networkDifficulty : options.maxDiff;
|
||||
//var diffMax = networkDifficulty < options.maxDiff ? networkDifficulty : options.maxDiff;
|
||||
var diffMax = options.maxDiff;
|
||||
if (ddiff * client.difficulty > diffMax) {
|
||||
ddiff = diffMax / client.difficulty;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user