diff --git a/csnode/include/csnode/blockchain.hpp b/csnode/include/csnode/blockchain.hpp index fe82eedd0..a40ef8fb8 100644 --- a/csnode/include/csnode/blockchain.hpp +++ b/csnode/include/csnode/blockchain.hpp @@ -408,6 +408,10 @@ public slots: void setStakingOn(bool stOn); void setTimeMinStage1(uint32_t timeStage1); + // compare only state content: transactions, new wallets, sequence, round fee, user fields, trusted mask + // true if both pools are not valid, or both pools have equal state content + static bool testContentEqual(const csdb::Pool& lhs, const csdb::Pool& rhs); + private: void createCachesPath(); @@ -545,10 +549,6 @@ public slots: cs::CachesSerializationManager* serializationManPtr_ = nullptr; - // compare only state content: transactions, new wallets, sequence, round fee, user fields - // true if both pools are not valid, or both pools have equal state content - static bool testContentEqual(const csdb::Pool& lhs, const csdb::Pool& rhs); - friend class cs::BlockChain_Serializer; static constexpr size_t kQuickStartSaveCachesInterval = 500'000; diff --git a/csnode/src/blockchain.cpp b/csnode/src/blockchain.cpp index b608f4415..a1b06da46 100644 --- a/csnode/src/blockchain.cpp +++ b/csnode/src/blockchain.cpp @@ -2139,6 +2139,8 @@ namespace { for (const auto& it : confidants) { out << it; } + // rewards and fees are credited only to the confidants marked as trusted + out << block.numberTrusted() << block.realTrusted(); out << block.previous_hash(); } } diff --git a/tests/csnode/blockchain_tests.cpp b/tests/csnode/blockchain_tests.cpp index 7050c422f..dcaa2406e 100644 --- a/tests/csnode/blockchain_tests.cpp +++ b/tests/csnode/blockchain_tests.cpp @@ -28,6 +28,7 @@ TEST(BlockChain, block_service_info) { BlockChain::setBootstrap(block, false); ASSERT_FALSE(BlockChain::isBootstrap(block)); } + // mining and staking are toggled independently (special transaction order 37) and // restored from quick-start caches through these accessors TEST(BlockChain, MiningAndStakingSettersAreIndependent) { @@ -45,3 +46,18 @@ TEST(BlockChain, MiningAndStakingSettersAreIndependent) { ASSERT_FALSE(blockChain.getMiningOn()); ASSERT_TRUE(blockChain.getStakingOn()); } + +// an "uncertain" own block is replaced in place by the network's version only when testContentEqual() holds; +// rewards and fees are credited through the trusted mask, so a different mask must not count as equal content +TEST(BlockChain, ContentEqualRequiresSameTrustedMask) { + csdb::Pool own; + own.set_sequence(10); + own.add_number_trusted(3); + own.add_real_trusted(0); + + csdb::Pool canonical = own.clone(); + ASSERT_TRUE(BlockChain::testContentEqual(own, canonical)); + + canonical.add_real_trusted(cs::Utils::maskToBits(cs::Bytes{ 0, 255, 1 })); + ASSERT_FALSE(BlockChain::testContentEqual(own, canonical)); +}