mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-22 03:30:35 +00:00
Create time Package for Shared/timeutil, mclock and slotutil (#9594)
* add time pkg * Go fmt
This commit is contained in:
parent
77de467250
commit
3e71997290
@ -56,9 +56,9 @@ go_library(
|
||||
"//shared/featureconfig:go_default_library",
|
||||
"//shared/mputil:go_default_library",
|
||||
"//shared/params:go_default_library",
|
||||
"//shared/slotutil:go_default_library",
|
||||
"//shared/timeutils:go_default_library",
|
||||
"//shared/version:go_default_library",
|
||||
"//time:go_default_library",
|
||||
"//time/slots:go_default_library",
|
||||
"@com_github_emicklei_dot//:go_default_library",
|
||||
"@com_github_pkg_errors//:go_default_library",
|
||||
"@com_github_prometheus_client_golang//prometheus:go_default_library",
|
||||
|
@ -18,7 +18,7 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/shared/bytesutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/featureconfig"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
"github.com/prysmaticlabs/prysm/shared/slotutil"
|
||||
"github.com/prysmaticlabs/prysm/time/slots"
|
||||
"github.com/sirupsen/logrus"
|
||||
"go.opencensus.io/trace"
|
||||
)
|
||||
@ -131,7 +131,7 @@ func (s *Service) saveHead(ctx context.Context, headRoot [32]byte) error {
|
||||
"newSlot": fmt.Sprintf("%d", newHeadSlot),
|
||||
"oldSlot": fmt.Sprintf("%d", headSlot),
|
||||
}).Debug("Chain reorg occurred")
|
||||
absoluteSlotDifference := slotutil.AbsoluteValueSlotDifference(newHeadSlot, headSlot)
|
||||
absoluteSlotDifference := slots.AbsoluteValueSlotDifference(newHeadSlot, headSlot)
|
||||
s.cfg.StateNotifier.StateFeed().Send(&feed.Event{
|
||||
Type: statefeed.Reorg,
|
||||
Data: ðpbv1.EventChainReorg{
|
||||
|
@ -9,8 +9,8 @@ import (
|
||||
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/block"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
"github.com/prysmaticlabs/prysm/shared/timeutils"
|
||||
"github.com/prysmaticlabs/prysm/shared/version"
|
||||
prysmTime "github.com/prysmaticlabs/prysm/time"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
@ -58,8 +58,8 @@ func logBlockSyncStatus(block block.BeaconBlock, blockRoot [32]byte, finalized *
|
||||
}).Info("Synced new block")
|
||||
log.WithFields(logrus.Fields{
|
||||
"slot": block.Slot,
|
||||
"sinceSlotStartTime": timeutils.Now().Sub(startTime),
|
||||
"chainServiceProcessedTime": timeutils.Now().Sub(receivedTime),
|
||||
"sinceSlotStartTime": prysmTime.Now().Sub(startTime),
|
||||
"chainServiceProcessedTime": prysmTime.Now().Sub(receivedTime),
|
||||
}).Debug("Sync new block times")
|
||||
return nil
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/shared/attestationutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/bytesutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
"github.com/prysmaticlabs/prysm/shared/timeutils"
|
||||
"github.com/prysmaticlabs/prysm/time"
|
||||
"go.opencensus.io/trace"
|
||||
)
|
||||
|
||||
@ -62,7 +62,7 @@ func (s *Service) onAttestation(ctx context.Context, a *ethpb.Attestation) error
|
||||
genesisTime := baseState.GenesisTime()
|
||||
|
||||
// Verify attestation target is from current epoch or previous epoch.
|
||||
if err := s.verifyAttTargetEpoch(ctx, genesisTime, uint64(timeutils.Now().Unix()), tgt); err != nil {
|
||||
if err := s.verifyAttTargetEpoch(ctx, genesisTime, uint64(time.Now().Unix()), tgt); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -17,7 +17,7 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
||||
"github.com/prysmaticlabs/prysm/shared/timeutils"
|
||||
"github.com/prysmaticlabs/prysm/time"
|
||||
)
|
||||
|
||||
func TestStore_OnAttestation_ErrorConditions(t *testing.T) {
|
||||
@ -138,7 +138,7 @@ func TestStore_OnAttestation_Ok(t *testing.T) {
|
||||
service, err := NewService(ctx, cfg)
|
||||
require.NoError(t, err)
|
||||
genesisState, pks := testutil.DeterministicGenesisState(t, 64)
|
||||
require.NoError(t, genesisState.SetGenesisTime(uint64(timeutils.Now().Unix())-params.BeaconConfig().SecondsPerSlot))
|
||||
require.NoError(t, genesisState.SetGenesisTime(uint64(time.Now().Unix())-params.BeaconConfig().SecondsPerSlot))
|
||||
require.NoError(t, service.saveGenesisData(ctx, genesisState))
|
||||
att, err := testutil.GenerateAttestations(genesisState, pks, 1, 0, false)
|
||||
require.NoError(t, err)
|
||||
|
@ -30,7 +30,7 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
||||
"github.com/prysmaticlabs/prysm/shared/timeutils"
|
||||
prysmTime "github.com/prysmaticlabs/prysm/time"
|
||||
)
|
||||
|
||||
func TestStore_OnBlock(t *testing.T) {
|
||||
@ -567,7 +567,7 @@ func blockTree1(t *testing.T, beaconDB db.Database, genesisRoot []byte) ([][]byt
|
||||
}
|
||||
|
||||
func TestCurrentSlot_HandlesOverflow(t *testing.T) {
|
||||
svc := Service{genesisTime: timeutils.Now().Add(1 * time.Hour)}
|
||||
svc := Service{genesisTime: prysmTime.Now().Add(1 * time.Hour)}
|
||||
|
||||
slot := svc.CurrentSlot()
|
||||
require.Equal(t, types.Slot(0), slot, "Unexpected slot")
|
||||
|
@ -14,7 +14,7 @@ import (
|
||||
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/shared/bytesutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
"github.com/prysmaticlabs/prysm/shared/slotutil"
|
||||
"github.com/prysmaticlabs/prysm/time/slots"
|
||||
"github.com/sirupsen/logrus"
|
||||
"go.opencensus.io/trace"
|
||||
)
|
||||
@ -114,7 +114,7 @@ func (s *Service) processAttestationsRoutine(subscribedToStateEvents chan<- stru
|
||||
log.Warn("Genesis time received, now available to process attestations")
|
||||
}
|
||||
|
||||
st := slotutil.NewSlotTicker(s.genesisTime, params.BeaconConfig().SecondsPerSlot)
|
||||
st := slots.NewSlotTicker(s.genesisTime, params.BeaconConfig().SecondsPerSlot)
|
||||
for {
|
||||
select {
|
||||
case <-s.ctx.Done():
|
||||
|
@ -19,7 +19,7 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
||||
"github.com/prysmaticlabs/prysm/shared/timeutils"
|
||||
prysmTime "github.com/prysmaticlabs/prysm/time"
|
||||
logTest "github.com/sirupsen/logrus/hooks/test"
|
||||
)
|
||||
|
||||
@ -103,10 +103,10 @@ func TestProcessAttestations_Ok(t *testing.T) {
|
||||
AttPool: attestations.NewPool(),
|
||||
}
|
||||
service, err := NewService(ctx, cfg)
|
||||
service.genesisTime = timeutils.Now().Add(-1 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second)
|
||||
service.genesisTime = prysmTime.Now().Add(-1 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second)
|
||||
require.NoError(t, err)
|
||||
genesisState, pks := testutil.DeterministicGenesisState(t, 64)
|
||||
require.NoError(t, genesisState.SetGenesisTime(uint64(timeutils.Now().Unix())-params.BeaconConfig().SecondsPerSlot))
|
||||
require.NoError(t, genesisState.SetGenesisTime(uint64(prysmTime.Now().Unix())-params.BeaconConfig().SecondsPerSlot))
|
||||
require.NoError(t, service.saveGenesisData(ctx, genesisState))
|
||||
atts, err := testutil.GenerateAttestations(genesisState, pks, 1, 0, false)
|
||||
require.NoError(t, err)
|
||||
|
@ -11,7 +11,7 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/monitoring/tracing"
|
||||
"github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/block"
|
||||
"github.com/prysmaticlabs/prysm/shared/featureconfig"
|
||||
"github.com/prysmaticlabs/prysm/shared/timeutils"
|
||||
"github.com/prysmaticlabs/prysm/time"
|
||||
"go.opencensus.io/trace"
|
||||
)
|
||||
|
||||
@ -33,7 +33,7 @@ type BlockReceiver interface {
|
||||
func (s *Service) ReceiveBlock(ctx context.Context, block block.SignedBeaconBlock, blockRoot [32]byte) error {
|
||||
ctx, span := trace.StartSpan(ctx, "blockChain.ReceiveBlock")
|
||||
defer span.End()
|
||||
receivedTime := timeutils.Now()
|
||||
receivedTime := time.Now()
|
||||
blockCopy := block.Copy()
|
||||
|
||||
// Apply state transition on the new block.
|
||||
|
@ -33,7 +33,7 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/block"
|
||||
"github.com/prysmaticlabs/prysm/shared/bytesutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
"github.com/prysmaticlabs/prysm/shared/slotutil"
|
||||
"github.com/prysmaticlabs/prysm/time/slots"
|
||||
"github.com/sirupsen/logrus"
|
||||
"go.opencensus.io/trace"
|
||||
)
|
||||
@ -152,7 +152,7 @@ func (s *Service) Start() {
|
||||
if err != nil {
|
||||
log.Fatalf("Could not hash tree root genesis state: %v", err)
|
||||
}
|
||||
go slotutil.CountdownToGenesis(s.ctx, s.genesisTime, uint64(gState.NumValidators()), gRoot)
|
||||
go slots.CountdownToGenesis(s.ctx, s.genesisTime, uint64(gState.NumValidators()), gRoot)
|
||||
|
||||
justifiedCheckpoint, err := s.cfg.BeaconDB.JustifiedCheckpoint(s.ctx)
|
||||
if err != nil {
|
||||
@ -252,7 +252,7 @@ func (s *Service) processChainStartTime(ctx context.Context, genesisTime time.Ti
|
||||
if err != nil {
|
||||
log.Fatalf("Could not hash tree root genesis state: %v", err)
|
||||
}
|
||||
go slotutil.CountdownToGenesis(ctx, genesisTime, uint64(initializedState.NumValidators()), gRoot)
|
||||
go slots.CountdownToGenesis(ctx, genesisTime, uint64(initializedState.NumValidators()), gRoot)
|
||||
|
||||
// We send out a state initialized event to the rest of the services
|
||||
// running in the beacon node.
|
||||
|
@ -24,8 +24,8 @@ go_library(
|
||||
deps = [
|
||||
"//beacon-chain/state:go_default_library",
|
||||
"//shared/params:go_default_library",
|
||||
"//shared/timeutils:go_default_library",
|
||||
"//shared/version:go_default_library",
|
||||
"//time:go_default_library",
|
||||
"@com_github_ethereum_go_ethereum//common/math:go_default_library",
|
||||
"@com_github_pkg_errors//:go_default_library",
|
||||
"@com_github_prysmaticlabs_eth2_types//:go_default_library",
|
||||
@ -42,7 +42,7 @@ go_test(
|
||||
"//shared/params:go_default_library",
|
||||
"//shared/testutil/assert:go_default_library",
|
||||
"//shared/testutil/require:go_default_library",
|
||||
"//shared/timeutils:go_default_library",
|
||||
"//time:go_default_library",
|
||||
"@com_github_prysmaticlabs_eth2_types//:go_default_library",
|
||||
],
|
||||
)
|
||||
|
@ -76,8 +76,8 @@ go_test(
|
||||
"//shared/testutil:go_default_library",
|
||||
"//shared/testutil/assert:go_default_library",
|
||||
"//shared/testutil/require:go_default_library",
|
||||
"//shared/timeutils:go_default_library",
|
||||
"//shared/trieutil:go_default_library",
|
||||
"//time:go_default_library",
|
||||
"@com_github_google_gofuzz//:go_default_library",
|
||||
"@com_github_prysmaticlabs_eth2_types//:go_default_library",
|
||||
"@com_github_prysmaticlabs_go_bitfield//:go_default_library",
|
||||
|
@ -14,7 +14,7 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
||||
"github.com/prysmaticlabs/prysm/shared/timeutils"
|
||||
prysmTime "github.com/prysmaticlabs/prysm/time"
|
||||
)
|
||||
|
||||
func TestSyncCommitteeIndices_CanGet(t *testing.T) {
|
||||
@ -299,14 +299,14 @@ func Test_ValidateSyncMessageTime(t *testing.T) {
|
||||
name: "sync_message.slot == current_slot",
|
||||
args: args{
|
||||
syncMessageSlot: 15,
|
||||
genesisTime: timeutils.Now().Add(-15 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second),
|
||||
genesisTime: prysmTime.Now().Add(-15 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "sync_message.slot == current_slot, received in middle of slot",
|
||||
args: args{
|
||||
syncMessageSlot: 15,
|
||||
genesisTime: timeutils.Now().Add(
|
||||
genesisTime: prysmTime.Now().Add(
|
||||
-15 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second,
|
||||
).Add(-(time.Duration(params.BeaconConfig().SecondsPerSlot/2) * time.Second)),
|
||||
},
|
||||
@ -315,7 +315,7 @@ func Test_ValidateSyncMessageTime(t *testing.T) {
|
||||
name: "sync_message.slot == current_slot, received 200ms early",
|
||||
args: args{
|
||||
syncMessageSlot: 16,
|
||||
genesisTime: timeutils.Now().Add(
|
||||
genesisTime: prysmTime.Now().Add(
|
||||
-16 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second,
|
||||
).Add(-200 * time.Millisecond),
|
||||
},
|
||||
@ -324,7 +324,7 @@ func Test_ValidateSyncMessageTime(t *testing.T) {
|
||||
name: "sync_message.slot > current_slot",
|
||||
args: args{
|
||||
syncMessageSlot: 16,
|
||||
genesisTime: timeutils.Now().Add(-(15 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second)),
|
||||
genesisTime: prysmTime.Now().Add(-(15 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second)),
|
||||
},
|
||||
wantedErr: "sync message slot 16 not within allowable range of",
|
||||
},
|
||||
@ -332,7 +332,7 @@ func Test_ValidateSyncMessageTime(t *testing.T) {
|
||||
name: "sync_message.slot == current_slot+CLOCK_DISPARITY",
|
||||
args: args{
|
||||
syncMessageSlot: 100,
|
||||
genesisTime: timeutils.Now().Add(-(100*time.Duration(params.BeaconConfig().SecondsPerSlot)*time.Second - params.BeaconNetworkConfig().MaximumGossipClockDisparity)),
|
||||
genesisTime: prysmTime.Now().Add(-(100*time.Duration(params.BeaconConfig().SecondsPerSlot)*time.Second - params.BeaconNetworkConfig().MaximumGossipClockDisparity)),
|
||||
},
|
||||
wantedErr: "",
|
||||
},
|
||||
@ -340,7 +340,7 @@ func Test_ValidateSyncMessageTime(t *testing.T) {
|
||||
name: "sync_message.slot == current_slot+CLOCK_DISPARITY-1000ms",
|
||||
args: args{
|
||||
syncMessageSlot: 100,
|
||||
genesisTime: timeutils.Now().Add(-(100 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second) + params.BeaconNetworkConfig().MaximumGossipClockDisparity + 1000*time.Millisecond),
|
||||
genesisTime: prysmTime.Now().Add(-(100 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second) + params.BeaconNetworkConfig().MaximumGossipClockDisparity + 1000*time.Millisecond),
|
||||
},
|
||||
wantedErr: "sync message slot 100 not within allowable range of",
|
||||
},
|
||||
@ -348,7 +348,7 @@ func Test_ValidateSyncMessageTime(t *testing.T) {
|
||||
name: "sync_message.slot == current_slot-CLOCK_DISPARITY",
|
||||
args: args{
|
||||
syncMessageSlot: 100,
|
||||
genesisTime: timeutils.Now().Add(-(100*time.Duration(params.BeaconConfig().SecondsPerSlot)*time.Second + params.BeaconNetworkConfig().MaximumGossipClockDisparity)),
|
||||
genesisTime: prysmTime.Now().Add(-(100*time.Duration(params.BeaconConfig().SecondsPerSlot)*time.Second + params.BeaconNetworkConfig().MaximumGossipClockDisparity)),
|
||||
},
|
||||
wantedErr: "",
|
||||
},
|
||||
@ -356,7 +356,7 @@ func Test_ValidateSyncMessageTime(t *testing.T) {
|
||||
name: "sync_message.slot > current_slot+CLOCK_DISPARITY",
|
||||
args: args{
|
||||
syncMessageSlot: 101,
|
||||
genesisTime: timeutils.Now().Add(-(100*time.Duration(params.BeaconConfig().SecondsPerSlot)*time.Second + params.BeaconNetworkConfig().MaximumGossipClockDisparity)),
|
||||
genesisTime: prysmTime.Now().Add(-(100*time.Duration(params.BeaconConfig().SecondsPerSlot)*time.Second + params.BeaconNetworkConfig().MaximumGossipClockDisparity)),
|
||||
},
|
||||
wantedErr: "sync message slot 101 not within allowable range of",
|
||||
},
|
||||
@ -364,7 +364,7 @@ func Test_ValidateSyncMessageTime(t *testing.T) {
|
||||
name: "sync_message.slot is well beyond current slot",
|
||||
args: args{
|
||||
syncMessageSlot: 1 << 32,
|
||||
genesisTime: timeutils.Now().Add(-15 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second),
|
||||
genesisTime: prysmTime.Now().Add(-15 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second),
|
||||
},
|
||||
wantedErr: "which exceeds max allowed value relative to the local clock",
|
||||
},
|
||||
|
@ -45,8 +45,8 @@ go_library(
|
||||
"//shared/mathutil:go_default_library",
|
||||
"//shared/params:go_default_library",
|
||||
"//shared/sliceutil:go_default_library",
|
||||
"//shared/timeutils:go_default_library",
|
||||
"//shared/trieutil:go_default_library",
|
||||
"//time:go_default_library",
|
||||
"@com_github_ferranbt_fastssz//:go_default_library",
|
||||
"@com_github_pkg_errors//:go_default_library",
|
||||
"@com_github_prysmaticlabs_eth2_types//:go_default_library",
|
||||
@ -88,7 +88,7 @@ go_test(
|
||||
"//shared/testutil:go_default_library",
|
||||
"//shared/testutil/assert:go_default_library",
|
||||
"//shared/testutil/require:go_default_library",
|
||||
"//shared/timeutils:go_default_library",
|
||||
"//time:go_default_library",
|
||||
"@com_github_google_gofuzz//:go_default_library",
|
||||
"@com_github_prysmaticlabs_eth2_types//:go_default_library",
|
||||
"@com_github_prysmaticlabs_go_bitfield//:go_default_library",
|
||||
|
@ -12,7 +12,7 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/shared/bls"
|
||||
"github.com/prysmaticlabs/prysm/shared/hashutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
"github.com/prysmaticlabs/prysm/shared/timeutils"
|
||||
prysmTime "github.com/prysmaticlabs/prysm/time"
|
||||
)
|
||||
|
||||
// ValidateNilAttestation checks if any composite field of input attestation is nil.
|
||||
@ -155,7 +155,7 @@ func ValidateAttestationTime(attSlot types.Slot, genesisTime time.Time, clockDis
|
||||
// so the upper bounds is set to now + clockDisparity(SECONDS_PER_SLOT * 2).
|
||||
// But when sending an attestation, it should not be in future slot.
|
||||
// so the upper bounds is set to now + clockDisparity(MAXIMUM_GOSSIP_CLOCK_DISPARITY).
|
||||
upperBounds := timeutils.Now().Add(clockDisparity)
|
||||
upperBounds := prysmTime.Now().Add(clockDisparity)
|
||||
|
||||
// An attestation cannot be older than the current slot - attestation propagation slot range
|
||||
// with a minor tolerance for peer clock disparity.
|
||||
@ -184,7 +184,7 @@ func ValidateAttestationTime(attSlot types.Slot, genesisTime time.Time, clockDis
|
||||
// VerifyCheckpointEpoch is within current epoch and previous epoch
|
||||
// with respect to current time. Returns true if it's within, false if it's not.
|
||||
func VerifyCheckpointEpoch(c *ethpb.Checkpoint, genesis time.Time) bool {
|
||||
now := uint64(timeutils.Now().Unix())
|
||||
now := uint64(prysmTime.Now().Unix())
|
||||
genesisTime := uint64(genesis.Unix())
|
||||
currentSlot := types.Slot((now - genesisTime) / params.BeaconConfig().SecondsPerSlot)
|
||||
currentEpoch := core.SlotToEpoch(currentSlot)
|
||||
|
@ -16,7 +16,7 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
||||
"github.com/prysmaticlabs/prysm/shared/timeutils"
|
||||
prysmTime "github.com/prysmaticlabs/prysm/time"
|
||||
)
|
||||
|
||||
func TestAttestation_IsAggregator(t *testing.T) {
|
||||
@ -141,14 +141,14 @@ func Test_ValidateAttestationTime(t *testing.T) {
|
||||
name: "attestation.slot == current_slot",
|
||||
args: args{
|
||||
attSlot: 15,
|
||||
genesisTime: timeutils.Now().Add(-15 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second),
|
||||
genesisTime: prysmTime.Now().Add(-15 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "attestation.slot == current_slot, received in middle of slot",
|
||||
args: args{
|
||||
attSlot: 15,
|
||||
genesisTime: timeutils.Now().Add(
|
||||
genesisTime: prysmTime.Now().Add(
|
||||
-15 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second,
|
||||
).Add(-(time.Duration(params.BeaconConfig().SecondsPerSlot/2) * time.Second)),
|
||||
},
|
||||
@ -157,7 +157,7 @@ func Test_ValidateAttestationTime(t *testing.T) {
|
||||
name: "attestation.slot == current_slot, received 200ms early",
|
||||
args: args{
|
||||
attSlot: 16,
|
||||
genesisTime: timeutils.Now().Add(
|
||||
genesisTime: prysmTime.Now().Add(
|
||||
-16 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second,
|
||||
).Add(-200 * time.Millisecond),
|
||||
},
|
||||
@ -166,7 +166,7 @@ func Test_ValidateAttestationTime(t *testing.T) {
|
||||
name: "attestation.slot > current_slot",
|
||||
args: args{
|
||||
attSlot: 16,
|
||||
genesisTime: timeutils.Now().Add(-15 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second),
|
||||
genesisTime: prysmTime.Now().Add(-15 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second),
|
||||
},
|
||||
wantedErr: "not within attestation propagation range",
|
||||
},
|
||||
@ -174,7 +174,7 @@ func Test_ValidateAttestationTime(t *testing.T) {
|
||||
name: "attestation.slot < current_slot-ATTESTATION_PROPAGATION_SLOT_RANGE",
|
||||
args: args{
|
||||
attSlot: 100 - params.BeaconNetworkConfig().AttestationPropagationSlotRange - 1,
|
||||
genesisTime: timeutils.Now().Add(-100 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second),
|
||||
genesisTime: prysmTime.Now().Add(-100 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second),
|
||||
},
|
||||
wantedErr: "not within attestation propagation range",
|
||||
},
|
||||
@ -182,14 +182,14 @@ func Test_ValidateAttestationTime(t *testing.T) {
|
||||
name: "attestation.slot = current_slot-ATTESTATION_PROPAGATION_SLOT_RANGE",
|
||||
args: args{
|
||||
attSlot: 100 - params.BeaconNetworkConfig().AttestationPropagationSlotRange,
|
||||
genesisTime: timeutils.Now().Add(-100 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second),
|
||||
genesisTime: prysmTime.Now().Add(-100 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "attestation.slot = current_slot-ATTESTATION_PROPAGATION_SLOT_RANGE, received 200ms late",
|
||||
args: args{
|
||||
attSlot: 100 - params.BeaconNetworkConfig().AttestationPropagationSlotRange,
|
||||
genesisTime: timeutils.Now().Add(
|
||||
genesisTime: prysmTime.Now().Add(
|
||||
-100 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second,
|
||||
).Add(200 * time.Millisecond),
|
||||
},
|
||||
@ -198,7 +198,7 @@ func Test_ValidateAttestationTime(t *testing.T) {
|
||||
name: "attestation.slot is well beyond current slot",
|
||||
args: args{
|
||||
attSlot: 1 << 32,
|
||||
genesisTime: timeutils.Now().Add(-15 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second),
|
||||
genesisTime: prysmTime.Now().Add(-15 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second),
|
||||
},
|
||||
wantedErr: "which exceeds max allowed value relative to the local clock",
|
||||
},
|
||||
|
@ -10,8 +10,8 @@ import (
|
||||
types "github.com/prysmaticlabs/eth2-types"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/state"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
"github.com/prysmaticlabs/prysm/shared/timeutils"
|
||||
"github.com/prysmaticlabs/prysm/shared/version"
|
||||
prysmTime "github.com/prysmaticlabs/prysm/time"
|
||||
)
|
||||
|
||||
// MaxSlotBuffer specifies the max buffer given to slots from
|
||||
@ -133,7 +133,7 @@ func VerifySlotTime(genesisTime uint64, slot types.Slot, timeTolerance time.Dura
|
||||
return err
|
||||
}
|
||||
|
||||
currentTime := timeutils.Now()
|
||||
currentTime := prysmTime.Now()
|
||||
diff := slotTime.Sub(currentTime)
|
||||
|
||||
if diff > timeTolerance {
|
||||
@ -163,7 +163,7 @@ func SlotsSince(time time.Time) types.Slot {
|
||||
// CurrentSlot returns the current slot as determined by the local clock and
|
||||
// provided genesis time.
|
||||
func CurrentSlot(genesisTimeSec uint64) types.Slot {
|
||||
now := timeutils.Now().Unix()
|
||||
now := prysmTime.Now().Unix()
|
||||
genesis := int64(genesisTimeSec)
|
||||
if now < genesis {
|
||||
return 0
|
||||
|
@ -11,7 +11,7 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
||||
"github.com/prysmaticlabs/prysm/shared/timeutils"
|
||||
prysmTime "github.com/prysmaticlabs/prysm/time"
|
||||
)
|
||||
|
||||
func TestSlotToEpoch_OK(t *testing.T) {
|
||||
@ -287,21 +287,21 @@ func TestVerifySlotTime(t *testing.T) {
|
||||
{
|
||||
name: "Past slot",
|
||||
args: args{
|
||||
genesisTime: timeutils.Now().Add(-1 * 5 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second).Unix(),
|
||||
genesisTime: prysmTime.Now().Add(-1 * 5 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second).Unix(),
|
||||
slot: 3,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "within tolerance",
|
||||
args: args{
|
||||
genesisTime: timeutils.Now().Add(-1 * 5 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second).Add(20 * time.Millisecond).Unix(),
|
||||
genesisTime: prysmTime.Now().Add(-1 * 5 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second).Add(20 * time.Millisecond).Unix(),
|
||||
slot: 5,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "future slot",
|
||||
args: args{
|
||||
genesisTime: timeutils.Now().Add(-1 * 5 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second).Unix(),
|
||||
genesisTime: prysmTime.Now().Add(-1 * 5 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second).Unix(),
|
||||
slot: 6,
|
||||
},
|
||||
wantedErr: "could not process slot from the future",
|
||||
@ -309,7 +309,7 @@ func TestVerifySlotTime(t *testing.T) {
|
||||
{
|
||||
name: "max future slot",
|
||||
args: args{
|
||||
genesisTime: timeutils.Now().Add(-1 * 5 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second).Unix(),
|
||||
genesisTime: prysmTime.Now().Add(-1 * 5 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second).Unix(),
|
||||
slot: types.Slot(MaxSlotBuffer + 6),
|
||||
},
|
||||
wantedErr: "exceeds max allowed value relative to the local clock",
|
||||
@ -317,7 +317,7 @@ func TestVerifySlotTime(t *testing.T) {
|
||||
{
|
||||
name: "evil future slot",
|
||||
args: args{
|
||||
genesisTime: timeutils.Now().Add(-1 * 24 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second).Unix(), // 24 slots in the past
|
||||
genesisTime: prysmTime.Now().Add(-1 * 24 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second).Unix(), // 24 slots in the past
|
||||
// Gets multiplied with slot duration, and results in an overflow. Wraps around to a valid time.
|
||||
// Lower than max signed int. And chosen specifically to wrap to a valid slot 24
|
||||
slot: types.Slot((^uint64(0))/params.BeaconConfig().SecondsPerSlot) + 24,
|
||||
@ -338,7 +338,7 @@ func TestVerifySlotTime(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestValidateSlotClock_HandlesBadSlot(t *testing.T) {
|
||||
genTime := timeutils.Now().Add(-1 * time.Duration(MaxSlotBuffer) * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second).Unix()
|
||||
genTime := prysmTime.Now().Add(-1 * time.Duration(MaxSlotBuffer) * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second).Unix()
|
||||
|
||||
assert.NoError(t, ValidateSlotClock(types.Slot(MaxSlotBuffer), uint64(genTime)), "unexpected error validating slot")
|
||||
assert.NoError(t, ValidateSlotClock(types.Slot(2*MaxSlotBuffer), uint64(genTime)), "unexpected error validating slot")
|
||||
|
@ -17,7 +17,7 @@ go_library(
|
||||
"//proto/prysm/v1alpha1:go_default_library",
|
||||
"//shared:go_default_library",
|
||||
"//shared/interop:go_default_library",
|
||||
"//shared/slotutil:go_default_library",
|
||||
"//time/slots:go_default_library",
|
||||
"@com_github_prysmaticlabs_eth2_types//:go_default_library",
|
||||
"@com_github_sirupsen_logrus//:go_default_library",
|
||||
],
|
||||
|
@ -18,7 +18,7 @@ import (
|
||||
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/shared"
|
||||
"github.com/prysmaticlabs/prysm/shared/interop"
|
||||
"github.com/prysmaticlabs/prysm/shared/slotutil"
|
||||
"github.com/prysmaticlabs/prysm/time/slots"
|
||||
)
|
||||
|
||||
var _ shared.Service = (*Service)(nil)
|
||||
@ -92,7 +92,7 @@ func NewService(ctx context.Context, cfg *Config) *Service {
|
||||
if err != nil {
|
||||
log.Fatalf("Could not hash tree root genesis state: %v", err)
|
||||
}
|
||||
go slotutil.CountdownToGenesis(ctx, time.Unix(int64(s.cfg.GenesisTime), 0), s.cfg.NumValidators, gRoot)
|
||||
go slots.CountdownToGenesis(ctx, time.Unix(int64(s.cfg.GenesisTime), 0), s.cfg.NumValidators, gRoot)
|
||||
|
||||
if err := s.saveGenesisState(ctx, genesisTrie); err != nil {
|
||||
log.Fatalf("Could not save interop genesis state %v", err)
|
||||
|
@ -23,8 +23,8 @@ go_library(
|
||||
"//shared/aggregation/attestations:go_default_library",
|
||||
"//shared/hashutil:go_default_library",
|
||||
"//shared/params:go_default_library",
|
||||
"//shared/slotutil:go_default_library",
|
||||
"//shared/timeutils:go_default_library",
|
||||
"//time:go_default_library",
|
||||
"//time/slots:go_default_library",
|
||||
"@com_github_hashicorp_golang_lru//:go_default_library",
|
||||
"@com_github_prometheus_client_golang//prometheus:go_default_library",
|
||||
"@com_github_prometheus_client_golang//prometheus/promauto:go_default_library",
|
||||
@ -54,7 +54,7 @@ go_test(
|
||||
"//shared/testutil:go_default_library",
|
||||
"//shared/testutil/assert:go_default_library",
|
||||
"//shared/testutil/require:go_default_library",
|
||||
"//shared/timeutils:go_default_library",
|
||||
"//time:go_default_library",
|
||||
"@com_github_prysmaticlabs_go_bitfield//:go_default_library",
|
||||
"@org_golang_google_protobuf//proto:go_default_library",
|
||||
],
|
||||
|
@ -50,7 +50,7 @@ func TestAttCaches_insertSeenBitDuplicates(t *testing.T) {
|
||||
// Make sure that duplicates are not inserted, but expiration time gets updated.
|
||||
require.NoError(t, c.insertSeenBit(att1))
|
||||
require.Equal(t, 1, c.seenAtt.ItemCount())
|
||||
_, expirationTime2, ok := c.seenAtt.GetWithExpiration(string(r[:]))
|
||||
_, expirationprysmTime, ok := c.seenAtt.GetWithExpiration(string(r[:]))
|
||||
require.Equal(t, true, ok)
|
||||
require.Equal(t, true, expirationTime2.After(expirationTime1), "Expiration time is not updated")
|
||||
require.Equal(t, true, expirationprysmTime.After(expirationTime1), "Expiration time is not updated")
|
||||
}
|
||||
|
@ -10,12 +10,12 @@ import (
|
||||
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
||||
attaggregation "github.com/prysmaticlabs/prysm/shared/aggregation/attestations"
|
||||
"github.com/prysmaticlabs/prysm/shared/hashutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/slotutil"
|
||||
"github.com/prysmaticlabs/prysm/time/slots"
|
||||
"go.opencensus.io/trace"
|
||||
)
|
||||
|
||||
// Prepare attestations for fork choice three times per slot.
|
||||
var prepareForkChoiceAttsPeriod = slotutil.DivideSlotBy(3 /* times-per-slot */)
|
||||
var prepareForkChoiceAttsPeriod = slots.DivideSlotBy(3 /* times-per-slot */)
|
||||
|
||||
// This prepares fork choice attestations by running batchForkChoiceAtts
|
||||
// every prepareForkChoiceAttsPeriod.
|
||||
|
@ -5,7 +5,7 @@ import (
|
||||
|
||||
types "github.com/prysmaticlabs/eth2-types"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
"github.com/prysmaticlabs/prysm/shared/timeutils"
|
||||
prysmTime "github.com/prysmaticlabs/prysm/time"
|
||||
)
|
||||
|
||||
// pruneAttsPool prunes attestations pool on every slot interval.
|
||||
@ -69,6 +69,6 @@ func (s *Service) pruneExpiredAtts() {
|
||||
func (s *Service) expired(slot types.Slot) bool {
|
||||
expirationSlot := slot + params.BeaconConfig().SlotsPerEpoch
|
||||
expirationTime := s.genesisTime + uint64(expirationSlot.Mul(params.BeaconConfig().SecondsPerSlot))
|
||||
currentTime := uint64(timeutils.Now().Unix())
|
||||
currentTime := uint64(prysmTime.Now().Unix())
|
||||
return currentTime >= expirationTime
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
||||
"github.com/prysmaticlabs/prysm/shared/timeutils"
|
||||
prysmTime "github.com/prysmaticlabs/prysm/time"
|
||||
)
|
||||
|
||||
func TestPruneExpired_Ticker(t *testing.T) {
|
||||
@ -44,7 +44,7 @@ func TestPruneExpired_Ticker(t *testing.T) {
|
||||
require.NoError(t, s.cfg.Pool.SaveBlockAttestations(atts))
|
||||
|
||||
// Rewind back one epoch worth of time.
|
||||
s.genesisTime = uint64(timeutils.Now().Unix()) - uint64(params.BeaconConfig().SlotsPerEpoch.Mul(params.BeaconConfig().SecondsPerSlot))
|
||||
s.genesisTime = uint64(prysmTime.Now().Unix()) - uint64(params.BeaconConfig().SlotsPerEpoch.Mul(params.BeaconConfig().SecondsPerSlot))
|
||||
|
||||
go s.pruneAttsPool()
|
||||
|
||||
@ -97,7 +97,7 @@ func TestPruneExpired_PruneExpiredAtts(t *testing.T) {
|
||||
require.NoError(t, s.cfg.Pool.SaveBlockAttestations(atts))
|
||||
|
||||
// Rewind back one epoch worth of time.
|
||||
s.genesisTime = uint64(timeutils.Now().Unix()) - uint64(params.BeaconConfig().SlotsPerEpoch.Mul(params.BeaconConfig().SecondsPerSlot))
|
||||
s.genesisTime = uint64(prysmTime.Now().Unix()) - uint64(params.BeaconConfig().SlotsPerEpoch.Mul(params.BeaconConfig().SecondsPerSlot))
|
||||
|
||||
s.pruneExpiredAtts()
|
||||
// All the attestations on slot 0 should be pruned.
|
||||
@ -118,7 +118,7 @@ func TestPruneExpired_Expired(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
// Rewind back one epoch worth of time.
|
||||
s.genesisTime = uint64(timeutils.Now().Unix()) - uint64(params.BeaconConfig().SlotsPerEpoch.Mul(params.BeaconConfig().SecondsPerSlot))
|
||||
s.genesisTime = uint64(prysmTime.Now().Unix()) - uint64(params.BeaconConfig().SlotsPerEpoch.Mul(params.BeaconConfig().SecondsPerSlot))
|
||||
assert.Equal(t, true, s.expired(0), "Should be expired")
|
||||
assert.Equal(t, false, s.expired(1), "Should not be expired")
|
||||
}
|
||||
|
@ -66,9 +66,9 @@ go_library(
|
||||
"//shared/p2putils:go_default_library",
|
||||
"//shared/params:go_default_library",
|
||||
"//shared/runutil:go_default_library",
|
||||
"//shared/slotutil:go_default_library",
|
||||
"//shared/timeutils:go_default_library",
|
||||
"//shared/version:go_default_library",
|
||||
"//time:go_default_library",
|
||||
"//time/slots:go_default_library",
|
||||
"@com_github_ethereum_go_ethereum//crypto:go_default_library",
|
||||
"@com_github_ethereum_go_ethereum//p2p/discover:go_default_library",
|
||||
"@com_github_ethereum_go_ethereum//p2p/enode:go_default_library",
|
||||
@ -154,8 +154,8 @@ go_test(
|
||||
"//shared/testutil:go_default_library",
|
||||
"//shared/testutil/assert:go_default_library",
|
||||
"//shared/testutil/require:go_default_library",
|
||||
"//shared/timeutils:go_default_library",
|
||||
"//shared/version:go_default_library",
|
||||
"//time:go_default_library",
|
||||
"@com_github_ethereum_go_ethereum//crypto:go_default_library",
|
||||
"@com_github_ethereum_go_ethereum//p2p/discover:go_default_library",
|
||||
"@com_github_ethereum_go_ethereum//p2p/enode:go_default_library",
|
||||
|
@ -12,7 +12,7 @@ import (
|
||||
pb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/shared/p2putils"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
"github.com/prysmaticlabs/prysm/shared/timeutils"
|
||||
prysmTime "github.com/prysmaticlabs/prysm/time"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
@ -90,7 +90,7 @@ func addForkEntry(
|
||||
}
|
||||
currentSlot := core.SlotsSince(genesisTime)
|
||||
currentEpoch := core.SlotToEpoch(currentSlot)
|
||||
if timeutils.Now().Before(genesisTime) {
|
||||
if prysmTime.Now().Before(genesisTime) {
|
||||
currentEpoch = 0
|
||||
}
|
||||
nextForkVersion, nextForkEpoch, err := p2putils.NextForkData(currentEpoch)
|
||||
|
@ -3,14 +3,14 @@ package p2p
|
||||
import (
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
"github.com/prysmaticlabs/prysm/shared/slotutil"
|
||||
"github.com/prysmaticlabs/prysm/time/slots"
|
||||
)
|
||||
|
||||
// A background routine which listens for new and upcoming forks and
|
||||
// updates the node's discovery service to reflect any new fork version
|
||||
// changes.
|
||||
func (s *Service) forkWatcher() {
|
||||
slotTicker := slotutil.NewSlotTicker(s.genesisTime, params.BeaconConfig().SecondsPerSlot)
|
||||
slotTicker := slots.NewSlotTicker(s.genesisTime, params.BeaconConfig().SecondsPerSlot)
|
||||
for {
|
||||
select {
|
||||
case currSlot := <-slotTicker.C():
|
||||
|
@ -12,7 +12,7 @@ import (
|
||||
"github.com/libp2p/go-libp2p-core/peer"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/p2p/peers"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/p2p/peers/peerdata"
|
||||
"github.com/prysmaticlabs/prysm/shared/timeutils"
|
||||
prysmTime "github.com/prysmaticlabs/prysm/time"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
@ -104,7 +104,7 @@ func (s *Service) AddConnectionHandler(reqFunc, goodByeFunc func(ctx context.Con
|
||||
if conn.Stat().Direction == network.DirInbound {
|
||||
_, err := s.peers.ChainState(remotePeer)
|
||||
peerExists := err == nil
|
||||
currentTime := timeutils.Now()
|
||||
currentTime := prysmTime.Now()
|
||||
|
||||
// Wait for peer to initiate handshake
|
||||
time.Sleep(timeForStatus)
|
||||
|
@ -13,7 +13,7 @@ go_library(
|
||||
"//proto/prysm/v1alpha1/metadata:go_default_library",
|
||||
"//shared/params:go_default_library",
|
||||
"//shared/rand:go_default_library",
|
||||
"//shared/timeutils:go_default_library",
|
||||
"//time:go_default_library",
|
||||
"@com_github_ethereum_go_ethereum//p2p/enr:go_default_library",
|
||||
"@com_github_libp2p_go_libp2p_core//network:go_default_library",
|
||||
"@com_github_libp2p_go_libp2p_core//peer:go_default_library",
|
||||
|
@ -18,7 +18,7 @@ go_library(
|
||||
"//proto/prysm/v1alpha1:go_default_library",
|
||||
"//shared/featureconfig:go_default_library",
|
||||
"//shared/rand:go_default_library",
|
||||
"//shared/timeutils:go_default_library",
|
||||
"//time:go_default_library",
|
||||
"@com_github_libp2p_go_libp2p_core//peer:go_default_library",
|
||||
"@com_github_prysmaticlabs_eth2_types//:go_default_library",
|
||||
],
|
||||
@ -45,7 +45,7 @@ go_test(
|
||||
"//shared/rand:go_default_library",
|
||||
"//shared/testutil/assert:go_default_library",
|
||||
"//shared/testutil/require:go_default_library",
|
||||
"//shared/timeutils:go_default_library",
|
||||
"//time:go_default_library",
|
||||
"@com_github_libp2p_go_libp2p_core//network:go_default_library",
|
||||
"@com_github_libp2p_go_libp2p_core//peer:go_default_library",
|
||||
"@com_github_prysmaticlabs_eth2_types//:go_default_library",
|
||||
|
@ -11,7 +11,7 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/cmd/beacon-chain/flags"
|
||||
"github.com/prysmaticlabs/prysm/shared/featureconfig"
|
||||
"github.com/prysmaticlabs/prysm/shared/rand"
|
||||
"github.com/prysmaticlabs/prysm/shared/timeutils"
|
||||
prysmTime "github.com/prysmaticlabs/prysm/time"
|
||||
)
|
||||
|
||||
var _ Scorer = (*BlockProviderScorer)(nil)
|
||||
@ -155,7 +155,7 @@ func (s *BlockProviderScorer) touch(pid peer.ID, t ...time.Time) {
|
||||
if len(t) == 1 {
|
||||
peerData.BlockProviderUpdated = t[0]
|
||||
} else {
|
||||
peerData.BlockProviderUpdated = timeutils.Now()
|
||||
peerData.BlockProviderUpdated = prysmTime.Now()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,7 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/shared/featureconfig"
|
||||
"github.com/prysmaticlabs/prysm/shared/rand"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
|
||||
"github.com/prysmaticlabs/prysm/shared/timeutils"
|
||||
"github.com/prysmaticlabs/prysm/time"
|
||||
)
|
||||
|
||||
func TestScorers_BlockProvider_Score(t *testing.T) {
|
||||
@ -57,7 +57,7 @@ func TestScorers_BlockProvider_Score(t *testing.T) {
|
||||
batchWeight := scorer.Params().ProcessedBatchWeight
|
||||
scorer.IncrementProcessedBlocks("peer1", batchSize*3)
|
||||
assert.Equal(t, roundScore(batchWeight*3), scorer.Score("peer1"), "Unexpected score")
|
||||
scorer.Touch("peer1", timeutils.Now().Add(-1*scorer.Params().StalePeerRefreshInterval))
|
||||
scorer.Touch("peer1", time.Now().Add(-1*scorer.Params().StalePeerRefreshInterval))
|
||||
},
|
||||
check: func(scorer *scorers.BlockProviderScorer) {
|
||||
assert.Equal(t, scorer.MaxScore(), scorer.Score("peer1"), "Unexpected score")
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/p2p/peers/peerdata"
|
||||
p2ptypes "github.com/prysmaticlabs/prysm/beacon-chain/p2p/types"
|
||||
pb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/shared/timeutils"
|
||||
"github.com/prysmaticlabs/prysm/time"
|
||||
)
|
||||
|
||||
var _ Scorer = (*PeerStatusScorer)(nil)
|
||||
@ -112,7 +112,7 @@ func (s *PeerStatusScorer) SetPeerStatus(pid peer.ID, chainState *pb.Status, val
|
||||
|
||||
peerData := s.store.PeerDataGetOrCreate(pid)
|
||||
peerData.ChainState = chainState
|
||||
peerData.ChainStateLastUpdated = timeutils.Now()
|
||||
peerData.ChainStateLastUpdated = time.Now()
|
||||
peerData.ChainStateValidationError = validationError
|
||||
|
||||
// Update maximum known head slot (scores will be calculated with respect to that maximum value).
|
||||
|
@ -42,7 +42,7 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/metadata"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
"github.com/prysmaticlabs/prysm/shared/rand"
|
||||
"github.com/prysmaticlabs/prysm/shared/timeutils"
|
||||
prysmTime "github.com/prysmaticlabs/prysm/time"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -320,7 +320,7 @@ func (p *Status) ChainStateLastUpdated(pid peer.ID) (time.Time, error) {
|
||||
if peerData, ok := p.store.PeerData(pid); ok {
|
||||
return peerData.ChainStateLastUpdated, nil
|
||||
}
|
||||
return timeutils.Now(), peerdata.ErrPeerUnknown
|
||||
return prysmTime.Now(), peerdata.ErrPeerUnknown
|
||||
}
|
||||
|
||||
// IsBad states if the peer is to be considered bad (by *any* of the registered scorers).
|
||||
@ -339,7 +339,7 @@ func (p *Status) NextValidTime(pid peer.ID) (time.Time, error) {
|
||||
if peerData, ok := p.store.PeerData(pid); ok {
|
||||
return peerData.NextValidTime, nil
|
||||
}
|
||||
return timeutils.Now(), peerdata.ErrPeerUnknown
|
||||
return prysmTime.Now(), peerdata.ErrPeerUnknown
|
||||
}
|
||||
|
||||
// SetNextValidTime sets the earliest possible time we are
|
||||
|
@ -16,7 +16,7 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/shared/bytesutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/p2putils"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
|
||||
"github.com/prysmaticlabs/prysm/shared/timeutils"
|
||||
prysmTime "github.com/prysmaticlabs/prysm/time"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
@ -347,7 +347,7 @@ func TestService_MonitorsStateForkUpdates(t *testing.T) {
|
||||
n = notifier.StateFeed().Send(&feed.Event{
|
||||
Type: statefeed.Initialized,
|
||||
Data: &statefeed.InitializedData{
|
||||
StartTime: timeutils.Now(),
|
||||
StartTime: prysmTime.Now(),
|
||||
GenesisValidatorsRoot: bytesutil.PadTo([]byte("genesis"), 32),
|
||||
},
|
||||
})
|
||||
|
@ -32,7 +32,7 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/shared"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
"github.com/prysmaticlabs/prysm/shared/runutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/slotutil"
|
||||
"github.com/prysmaticlabs/prysm/time/slots"
|
||||
"github.com/sirupsen/logrus"
|
||||
"go.opencensus.io/trace"
|
||||
)
|
||||
@ -46,7 +46,7 @@ var _ shared.Service = (*Service)(nil)
|
||||
var pollingPeriod = 6 * time.Second
|
||||
|
||||
// Refresh rate of ENR set at twice per slot.
|
||||
var refreshRate = slotutil.DivideSlotBy(2)
|
||||
var refreshRate = slots.DivideSlotBy(2)
|
||||
|
||||
// maxBadResponses is the maximum number of bad responses from a peer before we stop talking to it.
|
||||
const maxBadResponses = 5
|
||||
|
@ -26,7 +26,7 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/shared/p2putils"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
||||
"github.com/prysmaticlabs/prysm/shared/timeutils"
|
||||
prysmTime "github.com/prysmaticlabs/prysm/time"
|
||||
logTest "github.com/sirupsen/logrus/hooks/test"
|
||||
)
|
||||
|
||||
@ -154,7 +154,7 @@ func TestListenForNewNodes(t *testing.T) {
|
||||
cfg.UDPPort = uint(port)
|
||||
_, pkey := createAddrAndPrivKey(t)
|
||||
ipAddr := net.ParseIP("127.0.0.1")
|
||||
genesisTime := timeutils.Now()
|
||||
genesisTime := prysmTime.Now()
|
||||
genesisValidatorsRoot := make([]byte, 32)
|
||||
s := &Service{
|
||||
cfg: cfg,
|
||||
@ -305,7 +305,7 @@ func TestService_JoinLeaveTopic(t *testing.T) {
|
||||
// initializeStateWithForkDigest sets up the state feed initialized event and returns the fork
|
||||
// digest associated with that genesis event.
|
||||
func initializeStateWithForkDigest(ctx context.Context, t *testing.T, ef *event.Feed) [4]byte {
|
||||
gt := timeutils.Now()
|
||||
gt := prysmTime.Now()
|
||||
gvr := bytesutil.PadTo([]byte("genesis validator root"), 32)
|
||||
for n := 0; n == 0; {
|
||||
if ctx.Err() != nil {
|
||||
|
@ -40,8 +40,8 @@ go_library(
|
||||
"//shared/httputils/authorizationmethod:go_default_library",
|
||||
"//shared/logutil:go_default_library",
|
||||
"//shared/params:go_default_library",
|
||||
"//shared/timeutils:go_default_library",
|
||||
"//shared/trieutil:go_default_library",
|
||||
"//time:go_default_library",
|
||||
"@com_github_ethereum_go_ethereum//:go_default_library",
|
||||
"@com_github_ethereum_go_ethereum//accounts/abi/bind:go_default_library",
|
||||
"@com_github_ethereum_go_ethereum//common:go_default_library",
|
||||
|
@ -41,8 +41,8 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/shared/httputils/authorizationmethod"
|
||||
"github.com/prysmaticlabs/prysm/shared/logutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
"github.com/prysmaticlabs/prysm/shared/timeutils"
|
||||
"github.com/prysmaticlabs/prysm/shared/trieutil"
|
||||
prysmTime "github.com/prysmaticlabs/prysm/time"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
@ -704,7 +704,7 @@ func (s *Service) handleETH1FollowDistance() {
|
||||
|
||||
// use a 5 minutes timeout for block time, because the max mining time is 278 sec (block 7208027)
|
||||
// (analyzed the time of the block from 2018-09-01 to 2019-02-13)
|
||||
fiveMinutesTimeout := timeutils.Now().Add(-5 * time.Minute)
|
||||
fiveMinutesTimeout := prysmTime.Now().Add(-5 * time.Minute)
|
||||
// check that web3 client is syncing
|
||||
if time.Unix(int64(s.latestEth1Data.BlockTime), 0).Before(fiveMinutesTimeout) {
|
||||
log.Warn("eth1 client is not syncing")
|
||||
@ -1061,7 +1061,7 @@ func dedupEndpoints(endpoints []string) []string {
|
||||
// Checks if the provided timestamp is beyond the prescribed bound from
|
||||
// the current wall clock time.
|
||||
func eth1HeadIsBehind(timestamp uint64) bool {
|
||||
timeout := timeutils.Now().Add(-eth1Threshold)
|
||||
timeout := prysmTime.Now().Add(-eth1Threshold)
|
||||
// check that web3 client is syncing
|
||||
return time.Unix(int64(timestamp), 0).Before(timeout)
|
||||
}
|
||||
|
@ -50,8 +50,8 @@ go_library(
|
||||
"//shared/pagination:go_default_library",
|
||||
"//shared/params:go_default_library",
|
||||
"//shared/sliceutil:go_default_library",
|
||||
"//shared/slotutil:go_default_library",
|
||||
"//shared/version:go_default_library",
|
||||
"//time/slots:go_default_library",
|
||||
"@com_github_patrickmn_go_cache//:go_default_library",
|
||||
"@com_github_prometheus_client_golang//prometheus:go_default_library",
|
||||
"@com_github_prometheus_client_golang//prometheus/promauto:go_default_library",
|
||||
@ -111,7 +111,7 @@ go_test(
|
||||
"//shared/testutil:go_default_library",
|
||||
"//shared/testutil/assert:go_default_library",
|
||||
"//shared/testutil/require:go_default_library",
|
||||
"//shared/timeutils:go_default_library",
|
||||
"//time:go_default_library",
|
||||
"@com_github_golang_mock//gomock:go_default_library",
|
||||
"@com_github_prysmaticlabs_eth2_types//:go_default_library",
|
||||
"@com_github_prysmaticlabs_go_bitfield//:go_default_library",
|
||||
|
@ -19,7 +19,7 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/shared/cmd"
|
||||
"github.com/prysmaticlabs/prysm/shared/pagination"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
"github.com/prysmaticlabs/prysm/shared/slotutil"
|
||||
"github.com/prysmaticlabs/prysm/time/slots"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
"google.golang.org/protobuf/types/known/emptypb"
|
||||
@ -340,8 +340,8 @@ func (bs *Server) StreamIndexedAttestations(
|
||||
// already being done by the attestation pool in the operations service.
|
||||
func (bs *Server) collectReceivedAttestations(ctx context.Context) {
|
||||
attsByRoot := make(map[[32]byte][]*ethpb.Attestation)
|
||||
twoThirdsASlot := 2 * slotutil.DivideSlotBy(3) /* 2/3 slot duration */
|
||||
ticker := slotutil.NewSlotTickerWithOffset(bs.GenesisTimeFetcher.GenesisTime(), twoThirdsASlot, params.BeaconConfig().SecondsPerSlot)
|
||||
twoThirdsASlot := 2 * slots.DivideSlotBy(3) /* 2/3 slot duration */
|
||||
ticker := slots.NewSlotTickerWithOffset(bs.GenesisTimeFetcher.GenesisTime(), twoThirdsASlot, params.BeaconConfig().SecondsPerSlot)
|
||||
for {
|
||||
select {
|
||||
case <-ticker.C():
|
||||
|
@ -18,7 +18,7 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
||||
"github.com/prysmaticlabs/prysm/shared/timeutils"
|
||||
prysmTime "github.com/prysmaticlabs/prysm/time"
|
||||
"google.golang.org/protobuf/proto"
|
||||
"gopkg.in/d4l3k/messagediff.v1"
|
||||
)
|
||||
@ -33,7 +33,7 @@ func TestServer_ListBeaconCommittees_CurrentEpoch(t *testing.T) {
|
||||
|
||||
offset := int64(headState.Slot().Mul(params.BeaconConfig().SecondsPerSlot))
|
||||
m := &mock.ChainService{
|
||||
Genesis: timeutils.Now().Add(time.Duration(-1*offset) * time.Second),
|
||||
Genesis: prysmTime.Now().Add(time.Duration(-1*offset) * time.Second),
|
||||
}
|
||||
bs := &Server{
|
||||
HeadFetcher: m,
|
||||
@ -95,7 +95,7 @@ func TestServer_ListBeaconCommittees_PreviousEpoch(t *testing.T) {
|
||||
offset := int64(headState.Slot().Mul(params.BeaconConfig().SecondsPerSlot))
|
||||
m := &mock.ChainService{
|
||||
State: headState,
|
||||
Genesis: timeutils.Now().Add(time.Duration(-1*offset) * time.Second),
|
||||
Genesis: prysmTime.Now().Add(time.Duration(-1*offset) * time.Second),
|
||||
}
|
||||
bs := &Server{
|
||||
HeadFetcher: m,
|
||||
@ -149,7 +149,7 @@ func TestRetrieveCommitteesForRoot(t *testing.T) {
|
||||
|
||||
offset := int64(headState.Slot().Mul(params.BeaconConfig().SecondsPerSlot))
|
||||
m := &mock.ChainService{
|
||||
Genesis: timeutils.Now().Add(time.Duration(-1*offset) * time.Second),
|
||||
Genesis: prysmTime.Now().Add(time.Duration(-1*offset) * time.Second),
|
||||
}
|
||||
bs := &Server{
|
||||
HeadFetcher: m,
|
||||
|
@ -29,7 +29,7 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
||||
"github.com/prysmaticlabs/prysm/shared/timeutils"
|
||||
prysmTime "github.com/prysmaticlabs/prysm/time"
|
||||
"google.golang.org/protobuf/proto"
|
||||
"google.golang.org/protobuf/types/known/emptypb"
|
||||
)
|
||||
@ -1571,7 +1571,7 @@ func TestServer_GetValidatorParticipation_CurrentAndPrevEpoch(t *testing.T) {
|
||||
HeadFetcher: m,
|
||||
StateGen: stategen.New(beaconDB),
|
||||
GenesisTimeFetcher: &mock.ChainService{
|
||||
Genesis: timeutils.Now().Add(time.Duration(-1*offset) * time.Second),
|
||||
Genesis: prysmTime.Now().Add(time.Duration(-1*offset) * time.Second),
|
||||
},
|
||||
CanonicalFetcher: &mock.ChainService{
|
||||
CanonicalRoots: map[[32]byte]bool{
|
||||
@ -1649,7 +1649,7 @@ func TestServer_GetValidatorParticipation_OrphanedUntilGenesis(t *testing.T) {
|
||||
HeadFetcher: m,
|
||||
StateGen: stategen.New(beaconDB),
|
||||
GenesisTimeFetcher: &mock.ChainService{
|
||||
Genesis: timeutils.Now().Add(time.Duration(-1*offset) * time.Second),
|
||||
Genesis: prysmTime.Now().Add(time.Duration(-1*offset) * time.Second),
|
||||
},
|
||||
CanonicalFetcher: &mock.ChainService{
|
||||
CanonicalRoots: map[[32]byte]bool{
|
||||
@ -1714,7 +1714,7 @@ func TestServer_GetValidatorParticipation_CurrentAndPrevEpochAltair(t *testing.T
|
||||
HeadFetcher: m,
|
||||
StateGen: stategen.New(beaconDB),
|
||||
GenesisTimeFetcher: &mock.ChainService{
|
||||
Genesis: timeutils.Now().Add(time.Duration(-1*offset) * time.Second),
|
||||
Genesis: prysmTime.Now().Add(time.Duration(-1*offset) * time.Second),
|
||||
},
|
||||
CanonicalFetcher: &mock.ChainService{
|
||||
CanonicalRoots: map[[32]byte]bool{
|
||||
|
@ -58,10 +58,10 @@ go_library(
|
||||
"//shared/p2putils:go_default_library",
|
||||
"//shared/params:go_default_library",
|
||||
"//shared/rand:go_default_library",
|
||||
"//shared/slotutil:go_default_library",
|
||||
"//shared/timeutils:go_default_library",
|
||||
"//shared/trieutil:go_default_library",
|
||||
"//shared/version:go_default_library",
|
||||
"//time:go_default_library",
|
||||
"//time/slots:go_default_library",
|
||||
"@com_github_ferranbt_fastssz//:go_default_library",
|
||||
"@com_github_pkg_errors//:go_default_library",
|
||||
"@com_github_prysmaticlabs_eth2_types//:go_default_library",
|
||||
@ -132,8 +132,8 @@ go_test(
|
||||
"//shared/testutil:go_default_library",
|
||||
"//shared/testutil/assert:go_default_library",
|
||||
"//shared/testutil/require:go_default_library",
|
||||
"//shared/timeutils:go_default_library",
|
||||
"//shared/trieutil:go_default_library",
|
||||
"//time:go_default_library",
|
||||
"@com_github_golang_mock//gomock:go_default_library",
|
||||
"@com_github_prysmaticlabs_eth2_types//:go_default_library",
|
||||
"@com_github_prysmaticlabs_go_bitfield//:go_default_library",
|
||||
|
@ -18,8 +18,8 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/shared/bytesutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
"github.com/prysmaticlabs/prysm/shared/rand"
|
||||
"github.com/prysmaticlabs/prysm/shared/slotutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/timeutils"
|
||||
prysmTime "github.com/prysmaticlabs/prysm/time"
|
||||
"github.com/prysmaticlabs/prysm/time/slots"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
@ -48,8 +48,8 @@ func (vs *Server) StreamDuties(req *ethpb.DutiesRequest, stream ethpb.BeaconNode
|
||||
return status.Error(codes.Unavailable, "genesis time is not set")
|
||||
}
|
||||
var currentEpoch types.Epoch
|
||||
if genesisTime.Before(timeutils.Now()) {
|
||||
currentEpoch = slotutil.EpochsSinceGenesis(vs.TimeFetcher.GenesisTime())
|
||||
if genesisTime.Before(prysmTime.Now()) {
|
||||
currentEpoch = slots.EpochsSinceGenesis(vs.TimeFetcher.GenesisTime())
|
||||
}
|
||||
req.Epoch = currentEpoch
|
||||
res, err := vs.duties(stream.Context(), req)
|
||||
@ -66,7 +66,7 @@ func (vs *Server) StreamDuties(req *ethpb.DutiesRequest, stream ethpb.BeaconNode
|
||||
defer stateSub.Unsubscribe()
|
||||
|
||||
secondsPerEpoch := params.BeaconConfig().SecondsPerSlot * uint64(params.BeaconConfig().SlotsPerEpoch)
|
||||
epochTicker := slotutil.NewSlotTicker(vs.TimeFetcher.GenesisTime(), secondsPerEpoch)
|
||||
epochTicker := slots.NewSlotTicker(vs.TimeFetcher.GenesisTime(), secondsPerEpoch)
|
||||
for {
|
||||
select {
|
||||
// Ticks every epoch to submit assignments to connected validator clients.
|
||||
@ -82,7 +82,7 @@ func (vs *Server) StreamDuties(req *ethpb.DutiesRequest, stream ethpb.BeaconNode
|
||||
case ev := <-stateChannel:
|
||||
// If a reorg occurred, we recompute duties for the connected validator clients
|
||||
// and send another response over the server stream right away.
|
||||
currentEpoch = slotutil.EpochsSinceGenesis(vs.TimeFetcher.GenesisTime())
|
||||
currentEpoch = slots.EpochsSinceGenesis(vs.TimeFetcher.GenesisTime())
|
||||
if ev.Type == statefeed.Reorg {
|
||||
data, ok := ev.Data.(*ethpbv1.EventChainReorg)
|
||||
if !ok {
|
||||
@ -235,7 +235,7 @@ func (vs *Server) AssignValidatorToSubnet(pubkey []byte, status ethpb.ValidatorS
|
||||
}
|
||||
|
||||
_, ok, expTime := cache.SubnetIDs.GetPersistentSubnets(pubkey)
|
||||
if ok && expTime.After(timeutils.Now()) {
|
||||
if ok && expTime.After(prysmTime.Now()) {
|
||||
return
|
||||
}
|
||||
epochDuration := time.Duration(params.BeaconConfig().SlotsPerEpoch.Mul(params.BeaconConfig().SecondsPerSlot))
|
||||
@ -284,7 +284,7 @@ func registerSyncSubnet(currEpoch types.Epoch, syncPeriod uint64, pubkey []byte,
|
||||
currPeriod := core.SyncCommitteePeriod(currEpoch)
|
||||
endEpoch := startEpoch + params.BeaconConfig().EpochsPerSyncCommitteePeriod
|
||||
_, _, ok, expTime := cache.SyncSubnetIDs.GetSyncCommitteeSubnets(pubkey, startEpoch)
|
||||
if ok && expTime.After(timeutils.Now()) {
|
||||
if ok && expTime.After(prysmTime.Now()) {
|
||||
return
|
||||
}
|
||||
firstValidEpoch, err := startEpoch.SafeSub(params.BeaconConfig().SyncCommitteeSubnetCount)
|
||||
|
@ -25,7 +25,7 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
||||
"github.com/prysmaticlabs/prysm/shared/timeutils"
|
||||
prysmTime "github.com/prysmaticlabs/prysm/time"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
@ -463,7 +463,7 @@ func TestGetAttestationData_SucceedsInFirstEpoch(t *testing.T) {
|
||||
FinalizationFetcher: &mock.ChainService{
|
||||
CurrentJustifiedCheckPoint: beaconState.CurrentJustifiedCheckpoint(),
|
||||
},
|
||||
TimeFetcher: &mock.ChainService{Genesis: timeutils.Now().Add(time.Duration(-1*offset) * time.Second)},
|
||||
TimeFetcher: &mock.ChainService{Genesis: prysmTime.Now().Add(time.Duration(-1*offset) * time.Second)},
|
||||
StateNotifier: chainService.StateNotifier(),
|
||||
}
|
||||
|
||||
|
@ -92,10 +92,10 @@ go_library(
|
||||
"//shared/rand:go_default_library",
|
||||
"//shared/runutil:go_default_library",
|
||||
"//shared/sliceutil:go_default_library",
|
||||
"//shared/slotutil:go_default_library",
|
||||
"//shared/sszutil:go_default_library",
|
||||
"//shared/timeutils:go_default_library",
|
||||
"//shared/version:go_default_library",
|
||||
"//time:go_default_library",
|
||||
"//time/slots:go_default_library",
|
||||
"@com_github_ferranbt_fastssz//:go_default_library",
|
||||
"@com_github_hashicorp_golang_lru//:go_default_library",
|
||||
"@com_github_kevinms_leakybucket_go//:go_default_library",
|
||||
@ -197,7 +197,7 @@ go_test(
|
||||
"//shared/testutil:go_default_library",
|
||||
"//shared/testutil/assert:go_default_library",
|
||||
"//shared/testutil/require:go_default_library",
|
||||
"//shared/timeutils:go_default_library",
|
||||
"//time:go_default_library",
|
||||
"@com_github_d4l3k_messagediff//:go_default_library",
|
||||
"@com_github_ethereum_go_ethereum//p2p/enr:go_default_library",
|
||||
"@com_github_golang_snappy//:go_default_library",
|
||||
|
@ -7,13 +7,13 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/p2p"
|
||||
"github.com/prysmaticlabs/prysm/shared/p2putils"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
"github.com/prysmaticlabs/prysm/shared/slotutil"
|
||||
"github.com/prysmaticlabs/prysm/time/slots"
|
||||
)
|
||||
|
||||
// Is a background routine that observes for new incoming forks. Depending on the epoch
|
||||
// it will be in charge of subscribing/unsubscribing the relevant topics at the fork boundaries.
|
||||
func (s *Service) forkWatcher() {
|
||||
slotTicker := slotutil.NewSlotTicker(s.cfg.Chain.GenesisTime(), params.BeaconConfig().SecondsPerSlot)
|
||||
slotTicker := slots.NewSlotTicker(s.cfg.Chain.GenesisTime(), params.BeaconConfig().SecondsPerSlot)
|
||||
for {
|
||||
select {
|
||||
// In the event of a node restart, we will still end up subscribing to the correct
|
||||
|
@ -36,7 +36,7 @@ go_library(
|
||||
"//shared/mathutil:go_default_library",
|
||||
"//shared/params:go_default_library",
|
||||
"//shared/rand:go_default_library",
|
||||
"//shared/timeutils:go_default_library",
|
||||
"//time:go_default_library",
|
||||
"@com_github_kevinms_leakybucket_go//:go_default_library",
|
||||
"@com_github_libp2p_go_libp2p_core//peer:go_default_library",
|
||||
"@com_github_paulbellamy_ratecounter//:go_default_library",
|
||||
@ -82,7 +82,7 @@ go_test(
|
||||
"//shared/testutil:go_default_library",
|
||||
"//shared/testutil/assert:go_default_library",
|
||||
"//shared/testutil/require:go_default_library",
|
||||
"//shared/timeutils:go_default_library",
|
||||
"//time:go_default_library",
|
||||
"@com_github_ethereum_go_ethereum//p2p/enr:go_default_library",
|
||||
"@com_github_kevinms_leakybucket_go//:go_default_library",
|
||||
"@com_github_libp2p_go_libp2p_core//:go_default_library",
|
||||
@ -133,7 +133,7 @@ go_test(
|
||||
"//shared/testutil:go_default_library",
|
||||
"//shared/testutil/assert:go_default_library",
|
||||
"//shared/testutil/require:go_default_library",
|
||||
"//shared/timeutils:go_default_library",
|
||||
"//time:go_default_library",
|
||||
"@com_github_ethereum_go_ethereum//p2p/enr:go_default_library",
|
||||
"@com_github_kevinms_leakybucket_go//:go_default_library",
|
||||
"@com_github_libp2p_go_libp2p_core//:go_default_library",
|
||||
|
@ -12,7 +12,7 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/cmd/beacon-chain/flags"
|
||||
"github.com/prysmaticlabs/prysm/shared/mathutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
"github.com/prysmaticlabs/prysm/shared/timeutils"
|
||||
prysmTime "github.com/prysmaticlabs/prysm/time"
|
||||
"github.com/sirupsen/logrus"
|
||||
"go.opencensus.io/trace"
|
||||
)
|
||||
@ -22,12 +22,12 @@ func (f *blocksFetcher) peerLock(pid peer.ID) *peerLock {
|
||||
f.Lock()
|
||||
defer f.Unlock()
|
||||
if lock, ok := f.peerLocks[pid]; ok && lock != nil {
|
||||
lock.accessed = timeutils.Now()
|
||||
lock.accessed = prysmTime.Now()
|
||||
return lock
|
||||
}
|
||||
f.peerLocks[pid] = &peerLock{
|
||||
Mutex: sync.Mutex{},
|
||||
accessed: timeutils.Now(),
|
||||
accessed: prysmTime.Now(),
|
||||
}
|
||||
return f.peerLocks[pid]
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/cmd/beacon-chain/flags"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
||||
"github.com/prysmaticlabs/prysm/shared/timeutils"
|
||||
prysmTime "github.com/prysmaticlabs/prysm/time"
|
||||
)
|
||||
|
||||
func TestBlocksFetcher_selectFailOverPeer(t *testing.T) {
|
||||
@ -324,29 +324,29 @@ func TestBlocksFetcher_removeStalePeerLocks(t *testing.T) {
|
||||
peersIn: []peerData{
|
||||
{
|
||||
peerID: "a",
|
||||
accessed: timeutils.Now(),
|
||||
accessed: prysmTime.Now(),
|
||||
},
|
||||
{
|
||||
peerID: "b",
|
||||
accessed: timeutils.Now(),
|
||||
accessed: prysmTime.Now(),
|
||||
},
|
||||
{
|
||||
peerID: "c",
|
||||
accessed: timeutils.Now(),
|
||||
accessed: prysmTime.Now(),
|
||||
},
|
||||
},
|
||||
peersOut: []peerData{
|
||||
{
|
||||
peerID: "a",
|
||||
accessed: timeutils.Now(),
|
||||
accessed: prysmTime.Now(),
|
||||
},
|
||||
{
|
||||
peerID: "b",
|
||||
accessed: timeutils.Now(),
|
||||
accessed: prysmTime.Now(),
|
||||
},
|
||||
{
|
||||
peerID: "c",
|
||||
accessed: timeutils.Now(),
|
||||
accessed: prysmTime.Now(),
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -356,25 +356,25 @@ func TestBlocksFetcher_removeStalePeerLocks(t *testing.T) {
|
||||
peersIn: []peerData{
|
||||
{
|
||||
peerID: "a",
|
||||
accessed: timeutils.Now(),
|
||||
accessed: prysmTime.Now(),
|
||||
},
|
||||
{
|
||||
peerID: "b",
|
||||
accessed: timeutils.Now().Add(-peerLockMaxAge),
|
||||
accessed: prysmTime.Now().Add(-peerLockMaxAge),
|
||||
},
|
||||
{
|
||||
peerID: "c",
|
||||
accessed: timeutils.Now(),
|
||||
accessed: prysmTime.Now(),
|
||||
},
|
||||
},
|
||||
peersOut: []peerData{
|
||||
{
|
||||
peerID: "a",
|
||||
accessed: timeutils.Now(),
|
||||
accessed: prysmTime.Now(),
|
||||
},
|
||||
{
|
||||
peerID: "c",
|
||||
accessed: timeutils.Now(),
|
||||
accessed: prysmTime.Now(),
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -384,15 +384,15 @@ func TestBlocksFetcher_removeStalePeerLocks(t *testing.T) {
|
||||
peersIn: []peerData{
|
||||
{
|
||||
peerID: "a",
|
||||
accessed: timeutils.Now().Add(-peerLockMaxAge),
|
||||
accessed: prysmTime.Now().Add(-peerLockMaxAge),
|
||||
},
|
||||
{
|
||||
peerID: "b",
|
||||
accessed: timeutils.Now().Add(-peerLockMaxAge),
|
||||
accessed: prysmTime.Now().Add(-peerLockMaxAge),
|
||||
},
|
||||
{
|
||||
peerID: "c",
|
||||
accessed: timeutils.Now().Add(-peerLockMaxAge),
|
||||
accessed: prysmTime.Now().Add(-peerLockMaxAge),
|
||||
},
|
||||
},
|
||||
peersOut: []peerData{},
|
||||
|
@ -24,7 +24,7 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
||||
"github.com/prysmaticlabs/prysm/shared/timeutils"
|
||||
prysmTime "github.com/prysmaticlabs/prysm/time"
|
||||
logTest "github.com/sirupsen/logrus/hooks/test"
|
||||
)
|
||||
|
||||
@ -745,7 +745,7 @@ func TestBlocksQueue_onProcessSkippedEvent(t *testing.T) {
|
||||
|
||||
queue.smm.addStateMachine(256)
|
||||
// Machine is not skipped for too long. Do not mark as new just yet.
|
||||
queue.smm.machines[256].updated = timeutils.Now().Add(-1 * (skippedMachineTimeout / 2))
|
||||
queue.smm.machines[256].updated = prysmTime.Now().Add(-1 * (skippedMachineTimeout / 2))
|
||||
queue.smm.machines[256].state = stateSkipped
|
||||
queue.smm.addStateMachine(320)
|
||||
queue.smm.machines[320].state = stateScheduled
|
||||
@ -764,7 +764,7 @@ func TestBlocksQueue_onProcessSkippedEvent(t *testing.T) {
|
||||
|
||||
queue.smm.addStateMachine(256)
|
||||
// Machine is skipped for too long. Reset.
|
||||
queue.smm.machines[256].updated = timeutils.Now().Add(-1 * skippedMachineTimeout)
|
||||
queue.smm.machines[256].updated = prysmTime.Now().Add(-1 * skippedMachineTimeout)
|
||||
queue.smm.machines[256].state = stateSkipped
|
||||
queue.smm.addStateMachine(320)
|
||||
queue.smm.machines[320].state = stateScheduled
|
||||
@ -1001,7 +1001,7 @@ func TestBlocksQueue_onCheckStaleEvent(t *testing.T) {
|
||||
handlerFn := queue.onCheckStaleEvent(ctx)
|
||||
updatedState, err := handlerFn(&stateMachine{
|
||||
state: stateSent,
|
||||
updated: timeutils.Now().Add(-staleEpochTimeout / 2),
|
||||
updated: prysmTime.Now().Add(-staleEpochTimeout / 2),
|
||||
}, nil)
|
||||
// State should not change, as machine is not yet stale.
|
||||
assert.NoError(t, err)
|
||||
@ -1017,7 +1017,7 @@ func TestBlocksQueue_onCheckStaleEvent(t *testing.T) {
|
||||
handlerFn := queue.onCheckStaleEvent(ctx)
|
||||
updatedState, err := handlerFn(&stateMachine{
|
||||
state: stateSent,
|
||||
updated: timeutils.Now().Add(-staleEpochTimeout),
|
||||
updated: prysmTime.Now().Add(-staleEpochTimeout),
|
||||
}, nil)
|
||||
// State should change, as machine is stale.
|
||||
assert.NoError(t, err)
|
||||
|
@ -10,7 +10,7 @@ import (
|
||||
types "github.com/prysmaticlabs/eth2-types"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core"
|
||||
"github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/block"
|
||||
"github.com/prysmaticlabs/prysm/shared/timeutils"
|
||||
prysmTime "github.com/prysmaticlabs/prysm/time"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -79,7 +79,7 @@ func (smm *stateMachineManager) addStateMachine(startSlot types.Slot) *stateMach
|
||||
start: startSlot,
|
||||
state: stateNew,
|
||||
blocks: []block.SignedBeaconBlock{},
|
||||
updated: timeutils.Now(),
|
||||
updated: prysmTime.Now(),
|
||||
}
|
||||
smm.recalculateMachineAttribs()
|
||||
return smm.machines[startSlot]
|
||||
@ -158,7 +158,7 @@ func (m *stateMachine) setState(name stateID) {
|
||||
return
|
||||
}
|
||||
m.state = name
|
||||
m.updated = timeutils.Now()
|
||||
m.updated = prysmTime.Now()
|
||||
}
|
||||
|
||||
// trigger invokes the event handler on a given state machine.
|
||||
|
@ -32,7 +32,7 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
||||
"github.com/prysmaticlabs/prysm/shared/timeutils"
|
||||
prysmTime "github.com/prysmaticlabs/prysm/time"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
@ -103,7 +103,7 @@ func initializeTestServices(t *testing.T, slots []types.Slot, peers []*peerData)
|
||||
|
||||
// makeGenesisTime where now is the current slot.
|
||||
func makeGenesisTime(currentSlot types.Slot) time.Time {
|
||||
return timeutils.Now().Add(-1 * time.Second * time.Duration(currentSlot) * time.Duration(params.BeaconConfig().SecondsPerSlot))
|
||||
return prysmTime.Now().Add(-1 * time.Second * time.Duration(currentSlot) * time.Duration(params.BeaconConfig().SecondsPerSlot))
|
||||
}
|
||||
|
||||
// sanity test on helper function
|
||||
|
@ -20,7 +20,7 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/shared"
|
||||
"github.com/prysmaticlabs/prysm/shared/abool"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
"github.com/prysmaticlabs/prysm/shared/timeutils"
|
||||
prysmTime "github.com/prysmaticlabs/prysm/time"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
@ -82,7 +82,7 @@ func (s *Service) Start() {
|
||||
log.WithField("genesisTime", genesis).Info("Due to Sync Being Disabled, entering regular sync immediately.")
|
||||
return
|
||||
}
|
||||
if genesis.After(timeutils.Now()) {
|
||||
if genesis.After(prysmTime.Now()) {
|
||||
s.markSynced(genesis)
|
||||
log.WithField("genesisTime", genesis).Info("Genesis time has not arrived - not syncing")
|
||||
return
|
||||
|
@ -14,13 +14,13 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
"github.com/prysmaticlabs/prysm/shared/rand"
|
||||
"github.com/prysmaticlabs/prysm/shared/runutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/slotutil"
|
||||
"github.com/prysmaticlabs/prysm/time/slots"
|
||||
"github.com/sirupsen/logrus"
|
||||
"go.opencensus.io/trace"
|
||||
)
|
||||
|
||||
// This defines how often a node cleans up and processes pending attestations in the queue.
|
||||
var processPendingAttsPeriod = slotutil.DivideSlotBy(2 /* twice per slot */)
|
||||
var processPendingAttsPeriod = slots.DivideSlotBy(2 /* twice per slot */)
|
||||
|
||||
// This processes pending attestation queues on every `processPendingAttsPeriod`.
|
||||
func (s *Service) processPendingAttsQueue() {
|
||||
|
@ -27,7 +27,7 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
||||
"github.com/prysmaticlabs/prysm/shared/timeutils"
|
||||
prysmTime "github.com/prysmaticlabs/prysm/time"
|
||||
logTest "github.com/sirupsen/logrus/hooks/test"
|
||||
)
|
||||
|
||||
@ -43,7 +43,7 @@ func TestProcessPendingAtts_NoBlockRequestBlock(t *testing.T) {
|
||||
p1.Peers().SetChainState(p2.PeerID(), &pb.Status{})
|
||||
|
||||
r := &Service{
|
||||
cfg: &Config{P2P: p1, DB: db, Chain: &mock.ChainService{Genesis: timeutils.Now(), FinalizedCheckPoint: ðpb.Checkpoint{}}},
|
||||
cfg: &Config{P2P: p1, DB: db, Chain: &mock.ChainService{Genesis: prysmTime.Now(), FinalizedCheckPoint: ðpb.Checkpoint{}}},
|
||||
blkRootToPendingAtts: make(map[[32]byte][]*ethpb.SignedAggregateAttestationAndProof),
|
||||
chainStarted: abool.New(),
|
||||
}
|
||||
@ -150,7 +150,7 @@ func TestProcessPendingAtts_NoBroadcastWithBadSignature(t *testing.T) {
|
||||
cfg: &Config{
|
||||
P2P: p1,
|
||||
DB: db,
|
||||
Chain: &mock.ChainService{State: s, Genesis: timeutils.Now(), FinalizedCheckPoint: ðpb.Checkpoint{Root: make([]byte, 32)}},
|
||||
Chain: &mock.ChainService{State: s, Genesis: prysmTime.Now(), FinalizedCheckPoint: ðpb.Checkpoint{Root: make([]byte, 32)}},
|
||||
AttPool: attestations.NewPool(),
|
||||
},
|
||||
blkRootToPendingAtts: make(map[[32]byte][]*ethpb.SignedAggregateAttestationAndProof),
|
||||
|
@ -18,14 +18,14 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
"github.com/prysmaticlabs/prysm/shared/rand"
|
||||
"github.com/prysmaticlabs/prysm/shared/runutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/slotutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/sszutil"
|
||||
"github.com/prysmaticlabs/prysm/time/slots"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/trailofbits/go-mutexasserts"
|
||||
"go.opencensus.io/trace"
|
||||
)
|
||||
|
||||
var processPendingBlocksPeriod = slotutil.DivideSlotBy(3 /* times per slot */)
|
||||
var processPendingBlocksPeriod = slots.DivideSlotBy(3 /* times per slot */)
|
||||
|
||||
const maxPeerRequest = 50
|
||||
const numOfTries = 5
|
||||
|
@ -15,7 +15,7 @@ import (
|
||||
p2ptypes "github.com/prysmaticlabs/prysm/beacon-chain/p2p/types"
|
||||
"github.com/prysmaticlabs/prysm/monitoring/tracing"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
"github.com/prysmaticlabs/prysm/shared/timeutils"
|
||||
"github.com/prysmaticlabs/prysm/time"
|
||||
"go.opencensus.io/trace"
|
||||
)
|
||||
|
||||
@ -150,7 +150,7 @@ func (s *Service) registerRPC(baseTopic string, handle rpcHandler) {
|
||||
}
|
||||
s.rateLimiter.addRawStream(stream)
|
||||
|
||||
if err := stream.SetReadDeadline(timeutils.Now().Add(ttfbTimeout)); err != nil {
|
||||
if err := stream.SetReadDeadline(time.Now().Add(ttfbTimeout)); err != nil {
|
||||
log.WithError(err).Debug("Could not set stream read deadline")
|
||||
return
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/p2p"
|
||||
p2ptypes "github.com/prysmaticlabs/prysm/beacon-chain/p2p/types"
|
||||
"github.com/prysmaticlabs/prysm/shared/timeutils"
|
||||
"github.com/prysmaticlabs/prysm/time"
|
||||
)
|
||||
|
||||
// pingHandler reads the incoming ping rpc message from the peer.
|
||||
@ -86,7 +86,7 @@ func (s *Service) sendPingRequest(ctx context.Context, id peer.ID) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
currentTime := timeutils.Now()
|
||||
currentTime := time.Now()
|
||||
defer closeStream(stream, log)
|
||||
|
||||
code, errMsg, err := ReadStatusCode(stream, s.cfg.P2P.Encoding())
|
||||
@ -94,7 +94,7 @@ func (s *Service) sendPingRequest(ctx context.Context, id peer.ID) error {
|
||||
return err
|
||||
}
|
||||
// Records the latency of the ping request for that peer.
|
||||
s.cfg.P2P.Host().Peerstore().RecordLatency(id, timeutils.Now().Sub(currentTime))
|
||||
s.cfg.P2P.Host().Peerstore().RecordLatency(id, time.Now().Sub(currentTime))
|
||||
|
||||
if code != 0 {
|
||||
s.cfg.P2P.Peers().Scorers().BadResponsesScorer().Increment(stream.Conn().RemotePeer())
|
||||
|
@ -20,8 +20,8 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/shared/bytesutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
"github.com/prysmaticlabs/prysm/shared/runutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/slotutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/timeutils"
|
||||
prysmTime "github.com/prysmaticlabs/prysm/time"
|
||||
"github.com/prysmaticlabs/prysm/time/slots"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
@ -56,7 +56,7 @@ func (s *Service) maintainPeerStatuses() {
|
||||
// Peer has vanished; nothing to do.
|
||||
return
|
||||
}
|
||||
if timeutils.Now().After(lastUpdated.Add(interval)) {
|
||||
if prysmTime.Now().After(lastUpdated.Add(interval)) {
|
||||
if err := s.reValidatePeer(s.ctx, id); err != nil {
|
||||
log.WithField("peer", id).WithError(err).Debug("Could not revalidate peer")
|
||||
s.cfg.P2P.Peers().Scorers().BadResponsesScorer().Increment(id)
|
||||
@ -286,7 +286,7 @@ func (s *Service) validateStatusMessage(ctx context.Context, msg *pb.Status) err
|
||||
}
|
||||
genesis := s.cfg.Chain.GenesisTime()
|
||||
finalizedEpoch := s.cfg.Chain.FinalizedCheckpt().Epoch
|
||||
maxEpoch := slotutil.EpochsSinceGenesis(genesis)
|
||||
maxEpoch := slots.EpochsSinceGenesis(genesis)
|
||||
// It would take a minimum of 2 epochs to finalize a
|
||||
// previous epoch
|
||||
maxFinalizedEpoch := types.Epoch(0)
|
||||
|
@ -31,7 +31,7 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
||||
"github.com/prysmaticlabs/prysm/shared/timeutils"
|
||||
prysmTime "github.com/prysmaticlabs/prysm/time"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
@ -874,7 +874,7 @@ func TestShouldResync(t *testing.T) {
|
||||
name: "genesis epoch should not resync when syncing is true",
|
||||
args: args{
|
||||
headSlot: 31,
|
||||
genesis: timeutils.Now(),
|
||||
genesis: prysmTime.Now(),
|
||||
syncing: true,
|
||||
},
|
||||
want: false,
|
||||
@ -883,7 +883,7 @@ func TestShouldResync(t *testing.T) {
|
||||
name: "genesis epoch should not resync when syncing is false",
|
||||
args: args{
|
||||
headSlot: 31,
|
||||
genesis: timeutils.Now(),
|
||||
genesis: prysmTime.Now(),
|
||||
syncing: false,
|
||||
},
|
||||
want: false,
|
||||
@ -892,7 +892,7 @@ func TestShouldResync(t *testing.T) {
|
||||
name: "two epochs behind, resync ok",
|
||||
args: args{
|
||||
headSlot: 31,
|
||||
genesis: timeutils.Now().Add(-1 * 96 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second),
|
||||
genesis: prysmTime.Now().Add(-1 * 96 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second),
|
||||
syncing: false,
|
||||
},
|
||||
want: true,
|
||||
@ -901,7 +901,7 @@ func TestShouldResync(t *testing.T) {
|
||||
name: "two epochs behind, already syncing",
|
||||
args: args{
|
||||
headSlot: 31,
|
||||
genesis: timeutils.Now().Add(-1 * 96 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second),
|
||||
genesis: prysmTime.Now().Add(-1 * 96 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second),
|
||||
syncing: true,
|
||||
},
|
||||
want: false,
|
||||
|
@ -35,8 +35,8 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/shared/abool"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
"github.com/prysmaticlabs/prysm/shared/runutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/slotutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/timeutils"
|
||||
prysmTime "github.com/prysmaticlabs/prysm/time"
|
||||
"github.com/prysmaticlabs/prysm/time/slots"
|
||||
)
|
||||
|
||||
var _ shared.Service = (*Service)(nil)
|
||||
@ -56,7 +56,7 @@ var (
|
||||
// Seconds in one epoch.
|
||||
pendingBlockExpTime = time.Duration(params.BeaconConfig().SlotsPerEpoch.Mul(params.BeaconConfig().SecondsPerSlot)) * time.Second
|
||||
// time to allow processing early blocks.
|
||||
earlyBlockProcessingTolerance = slotutil.MultiplySlotBy(2)
|
||||
earlyBlockProcessingTolerance = slots.MultiplySlotBy(2)
|
||||
// time to allow processing early attestations.
|
||||
earlyAttestationProcessingTolerance = params.BeaconNetworkConfig().MaximumGossipClockDisparity
|
||||
errWrongMessage = errors.New("wrong pubsub message")
|
||||
@ -239,8 +239,8 @@ func (s *Service) registerHandlers() {
|
||||
s.registerRPCHandlers()
|
||||
// Wait for chainstart in separate routine.
|
||||
go func() {
|
||||
if startTime.After(timeutils.Now()) {
|
||||
time.Sleep(timeutils.Until(startTime))
|
||||
if startTime.After(prysmTime.Now()) {
|
||||
time.Sleep(prysmTime.Until(startTime))
|
||||
}
|
||||
log.WithField("starttime", startTime).Debug("Chain started in sync service")
|
||||
s.markForChainStart()
|
||||
|
@ -22,7 +22,7 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/shared/p2putils"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
"github.com/prysmaticlabs/prysm/shared/sliceutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/slotutil"
|
||||
"github.com/prysmaticlabs/prysm/time/slots"
|
||||
"go.opencensus.io/trace"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
@ -280,7 +280,7 @@ func (s *Service) subscribeStaticWithSubnets(topic string, validator pubsub.Vali
|
||||
s.subscribeWithBase(s.addDigestAndIndexToTopic(topic, digest, i), validator, handle)
|
||||
}
|
||||
genesis := s.cfg.Chain.GenesisTime()
|
||||
ticker := slotutil.NewSlotTicker(genesis, params.BeaconConfig().SecondsPerSlot)
|
||||
ticker := slots.NewSlotTicker(genesis, params.BeaconConfig().SecondsPerSlot)
|
||||
|
||||
go func() {
|
||||
for {
|
||||
@ -350,7 +350,7 @@ func (s *Service) subscribeDynamicWithSubnets(
|
||||
}
|
||||
subscriptions := make(map[uint64]*pubsub.Subscription, params.BeaconConfig().MaxCommitteesPerSlot)
|
||||
genesis := s.cfg.Chain.GenesisTime()
|
||||
ticker := slotutil.NewSlotTicker(genesis, params.BeaconConfig().SecondsPerSlot)
|
||||
ticker := slots.NewSlotTicker(genesis, params.BeaconConfig().SecondsPerSlot)
|
||||
|
||||
go func() {
|
||||
for {
|
||||
@ -480,7 +480,7 @@ func (s *Service) subscribeStaticWithSyncSubnets(topic string, validator pubsub.
|
||||
s.subscribeWithBase(s.addDigestAndIndexToTopic(topic, digest, i), validator, handle)
|
||||
}
|
||||
genesis := s.cfg.Chain.GenesisTime()
|
||||
ticker := slotutil.NewSlotTicker(genesis, params.BeaconConfig().SecondsPerSlot)
|
||||
ticker := slots.NewSlotTicker(genesis, params.BeaconConfig().SecondsPerSlot)
|
||||
|
||||
go func() {
|
||||
for {
|
||||
@ -549,7 +549,7 @@ func (s *Service) subscribeDynamicWithSyncSubnets(
|
||||
}
|
||||
subscriptions := make(map[uint64]*pubsub.Subscription, params.BeaconConfig().SyncCommitteeSubnetCount)
|
||||
genesis := s.cfg.Chain.GenesisTime()
|
||||
ticker := slotutil.NewSlotTicker(genesis, params.BeaconConfig().SecondsPerSlot)
|
||||
ticker := slots.NewSlotTicker(genesis, params.BeaconConfig().SecondsPerSlot)
|
||||
|
||||
go func() {
|
||||
for {
|
||||
|
@ -19,7 +19,7 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/block"
|
||||
"github.com/prysmaticlabs/prysm/shared/bytesutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
"github.com/prysmaticlabs/prysm/shared/timeutils"
|
||||
prysmTime "github.com/prysmaticlabs/prysm/time"
|
||||
"github.com/sirupsen/logrus"
|
||||
"go.opencensus.io/trace"
|
||||
)
|
||||
@ -28,7 +28,7 @@ import (
|
||||
// Blocks that have already been seen are ignored. If the BLS signature is any valid signature,
|
||||
// this method rebroadcasts the message.
|
||||
func (s *Service) validateBeaconBlockPubSub(ctx context.Context, pid peer.ID, msg *pubsub.Message) pubsub.ValidationResult {
|
||||
receivedTime := timeutils.Now()
|
||||
receivedTime := prysmTime.Now()
|
||||
// Validation runs on publish (not just subscriptions), so we should approve any message from
|
||||
// ourselves.
|
||||
if pid == s.cfg.P2P.PeerID() {
|
||||
@ -276,7 +276,7 @@ func captureArrivalTimeMetric(genesisTime uint64, currentSlot types.Slot) error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
ms := timeutils.Now().Sub(startTime) / time.Millisecond
|
||||
ms := prysmTime.Now().Sub(startTime) / time.Millisecond
|
||||
arrivalBlockPropagationHistogram.Observe(float64(ms))
|
||||
|
||||
return nil
|
||||
|
@ -32,8 +32,8 @@ go_library(
|
||||
"//shared/p2putils:go_default_library",
|
||||
"//shared/params:go_default_library",
|
||||
"//shared/sliceutil:go_default_library",
|
||||
"//shared/slotutil:go_default_library",
|
||||
"//shared/testutil:go_default_library",
|
||||
"//time/slots:go_default_library",
|
||||
"@com_github_pkg_errors//:go_default_library",
|
||||
"@com_github_prysmaticlabs_eth2_types//:go_default_library",
|
||||
"@com_github_prysmaticlabs_go_bitfield//:go_default_library",
|
||||
|
@ -17,7 +17,7 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/endtoend/types"
|
||||
eth "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/shared/p2putils"
|
||||
"github.com/prysmaticlabs/prysm/shared/slotutil"
|
||||
"github.com/prysmaticlabs/prysm/time/slots"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/protobuf/types/known/emptypb"
|
||||
)
|
||||
@ -120,7 +120,7 @@ func metricsTest(conns ...*grpc.ClientConn) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
timeSlot := slotutil.SlotsSinceGenesis(genesisResp.GenesisTime.AsTime())
|
||||
timeSlot := slots.SlotsSinceGenesis(genesisResp.GenesisTime.AsTime())
|
||||
if uint64(chainHead.HeadSlot) != uint64(timeSlot) {
|
||||
return fmt.Errorf("expected metrics slot to equal chain head slot, expected %d, received %d", chainHead.HeadSlot, timeSlot)
|
||||
}
|
||||
|
@ -14,8 +14,8 @@ go_library(
|
||||
"//endtoend/types:go_default_library",
|
||||
"//proto/prysm/v1alpha1:go_default_library",
|
||||
"//shared/params:go_default_library",
|
||||
"//shared/slotutil:go_default_library",
|
||||
"//shared/timeutils:go_default_library",
|
||||
"//time:go_default_library",
|
||||
"//time/slots:go_default_library",
|
||||
"@com_github_sirupsen_logrus//:go_default_library",
|
||||
"@org_golang_google_grpc//:go_default_library",
|
||||
"@org_golang_x_sync//errgroup:go_default_library",
|
||||
|
@ -3,7 +3,7 @@ package helpers
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/prysmaticlabs/prysm/shared/timeutils"
|
||||
prysmTime "github.com/prysmaticlabs/prysm/time"
|
||||
)
|
||||
|
||||
// EpochTicker is a special ticker for timing epoch changes.
|
||||
@ -36,7 +36,7 @@ func NewEpochTicker(genesisTime time.Time, secondsPerEpoch uint64) *EpochTicker
|
||||
c: make(chan uint64),
|
||||
done: make(chan struct{}),
|
||||
}
|
||||
ticker.start(genesisTime, secondsPerEpoch, timeutils.Since, timeutils.Until, time.After)
|
||||
ticker.start(genesisTime, secondsPerEpoch, prysmTime.Since, prysmTime.Until, time.After)
|
||||
return ticker
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,7 @@ import (
|
||||
e2etypes "github.com/prysmaticlabs/prysm/endtoend/types"
|
||||
eth "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
"github.com/prysmaticlabs/prysm/shared/slotutil"
|
||||
"github.com/prysmaticlabs/prysm/time/slots"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"golang.org/x/sync/errgroup"
|
||||
"google.golang.org/grpc"
|
||||
@ -242,7 +242,7 @@ func EpochTickerStartTime(genesis *eth.Genesis) time.Time {
|
||||
epochSeconds := uint64(params.BeaconConfig().SlotsPerEpoch.Mul(params.BeaconConfig().SecondsPerSlot))
|
||||
epochSecondsHalf := time.Duration(int64(epochSeconds*1000)/2) * time.Millisecond
|
||||
// Adding a half slot here to ensure the requests are in the middle of an epoch.
|
||||
middleOfEpoch := epochSecondsHalf + slotutil.DivideSlotBy(2 /* half a slot */)
|
||||
middleOfEpoch := epochSecondsHalf + slots.DivideSlotBy(2 /* half a slot */)
|
||||
genesisTime := time.Unix(genesis.GenesisTime.Seconds, 0)
|
||||
// Offsetting the ticker from genesis so it ticks in the middle of an epoch, in order to keep results consistent.
|
||||
return genesisTime.Add(middleOfEpoch)
|
||||
|
@ -8,7 +8,7 @@ go_library(
|
||||
deps = [
|
||||
"//proto/prysm/v1alpha1:go_default_library",
|
||||
"//shared/bls:go_default_library",
|
||||
"//shared/timeutils:go_default_library",
|
||||
"//time:go_default_library",
|
||||
"@com_github_prysmaticlabs_eth2_types//:go_default_library",
|
||||
"@com_github_prysmaticlabs_go_bitfield//:go_default_library",
|
||||
],
|
||||
|
@ -8,7 +8,7 @@ import (
|
||||
"github.com/prysmaticlabs/go-bitfield"
|
||||
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/shared/bls"
|
||||
"github.com/prysmaticlabs/prysm/shared/timeutils"
|
||||
"github.com/prysmaticlabs/prysm/time"
|
||||
)
|
||||
|
||||
// BitlistWithAllBitsSet creates list of bitlists with all bits set.
|
||||
@ -44,7 +44,7 @@ func Bitlists64WithSingleBitSet(n, length uint64) []*bitfield.Bitlist64 {
|
||||
|
||||
// BitlistsWithMultipleBitSet creates list of bitlists with random n bits set.
|
||||
func BitlistsWithMultipleBitSet(t testing.TB, n, length, count uint64) []bitfield.Bitlist {
|
||||
seed := timeutils.Now().UnixNano()
|
||||
seed := time.Now().UnixNano()
|
||||
t.Logf("bitlistsWithMultipleBitSet random seed: %v", seed)
|
||||
rand.Seed(seed)
|
||||
lists := make([]bitfield.Bitlist, n)
|
||||
@ -61,7 +61,7 @@ func BitlistsWithMultipleBitSet(t testing.TB, n, length, count uint64) []bitfiel
|
||||
|
||||
// Bitlists64WithMultipleBitSet creates list of bitlists with random n bits set.
|
||||
func Bitlists64WithMultipleBitSet(t testing.TB, n, length, count uint64) []*bitfield.Bitlist64 {
|
||||
seed := timeutils.Now().UnixNano()
|
||||
seed := time.Now().UnixNano()
|
||||
t.Logf("Bitlists64WithMultipleBitSet random seed: %v", seed)
|
||||
rand.Seed(seed)
|
||||
lists := make([]*bitfield.Bitlist64, n)
|
||||
|
@ -8,7 +8,7 @@ go_library(
|
||||
],
|
||||
importpath = "github.com/prysmaticlabs/prysm/shared/event",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = ["//shared/mclockutil:go_default_library"],
|
||||
deps = ["//time/mclock:go_default_library"],
|
||||
)
|
||||
|
||||
go_test(
|
||||
|
@ -21,7 +21,7 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/prysmaticlabs/prysm/shared/mclockutil"
|
||||
"github.com/prysmaticlabs/prysm/time/mclock"
|
||||
)
|
||||
|
||||
// waitQuotient is divided against the max backoff time, in order to have N requests based on the full
|
||||
@ -120,7 +120,7 @@ type resubscribeSub struct {
|
||||
err chan error
|
||||
unsub chan struct{}
|
||||
unsubOnce sync.Once
|
||||
lastTry mclockutil.AbsTime
|
||||
lastTry mclock.AbsTime
|
||||
waitTime, backoffMax time.Duration
|
||||
}
|
||||
|
||||
@ -155,7 +155,7 @@ func (s *resubscribeSub) subscribe() Subscription {
|
||||
var sub Subscription
|
||||
retry:
|
||||
for {
|
||||
s.lastTry = mclockutil.Now()
|
||||
s.lastTry = mclock.Now()
|
||||
ctx, cancel := context.WithCancel(context.TODO())
|
||||
go func() {
|
||||
rsub, err := s.fn(ctx)
|
||||
@ -194,7 +194,7 @@ func (s *resubscribeSub) waitForError(sub Subscription) bool {
|
||||
}
|
||||
|
||||
func (s *resubscribeSub) backoffWait() bool {
|
||||
if time.Duration(mclockutil.Now()-s.lastTry) > s.backoffMax {
|
||||
if time.Duration(mclock.Now()-s.lastTry) > s.backoffMax {
|
||||
s.waitTime = s.backoffMax / waitQuotient
|
||||
} else {
|
||||
s.waitTime *= 2
|
||||
|
@ -17,8 +17,8 @@ go_library(
|
||||
"//shared/hashutil:go_default_library",
|
||||
"//shared/mputil:go_default_library",
|
||||
"//shared/params:go_default_library",
|
||||
"//shared/timeutils:go_default_library",
|
||||
"//shared/trieutil:go_default_library",
|
||||
"//time:go_default_library",
|
||||
"@com_github_pkg_errors//:go_default_library",
|
||||
],
|
||||
)
|
||||
|
@ -15,8 +15,8 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/shared/hashutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/mputil"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
"github.com/prysmaticlabs/prysm/shared/timeutils"
|
||||
"github.com/prysmaticlabs/prysm/shared/trieutil"
|
||||
"github.com/prysmaticlabs/prysm/time"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -54,7 +54,7 @@ func GenerateGenesisStateFromDepositData(
|
||||
}
|
||||
root := trie.HashTreeRoot()
|
||||
if genesisTime == 0 {
|
||||
genesisTime = uint64(timeutils.Now().Unix())
|
||||
genesisTime = uint64(time.Now().Unix())
|
||||
}
|
||||
beaconState, err := coreState.GenesisBeaconState(ctx, deposits, genesisTime, ðpb.Eth1Data{
|
||||
DepositRoot: root[:],
|
||||
|
@ -13,7 +13,7 @@ go_library(
|
||||
deps = [
|
||||
"//shared/bls:go_default_library",
|
||||
"//shared/fileutil:go_default_library",
|
||||
"//shared/timeutils:go_default_library",
|
||||
"//time:go_default_library",
|
||||
"@com_github_minio_sha256_simd//:go_default_library",
|
||||
"@com_github_pborman_uuid//:go_default_library",
|
||||
"@com_github_sirupsen_logrus//:go_default_library",
|
||||
|
@ -26,7 +26,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/prysmaticlabs/prysm/shared/bls"
|
||||
"github.com/prysmaticlabs/prysm/shared/timeutils"
|
||||
prysmTime "github.com/prysmaticlabs/prysm/time"
|
||||
)
|
||||
|
||||
func aesCTRXOR(key, inText, iv []byte) ([]byte, error) {
|
||||
@ -52,7 +52,7 @@ func ensureInt(x interface{}) int {
|
||||
// keyFileName implements the naming convention for keyfiles:
|
||||
// UTC--<created_at UTC ISO8601>-<first 8 character of address hex>
|
||||
func keyFileName(pubkey bls.PublicKey) string {
|
||||
ts := timeutils.Now().UTC()
|
||||
ts := prysmTime.Now().UTC()
|
||||
return fmt.Sprintf("UTC--%s--%s", toISO8601(ts), hex.EncodeToString(pubkey.Marshal())[:8])
|
||||
}
|
||||
|
||||
|
@ -1,5 +0,0 @@
|
||||
package testing
|
||||
|
||||
import "github.com/prysmaticlabs/prysm/shared/slotutil"
|
||||
|
||||
var _ slotutil.Ticker = (*MockTicker)(nil)
|
@ -22,9 +22,9 @@ go_library(
|
||||
"//shared/grpcutils:go_default_library",
|
||||
"//shared/params:go_default_library",
|
||||
"//shared/sliceutil:go_default_library",
|
||||
"//shared/slotutil:go_default_library",
|
||||
"//slasher/cache:go_default_library",
|
||||
"//slasher/db:go_default_library",
|
||||
"//time/slots:go_default_library",
|
||||
"@com_github_grpc_ecosystem_go_grpc_middleware//:go_default_library",
|
||||
"@com_github_grpc_ecosystem_go_grpc_middleware//retry:go_default_library",
|
||||
"@com_github_grpc_ecosystem_go_grpc_middleware//tracing/opentracing:go_default_library",
|
||||
@ -61,11 +61,11 @@ go_test(
|
||||
"//shared/event:go_default_library",
|
||||
"//shared/mock:go_default_library",
|
||||
"//shared/params:go_default_library",
|
||||
"//shared/slotutil:go_default_library",
|
||||
"//shared/testutil/assert:go_default_library",
|
||||
"//shared/testutil/require:go_default_library",
|
||||
"//slasher/cache:go_default_library",
|
||||
"//slasher/db/testing:go_default_library",
|
||||
"//time/slots:go_default_library",
|
||||
"@com_github_golang_mock//gomock:go_default_library",
|
||||
"@com_github_prysmaticlabs_eth2_types//:go_default_library",
|
||||
"@com_github_sirupsen_logrus//:go_default_library",
|
||||
|
@ -8,7 +8,7 @@ import (
|
||||
"time"
|
||||
|
||||
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/shared/slotutil"
|
||||
"github.com/prysmaticlabs/prysm/time/slots"
|
||||
"github.com/sirupsen/logrus"
|
||||
"go.opencensus.io/trace"
|
||||
"google.golang.org/grpc/codes"
|
||||
@ -149,7 +149,7 @@ func (s *Service) collectReceivedAttestations(ctx context.Context) {
|
||||
defer span.End()
|
||||
|
||||
var atts []*ethpb.IndexedAttestation
|
||||
halfSlot := slotutil.DivideSlotBy(2 /* 1/2 slot duration */)
|
||||
halfSlot := slots.DivideSlotBy(2 /* 1/2 slot duration */)
|
||||
ticker := time.NewTicker(halfSlot)
|
||||
defer ticker.Stop()
|
||||
for {
|
||||
|
@ -9,9 +9,9 @@ import (
|
||||
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/shared/event"
|
||||
"github.com/prysmaticlabs/prysm/shared/mock"
|
||||
"github.com/prysmaticlabs/prysm/shared/slotutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
||||
testDB "github.com/prysmaticlabs/prysm/slasher/db/testing"
|
||||
"github.com/prysmaticlabs/prysm/time/slots"
|
||||
"google.golang.org/protobuf/types/known/emptypb"
|
||||
)
|
||||
|
||||
@ -109,7 +109,7 @@ func TestService_ReceiveAttestations_Batched(t *testing.T) {
|
||||
nil,
|
||||
).Do(func() {
|
||||
// Let a slot pass for the ticker.
|
||||
time.Sleep(slotutil.DivideSlotBy(1))
|
||||
time.Sleep(slots.DivideSlotBy(1))
|
||||
cancel()
|
||||
})
|
||||
|
||||
|
@ -3,6 +3,6 @@ load("@prysm//tools/go:def.bzl", "go_library")
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["utils.go"],
|
||||
importpath = "github.com/prysmaticlabs/prysm/shared/timeutils",
|
||||
importpath = "github.com/prysmaticlabs/prysm/time",
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
@ -3,7 +3,7 @@ load("@prysm//tools/go:def.bzl", "go_library")
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["mclock.go"],
|
||||
importpath = "github.com/prysmaticlabs/prysm/shared/mclockutil",
|
||||
importpath = "github.com/prysmaticlabs/prysm/time/mclock",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = ["@com_github_aristanetworks_goarista//monotime:go_default_library"],
|
||||
)
|
@ -15,7 +15,7 @@
|
||||
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
// Package mclockutil is a wrapper for a monotonic clock source.
|
||||
package mclockutil
|
||||
package mclock
|
||||
|
||||
import (
|
||||
"time"
|
@ -7,11 +7,11 @@ go_library(
|
||||
"slotticker.go",
|
||||
"slottime.go",
|
||||
],
|
||||
importpath = "github.com/prysmaticlabs/prysm/shared/slotutil",
|
||||
importpath = "github.com/prysmaticlabs/prysm/time/slots",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//shared/params:go_default_library",
|
||||
"//shared/timeutils:go_default_library",
|
||||
"//time:go_default_library",
|
||||
"@com_github_prysmaticlabs_eth2_types//:go_default_library",
|
||||
"@com_github_sirupsen_logrus//:go_default_library",
|
||||
],
|
||||
@ -30,7 +30,7 @@ go_test(
|
||||
deps = [
|
||||
"//shared/params:go_default_library",
|
||||
"//shared/testutil/require:go_default_library",
|
||||
"//shared/timeutils:go_default_library",
|
||||
"//time:go_default_library",
|
||||
"@com_github_prysmaticlabs_eth2_types//:go_default_library",
|
||||
"@com_github_sirupsen_logrus//:go_default_library",
|
||||
"@com_github_sirupsen_logrus//hooks/test:go_default_library",
|
@ -1,4 +1,4 @@
|
||||
package slotutil
|
||||
package slots
|
||||
|
||||
import (
|
||||
"context"
|
||||
@ -6,7 +6,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
"github.com/prysmaticlabs/prysm/shared/timeutils"
|
||||
prysmTime "github.com/prysmaticlabs/prysm/time"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
@ -29,7 +29,7 @@ func CountdownToGenesis(ctx context.Context, genesisTime time.Time, genesisValid
|
||||
}
|
||||
secondTimerActivated := false
|
||||
for {
|
||||
currentTime := timeutils.Now()
|
||||
currentTime := prysmTime.Now()
|
||||
if currentTime.After(genesisTime) {
|
||||
log.WithFields(logFields).Info("Chain genesis time reached")
|
||||
return
|
@ -1,4 +1,4 @@
|
||||
package slotutil
|
||||
package slots
|
||||
|
||||
import (
|
||||
"context"
|
||||
@ -7,7 +7,7 @@ import (
|
||||
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
||||
"github.com/prysmaticlabs/prysm/shared/timeutils"
|
||||
prysmTime "github.com/prysmaticlabs/prysm/time"
|
||||
"github.com/sirupsen/logrus"
|
||||
logTest "github.com/sirupsen/logrus/hooks/test"
|
||||
)
|
||||
@ -27,7 +27,7 @@ func TestCountdownToGenesis(t *testing.T) {
|
||||
genesisReached := "Chain genesis time reached"
|
||||
CountdownToGenesis(
|
||||
context.Background(),
|
||||
timeutils.Now().Add(2*time.Second),
|
||||
prysmTime.Now().Add(2*time.Second),
|
||||
params.BeaconConfig().MinGenesisActiveValidatorCount,
|
||||
[32]byte{},
|
||||
)
|
||||
@ -45,7 +45,7 @@ func TestCountdownToGenesis(t *testing.T) {
|
||||
}()
|
||||
CountdownToGenesis(
|
||||
ctx,
|
||||
timeutils.Now().Add(5*time.Second),
|
||||
prysmTime.Now().Add(5*time.Second),
|
||||
params.BeaconConfig().MinGenesisActiveValidatorCount,
|
||||
[32]byte{},
|
||||
)
|
@ -1,11 +1,11 @@
|
||||
// Package slotutil includes ticker and timer-related functions for Ethereum consensus.
|
||||
package slotutil
|
||||
package slots
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
types "github.com/prysmaticlabs/eth2-types"
|
||||
"github.com/prysmaticlabs/prysm/shared/timeutils"
|
||||
prysmTime "github.com/prysmaticlabs/prysm/time"
|
||||
)
|
||||
|
||||
// The Ticker interface defines a type which can expose a
|
||||
@ -48,7 +48,7 @@ func NewSlotTicker(genesisTime time.Time, secondsPerSlot uint64) *SlotTicker {
|
||||
c: make(chan types.Slot),
|
||||
done: make(chan struct{}),
|
||||
}
|
||||
ticker.start(genesisTime, secondsPerSlot, timeutils.Since, timeutils.Until, time.After)
|
||||
ticker.start(genesisTime, secondsPerSlot, prysmTime.Since, prysmTime.Until, time.After)
|
||||
return ticker
|
||||
}
|
||||
|
||||
@ -65,7 +65,7 @@ func NewSlotTickerWithOffset(genesisTime time.Time, offset time.Duration, second
|
||||
c: make(chan types.Slot),
|
||||
done: make(chan struct{}),
|
||||
}
|
||||
ticker.start(genesisTime.Add(offset), secondsPerSlot, timeutils.Since, timeutils.Until, time.After)
|
||||
ticker.start(genesisTime.Add(offset), secondsPerSlot, prysmTime.Since, prysmTime.Until, time.After)
|
||||
return ticker
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
package slotutil
|
||||
package slots
|
||||
|
||||
import (
|
||||
"testing"
|
@ -1,11 +1,11 @@
|
||||
package slotutil
|
||||
package slots
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
types "github.com/prysmaticlabs/eth2-types"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
"github.com/prysmaticlabs/prysm/shared/timeutils"
|
||||
prysmTime "github.com/prysmaticlabs/prysm/time"
|
||||
)
|
||||
|
||||
// SlotStartTime returns the start time in terms of its unix epoch
|
||||
@ -19,10 +19,10 @@ func SlotStartTime(genesis uint64, slot types.Slot) time.Time {
|
||||
// SlotsSinceGenesis returns the number of slots since
|
||||
// the provided genesis time.
|
||||
func SlotsSinceGenesis(genesis time.Time) types.Slot {
|
||||
if genesis.After(timeutils.Now()) { // Genesis has not occurred yet.
|
||||
if genesis.After(prysmTime.Now()) { // Genesis has not occurred yet.
|
||||
return 0
|
||||
}
|
||||
return types.Slot(uint64(timeutils.Since(genesis).Seconds()) / params.BeaconConfig().SecondsPerSlot)
|
||||
return types.Slot(uint64(prysmTime.Since(genesis).Seconds()) / params.BeaconConfig().SecondsPerSlot)
|
||||
}
|
||||
|
||||
// EpochsSinceGenesis returns the number of slots since
|
@ -1,4 +1,4 @@
|
||||
package slotutil
|
||||
package slots
|
||||
|
||||
import (
|
||||
"testing"
|
||||
@ -6,7 +6,7 @@ import (
|
||||
|
||||
types "github.com/prysmaticlabs/eth2-types"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
"github.com/prysmaticlabs/prysm/shared/timeutils"
|
||||
prysmTime "github.com/prysmaticlabs/prysm/time"
|
||||
)
|
||||
|
||||
func TestSlotsSinceGenesis(t *testing.T) {
|
||||
@ -21,14 +21,14 @@ func TestSlotsSinceGenesis(t *testing.T) {
|
||||
{
|
||||
name: "pre-genesis",
|
||||
args: args{
|
||||
genesis: timeutils.Now().Add(1 * time.Hour), // 1 hour in the future
|
||||
genesis: prysmTime.Now().Add(1 * time.Hour), // 1 hour in the future
|
||||
},
|
||||
want: 0,
|
||||
},
|
||||
{
|
||||
name: "post-genesis",
|
||||
args: args{
|
||||
genesis: timeutils.Now().Add(-5 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second),
|
||||
genesis: prysmTime.Now().Add(-5 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second),
|
||||
},
|
||||
want: 5,
|
||||
},
|
@ -1,4 +1,4 @@
|
||||
package slotutil
|
||||
package slots
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
@ -3,7 +3,7 @@ load("@prysm//tools/go:def.bzl", "go_library", "go_test")
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["mock.go"],
|
||||
importpath = "github.com/prysmaticlabs/prysm/shared/slotutil/testing",
|
||||
importpath = "github.com/prysmaticlabs/prysm/time/slots/testing",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = ["@com_github_prysmaticlabs_eth2_types//:go_default_library"],
|
||||
)
|
||||
@ -12,5 +12,5 @@ go_test(
|
||||
name = "go_default_test",
|
||||
srcs = ["mock_test.go"],
|
||||
embed = [":go_default_library"],
|
||||
deps = ["//shared/slotutil:go_default_library"],
|
||||
deps = ["//time/slots:go_default_library"],
|
||||
)
|
7
time/slots/testing/mock_test.go
Normal file
7
time/slots/testing/mock_test.go
Normal file
@ -0,0 +1,7 @@
|
||||
package testing
|
||||
|
||||
import (
|
||||
"github.com/prysmaticlabs/prysm/time/slots"
|
||||
)
|
||||
|
||||
var _ slots.Ticker = (*MockTicker)(nil)
|
@ -1,5 +1,5 @@
|
||||
// Package timeutils is a wrapper around the go standard time library.
|
||||
package timeutils
|
||||
package time
|
||||
|
||||
import (
|
||||
"time"
|
@ -82,7 +82,7 @@ go_test(
|
||||
"//shared/petnames:go_default_library",
|
||||
"//shared/testutil/assert:go_default_library",
|
||||
"//shared/testutil/require:go_default_library",
|
||||
"//shared/timeutils:go_default_library",
|
||||
"//time:go_default_library",
|
||||
"//validator/accounts/iface:go_default_library",
|
||||
"//validator/accounts/wallet:go_default_library",
|
||||
"//validator/keymanager:go_default_library",
|
||||
|
@ -18,7 +18,7 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
||||
"github.com/prysmaticlabs/prysm/shared/timeutils"
|
||||
prysmTime "github.com/prysmaticlabs/prysm/time"
|
||||
"github.com/prysmaticlabs/prysm/validator/accounts/iface"
|
||||
"github.com/prysmaticlabs/prysm/validator/accounts/wallet"
|
||||
"github.com/prysmaticlabs/prysm/validator/keymanager"
|
||||
@ -403,7 +403,7 @@ func createKeystore(t *testing.T, path string) (*keymanager.Keystore, string) {
|
||||
encoded, err := json.MarshalIndent(keystoreFile, "", "\t")
|
||||
require.NoError(t, err)
|
||||
// Write the encoded keystore to disk with the timestamp appended
|
||||
createdAt := timeutils.Now().Unix()
|
||||
createdAt := prysmTime.Now().Unix()
|
||||
fullPath := filepath.Join(path, fmt.Sprintf(imported.KeystoreFileNameFormat, createdAt))
|
||||
require.NoError(t, ioutil.WriteFile(fullPath, encoded, os.ModePerm))
|
||||
return keystoreFile, fullPath
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user