Added block/network difficulty to pool on share emitter

This commit is contained in:
Matt 2014-02-27 01:26:43 -07:00
parent 2d1b23ddb8
commit 4bad017613
4 changed files with 26 additions and 4 deletions

View File

@ -32,15 +32,18 @@ Features
* __POW__ (proof-of-work) & __POS__ (proof-of-stake) support
* Transaction messages support
* Vardiff (variable difficulty / share limiter)
* Supports algorithms:
* Supports the hashing algorithms:
* __SHA256__ (Bitcoin, Freicoin, Peercoin/PPCoin, Terracoin, etc..)
* __Scrypt__ (Litecoin, Dogecoin, Feathercoin, etc..)
* __Scrypt-jane__ (YaCoin, CopperBars, Pennies, Tickets, etc..)
* __Scrypt-Jane__ (YaCoin, CopperBars, Pennies, Tickets, etc..)
* __Quark__ (Quarkcoin [QRK])
* __X11__ (Darkcoin [DRK])
#### 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
* Clustering to take advantage of multiple CPU cores

View File

@ -5,6 +5,7 @@ var transactions = require('./transactions.js');
var util = require('./util.js');
var maxDifficulty = 0x00000000ffff0000000000000000000000000000000000000000000000000000;
/**
* The BlockTemplate class holds a single job.
@ -35,6 +36,7 @@ var BlockTemplate = module.exports = function BlockTemplate(jobId, rpcData, publ
this.rpcData = rpcData;
this.jobId = jobId;
/*
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')) :
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.transactionData = Buffer.concat(rpcData.transactions.map(function(tx){
return new Buffer(tx.data, 'hex');

View File

@ -61,6 +61,7 @@ var JobManager = module.exports = function JobManager(options){
var diffDividend = bignum((function(){
switch(options.algorithm){
case 'sha256':
case 'skein':
return '00000000ffff0000000000000000000000000000000000000000000000000000';
case 'scrypt':
case 'scrypt-jane':
@ -68,6 +69,8 @@ var JobManager = module.exports = function JobManager(options){
case 'quark':
case 'x11':
return '000000ffff000000000000000000000000000000000000000000000000000000';
case 'max':
return 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000000'
}
})(), 16);
@ -95,6 +98,17 @@ var JobManager = module.exports = function JobManager(options){
return function(){
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,
difficulty: difficulty,
height: job.rpcData.height,
difficulty: job.difficulty,
solution: blockHash
}, blockHex);

View File

@ -29,7 +29,7 @@ var pool = module.exports = function pool(options, authorizeFn){
var _this = this;
var publicKeyBuffer;
var maxDifficulty = 0x00000000ffff0000000000000000000000000000000000000000000000000000;
var emitLog = function(key, text) { _this.emit('log', 'debug' , 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);
if (processedNewBlock && options.varDiff.enabled)
_this.varDiff.setNetworkDifficulty(maxDifficulty / parseInt(result.target, 16));
_this.varDiff.setNetworkDifficulty(_this.jobManager.currentJob.difficulty);
callback(null, result);
callback = function(){};