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

Don't Panic if 0 Peers are Left #4594

Merged
merged 11 commits into from
Jan 20, 2020
15 changes: 11 additions & 4 deletions beacon-chain/sync/initial-sync/round_robin.go
Expand Up @@ -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"
Expand Down Expand Up @@ -44,15 +45,20 @@ 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 {
Copy link
Contributor

@shayzluf shayzluf Jan 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the result of this change can be great . as it stays the same epoch throughout initial sync.
the result as i see it will be that the best peer will be requested for all epochs from this initial value that was set at the beginning of sync to the new finalised epoch that is the current one (maybe a day later). this can put a lot of stress on one peer.
maybe something like this can be done to resolve this issue?

Suggested change
for s.chain.HeadSlot() < highestFinalizedSlot {
for s.chain.HeadSlot() < max(highestFinalizedSlot,helpers.StartSlot(s.highestFinalizedEpoch() + 1)) {

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it doesn't stay the same, we just ensure there are a safe amount of peers before updating it . Below there is this piece of code:

	if len(peers) >= flags.Get().MinimumSyncPeers {
			highestFinalizedSlot = helpers.StartSlot(finalizedEpoch + 1)
		}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missed it. thanks

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")
time.Sleep(refreshTime)
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) {
Expand Down Expand Up @@ -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)))
Expand Down Expand Up @@ -177,7 +183,8 @@ func (s *Service) roundRobinSync(genesis time.Time) error {
0, // remainder
)
if err != nil {
return err
log.Errorf("Request failed: %v", err)
rauljordan marked this conversation as resolved.
Show resolved Hide resolved
continue
}

// Since the block responses were appended to the list, we must sort them in order to
Expand Down