Skip to content

Commit fbef780

Browse files
committed
Post-rebase fixes.
1 parent a57cc81 commit fbef780

File tree

2 files changed

+22
-58
lines changed

2 files changed

+22
-58
lines changed

Cargo.lock

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6544,38 +6544,3 @@ dependencies = [
65446544
"zcash_address",
65456545
"zcash_protocol",
65466546
]
6547-
6548-
[[patch.unused]]
6549-
name = "zcash_address"
6550-
version = "0.5.0"
6551-
source = "git+https://github.com/zcash/librustzcash.git?rev=1410f1449100a417bfbc4f6c7167aa9808e38792#1410f1449100a417bfbc4f6c7167aa9808e38792"
6552-
6553-
[[patch.unused]]
6554-
name = "zcash_client_backend"
6555-
version = "0.13.0"
6556-
source = "git+https://github.com/zcash/librustzcash.git?rev=1410f1449100a417bfbc4f6c7167aa9808e38792#1410f1449100a417bfbc4f6c7167aa9808e38792"
6557-
6558-
[[patch.unused]]
6559-
name = "zcash_encoding"
6560-
version = "0.2.1"
6561-
source = "git+https://github.com/zcash/librustzcash.git?rev=1410f1449100a417bfbc4f6c7167aa9808e38792#1410f1449100a417bfbc4f6c7167aa9808e38792"
6562-
6563-
[[patch.unused]]
6564-
name = "zcash_history"
6565-
version = "0.4.0"
6566-
source = "git+https://github.com/zcash/librustzcash.git?rev=1410f1449100a417bfbc4f6c7167aa9808e38792#1410f1449100a417bfbc4f6c7167aa9808e38792"
6567-
6568-
[[patch.unused]]
6569-
name = "zcash_primitives"
6570-
version = "0.17.0"
6571-
source = "git+https://github.com/zcash/librustzcash.git?rev=1410f1449100a417bfbc4f6c7167aa9808e38792#1410f1449100a417bfbc4f6c7167aa9808e38792"
6572-
6573-
[[patch.unused]]
6574-
name = "zcash_proofs"
6575-
version = "0.17.0"
6576-
source = "git+https://github.com/zcash/librustzcash.git?rev=1410f1449100a417bfbc4f6c7167aa9808e38792#1410f1449100a417bfbc4f6c7167aa9808e38792"
6577-
6578-
[[patch.unused]]
6579-
name = "zcash_protocol"
6580-
version = "0.3.0"
6581-
source = "git+https://github.com/zcash/librustzcash.git?rev=1410f1449100a417bfbc4f6c7167aa9808e38792#1410f1449100a417bfbc4f6c7167aa9808e38792"

zebra-chain/src/block/subsidy/general.rs

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,40 +22,39 @@ use crate::{
2222
///
2323
/// Returns `None` if the divisor would overflow a `u64`.
2424
pub fn halving_divisor(height: Height, network: &Network) -> Option<u64> {
25+
// Some far-future shifts can be more than 63 bits
26+
1u64.checked_shl(num_halvings(height, network))
27+
}
28+
29+
/// The halving index for a block height and network.
30+
///
31+
/// `Halving(height)`, as described in [protocol specification §7.8][7.8]
32+
///
33+
/// [7.8]: https://zips.z.cash/protocol/protocol.pdf#subsidies
34+
pub fn num_halvings(height: Height, network: &Network) -> u32 {
35+
let slow_start_shift = network.slow_start_shift();
2536
let blossom_height = Blossom
2637
.activation_height(network)
2738
.expect("blossom activation height should be available");
2839

29-
if height < blossom_height {
30-
let pre_blossom_height = height - network.slow_start_shift();
31-
let halving_shift = pre_blossom_height / PRE_BLOSSOM_HALVING_INTERVAL;
32-
33-
let halving_div = 1u64
34-
.checked_shl(
35-
halving_shift
36-
.try_into()
37-
.expect("already checked for negatives"),
38-
)
39-
.expect("pre-blossom heights produce small shifts");
40-
41-
Some(halving_div)
40+
let halving_index = if height < slow_start_shift {
41+
0
42+
} else if height < blossom_height {
43+
let pre_blossom_height = height - slow_start_shift;
44+
pre_blossom_height / network.pre_blossom_halving_interval()
4245
} else {
43-
let pre_blossom_height = blossom_height - network.slow_start_shift();
46+
let pre_blossom_height = blossom_height - slow_start_shift;
4447
let scaled_pre_blossom_height =
4548
pre_blossom_height * HeightDiff::from(BLOSSOM_POW_TARGET_SPACING_RATIO);
4649

4750
let post_blossom_height = height - blossom_height;
4851

49-
let halving_shift =
50-
(scaled_pre_blossom_height + post_blossom_height) / POST_BLOSSOM_HALVING_INTERVAL;
52+
(scaled_pre_blossom_height + post_blossom_height) / network.post_blossom_halving_interval()
53+
};
5154

52-
// Some far-future shifts can be more than 63 bits
53-
1u64.checked_shl(
54-
halving_shift
55-
.try_into()
56-
.expect("already checked for negatives"),
57-
)
58-
}
55+
halving_index
56+
.try_into()
57+
.expect("already checked for negatives")
5958
}
6059

6160
#[cfg(zcash_unstable = "nsm")]

0 commit comments

Comments
 (0)