Skip to content

Commit

Permalink
Check if we are already synced to the current epoch before querying a…
Browse files Browse the repository at this point in the history
…ll of our peers (#4504)
  • Loading branch information
prestonvanloon authored and terencechain committed Jan 12, 2020
1 parent 6c4bf22 commit 7992375
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion beacon-chain/sync/rpc_status.go
Expand Up @@ -36,7 +36,10 @@ func (r *Service) maintainPeerStatuses() {
}
}
}
for !r.initialSync.Syncing() {
// If our head slot is not in the latest epoch, check peers to determine if we need to
// resync with the network.
currentSlot := uint64(roughtime.Now().Unix()-r.chain.GenesisTime().Unix()) / params.BeaconConfig().SecondsPerSlot
for !r.initialSync.Syncing() && helpers.SlotToEpoch(r.chain.HeadSlot()) < helpers.SlotToEpoch(currentSlot) {
_, highestEpoch, _ := r.p2p.Peers().BestFinalized(params.BeaconConfig().MaxPeersToSync, helpers.SlotToEpoch(r.chain.HeadSlot()))
if helpers.StartSlot(highestEpoch) > r.chain.HeadSlot() {
numberOfTimesResyncedCounter.Inc()
Expand Down

0 comments on commit 7992375

Please sign in to comment.