From 3b1b0cf164f1967c5767e5a8209b8953b768f6a0 Mon Sep 17 00:00:00 2001 From: EnzinoBB Date: Thu, 8 Oct 2026 12:18:32 +0200 Subject: [PATCH 1/2] csnode: fix swapped mining/staking flags when restoring consensus settings BlockChain keeps the consensus reward settings (set by special transaction order 37) so that they survive restarts through the quick-start caches. Two bugs mix up the two flags: - BlockChain::setMiningOn() writes stakingOn_, and setStakingOn() writes miningOn_. After a restart from caches (Node::init, node.cpp:195-196), Consensus::stakingOn gets the mining value and Consensus::miningOn gets the staking value. - The quick-start path emits successfullQuickStartEvent(..., miningOn_, miningOn_, ...), so Node::onSuccessQS sets stakingOn from miningOn. stakingOn and miningOn drive the block reward computed by trusted nodes (SolverCore::setBlockReward): reward split by stake, and whether a reward is written at all. A restarted node therefore computes different rewards than a node that kept running, whenever the two flags differ. On mainnet today both flags are on (block 176'776'210 distributes rewards by stake), so the bug is latent there. It becomes real as soon as order 37 switches only one of them. With both flags equal, the persisted values do not change meaning, so the fix is safe for existing caches. Test: BlockChain.MiningAndStakingSettersAreIndependent fails before the fix. nodetests: 119/119 pass. Co-Authored-By: Claude Opus 5.5 (1M context) --- csnode/src/blockchain.cpp | 6 +++--- tests/csnode/blockchain_tests.cpp | 19 ++++++++++++++++++- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/csnode/src/blockchain.cpp b/csnode/src/blockchain.cpp index 274d3a30c..b608f4415 100644 --- a/csnode/src/blockchain.cpp +++ b/csnode/src/blockchain.cpp @@ -136,7 +136,7 @@ bool BlockChain::init( if (lastSequence_ != 0) { firstBlockToReadInDatabase = lastSequence_ + 1; trxIndex_->pinFloor(lastSequence_.load()); - emit successfullQuickStartEvent(csdb::Amount(blockRewardIntegral_, blockRewardFraction_), csdb::Amount(miningCoefficientIntegral_, miningCoefficientFraction_), miningOn_, miningOn_, TimeMinStage1_); + emit successfullQuickStartEvent(csdb::Amount(blockRewardIntegral_, blockRewardFraction_), csdb::Amount(miningCoefficientIntegral_, miningCoefficientFraction_), miningOn_, stakingOn_, TimeMinStage1_); } csinfo() << "QUICK START! lastSequence_ is " << lastSequence_.load(); @@ -2349,10 +2349,10 @@ void BlockChain::setMiningCoefficient(csdb::Amount coefficient) { miningCoefficientFraction_ = coefficient.fraction(); } void BlockChain::setMiningOn(bool mOn) { - stakingOn_ = mOn; + miningOn_ = mOn; } void BlockChain::setStakingOn(bool stOn) { - miningOn_ = stOn; + stakingOn_ = stOn; } void BlockChain::setTimeMinStage1(uint32_t timeStage1) { TimeMinStage1_ = timeStage1; diff --git a/tests/csnode/blockchain_tests.cpp b/tests/csnode/blockchain_tests.cpp index d2fdf23d1..7050c422f 100644 --- a/tests/csnode/blockchain_tests.cpp +++ b/tests/csnode/blockchain_tests.cpp @@ -27,4 +27,21 @@ TEST(BlockChain, block_service_info) { ASSERT_TRUE(BlockChain::isBootstrap(block)); BlockChain::setBootstrap(block, false); ASSERT_FALSE(BlockChain::isBootstrap(block)); -} \ No newline at end of file +} +// mining and staking are toggled independently (special transaction order 37) and +// restored from quick-start caches through these accessors +TEST(BlockChain, MiningAndStakingSettersAreIndependent) { + const csdb::Address genesis = csdb::Address::from_string("0000000000000000000000000000000000000000000000000000000000000001"); + const csdb::Address start = csdb::Address::from_string("0000000000000000000000000000000000000000000000000000000000000002"); + BlockChain blockChain(genesis, start); + + blockChain.setMiningOn(true); + blockChain.setStakingOn(false); + ASSERT_TRUE(blockChain.getMiningOn()); + ASSERT_FALSE(blockChain.getStakingOn()); + + blockChain.setMiningOn(false); + blockChain.setStakingOn(true); + ASSERT_FALSE(blockChain.getMiningOn()); + ASSERT_TRUE(blockChain.getStakingOn()); +} From f0995adefdc7eb13e54a131e8b0fc2df06f6ccf2 Mon Sep 17 00:00:00 2001 From: EnzinoBB Date: Thu, 8 Oct 2026 12:18:32 +0200 Subject: [PATCH 2/2] csnode: warn when a confidant reward is dropped by the blockReward limit WalletsCache::Updater::fundConfidantsWalletsWitnReward() credits the rewards stored in a block, but silently turns any reward above the node's local Consensus::blockReward into 0. If a node's blockReward differs from the network's (e.g. a consensus-settings change not applied after a restart), that node stops crediting trusted rewards. Its balances then drift from the rest of the network until a validator's withdrawal fails validation on it ("rejected by graph validation", as for block 176'776'210). Log a warning, rate-limited to one line per 10'000 drops, with the dropped reward and the local blockReward, so operators can see this divergence instead of only its consequences. Logging only: behaviour is unchanged. Co-Authored-By: Claude Opus 5.5 (1M context) --- csnode/src/walletscache.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/csnode/src/walletscache.cpp b/csnode/src/walletscache.cpp index 8b5d3ed6d..6678fc27e 100644 --- a/csnode/src/walletscache.cpp +++ b/csnode/src/walletscache.cpp @@ -105,6 +105,12 @@ void WalletsCache::Updater::fundConfidantsWalletsWitnReward(const cs::Confidants auto walletData = getWalletData(confidants[i]); csdb::Amount reward = rewards[i]; if (reward > Consensus::blockReward || reward < csdb::Amount{ 0 }) { + // a dropped reward makes this node's balances differ from the network's + static uint64_t droppedRewards = 0; + if (droppedRewards++ % 10000 == 0) { + cswarning() << kLogPrefix << "confidant reward " << reward.to_string() << " dropped (local blockReward " + << Consensus::blockReward.to_string() << "), " << droppedRewards << " dropped so far"; + } reward = csdb::Amount{ 0 }; }