From 3238412dca26955d25ef4c566660d5941f82e010 Mon Sep 17 00:00:00 2001 From: teor Date: Tue, 28 Mar 2023 15:53:22 +1000 Subject: [PATCH] Fix the funding stream interval calculation --- .../src/block/subsidy/funding_streams.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/zebra-consensus/src/block/subsidy/funding_streams.rs b/zebra-consensus/src/block/subsidy/funding_streams.rs index 4d1ab9a6cc4..977b14a56d8 100644 --- a/zebra-consensus/src/block/subsidy/funding_streams.rs +++ b/zebra-consensus/src/block/subsidy/funding_streams.rs @@ -69,14 +69,18 @@ pub fn height_for_first_halving(network: Network) -> Height { /// /// [7.10]: https://zips.z.cash/protocol/protocol.pdf#fundingstreams fn funding_stream_address_period(height: Height, network: Network) -> u32 { - // - Spec equation: `address_period = floor((height - height_for_halving(1) - post_blossom_halving_interval)/funding_stream_address_change_interval)`: - // https://zips.z.cash/protocol/protocol.pdf#fundingstreams - // - In Rust, "integer division rounds towards zero": - // https://doc.rust-lang.org/stable/reference/expressions/operator-expr.html#arithmetic-and-logical-binary-operators + // Spec equation: `address_period = floor((height - (height_for_halving(1) - post_blossom_halving_interval))/funding_stream_address_change_interval)`, + // + // + // Note that the brackets make it so the post blossom halving interval is added to the total. + // + // In Rust, "integer division rounds towards zero": + // // This is the same as `floor()`, because these numbers are all positive. - let height_above_first_halving = height - height_for_first_halving(network); - let address_period = (height_above_first_halving - POST_BLOSSOM_HALVING_INTERVAL) + let height_after_first_halving = height - height_for_first_halving(network); + + let address_period = (height_after_first_halving + POST_BLOSSOM_HALVING_INTERVAL) / FUNDING_STREAM_ADDRESS_CHANGE_INTERVAL; address_period