Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix block rewards calculations #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Try larrys patch
benzcash committed Dec 12, 2019
commit ea4bb04bd95e6eb5d2f9ed4ea3d87fae95ee580d
23 changes: 15 additions & 8 deletions lib/blocks.js
Original file line number Diff line number Diff line change
@@ -135,7 +135,7 @@ BlockController.prototype.transformBlock = function(block, info) {
confirmations: info.confirmations,
previousblockhash: this._normalizePrevHash(blockObj.header.prevHash),
nextblockhash: info.nextHash,
reward: this.getBlockReward(info.height) / 1e8,
reward: this.getBlockReward(info.height, isMainChain) / 1e8,
isMainChain: (info.confirmations !== -1),
poolInfo: this.getPoolInfo(block)
};
@@ -330,7 +330,7 @@ BlockController.prototype.formatTimestamp = function(date) {
return yyyy + '-' + (mm[1] ? mm : '0' + mm[0]) + '-' + (dd[1] ? dd : '0' + dd[0]); //padding
};

BlockController.prototype.getBlockReward = function(height) {
BlockController.prototype.getBlockReward = function(height, isMainChain) {
var subsidy = new BN(12.5 * 1e8);

// Mining slow start
@@ -347,17 +347,24 @@ BlockController.prototype.getBlockReward = function(height) {
}

var halvings = Math.floor((height - (20000/2)) / 840000);

// Adjust for Blossom (see zcash src/chainparams.cpp)
if (isMainChain) { // mainnet
if (height >= 653600) {
halvings++;
}
} else { // testnet
if (height >= 584000) {
halvings++;
}
}

// Force block reward to zero when right shift is undefined.
if (halvings >= 64) {
return 0;
}

// If we've actived blossom, cut the reward in half
// https://github.com/zcash/zips/blob/master/zip-0208.rst
if (height > 653600) {
subsidy /= 2;

}

// Subsidy is cut in half every 840,000 blocks which will occur approximately every 4 years.
subsidy = subsidy.shrn(halvings);