Skip to content
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

Merged
merged 5 commits into from
Aug 1, 2019

Conversation

tynes
Copy link
Member

@tynes tynes commented Jun 30, 2019

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 for header.getJSON.

It also returns far less data and should always be consistent with the amount of data that it returns.

@codecov-io

This comment has been minimized.

@pinheadmz
Copy link
Member

I think this is available as an RPC command already no?

lib/node/http.js Outdated Show resolved Hide resolved
@braydonf
Copy link
Contributor

braydonf commented Jul 3, 2019

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.

@pinheadmz
Copy link
Member

@braydonf true, I actually make this a compound call like:

$ bcoin-cli rpc getblockheader `bcoin-cli rpc getblockhash <int height>`

@braydonf
Copy link
Contributor

braydonf commented Jul 3, 2019

Cool, that could be made into one call similar to getblockbyheight, a possible new RPC command to add (not necessary in this PR).

@braydonf
Copy link
Contributor

braydonf commented Jul 3, 2019

So I think this is just missing a test?

@tynes
Copy link
Member Author

tynes commented Jul 3, 2019

@braydonf Will update this PR with a test

@tynes tynes marked this pull request as ready for review July 5, 2019 21:41
@tynes
Copy link
Member Author

tynes commented Jul 5, 2019

Corresponding PR in bclient can be found here: bcoin-org/bclient#21

test/http-test.js Outdated Show resolved Hide resolved
@tynes
Copy link
Member Author

tynes commented Jul 8, 2019

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.

test/http-test.js Outdated Show resolved Hide resolved
test/http-test.js Outdated Show resolved Hide resolved
test/http-test.js Outdated Show resolved Hide resolved
for (const property of properties)
assert(property in header);

const block = await nclient.getBlock(height);
Copy link
Contributor

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}`);.

Copy link
Member Author

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.

Copy link
Contributor

@braydonf braydonf Jul 18, 2019

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.

Copy link
Member Author

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.

Copy link
Contributor

@braydonf braydonf left a 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 braydonf added the http label Jul 9, 2019
@tynes
Copy link
Member Author

tynes commented Jul 10, 2019

@braydonf Will push up fixes for the nits

@tynes
Copy link
Member Author

tynes commented Jul 18, 2019

Looks like existing tests need to be updated to generate an initial state in a before hook. Also looking more at the http-test.js and could probably be separated similar to node-rpc-test.js and wallet-rpc-test.js has been, it doesn't look like /block/${hash} is tested, aside from the additional getBlock call added below.

I agree that an additional PR can break up test/http-test.js

@braydonf braydonf merged commit f623708 into bcoin-org:master Aug 1, 2019
braydonf added a commit that referenced this pull request Aug 1, 2019
node/http: get block header by hash/height
@braydonf braydonf added this to the 2.0.0 milestone Jan 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants