validation: remove unused code in FindMostWorkChain #34884

pull stratospher wants to merge 2 commits into bitcoin:master from stratospher:2026_03_remove_unused_fmw changing 2 files +87 −2
  1. stratospher commented at 3:57 pm on March 20, 2026: contributor

    recent PRs like #31405, #30666 mark all m_block_index descendants as invalid immediately whenever an invalid block is encountered in SetBlockFailureFlags. so by the time we reach FindMostWorkChain, the block in setBlockIndexCandidates already has BLOCK_FAILED_VALID set on it - not just on its ancestor. this means pindexTest = pindexFailed whenever fFailedChain fires, and the inner while (pindexTest != pindexFailed) loop body is never reached!

    I think we can remove it but I’ve just replaced it with Assume in this PR for safety + good to document this invariant in case the code changes in future. (noticed by @ stickies-v in #32950 (review))

    the second commit is unrelated and adds a unit test for the situation in https://github.com/bitcoin/bitcoin/issues/32173

  2. validation: remove unused code in FindMostWorkChain
    the newer validation commits mark all m_block_index descendants
    as invalid immediately whenever an invalid block is encountered.
    (in SetBlockFailureFlags). there's also a CheckBlockIndex assert
    for this in ed764ea.
    
    so by the time we reach FindMostWorkChain, they're already
    marked as invalid and no need to repeat the work here.
    also nice logically for FindMostWorkChain to not deal with
    changing block validity status inside it.
    5690917fcb
  3. test: add invalidateblock, reconsiderblock unit test
    invalidateblock (iterates throguh all block indices) and
    reconsiderblock (iterates through ancestors/descendants)
    are not symmetrical to each other and can lead to edge case
    block constellations like in issue #32173 (fixed in 37bc207)
    being formed.
    
    add unit test for this scenario to safe guard against
    future regressions.
    a122fbd4c5
  4. DrahtBot added the label Validation on Mar 20, 2026
  5. DrahtBot commented at 3:58 pm on March 20, 2026: contributor

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

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    Concept ACK stickies-v

    If your review is incorrectly listed, please copy-paste <!–meta-tag:bot-skip–> into the comment that the bot should ignore.

    LLM Linter (✨ experimental)

    Possible typos and grammar issues:

    • we have a chain of 100 blocks: ... -> We have a chain of 100 blocks: ... [Sentence starts with lowercase “we”, which is a capitalization typo.]
    • by temporarily invalidating block99. the chain tip now falls to block98, -> by temporarily invalidating block99. The chain tip now falls to block98, [Lowercase “the” after a period is a capitalization typo.]

    2026-03-20 15:58:14

  6. stickies-v commented at 4:44 pm on March 20, 2026: contributor
    Concept ACK

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-03-20 18:13 UTC

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