Skip to content

Commit

Permalink
Add initial support for NU5 to zebra (#1823)
Browse files Browse the repository at this point in the history
* Add NU5 variant to NetworkUpgrade
* Add consensus branch ID for NU5
* Add network protocol versions for NU5
* Add NU5 to the protocol::version_consistent test
* Make unimplemented panic messages more specific
* Block target spacing doesn't change in NU5
* add comments for future updates for NU5

Co-authored-by: teor <[email protected]>
  • Loading branch information
yaahc and teor2345 authored Mar 2, 2021
1 parent 3c4cd31 commit e541746
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 2 deletions.
1 change: 1 addition & 0 deletions zebra-chain/src/block/root_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ impl RootHash {
ChainHistoryActivationReserved(bytes)
}
Heartwood | Canopy => ChainHistoryRoot(ChainHistoryMmrRootHash(bytes)),
NU5 => unimplemented!("NU5 uses hashAuthDataRoot as specified in ZIP-244"),
}
}

Expand Down
10 changes: 9 additions & 1 deletion zebra-chain/src/parameters/network_upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ pub enum NetworkUpgrade {
Heartwood,
/// The Zcash protocol after the Canopy upgrade.
Canopy,
/// The Zcash protocol after the NU5 upgrade.
///
/// Note: Network Upgrade 5 includes the Orchard Shielded Protocol, and
/// other changes. The NU5 code name has not been chosen yet.
NU5,
}

/// Mainnet network upgrade activation heights.
Expand All @@ -51,6 +56,7 @@ pub(crate) const MAINNET_ACTIVATION_HEIGHTS: &[(block::Height, NetworkUpgrade)]
(block::Height(653_600), Blossom),
(block::Height(903_000), Heartwood),
(block::Height(1_046_400), Canopy),
// TODO: Add NU5 mainnet activation height
];

/// Testnet network upgrade activation heights.
Expand All @@ -65,6 +71,7 @@ pub(crate) const TESTNET_ACTIVATION_HEIGHTS: &[(block::Height, NetworkUpgrade)]
(block::Height(584_000), Blossom),
(block::Height(903_800), Heartwood),
(block::Height(1_028_500), Canopy),
// TODO: Add NU5 testnet activation height
];

/// The Consensus Branch Id, used to bind transactions and blocks to a
Expand Down Expand Up @@ -94,6 +101,7 @@ pub(crate) const CONSENSUS_BRANCH_IDS: &[(NetworkUpgrade, ConsensusBranchId)] =
(Blossom, ConsensusBranchId(0x2bb40e60)),
(Heartwood, ConsensusBranchId(0xf5b9230b)),
(Canopy, ConsensusBranchId(0xe9ff75a6)),
(NU5, ConsensusBranchId(0xf919a198)),
];

/// The target block spacing before Blossom.
Expand Down Expand Up @@ -199,7 +207,7 @@ 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 => POST_BLOSSOM_POW_TARGET_SPACING,
Blossom | Heartwood | Canopy | NU5 => POST_BLOSSOM_POW_TARGET_SPACING,
};

Duration::seconds(spacing_seconds)
Expand Down
3 changes: 3 additions & 0 deletions zebra-chain/src/transaction/arbitrary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,9 @@ impl Arbitrary for Transaction {
NetworkUpgrade::Blossom | NetworkUpgrade::Heartwood | NetworkUpgrade::Canopy => {
Self::v4_strategy(ledger_state)
}
NetworkUpgrade::NU5 => {
unimplemented!("NU5 upgrade can use v4 or v5 transactions, as specified in ZIP-225")
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions zebra-chain/src/transaction/sighash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ impl<'a> SigHasher<'a> {
Sapling | Blossom | Heartwood | Canopy => self
.hash_sighash_zip243(&mut hash)
.expect("serialization into hasher never fails"),
NU5 => unimplemented!(
"NU5 upgrade uses a new transaction digest algorithm, as specified in ZIP-244"
),
}

hash.finalize()
Expand Down
5 changes: 4 additions & 1 deletion zebra-network/src/protocol/external/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ impl Version {
(Mainnet, Heartwood) => 170_011,
(Testnet, Canopy) => 170_012,
(Mainnet, Canopy) => 170_013,
(Testnet, NU5) => 170_014,
(Mainnet, NU5) => 170_015,
})
}

Expand Down Expand Up @@ -187,7 +189,7 @@ mod test {
zebra_test::init();

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

for &network_upgrade in &[
Expand All @@ -197,6 +199,7 @@ mod test {
Blossom,
Heartwood,
Canopy,
NU5,
] {
let height = network_upgrade.activation_height(network);
if let Some(height) = height {
Expand Down

0 comments on commit e541746

Please sign in to comment.