interfaces: fix findAncestorByHash returning true for unknown descendant #36484

Closed
Romansage6 wants to merge 1 commit from fix-findancestorbyhash-unknown-descendant into master AGit
Romansage6 commented 2026-10-09 07:02:23 +00:00 (Migrated from github.com)

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. 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
DrahtBot commented 2026-10-09 07:02:32 +00:00 (Migrated from github.com)

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.

<!--e57a25ab6845829454e8d69fc972939a--> The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. <!--006a51241073e994b41acfe9ec718e94--> ### External sites * Code coverage & benchmarks: https://corecheck.dev/bitcoin/bitcoin/pulls/36484 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/36484.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/36484#author-ralph <!--021abf342d371248e50ceaed478a90ca--> ### Reviews See [the guideline](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#code-review) and [AI policy](https://github.com/bitcoin/bitcoin/blob/master/doc/AI_POLICY.md) for information on the review process. A summary of reviews will appear here. <!--5faf32d7da4f0f540f40219e4f7537a3-->
First-time contributor

Base: 4bacf21a13c2ed25ef9362ca38f26bf0a67d22c9
Head: ac512d6f396995f21b7b7599b397e562fa352fb1

I found no actionable issues in this static review.

Full review report

<!-- forgejo-review-bot:bitcoin/bitcoin --> Base: `4bacf21a13c2ed25ef9362ca38f26bf0a67d22c9` Head: `ac512d6f396995f21b7b7599b397e562fa352fb1` I found no actionable issues in this static review. [Full review report](<https://review.fish.foo/traces/36484-ac512d6f396995f21b7b7599b397e562fa352fb1-634-1.html>)
l0rinc commented 2026-10-09 07:31:47 +00:00 (Migrated from github.com)
Exact duplicate of https://github.com/bitcoin/bitcoin/pull/36473#issuecomment-6060602624
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
bitcoin/bitcoin!36484
No description provided.