-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Process atts and update head before proposing #10653
Changes from 11 commits
4c9b1ff
3a101dc
d76a726
1dc94a5
2729c29
a180724
cb07337
5240935
12a7b4e
e7b2003
21456f5
c1d315e
3d4821a
f33f7b4
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 |
---|---|---|
|
@@ -128,39 +128,51 @@ func (s *Service) spawnProcessAttestationsRoutine(stateFeed *event.Feed) { | |
return | ||
} | ||
|
||
// Continue when there's no fork choice attestation, there's nothing to process and update head. | ||
// This covers the condition when the node is still initial syncing to the head of the chain. | ||
if s.cfg.AttPool.ForkchoiceAttestationCount() == 0 { | ||
continue | ||
} | ||
s.processAttestations(s.ctx) | ||
|
||
justified := s.store.JustifiedCheckpt() | ||
if justified == nil { | ||
log.WithError(errNilJustifiedInStore).Error("Could not get justified checkpoint") | ||
continue | ||
} | ||
balances, err := s.justifiedBalances.get(s.ctx, bytesutil.ToBytes32(justified.Root)) | ||
if err != nil { | ||
log.WithError(err).Errorf("Unable to get justified balances for root %v", justified.Root) | ||
continue | ||
} | ||
newHeadRoot, err := s.updateHead(s.ctx, balances) | ||
if err != nil { | ||
log.WithError(err).Warn("Resolving fork due to new attestation") | ||
} | ||
if s.headRoot() != newHeadRoot { | ||
log.WithFields(logrus.Fields{ | ||
"oldHeadRoot": fmt.Sprintf("%#x", s.headRoot()), | ||
"newHeadRoot": fmt.Sprintf("%#x", newHeadRoot), | ||
}).Debug("Head changed due to attestations") | ||
if err := s.UpdateHead(s.ctx); err != nil { | ||
log.WithError(err).Error("Could not process attestations and update head") | ||
return | ||
} | ||
s.notifyEngineIfChangedHead(s.ctx, newHeadRoot) | ||
} | ||
} | ||
}() | ||
} | ||
|
||
// UpdateHead processes fork choice attestations from the pool and updates the head. | ||
func (s *Service) UpdateHead(ctx context.Context) error { | ||
// Continue when there's no fork choice attestation, there's nothing to process and update head. | ||
// This covers the condition when the node is still initial syncing to the head of the chain. | ||
if s.cfg.AttPool.ForkchoiceAttestationCount() == 0 { | ||
return nil | ||
} | ||
|
||
// Only one process can process attestations and update head at a time. | ||
s.processAttestationsLock.Lock() | ||
defer s.processAttestationsLock.Unlock() | ||
Comment on lines
+149
to
+151
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 is the only addition from the refactor above |
||
|
||
s.processAttestations(ctx) | ||
|
||
justified := s.store.JustifiedCheckpt() | ||
if justified == nil { | ||
return errNilJustifiedInStore | ||
} | ||
balances, err := s.justifiedBalances.get(ctx, bytesutil.ToBytes32(justified.Root)) | ||
if err != nil { | ||
return err | ||
} | ||
newHeadRoot, err := s.updateHead(ctx, balances) | ||
if err != nil { | ||
log.WithError(err).Warn("Resolving fork due to new attestation") | ||
} | ||
if s.headRoot() != newHeadRoot { | ||
log.WithFields(logrus.Fields{ | ||
"oldHeadRoot": fmt.Sprintf("%#x", s.headRoot()), | ||
"newHeadRoot": fmt.Sprintf("%#x", newHeadRoot), | ||
}).Debug("Head changed due to attestations") | ||
} | ||
s.notifyEngineIfChangedHead(ctx, newHeadRoot) | ||
return nil | ||
} | ||
|
||
// This calls notify Forkchoice Update in the event that the head has changed | ||
func (s *Service) notifyEngineIfChangedHead(ctx context.Context, newHeadRoot [32]byte) { | ||
if s.headRoot() == newHeadRoot { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,6 +82,10 @@ func (vs *Server) buildPhase0BlockData(ctx context.Context, req *ethpb.BlockRequ | |
return nil, fmt.Errorf("syncing to latest head, not ready to respond") | ||
} | ||
|
||
if err := vs.HeadUpdater.UpdateHead(ctx); err != nil { | ||
log.WithError(err).Error("Could not process attestations and update head") | ||
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. Opt it to log an error instead of return error. Error from this call should not prevent block proposal |
||
} | ||
|
||
// Retrieve the parent block as the current head of the canonical chain. | ||
parentRoot, err := vs.HeadFetcher.HeadRoot(ctx) | ||
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.
We should say that it updates the canonical head of the chain based on information from fork-choice attestations and votes. It requires no external inputs.