mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-22 03:30:35 +00:00
Replace Roughtime With Timeutils Across Prysm (#7301)
* remove roughtime * change all references * rename Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
This commit is contained in:
parent
1a4129f5a6
commit
719e99ffd9
@ -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",
|
||||
|
@ -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",
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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")
|
||||
|
@ -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)
|
||||
|
@ -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",
|
||||
|
@ -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.
|
||||
|
@ -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",
|
||||
},
|
||||
|
@ -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
|
||||
|
@ -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")
|
||||
|
@ -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",
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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")
|
||||
}
|
||||
|
@ -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",
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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",
|
||||
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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")
|
||||
|
@ -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.
|
||||
|
@ -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",
|
||||
|
@ -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")
|
||||
|
@ -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",
|
||||
|
@ -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,
|
||||
|
@ -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",
|
||||
|
@ -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)
|
||||
|
@ -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))
|
||||
|
@ -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",
|
||||
|
@ -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",
|
||||
|
@ -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]
|
||||
}
|
||||
|
@ -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{},
|
||||
|
@ -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.
|
||||
|
@ -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
|
||||
|
@ -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,
|
||||
|
@ -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(),
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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())
|
||||
|
@ -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)
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
|
7
deps.bzl
7
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",
|
||||
|
@ -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",
|
||||
],
|
||||
)
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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",
|
||||
|
@ -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",
|
||||
],
|
||||
|
@ -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)
|
||||
|
@ -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",
|
||||
|
@ -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[:],
|
||||
|
@ -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",
|
||||
|
@ -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--<created_at UTC ISO8601>-<first 8 character of address hex>
|
||||
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])
|
||||
}
|
||||
|
||||
|
@ -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",
|
||||
],
|
||||
|
@ -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
|
||||
|
@ -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")
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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,
|
||||
},
|
||||
|
@ -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"],
|
||||
)
|
@ -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"
|
@ -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",
|
||||
],
|
||||
)
|
@ -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
|
||||
}
|
@ -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",
|
||||
|
@ -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 {
|
||||
|
@ -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",
|
||||
],
|
||||
)
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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",
|
||||
|
@ -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
|
||||
|
@ -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",
|
||||
|
@ -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
|
||||
|
@ -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())
|
||||
}
|
||||
|
||||
|
@ -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))
|
||||
}
|
||||
|
@ -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{
|
||||
|
@ -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.
|
||||
|
@ -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}
|
||||
|
@ -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",
|
||||
|
@ -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(),
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user