Skip to content

Commit e6dc3b6

Browse files
PaulLauxdmidemarya2upbqdn
authored
NU7 constants (ZcashFoundation#9256)
* Introduce Nu7 * Introduce Nu7 fo other crates of Zebra * Fix of new_regtest call (as it additionally needs Nu7 arg now) * Fix of new_regtest call (as it additionally needs Nu7 arg now) (2) * Set Nu7 as a network update for testnet in zebra-chain network tests * Fix serde names for NU7 * Update test snapshot in zebra-rpc to use NU7 * Copy Nu7-related changes from zsa-integration-state * Uncomment zcash_unstable = nu7 * Fix Nu7 constants and add cfg(zcash_unstable ...) attribute according to PR #15 review comments * Update network constant values according to PR #15 review comments * Add zcash_unstable=nu6 Rust flag to .cargo/config.toml to use nu6 by default * Add zcash_unstable = nu6 cfg in zebra-network/.../types.rs * Fix nu7 activation heights in network_upgrade.rs (nu6 value + 1 does not work - causes a test failure) * Add cfg for CURRENT_NETWORK_PROTOCOL_VERSION constant definition, add FIXMEs for a couple of Nu6 processing cases, add processing of Nu7 * Update get_blockchain_info@testnet_10.snap * Update get_blockchain_info@mainnet_10.snap * updated cfg flag * remove `zcash_unstable` flag * Remove testnet and mainnet NU7 activation heights, comment out consensus branch id and conversion to zcash primitives nu type * Yep, it'll work after NU7 * Yep, the test should work fine after NU7 * Yep, it only needs to be a post-nu6 height. * other fixes and cleanups * Updates snapshots, removes unnecessary FIXMEs, fixes issues with bad merge conflict resolution * fixes test hang when there are NUs defined without activation heights * fixes test, applies suggestion from code review. * Enable consensus branch ID for Nu7 --------- Co-authored-by: Dmitry Demin <[email protected]> Co-authored-by: Arya <[email protected]> Co-authored-by: Marek <[email protected]>
1 parent 9002cfc commit e6dc3b6

File tree

22 files changed

+86
-68
lines changed

22 files changed

+86
-68
lines changed

zebra-chain/src/block/commitment.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ impl Commitment {
125125
// NetworkUpgrade::current() returns the latest network upgrade that's activated at the provided height, so
126126
// on Regtest for heights above height 0, it could return NU6, and it's possible for the current network upgrade
127127
// to be NU6 (or Canopy, or any network upgrade above Heartwood) at the Heartwood activation height.
128-
(Canopy | Nu5 | Nu6, activation_height)
128+
(Canopy | Nu5 | Nu6 | Nu7, activation_height)
129129
if height == activation_height
130130
&& Some(height) == Heartwood.activation_height(network) =>
131131
{
@@ -136,7 +136,7 @@ impl Commitment {
136136
}
137137
}
138138
(Heartwood | Canopy, _) => Ok(ChainHistoryRoot(ChainHistoryMmrRootHash(bytes))),
139-
(Nu5 | Nu6, _) => Ok(ChainHistoryBlockTxAuthCommitment(
139+
(Nu5 | Nu6 | Nu7, _) => Ok(ChainHistoryBlockTxAuthCommitment(
140140
ChainHistoryBlockTxAuthCommitmentHash(bytes),
141141
)),
142142
}

zebra-chain/src/history_tree.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ impl NonEmptyHistoryTree {
102102
)?;
103103
InnerHistoryTree::PreOrchard(tree)
104104
}
105-
NetworkUpgrade::Nu5 | NetworkUpgrade::Nu6 => {
105+
NetworkUpgrade::Nu5 | NetworkUpgrade::Nu6 | NetworkUpgrade::Nu7 => {
106106
let tree = Tree::<OrchardOnward>::new_from_cache(
107107
network,
108108
network_upgrade,
@@ -156,7 +156,7 @@ impl NonEmptyHistoryTree {
156156
)?;
157157
(InnerHistoryTree::PreOrchard(tree), entry)
158158
}
159-
NetworkUpgrade::Nu5 | NetworkUpgrade::Nu6 => {
159+
NetworkUpgrade::Nu5 | NetworkUpgrade::Nu6 | NetworkUpgrade::Nu7 => {
160160
let (tree, entry) = Tree::<OrchardOnward>::new_from_block(
161161
network,
162162
block,

zebra-chain/src/parameters/network.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,10 @@ impl Network {
149149

150150
/// Creates a new [`Network::Testnet`] with `Regtest` parameters and the provided network upgrade activation heights.
151151
pub fn new_regtest(
152-
nu5_activation_height: Option<u32>,
153-
nu6_activation_height: Option<u32>,
152+
configured_activation_heights: testnet::ConfiguredActivationHeights,
154153
) -> Self {
155154
Self::new_configured_testnet(testnet::Parameters::new_regtest(
156-
nu5_activation_height,
157-
nu6_activation_height,
155+
configured_activation_heights,
158156
))
159157
}
160158

zebra-chain/src/parameters/network/subsidy.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ impl FundingStreamReceiver {
7777
/// [ZIP-1014]: https://zips.z.cash/zip-1014#abstract
7878
/// [`zcashd`]: https://github.com/zcash/zcash/blob/3f09cfa00a3c90336580a127e0096d99e25a38d6/src/consensus/funding.cpp#L13-L32
7979
/// [ZIP-1015]: https://zips.z.cash/zip-1015
80-
pub fn info(&self, is_nu6: bool) -> (&'static str, &'static str) {
81-
if is_nu6 {
80+
pub fn info(&self, is_post_nu6: bool) -> (&'static str, &'static str) {
81+
if is_post_nu6 {
8282
(
8383
match self {
8484
FundingStreamReceiver::Ecc => "Electric Coin Company",

zebra-chain/src/parameters/network/testnet.rs

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -118,35 +118,24 @@ impl From<&BTreeMap<Height, NetworkUpgrade>> for ConfiguredActivationHeights {
118118
let mut configured_activation_heights = ConfiguredActivationHeights::default();
119119

120120
for (height, network_upgrade) in activation_heights.iter() {
121-
match network_upgrade {
121+
let field = match network_upgrade {
122122
NetworkUpgrade::BeforeOverwinter => {
123-
configured_activation_heights.before_overwinter = Some(height.0);
124-
}
125-
NetworkUpgrade::Overwinter => {
126-
configured_activation_heights.overwinter = Some(height.0);
127-
}
128-
NetworkUpgrade::Sapling => {
129-
configured_activation_heights.sapling = Some(height.0);
130-
}
131-
NetworkUpgrade::Blossom => {
132-
configured_activation_heights.blossom = Some(height.0);
133-
}
134-
NetworkUpgrade::Heartwood => {
135-
configured_activation_heights.heartwood = Some(height.0);
136-
}
137-
NetworkUpgrade::Canopy => {
138-
configured_activation_heights.canopy = Some(height.0);
139-
}
140-
NetworkUpgrade::Nu5 => {
141-
configured_activation_heights.nu5 = Some(height.0);
142-
}
143-
NetworkUpgrade::Nu6 => {
144-
configured_activation_heights.nu6 = Some(height.0);
123+
&mut configured_activation_heights.before_overwinter
145124
}
125+
NetworkUpgrade::Overwinter => &mut configured_activation_heights.overwinter,
126+
NetworkUpgrade::Sapling => &mut configured_activation_heights.sapling,
127+
NetworkUpgrade::Blossom => &mut configured_activation_heights.blossom,
128+
NetworkUpgrade::Heartwood => &mut configured_activation_heights.heartwood,
129+
NetworkUpgrade::Canopy => &mut configured_activation_heights.canopy,
130+
NetworkUpgrade::Nu5 => &mut configured_activation_heights.nu5,
131+
NetworkUpgrade::Nu6 => &mut configured_activation_heights.nu6,
132+
NetworkUpgrade::Nu7 => &mut configured_activation_heights.nu7,
146133
NetworkUpgrade::Genesis => {
147134
continue;
148135
}
149-
}
136+
};
137+
138+
*field = Some(height.0)
150139
}
151140

152141
configured_activation_heights
@@ -271,6 +260,9 @@ pub struct ConfiguredActivationHeights {
271260
/// Activation height for `NU6` network upgrade.
272261
#[serde(rename = "NU6")]
273262
pub nu6: Option<u32>,
263+
/// Activation height for `NU7` network upgrade.
264+
#[serde(rename = "NU7")]
265+
pub nu7: Option<u32>,
274266
}
275267

276268
/// Builder for the [`Parameters`] struct.
@@ -405,6 +397,7 @@ impl ParametersBuilder {
405397
canopy,
406398
nu5,
407399
nu6,
400+
nu7,
408401
}: ConfiguredActivationHeights,
409402
) -> Self {
410403
use NetworkUpgrade::*;
@@ -427,6 +420,7 @@ impl ParametersBuilder {
427420
.chain(canopy.into_iter().map(|h| (h, Canopy)))
428421
.chain(nu5.into_iter().map(|h| (h, Nu5)))
429422
.chain(nu6.into_iter().map(|h| (h, Nu6)))
423+
.chain(nu7.into_iter().map(|h| (h, Nu7)))
430424
.map(|(h, nu)| (h.try_into().expect("activation height must be valid"), nu))
431425
.collect();
432426

@@ -672,11 +666,10 @@ impl Parameters {
672666
///
673667
/// Creates an instance of [`Parameters`] with `Regtest` values.
674668
pub fn new_regtest(
675-
nu5_activation_height: Option<u32>,
676-
nu6_activation_height: Option<u32>,
669+
ConfiguredActivationHeights { nu5, nu6, nu7, .. }: ConfiguredActivationHeights,
677670
) -> Self {
678671
#[cfg(any(test, feature = "proptest-impl"))]
679-
let nu5_activation_height = nu5_activation_height.or(Some(100));
672+
let nu5 = nu5.or(Some(100));
680673

681674
let parameters = Self::build()
682675
.with_genesis_hash(REGTEST_GENESIS_HASH)
@@ -689,8 +682,9 @@ impl Parameters {
689682
// most network upgrades are disabled by default for Regtest in zcashd
690683
.with_activation_heights(ConfiguredActivationHeights {
691684
canopy: Some(1),
692-
nu5: nu5_activation_height,
693-
nu6: nu6_activation_height,
685+
nu5,
686+
nu6,
687+
nu7,
694688
..Default::default()
695689
})
696690
.with_halving_interval(PRE_BLOSSOM_REGTEST_HALVING_INTERVAL);
@@ -735,7 +729,7 @@ impl Parameters {
735729
should_allow_unshielded_coinbase_spends,
736730
pre_blossom_halving_interval,
737731
post_blossom_halving_interval,
738-
} = Self::new_regtest(None, None);
732+
} = Self::new_regtest(Default::default());
739733

740734
self.network_name == network_name
741735
&& self.genesis_hash == genesis_hash

zebra-chain/src/parameters/network/tests/vectors.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ fn activates_network_upgrades_correctly() {
107107
let expected_activation_height = 1;
108108
let network = testnet::Parameters::build()
109109
.with_activation_heights(ConfiguredActivationHeights {
110-
nu6: Some(expected_activation_height),
110+
nu7: Some(expected_activation_height),
111111
..Default::default()
112112
})
113113
.to_network();
@@ -145,7 +145,7 @@ fn activates_network_upgrades_correctly() {
145145
(Network::Mainnet, MAINNET_ACTIVATION_HEIGHTS),
146146
(Network::new_default_testnet(), TESTNET_ACTIVATION_HEIGHTS),
147147
(
148-
Network::new_regtest(None, None),
148+
Network::new_regtest(Default::default()),
149149
expected_default_regtest_activation_heights,
150150
),
151151
] {
@@ -196,7 +196,7 @@ fn check_configured_network_name() {
196196
"Mainnet should be displayed as 'Mainnet'"
197197
);
198198
assert_eq!(
199-
Network::new_regtest(None, None).to_string(),
199+
Network::new_regtest(Default::default()).to_string(),
200200
"Regtest",
201201
"Regtest should be displayed as 'Regtest'"
202202
);

zebra-chain/src/parameters/network_upgrade.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use hex::{FromHex, ToHex};
1515
use proptest_derive::Arbitrary;
1616

1717
/// A list of network upgrades in the order that they must be activated.
18-
const NETWORK_UPGRADES_IN_ORDER: [NetworkUpgrade; 9] = [
18+
const NETWORK_UPGRADES_IN_ORDER: [NetworkUpgrade; 10] = [
1919
Genesis,
2020
BeforeOverwinter,
2121
Overwinter,
@@ -25,6 +25,7 @@ const NETWORK_UPGRADES_IN_ORDER: [NetworkUpgrade; 9] = [
2525
Canopy,
2626
Nu5,
2727
Nu6,
28+
Nu7,
2829
];
2930

3031
/// A Zcash network upgrade.
@@ -61,6 +62,9 @@ pub enum NetworkUpgrade {
6162
/// The Zcash protocol after the NU6 upgrade.
6263
#[serde(rename = "NU6")]
6364
Nu6,
65+
/// The Zcash protocol after the NU7 upgrade.
66+
#[serde(rename = "NU7")]
67+
Nu7,
6468
}
6569

6670
impl TryFrom<u32> for NetworkUpgrade {
@@ -116,6 +120,7 @@ const FAKE_MAINNET_ACTIVATION_HEIGHTS: &[(block::Height, NetworkUpgrade)] = &[
116120
(block::Height(30), Canopy),
117121
(block::Height(35), Nu5),
118122
(block::Height(40), Nu6),
123+
(block::Height(45), Nu7),
119124
];
120125

121126
/// Testnet network upgrade activation heights.
@@ -243,6 +248,7 @@ pub(crate) const CONSENSUS_BRANCH_IDS: &[(NetworkUpgrade, ConsensusBranchId)] =
243248
(Canopy, ConsensusBranchId(0xe9ff75a6)),
244249
(Nu5, ConsensusBranchId(0xc2d6d0b4)),
245250
(Nu6, ConsensusBranchId(0xc8e71055)),
251+
(Nu7, ConsensusBranchId(0x77190ad8)),
246252
];
247253

248254
/// The target block spacing before Blossom.
@@ -431,7 +437,9 @@ impl NetworkUpgrade {
431437
pub fn target_spacing(&self) -> Duration {
432438
let spacing_seconds = match self {
433439
Genesis | BeforeOverwinter | Overwinter | Sapling => PRE_BLOSSOM_POW_TARGET_SPACING,
434-
Blossom | Heartwood | Canopy | Nu5 | Nu6 => POST_BLOSSOM_POW_TARGET_SPACING.into(),
440+
Blossom | Heartwood | Canopy | Nu5 | Nu6 | Nu7 => {
441+
POST_BLOSSOM_POW_TARGET_SPACING.into()
442+
}
435443
};
436444

437445
Duration::seconds(spacing_seconds)
@@ -550,6 +558,7 @@ impl From<zcash_protocol::consensus::NetworkUpgrade> for NetworkUpgrade {
550558
zcash_protocol::consensus::NetworkUpgrade::Canopy => Self::Canopy,
551559
zcash_protocol::consensus::NetworkUpgrade::Nu5 => Self::Nu5,
552560
zcash_protocol::consensus::NetworkUpgrade::Nu6 => Self::Nu6,
561+
// zcash_protocol::consensus::NetworkUpgrade::Nu7 => Self::Nu7,
553562
}
554563
}
555564
}

zebra-chain/src/primitives/zcash_history.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,8 @@ impl Version for zcash_history::V1 {
276276
NetworkUpgrade::Heartwood
277277
| NetworkUpgrade::Canopy
278278
| NetworkUpgrade::Nu5
279-
| NetworkUpgrade::Nu6 => zcash_history::NodeData {
279+
| NetworkUpgrade::Nu6
280+
| NetworkUpgrade::Nu7 => zcash_history::NodeData {
280281
consensus_branch_id: branch_id.into(),
281282
subtree_commitment: block_hash,
282283
start_time: time,

zebra-chain/src/transaction/arbitrary.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,7 @@ impl Arbitrary for Transaction {
778778
NetworkUpgrade::Blossom | NetworkUpgrade::Heartwood | NetworkUpgrade::Canopy => {
779779
Self::v4_strategy(ledger_state)
780780
}
781-
NetworkUpgrade::Nu5 | NetworkUpgrade::Nu6 => prop_oneof![
781+
NetworkUpgrade::Nu5 | NetworkUpgrade::Nu6 | NetworkUpgrade::Nu7 => prop_oneof![
782782
Self::v4_strategy(ledger_state.clone()),
783783
Self::v5_strategy(ledger_state)
784784
]

zebra-consensus/src/checkpoint/list/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ fn checkpoint_list_load_hard_coded() -> Result<(), BoxError> {
237237

238238
let _ = Mainnet.checkpoint_list();
239239
let _ = Network::new_default_testnet().checkpoint_list();
240-
let _ = Network::new_regtest(None, None).checkpoint_list();
240+
let _ = Network::new_regtest(Default::default()).checkpoint_list();
241241

242242
Ok(())
243243
}

0 commit comments

Comments
 (0)