Skip to content

Commit bb23624

Browse files
committed
Post-rebase fixes.
1 parent 8500594 commit bb23624

File tree

7 files changed

+83
-116
lines changed

7 files changed

+83
-116
lines changed

Cargo.lock

Lines changed: 36 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,6 +1343,15 @@ dependencies = [
13431343
"byteorder",
13441344
]
13451345

1346+
[[package]]
1347+
name = "equihash"
1348+
version = "0.2.0"
1349+
source = "git+https://github.com/ShieldedLabs/librustzcash/?branch=nsm-zebra#5fcd3034e47d425df4846192abd4d84fb3752207"
1350+
dependencies = [
1351+
"blake2b_simd",
1352+
"byteorder",
1353+
]
1354+
13461355
[[package]]
13471356
name = "equivalent"
13481357
version = "1.0.1"
@@ -1372,7 +1381,7 @@ dependencies = [
13721381
[[package]]
13731382
name = "f4jumble"
13741383
version = "0.1.0"
1375-
source = "git+https://github.com/ShieldedLabs/librustzcash/?branch=nsm-zebra#1b4f984a61cc88029c0b78e9d13225aad76c6903"
1384+
source = "git+https://github.com/ShieldedLabs/librustzcash/?branch=nsm-zebra#5fcd3034e47d425df4846192abd4d84fb3752207"
13761385
dependencies = [
13771386
"blake2b_simd",
13781387
]
@@ -5548,14 +5557,14 @@ dependencies = [
55485557

55495558
[[package]]
55505559
name = "which"
5551-
version = "4.4.2"
5560+
version = "6.0.3"
55525561
source = "registry+https://github.com/rust-lang/crates.io-index"
5553-
checksum = "87ba24419a2078cd2b0f2ede2691b6c66d8e47836da3b6db8265ebad47afbfc7"
5562+
checksum = "b4ee928febd44d98f2f459a4a79bd4d928591333a494a10a868418ac1b39cf1f"
55545563
dependencies = [
55555564
"either",
55565565
"home",
5557-
"once_cell",
55585566
"rustix",
5567+
"winsafe",
55595568
]
55605569

55615570
[[package]]
@@ -5805,6 +5814,12 @@ dependencies = [
58055814
"windows-sys 0.48.0",
58065815
]
58075816

5817+
[[package]]
5818+
name = "winsafe"
5819+
version = "0.0.19"
5820+
source = "registry+https://github.com/rust-lang/crates.io-index"
5821+
checksum = "d135d17ab770252ad95e9a872d365cf3090e3be864a34ab46f48555993efc904"
5822+
58085823
[[package]]
58095824
name = "wyz"
58105825
version = "0.5.1"
@@ -5834,8 +5849,8 @@ checksum = "213b7324336b53d2414b2db8537e56544d981803139155afa84f76eeebb7a546"
58345849

58355850
[[package]]
58365851
name = "zcash_address"
5837-
version = "0.5.0"
5838-
source = "git+https://github.com/ShieldedLabs/librustzcash/?branch=nsm-zebra#1b4f984a61cc88029c0b78e9d13225aad76c6903"
5852+
version = "0.6.0"
5853+
source = "git+https://github.com/ShieldedLabs/librustzcash/?branch=nsm-zebra#5fcd3034e47d425df4846192abd4d84fb3752207"
58395854
dependencies = [
58405855
"bech32",
58415856
"bs58",
@@ -5846,8 +5861,8 @@ dependencies = [
58465861

58475862
[[package]]
58485863
name = "zcash_client_backend"
5849-
version = "0.13.0"
5850-
source = "git+https://github.com/ShieldedLabs/librustzcash/?branch=nsm-zebra#1b4f984a61cc88029c0b78e9d13225aad76c6903"
5864+
version = "0.14.0"
5865+
source = "git+https://github.com/ShieldedLabs/librustzcash/?branch=nsm-zebra#5fcd3034e47d425df4846192abd4d84fb3752207"
58515866
dependencies = [
58525867
"base64 0.22.1",
58535868
"bech32",
@@ -5886,7 +5901,7 @@ dependencies = [
58865901
[[package]]
58875902
name = "zcash_encoding"
58885903
version = "0.2.1"
5889-
source = "git+https://github.com/ShieldedLabs/librustzcash/?branch=nsm-zebra#1b4f984a61cc88029c0b78e9d13225aad76c6903"
5904+
source = "git+https://github.com/ShieldedLabs/librustzcash/?branch=nsm-zebra#5fcd3034e47d425df4846192abd4d84fb3752207"
58905905
dependencies = [
58915906
"byteorder",
58925907
"nonempty",
@@ -5895,7 +5910,7 @@ dependencies = [
58955910
[[package]]
58965911
name = "zcash_history"
58975912
version = "0.4.0"
5898-
source = "git+https://github.com/ShieldedLabs/librustzcash/?branch=nsm-zebra#1b4f984a61cc88029c0b78e9d13225aad76c6903"
5913+
source = "git+https://github.com/ShieldedLabs/librustzcash/?branch=nsm-zebra#5fcd3034e47d425df4846192abd4d84fb3752207"
58995914
dependencies = [
59005915
"blake2b_simd",
59015916
"byteorder",
@@ -5904,8 +5919,8 @@ dependencies = [
59045919

59055920
[[package]]
59065921
name = "zcash_keys"
5907-
version = "0.3.0"
5908-
source = "git+https://github.com/ShieldedLabs/librustzcash/?branch=nsm-zebra#1b4f984a61cc88029c0b78e9d13225aad76c6903"
5922+
version = "0.4.0"
5923+
source = "git+https://github.com/ShieldedLabs/librustzcash/?branch=nsm-zebra#5fcd3034e47d425df4846192abd4d84fb3752207"
59095924
dependencies = [
59105925
"bech32",
59115926
"blake2b_simd",
@@ -5942,8 +5957,8 @@ dependencies = [
59425957

59435958
[[package]]
59445959
name = "zcash_primitives"
5945-
version = "0.17.0"
5946-
source = "git+https://github.com/ShieldedLabs/librustzcash/?branch=nsm-zebra#1b4f984a61cc88029c0b78e9d13225aad76c6903"
5960+
version = "0.19.0"
5961+
source = "git+https://github.com/ShieldedLabs/librustzcash/?branch=nsm-zebra#5fcd3034e47d425df4846192abd4d84fb3752207"
59475962
dependencies = [
59485963
"aes",
59495964
"bip32",
@@ -5980,8 +5995,8 @@ dependencies = [
59805995

59815996
[[package]]
59825997
name = "zcash_proofs"
5983-
version = "0.17.0"
5984-
source = "git+https://github.com/ShieldedLabs/librustzcash/?branch=nsm-zebra#1b4f984a61cc88029c0b78e9d13225aad76c6903"
5998+
version = "0.19.0"
5999+
source = "git+https://github.com/ShieldedLabs/librustzcash/?branch=nsm-zebra#5fcd3034e47d425df4846192abd4d84fb3752207"
59856000
dependencies = [
59866001
"bellman",
59876002
"blake2b_simd",
@@ -6002,8 +6017,8 @@ dependencies = [
60026017

60036018
[[package]]
60046019
name = "zcash_protocol"
6005-
version = "0.3.0"
6006-
source = "git+https://github.com/ShieldedLabs/librustzcash/?branch=nsm-zebra#1b4f984a61cc88029c0b78e9d13225aad76c6903"
6020+
version = "0.4.0"
6021+
source = "git+https://github.com/ShieldedLabs/librustzcash/?branch=nsm-zebra#5fcd3034e47d425df4846192abd4d84fb3752207"
60076022
dependencies = [
60086023
"document-features",
60096024
"memuse",
@@ -6045,7 +6060,7 @@ dependencies = [
60456060
"criterion",
60466061
"dirs",
60476062
"ed25519-zebra",
6048-
"equihash",
6063+
"equihash 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
60496064
"futures",
60506065
"group",
60516066
"halo2_proofs",
@@ -6543,47 +6558,12 @@ dependencies = [
65436558

65446559
[[package]]
65456560
name = "zip321"
6546-
version = "0.1.0"
6547-
source = "git+https://github.com/ShieldedLabs/librustzcash/?branch=nsm-zebra#1b4f984a61cc88029c0b78e9d13225aad76c6903"
6561+
version = "0.2.0"
6562+
source = "git+https://github.com/ShieldedLabs/librustzcash/?branch=nsm-zebra#5fcd3034e47d425df4846192abd4d84fb3752207"
65486563
dependencies = [
65496564
"base64 0.22.1",
65506565
"nom",
65516566
"percent-encoding",
65526567
"zcash_address",
65536568
"zcash_protocol",
65546569
]
6555-
6556-
[[patch.unused]]
6557-
name = "zcash_address"
6558-
version = "0.5.0"
6559-
source = "git+https://github.com/zcash/librustzcash.git?rev=1410f1449100a417bfbc4f6c7167aa9808e38792#1410f1449100a417bfbc4f6c7167aa9808e38792"
6560-
6561-
[[patch.unused]]
6562-
name = "zcash_client_backend"
6563-
version = "0.13.0"
6564-
source = "git+https://github.com/zcash/librustzcash.git?rev=1410f1449100a417bfbc4f6c7167aa9808e38792#1410f1449100a417bfbc4f6c7167aa9808e38792"
6565-
6566-
[[patch.unused]]
6567-
name = "zcash_encoding"
6568-
version = "0.2.1"
6569-
source = "git+https://github.com/zcash/librustzcash.git?rev=1410f1449100a417bfbc4f6c7167aa9808e38792#1410f1449100a417bfbc4f6c7167aa9808e38792"
6570-
6571-
[[patch.unused]]
6572-
name = "zcash_history"
6573-
version = "0.4.0"
6574-
source = "git+https://github.com/zcash/librustzcash.git?rev=1410f1449100a417bfbc4f6c7167aa9808e38792#1410f1449100a417bfbc4f6c7167aa9808e38792"
6575-
6576-
[[patch.unused]]
6577-
name = "zcash_primitives"
6578-
version = "0.17.0"
6579-
source = "git+https://github.com/zcash/librustzcash.git?rev=1410f1449100a417bfbc4f6c7167aa9808e38792#1410f1449100a417bfbc4f6c7167aa9808e38792"
6580-
6581-
[[patch.unused]]
6582-
name = "zcash_proofs"
6583-
version = "0.17.0"
6584-
source = "git+https://github.com/zcash/librustzcash.git?rev=1410f1449100a417bfbc4f6c7167aa9808e38792#1410f1449100a417bfbc4f6c7167aa9808e38792"
6585-
6586-
[[patch.unused]]
6587-
name = "zcash_protocol"
6588-
version = "0.3.0"
6589-
source = "git+https://github.com/zcash/librustzcash.git?rev=1410f1449100a417bfbc4f6c7167aa9808e38792#1410f1449100a417bfbc4f6c7167aa9808e38792"

zebra-chain/src/block/subsidy/funding_streams/tests.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,7 @@ use color_eyre::Report;
44

55
use crate::{
66
block::subsidy::general::block_subsidy_pre_nsm,
7-
parameters::{
8-
subsidy::FundingStreamReceiver,
9-
testnet::{
10-
self, ConfiguredActivationHeights, ConfiguredFundingStreamRecipient,
11-
ConfiguredFundingStreams,
12-
},
13-
NetworkKind,
14-
},
7+
parameters::{subsidy::FundingStreamReceiver, NetworkKind},
158
};
169

1710
use super::*;
@@ -79,7 +72,8 @@ fn test_funding_stream_values() -> Result<(), Report> {
7972
nu6_fund_height_range.end,
8073
nu6_fund_height_range.end.next().unwrap(),
8174
] {
82-
let fsv = funding_stream_values(height, network, block_subsidy(height, network)?).unwrap();
75+
let fsv = funding_stream_values(height, network, block_subsidy_pre_nsm(height, network)?)
76+
.unwrap();
8377

8478
if height < canopy_activation_height {
8579
assert!(fsv.is_empty());

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

Lines changed: 23 additions & 26 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")]
@@ -429,9 +428,7 @@ mod test {
429428
fn check_height_for_num_halvings() {
430429
for network in Network::iter() {
431430
for halving in 1..1000 {
432-
let Some(height_for_halving) =
433-
zebra_chain::parameters::subsidy::height_for_halving(halving, &network)
434-
else {
431+
let Some(height_for_halving) = height_for_halving(halving, &network) else {
435432
panic!("could not find height for halving {halving}");
436433
};
437434

zebra-chain/src/error.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ pub enum SubsidyError {
8080

8181
#[error("invalid burn amount")]
8282
InvalidBurnAmount,
83+
84+
#[error("unexpected error occurred: {0}")]
85+
Other(String),
8386
}
8487

8588
impl From<amount::Error> for SubsidyError {

zebra-consensus/src/block/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ fn miner_fees_validation_failure() -> Result<(), Report> {
549549
let block = Block::zcash_deserialize(&zebra_test::vectors::BLOCK_MAINNET_347499_BYTES[..])
550550
.expect("block should deserialize");
551551
let height = block.coinbase_height().expect("valid coinbase height");
552-
let expected_block_subsidy = block_subsidy(height, &network)?;
552+
let expected_block_subsidy = block_subsidy_pre_nsm(height, &network)?;
553553
// See [ZIP-1015](https://zips.z.cash/zip-1015).
554554
let expected_deferred_amount: Amount<zebra_chain::amount::NonNegative> =
555555
subsidy::funding_streams::funding_stream_values(height, &network, expected_block_subsidy)

zebra-state/Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,6 @@ jubjub = "0.10.0"
114114

115115
tokio = { version = "1.41.0", features = ["full", "tracing", "test-util"] }
116116

117-
tokio = { version = "1.40.0", features = ["full", "tracing", "test-util"] }
118-
119117
zebra-chain = { path = "../zebra-chain", version = "1.0.0-beta.42", features = ["proptest-impl"] }
120118
zebra-test = { path = "../zebra-test/", version = "1.0.0-beta.42" }
121119

zebra-state/src/service/check.rs

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ pub fn subsidy_is_valid(
533533
let coinbase = block.transactions.first().ok_or(SubsidyError::NoCoinbase)?;
534534

535535
// Validate funding streams
536-
let Some(halving_div) = subsidy::general::halving_divisor(height, network) else {
536+
let Some(halving_div) = general::halving_divisor(height, network) else {
537537
// Far future halving, with no founders reward or funding streams
538538
return Ok(());
539539
};
@@ -560,13 +560,10 @@ pub fn subsidy_is_valid(
560560
// Note: Canopy activation is at the first halving on mainnet, but not on testnet
561561
// ZIP-1014 only applies to mainnet, ZIP-214 contains the specific rules for testnet
562562
// funding stream amount values
563-
let funding_streams = subsidy::funding_streams::funding_stream_values(
564-
height,
565-
network,
566-
expected_block_subsidy,
567-
)
568-
// we always expect a funding stream hashmap response even if empty
569-
.map_err(|err| BlockError::Other(err.to_string()))?;
563+
let funding_streams =
564+
funding_streams::funding_stream_values(height, network, expected_block_subsidy)
565+
// we always expect a funding stream hashmap response even if empty
566+
.map_err(|err| SubsidyError::Other(err.to_string()))?;
570567

571568
// # Consensus
572569
//
@@ -583,20 +580,18 @@ pub fn subsidy_is_valid(
583580
continue;
584581
}
585582

586-
let address =
587-
subsidy::funding_streams::funding_stream_address(height, network, receiver)
588-
// funding stream receivers other than the deferred pool must have an address
589-
.ok_or_else(|| {
590-
BlockError::Other(format!(
591-
"missing funding stream address at height {height:?}"
592-
))
593-
})?;
594-
595-
let has_expected_output =
596-
subsidy::funding_streams::filter_outputs_by_address(coinbase, address)
597-
.iter()
598-
.map(zebra_chain::transparent::Output::value)
599-
.any(|value| value == expected_amount);
583+
let address = funding_streams::funding_stream_address(height, network, receiver)
584+
// funding stream receivers other than the deferred pool must have an address
585+
.ok_or_else(|| {
586+
SubsidyError::Other(format!(
587+
"missing funding stream address at height {height:?}"
588+
))
589+
})?;
590+
591+
let has_expected_output = funding_streams::filter_outputs_by_address(coinbase, address)
592+
.iter()
593+
.map(zebra_chain::transparent::Output::value)
594+
.any(|value| value == expected_amount);
600595

601596
if !has_expected_output {
602597
Err(SubsidyError::FundingStreamNotFound)?;

0 commit comments

Comments
 (0)