Add the /headers[/:from_hash[/:count]] endpoint#41
Draft
afilini wants to merge 1 commit intoBlockstream:new-indexfrom
Draft
Add the /headers[/:from_hash[/:count]] endpoint#41afilini wants to merge 1 commit intoBlockstream:new-indexfrom
/headers[/:from_hash[/:count]] endpoint#41afilini wants to merge 1 commit intoBlockstream:new-indexfrom
Conversation
shesek
requested changes
Nov 10, 2021
Collaborator
shesek
left a comment
There was a problem hiding this comment.
Concept ACK, this looks very useful. Thanks for the contribution!
Added some review comments.
src/rest.rs
Outdated
| (&Method::GET, Some(&"headers"), hash, count, None, None) => { | ||
| let count = count | ||
| .and_then(|c| c.parse::<usize>().ok()) | ||
| .and_then(|c| match c { |
Collaborator
There was a problem hiding this comment.
How about c.max(1).min(2000) instead?
src/rest.rs
Outdated
| raw.append(&mut encode::serialize( | ||
| &encode::VarInt(headers.len() as u64), | ||
| )); | ||
| for header in headers.iter() { |
Collaborator
There was a problem hiding this comment.
Would be better to consume the vector with into_iter.
| None => return Err(HttpError::not_found("Block not found".to_string())), | ||
| }; | ||
|
|
||
| let mut raw = Vec::with_capacity(8 + 80 * headers.len()); |
Collaborator
There was a problem hiding this comment.
The header size is different in elements. I think this should be the only difference there.
| .unwrap() | ||
| .iter() | ||
| .rev() | ||
| .skip(self.best_height() - from_header.height()) |
Collaborator
There was a problem hiding this comment.
The best height might change between calling best_height() and starting the iteration itself. get_headers should grab one read lock and reuse it to ensure the state is consistent.
755925d to
018c094
Compare
Add a new endpoint to download headers in bulk, up to 2000 with a single request. Headers are returned in binary form, with the VarInt-encoded number of items in the body preceeding them. By default `from_hash` is the current best hash, but a different starting block can be specified. The returned list goes "backwards" returning the `count - 1` blocks *before* `from_hash` plus the header of `from_hash` itself. This allows caching the response indefinitely, since it's guaranteed that the headers that come before a given block will never change. Returns an error if `from_hash` is not a valid block or it isn't found in the blockchain. If `count` is greater than the limit of `2000` it will be silently capped to said value.
018c094 to
bf26302
Compare
junderw
pushed a commit
to junderw/electrs
that referenced
this pull request
Dec 12, 2023
Include tx confirmation status in bulk /block/txs response
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.
Opening this as a draft to gather some feedback. I'm pretty sure this won't compile on liquid right now, but I didn't want to invest too much time getting it to run in case there's no interest for this from your end.
Add a new endpoint to download headers in bulk, up to 2000 with a single
request.
Headers are returned in binary form, with the VarInt-encoded number of
items in the body preceeding them.
By default
from_hashis the current best hash, but a differentstarting block can be specified.
The returned list goes "backwards" returning the
count - 1blocksbefore
from_hashplus the header offrom_hashitself. This allowscaching the response indefinitely, since it's guaranteed that the
headers that come before a given block will never change.
Returns an error if
from_hashis not a valid block or it isn't foundin the blockchain.
If
countis greater than the limit of2000it will be silentlycapped to said value.