Don't Panic if 0 Peers are Left (#4594)

* log error
* Merge branch 'master' into dontReturnError
* return blocks
* change back
* Merge branch 'dontReturnError' of https://github.com/prysmaticlabs/geth-sharding into dontReturnError
* use a more static finalized epoch
* Update beacon-chain/sync/initial-sync/round_robin.go

Co-Authored-By: Raul Jordan <raul@prysmaticlabs.com>
* Merge refs/heads/master into dontReturnError
* jim's review
* Merge branch 'dontReturnError' of https://github.com/prysmaticlabs/geth-sharding into dontReturnError
* Update beacon-chain/sync/initial-sync/round_robin.go
This commit is contained in:
Nishant Das
2020-01-21 01:12:28 +08:00
committed by prylabs-bulldozer[bot]
parent dc4c1ca2b7
commit 781b7d6870

View File

@@ -9,6 +9,7 @@ import (
"sync/atomic"
"time"
"github.com/prysmaticlabs/prysm/beacon-chain/flags"
"github.com/libp2p/go-libp2p-core/peer"
"github.com/paulbellamy/ratecounter"
"github.com/pkg/errors"
@@ -44,8 +45,9 @@ func (s *Service) roundRobinSync(genesis time.Time) error {
counter := ratecounter.NewRateCounter(counterSeconds * time.Second)
randGenerator := rand.New(rand.NewSource(time.Now().Unix()))
var lastEmptyRequests int
highestFinalizedSlot := helpers.StartSlot(s.highestFinalizedEpoch() + 1)
// Step 1 - Sync to end of finalized epoch.
for s.chain.HeadSlot() < helpers.StartSlot(s.highestFinalizedEpoch()+1) {
for s.chain.HeadSlot() < highestFinalizedSlot {
root, finalizedEpoch, peers := s.p2p.Peers().BestFinalized(params.BeaconConfig().MaxPeersToSync, helpers.SlotToEpoch(s.chain.HeadSlot()))
if len(peers) == 0 {
log.Warn("No peers; waiting for reconnect")
@@ -53,6 +55,10 @@ func (s *Service) roundRobinSync(genesis time.Time) error {
continue
}
if len(peers) >= flags.Get().MinimumSyncPeers {
highestFinalizedSlot = helpers.StartSlot(finalizedEpoch + 1)
}
// shuffle peers to prevent a bad peer from
// stalling sync with invalid blocks
randGenerator.Shuffle(len(peers), func(i, j int) {
@@ -82,8 +88,8 @@ func (s *Service) roundRobinSync(genesis time.Time) error {
}
// Short circuit start far exceeding the highest finalized epoch in some infinite loop.
if start > helpers.StartSlot(s.highestFinalizedEpoch()+1) {
return nil, errors.Errorf("attempted to ask for a start slot of %d which is greater than the next highest epoch of %d", start, s.highestFinalizedEpoch()+1)
if start > highestFinalizedSlot {
return nil, errors.Errorf("attempted to ask for a start slot of %d which is greater than the next highest slot of %d", start, highestFinalizedSlot)
}
atomic.AddInt32(&p2pRequestCount, int32(len(peers)))
@@ -177,7 +183,8 @@ func (s *Service) roundRobinSync(genesis time.Time) error {
0, // remainder
)
if err != nil {
return err
log.WithError(err).Error("Round robing sync request failed")
continue
}
// Since the block responses were appended to the list, we must sort them in order to