Add prev_blockhash validation to CheckPoint#2115
Draft
evanlinjin wants to merge 8 commits intobitcoindevkit:masterfrom
Draft
Add prev_blockhash validation to CheckPoint#2115evanlinjin wants to merge 8 commits intobitcoindevkit:masterfrom
prev_blockhash validation to CheckPoint#2115evanlinjin wants to merge 8 commits intobitcoindevkit:masterfrom
Conversation
Additionally, `insert` now panics if the genesis block gets displaced (if it existed in the first place). Co-authored-by: valued mammal <valuedmammal@protonmail.com>
Make `TestLocalChain` and `ExpectedResult` generic over checkpoint data type `D`, allowing the same test infrastructure to work with both `BlockHash` and `TestBlock` types. Add `merge_chains_with_prev_blockhash` test to verify that `prev_blockhash` correctly invalidates conflicting blocks and connects disjoint chains. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Add comprehensive tests for CheckPoint::push error cases: - Push fails when height is not greater than current - Push fails when prev_blockhash conflicts with self - Push succeeds when prev_blockhash matches Include tests for CheckPoint::insert conflict handling: - Insert with conflicting prev_blockhash - Insert purges conflicting tail - Insert between conflicting checkpoints 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> Co-Authored-By: valued mammal <valuedmammal@protonmail.com>
evanlinjin
commented
Feb 5, 2026
| // OPTIMIZATION 2 -- if we have the same underlying pointer at this point, we | ||
| // can guarantee that no older blocks are introduced. | ||
| if o.eq_ptr(u) { | ||
| // TODO: Ensure this is correct! |
Member
Author
There was a problem hiding this comment.
This is correct! We can remove this comment!
evanlinjin
commented
Feb 5, 2026
Member
Author
There was a problem hiding this comment.
As highlighted in f7eedf3, we should do something about apply_changeset_to_checkpoint.
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.
Closes #2021
Related to #2076
Replaces #2024
Replaces #2091
Description
This PR adds
prev_blockhashawareness toCheckPoint, enabling proper chain validation when merging checkpoint chains that store block headers or similar data with previous block hash information.Notes to the reviewers
This PR replaces some prior attempts:
feat(chain)!: make
CheckPointdatafield optional #2024 - where we made theCheckPoint::dataoptional - however this resulted in internal complexity and an API with annoying edge cases. The tests from this PR were still useful.feat(chain)!: Add
prev_blockhashtoToBlockHashtrait #2091 - This second attempt had some good ideas, but was distracted from the goal of EnsureCheckPointchain methods validate and link via previous blockhash #2021. I mostly reused theCheckPoint::insertimplementation of that PR.Changelog notice
Checklists
All Submissions:
New Features: