blockchain, node/cn: bound the hash-based header ancestor lookup - #1010
Open
hyunsooda wants to merge 2 commits into
Open
blockchain, node/cn: bound the hash-based header ancestor lookup#1010hyunsooda wants to merge 2 commits into
hyunsooda wants to merge 2 commits into
Conversation
The hash-mode advance in the header request handler verified descent by walking Skip+1 parents and pre-allocating a Skip-sized hash slice, so a request whose answer is bounded by Amount could cost work proportional to the chain height. Ported go-ethereum's GetAncestor (#16946, released in v1.8.11, after Kaia's fork point): a canonical ancestor is resolved by number, and the non-canonical walk is bounded by a per-request budget. GetBlockHashesFromHash had no other caller and is removed, as upstream did. Constraint: the response shapes verified by TestGetBlockHeaders must not change Rejected: cap query.Skip instead | the cost no longer depends on Skip, and an arbitrary cap risks rejecting legitimate skeleton sync requests Directive: GetAncestor is a verbatim port; keep it diffable against upstream Confidence: high Scope-risk: narrow Not-tested: upstream's companion change that fetches later origins with GetHeader(hash, number) instead of GetHeaderByHash is deliberately not ported Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
ian0371
previously approved these changes
Aug 7, 2026
2dvorak
reviewed
Aug 10, 2026
2dvorak
left a comment
Contributor
There was a problem hiding this comment.
The new GetAncestor logic looks correct, but TestGetAncestor never actually exercises the budget running out. The 0xdead case stops after one hop (GetHeader returns nil), so if *maxNonCanonical == 0 { return ... } in headerchain.go:276 is never reached by any test — and that line is the whole point of the change.
Could we add a case for it?
TestGetAncestor's non-canonical case uses a hash with no header, so the walk gives up on its first hop and never reaches the budget guard. Add a case with a branch that outlasts the budget, and assert the walk ends with the budget spent rather than on a missing header. Confidence: high Scope-risk: narrow Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Contributor
Author
|
@2dvorak Thanks, added. |
2dvorak
approved these changes
Aug 11, 2026
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.
Proposed changes
The hash-mode advance in the header request handler verified descent by walking
Skip+1parents and pre-allocating aSkip-sized hash slice, so a request whose answer is bounded byAmountcould cost work proportional to the chain height. This ports go-ethereum'sGetAncestor(#16946, released in v1.8.11, after Kaia's fork point): a canonical ancestor is resolved by number, and the non-canonical walk is bounded by a per-request budget.GetBlockHashesFromHashhad no other caller and is removed, as upstream did.Types of changes
Checklist
I have read the CLA Document and I hereby sign the CLAin first time contribute after having read CLA$ make test)Related issues
Further comments