Skip to content

Commit

Permalink
Fix the funding stream interval calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
teor2345 committed Mar 28, 2023
1 parent 7ac8b89 commit 3238412
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions zebra-consensus/src/block/subsidy/funding_streams.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)`,
// <https://zips.z.cash/protocol/protocol.pdf#fundingstreams>
//
// Note that the brackets make it so the post blossom halving interval is added to the total.
//
// In Rust, "integer division rounds towards zero":
// <https://doc.rust-lang.org/stable/reference/expressions/operator-expr.html#arithmetic-and-logical-binary-operators>
// 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
Expand Down

0 comments on commit 3238412

Please sign in to comment.