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

NU7 to upstream #40

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
bf18f0c
Introduce Nu7
dmidem Aug 18, 2024
99ec8e6
Introduce Nu7 fo other crates of Zebra
dmidem Aug 19, 2024
7e2ca82
Fix of new_regtest call (as it additionally needs Nu7 arg now)
dmidem Oct 17, 2024
78e035a
Fix of new_regtest call (as it additionally needs Nu7 arg now) (2)
dmidem Oct 17, 2024
ac491b8
Set Nu7 as a network update for testnet in zebra-chain network tests
dmidem Oct 17, 2024
6883488
Fix serde names for NU7
dmidem Oct 17, 2024
aa373f1
Update test snapshot in zebra-rpc to use NU7
dmidem Oct 17, 2024
0fba7f3
Copy Nu7-related changes from zsa-integration-state
dmidem Feb 10, 2025
b42d84a
Uncomment zcash_unstable = nu7
dmidem Feb 10, 2025
d8b48c9
Fix Nu7 constants and add cfg(zcash_unstable ...) attribute according…
dmidem Feb 10, 2025
75f56e7
Update network constant values according to PR #15 review comments
dmidem Feb 10, 2025
f2b10a5
Add zcash_unstable=nu6 Rust flag to .cargo/config.toml to use nu6 by …
dmidem Feb 10, 2025
58da335
Add zcash_unstable = nu6 cfg in zebra-network/.../types.rs
dmidem Feb 10, 2025
9a5a5a1
Fix nu7 activation heights in network_upgrade.rs (nu6 value + 1 does …
dmidem Feb 11, 2025
c277d51
Add cfg for CURRENT_NETWORK_PROTOCOL_VERSION constant definition, add…
dmidem Feb 12, 2025
c48c753
Update get_blockchain_info@testnet_10.snap
dmidem Feb 12, 2025
152d893
Update get_blockchain_info@mainnet_10.snap
dmidem Feb 12, 2025
dd46071
Merge branch 'main' into zsa-integration-nu7-only
PaulLaux Feb 13, 2025
9b03c65
updated cfg flag
PaulLaux Feb 13, 2025
ee959b1
remove `zcash_unstable` flag
arya2 Feb 17, 2025
e47e5bf
Remove testnet and mainnet NU7 activation heights, comment out consen…
arya2 Feb 17, 2025
53e8520
Yep, it'll work after NU7
arya2 Feb 17, 2025
1e63277
Yep, the test should work fine after NU7
arya2 Feb 17, 2025
b2aae75
Yep, it only needs to be a post-nu6 height.
arya2 Feb 17, 2025
6bf3970
other fixes and cleanups
arya2 Feb 17, 2025
b8b4efe
Merge remote-tracking branch 'origin/main' into zsa-integration-nu7-only
arya2 Feb 18, 2025
8d302bb
Updates snapshots, removes unnecessary FIXMEs, fixes issues with bad …
arya2 Feb 18, 2025
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
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
6 changes: 2 additions & 4 deletions zebra-chain/src/parameters/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,10 @@ impl Network {

/// Creates a new [`Network::Testnet`] with `Regtest` parameters and the provided network upgrade activation heights.
pub fn new_regtest(
nu5_activation_height: Option<u32>,
nu6_activation_height: Option<u32>,
configured_activation_heights: testnet::ConfiguredActivationHeights,
) -> Self {
Self::new_configured_testnet(testnet::Parameters::new_regtest(
nu5_activation_height,
nu6_activation_height,
configured_activation_heights,
))
}

Expand Down
4 changes: 2 additions & 2 deletions zebra-chain/src/parameters/network/subsidy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ impl FundingStreamReceiver {
/// [ZIP-1014]: https://zips.z.cash/zip-1014#abstract
/// [`zcashd`]: https://github.com/zcash/zcash/blob/3f09cfa00a3c90336580a127e0096d99e25a38d6/src/consensus/funding.cpp#L13-L32
/// [ZIP-1015]: https://zips.z.cash/zip-1015
pub fn info(&self, is_nu6: bool) -> (&'static str, &'static str) {
if is_nu6 {
pub fn info(&self, is_post_nu6: bool) -> (&'static str, &'static str) {
if is_post_nu6 {
(
match self {
FundingStreamReceiver::Ecc => "Electric Coin Company",
Expand Down
54 changes: 24 additions & 30 deletions zebra-chain/src/parameters/network/testnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,35 +118,24 @@ impl From<&BTreeMap<Height, NetworkUpgrade>> for ConfiguredActivationHeights {
let mut configured_activation_heights = ConfiguredActivationHeights::default();

for (height, network_upgrade) in activation_heights.iter() {
match network_upgrade {
let field = match network_upgrade {
NetworkUpgrade::BeforeOverwinter => {
configured_activation_heights.before_overwinter = Some(height.0);
}
NetworkUpgrade::Overwinter => {
configured_activation_heights.overwinter = Some(height.0);
}
NetworkUpgrade::Sapling => {
configured_activation_heights.sapling = Some(height.0);
}
NetworkUpgrade::Blossom => {
configured_activation_heights.blossom = Some(height.0);
}
NetworkUpgrade::Heartwood => {
configured_activation_heights.heartwood = Some(height.0);
}
NetworkUpgrade::Canopy => {
configured_activation_heights.canopy = Some(height.0);
}
NetworkUpgrade::Nu5 => {
configured_activation_heights.nu5 = Some(height.0);
}
NetworkUpgrade::Nu6 => {
configured_activation_heights.nu6 = Some(height.0);
&mut configured_activation_heights.before_overwinter
}
NetworkUpgrade::Overwinter => &mut configured_activation_heights.overwinter,
NetworkUpgrade::Sapling => &mut configured_activation_heights.sapling,
NetworkUpgrade::Blossom => &mut configured_activation_heights.blossom,
NetworkUpgrade::Heartwood => &mut configured_activation_heights.heartwood,
NetworkUpgrade::Canopy => &mut configured_activation_heights.canopy,
NetworkUpgrade::Nu5 => &mut configured_activation_heights.nu5,
NetworkUpgrade::Nu6 => &mut configured_activation_heights.nu6,
NetworkUpgrade::Nu7 => &mut configured_activation_heights.nu7,
NetworkUpgrade::Genesis => {
continue;
}
}
};

*field = Some(height.0)
}

configured_activation_heights
Expand Down Expand Up @@ -271,6 +260,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 @@ -405,6 +397,7 @@ impl ParametersBuilder {
canopy,
nu5,
nu6,
nu7,
}: ConfiguredActivationHeights,
) -> Self {
use NetworkUpgrade::*;
Expand All @@ -427,6 +420,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 @@ -672,11 +666,10 @@ impl Parameters {
///
/// Creates an instance of [`Parameters`] with `Regtest` values.
pub fn new_regtest(
nu5_activation_height: Option<u32>,
nu6_activation_height: Option<u32>,
ConfiguredActivationHeights { nu5, nu6, nu7, .. }: ConfiguredActivationHeights,
) -> Self {
#[cfg(any(test, feature = "proptest-impl"))]
let nu5_activation_height = nu5_activation_height.or(Some(100));
let nu5 = nu5.or(Some(100));

let parameters = Self::build()
.with_genesis_hash(REGTEST_GENESIS_HASH)
Expand All @@ -689,8 +682,9 @@ impl Parameters {
// most network upgrades are disabled by default for Regtest in zcashd
.with_activation_heights(ConfiguredActivationHeights {
canopy: Some(1),
nu5: nu5_activation_height,
nu6: nu6_activation_height,
nu5,
nu6,
nu7,
..Default::default()
})
.with_halving_interval(PRE_BLOSSOM_REGTEST_HALVING_INTERVAL);
Expand Down Expand Up @@ -735,7 +729,7 @@ impl Parameters {
should_allow_unshielded_coinbase_spends,
pre_blossom_halving_interval,
post_blossom_halving_interval,
} = Self::new_regtest(None, None);
} = Self::new_regtest(Default::default());

self.network_name == network_name
&& self.genesis_hash == genesis_hash
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 @@ -108,7 +108,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 @@ -146,7 +146,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(Default::default()),
expected_default_regtest_activation_heights,
),
] {
Expand Down Expand Up @@ -197,7 +197,7 @@ fn check_configured_network_name() {
"Mainnet should be displayed as 'Mainnet'"
);
assert_eq!(
Network::new_regtest(None, None).to_string(),
Network::new_regtest(Default::default()).to_string(),
"Regtest",
"Regtest should be displayed as 'Regtest'"
);
Expand Down
14 changes: 12 additions & 2 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.
const NETWORK_UPGRADES_IN_ORDER: [NetworkUpgrade; 9] = [
const NETWORK_UPGRADES_IN_ORDER: [NetworkUpgrade; 10] = [
Genesis,
BeforeOverwinter,
Overwinter,
Expand All @@ -25,6 +25,7 @@ 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 TryFrom<u32> for NetworkUpgrade {
Expand Down Expand Up @@ -116,6 +120,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 Down Expand Up @@ -152,6 +157,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 @@ -243,6 +249,7 @@ pub(crate) const CONSENSUS_BRANCH_IDS: &[(NetworkUpgrade, ConsensusBranchId)] =
(Canopy, ConsensusBranchId(0xe9ff75a6)),
(Nu5, ConsensusBranchId(0xc2d6d0b4)),
(Nu6, ConsensusBranchId(0xc8e71055)),
// (Nu7, ConsensusBranchId(0x77190ad8)),
];

/// The target block spacing before Blossom.
Expand Down Expand Up @@ -431,7 +438,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 @@ -550,6 +559,7 @@ 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,
// 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
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(Default::default()).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 @@ -925,7 +925,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 @@ -1011,7 +1012,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
12 changes: 9 additions & 3 deletions zebra-consensus/src/transaction/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use zebra_chain::{
amount::{Amount, NonNegative},
block::{self, Block, Height},
orchard::{Action, AuthorizedAction, Flags},
parameters::{Network, NetworkUpgrade},
parameters::{testnet::ConfiguredActivationHeights, Network, NetworkUpgrade},
primitives::{ed25519, x25519, Groth16Proof},
sapling,
serialization::{DateTime32, ZcashDeserialize, ZcashDeserializeInto},
Expand Down Expand Up @@ -1007,7 +1007,10 @@ async fn mempool_request_with_immature_spend_is_rejected() {
async fn mempool_request_with_transparent_coinbase_spend_is_accepted_on_regtest() {
let _init_guard = zebra_test::init();

let network = Network::new_regtest(None, Some(1_000));
let network = Network::new_regtest(ConfiguredActivationHeights {
nu6: Some(1_000),
..Default::default()
});
let mut state: MockService<_, _, _, _> = MockService::build().for_unit_tests();
let verifier = Verifier::new_for_tests(&network, state.clone());

Expand Down Expand Up @@ -2865,7 +2868,10 @@ async fn v5_consensus_branch_ids() {

while let Some(next_nu) = network_upgrade.next_upgrade() {
// Check an outdated network upgrade.
let height = next_nu.activation_height(&network).expect("height");
let Some(height) = next_nu.activation_height(&network) else {
tracing::warn!(?next_nu, "missing activation height",);
continue;
};

let block_req = verifier
.clone()
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 @@ -347,7 +347,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
5 changes: 2 additions & 3 deletions zebra-network/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -725,12 +725,11 @@ 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
let configured_activation_heights = 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)
Network::new_regtest(configured_activation_heights)
}
(
NetworkKind::Testnet,
Expand Down
4 changes: 3 additions & 1 deletion zebra-network/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,8 @@ 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).
// TODO: Update this constant to the correct value after NU7 activation,
// pub const CURRENT_NETWORK_PROTOCOL_VERSION: Version = Version(170_140);
pub const CURRENT_NETWORK_PROTOCOL_VERSION: Version = Version(170_120);

/// The default RTT estimate for peer responses.
Expand Down Expand Up @@ -410,7 +412,7 @@ lazy_static! {

hash_map.insert(NetworkKind::Mainnet, Version::min_specified_for_upgrade(&Mainnet, Nu6));
hash_map.insert(NetworkKind::Testnet, Version::min_specified_for_upgrade(&Network::new_default_testnet(), Nu6));
hash_map.insert(NetworkKind::Regtest, Version::min_specified_for_upgrade(&Network::new_regtest(None, None), Nu6));
hash_map.insert(NetworkKind::Regtest, Version::min_specified_for_upgrade(&Network::new_regtest(Default::default()), Nu6));

hash_map
};
Expand Down
Loading