diff --git a/src/consensus/params.cpp b/src/consensus/params.cpp index 2179a30d3..35cc6c9d2 100644 --- a/src/consensus/params.cpp +++ b/src/consensus/params.cpp @@ -18,12 +18,12 @@ namespace Consensus { // postBlossom: // 1 = (H - SS) / preInterval + (height - H) / postInterval // height = H + postInterval + (SS - H) * (postInterval / preInterval) - // height = H + postInterval + (SS - H) / R + // height = H + postInterval + (SS - H) * R bool blossomActive = NetworkUpgradeActive(nHeight, Consensus::UPGRADE_BLOSSOM); if (blossomActive) { int blossomActivationHeight = vUpgrades[Consensus::UPGRADE_BLOSSOM].nActivationHeight; return blossomActivationHeight + nPostBlossomSubsidyHalvingInterval - - (SubsidySlowStartShift() - blossomActivationHeight) / BLOSSOM_POW_TARGET_SPACING_RATIO - 1; + + (SubsidySlowStartShift() - blossomActivationHeight) * BLOSSOM_POW_TARGET_SPACING_RATIO - 1; } else { return nPreBlossomSubsidyHalvingInterval + SubsidySlowStartShift() - 1; } diff --git a/src/consensus/params.h b/src/consensus/params.h index 7ececeeb7..979d294bf 100644 --- a/src/consensus/params.h +++ b/src/consensus/params.h @@ -67,7 +67,7 @@ static const unsigned int POST_BLOSSOM_POW_TARGET_SPACING = 75; static_assert(POST_BLOSSOM_POW_TARGET_SPACING < PRE_BLOSSOM_POW_TARGET_SPACING, "Blossom target spacing must be less than pre-Blossom target spacing."); static const unsigned int PRE_BLOSSOM_HALVING_INTERVAL = 840000; static const unsigned int PRE_BLOSSOM_REGTEST_HALVING_INTERVAL = 150; -static const unsigned int BLOSSOM_POW_TARGET_SPACING_RATIO = PRE_BLOSSOM_POW_TARGET_SPACING / POST_BLOSSOM_POW_TARGET_SPACING; +static const int BLOSSOM_POW_TARGET_SPACING_RATIO = PRE_BLOSSOM_POW_TARGET_SPACING / POST_BLOSSOM_POW_TARGET_SPACING; static const unsigned int POST_BLOSSOM_HALVING_INTERVAL = PRE_BLOSSOM_HALVING_INTERVAL * BLOSSOM_POW_TARGET_SPACING_RATIO; static const unsigned int POST_BLOSSOM_REGTEST_HALVING_INTERVAL = PRE_BLOSSOM_REGTEST_HALVING_INTERVAL * BLOSSOM_POW_TARGET_SPACING_RATIO; diff --git a/src/gtest/test_foundersreward.cpp b/src/gtest/test_foundersreward.cpp index 15e2c81b7..1f4f82411 100644 --- a/src/gtest/test_foundersreward.cpp +++ b/src/gtest/test_foundersreward.cpp @@ -13,6 +13,7 @@ #include #include #include "util.h" +#include "utiltest.h" // To run tests: // ./zcash-gtest --gtest_filter="founders_reward_test.*" @@ -119,6 +120,15 @@ TEST(founders_reward_test, general) { EXPECT_DEATH(params.GetFoundersRewardAddressAtHeight(maxHeight+1), "nHeight"); } +TEST(founders_reward_test, get_last_block_blossom) { + int blossomActivationHeight = /*slowStartShift*/ + Consensus::PRE_BLOSSOM_REGTEST_HALVING_INTERVAL / 2; // = 75 + auto params = RegtestActivateBlossom(false, blossomActivationHeight); + int slowStartShift = params.SubsidySlowStartShift(); // 0 for regtest + EXPECT_EQ(Consensus::PRE_BLOSSOM_REGTEST_HALVING_INTERVAL + slowStartShift - 1, params.GetLastFoundersRewardBlockHeight(0)); + EXPECT_EQ(Consensus::PRE_BLOSSOM_REGTEST_HALVING_INTERVAL + slowStartShift - 1, params.GetLastFoundersRewardBlockHeight(blossomActivationHeight - 1)); + int blossomBlocks = (Consensus::PRE_BLOSSOM_REGTEST_HALVING_INTERVAL- blossomActivationHeight) * Consensus::BLOSSOM_POW_TARGET_SPACING_RATIO; + EXPECT_EQ(blossomActivationHeight + blossomBlocks + slowStartShift - 1, params.GetLastFoundersRewardBlockHeight(blossomActivationHeight)); +} #define NUM_MAINNET_FOUNDER_ADDRESSES 48 @@ -147,7 +157,7 @@ TEST(founders_reward_test, regtest) { // Test that 10% founders reward is fully rewarded after the first halving and slow start shift. // On Mainnet, this would be 2,100,000 ZEC after 850,000 blocks (840,000 + 10,000). -TEST(founders_reward_test, slow_start_subsidy) { +TEST(founders_reward_test, slow_start_subsidy) { // TODO: Update this test when the Blossom activation height is set SelectParams(CBaseChainParams::MAIN); CChainParams params = Params(); diff --git a/src/gtest/test_pow.cpp b/src/gtest/test_pow.cpp index 281701892..4e0e8fcdc 100644 --- a/src/gtest/test_pow.cpp +++ b/src/gtest/test_pow.cpp @@ -79,8 +79,8 @@ TEST(PoW, DifficultyAveraging) { } TEST(PoW, DifficultyAveragingBlossom) { - TestDifficultyAveragigingImpl(ActivateBlossom(true)); - DeactivateBlossom(); + TestDifficultyAveragigingImpl(RegtestActivateBlossom(true)); + RegtestDeactivateBlossom(); } TEST(PoW, MinDifficultyRules) { diff --git a/src/test/pow_tests.cpp b/src/test/pow_tests.cpp index 416b4ac7c..3aebbc00d 100644 --- a/src/test/pow_tests.cpp +++ b/src/test/pow_tests.cpp @@ -32,7 +32,7 @@ BOOST_AUTO_TEST_CASE(get_next_work) BOOST_AUTO_TEST_CASE(get_next_work_blossom) { - const Consensus::Params& params = ActivateBlossom(true); + const Consensus::Params& params = RegtestActivateBlossom(true); BOOST_CHECK_EQUAL(75, params.PoWTargetSpacing(0)); int64_t nLastRetargetTime = 1000000000; // NOTE: Not an actual block time @@ -42,7 +42,7 @@ BOOST_AUTO_TEST_CASE(get_next_work_blossom) BOOST_CHECK_GT(0x1d011998, CalculateNextWorkRequired(bnAvg, nThisTime, nLastRetargetTime, params, 0)); - DeactivateBlossom(); + RegtestDeactivateBlossom(); } /* Test the constraint on the upper bound for next work */ @@ -61,7 +61,7 @@ BOOST_AUTO_TEST_CASE(get_next_work_pow_limit) BOOST_AUTO_TEST_CASE(get_next_work_pow_limit_blossom) { - const Consensus::Params& params = ActivateBlossom(true); + const Consensus::Params& params = RegtestActivateBlossom(true); int64_t nLastRetargetTime = 1231006505; int64_t nThisTime = 1233061996; @@ -70,7 +70,7 @@ BOOST_AUTO_TEST_CASE(get_next_work_pow_limit_blossom) BOOST_CHECK_EQUAL(0x1f07ffff, CalculateNextWorkRequired(bnAvg, nThisTime, nLastRetargetTime, params, 0)); - DeactivateBlossom(); + RegtestDeactivateBlossom(); } /* Test the constraint on the lower bound for actual time taken */ @@ -91,7 +91,7 @@ BOOST_AUTO_TEST_CASE(get_next_work_lower_limit_actual) BOOST_AUTO_TEST_CASE(get_next_work_lower_limit_actual_blossom) { - const Consensus::Params& params = ActivateBlossom(true); + const Consensus::Params& params = RegtestActivateBlossom(true); int64_t nLastRetargetTime = 1000000000; // NOTE: Not an actual block time int64_t nThisTime = 1000000458; @@ -100,7 +100,7 @@ BOOST_AUTO_TEST_CASE(get_next_work_lower_limit_actual_blossom) BOOST_CHECK_EQUAL(0x1c04bceb, CalculateNextWorkRequired(bnAvg, nThisTime, nLastRetargetTime, params, 0)); - DeactivateBlossom(); + RegtestDeactivateBlossom(); } /* Test the constraint on the upper bound for actual time taken */ @@ -120,7 +120,7 @@ BOOST_AUTO_TEST_CASE(get_next_work_upper_limit_actual) BOOST_AUTO_TEST_CASE(get_next_work_upper_limit_actual_blossom) { - const Consensus::Params& params = ActivateBlossom(true); + const Consensus::Params& params = RegtestActivateBlossom(true); int64_t nLastRetargetTime = 1000000000; // NOTE: Not an actual block time int64_t nThisTime = 1000002908; @@ -129,7 +129,7 @@ BOOST_AUTO_TEST_CASE(get_next_work_upper_limit_actual_blossom) BOOST_CHECK_EQUAL(0x1c4a93bb, CalculateNextWorkRequired(bnAvg, nThisTime, nLastRetargetTime, params, 0)); - DeactivateBlossom(); + RegtestDeactivateBlossom(); } void GetBlockProofEquivalentTimeImpl(const Consensus::Params& params) { @@ -160,8 +160,8 @@ BOOST_AUTO_TEST_CASE(GetBlockProofEquivalentTime_test) BOOST_AUTO_TEST_CASE(GetBlockProofEquivalentTime_test_blossom) { - GetBlockProofEquivalentTimeImpl(ActivateBlossom(true)); - DeactivateBlossom(); + GetBlockProofEquivalentTimeImpl(RegtestActivateBlossom(true)); + RegtestDeactivateBlossom(); } BOOST_AUTO_TEST_SUITE_END() diff --git a/src/utiltest.cpp b/src/utiltest.cpp index 9e382d084..d8e1e4410 100644 --- a/src/utiltest.cpp +++ b/src/utiltest.cpp @@ -200,18 +200,18 @@ void RegtestDeactivateSapling() { UpdateNetworkUpgradeParameters(Consensus::UPGRADE_OVERWINTER, Consensus::NetworkUpgrade::NO_ACTIVATION_HEIGHT); } -const Consensus::Params& ActivateBlossom(bool updatePow) { +const Consensus::Params& RegtestActivateBlossom(bool updatePow, int blossomActivationHeight) { SelectParams(CBaseChainParams::REGTEST); UpdateNetworkUpgradeParameters(Consensus::UPGRADE_OVERWINTER, Consensus::NetworkUpgrade::ALWAYS_ACTIVE); UpdateNetworkUpgradeParameters(Consensus::UPGRADE_SAPLING, Consensus::NetworkUpgrade::ALWAYS_ACTIVE); - UpdateNetworkUpgradeParameters(Consensus::UPGRADE_BLOSSOM, Consensus::NetworkUpgrade::ALWAYS_ACTIVE); + UpdateNetworkUpgradeParameters(Consensus::UPGRADE_BLOSSOM, blossomActivationHeight); if (updatePow) { UpdateRegtestPow(32, 16, uint256S("0007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")); } return Params().GetConsensus(); } -void DeactivateBlossom() { +void RegtestDeactivateBlossom() { UpdateRegtestPow(0, 0, uint256S("0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f")); UpdateNetworkUpgradeParameters(Consensus::UPGRADE_BLOSSOM, Consensus::NetworkUpgrade::NO_ACTIVATION_HEIGHT); UpdateNetworkUpgradeParameters(Consensus::UPGRADE_SAPLING, Consensus::NetworkUpgrade::NO_ACTIVATION_HEIGHT); diff --git a/src/utiltest.h b/src/utiltest.h index 9fd3b6613..df060362e 100644 --- a/src/utiltest.h +++ b/src/utiltest.h @@ -43,9 +43,9 @@ const Consensus::Params& RegtestActivateSapling(); void RegtestDeactivateSapling(); -const Consensus::Params& ActivateBlossom(bool updatePow); +const Consensus::Params& RegtestActivateBlossom(bool updatePow, int blossomActivationHeight = Consensus::NetworkUpgrade::ALWAYS_ACTIVE); -void DeactivateBlossom(); +void RegtestDeactivateBlossom(); libzcash::SaplingExtendedSpendingKey GetTestMasterSaplingSpendingKey();