Rename method and use int64_t
This commit is contained in:
parent
d9ef43dc25
commit
b99003c1ec
|
@ -11,22 +11,22 @@ namespace Consensus {
|
|||
return NetworkUpgradeState(nHeight, *this, idx) == UPGRADE_ACTIVE;
|
||||
}
|
||||
|
||||
int Params::Halvings(int nHeight) const {
|
||||
int Params::Halving(int nHeight) const {
|
||||
// zip208
|
||||
// Halving(height) :=
|
||||
// floor((height - SlowStartShift) / PreBlossomHalvingInterval), if not IsBlossomActivated(height)
|
||||
// floor((BlossomActivationHeight - SlowStartShift) / PreBlossomHalvingInterval + (height - BlossomActivationHeight) / PostBlossomHalvingInterval), otherwise
|
||||
if (NetworkUpgradeActive(nHeight, Consensus::UPGRADE_BLOSSOM)) {
|
||||
int blossomActivationHeight = vUpgrades[Consensus::UPGRADE_BLOSSOM].nActivationHeight;
|
||||
int64_t blossomActivationHeight = vUpgrades[Consensus::UPGRADE_BLOSSOM].nActivationHeight;
|
||||
// Ideally we would say:
|
||||
// halvings = (blossomActivationHeight - consensusParams.SubsidySlowStartShift()) / consensusParams.nPreBlossomSubsidyHalvingInterval
|
||||
// + (nHeight - blossomActivationHeight) / consensusParams.nPostBlossomSubsidyHalvingInterval;
|
||||
// But, (blossomActivationHeight - consensusParams.SubsidySlowStartShift()) / consensusParams.nPreBlossomSubsidyHalvingInterval
|
||||
// would need to be treated as a rational number in order for this to work.
|
||||
// Define scaledHalvings := halvings * consensusParams.nPostBlossomSubsidyHalvingInterval;
|
||||
int scaledHalvings = ((blossomActivationHeight - SubsidySlowStartShift()) * Consensus::BLOSSOM_POW_TARGET_SPACING_RATIO)
|
||||
int64_t scaledHalvings = ((blossomActivationHeight - SubsidySlowStartShift()) * Consensus::BLOSSOM_POW_TARGET_SPACING_RATIO)
|
||||
+ (nHeight - blossomActivationHeight);
|
||||
return scaledHalvings / nPostBlossomSubsidyHalvingInterval;
|
||||
return (int) (scaledHalvings / nPostBlossomSubsidyHalvingInterval);
|
||||
} else {
|
||||
return (nHeight - SubsidySlowStartShift()) / nPreBlossomSubsidyHalvingInterval;
|
||||
}
|
||||
|
|
|
@ -104,7 +104,7 @@ struct Params {
|
|||
int nPreBlossomSubsidyHalvingInterval;
|
||||
int nPostBlossomSubsidyHalvingInterval;
|
||||
|
||||
int Halvings(int nHeight) const;
|
||||
int Halving(int nHeight) const;
|
||||
|
||||
int GetLastFoundersRewardBlockHeight(int nHeight) const;
|
||||
|
||||
|
|
|
@ -129,8 +129,8 @@ TEST(founders_reward_test, regtest_get_last_block_blossom) {
|
|||
int blossomActivationHeight = Consensus::PRE_BLOSSOM_REGTEST_HALVING_INTERVAL / 2; // = 75
|
||||
auto params = RegtestActivateBlossom(false, blossomActivationHeight);
|
||||
int lastFRHeight = params.GetLastFoundersRewardBlockHeight(blossomActivationHeight);
|
||||
EXPECT_EQ(0, params.Halvings(lastFRHeight));
|
||||
EXPECT_EQ(1, params.Halvings(lastFRHeight + 1));
|
||||
EXPECT_EQ(0, params.Halving(lastFRHeight));
|
||||
EXPECT_EQ(1, params.Halving(lastFRHeight + 1));
|
||||
RegtestDeactivateBlossom();
|
||||
}
|
||||
|
||||
|
@ -138,8 +138,8 @@ TEST(founders_reward_test, mainnet_get_last_block) {
|
|||
SelectParams(CBaseChainParams::MAIN);
|
||||
auto params = Params().GetConsensus();
|
||||
int lastFRHeight = GetLastFoundersRewardHeight(params);
|
||||
EXPECT_EQ(0, params.Halvings(lastFRHeight));
|
||||
EXPECT_EQ(1, params.Halvings(lastFRHeight + 1));
|
||||
EXPECT_EQ(0, params.Halving(lastFRHeight));
|
||||
EXPECT_EQ(1, params.Halving(lastFRHeight + 1));
|
||||
}
|
||||
|
||||
#define NUM_MAINNET_FOUNDER_ADDRESSES 48
|
||||
|
|
|
@ -1762,7 +1762,7 @@ CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams)
|
|||
|
||||
assert(nHeight > consensusParams.SubsidySlowStartShift());
|
||||
|
||||
int halvings = consensusParams.Halvings(nHeight);
|
||||
int halvings = consensusParams.Halving(nHeight);
|
||||
|
||||
// Force block reward to zero when right shift is undefined.
|
||||
if (halvings >= 64)
|
||||
|
|
Loading…
Reference in New Issue