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

More conservative selection of non-finalized peers #7086

Merged
merged 6 commits into from
Aug 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions beacon-chain/sync/initial-sync/blocks_fetcher_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ func (f *blocksFetcher) bestFinalizedSlot() uint64 {
return helpers.StartSlot(finalizedEpoch)
}

// bestNonFinalizedSlot returns the highest non-finalized slot of the majority of connected peers.
// bestNonFinalizedSlot returns the highest non-finalized slot of enough number of connected peers.
func (f *blocksFetcher) bestNonFinalizedSlot() uint64 {
headEpoch := helpers.SlotToEpoch(f.headFetcher.HeadSlot())
targetEpoch, _ := f.p2p.Peers().BestNonFinalized(flags.Get().MinimumSyncPeers, headEpoch)
targetEpoch, _ := f.p2p.Peers().BestNonFinalized(flags.Get().MinimumSyncPeers*2, headEpoch)
return helpers.StartSlot(targetEpoch)
}
8 changes: 6 additions & 2 deletions beacon-chain/sync/rpc_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,12 @@ func (s *Service) resyncIfBehind() {
runutil.RunEvery(s.ctx, interval, func() {
if s.shouldReSync() {
syncedEpoch := helpers.SlotToEpoch(s.chain.HeadSlot())
highestEpoch, _ := s.p2p.Peers().BestNonFinalized(flags.Get().MinimumSyncPeers, syncedEpoch)
if helpers.StartSlot(highestEpoch) > s.chain.HeadSlot() {
// Factor number of expected minimum sync peers, to make sure that enough peers are
// available to resync (some peers may go away between checking non-finalized peers and
// actual resyncing).
highestEpoch, _ := s.p2p.Peers().BestNonFinalized(flags.Get().MinimumSyncPeers*2, syncedEpoch)
// Check if the current node is more than 1 epoch behind.
if highestEpoch > (syncedEpoch + 1) {
log.WithFields(logrus.Fields{
"currentEpoch": helpers.SlotToEpoch(s.chain.CurrentSlot()),
"syncedEpoch": syncedEpoch,
Expand Down