Algebraic improvements related to halving

This commit is contained in:
Eirik Ogilvie-Wigley 2019-08-05 14:02:31 -06:00
parent 8f0a54c142
commit f97b9c5d9f
1 changed files with 8 additions and 7 deletions

View File

@ -19,10 +19,10 @@ namespace Consensus {
// + (nHeight - blossomActivationHeight) / consensusParams.nPostBlossomSubsidyHalvingInterval; // + (nHeight - blossomActivationHeight) / consensusParams.nPostBlossomSubsidyHalvingInterval;
// But, (blossomActivationHeight - consensusParams.SubsidySlowStartShift()) / consensusParams.nPreBlossomSubsidyHalvingInterval // But, (blossomActivationHeight - consensusParams.SubsidySlowStartShift()) / consensusParams.nPreBlossomSubsidyHalvingInterval
// would need to be treated as a rational number in order for this to work. // would need to be treated as a rational number in order for this to work.
// Define scaledHalvings := halvings * consensusParams.nPreBlossomSubsidyHalvingInterval; // Define scaledHalvings := halvings * consensusParams.nPostBlossomSubsidyHalvingInterval;
int scaledHalvings = (blossomActivationHeight - SubsidySlowStartShift()) int scaledHalvings = ((blossomActivationHeight - SubsidySlowStartShift()) * Consensus::BLOSSOM_POW_TARGET_SPACING_RATIO)
+ (nHeight - blossomActivationHeight) / Consensus::BLOSSOM_POW_TARGET_SPACING_RATIO; + (nHeight - blossomActivationHeight);
return scaledHalvings / nPreBlossomSubsidyHalvingInterval; return scaledHalvings / nPostBlossomSubsidyHalvingInterval;
} else { } else {
return (nHeight - SubsidySlowStartShift()) / nPreBlossomSubsidyHalvingInterval; return (nHeight - SubsidySlowStartShift()) / nPreBlossomSubsidyHalvingInterval;
} }
@ -40,14 +40,15 @@ namespace Consensus {
// height = preInterval + SS // height = preInterval + SS
// postBlossom: // postBlossom:
// 1 = (H - SS) / preInterval + (height - H) / postInterval // 1 = (H - SS) / preInterval + (height - H) / postInterval
// height = H + postInterval + (SS - H) * (postInterval / preInterval) // height = H + postInterval - (H - SS) * (postInterval / preInterval)
// height = H + postInterval + (SS - H) * R // height = H + postInterval - (H - SS) * R
// Note: This depends on R being an integer
bool blossomActive = NetworkUpgradeActive(nHeight, Consensus::UPGRADE_BLOSSOM); bool blossomActive = NetworkUpgradeActive(nHeight, Consensus::UPGRADE_BLOSSOM);
if (blossomActive) { if (blossomActive) {
int blossomActivationHeight = vUpgrades[Consensus::UPGRADE_BLOSSOM].nActivationHeight; int blossomActivationHeight = vUpgrades[Consensus::UPGRADE_BLOSSOM].nActivationHeight;
// The following calculation depends on BLOSSOM_POW_TARGET_SPACING_RATIO being an integer. // The following calculation depends on BLOSSOM_POW_TARGET_SPACING_RATIO being an integer.
return blossomActivationHeight + nPostBlossomSubsidyHalvingInterval return blossomActivationHeight + nPostBlossomSubsidyHalvingInterval
+ (SubsidySlowStartShift() - blossomActivationHeight) * BLOSSOM_POW_TARGET_SPACING_RATIO - 1; - (blossomActivationHeight - SubsidySlowStartShift()) * BLOSSOM_POW_TARGET_SPACING_RATIO - 1;
} else { } else {
return nPreBlossomSubsidyHalvingInterval + SubsidySlowStartShift() - 1; return nPreBlossomSubsidyHalvingInterval + SubsidySlowStartShift() - 1;
} }