Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions lib/blockTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions lib/jobManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}

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

Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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": {
Expand Down