mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-12 12:40:05 +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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if msgLen > maxSize {
|
||||||
|
return fmt.Errorf("remaining bytes %d goes over the provided max limit of %d", msgLen, maxSize)
|
||||||
|
}
|
||||||
if e.UseSnappyCompression {
|
if e.UseSnappyCompression {
|
||||||
r = newBufferedReader(r)
|
r = newBufferedReader(r)
|
||||||
defer bufReaderPool.Put(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)))
|
b := make([]byte, e.MaxLength(int(msgLen)))
|
||||||
numOfBytes, err := r.Read(b)
|
numOfBytes, err := r.Read(b)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -431,7 +431,7 @@ func (p *Status) BestFinalized(maxPeers int, ourFinalizedEpoch uint64) ([]byte,
|
|||||||
connected := p.Connected()
|
connected := p.Connected()
|
||||||
finalized := make(map[[32]byte]uint64)
|
finalized := make(map[[32]byte]uint64)
|
||||||
rootToEpoch := 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))
|
potentialPIDs := make([]peer.ID, 0, len(connected))
|
||||||
for _, pid := range connected {
|
for _, pid := range connected {
|
||||||
peerChainState, err := p.ChainState(pid)
|
peerChainState, err := p.ChainState(pid)
|
||||||
@ -439,7 +439,7 @@ func (p *Status) BestFinalized(maxPeers int, ourFinalizedEpoch uint64) ([]byte,
|
|||||||
root := bytesutil.ToBytes32(peerChainState.FinalizedRoot)
|
root := bytesutil.ToBytes32(peerChainState.FinalizedRoot)
|
||||||
finalized[root]++
|
finalized[root]++
|
||||||
rootToEpoch[root] = peerChainState.FinalizedEpoch
|
rootToEpoch[root] = peerChainState.FinalizedEpoch
|
||||||
pidEpochs[pid] = peerChainState.FinalizedEpoch
|
pidEpoch[pid] = peerChainState.FinalizedEpoch
|
||||||
potentialPIDs = append(potentialPIDs, pid)
|
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 PIDs by finalized epoch, in decreasing order.
|
||||||
sort.Slice(potentialPIDs, func(i, j int) bool {
|
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.
|
// Trim potential peers to those on or after target epoch.
|
||||||
for i, pid := range potentialPIDs {
|
for i, pid := range potentialPIDs {
|
||||||
if pidEpochs[pid] < targetEpoch {
|
if pidEpoch[pid] < targetEpoch {
|
||||||
potentialPIDs = potentialPIDs[:i]
|
potentialPIDs = potentialPIDs[:i]
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@ -484,8 +484,8 @@ func (p *Status) fetch(pid peer.ID) *peerStatus {
|
|||||||
return p.status[pid]
|
return p.status[pid]
|
||||||
}
|
}
|
||||||
|
|
||||||
// CurrentEpoch returns the highest reported epoch amongst peers.
|
// HighestEpoch returns the highest epoch reported epoch amongst peers.
|
||||||
func (p *Status) CurrentEpoch() uint64 {
|
func (p *Status) HighestEpoch() uint64 {
|
||||||
p.lock.RLock()
|
p.lock.RLock()
|
||||||
defer p.lock.RUnlock()
|
defer p.lock.RUnlock()
|
||||||
var highestSlot uint64
|
var highestSlot uint64
|
||||||
|
@ -671,8 +671,8 @@ func TestStatus_CurrentEpoch(t *testing.T) {
|
|||||||
HeadSlot: params.BeaconConfig().SlotsPerEpoch * 4,
|
HeadSlot: params.BeaconConfig().SlotsPerEpoch * 4,
|
||||||
})
|
})
|
||||||
|
|
||||||
if p.CurrentEpoch() != 5 {
|
if p.HighestEpoch() != 5 {
|
||||||
t.Fatalf("Expected current epoch to be 5, got %d", p.CurrentEpoch())
|
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
|
// 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.
|
// 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()) &&
|
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")
|
return errors.New("out of sync")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user