-
Notifications
You must be signed in to change notification settings - Fork 810
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
node/http: get block header by hash/height #808
Conversation
This comment has been minimized.
This comment has been minimized.
I think this is available as an RPC command already no? |
Yeah, however it doesn't look like it can be queried by height currently there though. |
@braydonf true, I actually make this a compound call like:
|
Cool, that could be made into one call similar to |
So I think this is just missing a test? |
@braydonf Will update this PR with a test |
Corresponding PR in |
Added a test to assert that the same header is fetched when querying by hash and by height to cover the get block header by hash codepath. |
for (const property of properties) | ||
assert(property in header); | ||
|
||
const block = await nclient.getBlock(height); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It could be worth it to use nclient.get(`/block/${height}\`);
here instead, as to be similar to the header call with await nclient.get(`/header/${height}`);
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm only using nclient.get('/header/${height}')
here because there is no nclient.getBlockHeader
. There is a PR to add it here: https://github.com/bcoin-org/bclient/pull/21/files
I feel like the raw get request should be turned into using the wrapper once its merged into bclient
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a reason why I think it's better to use nclient.get
in most cases. I think there is also case to have a minimal RPC/HTTP client for testing, instead of depending on bclient. Meanwhile bclient does not have any tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there is also case to have a minimal RPC/HTTP client for testing, instead of depending on bclient.
I get this perspective and its generally not the best practice to couple tests for different repos together. bclient
is partially tested in bcoin
(which is better than no tests at all). Since bclient
is used in production and is already a dependency of bcoin
, I feel like using it in tests is a net positive, unless you want bcoin
as a devDependency
of bclient
so that a full test suite can be written there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be useful for light wallet clients an as alternative means to syncing a header chain.
@braydonf Will push up fixes for the nits |
I agree that an additional PR can break up |
node/http: get block header by hash/height
Add an HTTP endpoint to the Node for fetching block headers.
GET /header/:block
This endpoint makes 1 less database call than fetching a block by hash or height. The
view
is not necessary forheader.getJSON
.It also returns far less data and should always be consistent with the amount of data that it returns.