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 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
226 changes: 79 additions & 147 deletions Cargo.lock

Large diffs are not rendered by default.

17 changes: 9 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@ resolver = "2"
incrementalmerkletree = "0.7.0"
orchard = "0.9.0"
sapling-crypto = "0.2.0"
zcash_address = "0.5.0"
zcash_client_backend = "0.13.0"
zcash_encoding = "0.2.1"
zcash_history = "0.4.0"
zcash_keys = "0.3.0"
zcash_primitives = "0.17.0"
zcash_proofs = "0.17.0"
zcash_protocol = "0.3.0"
# TODO: Revert to a release once librustzcash is released (#8749).
zcash_address = { git = "https://github.com/ShieldedLabs/librustzcash/", branch = "nsm-zebra" }
zcash_client_backend = { git = "https://github.com/ShieldedLabs/librustzcash/", branch = "nsm-zebra" }
zcash_encoding = { git = "https://github.com/ShieldedLabs/librustzcash/", branch = "nsm-zebra" }
zcash_history = { git = "https://github.com/ShieldedLabs/librustzcash/", branch = "nsm-zebra" }
zcash_keys = { git = "https://github.com/ShieldedLabs/librustzcash/", branch = "nsm-zebra" }
zcash_primitives = { git = "https://github.com/ShieldedLabs/librustzcash/", branch = "nsm-zebra" }
zcash_proofs = { git = "https://github.com/ShieldedLabs/librustzcash/", branch = "nsm-zebra" }
zcash_protocol = { git = "https://github.com/ShieldedLabs/librustzcash/", branch = "nsm-zebra" }

[workspace.metadata.release]

Expand Down
5 changes: 5 additions & 0 deletions zebra-chain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ categories = ["asynchronous", "cryptography::cryptocurrencies", "encoding"]
[features]
default = []

nsm = []

# Production features that activate extra functionality

# Consensus-critical conversion from JSON to Zcash types
Expand Down Expand Up @@ -178,3 +180,6 @@ required-features = ["bench"]
[[bench]]
name = "redpallas"
harness = false

[lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(zcash_unstable, values("nsm"))'] }
2 changes: 1 addition & 1 deletion zebra-chain/src/amount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ impl Constraint for NonNegative {
/// -MAX_MONEY..=0,
/// );
/// ```
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Default)]
pub struct NegativeOrZero;

impl Constraint for NegativeOrZero {
Expand Down
3 changes: 2 additions & 1 deletion zebra-chain/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ use crate::{
};

mod commitment;
mod error;
mod hash;
mod header;
mod height;
mod serialize;

pub mod error;
pub mod genesis;
pub mod merkle;
pub mod subsidy;

#[cfg(any(test, feature = "proptest-impl"))]
pub mod arbitrary;
Expand Down
4 changes: 4 additions & 0 deletions zebra-chain/src/block/commitment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ impl Commitment {
(Nu5 | Nu6, _) => Ok(ChainHistoryBlockTxAuthCommitment(
ChainHistoryBlockTxAuthCommitmentHash(bytes),
)),
#[cfg(zcash_unstable = "nsm")]
(ZFuture, _) => Ok(ChainHistoryBlockTxAuthCommitment(
ChainHistoryBlockTxAuthCommitmentHash(bytes),
)),
}
}

Expand Down
15 changes: 14 additions & 1 deletion zebra-chain/src/block/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,22 @@

use thiserror::Error;

use crate::error::SubsidyError;

#[cfg(any(test, feature = "proptest-impl"))]
use proptest_derive::Arbitrary;

