validation: don't treat snapshot block as linked on startup #36702

pull shuv-amp wants to merge 1 commits into bitcoin:master from shuv-amp:fix-snapshot-block-unlinked-on-startup changing 3 files +15 −0
  1. shuv-amp commented at 11:23 AM on October 30, 2026: contributor

    Background sync requests blocks up to and including the snapshot block from several peers at once, so the snapshot block can be stored before one of its ancestors. ReceivedBlockTransactions() then keeps it in m_blocks_unlinked, but that isn't persisted. On restart LoadBlockIndex() gives it the hardcoded m_chain_tx_count, PopulateBlockIndexCandidates() makes it a background candidate, and FindMostWorkChain() walks back to its parent, which has no chain tx count:

    Assertion failed: (pindexTest->HaveNumChainTxs() || pindexTest->nHeight == 0), function FindMostWorkChain, file validation.cpp, line 3217.
    

    It needs a restart in that window, so it should be rare, but after that the node aborts on every start. The only ways out I found are -reindex-chainstate or -reindex, and both delete the snapshot chainstate.

    Fix this by adding the snapshot block to m_blocks_unlinked on startup if an ancestor is missing, and not making it a background candidate until then. Both are needed, without the first one background validation stalls. A node that is already stuck starts with the fix and finishes background validation without a reindex.

    The new step in feature_assumeutxo.py restarts the node after the snapshot block is submitted out of order, and fails on master. I also reproduced it over p2p with a test peer that withholds the snapshot block's parent.

    These are the two changes from #35307 (closed, the motivation there was submitblock before loadtxoutset) without its blockfile and VerifyDB changes. cyb3ralbert hit the same assertion while testing #36452 (https://github.com/bitcoin/bitcoin/pull/36452#issuecomment-6464524112), which is still needed when the snapshot tip is at the snapshot block. #36149 drops the BLOCK_HAVE_DATA check in the branch right below, so whichever is merged second should match it.

  2. DrahtBot added the label Validation on Oct 30, 2026
  3. DrahtBot commented at 11:23 AM on October 30, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    <!--006a51241073e994b41acfe9ec718e94-->

    External sites

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline and AI policy for information on the review process. A summary of reviews will appear here.

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #36503 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36503.svg"></sub> (rpc: reject AssumeUTXO rollback without tip data by l0rinc)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

  4. ValeraFinebits commented at 9:41 AM on October 31, 2026: none

    Tested feature_assumeutxo.py at 80f6ddd on Windows x64: passes with the fix. Reverting only the two C++ changes while keeping the new test reproduces the startup assertion in FindMostWorkChain().

  5. Yudis-bit commented at 4:10 PM on November 4, 2026: none

    Can target_block->pprev be null under mock parameters in unit tests? pindex->pprev is dereferenced directly without a null guard before checking HaveNumChainTxs(), whereas the loop below explicitly guards against null parents.

    Reverting the two C++ hunks against 80f6ddd6c reproduces the SIGABRT at validation.cpp:3217 in FindMostWorkChain. With the patch, feature_assumeutxo.py and validation unit tests pass locally.

    PR #36149 drops BLOCK_HAVE_DATA in LoadBlockIndex so pruned blocks without data stay in m_blocks_unlinked while waiting for parents. Whichever lands second will need to align that branch.

  6. shuv-amp commented at 4:17 PM on November 6, 2026: contributor

    Can target_block->pprev be null under mock parameters in unit tests?

    The target block is only set on the historical chainstate to the snapshot base block (in AddChainstate), which has to match an assumeutxo entry from chainparams and is never genesis. The unit tests create snapshot chainstates on non-genesis blocks as well (or clear the target immediately). The pprev == nullptr guard further down in the loop is for genesis when iterating all block indices.

  7. sedited referenced this in commit 92690e11fe on Nov 9, 2026
  8. sedited referenced this in commit 80de8c2647 on Nov 9, 2026
  9. sedited referenced this in commit 9adfc7a8b2 on Nov 9, 2026
  10. sedited referenced this in commit 14224b5e60 on Nov 10, 2026
  11. sedited referenced this in commit 165c3ef4ba on Nov 10, 2026
  12. sedited referenced this in commit 765d80aa85 on Nov 11, 2026
  13. sedited referenced this in commit 0173cd88d9 on Nov 11, 2026
  14. sedited referenced this in commit 3e5494bd63 on Nov 11, 2026
  15. sedited referenced this in commit e1da1d1a1f on Nov 11, 2026
  16. cyb3ralbert commented at 7:42 AM on November 12, 2026: contributor

    Could you add wait_for_full_init=False to the restart for current master?

    The test waits for index sync before establishing the peer connection needed to complete it. With this change, feature_assumeutxo.py passes.

  17. DrahtBot added the label CI failed on Nov 12, 2026
  18. sedited referenced this in commit 4dfbb745de on Nov 12, 2026
  19. sedited referenced this in commit 0e95c753ee on Nov 12, 2026
  20. validation: don't treat snapshot block as linked on startup
    If the snapshot block is received during background sync before some
    of its ancestors, ReceivedBlockTransactions() adds it to
    m_blocks_unlinked and it isn't a background candidate until the
    missing blocks arrive.
    
    LoadBlockIndex() doesn't restore this on restart. The snapshot block
    gets its m_chain_tx_count from the assumeutxo data and is never added
    to m_blocks_unlinked, so PopulateBlockIndexCandidates() makes it a
    background candidate. FindMostWorkChain() then walks back to its
    parent, which has m_chain_tx_count 0, and hits the HaveNumChainTxs()
    assert. This happens on every restart.
    
    Add the block to m_blocks_unlinked on startup if an ancestor is
    missing, and skip it as a background candidate until then. Without
    the m_blocks_unlinked entry the block isn't picked up when the
    missing blocks arrive, and background validation stalls.
    
    Extend feature_assumeutxo.py to restart the node in this state.
    aad458e785
  21. shuv-amp force-pushed on Nov 12, 2026
  22. shuv-amp commented at 5:35 PM on November 12, 2026: contributor

    Could you add wait_for_full_init=False to the restart for current master?

    Rebased and done.

  23. DrahtBot removed the label CI failed on Nov 12, 2026
  24. sedited referenced this in commit c03b1170ae on Nov 12, 2026
  25. sedited referenced this in commit cf4d0fa738 on Nov 12, 2026
  26. sedited referenced this in commit 6e063cf69d on Nov 13, 2026
  27. sedited referenced this in commit 89376e4665 on Nov 13, 2026
  28. sedited referenced this in commit e8b36f4180 on Nov 14, 2026
  29. sedited referenced this in commit c2b225cbd8 on Nov 15, 2026

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-11-20 15:51 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me