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

Conversation

benzcash
Copy link

@LarryRuane
Copy link
Collaborator

closes zcash/zcash#4117

@LarryRuane
Copy link
Collaborator

There are a few simple getBlockReward tests in test/blocks.js, but they've never been updated from bitcoin to zcash. There are probably other tests that similarly haven't been updated for zcash. So it's probably okay to not update the getBlockReward() tests as part of this PR since the test suite probably doesn't currently run anyway. It's easy to manually test this change, and we probably need not be concerned about regressions in this code since it so seldom changes.

On the other hand, it wouldn't be hard to update the tests. What do people think?

Copy link
Collaborator

@LarryRuane LarryRuane left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK

lib/blocks.js Outdated
@@ -352,6 +352,12 @@ BlockController.prototype.getBlockReward = function(height) {
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) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition should be greater-or-equal.

lib/blocks.js Outdated
// 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;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this way of dividing by 2 would work as well as incrementing halvings as I proposed. I guess it's a matter of taste; I'm fine either way. (Also, of course, this would have to be conditional on testnet versus mainnet.)

@benzcash
Copy link
Author

I applied these changes to the testnet explorer.
https://explorer.testnet.z.cash/block/003b958bc18c1df92976650f049cd17b409773ac6758ffb9ebdb275d1b722a74

Can anyone spot check the Block Rewards and let me know if it looks good?

@LarryRuane @daira @mdr0id 🙏

Copy link

@daira daira left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK modulo comment.

@@ -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, (info.confirmations !== -1)) / 1e8,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there no better way to get which network we're on than this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants