-
Notifications
You must be signed in to change notification settings - Fork 0
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 implementation #65
Changes from 66 commits
d58ac5b
f34dd02
b890183
f62a230
a56c5da
d670033
c6175b8
af4d4bb
fbbd655
424bf1a
b0b0f65
dac8d1f
cd8524b
3c83b72
aac4840
6da0474
0049a3b
98f4747
2365c2b
7e87fa5
2bd5e45
2704c8a
5eec964
3a18a4d
35f02fb
2ab8e16
c841df1
fb2b73a
cdd8afa
5733e8d
008f35e
cbd3b38
307d025
ce0a391
b7d4833
aad64db
c0d551d
944377d
5856713
9ddc1a7
c0fbc44
1ffcf4e
beb1d8d
fee70aa
2c11d9a
918beb9
46ac12c
6b743b8
9b9e525
cac470f
f160f25
4dbee84
8b9672d
1860f1d
f4cf872
aec1879
830260f
acb8f97
4f6ec46
3d20879
7f045e7
f411948
3ac2618
ea1770e
fe88163
fc38730
6652222
dc0a815
a434849
9f52b1b
10ff1e0
f79962b
738ed17
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -355,7 +355,9 @@ impl Parameters for MainNetwork { | |
NetworkUpgrade::Canopy => Some(BlockHeight(1_046_400)), | ||
NetworkUpgrade::Nu5 => Some(BlockHeight(1_687_104)), | ||
#[cfg(zcash_unstable = "nu6")] | ||
NetworkUpgrade::Nu6 => None, | ||
NetworkUpgrade::Nu6 => Some(BlockHeight(1_687_106)), | ||
#[cfg(zcash_unstable = "nu6" /* TODO nu7 */ )] | ||
NetworkUpgrade::Nu7 => Some(BlockHeight(1_687_107)), | ||
#[cfg(zcash_unstable = "zfuture")] | ||
NetworkUpgrade::ZFuture => None, | ||
} | ||
|
@@ -386,6 +388,8 @@ impl Parameters for TestNetwork { | |
NetworkUpgrade::Nu5 => Some(BlockHeight(1_842_420)), | ||
#[cfg(zcash_unstable = "nu6")] | ||
NetworkUpgrade::Nu6 => None, | ||
#[cfg(zcash_unstable = "nu6" /* TODO nu7 */ )] | ||
NetworkUpgrade::Nu7 => Some(BlockHeight(1_842_421)), | ||
#[cfg(zcash_unstable = "zfuture")] | ||
NetworkUpgrade::ZFuture => None, | ||
} | ||
|
@@ -454,6 +458,11 @@ pub enum NetworkUpgrade { | |
/// [Nu6]: https://z.cash/upgrade/nu6/ | ||
#[cfg(zcash_unstable = "nu6")] | ||
Nu6, | ||
/// The [Nu7] network upgrade. | ||
/// | ||
/// [Nu7]: https://z.cash/upgrade/nu7/ | ||
#[cfg(zcash_unstable = "nu6" /* TODO nu7 */ )] | ||
Nu7, | ||
/// The ZFUTURE network upgrade. | ||
/// | ||
/// This upgrade is expected never to activate on mainnet; | ||
|
@@ -476,6 +485,8 @@ impl fmt::Display for NetworkUpgrade { | |
NetworkUpgrade::Nu5 => write!(f, "Nu5"), | ||
#[cfg(zcash_unstable = "nu6")] | ||
NetworkUpgrade::Nu6 => write!(f, "Nu6"), | ||
#[cfg(zcash_unstable = "nu6" /* TODO nu7 */ )] | ||
NetworkUpgrade::Nu7 => write!(f, "Nu7"), | ||
#[cfg(zcash_unstable = "zfuture")] | ||
NetworkUpgrade::ZFuture => write!(f, "ZFUTURE"), | ||
} | ||
|
@@ -493,6 +504,8 @@ impl NetworkUpgrade { | |
NetworkUpgrade::Nu5 => BranchId::Nu5, | ||
#[cfg(zcash_unstable = "nu6")] | ||
NetworkUpgrade::Nu6 => BranchId::Nu6, | ||
#[cfg(zcash_unstable = "nu6" /* TODO nu7 */ )] | ||
NetworkUpgrade::Nu7 => BranchId::Nu7, | ||
#[cfg(zcash_unstable = "zfuture")] | ||
NetworkUpgrade::ZFuture => BranchId::ZFuture, | ||
} | ||
|
@@ -512,6 +525,8 @@ const UPGRADES_IN_ORDER: &[NetworkUpgrade] = &[ | |
NetworkUpgrade::Nu5, | ||
#[cfg(zcash_unstable = "nu6")] | ||
NetworkUpgrade::Nu6, | ||
#[cfg(zcash_unstable = "nu6" /* TODO nu7 */ )] | ||
NetworkUpgrade::Nu7, | ||
]; | ||
|
||
/// The "grace period" defined in [ZIP 212]. | ||
|
@@ -551,6 +566,9 @@ pub enum BranchId { | |
/// The consensus rules deployed by [`NetworkUpgrade::Nu6`]. | ||
#[cfg(zcash_unstable = "nu6")] | ||
Nu6, | ||
/// The consensus rules deployed by [`NetworkUpgrade::Nu7`]. | ||
#[cfg(zcash_unstable = "nu6" /* TODO nu7 */ )] | ||
Nu7, | ||
/// Candidates for future consensus rules; this branch will never | ||
/// activate on mainnet. | ||
#[cfg(zcash_unstable = "zfuture")] | ||
|
@@ -573,6 +591,8 @@ impl TryFrom<u32> for BranchId { | |
0xc2d6_d0b4 => Ok(BranchId::Nu5), | ||
#[cfg(zcash_unstable = "nu6")] | ||
0xc8e7_1055 => Ok(BranchId::Nu6), | ||
#[cfg(zcash_unstable = "nu6" /* TODO nu7 */ )] | ||
0x7777_7777 => Ok(BranchId::Nu7), | ||
#[cfg(zcash_unstable = "zfuture")] | ||
0xffff_ffff => Ok(BranchId::ZFuture), | ||
_ => Err("Unknown consensus branch ID"), | ||
|
@@ -592,6 +612,8 @@ impl From<BranchId> for u32 { | |
BranchId::Nu5 => 0xc2d6_d0b4, | ||
#[cfg(zcash_unstable = "nu6")] | ||
BranchId::Nu6 => 0xc8e7_1055, | ||
#[cfg(zcash_unstable = "nu6" /* TODO nu7 */ )] | ||
BranchId::Nu7 => 0x7777_7777, | ||
#[cfg(zcash_unstable = "zfuture")] | ||
BranchId::ZFuture => 0xffff_ffff, | ||
} | ||
|
@@ -657,15 +679,17 @@ impl BranchId { | |
BranchId::Canopy => params | ||
.activation_height(NetworkUpgrade::Canopy) | ||
.map(|lower| (lower, params.activation_height(NetworkUpgrade::Nu5))), | ||
BranchId::Nu5 => params.activation_height(NetworkUpgrade::Nu5).map(|lower| { | ||
#[cfg(zcash_unstable = "zfuture")] | ||
let upper = params.activation_height(NetworkUpgrade::ZFuture); | ||
#[cfg(not(zcash_unstable = "zfuture"))] | ||
let upper = None; | ||
(lower, upper) | ||
}), | ||
BranchId::Nu5 => params | ||
.activation_height(NetworkUpgrade::Nu5) | ||
.map(|lower| (lower, upper_bound(lower, params))), | ||
#[cfg(zcash_unstable = "nu6")] | ||
BranchId::Nu6 => None, | ||
BranchId::Nu6 => params | ||
.activation_height(NetworkUpgrade::Nu6) | ||
.map(|lower| (lower, upper_bound(lower, params))), | ||
#[cfg(zcash_unstable = "nu6" /* TODO nu7 */ )] | ||
BranchId::Nu7 => params | ||
.activation_height(NetworkUpgrade::Nu7) | ||
.map(|lower| (lower, upper_bound(lower, params))), | ||
#[cfg(zcash_unstable = "zfuture")] | ||
BranchId::ZFuture => params | ||
.activation_height(NetworkUpgrade::ZFuture) | ||
|
@@ -677,6 +701,39 @@ impl BranchId { | |
!matches!(self, BranchId::Sprout | BranchId::Overwinter) | ||
} | ||
} | ||
#[allow(unused_variables)] | ||
fn upper_bound<P: Parameters>(target_height: BlockHeight, params: &P) -> Option<BlockHeight> { | ||
#[allow(dead_code)] | ||
fn check_bound<P: Parameters>( | ||
target_height: BlockHeight, | ||
current_upper: Option<BlockHeight>, | ||
nu: NetworkUpgrade, | ||
params: &P, | ||
) -> Option<BlockHeight> { | ||
let nu_height = params.activation_height(nu); | ||
if nu_height.is_some() && nu_height.unwrap() > target_height { | ||
nu_height | ||
} else { | ||
current_upper | ||
} | ||
} | ||
|
||
#[allow(unused_mut)] | ||
let mut upper = None; | ||
#[cfg(zcash_unstable = "nu6")] | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure we need the scope? (x3) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, looks ugly af, but I'm not sure how to do it better. Open to ideas... |
||
upper = check_bound(target_height, upper, NetworkUpgrade::Nu6, params); | ||
} | ||
#[cfg(zcash_unstable = "nu6" /* TODO nu7 */ )] | ||
{ | ||
upper = check_bound(target_height, upper, NetworkUpgrade::Nu7, params); | ||
} | ||
#[cfg(zcash_unstable = "zfuture")] | ||
{ | ||
upper = check_bound(target_height, upper, NetworkUpgrade::ZFuture, params); | ||
} | ||
upper | ||
} | ||
|
||
#[cfg(any(test, feature = "test-dependencies"))] | ||
pub mod testing { | ||
|
@@ -696,6 +753,8 @@ pub mod testing { | |
BranchId::Nu5, | ||
#[cfg(zcash_unstable = "nu6")] | ||
BranchId::Nu6, | ||
#[cfg(zcash_unstable = "nu6" /* TODO nu7 */ )] | ||
BranchId::Nu7, | ||
#[cfg(zcash_unstable = "zfuture")] | ||
BranchId::ZFuture, | ||
]) | ||
|
@@ -789,9 +848,15 @@ mod tests { | |
BranchId::for_height(&MAIN_NETWORK, BlockHeight(1_687_104)), | ||
BranchId::Nu5, | ||
); | ||
#[cfg(zcash_unstable = "nu6")] | ||
assert_eq!( | ||
BranchId::for_height(&MAIN_NETWORK, BlockHeight(5_000_000)), | ||
BranchId::Nu5, | ||
BranchId::for_height(&MAIN_NETWORK, BlockHeight(1_687_106)), | ||
BranchId::Nu6, | ||
); | ||
#[cfg(zcash_unstable = "nu6" /* TODO nu7 */ )] | ||
assert_eq!( | ||
BranchId::for_height(&MAIN_NETWORK, BlockHeight(1_842_421)), | ||
BranchId::Nu7, | ||
); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why comment out?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We decided not to touch zcah_client_xxx crates for now and this target requires them
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so let's remove just the relevant lines:
Seems that it can work