Skip to content

csnode: give BlockChain's consensus-settings members defined defaults - #12

Merged
EnzinoBB merged 1 commit into
masterfrom
fix/blockchain-settings-init
Oct 9, 2026
Merged

EnzinoBB merged 1 commit into
masterfrom
fix/blockchain-settings-init

Conversation

@EnzinoBB

@EnzinoBB EnzinoBB commented Oct 9, 2026 •

Copy link
Copy Markdown
Collaborator

Problem (part of path B)

In BlockChain, blockRewardIntegral_/Fraction_, miningCoefficientIntegral_/Fraction_, stakingOn_, miningOn_ and TimeMinStage1_ have no initializer, and the constructor does not set them. Yet:

  • they are written into every quick-start checkpoint (BlockChain_Serializer::save);
  • they are read back on the --set-bc-top path (Node::init);
  • they are emitted by successfullQuickStartEvent.

Until a consensus-settings change, or a cache load, assigns them, using them is undefined behaviour. In particular, a checkpoint saved by a slow-starting node before the order-37 activation can carry arbitrary reward settings.

Fix (blockchain.hpp, +8/-7)

Use the same defaults as BlockChain_Serializer::clear(): zero amounts, both flags off, TimeMinStage1 = 500. Nothing changes for members that are assigned before use.

Test

BlockChain.ConsensusSettingsHaveDefinedDefaults documents the defaults. The old code may pass it by chance, since uninitialised memory often reads as zero: that is the limit of testing undefined behaviour. nodetests 121/121.

What this does not do

It does not persist the pending order-37 change. That needs a new checkpoint format, which would force every node into a slow start, and has to be decided separately. Meanwhile, the warning from PR #8 flags a node with a wrong blockReward within a few blocks.

🤖 Generated with Claude Code

blockRewardIntegral_/Fraction_, miningCoefficientIntegral_/Fraction_,
stakingOn_, miningOn_ and TimeMinStage1_ had no initializer and are not set
by the BlockChain constructor. They are written into every quick-start
checkpoint (BlockChain_Serializer::save), read back on the --set-bc-top path
(Node::init) and emitted by successfullQuickStartEvent. Before any
consensus-settings change, or a cache load, has assigned them, that is
undefined behaviour. In particular, a checkpoint saved by a slow-starting node
before the order-37 activation can carry arbitrary reward settings.

Use the same defaults as BlockChain_Serializer::clear(): zero amounts,
both flags off, TimeMinStage1 = 500. Nothing changes for members that are
assigned before use.

Test: BlockChain.ConsensusSettingsHaveDefinedDefaults. It documents the
defaults; the old code may pass it by chance, since reading uninitialised
memory often yields zero. nodetests: 121/121 pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@EnzinoBB
EnzinoBB merged commit c042eb0 into master Oct 9, 2026
1 check passed
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