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

Network Sustainability Mechanism - ZIP 234 & 235 implementation #8948

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

mariopil
Copy link

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 at height-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

  • The PR name will make sense to users.
  • The PR provides a CHANGELOG summary.
  • The solution is tested.
  • The documentation is up to date.
  • The PR has a priority label.

PR Reviewer's Checklist

  • The PR Author's checklist is complete.
  • The PR resolves the issue.

@mariopil mariopil requested review from a team as code owners October 18, 2024 13:14
@mariopil mariopil requested review from upbqdn and removed request for a team October 18, 2024 13:14
@mpguerra mpguerra requested review from conradoplg and arya2 October 21, 2024 07:40
@arya2 arya2 added the do-not-merge Tells Mergify not to merge this PR label Oct 26, 2024
@arya2 arya2 removed the do-not-merge Tells Mergify not to merge this PR label Dec 7, 2024
@mpguerra mpguerra added the no-review-reminders Turn off review reminders label Jan 13, 2025
@jackgavigan
Copy link
Contributor

jackgavigan commented Jan 16, 2025

@mariopil Does this PR need to be refreshed when the NSM ZIPs are finalized?

@mariopil
Copy link
Author

@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.

Copy link
Collaborator

@conradoplg conradoplg left a 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.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
// TODO: Update NU6 activation height once it's been specified.

Comment on lines +309 to +312
#[cfg(zcash_unstable = "nsm")]
pub fn has_burn_amount(&self) -> bool {
self.burn_amount() > Amount::<NonNegative>::zero()
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

"burn" reference

Comment on lines +121 to +122
// > 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()),
Copy link
Collaborator

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()?;
Copy link
Collaborator

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(),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
Witnessed(id) => f.debug_tuple("WtxId").field(id).finish(),
Witnessed(_id) => f.debug_tuple("WtxId").field(&"private").finish(),

Please don't change unrelated code

Comment on lines -611 to -620
// 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
};

Copy link
Collaborator

Choose a reason for hiding this comment

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

Why was this removed?

Copy link
Author

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 {
Copy link
Collaborator

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(),
Copy link
Collaborator

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

Copy link

@giddie giddie Jan 17, 2025

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,
Copy link
Collaborator

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,
Copy link
Collaborator

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

@oxarbitrage oxarbitrage added do-not-merge Tells Mergify not to merge this PR and removed do-not-merge Tells Mergify not to merge this PR labels Feb 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-review-reminders Turn off review reminders
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants