mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-24 20:37:17 +00:00
Best practice feedback - part 2 (#6389)
* Feedback 10. Rename to highest epoch * Feedback 11. Rename to pidepoch * Feedback 39. Swap length * Typo * Merge refs/heads/master into best-practice-pt2
This commit is contained in:
parent
e27ed8174b
commit
a9c1d25a35
@ -160,13 +160,13 @@ func (e SszNetworkEncoder) DecodeWithMaxLength(r io.Reader, to interface{}, maxS
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if msgLen > maxSize {
|
||||
return fmt.Errorf("remaining bytes %d goes over the provided max limit of %d", msgLen, maxSize)
|
||||
}
|
||||
if e.UseSnappyCompression {
|
||||
r = newBufferedReader(r)
|
||||
defer bufReaderPool.Put(r)
|
||||
}
|
||||
if msgLen > maxSize {
|
||||
return fmt.Errorf("remaining bytes %d goes over the provided max limit of %d", msgLen, maxSize)
|
||||
}
|
||||
b := make([]byte, e.MaxLength(int(msgLen)))
|
||||
numOfBytes, err := r.Read(b)
|
||||
if err != nil {
|
||||
|
@ -431,7 +431,7 @@ func (p *Status) BestFinalized(maxPeers int, ourFinalizedEpoch uint64) ([]byte,
|
||||
connected := p.Connected()
|
||||
finalized := make(map[[32]byte]uint64)
|
||||
rootToEpoch := make(map[[32]byte]uint64)
|
||||
pidEpochs := make(map[peer.ID]uint64)
|
||||
pidEpoch := make(map[peer.ID]uint64)
|
||||
potentialPIDs := make([]peer.ID, 0, len(connected))
|
||||
for _, pid := range connected {
|
||||
peerChainState, err := p.ChainState(pid)
|
||||
@ -439,7 +439,7 @@ func (p *Status) BestFinalized(maxPeers int, ourFinalizedEpoch uint64) ([]byte,
|
||||
root := bytesutil.ToBytes32(peerChainState.FinalizedRoot)
|
||||
finalized[root]++
|
||||
rootToEpoch[root] = peerChainState.FinalizedEpoch
|
||||
pidEpochs[pid] = peerChainState.FinalizedEpoch
|
||||
pidEpoch[pid] = peerChainState.FinalizedEpoch
|
||||
potentialPIDs = append(potentialPIDs, pid)
|
||||
}
|
||||
}
|
||||
@ -457,12 +457,12 @@ func (p *Status) BestFinalized(maxPeers int, ourFinalizedEpoch uint64) ([]byte,
|
||||
|
||||
// Sort PIDs by finalized epoch, in decreasing order.
|
||||
sort.Slice(potentialPIDs, func(i, j int) bool {
|
||||
return pidEpochs[potentialPIDs[i]] > pidEpochs[potentialPIDs[j]]
|
||||
return pidEpoch[potentialPIDs[i]] > pidEpoch[potentialPIDs[j]]
|
||||
})
|
||||
|
||||
// Trim potential peers to those on or after target epoch.
|
||||
for i, pid := range potentialPIDs {
|
||||
if pidEpochs[pid] < targetEpoch {
|
||||
if pidEpoch[pid] < targetEpoch {
|
||||
potentialPIDs = potentialPIDs[:i]
|
||||
break
|
||||
}
|
||||
@ -484,8 +484,8 @@ func (p *Status) fetch(pid peer.ID) *peerStatus {
|
||||
return p.status[pid]
|
||||
}
|
||||
|
||||
// CurrentEpoch returns the highest reported epoch amongst peers.
|
||||
func (p *Status) CurrentEpoch() uint64 {
|
||||
// HighestEpoch returns the highest epoch reported epoch amongst peers.
|
||||
func (p *Status) HighestEpoch() uint64 {
|
||||
p.lock.RLock()
|
||||
defer p.lock.RUnlock()
|
||||
var highestSlot uint64
|
||||
|
@ -671,8 +671,8 @@ func TestStatus_CurrentEpoch(t *testing.T) {
|
||||
HeadSlot: params.BeaconConfig().SlotsPerEpoch * 4,
|
||||
})
|
||||
|
||||
if p.CurrentEpoch() != 5 {
|
||||
t.Fatalf("Expected current epoch to be 5, got %d", p.CurrentEpoch())
|
||||
if p.HighestEpoch() != 5 {
|
||||
t.Fatalf("Expected current epoch to be 5, got %d", p.HighestEpoch())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -177,7 +177,7 @@ func (s *Service) Status() error {
|
||||
// If our head slot is on a previous epoch and our peers are reporting their head block are
|
||||
// in the most recent epoch, then we might be out of sync.
|
||||
if headEpoch := helpers.SlotToEpoch(s.chain.HeadSlot()); headEpoch+1 < helpers.SlotToEpoch(s.chain.CurrentSlot()) &&
|
||||
headEpoch+1 < s.p2p.Peers().CurrentEpoch() {
|
||||
headEpoch+1 < s.p2p.Peers().HighestEpoch() {
|
||||
return errors.New("out of sync")
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user