Fix integer truncation in Blossom halving calculation

This commit is contained in:
Eirik Ogilvie-Wigley 2019-08-02 19:35:53 -06:00
parent e6c0f743aa
commit 27ee4d64f2
1 changed files with 9 additions and 2 deletions

View File

@ -1770,8 +1770,15 @@ CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams)
int halvings;
if (blossomActive) {
int blossomActivationHeight = consensusParams.vUpgrades[Consensus::UPGRADE_BLOSSOM].nActivationHeight;
halvings = (blossomActivationHeight - consensusParams.SubsidySlowStartShift()) / consensusParams.nPreBlossomSubsidyHalvingInterval
+ (nHeight - blossomActivationHeight) / consensusParams.nPostBlossomSubsidyHalvingInterval;
// // Ideally we would say:
// halvings = (blossomActivationHeight - consensusParams.SubsidySlowStartShift()) / consensusParams.nPreBlossomSubsidyHalvingInterval
// + (nHeight - blossomActivationHeight) / consensusParams.nPostBlossomSubsidyHalvingInterval;
// But, (blossomActivationHeight - consensusParams.SubsidySlowStartShift()) / consensusParams.nPreBlossomSubsidyHalvingInterval
// needs to be a treated rational number or this does not work.
// Define scaledHalvings := halvings * consensusParams.nPreBlossomSubsidyHalvingInterval;
int scaledHalvings = (blossomActivationHeight - consensusParams.SubsidySlowStartShift())
+ (nHeight - blossomActivationHeight) / Consensus::BLOSSOM_POW_TARGET_SPACING_RATIO;
halvings = scaledHalvings / consensusParams.nPreBlossomSubsidyHalvingInterval;
} else {
halvings = (nHeight - consensusParams.SubsidySlowStartShift()) / consensusParams.nPreBlossomSubsidyHalvingInterval;
}