Clean up state types (#11916)

* Clean up state types

* rename package
This commit is contained in:
Radosław Kapka
2023-01-26 15:40:12 +01:00
committed by GitHub
parent a296a0c783
commit 77d3ccb9ad
555 changed files with 4696 additions and 4958 deletions

View File

@@ -38,7 +38,7 @@ import (
"github.com/prysmaticlabs/prysm/v3/beacon-chain/p2p/peers/scorers"
"github.com/prysmaticlabs/prysm/v3/config/features"
"github.com/prysmaticlabs/prysm/v3/config/params"
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/v3/crypto/rand"
pmath "github.com/prysmaticlabs/prysm/v3/math"
pb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
@@ -645,11 +645,11 @@ func (p *Status) deprecatedPrune() {
// 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 epoch number and list of peers that are at or beyond that epoch.
func (p *Status) BestFinalized(maxPeers int, ourFinalizedEpoch types.Epoch) (types.Epoch, []peer.ID) {
func (p *Status) BestFinalized(maxPeers int, ourFinalizedEpoch primitives.Epoch) (primitives.Epoch, []peer.ID) {
connected := p.Connected()
finalizedEpochVotes := make(map[types.Epoch]uint64)
pidEpoch := make(map[peer.ID]types.Epoch, len(connected))
pidHead := make(map[peer.ID]types.Slot, len(connected))
finalizedEpochVotes := make(map[primitives.Epoch]uint64)
pidEpoch := make(map[peer.ID]primitives.Epoch, len(connected))
pidHead := make(map[peer.ID]primitives.Slot, len(connected))
potentialPIDs := make([]peer.ID, 0, len(connected))
for _, pid := range connected {
peerChainState, err := p.ChainState(pid)
@@ -662,7 +662,7 @@ func (p *Status) BestFinalized(maxPeers int, ourFinalizedEpoch types.Epoch) (typ
}
// Select the target epoch, which is the epoch most peers agree upon.
var targetEpoch types.Epoch
var targetEpoch primitives.Epoch
var mostVotes uint64
for epoch, count := range finalizedEpochVotes {
if count > mostVotes || (count == mostVotes && epoch > targetEpoch) {
@@ -697,11 +697,11 @@ func (p *Status) BestFinalized(maxPeers int, ourFinalizedEpoch types.Epoch) (typ
// BestNonFinalized returns the highest known epoch, higher than ours,
// and is shared by at least minPeers.
func (p *Status) BestNonFinalized(minPeers int, ourHeadEpoch types.Epoch) (types.Epoch, []peer.ID) {
func (p *Status) BestNonFinalized(minPeers int, ourHeadEpoch primitives.Epoch) (primitives.Epoch, []peer.ID) {
connected := p.Connected()
epochVotes := make(map[types.Epoch]uint64)
pidEpoch := make(map[peer.ID]types.Epoch, len(connected))
pidHead := make(map[peer.ID]types.Slot, len(connected))
epochVotes := make(map[primitives.Epoch]uint64)
pidEpoch := make(map[peer.ID]primitives.Epoch, len(connected))
pidHead := make(map[peer.ID]primitives.Slot, len(connected))
potentialPIDs := make([]peer.ID, 0, len(connected))
ourHeadSlot := params.BeaconConfig().SlotsPerEpoch.Mul(uint64(ourHeadEpoch))
@@ -717,7 +717,7 @@ func (p *Status) BestNonFinalized(minPeers int, ourHeadEpoch types.Epoch) (types
}
// Select the target epoch, which has enough peers' votes (>= minPeers).
var targetEpoch types.Epoch
var targetEpoch primitives.Epoch
for epoch, votes := range epochVotes {
if votes >= uint64(minPeers) && targetEpoch < epoch {
targetEpoch = epoch
@@ -878,10 +878,10 @@ func (p *Status) deprecatedPeersToPrune() []peer.ID {
}
// HighestEpoch returns the highest epoch reported epoch amongst peers.
func (p *Status) HighestEpoch() types.Epoch {
func (p *Status) HighestEpoch() primitives.Epoch {
p.store.RLock()
defer p.store.RUnlock()
var highestSlot types.Slot
var highestSlot primitives.Slot
for _, peerData := range p.store.Peers() {
if peerData != nil && peerData.ChainState != nil && peerData.ChainState.HeadSlot > highestSlot {
highestSlot = peerData.ChainState.HeadSlot