From ad92b6508a3f3b868d18b9e3607260d8f055c36b Mon Sep 17 00:00:00 2001 From: rauljordan Date: Fri, 26 Jun 2020 10:27:09 -0500 Subject: [PATCH] no error returned --- beacon-chain/p2p/peers/status.go | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/beacon-chain/p2p/peers/status.go b/beacon-chain/p2p/peers/status.go index fb4189461bfb..8a9b970f5e54 100644 --- a/beacon-chain/p2p/peers/status.go +++ b/beacon-chain/p2p/peers/status.go @@ -32,9 +32,9 @@ import ( ma "github.com/multiformats/go-multiaddr" ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1" "github.com/prysmaticlabs/go-bitfield" + "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1" - "github.com/prysmaticlabs/prysm/shared/bytesutil" "github.com/prysmaticlabs/prysm/shared/roughtime" ) @@ -427,33 +427,29 @@ func (p *Status) Decay() { // Ideally, all peers would be reporting the same finalized epoch but some may be behind due to their own latency, or because of // their finalized epoch at the time we queried them. // Returns the best finalized root, epoch number, and list of peers that are at or beyond that epoch. -func (p *Status) BestFinalized(maxPeers int, ourFinalizedEpoch uint64) ([]byte, uint64, []peer.ID) { +func (p *Status) BestFinalized(maxPeers int, ourFinalizedEpoch uint64) (uint64, []peer.ID, error) { connected := p.Connected() - finalized := make(map[[32]byte]uint64) - rootToEpoch := make(map[[32]byte]uint64) + finalizedEpochVotes := make(map[uint64]uint64) pidEpoch := make(map[peer.ID]uint64) potentialPIDs := make([]peer.ID, 0, len(connected)) for _, pid := range connected { peerChainState, err := p.ChainState(pid) if err == nil && peerChainState != nil && peerChainState.FinalizedEpoch >= ourFinalizedEpoch { - root := bytesutil.ToBytes32(peerChainState.FinalizedRoot) - finalized[root]++ - rootToEpoch[root] = peerChainState.FinalizedEpoch + finalizedEpochVotes[peerChainState.FinalizedEpoch]++ pidEpoch[pid] = peerChainState.FinalizedEpoch potentialPIDs = append(potentialPIDs, pid) } } // Select the target epoch, which is the epoch most peers agree upon. - var targetRoot [32]byte + var targetEpoch uint64 var mostVotes uint64 - for root, count := range finalized { + for epoch, count := range finalizedEpochVotes { if count > mostVotes { mostVotes = count - targetRoot = root + targetEpoch = epoch } } - targetEpoch := rootToEpoch[targetRoot] // Sort PIDs by finalized epoch, in decreasing order. sort.Slice(potentialPIDs, func(i, j int) bool { @@ -473,7 +469,7 @@ func (p *Status) BestFinalized(maxPeers int, ourFinalizedEpoch uint64) ([]byte, potentialPIDs = potentialPIDs[:maxPeers] } - return targetRoot[:], targetEpoch, potentialPIDs + return targetEpoch, potentialPIDs, nil } // fetch is a helper function that fetches a peer status, possibly creating it.