interfaces: fix findAncestorByHash returning true for unknown block #36490

pull Yudis-bit wants to merge 1 commits into bitcoin:master from Yudis-bit:fix-findancestor-unknown changing 2 files +7 −1
  1. Yudis-bit commented at 4:01 PM on October 9, 2026: none

    Fixes #36472.

    When findAncestorByHash(block_hash, ancestor_hash, ...) is called with an unknown or null block_hash, LookupBlockIndex(block_hash) returns nullptr. The preceding check if (block && ancestor && block->GetAncestor(...) != ancestor) ancestor = nullptr; evaluates to false when block is null, leaving ancestor untouched. If ancestor_hash exists, FillBlock(ancestor, ...) evaluates to true, falsely reporting that an unknown descendant descends from a known block.

    This patch updates the guard in src/node/interfaces.cpp to ensure ancestor is reset to null whenever !block || !ancestor || block->GetAncestor(ancestor->nHeight) != ancestor.

    Unit test coverage is added in src/test/interfaces_tests.cpp asserting that findAncestorByHash returns false when block_hash is null, preserves height = -1 in the output struct, returns false when ancestor_hash is null, returns false when both are null, and correctly returns true for identical blocks.

  2. interfaces: fix findAncestorByHash returning true for unknown block
    When the block argument cannot be resolved via LookupBlockIndex (i.e. block is nullptr), findAncestorByHash previously left ancestor untouched, incorrectly returning true if ancestor was valid.
    
    Fix this by ensuring ancestor is set to nullptr if either block or ancestor is null, or if block does not descend from ancestor. Add unit test assertions covering unknown block, unknown ancestor, both unknown, and height preservation.
    3cae888dc8
  3. Yudis-bit requested review from Copilot on Oct 9, 2026
  4. DrahtBot added the label IPC on Oct 9, 2026
  5. Copilot commented at 4:01 PM on October 9, 2026: none

    Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

  6. DrahtBot commented at 4:01 PM on October 9, 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-->

  7. sedited commented at 7:40 PM on October 9, 2026: contributor

    Another duplicate of #36473 (comment)

  8. sedited closed this on Oct 9, 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