Have MTP in checkpoint data and report missing blocks#2186
Draft
evanlinjin wants to merge 2 commits intobitcoindevkit:masterfrom
Draft
Have MTP in checkpoint data and report missing blocks#2186evanlinjin wants to merge 2 commits intobitcoindevkit:masterfrom
evanlinjin wants to merge 2 commits intobitcoindevkit:masterfrom
Conversation
Introduce `WithMtp<D>` so that `CheckPoint<WithMtp<D>>` carries a compile-time guarantee that the median-time-past (BIP-0113) is available at every checkpoint, without walking 11 ancestor blocks per lookup. `CheckPoint::mtp()` returns the stored value. Rename `median_time_past` to `compute_mtp` to make the chain-walking cost explicit at the call site and to contrast it with the cheap `mtp()` accessor on `CheckPoint<WithMtp<D>>`.
Change `CheckPoint::compute_mtp` to return `Result<u32, MissingBlocks>` instead of `Option<u32>`. On failure, `MissingBlocks` lists every height in the MTP window (`h-10..=h`) that the chain is missing, enabling callers to drive a fetch-retry loop against their chain source. This is motivated by light-client chain sources such as Electrum, which do not expose MTP values directly. Callers need to know precisely which block headers to fetch; a bare `None` forces either eager full-chain prefetching or blind re-walking.
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.
Description
Context: #2076 (comment)
Adds a way to carry a precomputed median-time-past (MTP) value on each checkpoint at the type level, and reworks
compute_mtpso callers can drive fetch-retry loops when blocks are missing.WithMtp<D>wrapper:CheckPoint<WithMtp<D>>gives a compile-time guarantee that MTP is available for every checkpoint, without walking 11 ancestor blocks per lookup. A newCheckPoint::mtp()method returns the stored value in O(1).compute_mtpreturnsResult<u32, MissingBlocks>instead ofOption<u32>.MissingBlockslists every height in the MTP window (h-10..=h) that the chain is missing, so callers — especially light-client chain sources like Electrum that don't expose MTP directly — can batch-fetch exactly the headers they need and retry.median_time_past→compute_mtpto make the chain-walk cost explicit and contrast with the O(1)mtp()accessor.Notes to the reviewers
Breaking change, marked
feat(core)!. Two API breaks:median_time_past→compute_mtpcompute_mtpreturnsResult<u32, MissingBlocks>(wasOption<u32>)Changelog notice
Checklists
All Submissions:
New Features: