InvalidateBlock assert with AddToBlockIndex #36117

issue Crypt-iQ opened this issue on August 28, 2026
  1. Crypt-iQ commented at 6:17 PM on August 28, 2026: contributor

    While reviewing #34254, I asked Claude to examine for any multi-threaded issues with InvalidateBlock. It came up with the following crash which I verified:

    • [rpc thread] in InvalidateBlock, populate the list of highpow_outofchain_headers here and then release cs_main. These headers are all better than the new tip we should be getting and will be used to update m_best_header later.
    • [other thread] acquire cs_main and call AddToBlockIndex with a header that is not better than m_best_header but is better than every header in highpow_outofchain_headers. This means AddToBlockIndex won't update m_best_header here
    • [rpc thread] acquire cs_main in the loop and update m_best_header based on the candidates in highpow_outofchain_headers here
    • [rpc thread] calls CheckBlockIndex which fails on the assert since there is actually a header with more work than m_best_header: https://github.com/bitcoin/bitcoin/blob/05e49b342faa1412266951429c135e9f5daa30c2/src/validation.cpp#L5317-L5318

    Haven't really thought about how to fix this too much.

    Vibe-coded functional test: https://github.com/Crypt-iQ/bitcoin/tree/08282026/rpc_invalidateblock_crash Run with: <build_dir>/test/functional/test_runner.py rpc_invalidateblock.py --race-attempts=5000 and inspect stderr of node2 in the tmp test directory.

  2. Crypt-iQ commented at 6:18 PM on August 28, 2026: contributor
  3. furszy commented at 7:28 PM on August 28, 2026: member

    there are a few known issues that invalidateblock has, including this one. I took advantage of one of them to trigger other issues that are harder to reach without it #35003 (review) (this is essentially a lack of atomicity). It would be good to fix that one too now that we are going to touch this.

  4. Crypt-iQ commented at 7:40 PM on August 28, 2026: contributor

    @furszy is there a list of these issues so we can triage them? I think Claude found another one and I'm unsure if it's a dupe.

  5. furszy commented at 8:11 PM on August 28, 2026: member

    I drop them into random PR comments to make the scavenger hunt slightly more interesting. Jokes aside, no single issue listing them all I am aware of. We can start grouping them.


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-08-31 18:51 UTC

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