From 71d5f412576af19c83ee1e4dbe415fba4b422ebd Mon Sep 17 00:00:00 2001 From: Matt Date: Thu, 27 Mar 2014 18:10:38 -0600 Subject: [PATCH] Put all the different hashing algo info in the same place. Attempted to add keccak - it may or may not work. --- README.md | 2 + algo_dev.txt | 14 +++++- lib/algoProperties.js | 77 ++++++++++++++++++++++++++++++ lib/index.js | 4 ++ lib/pool.js | 108 ++++++++++-------------------------------- 5 files changed, 121 insertions(+), 84 deletions(-) create mode 100644 lib/algoProperties.js diff --git a/README.md b/README.md index b715ce5..28e60bc 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,8 @@ Under development: * ✗ *Bcrypt* (Taojingcoin [TJC]) * ✗ *Hefty1* (Heavycoin [HVC]) * ✗ *Blake* (Blakecoin [BLC]) +* ✗ *Fugue* (Fuguecoin [FC]) +* ✗ *SHAvite-3* (INKcoin [INK]) #### Under development diff --git a/algo_dev.txt b/algo_dev.txt index 888703b..817ef3f 100644 --- a/algo_dev.txt +++ b/algo_dev.txt @@ -5,6 +5,7 @@ https://github.com/heavycoin/heavycoin-hash-python keccak https://github.com/phusion/node-sha3 +https://github.com/GalleonBank/galleon blake https://github.com/BlueDragon747/Blakecoin_Python_POW_Module @@ -22,4 +23,15 @@ https://github.com/ahmedbodi/stratum-mining/tree/NScrypt max https://github.com/Prydie/maxcoin-hash-python -https://github.com/ahmedbodi/stratum-mining-maxcoin \ No newline at end of file +https://github.com/ahmedbodi/stratum-mining-maxcoin + + +fugue +https://github.com/fuguecoin/fuguecoin + + +SHAvite-3 +https://github.com/inkcoin/inkcoin-project/blob/f729f1070eb6222832f34fbf087b1aea16522962/src/hashblock.h +https://github.com/inkcoin/inkcoin-project +http://www.cs.technion.ac.il/~orrd/SHAvite-3/ +https://bitcointalk.org/index.php?topic=481516.0 \ No newline at end of file diff --git a/lib/algoProperties.js b/lib/algoProperties.js new file mode 100644 index 0000000..519fc5b --- /dev/null +++ b/lib/algoProperties.js @@ -0,0 +1,77 @@ +var scrypt = require('scrypt256-hash'); +var quark = require('quark-hash'); +var scryptJane = require('scrypt-jane-hash'); +var x11 = require('x11-hash'); +var keccak = require('keccak-hash'); +var SHA3 = require('sha3'); + +global.algos = { + 'sha256': { + diff: '00000000ffff0000000000000000000000000000000000000000000000000000', + hash: function(){ + return util.doublesha.apply(this, arguments); + } + }, + 'scrypt': { + diff: '0000ffff00000000000000000000000000000000000000000000000000000000', + hash: function(){ + return scrypt.digest.apply(this, arguments); + } + }, + 'scrypt-jane': { + diff: '0000ffff00000000000000000000000000000000000000000000000000000000', + hash: function(){ + return scryptJane.digest.apply(this, arguments); + } + }, + 'x11': { + diff: '0000ffff00000000000000000000000000000000000000000000000000000000', + hash: function(){ + return x11.digest.apply(this, arguments); + } + }, + quark: { + diff: '000000ffff000000000000000000000000000000000000000000000000000000', + hash: function(){ + return quark.digest.apply(this, arguments); + } + }, + 'keccak': { + diff: 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000000', + hash: function(headerBuff, nTimeInt){ + var a = new SHA3.SHA3Hash(256); + //a.update(headerBuff.toString('utf8') + nTimeInt.toString(), 'utf8'); + a.update(headerBuff.toString('utf8'), 'utf8'); + var round1 = new Buffer(a.digest('hex'), 'hex'); + return round1.slice(0, 33); + /*var b = new SHA3.SHA3Hash(256); + b.update(round1.toString('utf8'), 'utf8'); + var round2 = new Buffer(b.digest('hex'), 'hex'); + return round2.slice(0, 33);*/ + } + }, + 'skein': { + diff: '00000000ffff0000000000000000000000000000000000000000000000000000', + hash: function(){ + + } + }, + 'hefty1': { + diff: '00000000ffff0000000000000000000000000000000000000000000000000000', + hash: function(){ + + } + }, + max: { + diff: 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000000', + hash: function(){ + + } + }, + fugue: { + diff: '0000ffff00000000000000000000000000000000000000000000000000000000', + hash: function(){ + + } + } +}; \ No newline at end of file diff --git a/lib/index.js b/lib/index.js index 4ffb015..dccd34a 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,10 +1,14 @@ var net = require('net'); var events = require('events'); +//Gives us global access to everything we need for each hashing algorithm +require('./algoProperties.js'); + var pool = require('./pool.js'); exports.daemon = require('./daemon.js'); + exports.createPool = function(poolOptions, authorizeFn){ var newPool = new pool(poolOptions, authorizeFn); return newPool; diff --git a/lib/pool.js b/lib/pool.js index a739ef9..2dc543f 100644 --- a/lib/pool.js +++ b/lib/pool.js @@ -1,8 +1,6 @@ var events = require('events'); var async = require('async'); - - var varDiff = require('./varDiff.js'); var daemon = require('./daemon.js'); var peer = require('./peer.js'); @@ -10,12 +8,6 @@ var stratum = require('./stratum.js'); var jobManager = require('./jobManager.js'); var util = require('./util.js'); -var scrypt = require('scrypt256-hash'); -var quark = require('quark-hash'); -var scryptJane = require('scrypt-jane-hash'); -var x11 = require('x11-hash'); -//var keccak = require('keccak-hash'); -var SHA3 = require('sha3'); var bignum = require('bignum'); @@ -46,69 +38,16 @@ var pool = module.exports = function pool(options, authorizeFn){ var emitSpecialLog = function(text) { _this.emit('log', 'special', text); }; + + if (!(options.coin.algorithm in algos)){ + emitErrorLog('The ' + options.coin.algorithm + ' hashing algorithm is not supported.'); + throw new Error(); + } + //Which number to use as dividend when converting difficulty to target + var maxDifficulty = bignum(algos[options.coin.algorithm].diff, 16); - var diffHex = (function(){ - switch(options.coin.algorithm){ - case 'sha256': - case 'skein': - case 'hefty1': - case 'keccak': - return '00000000ffff0000000000000000000000000000000000000000000000000000'; - case 'scrypt': - case 'scrypt-jane': - case 'x11': - case 'quark': - case 'max': - return '0000ffff00000000000000000000000000000000000000000000000000000000'; - default: - emitErrorLog('The ' + options.coin.algorithm + ' hashing algorithm is not supported.'); - throw new Error(); - } - })(); - var maxDifficulty = bignum(diffHex, 16); - - - - //On initialization lets figure out which hashing algorithm to use - var hashDigest = (function(){ - switch(options.coin.algorithm){ - case 'sha256': - return function(){ - return util.doublesha.apply(this, arguments); - }; - case 'scrypt': - return function(){ - return scrypt.digest.apply(this, arguments); - }; - case 'scrypt-jane': - return function(){ - return scryptJane.digest.apply(this, arguments); - }; - case 'quark': - return function(){ - return quark.digest.apply(this, arguments); - }; - case 'x11': - return function(){ - return x11.digest.apply(this, arguments); - }; - case 'keccak': - return function(headerBuff, nTimeInt){ - var d = new SHA3.SHA3Hash(256); - d.update(headerBuff.toString('utf8') + nTimeInt.toString(), 'utf8'); - return new Buffer(d.digest('hex'), 'hex'); - }; - case 'skein': - return function(){ - - }; - default: - return function(){ - console.log('Hashing algorithm ' + options.coin.algorithm + ' not supported'); - }; - } - })(); + var hashDigest = algos[options.coin.algorithm].hash; this.start = function(){ @@ -164,7 +103,8 @@ var pool = module.exports = function pool(options, authorizeFn){ function OutputPoolInfo(){ - var startMessage = 'Stratum Pool Server Started for ' + options.coin.name + ' [' + options.coin.symbol.toUpperCase() + ']'; + var startMessage = 'Stratum Pool Server Started for ' + options.coin.name + + ' [' + options.coin.symbol.toUpperCase() + '] {' + options.coin.algorithm + '}'; if (process.env.forkId && process.env.forkId !== '0'){ emitLog(startMessage); return; @@ -692,21 +632,23 @@ var pool = module.exports = function pool(options, authorizeFn){ function CheckBlockAccepted(blockHash, callback){ - _this.daemon.cmd('getblock', - [blockHash], - function(results){ - var validResults = results.filter(function(result){ - return result.response && (result.response.hash === blockHash) - }); + setTimeout(function(){ + _this.daemon.cmd('getblock', + [blockHash], + function(results){ + var validResults = results.filter(function(result){ + return result.response && (result.response.hash === blockHash) + }); - if (validResults.length >= 1){ - callback(true, validResults[0].response.tx[0]); + if (validResults.length >= 1){ + callback(true, validResults[0].response.tx[0]); + } + else{ + callback(false); + } } - else{ - callback(false); - } - } - ); + ); + }, 500); }