Skip to content

csnode: restore the consensus reward settings correctly from quick-start caches - #87

Open
EnzinoBB wants to merge 1 commit into
CREDITSCOM:masterfrom
CreditsCommunity:official/consensus-settings-restore
Open

EnzinoBB wants to merge 1 commit into
CREDITSCOM:masterfrom
CreditsCommunity:official/consensus-settings-restore

Conversation

@EnzinoBB

@EnzinoBB EnzinoBB commented Nov 1, 2026

Copy link
Copy Markdown

Why this PR

BlockChain keeps the consensus reward settings set by special transaction order 37 (block reward, mining coefficient, stakingOn, miningOn, TimeMinStage1) so that they survive restarts through the quick-start caches. A restarted node can come back with other settings than a node that kept running:

  • BlockChain::setMiningOn() writes stakingOn_ and setStakingOn() writes miningOn_, so after a restart from caches Consensus::stakingOn gets the mining value and Consensus::miningOn the staking value;
  • the quick-start path emits successfullQuickStartEvent(..., miningOn_, miningOn_, ...), so Node::onSuccessQS sets stakingOn from miningOn;
  • the seven members have no initializer, are saved into every checkpoint and are read back on the --set-bc-top path, possibly before anything assigned them.

stakingOn and miningOn drive the block reward computed by trusted nodes (SolverCore::setBlockReward). With both flags on, as on mainnet today, the first two defects have no effect; they would as soon as order 37 changes only one flag.

What changes

  • csnode/src/blockchain.cpp: the two setters write their own member; the quick-start event passes stakingOn_.
  • csnode/include/csnode/blockchain.hpp: the members get the defaults of BlockChain_Serializer::clear() (zero amounts, both flags off, TimeMinStage1 = 500).
  • csnode/src/walletscache.cpp: fundConfidantsWalletsWitnReward logs a warning (one line per 10,000) when it drops a confidant reward above the local blockReward, so a node whose settings differ from the network's shows it. Logging only.

Effect on the network

No change while stakingOn and miningOn are equal, and existing caches keep their meaning. If order 37 ever sets them to different values, restarted nodes with and without this change would compute different rewards, so it should be deployed by all nodes before such an order.

Tests

tests/csnode/blockchain_settings_tests.cpp (new): the setters are independent; the members have defined defaults. Built and run on 4a95aaa (GCC 13).

Same change in the community fork: CreditsCommunity#8 and #12, running on mainnet community nodes.

…art caches

BlockChain keeps the consensus reward settings (special transaction order 37) so that they survive
restarts through the quick-start caches. Three defects affect a restarted node:

- BlockChain::setMiningOn() wrote stakingOn_ and setStakingOn() wrote miningOn_, so after a
  restart from caches Consensus::stakingOn got the mining value and Consensus::miningOn the
  staking value
- the quick-start path emitted successfullQuickStartEvent(..., miningOn_, miningOn_, ...), so
  Node::onSuccessQS set stakingOn from miningOn
- blockRewardIntegral_/Fraction_, miningCoefficientIntegral_/Fraction_, stakingOn_, miningOn_ and
  TimeMinStage1_ had no initializer; they are saved into every checkpoint and read back on the
  --set-bc-top path, possibly before anything assigned them. They now have the defaults of
  BlockChain_Serializer::clear(): zero amounts, both flags off, TimeMinStage1 = 500

stakingOn and miningOn drive the block reward computed by trusted nodes (SolverCore::setBlockReward),
so a restarted node computed other rewards than a node that kept running whenever the two flags
differ. With both flags equal (mainnet today) nothing changes, and existing caches keep their
meaning.

WalletsCache::Updater::fundConfidantsWalletsWitnReward also logs a warning (one line per 10,000)
when it drops a confidant reward above the local blockReward, so that a node whose settings differ
from the network's shows it. Logging only.

Tests: tests/csnode/blockchain_settings_tests.cpp.

Same change in the community fork: #8 and #12.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant