Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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
3 changes: 3 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
# Flags that apply to all Zebra crates and configurations
[target.'cfg(all())']
rustflags = [
# FIXME: Consider removing this line later (it's needed for the ZSA version of librustzcash crates)
"--cfg", "zcash_unstable=\"nu6\"",

# Zebra standard lints for Rust 1.65+

# High-risk code
Expand Down
4 changes: 2 additions & 2 deletions zebra-chain/src/block/commitment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ impl Commitment {
// NetworkUpgrade::current() returns the latest network upgrade that's activated at the provided height, so
// on Regtest for heights above height 0, it could return NU6, and it's possible for the current network upgrade
// to be NU6 (or Canopy, or any network upgrade above Heartwood) at the Heartwood activation height.
(Canopy | Nu5 | Nu6, activation_height)
(Canopy | Nu5 | Nu6 | Nu7, activation_height)
if height == activation_height
&& Some(height) == Heartwood.activation_height(network) =>
{
Expand All @@ -136,7 +136,7 @@ impl Commitment {
}
}
(Heartwood | Canopy, _) => Ok(ChainHistoryRoot(ChainHistoryMmrRootHash(bytes))),
(Nu5 | Nu6, _) => Ok(ChainHistoryBlockTxAuthCommitment(
(Nu5 | Nu6 | Nu7, _) => Ok(ChainHistoryBlockTxAuthCommitment(
ChainHistoryBlockTxAuthCommitmentHash(bytes),
)),
}
Expand Down
4 changes: 2 additions & 2 deletions zebra-chain/src/history_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ impl NonEmptyHistoryTree {
)?;
InnerHistoryTree::PreOrchard(tree)
}
NetworkUpgrade::Nu5 | NetworkUpgrade::Nu6 => {
NetworkUpgrade::Nu5 | NetworkUpgrade::Nu6 | NetworkUpgrade::Nu7 => {
let tree = Tree::<OrchardOnward>::new_from_cache(
network,
network_upgrade,
Expand Down Expand Up @@ -156,7 +156,7 @@ impl NonEmptyHistoryTree {
)?;
(InnerHistoryTree::PreOrchard(tree), entry)
}
NetworkUpgrade::Nu5 | NetworkUpgrade::Nu6 => {
NetworkUpgrade::Nu5 | NetworkUpgrade::Nu6 | NetworkUpgrade::Nu7 => {
let (tree, entry) = Tree::<OrchardOnward>::new_from_block(
network,
block,
Expand Down
2 changes: 2 additions & 0 deletions zebra-chain/src/parameters/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,12 @@ impl Network {
pub fn new_regtest(
nu5_activation_height: Option<u32>,
nu6_activation_height: Option<u32>,
nu7_activation_height: Option<u32>,
) -> Self {
Self::new_configured_testnet(testnet::Parameters::new_regtest(
nu5_activation_height,
nu6_activation_height,
nu7_activation_height,
))
}

Expand Down
10 changes: 9 additions & 1 deletion zebra-chain/src/parameters/network/testnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,9 @@ pub struct ConfiguredActivationHeights {
/// Activation height for `NU6` network upgrade.
#[serde(rename = "NU6")]
pub nu6: Option<u32>,
/// Activation height for `NU7` network upgrade.
#[serde(rename = "NU7")]
pub nu7: Option<u32>,
}

/// Builder for the [`Parameters`] struct.
Expand Down Expand Up @@ -336,6 +339,7 @@ impl ParametersBuilder {
canopy,
nu5,
nu6,
nu7,
}: ConfiguredActivationHeights,
) -> Self {
use NetworkUpgrade::*;
Expand All @@ -358,6 +362,7 @@ impl ParametersBuilder {
.chain(canopy.into_iter().map(|h| (h, Canopy)))
.chain(nu5.into_iter().map(|h| (h, Nu5)))
.chain(nu6.into_iter().map(|h| (h, Nu6)))
.chain(nu7.into_iter().map(|h| (h, Nu7)))
.map(|(h, nu)| (h.try_into().expect("activation height must be valid"), nu))
.collect();

Expand Down Expand Up @@ -588,6 +593,7 @@ impl Parameters {
pub fn new_regtest(
nu5_activation_height: Option<u32>,
nu6_activation_height: Option<u32>,
nu7_activation_height: Option<u32>,
) -> Self {
#[cfg(any(test, feature = "proptest-impl"))]
let nu5_activation_height = nu5_activation_height.or(Some(100));
Expand All @@ -604,6 +610,7 @@ impl Parameters {
canopy: Some(1),
nu5: nu5_activation_height,
nu6: nu6_activation_height,
nu7: nu7_activation_height,
..Default::default()
})
.with_halving_interval(PRE_BLOSSOM_REGTEST_HALVING_INTERVAL);
Expand Down Expand Up @@ -647,7 +654,7 @@ impl Parameters {
disable_pow,
pre_blossom_halving_interval,
post_blossom_halving_interval,
} = Self::new_regtest(None, None);
} = Self::new_regtest(None, None, None);

self.network_name == network_name
&& self.genesis_hash == genesis_hash
Expand Down Expand Up @@ -780,6 +787,7 @@ impl Network {

/// Returns post-Canopy funding streams for this network at the provided height
pub fn funding_streams(&self, height: Height) -> &FundingStreams {
// FIXME: Would this work after Nu7 activation?
if NetworkUpgrade::current(self, height) < NetworkUpgrade::Nu6 {
self.pre_nu6_funding_streams()
} else {
Expand Down
6 changes: 3 additions & 3 deletions zebra-chain/src/parameters/network/tests/vectors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ fn activates_network_upgrades_correctly() {
let expected_activation_height = 1;
let network = testnet::Parameters::build()
.with_activation_heights(ConfiguredActivationHeights {
nu6: Some(expected_activation_height),
nu7: Some(expected_activation_height),
..Default::default()
})
.to_network();
Expand Down Expand Up @@ -147,7 +147,7 @@ fn activates_network_upgrades_correctly() {
(Network::Mainnet, MAINNET_ACTIVATION_HEIGHTS),
(Network::new_default_testnet(), TESTNET_ACTIVATION_HEIGHTS),
(
Network::new_regtest(None, None),
Network::new_regtest(None, None, None),
expected_default_regtest_activation_heights,
),
] {
Expand Down Expand Up @@ -198,7 +198,7 @@ fn check_configured_network_name() {
"Mainnet should be displayed as 'Mainnet'"
);
assert_eq!(
Network::new_regtest(None, None).to_string(),
Network::new_regtest(None, None, None).to_string(),
"Regtest",
"Regtest should be displayed as 'Regtest'"
);
Expand Down
27 changes: 24 additions & 3 deletions zebra-chain/src/parameters/network_upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use hex::{FromHex, ToHex};
use proptest_derive::Arbitrary;

/// A list of network upgrades in the order that they must be activated.
pub const NETWORK_UPGRADES_IN_ORDER: [NetworkUpgrade; 9] = [
pub const NETWORK_UPGRADES_IN_ORDER: [NetworkUpgrade; 10] = [
Genesis,
BeforeOverwinter,
Overwinter,
Expand All @@ -25,6 +25,7 @@ pub const NETWORK_UPGRADES_IN_ORDER: [NetworkUpgrade; 9] = [
Canopy,
Nu5,
Nu6,
Nu7,
];

/// A Zcash network upgrade.
Expand Down Expand Up @@ -61,6 +62,9 @@ pub enum NetworkUpgrade {
/// The Zcash protocol after the NU6 upgrade.
#[serde(rename = "NU6")]
Nu6,
/// The Zcash protocol after the NU7 upgrade.
#[serde(rename = "NU7")]
Nu7,
}

impl fmt::Display for NetworkUpgrade {
Expand Down Expand Up @@ -90,6 +94,9 @@ pub(super) const MAINNET_ACTIVATION_HEIGHTS: &[(block::Height, NetworkUpgrade)]
(block::Height(1_046_400), Canopy),
(block::Height(1_687_104), Nu5),
(block::Height(2_726_400), Nu6),
// FIXME: TODO: Use a proper value below.
#[cfg(zcash_unstable = "nu6" /* TODO nu7 */ )]
(block::Height(3_111_000), Nu7),
];

/// Fake mainnet network upgrade activation heights, used in tests.
Expand All @@ -104,6 +111,7 @@ const FAKE_MAINNET_ACTIVATION_HEIGHTS: &[(block::Height, NetworkUpgrade)] = &[
(block::Height(30), Canopy),
(block::Height(35), Nu5),
(block::Height(40), Nu6),
(block::Height(45), Nu7),
];

/// Testnet network upgrade activation heights.
Expand All @@ -126,6 +134,9 @@ pub(super) const TESTNET_ACTIVATION_HEIGHTS: &[(block::Height, NetworkUpgrade)]
(block::Height(1_028_500), Canopy),
(block::Height(1_842_420), Nu5),
(block::Height(2_976_000), Nu6),
// FIXME: TODO: Use a proper value below.
#[cfg(zcash_unstable = "nu6" /* TODO nu7 */ )]
(block::Height(3_222_000), Nu7),
];

/// Fake testnet network upgrade activation heights, used in tests.
Expand All @@ -140,6 +151,7 @@ const FAKE_TESTNET_ACTIVATION_HEIGHTS: &[(block::Height, NetworkUpgrade)] = &[
(block::Height(30), Canopy),
(block::Height(35), Nu5),
(block::Height(40), Nu6),
(block::Height(45), Nu7),
];

/// The Consensus Branch Id, used to bind transactions and blocks to a
Expand Down Expand Up @@ -222,6 +234,9 @@ pub(crate) const CONSENSUS_BRANCH_IDS: &[(NetworkUpgrade, ConsensusBranchId)] =
(Canopy, ConsensusBranchId(0xe9ff75a6)),
(Nu5, ConsensusBranchId(0xc2d6d0b4)),
(Nu6, ConsensusBranchId(0xc8e71055)),
// FIXME: TODO: Use a proper value below.
#[cfg(zcash_unstable = "nu6" /* TODO nu7 */ )]
(Nu7, ConsensusBranchId(0x77190ad8)),
];

/// The target block spacing before Blossom.
Expand Down Expand Up @@ -338,7 +353,8 @@ impl NetworkUpgrade {
Heartwood => Some(Canopy),
Canopy => Some(Nu5),
Nu5 => Some(Nu6),
Nu6 => None,
Nu6 => Some(Nu7),
Nu7 => None,
}
}

Expand Down Expand Up @@ -415,7 +431,9 @@ impl NetworkUpgrade {
pub fn target_spacing(&self) -> Duration {
let spacing_seconds = match self {
Genesis | BeforeOverwinter | Overwinter | Sapling => PRE_BLOSSOM_POW_TARGET_SPACING,
Blossom | Heartwood | Canopy | Nu5 | Nu6 => POST_BLOSSOM_POW_TARGET_SPACING.into(),
Blossom | Heartwood | Canopy | Nu5 | Nu6 | Nu7 => {
POST_BLOSSOM_POW_TARGET_SPACING.into()
}
};

Duration::seconds(spacing_seconds)
Expand Down Expand Up @@ -537,6 +555,9 @@ impl From<zcash_protocol::consensus::NetworkUpgrade> for NetworkUpgrade {
zcash_protocol::consensus::NetworkUpgrade::Canopy => Self::Canopy,
zcash_protocol::consensus::NetworkUpgrade::Nu5 => Self::Nu5,
zcash_protocol::consensus::NetworkUpgrade::Nu6 => Self::Nu6,
// FIXME: TODO: Use a proper value below.
#[cfg(zcash_unstable = "nu6" /* TODO nu7 */ )]
zcash_protocol::consensus::NetworkUpgrade::Nu7 => Self::Nu7,
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion zebra-chain/src/primitives/zcash_history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,8 @@ impl Version for zcash_history::V1 {
NetworkUpgrade::Heartwood
| NetworkUpgrade::Canopy
| NetworkUpgrade::Nu5
| NetworkUpgrade::Nu6 => zcash_history::NodeData {
| NetworkUpgrade::Nu6
| NetworkUpgrade::Nu7 => zcash_history::NodeData {
consensus_branch_id: branch_id.into(),
subtree_commitment: block_hash,
start_time: time,
Expand Down
2 changes: 1 addition & 1 deletion zebra-chain/src/transaction/arbitrary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ impl Arbitrary for Transaction {
NetworkUpgrade::Blossom | NetworkUpgrade::Heartwood | NetworkUpgrade::Canopy => {
Self::v4_strategy(ledger_state)
}
NetworkUpgrade::Nu5 | NetworkUpgrade::Nu6 => prop_oneof![
NetworkUpgrade::Nu5 | NetworkUpgrade::Nu6 | NetworkUpgrade::Nu7 => prop_oneof![
Self::v4_strategy(ledger_state.clone()),
Self::v5_strategy(ledger_state)
]
Expand Down
1 change: 1 addition & 0 deletions zebra-consensus/src/block/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ pub fn miner_fees_are_valid(
// input.
//
// > [NU6 onward] The total output of a coinbase transaction MUST be equal to its total input.
// FIXME: Would this work after Nu7 activation?
if if NetworkUpgrade::current(network, height) < NetworkUpgrade::Nu6 {
total_output_value > total_input_value
} else {
Expand Down
1 change: 1 addition & 0 deletions zebra-consensus/src/block/subsidy/funding_streams/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::block::subsidy::general::block_subsidy;
use super::*;

/// Checks that the Mainnet funding stream values are correct.
// FIXME: Would this work after Nu7 activation?
#[test]
fn test_funding_stream_values() -> Result<(), Report> {
let _init_guard = zebra_test::init();
Expand Down
2 changes: 1 addition & 1 deletion zebra-consensus/src/checkpoint/list/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ fn checkpoint_list_load_hard_coded() -> Result<(), BoxError> {

let _ = Mainnet.checkpoint_list();
let _ = Network::new_default_testnet().checkpoint_list();
let _ = Network::new_regtest(None, None).checkpoint_list();
let _ = Network::new_regtest(None, None, None).checkpoint_list();

Ok(())
}
Expand Down
5 changes: 3 additions & 2 deletions zebra-consensus/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,8 @@ where
| NetworkUpgrade::Heartwood
| NetworkUpgrade::Canopy
| NetworkUpgrade::Nu5
| NetworkUpgrade::Nu6 => Ok(()),
| NetworkUpgrade::Nu6
| NetworkUpgrade::Nu7 => Ok(()),

// Does not support V4 transactions
NetworkUpgrade::Genesis
Expand Down Expand Up @@ -910,7 +911,7 @@ where
//
// Note: Here we verify the transaction version number of the above rule, the group
// id is checked in zebra-chain crate, in the transaction serialize.
NetworkUpgrade::Nu5 | NetworkUpgrade::Nu6 => Ok(()),
NetworkUpgrade::Nu5 | NetworkUpgrade::Nu6 | NetworkUpgrade::Nu7 => Ok(()),

// Does not support V5 transactions
NetworkUpgrade::Genesis
Expand Down
3 changes: 2 additions & 1 deletion zebra-consensus/src/transaction/tests/prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,8 @@ fn sanitize_transaction_version(
BeforeOverwinter => 2,
Overwinter => 3,
Sapling | Blossom | Heartwood | Canopy => 4,
Nu5 | Nu6 => 5,
// FIXME: Use 6 for Nu7
Nu5 | Nu6 | Nu7 => 5,
}
};

Expand Down
17 changes: 11 additions & 6 deletions zebra-network/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -668,12 +668,17 @@ impl<'de> Deserialize<'de> for Config {
(NetworkKind::Mainnet, _) => Network::Mainnet,
(NetworkKind::Testnet, None) => Network::new_default_testnet(),
(NetworkKind::Regtest, testnet_parameters) => {
let (nu5_activation_height, nu6_activation_height) = testnet_parameters
.and_then(|params| params.activation_heights)
.map(|ConfiguredActivationHeights { nu5, nu6, .. }| (nu5, nu6))
.unwrap_or_default();

Network::new_regtest(nu5_activation_height, nu6_activation_height)
let (nu5_activation_height, nu6_activation_height, nu7_activation_height) =
testnet_parameters
.and_then(|params| params.activation_heights)
.map(|ConfiguredActivationHeights { nu5, nu6, nu7, .. }| (nu5, nu6, nu7))
.unwrap_or_default();

Network::new_regtest(
nu5_activation_height,
nu6_activation_height,
nu7_activation_height,
)
}
(
NetworkKind::Testnet,
Expand Down
4 changes: 4 additions & 0 deletions zebra-network/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,10 @@ pub const TIMESTAMP_TRUNCATION_SECONDS: u32 = 30 * 60;
///
/// This version of Zebra draws the current network protocol version from
/// [ZIP-253](https://zips.z.cash/zip-0253).
#[cfg(not(zcash_unstable = "nu6" /* TODO nu7 */ ))]
pub const CURRENT_NETWORK_PROTOCOL_VERSION: Version = Version(170_120);
#[cfg(zcash_unstable = "nu6" /* TODO nu7 */ )]
pub const CURRENT_NETWORK_PROTOCOL_VERSION: Version = Version(170_140);

/// The default RTT estimate for peer responses.
///
Expand Down Expand Up @@ -398,6 +401,7 @@ lazy_static! {
/// Testnet network upgrades.
// TODO: Change `Nu6` to `Nu7` after NU7 activation.
// TODO: Move the value here to a field on `testnet::Parameters` (#8367)
// TODO: FIXME: Change `Nu...` to `Nu7` after NU7 activation?
pub static ref INITIAL_MIN_NETWORK_PROTOCOL_VERSION: HashMap<NetworkKind, Version> = {
let mut hash_map = HashMap::new();

Expand Down
10 changes: 8 additions & 2 deletions zebra-network/src/protocol/external/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ impl Version {
(Mainnet, Nu5) => 170_100,
(Testnet(params), Nu6) if params.is_default_testnet() => 170_110,
(Mainnet, Nu6) => 170_120,
#[cfg(zcash_unstable = "nu6" /* TODO nu7 */ )]
(Testnet(params), Nu7) if params.is_default_testnet() => 170_130,
#[cfg(zcash_unstable = "nu6" /* TODO nu7 */ )]
(Mainnet, Nu7) => 170_140,

// It should be fine to reject peers with earlier network protocol versions on custom testnets for now.
(Testnet(_), _) => CURRENT_NETWORK_PROTOCOL_VERSION.0,
Expand Down Expand Up @@ -205,8 +209,9 @@ mod test {
let _init_guard = zebra_test::init();

let highest_network_upgrade = NetworkUpgrade::current(network, block::Height::MAX);
assert!(highest_network_upgrade == Nu6 || highest_network_upgrade == Nu5,
"expected coverage of all network upgrades: add the new network upgrade to the list in this test");
assert!(
highest_network_upgrade == Nu7 || highest_network_upgrade == Nu6 || highest_network_upgrade == Nu5,
"expected coverage of all network upgrades: add the new network upgrade to the list in this test");

for &network_upgrade in &[
BeforeOverwinter,
Expand All @@ -217,6 +222,7 @@ mod test {
Canopy,
Nu5,
Nu6,
Nu7,
] {
let height = network_upgrade.activation_height(network);
if let Some(height) = height {
Expand Down
Loading
Loading