Skip to content

Give correct error for too high block number#131

Merged
emostov merged 2 commits intomasterfrom
zeke-height-3
Jul 2, 2020
Merged

Give correct error for too high block number#131
emostov merged 2 commits intomasterfrom
zeke-height-3

Conversation

@emostov
Copy link
Contributor

@emostov emostov commented Jun 30, 2020

Closes #67

Instead of handling this as its own validation in the middleware pipeline, I realized it makes more sense to do the validation in getHashForBlock. My reasoning is that proper validation requires a call to get the latest block. In getHashForBlock we do several less expensive checks prior and then only check for invalid height if the rpc query getBlockHash fails. Finally, some error catching is added in the get and post wrappers to check for the recently introduced HttpError.

Copy link
Collaborator

@joepetrowski joepetrowski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally LGTM but not caught up on these http-errors so can't say for certain that it's ready. Will let @danforbes take a look too.

Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com>
Copy link
Contributor

@danforbes danforbes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't believe that we can merge this because it breaks our API.

// Check if the block number is too high
const { number } = await api.rpc.chain.getHeader();
if (blockNumber && number.toNumber() < blockNumber) {
throw new BadRequest(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a breaking change because we are now returning a different HTTP response code so I would suggest keeping this until v1.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see the argument that it is a breaking change since we introduce a new error that potentially prevents an older error message from appearing. However I think there are two reasons this is ok right now. 1) we have a precedent for introducing these types of error handling changes pre v1 (see #123 as a recent example) and 2) it is replacing downstream error messages that I see as significantly less helpful.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not the error message that is really the problem, it's the error code. This could break integrations if people are expecting a 5xx type error when the block number isn't right.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see what you mean about #123 though...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think of changing it to a 500 but leaving the rest?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think our user group is small enough that we can ask them...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we hadn't have already released #123 I would have gone with Zeke's suggestion but given the state of things, I think Joe's is more reasonable.

@emostov emostov added the B2 - Breaks API Breaking changes to the API label Jul 2, 2020
@emostov emostov merged commit 164084f into master Jul 2, 2020
@emostov emostov deleted the zeke-height-3 branch July 3, 2020 16:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

B2 - Breaks API Breaking changes to the API

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Requesting a block that doesn't yet exist returns a 500

3 participants