Skip to content

csnode: fix swapped mining/staking flags on restore + warn on dropped rewards - #8

Merged
EnzinoBB merged 2 commits into
masterfrom
fix/consensus-settings-restore
Oct 9, 2026
Merged

EnzinoBB merged 2 commits into
masterfrom
fix/consensus-settings-restore

Conversation

@EnzinoBB

@EnzinoBB EnzinoBB commented Oct 8, 2026 •

Copy link
Copy Markdown
Collaborator

Context

Since 5 June 2026 some nodes have been stuck at block 176'776'210 (rejected by graph validation, then stop block validation). Its only transaction is validator 9c8VaDD6… withdrawing 57'744 CS of accumulated trusted-node rewards. On the stuck nodes that wallet holds a lower balance than on the rest of the network: node balances diverge. The exact root cause is still to be proven and needs logs from stuck nodes. This PR fixes two defects found on the reward path.

1. fix swapped mining/staking flags… (real bug, latent on mainnet today)

  • BlockChain::setMiningOn() writes stakingOn_ and setStakingOn() writes miningOn_, so after a restart from caches the two consensus flags are swapped.
  • Quick start emits miningOn_ twice, so stakingOn takes the mining value.
  • The flags drive the reward computed by trusted nodes (SolverCore::setBlockReward). A restarted node computes different rewards from one that kept running whenever the two flags differ.
  • On mainnet both are on today, so the bug is latent and the fix is safe for existing caches. It would bite on the first order-37 change that switches only one of them.
  • Test BlockChain.MiningAndStakingSettersAreIndependent: fails before the fix, passes after.

2. warn when a confidant reward is dropped… (diagnostics, behaviour unchanged)

fundConfidantsWalletsWitnReward() silently turns into 0 any reward above the local Consensus::blockReward. A node whose blockReward differs from the network's stops crediting rewards, and its balances drift until a validator's withdrawal fails. The node now logs it, at most one line per 10'000 occurrences.

Verification

nodetests 119/119 locally (GCC 13, static Boost 1.83); CI on this PR.

Upstream

Two independent commits that apply as is to CREDITSCOM/node (identical files).

🤖 Generated with Claude Code

EnzinoBB and others added 2 commits October 8, 2026 12:18
…tings

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) <noreply@anthropic.com>
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) <noreply@anthropic.com>
@EnzinoBB
EnzinoBB merged commit b8cfe86 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