Added block/network difficulty to pool on share emitter
This commit is contained in:
parent
2d1b23ddb8
commit
4bad017613
@ -32,15 +32,18 @@ Features
|
|||||||
* __POW__ (proof-of-work) & __POS__ (proof-of-stake) support
|
* __POW__ (proof-of-work) & __POS__ (proof-of-stake) support
|
||||||
* Transaction messages support
|
* Transaction messages support
|
||||||
* Vardiff (variable difficulty / share limiter)
|
* Vardiff (variable difficulty / share limiter)
|
||||||
* Supports algorithms:
|
* Supports the hashing algorithms:
|
||||||
* __SHA256__ (Bitcoin, Freicoin, Peercoin/PPCoin, Terracoin, etc..)
|
* __SHA256__ (Bitcoin, Freicoin, Peercoin/PPCoin, Terracoin, etc..)
|
||||||
* __Scrypt__ (Litecoin, Dogecoin, Feathercoin, etc..)
|
* __Scrypt__ (Litecoin, Dogecoin, Feathercoin, etc..)
|
||||||
* __Scrypt-jane__ (YaCoin, CopperBars, Pennies, Tickets, etc..)
|
* __Scrypt-Jane__ (YaCoin, CopperBars, Pennies, Tickets, etc..)
|
||||||
* __Quark__ (Quarkcoin [QRK])
|
* __Quark__ (Quarkcoin [QRK])
|
||||||
* __X11__ (Darkcoin [DRK])
|
* __X11__ (Darkcoin [DRK])
|
||||||
|
|
||||||
|
|
||||||
#### Under development
|
#### Under development
|
||||||
|
* [Scrypt-VRT](https://github.com/scr34m/vertcoin_scrypt) (Scrypt-Adaptive-Nfactor) (Vertcoin) algorithm
|
||||||
|
* [Skein](https://github.com/ahmedbodi/stratum-mining-maxcoin/blob/master/lib/skeinhash.py) (Skeincoin) algorithm
|
||||||
|
* [Max](https://github.com/Prydie/maxcoin-hash-python) algorithm
|
||||||
* P2P functionality for highly efficient block updates from daemon as a peer node
|
* P2P functionality for highly efficient block updates from daemon as a peer node
|
||||||
* Clustering to take advantage of multiple CPU cores
|
* Clustering to take advantage of multiple CPU cores
|
||||||
|
|
||||||
|
|||||||
@ -5,6 +5,7 @@ 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.
|
||||||
@ -35,6 +36,7 @@ var BlockTemplate = module.exports = function BlockTemplate(jobId, rpcData, publ
|
|||||||
this.rpcData = rpcData;
|
this.rpcData = rpcData;
|
||||||
this.jobId = jobId;
|
this.jobId = jobId;
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Use the 'target' field if available, but some daemons only return the 'bits' field
|
Use the 'target' field if available, but some daemons only return the 'bits' field
|
||||||
*/
|
*/
|
||||||
@ -42,6 +44,8 @@ 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 = Math.round(maxDifficulty / this.target.toNumber() * 1e8) / 1e8;
|
||||||
|
|
||||||
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){
|
||||||
return new Buffer(tx.data, 'hex');
|
return new Buffer(tx.data, 'hex');
|
||||||
|
|||||||
@ -61,6 +61,7 @@ var JobManager = module.exports = function JobManager(options){
|
|||||||
var diffDividend = bignum((function(){
|
var diffDividend = bignum((function(){
|
||||||
switch(options.algorithm){
|
switch(options.algorithm){
|
||||||
case 'sha256':
|
case 'sha256':
|
||||||
|
case 'skein':
|
||||||
return '00000000ffff0000000000000000000000000000000000000000000000000000';
|
return '00000000ffff0000000000000000000000000000000000000000000000000000';
|
||||||
case 'scrypt':
|
case 'scrypt':
|
||||||
case 'scrypt-jane':
|
case 'scrypt-jane':
|
||||||
@ -68,6 +69,8 @@ var JobManager = module.exports = function JobManager(options){
|
|||||||
case 'quark':
|
case 'quark':
|
||||||
case 'x11':
|
case 'x11':
|
||||||
return '000000ffff000000000000000000000000000000000000000000000000000000';
|
return '000000ffff000000000000000000000000000000000000000000000000000000';
|
||||||
|
case 'max':
|
||||||
|
return 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000000'
|
||||||
}
|
}
|
||||||
})(), 16);
|
})(), 16);
|
||||||
|
|
||||||
@ -95,6 +98,17 @@ var JobManager = module.exports = function JobManager(options){
|
|||||||
return function(){
|
return function(){
|
||||||
return x11.digest.apply(this, arguments);
|
return x11.digest.apply(this, arguments);
|
||||||
}
|
}
|
||||||
|
case 'max':
|
||||||
|
return function(){
|
||||||
|
//https://github.com/phusion/node-sha3
|
||||||
|
//https://github.com/Prydie/maxcoin-hash-python
|
||||||
|
//https://github.com/ahmedbodi/stratum-mining-maxcoin/blob/master/lib/template_registry.py
|
||||||
|
}
|
||||||
|
case 'skein':
|
||||||
|
return function(){
|
||||||
|
//https://github.com/cruzrr/insanehash
|
||||||
|
//https://github.com/Crypto-Expert/stratum-mining/blob/master/lib/skein.py
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
|
||||||
@ -246,6 +260,7 @@ var JobManager = module.exports = function JobManager(options){
|
|||||||
worker: workerName,
|
worker: workerName,
|
||||||
difficulty: difficulty,
|
difficulty: difficulty,
|
||||||
height: job.rpcData.height,
|
height: job.rpcData.height,
|
||||||
|
difficulty: job.difficulty,
|
||||||
solution: blockHash
|
solution: blockHash
|
||||||
}, blockHex);
|
}, blockHex);
|
||||||
|
|
||||||
|
|||||||
@ -29,7 +29,7 @@ var pool = module.exports = function pool(options, authorizeFn){
|
|||||||
var _this = this;
|
var _this = this;
|
||||||
var publicKeyBuffer;
|
var publicKeyBuffer;
|
||||||
|
|
||||||
var maxDifficulty = 0x00000000ffff0000000000000000000000000000000000000000000000000000;
|
|
||||||
|
|
||||||
var emitLog = function(key, text) { _this.emit('log', 'debug' , key, text); };
|
var emitLog = function(key, text) { _this.emit('log', 'debug' , key, text); };
|
||||||
var emitWarningLog = function(key, text) { _this.emit('log', 'warning', key, text); };
|
var emitWarningLog = function(key, text) { _this.emit('log', 'warning', key, text); };
|
||||||
@ -368,7 +368,7 @@ var pool = module.exports = function pool(options, authorizeFn){
|
|||||||
var processedNewBlock = _this.jobManager.processTemplate(result, publicKeyBuffer);
|
var processedNewBlock = _this.jobManager.processTemplate(result, publicKeyBuffer);
|
||||||
|
|
||||||
if (processedNewBlock && options.varDiff.enabled)
|
if (processedNewBlock && options.varDiff.enabled)
|
||||||
_this.varDiff.setNetworkDifficulty(maxDifficulty / parseInt(result.target, 16));
|
_this.varDiff.setNetworkDifficulty(_this.jobManager.currentJob.difficulty);
|
||||||
|
|
||||||
callback(null, result);
|
callback(null, result);
|
||||||
callback = function(){};
|
callback = function(){};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user