-
Notifications
You must be signed in to change notification settings - Fork 120
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
Block Subsidy and Founders Reward Amounts #1051
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did some initial review, only about half of the PR but I think I left enough comments for you to make a bunch more progress before my next more comprehensive review.
Thanks @yaahc , that was great, specially the combinator suggestions that i have big troubles to implement on my own :) I will take care of all the changes. |
45f1af3
to
afc3fdc
Compare
Hi @oxarbitrage, just wondering if you'd like a detailed review here? It seems like the Canopy Funding Streams implementation isn't finished yet - do you want to focus on the Founders Reward in this PR, and do Funding Streams in a separate PR? I also noticed a few things that could improve the code:
|
97d6f31
to
88ded24
Compare
@teor2345 i was thinking on adding the formulas in latex from https://zips.z.cash/protocol/protocol.pdf#subsidies into the comments of the subsidy functions. let me know what do you think.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a lot of good work here - there are so many block subsidy rules to cover!
During my review, I tried to focus on the correctness of the code.
(the table was wrong, so I moved it to a later comment, and corrected it)
Here are some other things we can do to make sure the code is correct, and make it easier to read:
- use the appropriate types:
block::Height
andAmount<NonNegative>
- explain what each complex calculation does, and why it is accurate - this will be a lot easier once the calculations are split into separate functions
Please also choose a consistent name for the subsidy modules. At the moment, we have:
block::subsidies
parameters::subsidy
In this case, the standard term is subsidy
. (If there isn't a standard term, I try to use the singular name. That is, subsidy
rather than subsidies
.)
In regards to the use of Let me know what do you think about that @teor2345 as i maybe have something missing. Thanks. |
Adding |
zebra-consensus/src/block/check.rs
Outdated
@@ -90,5 +90,5 @@ pub fn subsidy_is_correct(network: Network, block: &Block) -> Result<(), BoxErro | |||
return Ok(()); | |||
} | |||
} | |||
Err("subsidy is not correct")? | |||
Err("validation of block subsidy rules inside coinbase transaction failed")? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We try to format errors as "error kind: conditions that caused the error".
The checks in the function are incomplete, so it is hard to write a good error description. Here is an error with all the checks that the function should do. As you can see, the error is very long.
So we should split up the checks for:
- the sum of the coinbase outputs, and
- the founders reward.
Since we want to check the founders reward for blocks 1..Canopy, but always check the coinbase output sum, these checks should be in different functions.
Err("validation of block subsidy rules inside coinbase transaction failed")? | |
Err("invalid coinbase transaction: the sum of the coinbase transaction outputs must be less than or equal to the block subsidy plus transaction fees, and the exact founders reward value must be sent as a single output to the correct address")? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't do the sum of coinbase outputs
check yet, so let's just check the founders reward, and error if it fails.
Then we can add a TODO and Ok(())
at the end of the function
How should we handle inexact divisions? I'd like to make them errors, so that we explicitly handle remainders in every calculation. Here's the list of operators I think we'll want for amount:
We should also implement the corresponding
Things we might want to implement - but let's wait and see if we need them:
Things we don't want to implement, because they are probably coding errors:
|
The rules table I originally posted was incomplete and incorrect. Here's my second attempt: Here is my understanding of the block subsidy rules from the spec - rules that we don't need to handle are in
This rules summary table can go in the module doc comment of the block subsidy module. In this PR, we'll implement the rules from:
Here's how we'll handle the rules from the other network upgrades:
I think it would be helpful to have functions for each different set of rules, and group those functions into modules. Then the top-level subsidy module can select the appropriate rules using a For example, we could have modules for:
|
Hey @oxarbitrage let me know when you're ready for another review. Can I do the review before you rebase on the latest main branch? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good!
I tried to suggest some type and calculation fixes, let me know if they don't work out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some updates based on our conversations over the last day
zebra-consensus/src/block/check.rs
Outdated
@@ -90,5 +90,5 @@ pub fn subsidy_is_correct(network: Network, block: &Block) -> Result<(), BoxErro | |||
return Ok(()); | |||
} | |||
} | |||
Err("subsidy is not correct")? | |||
Err("validation of block subsidy rules inside coinbase transaction failed")? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't do the sum of coinbase outputs
check yet, so let's just check the founders reward, and error if it fails.
Then we can add a TODO and Ok(())
at the end of the function
@oxarbitrage now that we have a stable design for
|
I think we are going to be comparing amounts more sooner than later so added the operators to do it at 7b0f166 |
I implemented in 453ad1f however having some issues to make them safe. I cant return a |
Try copying the implementations from: And changing the types. |
Co-authored-by: Jane Lusby <jlusby42@gmail.com>
Hey @oxarbitrage, I just realised that we're missing failure tests. Let's write a test for each error:
It should be easy to make these tests using It would also be good to make sure that we allow duplicate outputs, as long as at least one output passes - I'll put that on the tracking issue. I also:
|
Block subsidy: matches to if-elses
b4b39bf
to
2372341
Compare
Oops, I think we missed this PR - we still need a review from someone who isn't me or @oxarbitrage. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made a mistake with testnet funding stream activation, I'll fix it soon.
ZIP-1014 only applies to mainnet, where Canopy is at the first halving. On testnet, Canopy is before the first halving, and the dev fund rules apply from Canopy. (See ZIP-214.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is good to go, but I'd like to get someone else to look at the bits I wrote.
The last fix looks good, i think i already checked the rest. We should merge this one and IMHO, continue with the block subsidy design(#1129) and implement the rest of it in separated PRs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This PR calculates:
And checks:
We can't check the block subsidy yet, because we don't calculate miner fees in this PR.
Part of #338