Skip to content

Commit

Permalink
More conservative selection of non-finalized peers (#7086)
Browse files Browse the repository at this point in the history
* more conservative selection of non-finalized peers
* Merge refs/heads/master into init-sync-non-finalized-loop
* Nishant's suggestion on possible overflow
* Merge branch 'init-sync-non-finalized-loop' of github.com:prysmaticlabs/prysm into init-sync-non-finalized-loop
* Merge refs/heads/master into init-sync-non-finalized-loop
* Merge refs/heads/master into init-sync-non-finalized-loop
  • Loading branch information
farazdagi authored Aug 24, 2020
1 parent 5d0f6c5 commit 5c9830f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
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

0 comments on commit 5c9830f

Please sign in to comment.