From 502896e13080f89bbda5af8cb7a83b6ba782433e Mon Sep 17 00:00:00 2001 From: Kris Nuttycombe Date: Tue, 7 Jul 2020 16:32:18 -0600 Subject: [PATCH] Fix incorrect subtraction of Halving(blossomActivationHeight) from halvingIndex --- src/consensus/params.cpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/consensus/params.cpp b/src/consensus/params.cpp index 4ff3eeb76..21c4dd49c 100644 --- a/src/consensus/params.cpp +++ b/src/consensus/params.cpp @@ -53,7 +53,7 @@ namespace Consensus { // Halving(h) returns the halving index at the specified height. It is // defined as floor(f(h)) where f is a strictly increasing rational // function, so it's sufficient to solve for f(height) = halvingIndex - // in the rationals and then take ceiling(height - 1). + // in the rationals and then take ceiling(height). // // H := blossom activation height; // SS := SubsidySlowStartShift(); @@ -61,23 +61,28 @@ namespace Consensus { // (The following calculation depends on BLOSSOM_POW_TARGET_SPACING_RATIO being an integer.) // // preBlossom: - // 1 = (height - SS) / preInterval - // height = preInterval + SS + // i = (height - SS) / preInterval + // height = (preInterval * i) + SS // // postBlossom: // i = (H - SS) / preInterval + (HalvingHeight(i) - H) / postInterval // preInterval = postInterval / R // i = (H - SS) / (postInterval / R) + (HalvingHeight(i) - H) / postInterval // i = (R * (H - SS) + HalvingHeight(i) - H) / postInterval + // postInterval * i = R * (H - SS) + HalvingHeight(i) - H // HalvingHeight(i) = postInterval * i - R * (H - SS) + H - // under normal circumstances, Halving(H) = 0 if (NetworkUpgradeActive(nHeight, Consensus::UPGRADE_BLOSSOM)) { int blossomActivationHeight = vUpgrades[Consensus::UPGRADE_BLOSSOM].nActivationHeight; - return blossomActivationHeight - - ((blossomActivationHeight - SubsidySlowStartShift()) * BLOSSOM_POW_TARGET_SPACING_RATIO) - + (nPostBlossomSubsidyHalvingInterval * (halvingIndex - Halving(blossomActivationHeight))); + + // Halving(H) = 0 because Blossom activated prior to the first halving + assert(Halving(blossomActivationHeight) == 0); + + return + (nPostBlossomSubsidyHalvingInterval * halvingIndex) + - (BLOSSOM_POW_TARGET_SPACING_RATIO * (blossomActivationHeight - SubsidySlowStartShift())) + + blossomActivationHeight; } else { - return (halvingIndex * nPreBlossomSubsidyHalvingInterval) + SubsidySlowStartShift(); + return (nPreBlossomSubsidyHalvingInterval * halvingIndex) + SubsidySlowStartShift(); } }