Skip to content

Commit

Permalink
Added block/network difficulty to pool on share emitter
Browse files Browse the repository at this point in the history
  • Loading branch information
zone117x committed Feb 27, 2014
1 parent 2d1b23d commit 4bad017
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions lib/blockTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var transactions = require('./transactions.js');
var util = require('./util.js');


var maxDifficulty = 0x00000000ffff0000000000000000000000000000000000000000000000000000;

/**
* The BlockTemplate class holds a single job.
Expand Down Expand Up @@ -35,13 +36,16 @@ 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
*/
this.target = rpcData.target ?
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');
Expand Down
15 changes: 15 additions & 0 deletions lib/jobManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,16 @@ 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':
return '0000ffff00000000000000000000000000000000000000000000000000000000';
case 'quark':
case 'x11':
return '000000ffff000000000000000000000000000000000000000000000000000000';
case 'max':
return 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000000'
}
})(), 16);

Expand Down Expand Up @@ -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
}
}
})();

Expand Down Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions lib/pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -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); };
Expand Down Expand Up @@ -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(){};
Expand Down

0 comments on commit 4bad017

Please sign in to comment.