-
Notifications
You must be signed in to change notification settings - Fork 1.3k
only viable head is invalid #11117
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
only viable head is invalid #11117
Changes from all commits
bcbdf43
534d1ea
bd0c5f2
4cad80e
6ce8999
f8890ff
a5778c5
d794b14
8e1d12e
9ccb63a
84f0c8f
98c27db
2eb203b
164dbb4
908dc3e
18e1444
3ecd852
12ca2cf
2ce8c91
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| package blockchain | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "context" | ||
| "time" | ||
|
|
||
|
|
@@ -299,13 +300,14 @@ func (s *Service) ForkChoicer() forkchoice.ForkChoicer { | |
|
|
||
| // IsOptimistic returns true if the current head is optimistic. | ||
| func (s *Service) IsOptimistic(ctx context.Context) (bool, error) { | ||
| s.headLock.RLock() | ||
| defer s.headLock.RUnlock() | ||
| if slots.ToEpoch(s.CurrentSlot()) < params.BeaconConfig().BellatrixForkEpoch { | ||
| return false, nil | ||
| } | ||
| s.headLock.RLock() | ||
| headRoot := s.head.root | ||
| s.headLock.RUnlock() | ||
|
|
||
| return s.IsOptimisticForRoot(ctx, s.head.root) | ||
| return s.IsOptimisticForRoot(ctx, headRoot) | ||
| } | ||
|
|
||
| // IsFinalized returns true if the input root is finalized. | ||
|
|
@@ -332,7 +334,17 @@ func (s *Service) IsOptimisticForRoot(ctx context.Context, root [32]byte) (bool, | |
| return false, err | ||
| } | ||
| if ss == nil { | ||
| return false, errInvalidNilSummary | ||
| // if the requested root is the headroot we should treat the | ||
| // node as optimistic. This can happen if we pruned INVALID | ||
| // nodes and no viable head is available. | ||
| headRoot, err := s.HeadRoot(ctx) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how does this work, we have a head for which there is no state summary/block in the db ?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, and even worse, it can be different than forkchoice's |
||
| if err != nil { | ||
| return true, err | ||
| } | ||
| if bytes.Equal(headRoot, root[:]) { | ||
| return true, nil | ||
| } | ||
| return true, errInvalidNilSummary | ||
| } | ||
|
|
||
| validatedCheckpoint, err := s.cfg.BeaconDB.LastValidatedCheckpoint(ctx) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -106,8 +106,12 @@ func (s *Service) notifyForkchoiceUpdate(ctx context.Context, arg *notifyForkcho | |
|
|
||
| r, err := s.cfg.ForkChoiceStore.Head(ctx, s.justifiedBalances.balances) | ||
| if err != nil { | ||
| log.WithError(err).Error("Could not get head root") | ||
| return nil, nil | ||
| log.WithFields(logrus.Fields{ | ||
| "slot": headBlk.Slot(), | ||
| "blockRoot": fmt.Sprintf("%#x", bytesutil.Trunc(headRoot[:])), | ||
| "invalidCount": len(invalidRoots), | ||
| }).Warn("Pruned invalid blocks, could not update head root") | ||
| return nil, invalidBlock{error: ErrInvalidPayload, root: arg.headRoot, invalidAncestorRoots: invalidRoots} | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this will log here the pruned blocks, this is a code smell for a few reasons:
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here's what is bothering me a little bit. We are returning nil for every
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It bothers me too, but we used to return errors on everything and it was bad rendering the node locked with minor things. I feel this situation shouldn't happen often so it's kinda safe to put it here, I haven't thought deeply on the other errors here.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a reason we only add the invalid block error here ? invalidBlock{error: ErrInvalidPayload, root: arg.headRoot, invalidAncestorRoots: invalidRoots}In this whole conditional branch, this is the only location where we return the error. |
||
| } | ||
| b, err := s.getBlock(ctx, r) | ||
| if err != nil { | ||
|
|
||
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.
IsOptimisticForRootnow requires a lock.