Skip to content

Commit

Permalink
rename function
Browse files Browse the repository at this point in the history
  • Loading branch information
oxarbitrage committed Oct 7, 2024
1 parent b1cabcd commit 71bbaf7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
9 changes: 4 additions & 5 deletions zebra-chain/src/parameters/network/subsidy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,8 +413,7 @@ impl ParameterSubsidy for Network {
} else if params.is_default_testnet() {
FIRST_HALVING_TESTNET
} else {
height_for_halving_index(1, self)
.expect("first halving height should be available")
height_for_halving(1, self).expect("first halving height should be available")
}
}
}
Expand Down Expand Up @@ -558,8 +557,8 @@ pub fn funding_stream_address_period<N: ParameterSubsidy>(height: Height, networ
/// See `Halving(height)`, as described in [protocol specification §7.8][7.8]
///
/// [7.8]: https://zips.z.cash/protocol/protocol.pdf#subsidies
pub fn height_for_halving_index(halving_index: u32, network: &Network) -> Option<Height> {
if halving_index == 0 {
pub fn height_for_halving(halving: u32, network: &Network) -> Option<Height> {
if halving == 0 {
return Some(Height(0));
}

Expand All @@ -571,7 +570,7 @@ pub fn height_for_halving_index(halving_index: u32, network: &Network) -> Option
.0,
);
let pre_blossom_halving_interval = network.pre_blossom_halving_interval();
let halving_index = i64::from(halving_index);
let halving_index = i64::from(halving);

let unscaled_height = halving_index
.checked_mul(pre_blossom_halving_interval)
Expand Down
13 changes: 5 additions & 8 deletions zebra-consensus/src/block/subsidy/general.rs
Original file line number Diff line number Diff line change
Expand Up @@ -506,28 +506,25 @@ mod test {
#[test]
fn check_height_for_num_halvings() {
for network in Network::iter() {
for halving_index in 1..1000 {
for halving in 1..1000 {
let Some(height_for_halving) =
zebra_chain::parameters::subsidy::height_for_halving_index(
halving_index,
&network,
)
zebra_chain::parameters::subsidy::height_for_halving(halving, &network)
else {
panic!("could not find height for halving {halving_index}");
panic!("could not find height for halving {halving}");
};

let prev_height = height_for_halving
.previous()
.expect("there should be a previous height");

assert_eq!(
halving_index,
halving,
num_halvings(height_for_halving, &network),
"num_halvings should match the halving index"
);

assert_eq!(
halving_index - 1,
halving - 1,
num_halvings(prev_height, &network),
"num_halvings for the prev height should be 1 less than the halving index"
);
Expand Down

0 comments on commit 71bbaf7

Please sign in to comment.