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

fix: finalization for /blocks/head #631

Merged
merged 6 commits into from
Aug 9, 2021
Merged

Conversation

TarikGul
Copy link
Member

@TarikGul TarikGul commented Aug 9, 2021

This fixes the default behavior for querying the finalized head. The query param and its expected behavior still works. The only issue is the /blocks/head endpoint is not returning the finalized head by default, which means you have to tag the finalized param onto the query. This fixes the slight bug introduced in this PR #615.

const { hash, queryFinalizedHead, omitFinalizedTag } =
await this.parseFinalizationOpts(this.options.finalizes, paramFinalized);
await this.parseFinalizationOpts(
Copy link
Member

Choose a reason for hiding this comment

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

I don't get this, how does it fix it by converting passing it as a String rather than a boolean?

Copy link
Member Author

Choose a reason for hiding this comment

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

hmmm, you make a good point that it is confusing too outside eyes as to what is happening, so I am going to just revert it completely to what it use to be so that there is no confusion.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm a bit confused about the string usage; can the string just be true or false and, why a string and not a bool? I'm probably missing too much context really :)

Sounds like you'll revert anyway so maybe I don't need to know :D

Copy link
Member Author

Choose a reason for hiding this comment

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

@niklasad1 @jsdw Okay, so I reverted it back to what it was originally before I abstracted out of the controller. Hopefully it's a little clearer

Copy link
Contributor

@insipx insipx left a comment

Choose a reason for hiding this comment

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

So IIUC, finalizes checks if the network itself supports finalization, and finalized is a user parameter, but I'm not sure what the use of FinalizedTag/queryFinalizedHead is. What does FinalizedTagdo that queryFinalizedHeaddoes not? I'm trying to understand why we use queryFinalizedHead with the chain.getHeader() func. Or why when we use getHeaderwhen queryFinalizedHead head is false, and getFinalizedHead when queryFinalizedHead is true.

Otherwise I think this looks good

@TarikGul
Copy link
Member Author

TarikGul commented Aug 9, 2021

@insipx Great question, I just added a comment to clarify. But the idea behind queryFinalizedHead is to confirm that the queried blockhead is either finalized or not. We do that by comparing the results of the finalized head blocks height, and see if it is greater than or equal to the blockhead that's queried. That is why we have the queryFinalizedHead boolean. (The naming can be confusing).

The logic where this all takes place when this is queried (/blocks/head?finalized=false) is here

Copy link
Contributor

@insipx insipx left a comment

Choose a reason for hiding this comment

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

makes sense to me

@TarikGul TarikGul merged commit 8d0d538 into master Aug 9, 2021
@TarikGul TarikGul deleted the tarik-fix-finalization-head branch August 9, 2021 19:12
@jsdw jsdw mentioned this pull request Aug 10, 2021
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants