Skip to content

interfaces: fix findAncestorByHash returning true for unknown descendant - #36484

Closed
Romansage6 wants to merge 1 commit into
bitcoin:masterfrom
Romansage6:fix-findancestorbyhash-unknown-descendant
Closed

Romansage6 wants to merge 1 commit into
bitcoin:masterfrom
Romansage6:fix-findancestorbyhash-unknown-descendant

Conversation

@Romansage6

Copy link
Copy Markdown

findAncestorByHash nulled out 'ancestor' only when the descendant block was
also known, due to a 'block &&' guard. If block_hash didn't resolve to a
known block, the guard short-circuited and the still-valid ancestor pointer
was passed to FillBlock, causing the call to report success for an unknown
descendant.

checked the sibling functions findCommonAncestor and findAncestorByHeight
for the same short-circuit pattern; both already default to a null result
whenever either lookup fails, so no equivalent bug exists there.

Extended the existing interfaces_tests/findAncestorByHash unit test with a
regression assertion for an unknown descendant hash. Verified it fails
without the fix and passes with it
(./build/bin/test_bitcoin --run_test=interfaces_tests/findAncestorByHash).

fixes #36472

findAncestorByHash nulled out 'ancestor' only when the descendant block was
also known, due to a 'block &&' guard. If block_hash didn't resolve to a
known block, the guard short-circuited and the still-valid ancestor pointer
was passed to FillBlock, causing the call to report success for an unknown
descendant.

Add a regression assertion to the existing findAncestorByHash unit test.

fixes bitcoin#36472
@DrahtBot DrahtBot added the IPC label Oct 9, 2026
@DrahtBot

DrahtBot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

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

External sites

Reviews

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

@l0rinc

l0rinc commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Exact duplicate of #36473 (comment)

@maflcko maflcko closed this Oct 9, 2026
ryanofsky added a commit to ryanofsky/bitcoin that referenced this pull request Nov 5, 2026
Chain::findAncestorByHash returned true when block_hash was unknown and
ancestor_hash was known, because the check clearing the ancestor pointer
only ran when both hashes were found. Clear the ancestor whenever the
block is not found.

Fixes bitcoin#36472, reported by enirox001 while testing the IPC Chain interface
from bitcoin#29409. The same fix was previously proposed in bitcoin#36473, bitcoin#36484 and
bitcoin#36490 by Romansage6 and Yudis-bit.

This change was written with Claude Opus 5.5 (1M context).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

interfaces: findAncestorByHash returns true for an unknown descendant

4 participants