From a6f4cdc50abb7ae7685f9acd492f29a9291bbd4d Mon Sep 17 00:00:00 2001 From: MaxHero Date: Fri, 22 Sep 2017 11:41:54 +0300 Subject: [PATCH] adaptation for minexcoin equihash verifier --- lib/blockTemplate.js | 9 +--- lib/jobManager.js | 6 +-- lib/pool.js | 4 +- lib/stratum.js | 12 ++--- lib/transactions.js | 104 +++++++++++++------------------------------ package.json | 10 ++--- 6 files changed, 48 insertions(+), 97 deletions(-) diff --git a/lib/blockTemplate.js b/lib/blockTemplate.js index 7c1f8db..43e92a1 100644 --- a/lib/blockTemplate.js +++ b/lib/blockTemplate.js @@ -23,14 +23,7 @@ var BlockTemplate = module.exports = function BlockTemplate(jobId, rpcData, extr this.difficulty = parseFloat((diff1 / this.target.toNumber()).toFixed(9)); // generate the fees and coinbase tx - var blockReward = (this.rpcData.miner) * 100000000; - if (payFoundersReward === true) { - if (!this.rpcData.founders || this.rpcData.founders.length <= 0) { - console.log('Error, founders reward missing for block template!'); - } else { - blockReward = (this.rpcData.miner + this.rpcData.founders) * 100000000; - } - } + var blockReward = 250000000; var fees = []; rpcData.transactions.forEach(function(value) { diff --git a/lib/jobManager.js b/lib/jobManager.js index edf91c4..2fc33d4 100644 --- a/lib/jobManager.js +++ b/lib/jobManager.js @@ -209,7 +209,7 @@ var JobManager = module.exports = function JobManager(options) { return shareError([20, 'incorrect size of nonce']); } - if (soln.length !== 2694) { + if (soln.length !== 138) { return shareError([20, 'incorrect size of solution']); } @@ -224,7 +224,7 @@ var JobManager = module.exports = function JobManager(options) { var extraNonce1Buffer = new Buffer(extraNonce1, 'hex'); var extraNonce2Buffer = new Buffer(extraNonce2, 'hex'); - var headerBuffer = job.serializeHeader(nTime, nonce); // 144 bytes (doesn't contain soln) + var headerBuffer = job.serializeHeader(nTime, nonce); // 140 bytes (doesn't contain soln) var headerSolnBuffer = new Buffer.concat([headerBuffer, new Buffer(soln, 'hex')]); var headerHash = util.sha256d(headerSolnBuffer); var headerBigNum = bignum.fromBuffer(headerHash, {endian: 'little', size: 32}); @@ -237,7 +237,7 @@ var JobManager = module.exports = function JobManager(options) { var blockDiffAdjusted = job.difficulty * shareMultiplier; // check if valid solution - if (hashDigest(headerBuffer, new Buffer(soln.slice(6), 'hex')) !== true) { + if (hashDigest(headerBuffer, new Buffer(soln.slice(2), 'hex')) !== true) { return shareError([20, 'invalid solution']); } //check if block candidate diff --git a/lib/pool.js b/lib/pool.js index d518f3f..b7715a6 100644 --- a/lib/pool.js +++ b/lib/pool.js @@ -583,8 +583,8 @@ var pool = module.exports = function pool(options, authorizeFn) { result.instance.index + ' with error ' + JSON.stringify(result.error)); callback(result.error); } else { - result.response.miner = subsidy.miner; - result.response.founders = (subsidy.founders || subsidy.community); + result.response.miner = 2.5; + result.response.founders = 0; var processedNewBlock = _this.jobManager.processTemplate(result.response); callback(null, result.response, processedNewBlock); callback = function () { diff --git a/lib/stratum.js b/lib/stratum.js index f029d00..a8d0d4c 100644 --- a/lib/stratum.js +++ b/lib/stratum.js @@ -127,11 +127,13 @@ var StratumClient = function(options){ options.authorizeFn(_this.remoteAddress, options.socket.localPort, _this.workerName, _this.workerPass, function(result) { _this.authorized = (!result.error && result.authorized); - sendJson({ - id : message.id, - result : _this.authorized, - error : result.error - }); + //Due to mxMinex disconnects on pool authorize confirmation, we don't send confirmation. + //TODO: fix when miner software would be implemented. + // sendJson({ + // id : message.id, + // result : _this.authorized, + // error : result.error + // }); // If the authorizer wants us to close the socket lets do it. if (result.disconnect === true) { diff --git a/lib/transactions.js b/lib/transactions.js index e4340f5..76987dd 100644 --- a/lib/transactions.js +++ b/lib/transactions.js @@ -20,16 +20,25 @@ function scriptCompile(addrHash){ return script; } -function scriptFoundersCompile(address){ - script = bitcoin.script.compile( - [ - bitcoin.opcodes.OP_HASH160, - address, - bitcoin.opcodes.OP_EQUAL - ]); - return script; +function minexBankRewardCompute(blockHeight, totalReward) { + if (blockHeight <= 4500000) { + /** + * 1- 900000 20% + * 900001-1800000 30% + * 1800001-2700000 40% + * 2700001-3600000 50% + * 3600001-4500000 60% + */ + return Math.floor(totalReward / 10) * (2 + Math.floor((blockHeight - 1) / 900000)); + } + + //4500001-∞ 70% + return Math.floor(totalReward / 10) * 7; } +function minexBankScriptCompile() { + return new Buffer('2103ae6efe9458f1d3bdd9a458b1970eabbdf9fcb1357e0dff2744a777ff43c391eeac', 'hex'); +} exports.createGeneration = function(blockHeight, blockReward, feeReward, recipients, poolAddress, payFoundersReward, percentFoundersReward, maxFoundersRewardBlockHeight, foundersRewardAddressChangeInterval, vFoundersRewardAddress, percentTreasuryReward, treasuryRewardStartBlockHeight, treasuryRewardAddressChangeInterval, vTreasuryRewardAddress){ var poolAddrHash = bitcoin.address.fromBase58Check(poolAddress).hash; @@ -60,74 +69,21 @@ exports.createGeneration = function(blockHeight, blockReward, feeReward, recipie Buffer('5a2d4e4f4d50212068747470733a2f2f6769746875622e636f6d2f6a6f7368756179616275742f7a2d6e6f6d70', 'hex')]) //Z-NOMP! https://github.com/joshuayabut/z-nomp ); - // calculate total fees - var feePercent = 0; - for (var i = 0; i < recipients.length; i++) { - feePercent = feePercent + recipients[i].percent; - } + var totalReward = blockReward + feeReward; + var minexbankReward = minexBankRewardCompute(blockHeight, totalReward); + var poolReward = totalReward - minexbankReward; - // txs with founders reward - if (payFoundersReward === true && (maxFoundersRewardBlockHeight >= blockHeight || treasuryRewardStartBlockHeight)) { - - // founders or treasury reward? - if (treasuryRewardStartBlockHeight && blockHeight >= treasuryRewardStartBlockHeight) { - - // treasury reward - var index = parseInt(Math.floor(((blockHeight - treasuryRewardStartBlockHeight) / treasuryRewardAddressChangeInterval) % vTreasuryRewardAddress.length)); - var foundersAddrHash = bitcoin.address.fromBase58Check(vTreasuryRewardAddress[index]).hash; - - //console.log("treasuryIndex: "+index); - //console.log("treasuryAddr: "+vTreasuryRewardAddress[index]); - - // pool t-addr - tx.addOutput( - scriptCompile(poolAddrHash), - Math.round(blockReward * (1 - (percentTreasuryReward + feePercent) / 100)) + feeReward - ); - // treasury t-addr - tx.addOutput( - scriptFoundersCompile(foundersAddrHash), - Math.round(blockReward * (percentTreasuryReward / 100)) - ); - - } else { - - // founders reward - var index = parseInt(Math.floor(blockHeight / foundersRewardAddressChangeInterval)); - var foundersAddrHash = bitcoin.address.fromBase58Check(vFoundersRewardAddress[index]).hash; - - //console.log("foundersIndex: "+index); - //console.log("foundersAddr: "+vFoundersRewardAddress[index]); - - // pool t-addr - tx.addOutput( - scriptCompile(poolAddrHash), - Math.round(blockReward * (1 - (percentFoundersReward + feePercent) / 100)) + feeReward - ); - // founders t-addr - tx.addOutput( - scriptFoundersCompile(foundersAddrHash), - Math.round(blockReward * (percentFoundersReward / 100)) - ); - } - } - // no founders rewards :) - else - { - // pool t-addr - tx.addOutput( - scriptCompile(poolAddrHash), - Math.round(blockReward * (1 - (feePercent / 100))) + feeReward - ); - } + //pool + tx.addOutput( + scriptCompile(poolAddrHash), + poolReward + ); - // pool fee recipients t-addr - for (var i = 0; i < recipients.length; i++) { - tx.addOutput( - scriptCompile(bitcoin.address.fromBase58Check(recipients[i].address).hash), - Math.round(blockReward * (recipients[i].percent / 100)) - ); - } + //minexbank + tx.addOutput( + minexBankScriptCompile(), + minexbankReward + ); txHex = tx.toHex(); diff --git a/package.json b/package.json index d91c70f..51cc5e5 100644 --- a/package.json +++ b/package.json @@ -12,9 +12,9 @@ "litecoin", "scrypt" ], - "homepage": "https://github.com/joshuayabut/node-stratum-pool", + "homepage": "https://github.com/MaxHero/minex-node-stratum-pool", "bugs": { - "url": "https://github.com/joshuayabut/node-stratum-pool/issues" + "url": "https://github.com/MaxHero/minex-node-stratum-pool/issues" }, "license": "GPL-2.0", "author": "Matthew Little", @@ -25,15 +25,15 @@ "main": "lib/index.js", "repository": { "type": "git", - "url": "https://github.com/joshuayabut/node-stratum-pool.git" + "url": "https://github.com/MaxHero/minex-node-stratum-pool.git" }, "dependencies": { - "equihashverify": "git+https://github.com/joshuayabut/equihashverify.git", + "equihashverify": "git+https://github.com/MaxHero/minexequihashverify.git", "bignum": "*", "base58-native": "*", "async": "*", "merkle-bitcoin": "git+https://github.com/joshuayabut/merkle-bitcoin.git", - "bitcoinjs-lib-zcash": "git+https://github.com/runn1ng/bitcoinjs-lib.git#zcash", + "bitcoinjs-lib-zcash": "git+https://github.com/MaxHero/bitcoinjs-lib.git#minexcoin", "promise": "*" }, "engines": {