diff --git a/csnode/include/csnode/blockchain.hpp b/csnode/include/csnode/blockchain.hpp index a40ef8fb8..348aea307 100644 --- a/csnode/include/csnode/blockchain.hpp +++ b/csnode/include/csnode/blockchain.hpp @@ -553,12 +553,13 @@ public slots: static constexpr size_t kQuickStartSaveCachesInterval = 500'000; std::chrono::steady_clock::time_point lastCheckpointWallClock_ = std::chrono::steady_clock::now(); - int32_t blockRewardIntegral_; - uint64_t blockRewardFraction_ ; - int32_t miningCoefficientIntegral_; - uint64_t miningCoefficientFraction_; - bool stakingOn_; - bool miningOn_; - uint32_t TimeMinStage1_; + // consensus settings persisted in quick-start caches; same defaults as BlockChain_Serializer::clear() + int32_t blockRewardIntegral_ = 0; + uint64_t blockRewardFraction_ = 0; + int32_t miningCoefficientIntegral_ = 0; + uint64_t miningCoefficientFraction_ = 0; + bool stakingOn_ = false; + bool miningOn_ = false; + uint32_t TimeMinStage1_ = 500; }; #endif // BLOCKCHAIN_HPP diff --git a/tests/csnode/blockchain_tests.cpp b/tests/csnode/blockchain_tests.cpp index dcaa2406e..66c9a1833 100644 --- a/tests/csnode/blockchain_tests.cpp +++ b/tests/csnode/blockchain_tests.cpp @@ -61,3 +61,17 @@ TEST(BlockChain, ContentEqualRequiresSameTrustedMask) { canonical.add_real_trusted(cs::Utils::maskToBits(cs::Bytes{ 0, 255, 1 })); ASSERT_FALSE(BlockChain::testContentEqual(own, canonical)); } + +// these members are saved into quick-start caches and read back on the --set-bc-top path, +// possibly before any consensus-settings change has set them +TEST(BlockChain, ConsensusSettingsHaveDefinedDefaults) { + const csdb::Address genesis = csdb::Address::from_string("0000000000000000000000000000000000000000000000000000000000000001"); + const csdb::Address start = csdb::Address::from_string("0000000000000000000000000000000000000000000000000000000000000002"); + BlockChain blockChain(genesis, start); + + ASSERT_TRUE(blockChain.getBlockReward() == csdb::Amount{ 0 }); + ASSERT_TRUE(blockChain.getMiningCoefficient() == csdb::Amount{ 0 }); + ASSERT_FALSE(blockChain.getMiningOn()); + ASSERT_FALSE(blockChain.getStakingOn()); + ASSERT_EQ(blockChain.getTimeMinStage1(), 500u); +}