mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 12:57:18 +00:00
Use helper to calculate epoch (#4497)
This commit is contained in:
parent
4e6c8c5b1a
commit
3c5d5bfc7b
@ -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
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user