-
Notifications
You must be signed in to change notification settings - Fork 117
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
Network Sustainability Mechanism - ZIP 234 & 235 implementation #8948
base: main
Are you sure you want to change the base?
Conversation
ce2eedd
to
4029650
Compare
… get_block_template RPC call.
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. |
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
@@ -89,7 +109,10 @@ pub(super) const MAINNET_ACTIVATION_HEIGHTS: &[(block::Height, NetworkUpgrade)] | |||
(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. |
#[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
@@ -124,7 +124,7 @@ impl fmt::Display for UnminedTxId { | |||
.debug_tuple("transaction::Hash") | |||
.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()
.
@@ -444,17 +458,21 @@ where | |||
// 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
@@ -444,17 +458,21 @@ where | |||
// Get the `value_balance` to calculate the transaction fee. | |||
let value_balance = tx.value_balance(&spent_utxos); | |||
|
|||
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.
@@ -29,7 +29,7 @@ proptest! { | |||
(network, block_height) in sapling_onwards_strategy(), | |||
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
@@ -49,15 +55,15 @@ const PARENT_ERROR_MAP_LIMIT: usize = MAX_BLOCK_REORG_HEIGHT as usize * 2; | |||
pub(crate) fn validate_and_commit_non_finalized( | |||
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
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_reserve
which 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_amount
field 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