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

Add initial support for NU5 to zebra #1823

Merged
merged 8 commits into from
Mar 2, 2021
Merged
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
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.
teor2345 marked this conversation as resolved.
Show resolved Hide resolved
///
/// 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