From b99003c1ecc1917989e8bcaf53ee19cfaf79e73e Mon Sep 17 00:00:00 2001 From: Eirik Ogilvie-Wigley Date: Wed, 7 Aug 2019 10:05:01 -0600 Subject: [PATCH] Rename method and use int64_t --- src/consensus/params.cpp | 8 ++++---- src/consensus/params.h | 2 +- src/gtest/test_foundersreward.cpp | 8 ++++---- src/main.cpp | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/consensus/params.cpp b/src/consensus/params.cpp index b0f2079e7..1062df349 100644 --- a/src/consensus/params.cpp +++ b/src/consensus/params.cpp @@ -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; } diff --git a/src/consensus/params.h b/src/consensus/params.h index 84fff232a..a3bbbd313 100644 --- a/src/consensus/params.h +++ b/src/consensus/params.h @@ -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; diff --git a/src/gtest/test_foundersreward.cpp b/src/gtest/test_foundersreward.cpp index 7eeb7fa0d..70826ae2a 100644 --- a/src/gtest/test_foundersreward.cpp +++ b/src/gtest/test_foundersreward.cpp @@ -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 diff --git a/src/main.cpp b/src/main.cpp index 3ebe6b371..7447e2f32 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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)