rest: Query predecessor headers using negative count param#33752
rest: Query predecessor headers using negative count param#33752A-Manning wants to merge 1 commit intobitcoin:masterfrom
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. Code Coverage & BenchmarksFor details see: https://corecheck.dev/bitcoin/bitcoin/pulls/33752. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please copy-paste ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
ae13046 to
b638085
Compare
475bb22 to
1f5b786
Compare
|
Though, I wonder what the use case is. If someone knows a header, it seems likely they also know about the previous headers and a feature to support asking for them would have no users? |
Knowing a header only means that you know the previous block hash. If you want to request headers from best tip to genesis, There is no existing mechanism other than requesting headers one-at-a-time. This makes it possible to batch request headers from tip to genesis, which is much more efficient than requesting one-at-a-time. |
stickies-v
left a comment
There was a problem hiding this comment.
There is no existing mechanism other than requesting headers one-at-a-time.
Request the starting hash with GET /rest/blockhashbyheight/<HEIGHT>.<bin|hex|json> and then request headers upward with /rest/headers/?
Concept NACK, unless I'm misunderstanding the limitations/use case.
We currently use this approach at L2L. This strategy is far from ideal - any of the upward requests may return headers from a different active chain, in the event of a re-org. It is necessary to check that the final block hash is the same as the tip hash we want to sync to, and if it is not, then the only way to retrieve the headers would be requesting headers via JSON-RPC, one at a time. |
|
The reorg potential does make using the interface more cumbersome in general, I'm not sure your approach solves that? You're still limited by what's in the |
1f5b786 to
200a9c9
Compare
|
@stickies-v Updated to handle the case where the requested block header is no longer in the active chain. |
|
I'm still a bit confused at what this is solving. Re-orgs are just a couple of blocks deep, so it shouldn't make a difference which direction you are querying from. Whether you need to handle reorgs around the tip after querying headers beginning from your current state, or beginning from the last known tip, you still need to reconcile reorgs either way, no? |
There is currently no mechanism by which to batch-query headers from tip, backwards towards genesis.
This PR extends the REST Blockheaders API to support batch-querying predecessor headers, by providing a negative count parameter.