mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 21:38:05 -05:00
Move slot epoch from core to time pkg (#9714)
* Move slot epoch from core to time pkg * Fix fuzz Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
This commit is contained in:
@@ -24,9 +24,9 @@ go_library(
|
||||
"//api/grpc:go_default_library",
|
||||
"//async:go_default_library",
|
||||
"//async/event:go_default_library",
|
||||
"//beacon-chain/core:go_default_library",
|
||||
"//beacon-chain/core/altair:go_default_library",
|
||||
"//beacon-chain/core/signing:go_default_library",
|
||||
"//beacon-chain/core/time:go_default_library",
|
||||
"//cache/lru:go_default_library",
|
||||
"//config/features:go_default_library",
|
||||
"//config/params:go_default_library",
|
||||
|
||||
@@ -6,8 +6,8 @@ import (
|
||||
"time"
|
||||
|
||||
types "github.com/prysmaticlabs/eth2-types"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/signing"
|
||||
coreTime "github.com/prysmaticlabs/prysm/beacon-chain/core/time"
|
||||
"github.com/prysmaticlabs/prysm/config/params"
|
||||
"github.com/prysmaticlabs/prysm/crypto/bls"
|
||||
"github.com/prysmaticlabs/prysm/monitoring/tracing"
|
||||
@@ -118,7 +118,7 @@ func (v *validator) SubmitAggregateAndProof(ctx context.Context, slot types.Slot
|
||||
|
||||
// Signs input slot with domain selection proof. This is used to create the signature for aggregator selection.
|
||||
func (v *validator) signSlotWithSelectionProof(ctx context.Context, pubKey [48]byte, slot types.Slot) (signature []byte, err error) {
|
||||
domain, err := v.domainData(ctx, core.SlotToEpoch(slot), params.BeaconConfig().DomainSelectionProof[:])
|
||||
domain, err := v.domainData(ctx, coreTime.SlotToEpoch(slot), params.BeaconConfig().DomainSelectionProof[:])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -173,7 +173,7 @@ func (v *validator) waitToSlotTwoThirds(ctx context.Context, slot types.Slot) {
|
||||
// This returns the signature of validator signing over aggregate and
|
||||
// proof object.
|
||||
func (v *validator) aggregateAndProofSig(ctx context.Context, pubKey [48]byte, agg *ethpb.AggregateAttestationAndProof) ([]byte, error) {
|
||||
d, err := v.domainData(ctx, core.SlotToEpoch(agg.Aggregate.Data.Slot), params.BeaconConfig().DomainAggregateAndProof[:])
|
||||
d, err := v.domainData(ctx, coreTime.SlotToEpoch(agg.Aggregate.Data.Slot), params.BeaconConfig().DomainAggregateAndProof[:])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"time"
|
||||
|
||||
types "github.com/prysmaticlabs/eth2-types"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core"
|
||||
coreTime "github.com/prysmaticlabs/prysm/beacon-chain/core/time"
|
||||
"github.com/prysmaticlabs/prysm/config/params"
|
||||
"github.com/prysmaticlabs/prysm/encoding/bytesutil"
|
||||
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
||||
@@ -73,7 +73,7 @@ func (v *validator) LogNextDutyTimeLeft(slot types.Slot) error {
|
||||
if nextDutySlot == 0 {
|
||||
log.WithField("slotInEpoch", slot%params.BeaconConfig().SlotsPerEpoch).Info("No duty until next epoch")
|
||||
} else {
|
||||
nextDutyTime, err := core.SlotToTime(v.genesisTime, nextDutySlot)
|
||||
nextDutyTime, err := coreTime.SlotToTime(v.genesisTime, nextDutySlot)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus/promauto"
|
||||
types "github.com/prysmaticlabs/eth2-types"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/time"
|
||||
"github.com/prysmaticlabs/prysm/config/params"
|
||||
"github.com/prysmaticlabs/prysm/encoding/bytesutil"
|
||||
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
||||
@@ -218,7 +218,7 @@ var (
|
||||
// and penalties over time, percentage gain/loss, and gives the end user a better idea
|
||||
// of how the validator performs with respect to the rest.
|
||||
func (v *validator) LogValidatorGainsAndLosses(ctx context.Context, slot types.Slot) error {
|
||||
if !core.IsEpochEnd(slot) || slot <= params.BeaconConfig().SlotsPerEpoch {
|
||||
if !time.IsEpochEnd(slot) || slot <= params.BeaconConfig().SlotsPerEpoch {
|
||||
// Do nothing unless we are at the end of the epoch, and not in the first epoch.
|
||||
return nil
|
||||
}
|
||||
@@ -324,7 +324,7 @@ func (v *validator) LogValidatorGainsAndLosses(ctx context.Context, slot types.S
|
||||
}
|
||||
|
||||
// These fields are deprecated after Altair.
|
||||
if core.SlotToEpoch(slot) < params.BeaconConfig().AltairForkEpoch {
|
||||
if time.SlotToEpoch(slot) < params.BeaconConfig().AltairForkEpoch {
|
||||
if i < len(resp.InclusionSlots) {
|
||||
previousEpochSummaryFields["inclusionSlot"] = resp.InclusionSlots[i]
|
||||
} else {
|
||||
@@ -336,7 +336,7 @@ func (v *validator) LogValidatorGainsAndLosses(ctx context.Context, slot types.S
|
||||
log.WithField("pubKey", truncatedKey).Warn("Missing inclusion distance")
|
||||
}
|
||||
}
|
||||
if core.SlotToEpoch(slot) >= params.BeaconConfig().AltairForkEpoch {
|
||||
if time.SlotToEpoch(slot) >= params.BeaconConfig().AltairForkEpoch {
|
||||
if i < len(resp.InactivityScores) {
|
||||
previousEpochSummaryFields["inactivityScore"] = resp.InactivityScores[i]
|
||||
} else {
|
||||
@@ -364,7 +364,7 @@ func (v *validator) LogValidatorGainsAndLosses(ctx context.Context, slot types.S
|
||||
}
|
||||
|
||||
// Phase0 specific metrics
|
||||
if core.SlotToEpoch(slot) < params.BeaconConfig().AltairForkEpoch {
|
||||
if time.SlotToEpoch(slot) < params.BeaconConfig().AltairForkEpoch {
|
||||
if i < len(resp.InclusionDistances) {
|
||||
ValidatorInclusionDistancesGaugeVec.WithLabelValues(fmtKey).Set(float64(resp.InclusionDistances[i]))
|
||||
}
|
||||
@@ -395,7 +395,7 @@ func (v *validator) UpdateLogAggregateStats(resp *ethpb.ValidatorPerformanceResp
|
||||
for i := range resp.PublicKeys {
|
||||
// In phase0, we consider attestations included if the inclusion slot is not max uint64.
|
||||
// In altair, we consider attestations included if correctlyVotedTarget is true.
|
||||
if core.SlotToEpoch(slot) < params.BeaconConfig().AltairForkEpoch && i < len(resp.InclusionDistances) {
|
||||
if time.SlotToEpoch(slot) < params.BeaconConfig().AltairForkEpoch && i < len(resp.InclusionDistances) {
|
||||
if uint64(resp.InclusionSlots[i]) != ^uint64(0) {
|
||||
included++
|
||||
summary.includedAttestedCount++
|
||||
@@ -420,7 +420,7 @@ func (v *validator) UpdateLogAggregateStats(resp *ethpb.ValidatorPerformanceResp
|
||||
}
|
||||
|
||||
// Altair metrics
|
||||
if core.SlotToEpoch(slot) > params.BeaconConfig().AltairForkEpoch && i < len(resp.InactivityScores) {
|
||||
if time.SlotToEpoch(slot) > params.BeaconConfig().AltairForkEpoch && i < len(resp.InactivityScores) {
|
||||
inactivityScore += int(resp.InactivityScores[i])
|
||||
}
|
||||
}
|
||||
@@ -445,7 +445,7 @@ func (v *validator) UpdateLogAggregateStats(resp *ethpb.ValidatorPerformanceResp
|
||||
}
|
||||
|
||||
// Altair summary fields.
|
||||
if core.SlotToEpoch(slot) > params.BeaconConfig().AltairForkEpoch && len(resp.CorrectlyVotedTarget) > 0 {
|
||||
if time.SlotToEpoch(slot) > params.BeaconConfig().AltairForkEpoch && len(resp.CorrectlyVotedTarget) > 0 {
|
||||
epochSummaryFields["averageInactivityScore"] = fmt.Sprintf("%.0f", float64(inactivityScore)/float64(len(resp.CorrectlyVotedTarget)))
|
||||
}
|
||||
|
||||
@@ -476,7 +476,7 @@ func (v *validator) UpdateLogAggregateStats(resp *ethpb.ValidatorPerformanceResp
|
||||
}
|
||||
|
||||
// Add phase0 specific fields
|
||||
if core.SlotToEpoch(slot) < params.BeaconConfig().AltairForkEpoch {
|
||||
if time.SlotToEpoch(slot) < params.BeaconConfig().AltairForkEpoch {
|
||||
launchSummaryFields["averageInclusionDistance"] = fmt.Sprintf("%.2f slots", float64(summary.totalDistance)/float64(summary.includedAttestedCount))
|
||||
}
|
||||
|
||||
|
||||
@@ -9,8 +9,8 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
types "github.com/prysmaticlabs/eth2-types"
|
||||
"github.com/prysmaticlabs/prysm/async"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/signing"
|
||||
coreTime "github.com/prysmaticlabs/prysm/beacon-chain/core/time"
|
||||
"github.com/prysmaticlabs/prysm/config/params"
|
||||
"github.com/prysmaticlabs/prysm/crypto/bls"
|
||||
"github.com/prysmaticlabs/prysm/crypto/rand"
|
||||
@@ -39,7 +39,7 @@ const signExitErr = "could not sign voluntary exit proposal"
|
||||
// the state root computation, and finally signed by the validator before being
|
||||
// sent back to the beacon node for broadcasting.
|
||||
func (v *validator) ProposeBlock(ctx context.Context, slot types.Slot, pubKey [48]byte) {
|
||||
currEpoch := core.SlotToEpoch(slot)
|
||||
currEpoch := coreTime.SlotToEpoch(slot)
|
||||
switch {
|
||||
case currEpoch >= params.BeaconConfig().AltairForkEpoch:
|
||||
v.proposeBlockAltair(ctx, slot, pubKey)
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
|
||||
"github.com/pkg/errors"
|
||||
types "github.com/prysmaticlabs/eth2-types"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core"
|
||||
coreTime "github.com/prysmaticlabs/prysm/beacon-chain/core/time"
|
||||
"github.com/prysmaticlabs/prysm/config/params"
|
||||
"github.com/prysmaticlabs/prysm/encoding/bytesutil"
|
||||
"github.com/prysmaticlabs/prysm/validator/client/iface"
|
||||
@@ -170,7 +170,7 @@ func run(ctx context.Context, v iface.Validator) {
|
||||
}
|
||||
|
||||
// Start fetching domain data for the next epoch.
|
||||
if core.IsEpochEnd(slot) {
|
||||
if coreTime.IsEpochEnd(slot) {
|
||||
go v.UpdateDomainDataCaches(ctx, slot+1)
|
||||
}
|
||||
|
||||
|
||||
@@ -7,9 +7,9 @@ import (
|
||||
fssz "github.com/ferranbt/fastssz"
|
||||
emptypb "github.com/golang/protobuf/ptypes/empty"
|
||||
types "github.com/prysmaticlabs/eth2-types"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/altair"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/signing"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/time"
|
||||
"github.com/prysmaticlabs/prysm/config/params"
|
||||
"github.com/prysmaticlabs/prysm/crypto/bls"
|
||||
"github.com/prysmaticlabs/prysm/encoding/bytesutil"
|
||||
@@ -41,7 +41,7 @@ func (v *validator) SubmitSyncCommitteeMessage(ctx context.Context, slot types.S
|
||||
return
|
||||
}
|
||||
|
||||
d, err := v.domainData(ctx, core.SlotToEpoch(slot), params.BeaconConfig().DomainSyncCommittee[:])
|
||||
d, err := v.domainData(ctx, time.SlotToEpoch(slot), params.BeaconConfig().DomainSyncCommittee[:])
|
||||
if err != nil {
|
||||
log.WithError(err).Error("Could not get sync committee domain data")
|
||||
return
|
||||
@@ -191,7 +191,7 @@ func (v *validator) selectionProofs(ctx context.Context, slot types.Slot, pubKey
|
||||
|
||||
// Signs input slot with domain sync committee selection proof. This is used to create the signature for sync committee selection.
|
||||
func (v *validator) signSyncSelectionData(ctx context.Context, pubKey [48]byte, index uint64, slot types.Slot) (signature []byte, err error) {
|
||||
domain, err := v.domainData(ctx, core.SlotToEpoch(slot), params.BeaconConfig().DomainSyncCommitteeSelectionProof[:])
|
||||
domain, err := v.domainData(ctx, time.SlotToEpoch(slot), params.BeaconConfig().DomainSyncCommitteeSelectionProof[:])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -208,7 +208,7 @@ func (v *validator) signSyncSelectionData(ctx context.Context, pubKey [48]byte,
|
||||
|
||||
// This returns the signature of validator signing over sync committee contribution and proof object.
|
||||
func (v *validator) signContributionAndProof(ctx context.Context, pubKey [48]byte, c *ethpb.ContributionAndProof) ([]byte, error) {
|
||||
d, err := v.domainData(ctx, core.SlotToEpoch(c.Contribution.Slot), params.BeaconConfig().DomainContributionAndProof[:])
|
||||
d, err := v.domainData(ctx, time.SlotToEpoch(c.Contribution.Slot), params.BeaconConfig().DomainContributionAndProof[:])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -19,8 +19,8 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
types "github.com/prysmaticlabs/eth2-types"
|
||||
"github.com/prysmaticlabs/prysm/async/event"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/altair"
|
||||
coreTime "github.com/prysmaticlabs/prysm/beacon-chain/core/time"
|
||||
"github.com/prysmaticlabs/prysm/config/features"
|
||||
"github.com/prysmaticlabs/prysm/config/params"
|
||||
"github.com/prysmaticlabs/prysm/crypto/hash"
|
||||
@@ -458,7 +458,7 @@ func (v *validator) UpdateDuties(ctx context.Context, slot types.Slot) error {
|
||||
return nil
|
||||
}
|
||||
// Set deadline to end of epoch.
|
||||
ss, err := core.StartSlot(core.SlotToEpoch(slot) + 1)
|
||||
ss, err := coreTime.StartSlot(coreTime.SlotToEpoch(slot) + 1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -615,7 +615,7 @@ func (v *validator) RolesAt(ctx context.Context, slot types.Slot) (map[[48]byte]
|
||||
// broadcasts signatures for `slot - 1` for inclusion in `slot`. At the last slot of the epoch,
|
||||
// the validator checks whether it's in the sync committee of following epoch.
|
||||
inSyncCommittee := false
|
||||
if core.IsEpochEnd(slot) {
|
||||
if coreTime.IsEpochEnd(slot) {
|
||||
if v.duties.NextEpochDuties[validator].IsSyncCommittee {
|
||||
roles = append(roles, iface.RoleSyncCommittee)
|
||||
inSyncCommittee = true
|
||||
@@ -717,7 +717,7 @@ func (v *validator) UpdateDomainDataCaches(ctx context.Context, slot types.Slot)
|
||||
params.BeaconConfig().DomainSelectionProof[:],
|
||||
params.BeaconConfig().DomainAggregateAndProof[:],
|
||||
} {
|
||||
_, err := v.domainData(ctx, core.SlotToEpoch(slot), d)
|
||||
_, err := v.domainData(ctx, coreTime.SlotToEpoch(slot), d)
|
||||
if err != nil {
|
||||
log.WithError(err).Errorf("Failed to update domain data for domain %v", d)
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ go_library(
|
||||
deps = [
|
||||
"//async/abool:go_default_library",
|
||||
"//async/event:go_default_library",
|
||||
"//beacon-chain/core:go_default_library",
|
||||
"//beacon-chain/core/time:go_default_library",
|
||||
"//config/features:go_default_library",
|
||||
"//config/params:go_default_library",
|
||||
"//encoding/bytesutil:go_default_library",
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
|
||||
"github.com/pkg/errors"
|
||||
types "github.com/prysmaticlabs/eth2-types"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/time"
|
||||
"github.com/prysmaticlabs/prysm/config/params"
|
||||
"github.com/prysmaticlabs/prysm/encoding/bytesutil"
|
||||
bolt "go.etcd.io/bbolt"
|
||||
@@ -193,8 +193,8 @@ func pruneProposalHistoryBySlot(valBucket *bolt.Bucket, newestSlot types.Slot) e
|
||||
c := valBucket.Cursor()
|
||||
for k, _ := c.First(); k != nil; k, _ = c.First() {
|
||||
slot := bytesutil.BytesToSlotBigEndian(k)
|
||||
epoch := core.SlotToEpoch(slot)
|
||||
newestEpoch := core.SlotToEpoch(newestSlot)
|
||||
epoch := time.SlotToEpoch(slot)
|
||||
newestEpoch := time.SlotToEpoch(newestSlot)
|
||||
// Only delete epochs that are older than the weak subjectivity period.
|
||||
if epoch+params.BeaconConfig().WeakSubjectivityPeriod <= newestEpoch {
|
||||
if err := c.Delete(); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user