Repository navigation
Conversation
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.
Contributor
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. External sites
ReviewsSee the guideline and AI policy for information on the review process. |
Contributor
|
Another duplicate of #36473 (comment) |
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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Fixes #36472.
When
findAncestorByHash(block_hash, ancestor_hash, ...)is called with an unknown or nullblock_hash,LookupBlockIndex(block_hash)returnsnullptr. The preceding checkif (block && ancestor && block->GetAncestor(...) != ancestor) ancestor = nullptr;evaluates to false whenblockis null, leavingancestoruntouched. Ifancestor_hashexists,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.cppto ensureancestoris reset to null whenever!block || !ancestor || block->GetAncestor(ancestor->nHeight) != ancestor.Unit test coverage is added in
src/test/interfaces_tests.cppasserting thatfindAncestorByHashreturns false whenblock_hashis null, preservesheight = -1in the output struct, returns false whenancestor_hashis null, returns false when both are null, and correctly returns true for identical blocks.