Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions csnode/include/csnode/blockchain.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions csnode/src/blockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down
16 changes: 16 additions & 0 deletions tests/csnode/blockchain_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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));
}
Loading