fix(core): store gap snapshot before writeHeadBlock to close crash window#2476
fix(core): store gap snapshot before writeHeadBlock to close crash window#2476gzliudan wants to merge 1 commit into
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
Fixes a crash/consensus-drop window around XDPoS gap-block snapshot creation by ensuring the masternode snapshot is generated and stored before head markers are persisted (both on normal canonical inserts and during reorgs).
Changes:
- Move gap-block masternode snapshot generation to occur before
writeHeadBlockinwriteBlockWithState. - Apply the same “snapshot-first” ordering in the reorg head-advancement loop.
- Introduce
updateM1ForBlock(block, statedb)to compute candidates/stakes directly from the committed state trie (avoiding dependence onbc.CurrentBlock()/bc.CurrentHeader()).
b1fdf32 to
d93b6cd
Compare
0294177 to
2e605b3
Compare
…ndow UpdateMasternodes (called via UpdateM1) was invoked after writeHeadBlock, leaving a window where the node head pointed to a gap block but no corresponding snapshot existed in the database. If the process was killed or restarted during the lengthy per-candidate EVM calls in UpdateM1, the snapshot would never be written. On the next boot the node would load the gap block as its head, then fail with: Cannot find snapshot from last gap block err="leveldb: not found" on every block in the following epoch, silently dropping out of consensus. Fix: add updateM1ForBlock(block, statedb) which reads candidates and stakes directly from the committed state trie (same as downloader.generateSnapshot) without depending on bc.CurrentBlock() or bc.CurrentHeader(). Both the canonical-chain path (writeBlockWithState) and the reorg path (reorg) now call updateM1ForBlock with bc.StateAt(block.Root()) before writeHeadBlock, so the snapshot is durable before the head markers are persisted. The original UpdateM1 is retained unchanged for external callers and tests.
2e605b3 to
5b1992b
Compare
Proposed changes
UpdateMasternodes (called via UpdateM1) was invoked after writeHeadBlock, leaving a window where the node head pointed to a gap block but no corresponding snapshot existed in the database. If the process was killed or restarted during the lengthy per-candidate EVM calls in UpdateM1, the snapshot would never be written. On the next boot the node would load the gap block as its head, then fail with:
Cannot find snapshot from last gap block err="leveldb: not found"
on every block in the following epoch, silently dropping out of consensus.
Fix: add updateM1ForBlock(block, statedb) which reads candidates and stakes directly from the committed state trie (same as downloader.generateSnapshot) without depending on bc.CurrentBlock() or bc.CurrentHeader(). Both the canonical-chain path (writeBlockWithState) and the reorg path (reorg) now call updateM1ForBlock with bc.StateAt(block.Root()) before writeHeadBlock, so the snapshot is durable before the head markers are persisted.
The original UpdateM1 is retained unchanged for external callers and tests.
Types of changes
What types of changes does your code introduce to XDC network?
Put an
✅in the boxes that applyImpacted Components
Which parts of the codebase does this PR touch?
Put an
✅in the boxes that applyChecklist
Put an
✅in the boxes once you have confirmed below actions (or provide reasons on not doing so) that