From c37103907007d517650cb61360826b0112895cc5 Mon Sep 17 00:00:00 2001 From: Darkcoin Date: Sat, 7 Jun 2014 15:03:31 -0700 Subject: [PATCH 01/32] Darkcoin masternode payments have been changed from 10% to 20% --- lib/transactions.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/transactions.js b/lib/transactions.js index a70d00524..dc4402c52 100644 --- a/lib/transactions.js +++ b/lib/transactions.js @@ -133,7 +133,7 @@ var generateOutputTransactions = function(poolRecipient, recipients, rpcData){ if (rpcData.payee) { - var payeeReward = Math.ceil(reward / 10); + var payeeReward = Math.ceil(reward / 5); reward -= payeeReward; rewardToPool -= payeeReward; @@ -242,4 +242,4 @@ exports.CreateGeneration = function(rpcData, publicKey, extraNoncePlaceholder, r return [p1, p2]; -}; \ No newline at end of file +}; From 18c2212e7f1d2c30bb8c0d715c70cc16361b464a Mon Sep 17 00:00:00 2001 From: bolkin Date: Sun, 15 Jun 2014 19:01:55 -0400 Subject: [PATCH 02/32] fix auth parameters --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 25c93c09b..e8c3c92d3 100644 --- a/README.md +++ b/README.md @@ -276,7 +276,7 @@ var pool = Stratum.createPool({ } -}, function(ip, workerName, password, callback){ //stratum authorization function +}, function(ip, port , workerName, password, callback){ //stratum authorization function console.log("Authorize " + workerName + ":" + password + "@" + ip); callback({ error: null, From 66d40380511bde8597e76b73e1bef8a78de7c018 Mon Sep 17 00:00:00 2001 From: Matthew Little Date: Mon, 16 Jun 2014 11:39:45 -0600 Subject: [PATCH 03/32] Added NIST5 hashing --- README.md | 4 ++-- lib/algoProperties.js | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 25c93c09b..edf949a73 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,7 @@ Features * ✓ __Quark__ (Quarkcoin [QRK]) * ✓ __X11__ (Darkcoin [DRK], Hirocoin, Limecoin) * ✓ __X13__ (MaruCoin, BoostCoin) +* ✓ __NIST5__ (Talkcoin) * ✓ __Keccak__ (Maxcoin [MAX], HelixCoin, CryptoMeth, Galleon, 365coin, Slothcoin, BitcointalkCoin) * ✓ __Skein__ (Skeincoin [SKC]) * ✓ __Groestl__ (Groestlcoin [GRS]) @@ -53,13 +54,12 @@ May be working (needs additional testing): * ? *Blake* (Blakecoin [BLC]) * ? *Fugue* (Fuguecoin [FC]) * ? *Qubit* (Qubitcoin [Q2C], Myriadcoin [MYR]) -* ? *Hefty1* (Heavycoin [HVC]) * ? *SHAvite-3* (INKcoin [INK]) Not working currently: * *Groestl* - for Myriadcoin * *Keccak* - for eCoin & Copperlark - +* *Hefty1* (Heavycoin [HVC]) Requirements diff --git a/lib/algoProperties.js b/lib/algoProperties.js index d2494c0de..a1b84e0af 100644 --- a/lib/algoProperties.js +++ b/lib/algoProperties.js @@ -74,6 +74,13 @@ var algos = module.exports = global.algos = { } } }, + nist5: { + hash: function(){ + return function(){ + return multiHashing.nist5.apply(this, arguments); + } + } + }, quark: { hash: function(){ return function(){ From d2354063acb84571d63e4c4cd88784e677aa3a0a Mon Sep 17 00:00:00 2001 From: Matthew Little Date: Sat, 21 Jun 2014 09:20:03 -0600 Subject: [PATCH 04/32] Allow reward type to be configured in coin definition instead of auto detected --- lib/pool.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/pool.js b/lib/pool.js index 88abbbfc6..e2482af46 100644 --- a/lib/pool.js +++ b/lib/pool.js @@ -398,10 +398,12 @@ var pool = module.exports = function pool(options, authorizeFn){ return; } - if (isNaN(rpcResults.getdifficulty) && 'proof-of-stake' in rpcResults.getdifficulty) - options.coin.reward = 'POS'; - else - options.coin.reward = 'POW'; + if (!options.coin.reward) { + if (isNaN(rpcResults.getdifficulty) && 'proof-of-stake' in rpcResults.getdifficulty) + options.coin.reward = 'POS'; + else + options.coin.reward = 'POW'; + } /* POS coins must use the pubkey in coinbase transaction, and pubkey is From d7802bcbd3b5fedfc0ddc7b810cbfa3197e92fd3 Mon Sep 17 00:00:00 2001 From: Christopher Franko Date: Sat, 21 Jun 2014 14:32:32 -0400 Subject: [PATCH 05/32] Updated to add Scypt-og For aidencoin --- lib/algoProperties.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/algoProperties.js b/lib/algoProperties.js index a1b84e0af..f08e2f843 100644 --- a/lib/algoProperties.js +++ b/lib/algoProperties.js @@ -26,6 +26,19 @@ var algos = module.exports = global.algos = { } } }, + 'scrypt-og': { + //Aiden settings + //Uncomment diff if you want to use hardcoded truncated diff + //diff: '0000ffff00000000000000000000000000000000000000000000000000000000', + multiplier: Math.pow(2, 16), + hash: function(coinConfig){ + var nValue = coinConfig.nValue || 64; + var rValue = coinConfig.rValue || 1; + return function(data){ + return multiHashing.scrypt(data,nValue,rValue); + } + } + }, 'scrypt-jane': { multiplier: Math.pow(2, 16), hash: function(coinConfig){ From 3586ec0d7374b2acc5a72d5ef597da26f0e39d54 Mon Sep 17 00:00:00 2001 From: Matthew Little Date: Fri, 27 Jun 2014 11:25:55 -0600 Subject: [PATCH 06/32] Initial x15 support --- lib/algoProperties.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/algoProperties.js b/lib/algoProperties.js index a1b84e0af..1ec80682f 100644 --- a/lib/algoProperties.js +++ b/lib/algoProperties.js @@ -74,6 +74,13 @@ var algos = module.exports = global.algos = { } } }, + x15: { + hash: function(){ + return function(){ + return multiHashing.x15.apply(this, arguments); + } + } + }, nist5: { hash: function(){ return function(){ From 8713a643ebb029daa95946cd2591d07bcd9bb142 Mon Sep 17 00:00:00 2001 From: qazzac Date: Sat, 10 May 2014 17:37:14 +0900 Subject: [PATCH 07/32] Support sha1coin Signed-off-by: Masaki Muranaka --- README.md | 3 ++- lib/algoProperties.js | 7 +++++++ lib/jobManager.js | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 15c1efbab..8766f6710 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,7 @@ May be working (needs additional testing): * ? *Fugue* (Fuguecoin [FC]) * ? *Qubit* (Qubitcoin [Q2C], Myriadcoin [MYR]) * ? *SHAvite-3* (INKcoin [INK]) +* ? *Sha1* (Sha1coin [SHA], Yaycoin [YAY]) Not working currently: * *Groestl* - for Myriadcoin @@ -83,7 +84,7 @@ npm update Create the configuration for your coin: Possible options for `algorithm`: *sha256, scrypt, scrypt-jane, scrypt-n, quark, x11, keccak, blake, -skein, groestl, fugue, shavite3, hefty1, or qubit*. +skein, groestl, fugue, shavite3, hefty1, qubit, or sha1*. ```javascript var myCoin = { diff --git a/lib/algoProperties.js b/lib/algoProperties.js index 1ec80682f..6b7c3ecf0 100644 --- a/lib/algoProperties.js +++ b/lib/algoProperties.js @@ -60,6 +60,13 @@ var algos = module.exports = global.algos = { } } }, + sha1: { + hash: function(){ + return function(){ + return multiHashing.sha1.apply(this, arguments); + } + } + }, x11: { hash: function(){ return function(){ diff --git a/lib/jobManager.js b/lib/jobManager.js index b84d2805f..0c5103aad 100644 --- a/lib/jobManager.js +++ b/lib/jobManager.js @@ -97,6 +97,7 @@ var JobManager = module.exports = function JobManager(options){ }; } case 'scrypt-n': + case 'sha1': return function (d) { return util.reverseBuffer(util.sha256d(d)); }; From af52fe30c54f91c943a90cb2ea4fe1999ce98646 Mon Sep 17 00:00:00 2001 From: Christopher Franko Date: Fri, 14 Nov 2014 11:52:43 -0500 Subject: [PATCH 08/32] patch-2 scrypt-og this fixes the problem with blocks not submitting correctly to the daemon for aidencoin. --- lib/jobManager.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/jobManager.js b/lib/jobManager.js index 0c5103aad..cbcfc48ed 100644 --- a/lib/jobManager.js +++ b/lib/jobManager.js @@ -90,6 +90,12 @@ var JobManager = module.exports = function JobManager(options){ return util.reverseBuffer(hashDigest.apply(this, arguments)); }; } + case 'scrypt-og': + if (options.coin.reward === 'POS') { + return function (d) { + return util.reverseBuffer(hashDigest.apply(this, arguments)); + }; + } case 'scrypt-jane': if (options.coin.reward === 'POS') { return function (d) { From 25f65352a09b5df4dc014dd0eaf7c37610ecff6c Mon Sep 17 00:00:00 2001 From: romanornr Date: Thu, 1 Dec 2016 00:40:28 +0100 Subject: [PATCH 09/32] Variable length integer IntBuffer fix https://en.bitcoin.it/wiki/Protocol_documentation#Variable_length_integer Blocks with amount of transactions > 65535 will be rejected. Fixed now --- lib/util.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/util.js b/lib/util.js index 453939cf3..04030e111 100644 --- a/lib/util.js +++ b/lib/util.js @@ -76,12 +76,12 @@ exports.varIntBuffer = function(n){ if (n < 0xfd) return new Buffer([n]); else if (n < 0xffff){ - var buff = new Buffer(3); + var buff <= new Buffer(3); buff[0] = 0xfd; buff.writeUInt16LE(n, 1); return buff; } - else if (n < 0xffffffff){ + else if (n <= 0xffffffff){ var buff = new Buffer(5); buff[0] = 0xfe; buff.writeUInt32LE(n, 1); @@ -373,4 +373,4 @@ exports.convertBitsToBuff = function(bitsBuff){ exports.getTruncatedDiff = function(shift){ return exports.convertBitsToBuff(exports.bufferToCompactBits(exports.shiftMax256Right(shift))); -}; \ No newline at end of file +}; From 13653a3951b3dc3c6c322814257bfdfa0c4be5e3 Mon Sep 17 00:00:00 2001 From: romanornr Date: Thu, 1 Dec 2016 00:56:31 +0100 Subject: [PATCH 10/32] version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6b195a55e..4bc8904e8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "stratum-pool", - "version": "0.1.6", + "version": "0.1.9", "description": "High performance Stratum poolserver in Node.js", "keywords": [ "stratum", From 783058502327c8bf75309d6479d19132c29dfa85 Mon Sep 17 00:00:00 2001 From: romanornr Date: Thu, 1 Dec 2016 01:41:19 +0100 Subject: [PATCH 11/32] Lyra2RE diff by 128 --- lib/algoProperties.js | 9 +++++++++ lib/jobManager.js | 1 + 2 files changed, 10 insertions(+) diff --git a/lib/algoProperties.js b/lib/algoProperties.js index 7725ee622..7b8d26210 100644 --- a/lib/algoProperties.js +++ b/lib/algoProperties.js @@ -73,6 +73,15 @@ var algos = module.exports = global.algos = { } } }, + lyra2re: { + multiplier: Math.pow(2, 7), + hash: function(){ + return function(){ + return multiHashing.lyra2re.apply(this, arguments); + } + } + }, + } sha1: { hash: function(){ return function(){ diff --git a/lib/jobManager.js b/lib/jobManager.js index cbcfc48ed..194231c21 100644 --- a/lib/jobManager.js +++ b/lib/jobManager.js @@ -102,6 +102,7 @@ var JobManager = module.exports = function JobManager(options){ return util.reverseBuffer(hashDigest.apply(this, arguments)); }; } + case 'lyra2re': case 'scrypt-n': case 'sha1': return function (d) { From 0cd4fcbc0e0c5cf5f65ba767f32645f42b38d0ca Mon Sep 17 00:00:00 2001 From: romanornr Date: Sat, 10 Dec 2016 11:53:44 +0100 Subject: [PATCH 12/32] revert Lyra2RE --- lib/algoProperties.js | 9 --------- lib/jobManager.js | 1 - 2 files changed, 10 deletions(-) diff --git a/lib/algoProperties.js b/lib/algoProperties.js index 7b8d26210..7725ee622 100644 --- a/lib/algoProperties.js +++ b/lib/algoProperties.js @@ -73,15 +73,6 @@ var algos = module.exports = global.algos = { } } }, - lyra2re: { - multiplier: Math.pow(2, 7), - hash: function(){ - return function(){ - return multiHashing.lyra2re.apply(this, arguments); - } - } - }, - } sha1: { hash: function(){ return function(){ diff --git a/lib/jobManager.js b/lib/jobManager.js index 194231c21..cbcfc48ed 100644 --- a/lib/jobManager.js +++ b/lib/jobManager.js @@ -102,7 +102,6 @@ var JobManager = module.exports = function JobManager(options){ return util.reverseBuffer(hashDigest.apply(this, arguments)); }; } - case 'lyra2re': case 'scrypt-n': case 'sha1': return function (d) { From 1b8c7086be986cb80dde76b83f45c37cdecc23cc Mon Sep 17 00:00:00 2001 From: Matthew Little Date: Thu, 22 Dec 2016 18:50:31 -0700 Subject: [PATCH 13/32] Update util.js Fix typo --- lib/util.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/util.js b/lib/util.js index 04030e111..394d05997 100644 --- a/lib/util.js +++ b/lib/util.js @@ -75,8 +75,8 @@ Defined in bitcoin protocol here: exports.varIntBuffer = function(n){ if (n < 0xfd) return new Buffer([n]); - else if (n < 0xffff){ - var buff <= new Buffer(3); + else if (n <= 0xffff){ + var buff = new Buffer(3); buff[0] = 0xfd; buff.writeUInt16LE(n, 1); return buff; From 7894c4713e86b81394f347878400d4f69dda331c Mon Sep 17 00:00:00 2001 From: jonnybravo0311 Date: Sun, 11 Dec 2016 15:13:59 -0500 Subject: [PATCH 14/32] segwit support Use tx ID if it exists, else continue to use tx hash --- lib/blockTemplate.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/blockTemplate.js b/lib/blockTemplate.js index 886cdd19b..723e0cfa8 100644 --- a/lib/blockTemplate.js +++ b/lib/blockTemplate.js @@ -23,6 +23,9 @@ var BlockTemplate = module.exports = function BlockTemplate(jobId, rpcData, pool function getTransactionBuffers(txs){ var txHashes = txs.map(function(tx){ + if (tx.txid !== undefined) { + return util.uint256BufferFromHash(tx.txid); + } return util.uint256BufferFromHash(tx.hash); }); return [null].concat(txHashes); @@ -136,4 +139,4 @@ var BlockTemplate = module.exports = function BlockTemplate(jobId, rpcData, pool } return this.jobParams; }; -}; \ No newline at end of file +}; From ff92d28422589dc9de3c7f81fa191d604782c854 Mon Sep 17 00:00:00 2001 From: jonnybravo0311 Date: Sun, 11 Dec 2016 15:19:49 -0500 Subject: [PATCH 15/32] segwit support Change call to GBT to include segwit rules --- lib/pool.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/pool.js b/lib/pool.js index e2482af46..2b6ad4df0 100644 --- a/lib/pool.js +++ b/lib/pool.js @@ -119,7 +119,7 @@ var pool = module.exports = function pool(options, authorizeFn){ function OnBlockchainSynced(syncedCallback){ var checkSynced = function(displayNotSynced){ - _this.daemon.cmd('getblocktemplate', [], function(results){ + _this.daemon.cmd('getblocktemplate', [{"capabilities": [ "coinbasetxn", "workid", "coinbase/append" ], "rules": [ "segwit" ]}], function(results){ var synced = results.every(function(r){ return !r.error || r.error.code !== -10; }); @@ -566,7 +566,7 @@ var pool = module.exports = function pool(options, authorizeFn){ function GetBlockTemplate(callback){ _this.daemon.cmd('getblocktemplate', - [{"capabilities": [ "coinbasetxn", "workid", "coinbase/append" ]}], + [{"capabilities": [ "coinbasetxn", "workid", "coinbase/append" ], "rules": [ "segwit" ]}], function(result){ if (result.error){ emitErrorLog('getblocktemplate call failed for daemon instance ' + From f2c90d45822562aaa9e418c9069a70aaa2b88005 Mon Sep 17 00:00:00 2001 From: jonnybravo0311 Date: Sun, 11 Dec 2016 15:21:41 -0500 Subject: [PATCH 16/32] segwit support Add commitment to coinbase transaction --- lib/transactions.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/transactions.js b/lib/transactions.js index dc4402c52..76cc1e8c4 100644 --- a/lib/transactions.js +++ b/lib/transactions.js @@ -165,7 +165,15 @@ var generateOutputTransactions = function(poolRecipient, recipients, rpcData){ util.varIntBuffer(poolRecipient.length), poolRecipient ])); - + + if (rpcData.default_witness_commitment !== undefined){ + witness_commitment = new Buffer(rpcData.default_witness_commitment, 'hex'); + txOutputBuffers.unshift(Buffer.concat([ + util.packInt64LE(0), + util.varIntBuffer(witness_commitment.length), + witness_commitment + ])); + } return Buffer.concat([ util.varIntBuffer(txOutputBuffers.length), From 74b7e1fe143af72da9a0c21733505b69f5b47f42 Mon Sep 17 00:00:00 2001 From: Kristopher Klosterman Date: Fri, 7 Jul 2017 21:45:28 -0400 Subject: [PATCH 17/32] updated buffers to Node API 8.1.3 --- lib/algoProperties.js | 4 +- lib/util.js | 105 +++++++++++++++++------------------------- package-lock.json | 25 ++++++++++ package.json | 6 +-- 4 files changed, 71 insertions(+), 69 deletions(-) create mode 100644 package-lock.json diff --git a/lib/algoProperties.js b/lib/algoProperties.js index 7725ee622..cb3658e66 100644 --- a/lib/algoProperties.js +++ b/lib/algoProperties.js @@ -39,7 +39,7 @@ var algos = module.exports = global.algos = { } } }, - 'scrypt-jane': { + /*'scrypt-jane': { multiplier: Math.pow(2, 16), hash: function(coinConfig){ var nTimestamp = coinConfig.chainStartTime || 1367991200; @@ -49,7 +49,7 @@ var algos = module.exports = global.algos = { return multiHashing.scryptjane(data, nTime, nTimestamp, nMin, nMax); } } - }, + },*/ 'scrypt-n': { multiplier: Math.pow(2, 16), hash: function(coinConfig){ diff --git a/lib/util.js b/lib/util.js index 394d05997..6f93b2d47 100644 --- a/lib/util.js +++ b/lib/util.js @@ -7,7 +7,7 @@ var bignum = require('bignum'); exports.addressFromEx = function(exAddress, ripdm160Key){ try { var versionByte = exports.getVersionByte(exAddress); - var addrBase = Buffer.concat([versionByte, new Buffer(ripdm160Key, 'hex')]); + var addrBase = Buffer.concat([versionByte, Buffer.from(ripdm160Key, 'hex')]); var checksum = exports.sha256d(addrBase).slice(0, 4); var address = Buffer.concat([addrBase, checksum]); return base58.encode(address); @@ -34,14 +34,14 @@ exports.sha256d = function(buffer){ }; exports.reverseBuffer = function(buff){ - var reversed = new Buffer(buff.length); + var reversed = Buffer.alloc(buff.length); for (var i = buff.length - 1; i >= 0; i--) reversed[buff.length - i - 1] = buff[i]; return reversed; }; exports.reverseHex = function(hex){ - return exports.reverseBuffer(new Buffer(hex, 'hex')).toString('hex'); + return exports.reverseBuffer(Buffer.from(hex, 'hex')).toString('hex'); }; exports.reverseByteOrder = function(buff){ @@ -51,13 +51,13 @@ exports.reverseByteOrder = function(buff){ exports.uint256BufferFromHash = function(hex){ - var fromHex = new Buffer(hex, 'hex'); + var fromHex; - if (fromHex.length != 32){ - var empty = new Buffer(32); - empty.fill(0); - fromHex.copy(empty); - fromHex = empty; + if (hex != 0) { + fromHex = Buffer.from(hex, 'hex'); + } else { + fromHex = Buffer.alloc(32); + fromHex.fill(0); } return exports.reverseBuffer(fromHex); @@ -74,21 +74,21 @@ Defined in bitcoin protocol here: */ exports.varIntBuffer = function(n){ if (n < 0xfd) - return new Buffer([n]); + return Buffer.from([n]); else if (n <= 0xffff){ - var buff = new Buffer(3); + var buff = Buffer.alloc(3); buff[0] = 0xfd; buff.writeUInt16LE(n, 1); return buff; } else if (n <= 0xffffffff){ - var buff = new Buffer(5); + var buff = Buffer.alloc(5); buff[0] = 0xfe; buff.writeUInt32LE(n, 1); return buff; } else{ - var buff = new Buffer(9); + var buff = Buffer.alloc(9); buff[0] = 0xff; exports.packUInt16LE(n).copy(buff, 1); return buff; @@ -96,7 +96,7 @@ exports.varIntBuffer = function(n){ }; exports.varStringBuffer = function(string){ - var strBuff = new Buffer(string); + var strBuff = Buffer.from(string); return Buffer.concat([exports.varIntBuffer(strBuff.length), strBuff]); }; @@ -108,33 +108,10 @@ Used to format height and date when putting into script signature: */ exports.serializeNumber = function(n){ - /* Old version that is bugged - if (n < 0xfd){ - var buff = new Buffer(2); - buff[0] = 0x1; - buff.writeUInt8(n, 1); - return buff; - } - else if (n <= 0xffff){ - var buff = new Buffer(4); - buff[0] = 0x3; - buff.writeUInt16LE(n, 1); - return buff; - } - else if (n <= 0xffffffff){ - var buff = new Buffer(5); - buff[0] = 0x4; - buff.writeUInt32LE(n, 1); - return buff; - } - else{ - return Buffer.concat([new Buffer([0x9]), binpack.packUInt64(n, 'little')]); - }*/ - - //New version from TheSeven - if (n >= 1 && n <= 16) return new Buffer([0x50 + n]); + //Version from TheSeven + if (n >= 1 && n <= 16) return Buffer.from([0x50 + n]); var l = 1; - var buff = new Buffer(9); + var buff = Buffer.alloc(9); while (n > 0x7f) { buff.writeUInt8(n & 0xff, l++); @@ -154,58 +131,58 @@ exports.serializeString = function(s){ if (s.length < 253) return Buffer.concat([ - new Buffer([s.length]), - new Buffer(s) + Buffer.from([s.length]), + Buffer.from(s) ]); else if (s.length < 0x10000) return Buffer.concat([ - new Buffer([253]), + Buffer.from([253]), exports.packUInt16LE(s.length), - new Buffer(s) + Buffer.from(s) ]); else if (s.length < 0x100000000) return Buffer.concat([ - new Buffer([254]), + Buffer.from([254]), exports.packUInt32LE(s.length), - new Buffer(s) + Buffer.from(s) ]); else return Buffer.concat([ - new Buffer([255]), + Buffer.from([255]), exports.packUInt16LE(s.length), - new Buffer(s) + Buffer.from(s) ]); }; exports.packUInt16LE = function(num){ - var buff = new Buffer(2); + var buff = Buffer.alloc(2); buff.writeUInt16LE(num, 0); return buff; }; exports.packInt32LE = function(num){ - var buff = new Buffer(4); + var buff = Buffer.alloc(4); buff.writeInt32LE(num, 0); return buff; }; exports.packInt32BE = function(num){ - var buff = new Buffer(4); + var buff = Buffer.alloc(4); buff.writeInt32BE(num, 0); return buff; }; exports.packUInt32LE = function(num){ - var buff = new Buffer(4); + var buff = Buffer.alloc(4); buff.writeUInt32LE(num, 0); return buff; }; exports.packUInt32BE = function(num){ - var buff = new Buffer(4); + var buff = Buffer.alloc(4); buff.writeUInt32BE(num, 0); return buff; }; exports.packInt64LE = function(num){ - var buff = new Buffer(8); + var buff = Buffer.alloc(8); buff.writeUInt32LE(num % Math.pow(2, 32), 0); buff.writeUInt32LE(Math.floor(num / Math.pow(2, 32)), 4); return buff; @@ -245,17 +222,17 @@ exports.pubkeyToScript = function(key){ console.error('Invalid pubkey: ' + key); throw new Error(); } - var pubkey = new Buffer(35); + var pubkey = Buffer.alloc(35); pubkey[0] = 0x21; pubkey[34] = 0xac; - new Buffer(key, 'hex').copy(pubkey, 1); + Buffer.from(key, 'hex').copy(pubkey, 1); return pubkey; }; exports.miningKeyToScript = function(key){ - var keyBuffer = new Buffer(key, 'hex'); - return Buffer.concat([new Buffer([0x76, 0xa9, 0x14]), keyBuffer, new Buffer([0x88, 0xac])]); + var keyBuffer = Buffer.from(key, 'hex'); + return Buffer.concat([Buffer.from([0x76, 0xa9, 0x14]), keyBuffer, Buffer.from([0x88, 0xac])]); }; /* @@ -277,7 +254,7 @@ exports.addressToScript = function(addr){ var pubkey = decoded.slice(1,-4); - return Buffer.concat([new Buffer([0x76, 0xa9, 0x14]), pubkey, new Buffer([0x88, 0xac])]); + return Buffer.concat([Buffer.from([0x76, 0xa9, 0x14]), pubkey, Buffer.from([0x88, 0xac])]); }; @@ -324,7 +301,7 @@ exports.shiftMax256Right = function(shiftRight){ } - return new Buffer(octets); + return Buffer.from(octets); }; @@ -332,9 +309,9 @@ exports.bufferToCompactBits = function(startingBuff){ var bigNum = bignum.fromBuffer(startingBuff); var buff = bigNum.toBuffer(); - buff = buff.readUInt8(0) > 0x7f ? Buffer.concat([new Buffer([0x00]), buff]) : buff; + buff = buff.readUInt8(0) > 0x7f ? Buffer.concat([Buffer.from([0x00]), buff]) : buff; - buff = Buffer.concat([new Buffer([buff.length]), buff]); + buff = Buffer.concat([Buffer.from([buff.length]), buff]); var compact = buff.slice(0, 4); return compact; }; @@ -358,14 +335,14 @@ exports.bignumFromBitsBuffer = function(bitsBuff){ }; exports.bignumFromBitsHex = function(bitsString){ - var bitsBuff = new Buffer(bitsString, 'hex'); + var bitsBuff = Buffer.from(bitsString, 'hex'); return exports.bignumFromBitsBuffer(bitsBuff); }; exports.convertBitsToBuff = function(bitsBuff){ var target = exports.bignumFromBitsBuffer(bitsBuff); var resultBuff = target.toBuffer(); - var buff256 = new Buffer(32); + var buff256 = Buffer.alloc(32); buff256.fill(0); resultBuff.copy(buff256, buff256.length - resultBuff.length); return buff256; diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 000000000..f9b163273 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,25 @@ +{ + "name": "stratum-pool", + "version": "0.1.9", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "bindings": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/bindings/-/bindings-1.2.1.tgz", + "integrity": "sha1-FK1hE4EtLTfXLme0ystLtyZQXxE=" + }, + "multi-hashing": { + "version": "git+https://github.com/krisklosterman/node-multi-hashing.git#58de58a2977b87a8b48292fdf2feae06c81b085f", + "requires": { + "bindings": "1.2.1", + "nan": "2.6.2" + } + }, + "nan": { + "version": "2.6.2", + "resolved": "https://registry.npmjs.org/nan/-/nan-2.6.2.tgz", + "integrity": "sha1-5P805slf37WuzAjeZZb0NgWn20U=" + } + } +} diff --git a/package.json b/package.json index 4bc8904e8..ff78b1929 100644 --- a/package.json +++ b/package.json @@ -28,10 +28,10 @@ "url": "https://github.com/zone117x/node-stratum-pool.git" }, "dependencies": { - "multi-hashing": "git://github.com/zone117x/node-multi-hashing.git", - "bignum": "*", + "async": "*", "base58-native": "*", - "async": "*" + "bignum": "*", + "multi-hashing": "git+https://github.com/krisklosterman/node-multi-hashing.git" }, "engines": { "node": ">=0.10" From 3c4542f294f9e98f15e9fd046bfd92bb840ca68a Mon Sep 17 00:00:00 2001 From: Kristopher Klosterman Date: Sun, 9 Jul 2017 22:13:41 -0400 Subject: [PATCH 18/32] pushing to test on different platoform --- lib/blockTemplate.js | 12 ++--- lib/jobManager.js | 6 +-- lib/peer.js | 18 +++---- lib/transactions.js | 126 ++----------------------------------------- package-lock.json | 25 --------- package.json | 2 +- 6 files changed, 24 insertions(+), 165 deletions(-) delete mode 100644 package-lock.json diff --git a/lib/blockTemplate.js b/lib/blockTemplate.js index 723e0cfa8..89a3079c5 100644 --- a/lib/blockTemplate.js +++ b/lib/blockTemplate.js @@ -32,12 +32,12 @@ var BlockTemplate = module.exports = function BlockTemplate(jobId, rpcData, pool } function getVoteData(){ - if (!rpcData.masternode_payments) return new Buffer([]); + if (!rpcData.masternode_payments) return Buffer.from([]); return Buffer.concat( [util.varIntBuffer(rpcData.votes.length)].concat( rpcData.votes.map(function (vt) { - return new Buffer(vt, 'hex'); + return Buffer.from(vt, 'hex'); }) ) ); @@ -59,9 +59,9 @@ var BlockTemplate = module.exports = function BlockTemplate(jobId, rpcData, pool - this.prevHashReversed = util.reverseByteOrder(new Buffer(rpcData.previousblockhash, 'hex')).toString('hex'); + this.prevHashReversed = util.reverseByteOrder(Buffer.from(rpcData.previousblockhash, 'hex')).toString('hex'); this.transactionData = Buffer.concat(rpcData.transactions.map(function(tx){ - return new Buffer(tx.data, 'hex'); + return Buffer.from(tx.data, 'hex'); })); this.merkleTree = new merkleTree(getTransactionBuffers(rpcData.transactions)); this.merkleBranch = getMerkleHashes(this.merkleTree.steps); @@ -87,7 +87,7 @@ var BlockTemplate = module.exports = function BlockTemplate(jobId, rpcData, pool //https://en.bitcoin.it/wiki/Protocol_specification#Block_Headers this.serializeHeader = function(merkleRoot, nTime, nonce){ - var header = new Buffer(80); + var header = Buffer.alloc(80); var position = 0; header.write(nonce, position, 4, 'hex'); header.write(rpcData.bits, position += 4, 4, 'hex'); @@ -110,7 +110,7 @@ var BlockTemplate = module.exports = function BlockTemplate(jobId, rpcData, pool getVoteData(), //POS coins require a zero byte appended to block which the daemon replaces with the signature - new Buffer(reward === 'POS' ? [0] : []) + Buffer.from(reward === 'POS' ? [0] : []) ]); }; diff --git a/lib/jobManager.js b/lib/jobManager.js index cbcfc48ed..10275e9fa 100644 --- a/lib/jobManager.js +++ b/lib/jobManager.js @@ -58,7 +58,7 @@ var JobManager = module.exports = function JobManager(options){ //public members this.extraNonceCounter = new ExtraNonceCounter(options.instanceId); - this.extraNoncePlaceholder = new Buffer('f000000ff111111f', 'hex'); + this.extraNoncePlaceholder = Buffer.from('f000000ff111111f', 'hex'); this.extraNonce2Size = this.extraNoncePlaceholder.length - this.extraNonceCounter.size; this.currentJob; @@ -213,8 +213,8 @@ var JobManager = module.exports = function JobManager(options){ } - var extraNonce1Buffer = new Buffer(extraNonce1, 'hex'); - var extraNonce2Buffer = new Buffer(extraNonce2, 'hex'); + var extraNonce1Buffer = Buffer.from(extraNonce1, 'hex'); + var extraNonce2Buffer = Buffer.from(extraNonce2, 'hex'); var coinbaseBuffer = job.serializeCoinbase(extraNonce1Buffer, extraNonce2Buffer); var coinbaseHash = coinbaseHasher(coinbaseBuffer); diff --git a/lib/peer.js b/lib/peer.js index 5435c3b97..7ce61e0e0 100644 --- a/lib/peer.js +++ b/lib/peer.js @@ -9,7 +9,7 @@ var util = require('./util.js'); var fixedLenStringBuffer = function(s, len) { - var buff = new Buffer(len); + var buff = Buffer.alloc(len); buff.fill(0); buff.write(s); return buff; @@ -26,7 +26,7 @@ var commandStringBuffer = function (s) { - callback returns 1) data buffer and 2) lopped/over-read data */ var readFlowingBytes = function (stream, amount, preRead, callback) { - var buff = preRead ? preRead : new Buffer([]); + var buff = preRead ? preRead : Buffer.from([]); var readData = function (data) { buff = Buffer.concat([buff, data]); @@ -39,14 +39,14 @@ var readFlowingBytes = function (stream, amount, preRead, callback) { stream.once('data', readData); }; - readData(new Buffer([])); + readData(Buffer.from([])); }; var Peer = module.exports = function (options) { var _this = this; var client; - var magic = new Buffer(options.testnet ? options.coin.peerMagicTestnet : options.coin.peerMagic, 'hex'); + var magic = Buffer.from(options.testnet ? options.coin.peerMagicTestnet : options.coin.peerMagic, 'hex'); var magicInt = magic.readUInt32LE(0); var verack = false; var validConnectionConfig = true; @@ -58,14 +58,14 @@ var Peer = module.exports = function (options) { block: 2 }; - var networkServices = new Buffer('0100000000000000', 'hex'); //NODE_NETWORK services (value 1 packed as uint64) - var emptyNetAddress = new Buffer('010000000000000000000000000000000000ffff000000000000', 'hex'); + var networkServices = Buffer.from('0100000000000000', 'hex'); //NODE_NETWORK services (value 1 packed as uint64) + var emptyNetAddress = Buffer.from('010000000000000000000000000000000000ffff000000000000', 'hex'); var userAgent = util.varStringBuffer('/node-stratum/'); - var blockStartHeight = new Buffer('00000000', 'hex'); //block start_height, can be empty + var blockStartHeight = Buffer.from('00000000', 'hex'); //block start_height, can be empty //If protocol version is new enough, add do not relay transactions flag byte, outlined in BIP37 //https://github.com/bitcoin/bips/blob/master/bip-0037.mediawiki#extensions-to-existing-messages - var relayTransactions = options.p2p.disableTransactions === true ? new Buffer([false]) : new Buffer([]); + var relayTransactions = options.p2p.disableTransactions === true ? Buffer.from([false]) : Buffer.from([]); var commands = { version: commandStringBuffer('version'), @@ -127,7 +127,7 @@ var Peer = module.exports = function (options) { if (header.readUInt32LE(0) === magicInt) { beginReadingMessage(header); } else { - beginReadingMessage(new Buffer([])); + beginReadingMessage(Buffer.from([])); } return; } diff --git a/lib/transactions.js b/lib/transactions.js index 76cc1e8c4..dcd9daa53 100644 --- a/lib/transactions.js +++ b/lib/transactions.js @@ -1,121 +1,5 @@ var util = require('./util.js'); - -/* -function Transaction(params){ - - var version = params.version || 1, - inputs = params.inputs || [], - outputs = params.outputs || [], - lockTime = params.lockTime || 0; - - - this.toBuffer = function(){ - return Buffer.concat([ - binpack.packUInt32(version, 'little'), - util.varIntBuffer(inputs.length), - Buffer.concat(inputs.map(function(i){ return i.toBuffer() })), - util.varIntBuffer(outputs.length), - Buffer.concat(outputs.map(function(o){ return o.toBuffer() })), - binpack.packUInt32(lockTime, 'little') - ]); - }; - - this.inputs = inputs; - this.outputs = outputs; - -} - -function TransactionInput(params){ - - var prevOutHash = params.prevOutHash || 0, - prevOutIndex = params.prevOutIndex, - sigScript = params.sigScript, - sequence = params.sequence || 0; - - - this.toBuffer = function(){ - sigScriptBuffer = sigScript.toBuffer(); - console.log('scriptSig length ' + sigScriptBuffer.length); - return Buffer.concat([ - util.uint256BufferFromHash(prevOutHash), - binpack.packUInt32(prevOutIndex, 'little'), - util.varIntBuffer(sigScriptBuffer.length), - sigScriptBuffer, - binpack.packUInt32(sequence) - ]); - }; -} - -function TransactionOutput(params){ - - var value = params.value, - pkScriptBuffer = params.pkScriptBuffer; - - this.toBuffer = function(){ - return Buffer.concat([ - binpack.packInt64(value, 'little'), - util.varIntBuffer(pkScriptBuffer.length), - pkScriptBuffer - ]); - }; -} - -function ScriptSig(params){ - - var height = params.height, - flags = params.flags, - extraNoncePlaceholder = params.extraNoncePlaceholder; - - this.toBuffer = function(){ - - return Buffer.concat([ - util.serializeNumber(height), - new Buffer(flags, 'hex'), - util.serializeNumber(Date.now() / 1000 | 0), - new Buffer([extraNoncePlaceholder.length]), - extraNoncePlaceholder, - util.serializeString('/nodeStratum/') - ]); - } -}; - - -var Generation = exports.Generation = function Generation(rpcData, publicKey, extraNoncePlaceholder){ - - var tx = new Transaction({ - inputs: [new TransactionInput({ - prevOutIndex : Math.pow(2, 32) - 1, - sigScript : new ScriptSig({ - height : rpcData.height, - flags : rpcData.coinbaseaux.flags, - extraNoncePlaceholder : extraNoncePlaceholder - }) - })], - outputs: [new TransactionOutput({ - value : rpcData.coinbasevalue, - pkScriptBuffer : publicKey - })] - }); - - var txBuffer = tx.toBuffer(); - var epIndex = buffertools.indexOf(txBuffer, extraNoncePlaceholder); - var p1 = txBuffer.slice(0, epIndex); - var p2 = txBuffer.slice(epIndex + extraNoncePlaceholder.length); - - this.transaction = tx; - this.coinbase = [p1, p2]; - -}; -*/ - - -/* - ^^^^ The above code was a bit slow. The below code is uglier but optimized. - */ - - - /* This function creates the generation transaction that accepts the reward for successfully mining a new block. @@ -167,7 +51,7 @@ var generateOutputTransactions = function(poolRecipient, recipients, rpcData){ ])); if (rpcData.default_witness_commitment !== undefined){ - witness_commitment = new Buffer(rpcData.default_witness_commitment, 'hex'); + witness_commitment = Buffer.from(rpcData.default_witness_commitment, 'hex'); txOutputBuffers.unshift(Buffer.concat([ util.packInt64LE(0), util.varIntBuffer(witness_commitment.length), @@ -196,19 +80,19 @@ exports.CreateGeneration = function(rpcData, publicKey, extraNoncePlaceholder, r //Only required for POS coins var txTimestamp = reward === 'POS' ? - util.packUInt32LE(rpcData.curtime) : new Buffer([]); + util.packUInt32LE(rpcData.curtime) : Buffer.from([]); //For coins that support/require transaction comments var txComment = txMessages === true ? util.serializeString('https://github.com/zone117x/node-stratum') : - new Buffer([]); + Buffer.from([]); var scriptSigPart1 = Buffer.concat([ util.serializeNumber(rpcData.height), - new Buffer(rpcData.coinbaseaux.flags, 'hex'), + Buffer.from(rpcData.coinbaseaux.flags, 'hex'), util.serializeNumber(Date.now() / 1000 | 0), - new Buffer([extraNoncePlaceholder.length]) + Buffer.from([extraNoncePlaceholder.length]) ]); var scriptSigPart2 = util.serializeString('/nodeStratum/'); diff --git a/package-lock.json b/package-lock.json deleted file mode 100644 index f9b163273..000000000 --- a/package-lock.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "name": "stratum-pool", - "version": "0.1.9", - "lockfileVersion": 1, - "requires": true, - "dependencies": { - "bindings": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/bindings/-/bindings-1.2.1.tgz", - "integrity": "sha1-FK1hE4EtLTfXLme0ystLtyZQXxE=" - }, - "multi-hashing": { - "version": "git+https://github.com/krisklosterman/node-multi-hashing.git#58de58a2977b87a8b48292fdf2feae06c81b085f", - "requires": { - "bindings": "1.2.1", - "nan": "2.6.2" - } - }, - "nan": { - "version": "2.6.2", - "resolved": "https://registry.npmjs.org/nan/-/nan-2.6.2.tgz", - "integrity": "sha1-5P805slf37WuzAjeZZb0NgWn20U=" - } - } -} diff --git a/package.json b/package.json index ff78b1929..af307d16f 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "async": "*", "base58-native": "*", "bignum": "*", - "multi-hashing": "git+https://github.com/krisklosterman/node-multi-hashing.git" + "multi-hashing": "git://github.com/krisklosterman/node-multi-hashing.git" }, "engines": { "node": ">=0.10" From 2ef76aa7932837d136a507b119742bedd07c2ee4 Mon Sep 17 00:00:00 2001 From: Kristopher Klosterman Date: Mon, 10 Jul 2017 10:04:29 -0400 Subject: [PATCH 19/32] added some loggin for debuging --- .gitignore | 3 ++- lib/jobManager.js | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index d35bbf75a..1b18ef571 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ node_modules/ -.idea/ \ No newline at end of file +.idea/ +.vscode/ \ No newline at end of file diff --git a/lib/jobManager.js b/lib/jobManager.js index 10275e9fa..66413dafe 100644 --- a/lib/jobManager.js +++ b/lib/jobManager.js @@ -212,6 +212,7 @@ var JobManager = module.exports = function JobManager(options){ return shareError([22, 'duplicate share']); } + console.log(jobId + " | " + previousDifficulty + " | " + difficulty + " | " + extraNonce1 + " | " + extraNonce2 + " | " + nTime + " | " + nonce + " | " + ipAddress + " | " + port + " | " + workerName); var extraNonce1Buffer = Buffer.from(extraNonce1, 'hex'); var extraNonce2Buffer = Buffer.from(extraNonce2, 'hex'); @@ -233,10 +234,23 @@ var JobManager = module.exports = function JobManager(options){ var blockDiffAdjusted = job.difficulty * shareMultiplier; + console.log(extraNonce1Buffer); + console.log(extraNonce2Buffer); + console.log(coinbaseBuffer); + console.log(coinbaseHash); + console.log(merkleRoot); + console.log(headerBuffer); + console.log(headerHash); + console.log(headerBigNum); + console.log(shareDiff); + console.log(blockDiffAdjusted); + //Check if share is a block candidate (matched network difficulty) if (job.target.ge(headerBigNum)){ blockHex = job.serializeBlock(headerBuffer, coinbaseBuffer).toString('hex'); blockHash = blockHasher(headerBuffer, nTime).toString('hex'); + console.log(blockHex); + console.log(blockHash); } else { if (options.emitInvalidBlockHashes) From 3053926905c07535bacf9e27ece95140644cbff9 Mon Sep 17 00:00:00 2001 From: Kristopher Klosterman Date: Mon, 10 Jul 2017 15:09:13 -0400 Subject: [PATCH 20/32] testing --- lib/jobManager.js | 1 + lib/pool.js | 4 +++- package.json | 6 +++--- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/jobManager.js b/lib/jobManager.js index 66413dafe..685fbd4cf 100644 --- a/lib/jobManager.js +++ b/lib/jobManager.js @@ -246,6 +246,7 @@ var JobManager = module.exports = function JobManager(options){ console.log(blockDiffAdjusted); //Check if share is a block candidate (matched network difficulty) + console.log("Job Target: " + job.target); if (job.target.ge(headerBigNum)){ blockHex = job.serializeBlock(headerBuffer, coinbaseBuffer).toString('hex'); blockHash = blockHasher(headerBuffer, nTime).toString('hex'); diff --git a/lib/pool.js b/lib/pool.js index 2b6ad4df0..af02f6977 100644 --- a/lib/pool.js +++ b/lib/pool.js @@ -627,6 +627,7 @@ var pool = module.exports = function pool(options, authorizeFn){ Object.keys(origStratumClients).forEach(function (subId) { stratumClients.push({subId: subId, client: origStratumClients[subId]}); }); + //TODO: Think of a way to use API 8's async/await and promises to replace async lib async.filter( stratumClients, filterFn, @@ -646,7 +647,8 @@ var pool = module.exports = function pool(options, authorizeFn){ ); }); } - ) + ); + }; diff --git a/package.json b/package.json index af307d16f..d1e3f589e 100644 --- a/package.json +++ b/package.json @@ -28,9 +28,9 @@ "url": "https://github.com/zone117x/node-stratum-pool.git" }, "dependencies": { - "async": "*", - "base58-native": "*", - "bignum": "*", + "async": "^2.5.0", + "base58-native": "^0.1.4", + "bignum": "^0.12.5", "multi-hashing": "git://github.com/krisklosterman/node-multi-hashing.git" }, "engines": { From 85fed70736dcecd298f9f7fb61e0da70d83c0c6a Mon Sep 17 00:00:00 2001 From: Kristopher Klosterman Date: Mon, 10 Jul 2017 17:30:31 -0400 Subject: [PATCH 21/32] testing --- lib/util.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/util.js b/lib/util.js index 6f93b2d47..79df1af61 100644 --- a/lib/util.js +++ b/lib/util.js @@ -24,6 +24,7 @@ exports.getVersionByte = function(addr){ }; exports.sha256 = function(buffer){ + console.log('RUNNING NSP sha256 method'); var hash1 = crypto.createHash('sha256'); hash1.update(buffer); return hash1.digest(); From f5f8422592cc026cea18839934a22cf79120c845 Mon Sep 17 00:00:00 2001 From: Kristopher Klosterman Date: Tue, 11 Jul 2017 08:52:38 -0400 Subject: [PATCH 22/32] adding logging for testing --- lib/pool.js | 10 ++++++++++ lib/util.js | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/pool.js b/lib/pool.js index af02f6977..a7cf13549 100644 --- a/lib/pool.js +++ b/lib/pool.js @@ -224,6 +224,8 @@ var pool = module.exports = function pool(options, authorizeFn){ */ function SubmitBlock(blockHex, callback){ + console.log("SUBMIT BLOCK: BlockHex: " + blockHex) + var rpcCommand, rpcArgs; if (options.hasSubmitMethod){ rpcCommand = 'submitblock'; @@ -249,6 +251,8 @@ var pool = module.exports = function pool(options, authorizeFn){ } else if (result.response === 'rejected') { emitErrorLog('Daemon instance ' + result.instance.index + ' rejected a supposedly valid block'); + console.log("NSP: SubmitBlock: Rejected"); + console.log(result); return; } } @@ -315,6 +319,9 @@ var pool = module.exports = function pool(options, authorizeFn){ before we emit the share, lets submit the block, then check if it was accepted using RPC getblock */ + console.log("NSP: OnShare: sharedata and blockhex following this"); + console.log(shareData); + console.log(blockHex); if (!isValidBlock) emitShare(); else{ @@ -329,6 +336,9 @@ var pool = module.exports = function pool(options, authorizeFn){ emitLog('Block notification via RPC after block submission'); }); + console.log("NSP: CheckBlockAccepted called: "); + console.log(isAccepted); + }); }); } diff --git a/lib/util.js b/lib/util.js index 79df1af61..e9f77690d 100644 --- a/lib/util.js +++ b/lib/util.js @@ -24,9 +24,9 @@ exports.getVersionByte = function(addr){ }; exports.sha256 = function(buffer){ - console.log('RUNNING NSP sha256 method'); var hash1 = crypto.createHash('sha256'); hash1.update(buffer); + console.log("Running sha256 on nsp: " + hash1); return hash1.digest(); }; From ebc30bb11d6568b4013346f001260b910d8a1025 Mon Sep 17 00:00:00 2001 From: Kristopher Klosterman Date: Wed, 12 Jul 2017 12:05:41 -0400 Subject: [PATCH 23/32] removed all the testing comments --- lib/jobManager.js | 16 ---------------- lib/pool.js | 10 ---------- lib/util.js | 1 - 3 files changed, 27 deletions(-) diff --git a/lib/jobManager.js b/lib/jobManager.js index 685fbd4cf..bb6d9cd8a 100644 --- a/lib/jobManager.js +++ b/lib/jobManager.js @@ -212,8 +212,6 @@ var JobManager = module.exports = function JobManager(options){ return shareError([22, 'duplicate share']); } - console.log(jobId + " | " + previousDifficulty + " | " + difficulty + " | " + extraNonce1 + " | " + extraNonce2 + " | " + nTime + " | " + nonce + " | " + ipAddress + " | " + port + " | " + workerName); - var extraNonce1Buffer = Buffer.from(extraNonce1, 'hex'); var extraNonce2Buffer = Buffer.from(extraNonce2, 'hex'); @@ -234,24 +232,10 @@ var JobManager = module.exports = function JobManager(options){ var blockDiffAdjusted = job.difficulty * shareMultiplier; - console.log(extraNonce1Buffer); - console.log(extraNonce2Buffer); - console.log(coinbaseBuffer); - console.log(coinbaseHash); - console.log(merkleRoot); - console.log(headerBuffer); - console.log(headerHash); - console.log(headerBigNum); - console.log(shareDiff); - console.log(blockDiffAdjusted); - //Check if share is a block candidate (matched network difficulty) - console.log("Job Target: " + job.target); if (job.target.ge(headerBigNum)){ blockHex = job.serializeBlock(headerBuffer, coinbaseBuffer).toString('hex'); blockHash = blockHasher(headerBuffer, nTime).toString('hex'); - console.log(blockHex); - console.log(blockHash); } else { if (options.emitInvalidBlockHashes) diff --git a/lib/pool.js b/lib/pool.js index a7cf13549..af02f6977 100644 --- a/lib/pool.js +++ b/lib/pool.js @@ -224,8 +224,6 @@ var pool = module.exports = function pool(options, authorizeFn){ */ function SubmitBlock(blockHex, callback){ - console.log("SUBMIT BLOCK: BlockHex: " + blockHex) - var rpcCommand, rpcArgs; if (options.hasSubmitMethod){ rpcCommand = 'submitblock'; @@ -251,8 +249,6 @@ var pool = module.exports = function pool(options, authorizeFn){ } else if (result.response === 'rejected') { emitErrorLog('Daemon instance ' + result.instance.index + ' rejected a supposedly valid block'); - console.log("NSP: SubmitBlock: Rejected"); - console.log(result); return; } } @@ -319,9 +315,6 @@ var pool = module.exports = function pool(options, authorizeFn){ before we emit the share, lets submit the block, then check if it was accepted using RPC getblock */ - console.log("NSP: OnShare: sharedata and blockhex following this"); - console.log(shareData); - console.log(blockHex); if (!isValidBlock) emitShare(); else{ @@ -336,9 +329,6 @@ var pool = module.exports = function pool(options, authorizeFn){ emitLog('Block notification via RPC after block submission'); }); - console.log("NSP: CheckBlockAccepted called: "); - console.log(isAccepted); - }); }); } diff --git a/lib/util.js b/lib/util.js index e9f77690d..6f93b2d47 100644 --- a/lib/util.js +++ b/lib/util.js @@ -26,7 +26,6 @@ exports.getVersionByte = function(addr){ exports.sha256 = function(buffer){ var hash1 = crypto.createHash('sha256'); hash1.update(buffer); - console.log("Running sha256 on nsp: " + hash1); return hash1.digest(); }; From 239db54abbe19a7c8bec50e1e6aca80c990b1b69 Mon Sep 17 00:00:00 2001 From: Kristopher Klosterman Date: Wed, 12 Jul 2017 13:30:05 -0400 Subject: [PATCH 24/32] More error testing... --- lib/pool.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/pool.js b/lib/pool.js index af02f6977..92f5d8ef9 100644 --- a/lib/pool.js +++ b/lib/pool.js @@ -568,6 +568,7 @@ var pool = module.exports = function pool(options, authorizeFn){ _this.daemon.cmd('getblocktemplate', [{"capabilities": [ "coinbasetxn", "workid", "coinbase/append" ], "rules": [ "segwit" ]}], function(result){ + console.log(result); if (result.error){ emitErrorLog('getblocktemplate call failed for daemon instance ' + result.instance.index + ' with error ' + JSON.stringify(result.error)); From b3b4cd1a33a06f2a7eb2665c27f44afd3d7d7b66 Mon Sep 17 00:00:00 2001 From: Kristopher Klosterman Date: Wed, 12 Jul 2017 13:33:05 -0400 Subject: [PATCH 25/32] logging in the wrong place --- lib/pool.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pool.js b/lib/pool.js index 92f5d8ef9..0375721a8 100644 --- a/lib/pool.js +++ b/lib/pool.js @@ -568,8 +568,8 @@ var pool = module.exports = function pool(options, authorizeFn){ _this.daemon.cmd('getblocktemplate', [{"capabilities": [ "coinbasetxn", "workid", "coinbase/append" ], "rules": [ "segwit" ]}], function(result){ - console.log(result); if (result.error){ + console.log(result); emitErrorLog('getblocktemplate call failed for daemon instance ' + result.instance.index + ' with error ' + JSON.stringify(result.error)); callback(result.error); From 4ff88f70d0c38cd08893cc8ce74b223f7856a363 Mon Sep 17 00:00:00 2001 From: Kristopher Klosterman Date: Mon, 17 Jul 2017 10:54:59 -0400 Subject: [PATCH 26/32] testing updates --- lib/pool.js | 4 ++-- lib/stratum.js | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/pool.js b/lib/pool.js index 0375721a8..c12075a3d 100644 --- a/lib/pool.js +++ b/lib/pool.js @@ -231,7 +231,7 @@ var pool = module.exports = function pool(options, authorizeFn){ } else{ rpcCommand = 'getblocktemplate'; - rpcArgs = [{'mode': 'submit', 'data': blockHex}]; + rpcArgs = [{'mode': 'submit', 'data': blockHex}]; // TODO: is mode submit even correct? } @@ -569,7 +569,7 @@ var pool = module.exports = function pool(options, authorizeFn){ [{"capabilities": [ "coinbasetxn", "workid", "coinbase/append" ], "rules": [ "segwit" ]}], function(result){ if (result.error){ - console.log(result); + console.log("GetBlockTemplate()", result); emitErrorLog('getblocktemplate call failed for daemon instance ' + result.instance.index + ' with error ' + JSON.stringify(result.error)); callback(result.error); diff --git a/lib/stratum.js b/lib/stratum.js index 02f2728e8..1bed2e42e 100644 --- a/lib/stratum.js +++ b/lib/stratum.js @@ -60,7 +60,9 @@ var StratumClient = function(options){ }; function handleMessage(message){ + //added mining.extranonce.subscribe TODO:: why does scryptn client send it this way? switch(message.method){ + //case 'mining.extranonce.subscribe': case 'mining.subscribe': handleSubscribe(message); break; From 8484c5af1ef093431241303b4905c8344c607ec5 Mon Sep 17 00:00:00 2001 From: Kristopher Klosterman Date: Wed, 19 Jul 2017 15:16:56 -0400 Subject: [PATCH 27/32] Added debuging for failed block submits --- lib/jobManager.js | 33 +++++++++++++++++++++++++++++++++ lib/util.js | 2 +- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/lib/jobManager.js b/lib/jobManager.js index bb6d9cd8a..d08786660 100644 --- a/lib/jobManager.js +++ b/lib/jobManager.js @@ -183,6 +183,18 @@ var JobManager = module.exports = function JobManager(options){ }); return {error: error, result: null}; }; + console.log("processShare - Stuff passed in", { + "jobId": jobId, + "previousDifficulty": previousDifficulty, + "difficulty": difficulty, + "extraNonce1": extraNonce1, + "extraNonce2": extraNonce2, + "nTime": nTime, + "nonce": nonce, + "ipAddress": ipAddress, + "port": port, + "workerName": workerName + }); var submitTime = Date.now() / 1000 | 0; @@ -232,10 +244,31 @@ var JobManager = module.exports = function JobManager(options){ var blockDiffAdjusted = job.difficulty * shareMultiplier; + console.log("processShare - Stuff calculated", { + "extraNonce1Buffer": extraNonce1Buffer, + "extraNonce2Buffer": extraNonce2Buffer, + "coinbaseBuffer": coinbaseBuffer, + "coinbaseHash": coinbaseHash, + "merkleRoot": merkleRoot, + "headerBuffer": headerBuffer, + "headerHash": headerHash, + "headerBigNum": headerBigNum, + "shareDiff": shareDiff, + "blockDiffAdjusted": blockDiffAdjusted + }); + + console.log("processShare - Globals", { + "job.target": job.target + }); + //Check if share is a block candidate (matched network difficulty) if (job.target.ge(headerBigNum)){ blockHex = job.serializeBlock(headerBuffer, coinbaseBuffer).toString('hex'); blockHash = blockHasher(headerBuffer, nTime).toString('hex'); + console.log("processShare - Block Candidate", { + "blockHex": blockHex, + "blockHash": blockHash + }); } else { if (options.emitInvalidBlockHashes) diff --git a/lib/util.js b/lib/util.js index 6f93b2d47..f233b480c 100644 --- a/lib/util.js +++ b/lib/util.js @@ -57,7 +57,7 @@ exports.uint256BufferFromHash = function(hex){ fromHex = Buffer.from(hex, 'hex'); } else { fromHex = Buffer.alloc(32); - fromHex.fill(0); + //fromHex.fill(0); This is not needed because it happens by default with .alloc } return exports.reverseBuffer(fromHex); From ac43b48e31fe06d81460a4068f6b38828eec2f49 Mon Sep 17 00:00:00 2001 From: Kristopher Klosterman Date: Mon, 7 Aug 2017 07:51:31 -0400 Subject: [PATCH 28/32] Removed Logging --- lib/jobManager.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/jobManager.js b/lib/jobManager.js index d08786660..07087e0f8 100644 --- a/lib/jobManager.js +++ b/lib/jobManager.js @@ -183,7 +183,7 @@ var JobManager = module.exports = function JobManager(options){ }); return {error: error, result: null}; }; - console.log("processShare - Stuff passed in", { + /*console.log("processShare - Stuff passed in", { "jobId": jobId, "previousDifficulty": previousDifficulty, "difficulty": difficulty, @@ -194,7 +194,7 @@ var JobManager = module.exports = function JobManager(options){ "ipAddress": ipAddress, "port": port, "workerName": workerName - }); + });*/ var submitTime = Date.now() / 1000 | 0; @@ -244,7 +244,7 @@ var JobManager = module.exports = function JobManager(options){ var blockDiffAdjusted = job.difficulty * shareMultiplier; - console.log("processShare - Stuff calculated", { + /*console.log("processShare - Stuff calculated", { "extraNonce1Buffer": extraNonce1Buffer, "extraNonce2Buffer": extraNonce2Buffer, "coinbaseBuffer": coinbaseBuffer, @@ -255,20 +255,20 @@ var JobManager = module.exports = function JobManager(options){ "headerBigNum": headerBigNum, "shareDiff": shareDiff, "blockDiffAdjusted": blockDiffAdjusted - }); + });*/ - console.log("processShare - Globals", { + /*console.log("processShare - Globals", { "job.target": job.target - }); + });*/ //Check if share is a block candidate (matched network difficulty) if (job.target.ge(headerBigNum)){ blockHex = job.serializeBlock(headerBuffer, coinbaseBuffer).toString('hex'); blockHash = blockHasher(headerBuffer, nTime).toString('hex'); - console.log("processShare - Block Candidate", { + /*console.log("processShare - Block Candidate", { "blockHex": blockHex, "blockHash": blockHash - }); + });*/ } else { if (options.emitInvalidBlockHashes) From a01db6ef4a5297100ec38e7bc483f92c10fa7fb5 Mon Sep 17 00:00:00 2001 From: Kristopher Klosterman Date: Tue, 15 Aug 2017 10:40:49 -0400 Subject: [PATCH 29/32] Added some more information around mining.extranounce.subscribe, testing first time --- lib/stratum.js | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/lib/stratum.js b/lib/stratum.js index 1bed2e42e..10641a2cb 100644 --- a/lib/stratum.js +++ b/lib/stratum.js @@ -60,11 +60,12 @@ var StratumClient = function(options){ }; function handleMessage(message){ - //added mining.extranonce.subscribe TODO:: why does scryptn client send it this way? switch(message.method){ - //case 'mining.extranonce.subscribe': + case 'mining.extranonce.subscribe': + handleExtraNounceSubscribe(message); case 'mining.subscribe': handleSubscribe(message); + console.log(message); break; case 'mining.authorize': handleAuthorize(message, true /*reply to socket*/); @@ -86,6 +87,23 @@ var StratumClient = function(options){ } } + function handleExtraNounceSubscribe(message) { + // Support for mining.extranonce.subscribe is currently not written. The client sends this to let the server know + // its supported, not handeling it is ok. The client first sends mining.subscribe, then send the extranounce command. + // It expects a return of the extranounce value and size if supported. + _this.emit('unknownStratumMethod', "Currently " + message + " is not supported, sending not support back to client."); + sendJson({ + id: message.id, + result: false, + "error": [20, "Not supported.", null] + }); + console.log({ + id: message.id, + result: false, + "error": [20, "Not supported.", null] + }); + } + function handleSubscribe(message){ if (! _this._authorized ) { _this.requestedSubscriptionBeforeAuth = true; From dcd68b3bbb43ffcdbded90871023e35d04d91e6e Mon Sep 17 00:00:00 2001 From: Kristopher Klosterman Date: Tue, 15 Aug 2017 10:55:42 -0400 Subject: [PATCH 30/32] Removed some buggy code, from last commit --- lib/stratum.js | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/lib/stratum.js b/lib/stratum.js index 10641a2cb..9377e5eab 100644 --- a/lib/stratum.js +++ b/lib/stratum.js @@ -61,11 +61,10 @@ var StratumClient = function(options){ function handleMessage(message){ switch(message.method){ - case 'mining.extranonce.subscribe': - handleExtraNounceSubscribe(message); + //case 'mining.extranonce.subscribe': + // handleExtraNounceSubscribe(message); case 'mining.subscribe': handleSubscribe(message); - console.log(message); break; case 'mining.authorize': handleAuthorize(message, true /*reply to socket*/); @@ -88,20 +87,17 @@ var StratumClient = function(options){ } function handleExtraNounceSubscribe(message) { + // TODO: Apparently even trying to catch this message causes low difficulty shares to be submitted by client, more investigation needed + // Support for mining.extranonce.subscribe is currently not written. The client sends this to let the server know // its supported, not handeling it is ok. The client first sends mining.subscribe, then send the extranounce command. // It expects a return of the extranounce value and size if supported. - _this.emit('unknownStratumMethod', "Currently " + message + " is not supported, sending not support back to client."); + //_this.emit('unknownStratumMethod', { method: "Currently " + message.method + " is not supported, sending not supported back to client." }); sendJson({ id: message.id, result: false, "error": [20, "Not supported.", null] }); - console.log({ - id: message.id, - result: false, - "error": [20, "Not supported.", null] - }); } function handleSubscribe(message){ From bef7181e5045055c282e20c73228553288321f2e Mon Sep 17 00:00:00 2001 From: Kristopher Klosterman Date: Wed, 16 Aug 2017 08:20:33 -0400 Subject: [PATCH 31/32] Added Scrypt Jane back in --- lib/algoProperties.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/algoProperties.js b/lib/algoProperties.js index cb3658e66..7725ee622 100644 --- a/lib/algoProperties.js +++ b/lib/algoProperties.js @@ -39,7 +39,7 @@ var algos = module.exports = global.algos = { } } }, - /*'scrypt-jane': { + 'scrypt-jane': { multiplier: Math.pow(2, 16), hash: function(coinConfig){ var nTimestamp = coinConfig.chainStartTime || 1367991200; @@ -49,7 +49,7 @@ var algos = module.exports = global.algos = { return multiHashing.scryptjane(data, nTime, nTimestamp, nMin, nMax); } } - },*/ + }, 'scrypt-n': { multiplier: Math.pow(2, 16), hash: function(coinConfig){ From fe4884366fa513079a8fc8d5e6adcad524f03d1b Mon Sep 17 00:00:00 2001 From: Vagabondan Date: Tue, 21 Nov 2017 23:15:55 +0300 Subject: [PATCH 32/32] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d1e3f589e..95cab00d9 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "async": "^2.5.0", "base58-native": "^0.1.4", "bignum": "^0.12.5", - "multi-hashing": "git://github.com/krisklosterman/node-multi-hashing.git" + "multi-hashing": "git://github.com/vagabondan/node-multi-hashing.git" }, "engines": { "node": ">=0.10"