diff --git a/BUILD.bazel b/BUILD.bazel index 765211313..93bb8f328 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -104,7 +104,6 @@ nogo( "@org_golang_x_tools//go/analysis/passes/inspect:go_tool_library", "@org_golang_x_tools//go/analysis/passes/asmdecl:go_tool_library", "//tools/analyzers/maligned:go_tool_library", - "//tools/analyzers/roughtime:go_tool_library", "//tools/analyzers/cryptorand:go_tool_library", "//tools/analyzers/errcheck:go_tool_library", "//tools/analyzers/featureconfig:go_tool_library", diff --git a/beacon-chain/blockchain/BUILD.bazel b/beacon-chain/blockchain/BUILD.bazel index 59330c686..1c78c72e5 100644 --- a/beacon-chain/blockchain/BUILD.bazel +++ b/beacon-chain/blockchain/BUILD.bazel @@ -51,8 +51,8 @@ go_library( "//shared/featureconfig:go_default_library", "//shared/hashutil:go_default_library", "//shared/params:go_default_library", - "//shared/roughtime:go_default_library", "//shared/slotutil:go_default_library", + "//shared/timeutils:go_default_library", "//shared/traceutil:go_default_library", "@com_github_emicklei_dot//:go_default_library", "@com_github_hashicorp_golang_lru//:go_default_library", diff --git a/beacon-chain/blockchain/metrics.go b/beacon-chain/blockchain/metrics.go index 0b4a2e24d..720d5371b 100644 --- a/beacon-chain/blockchain/metrics.go +++ b/beacon-chain/blockchain/metrics.go @@ -11,7 +11,7 @@ import ( stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/shared/bytesutil" "github.com/prysmaticlabs/prysm/shared/params" - "github.com/prysmaticlabs/prysm/shared/roughtime" + "github.com/prysmaticlabs/prysm/shared/timeutils" ) var ( @@ -239,7 +239,7 @@ func captureSentTimeMetric(genesisTime uint64, currentSlot uint64) error { if err != nil { return err } - diffMs := roughtime.Now().Sub(startTime) / time.Millisecond + diffMs := timeutils.Now().Sub(startTime) / time.Millisecond sentBlockPropagationHistogram.Observe(float64(diffMs)) return nil diff --git a/beacon-chain/blockchain/process_attestation.go b/beacon-chain/blockchain/process_attestation.go index 7500ce9b4..9af262393 100644 --- a/beacon-chain/blockchain/process_attestation.go +++ b/beacon-chain/blockchain/process_attestation.go @@ -13,7 +13,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/roughtime" + "github.com/prysmaticlabs/prysm/shared/timeutils" "go.opencensus.io/trace" ) @@ -74,7 +74,7 @@ func (s *Service) onAttestation(ctx context.Context, a *ethpb.Attestation) ([]ui if err != nil { return nil, err } - if err := s.verifyAttTargetEpoch(ctx, uint64(s.genesisTime.Unix()), uint64(roughtime.Now().Unix()), tgt); err != nil { + if err := s.verifyAttTargetEpoch(ctx, uint64(s.genesisTime.Unix()), uint64(timeutils.Now().Unix()), tgt); err != nil { return nil, err } if err := s.verifyBeaconBlock(ctx, a.Data); err != nil { @@ -126,7 +126,7 @@ func (s *Service) onAttestation(ctx context.Context, a *ethpb.Attestation) ([]ui genesisTime := baseState.GenesisTime() // Verify attestation target is from current epoch or previous epoch. - if err := s.verifyAttTargetEpoch(ctx, genesisTime, uint64(roughtime.Now().Unix()), tgt); err != nil { + if err := s.verifyAttTargetEpoch(ctx, genesisTime, uint64(timeutils.Now().Unix()), tgt); err != nil { return nil, err } diff --git a/beacon-chain/blockchain/process_block_test.go b/beacon-chain/blockchain/process_block_test.go index da13c7e75..a68c94633 100644 --- a/beacon-chain/blockchain/process_block_test.go +++ b/beacon-chain/blockchain/process_block_test.go @@ -20,10 +20,10 @@ import ( "github.com/prysmaticlabs/prysm/shared/attestationutil" "github.com/prysmaticlabs/prysm/shared/bytesutil" "github.com/prysmaticlabs/prysm/shared/params" - "github.com/prysmaticlabs/prysm/shared/roughtime" "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" ) func TestStore_OnBlock(t *testing.T) { @@ -512,7 +512,7 @@ func blockTree1(db db.Database, genesisRoot []byte) ([][]byte, error) { } func TestCurrentSlot_HandlesOverflow(t *testing.T) { - svc := Service{genesisTime: roughtime.Now().Add(1 * time.Hour)} + svc := Service{genesisTime: timeutils.Now().Add(1 * time.Hour)} slot := svc.CurrentSlot() require.Equal(t, uint64(0), slot, "Unexpected slot") diff --git a/beacon-chain/blockchain/receive_attestation.go b/beacon-chain/blockchain/receive_attestation.go index 5a94bba41..33ea4a761 100644 --- a/beacon-chain/blockchain/receive_attestation.go +++ b/beacon-chain/blockchain/receive_attestation.go @@ -14,8 +14,8 @@ import ( "github.com/prysmaticlabs/prysm/shared/bytesutil" "github.com/prysmaticlabs/prysm/shared/featureconfig" "github.com/prysmaticlabs/prysm/shared/params" - "github.com/prysmaticlabs/prysm/shared/roughtime" "github.com/prysmaticlabs/prysm/shared/slotutil" + "github.com/prysmaticlabs/prysm/shared/timeutils" "github.com/sirupsen/logrus" "go.opencensus.io/trace" ) @@ -159,7 +159,7 @@ func (s *Service) processAttestation(subscribedToStateEvents chan struct{}) { // This verifies the epoch of input checkpoint is within current epoch and previous epoch // with respect to current time. Returns true if it's within, false if it's not. func (s *Service) verifyCheckpointEpoch(c *ethpb.Checkpoint) bool { - now := uint64(roughtime.Now().Unix()) + now := uint64(timeutils.Now().Unix()) genesisTime := uint64(s.genesisTime.Unix()) currentSlot := (now - genesisTime) / params.BeaconConfig().SecondsPerSlot currentEpoch := helpers.SlotToEpoch(currentSlot) diff --git a/beacon-chain/core/helpers/BUILD.bazel b/beacon-chain/core/helpers/BUILD.bazel index fda41a414..54b89db19 100644 --- a/beacon-chain/core/helpers/BUILD.bazel +++ b/beacon-chain/core/helpers/BUILD.bazel @@ -40,8 +40,8 @@ go_library( "//shared/hashutil:go_default_library", "//shared/mathutil:go_default_library", "//shared/params:go_default_library", - "//shared/roughtime:go_default_library", "//shared/sliceutil:go_default_library", + "//shared/timeutils:go_default_library", "@com_github_ferranbt_fastssz//:go_default_library", "@com_github_pkg_errors//:go_default_library", "@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library", @@ -74,11 +74,11 @@ go_test( "//shared/bytesutil:go_default_library", "//shared/hashutil:go_default_library", "//shared/params:go_default_library", - "//shared/roughtime:go_default_library", "//shared/sliceutil:go_default_library", "//shared/testutil:go_default_library", "//shared/testutil/assert:go_default_library", "//shared/testutil/require:go_default_library", + "//shared/timeutils:go_default_library", "@com_github_google_gofuzz//:go_default_library", "@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library", "@com_github_prysmaticlabs_go_bitfield//:go_default_library", diff --git a/beacon-chain/core/helpers/attestation.go b/beacon-chain/core/helpers/attestation.go index 975d838b2..cc429a9b0 100644 --- a/beacon-chain/core/helpers/attestation.go +++ b/beacon-chain/core/helpers/attestation.go @@ -10,7 +10,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/roughtime" + "github.com/prysmaticlabs/prysm/shared/timeutils" ) // SlotSignature returns the signed signature of the hash tree root of input slot. @@ -139,7 +139,7 @@ func ValidateAttestationTime(attSlot uint64, genesisTime time.Time) error { // An attestation cannot be from the future, so the upper bounds is set to now, with a minor // tolerance for peer clock disparity. - upperBounds := roughtime.Now().Add(clockDisparity) + upperBounds := timeutils.Now().Add(clockDisparity) // An attestation cannot be older than the current slot - attestation propagation slot range // with a minor tolerance for peer clock disparity. diff --git a/beacon-chain/core/helpers/attestation_test.go b/beacon-chain/core/helpers/attestation_test.go index 6debec86f..6fd9c92c6 100644 --- a/beacon-chain/core/helpers/attestation_test.go +++ b/beacon-chain/core/helpers/attestation_test.go @@ -12,10 +12,10 @@ import ( "github.com/prysmaticlabs/prysm/shared/bls" "github.com/prysmaticlabs/prysm/shared/bytesutil" "github.com/prysmaticlabs/prysm/shared/params" - "github.com/prysmaticlabs/prysm/shared/roughtime" "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" ) func TestAttestation_SlotSignature(t *testing.T) { @@ -162,14 +162,14 @@ func Test_ValidateAttestationTime(t *testing.T) { name: "attestation.slot == current_slot", args: args{ attSlot: 15, - genesisTime: roughtime.Now().Add(-15 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second), + genesisTime: timeutils.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: roughtime.Now().Add( + genesisTime: timeutils.Now().Add( -15 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second, ).Add(-(time.Duration(params.BeaconConfig().SecondsPerSlot/2) * time.Second)), }, @@ -178,7 +178,7 @@ func Test_ValidateAttestationTime(t *testing.T) { name: "attestation.slot == current_slot, received 200ms early", args: args{ attSlot: 16, - genesisTime: roughtime.Now().Add( + genesisTime: timeutils.Now().Add( -16 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second, ).Add(-200 * time.Millisecond), }, @@ -187,7 +187,7 @@ func Test_ValidateAttestationTime(t *testing.T) { name: "attestation.slot > current_slot", args: args{ attSlot: 16, - genesisTime: roughtime.Now().Add(-15 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second), + genesisTime: timeutils.Now().Add(-15 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second), }, wantedErr: "not within attestation propagation range", }, @@ -195,7 +195,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: roughtime.Now().Add(-100 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second), + genesisTime: timeutils.Now().Add(-100 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second), }, wantedErr: "not within attestation propagation range", }, @@ -203,14 +203,14 @@ func Test_ValidateAttestationTime(t *testing.T) { name: "attestation.slot = current_slot-ATTESTATION_PROPAGATION_SLOT_RANGE", args: args{ attSlot: 100 - params.BeaconNetworkConfig().AttestationPropagationSlotRange, - genesisTime: roughtime.Now().Add(-100 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second), + genesisTime: timeutils.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: roughtime.Now().Add( + genesisTime: timeutils.Now().Add( -100 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second, ).Add(200 * time.Millisecond), }, @@ -219,7 +219,7 @@ func Test_ValidateAttestationTime(t *testing.T) { name: "attestation.slot is well beyond current slot", args: args{ attSlot: 1 << 32, - genesisTime: roughtime.Now().Add(-15 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second), + genesisTime: timeutils.Now().Add(-15 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second), }, wantedErr: "which exceeds max allowed value relative to the local clock", }, diff --git a/beacon-chain/core/helpers/slot_epoch.go b/beacon-chain/core/helpers/slot_epoch.go index e4df4b991..20d1b41a0 100644 --- a/beacon-chain/core/helpers/slot_epoch.go +++ b/beacon-chain/core/helpers/slot_epoch.go @@ -8,7 +8,7 @@ import ( stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/shared/mathutil" "github.com/prysmaticlabs/prysm/shared/params" - "github.com/prysmaticlabs/prysm/shared/roughtime" + "github.com/prysmaticlabs/prysm/shared/timeutils" ) // MaxSlotBuffer specifies the max buffer given to slots from @@ -112,7 +112,7 @@ func VerifySlotTime(genesisTime uint64, slot uint64, timeTolerance time.Duration return err } - currentTime := roughtime.Now() + currentTime := timeutils.Now() diff := slotTime.Sub(currentTime) if diff > timeTolerance { @@ -142,7 +142,7 @@ func SlotsSince(time time.Time) uint64 { // CurrentSlot returns the current slot as determined by the local clock and // provided genesis time. func CurrentSlot(genesisTimeSec uint64) uint64 { - now := roughtime.Now().Unix() + now := timeutils.Now().Unix() genesis := int64(genesisTimeSec) if now < genesis { return 0 diff --git a/beacon-chain/core/helpers/slot_epoch_test.go b/beacon-chain/core/helpers/slot_epoch_test.go index 1dce00a37..211570012 100644 --- a/beacon-chain/core/helpers/slot_epoch_test.go +++ b/beacon-chain/core/helpers/slot_epoch_test.go @@ -5,9 +5,9 @@ import ( "testing" "time" - "github.com/prysmaticlabs/prysm/shared/roughtime" "github.com/prysmaticlabs/prysm/shared/testutil/assert" "github.com/prysmaticlabs/prysm/shared/testutil/require" + "github.com/prysmaticlabs/prysm/shared/timeutils" beaconstate "github.com/prysmaticlabs/prysm/beacon-chain/state" pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1" @@ -264,21 +264,21 @@ func TestVerifySlotTime(t *testing.T) { { name: "Past slot", args: args{ - genesisTime: roughtime.Now().Add(-1 * 5 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second).Unix(), + genesisTime: timeutils.Now().Add(-1 * 5 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second).Unix(), slot: 3, }, }, { name: "within tolerance", args: args{ - genesisTime: roughtime.Now().Add(-1 * 5 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second).Add(20 * time.Millisecond).Unix(), + genesisTime: timeutils.Now().Add(-1 * 5 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second).Add(20 * time.Millisecond).Unix(), slot: 5, }, }, { name: "future slot", args: args{ - genesisTime: roughtime.Now().Add(-1 * 5 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second).Unix(), + genesisTime: timeutils.Now().Add(-1 * 5 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second).Unix(), slot: 6, }, wantedErr: "could not process slot from the future", @@ -286,7 +286,7 @@ func TestVerifySlotTime(t *testing.T) { { name: "max future slot", args: args{ - genesisTime: roughtime.Now().Add(-1 * 5 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second).Unix(), + genesisTime: timeutils.Now().Add(-1 * 5 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second).Unix(), slot: MaxSlotBuffer + 6, }, wantedErr: "exceeds max allowed value relative to the local clock", @@ -294,7 +294,7 @@ func TestVerifySlotTime(t *testing.T) { { name: "evil future slot", args: args{ - genesisTime: roughtime.Now().Add(-1 * 24 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second).Unix(), // 24 slots in the past + genesisTime: timeutils.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: ((^uint64(0)) / params.BeaconConfig().SecondsPerSlot) + 24, @@ -315,7 +315,7 @@ func TestVerifySlotTime(t *testing.T) { } func TestValidateSlotClock_HandlesBadSlot(t *testing.T) { - genTime := roughtime.Now().Add(-1 * time.Duration(MaxSlotBuffer) * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second).Unix() + genTime := timeutils.Now().Add(-1 * time.Duration(MaxSlotBuffer) * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second).Unix() assert.NoError(t, ValidateSlotClock(MaxSlotBuffer, uint64(genTime)), "unexpected error validating slot") assert.NoError(t, ValidateSlotClock(2*MaxSlotBuffer, uint64(genTime)), "unexpected error validating slot") diff --git a/beacon-chain/operations/attestations/BUILD.bazel b/beacon-chain/operations/attestations/BUILD.bazel index 0c9e0235f..07622d1da 100644 --- a/beacon-chain/operations/attestations/BUILD.bazel +++ b/beacon-chain/operations/attestations/BUILD.bazel @@ -22,8 +22,8 @@ go_library( "//shared/aggregation/attestations:go_default_library", "//shared/hashutil:go_default_library", "//shared/params:go_default_library", - "//shared/roughtime:go_default_library", "//shared/slotutil:go_default_library", + "//shared/timeutils: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", @@ -48,10 +48,10 @@ go_test( "//shared/aggregation/attestations:go_default_library", "//shared/bls:go_default_library", "//shared/params:go_default_library", - "//shared/roughtime:go_default_library", "//shared/runutil:go_default_library", "//shared/testutil/assert:go_default_library", "//shared/testutil/require:go_default_library", + "//shared/timeutils:go_default_library", "@com_github_gogo_protobuf//proto:go_default_library", "@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library", "@com_github_prysmaticlabs_go_bitfield//:go_default_library", diff --git a/beacon-chain/operations/attestations/prune_expired.go b/beacon-chain/operations/attestations/prune_expired.go index ff101c214..14cadc0a6 100644 --- a/beacon-chain/operations/attestations/prune_expired.go +++ b/beacon-chain/operations/attestations/prune_expired.go @@ -4,7 +4,7 @@ import ( "time" "github.com/prysmaticlabs/prysm/shared/params" - "github.com/prysmaticlabs/prysm/shared/roughtime" + "github.com/prysmaticlabs/prysm/shared/timeutils" ) // pruneAttsPool prunes attestations pool on every slot interval. @@ -68,6 +68,6 @@ func (s *Service) pruneExpiredAtts() { func (s *Service) expired(slot uint64) bool { expirationSlot := slot + params.BeaconConfig().SlotsPerEpoch expirationTime := s.genesisTime + expirationSlot*params.BeaconConfig().SecondsPerSlot - currentTime := uint64(roughtime.Now().Unix()) + currentTime := uint64(timeutils.Now().Unix()) return currentTime >= expirationTime } diff --git a/beacon-chain/operations/attestations/prune_expired_test.go b/beacon-chain/operations/attestations/prune_expired_test.go index 4587620b9..5b809fa47 100644 --- a/beacon-chain/operations/attestations/prune_expired_test.go +++ b/beacon-chain/operations/attestations/prune_expired_test.go @@ -8,10 +8,10 @@ import ( ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1" "github.com/prysmaticlabs/go-bitfield" "github.com/prysmaticlabs/prysm/shared/params" - "github.com/prysmaticlabs/prysm/shared/roughtime" "github.com/prysmaticlabs/prysm/shared/runutil" "github.com/prysmaticlabs/prysm/shared/testutil/assert" "github.com/prysmaticlabs/prysm/shared/testutil/require" + "github.com/prysmaticlabs/prysm/shared/timeutils" ) func TestPruneExpired_Ticker(t *testing.T) { @@ -67,7 +67,7 @@ func TestPruneExpired_Ticker(t *testing.T) { require.NoError(t, s.pool.SaveBlockAttestations(atts)) // Rewind back one epoch worth of time. - s.genesisTime = uint64(roughtime.Now().Unix()) - params.BeaconConfig().SlotsPerEpoch*params.BeaconConfig().SecondsPerSlot + s.genesisTime = uint64(timeutils.Now().Unix()) - params.BeaconConfig().SlotsPerEpoch*params.BeaconConfig().SecondsPerSlot go s.pruneAttsPool() @@ -144,7 +144,7 @@ func TestPruneExpired_PruneExpiredAtts(t *testing.T) { require.NoError(t, s.pool.SaveBlockAttestations(atts)) // Rewind back one epoch worth of time. - s.genesisTime = uint64(roughtime.Now().Unix()) - params.BeaconConfig().SlotsPerEpoch*params.BeaconConfig().SecondsPerSlot + s.genesisTime = uint64(timeutils.Now().Unix()) - params.BeaconConfig().SlotsPerEpoch*params.BeaconConfig().SecondsPerSlot s.pruneExpiredAtts() // All the attestations on slot 0 should be pruned. @@ -165,7 +165,7 @@ func TestPruneExpired_Expired(t *testing.T) { require.NoError(t, err) // Rewind back one epoch worth of time. - s.genesisTime = uint64(roughtime.Now().Unix()) - params.BeaconConfig().SlotsPerEpoch*params.BeaconConfig().SecondsPerSlot + s.genesisTime = uint64(timeutils.Now().Unix()) - params.BeaconConfig().SlotsPerEpoch*params.BeaconConfig().SecondsPerSlot assert.Equal(t, true, s.expired(0), "Should be expired") assert.Equal(t, false, s.expired(1), "Should not be expired") } diff --git a/beacon-chain/p2p/BUILD.bazel b/beacon-chain/p2p/BUILD.bazel index 04664850b..249b02724 100644 --- a/beacon-chain/p2p/BUILD.bazel +++ b/beacon-chain/p2p/BUILD.bazel @@ -49,9 +49,9 @@ go_library( "//shared/iputils:go_default_library", "//shared/p2putils:go_default_library", "//shared/params:go_default_library", - "//shared/roughtime:go_default_library", "//shared/runutil:go_default_library", "//shared/slotutil:go_default_library", + "//shared/timeutils:go_default_library", "//shared/traceutil:go_default_library", "//shared/version:go_default_library", "@com_github_btcsuite_btcd//btcec:go_default_library", diff --git a/beacon-chain/p2p/fork.go b/beacon-chain/p2p/fork.go index 90ffa23d2..d63e284b8 100644 --- a/beacon-chain/p2p/fork.go +++ b/beacon-chain/p2p/fork.go @@ -12,7 +12,7 @@ import ( pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1" "github.com/prysmaticlabs/prysm/shared/p2putils" "github.com/prysmaticlabs/prysm/shared/params" - "github.com/prysmaticlabs/prysm/shared/roughtime" + "github.com/prysmaticlabs/prysm/shared/timeutils" "github.com/sirupsen/logrus" ) @@ -87,7 +87,7 @@ func addForkEntry( } currentSlot := helpers.SlotsSince(genesisTime) currentEpoch := helpers.SlotToEpoch(currentSlot) - if roughtime.Now().Before(genesisTime) { + if timeutils.Now().Before(genesisTime) { currentSlot, currentEpoch = 0, 0 } fork, err := p2putils.Fork(currentEpoch) diff --git a/beacon-chain/p2p/handshake.go b/beacon-chain/p2p/handshake.go index 4f00ce9fe..a833badde 100644 --- a/beacon-chain/p2p/handshake.go +++ b/beacon-chain/p2p/handshake.go @@ -10,7 +10,7 @@ import ( "github.com/libp2p/go-libp2p-core/network" "github.com/libp2p/go-libp2p-core/peer" "github.com/prysmaticlabs/prysm/beacon-chain/p2p/peers" - "github.com/prysmaticlabs/prysm/shared/roughtime" + "github.com/prysmaticlabs/prysm/shared/timeutils" "github.com/sirupsen/logrus" ) @@ -98,7 +98,7 @@ func (s *Service) AddConnectionHandler(reqFunc func(ctx context.Context, id peer if conn.Stat().Direction == network.DirInbound { _, err := s.peers.ChainState(remotePeer) peerExists := err == nil - currentTime := roughtime.Now() + currentTime := timeutils.Now() // Wait for peer to initiate handshake time.Sleep(timeForStatus) diff --git a/beacon-chain/p2p/peers/BUILD.bazel b/beacon-chain/p2p/peers/BUILD.bazel index 800209700..14e556bfc 100644 --- a/beacon-chain/p2p/peers/BUILD.bazel +++ b/beacon-chain/p2p/peers/BUILD.bazel @@ -19,7 +19,7 @@ go_library( "//shared/featureconfig:go_default_library", "//shared/params:go_default_library", "//shared/rand:go_default_library", - "//shared/roughtime:go_default_library", + "//shared/timeutils:go_default_library", "@com_github_ethereum_go_ethereum//p2p/enr:go_default_library", "@com_github_gogo_protobuf//proto:go_default_library", "@com_github_libp2p_go_libp2p_core//network:go_default_library", @@ -47,9 +47,9 @@ go_test( "//shared/featureconfig:go_default_library", "//shared/params:go_default_library", "//shared/rand:go_default_library", - "//shared/roughtime:go_default_library", "//shared/testutil/assert:go_default_library", "//shared/testutil/require:go_default_library", + "//shared/timeutils: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", diff --git a/beacon-chain/p2p/peers/score_block_providers.go b/beacon-chain/p2p/peers/score_block_providers.go index 0329c283e..178f652ca 100644 --- a/beacon-chain/p2p/peers/score_block_providers.go +++ b/beacon-chain/p2p/peers/score_block_providers.go @@ -11,7 +11,7 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/flags" "github.com/prysmaticlabs/prysm/shared/featureconfig" "github.com/prysmaticlabs/prysm/shared/rand" - "github.com/prysmaticlabs/prysm/shared/roughtime" + "github.com/prysmaticlabs/prysm/shared/timeutils" ) const ( @@ -160,7 +160,7 @@ func (s *BlockProviderScorer) touch(pid peer.ID, t ...time.Time) { if len(t) == 1 { s.store.peers[pid].blockProviderUpdated = t[0] } else { - s.store.peers[pid].blockProviderUpdated = roughtime.Now() + s.store.peers[pid].blockProviderUpdated = timeutils.Now() } } diff --git a/beacon-chain/p2p/peers/score_block_providers_test.go b/beacon-chain/p2p/peers/score_block_providers_test.go index 32b48acaf..82f097dcf 100644 --- a/beacon-chain/p2p/peers/score_block_providers_test.go +++ b/beacon-chain/p2p/peers/score_block_providers_test.go @@ -10,8 +10,8 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/flags" "github.com/prysmaticlabs/prysm/beacon-chain/p2p/peers" "github.com/prysmaticlabs/prysm/shared/rand" - "github.com/prysmaticlabs/prysm/shared/roughtime" "github.com/prysmaticlabs/prysm/shared/testutil/assert" + "github.com/prysmaticlabs/prysm/shared/timeutils" ) func TestPeerScorer_BlockProvider_Score(t *testing.T) { @@ -54,7 +54,7 @@ func TestPeerScorer_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", roughtime.Now().Add(-1*scorer.Params().StalePeerRefreshInterval)) + scorer.Touch("peer1", timeutils.Now().Add(-1*scorer.Params().StalePeerRefreshInterval)) }, check: func(scorer *peers.BlockProviderScorer) { assert.Equal(t, scorer.MaxScore(), scorer.Score("peer1"), "Unexpected score") diff --git a/beacon-chain/p2p/peers/status.go b/beacon-chain/p2p/peers/status.go index 55ec9f7fa..1ad682d8c 100644 --- a/beacon-chain/p2p/peers/status.go +++ b/beacon-chain/p2p/peers/status.go @@ -35,7 +35,7 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1" "github.com/prysmaticlabs/prysm/shared/params" - "github.com/prysmaticlabs/prysm/shared/roughtime" + "github.com/prysmaticlabs/prysm/shared/timeutils" ) // PeerConnectionState is the state of the connection. @@ -166,7 +166,7 @@ func (p *Status) SetChainState(pid peer.ID, chainState *pb.Status) { peerData := p.fetch(pid) peerData.chainState = chainState - peerData.chainStateLastUpdated = roughtime.Now() + peerData.chainStateLastUpdated = timeutils.Now() } // ChainState gets the chain state of the given remote peer. @@ -279,7 +279,7 @@ func (p *Status) ChainStateLastUpdated(pid peer.ID) (time.Time, error) { if peerData, ok := p.store.peers[pid]; ok { return peerData.chainStateLastUpdated, nil } - return roughtime.Now(), ErrPeerUnknown + return timeutils.Now(), ErrPeerUnknown } // IsBad states if the peer is to be considered bad. diff --git a/beacon-chain/powchain/BUILD.bazel b/beacon-chain/powchain/BUILD.bazel index b7c5b66bb..46373066f 100644 --- a/beacon-chain/powchain/BUILD.bazel +++ b/beacon-chain/powchain/BUILD.bazel @@ -29,7 +29,7 @@ go_library( "//shared/bytesutil:go_default_library", "//shared/hashutil:go_default_library", "//shared/params:go_default_library", - "//shared/roughtime:go_default_library", + "//shared/timeutils:go_default_library", "//shared/trieutil:go_default_library", "@com_github_ethereum_go_ethereum//:go_default_library", "@com_github_ethereum_go_ethereum//accounts/abi/bind:go_default_library", diff --git a/beacon-chain/powchain/service.go b/beacon-chain/powchain/service.go index 2a7c322a3..9c186659f 100644 --- a/beacon-chain/powchain/service.go +++ b/beacon-chain/powchain/service.go @@ -32,7 +32,7 @@ import ( protodb "github.com/prysmaticlabs/prysm/proto/beacon/db" "github.com/prysmaticlabs/prysm/shared/bytesutil" "github.com/prysmaticlabs/prysm/shared/params" - "github.com/prysmaticlabs/prysm/shared/roughtime" + "github.com/prysmaticlabs/prysm/shared/timeutils" "github.com/prysmaticlabs/prysm/shared/trieutil" "github.com/sirupsen/logrus" ) @@ -610,7 +610,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 := roughtime.Now().Add(-5 * time.Minute) + fiveMinutesTimeout := timeutils.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") diff --git a/beacon-chain/rpc/beacon/BUILD.bazel b/beacon-chain/rpc/beacon/BUILD.bazel index 403616c99..88e3e3800 100644 --- a/beacon-chain/rpc/beacon/BUILD.bazel +++ b/beacon-chain/rpc/beacon/BUILD.bazel @@ -100,10 +100,10 @@ go_test( "//shared/featureconfig:go_default_library", "//shared/mock:go_default_library", "//shared/params:go_default_library", - "//shared/roughtime:go_default_library", "//shared/testutil:go_default_library", "//shared/testutil/assert:go_default_library", "//shared/testutil/require:go_default_library", + "//shared/timeutils:go_default_library", "@com_github_gogo_protobuf//proto:go_default_library", "@com_github_gogo_protobuf//types:go_default_library", "@com_github_golang_mock//gomock:go_default_library", diff --git a/beacon-chain/rpc/beacon/committees_test.go b/beacon-chain/rpc/beacon/committees_test.go index 5e15b5b2f..5161615c7 100644 --- a/beacon-chain/rpc/beacon/committees_test.go +++ b/beacon-chain/rpc/beacon/committees_test.go @@ -17,10 +17,10 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/state/stategen" pbp2p "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1" "github.com/prysmaticlabs/prysm/shared/params" - "github.com/prysmaticlabs/prysm/shared/roughtime" "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" "gopkg.in/d4l3k/messagediff.v1" ) @@ -33,7 +33,7 @@ func TestServer_ListBeaconCommittees_CurrentEpoch(t *testing.T) { headState := setupActiveValidators(t, db, numValidators) m := &mock.ChainService{ - Genesis: roughtime.Now().Add(time.Duration(-1*int64(headState.Slot()*params.BeaconConfig().SecondsPerSlot)) * time.Second), + Genesis: timeutils.Now().Add(time.Duration(-1*int64(headState.Slot()*params.BeaconConfig().SecondsPerSlot)) * time.Second), } bs := &Server{ HeadFetcher: m, @@ -94,7 +94,7 @@ func TestServer_ListBeaconCommittees_PreviousEpoch(t *testing.T) { m := &mock.ChainService{ State: headState, - Genesis: roughtime.Now().Add(time.Duration(-1*int64(headState.Slot()*params.BeaconConfig().SecondsPerSlot)) * time.Second), + Genesis: timeutils.Now().Add(time.Duration(-1*int64(headState.Slot()*params.BeaconConfig().SecondsPerSlot)) * time.Second), } bs := &Server{ HeadFetcher: m, @@ -147,7 +147,7 @@ func TestRetrieveCommitteesForRoot(t *testing.T) { headState := setupActiveValidators(t, db, numValidators) m := &mock.ChainService{ - Genesis: roughtime.Now().Add(time.Duration(-1*int64(headState.Slot()*params.BeaconConfig().SecondsPerSlot)) * time.Second), + Genesis: timeutils.Now().Add(time.Duration(-1*int64(headState.Slot()*params.BeaconConfig().SecondsPerSlot)) * time.Second), } bs := &Server{ HeadFetcher: m, diff --git a/beacon-chain/rpc/validator/BUILD.bazel b/beacon-chain/rpc/validator/BUILD.bazel index 337ad0db1..0116d82ef 100644 --- a/beacon-chain/rpc/validator/BUILD.bazel +++ b/beacon-chain/rpc/validator/BUILD.bazel @@ -46,8 +46,8 @@ go_library( "//shared/hashutil:go_default_library", "//shared/params:go_default_library", "//shared/rand:go_default_library", - "//shared/roughtime:go_default_library", "//shared/slotutil:go_default_library", + "//shared/timeutils:go_default_library", "//shared/traceutil:go_default_library", "//shared/trieutil:go_default_library", "@com_github_ferranbt_fastssz//:go_default_library", @@ -104,10 +104,10 @@ go_test( "//shared/hashutil:go_default_library", "//shared/mock:go_default_library", "//shared/params:go_default_library", - "//shared/roughtime:go_default_library", "//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", "@com_github_ferranbt_fastssz//:go_default_library", "@com_github_gogo_protobuf//proto:go_default_library", diff --git a/beacon-chain/rpc/validator/assignments.go b/beacon-chain/rpc/validator/assignments.go index 175af8d77..6eeab1539 100644 --- a/beacon-chain/rpc/validator/assignments.go +++ b/beacon-chain/rpc/validator/assignments.go @@ -13,8 +13,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/roughtime" "github.com/prysmaticlabs/prysm/shared/slotutil" + "github.com/prysmaticlabs/prysm/shared/timeutils" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" ) @@ -40,7 +40,7 @@ func (vs *Server) StreamDuties(req *ethpb.DutiesRequest, stream ethpb.BeaconNode // the number epochs since the genesis time, otherwise 0 by default. genesisTime := vs.GenesisTimeFetcher.GenesisTime() var currentEpoch uint64 - if genesisTime.Before(roughtime.Now()) { + if genesisTime.Before(timeutils.Now()) { currentEpoch = slotutil.EpochsSinceGenesis(vs.GenesisTimeFetcher.GenesisTime()) } req.Epoch = currentEpoch @@ -199,7 +199,7 @@ func assignValidatorToSubnet(pubkey []byte, status ethpb.ValidatorStatus) { } _, ok, expTime := cache.SubnetIDs.GetPersistentSubnets(pubkey) - if ok && expTime.After(roughtime.Now()) { + if ok && expTime.After(timeutils.Now()) { return } epochDuration := time.Duration(params.BeaconConfig().SlotsPerEpoch * params.BeaconConfig().SecondsPerSlot) diff --git a/beacon-chain/rpc/validator/attester_test.go b/beacon-chain/rpc/validator/attester_test.go index 2f8097e09..988dd0804 100644 --- a/beacon-chain/rpc/validator/attester_test.go +++ b/beacon-chain/rpc/validator/attester_test.go @@ -22,10 +22,10 @@ import ( "github.com/prysmaticlabs/prysm/shared/bls" "github.com/prysmaticlabs/prysm/shared/bytesutil" "github.com/prysmaticlabs/prysm/shared/params" - "github.com/prysmaticlabs/prysm/shared/roughtime" "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" ) func TestProposeAttestation_OK(t *testing.T) { @@ -484,7 +484,7 @@ func TestGetAttestationData_SucceedsInFirstEpoch(t *testing.T) { FinalizationFetcher: &mock.ChainService{ CurrentJustifiedCheckPoint: beaconState.CurrentJustifiedCheckpoint(), }, - GenesisTimeFetcher: &mock.ChainService{Genesis: roughtime.Now().Add(time.Duration(-1*int64(slot*params.BeaconConfig().SecondsPerSlot)) * time.Second)}, + GenesisTimeFetcher: &mock.ChainService{Genesis: timeutils.Now().Add(time.Duration(-1*int64(slot*params.BeaconConfig().SecondsPerSlot)) * time.Second)}, StateNotifier: chainService.StateNotifier(), } require.NoError(t, db.SaveState(ctx, beaconState, blockRoot)) diff --git a/beacon-chain/sync/BUILD.bazel b/beacon-chain/sync/BUILD.bazel index e1365e47e..044bc05fa 100644 --- a/beacon-chain/sync/BUILD.bazel +++ b/beacon-chain/sync/BUILD.bazel @@ -73,10 +73,10 @@ go_library( "//shared/p2putils:go_default_library", "//shared/params:go_default_library", "//shared/rand:go_default_library", - "//shared/roughtime:go_default_library", "//shared/runutil:go_default_library", "//shared/sliceutil:go_default_library", "//shared/slotutil:go_default_library", + "//shared/timeutils:go_default_library", "//shared/traceutil:go_default_library", "@com_github_gogo_protobuf//proto:go_default_library", "@com_github_hashicorp_golang_lru//:go_default_library", @@ -154,10 +154,10 @@ go_test( "//shared/featureconfig:go_default_library", "//shared/params:go_default_library", "//shared/rand:go_default_library", - "//shared/roughtime:go_default_library", "//shared/testutil:go_default_library", "//shared/testutil/assert:go_default_library", "//shared/testutil/require:go_default_library", + "//shared/timeutils:go_default_library", "@com_github_ethereum_go_ethereum//p2p/enr:go_default_library", "@com_github_gogo_protobuf//proto:go_default_library", "@com_github_hashicorp_golang_lru//:go_default_library", diff --git a/beacon-chain/sync/initial-sync/BUILD.bazel b/beacon-chain/sync/initial-sync/BUILD.bazel index 2ae82047f..451716550 100644 --- a/beacon-chain/sync/initial-sync/BUILD.bazel +++ b/beacon-chain/sync/initial-sync/BUILD.bazel @@ -34,7 +34,7 @@ go_library( "//shared/mathutil:go_default_library", "//shared/params:go_default_library", "//shared/rand:go_default_library", - "//shared/roughtime:go_default_library", + "//shared/timeutils:go_default_library", "@com_github_kevinms_leakybucket_go//:go_default_library", "@com_github_libp2p_go_libp2p_core//helpers:go_default_library", "@com_github_libp2p_go_libp2p_core//mux:go_default_library", @@ -76,11 +76,11 @@ go_test( "//shared/featureconfig:go_default_library", "//shared/hashutil:go_default_library", "//shared/params:go_default_library", - "//shared/roughtime:go_default_library", "//shared/sliceutil:go_default_library", "//shared/testutil:go_default_library", "//shared/testutil/assert:go_default_library", "//shared/testutil/require:go_default_library", + "//shared/timeutils: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", @@ -120,11 +120,11 @@ go_test( "//shared/featureconfig:go_default_library", "//shared/hashutil:go_default_library", "//shared/params:go_default_library", - "//shared/roughtime:go_default_library", "//shared/sliceutil:go_default_library", "//shared/testutil:go_default_library", "//shared/testutil/assert:go_default_library", "//shared/testutil/require:go_default_library", + "//shared/timeutils: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", diff --git a/beacon-chain/sync/initial-sync/blocks_fetcher_peers.go b/beacon-chain/sync/initial-sync/blocks_fetcher_peers.go index b0f97eb91..8338f9282 100644 --- a/beacon-chain/sync/initial-sync/blocks_fetcher_peers.go +++ b/beacon-chain/sync/initial-sync/blocks_fetcher_peers.go @@ -13,7 +13,7 @@ import ( scorers "github.com/prysmaticlabs/prysm/beacon-chain/p2p/peers" "github.com/prysmaticlabs/prysm/shared/mathutil" "github.com/prysmaticlabs/prysm/shared/params" - "github.com/prysmaticlabs/prysm/shared/roughtime" + "github.com/prysmaticlabs/prysm/shared/timeutils" "github.com/sirupsen/logrus" "go.opencensus.io/trace" ) @@ -23,12 +23,12 @@ func (f *blocksFetcher) getPeerLock(pid peer.ID) *peerLock { f.Lock() defer f.Unlock() if lock, ok := f.peerLocks[pid]; ok { - lock.accessed = roughtime.Now() + lock.accessed = timeutils.Now() return lock } f.peerLocks[pid] = &peerLock{ Mutex: sync.Mutex{}, - accessed: roughtime.Now(), + accessed: timeutils.Now(), } return f.peerLocks[pid] } diff --git a/beacon-chain/sync/initial-sync/blocks_fetcher_test.go b/beacon-chain/sync/initial-sync/blocks_fetcher_test.go index 021bdb414..29cd4a867 100644 --- a/beacon-chain/sync/initial-sync/blocks_fetcher_test.go +++ b/beacon-chain/sync/initial-sync/blocks_fetcher_test.go @@ -24,11 +24,11 @@ import ( beaconsync "github.com/prysmaticlabs/prysm/beacon-chain/sync" p2ppb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1" "github.com/prysmaticlabs/prysm/shared/params" - "github.com/prysmaticlabs/prysm/shared/roughtime" "github.com/prysmaticlabs/prysm/shared/sliceutil" "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/sirupsen/logrus" ) @@ -1041,29 +1041,29 @@ func TestBlocksFetcher_removeStalePeerLocks(t *testing.T) { peersIn: []peerData{ { peerID: "a", - accessed: roughtime.Now(), + accessed: timeutils.Now(), }, { peerID: "b", - accessed: roughtime.Now(), + accessed: timeutils.Now(), }, { peerID: "c", - accessed: roughtime.Now(), + accessed: timeutils.Now(), }, }, peersOut: []peerData{ { peerID: "a", - accessed: roughtime.Now(), + accessed: timeutils.Now(), }, { peerID: "b", - accessed: roughtime.Now(), + accessed: timeutils.Now(), }, { peerID: "c", - accessed: roughtime.Now(), + accessed: timeutils.Now(), }, }, }, @@ -1073,25 +1073,25 @@ func TestBlocksFetcher_removeStalePeerLocks(t *testing.T) { peersIn: []peerData{ { peerID: "a", - accessed: roughtime.Now(), + accessed: timeutils.Now(), }, { peerID: "b", - accessed: roughtime.Now().Add(-peerLockMaxAge), + accessed: timeutils.Now().Add(-peerLockMaxAge), }, { peerID: "c", - accessed: roughtime.Now(), + accessed: timeutils.Now(), }, }, peersOut: []peerData{ { peerID: "a", - accessed: roughtime.Now(), + accessed: timeutils.Now(), }, { peerID: "c", - accessed: roughtime.Now(), + accessed: timeutils.Now(), }, }, }, @@ -1101,15 +1101,15 @@ func TestBlocksFetcher_removeStalePeerLocks(t *testing.T) { peersIn: []peerData{ { peerID: "a", - accessed: roughtime.Now().Add(-peerLockMaxAge), + accessed: timeutils.Now().Add(-peerLockMaxAge), }, { peerID: "b", - accessed: roughtime.Now().Add(-peerLockMaxAge), + accessed: timeutils.Now().Add(-peerLockMaxAge), }, { peerID: "c", - accessed: roughtime.Now().Add(-peerLockMaxAge), + accessed: timeutils.Now().Add(-peerLockMaxAge), }, }, peersOut: []peerData{}, diff --git a/beacon-chain/sync/initial-sync/fsm.go b/beacon-chain/sync/initial-sync/fsm.go index 48510bdf2..3aa079ccd 100644 --- a/beacon-chain/sync/initial-sync/fsm.go +++ b/beacon-chain/sync/initial-sync/fsm.go @@ -9,7 +9,7 @@ import ( "github.com/libp2p/go-libp2p-core/peer" eth "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" - "github.com/prysmaticlabs/prysm/shared/roughtime" + "github.com/prysmaticlabs/prysm/shared/timeutils" ) const ( @@ -78,7 +78,7 @@ func (smm *stateMachineManager) addStateMachine(start uint64) *stateMachine { start: start, state: stateNew, blocks: []*eth.SignedBeaconBlock{}, - updated: roughtime.Now(), + updated: timeutils.Now(), } smm.recalculateMachineAttribs() return smm.machines[start] @@ -157,7 +157,7 @@ func (m *stateMachine) setState(name stateID) { return } m.state = name - m.updated = roughtime.Now() + m.updated = timeutils.Now() } // trigger invokes the event handler on a given state machine. diff --git a/beacon-chain/sync/initial-sync/initial_sync_test.go b/beacon-chain/sync/initial-sync/initial_sync_test.go index f06915188..323d3420c 100644 --- a/beacon-chain/sync/initial-sync/initial_sync_test.go +++ b/beacon-chain/sync/initial-sync/initial_sync_test.go @@ -26,11 +26,11 @@ import ( "github.com/prysmaticlabs/prysm/shared/featureconfig" "github.com/prysmaticlabs/prysm/shared/hashutil" "github.com/prysmaticlabs/prysm/shared/params" - "github.com/prysmaticlabs/prysm/shared/roughtime" "github.com/prysmaticlabs/prysm/shared/sliceutil" "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/sirupsen/logrus" ) @@ -98,7 +98,7 @@ func initializeTestServices(t *testing.T, blocks []uint64, peers []*peerData) (* // makeGenesisTime where now is the current slot. func makeGenesisTime(currentSlot uint64) time.Time { - return roughtime.Now().Add(-1 * time.Second * time.Duration(currentSlot) * time.Duration(params.BeaconConfig().SecondsPerSlot)) + return timeutils.Now().Add(-1 * time.Second * time.Duration(currentSlot) * time.Duration(params.BeaconConfig().SecondsPerSlot)) } // sanity test on helper function diff --git a/beacon-chain/sync/initial-sync/service.go b/beacon-chain/sync/initial-sync/service.go index 1820d9c84..4d24e6c0d 100644 --- a/beacon-chain/sync/initial-sync/service.go +++ b/beacon-chain/sync/initial-sync/service.go @@ -19,7 +19,7 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/p2p" "github.com/prysmaticlabs/prysm/shared" "github.com/prysmaticlabs/prysm/shared/params" - "github.com/prysmaticlabs/prysm/shared/roughtime" + "github.com/prysmaticlabs/prysm/shared/timeutils" "github.com/sirupsen/logrus" ) @@ -92,7 +92,7 @@ func (s *Service) Start() { return } - if genesis.After(roughtime.Now()) { + if genesis.After(timeutils.Now()) { s.synced = true s.stateNotifier.StateFeed().Send(&feed.Event{ Type: statefeed.Synced, diff --git a/beacon-chain/sync/pending_attestations_queue_test.go b/beacon-chain/sync/pending_attestations_queue_test.go index 31e6b0a94..1fcd95d91 100644 --- a/beacon-chain/sync/pending_attestations_queue_test.go +++ b/beacon-chain/sync/pending_attestations_queue_test.go @@ -21,10 +21,10 @@ import ( "github.com/prysmaticlabs/prysm/shared/bls" "github.com/prysmaticlabs/prysm/shared/bytesutil" "github.com/prysmaticlabs/prysm/shared/params" - "github.com/prysmaticlabs/prysm/shared/roughtime" "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" logTest "github.com/sirupsen/logrus/hooks/test" ) @@ -42,7 +42,7 @@ func TestProcessPendingAtts_NoBlockRequestBlock(t *testing.T) { r := &Service{ p2p: p1, db: db, - chain: &mock.ChainService{Genesis: roughtime.Now(), FinalizedCheckPoint: ðpb.Checkpoint{}}, + chain: &mock.ChainService{Genesis: timeutils.Now(), FinalizedCheckPoint: ðpb.Checkpoint{}}, blkRootToPendingAtts: make(map[[32]byte][]*ethpb.SignedAggregateAttestationAndProof), stateSummaryCache: cache.NewStateSummaryCache(), } @@ -61,7 +61,7 @@ func TestProcessPendingAtts_HasBlockSaveUnAggregatedAtt(t *testing.T) { r := &Service{ p2p: p1, db: db, - chain: &mock.ChainService{Genesis: roughtime.Now()}, + chain: &mock.ChainService{Genesis: timeutils.Now()}, blkRootToPendingAtts: make(map[[32]byte][]*ethpb.SignedAggregateAttestationAndProof), attPool: attestations.NewPool(), stateSummaryCache: cache.NewStateSummaryCache(), @@ -105,7 +105,7 @@ func TestProcessPendingAtts_NoBroadcastWithBadSignature(t *testing.T) { r := &Service{ p2p: p1, db: db, - chain: &mock.ChainService{Genesis: roughtime.Now()}, + chain: &mock.ChainService{Genesis: timeutils.Now()}, blkRootToPendingAtts: make(map[[32]byte][]*ethpb.SignedAggregateAttestationAndProof), attPool: attestations.NewPool(), stateSummaryCache: cache.NewStateSummaryCache(), diff --git a/beacon-chain/sync/rpc.go b/beacon-chain/sync/rpc.go index cf585ef78..0bf7cde95 100644 --- a/beacon-chain/sync/rpc.go +++ b/beacon-chain/sync/rpc.go @@ -11,7 +11,7 @@ import ( "github.com/libp2p/go-libp2p-core/network" "github.com/prysmaticlabs/prysm/beacon-chain/p2p" "github.com/prysmaticlabs/prysm/shared/params" - "github.com/prysmaticlabs/prysm/shared/roughtime" + "github.com/prysmaticlabs/prysm/shared/timeutils" "github.com/prysmaticlabs/prysm/shared/traceutil" "go.opencensus.io/trace" ) @@ -75,7 +75,7 @@ func (s *Service) registerRPC(baseTopic string, handle rpcHandler) { span.AddAttributes(trace.StringAttribute("peer", stream.Conn().RemotePeer().Pretty())) log := log.WithField("peer", stream.Conn().RemotePeer().Pretty()) - if err := stream.SetReadDeadline(roughtime.Now().Add(ttfbTimeout)); err != nil { + if err := stream.SetReadDeadline(timeutils.Now().Add(ttfbTimeout)); err != nil { log.WithError(err).Debug("Could not set stream read deadline") return } diff --git a/beacon-chain/sync/rpc_ping.go b/beacon-chain/sync/rpc_ping.go index f7618241e..53e280eba 100644 --- a/beacon-chain/sync/rpc_ping.go +++ b/beacon-chain/sync/rpc_ping.go @@ -11,7 +11,7 @@ import ( "github.com/libp2p/go-libp2p-core/mux" "github.com/libp2p/go-libp2p-core/peer" "github.com/prysmaticlabs/prysm/beacon-chain/p2p" - "github.com/prysmaticlabs/prysm/shared/roughtime" + "github.com/prysmaticlabs/prysm/shared/timeutils" ) // pingHandler reads the incoming ping rpc message from the peer. @@ -95,7 +95,7 @@ func (s *Service) sendPingRequest(ctx context.Context, id peer.ID) error { if err != nil { return err } - currentTime := roughtime.Now() + currentTime := timeutils.Now() defer func() { if err := helpers.FullClose(stream); err != nil && err.Error() != mux.ErrReset.Error() { log.WithError(err).Debugf("Failed to reset stream with protocol %s", stream.Protocol()) @@ -107,7 +107,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.p2p.Host().Peerstore().RecordLatency(id, roughtime.Now().Sub(currentTime)) + s.p2p.Host().Peerstore().RecordLatency(id, timeutils.Now().Sub(currentTime)) if code != 0 { s.p2p.Peers().Scorers().BadResponsesScorer().Increment(stream.Conn().RemotePeer()) diff --git a/beacon-chain/sync/rpc_status.go b/beacon-chain/sync/rpc_status.go index bb36caa20..132318cab 100644 --- a/beacon-chain/sync/rpc_status.go +++ b/beacon-chain/sync/rpc_status.go @@ -18,9 +18,9 @@ import ( pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1" "github.com/prysmaticlabs/prysm/shared/bytesutil" "github.com/prysmaticlabs/prysm/shared/params" - "github.com/prysmaticlabs/prysm/shared/roughtime" "github.com/prysmaticlabs/prysm/shared/runutil" "github.com/prysmaticlabs/prysm/shared/slotutil" + "github.com/prysmaticlabs/prysm/shared/timeutils" "github.com/sirupsen/logrus" ) @@ -53,7 +53,7 @@ func (s *Service) maintainPeerStatuses() { // Peer has vanished; nothing to do. return } - if roughtime.Now().After(lastUpdated.Add(interval)) { + if timeutils.Now().After(lastUpdated.Add(interval)) { if err := s.reValidatePeer(s.ctx, id); err != nil { log.WithField("peer", id).WithError(err).Debug("Failed to revalidate peer") s.p2p.Peers().Scorers().BadResponsesScorer().Increment(id) diff --git a/beacon-chain/sync/rpc_status_test.go b/beacon-chain/sync/rpc_status_test.go index 24ada746a..6494ee4c7 100644 --- a/beacon-chain/sync/rpc_status_test.go +++ b/beacon-chain/sync/rpc_status_test.go @@ -24,10 +24,10 @@ import ( pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1" "github.com/prysmaticlabs/prysm/shared/bytesutil" "github.com/prysmaticlabs/prysm/shared/params" - "github.com/prysmaticlabs/prysm/shared/roughtime" "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" ) func TestStatusRPCHandler_Disconnects_OnForkVersionMismatch(t *testing.T) { @@ -673,7 +673,7 @@ func TestShouldResync(t *testing.T) { name: "genesis epoch should not resync when syncing is true", args: args{ headSlot: uint64(31), - genesis: roughtime.Now(), + genesis: timeutils.Now(), syncing: true, }, want: false, @@ -682,7 +682,7 @@ func TestShouldResync(t *testing.T) { name: "genesis epoch should not resync when syncing is false", args: args{ headSlot: uint64(31), - genesis: roughtime.Now(), + genesis: timeutils.Now(), syncing: false, }, want: false, @@ -691,7 +691,7 @@ func TestShouldResync(t *testing.T) { name: "two epochs behind, resync ok", args: args{ headSlot: uint64(31), - genesis: roughtime.Now().Add(-1 * 96 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second), + genesis: timeutils.Now().Add(-1 * 96 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second), syncing: false, }, want: true, @@ -700,7 +700,7 @@ func TestShouldResync(t *testing.T) { name: "two epochs behind, already syncing", args: args{ headSlot: uint64(31), - genesis: roughtime.Now().Add(-1 * 96 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second), + genesis: timeutils.Now().Add(-1 * 96 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second), syncing: true, }, want: false, diff --git a/beacon-chain/sync/service.go b/beacon-chain/sync/service.go index c9efb0878..6a900e8a9 100644 --- a/beacon-chain/sync/service.go +++ b/beacon-chain/sync/service.go @@ -28,8 +28,8 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/p2p" "github.com/prysmaticlabs/prysm/beacon-chain/state/stategen" "github.com/prysmaticlabs/prysm/shared" - "github.com/prysmaticlabs/prysm/shared/roughtime" "github.com/prysmaticlabs/prysm/shared/runutil" + "github.com/prysmaticlabs/prysm/shared/timeutils" ) var _ = shared.Service(&Service{}) @@ -249,9 +249,9 @@ func (s *Service) registerHandlers() { s.registerRPCHandlers() s.registerSubscribers() - if data.StartTime.After(roughtime.Now()) { + if data.StartTime.After(timeutils.Now()) { stateSub.Unsubscribe() - time.Sleep(roughtime.Until(data.StartTime)) + time.Sleep(timeutils.Until(data.StartTime)) } s.chainStarted = true } diff --git a/beacon-chain/sync/validate_beacon_blocks.go b/beacon-chain/sync/validate_beacon_blocks.go index f8eeb1b42..00d4e239a 100644 --- a/beacon-chain/sync/validate_beacon_blocks.go +++ b/beacon-chain/sync/validate_beacon_blocks.go @@ -14,7 +14,7 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/core/state" "github.com/prysmaticlabs/prysm/shared/bytesutil" "github.com/prysmaticlabs/prysm/shared/params" - "github.com/prysmaticlabs/prysm/shared/roughtime" + "github.com/prysmaticlabs/prysm/shared/timeutils" "github.com/prysmaticlabs/prysm/shared/traceutil" "go.opencensus.io/trace" ) @@ -203,7 +203,7 @@ func captureArrivalTimeMetric(genesisTime uint64, currentSlot uint64) error { if err != nil { return err } - diffMs := roughtime.Now().Sub(startTime) / time.Millisecond + diffMs := timeutils.Now().Sub(startTime) / time.Millisecond arrivalBlockPropagationHistogram.Observe(float64(diffMs)) return nil diff --git a/deps.bzl b/deps.bzl index 89da61e0f..28e397844 100644 --- a/deps.bzl +++ b/deps.bzl @@ -1889,13 +1889,6 @@ def prysm_deps(): sum = "h1:JTTnM6wKzdA0Jqodd966MVj4vWbbquZykeX1sKbe2C4=", version = "v2.2.0", ) - go_repository( - name = "com_googlesource_roughtime_roughtime_git", - build_file_generation = "on", - importpath = "roughtime.googlesource.com/roughtime.git", - sum = "h1:Cmz+zn5wHFlBz3sPMsCzjmsn4zKLMMRRxhqnlKQ/zfI=", - version = "v0.0.0-20190418172256-51f6971f5f06", - ) go_repository( name = "com_github_multiformats_go_base36", importpath = "github.com/multiformats/go-base36", diff --git a/endtoend/helpers/BUILD.bazel b/endtoend/helpers/BUILD.bazel index 885290a18..319a4a96e 100644 --- a/endtoend/helpers/BUILD.bazel +++ b/endtoend/helpers/BUILD.bazel @@ -12,6 +12,6 @@ go_library( deps = [ "//endtoend/params:go_default_library", "//endtoend/types:go_default_library", - "//shared/roughtime:go_default_library", + "//shared/timeutils:go_default_library", ], ) diff --git a/endtoend/helpers/epochTimer.go b/endtoend/helpers/epochTimer.go index c5fc17181..2de5b6fcc 100644 --- a/endtoend/helpers/epochTimer.go +++ b/endtoend/helpers/epochTimer.go @@ -3,7 +3,7 @@ package helpers import ( "time" - "github.com/prysmaticlabs/prysm/shared/roughtime" + "github.com/prysmaticlabs/prysm/shared/timeutils" ) // EpochTicker is a special ticker for timing epoch changes. @@ -36,7 +36,7 @@ func GetEpochTicker(genesisTime time.Time, secondsPerEpoch uint64) *EpochTicker c: make(chan uint64), done: make(chan struct{}), } - ticker.start(genesisTime, secondsPerEpoch, roughtime.Since, roughtime.Until, time.After) + ticker.start(genesisTime, secondsPerEpoch, timeutils.Since, timeutils.Until, time.After) return ticker } diff --git a/nogo_config.json b/nogo_config.json index 787fa73e5..461447e80 100644 --- a/nogo_config.json +++ b/nogo_config.json @@ -67,22 +67,6 @@ "proto/.*": "Excluding protobuf objects for now" } }, - "roughtime": { - "only_files": { - "beacon-chain/.*": "", - "shared/.*": "", - "validator/.*": "" - }, - "exclude_files": { - ".*/.*_test\\.go": "Tests are OK to use time.Now()", - "shared/version/version\\.go": "Used for printing build time", - "shared/roughtime/roughtime\\.go": "Required to bootstrap roughtime", - "beacon-chain/blockchain/testing/*": "Test-only package", - "beacon-chain/p2p/sender\\.go": "Libp2p uses time.Now and this file sets a time based deadline in such a way that roughtime cannot be used", - "beacon-chain/sync/deadlines\\.go": "Libp2p uses time.Now and this file sets a time based deadline in such a way that roughtime cannot be used", - "shared/grpcutils/grpcutils\\.go": "Uses time.Now() for gRPC duration logging" - } - }, "errcheck": { "exclude_files": { "external/.*": "Third party code", diff --git a/shared/aggregation/testing/BUILD.bazel b/shared/aggregation/testing/BUILD.bazel index dfc007821..519df4ef3 100644 --- a/shared/aggregation/testing/BUILD.bazel +++ b/shared/aggregation/testing/BUILD.bazel @@ -7,7 +7,7 @@ go_library( visibility = ["//visibility:public"], deps = [ "//shared/bls:go_default_library", - "//shared/roughtime:go_default_library", + "//shared/timeutils:go_default_library", "@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library", "@com_github_prysmaticlabs_go_bitfield//:go_default_library", ], diff --git a/shared/aggregation/testing/bitlistutils.go b/shared/aggregation/testing/bitlistutils.go index 361bfd184..6a192b599 100644 --- a/shared/aggregation/testing/bitlistutils.go +++ b/shared/aggregation/testing/bitlistutils.go @@ -7,7 +7,7 @@ import ( ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1" "github.com/prysmaticlabs/go-bitfield" "github.com/prysmaticlabs/prysm/shared/bls" - "github.com/prysmaticlabs/prysm/shared/roughtime" + "github.com/prysmaticlabs/prysm/shared/timeutils" ) // BitlistWithAllBitsSet creates list of bitlists with all bits set. @@ -32,7 +32,7 @@ func BitlistsWithSingleBitSet(t testing.TB, n, length uint64) []bitfield.Bitlist // BitlistsWithMultipleBitSet creates list of bitlists with random n bits set. func BitlistsWithMultipleBitSet(t testing.TB, n, length, count uint64) []bitfield.Bitlist { - seed := roughtime.Now().UnixNano() + seed := timeutils.Now().UnixNano() t.Logf("bitlistsWithMultipleBitSet random seed: %v", seed) rand.Seed(seed) lists := make([]bitfield.Bitlist, n) diff --git a/shared/interop/BUILD.bazel b/shared/interop/BUILD.bazel index 85d6e201f..6f03e70fc 100644 --- a/shared/interop/BUILD.bazel +++ b/shared/interop/BUILD.bazel @@ -17,7 +17,7 @@ go_library( "//shared/hashutil:go_default_library", "//shared/mputil:go_default_library", "//shared/params:go_default_library", - "//shared/roughtime:go_default_library", + "//shared/timeutils:go_default_library", "//shared/trieutil:go_default_library", "@com_github_pkg_errors//:go_default_library", "@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library", diff --git a/shared/interop/generate_genesis_state.go b/shared/interop/generate_genesis_state.go index 135d67548..5fa59204d 100644 --- a/shared/interop/generate_genesis_state.go +++ b/shared/interop/generate_genesis_state.go @@ -15,7 +15,7 @@ import ( "github.com/prysmaticlabs/prysm/shared/hashutil" "github.com/prysmaticlabs/prysm/shared/mputil" "github.com/prysmaticlabs/prysm/shared/params" - "github.com/prysmaticlabs/prysm/shared/roughtime" + "github.com/prysmaticlabs/prysm/shared/timeutils" "github.com/prysmaticlabs/prysm/shared/trieutil" ) @@ -49,7 +49,7 @@ func GenerateGenesisState(genesisTime, numValidators uint64) (*pb.BeaconState, [ } root := trie.Root() if genesisTime == 0 { - genesisTime = uint64(roughtime.Now().Unix()) + genesisTime = uint64(timeutils.Now().Unix()) } beaconState, err := state.GenesisBeaconState(deposits, genesisTime, ðpb.Eth1Data{ DepositRoot: root[:], diff --git a/shared/keystore/BUILD.bazel b/shared/keystore/BUILD.bazel index e5ee1207a..5d8115449 100644 --- a/shared/keystore/BUILD.bazel +++ b/shared/keystore/BUILD.bazel @@ -14,7 +14,7 @@ go_library( deps = [ "//shared/bls:go_default_library", "//shared/params:go_default_library", - "//shared/roughtime:go_default_library", + "//shared/timeutils: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", diff --git a/shared/keystore/utils.go b/shared/keystore/utils.go index 260946b84..77bfe97d5 100644 --- a/shared/keystore/utils.go +++ b/shared/keystore/utils.go @@ -26,7 +26,7 @@ import ( "time" "github.com/prysmaticlabs/prysm/shared/bls" - "github.com/prysmaticlabs/prysm/shared/roughtime" + "github.com/prysmaticlabs/prysm/shared/timeutils" ) 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--- func keyFileName(pubkey bls.PublicKey) string { - ts := roughtime.Now().UTC() + ts := timeutils.Now().UTC() return fmt.Sprintf("UTC--%s--%s", toISO8601(ts), hex.EncodeToString(pubkey.Marshal())[:8]) } diff --git a/shared/slotutil/BUILD.bazel b/shared/slotutil/BUILD.bazel index dfd5efe06..9318f4968 100644 --- a/shared/slotutil/BUILD.bazel +++ b/shared/slotutil/BUILD.bazel @@ -12,7 +12,7 @@ go_library( visibility = ["//visibility:public"], deps = [ "//shared/params:go_default_library", - "//shared/roughtime:go_default_library", + "//shared/timeutils:go_default_library", "@com_github_sirupsen_logrus//:go_default_library", ], ) @@ -29,8 +29,8 @@ go_test( embed = [":go_default_library"], deps = [ "//shared/params:go_default_library", - "//shared/roughtime:go_default_library", "//shared/testutil/require:go_default_library", + "//shared/timeutils:go_default_library", "@com_github_sirupsen_logrus//:go_default_library", "@com_github_sirupsen_logrus//hooks/test:go_default_library", ], diff --git a/shared/slotutil/countdown.go b/shared/slotutil/countdown.go index a0d269ba2..3a3e4a69d 100644 --- a/shared/slotutil/countdown.go +++ b/shared/slotutil/countdown.go @@ -6,7 +6,7 @@ import ( "time" "github.com/prysmaticlabs/prysm/shared/params" - "github.com/prysmaticlabs/prysm/shared/roughtime" + "github.com/prysmaticlabs/prysm/shared/timeutils" "github.com/sirupsen/logrus" ) @@ -28,7 +28,7 @@ func CountdownToGenesis(ctx context.Context, genesisTime time.Time, genesisValid } secondTimerActivated := false for { - currentTime := roughtime.Now() + currentTime := timeutils.Now() if currentTime.After(genesisTime) { log.WithFields(logFields).Info("Chain genesis time reached") return diff --git a/shared/slotutil/countdown_test.go b/shared/slotutil/countdown_test.go index 0e0684898..2a1a43054 100644 --- a/shared/slotutil/countdown_test.go +++ b/shared/slotutil/countdown_test.go @@ -6,8 +6,8 @@ import ( "time" "github.com/prysmaticlabs/prysm/shared/params" - "github.com/prysmaticlabs/prysm/shared/roughtime" "github.com/prysmaticlabs/prysm/shared/testutil/require" + "github.com/prysmaticlabs/prysm/shared/timeutils" logTest "github.com/sirupsen/logrus/hooks/test" ) @@ -24,7 +24,7 @@ func TestCountdownToGenesis(t *testing.T) { genesisReached := "Chain genesis time reached" CountdownToGenesis( context.Background(), - roughtime.Now().Add(2*time.Second), + timeutils.Now().Add(2*time.Second), params.BeaconConfig().MinGenesisActiveValidatorCount, ) require.LogsContain(t, hook, firstStringResult) @@ -41,7 +41,7 @@ func TestCountdownToGenesis(t *testing.T) { }() CountdownToGenesis( ctx, - roughtime.Now().Add(5*time.Second), + timeutils.Now().Add(5*time.Second), params.BeaconConfig().MinGenesisActiveValidatorCount, ) require.LogsContain(t, hook, "4s until chain genesis") diff --git a/shared/slotutil/slotticker.go b/shared/slotutil/slotticker.go index 51bc4ed6d..c859346c0 100644 --- a/shared/slotutil/slotticker.go +++ b/shared/slotutil/slotticker.go @@ -4,7 +4,7 @@ package slotutil import ( "time" - "github.com/prysmaticlabs/prysm/shared/roughtime" + "github.com/prysmaticlabs/prysm/shared/timeutils" ) // The Ticker interface defines a type which can expose a @@ -47,7 +47,7 @@ func GetSlotTicker(genesisTime time.Time, secondsPerSlot uint64) *SlotTicker { c: make(chan uint64), done: make(chan struct{}), } - ticker.start(genesisTime, secondsPerSlot, roughtime.Since, roughtime.Until, time.After) + ticker.start(genesisTime, secondsPerSlot, timeutils.Since, timeutils.Until, time.After) return ticker } @@ -64,7 +64,7 @@ func GetSlotTickerWithOffset(genesisTime time.Time, offset time.Duration, second c: make(chan uint64), done: make(chan struct{}), } - ticker.start(genesisTime.Add(offset), secondsPerSlot, roughtime.Since, roughtime.Until, time.After) + ticker.start(genesisTime.Add(offset), secondsPerSlot, timeutils.Since, timeutils.Until, time.After) return ticker } diff --git a/shared/slotutil/slottime.go b/shared/slotutil/slottime.go index 8bece8085..74314dc41 100644 --- a/shared/slotutil/slottime.go +++ b/shared/slotutil/slottime.go @@ -4,7 +4,7 @@ import ( "time" "github.com/prysmaticlabs/prysm/shared/params" - "github.com/prysmaticlabs/prysm/shared/roughtime" + "github.com/prysmaticlabs/prysm/shared/timeutils" ) // SlotStartTime returns the start time in terms of its unix epoch @@ -18,10 +18,10 @@ func SlotStartTime(genesis uint64, slot uint64) time.Time { // SlotsSinceGenesis returns the number of slots since // the provided genesis time. func SlotsSinceGenesis(genesis time.Time) uint64 { - if genesis.After(roughtime.Now()) { // Genesis has not occurred yet. + if genesis.After(timeutils.Now()) { // Genesis has not occurred yet. return 0 } - return uint64(roughtime.Since(genesis).Seconds()) / params.BeaconConfig().SecondsPerSlot + return uint64(timeutils.Since(genesis).Seconds()) / params.BeaconConfig().SecondsPerSlot } // EpochsSinceGenesis returns the number of slots since diff --git a/shared/slotutil/slottime_test.go b/shared/slotutil/slottime_test.go index ca3d22b01..21c0f57d4 100644 --- a/shared/slotutil/slottime_test.go +++ b/shared/slotutil/slottime_test.go @@ -5,7 +5,7 @@ import ( "time" "github.com/prysmaticlabs/prysm/shared/params" - "github.com/prysmaticlabs/prysm/shared/roughtime" + "github.com/prysmaticlabs/prysm/shared/timeutils" ) func TestSlotsSinceGenesis(t *testing.T) { @@ -20,14 +20,14 @@ func TestSlotsSinceGenesis(t *testing.T) { { name: "pre-genesis", args: args{ - genesis: roughtime.Now().Add(1 * time.Hour), // 1 hour in the future + genesis: timeutils.Now().Add(1 * time.Hour), // 1 hour in the future }, want: 0, }, { name: "post-genesis", args: args{ - genesis: roughtime.Now().Add(-5 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second), + genesis: timeutils.Now().Add(-5 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second), }, want: 5, }, diff --git a/shared/roughtime/BUILD.bazel b/shared/timeutils/BUILD.bazel similarity index 58% rename from shared/roughtime/BUILD.bazel rename to shared/timeutils/BUILD.bazel index ac5cb4035..dfebcd028 100644 --- a/shared/roughtime/BUILD.bazel +++ b/shared/timeutils/BUILD.bazel @@ -2,7 +2,7 @@ load("@prysm//tools/go:def.bzl", "go_library") go_library( name = "go_default_library", - srcs = ["roughtime.go"], - importpath = "github.com/prysmaticlabs/prysm/shared/roughtime", + srcs = ["utils.go"], + importpath = "github.com/prysmaticlabs/prysm/shared/timeutils", visibility = ["//visibility:public"], ) diff --git a/shared/roughtime/roughtime.go b/shared/timeutils/utils.go similarity index 75% rename from shared/roughtime/roughtime.go rename to shared/timeutils/utils.go index 249b414b7..7c7dd051e 100644 --- a/shared/roughtime/roughtime.go +++ b/shared/timeutils/utils.go @@ -1,5 +1,5 @@ -// Package roughtime is a soon to be deprecated wrapper for the local clock time. -package roughtime +// Package timeutils is a wrapper around the go standard time library. +package timeutils import ( "time" diff --git a/tools/analyzers/roughtime/BUILD.bazel b/tools/analyzers/roughtime/BUILD.bazel deleted file mode 100644 index bde313f67..000000000 --- a/tools/analyzers/roughtime/BUILD.bazel +++ /dev/null @@ -1,26 +0,0 @@ -load("@prysm//tools/go:def.bzl", "go_library") -load("@io_bazel_rules_go//go:def.bzl", "go_tool_library") - -go_library( - name = "go_default_library", - srcs = ["analyzer.go"], - importpath = "github.com/prysmaticlabs/prysm/tools/analyzers/roughtime", - visibility = ["//visibility:public"], - deps = [ - "@org_golang_x_tools//go/analysis:go_default_library", - "@org_golang_x_tools//go/analysis/passes/inspect:go_default_library", - "@org_golang_x_tools//go/ast/inspector:go_default_library", - ], -) - -go_tool_library( - name = "go_tool_library", - srcs = ["analyzer.go"], - importpath = "github.com/prysmaticlabs/prysm/tools/analyzers/roughtime", - visibility = ["//visibility:public"], - deps = [ - "@org_golang_x_tools//go/analysis:go_tool_library", - "@org_golang_x_tools//go/analysis/passes/inspect:go_tool_library", - "@org_golang_x_tools//go/ast/inspector:go_tool_library", - ], -) diff --git a/tools/analyzers/roughtime/analyzer.go b/tools/analyzers/roughtime/analyzer.go deleted file mode 100644 index a6d6dbb5f..000000000 --- a/tools/analyzers/roughtime/analyzer.go +++ /dev/null @@ -1,56 +0,0 @@ -package roughtime - -import ( - "errors" - "go/ast" - - "golang.org/x/tools/go/analysis" - "golang.org/x/tools/go/analysis/passes/inspect" - "golang.org/x/tools/go/ast/inspector" -) - -// Doc explaining the tool. -const Doc = "Tool to enforce the use of roughtime.Now() rather than time.Now(). This is " + - "critically important to certain ETH2 systems where the client / server must be in sync with " + - "some NTP network." - -// Analyzer runs static analysis. -var Analyzer = &analysis.Analyzer{ - Name: "roughtime", - Doc: Doc, - Requires: []*analysis.Analyzer{inspect.Analyzer}, - Run: run, -} - -func run(pass *analysis.Pass) (interface{}, error) { - inspect, ok := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector) - if !ok { - return nil, errors.New("analyzer is not type *inspector.Inspector") - } - - nodeFilter := []ast.Node{ - (*ast.CallExpr)(nil), - } - - inspect.Preorder(nodeFilter, func(node ast.Node) { - if ce, ok := node.(*ast.CallExpr); ok { - if isPkgDot(ce.Fun, "time", "Now") { - pass.Reportf(node.Pos(), "Do not use time.Now(), use "+ - "github.com/prysmaticlabs/prysm/shared/roughtime.Now() or add an exclusion "+ - "to //:nogo.json.") - } - } - }) - - return nil, nil -} - -func isPkgDot(expr ast.Expr, pkg, name string) bool { - sel, ok := expr.(*ast.SelectorExpr) - return ok && isIdent(sel.X, pkg) && isIdent(sel.Sel, name) -} - -func isIdent(expr ast.Expr, ident string) bool { - id, ok := expr.(*ast.Ident) - return ok && id.Name == ident -} diff --git a/tools/faucet/BUILD.bazel b/tools/faucet/BUILD.bazel index 778beeaae..eddad8bf9 100644 --- a/tools/faucet/BUILD.bazel +++ b/tools/faucet/BUILD.bazel @@ -13,7 +13,7 @@ SRCS = [ DEPS = [ "//proto/faucet:faucet_go_proto", - "//shared/roughtime:go_default_library", + "//shared/timeutils:go_default_library", "//shared/maxprocs:go_default_library", "@org_golang_google_grpc//:go_default_library", "@org_golang_google_grpc//peer:go_default_library", diff --git a/tools/faucet/server.go b/tools/faucet/server.go index cf6369dce..8be19b91a 100644 --- a/tools/faucet/server.go +++ b/tools/faucet/server.go @@ -18,7 +18,7 @@ import ( "github.com/ethereum/go-ethereum/params" "github.com/prestonvanloon/go-recaptcha" faucetpb "github.com/prysmaticlabs/prysm/proto/faucet" - "github.com/prysmaticlabs/prysm/shared/roughtime" + "github.com/prysmaticlabs/prysm/shared/timeutils" "google.golang.org/grpc/metadata" ) @@ -98,7 +98,7 @@ func (s *faucetServer) verifyRecaptcha(peer string, req *faucetpb.FundingRequest if rr.Score < s.minScore { return fmt.Errorf("recaptcha score too low (%f)", rr.Score) } - if roughtime.Now().After(rr.ChallengeTS.Add(2 * time.Minute)) { + if timeutils.Now().After(rr.ChallengeTS.Add(2 * time.Minute)) { return errors.New("captcha challenge too old") } if rr.Action != req.WalletAddress { diff --git a/tools/update-genesis-time/BUILD.bazel b/tools/update-genesis-time/BUILD.bazel index e9fd92b72..5ae370efe 100644 --- a/tools/update-genesis-time/BUILD.bazel +++ b/tools/update-genesis-time/BUILD.bazel @@ -8,7 +8,7 @@ go_library( visibility = ["//visibility:public"], deps = [ "//proto/beacon/p2p/v1:go_default_library", - "//shared/roughtime:go_default_library", + "//shared/timeutils:go_default_library", "@com_github_prysmaticlabs_go_ssz//:go_default_library", ], ) diff --git a/tools/update-genesis-time/main.go b/tools/update-genesis-time/main.go index a6a26c062..75755f836 100644 --- a/tools/update-genesis-time/main.go +++ b/tools/update-genesis-time/main.go @@ -7,7 +7,7 @@ import ( "github.com/prysmaticlabs/go-ssz" pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1" - "github.com/prysmaticlabs/prysm/shared/roughtime" + "github.com/prysmaticlabs/prysm/shared/timeutils" ) var ( @@ -27,7 +27,7 @@ func main() { } if *genesisTime == 0 { log.Print("No --genesis-time specified, defaulting to now") - beaconState.GenesisTime = uint64(roughtime.Now().Unix()) + beaconState.GenesisTime = uint64(timeutils.Now().Unix()) } else { beaconState.GenesisTime = *genesisTime } diff --git a/validator/accounts/v2/BUILD.bazel b/validator/accounts/v2/BUILD.bazel index 26b017d5c..60980d2e0 100644 --- a/validator/accounts/v2/BUILD.bazel +++ b/validator/accounts/v2/BUILD.bazel @@ -81,10 +81,10 @@ go_test( "//shared/params:go_default_library", "//shared/petnames:go_default_library", "//shared/promptutil:go_default_library", - "//shared/roughtime:go_default_library", "//shared/testutil:go_default_library", "//shared/testutil/assert:go_default_library", "//shared/testutil/require:go_default_library", + "//shared/timeutils:go_default_library", "//validator/accounts/v2/wallet:go_default_library", "//validator/flags:go_default_library", "//validator/keymanager/v2:go_default_library", diff --git a/validator/accounts/v2/accounts_import_test.go b/validator/accounts/v2/accounts_import_test.go index 173401b6d..37318d063 100644 --- a/validator/accounts/v2/accounts_import_test.go +++ b/validator/accounts/v2/accounts_import_test.go @@ -16,10 +16,10 @@ import ( "github.com/prysmaticlabs/prysm/shared/bls" "github.com/prysmaticlabs/prysm/shared/bytesutil" "github.com/prysmaticlabs/prysm/shared/params" - "github.com/prysmaticlabs/prysm/shared/roughtime" "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/validator/accounts/v2/wallet" v2keymanager "github.com/prysmaticlabs/prysm/validator/keymanager/v2" "github.com/prysmaticlabs/prysm/validator/keymanager/v2/direct" @@ -341,7 +341,7 @@ func createKeystore(t *testing.T, path string) (*v2keymanager.Keystore, string) encoded, err := json.MarshalIndent(keystoreFile, "", "\t") require.NoError(t, err) // Write the encoded keystore to disk with the timestamp appended - createdAt := roughtime.Now().Unix() + createdAt := timeutils.Now().Unix() fullPath := filepath.Join(path, fmt.Sprintf(direct.KeystoreFileNameFormat, createdAt)) require.NoError(t, ioutil.WriteFile(fullPath, encoded, os.ModePerm)) return keystoreFile, fullPath diff --git a/validator/client/BUILD.bazel b/validator/client/BUILD.bazel index 3ac60f926..7163a6e1e 100644 --- a/validator/client/BUILD.bazel +++ b/validator/client/BUILD.bazel @@ -30,8 +30,8 @@ go_library( "//shared/grpcutils:go_default_library", "//shared/hashutil:go_default_library", "//shared/params:go_default_library", - "//shared/roughtime:go_default_library", "//shared/slotutil:go_default_library", + "//shared/timeutils:go_default_library", "//validator/accounts/v2/wallet:go_default_library", "//validator/db:go_default_library", "//validator/keymanager/v1:go_default_library", @@ -90,11 +90,11 @@ go_test( "//shared/keystore:go_default_library", "//shared/mock:go_default_library", "//shared/params:go_default_library", - "//shared/roughtime:go_default_library", "//shared/slotutil:go_default_library", "//shared/testutil:go_default_library", "//shared/testutil/assert:go_default_library", "//shared/testutil/require:go_default_library", + "//shared/timeutils:go_default_library", "//validator/accounts/v1:go_default_library", "//validator/db/testing:go_default_library", "//validator/keymanager/v1:go_default_library", diff --git a/validator/client/aggregate.go b/validator/client/aggregate.go index 902302c1f..72a0690d1 100644 --- a/validator/client/aggregate.go +++ b/validator/client/aggregate.go @@ -12,8 +12,8 @@ import ( "github.com/prysmaticlabs/prysm/shared/bls" "github.com/prysmaticlabs/prysm/shared/featureconfig" "github.com/prysmaticlabs/prysm/shared/params" - "github.com/prysmaticlabs/prysm/shared/roughtime" "github.com/prysmaticlabs/prysm/shared/slotutil" + "github.com/prysmaticlabs/prysm/shared/timeutils" "go.opencensus.io/trace" ) @@ -153,7 +153,7 @@ func (v *validator) waitToSlotTwoThirds(ctx context.Context, slot uint64) { startTime := slotutil.SlotStartTime(v.genesisTime, slot) finalTime := startTime.Add(delay) - time.Sleep(roughtime.Until(finalTime)) + time.Sleep(timeutils.Until(finalTime)) } // This returns the signature of validator signing over aggregate and diff --git a/validator/client/aggregate_test.go b/validator/client/aggregate_test.go index e4d28e2a2..45489a1dc 100644 --- a/validator/client/aggregate_test.go +++ b/validator/client/aggregate_test.go @@ -10,10 +10,10 @@ import ( "github.com/prysmaticlabs/go-bitfield" "github.com/prysmaticlabs/prysm/shared/bls" "github.com/prysmaticlabs/prysm/shared/params" - "github.com/prysmaticlabs/prysm/shared/roughtime" "github.com/prysmaticlabs/prysm/shared/slotutil" "github.com/prysmaticlabs/prysm/shared/testutil/assert" "github.com/prysmaticlabs/prysm/shared/testutil/require" + "github.com/prysmaticlabs/prysm/shared/timeutils" logTest "github.com/sirupsen/logrus/hooks/test" ) @@ -122,7 +122,7 @@ func TestSubmitAggregateAndProof_Ok(t *testing.T) { func TestWaitForSlotTwoThird_WaitCorrectly(t *testing.T) { validator, _, finish := setup(t) defer finish() - currentTime := roughtime.Now() + currentTime := timeutils.Now() numOfSlots := uint64(4) validator.genesisTime = uint64(currentTime.Unix()) - (numOfSlots * params.BeaconConfig().SecondsPerSlot) oneThird := slotutil.DivideSlotBy(3 /* one third of slot duration */) @@ -130,7 +130,7 @@ func TestWaitForSlotTwoThird_WaitCorrectly(t *testing.T) { twoThirdTime := currentTime.Add(timeToSleep) validator.waitToSlotTwoThirds(context.Background(), numOfSlots) - currentTime = roughtime.Now() + currentTime = timeutils.Now() assert.Equal(t, twoThirdTime.Unix(), currentTime.Unix()) } diff --git a/validator/client/attest.go b/validator/client/attest.go index 8b9a5e41a..8ddb612d8 100644 --- a/validator/client/attest.go +++ b/validator/client/attest.go @@ -16,8 +16,8 @@ import ( "github.com/prysmaticlabs/prysm/shared/featureconfig" "github.com/prysmaticlabs/prysm/shared/hashutil" "github.com/prysmaticlabs/prysm/shared/params" - "github.com/prysmaticlabs/prysm/shared/roughtime" "github.com/prysmaticlabs/prysm/shared/slotutil" + "github.com/prysmaticlabs/prysm/shared/timeutils" keymanager "github.com/prysmaticlabs/prysm/validator/keymanager/v1" "github.com/sirupsen/logrus" "go.opencensus.io/trace" @@ -226,5 +226,5 @@ func (v *validator) waitToSlotOneThird(ctx context.Context, slot uint64) { delay := slotutil.DivideSlotBy(3 /* a third of the slot duration */) startTime := slotutil.SlotStartTime(v.genesisTime, slot) finalTime := startTime.Add(delay) - time.Sleep(roughtime.Until(finalTime)) + time.Sleep(timeutils.Until(finalTime)) } diff --git a/validator/client/attest_test.go b/validator/client/attest_test.go index a04620c0b..a8493b00f 100644 --- a/validator/client/attest_test.go +++ b/validator/client/attest_test.go @@ -14,9 +14,9 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/shared/bytesutil" "github.com/prysmaticlabs/prysm/shared/featureconfig" - "github.com/prysmaticlabs/prysm/shared/roughtime" "github.com/prysmaticlabs/prysm/shared/testutil/assert" "github.com/prysmaticlabs/prysm/shared/testutil/require" + "github.com/prysmaticlabs/prysm/shared/timeutils" logTest "github.com/sirupsen/logrus/hooks/test" "gopkg.in/d4l3k/messagediff.v1" ) @@ -308,7 +308,7 @@ func TestAttestToBlockHead_DoesNotAttestBeforeDelay(t *testing.T) { validator, m, finish := setup(t) defer finish() - validator.genesisTime = uint64(roughtime.Now().Unix()) + validator.genesisTime = uint64(timeutils.Now().Unix()) m.validatorClient.EXPECT().GetDuties( gomock.Any(), // ctx gomock.AssignableToTypeOf(ðpb.DutiesRequest{}), @@ -338,7 +338,7 @@ func TestAttestToBlockHead_DoesAttestAfterDelay(t *testing.T) { wg.Add(1) defer wg.Wait() - validator.genesisTime = uint64(roughtime.Now().Unix()) + validator.genesisTime = uint64(timeutils.Now().Unix()) validatorIndex := uint64(5) committee := []uint64{0, 3, 4, 2, validatorIndex, 6, 8, 9, 10} validator.duties = ðpb.DutiesResponse{Duties: []*ethpb.DutiesResponse_Duty{ diff --git a/validator/client/mock_validator.go b/validator/client/mock_validator.go index 887c5de7c..3fc8c39a1 100644 --- a/validator/client/mock_validator.go +++ b/validator/client/mock_validator.go @@ -5,7 +5,7 @@ import ( "time" ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1" - "github.com/prysmaticlabs/prysm/shared/roughtime" + "github.com/prysmaticlabs/prysm/shared/timeutils" ) var _ = Validator(&FakeValidator{}) @@ -93,7 +93,7 @@ func (fv *FakeValidator) CanonicalHeadSlot(_ context.Context) (uint64, error) { // SlotDeadline for mocking. func (fv *FakeValidator) SlotDeadline(_ uint64) time.Time { fv.SlotDeadlineCalled = true - return roughtime.Now() + return timeutils.Now() } // NextSlot for mocking. diff --git a/validator/client/propose.go b/validator/client/propose.go index 2ea3aaa22..90178be9e 100644 --- a/validator/client/propose.go +++ b/validator/client/propose.go @@ -14,7 +14,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/roughtime" + "github.com/prysmaticlabs/prysm/shared/timeutils" km "github.com/prysmaticlabs/prysm/validator/keymanager/v1" "github.com/sirupsen/logrus" "go.opencensus.io/trace" @@ -142,7 +142,7 @@ func ProposeExit( if err != nil { return errors.Wrap(err, "gRPC call to get genesis time failed") } - totalSecondsPassed := roughtime.Now().Unix() - genesisResponse.GenesisTime.Seconds + totalSecondsPassed := timeutils.Now().Unix() - genesisResponse.GenesisTime.Seconds currentEpoch := uint64(totalSecondsPassed) / (params.BeaconConfig().SecondsPerSlot * params.BeaconConfig().SlotsPerEpoch) exit := ðpb.VoluntaryExit{Epoch: currentEpoch, ValidatorIndex: indexResponse.Index} diff --git a/validator/rpc/BUILD.bazel b/validator/rpc/BUILD.bazel index 9ef4f7d54..03a0417e0 100644 --- a/validator/rpc/BUILD.bazel +++ b/validator/rpc/BUILD.bazel @@ -19,7 +19,7 @@ go_library( "//shared/petnames:go_default_library", "//shared/promptutil:go_default_library", "//shared/rand:go_default_library", - "//shared/roughtime:go_default_library", + "//shared/timeutils:go_default_library", "//shared/traceutil:go_default_library", "//validator/accounts/v2:go_default_library", "//validator/accounts/v2/wallet:go_default_library", diff --git a/validator/rpc/auth.go b/validator/rpc/auth.go index 4b69e228e..016e2e00b 100644 --- a/validator/rpc/auth.go +++ b/validator/rpc/auth.go @@ -12,7 +12,7 @@ import ( pb "github.com/prysmaticlabs/prysm/proto/validator/accounts/v2" "github.com/prysmaticlabs/prysm/shared/promptutil" - "github.com/prysmaticlabs/prysm/shared/roughtime" + "github.com/prysmaticlabs/prysm/shared/timeutils" "github.com/prysmaticlabs/prysm/validator/accounts/v2/wallet" ) @@ -95,7 +95,7 @@ func (s *Server) sendAuthResponse() (*pb.AuthResponse, error) { func (s *Server) createTokenString() (string, uint64, error) { // Create a new token object, specifying signing method and the claims // you would like it to contain. - expirationTime := roughtime.Now().Add(tokenExpiryLength) + expirationTime := timeutils.Now().Add(tokenExpiryLength) token := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.StandardClaims{ ExpiresAt: expirationTime.Unix(), })