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

Forkchoice: expose if no tip is viable #11153

Merged
merged 4 commits into from
Aug 3, 2022

Conversation

potuz
Copy link
Contributor

@potuz potuz commented Aug 2, 2022

This PR changes the behavior on when the node is considered optimistic.
A call to blockchain.IsOptimistic() relies solely on forkchoice, if
all tips are invalid, then it's optimistic. If the current headroot is
not in forkchoice then it's optimistic.

A call to blockchain.IsOptimisticForRoot() will return true if the
requested root is headroot and it's not found in forkchoice

This PR changes the behavior on when the node is considered optimistic.
A call to `blockchain.IsOptimistic()` relies solely on forkchoice, if
all tips are invalid, then it's optimistic. If the current headroot is
not in forkchoice then it's optimistic.

A call to `blockchain.IsOptimisticForRoot()` will return true if the
requested root is headroot and it's not found in forkchoice
@potuz potuz requested a review from a team as a code owner August 2, 2022 18:47
Comment on lines +347 to +353
headRoot, err := s.HeadRoot(ctx)
if err != nil {
return true, err
}
if bytes.Equal(headRoot, root[:]) {
return true, nil
}
Copy link
Member

Choose a reason for hiding this comment

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

This is confusing. I think often readers will miss the fact that we only end up here if the root is not in fork choice store

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'll update the comment

ss, err := s.cfg.BeaconDB.StateSummary(ctx, root)
if err != nil {
return false, err
}

if ss == nil {
Copy link
Member

Choose a reason for hiding this comment

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

Why not do this so we don't have to worry about s?HeadRoot at all

Suggested change
if ss == nil {
if ss == nil {
if s.cfg.ForkChoiceStore.AllTipsAreInvalid() {
return true, nil
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

because forkchoice's AllTipsAreInvalid may fail if there was no call to Head() between the prunning and the call here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But I agree that it's such a long shot that someone requests by root (instead of just IsOptimistic) exactly at this same time. I'll let you decide, if you want me to switch this to avoid the comparison I'm happy with it... this is not really a hot path

Copy link
Member

Choose a reason for hiding this comment

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

I'm just thinking future proof. What if we were to remove HeadRoot from blockchain's chaininfo one day and default everything to the fork choice store's head?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah but the problem of doing the suggestion is that someone may actually be requesting by root an old block, we should reply correctly instead of "true" if forkchoice is in an incoherent state

@prylabs-bulldozer prylabs-bulldozer bot merged commit 19e4cd3 into develop Aug 3, 2022
@delete-merged-branch delete-merged-branch bot deleted the forkchoice_interface_no_viable branch August 3, 2022 13:59
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.

2 participants