interfaces: fix findAncestorByHash false positive #36473

pull Romansage6 wants to merge 1 commits into bitcoin:master from Romansage6:2026-10-fix-findancestorbyhash changing 2 files +3 −1
  1. Romansage6 commented at 1:04 PM on October 8, 2026: none

    findAncestorByHash looks up both block_hash and ancestor_hash, then was only supposed to clear the ancestor pointer when the lookups succeeded but the ancestor relationship didn't hold:

    if (block && ancestor && block->GetAncestor(ancestor->nHeight) != ancestor) ancestor = nullptr;
    

    Because of the && short circuit, an unknown block_hash makes the whole condition false without ever evaluating the relationship check, so a successful ancestor_hash lookup is passed through unmodified and the function reports true for a descendant that doesn't exist.

    Before:

    chain->findAncestorByHash(uint256{}, active[0]->GetBlockHash()) // returns true
    

    After this change it correctly returns false when either hash is unknown, in addition to the existing relationship check.

    Tested with:

    cmake --build build --target test_bitcoin -j8
    ./build/bin/test_bitcoin --run_test=interfaces_tests
    

    Full suite (./build/bin/test_bitcoin, 877 cases) also passes with no regressions. Added two new cases to interfaces_tests/findAncestorByHash covering unknown block_hash and unknown ancestor_hash, which fail on master and pass with this fix.

    Fixes #36472

  2. interfaces: fix findAncestorByHash false positive
    findAncestorByHash looked up both block_hash and ancestor_hash, then
    cleared the ancestor pointer only when both lookups succeeded but the
    ancestor relationship did not hold:
    
      if (block && ancestor && block->GetAncestor(...) != ancestor)
          ancestor = nullptr;
    
    Because of the && short circuit, an unknown block_hash made the whole
    condition false without ever running the relationship check, so a
    successful ancestor_hash lookup was passed through unmodified and the
    function reported true for a descendant that does not exist.
    
    Clear the ancestor whenever either lookup fails, not only when the
    relationship check fails.
    
    Add unit test cases for an unknown block_hash and an unknown
    ancestor_hash, matching the reported regression.
    
    Fixes #36472
    ccea7c93f5
  3. DrahtBot added the label IPC on Oct 8, 2026
  4. DrahtBot commented at 1:05 PM on October 8, 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.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

  5. sedited commented at 1:10 PM on October 8, 2026: contributor

    This seems to be a drive-by LLM contribution from an issue that was created not even an hour ago. Closing again.

  6. sedited closed this on Oct 8, 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-10-11 08:51 UTC

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