#[derive(Clone, Error, Debug, PartialEq, Eq)]
#[cfg_attr(any(test, feature = "proptest-impl"), derive(Arbitrary))]
#[allow(missing_docs)]
#[derive(Error, Debug, PartialEq, Eq)]
pub enum BlockError {
#[error("block has no transactions")]
NoTransactions,

#[error("transaction has wrong consensus branch id for block network upgrade")]
WrongTransactionConsensusBranchId,

#[error("block failed subsidy validation")]
#[cfg_attr(any(test, feature = "proptest-impl"), proptest(skip))]
Subsidy(#[from] SubsidyError),
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use std::collections::HashMap;

use zebra_chain::{
use crate::{
amount::{Amount, Error, NonNegative},
block::Height,
parameters::{subsidy::*, Network, NetworkUpgrade::*},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
//! Tests for funding streams.

use color_eyre::Report;
use zebra_chain::parameters::{
subsidy::FundingStreamReceiver,
testnet::{
self, ConfiguredActivationHeights, ConfiguredFundingStreamRecipient,
ConfiguredFundingStreams,

use crate::{
block::subsidy::general::block_subsidy_pre_nsm,
parameters::{
subsidy::FundingStreamReceiver,
testnet::{
self, ConfiguredActivationHeights, ConfiguredFundingStreamRecipient,
ConfiguredFundingStreams,
},
NetworkKind,
},
NetworkKind,
};

use crate::block::subsidy::general::block_subsidy;

use super::*;

/// Check mainnet funding stream values are correct for the entire period.
Expand All @@ -26,7 +28,7 @@ fn test_funding_stream_values() -> Result<(), Report> {
assert!(funding_stream_values(
canopy_height_minus1,
network,
block_subsidy(canopy_height_minus1, network)?
block_subsidy_pre_nsm(canopy_height_minus1, network)?
)?
.is_empty());

Expand All @@ -50,7 +52,7 @@ fn test_funding_stream_values() -> Result<(), Report> {
funding_stream_values(
canopy_height,
network,
block_subsidy(canopy_height, network)?
block_subsidy_pre_nsm(canopy_height, network)?
)
.unwrap(),
hash_map
Expand All @@ -60,7 +62,7 @@ fn test_funding_stream_values() -> Result<(), Report> {
funding_stream_values(
canopy_height_plus1,
network,
block_subsidy(canopy_height_plus1, network)?
block_subsidy_pre_nsm(canopy_height_plus1, network)?
)
.unwrap(),
hash_map
Expand All @@ -70,7 +72,7 @@ fn test_funding_stream_values() -> Result<(), Report> {
funding_stream_values(
canopy_height_plus2,
network,
block_subsidy(canopy_height_plus2, network)?
block_subsidy_pre_nsm(canopy_height_plus2, network)?
)
.unwrap(),
hash_map
Expand All @@ -82,11 +84,11 @@ fn test_funding_stream_values() -> Result<(), Report> {
let last = (end - 1).unwrap();

assert_eq!(
funding_stream_values(last, network, block_subsidy(last, network)?).unwrap(),
funding_stream_values(last, network, block_subsidy_pre_nsm(last, network)?).unwrap(),
hash_map
);

assert!(funding_stream_values(end, network, block_subsidy(end, network)?)?.is_empty());
assert!(funding_stream_values(end, network, block_subsidy_pre_nsm(end, network)?)?.is_empty());

// TODO: Replace this with Mainnet once there's an NU6 activation height defined for Mainnet
let network = testnet::Parameters::build()
Expand Down Expand Up @@ -137,7 +139,8 @@ fn test_funding_stream_values() -> Result<(), Report> {
Height(nu6_height.0 + 1),
] {
assert_eq!(
funding_stream_values(height, &network, block_subsidy(height, &network)?).unwrap(),
funding_stream_values(height, &network, block_subsidy_pre_nsm(height, &network)?)
.unwrap(),
hash_map
);
}
Expand Down Expand Up @@ -191,7 +194,8 @@ fn test_funding_stream_values() -> Result<(), Report> {
Height(nu6_height.0 + 1),
] {
assert_eq!(
funding_stream_values(height, &network, block_subsidy(height, &network)?).unwrap(),
funding_stream_values(height, &network, block_subsidy_pre_nsm(height, &network)?)
.unwrap(),
hash_map
);
}
Expand Down
Loading
Loading