-
Notifications
You must be signed in to change notification settings - Fork 168
Network Sustainability Mechanism - ZIP 234 & 235 implementation #8948
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
base: main
Are you sure you want to change the base?
Conversation
1ba587c to
bb23624
Compare
|
@mariopil Does this PR need to be refreshed when the NSM ZIPs are finalized? |
Yes. Currently, the implementation of both 234 and 235 zips is under one feature flag, but they will be covered by separate feature flags. |
conradoplg
left a comment
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.
This is a first pass review, I mostly looked into the feature gating and overall structure
| (block::Height(903_000), Heartwood), | ||
| (block::Height(1_046_400), Canopy), | ||
| (block::Height(1_687_104), Nu5), | ||
| // TODO: Update NU6 activation height once it's been specified. |
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.
| // TODO: Update NU6 activation height once it's been specified. |
zebra-chain/src/transaction.rs
Outdated
| #[cfg(zcash_unstable = "nsm")] | ||
| pub fn has_burn_amount(&self) -> bool { | ||
| self.burn_amount() > Amount::<NonNegative>::zero() | ||
| } |
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.
"burn" reference
| // > The NSM burn_amount field [ZIP-233] must be set at minimum to 60% of miner fees [ZIP-235]. | ||
| burn_amount: burn_amount.unwrap_or_else(|| ((miner_fee * 6).unwrap() / 10).unwrap()), |
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.
"burn" mentioned
| let orchard_shielded_data = (&mut limited_reader).zcash_deserialize_into()?; | ||
|
|
||
| // Denoted as `burn_amount` in the spec. | ||
| let burn_amount = (&mut limited_reader).zcash_deserialize_into()?; |
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.
"burn" mentioned
| .field(&"private") | ||
| .finish(), | ||
| Witnessed(_id) => f.debug_tuple("WtxId").field(&"private").finish(), | ||
| Witnessed(id) => f.debug_tuple("WtxId").field(id).finish(), |
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.
| Witnessed(id) => f.debug_tuple("WtxId").field(id).finish(), | |
| Witnessed(_id) => f.debug_tuple("WtxId").field(&"private").finish(), |
Please don't change unrelated code
| // We can't get the block subsidy for blocks with heights in the slow start interval, so we | ||
| // omit the calculation of the expected deferred amount. | ||
| let expected_deferred_amount = if height > self.network.slow_start_interval() { | ||
| // See [ZIP-1015](https://zips.z.cash/zip-1015). | ||
| funding_stream_values(height, &self.network, block_subsidy(height, &self.network)?)? | ||
| .remove(&FundingStreamReceiver::Deferred) | ||
| } else { | ||
| None | ||
| }; | ||
|
|
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.
Why was this removed?
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.
Moved to zebra-state/src/service/write.rs write, write_blocks_from_channels().
zebra-consensus/src/transaction.rs
Outdated
| // Get the `value_balance` to calculate the transaction fee. | ||
| let value_balance = tx.value_balance(&spent_utxos); | ||
|
|
||
| let burn_amount = match *tx { |
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.
"burn" mentioned
zebra-consensus/src/transaction.rs
Outdated
|
|
||
| let burn_amount = match *tx { | ||
| #[cfg(zcash_unstable = "nsm")] | ||
| Transaction::ZFuture{ .. } => tx.burn_amount(), |
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.
"burn" mentioned - sorry, at this point it's better for you to simply search for all instances of it
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.
Yeah, we've only just submitted PRs to adjust the ZIPs. We've not adjusted this code yet, especially since only 233 is targeted for inclusion in NU7.
| block_time in datetime_full(), | ||
| relative_source_fund_heights in vec(0.0..1.0, 1..=MAX_TRANSPARENT_INPUTS), | ||
| transaction_version in 4_u8..=5, | ||
| transaction_version in 4_u8..=6, |
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.
Needs to be feature-gated
| finalized_state: &ZebraDb, | ||
| non_finalized_state: &mut NonFinalizedState, | ||
| prepared: SemanticallyVerifiedBlock, | ||
| prepared: &mut SemanticallyVerifiedBlock, |
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.
Document what is modified in the block
bb23624 to
640d321
Compare
|
Needs rebasing/conflict solving |
640d321 to
63aab29
Compare
| /// > transaction as the first transaction in the block. | ||
| /// | ||
| /// <https://zips.z.cash/protocol/protocol.pdf#coinbasetransactions> | ||
| pub fn coinbase_is_first(block: &Block) -> Result<Arc<transaction::Transaction>, BlockError> { |
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.
Moved to zebra-state/src/service/check.rs
| /// Returns `Ok(())` if the miner fees consensus rule is valid. | ||
| /// | ||
| /// [7.1.2]: https://zips.z.cash/protocol/protocol.pdf#txnconsensus | ||
| pub fn miner_fees_are_valid( |
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.
Moved to zebra-state/src/service/check.rs
| /// the block subsidy in `block` is valid for `network` | ||
| /// | ||
| /// [3.9]: https://zips.z.cash/protocol/protocol.pdf#subsidyconcepts | ||
| pub fn subsidy_is_valid( |
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.
Moved to zebra-state/src/service/check.rs
63aab29 to
20a4f8f
Compare
|
The PR has been rebased and updated |
Motivation
This PR implements ZIP-234 and ZIP-235.
Specifications & References
ZIP-234, ZIP-235
Solution
This PR is implemented above #8930 which implements the ZIP-233. It smoothes the issuance curve (ZIP-234) and introduces the split between miner fees (40%) and the amount that is burned (60%, ZIP-235). Some of the code used in the block semantical verification for block subsidy calculation has been moved into the write task, as now the block subsidy calculation relies on the current amount of
money_reservewhich is obtained from pool value balance atheight-1- therefore the previous block must be already present at least in the non-finalized best chain.Tests
For testing purposes, a local testnet network was set up. It contained two nodes—a zebra and a zcashd one (with the ZIP-234 & 235 implemented, too, PR zcash/zcash#6970). A transaction in a new format containing the
burn_amountfield was created and added to the block by zcashd. The zebra node synced with zcashd without any errors and accepted the block.A couple of unit tests were also added.
Follow-up Work
PR Author's Checklist
PR Reviewer's Checklist