diff --git a/beacon-chain/sync/initial-sync/round_robin.go b/beacon-chain/sync/initial-sync/round_robin.go index e9afc75d5741..f1ebb52a4851 100644 --- a/beacon-chain/sync/initial-sync/round_robin.go +++ b/beacon-chain/sync/initial-sync/round_robin.go @@ -46,7 +46,7 @@ func (s *Service) roundRobinSync(genesis time.Time) error { var lastEmptyRequests int // Step 1 - Sync to end of finalized epoch. for s.chain.HeadSlot() < helpers.StartSlot(s.highestFinalizedEpoch()+1) { - root, finalizedEpoch, peers := s.p2p.Peers().BestFinalized(params.BeaconConfig().MaxPeersToSync, s.chain.HeadSlot()/params.BeaconConfig().SlotsPerEpoch) + 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) @@ -225,13 +225,13 @@ func (s *Service) roundRobinSync(genesis time.Time) error { // we receive there after must build on the finalized chain or be considered invalid during // fork choice resolution / block processing. best := s.bestPeer() - root, _, _ := s.p2p.Peers().BestFinalized(params.BeaconConfig().MaxPeersToSync, s.chain.HeadSlot()/params.BeaconConfig().SlotsPerEpoch) + root, _, _ := s.p2p.Peers().BestFinalized(params.BeaconConfig().MaxPeersToSync, helpers.SlotToEpoch(s.chain.HeadSlot())) // if no best peer exists, retry until a new best peer is found. for len(best) == 0 { time.Sleep(refreshTime) best = s.bestPeer() - root, _, _ = s.p2p.Peers().BestFinalized(params.BeaconConfig().MaxPeersToSync, s.chain.HeadSlot()/params.BeaconConfig().SlotsPerEpoch) + root, _, _ = s.p2p.Peers().BestFinalized(params.BeaconConfig().MaxPeersToSync, helpers.SlotToEpoch(s.chain.HeadSlot())) } for head := helpers.SlotsSince(genesis); s.chain.HeadSlot() < head; { req := &p2ppb.BeaconBlocksByRangeRequest{ @@ -297,7 +297,7 @@ func (s *Service) requestBlocks(ctx context.Context, req *p2ppb.BeaconBlocksByRa // highestFinalizedEpoch as reported by peers. This is the absolute highest finalized epoch as // reported by peers. func (s *Service) highestFinalizedEpoch() uint64 { - _, epoch, _ := s.p2p.Peers().BestFinalized(params.BeaconConfig().MaxPeersToSync, s.chain.HeadSlot()/params.BeaconConfig().SlotsPerEpoch) + _, epoch, _ := s.p2p.Peers().BestFinalized(params.BeaconConfig().MaxPeersToSync, helpers.SlotToEpoch(s.chain.HeadSlot())) return epoch } diff --git a/beacon-chain/sync/initial-sync/service.go b/beacon-chain/sync/initial-sync/service.go index 6595737d6de7..96acb040b5fb 100644 --- a/beacon-chain/sync/initial-sync/service.go +++ b/beacon-chain/sync/initial-sync/service.go @@ -168,7 +168,7 @@ func (s *Service) waitForMinimumPeers() { required = flags.Get().MinimumSyncPeers } for { - _, _, peers := s.p2p.Peers().BestFinalized(params.BeaconConfig().MaxPeersToSync, s.chain.HeadSlot()/params.BeaconConfig().SlotsPerEpoch) + _, _, peers := s.p2p.Peers().BestFinalized(params.BeaconConfig().MaxPeersToSync, helpers.SlotToEpoch(s.chain.HeadSlot())) if len(peers) >= required { break } diff --git a/beacon-chain/sync/rpc_status.go b/beacon-chain/sync/rpc_status.go index ed4d9090a542..9b93bdb6b763 100644 --- a/beacon-chain/sync/rpc_status.go +++ b/beacon-chain/sync/rpc_status.go @@ -37,7 +37,7 @@ func (r *Service) maintainPeerStatuses() { } } for !r.initialSync.Syncing() { - _, highestEpoch, _ := r.p2p.Peers().BestFinalized(params.BeaconConfig().MaxPeersToSync, r.chain.HeadSlot()/params.BeaconConfig().SlotsPerEpoch) + _, highestEpoch, _ := r.p2p.Peers().BestFinalized(params.BeaconConfig().MaxPeersToSync, helpers.SlotToEpoch(r.chain.HeadSlot())) if helpers.StartSlot(highestEpoch) > r.chain.HeadSlot() { numberOfTimesResyncedCounter.Inc() r.clearPendingSlots()