From 3e71997290dabe0e57d375c8c3a0165139968993 Mon Sep 17 00:00:00 2001 From: terence tsao Date: Tue, 14 Sep 2021 17:09:04 -0700 Subject: [PATCH] Create time Package for Shared/timeutil, mclock and slotutil (#9594) * add time pkg * Go fmt --- beacon-chain/blockchain/BUILD.bazel | 4 +-- beacon-chain/blockchain/head.go | 4 +-- beacon-chain/blockchain/log.go | 6 ++-- .../blockchain/process_attestation.go | 4 +-- .../blockchain/process_attestation_test.go | 4 +-- beacon-chain/blockchain/process_block_test.go | 4 +-- .../blockchain/receive_attestation.go | 4 +-- .../blockchain/receive_attestation_test.go | 6 ++-- beacon-chain/blockchain/receive_block.go | 4 +-- beacon-chain/blockchain/service.go | 6 ++-- beacon-chain/core/BUILD.bazel | 4 +-- beacon-chain/core/altair/BUILD.bazel | 2 +- .../core/altair/sync_committee_test.go | 20 ++++++------- beacon-chain/core/helpers/BUILD.bazel | 4 +-- beacon-chain/core/helpers/attestation.go | 6 ++-- beacon-chain/core/helpers/attestation_test.go | 18 +++++------ beacon-chain/core/slot_epoch.go | 6 ++-- beacon-chain/core/slot_epoch_test.go | 14 ++++----- beacon-chain/interop-cold-start/BUILD.bazel | 2 +- beacon-chain/interop-cold-start/service.go | 4 +-- .../operations/attestations/BUILD.bazel | 6 ++-- .../attestations/kv/seen_bits_test.go | 4 +-- .../attestations/prepare_forkchoice.go | 4 +-- .../operations/attestations/prune_expired.go | 4 +-- .../attestations/prune_expired_test.go | 8 ++--- beacon-chain/p2p/BUILD.bazel | 6 ++-- beacon-chain/p2p/fork.go | 4 +-- beacon-chain/p2p/fork_watcher.go | 4 +-- beacon-chain/p2p/handshake.go | 4 +-- beacon-chain/p2p/peers/BUILD.bazel | 2 +- beacon-chain/p2p/peers/scorers/BUILD.bazel | 4 +-- .../p2p/peers/scorers/block_providers.go | 4 +-- .../p2p/peers/scorers/block_providers_test.go | 4 +-- beacon-chain/p2p/peers/scorers/peer_status.go | 4 +-- beacon-chain/p2p/peers/status.go | 6 ++-- beacon-chain/p2p/pubsub_filter_test.go | 4 +-- beacon-chain/p2p/service.go | 4 +-- beacon-chain/p2p/service_test.go | 6 ++-- beacon-chain/powchain/BUILD.bazel | 2 +- beacon-chain/powchain/service.go | 6 ++-- .../rpc/prysm/v1alpha1/beacon/BUILD.bazel | 4 +-- .../rpc/prysm/v1alpha1/beacon/attestations.go | 6 ++-- .../prysm/v1alpha1/beacon/committees_test.go | 8 ++--- .../prysm/v1alpha1/beacon/validators_test.go | 8 ++--- .../rpc/prysm/v1alpha1/validator/BUILD.bazel | 6 ++-- .../prysm/v1alpha1/validator/assignments.go | 16 +++++----- .../prysm/v1alpha1/validator/attester_test.go | 4 +-- beacon-chain/sync/BUILD.bazel | 6 ++-- beacon-chain/sync/fork_watcher.go | 4 +-- beacon-chain/sync/initial-sync/BUILD.bazel | 6 ++-- .../sync/initial-sync/blocks_fetcher_peers.go | 6 ++-- .../initial-sync/blocks_fetcher_peers_test.go | 30 +++++++++---------- .../sync/initial-sync/blocks_queue_test.go | 10 +++---- beacon-chain/sync/initial-sync/fsm.go | 6 ++-- .../sync/initial-sync/initial_sync_test.go | 4 +-- beacon-chain/sync/initial-sync/service.go | 4 +-- .../sync/pending_attestations_queue.go | 4 +-- .../sync/pending_attestations_queue_test.go | 6 ++-- beacon-chain/sync/pending_blocks_queue.go | 4 +-- beacon-chain/sync/rpc.go | 4 +-- beacon-chain/sync/rpc_ping.go | 6 ++-- beacon-chain/sync/rpc_status.go | 8 ++--- beacon-chain/sync/rpc_status_test.go | 10 +++---- beacon-chain/sync/service.go | 10 +++---- beacon-chain/sync/subscriber.go | 10 +++---- beacon-chain/sync/validate_beacon_blocks.go | 6 ++-- endtoend/evaluators/BUILD.bazel | 2 +- endtoend/evaluators/metrics.go | 4 +-- endtoend/helpers/BUILD.bazel | 4 +-- endtoend/helpers/epochTimer.go | 4 +-- endtoend/helpers/helpers.go | 4 +-- shared/aggregation/testing/BUILD.bazel | 2 +- shared/aggregation/testing/bitlistutils.go | 6 ++-- shared/event/BUILD.bazel | 2 +- shared/event/subscription.go | 8 ++--- shared/interop/BUILD.bazel | 2 +- shared/interop/generate_genesis_state.go | 4 +-- shared/keystore/BUILD.bazel | 2 +- shared/keystore/utils.go | 4 +-- shared/slotutil/testing/mock_test.go | 5 ---- slasher/beaconclient/BUILD.bazel | 4 +-- slasher/beaconclient/receivers.go | 4 +-- slasher/beaconclient/receivers_test.go | 4 +-- {shared/timeutils => time}/BUILD.bazel | 2 +- .../mclockutil => time/mclock}/BUILD.bazel | 2 +- {shared/mclockutil => time/mclock}/mclock.go | 2 +- {shared/slotutil => time/slots}/BUILD.bazel | 6 ++-- {shared/slotutil => time/slots}/countdown.go | 6 ++-- .../slotutil => time/slots}/countdown_test.go | 8 ++--- {shared/slotutil => time/slots}/slotticker.go | 8 ++--- .../slots}/slotticker_test.go | 2 +- {shared/slotutil => time/slots}/slottime.go | 8 ++--- .../slotutil => time/slots}/slottime_test.go | 8 ++--- .../slotutil => time/slots}/slotutil_test.go | 2 +- .../slots}/testing/BUILD.bazel | 4 +-- .../slotutil => time/slots}/testing/mock.go | 0 time/slots/testing/mock_test.go | 7 +++++ {shared/timeutils => time}/utils.go | 2 +- validator/accounts/BUILD.bazel | 2 +- validator/accounts/accounts_import_test.go | 4 +-- validator/client/BUILD.bazel | 10 +++---- validator/client/aggregate.go | 10 +++---- validator/client/aggregate_test.go | 16 +++++----- validator/client/attest.go | 10 +++---- validator/client/attest_test.go | 6 ++-- validator/client/log.go | 4 +-- validator/client/propose.go | 4 +-- validator/client/testutil/BUILD.bazel | 2 +- validator/client/testutil/mock_validator.go | 4 +-- validator/client/validator.go | 8 ++--- validator/client/wait_for_activation.go | 4 +-- validator/client/wait_for_activation_test.go | 2 +- validator/rpc/BUILD.bazel | 4 +-- validator/rpc/auth.go | 4 +-- validator/rpc/intercepter_test.go | 4 +-- 115 files changed, 322 insertions(+), 320 deletions(-) delete mode 100644 shared/slotutil/testing/mock_test.go rename {shared/timeutils => time}/BUILD.bazel (70%) rename {shared/mclockutil => time/mclock}/BUILD.bazel (77%) rename {shared/mclockutil => time/mclock}/mclock.go (98%) rename {shared/slotutil => time/slots}/BUILD.bazel (85%) rename {shared/slotutil => time/slots}/countdown.go (94%) rename {shared/slotutil => time/slots}/countdown_test.go (90%) rename {shared/slotutil => time/slots}/slotticker.go (91%) rename {shared/slotutil => time/slots}/slotticker_test.go (99%) rename {shared/slotutil => time/slots}/slottime.go (89%) rename {shared/slotutil => time/slots}/slottime_test.go (91%) rename {shared/slotutil => time/slots}/slotutil_test.go (91%) rename {shared/slotutil => time/slots}/testing/BUILD.bazel (73%) rename {shared/slotutil => time/slots}/testing/mock.go (100%) create mode 100644 time/slots/testing/mock_test.go rename {shared/timeutils => time}/utils.go (95%) diff --git a/beacon-chain/blockchain/BUILD.bazel b/beacon-chain/blockchain/BUILD.bazel index 654917043..c3101e6cf 100644 --- a/beacon-chain/blockchain/BUILD.bazel +++ b/beacon-chain/blockchain/BUILD.bazel @@ -56,9 +56,9 @@ go_library( "//shared/featureconfig:go_default_library", "//shared/mputil:go_default_library", "//shared/params:go_default_library", - "//shared/slotutil:go_default_library", - "//shared/timeutils:go_default_library", "//shared/version:go_default_library", + "//time:go_default_library", + "//time/slots:go_default_library", "@com_github_emicklei_dot//:go_default_library", "@com_github_pkg_errors//:go_default_library", "@com_github_prometheus_client_golang//prometheus:go_default_library", diff --git a/beacon-chain/blockchain/head.go b/beacon-chain/blockchain/head.go index 16d186c0f..939726ec7 100644 --- a/beacon-chain/blockchain/head.go +++ b/beacon-chain/blockchain/head.go @@ -18,7 +18,7 @@ import ( "github.com/prysmaticlabs/prysm/shared/bytesutil" "github.com/prysmaticlabs/prysm/shared/featureconfig" "github.com/prysmaticlabs/prysm/shared/params" - "github.com/prysmaticlabs/prysm/shared/slotutil" + "github.com/prysmaticlabs/prysm/time/slots" "github.com/sirupsen/logrus" "go.opencensus.io/trace" ) @@ -131,7 +131,7 @@ func (s *Service) saveHead(ctx context.Context, headRoot [32]byte) error { "newSlot": fmt.Sprintf("%d", newHeadSlot), "oldSlot": fmt.Sprintf("%d", headSlot), }).Debug("Chain reorg occurred") - absoluteSlotDifference := slotutil.AbsoluteValueSlotDifference(newHeadSlot, headSlot) + absoluteSlotDifference := slots.AbsoluteValueSlotDifference(newHeadSlot, headSlot) s.cfg.StateNotifier.StateFeed().Send(&feed.Event{ Type: statefeed.Reorg, Data: ðpbv1.EventChainReorg{ diff --git a/beacon-chain/blockchain/log.go b/beacon-chain/blockchain/log.go index 70cfccbc5..aca309369 100644 --- a/beacon-chain/blockchain/log.go +++ b/beacon-chain/blockchain/log.go @@ -9,8 +9,8 @@ import ( ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/block" "github.com/prysmaticlabs/prysm/shared/params" - "github.com/prysmaticlabs/prysm/shared/timeutils" "github.com/prysmaticlabs/prysm/shared/version" + prysmTime "github.com/prysmaticlabs/prysm/time" "github.com/sirupsen/logrus" ) @@ -58,8 +58,8 @@ func logBlockSyncStatus(block block.BeaconBlock, blockRoot [32]byte, finalized * }).Info("Synced new block") log.WithFields(logrus.Fields{ "slot": block.Slot, - "sinceSlotStartTime": timeutils.Now().Sub(startTime), - "chainServiceProcessedTime": timeutils.Now().Sub(receivedTime), + "sinceSlotStartTime": prysmTime.Now().Sub(startTime), + "chainServiceProcessedTime": prysmTime.Now().Sub(receivedTime), }).Debug("Sync new block times") return nil } diff --git a/beacon-chain/blockchain/process_attestation.go b/beacon-chain/blockchain/process_attestation.go index 21a8b6b20..747abe1ee 100644 --- a/beacon-chain/blockchain/process_attestation.go +++ b/beacon-chain/blockchain/process_attestation.go @@ -10,7 +10,7 @@ import ( "github.com/prysmaticlabs/prysm/shared/attestationutil" "github.com/prysmaticlabs/prysm/shared/bytesutil" "github.com/prysmaticlabs/prysm/shared/params" - "github.com/prysmaticlabs/prysm/shared/timeutils" + "github.com/prysmaticlabs/prysm/time" "go.opencensus.io/trace" ) @@ -62,7 +62,7 @@ func (s *Service) onAttestation(ctx context.Context, a *ethpb.Attestation) error genesisTime := baseState.GenesisTime() // Verify attestation target is from current epoch or previous epoch. - if err := s.verifyAttTargetEpoch(ctx, genesisTime, uint64(timeutils.Now().Unix()), tgt); err != nil { + if err := s.verifyAttTargetEpoch(ctx, genesisTime, uint64(time.Now().Unix()), tgt); err != nil { return err } diff --git a/beacon-chain/blockchain/process_attestation_test.go b/beacon-chain/blockchain/process_attestation_test.go index 52b3167c1..3fdbcf395 100644 --- a/beacon-chain/blockchain/process_attestation_test.go +++ b/beacon-chain/blockchain/process_attestation_test.go @@ -17,7 +17,7 @@ import ( "github.com/prysmaticlabs/prysm/shared/testutil" "github.com/prysmaticlabs/prysm/shared/testutil/assert" "github.com/prysmaticlabs/prysm/shared/testutil/require" - "github.com/prysmaticlabs/prysm/shared/timeutils" + "github.com/prysmaticlabs/prysm/time" ) func TestStore_OnAttestation_ErrorConditions(t *testing.T) { @@ -138,7 +138,7 @@ func TestStore_OnAttestation_Ok(t *testing.T) { service, err := NewService(ctx, cfg) require.NoError(t, err) genesisState, pks := testutil.DeterministicGenesisState(t, 64) - require.NoError(t, genesisState.SetGenesisTime(uint64(timeutils.Now().Unix())-params.BeaconConfig().SecondsPerSlot)) + require.NoError(t, genesisState.SetGenesisTime(uint64(time.Now().Unix())-params.BeaconConfig().SecondsPerSlot)) require.NoError(t, service.saveGenesisData(ctx, genesisState)) att, err := testutil.GenerateAttestations(genesisState, pks, 1, 0, false) require.NoError(t, err) diff --git a/beacon-chain/blockchain/process_block_test.go b/beacon-chain/blockchain/process_block_test.go index 6ba2551b5..f171e3d64 100644 --- a/beacon-chain/blockchain/process_block_test.go +++ b/beacon-chain/blockchain/process_block_test.go @@ -30,7 +30,7 @@ import ( "github.com/prysmaticlabs/prysm/shared/testutil" "github.com/prysmaticlabs/prysm/shared/testutil/assert" "github.com/prysmaticlabs/prysm/shared/testutil/require" - "github.com/prysmaticlabs/prysm/shared/timeutils" + prysmTime "github.com/prysmaticlabs/prysm/time" ) func TestStore_OnBlock(t *testing.T) { @@ -567,7 +567,7 @@ func blockTree1(t *testing.T, beaconDB db.Database, genesisRoot []byte) ([][]byt } func TestCurrentSlot_HandlesOverflow(t *testing.T) { - svc := Service{genesisTime: timeutils.Now().Add(1 * time.Hour)} + svc := Service{genesisTime: prysmTime.Now().Add(1 * time.Hour)} slot := svc.CurrentSlot() require.Equal(t, types.Slot(0), slot, "Unexpected slot") diff --git a/beacon-chain/blockchain/receive_attestation.go b/beacon-chain/blockchain/receive_attestation.go index 0ad5ab3fb..763ccb373 100644 --- a/beacon-chain/blockchain/receive_attestation.go +++ b/beacon-chain/blockchain/receive_attestation.go @@ -14,7 +14,7 @@ import ( ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/shared/bytesutil" "github.com/prysmaticlabs/prysm/shared/params" - "github.com/prysmaticlabs/prysm/shared/slotutil" + "github.com/prysmaticlabs/prysm/time/slots" "github.com/sirupsen/logrus" "go.opencensus.io/trace" ) @@ -114,7 +114,7 @@ func (s *Service) processAttestationsRoutine(subscribedToStateEvents chan<- stru log.Warn("Genesis time received, now available to process attestations") } - st := slotutil.NewSlotTicker(s.genesisTime, params.BeaconConfig().SecondsPerSlot) + st := slots.NewSlotTicker(s.genesisTime, params.BeaconConfig().SecondsPerSlot) for { select { case <-s.ctx.Done(): diff --git a/beacon-chain/blockchain/receive_attestation_test.go b/beacon-chain/blockchain/receive_attestation_test.go index 97d5af8d7..b1b160186 100644 --- a/beacon-chain/blockchain/receive_attestation_test.go +++ b/beacon-chain/blockchain/receive_attestation_test.go @@ -19,7 +19,7 @@ import ( "github.com/prysmaticlabs/prysm/shared/params" "github.com/prysmaticlabs/prysm/shared/testutil" "github.com/prysmaticlabs/prysm/shared/testutil/require" - "github.com/prysmaticlabs/prysm/shared/timeutils" + prysmTime "github.com/prysmaticlabs/prysm/time" logTest "github.com/sirupsen/logrus/hooks/test" ) @@ -103,10 +103,10 @@ func TestProcessAttestations_Ok(t *testing.T) { AttPool: attestations.NewPool(), } service, err := NewService(ctx, cfg) - service.genesisTime = timeutils.Now().Add(-1 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second) + service.genesisTime = prysmTime.Now().Add(-1 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second) require.NoError(t, err) genesisState, pks := testutil.DeterministicGenesisState(t, 64) - require.NoError(t, genesisState.SetGenesisTime(uint64(timeutils.Now().Unix())-params.BeaconConfig().SecondsPerSlot)) + require.NoError(t, genesisState.SetGenesisTime(uint64(prysmTime.Now().Unix())-params.BeaconConfig().SecondsPerSlot)) require.NoError(t, service.saveGenesisData(ctx, genesisState)) atts, err := testutil.GenerateAttestations(genesisState, pks, 1, 0, false) require.NoError(t, err) diff --git a/beacon-chain/blockchain/receive_block.go b/beacon-chain/blockchain/receive_block.go index a0de0852f..2cf157c40 100644 --- a/beacon-chain/blockchain/receive_block.go +++ b/beacon-chain/blockchain/receive_block.go @@ -11,7 +11,7 @@ import ( "github.com/prysmaticlabs/prysm/monitoring/tracing" "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/block" "github.com/prysmaticlabs/prysm/shared/featureconfig" - "github.com/prysmaticlabs/prysm/shared/timeutils" + "github.com/prysmaticlabs/prysm/time" "go.opencensus.io/trace" ) @@ -33,7 +33,7 @@ type BlockReceiver interface { func (s *Service) ReceiveBlock(ctx context.Context, block block.SignedBeaconBlock, blockRoot [32]byte) error { ctx, span := trace.StartSpan(ctx, "blockChain.ReceiveBlock") defer span.End() - receivedTime := timeutils.Now() + receivedTime := time.Now() blockCopy := block.Copy() // Apply state transition on the new block. diff --git a/beacon-chain/blockchain/service.go b/beacon-chain/blockchain/service.go index 68ec034fe..541b1e762 100644 --- a/beacon-chain/blockchain/service.go +++ b/beacon-chain/blockchain/service.go @@ -33,7 +33,7 @@ import ( "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/block" "github.com/prysmaticlabs/prysm/shared/bytesutil" "github.com/prysmaticlabs/prysm/shared/params" - "github.com/prysmaticlabs/prysm/shared/slotutil" + "github.com/prysmaticlabs/prysm/time/slots" "github.com/sirupsen/logrus" "go.opencensus.io/trace" ) @@ -152,7 +152,7 @@ func (s *Service) Start() { if err != nil { log.Fatalf("Could not hash tree root genesis state: %v", err) } - go slotutil.CountdownToGenesis(s.ctx, s.genesisTime, uint64(gState.NumValidators()), gRoot) + go slots.CountdownToGenesis(s.ctx, s.genesisTime, uint64(gState.NumValidators()), gRoot) justifiedCheckpoint, err := s.cfg.BeaconDB.JustifiedCheckpoint(s.ctx) if err != nil { @@ -252,7 +252,7 @@ func (s *Service) processChainStartTime(ctx context.Context, genesisTime time.Ti if err != nil { log.Fatalf("Could not hash tree root genesis state: %v", err) } - go slotutil.CountdownToGenesis(ctx, genesisTime, uint64(initializedState.NumValidators()), gRoot) + go slots.CountdownToGenesis(ctx, genesisTime, uint64(initializedState.NumValidators()), gRoot) // We send out a state initialized event to the rest of the services // running in the beacon node. diff --git a/beacon-chain/core/BUILD.bazel b/beacon-chain/core/BUILD.bazel index 8f8d44dd6..58ba46327 100644 --- a/beacon-chain/core/BUILD.bazel +++ b/beacon-chain/core/BUILD.bazel @@ -24,8 +24,8 @@ go_library( deps = [ "//beacon-chain/state:go_default_library", "//shared/params:go_default_library", - "//shared/timeutils:go_default_library", "//shared/version:go_default_library", + "//time:go_default_library", "@com_github_ethereum_go_ethereum//common/math:go_default_library", "@com_github_pkg_errors//:go_default_library", "@com_github_prysmaticlabs_eth2_types//:go_default_library", @@ -42,7 +42,7 @@ go_test( "//shared/params:go_default_library", "//shared/testutil/assert:go_default_library", "//shared/testutil/require:go_default_library", - "//shared/timeutils:go_default_library", + "//time:go_default_library", "@com_github_prysmaticlabs_eth2_types//:go_default_library", ], ) diff --git a/beacon-chain/core/altair/BUILD.bazel b/beacon-chain/core/altair/BUILD.bazel index 1cc5058f3..03698ad44 100644 --- a/beacon-chain/core/altair/BUILD.bazel +++ b/beacon-chain/core/altair/BUILD.bazel @@ -76,8 +76,8 @@ go_test( "//shared/testutil:go_default_library", "//shared/testutil/assert:go_default_library", "//shared/testutil/require:go_default_library", - "//shared/timeutils:go_default_library", "//shared/trieutil:go_default_library", + "//time:go_default_library", "@com_github_google_gofuzz//:go_default_library", "@com_github_prysmaticlabs_eth2_types//:go_default_library", "@com_github_prysmaticlabs_go_bitfield//:go_default_library", diff --git a/beacon-chain/core/altair/sync_committee_test.go b/beacon-chain/core/altair/sync_committee_test.go index f430ed200..5d7721ba8 100644 --- a/beacon-chain/core/altair/sync_committee_test.go +++ b/beacon-chain/core/altair/sync_committee_test.go @@ -14,7 +14,7 @@ import ( "github.com/prysmaticlabs/prysm/shared/params" "github.com/prysmaticlabs/prysm/shared/testutil/assert" "github.com/prysmaticlabs/prysm/shared/testutil/require" - "github.com/prysmaticlabs/prysm/shared/timeutils" + prysmTime "github.com/prysmaticlabs/prysm/time" ) func TestSyncCommitteeIndices_CanGet(t *testing.T) { @@ -299,14 +299,14 @@ func Test_ValidateSyncMessageTime(t *testing.T) { name: "sync_message.slot == current_slot", args: args{ syncMessageSlot: 15, - genesisTime: timeutils.Now().Add(-15 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second), + genesisTime: prysmTime.Now().Add(-15 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second), }, }, { name: "sync_message.slot == current_slot, received in middle of slot", args: args{ syncMessageSlot: 15, - genesisTime: timeutils.Now().Add( + genesisTime: prysmTime.Now().Add( -15 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second, ).Add(-(time.Duration(params.BeaconConfig().SecondsPerSlot/2) * time.Second)), }, @@ -315,7 +315,7 @@ func Test_ValidateSyncMessageTime(t *testing.T) { name: "sync_message.slot == current_slot, received 200ms early", args: args{ syncMessageSlot: 16, - genesisTime: timeutils.Now().Add( + genesisTime: prysmTime.Now().Add( -16 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second, ).Add(-200 * time.Millisecond), }, @@ -324,7 +324,7 @@ func Test_ValidateSyncMessageTime(t *testing.T) { name: "sync_message.slot > current_slot", args: args{ syncMessageSlot: 16, - genesisTime: timeutils.Now().Add(-(15 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second)), + genesisTime: prysmTime.Now().Add(-(15 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second)), }, wantedErr: "sync message slot 16 not within allowable range of", }, @@ -332,7 +332,7 @@ func Test_ValidateSyncMessageTime(t *testing.T) { name: "sync_message.slot == current_slot+CLOCK_DISPARITY", args: args{ syncMessageSlot: 100, - genesisTime: timeutils.Now().Add(-(100*time.Duration(params.BeaconConfig().SecondsPerSlot)*time.Second - params.BeaconNetworkConfig().MaximumGossipClockDisparity)), + genesisTime: prysmTime.Now().Add(-(100*time.Duration(params.BeaconConfig().SecondsPerSlot)*time.Second - params.BeaconNetworkConfig().MaximumGossipClockDisparity)), }, wantedErr: "", }, @@ -340,7 +340,7 @@ func Test_ValidateSyncMessageTime(t *testing.T) { name: "sync_message.slot == current_slot+CLOCK_DISPARITY-1000ms", args: args{ syncMessageSlot: 100, - genesisTime: timeutils.Now().Add(-(100 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second) + params.BeaconNetworkConfig().MaximumGossipClockDisparity + 1000*time.Millisecond), + genesisTime: prysmTime.Now().Add(-(100 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second) + params.BeaconNetworkConfig().MaximumGossipClockDisparity + 1000*time.Millisecond), }, wantedErr: "sync message slot 100 not within allowable range of", }, @@ -348,7 +348,7 @@ func Test_ValidateSyncMessageTime(t *testing.T) { name: "sync_message.slot == current_slot-CLOCK_DISPARITY", args: args{ syncMessageSlot: 100, - genesisTime: timeutils.Now().Add(-(100*time.Duration(params.BeaconConfig().SecondsPerSlot)*time.Second + params.BeaconNetworkConfig().MaximumGossipClockDisparity)), + genesisTime: prysmTime.Now().Add(-(100*time.Duration(params.BeaconConfig().SecondsPerSlot)*time.Second + params.BeaconNetworkConfig().MaximumGossipClockDisparity)), }, wantedErr: "", }, @@ -356,7 +356,7 @@ func Test_ValidateSyncMessageTime(t *testing.T) { name: "sync_message.slot > current_slot+CLOCK_DISPARITY", args: args{ syncMessageSlot: 101, - genesisTime: timeutils.Now().Add(-(100*time.Duration(params.BeaconConfig().SecondsPerSlot)*time.Second + params.BeaconNetworkConfig().MaximumGossipClockDisparity)), + genesisTime: prysmTime.Now().Add(-(100*time.Duration(params.BeaconConfig().SecondsPerSlot)*time.Second + params.BeaconNetworkConfig().MaximumGossipClockDisparity)), }, wantedErr: "sync message slot 101 not within allowable range of", }, @@ -364,7 +364,7 @@ func Test_ValidateSyncMessageTime(t *testing.T) { name: "sync_message.slot is well beyond current slot", args: args{ syncMessageSlot: 1 << 32, - genesisTime: timeutils.Now().Add(-15 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second), + genesisTime: prysmTime.Now().Add(-15 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second), }, wantedErr: "which exceeds max allowed value relative to the local clock", }, diff --git a/beacon-chain/core/helpers/BUILD.bazel b/beacon-chain/core/helpers/BUILD.bazel index afc281666..615650548 100644 --- a/beacon-chain/core/helpers/BUILD.bazel +++ b/beacon-chain/core/helpers/BUILD.bazel @@ -45,8 +45,8 @@ go_library( "//shared/mathutil:go_default_library", "//shared/params:go_default_library", "//shared/sliceutil:go_default_library", - "//shared/timeutils:go_default_library", "//shared/trieutil:go_default_library", + "//time:go_default_library", "@com_github_ferranbt_fastssz//:go_default_library", "@com_github_pkg_errors//:go_default_library", "@com_github_prysmaticlabs_eth2_types//:go_default_library", @@ -88,7 +88,7 @@ go_test( "//shared/testutil:go_default_library", "//shared/testutil/assert:go_default_library", "//shared/testutil/require:go_default_library", - "//shared/timeutils:go_default_library", + "//time:go_default_library", "@com_github_google_gofuzz//:go_default_library", "@com_github_prysmaticlabs_eth2_types//:go_default_library", "@com_github_prysmaticlabs_go_bitfield//:go_default_library", diff --git a/beacon-chain/core/helpers/attestation.go b/beacon-chain/core/helpers/attestation.go index 1a0d4a1a7..efdc20b15 100644 --- a/beacon-chain/core/helpers/attestation.go +++ b/beacon-chain/core/helpers/attestation.go @@ -12,7 +12,7 @@ import ( "github.com/prysmaticlabs/prysm/shared/bls" "github.com/prysmaticlabs/prysm/shared/hashutil" "github.com/prysmaticlabs/prysm/shared/params" - "github.com/prysmaticlabs/prysm/shared/timeutils" + prysmTime "github.com/prysmaticlabs/prysm/time" ) // ValidateNilAttestation checks if any composite field of input attestation is nil. @@ -155,7 +155,7 @@ func ValidateAttestationTime(attSlot types.Slot, genesisTime time.Time, clockDis // so the upper bounds is set to now + clockDisparity(SECONDS_PER_SLOT * 2). // But when sending an attestation, it should not be in future slot. // so the upper bounds is set to now + clockDisparity(MAXIMUM_GOSSIP_CLOCK_DISPARITY). - upperBounds := timeutils.Now().Add(clockDisparity) + upperBounds := prysmTime.Now().Add(clockDisparity) // An attestation cannot be older than the current slot - attestation propagation slot range // with a minor tolerance for peer clock disparity. @@ -184,7 +184,7 @@ func ValidateAttestationTime(attSlot types.Slot, genesisTime time.Time, clockDis // VerifyCheckpointEpoch is within current epoch and previous epoch // with respect to current time. Returns true if it's within, false if it's not. func VerifyCheckpointEpoch(c *ethpb.Checkpoint, genesis time.Time) bool { - now := uint64(timeutils.Now().Unix()) + now := uint64(prysmTime.Now().Unix()) genesisTime := uint64(genesis.Unix()) currentSlot := types.Slot((now - genesisTime) / params.BeaconConfig().SecondsPerSlot) currentEpoch := core.SlotToEpoch(currentSlot) diff --git a/beacon-chain/core/helpers/attestation_test.go b/beacon-chain/core/helpers/attestation_test.go index 08c5e9d99..5cec1ebd3 100644 --- a/beacon-chain/core/helpers/attestation_test.go +++ b/beacon-chain/core/helpers/attestation_test.go @@ -16,7 +16,7 @@ import ( "github.com/prysmaticlabs/prysm/shared/testutil" "github.com/prysmaticlabs/prysm/shared/testutil/assert" "github.com/prysmaticlabs/prysm/shared/testutil/require" - "github.com/prysmaticlabs/prysm/shared/timeutils" + prysmTime "github.com/prysmaticlabs/prysm/time" ) func TestAttestation_IsAggregator(t *testing.T) { @@ -141,14 +141,14 @@ func Test_ValidateAttestationTime(t *testing.T) { name: "attestation.slot == current_slot", args: args{ attSlot: 15, - genesisTime: timeutils.Now().Add(-15 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second), + genesisTime: prysmTime.Now().Add(-15 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second), }, }, { name: "attestation.slot == current_slot, received in middle of slot", args: args{ attSlot: 15, - genesisTime: timeutils.Now().Add( + genesisTime: prysmTime.Now().Add( -15 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second, ).Add(-(time.Duration(params.BeaconConfig().SecondsPerSlot/2) * time.Second)), }, @@ -157,7 +157,7 @@ func Test_ValidateAttestationTime(t *testing.T) { name: "attestation.slot == current_slot, received 200ms early", args: args{ attSlot: 16, - genesisTime: timeutils.Now().Add( + genesisTime: prysmTime.Now().Add( -16 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second, ).Add(-200 * time.Millisecond), }, @@ -166,7 +166,7 @@ func Test_ValidateAttestationTime(t *testing.T) { name: "attestation.slot > current_slot", args: args{ attSlot: 16, - genesisTime: timeutils.Now().Add(-15 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second), + genesisTime: prysmTime.Now().Add(-15 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second), }, wantedErr: "not within attestation propagation range", }, @@ -174,7 +174,7 @@ func Test_ValidateAttestationTime(t *testing.T) { name: "attestation.slot < current_slot-ATTESTATION_PROPAGATION_SLOT_RANGE", args: args{ attSlot: 100 - params.BeaconNetworkConfig().AttestationPropagationSlotRange - 1, - genesisTime: timeutils.Now().Add(-100 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second), + genesisTime: prysmTime.Now().Add(-100 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second), }, wantedErr: "not within attestation propagation range", }, @@ -182,14 +182,14 @@ func Test_ValidateAttestationTime(t *testing.T) { name: "attestation.slot = current_slot-ATTESTATION_PROPAGATION_SLOT_RANGE", args: args{ attSlot: 100 - params.BeaconNetworkConfig().AttestationPropagationSlotRange, - genesisTime: timeutils.Now().Add(-100 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second), + genesisTime: prysmTime.Now().Add(-100 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second), }, }, { name: "attestation.slot = current_slot-ATTESTATION_PROPAGATION_SLOT_RANGE, received 200ms late", args: args{ attSlot: 100 - params.BeaconNetworkConfig().AttestationPropagationSlotRange, - genesisTime: timeutils.Now().Add( + genesisTime: prysmTime.Now().Add( -100 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second, ).Add(200 * time.Millisecond), }, @@ -198,7 +198,7 @@ func Test_ValidateAttestationTime(t *testing.T) { name: "attestation.slot is well beyond current slot", args: args{ attSlot: 1 << 32, - genesisTime: timeutils.Now().Add(-15 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second), + genesisTime: prysmTime.Now().Add(-15 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second), }, wantedErr: "which exceeds max allowed value relative to the local clock", }, diff --git a/beacon-chain/core/slot_epoch.go b/beacon-chain/core/slot_epoch.go index d5ae85db2..23a50951a 100644 --- a/beacon-chain/core/slot_epoch.go +++ b/beacon-chain/core/slot_epoch.go @@ -10,8 +10,8 @@ import ( types "github.com/prysmaticlabs/eth2-types" "github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/shared/params" - "github.com/prysmaticlabs/prysm/shared/timeutils" "github.com/prysmaticlabs/prysm/shared/version" + prysmTime "github.com/prysmaticlabs/prysm/time" ) // MaxSlotBuffer specifies the max buffer given to slots from @@ -133,7 +133,7 @@ func VerifySlotTime(genesisTime uint64, slot types.Slot, timeTolerance time.Dura return err } - currentTime := timeutils.Now() + currentTime := prysmTime.Now() diff := slotTime.Sub(currentTime) if diff > timeTolerance { @@ -163,7 +163,7 @@ func SlotsSince(time time.Time) types.Slot { // CurrentSlot returns the current slot as determined by the local clock and // provided genesis time. func CurrentSlot(genesisTimeSec uint64) types.Slot { - now := timeutils.Now().Unix() + now := prysmTime.Now().Unix() genesis := int64(genesisTimeSec) if now < genesis { return 0 diff --git a/beacon-chain/core/slot_epoch_test.go b/beacon-chain/core/slot_epoch_test.go index bc55e32b7..990201b0d 100644 --- a/beacon-chain/core/slot_epoch_test.go +++ b/beacon-chain/core/slot_epoch_test.go @@ -11,7 +11,7 @@ import ( "github.com/prysmaticlabs/prysm/shared/params" "github.com/prysmaticlabs/prysm/shared/testutil/assert" "github.com/prysmaticlabs/prysm/shared/testutil/require" - "github.com/prysmaticlabs/prysm/shared/timeutils" + prysmTime "github.com/prysmaticlabs/prysm/time" ) func TestSlotToEpoch_OK(t *testing.T) { @@ -287,21 +287,21 @@ func TestVerifySlotTime(t *testing.T) { { name: "Past slot", args: args{ - genesisTime: timeutils.Now().Add(-1 * 5 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second).Unix(), + genesisTime: prysmTime.Now().Add(-1 * 5 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second).Unix(), slot: 3, }, }, { name: "within tolerance", args: args{ - genesisTime: timeutils.Now().Add(-1 * 5 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second).Add(20 * time.Millisecond).Unix(), + genesisTime: prysmTime.Now().Add(-1 * 5 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second).Add(20 * time.Millisecond).Unix(), slot: 5, }, }, { name: "future slot", args: args{ - genesisTime: timeutils.Now().Add(-1 * 5 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second).Unix(), + genesisTime: prysmTime.Now().Add(-1 * 5 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second).Unix(), slot: 6, }, wantedErr: "could not process slot from the future", @@ -309,7 +309,7 @@ func TestVerifySlotTime(t *testing.T) { { name: "max future slot", args: args{ - genesisTime: timeutils.Now().Add(-1 * 5 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second).Unix(), + genesisTime: prysmTime.Now().Add(-1 * 5 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second).Unix(), slot: types.Slot(MaxSlotBuffer + 6), }, wantedErr: "exceeds max allowed value relative to the local clock", @@ -317,7 +317,7 @@ func TestVerifySlotTime(t *testing.T) { { name: "evil future slot", args: args{ - genesisTime: timeutils.Now().Add(-1 * 24 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second).Unix(), // 24 slots in the past + genesisTime: prysmTime.Now().Add(-1 * 24 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second).Unix(), // 24 slots in the past // Gets multiplied with slot duration, and results in an overflow. Wraps around to a valid time. // Lower than max signed int. And chosen specifically to wrap to a valid slot 24 slot: types.Slot((^uint64(0))/params.BeaconConfig().SecondsPerSlot) + 24, @@ -338,7 +338,7 @@ func TestVerifySlotTime(t *testing.T) { } func TestValidateSlotClock_HandlesBadSlot(t *testing.T) { - genTime := timeutils.Now().Add(-1 * time.Duration(MaxSlotBuffer) * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second).Unix() + genTime := prysmTime.Now().Add(-1 * time.Duration(MaxSlotBuffer) * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second).Unix() assert.NoError(t, ValidateSlotClock(types.Slot(MaxSlotBuffer), uint64(genTime)), "unexpected error validating slot") assert.NoError(t, ValidateSlotClock(types.Slot(2*MaxSlotBuffer), uint64(genTime)), "unexpected error validating slot") diff --git a/beacon-chain/interop-cold-start/BUILD.bazel b/beacon-chain/interop-cold-start/BUILD.bazel index 50e02803e..2fed6776c 100644 --- a/beacon-chain/interop-cold-start/BUILD.bazel +++ b/beacon-chain/interop-cold-start/BUILD.bazel @@ -17,7 +17,7 @@ go_library( "//proto/prysm/v1alpha1:go_default_library", "//shared:go_default_library", "//shared/interop:go_default_library", - "//shared/slotutil:go_default_library", + "//time/slots:go_default_library", "@com_github_prysmaticlabs_eth2_types//:go_default_library", "@com_github_sirupsen_logrus//:go_default_library", ], diff --git a/beacon-chain/interop-cold-start/service.go b/beacon-chain/interop-cold-start/service.go index f1bd9f060..39d9715c0 100644 --- a/beacon-chain/interop-cold-start/service.go +++ b/beacon-chain/interop-cold-start/service.go @@ -18,7 +18,7 @@ import ( ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/shared" "github.com/prysmaticlabs/prysm/shared/interop" - "github.com/prysmaticlabs/prysm/shared/slotutil" + "github.com/prysmaticlabs/prysm/time/slots" ) var _ shared.Service = (*Service)(nil) @@ -92,7 +92,7 @@ func NewService(ctx context.Context, cfg *Config) *Service { if err != nil { log.Fatalf("Could not hash tree root genesis state: %v", err) } - go slotutil.CountdownToGenesis(ctx, time.Unix(int64(s.cfg.GenesisTime), 0), s.cfg.NumValidators, gRoot) + go slots.CountdownToGenesis(ctx, time.Unix(int64(s.cfg.GenesisTime), 0), s.cfg.NumValidators, gRoot) if err := s.saveGenesisState(ctx, genesisTrie); err != nil { log.Fatalf("Could not save interop genesis state %v", err) diff --git a/beacon-chain/operations/attestations/BUILD.bazel b/beacon-chain/operations/attestations/BUILD.bazel index 1f5c5b626..8011a5577 100644 --- a/beacon-chain/operations/attestations/BUILD.bazel +++ b/beacon-chain/operations/attestations/BUILD.bazel @@ -23,8 +23,8 @@ go_library( "//shared/aggregation/attestations:go_default_library", "//shared/hashutil:go_default_library", "//shared/params:go_default_library", - "//shared/slotutil:go_default_library", - "//shared/timeutils:go_default_library", + "//time:go_default_library", + "//time/slots:go_default_library", "@com_github_hashicorp_golang_lru//:go_default_library", "@com_github_prometheus_client_golang//prometheus:go_default_library", "@com_github_prometheus_client_golang//prometheus/promauto:go_default_library", @@ -54,7 +54,7 @@ go_test( "//shared/testutil:go_default_library", "//shared/testutil/assert:go_default_library", "//shared/testutil/require:go_default_library", - "//shared/timeutils:go_default_library", + "//time:go_default_library", "@com_github_prysmaticlabs_go_bitfield//:go_default_library", "@org_golang_google_protobuf//proto:go_default_library", ], diff --git a/beacon-chain/operations/attestations/kv/seen_bits_test.go b/beacon-chain/operations/attestations/kv/seen_bits_test.go index 6470fdbd7..5848ae745 100644 --- a/beacon-chain/operations/attestations/kv/seen_bits_test.go +++ b/beacon-chain/operations/attestations/kv/seen_bits_test.go @@ -50,7 +50,7 @@ func TestAttCaches_insertSeenBitDuplicates(t *testing.T) { // Make sure that duplicates are not inserted, but expiration time gets updated. require.NoError(t, c.insertSeenBit(att1)) require.Equal(t, 1, c.seenAtt.ItemCount()) - _, expirationTime2, ok := c.seenAtt.GetWithExpiration(string(r[:])) + _, expirationprysmTime, ok := c.seenAtt.GetWithExpiration(string(r[:])) require.Equal(t, true, ok) - require.Equal(t, true, expirationTime2.After(expirationTime1), "Expiration time is not updated") + require.Equal(t, true, expirationprysmTime.After(expirationTime1), "Expiration time is not updated") } diff --git a/beacon-chain/operations/attestations/prepare_forkchoice.go b/beacon-chain/operations/attestations/prepare_forkchoice.go index d15180c4d..29a326b91 100644 --- a/beacon-chain/operations/attestations/prepare_forkchoice.go +++ b/beacon-chain/operations/attestations/prepare_forkchoice.go @@ -10,12 +10,12 @@ import ( ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" attaggregation "github.com/prysmaticlabs/prysm/shared/aggregation/attestations" "github.com/prysmaticlabs/prysm/shared/hashutil" - "github.com/prysmaticlabs/prysm/shared/slotutil" + "github.com/prysmaticlabs/prysm/time/slots" "go.opencensus.io/trace" ) // Prepare attestations for fork choice three times per slot. -var prepareForkChoiceAttsPeriod = slotutil.DivideSlotBy(3 /* times-per-slot */) +var prepareForkChoiceAttsPeriod = slots.DivideSlotBy(3 /* times-per-slot */) // This prepares fork choice attestations by running batchForkChoiceAtts // every prepareForkChoiceAttsPeriod. diff --git a/beacon-chain/operations/attestations/prune_expired.go b/beacon-chain/operations/attestations/prune_expired.go index 03ac03124..fff8cefc9 100644 --- a/beacon-chain/operations/attestations/prune_expired.go +++ b/beacon-chain/operations/attestations/prune_expired.go @@ -5,7 +5,7 @@ import ( types "github.com/prysmaticlabs/eth2-types" "github.com/prysmaticlabs/prysm/shared/params" - "github.com/prysmaticlabs/prysm/shared/timeutils" + prysmTime "github.com/prysmaticlabs/prysm/time" ) // pruneAttsPool prunes attestations pool on every slot interval. @@ -69,6 +69,6 @@ func (s *Service) pruneExpiredAtts() { func (s *Service) expired(slot types.Slot) bool { expirationSlot := slot + params.BeaconConfig().SlotsPerEpoch expirationTime := s.genesisTime + uint64(expirationSlot.Mul(params.BeaconConfig().SecondsPerSlot)) - currentTime := uint64(timeutils.Now().Unix()) + currentTime := uint64(prysmTime.Now().Unix()) return currentTime >= expirationTime } diff --git a/beacon-chain/operations/attestations/prune_expired_test.go b/beacon-chain/operations/attestations/prune_expired_test.go index 39068f925..4977691b7 100644 --- a/beacon-chain/operations/attestations/prune_expired_test.go +++ b/beacon-chain/operations/attestations/prune_expired_test.go @@ -12,7 +12,7 @@ import ( "github.com/prysmaticlabs/prysm/shared/testutil" "github.com/prysmaticlabs/prysm/shared/testutil/assert" "github.com/prysmaticlabs/prysm/shared/testutil/require" - "github.com/prysmaticlabs/prysm/shared/timeutils" + prysmTime "github.com/prysmaticlabs/prysm/time" ) func TestPruneExpired_Ticker(t *testing.T) { @@ -44,7 +44,7 @@ func TestPruneExpired_Ticker(t *testing.T) { require.NoError(t, s.cfg.Pool.SaveBlockAttestations(atts)) // Rewind back one epoch worth of time. - s.genesisTime = uint64(timeutils.Now().Unix()) - uint64(params.BeaconConfig().SlotsPerEpoch.Mul(params.BeaconConfig().SecondsPerSlot)) + s.genesisTime = uint64(prysmTime.Now().Unix()) - uint64(params.BeaconConfig().SlotsPerEpoch.Mul(params.BeaconConfig().SecondsPerSlot)) go s.pruneAttsPool() @@ -97,7 +97,7 @@ func TestPruneExpired_PruneExpiredAtts(t *testing.T) { require.NoError(t, s.cfg.Pool.SaveBlockAttestations(atts)) // Rewind back one epoch worth of time. - s.genesisTime = uint64(timeutils.Now().Unix()) - uint64(params.BeaconConfig().SlotsPerEpoch.Mul(params.BeaconConfig().SecondsPerSlot)) + s.genesisTime = uint64(prysmTime.Now().Unix()) - uint64(params.BeaconConfig().SlotsPerEpoch.Mul(params.BeaconConfig().SecondsPerSlot)) s.pruneExpiredAtts() // All the attestations on slot 0 should be pruned. @@ -118,7 +118,7 @@ func TestPruneExpired_Expired(t *testing.T) { require.NoError(t, err) // Rewind back one epoch worth of time. - s.genesisTime = uint64(timeutils.Now().Unix()) - uint64(params.BeaconConfig().SlotsPerEpoch.Mul(params.BeaconConfig().SecondsPerSlot)) + s.genesisTime = uint64(prysmTime.Now().Unix()) - uint64(params.BeaconConfig().SlotsPerEpoch.Mul(params.BeaconConfig().SecondsPerSlot)) assert.Equal(t, true, s.expired(0), "Should be expired") assert.Equal(t, false, s.expired(1), "Should not be expired") } diff --git a/beacon-chain/p2p/BUILD.bazel b/beacon-chain/p2p/BUILD.bazel index c3a949eee..95248f5b3 100644 --- a/beacon-chain/p2p/BUILD.bazel +++ b/beacon-chain/p2p/BUILD.bazel @@ -66,9 +66,9 @@ go_library( "//shared/p2putils:go_default_library", "//shared/params:go_default_library", "//shared/runutil:go_default_library", - "//shared/slotutil:go_default_library", - "//shared/timeutils:go_default_library", "//shared/version:go_default_library", + "//time:go_default_library", + "//time/slots:go_default_library", "@com_github_ethereum_go_ethereum//crypto:go_default_library", "@com_github_ethereum_go_ethereum//p2p/discover:go_default_library", "@com_github_ethereum_go_ethereum//p2p/enode:go_default_library", @@ -154,8 +154,8 @@ go_test( "//shared/testutil:go_default_library", "//shared/testutil/assert:go_default_library", "//shared/testutil/require:go_default_library", - "//shared/timeutils:go_default_library", "//shared/version:go_default_library", + "//time:go_default_library", "@com_github_ethereum_go_ethereum//crypto:go_default_library", "@com_github_ethereum_go_ethereum//p2p/discover:go_default_library", "@com_github_ethereum_go_ethereum//p2p/enode:go_default_library", diff --git a/beacon-chain/p2p/fork.go b/beacon-chain/p2p/fork.go index b841d49ee..29d9884d0 100644 --- a/beacon-chain/p2p/fork.go +++ b/beacon-chain/p2p/fork.go @@ -12,7 +12,7 @@ import ( pb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/shared/p2putils" "github.com/prysmaticlabs/prysm/shared/params" - "github.com/prysmaticlabs/prysm/shared/timeutils" + prysmTime "github.com/prysmaticlabs/prysm/time" "github.com/sirupsen/logrus" ) @@ -90,7 +90,7 @@ func addForkEntry( } currentSlot := core.SlotsSince(genesisTime) currentEpoch := core.SlotToEpoch(currentSlot) - if timeutils.Now().Before(genesisTime) { + if prysmTime.Now().Before(genesisTime) { currentEpoch = 0 } nextForkVersion, nextForkEpoch, err := p2putils.NextForkData(currentEpoch) diff --git a/beacon-chain/p2p/fork_watcher.go b/beacon-chain/p2p/fork_watcher.go index 43f059991..931df9284 100644 --- a/beacon-chain/p2p/fork_watcher.go +++ b/beacon-chain/p2p/fork_watcher.go @@ -3,14 +3,14 @@ package p2p import ( "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/shared/params" - "github.com/prysmaticlabs/prysm/shared/slotutil" + "github.com/prysmaticlabs/prysm/time/slots" ) // A background routine which listens for new and upcoming forks and // updates the node's discovery service to reflect any new fork version // changes. func (s *Service) forkWatcher() { - slotTicker := slotutil.NewSlotTicker(s.genesisTime, params.BeaconConfig().SecondsPerSlot) + slotTicker := slots.NewSlotTicker(s.genesisTime, params.BeaconConfig().SecondsPerSlot) for { select { case currSlot := <-slotTicker.C(): diff --git a/beacon-chain/p2p/handshake.go b/beacon-chain/p2p/handshake.go index 38c3537fe..51aee6fb2 100644 --- a/beacon-chain/p2p/handshake.go +++ b/beacon-chain/p2p/handshake.go @@ -12,7 +12,7 @@ import ( "github.com/libp2p/go-libp2p-core/peer" "github.com/prysmaticlabs/prysm/beacon-chain/p2p/peers" "github.com/prysmaticlabs/prysm/beacon-chain/p2p/peers/peerdata" - "github.com/prysmaticlabs/prysm/shared/timeutils" + prysmTime "github.com/prysmaticlabs/prysm/time" "github.com/sirupsen/logrus" ) @@ -104,7 +104,7 @@ func (s *Service) AddConnectionHandler(reqFunc, goodByeFunc func(ctx context.Con if conn.Stat().Direction == network.DirInbound { _, err := s.peers.ChainState(remotePeer) peerExists := err == nil - currentTime := timeutils.Now() + currentTime := prysmTime.Now() // Wait for peer to initiate handshake time.Sleep(timeForStatus) diff --git a/beacon-chain/p2p/peers/BUILD.bazel b/beacon-chain/p2p/peers/BUILD.bazel index 05428e0ac..5856b21ce 100644 --- a/beacon-chain/p2p/peers/BUILD.bazel +++ b/beacon-chain/p2p/peers/BUILD.bazel @@ -13,7 +13,7 @@ go_library( "//proto/prysm/v1alpha1/metadata:go_default_library", "//shared/params:go_default_library", "//shared/rand:go_default_library", - "//shared/timeutils:go_default_library", + "//time:go_default_library", "@com_github_ethereum_go_ethereum//p2p/enr:go_default_library", "@com_github_libp2p_go_libp2p_core//network:go_default_library", "@com_github_libp2p_go_libp2p_core//peer:go_default_library", diff --git a/beacon-chain/p2p/peers/scorers/BUILD.bazel b/beacon-chain/p2p/peers/scorers/BUILD.bazel index eedc80780..4bfbe4560 100644 --- a/beacon-chain/p2p/peers/scorers/BUILD.bazel +++ b/beacon-chain/p2p/peers/scorers/BUILD.bazel @@ -18,7 +18,7 @@ go_library( "//proto/prysm/v1alpha1:go_default_library", "//shared/featureconfig:go_default_library", "//shared/rand:go_default_library", - "//shared/timeutils:go_default_library", + "//time:go_default_library", "@com_github_libp2p_go_libp2p_core//peer:go_default_library", "@com_github_prysmaticlabs_eth2_types//:go_default_library", ], @@ -45,7 +45,7 @@ go_test( "//shared/rand:go_default_library", "//shared/testutil/assert:go_default_library", "//shared/testutil/require:go_default_library", - "//shared/timeutils:go_default_library", + "//time:go_default_library", "@com_github_libp2p_go_libp2p_core//network:go_default_library", "@com_github_libp2p_go_libp2p_core//peer:go_default_library", "@com_github_prysmaticlabs_eth2_types//:go_default_library", diff --git a/beacon-chain/p2p/peers/scorers/block_providers.go b/beacon-chain/p2p/peers/scorers/block_providers.go index cdd95062b..c49490a9c 100644 --- a/beacon-chain/p2p/peers/scorers/block_providers.go +++ b/beacon-chain/p2p/peers/scorers/block_providers.go @@ -11,7 +11,7 @@ import ( "github.com/prysmaticlabs/prysm/cmd/beacon-chain/flags" "github.com/prysmaticlabs/prysm/shared/featureconfig" "github.com/prysmaticlabs/prysm/shared/rand" - "github.com/prysmaticlabs/prysm/shared/timeutils" + prysmTime "github.com/prysmaticlabs/prysm/time" ) var _ Scorer = (*BlockProviderScorer)(nil) @@ -155,7 +155,7 @@ func (s *BlockProviderScorer) touch(pid peer.ID, t ...time.Time) { if len(t) == 1 { peerData.BlockProviderUpdated = t[0] } else { - peerData.BlockProviderUpdated = timeutils.Now() + peerData.BlockProviderUpdated = prysmTime.Now() } } diff --git a/beacon-chain/p2p/peers/scorers/block_providers_test.go b/beacon-chain/p2p/peers/scorers/block_providers_test.go index a0b0b5a3d..ad0dcb0a3 100644 --- a/beacon-chain/p2p/peers/scorers/block_providers_test.go +++ b/beacon-chain/p2p/peers/scorers/block_providers_test.go @@ -14,7 +14,7 @@ import ( "github.com/prysmaticlabs/prysm/shared/featureconfig" "github.com/prysmaticlabs/prysm/shared/rand" "github.com/prysmaticlabs/prysm/shared/testutil/assert" - "github.com/prysmaticlabs/prysm/shared/timeutils" + "github.com/prysmaticlabs/prysm/time" ) func TestScorers_BlockProvider_Score(t *testing.T) { @@ -57,7 +57,7 @@ func TestScorers_BlockProvider_Score(t *testing.T) { batchWeight := scorer.Params().ProcessedBatchWeight scorer.IncrementProcessedBlocks("peer1", batchSize*3) assert.Equal(t, roundScore(batchWeight*3), scorer.Score("peer1"), "Unexpected score") - scorer.Touch("peer1", timeutils.Now().Add(-1*scorer.Params().StalePeerRefreshInterval)) + scorer.Touch("peer1", time.Now().Add(-1*scorer.Params().StalePeerRefreshInterval)) }, check: func(scorer *scorers.BlockProviderScorer) { assert.Equal(t, scorer.MaxScore(), scorer.Score("peer1"), "Unexpected score") diff --git a/beacon-chain/p2p/peers/scorers/peer_status.go b/beacon-chain/p2p/peers/scorers/peer_status.go index 87c536a18..dbb02c7cb 100644 --- a/beacon-chain/p2p/peers/scorers/peer_status.go +++ b/beacon-chain/p2p/peers/scorers/peer_status.go @@ -9,7 +9,7 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/p2p/peers/peerdata" p2ptypes "github.com/prysmaticlabs/prysm/beacon-chain/p2p/types" pb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" - "github.com/prysmaticlabs/prysm/shared/timeutils" + "github.com/prysmaticlabs/prysm/time" ) var _ Scorer = (*PeerStatusScorer)(nil) @@ -112,7 +112,7 @@ func (s *PeerStatusScorer) SetPeerStatus(pid peer.ID, chainState *pb.Status, val peerData := s.store.PeerDataGetOrCreate(pid) peerData.ChainState = chainState - peerData.ChainStateLastUpdated = timeutils.Now() + peerData.ChainStateLastUpdated = time.Now() peerData.ChainStateValidationError = validationError // Update maximum known head slot (scores will be calculated with respect to that maximum value). diff --git a/beacon-chain/p2p/peers/status.go b/beacon-chain/p2p/peers/status.go index 82594c580..1a1f1a407 100644 --- a/beacon-chain/p2p/peers/status.go +++ b/beacon-chain/p2p/peers/status.go @@ -42,7 +42,7 @@ import ( "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/metadata" "github.com/prysmaticlabs/prysm/shared/params" "github.com/prysmaticlabs/prysm/shared/rand" - "github.com/prysmaticlabs/prysm/shared/timeutils" + prysmTime "github.com/prysmaticlabs/prysm/time" ) const ( @@ -320,7 +320,7 @@ func (p *Status) ChainStateLastUpdated(pid peer.ID) (time.Time, error) { if peerData, ok := p.store.PeerData(pid); ok { return peerData.ChainStateLastUpdated, nil } - return timeutils.Now(), peerdata.ErrPeerUnknown + return prysmTime.Now(), peerdata.ErrPeerUnknown } // IsBad states if the peer is to be considered bad (by *any* of the registered scorers). @@ -339,7 +339,7 @@ func (p *Status) NextValidTime(pid peer.ID) (time.Time, error) { if peerData, ok := p.store.PeerData(pid); ok { return peerData.NextValidTime, nil } - return timeutils.Now(), peerdata.ErrPeerUnknown + return prysmTime.Now(), peerdata.ErrPeerUnknown } // SetNextValidTime sets the earliest possible time we are diff --git a/beacon-chain/p2p/pubsub_filter_test.go b/beacon-chain/p2p/pubsub_filter_test.go index 302c123a0..4fce59e32 100644 --- a/beacon-chain/p2p/pubsub_filter_test.go +++ b/beacon-chain/p2p/pubsub_filter_test.go @@ -16,7 +16,7 @@ import ( "github.com/prysmaticlabs/prysm/shared/bytesutil" "github.com/prysmaticlabs/prysm/shared/p2putils" "github.com/prysmaticlabs/prysm/shared/testutil/assert" - "github.com/prysmaticlabs/prysm/shared/timeutils" + prysmTime "github.com/prysmaticlabs/prysm/time" "github.com/stretchr/testify/require" ) @@ -347,7 +347,7 @@ func TestService_MonitorsStateForkUpdates(t *testing.T) { n = notifier.StateFeed().Send(&feed.Event{ Type: statefeed.Initialized, Data: &statefeed.InitializedData{ - StartTime: timeutils.Now(), + StartTime: prysmTime.Now(), GenesisValidatorsRoot: bytesutil.PadTo([]byte("genesis"), 32), }, }) diff --git a/beacon-chain/p2p/service.go b/beacon-chain/p2p/service.go index fd6244400..be3591b1e 100644 --- a/beacon-chain/p2p/service.go +++ b/beacon-chain/p2p/service.go @@ -32,7 +32,7 @@ import ( "github.com/prysmaticlabs/prysm/shared" "github.com/prysmaticlabs/prysm/shared/params" "github.com/prysmaticlabs/prysm/shared/runutil" - "github.com/prysmaticlabs/prysm/shared/slotutil" + "github.com/prysmaticlabs/prysm/time/slots" "github.com/sirupsen/logrus" "go.opencensus.io/trace" ) @@ -46,7 +46,7 @@ var _ shared.Service = (*Service)(nil) var pollingPeriod = 6 * time.Second // Refresh rate of ENR set at twice per slot. -var refreshRate = slotutil.DivideSlotBy(2) +var refreshRate = slots.DivideSlotBy(2) // maxBadResponses is the maximum number of bad responses from a peer before we stop talking to it. const maxBadResponses = 5 diff --git a/beacon-chain/p2p/service_test.go b/beacon-chain/p2p/service_test.go index 7b1b5e5ab..a403fa0b0 100644 --- a/beacon-chain/p2p/service_test.go +++ b/beacon-chain/p2p/service_test.go @@ -26,7 +26,7 @@ import ( "github.com/prysmaticlabs/prysm/shared/p2putils" "github.com/prysmaticlabs/prysm/shared/testutil/assert" "github.com/prysmaticlabs/prysm/shared/testutil/require" - "github.com/prysmaticlabs/prysm/shared/timeutils" + prysmTime "github.com/prysmaticlabs/prysm/time" logTest "github.com/sirupsen/logrus/hooks/test" ) @@ -154,7 +154,7 @@ func TestListenForNewNodes(t *testing.T) { cfg.UDPPort = uint(port) _, pkey := createAddrAndPrivKey(t) ipAddr := net.ParseIP("127.0.0.1") - genesisTime := timeutils.Now() + genesisTime := prysmTime.Now() genesisValidatorsRoot := make([]byte, 32) s := &Service{ cfg: cfg, @@ -305,7 +305,7 @@ func TestService_JoinLeaveTopic(t *testing.T) { // initializeStateWithForkDigest sets up the state feed initialized event and returns the fork // digest associated with that genesis event. func initializeStateWithForkDigest(ctx context.Context, t *testing.T, ef *event.Feed) [4]byte { - gt := timeutils.Now() + gt := prysmTime.Now() gvr := bytesutil.PadTo([]byte("genesis validator root"), 32) for n := 0; n == 0; { if ctx.Err() != nil { diff --git a/beacon-chain/powchain/BUILD.bazel b/beacon-chain/powchain/BUILD.bazel index ba41e4c63..a3949dcb3 100644 --- a/beacon-chain/powchain/BUILD.bazel +++ b/beacon-chain/powchain/BUILD.bazel @@ -40,8 +40,8 @@ go_library( "//shared/httputils/authorizationmethod:go_default_library", "//shared/logutil:go_default_library", "//shared/params:go_default_library", - "//shared/timeutils:go_default_library", "//shared/trieutil:go_default_library", + "//time:go_default_library", "@com_github_ethereum_go_ethereum//:go_default_library", "@com_github_ethereum_go_ethereum//accounts/abi/bind:go_default_library", "@com_github_ethereum_go_ethereum//common:go_default_library", diff --git a/beacon-chain/powchain/service.go b/beacon-chain/powchain/service.go index 51d29337a..158d69b24 100644 --- a/beacon-chain/powchain/service.go +++ b/beacon-chain/powchain/service.go @@ -41,8 +41,8 @@ import ( "github.com/prysmaticlabs/prysm/shared/httputils/authorizationmethod" "github.com/prysmaticlabs/prysm/shared/logutil" "github.com/prysmaticlabs/prysm/shared/params" - "github.com/prysmaticlabs/prysm/shared/timeutils" "github.com/prysmaticlabs/prysm/shared/trieutil" + prysmTime "github.com/prysmaticlabs/prysm/time" "github.com/sirupsen/logrus" ) @@ -704,7 +704,7 @@ func (s *Service) handleETH1FollowDistance() { // use a 5 minutes timeout for block time, because the max mining time is 278 sec (block 7208027) // (analyzed the time of the block from 2018-09-01 to 2019-02-13) - fiveMinutesTimeout := timeutils.Now().Add(-5 * time.Minute) + fiveMinutesTimeout := prysmTime.Now().Add(-5 * time.Minute) // check that web3 client is syncing if time.Unix(int64(s.latestEth1Data.BlockTime), 0).Before(fiveMinutesTimeout) { log.Warn("eth1 client is not syncing") @@ -1061,7 +1061,7 @@ func dedupEndpoints(endpoints []string) []string { // Checks if the provided timestamp is beyond the prescribed bound from // the current wall clock time. func eth1HeadIsBehind(timestamp uint64) bool { - timeout := timeutils.Now().Add(-eth1Threshold) + timeout := prysmTime.Now().Add(-eth1Threshold) // check that web3 client is syncing return time.Unix(int64(timestamp), 0).Before(timeout) } diff --git a/beacon-chain/rpc/prysm/v1alpha1/beacon/BUILD.bazel b/beacon-chain/rpc/prysm/v1alpha1/beacon/BUILD.bazel index a33c0e6b6..8e97fd2c7 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/beacon/BUILD.bazel +++ b/beacon-chain/rpc/prysm/v1alpha1/beacon/BUILD.bazel @@ -50,8 +50,8 @@ go_library( "//shared/pagination:go_default_library", "//shared/params:go_default_library", "//shared/sliceutil:go_default_library", - "//shared/slotutil:go_default_library", "//shared/version:go_default_library", + "//time/slots:go_default_library", "@com_github_patrickmn_go_cache//:go_default_library", "@com_github_prometheus_client_golang//prometheus:go_default_library", "@com_github_prometheus_client_golang//prometheus/promauto:go_default_library", @@ -111,7 +111,7 @@ go_test( "//shared/testutil:go_default_library", "//shared/testutil/assert:go_default_library", "//shared/testutil/require:go_default_library", - "//shared/timeutils:go_default_library", + "//time:go_default_library", "@com_github_golang_mock//gomock:go_default_library", "@com_github_prysmaticlabs_eth2_types//:go_default_library", "@com_github_prysmaticlabs_go_bitfield//:go_default_library", diff --git a/beacon-chain/rpc/prysm/v1alpha1/beacon/attestations.go b/beacon-chain/rpc/prysm/v1alpha1/beacon/attestations.go index 26996e59b..2f9f48d50 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/beacon/attestations.go +++ b/beacon-chain/rpc/prysm/v1alpha1/beacon/attestations.go @@ -19,7 +19,7 @@ import ( "github.com/prysmaticlabs/prysm/shared/cmd" "github.com/prysmaticlabs/prysm/shared/pagination" "github.com/prysmaticlabs/prysm/shared/params" - "github.com/prysmaticlabs/prysm/shared/slotutil" + "github.com/prysmaticlabs/prysm/time/slots" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" "google.golang.org/protobuf/types/known/emptypb" @@ -340,8 +340,8 @@ func (bs *Server) StreamIndexedAttestations( // already being done by the attestation pool in the operations service. func (bs *Server) collectReceivedAttestations(ctx context.Context) { attsByRoot := make(map[[32]byte][]*ethpb.Attestation) - twoThirdsASlot := 2 * slotutil.DivideSlotBy(3) /* 2/3 slot duration */ - ticker := slotutil.NewSlotTickerWithOffset(bs.GenesisTimeFetcher.GenesisTime(), twoThirdsASlot, params.BeaconConfig().SecondsPerSlot) + twoThirdsASlot := 2 * slots.DivideSlotBy(3) /* 2/3 slot duration */ + ticker := slots.NewSlotTickerWithOffset(bs.GenesisTimeFetcher.GenesisTime(), twoThirdsASlot, params.BeaconConfig().SecondsPerSlot) for { select { case <-ticker.C(): diff --git a/beacon-chain/rpc/prysm/v1alpha1/beacon/committees_test.go b/beacon-chain/rpc/prysm/v1alpha1/beacon/committees_test.go index f0e25345f..7f3ef9265 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/beacon/committees_test.go +++ b/beacon-chain/rpc/prysm/v1alpha1/beacon/committees_test.go @@ -18,7 +18,7 @@ import ( "github.com/prysmaticlabs/prysm/shared/testutil" "github.com/prysmaticlabs/prysm/shared/testutil/assert" "github.com/prysmaticlabs/prysm/shared/testutil/require" - "github.com/prysmaticlabs/prysm/shared/timeutils" + prysmTime "github.com/prysmaticlabs/prysm/time" "google.golang.org/protobuf/proto" "gopkg.in/d4l3k/messagediff.v1" ) @@ -33,7 +33,7 @@ func TestServer_ListBeaconCommittees_CurrentEpoch(t *testing.T) { offset := int64(headState.Slot().Mul(params.BeaconConfig().SecondsPerSlot)) m := &mock.ChainService{ - Genesis: timeutils.Now().Add(time.Duration(-1*offset) * time.Second), + Genesis: prysmTime.Now().Add(time.Duration(-1*offset) * time.Second), } bs := &Server{ HeadFetcher: m, @@ -95,7 +95,7 @@ func TestServer_ListBeaconCommittees_PreviousEpoch(t *testing.T) { offset := int64(headState.Slot().Mul(params.BeaconConfig().SecondsPerSlot)) m := &mock.ChainService{ State: headState, - Genesis: timeutils.Now().Add(time.Duration(-1*offset) * time.Second), + Genesis: prysmTime.Now().Add(time.Duration(-1*offset) * time.Second), } bs := &Server{ HeadFetcher: m, @@ -149,7 +149,7 @@ func TestRetrieveCommitteesForRoot(t *testing.T) { offset := int64(headState.Slot().Mul(params.BeaconConfig().SecondsPerSlot)) m := &mock.ChainService{ - Genesis: timeutils.Now().Add(time.Duration(-1*offset) * time.Second), + Genesis: prysmTime.Now().Add(time.Duration(-1*offset) * time.Second), } bs := &Server{ HeadFetcher: m, diff --git a/beacon-chain/rpc/prysm/v1alpha1/beacon/validators_test.go b/beacon-chain/rpc/prysm/v1alpha1/beacon/validators_test.go index eb409750f..4924e5ca8 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/beacon/validators_test.go +++ b/beacon-chain/rpc/prysm/v1alpha1/beacon/validators_test.go @@ -29,7 +29,7 @@ import ( "github.com/prysmaticlabs/prysm/shared/testutil" "github.com/prysmaticlabs/prysm/shared/testutil/assert" "github.com/prysmaticlabs/prysm/shared/testutil/require" - "github.com/prysmaticlabs/prysm/shared/timeutils" + prysmTime "github.com/prysmaticlabs/prysm/time" "google.golang.org/protobuf/proto" "google.golang.org/protobuf/types/known/emptypb" ) @@ -1571,7 +1571,7 @@ func TestServer_GetValidatorParticipation_CurrentAndPrevEpoch(t *testing.T) { HeadFetcher: m, StateGen: stategen.New(beaconDB), GenesisTimeFetcher: &mock.ChainService{ - Genesis: timeutils.Now().Add(time.Duration(-1*offset) * time.Second), + Genesis: prysmTime.Now().Add(time.Duration(-1*offset) * time.Second), }, CanonicalFetcher: &mock.ChainService{ CanonicalRoots: map[[32]byte]bool{ @@ -1649,7 +1649,7 @@ func TestServer_GetValidatorParticipation_OrphanedUntilGenesis(t *testing.T) { HeadFetcher: m, StateGen: stategen.New(beaconDB), GenesisTimeFetcher: &mock.ChainService{ - Genesis: timeutils.Now().Add(time.Duration(-1*offset) * time.Second), + Genesis: prysmTime.Now().Add(time.Duration(-1*offset) * time.Second), }, CanonicalFetcher: &mock.ChainService{ CanonicalRoots: map[[32]byte]bool{ @@ -1714,7 +1714,7 @@ func TestServer_GetValidatorParticipation_CurrentAndPrevEpochAltair(t *testing.T HeadFetcher: m, StateGen: stategen.New(beaconDB), GenesisTimeFetcher: &mock.ChainService{ - Genesis: timeutils.Now().Add(time.Duration(-1*offset) * time.Second), + Genesis: prysmTime.Now().Add(time.Duration(-1*offset) * time.Second), }, CanonicalFetcher: &mock.ChainService{ CanonicalRoots: map[[32]byte]bool{ diff --git a/beacon-chain/rpc/prysm/v1alpha1/validator/BUILD.bazel b/beacon-chain/rpc/prysm/v1alpha1/validator/BUILD.bazel index f2d7cb961..fe51a9da0 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/validator/BUILD.bazel +++ b/beacon-chain/rpc/prysm/v1alpha1/validator/BUILD.bazel @@ -58,10 +58,10 @@ go_library( "//shared/p2putils:go_default_library", "//shared/params:go_default_library", "//shared/rand:go_default_library", - "//shared/slotutil:go_default_library", - "//shared/timeutils:go_default_library", "//shared/trieutil:go_default_library", "//shared/version:go_default_library", + "//time:go_default_library", + "//time/slots:go_default_library", "@com_github_ferranbt_fastssz//:go_default_library", "@com_github_pkg_errors//:go_default_library", "@com_github_prysmaticlabs_eth2_types//:go_default_library", @@ -132,8 +132,8 @@ go_test( "//shared/testutil:go_default_library", "//shared/testutil/assert:go_default_library", "//shared/testutil/require:go_default_library", - "//shared/timeutils:go_default_library", "//shared/trieutil:go_default_library", + "//time:go_default_library", "@com_github_golang_mock//gomock:go_default_library", "@com_github_prysmaticlabs_eth2_types//:go_default_library", "@com_github_prysmaticlabs_go_bitfield//:go_default_library", diff --git a/beacon-chain/rpc/prysm/v1alpha1/validator/assignments.go b/beacon-chain/rpc/prysm/v1alpha1/validator/assignments.go index a43c8f232..4a57a4c0b 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/validator/assignments.go +++ b/beacon-chain/rpc/prysm/v1alpha1/validator/assignments.go @@ -18,8 +18,8 @@ import ( "github.com/prysmaticlabs/prysm/shared/bytesutil" "github.com/prysmaticlabs/prysm/shared/params" "github.com/prysmaticlabs/prysm/shared/rand" - "github.com/prysmaticlabs/prysm/shared/slotutil" - "github.com/prysmaticlabs/prysm/shared/timeutils" + prysmTime "github.com/prysmaticlabs/prysm/time" + "github.com/prysmaticlabs/prysm/time/slots" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" ) @@ -48,8 +48,8 @@ func (vs *Server) StreamDuties(req *ethpb.DutiesRequest, stream ethpb.BeaconNode return status.Error(codes.Unavailable, "genesis time is not set") } var currentEpoch types.Epoch - if genesisTime.Before(timeutils.Now()) { - currentEpoch = slotutil.EpochsSinceGenesis(vs.TimeFetcher.GenesisTime()) + if genesisTime.Before(prysmTime.Now()) { + currentEpoch = slots.EpochsSinceGenesis(vs.TimeFetcher.GenesisTime()) } req.Epoch = currentEpoch res, err := vs.duties(stream.Context(), req) @@ -66,7 +66,7 @@ func (vs *Server) StreamDuties(req *ethpb.DutiesRequest, stream ethpb.BeaconNode defer stateSub.Unsubscribe() secondsPerEpoch := params.BeaconConfig().SecondsPerSlot * uint64(params.BeaconConfig().SlotsPerEpoch) - epochTicker := slotutil.NewSlotTicker(vs.TimeFetcher.GenesisTime(), secondsPerEpoch) + epochTicker := slots.NewSlotTicker(vs.TimeFetcher.GenesisTime(), secondsPerEpoch) for { select { // Ticks every epoch to submit assignments to connected validator clients. @@ -82,7 +82,7 @@ func (vs *Server) StreamDuties(req *ethpb.DutiesRequest, stream ethpb.BeaconNode case ev := <-stateChannel: // If a reorg occurred, we recompute duties for the connected validator clients // and send another response over the server stream right away. - currentEpoch = slotutil.EpochsSinceGenesis(vs.TimeFetcher.GenesisTime()) + currentEpoch = slots.EpochsSinceGenesis(vs.TimeFetcher.GenesisTime()) if ev.Type == statefeed.Reorg { data, ok := ev.Data.(*ethpbv1.EventChainReorg) if !ok { @@ -235,7 +235,7 @@ func (vs *Server) AssignValidatorToSubnet(pubkey []byte, status ethpb.ValidatorS } _, ok, expTime := cache.SubnetIDs.GetPersistentSubnets(pubkey) - if ok && expTime.After(timeutils.Now()) { + if ok && expTime.After(prysmTime.Now()) { return } epochDuration := time.Duration(params.BeaconConfig().SlotsPerEpoch.Mul(params.BeaconConfig().SecondsPerSlot)) @@ -284,7 +284,7 @@ func registerSyncSubnet(currEpoch types.Epoch, syncPeriod uint64, pubkey []byte, currPeriod := core.SyncCommitteePeriod(currEpoch) endEpoch := startEpoch + params.BeaconConfig().EpochsPerSyncCommitteePeriod _, _, ok, expTime := cache.SyncSubnetIDs.GetSyncCommitteeSubnets(pubkey, startEpoch) - if ok && expTime.After(timeutils.Now()) { + if ok && expTime.After(prysmTime.Now()) { return } firstValidEpoch, err := startEpoch.SafeSub(params.BeaconConfig().SyncCommitteeSubnetCount) diff --git a/beacon-chain/rpc/prysm/v1alpha1/validator/attester_test.go b/beacon-chain/rpc/prysm/v1alpha1/validator/attester_test.go index 993ecf450..43cc5dda8 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/validator/attester_test.go +++ b/beacon-chain/rpc/prysm/v1alpha1/validator/attester_test.go @@ -25,7 +25,7 @@ import ( "github.com/prysmaticlabs/prysm/shared/testutil" "github.com/prysmaticlabs/prysm/shared/testutil/assert" "github.com/prysmaticlabs/prysm/shared/testutil/require" - "github.com/prysmaticlabs/prysm/shared/timeutils" + prysmTime "github.com/prysmaticlabs/prysm/time" "google.golang.org/protobuf/proto" ) @@ -463,7 +463,7 @@ func TestGetAttestationData_SucceedsInFirstEpoch(t *testing.T) { FinalizationFetcher: &mock.ChainService{ CurrentJustifiedCheckPoint: beaconState.CurrentJustifiedCheckpoint(), }, - TimeFetcher: &mock.ChainService{Genesis: timeutils.Now().Add(time.Duration(-1*offset) * time.Second)}, + TimeFetcher: &mock.ChainService{Genesis: prysmTime.Now().Add(time.Duration(-1*offset) * time.Second)}, StateNotifier: chainService.StateNotifier(), } diff --git a/beacon-chain/sync/BUILD.bazel b/beacon-chain/sync/BUILD.bazel index b26d881c7..967dd5233 100644 --- a/beacon-chain/sync/BUILD.bazel +++ b/beacon-chain/sync/BUILD.bazel @@ -92,10 +92,10 @@ go_library( "//shared/rand:go_default_library", "//shared/runutil:go_default_library", "//shared/sliceutil:go_default_library", - "//shared/slotutil:go_default_library", "//shared/sszutil:go_default_library", - "//shared/timeutils:go_default_library", "//shared/version:go_default_library", + "//time:go_default_library", + "//time/slots:go_default_library", "@com_github_ferranbt_fastssz//:go_default_library", "@com_github_hashicorp_golang_lru//:go_default_library", "@com_github_kevinms_leakybucket_go//:go_default_library", @@ -197,7 +197,7 @@ go_test( "//shared/testutil:go_default_library", "//shared/testutil/assert:go_default_library", "//shared/testutil/require:go_default_library", - "//shared/timeutils:go_default_library", + "//time:go_default_library", "@com_github_d4l3k_messagediff//:go_default_library", "@com_github_ethereum_go_ethereum//p2p/enr:go_default_library", "@com_github_golang_snappy//:go_default_library", diff --git a/beacon-chain/sync/fork_watcher.go b/beacon-chain/sync/fork_watcher.go index 9337e816e..9c081df64 100644 --- a/beacon-chain/sync/fork_watcher.go +++ b/beacon-chain/sync/fork_watcher.go @@ -7,13 +7,13 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/p2p" "github.com/prysmaticlabs/prysm/shared/p2putils" "github.com/prysmaticlabs/prysm/shared/params" - "github.com/prysmaticlabs/prysm/shared/slotutil" + "github.com/prysmaticlabs/prysm/time/slots" ) // Is a background routine that observes for new incoming forks. Depending on the epoch // it will be in charge of subscribing/unsubscribing the relevant topics at the fork boundaries. func (s *Service) forkWatcher() { - slotTicker := slotutil.NewSlotTicker(s.cfg.Chain.GenesisTime(), params.BeaconConfig().SecondsPerSlot) + slotTicker := slots.NewSlotTicker(s.cfg.Chain.GenesisTime(), params.BeaconConfig().SecondsPerSlot) for { select { // In the event of a node restart, we will still end up subscribing to the correct diff --git a/beacon-chain/sync/initial-sync/BUILD.bazel b/beacon-chain/sync/initial-sync/BUILD.bazel index 43e41b7a9..721606bac 100644 --- a/beacon-chain/sync/initial-sync/BUILD.bazel +++ b/beacon-chain/sync/initial-sync/BUILD.bazel @@ -36,7 +36,7 @@ go_library( "//shared/mathutil:go_default_library", "//shared/params:go_default_library", "//shared/rand:go_default_library", - "//shared/timeutils:go_default_library", + "//time:go_default_library", "@com_github_kevinms_leakybucket_go//:go_default_library", "@com_github_libp2p_go_libp2p_core//peer:go_default_library", "@com_github_paulbellamy_ratecounter//:go_default_library", @@ -82,7 +82,7 @@ go_test( "//shared/testutil:go_default_library", "//shared/testutil/assert:go_default_library", "//shared/testutil/require:go_default_library", - "//shared/timeutils:go_default_library", + "//time:go_default_library", "@com_github_ethereum_go_ethereum//p2p/enr:go_default_library", "@com_github_kevinms_leakybucket_go//:go_default_library", "@com_github_libp2p_go_libp2p_core//:go_default_library", @@ -133,7 +133,7 @@ go_test( "//shared/testutil:go_default_library", "//shared/testutil/assert:go_default_library", "//shared/testutil/require:go_default_library", - "//shared/timeutils:go_default_library", + "//time:go_default_library", "@com_github_ethereum_go_ethereum//p2p/enr:go_default_library", "@com_github_kevinms_leakybucket_go//:go_default_library", "@com_github_libp2p_go_libp2p_core//:go_default_library", diff --git a/beacon-chain/sync/initial-sync/blocks_fetcher_peers.go b/beacon-chain/sync/initial-sync/blocks_fetcher_peers.go index 6b0500e96..3532da025 100644 --- a/beacon-chain/sync/initial-sync/blocks_fetcher_peers.go +++ b/beacon-chain/sync/initial-sync/blocks_fetcher_peers.go @@ -12,7 +12,7 @@ import ( "github.com/prysmaticlabs/prysm/cmd/beacon-chain/flags" "github.com/prysmaticlabs/prysm/shared/mathutil" "github.com/prysmaticlabs/prysm/shared/params" - "github.com/prysmaticlabs/prysm/shared/timeutils" + prysmTime "github.com/prysmaticlabs/prysm/time" "github.com/sirupsen/logrus" "go.opencensus.io/trace" ) @@ -22,12 +22,12 @@ func (f *blocksFetcher) peerLock(pid peer.ID) *peerLock { f.Lock() defer f.Unlock() if lock, ok := f.peerLocks[pid]; ok && lock != nil { - lock.accessed = timeutils.Now() + lock.accessed = prysmTime.Now() return lock } f.peerLocks[pid] = &peerLock{ Mutex: sync.Mutex{}, - accessed: timeutils.Now(), + accessed: prysmTime.Now(), } return f.peerLocks[pid] } diff --git a/beacon-chain/sync/initial-sync/blocks_fetcher_peers_test.go b/beacon-chain/sync/initial-sync/blocks_fetcher_peers_test.go index 5f105c7fb..299661149 100644 --- a/beacon-chain/sync/initial-sync/blocks_fetcher_peers_test.go +++ b/beacon-chain/sync/initial-sync/blocks_fetcher_peers_test.go @@ -15,7 +15,7 @@ import ( "github.com/prysmaticlabs/prysm/cmd/beacon-chain/flags" "github.com/prysmaticlabs/prysm/shared/testutil/assert" "github.com/prysmaticlabs/prysm/shared/testutil/require" - "github.com/prysmaticlabs/prysm/shared/timeutils" + prysmTime "github.com/prysmaticlabs/prysm/time" ) func TestBlocksFetcher_selectFailOverPeer(t *testing.T) { @@ -324,29 +324,29 @@ func TestBlocksFetcher_removeStalePeerLocks(t *testing.T) { peersIn: []peerData{ { peerID: "a", - accessed: timeutils.Now(), + accessed: prysmTime.Now(), }, { peerID: "b", - accessed: timeutils.Now(), + accessed: prysmTime.Now(), }, { peerID: "c", - accessed: timeutils.Now(), + accessed: prysmTime.Now(), }, }, peersOut: []peerData{ { peerID: "a", - accessed: timeutils.Now(), + accessed: prysmTime.Now(), }, { peerID: "b", - accessed: timeutils.Now(), + accessed: prysmTime.Now(), }, { peerID: "c", - accessed: timeutils.Now(), + accessed: prysmTime.Now(), }, }, }, @@ -356,25 +356,25 @@ func TestBlocksFetcher_removeStalePeerLocks(t *testing.T) { peersIn: []peerData{ { peerID: "a", - accessed: timeutils.Now(), + accessed: prysmTime.Now(), }, { peerID: "b", - accessed: timeutils.Now().Add(-peerLockMaxAge), + accessed: prysmTime.Now().Add(-peerLockMaxAge), }, { peerID: "c", - accessed: timeutils.Now(), + accessed: prysmTime.Now(), }, }, peersOut: []peerData{ { peerID: "a", - accessed: timeutils.Now(), + accessed: prysmTime.Now(), }, { peerID: "c", - accessed: timeutils.Now(), + accessed: prysmTime.Now(), }, }, }, @@ -384,15 +384,15 @@ func TestBlocksFetcher_removeStalePeerLocks(t *testing.T) { peersIn: []peerData{ { peerID: "a", - accessed: timeutils.Now().Add(-peerLockMaxAge), + accessed: prysmTime.Now().Add(-peerLockMaxAge), }, { peerID: "b", - accessed: timeutils.Now().Add(-peerLockMaxAge), + accessed: prysmTime.Now().Add(-peerLockMaxAge), }, { peerID: "c", - accessed: timeutils.Now().Add(-peerLockMaxAge), + accessed: prysmTime.Now().Add(-peerLockMaxAge), }, }, peersOut: []peerData{}, diff --git a/beacon-chain/sync/initial-sync/blocks_queue_test.go b/beacon-chain/sync/initial-sync/blocks_queue_test.go index 7b407397a..70a6fc511 100644 --- a/beacon-chain/sync/initial-sync/blocks_queue_test.go +++ b/beacon-chain/sync/initial-sync/blocks_queue_test.go @@ -24,7 +24,7 @@ import ( "github.com/prysmaticlabs/prysm/shared/testutil" "github.com/prysmaticlabs/prysm/shared/testutil/assert" "github.com/prysmaticlabs/prysm/shared/testutil/require" - "github.com/prysmaticlabs/prysm/shared/timeutils" + prysmTime "github.com/prysmaticlabs/prysm/time" logTest "github.com/sirupsen/logrus/hooks/test" ) @@ -745,7 +745,7 @@ func TestBlocksQueue_onProcessSkippedEvent(t *testing.T) { queue.smm.addStateMachine(256) // Machine is not skipped for too long. Do not mark as new just yet. - queue.smm.machines[256].updated = timeutils.Now().Add(-1 * (skippedMachineTimeout / 2)) + queue.smm.machines[256].updated = prysmTime.Now().Add(-1 * (skippedMachineTimeout / 2)) queue.smm.machines[256].state = stateSkipped queue.smm.addStateMachine(320) queue.smm.machines[320].state = stateScheduled @@ -764,7 +764,7 @@ func TestBlocksQueue_onProcessSkippedEvent(t *testing.T) { queue.smm.addStateMachine(256) // Machine is skipped for too long. Reset. - queue.smm.machines[256].updated = timeutils.Now().Add(-1 * skippedMachineTimeout) + queue.smm.machines[256].updated = prysmTime.Now().Add(-1 * skippedMachineTimeout) queue.smm.machines[256].state = stateSkipped queue.smm.addStateMachine(320) queue.smm.machines[320].state = stateScheduled @@ -1001,7 +1001,7 @@ func TestBlocksQueue_onCheckStaleEvent(t *testing.T) { handlerFn := queue.onCheckStaleEvent(ctx) updatedState, err := handlerFn(&stateMachine{ state: stateSent, - updated: timeutils.Now().Add(-staleEpochTimeout / 2), + updated: prysmTime.Now().Add(-staleEpochTimeout / 2), }, nil) // State should not change, as machine is not yet stale. assert.NoError(t, err) @@ -1017,7 +1017,7 @@ func TestBlocksQueue_onCheckStaleEvent(t *testing.T) { handlerFn := queue.onCheckStaleEvent(ctx) updatedState, err := handlerFn(&stateMachine{ state: stateSent, - updated: timeutils.Now().Add(-staleEpochTimeout), + updated: prysmTime.Now().Add(-staleEpochTimeout), }, nil) // State should change, as machine is stale. assert.NoError(t, err) diff --git a/beacon-chain/sync/initial-sync/fsm.go b/beacon-chain/sync/initial-sync/fsm.go index 435d3c5ac..7ef389409 100644 --- a/beacon-chain/sync/initial-sync/fsm.go +++ b/beacon-chain/sync/initial-sync/fsm.go @@ -10,7 +10,7 @@ import ( types "github.com/prysmaticlabs/eth2-types" "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/block" - "github.com/prysmaticlabs/prysm/shared/timeutils" + prysmTime "github.com/prysmaticlabs/prysm/time" ) const ( @@ -79,7 +79,7 @@ func (smm *stateMachineManager) addStateMachine(startSlot types.Slot) *stateMach start: startSlot, state: stateNew, blocks: []block.SignedBeaconBlock{}, - updated: timeutils.Now(), + updated: prysmTime.Now(), } smm.recalculateMachineAttribs() return smm.machines[startSlot] @@ -158,7 +158,7 @@ func (m *stateMachine) setState(name stateID) { return } m.state = name - m.updated = timeutils.Now() + m.updated = prysmTime.Now() } // trigger invokes the event handler on a given state machine. diff --git a/beacon-chain/sync/initial-sync/initial_sync_test.go b/beacon-chain/sync/initial-sync/initial_sync_test.go index 0ec890836..7320975ff 100644 --- a/beacon-chain/sync/initial-sync/initial_sync_test.go +++ b/beacon-chain/sync/initial-sync/initial_sync_test.go @@ -32,7 +32,7 @@ import ( "github.com/prysmaticlabs/prysm/shared/testutil" "github.com/prysmaticlabs/prysm/shared/testutil/assert" "github.com/prysmaticlabs/prysm/shared/testutil/require" - "github.com/prysmaticlabs/prysm/shared/timeutils" + prysmTime "github.com/prysmaticlabs/prysm/time" "github.com/sirupsen/logrus" ) @@ -103,7 +103,7 @@ func initializeTestServices(t *testing.T, slots []types.Slot, peers []*peerData) // makeGenesisTime where now is the current slot. func makeGenesisTime(currentSlot types.Slot) time.Time { - return timeutils.Now().Add(-1 * time.Second * time.Duration(currentSlot) * time.Duration(params.BeaconConfig().SecondsPerSlot)) + return prysmTime.Now().Add(-1 * time.Second * time.Duration(currentSlot) * time.Duration(params.BeaconConfig().SecondsPerSlot)) } // sanity test on helper function diff --git a/beacon-chain/sync/initial-sync/service.go b/beacon-chain/sync/initial-sync/service.go index db05e9b95..ca385c808 100644 --- a/beacon-chain/sync/initial-sync/service.go +++ b/beacon-chain/sync/initial-sync/service.go @@ -20,7 +20,7 @@ import ( "github.com/prysmaticlabs/prysm/shared" "github.com/prysmaticlabs/prysm/shared/abool" "github.com/prysmaticlabs/prysm/shared/params" - "github.com/prysmaticlabs/prysm/shared/timeutils" + prysmTime "github.com/prysmaticlabs/prysm/time" "github.com/sirupsen/logrus" ) @@ -82,7 +82,7 @@ func (s *Service) Start() { log.WithField("genesisTime", genesis).Info("Due to Sync Being Disabled, entering regular sync immediately.") return } - if genesis.After(timeutils.Now()) { + if genesis.After(prysmTime.Now()) { s.markSynced(genesis) log.WithField("genesisTime", genesis).Info("Genesis time has not arrived - not syncing") return diff --git a/beacon-chain/sync/pending_attestations_queue.go b/beacon-chain/sync/pending_attestations_queue.go index c907f022c..667145e74 100644 --- a/beacon-chain/sync/pending_attestations_queue.go +++ b/beacon-chain/sync/pending_attestations_queue.go @@ -14,13 +14,13 @@ import ( "github.com/prysmaticlabs/prysm/shared/params" "github.com/prysmaticlabs/prysm/shared/rand" "github.com/prysmaticlabs/prysm/shared/runutil" - "github.com/prysmaticlabs/prysm/shared/slotutil" + "github.com/prysmaticlabs/prysm/time/slots" "github.com/sirupsen/logrus" "go.opencensus.io/trace" ) // This defines how often a node cleans up and processes pending attestations in the queue. -var processPendingAttsPeriod = slotutil.DivideSlotBy(2 /* twice per slot */) +var processPendingAttsPeriod = slots.DivideSlotBy(2 /* twice per slot */) // This processes pending attestation queues on every `processPendingAttsPeriod`. func (s *Service) processPendingAttsQueue() { diff --git a/beacon-chain/sync/pending_attestations_queue_test.go b/beacon-chain/sync/pending_attestations_queue_test.go index f3d349921..c6932fca4 100644 --- a/beacon-chain/sync/pending_attestations_queue_test.go +++ b/beacon-chain/sync/pending_attestations_queue_test.go @@ -27,7 +27,7 @@ import ( "github.com/prysmaticlabs/prysm/shared/testutil" "github.com/prysmaticlabs/prysm/shared/testutil/assert" "github.com/prysmaticlabs/prysm/shared/testutil/require" - "github.com/prysmaticlabs/prysm/shared/timeutils" + prysmTime "github.com/prysmaticlabs/prysm/time" logTest "github.com/sirupsen/logrus/hooks/test" ) @@ -43,7 +43,7 @@ func TestProcessPendingAtts_NoBlockRequestBlock(t *testing.T) { p1.Peers().SetChainState(p2.PeerID(), &pb.Status{}) r := &Service{ - cfg: &Config{P2P: p1, DB: db, Chain: &mock.ChainService{Genesis: timeutils.Now(), FinalizedCheckPoint: ðpb.Checkpoint{}}}, + cfg: &Config{P2P: p1, DB: db, Chain: &mock.ChainService{Genesis: prysmTime.Now(), FinalizedCheckPoint: ðpb.Checkpoint{}}}, blkRootToPendingAtts: make(map[[32]byte][]*ethpb.SignedAggregateAttestationAndProof), chainStarted: abool.New(), } @@ -150,7 +150,7 @@ func TestProcessPendingAtts_NoBroadcastWithBadSignature(t *testing.T) { cfg: &Config{ P2P: p1, DB: db, - Chain: &mock.ChainService{State: s, Genesis: timeutils.Now(), FinalizedCheckPoint: ðpb.Checkpoint{Root: make([]byte, 32)}}, + Chain: &mock.ChainService{State: s, Genesis: prysmTime.Now(), FinalizedCheckPoint: ðpb.Checkpoint{Root: make([]byte, 32)}}, AttPool: attestations.NewPool(), }, blkRootToPendingAtts: make(map[[32]byte][]*ethpb.SignedAggregateAttestationAndProof), diff --git a/beacon-chain/sync/pending_blocks_queue.go b/beacon-chain/sync/pending_blocks_queue.go index 786eb3c6c..05d8f3280 100644 --- a/beacon-chain/sync/pending_blocks_queue.go +++ b/beacon-chain/sync/pending_blocks_queue.go @@ -18,14 +18,14 @@ import ( "github.com/prysmaticlabs/prysm/shared/params" "github.com/prysmaticlabs/prysm/shared/rand" "github.com/prysmaticlabs/prysm/shared/runutil" - "github.com/prysmaticlabs/prysm/shared/slotutil" "github.com/prysmaticlabs/prysm/shared/sszutil" + "github.com/prysmaticlabs/prysm/time/slots" "github.com/sirupsen/logrus" "github.com/trailofbits/go-mutexasserts" "go.opencensus.io/trace" ) -var processPendingBlocksPeriod = slotutil.DivideSlotBy(3 /* times per slot */) +var processPendingBlocksPeriod = slots.DivideSlotBy(3 /* times per slot */) const maxPeerRequest = 50 const numOfTries = 5 diff --git a/beacon-chain/sync/rpc.go b/beacon-chain/sync/rpc.go index 3f81949b4..23916d65f 100644 --- a/beacon-chain/sync/rpc.go +++ b/beacon-chain/sync/rpc.go @@ -15,7 +15,7 @@ import ( p2ptypes "github.com/prysmaticlabs/prysm/beacon-chain/p2p/types" "github.com/prysmaticlabs/prysm/monitoring/tracing" "github.com/prysmaticlabs/prysm/shared/params" - "github.com/prysmaticlabs/prysm/shared/timeutils" + "github.com/prysmaticlabs/prysm/time" "go.opencensus.io/trace" ) @@ -150,7 +150,7 @@ func (s *Service) registerRPC(baseTopic string, handle rpcHandler) { } s.rateLimiter.addRawStream(stream) - if err := stream.SetReadDeadline(timeutils.Now().Add(ttfbTimeout)); err != nil { + if err := stream.SetReadDeadline(time.Now().Add(ttfbTimeout)); err != nil { log.WithError(err).Debug("Could not set stream read deadline") return } diff --git a/beacon-chain/sync/rpc_ping.go b/beacon-chain/sync/rpc_ping.go index 5b84af5da..7113de038 100644 --- a/beacon-chain/sync/rpc_ping.go +++ b/beacon-chain/sync/rpc_ping.go @@ -12,7 +12,7 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/p2p" p2ptypes "github.com/prysmaticlabs/prysm/beacon-chain/p2p/types" - "github.com/prysmaticlabs/prysm/shared/timeutils" + "github.com/prysmaticlabs/prysm/time" ) // pingHandler reads the incoming ping rpc message from the peer. @@ -86,7 +86,7 @@ func (s *Service) sendPingRequest(ctx context.Context, id peer.ID) error { if err != nil { return err } - currentTime := timeutils.Now() + currentTime := time.Now() defer closeStream(stream, log) code, errMsg, err := ReadStatusCode(stream, s.cfg.P2P.Encoding()) @@ -94,7 +94,7 @@ func (s *Service) sendPingRequest(ctx context.Context, id peer.ID) error { return err } // Records the latency of the ping request for that peer. - s.cfg.P2P.Host().Peerstore().RecordLatency(id, timeutils.Now().Sub(currentTime)) + s.cfg.P2P.Host().Peerstore().RecordLatency(id, time.Now().Sub(currentTime)) if code != 0 { s.cfg.P2P.Peers().Scorers().BadResponsesScorer().Increment(stream.Conn().RemotePeer()) diff --git a/beacon-chain/sync/rpc_status.go b/beacon-chain/sync/rpc_status.go index 21a7551a6..a23308273 100644 --- a/beacon-chain/sync/rpc_status.go +++ b/beacon-chain/sync/rpc_status.go @@ -20,8 +20,8 @@ import ( "github.com/prysmaticlabs/prysm/shared/bytesutil" "github.com/prysmaticlabs/prysm/shared/params" "github.com/prysmaticlabs/prysm/shared/runutil" - "github.com/prysmaticlabs/prysm/shared/slotutil" - "github.com/prysmaticlabs/prysm/shared/timeutils" + prysmTime "github.com/prysmaticlabs/prysm/time" + "github.com/prysmaticlabs/prysm/time/slots" "github.com/sirupsen/logrus" ) @@ -56,7 +56,7 @@ func (s *Service) maintainPeerStatuses() { // Peer has vanished; nothing to do. return } - if timeutils.Now().After(lastUpdated.Add(interval)) { + if prysmTime.Now().After(lastUpdated.Add(interval)) { if err := s.reValidatePeer(s.ctx, id); err != nil { log.WithField("peer", id).WithError(err).Debug("Could not revalidate peer") s.cfg.P2P.Peers().Scorers().BadResponsesScorer().Increment(id) @@ -286,7 +286,7 @@ func (s *Service) validateStatusMessage(ctx context.Context, msg *pb.Status) err } genesis := s.cfg.Chain.GenesisTime() finalizedEpoch := s.cfg.Chain.FinalizedCheckpt().Epoch - maxEpoch := slotutil.EpochsSinceGenesis(genesis) + maxEpoch := slots.EpochsSinceGenesis(genesis) // It would take a minimum of 2 epochs to finalize a // previous epoch maxFinalizedEpoch := types.Epoch(0) diff --git a/beacon-chain/sync/rpc_status_test.go b/beacon-chain/sync/rpc_status_test.go index 2d54676eb..f8e899e39 100644 --- a/beacon-chain/sync/rpc_status_test.go +++ b/beacon-chain/sync/rpc_status_test.go @@ -31,7 +31,7 @@ import ( "github.com/prysmaticlabs/prysm/shared/testutil" "github.com/prysmaticlabs/prysm/shared/testutil/assert" "github.com/prysmaticlabs/prysm/shared/testutil/require" - "github.com/prysmaticlabs/prysm/shared/timeutils" + prysmTime "github.com/prysmaticlabs/prysm/time" "google.golang.org/protobuf/proto" ) @@ -874,7 +874,7 @@ func TestShouldResync(t *testing.T) { name: "genesis epoch should not resync when syncing is true", args: args{ headSlot: 31, - genesis: timeutils.Now(), + genesis: prysmTime.Now(), syncing: true, }, want: false, @@ -883,7 +883,7 @@ func TestShouldResync(t *testing.T) { name: "genesis epoch should not resync when syncing is false", args: args{ headSlot: 31, - genesis: timeutils.Now(), + genesis: prysmTime.Now(), syncing: false, }, want: false, @@ -892,7 +892,7 @@ func TestShouldResync(t *testing.T) { name: "two epochs behind, resync ok", args: args{ headSlot: 31, - genesis: timeutils.Now().Add(-1 * 96 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second), + genesis: prysmTime.Now().Add(-1 * 96 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second), syncing: false, }, want: true, @@ -901,7 +901,7 @@ func TestShouldResync(t *testing.T) { name: "two epochs behind, already syncing", args: args{ headSlot: 31, - genesis: timeutils.Now().Add(-1 * 96 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second), + genesis: prysmTime.Now().Add(-1 * 96 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second), syncing: true, }, want: false, diff --git a/beacon-chain/sync/service.go b/beacon-chain/sync/service.go index b76f9ca80..315de653c 100644 --- a/beacon-chain/sync/service.go +++ b/beacon-chain/sync/service.go @@ -35,8 +35,8 @@ import ( "github.com/prysmaticlabs/prysm/shared/abool" "github.com/prysmaticlabs/prysm/shared/params" "github.com/prysmaticlabs/prysm/shared/runutil" - "github.com/prysmaticlabs/prysm/shared/slotutil" - "github.com/prysmaticlabs/prysm/shared/timeutils" + prysmTime "github.com/prysmaticlabs/prysm/time" + "github.com/prysmaticlabs/prysm/time/slots" ) var _ shared.Service = (*Service)(nil) @@ -56,7 +56,7 @@ var ( // Seconds in one epoch. pendingBlockExpTime = time.Duration(params.BeaconConfig().SlotsPerEpoch.Mul(params.BeaconConfig().SecondsPerSlot)) * time.Second // time to allow processing early blocks. - earlyBlockProcessingTolerance = slotutil.MultiplySlotBy(2) + earlyBlockProcessingTolerance = slots.MultiplySlotBy(2) // time to allow processing early attestations. earlyAttestationProcessingTolerance = params.BeaconNetworkConfig().MaximumGossipClockDisparity errWrongMessage = errors.New("wrong pubsub message") @@ -239,8 +239,8 @@ func (s *Service) registerHandlers() { s.registerRPCHandlers() // Wait for chainstart in separate routine. go func() { - if startTime.After(timeutils.Now()) { - time.Sleep(timeutils.Until(startTime)) + if startTime.After(prysmTime.Now()) { + time.Sleep(prysmTime.Until(startTime)) } log.WithField("starttime", startTime).Debug("Chain started in sync service") s.markForChainStart() diff --git a/beacon-chain/sync/subscriber.go b/beacon-chain/sync/subscriber.go index da373d31d..c15edf2bd 100644 --- a/beacon-chain/sync/subscriber.go +++ b/beacon-chain/sync/subscriber.go @@ -22,7 +22,7 @@ import ( "github.com/prysmaticlabs/prysm/shared/p2putils" "github.com/prysmaticlabs/prysm/shared/params" "github.com/prysmaticlabs/prysm/shared/sliceutil" - "github.com/prysmaticlabs/prysm/shared/slotutil" + "github.com/prysmaticlabs/prysm/time/slots" "go.opencensus.io/trace" "google.golang.org/protobuf/proto" ) @@ -280,7 +280,7 @@ func (s *Service) subscribeStaticWithSubnets(topic string, validator pubsub.Vali s.subscribeWithBase(s.addDigestAndIndexToTopic(topic, digest, i), validator, handle) } genesis := s.cfg.Chain.GenesisTime() - ticker := slotutil.NewSlotTicker(genesis, params.BeaconConfig().SecondsPerSlot) + ticker := slots.NewSlotTicker(genesis, params.BeaconConfig().SecondsPerSlot) go func() { for { @@ -350,7 +350,7 @@ func (s *Service) subscribeDynamicWithSubnets( } subscriptions := make(map[uint64]*pubsub.Subscription, params.BeaconConfig().MaxCommitteesPerSlot) genesis := s.cfg.Chain.GenesisTime() - ticker := slotutil.NewSlotTicker(genesis, params.BeaconConfig().SecondsPerSlot) + ticker := slots.NewSlotTicker(genesis, params.BeaconConfig().SecondsPerSlot) go func() { for { @@ -480,7 +480,7 @@ func (s *Service) subscribeStaticWithSyncSubnets(topic string, validator pubsub. s.subscribeWithBase(s.addDigestAndIndexToTopic(topic, digest, i), validator, handle) } genesis := s.cfg.Chain.GenesisTime() - ticker := slotutil.NewSlotTicker(genesis, params.BeaconConfig().SecondsPerSlot) + ticker := slots.NewSlotTicker(genesis, params.BeaconConfig().SecondsPerSlot) go func() { for { @@ -549,7 +549,7 @@ func (s *Service) subscribeDynamicWithSyncSubnets( } subscriptions := make(map[uint64]*pubsub.Subscription, params.BeaconConfig().SyncCommitteeSubnetCount) genesis := s.cfg.Chain.GenesisTime() - ticker := slotutil.NewSlotTicker(genesis, params.BeaconConfig().SecondsPerSlot) + ticker := slots.NewSlotTicker(genesis, params.BeaconConfig().SecondsPerSlot) go func() { for { diff --git a/beacon-chain/sync/validate_beacon_blocks.go b/beacon-chain/sync/validate_beacon_blocks.go index bd0f462cb..f87fa330e 100644 --- a/beacon-chain/sync/validate_beacon_blocks.go +++ b/beacon-chain/sync/validate_beacon_blocks.go @@ -19,7 +19,7 @@ import ( "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/block" "github.com/prysmaticlabs/prysm/shared/bytesutil" "github.com/prysmaticlabs/prysm/shared/params" - "github.com/prysmaticlabs/prysm/shared/timeutils" + prysmTime "github.com/prysmaticlabs/prysm/time" "github.com/sirupsen/logrus" "go.opencensus.io/trace" ) @@ -28,7 +28,7 @@ import ( // Blocks that have already been seen are ignored. If the BLS signature is any valid signature, // this method rebroadcasts the message. func (s *Service) validateBeaconBlockPubSub(ctx context.Context, pid peer.ID, msg *pubsub.Message) pubsub.ValidationResult { - receivedTime := timeutils.Now() + receivedTime := prysmTime.Now() // Validation runs on publish (not just subscriptions), so we should approve any message from // ourselves. if pid == s.cfg.P2P.PeerID() { @@ -276,7 +276,7 @@ func captureArrivalTimeMetric(genesisTime uint64, currentSlot types.Slot) error if err != nil { return err } - ms := timeutils.Now().Sub(startTime) / time.Millisecond + ms := prysmTime.Now().Sub(startTime) / time.Millisecond arrivalBlockPropagationHistogram.Observe(float64(ms)) return nil diff --git a/endtoend/evaluators/BUILD.bazel b/endtoend/evaluators/BUILD.bazel index 3dee87938..cd43e9626 100644 --- a/endtoend/evaluators/BUILD.bazel +++ b/endtoend/evaluators/BUILD.bazel @@ -32,8 +32,8 @@ go_library( "//shared/p2putils:go_default_library", "//shared/params:go_default_library", "//shared/sliceutil:go_default_library", - "//shared/slotutil:go_default_library", "//shared/testutil:go_default_library", + "//time/slots:go_default_library", "@com_github_pkg_errors//:go_default_library", "@com_github_prysmaticlabs_eth2_types//:go_default_library", "@com_github_prysmaticlabs_go_bitfield//:go_default_library", diff --git a/endtoend/evaluators/metrics.go b/endtoend/evaluators/metrics.go index d995f9633..35850614a 100644 --- a/endtoend/evaluators/metrics.go +++ b/endtoend/evaluators/metrics.go @@ -17,7 +17,7 @@ import ( "github.com/prysmaticlabs/prysm/endtoend/types" eth "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/shared/p2putils" - "github.com/prysmaticlabs/prysm/shared/slotutil" + "github.com/prysmaticlabs/prysm/time/slots" "google.golang.org/grpc" "google.golang.org/protobuf/types/known/emptypb" ) @@ -120,7 +120,7 @@ func metricsTest(conns ...*grpc.ClientConn) error { if err != nil { return err } - timeSlot := slotutil.SlotsSinceGenesis(genesisResp.GenesisTime.AsTime()) + timeSlot := slots.SlotsSinceGenesis(genesisResp.GenesisTime.AsTime()) if uint64(chainHead.HeadSlot) != uint64(timeSlot) { return fmt.Errorf("expected metrics slot to equal chain head slot, expected %d, received %d", chainHead.HeadSlot, timeSlot) } diff --git a/endtoend/helpers/BUILD.bazel b/endtoend/helpers/BUILD.bazel index fd4ed256b..7476ced02 100644 --- a/endtoend/helpers/BUILD.bazel +++ b/endtoend/helpers/BUILD.bazel @@ -14,8 +14,8 @@ go_library( "//endtoend/types:go_default_library", "//proto/prysm/v1alpha1:go_default_library", "//shared/params:go_default_library", - "//shared/slotutil:go_default_library", - "//shared/timeutils:go_default_library", + "//time:go_default_library", + "//time/slots:go_default_library", "@com_github_sirupsen_logrus//:go_default_library", "@org_golang_google_grpc//:go_default_library", "@org_golang_x_sync//errgroup:go_default_library", diff --git a/endtoend/helpers/epochTimer.go b/endtoend/helpers/epochTimer.go index 06c092d6b..36bae73a9 100644 --- a/endtoend/helpers/epochTimer.go +++ b/endtoend/helpers/epochTimer.go @@ -3,7 +3,7 @@ package helpers import ( "time" - "github.com/prysmaticlabs/prysm/shared/timeutils" + prysmTime "github.com/prysmaticlabs/prysm/time" ) // EpochTicker is a special ticker for timing epoch changes. @@ -36,7 +36,7 @@ func NewEpochTicker(genesisTime time.Time, secondsPerEpoch uint64) *EpochTicker c: make(chan uint64), done: make(chan struct{}), } - ticker.start(genesisTime, secondsPerEpoch, timeutils.Since, timeutils.Until, time.After) + ticker.start(genesisTime, secondsPerEpoch, prysmTime.Since, prysmTime.Until, time.After) return ticker } diff --git a/endtoend/helpers/helpers.go b/endtoend/helpers/helpers.go index ad1c6ed84..df27f1025 100644 --- a/endtoend/helpers/helpers.go +++ b/endtoend/helpers/helpers.go @@ -20,7 +20,7 @@ import ( e2etypes "github.com/prysmaticlabs/prysm/endtoend/types" eth "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/shared/params" - "github.com/prysmaticlabs/prysm/shared/slotutil" + "github.com/prysmaticlabs/prysm/time/slots" log "github.com/sirupsen/logrus" "golang.org/x/sync/errgroup" "google.golang.org/grpc" @@ -242,7 +242,7 @@ func EpochTickerStartTime(genesis *eth.Genesis) time.Time { epochSeconds := uint64(params.BeaconConfig().SlotsPerEpoch.Mul(params.BeaconConfig().SecondsPerSlot)) epochSecondsHalf := time.Duration(int64(epochSeconds*1000)/2) * time.Millisecond // Adding a half slot here to ensure the requests are in the middle of an epoch. - middleOfEpoch := epochSecondsHalf + slotutil.DivideSlotBy(2 /* half a slot */) + middleOfEpoch := epochSecondsHalf + slots.DivideSlotBy(2 /* half a slot */) genesisTime := time.Unix(genesis.GenesisTime.Seconds, 0) // Offsetting the ticker from genesis so it ticks in the middle of an epoch, in order to keep results consistent. return genesisTime.Add(middleOfEpoch) diff --git a/shared/aggregation/testing/BUILD.bazel b/shared/aggregation/testing/BUILD.bazel index a00335235..d85339466 100644 --- a/shared/aggregation/testing/BUILD.bazel +++ b/shared/aggregation/testing/BUILD.bazel @@ -8,7 +8,7 @@ go_library( deps = [ "//proto/prysm/v1alpha1:go_default_library", "//shared/bls:go_default_library", - "//shared/timeutils:go_default_library", + "//time:go_default_library", "@com_github_prysmaticlabs_eth2_types//:go_default_library", "@com_github_prysmaticlabs_go_bitfield//:go_default_library", ], diff --git a/shared/aggregation/testing/bitlistutils.go b/shared/aggregation/testing/bitlistutils.go index ddcbc3705..170d84cf6 100644 --- a/shared/aggregation/testing/bitlistutils.go +++ b/shared/aggregation/testing/bitlistutils.go @@ -8,7 +8,7 @@ import ( "github.com/prysmaticlabs/go-bitfield" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/shared/bls" - "github.com/prysmaticlabs/prysm/shared/timeutils" + "github.com/prysmaticlabs/prysm/time" ) // BitlistWithAllBitsSet creates list of bitlists with all bits set. @@ -44,7 +44,7 @@ func Bitlists64WithSingleBitSet(n, length uint64) []*bitfield.Bitlist64 { // BitlistsWithMultipleBitSet creates list of bitlists with random n bits set. func BitlistsWithMultipleBitSet(t testing.TB, n, length, count uint64) []bitfield.Bitlist { - seed := timeutils.Now().UnixNano() + seed := time.Now().UnixNano() t.Logf("bitlistsWithMultipleBitSet random seed: %v", seed) rand.Seed(seed) lists := make([]bitfield.Bitlist, n) @@ -61,7 +61,7 @@ func BitlistsWithMultipleBitSet(t testing.TB, n, length, count uint64) []bitfiel // Bitlists64WithMultipleBitSet creates list of bitlists with random n bits set. func Bitlists64WithMultipleBitSet(t testing.TB, n, length, count uint64) []*bitfield.Bitlist64 { - seed := timeutils.Now().UnixNano() + seed := time.Now().UnixNano() t.Logf("Bitlists64WithMultipleBitSet random seed: %v", seed) rand.Seed(seed) lists := make([]*bitfield.Bitlist64, n) diff --git a/shared/event/BUILD.bazel b/shared/event/BUILD.bazel index 2add93e9d..0e3f9db69 100644 --- a/shared/event/BUILD.bazel +++ b/shared/event/BUILD.bazel @@ -8,7 +8,7 @@ go_library( ], importpath = "github.com/prysmaticlabs/prysm/shared/event", visibility = ["//visibility:public"], - deps = ["//shared/mclockutil:go_default_library"], + deps = ["//time/mclock:go_default_library"], ) go_test( diff --git a/shared/event/subscription.go b/shared/event/subscription.go index c6067dbb4..71c26b200 100644 --- a/shared/event/subscription.go +++ b/shared/event/subscription.go @@ -21,7 +21,7 @@ import ( "sync" "time" - "github.com/prysmaticlabs/prysm/shared/mclockutil" + "github.com/prysmaticlabs/prysm/time/mclock" ) // waitQuotient is divided against the max backoff time, in order to have N requests based on the full @@ -120,7 +120,7 @@ type resubscribeSub struct { err chan error unsub chan struct{} unsubOnce sync.Once - lastTry mclockutil.AbsTime + lastTry mclock.AbsTime waitTime, backoffMax time.Duration } @@ -155,7 +155,7 @@ func (s *resubscribeSub) subscribe() Subscription { var sub Subscription retry: for { - s.lastTry = mclockutil.Now() + s.lastTry = mclock.Now() ctx, cancel := context.WithCancel(context.TODO()) go func() { rsub, err := s.fn(ctx) @@ -194,7 +194,7 @@ func (s *resubscribeSub) waitForError(sub Subscription) bool { } func (s *resubscribeSub) backoffWait() bool { - if time.Duration(mclockutil.Now()-s.lastTry) > s.backoffMax { + if time.Duration(mclock.Now()-s.lastTry) > s.backoffMax { s.waitTime = s.backoffMax / waitQuotient } else { s.waitTime *= 2 diff --git a/shared/interop/BUILD.bazel b/shared/interop/BUILD.bazel index 0f6440303..7bd9bd947 100644 --- a/shared/interop/BUILD.bazel +++ b/shared/interop/BUILD.bazel @@ -17,8 +17,8 @@ go_library( "//shared/hashutil:go_default_library", "//shared/mputil:go_default_library", "//shared/params:go_default_library", - "//shared/timeutils:go_default_library", "//shared/trieutil:go_default_library", + "//time:go_default_library", "@com_github_pkg_errors//:go_default_library", ], ) diff --git a/shared/interop/generate_genesis_state.go b/shared/interop/generate_genesis_state.go index 05f556225..be4aea128 100644 --- a/shared/interop/generate_genesis_state.go +++ b/shared/interop/generate_genesis_state.go @@ -15,8 +15,8 @@ import ( "github.com/prysmaticlabs/prysm/shared/hashutil" "github.com/prysmaticlabs/prysm/shared/mputil" "github.com/prysmaticlabs/prysm/shared/params" - "github.com/prysmaticlabs/prysm/shared/timeutils" "github.com/prysmaticlabs/prysm/shared/trieutil" + "github.com/prysmaticlabs/prysm/time" ) var ( @@ -54,7 +54,7 @@ func GenerateGenesisStateFromDepositData( } root := trie.HashTreeRoot() if genesisTime == 0 { - genesisTime = uint64(timeutils.Now().Unix()) + genesisTime = uint64(time.Now().Unix()) } beaconState, err := coreState.GenesisBeaconState(ctx, deposits, genesisTime, ðpb.Eth1Data{ DepositRoot: root[:], diff --git a/shared/keystore/BUILD.bazel b/shared/keystore/BUILD.bazel index e953cb288..003d077dc 100644 --- a/shared/keystore/BUILD.bazel +++ b/shared/keystore/BUILD.bazel @@ -13,7 +13,7 @@ go_library( deps = [ "//shared/bls:go_default_library", "//shared/fileutil:go_default_library", - "//shared/timeutils:go_default_library", + "//time:go_default_library", "@com_github_minio_sha256_simd//:go_default_library", "@com_github_pborman_uuid//:go_default_library", "@com_github_sirupsen_logrus//:go_default_library", diff --git a/shared/keystore/utils.go b/shared/keystore/utils.go index 77bfe97d5..d6b18cdd3 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/timeutils" + prysmTime "github.com/prysmaticlabs/prysm/time" ) func aesCTRXOR(key, inText, iv []byte) ([]byte, error) { @@ -52,7 +52,7 @@ func ensureInt(x interface{}) int { // keyFileName implements the naming convention for keyfiles: // UTC--- func keyFileName(pubkey bls.PublicKey) string { - ts := timeutils.Now().UTC() + ts := prysmTime.Now().UTC() return fmt.Sprintf("UTC--%s--%s", toISO8601(ts), hex.EncodeToString(pubkey.Marshal())[:8]) } diff --git a/shared/slotutil/testing/mock_test.go b/shared/slotutil/testing/mock_test.go deleted file mode 100644 index a45febfd2..000000000 --- a/shared/slotutil/testing/mock_test.go +++ /dev/null @@ -1,5 +0,0 @@ -package testing - -import "github.com/prysmaticlabs/prysm/shared/slotutil" - -var _ slotutil.Ticker = (*MockTicker)(nil) diff --git a/slasher/beaconclient/BUILD.bazel b/slasher/beaconclient/BUILD.bazel index eba21924e..c4b110987 100644 --- a/slasher/beaconclient/BUILD.bazel +++ b/slasher/beaconclient/BUILD.bazel @@ -22,9 +22,9 @@ go_library( "//shared/grpcutils:go_default_library", "//shared/params:go_default_library", "//shared/sliceutil:go_default_library", - "//shared/slotutil:go_default_library", "//slasher/cache:go_default_library", "//slasher/db:go_default_library", + "//time/slots:go_default_library", "@com_github_grpc_ecosystem_go_grpc_middleware//:go_default_library", "@com_github_grpc_ecosystem_go_grpc_middleware//retry:go_default_library", "@com_github_grpc_ecosystem_go_grpc_middleware//tracing/opentracing:go_default_library", @@ -61,11 +61,11 @@ go_test( "//shared/event:go_default_library", "//shared/mock:go_default_library", "//shared/params:go_default_library", - "//shared/slotutil:go_default_library", "//shared/testutil/assert:go_default_library", "//shared/testutil/require:go_default_library", "//slasher/cache:go_default_library", "//slasher/db/testing:go_default_library", + "//time/slots:go_default_library", "@com_github_golang_mock//gomock:go_default_library", "@com_github_prysmaticlabs_eth2_types//:go_default_library", "@com_github_sirupsen_logrus//:go_default_library", diff --git a/slasher/beaconclient/receivers.go b/slasher/beaconclient/receivers.go index 99606fbec..ce1fba3bf 100644 --- a/slasher/beaconclient/receivers.go +++ b/slasher/beaconclient/receivers.go @@ -8,7 +8,7 @@ import ( "time" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" - "github.com/prysmaticlabs/prysm/shared/slotutil" + "github.com/prysmaticlabs/prysm/time/slots" "github.com/sirupsen/logrus" "go.opencensus.io/trace" "google.golang.org/grpc/codes" @@ -149,7 +149,7 @@ func (s *Service) collectReceivedAttestations(ctx context.Context) { defer span.End() var atts []*ethpb.IndexedAttestation - halfSlot := slotutil.DivideSlotBy(2 /* 1/2 slot duration */) + halfSlot := slots.DivideSlotBy(2 /* 1/2 slot duration */) ticker := time.NewTicker(halfSlot) defer ticker.Stop() for { diff --git a/slasher/beaconclient/receivers_test.go b/slasher/beaconclient/receivers_test.go index 06f535d23..17930a07d 100644 --- a/slasher/beaconclient/receivers_test.go +++ b/slasher/beaconclient/receivers_test.go @@ -9,9 +9,9 @@ import ( ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/shared/event" "github.com/prysmaticlabs/prysm/shared/mock" - "github.com/prysmaticlabs/prysm/shared/slotutil" "github.com/prysmaticlabs/prysm/shared/testutil/require" testDB "github.com/prysmaticlabs/prysm/slasher/db/testing" + "github.com/prysmaticlabs/prysm/time/slots" "google.golang.org/protobuf/types/known/emptypb" ) @@ -109,7 +109,7 @@ func TestService_ReceiveAttestations_Batched(t *testing.T) { nil, ).Do(func() { // Let a slot pass for the ticker. - time.Sleep(slotutil.DivideSlotBy(1)) + time.Sleep(slots.DivideSlotBy(1)) cancel() }) diff --git a/shared/timeutils/BUILD.bazel b/time/BUILD.bazel similarity index 70% rename from shared/timeutils/BUILD.bazel rename to time/BUILD.bazel index dfebcd028..fa51cdfe2 100644 --- a/shared/timeutils/BUILD.bazel +++ b/time/BUILD.bazel @@ -3,6 +3,6 @@ load("@prysm//tools/go:def.bzl", "go_library") go_library( name = "go_default_library", srcs = ["utils.go"], - importpath = "github.com/prysmaticlabs/prysm/shared/timeutils", + importpath = "github.com/prysmaticlabs/prysm/time", visibility = ["//visibility:public"], ) diff --git a/shared/mclockutil/BUILD.bazel b/time/mclock/BUILD.bazel similarity index 77% rename from shared/mclockutil/BUILD.bazel rename to time/mclock/BUILD.bazel index 6e01102bc..0a947cf91 100644 --- a/shared/mclockutil/BUILD.bazel +++ b/time/mclock/BUILD.bazel @@ -3,7 +3,7 @@ load("@prysm//tools/go:def.bzl", "go_library") go_library( name = "go_default_library", srcs = ["mclock.go"], - importpath = "github.com/prysmaticlabs/prysm/shared/mclockutil", + importpath = "github.com/prysmaticlabs/prysm/time/mclock", visibility = ["//visibility:public"], deps = ["@com_github_aristanetworks_goarista//monotime:go_default_library"], ) diff --git a/shared/mclockutil/mclock.go b/time/mclock/mclock.go similarity index 98% rename from shared/mclockutil/mclock.go rename to time/mclock/mclock.go index af817f932..e41ef0418 100644 --- a/shared/mclockutil/mclock.go +++ b/time/mclock/mclock.go @@ -15,7 +15,7 @@ // along with the go-ethereum library. If not, see . // Package mclockutil is a wrapper for a monotonic clock source. -package mclockutil +package mclock import ( "time" diff --git a/shared/slotutil/BUILD.bazel b/time/slots/BUILD.bazel similarity index 85% rename from shared/slotutil/BUILD.bazel rename to time/slots/BUILD.bazel index 4c61bfe39..9bb7733ad 100644 --- a/shared/slotutil/BUILD.bazel +++ b/time/slots/BUILD.bazel @@ -7,11 +7,11 @@ go_library( "slotticker.go", "slottime.go", ], - importpath = "github.com/prysmaticlabs/prysm/shared/slotutil", + importpath = "github.com/prysmaticlabs/prysm/time/slots", visibility = ["//visibility:public"], deps = [ "//shared/params:go_default_library", - "//shared/timeutils:go_default_library", + "//time:go_default_library", "@com_github_prysmaticlabs_eth2_types//:go_default_library", "@com_github_sirupsen_logrus//:go_default_library", ], @@ -30,7 +30,7 @@ go_test( deps = [ "//shared/params:go_default_library", "//shared/testutil/require:go_default_library", - "//shared/timeutils:go_default_library", + "//time:go_default_library", "@com_github_prysmaticlabs_eth2_types//:go_default_library", "@com_github_sirupsen_logrus//:go_default_library", "@com_github_sirupsen_logrus//hooks/test:go_default_library", diff --git a/shared/slotutil/countdown.go b/time/slots/countdown.go similarity index 94% rename from shared/slotutil/countdown.go rename to time/slots/countdown.go index 19e6f11f0..01ccc2359 100644 --- a/shared/slotutil/countdown.go +++ b/time/slots/countdown.go @@ -1,4 +1,4 @@ -package slotutil +package slots import ( "context" @@ -6,7 +6,7 @@ import ( "time" "github.com/prysmaticlabs/prysm/shared/params" - "github.com/prysmaticlabs/prysm/shared/timeutils" + prysmTime "github.com/prysmaticlabs/prysm/time" "github.com/sirupsen/logrus" ) @@ -29,7 +29,7 @@ func CountdownToGenesis(ctx context.Context, genesisTime time.Time, genesisValid } secondTimerActivated := false for { - currentTime := timeutils.Now() + currentTime := prysmTime.Now() if currentTime.After(genesisTime) { log.WithFields(logFields).Info("Chain genesis time reached") return diff --git a/shared/slotutil/countdown_test.go b/time/slots/countdown_test.go similarity index 90% rename from shared/slotutil/countdown_test.go rename to time/slots/countdown_test.go index a0ee93aa6..665b3366c 100644 --- a/shared/slotutil/countdown_test.go +++ b/time/slots/countdown_test.go @@ -1,4 +1,4 @@ -package slotutil +package slots import ( "context" @@ -7,7 +7,7 @@ import ( "github.com/prysmaticlabs/prysm/shared/params" "github.com/prysmaticlabs/prysm/shared/testutil/require" - "github.com/prysmaticlabs/prysm/shared/timeutils" + prysmTime "github.com/prysmaticlabs/prysm/time" "github.com/sirupsen/logrus" logTest "github.com/sirupsen/logrus/hooks/test" ) @@ -27,7 +27,7 @@ func TestCountdownToGenesis(t *testing.T) { genesisReached := "Chain genesis time reached" CountdownToGenesis( context.Background(), - timeutils.Now().Add(2*time.Second), + prysmTime.Now().Add(2*time.Second), params.BeaconConfig().MinGenesisActiveValidatorCount, [32]byte{}, ) @@ -45,7 +45,7 @@ func TestCountdownToGenesis(t *testing.T) { }() CountdownToGenesis( ctx, - timeutils.Now().Add(5*time.Second), + prysmTime.Now().Add(5*time.Second), params.BeaconConfig().MinGenesisActiveValidatorCount, [32]byte{}, ) diff --git a/shared/slotutil/slotticker.go b/time/slots/slotticker.go similarity index 91% rename from shared/slotutil/slotticker.go rename to time/slots/slotticker.go index 0bd30b93e..013e05bff 100644 --- a/shared/slotutil/slotticker.go +++ b/time/slots/slotticker.go @@ -1,11 +1,11 @@ // Package slotutil includes ticker and timer-related functions for Ethereum consensus. -package slotutil +package slots import ( "time" types "github.com/prysmaticlabs/eth2-types" - "github.com/prysmaticlabs/prysm/shared/timeutils" + prysmTime "github.com/prysmaticlabs/prysm/time" ) // The Ticker interface defines a type which can expose a @@ -48,7 +48,7 @@ func NewSlotTicker(genesisTime time.Time, secondsPerSlot uint64) *SlotTicker { c: make(chan types.Slot), done: make(chan struct{}), } - ticker.start(genesisTime, secondsPerSlot, timeutils.Since, timeutils.Until, time.After) + ticker.start(genesisTime, secondsPerSlot, prysmTime.Since, prysmTime.Until, time.After) return ticker } @@ -65,7 +65,7 @@ func NewSlotTickerWithOffset(genesisTime time.Time, offset time.Duration, second c: make(chan types.Slot), done: make(chan struct{}), } - ticker.start(genesisTime.Add(offset), secondsPerSlot, timeutils.Since, timeutils.Until, time.After) + ticker.start(genesisTime.Add(offset), secondsPerSlot, prysmTime.Since, prysmTime.Until, time.After) return ticker } diff --git a/shared/slotutil/slotticker_test.go b/time/slots/slotticker_test.go similarity index 99% rename from shared/slotutil/slotticker_test.go rename to time/slots/slotticker_test.go index 995aea843..97e6c2547 100644 --- a/shared/slotutil/slotticker_test.go +++ b/time/slots/slotticker_test.go @@ -1,4 +1,4 @@ -package slotutil +package slots import ( "testing" diff --git a/shared/slotutil/slottime.go b/time/slots/slottime.go similarity index 89% rename from shared/slotutil/slottime.go rename to time/slots/slottime.go index 20c7fca3a..201ee9a27 100644 --- a/shared/slotutil/slottime.go +++ b/time/slots/slottime.go @@ -1,11 +1,11 @@ -package slotutil +package slots import ( "time" types "github.com/prysmaticlabs/eth2-types" "github.com/prysmaticlabs/prysm/shared/params" - "github.com/prysmaticlabs/prysm/shared/timeutils" + prysmTime "github.com/prysmaticlabs/prysm/time" ) // SlotStartTime returns the start time in terms of its unix epoch @@ -19,10 +19,10 @@ func SlotStartTime(genesis uint64, slot types.Slot) time.Time { // SlotsSinceGenesis returns the number of slots since // the provided genesis time. func SlotsSinceGenesis(genesis time.Time) types.Slot { - if genesis.After(timeutils.Now()) { // Genesis has not occurred yet. + if genesis.After(prysmTime.Now()) { // Genesis has not occurred yet. return 0 } - return types.Slot(uint64(timeutils.Since(genesis).Seconds()) / params.BeaconConfig().SecondsPerSlot) + return types.Slot(uint64(prysmTime.Since(genesis).Seconds()) / params.BeaconConfig().SecondsPerSlot) } // EpochsSinceGenesis returns the number of slots since diff --git a/shared/slotutil/slottime_test.go b/time/slots/slottime_test.go similarity index 91% rename from shared/slotutil/slottime_test.go rename to time/slots/slottime_test.go index 72f70c719..232d4dca0 100644 --- a/shared/slotutil/slottime_test.go +++ b/time/slots/slottime_test.go @@ -1,4 +1,4 @@ -package slotutil +package slots import ( "testing" @@ -6,7 +6,7 @@ import ( types "github.com/prysmaticlabs/eth2-types" "github.com/prysmaticlabs/prysm/shared/params" - "github.com/prysmaticlabs/prysm/shared/timeutils" + prysmTime "github.com/prysmaticlabs/prysm/time" ) func TestSlotsSinceGenesis(t *testing.T) { @@ -21,14 +21,14 @@ func TestSlotsSinceGenesis(t *testing.T) { { name: "pre-genesis", args: args{ - genesis: timeutils.Now().Add(1 * time.Hour), // 1 hour in the future + genesis: prysmTime.Now().Add(1 * time.Hour), // 1 hour in the future }, want: 0, }, { name: "post-genesis", args: args{ - genesis: timeutils.Now().Add(-5 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second), + genesis: prysmTime.Now().Add(-5 * time.Duration(params.BeaconConfig().SecondsPerSlot) * time.Second), }, want: 5, }, diff --git a/shared/slotutil/slotutil_test.go b/time/slots/slotutil_test.go similarity index 91% rename from shared/slotutil/slotutil_test.go rename to time/slots/slotutil_test.go index 4d41353ad..754635798 100644 --- a/shared/slotutil/slotutil_test.go +++ b/time/slots/slotutil_test.go @@ -1,4 +1,4 @@ -package slotutil +package slots import ( "io/ioutil" diff --git a/shared/slotutil/testing/BUILD.bazel b/time/slots/testing/BUILD.bazel similarity index 73% rename from shared/slotutil/testing/BUILD.bazel rename to time/slots/testing/BUILD.bazel index 23feded52..cef79693b 100644 --- a/shared/slotutil/testing/BUILD.bazel +++ b/time/slots/testing/BUILD.bazel @@ -3,7 +3,7 @@ load("@prysm//tools/go:def.bzl", "go_library", "go_test") go_library( name = "go_default_library", srcs = ["mock.go"], - importpath = "github.com/prysmaticlabs/prysm/shared/slotutil/testing", + importpath = "github.com/prysmaticlabs/prysm/time/slots/testing", visibility = ["//visibility:public"], deps = ["@com_github_prysmaticlabs_eth2_types//:go_default_library"], ) @@ -12,5 +12,5 @@ go_test( name = "go_default_test", srcs = ["mock_test.go"], embed = [":go_default_library"], - deps = ["//shared/slotutil:go_default_library"], + deps = ["//time/slots:go_default_library"], ) diff --git a/shared/slotutil/testing/mock.go b/time/slots/testing/mock.go similarity index 100% rename from shared/slotutil/testing/mock.go rename to time/slots/testing/mock.go diff --git a/time/slots/testing/mock_test.go b/time/slots/testing/mock_test.go new file mode 100644 index 000000000..0cc5c073a --- /dev/null +++ b/time/slots/testing/mock_test.go @@ -0,0 +1,7 @@ +package testing + +import ( + "github.com/prysmaticlabs/prysm/time/slots" +) + +var _ slots.Ticker = (*MockTicker)(nil) diff --git a/shared/timeutils/utils.go b/time/utils.go similarity index 95% rename from shared/timeutils/utils.go rename to time/utils.go index 7c7dd051e..8e15d27e8 100644 --- a/shared/timeutils/utils.go +++ b/time/utils.go @@ -1,5 +1,5 @@ // Package timeutils is a wrapper around the go standard time library. -package timeutils +package time import ( "time" diff --git a/validator/accounts/BUILD.bazel b/validator/accounts/BUILD.bazel index 17d362802..3069e51e9 100644 --- a/validator/accounts/BUILD.bazel +++ b/validator/accounts/BUILD.bazel @@ -82,7 +82,7 @@ go_test( "//shared/petnames:go_default_library", "//shared/testutil/assert:go_default_library", "//shared/testutil/require:go_default_library", - "//shared/timeutils:go_default_library", + "//time:go_default_library", "//validator/accounts/iface:go_default_library", "//validator/accounts/wallet:go_default_library", "//validator/keymanager:go_default_library", diff --git a/validator/accounts/accounts_import_test.go b/validator/accounts/accounts_import_test.go index ac5b741a9..1030c8561 100644 --- a/validator/accounts/accounts_import_test.go +++ b/validator/accounts/accounts_import_test.go @@ -18,7 +18,7 @@ import ( "github.com/prysmaticlabs/prysm/shared/params" "github.com/prysmaticlabs/prysm/shared/testutil/assert" "github.com/prysmaticlabs/prysm/shared/testutil/require" - "github.com/prysmaticlabs/prysm/shared/timeutils" + prysmTime "github.com/prysmaticlabs/prysm/time" "github.com/prysmaticlabs/prysm/validator/accounts/iface" "github.com/prysmaticlabs/prysm/validator/accounts/wallet" "github.com/prysmaticlabs/prysm/validator/keymanager" @@ -403,7 +403,7 @@ func createKeystore(t *testing.T, path string) (*keymanager.Keystore, string) { encoded, err := json.MarshalIndent(keystoreFile, "", "\t") require.NoError(t, err) // Write the encoded keystore to disk with the timestamp appended - createdAt := timeutils.Now().Unix() + createdAt := prysmTime.Now().Unix() fullPath := filepath.Join(path, fmt.Sprintf(imported.KeystoreFileNameFormat, createdAt)) require.NoError(t, ioutil.WriteFile(fullPath, encoded, os.ModePerm)) return keystoreFile, fullPath diff --git a/validator/client/BUILD.bazel b/validator/client/BUILD.bazel index 701adc5eb..1201f0a8f 100644 --- a/validator/client/BUILD.bazel +++ b/validator/client/BUILD.bazel @@ -42,9 +42,9 @@ go_library( "//shared/params:go_default_library", "//shared/rand:go_default_library", "//shared/slashutil:go_default_library", - "//shared/slotutil:go_default_library", - "//shared/timeutils:go_default_library", "//shared/version:go_default_library", + "//time:go_default_library", + "//time/slots:go_default_library", "//validator/accounts/iface:go_default_library", "//validator/accounts/wallet:go_default_library", "//validator/client/iface:go_default_library", @@ -118,12 +118,12 @@ go_test( "//shared/fileutil:go_default_library", "//shared/mock:go_default_library", "//shared/params:go_default_library", - "//shared/slotutil:go_default_library", - "//shared/slotutil/testing: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", + "//time:go_default_library", + "//time/slots:go_default_library", + "//time/slots/testing:go_default_library", "//validator/accounts/testing:go_default_library", "//validator/client/iface:go_default_library", "//validator/client/testutil:go_default_library", diff --git a/validator/client/aggregate.go b/validator/client/aggregate.go index 3c2e8bf42..c1f42c5d1 100644 --- a/validator/client/aggregate.go +++ b/validator/client/aggregate.go @@ -13,8 +13,8 @@ import ( validatorpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/validator-client" "github.com/prysmaticlabs/prysm/shared/bls" "github.com/prysmaticlabs/prysm/shared/params" - "github.com/prysmaticlabs/prysm/shared/slotutil" - "github.com/prysmaticlabs/prysm/shared/timeutils" + prysmTime "github.com/prysmaticlabs/prysm/time" + "github.com/prysmaticlabs/prysm/time/slots" "go.opencensus.io/trace" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" @@ -149,13 +149,13 @@ func (v *validator) waitToSlotTwoThirds(ctx context.Context, slot types.Slot) { ctx, span := trace.StartSpan(ctx, "validator.waitToSlotTwoThirds") defer span.End() - oneThird := slotutil.DivideSlotBy(3 /* one third of slot duration */) + oneThird := slots.DivideSlotBy(3 /* one third of slot duration */) twoThird := oneThird + oneThird delay := twoThird - startTime := slotutil.SlotStartTime(v.genesisTime, slot) + startTime := slots.SlotStartTime(v.genesisTime, slot) finalTime := startTime.Add(delay) - wait := timeutils.Until(finalTime) + wait := prysmTime.Until(finalTime) if wait <= 0 { return } diff --git a/validator/client/aggregate_test.go b/validator/client/aggregate_test.go index 91dc25cc1..13d75c461 100644 --- a/validator/client/aggregate_test.go +++ b/validator/client/aggregate_test.go @@ -11,11 +11,11 @@ import ( ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/shared/bls" "github.com/prysmaticlabs/prysm/shared/params" - "github.com/prysmaticlabs/prysm/shared/slotutil" "github.com/prysmaticlabs/prysm/shared/testutil" "github.com/prysmaticlabs/prysm/shared/testutil/assert" "github.com/prysmaticlabs/prysm/shared/testutil/require" - "github.com/prysmaticlabs/prysm/shared/timeutils" + "github.com/prysmaticlabs/prysm/time" + "github.com/prysmaticlabs/prysm/time/slots" logTest "github.com/sirupsen/logrus/hooks/test" ) @@ -118,30 +118,30 @@ func TestSubmitAggregateAndProof_Ok(t *testing.T) { func TestWaitForSlotTwoThird_WaitCorrectly(t *testing.T) { validator, _, _, finish := setup(t) defer finish() - currentTime := timeutils.Now() + currentTime := time.Now() numOfSlots := types.Slot(4) validator.genesisTime = uint64(currentTime.Unix()) - uint64(numOfSlots.Mul(params.BeaconConfig().SecondsPerSlot)) - oneThird := slotutil.DivideSlotBy(3 /* one third of slot duration */) + oneThird := slots.DivideSlotBy(3 /* one third of slot duration */) timeToSleep := oneThird + oneThird twoThirdTime := currentTime.Add(timeToSleep) validator.waitToSlotTwoThirds(context.Background(), numOfSlots) - currentTime = timeutils.Now() + currentTime = time.Now() assert.Equal(t, twoThirdTime.Unix(), currentTime.Unix()) } func TestWaitForSlotTwoThird_DoneContext_ReturnsImmediately(t *testing.T) { validator, _, _, finish := setup(t) defer finish() - currentTime := timeutils.Now() + currentTime := time.Now() numOfSlots := types.Slot(4) validator.genesisTime = uint64(currentTime.Unix()) - uint64(numOfSlots.Mul(params.BeaconConfig().SecondsPerSlot)) - expectedTime := timeutils.Now() + expectedTime := time.Now() ctx, cancel := context.WithCancel(context.Background()) cancel() validator.waitToSlotTwoThirds(ctx, numOfSlots) - currentTime = timeutils.Now() + currentTime = time.Now() assert.Equal(t, expectedTime.Unix(), currentTime.Unix()) } diff --git a/validator/client/attest.go b/validator/client/attest.go index 6aa2c2889..a155caebe 100644 --- a/validator/client/attest.go +++ b/validator/client/attest.go @@ -20,8 +20,8 @@ import ( "github.com/prysmaticlabs/prysm/shared/hashutil" "github.com/prysmaticlabs/prysm/shared/mputil" "github.com/prysmaticlabs/prysm/shared/params" - "github.com/prysmaticlabs/prysm/shared/slotutil" - "github.com/prysmaticlabs/prysm/shared/timeutils" + prysmTime "github.com/prysmaticlabs/prysm/time" + "github.com/prysmaticlabs/prysm/time/slots" "github.com/prysmaticlabs/prysm/validator/client/iface" "github.com/sirupsen/logrus" "go.opencensus.io/trace" @@ -257,10 +257,10 @@ func (v *validator) waitOneThirdOrValidBlock(ctx context.Context, slot types.Slo return } - delay := slotutil.DivideSlotBy(3 /* a third of the slot duration */) - startTime := slotutil.SlotStartTime(v.genesisTime, slot) + delay := slots.DivideSlotBy(3 /* a third of the slot duration */) + startTime := slots.SlotStartTime(v.genesisTime, slot) finalTime := startTime.Add(delay) - wait := timeutils.Until(finalTime) + wait := prysmTime.Until(finalTime) if wait <= 0 { return } diff --git a/validator/client/attest_test.go b/validator/client/attest_test.go index d1d09831b..e1a181423 100644 --- a/validator/client/attest_test.go +++ b/validator/client/attest_test.go @@ -24,7 +24,7 @@ import ( "github.com/prysmaticlabs/prysm/shared/testutil" "github.com/prysmaticlabs/prysm/shared/testutil/assert" "github.com/prysmaticlabs/prysm/shared/testutil/require" - "github.com/prysmaticlabs/prysm/shared/timeutils" + prysmTime "github.com/prysmaticlabs/prysm/time" logTest "github.com/sirupsen/logrus/hooks/test" grpc "google.golang.org/grpc" "gopkg.in/d4l3k/messagediff.v1" @@ -333,7 +333,7 @@ func TestAttestToBlockHead_DoesNotAttestBeforeDelay(t *testing.T) { pubKey := [48]byte{} copy(pubKey[:], validatorKey.PublicKey().Marshal()) - validator.genesisTime = uint64(timeutils.Now().Unix()) + validator.genesisTime = uint64(prysmTime.Now().Unix()) m.validatorClient.EXPECT().GetDuties( gomock.Any(), // ctx gomock.AssignableToTypeOf(ðpb.DutiesRequest{}), @@ -363,7 +363,7 @@ func TestAttestToBlockHead_DoesAttestAfterDelay(t *testing.T) { wg.Add(1) defer wg.Wait() - validator.genesisTime = uint64(timeutils.Now().Unix()) + validator.genesisTime = uint64(prysmTime.Now().Unix()) validatorIndex := types.ValidatorIndex(5) committee := []types.ValidatorIndex{0, 3, 4, 2, validatorIndex, 6, 8, 9, 10} pubKey := [48]byte{} diff --git a/validator/client/log.go b/validator/client/log.go index f4498afd3..3aa2d6a89 100644 --- a/validator/client/log.go +++ b/validator/client/log.go @@ -9,7 +9,7 @@ import ( ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/shared/bytesutil" "github.com/prysmaticlabs/prysm/shared/params" - "github.com/prysmaticlabs/prysm/shared/timeutils" + prysmTime "github.com/prysmaticlabs/prysm/time" "github.com/sirupsen/logrus" ) @@ -77,7 +77,7 @@ func (v *validator) LogNextDutyTimeLeft(slot types.Slot) error { if err != nil { return err } - timeLeft := time.Duration(nextDutyTime.Unix() - timeutils.Now().Unix()).Nanoseconds() + timeLeft := time.Duration(nextDutyTime.Unix() - prysmTime.Now().Unix()).Nanoseconds() // There is not much value to log if time left is less than one slot. if uint64(timeLeft) >= params.BeaconConfig().SecondsPerSlot { log.WithFields( diff --git a/validator/client/propose.go b/validator/client/propose.go index 241356bf9..5f400f5a2 100644 --- a/validator/client/propose.go +++ b/validator/client/propose.go @@ -19,8 +19,8 @@ import ( "github.com/prysmaticlabs/prysm/shared/mputil" "github.com/prysmaticlabs/prysm/shared/params" "github.com/prysmaticlabs/prysm/shared/rand" - "github.com/prysmaticlabs/prysm/shared/timeutils" "github.com/prysmaticlabs/prysm/shared/version" + prysmTime "github.com/prysmaticlabs/prysm/time" "github.com/prysmaticlabs/prysm/validator/client/iface" "github.com/sirupsen/logrus" "go.opencensus.io/trace" @@ -333,7 +333,7 @@ func ProposeExit( if err != nil { return errors.Wrap(err, "gRPC call to get genesis time failed") } - totalSecondsPassed := timeutils.Now().Unix() - genesisResponse.GenesisTime.Seconds + totalSecondsPassed := prysmTime.Now().Unix() - genesisResponse.GenesisTime.Seconds currentEpoch := types.Epoch(uint64(totalSecondsPassed) / uint64(params.BeaconConfig().SlotsPerEpoch.Mul(params.BeaconConfig().SecondsPerSlot))) exit := ðpb.VoluntaryExit{Epoch: currentEpoch, ValidatorIndex: indexResponse.Index} diff --git a/validator/client/testutil/BUILD.bazel b/validator/client/testutil/BUILD.bazel index 69af122b4..94ea6275d 100644 --- a/validator/client/testutil/BUILD.bazel +++ b/validator/client/testutil/BUILD.bazel @@ -12,7 +12,7 @@ go_library( deps = [ "//proto/prysm/v1alpha1:go_default_library", "//shared/bytesutil:go_default_library", - "//shared/timeutils:go_default_library", + "//time:go_default_library", "//validator/client/iface:go_default_library", "//validator/keymanager:go_default_library", "@com_github_prysmaticlabs_eth2_types//:go_default_library", diff --git a/validator/client/testutil/mock_validator.go b/validator/client/testutil/mock_validator.go index e9157b444..2a035c24e 100644 --- a/validator/client/testutil/mock_validator.go +++ b/validator/client/testutil/mock_validator.go @@ -7,7 +7,7 @@ import ( types "github.com/prysmaticlabs/eth2-types" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" - "github.com/prysmaticlabs/prysm/shared/timeutils" + prysmTime "github.com/prysmaticlabs/prysm/time" "github.com/prysmaticlabs/prysm/validator/client/iface" "github.com/prysmaticlabs/prysm/validator/keymanager" ) @@ -112,7 +112,7 @@ func (fv *FakeValidator) CanonicalHeadSlot(_ context.Context) (types.Slot, error // SlotDeadline for mocking. func (fv *FakeValidator) SlotDeadline(_ types.Slot) time.Time { fv.SlotDeadlineCalled = true - return timeutils.Now() + return prysmTime.Now() } // NextSlot for mocking. diff --git a/validator/client/validator.go b/validator/client/validator.go index 4598d7dd1..8440c945c 100644 --- a/validator/client/validator.go +++ b/validator/client/validator.go @@ -28,7 +28,7 @@ import ( "github.com/prysmaticlabs/prysm/shared/featureconfig" "github.com/prysmaticlabs/prysm/shared/hashutil" "github.com/prysmaticlabs/prysm/shared/params" - "github.com/prysmaticlabs/prysm/shared/slotutil" + "github.com/prysmaticlabs/prysm/time/slots" accountsiface "github.com/prysmaticlabs/prysm/validator/accounts/iface" "github.com/prysmaticlabs/prysm/validator/accounts/wallet" "github.com/prysmaticlabs/prysm/validator/client/iface" @@ -72,7 +72,7 @@ type validator struct { highestValidSlot types.Slot domainDataCache *ristretto.Cache aggregatedSlotCommitteeIDCache *lru.Cache - ticker slotutil.Ticker + ticker slots.Ticker prevBalance map[[48]byte]uint64 duties *ethpb.DutiesResponse startBalances map[[48]byte]uint64 @@ -188,7 +188,7 @@ func (v *validator) WaitForChainStart(ctx context.Context) error { // Once the ChainStart log is received, we update the genesis time of the validator client // and begin a slot ticker used to track the current slot the beacon node is in. - v.ticker = slotutil.NewSlotTicker(time.Unix(int64(v.genesisTime), 0), params.BeaconConfig().SecondsPerSlot) + v.ticker = slots.NewSlotTicker(time.Unix(int64(v.genesisTime), 0), params.BeaconConfig().SecondsPerSlot) log.WithField("genesisTime", time.Unix(int64(v.genesisTime), 0)).Info("Beacon chain started") return nil } @@ -209,7 +209,7 @@ func (v *validator) WaitForSync(ctx context.Context) error { for { select { // Poll every half slot. - case <-time.After(slotutil.DivideSlotBy(2 /* twice per slot */)): + case <-time.After(slots.DivideSlotBy(2 /* twice per slot */)): s, err := v.node.GetSyncStatus(ctx, &emptypb.Empty{}) if err != nil { return errors.Wrap(iface.ErrConnectionIssue, errors.Wrap(err, "could not get sync status").Error()) diff --git a/validator/client/wait_for_activation.go b/validator/client/wait_for_activation.go index 4b330aabc..57e10b8ba 100644 --- a/validator/client/wait_for_activation.go +++ b/validator/client/wait_for_activation.go @@ -11,7 +11,7 @@ import ( "github.com/prysmaticlabs/prysm/shared/bytesutil" "github.com/prysmaticlabs/prysm/shared/mathutil" "github.com/prysmaticlabs/prysm/shared/params" - "github.com/prysmaticlabs/prysm/shared/slotutil" + "github.com/prysmaticlabs/prysm/time/slots" "github.com/prysmaticlabs/prysm/validator/keymanager/remote" "go.opencensus.io/trace" ) @@ -179,7 +179,7 @@ func (v *validator) waitForActivation(ctx context.Context, accountsChangedChan < } } - v.ticker = slotutil.NewSlotTicker(time.Unix(int64(v.genesisTime), 0), params.BeaconConfig().SecondsPerSlot) + v.ticker = slots.NewSlotTicker(time.Unix(int64(v.genesisTime), 0), params.BeaconConfig().SecondsPerSlot) return nil } diff --git a/validator/client/wait_for_activation_test.go b/validator/client/wait_for_activation_test.go index b4b702a30..d5960183d 100644 --- a/validator/client/wait_for_activation_test.go +++ b/validator/client/wait_for_activation_test.go @@ -13,9 +13,9 @@ import ( "github.com/prysmaticlabs/prysm/shared/bls" "github.com/prysmaticlabs/prysm/shared/bytesutil" "github.com/prysmaticlabs/prysm/shared/mock" - slotutilmock "github.com/prysmaticlabs/prysm/shared/slotutil/testing" "github.com/prysmaticlabs/prysm/shared/testutil/assert" "github.com/prysmaticlabs/prysm/shared/testutil/require" + slotutilmock "github.com/prysmaticlabs/prysm/time/slots/testing" walletMock "github.com/prysmaticlabs/prysm/validator/accounts/testing" "github.com/prysmaticlabs/prysm/validator/client/testutil" "github.com/prysmaticlabs/prysm/validator/keymanager/derived" diff --git a/validator/rpc/BUILD.bazel b/validator/rpc/BUILD.bazel index e774e8cd1..46e40cda5 100644 --- a/validator/rpc/BUILD.bazel +++ b/validator/rpc/BUILD.bazel @@ -30,8 +30,8 @@ go_library( "//shared/petnames:go_default_library", "//shared/promptutil:go_default_library", "//shared/rand:go_default_library", - "//shared/timeutils:go_default_library", "//shared/version:go_default_library", + "//time:go_default_library", "//validator/accounts:go_default_library", "//validator/accounts/iface:go_default_library", "//validator/accounts/wallet:go_default_library", @@ -89,7 +89,7 @@ go_test( "//shared/mock:go_default_library", "//shared/testutil/assert:go_default_library", "//shared/testutil/require:go_default_library", - "//shared/timeutils:go_default_library", + "//time:go_default_library", "//validator/accounts:go_default_library", "//validator/accounts/iface:go_default_library", "//validator/accounts/wallet:go_default_library", diff --git a/validator/rpc/auth.go b/validator/rpc/auth.go index a8cc4a5bb..aa0b32c66 100644 --- a/validator/rpc/auth.go +++ b/validator/rpc/auth.go @@ -11,7 +11,7 @@ import ( pb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/validator-client" "github.com/prysmaticlabs/prysm/shared/fileutil" "github.com/prysmaticlabs/prysm/shared/promptutil" - "github.com/prysmaticlabs/prysm/shared/timeutils" + prysmTime "github.com/prysmaticlabs/prysm/time" "github.com/prysmaticlabs/prysm/validator/accounts/wallet" "golang.org/x/crypto/bcrypt" "google.golang.org/grpc/codes" @@ -191,7 +191,7 @@ func (s *Server) checkUserSignup(ctx context.Context) { 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 := timeutils.Now().Add(tokenExpiryLength) + expirationTime := prysmTime.Now().Add(tokenExpiryLength) token := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.StandardClaims{ ExpiresAt: expirationTime.Unix(), }) diff --git a/validator/rpc/intercepter_test.go b/validator/rpc/intercepter_test.go index dd5194ec3..45c5b76f6 100644 --- a/validator/rpc/intercepter_test.go +++ b/validator/rpc/intercepter_test.go @@ -6,7 +6,7 @@ import ( "github.com/golang-jwt/jwt" "github.com/prysmaticlabs/prysm/shared/testutil/require" - "github.com/prysmaticlabs/prysm/shared/timeutils" + "github.com/prysmaticlabs/prysm/time" "google.golang.org/grpc" "google.golang.org/grpc/metadata" ) @@ -63,7 +63,7 @@ func TestServer_JWTInterceptor_BadToken(t *testing.T) { func TestServer_JWTInterceptor_InvalidSigningType(t *testing.T) { ss := &Server{jwtKey: make([]byte, 32)} - expirationTime := timeutils.Now().Add(tokenExpiryLength) + expirationTime := time.Now().Add(tokenExpiryLength) // Use a different signing type than the expected, HMAC. token := jwt.NewWithClaims(jwt.SigningMethodRS256, jwt.StandardClaims{ ExpiresAt: expirationTime.Unix(),