From 8219af46e491ae8ae518998743bbcb6e812c7b54 Mon Sep 17 00:00:00 2001 From: terence tsao Date: Thu, 30 Sep 2021 12:00:14 -0700 Subject: [PATCH] Move slot epoch from core to time pkg (#9714) * Move slot epoch from core to time pkg * Fix fuzz Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com> --- beacon-chain/blockchain/BUILD.bazel | 2 +- beacon-chain/blockchain/head.go | 14 +++--- .../blockchain/head_sync_committee_info.go | 18 +++---- .../head_sync_committee_info_test.go | 8 ++-- beacon-chain/blockchain/head_test.go | 6 +-- beacon-chain/blockchain/log.go | 6 +-- .../blockchain/process_attestation.go | 4 +- .../blockchain/process_attestation_helpers.go | 6 +-- .../blockchain/process_attestation_test.go | 4 +- beacon-chain/blockchain/process_block.go | 10 ++-- .../blockchain/process_block_helpers.go | 16 +++---- .../blockchain/receive_attestation.go | 12 ++--- .../blockchain/receive_attestation_test.go | 4 +- beacon-chain/blockchain/receive_block.go | 4 +- beacon-chain/blockchain/service.go | 6 +-- beacon-chain/blockchain/service_test.go | 6 +-- .../blockchain/weak_subjectivity_checks.go | 4 +- beacon-chain/core/altair/BUILD.bazel | 4 +- beacon-chain/core/altair/attestation.go | 6 +-- beacon-chain/core/altair/attestation_test.go | 14 +++--- beacon-chain/core/altair/block.go | 6 +-- beacon-chain/core/altair/block_test.go | 18 +++---- beacon-chain/core/altair/epoch_precompute.go | 14 +++--- beacon-chain/core/altair/epoch_spec.go | 4 +- beacon-chain/core/altair/epoch_spec_test.go | 4 +- beacon-chain/core/altair/sync_committee.go | 12 ++--- beacon-chain/core/altair/upgrade.go | 4 +- beacon-chain/core/altair/upgrade_test.go | 4 +- beacon-chain/core/blocks/BUILD.bazel | 4 +- beacon-chain/core/blocks/attestation.go | 8 ++-- beacon-chain/core/blocks/attester_slashing.go | 4 +- beacon-chain/core/blocks/exit.go | 4 +- beacon-chain/core/blocks/exit_test.go | 4 +- beacon-chain/core/blocks/header_test.go | 14 +++--- beacon-chain/core/blocks/proposer_slashing.go | 6 +-- .../core/blocks/proposer_slashing_test.go | 4 +- beacon-chain/core/blocks/randao.go | 4 +- beacon-chain/core/blocks/randao_test.go | 8 ++-- beacon-chain/core/blocks/signature.go | 14 +++--- beacon-chain/core/epoch/BUILD.bazel | 4 +- beacon-chain/core/epoch/epoch_processing.go | 16 +++---- .../core/epoch/epoch_processing_test.go | 6 +-- .../core/epoch/precompute/BUILD.bazel | 4 +- .../core/epoch/precompute/attestation.go | 6 +-- .../precompute/justification_finalization.go | 8 ++-- beacon-chain/core/epoch/precompute/new.go | 6 +-- .../core/epoch/precompute/reward_penalty.go | 6 +-- .../epoch/precompute/reward_penalty_test.go | 4 +- .../core/epoch/precompute/slashing.go | 4 +- beacon-chain/core/helpers/BUILD.bazel | 4 +- beacon-chain/core/helpers/attestation.go | 16 +++---- beacon-chain/core/helpers/attestation_test.go | 4 +- beacon-chain/core/helpers/beacon_committee.go | 20 ++++---- .../core/helpers/beacon_committee_test.go | 26 +++++----- beacon-chain/core/helpers/block.go | 4 +- .../core/helpers/rewards_penalties.go | 4 +- .../core/helpers/rewards_penalties_test.go | 12 ++--- beacon-chain/core/helpers/sync_committee.go | 8 ++-- beacon-chain/core/helpers/validators.go | 8 ++-- beacon-chain/core/helpers/validators_test.go | 6 +-- .../core/helpers/weak_subjectivity.go | 10 ++-- beacon-chain/core/signing/BUILD.bazel | 2 +- .../core/signing/signing_root_test.go | 4 +- beacon-chain/core/{ => time}/BUILD.bazel | 22 +-------- beacon-chain/core/{ => time}/slot_epoch.go | 2 +- .../core/{ => time}/slot_epoch_test.go | 2 +- beacon-chain/core/transition/BUILD.bazel | 4 +- .../altair_transition_no_verify_sig_test.go | 10 ++-- .../core/transition/benchmarks_test.go | 6 +-- beacon-chain/core/transition/transition.go | 8 ++-- .../transition_no_verify_sig_test.go | 6 +-- .../core/transition/transition_test.go | 10 ++-- beacon-chain/core/validators/BUILD.bazel | 4 +- beacon-chain/core/validators/validator.go | 8 ++-- .../core/validators/validator_test.go | 10 ++-- beacon-chain/db/kv/BUILD.bazel | 2 +- beacon-chain/db/kv/blocks.go | 6 +-- beacon-chain/db/kv/state.go | 4 +- beacon-chain/db/slasherkv/BUILD.bazel | 4 +- beacon-chain/db/slasherkv/pruning.go | 4 +- beacon-chain/db/slasherkv/pruning_test.go | 20 ++++---- beacon-chain/operations/slashings/BUILD.bazel | 2 +- beacon-chain/operations/slashings/service.go | 4 +- .../operations/voluntaryexits/BUILD.bazel | 2 +- .../operations/voluntaryexits/service.go | 4 +- beacon-chain/p2p/BUILD.bazel | 2 +- beacon-chain/p2p/broadcaster.go | 4 +- beacon-chain/p2p/discovery.go | 4 +- beacon-chain/p2p/fork.go | 6 +-- beacon-chain/p2p/fork_watcher.go | 4 +- beacon-chain/p2p/gossip_scoring_params.go | 6 +-- beacon-chain/p2p/peers/BUILD.bazel | 2 +- beacon-chain/p2p/peers/status.go | 6 +-- beacon-chain/powchain/BUILD.bazel | 4 +- beacon-chain/powchain/service.go | 6 +-- beacon-chain/powchain/service_test.go | 4 +- beacon-chain/rpc/apimiddleware/BUILD.bazel | 4 +- .../rpc/apimiddleware/custom_hooks.go | 4 +- .../rpc/apimiddleware/custom_hooks_test.go | 4 +- beacon-chain/rpc/eth/beacon/BUILD.bazel | 4 +- beacon-chain/rpc/eth/beacon/pool.go | 4 +- beacon-chain/rpc/eth/beacon/pool_test.go | 8 ++-- beacon-chain/rpc/eth/beacon/state.go | 4 +- beacon-chain/rpc/eth/beacon/validator.go | 12 ++--- beacon-chain/rpc/eth/beacon/validator_test.go | 12 ++--- beacon-chain/rpc/eth/validator/BUILD.bazel | 4 +- beacon-chain/rpc/eth/validator/validator.go | 30 ++++++------ .../rpc/eth/validator/validator_test.go | 10 ++-- .../rpc/prysm/v1alpha1/beacon/BUILD.bazel | 4 +- .../rpc/prysm/v1alpha1/beacon/assignments.go | 6 +-- .../prysm/v1alpha1/beacon/assignments_test.go | 4 +- .../rpc/prysm/v1alpha1/beacon/attestations.go | 4 +- .../v1alpha1/beacon/attestations_test.go | 4 +- .../rpc/prysm/v1alpha1/beacon/blocks.go | 12 ++--- .../rpc/prysm/v1alpha1/beacon/blocks_test.go | 8 ++-- .../rpc/prysm/v1alpha1/beacon/committees.go | 16 +++---- .../prysm/v1alpha1/beacon/committees_test.go | 4 +- .../rpc/prysm/v1alpha1/beacon/validators.go | 40 ++++++++-------- .../v1alpha1/beacon/validators_stream.go | 4 +- .../prysm/v1alpha1/beacon/validators_test.go | 16 +++---- .../rpc/prysm/v1alpha1/validator/BUILD.bazel | 4 +- .../prysm/v1alpha1/validator/aggregator.go | 4 +- .../prysm/v1alpha1/validator/assignments.go | 20 ++++---- .../rpc/prysm/v1alpha1/validator/attester.go | 18 +++---- .../prysm/v1alpha1/validator/attester_test.go | 10 ++-- .../rpc/prysm/v1alpha1/validator/proposer.go | 8 ++-- .../prysm/v1alpha1/validator/proposer_test.go | 6 +-- .../rpc/prysm/v1alpha1/validator/status.go | 8 ++-- .../prysm/v1alpha1/validator/status_test.go | 10 ++-- beacon-chain/slasher/BUILD.bazel | 4 +- .../slasher/detect_attestations_test.go | 10 ++-- beacon-chain/slasher/receive.go | 8 ++-- beacon-chain/state/stategen/BUILD.bazel | 2 +- beacon-chain/state/stategen/replay.go | 4 +- beacon-chain/state/stategen/setter.go | 4 +- beacon-chain/sync/BUILD.bazel | 4 +- beacon-chain/sync/fork_watcher.go | 4 +- beacon-chain/sync/initial-sync/BUILD.bazel | 4 +- .../sync/initial-sync/blocks_fetcher_peers.go | 4 +- .../sync/initial-sync/blocks_fetcher_test.go | 14 +++--- .../sync/initial-sync/blocks_fetcher_utils.go | 18 +++---- .../initial-sync/blocks_fetcher_utils_test.go | 6 +-- .../sync/initial-sync/blocks_queue.go | 14 +++--- .../sync/initial-sync/blocks_queue_test.go | 14 +++--- beacon-chain/sync/initial-sync/fsm.go | 4 +- .../sync/initial-sync/initial_sync_test.go | 6 +-- beacon-chain/sync/initial-sync/round_robin.go | 24 +++++----- beacon-chain/sync/initial-sync/service.go | 8 ++-- .../sync/initial-sync/service_test.go | 6 +-- beacon-chain/sync/metrics.go | 4 +- .../sync/pending_attestations_queue.go | 4 +- beacon-chain/sync/pending_blocks_queue.go | 4 +- beacon-chain/sync/rpc.go | 4 +- .../sync/rpc_beacon_blocks_by_range_test.go | 6 +-- beacon-chain/sync/rpc_goodbye.go | 4 +- beacon-chain/sync/rpc_metadata.go | 6 +-- beacon-chain/sync/rpc_ping.go | 4 +- beacon-chain/sync/rpc_send_request.go | 6 +-- beacon-chain/sync/rpc_status.go | 16 +++---- beacon-chain/sync/service.go | 6 +-- beacon-chain/sync/subscriber.go | 4 +- .../sync/subscriber_beacon_attestation.go | 6 +-- beacon-chain/sync/subscriber_test.go | 4 +- beacon-chain/sync/validate_aggregate_proof.go | 10 ++-- .../sync/validate_beacon_attestation.go | 4 +- beacon-chain/sync/validate_beacon_blocks.go | 12 ++--- .../sync/validate_beacon_blocks_test.go | 4 +- .../sync/validate_proposer_slashing_test.go | 6 +-- .../validate_sync_committee_message_test.go | 14 +++--- .../validate_sync_contribution_proof_test.go | 48 +++++++++---------- .../sync/validate_voluntary_exit_test.go | 4 +- network/forks/BUILD.bazel | 2 +- network/forks/fork.go | 10 ++-- testing/endtoend/evaluators/BUILD.bazel | 2 +- testing/endtoend/evaluators/fork.go | 4 +- testing/endtoend/evaluators/validator.go | 10 ++-- testing/fuzz/BUILD.bazel | 4 +- testing/fuzz/state_fuzz.go | 6 +-- testing/slasher/simulator/BUILD.bazel | 2 +- .../simulator/attestation_generator.go | 4 +- testing/slasher/simulator/simulator.go | 6 +-- testing/util/BUILD.bazel | 4 +- testing/util/altair.go | 6 +-- testing/util/attestation.go | 4 +- testing/util/block.go | 14 +++--- testing/util/helpers.go | 4 +- testing/util/helpers_test.go | 6 +-- testing/util/sync_aggregate.go | 10 ++-- tools/benchmark-files-gen/BUILD.bazel | 2 +- tools/benchmark-files-gen/main.go | 4 +- validator/client/BUILD.bazel | 2 +- validator/client/aggregate.go | 6 +-- validator/client/log.go | 4 +- validator/client/metrics.go | 18 +++---- validator/client/propose.go | 4 +- validator/client/runner.go | 4 +- validator/client/sync_committee.go | 8 ++-- validator/client/validator.go | 8 ++-- validator/db/kv/BUILD.bazel | 2 +- validator/db/kv/proposer_protection.go | 6 +-- 200 files changed, 739 insertions(+), 757 deletions(-) rename beacon-chain/core/{ => time}/BUILD.bazel (59%) rename beacon-chain/core/{ => time}/slot_epoch.go (99%) rename beacon-chain/core/{ => time}/slot_epoch_test.go (99%) diff --git a/beacon-chain/blockchain/BUILD.bazel b/beacon-chain/blockchain/BUILD.bazel index 8cfd5cfc3c..5f64e46da5 100644 --- a/beacon-chain/blockchain/BUILD.bazel +++ b/beacon-chain/blockchain/BUILD.bazel @@ -30,13 +30,13 @@ go_library( "//async/event:go_default_library", "//beacon-chain/cache:go_default_library", "//beacon-chain/cache/depositcache:go_default_library", - "//beacon-chain/core:go_default_library", "//beacon-chain/core/altair:go_default_library", "//beacon-chain/core/epoch/precompute:go_default_library", "//beacon-chain/core/feed:go_default_library", "//beacon-chain/core/feed/state:go_default_library", "//beacon-chain/core/helpers:go_default_library", "//beacon-chain/core/signing:go_default_library", + "//beacon-chain/core/time:go_default_library", "//beacon-chain/core/transition:go_default_library", "//beacon-chain/db:go_default_library", "//beacon-chain/db/filters:go_default_library", diff --git a/beacon-chain/blockchain/head.go b/beacon-chain/blockchain/head.go index 927ecdf207..53a53d7ab4 100644 --- a/beacon-chain/blockchain/head.go +++ b/beacon-chain/blockchain/head.go @@ -7,10 +7,10 @@ import ( "github.com/pkg/errors" types "github.com/prysmaticlabs/eth2-types" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/feed" statefeed "github.com/prysmaticlabs/prysm/beacon-chain/core/feed/state" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/forkchoice/protoarray" "github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/config/features" @@ -141,7 +141,7 @@ func (s *Service) saveHead(ctx context.Context, headRoot [32]byte) error { NewHeadBlock: headRoot[:], OldHeadState: oldStateRoot, NewHeadState: newStateRoot, - Epoch: core.SlotToEpoch(newHeadSlot), + Epoch: time.SlotToEpoch(newHeadSlot), }, }) @@ -298,7 +298,7 @@ func (s *Service) cacheJustifiedStateBalances(ctx context.Context, justifiedRoot return errors.New("justified state can't be nil") } - epoch := core.CurrentEpoch(justifiedState) + epoch := time.CurrentEpoch(justifiedState) justifiedBalances := make([]uint64, justifiedState.NumValidators()) if err := justifiedState.ReadFromEveryValidator(func(idx int, val state.ReadOnlyValidator) error { @@ -336,15 +336,15 @@ func (s *Service) notifyNewHeadEvent( currentDutyDependentRoot := s.genesisRoot[:] var previousDutyEpoch types.Epoch - currentDutyEpoch := core.SlotToEpoch(newHeadSlot) + currentDutyEpoch := time.SlotToEpoch(newHeadSlot) if currentDutyEpoch > 0 { previousDutyEpoch = currentDutyEpoch.Sub(1) } - currentDutySlot, err := core.StartSlot(currentDutyEpoch) + currentDutySlot, err := time.StartSlot(currentDutyEpoch) if err != nil { return errors.Wrap(err, "could not get duty slot") } - previousDutySlot, err := core.StartSlot(previousDutyEpoch) + previousDutySlot, err := time.StartSlot(previousDutyEpoch) if err != nil { return errors.Wrap(err, "could not get duty slot") } @@ -366,7 +366,7 @@ func (s *Service) notifyNewHeadEvent( Slot: newHeadSlot, Block: newHeadRoot, State: newHeadStateRoot, - EpochTransition: core.IsEpochStart(newHeadSlot), + EpochTransition: time.IsEpochStart(newHeadSlot), PreviousDutyDependentRoot: previousDutyDependentRoot, CurrentDutyDependentRoot: currentDutyDependentRoot, }, diff --git a/beacon-chain/blockchain/head_sync_committee_info.go b/beacon-chain/blockchain/head_sync_committee_info.go index 84c2a35b5d..66fc04bb3f 100644 --- a/beacon-chain/blockchain/head_sync_committee_info.go +++ b/beacon-chain/blockchain/head_sync_committee_info.go @@ -8,10 +8,10 @@ import ( types "github.com/prysmaticlabs/eth2-types" "github.com/prysmaticlabs/prysm/async" "github.com/prysmaticlabs/prysm/beacon-chain/cache" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/altair" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/beacon-chain/core/signing" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/core/transition" "github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/config/params" @@ -62,14 +62,14 @@ func (s *Service) HeadSyncContributionProofDomain(ctx context.Context, slot type // rather than for the range // [compute_start_slot_at_epoch(epoch), compute_start_slot_at_epoch(epoch) + SLOTS_PER_EPOCH) func (s *Service) HeadSyncCommitteeIndices(ctx context.Context, index types.ValidatorIndex, slot types.Slot) ([]types.CommitteeIndex, error) { - nextSlotEpoch := core.SlotToEpoch(slot + 1) - currentEpoch := core.SlotToEpoch(slot) + nextSlotEpoch := time.SlotToEpoch(slot + 1) + currentEpoch := time.SlotToEpoch(slot) switch { - case core.SyncCommitteePeriod(nextSlotEpoch) == core.SyncCommitteePeriod(currentEpoch): + case time.SyncCommitteePeriod(nextSlotEpoch) == time.SyncCommitteePeriod(currentEpoch): return s.headCurrentSyncCommitteeIndices(ctx, index, slot) // At sync committee period boundary, validator should sample the next epoch sync committee. - case core.SyncCommitteePeriod(nextSlotEpoch) == core.SyncCommitteePeriod(currentEpoch)+1: + case time.SyncCommitteePeriod(nextSlotEpoch) == time.SyncCommitteePeriod(currentEpoch)+1: return s.headNextSyncCommitteeIndices(ctx, index, slot) default: // Impossible condition. @@ -105,11 +105,11 @@ func (s *Service) HeadSyncCommitteePubKeys(ctx context.Context, slot types.Slot, return nil, err } - nextSlotEpoch := core.SlotToEpoch(headState.Slot() + 1) - currEpoch := core.SlotToEpoch(headState.Slot()) + nextSlotEpoch := time.SlotToEpoch(headState.Slot() + 1) + currEpoch := time.SlotToEpoch(headState.Slot()) var syncCommittee *ethpb.SyncCommittee - if currEpoch == nextSlotEpoch || core.SyncCommitteePeriod(currEpoch) == core.SyncCommitteePeriod(nextSlotEpoch) { + if currEpoch == nextSlotEpoch || time.SyncCommitteePeriod(currEpoch) == time.SyncCommitteePeriod(nextSlotEpoch) { syncCommittee, err = headState.CurrentSyncCommittee() if err != nil { return nil, err @@ -130,7 +130,7 @@ func (s *Service) domainWithHeadState(ctx context.Context, slot types.Slot, doma if err != nil { return nil, err } - return signing.Domain(headState.Fork(), core.SlotToEpoch(headState.Slot()), domain, headState.GenesisValidatorRoot()) + return signing.Domain(headState.Fork(), time.SlotToEpoch(headState.Slot()), domain, headState.GenesisValidatorRoot()) } // returns the head state that is advanced up to `slot`. It utilizes the cache `syncCommitteeHeadState` by retrieving using `slot` as key. diff --git a/beacon-chain/blockchain/head_sync_committee_info_test.go b/beacon-chain/blockchain/head_sync_committee_info_test.go index 4ce7503214..d3fb47ea30 100644 --- a/beacon-chain/blockchain/head_sync_committee_info_test.go +++ b/beacon-chain/blockchain/head_sync_committee_info_test.go @@ -6,8 +6,8 @@ import ( types "github.com/prysmaticlabs/eth2-types" "github.com/prysmaticlabs/prysm/beacon-chain/cache" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/signing" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" dbtest "github.com/prysmaticlabs/prysm/beacon-chain/db/testing" "github.com/prysmaticlabs/prysm/beacon-chain/state/stategen" "github.com/prysmaticlabs/prysm/config/params" @@ -122,7 +122,7 @@ func TestService_HeadSyncCommitteeDomain(t *testing.T) { c := &Service{} c.head = &head{state: s} - wanted, err := signing.Domain(s.Fork(), core.SlotToEpoch(s.Slot()), params.BeaconConfig().DomainSyncCommittee, s.GenesisValidatorRoot()) + wanted, err := signing.Domain(s.Fork(), time.SlotToEpoch(s.Slot()), params.BeaconConfig().DomainSyncCommittee, s.GenesisValidatorRoot()) require.NoError(t, err) d, err := c.HeadSyncCommitteeDomain(context.Background(), 0) @@ -136,7 +136,7 @@ func TestService_HeadSyncContributionProofDomain(t *testing.T) { c := &Service{} c.head = &head{state: s} - wanted, err := signing.Domain(s.Fork(), core.SlotToEpoch(s.Slot()), params.BeaconConfig().DomainContributionAndProof, s.GenesisValidatorRoot()) + wanted, err := signing.Domain(s.Fork(), time.SlotToEpoch(s.Slot()), params.BeaconConfig().DomainContributionAndProof, s.GenesisValidatorRoot()) require.NoError(t, err) d, err := c.HeadSyncContributionProofDomain(context.Background(), 0) @@ -150,7 +150,7 @@ func TestService_HeadSyncSelectionProofDomain(t *testing.T) { c := &Service{} c.head = &head{state: s} - wanted, err := signing.Domain(s.Fork(), core.SlotToEpoch(s.Slot()), params.BeaconConfig().DomainSyncCommitteeSelectionProof, s.GenesisValidatorRoot()) + wanted, err := signing.Domain(s.Fork(), time.SlotToEpoch(s.Slot()), params.BeaconConfig().DomainSyncCommitteeSelectionProof, s.GenesisValidatorRoot()) require.NoError(t, err) d, err := c.HeadSyncSelectionProofDomain(context.Background(), 0) diff --git a/beacon-chain/blockchain/head_test.go b/beacon-chain/blockchain/head_test.go index 1d3e826616..ec3e942381 100644 --- a/beacon-chain/blockchain/head_test.go +++ b/beacon-chain/blockchain/head_test.go @@ -8,7 +8,7 @@ import ( types "github.com/prysmaticlabs/eth2-types" mock "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing" - "github.com/prysmaticlabs/prysm/beacon-chain/core" + coreTime "github.com/prysmaticlabs/prysm/beacon-chain/core/time" testDB "github.com/prysmaticlabs/prysm/beacon-chain/db/testing" "github.com/prysmaticlabs/prysm/config/features" "github.com/prysmaticlabs/prysm/config/params" @@ -187,9 +187,9 @@ func Test_notifyNewHeadEvent(t *testing.T) { }, genesisRoot: genesisRoot, } - epoch1Start, err := core.StartSlot(1) + epoch1Start, err := coreTime.StartSlot(1) require.NoError(t, err) - epoch2Start, err := core.StartSlot(1) + epoch2Start, err := coreTime.StartSlot(1) require.NoError(t, err) require.NoError(t, bState.SetSlot(epoch1Start)) diff --git a/beacon-chain/blockchain/log.go b/beacon-chain/blockchain/log.go index 278ab35f68..fe803a9476 100644 --- a/beacon-chain/blockchain/log.go +++ b/beacon-chain/blockchain/log.go @@ -5,7 +5,7 @@ import ( "fmt" "time" - "github.com/prysmaticlabs/prysm/beacon-chain/core" + coreTime "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/config/params" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/block" @@ -44,7 +44,7 @@ func logStateTransitionData(b block.BeaconBlock) { } func logBlockSyncStatus(block block.BeaconBlock, blockRoot [32]byte, finalized *ethpb.Checkpoint, receivedTime time.Time, genesisTime uint64) error { - startTime, err := core.SlotToTime(genesisTime, block.Slot()) + startTime, err := coreTime.SlotToTime(genesisTime, block.Slot()) if err != nil { return err } @@ -52,7 +52,7 @@ func logBlockSyncStatus(block block.BeaconBlock, blockRoot [32]byte, finalized * "slot": block.Slot(), "slotInEpoch": block.Slot() % params.BeaconConfig().SlotsPerEpoch, "block": fmt.Sprintf("0x%s...", hex.EncodeToString(blockRoot[:])[:8]), - "epoch": core.SlotToEpoch(block.Slot()), + "epoch": coreTime.SlotToEpoch(block.Slot()), "finalizedEpoch": finalized.Epoch, "finalizedRoot": fmt.Sprintf("0x%s...", hex.EncodeToString(finalized.Root)[:8]), }).Info("Synced new block") diff --git a/beacon-chain/blockchain/process_attestation.go b/beacon-chain/blockchain/process_attestation.go index e40b72764f..14998a74a3 100644 --- a/beacon-chain/blockchain/process_attestation.go +++ b/beacon-chain/blockchain/process_attestation.go @@ -4,8 +4,8 @@ import ( "context" "github.com/pkg/errors" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" + coreTime "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/encoding/bytesutil" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" @@ -75,7 +75,7 @@ func (s *Service) onAttestation(ctx context.Context, a *ethpb.Attestation) error // validate_aggregate_proof.go and validate_beacon_attestation.go // Verify attestations can only affect the fork choice of subsequent slots. - if err := core.VerifySlotTime(genesisTime, a.Data.Slot+1, params.BeaconNetworkConfig().MaximumGossipClockDisparity); err != nil { + if err := coreTime.VerifySlotTime(genesisTime, a.Data.Slot+1, params.BeaconNetworkConfig().MaximumGossipClockDisparity); err != nil { return err } diff --git a/beacon-chain/blockchain/process_attestation_helpers.go b/beacon-chain/blockchain/process_attestation_helpers.go index 1e60a03a85..ccaa79b17d 100644 --- a/beacon-chain/blockchain/process_attestation_helpers.go +++ b/beacon-chain/blockchain/process_attestation_helpers.go @@ -8,8 +8,8 @@ import ( "github.com/pkg/errors" types "github.com/prysmaticlabs/eth2-types" "github.com/prysmaticlabs/prysm/async" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/core/transition" "github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/config/params" @@ -38,7 +38,7 @@ func (s *Service) getAttPreState(ctx context.Context, c *ethpb.Checkpoint) (stat return nil, errors.Wrapf(err, "could not get pre state for epoch %d", c.Epoch) } - epochStartSlot, err := core.StartSlot(c.Epoch) + epochStartSlot, err := time.StartSlot(c.Epoch) if err != nil { return nil, err } @@ -63,7 +63,7 @@ func (s *Service) getAttPreState(ctx context.Context, c *ethpb.Checkpoint) (stat // verifyAttTargetEpoch validates attestation is from the current or previous epoch. func (s *Service) verifyAttTargetEpoch(_ context.Context, genesisTime, nowTime uint64, c *ethpb.Checkpoint) error { currentSlot := types.Slot((nowTime - genesisTime) / params.BeaconConfig().SecondsPerSlot) - currentEpoch := core.SlotToEpoch(currentSlot) + currentEpoch := time.SlotToEpoch(currentSlot) var prevEpoch types.Epoch // Prevents previous epoch under flow if currentEpoch > 1 { diff --git a/beacon-chain/blockchain/process_attestation_test.go b/beacon-chain/blockchain/process_attestation_test.go index bcd85eef87..5d80bd4414 100644 --- a/beacon-chain/blockchain/process_attestation_test.go +++ b/beacon-chain/blockchain/process_attestation_test.go @@ -5,7 +5,7 @@ import ( "testing" types "github.com/prysmaticlabs/eth2-types" - "github.com/prysmaticlabs/prysm/beacon-chain/core" + coreTime "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/core/transition" testDB "github.com/prysmaticlabs/prysm/beacon-chain/db/testing" "github.com/prysmaticlabs/prysm/beacon-chain/forkchoice/protoarray" @@ -251,7 +251,7 @@ func TestStore_UpdateCheckpointState(t *testing.T) { require.NoError(t, service.cfg.BeaconDB.SaveState(ctx, baseState, bytesutil.ToBytes32(newCheckpoint.Root))) returned, err = service.getAttPreState(ctx, newCheckpoint) require.NoError(t, err) - s, err := core.StartSlot(newCheckpoint.Epoch) + s, err := coreTime.StartSlot(newCheckpoint.Epoch) require.NoError(t, err) baseState, err = transition.ProcessSlots(ctx, baseState, s) require.NoError(t, err) diff --git a/beacon-chain/blockchain/process_block.go b/beacon-chain/blockchain/process_block.go index 393bd8bfa0..f6dab7a17a 100644 --- a/beacon-chain/blockchain/process_block.go +++ b/beacon-chain/blockchain/process_block.go @@ -6,10 +6,10 @@ import ( "time" "github.com/pkg/errors" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/feed" statefeed "github.com/prysmaticlabs/prysm/beacon-chain/core/feed/state" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" + coreTime "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/core/transition" "github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/config/features" @@ -268,7 +268,7 @@ func (s *Service) onBlockBatch(ctx context.Context, blks []block.SignedBeaconBlo return nil, nil, err } // Save potential boundary states. - if core.IsEpochStart(preState.Slot()) { + if coreTime.IsEpochStart(preState.Slot()) { boundaries[blockRoots[i]] = preState.Copy() if err := s.handleEpochBoundary(ctx, preState); err != nil { return nil, nil, errors.Wrap(err, "could not handle epoch boundary state") @@ -351,7 +351,7 @@ func (s *Service) handleEpochBoundary(ctx context.Context, postState state.Beaco if postState.Slot()+1 == s.nextEpochBoundarySlot { // Update caches for the next epoch at epoch boundary slot - 1. - if err := helpers.UpdateCommitteeCache(postState, core.NextEpoch(postState)); err != nil { + if err := helpers.UpdateCommitteeCache(postState, coreTime.NextEpoch(postState)); err != nil { return err } copied := postState.Copy() @@ -367,14 +367,14 @@ func (s *Service) handleEpochBoundary(ctx context.Context, postState state.Beaco return err } var err error - s.nextEpochBoundarySlot, err = core.StartSlot(core.NextEpoch(postState)) + s.nextEpochBoundarySlot, err = coreTime.StartSlot(coreTime.NextEpoch(postState)) if err != nil { return err } // Update caches at epoch boundary slot. // The following updates have short cut to return nil cheaply if fulfilled during boundary slot - 1. - if err := helpers.UpdateCommitteeCache(postState, core.CurrentEpoch(postState)); err != nil { + if err := helpers.UpdateCommitteeCache(postState, coreTime.CurrentEpoch(postState)); err != nil { return err } if err := helpers.UpdateProposerIndicesInCache(ctx, postState); err != nil { diff --git a/beacon-chain/blockchain/process_block_helpers.go b/beacon-chain/blockchain/process_block_helpers.go index 738c0133e2..c82d2bbd87 100644 --- a/beacon-chain/blockchain/process_block_helpers.go +++ b/beacon-chain/blockchain/process_block_helpers.go @@ -7,8 +7,8 @@ import ( "github.com/pkg/errors" types "github.com/prysmaticlabs/eth2-types" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/encoding/bytesutil" @@ -21,7 +21,7 @@ import ( // CurrentSlot returns the current slot based on time. func (s *Service) CurrentSlot() types.Slot { - return core.CurrentSlot(uint64(s.genesisTime.Unix())) + return time.CurrentSlot(uint64(s.genesisTime.Unix())) } // getBlockPreState returns the pre state of an incoming block. It uses the parent root of the block @@ -45,7 +45,7 @@ func (s *Service) getBlockPreState(ctx context.Context, b block.BeaconBlock) (st } // Verify block slot time is not from the future. - if err := core.VerifySlotTime(preState.GenesisTime(), b.Slot(), params.BeaconNetworkConfig().MaximumGossipClockDisparity); err != nil { + if err := time.VerifySlotTime(preState.GenesisTime(), b.Slot(), params.BeaconNetworkConfig().MaximumGossipClockDisparity); err != nil { return nil, err } @@ -122,7 +122,7 @@ func (s *Service) VerifyBlkDescendant(ctx context.Context, root [32]byte) error // verifyBlkFinalizedSlot validates input block is not less than or equal // to current finalized slot. func (s *Service) verifyBlkFinalizedSlot(b block.BeaconBlock) error { - finalizedSlot, err := core.StartSlot(s.finalizedCheckpt.Epoch) + finalizedSlot, err := time.StartSlot(s.finalizedCheckpt.Epoch) if err != nil { return err } @@ -140,7 +140,7 @@ func (s *Service) shouldUpdateCurrentJustified(ctx context.Context, newJustified ctx, span := trace.StartSpan(ctx, "blockChain.shouldUpdateCurrentJustified") defer span.End() - if core.SlotsSinceEpochStarts(s.CurrentSlot()) < params.BeaconConfig().SafeSlotsToUpdateJustified { + if time.SlotsSinceEpochStarts(s.CurrentSlot()) < params.BeaconConfig().SafeSlotsToUpdateJustified { return true, nil } var newJustifiedBlockSigned block.SignedBeaconBlock @@ -159,7 +159,7 @@ func (s *Service) shouldUpdateCurrentJustified(ctx context.Context, newJustified } newJustifiedBlock := newJustifiedBlockSigned.Block() - jSlot, err := core.StartSlot(s.justifiedCheckpt.Epoch) + jSlot, err := time.StartSlot(s.justifiedCheckpt.Epoch) if err != nil { return false, err } @@ -348,7 +348,7 @@ func (s *Service) finalizedImpliesNewJustified(ctx context.Context, state state. } // Update justified if store justified is not in chain with finalized check point. - finalizedSlot, err := core.StartSlot(s.finalizedCheckpt.Epoch) + finalizedSlot, err := time.StartSlot(s.finalizedCheckpt.Epoch) if err != nil { return err } @@ -377,7 +377,7 @@ func (s *Service) fillInForkChoiceMissingBlocks(ctx context.Context, blk block.B parentRoot := bytesutil.ToBytes32(blk.ParentRoot()) slot := blk.Slot() // Fork choice only matters from last finalized slot. - fSlot, err := core.StartSlot(s.finalizedCheckpt.Epoch) + fSlot, err := time.StartSlot(s.finalizedCheckpt.Epoch) if err != nil { return err } diff --git a/beacon-chain/blockchain/receive_attestation.go b/beacon-chain/blockchain/receive_attestation.go index a3120af4ab..599682dffc 100644 --- a/beacon-chain/blockchain/receive_attestation.go +++ b/beacon-chain/blockchain/receive_attestation.go @@ -7,9 +7,9 @@ import ( "time" "github.com/pkg/errors" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/feed" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" + coreTime "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/encoding/bytesutil" @@ -51,11 +51,11 @@ func (s *Service) ReceiveAttestationNoPubsub(ctx context.Context, att *ethpb.Att // AttestationTargetState returns the pre state of attestation. func (s *Service) AttestationTargetState(ctx context.Context, target *ethpb.Checkpoint) (state.BeaconState, error) { - ss, err := core.StartSlot(target.Epoch) + ss, err := coreTime.StartSlot(target.Epoch) if err != nil { return nil, err } - if err := core.ValidateSlotClock(ss, uint64(s.genesisTime.Unix())); err != nil { + if err := coreTime.ValidateSlotClock(ss, uint64(s.genesisTime.Unix())); err != nil { return nil, err } return s.getAttPreState(ctx, target) @@ -63,7 +63,7 @@ func (s *Service) AttestationTargetState(ctx context.Context, target *ethpb.Chec // VerifyLmdFfgConsistency verifies that attestation's LMD and FFG votes are consistency to each other. func (s *Service) VerifyLmdFfgConsistency(ctx context.Context, a *ethpb.Attestation) error { - targetSlot, err := core.StartSlot(a.Data.Target.Epoch) + targetSlot, err := coreTime.StartSlot(a.Data.Target.Epoch) if err != nil { return err } @@ -88,7 +88,7 @@ func (s *Service) VerifyFinalizedConsistency(ctx context.Context, root []byte) e } f := s.FinalizedCheckpt() - ss, err := core.StartSlot(f.Epoch) + ss, err := coreTime.StartSlot(f.Epoch) if err != nil { return err } @@ -147,7 +147,7 @@ func (s *Service) processAttestations(ctx context.Context) { // This delays consideration in the fork choice until their slot is in the past. // https://github.com/ethereum/consensus-specs/blob/dev/specs/phase0/fork-choice.md#validate_on_attestation nextSlot := a.Data.Slot + 1 - if err := core.VerifySlotTime(uint64(s.genesisTime.Unix()), nextSlot, params.BeaconNetworkConfig().MaximumGossipClockDisparity); err != nil { + if err := coreTime.VerifySlotTime(uint64(s.genesisTime.Unix()), nextSlot, params.BeaconNetworkConfig().MaximumGossipClockDisparity); err != nil { continue } diff --git a/beacon-chain/blockchain/receive_attestation_test.go b/beacon-chain/blockchain/receive_attestation_test.go index a57ca3f2b8..427d7eb57a 100644 --- a/beacon-chain/blockchain/receive_attestation_test.go +++ b/beacon-chain/blockchain/receive_attestation_test.go @@ -6,8 +6,8 @@ import ( "time" types "github.com/prysmaticlabs/eth2-types" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" + coreTime "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/core/transition" testDB "github.com/prysmaticlabs/prysm/beacon-chain/db/testing" "github.com/prysmaticlabs/prysm/beacon-chain/forkchoice/protoarray" @@ -35,7 +35,7 @@ func TestAttestationCheckPtState_FarFutureSlot(t *testing.T) { chainService := setupBeaconChain(t, beaconDB) chainService.genesisTime = time.Now() - e := types.Epoch(core.MaxSlotBuffer/uint64(params.BeaconConfig().SlotsPerEpoch) + 1) + e := types.Epoch(coreTime.MaxSlotBuffer/uint64(params.BeaconConfig().SlotsPerEpoch) + 1) _, err := chainService.AttestationTargetState(context.Background(), ðpb.Checkpoint{Epoch: e}) require.ErrorContains(t, "exceeds max allowed value relative to the local clock", err) } diff --git a/beacon-chain/blockchain/receive_block.go b/beacon-chain/blockchain/receive_block.go index d26ee46bfc..d8689ca356 100644 --- a/beacon-chain/blockchain/receive_block.go +++ b/beacon-chain/blockchain/receive_block.go @@ -5,9 +5,9 @@ import ( "github.com/pkg/errors" types "github.com/prysmaticlabs/eth2-types" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/feed" statefeed "github.com/prysmaticlabs/prysm/beacon-chain/core/feed/state" + coreTime "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/monitoring/tracing" "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/block" "github.com/prysmaticlabs/prysm/time" @@ -142,7 +142,7 @@ func (s *Service) handlePostBlockOperations(b block.BeaconBlock) error { // This checks whether it's time to start saving hot state to DB. // It's time when there's `epochsSinceFinalitySaveHotStateDB` epochs of non-finality. func (s *Service) checkSaveHotStateDB(ctx context.Context) error { - currentEpoch := core.SlotToEpoch(s.CurrentSlot()) + currentEpoch := coreTime.SlotToEpoch(s.CurrentSlot()) // Prevent `sinceFinality` going underflow. var sinceFinality types.Epoch if currentEpoch > s.finalizedCheckpt.Epoch { diff --git a/beacon-chain/blockchain/service.go b/beacon-chain/blockchain/service.go index 0e96b4491b..84623f5748 100644 --- a/beacon-chain/blockchain/service.go +++ b/beacon-chain/blockchain/service.go @@ -14,10 +14,10 @@ import ( "github.com/prysmaticlabs/prysm/async/event" "github.com/prysmaticlabs/prysm/beacon-chain/cache" "github.com/prysmaticlabs/prysm/beacon-chain/cache/depositcache" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/feed" statefeed "github.com/prysmaticlabs/prysm/beacon-chain/core/feed/state" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" + coreTime "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/core/transition" "github.com/prysmaticlabs/prysm/beacon-chain/db" f "github.com/prysmaticlabs/prysm/beacon-chain/forkchoice" @@ -176,7 +176,7 @@ func (s *Service) Start() { s.prevFinalizedCheckpt = ethpb.CopyCheckpoint(finalizedCheckpoint) s.resumeForkChoice(justifiedCheckpoint, finalizedCheckpoint) - ss, err := core.StartSlot(s.finalizedCheckpt.Epoch) + ss, err := coreTime.StartSlot(s.finalizedCheckpt.Epoch) if err != nil { log.Fatalf("Could not get start slot of finalized epoch: %v", err) } @@ -413,7 +413,7 @@ func (s *Service) initializeChainInfo(ctx context.Context) error { if err != nil { return errors.Wrap(err, "could not retrieve head block") } - headEpoch := core.SlotToEpoch(headBlock.Block().Slot()) + headEpoch := coreTime.SlotToEpoch(headBlock.Block().Slot()) var epochsSinceFinality types.Epoch if headEpoch > finalized.Epoch { epochsSinceFinality = headEpoch - finalized.Epoch diff --git a/beacon-chain/blockchain/service_test.go b/beacon-chain/blockchain/service_test.go index 8f065cc0fe..ad38160d42 100644 --- a/beacon-chain/blockchain/service_test.go +++ b/beacon-chain/blockchain/service_test.go @@ -10,11 +10,11 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/prysmaticlabs/prysm/async/event" "github.com/prysmaticlabs/prysm/beacon-chain/cache/depositcache" - "github.com/prysmaticlabs/prysm/beacon-chain/core" b "github.com/prysmaticlabs/prysm/beacon-chain/core/blocks" "github.com/prysmaticlabs/prysm/beacon-chain/core/feed" statefeed "github.com/prysmaticlabs/prysm/beacon-chain/core/feed/state" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" + coreTime "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/core/transition" "github.com/prysmaticlabs/prysm/beacon-chain/db" testDB "github.com/prysmaticlabs/prysm/beacon-chain/db/testing" @@ -281,7 +281,7 @@ func TestChainService_InitializeChainInfo(t *testing.T) { require.NoError(t, beaconDB.SaveState(ctx, headState, headRoot)) require.NoError(t, beaconDB.SaveState(ctx, headState, genesisRoot)) require.NoError(t, beaconDB.SaveBlock(ctx, wrapper.WrappedPhase0SignedBeaconBlock(headBlock))) - require.NoError(t, beaconDB.SaveFinalizedCheckpoint(ctx, ðpb.Checkpoint{Epoch: core.SlotToEpoch(finalizedSlot), Root: headRoot[:]})) + require.NoError(t, beaconDB.SaveFinalizedCheckpoint(ctx, ðpb.Checkpoint{Epoch: coreTime.SlotToEpoch(finalizedSlot), Root: headRoot[:]})) c := &Service{cfg: &Config{BeaconDB: beaconDB, StateGen: stategen.New(beaconDB)}} require.NoError(t, c.initializeChainInfo(ctx)) headBlk, err := c.HeadBlock(ctx) @@ -375,7 +375,7 @@ func TestChainService_InitializeChainInfo_HeadSync(t *testing.T) { require.NoError(t, beaconDB.SaveState(ctx, headState, headRoot)) require.NoError(t, beaconDB.SaveHeadBlockRoot(ctx, headRoot)) require.NoError(t, beaconDB.SaveFinalizedCheckpoint(ctx, ðpb.Checkpoint{ - Epoch: core.SlotToEpoch(finalizedBlock.Block.Slot), + Epoch: coreTime.SlotToEpoch(finalizedBlock.Block.Slot), Root: finalizedRoot[:], })) diff --git a/beacon-chain/blockchain/weak_subjectivity_checks.go b/beacon-chain/blockchain/weak_subjectivity_checks.go index a7967282c1..2aa4de8a30 100644 --- a/beacon-chain/blockchain/weak_subjectivity_checks.go +++ b/beacon-chain/blockchain/weak_subjectivity_checks.go @@ -4,7 +4,7 @@ import ( "context" "fmt" - "github.com/prysmaticlabs/prysm/beacon-chain/core" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/db/filters" "github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/encoding/bytesutil" @@ -38,7 +38,7 @@ func (s *Service) VerifyWeakSubjectivityRoot(ctx context.Context) error { return fmt.Errorf("node does not have root in DB: %#x", r) } - startSlot, err := core.StartSlot(s.cfg.WeakSubjectivityCheckpt.Epoch) + startSlot, err := time.StartSlot(s.cfg.WeakSubjectivityCheckpt.Epoch) if err != nil { return err } diff --git a/beacon-chain/core/altair/BUILD.bazel b/beacon-chain/core/altair/BUILD.bazel index 64f7b3f0f7..8d947a2e7d 100644 --- a/beacon-chain/core/altair/BUILD.bazel +++ b/beacon-chain/core/altair/BUILD.bazel @@ -21,12 +21,12 @@ go_library( "//validator/client:__pkg__", ], deps = [ - "//beacon-chain/core:go_default_library", "//beacon-chain/core/blocks:go_default_library", "//beacon-chain/core/epoch:go_default_library", "//beacon-chain/core/epoch/precompute:go_default_library", "//beacon-chain/core/helpers:go_default_library", "//beacon-chain/core/signing:go_default_library", + "//beacon-chain/core/time:go_default_library", "//beacon-chain/p2p/types:go_default_library", "//beacon-chain/state:go_default_library", "//beacon-chain/state/v2:go_default_library", @@ -61,11 +61,11 @@ go_test( ], embed = [":go_default_library"], deps = [ - "//beacon-chain/core:go_default_library", "//beacon-chain/core/epoch:go_default_library", "//beacon-chain/core/epoch/precompute:go_default_library", "//beacon-chain/core/helpers:go_default_library", "//beacon-chain/core/signing:go_default_library", + "//beacon-chain/core/time:go_default_library", "//beacon-chain/p2p/types:go_default_library", "//beacon-chain/state:go_default_library", "//beacon-chain/state/v2:go_default_library", diff --git a/beacon-chain/core/altair/attestation.go b/beacon-chain/core/altair/attestation.go index a43f90ece1..37659ac882 100644 --- a/beacon-chain/core/altair/attestation.go +++ b/beacon-chain/core/altair/attestation.go @@ -7,9 +7,9 @@ import ( "github.com/pkg/errors" types "github.com/prysmaticlabs/eth2-types" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/blocks" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/config/params" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" @@ -105,7 +105,7 @@ func SetParticipationAndRewardProposer( indices []uint64, participatedFlags map[uint8]bool, totalBalance uint64) (state.BeaconState, error) { var epochParticipation []byte - currentEpoch := core.CurrentEpoch(beaconState) + currentEpoch := time.CurrentEpoch(beaconState) var err error if targetEpoch == currentEpoch { epochParticipation, err = beaconState.CurrentEpochParticipation() @@ -240,7 +240,7 @@ func RewardProposer(ctx context.Context, beaconState state.BeaconState, proposer // // return participation_flag_indices func AttestationParticipationFlagIndices(beaconState state.BeaconStateAltair, data *ethpb.AttestationData, delay types.Slot) (map[uint8]bool, error) { - currEpoch := core.CurrentEpoch(beaconState) + currEpoch := time.CurrentEpoch(beaconState) var justifiedCheckpt *ethpb.Checkpoint if data.Target.Epoch == currEpoch { justifiedCheckpt = beaconState.CurrentJustifiedCheckpoint() diff --git a/beacon-chain/core/altair/attestation_test.go b/beacon-chain/core/altair/attestation_test.go index 76ebe0b719..3db42636b7 100644 --- a/beacon-chain/core/altair/attestation_test.go +++ b/beacon-chain/core/altair/attestation_test.go @@ -8,10 +8,10 @@ import ( fuzz "github.com/google/gofuzz" types "github.com/prysmaticlabs/eth2-types" "github.com/prysmaticlabs/go-bitfield" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/altair" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/beacon-chain/core/signing" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/state" stateAltair "github.com/prysmaticlabs/prysm/beacon-chain/state/v2" "github.com/prysmaticlabs/prysm/config/params" @@ -75,8 +75,8 @@ func TestProcessAttestations_NeitherCurrentNorPrevEpoch(t *testing.T) { want := fmt.Sprintf( "expected target epoch (%d) to be the previous epoch (%d) or the current epoch (%d)", att.Data.Target.Epoch, - core.PrevEpoch(beaconState), - core.CurrentEpoch(beaconState), + time.PrevEpoch(beaconState), + time.CurrentEpoch(beaconState), ) wsb, err := wrapper.WrappedAltairSignedBeaconBlock(b) require.NoError(t, err) @@ -111,7 +111,7 @@ func TestProcessAttestations_CurrentEpochFFGDataMismatches(t *testing.T) { require.NoError(t, err) _, err = altair.ProcessAttestationsNoVerifySignature(context.Background(), beaconState, wsb) require.ErrorContains(t, want, err) - b.Block.Body.Attestations[0].Data.Source.Epoch = core.CurrentEpoch(beaconState) + b.Block.Body.Attestations[0].Data.Source.Epoch = time.CurrentEpoch(beaconState) b.Block.Body.Attestations[0].Data.Source.Root = []byte{} wsb, err = wrapper.WrappedAltairSignedBeaconBlock(b) require.NoError(t, err) @@ -152,8 +152,8 @@ func TestProcessAttestations_PrevEpochFFGDataMismatches(t *testing.T) { require.NoError(t, err) _, err = altair.ProcessAttestationsNoVerifySignature(context.Background(), beaconState, wsb) require.ErrorContains(t, want, err) - b.Block.Body.Attestations[0].Data.Source.Epoch = core.PrevEpoch(beaconState) - b.Block.Body.Attestations[0].Data.Target.Epoch = core.PrevEpoch(beaconState) + b.Block.Body.Attestations[0].Data.Source.Epoch = time.PrevEpoch(beaconState) + b.Block.Body.Attestations[0].Data.Target.Epoch = time.PrevEpoch(beaconState) b.Block.Body.Attestations[0].Data.Source.Root = []byte{} wsb, err = wrapper.WrappedAltairSignedBeaconBlock(b) require.NoError(t, err) @@ -471,7 +471,7 @@ func TestSetParticipationAndRewardProposer(t *testing.T) { beaconState, _ := util.DeterministicGenesisStateAltair(t, params.BeaconConfig().MaxValidatorsPerCommittee) require.NoError(t, beaconState.SetSlot(params.BeaconConfig().SlotsPerEpoch)) - currentEpoch := core.CurrentEpoch(beaconState) + currentEpoch := time.CurrentEpoch(beaconState) if test.epoch == currentEpoch { require.NoError(t, beaconState.SetCurrentParticipationBits(test.epochParticipation)) } else { diff --git a/beacon-chain/core/altair/block.go b/beacon-chain/core/altair/block.go index 4a00e1b143..c9e899d35b 100644 --- a/beacon-chain/core/altair/block.go +++ b/beacon-chain/core/altair/block.go @@ -5,9 +5,9 @@ import ( "errors" types "github.com/prysmaticlabs/eth2-types" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/beacon-chain/core/signing" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" p2pType "github.com/prysmaticlabs/prysm/beacon-chain/p2p/types" "github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/config/params" @@ -101,8 +101,8 @@ func FilterSyncCommitteeVotes(s state.BeaconStateAltair, sync *ethpb.SyncAggrega // VerifySyncCommitteeSig verifies sync committee signature `syncSig` is valid with respect to public keys `syncKeys`. func VerifySyncCommitteeSig(s state.BeaconStateAltair, syncKeys []bls.PublicKey, syncSig []byte) error { - ps := core.PrevSlot(s.Slot()) - d, err := signing.Domain(s.Fork(), core.SlotToEpoch(ps), params.BeaconConfig().DomainSyncCommittee, s.GenesisValidatorRoot()) + ps := time.PrevSlot(s.Slot()) + d, err := signing.Domain(s.Fork(), time.SlotToEpoch(ps), params.BeaconConfig().DomainSyncCommittee, s.GenesisValidatorRoot()) if err != nil { return err } diff --git a/beacon-chain/core/altair/block_test.go b/beacon-chain/core/altair/block_test.go index c185b97b4f..28ad5cd6c3 100644 --- a/beacon-chain/core/altair/block_test.go +++ b/beacon-chain/core/altair/block_test.go @@ -7,10 +7,10 @@ import ( types "github.com/prysmaticlabs/eth2-types" "github.com/prysmaticlabs/go-bitfield" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/altair" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/beacon-chain/core/signing" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" p2pType "github.com/prysmaticlabs/prysm/beacon-chain/p2p/types" "github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/crypto/bls" @@ -33,13 +33,13 @@ func TestProcessSyncCommittee_PerfectParticipation(t *testing.T) { } indices, err := altair.NextSyncCommitteeIndices(context.Background(), beaconState) require.NoError(t, err) - ps := core.PrevSlot(beaconState.Slot()) + ps := time.PrevSlot(beaconState.Slot()) pbr, err := helpers.BlockRootAtSlot(beaconState, ps) require.NoError(t, err) sigs := make([]bls.Signature, len(indices)) for i, indice := range indices { b := p2pType.SSZBytes(pbr) - sb, err := signing.ComputeDomainAndSign(beaconState, core.CurrentEpoch(beaconState), &b, params.BeaconConfig().DomainSyncCommittee, privKeys[indice]) + sb, err := signing.ComputeDomainAndSign(beaconState, time.CurrentEpoch(beaconState), &b, params.BeaconConfig().DomainSyncCommittee, privKeys[indice]) require.NoError(t, err) sig, err := bls.SignatureFromBytes(sb) require.NoError(t, err) @@ -107,13 +107,13 @@ func TestProcessSyncCommittee_MixParticipation_BadSignature(t *testing.T) { } indices, err := altair.NextSyncCommitteeIndices(context.Background(), beaconState) require.NoError(t, err) - ps := core.PrevSlot(beaconState.Slot()) + ps := time.PrevSlot(beaconState.Slot()) pbr, err := helpers.BlockRootAtSlot(beaconState, ps) require.NoError(t, err) sigs := make([]bls.Signature, len(indices)) for i, indice := range indices { b := p2pType.SSZBytes(pbr) - sb, err := signing.ComputeDomainAndSign(beaconState, core.CurrentEpoch(beaconState), &b, params.BeaconConfig().DomainSyncCommittee, privKeys[indice]) + sb, err := signing.ComputeDomainAndSign(beaconState, time.CurrentEpoch(beaconState), &b, params.BeaconConfig().DomainSyncCommittee, privKeys[indice]) require.NoError(t, err) sig, err := bls.SignatureFromBytes(sb) require.NoError(t, err) @@ -142,14 +142,14 @@ func TestProcessSyncCommittee_MixParticipation_GoodSignature(t *testing.T) { } indices, err := altair.NextSyncCommitteeIndices(context.Background(), beaconState) require.NoError(t, err) - ps := core.PrevSlot(beaconState.Slot()) + ps := time.PrevSlot(beaconState.Slot()) pbr, err := helpers.BlockRootAtSlot(beaconState, ps) require.NoError(t, err) sigs := make([]bls.Signature, 0, len(indices)) for i, indice := range indices { if syncBits.BitAt(uint64(i)) { b := p2pType.SSZBytes(pbr) - sb, err := signing.ComputeDomainAndSign(beaconState, core.CurrentEpoch(beaconState), &b, params.BeaconConfig().DomainSyncCommittee, privKeys[indice]) + sb, err := signing.ComputeDomainAndSign(beaconState, time.CurrentEpoch(beaconState), &b, params.BeaconConfig().DomainSyncCommittee, privKeys[indice]) require.NoError(t, err) sig, err := bls.SignatureFromBytes(sb) require.NoError(t, err) @@ -215,14 +215,14 @@ func Test_VerifySyncCommitteeSig(t *testing.T) { } indices, err := altair.NextSyncCommitteeIndices(context.Background(), beaconState) require.NoError(t, err) - ps := core.PrevSlot(beaconState.Slot()) + ps := time.PrevSlot(beaconState.Slot()) pbr, err := helpers.BlockRootAtSlot(beaconState, ps) require.NoError(t, err) sigs := make([]bls.Signature, len(indices)) pks := make([]bls.PublicKey, len(indices)) for i, indice := range indices { b := p2pType.SSZBytes(pbr) - sb, err := signing.ComputeDomainAndSign(beaconState, core.CurrentEpoch(beaconState), &b, params.BeaconConfig().DomainSyncCommittee, privKeys[indice]) + sb, err := signing.ComputeDomainAndSign(beaconState, time.CurrentEpoch(beaconState), &b, params.BeaconConfig().DomainSyncCommittee, privKeys[indice]) require.NoError(t, err) sig, err := bls.SignatureFromBytes(sb) require.NoError(t, err) diff --git a/beacon-chain/core/altair/epoch_precompute.go b/beacon-chain/core/altair/epoch_precompute.go index 5fcbfe773e..8f0d7ba6c6 100644 --- a/beacon-chain/core/altair/epoch_precompute.go +++ b/beacon-chain/core/altair/epoch_precompute.go @@ -4,9 +4,9 @@ import ( "context" "github.com/pkg/errors" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/epoch/precompute" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/math" @@ -19,8 +19,8 @@ func InitializePrecomputeValidators(ctx context.Context, beaconState state.Beaco defer span.End() vals := make([]*precompute.Validator, beaconState.NumValidators()) bal := &precompute.Balance{} - prevEpoch := core.PrevEpoch(beaconState) - currentEpoch := core.CurrentEpoch(beaconState) + prevEpoch := time.PrevEpoch(beaconState) + currentEpoch := time.CurrentEpoch(beaconState) inactivityScores, err := beaconState.InactivityScores() if err != nil { return nil, nil, err @@ -74,7 +74,7 @@ func ProcessInactivityScores( defer span.End() cfg := params.BeaconConfig() - if core.CurrentEpoch(beaconState) == cfg.GenesisEpoch { + if time.CurrentEpoch(beaconState) == cfg.GenesisEpoch { return beaconState, vals, nil } @@ -85,7 +85,7 @@ func ProcessInactivityScores( bias := cfg.InactivityScoreBias recoveryRate := cfg.InactivityScoreRecoveryRate - prevEpoch := core.PrevEpoch(beaconState) + prevEpoch := time.PrevEpoch(beaconState) finalizedEpoch := beaconState.FinalizedCheckpointEpoch() for i, v := range vals { if !precompute.EligibleForRewards(v) { @@ -182,7 +182,7 @@ func ProcessRewardsAndPenaltiesPrecompute( ) (state.BeaconStateAltair, error) { // Don't process rewards and penalties in genesis epoch. cfg := params.BeaconConfig() - if core.CurrentEpoch(beaconState) == cfg.GenesisEpoch { + if time.CurrentEpoch(beaconState) == cfg.GenesisEpoch { return beaconState, nil } @@ -227,7 +227,7 @@ func AttestationsDelta(beaconState state.BeaconStateAltair, bal *precompute.Bala penalties = make([]uint64, numOfVals) cfg := params.BeaconConfig() - prevEpoch := core.PrevEpoch(beaconState) + prevEpoch := time.PrevEpoch(beaconState) finalizedEpoch := beaconState.FinalizedCheckpointEpoch() increment := cfg.EffectiveBalanceIncrement factor := cfg.BaseRewardFactor diff --git a/beacon-chain/core/altair/epoch_spec.go b/beacon-chain/core/altair/epoch_spec.go index 125c725c72..2720ea0eb9 100644 --- a/beacon-chain/core/altair/epoch_spec.go +++ b/beacon-chain/core/altair/epoch_spec.go @@ -3,8 +3,8 @@ package altair import ( "context" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/config/params" log "github.com/sirupsen/logrus" @@ -19,7 +19,7 @@ import ( // state.current_sync_committee = state.next_sync_committee // state.next_sync_committee = get_next_sync_committee(state) func ProcessSyncCommitteeUpdates(ctx context.Context, beaconState state.BeaconStateAltair) (state.BeaconStateAltair, error) { - nextEpoch := core.NextEpoch(beaconState) + nextEpoch := time.NextEpoch(beaconState) if nextEpoch%params.BeaconConfig().EpochsPerSyncCommitteePeriod == 0 { nextSyncCommittee, err := beaconState.NextSyncCommittee() if err != nil { diff --git a/beacon-chain/core/altair/epoch_spec_test.go b/beacon-chain/core/altair/epoch_spec_test.go index 12526062c6..00036a8fd9 100644 --- a/beacon-chain/core/altair/epoch_spec_test.go +++ b/beacon-chain/core/altair/epoch_spec_test.go @@ -7,10 +7,10 @@ import ( "testing" types "github.com/prysmaticlabs/eth2-types" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/altair" "github.com/prysmaticlabs/prysm/beacon-chain/core/epoch" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" stateAltair "github.com/prysmaticlabs/prysm/beacon-chain/state/v2" "github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/encoding/bytesutil" @@ -59,7 +59,7 @@ func TestProcessSyncCommitteeUpdates_CanRotate(t *testing.T) { require.DeepEqual(t, next, c) // Test boundary condition. - slot := params.BeaconConfig().SlotsPerEpoch * types.Slot(core.CurrentEpoch(s)+params.BeaconConfig().EpochsPerSyncCommitteePeriod) + slot := params.BeaconConfig().SlotsPerEpoch * types.Slot(time.CurrentEpoch(s)+params.BeaconConfig().EpochsPerSyncCommitteePeriod) require.NoError(t, s.SetSlot(slot)) boundaryCommittee, err := altair.NextSyncCommittee(context.Background(), s) require.NoError(t, err) diff --git a/beacon-chain/core/altair/sync_committee.go b/beacon-chain/core/altair/sync_committee.go index b90b6175d5..d15e4ec324 100644 --- a/beacon-chain/core/altair/sync_committee.go +++ b/beacon-chain/core/altair/sync_committee.go @@ -7,8 +7,8 @@ import ( "github.com/pkg/errors" types "github.com/prysmaticlabs/eth2-types" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" + coreTime "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/crypto/bls" @@ -97,7 +97,7 @@ func NextSyncCommittee(ctx context.Context, s state.BeaconStateAltair) (*ethpb.S // i += 1 // return sync_committee_indices func NextSyncCommitteeIndices(ctx context.Context, s state.BeaconStateAltair) ([]types.ValidatorIndex, error) { - epoch := core.NextEpoch(s) + epoch := coreTime.NextEpoch(s) indices, err := helpers.ActiveValidatorIndices(ctx, s, epoch) if err != nil { return nil, err @@ -185,15 +185,15 @@ func IsSyncCommitteeAggregator(sig []byte) (bool, error) { // ValidateSyncMessageTime validates sync message to ensure that the provided slot is valid. func ValidateSyncMessageTime(slot types.Slot, genesisTime time.Time, clockDisparity time.Duration) error { - if err := core.ValidateSlotClock(slot, uint64(genesisTime.Unix())); err != nil { + if err := coreTime.ValidateSlotClock(slot, uint64(genesisTime.Unix())); err != nil { return err } - messageTime, err := core.SlotToTime(uint64(genesisTime.Unix()), slot) + messageTime, err := coreTime.SlotToTime(uint64(genesisTime.Unix()), slot) if err != nil { return err } - currentSlot := core.SlotsSince(genesisTime) - slotStartTime, err := core.SlotToTime(uint64(genesisTime.Unix()), currentSlot) + currentSlot := coreTime.SlotsSince(genesisTime) + slotStartTime, err := coreTime.SlotToTime(uint64(genesisTime.Unix()), currentSlot) if err != nil { return err } diff --git a/beacon-chain/core/altair/upgrade.go b/beacon-chain/core/altair/upgrade.go index 437715e9bf..03b6ee7d06 100644 --- a/beacon-chain/core/altair/upgrade.go +++ b/beacon-chain/core/altair/upgrade.go @@ -3,8 +3,8 @@ package altair import ( "context" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/state" statealtair "github.com/prysmaticlabs/prysm/beacon-chain/state/v2" "github.com/prysmaticlabs/prysm/config/params" @@ -63,7 +63,7 @@ import ( // post.next_sync_committee = get_next_sync_committee(post) // return post func UpgradeToAltair(ctx context.Context, state state.BeaconState) (state.BeaconStateAltair, error) { - epoch := core.CurrentEpoch(state) + epoch := time.CurrentEpoch(state) numValidators := state.NumValidators() s := ðpb.BeaconStateAltair{ diff --git a/beacon-chain/core/altair/upgrade_test.go b/beacon-chain/core/altair/upgrade_test.go index da710772e2..2a0ff2b21f 100644 --- a/beacon-chain/core/altair/upgrade_test.go +++ b/beacon-chain/core/altair/upgrade_test.go @@ -6,9 +6,9 @@ import ( types "github.com/prysmaticlabs/eth2-types" "github.com/prysmaticlabs/go-bitfield" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/altair" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/state" stateAltair "github.com/prysmaticlabs/prysm/beacon-chain/state/v2" "github.com/prysmaticlabs/prysm/config/params" @@ -109,7 +109,7 @@ func TestUpgradeToAltair(t *testing.T) { require.DeepSSZEqual(t, ðpb.Fork{ PreviousVersion: st.Fork().CurrentVersion, CurrentVersion: params.BeaconConfig().AltairForkVersion, - Epoch: core.CurrentEpoch(st), + Epoch: time.CurrentEpoch(st), }, f) csc, err := aState.CurrentSyncCommittee() require.NoError(t, err) diff --git a/beacon-chain/core/blocks/BUILD.bazel b/beacon-chain/core/blocks/BUILD.bazel index c921a24a3d..48242a12a9 100644 --- a/beacon-chain/core/blocks/BUILD.bazel +++ b/beacon-chain/core/blocks/BUILD.bazel @@ -24,9 +24,9 @@ go_library( "//validator:__subpackages__", ], deps = [ - "//beacon-chain/core:go_default_library", "//beacon-chain/core/helpers:go_default_library", "//beacon-chain/core/signing:go_default_library", + "//beacon-chain/core/time:go_default_library", "//beacon-chain/core/validators:go_default_library", "//beacon-chain/state:go_default_library", "//config/params:go_default_library", @@ -74,9 +74,9 @@ go_test( embed = [":go_default_library"], shard_count = 2, deps = [ - "//beacon-chain/core:go_default_library", "//beacon-chain/core/helpers:go_default_library", "//beacon-chain/core/signing:go_default_library", + "//beacon-chain/core/time:go_default_library", "//beacon-chain/core/validators:go_default_library", "//beacon-chain/p2p/types:go_default_library", "//beacon-chain/state:go_default_library", diff --git a/beacon-chain/core/blocks/attestation.go b/beacon-chain/core/blocks/attestation.go index e9d4342a3b..e9ec726637 100644 --- a/beacon-chain/core/blocks/attestation.go +++ b/beacon-chain/core/blocks/attestation.go @@ -6,9 +6,9 @@ import ( "github.com/pkg/errors" types "github.com/prysmaticlabs/eth2-types" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/beacon-chain/core/signing" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/crypto/bls" @@ -52,8 +52,8 @@ func VerifyAttestationNoVerifySignature( if err := helpers.ValidateNilAttestation(att); err != nil { return err } - currEpoch := core.CurrentEpoch(beaconState) - prevEpoch := core.PrevEpoch(beaconState) + currEpoch := time.CurrentEpoch(beaconState) + prevEpoch := time.PrevEpoch(beaconState) data := att.Data if data.Target.Epoch != prevEpoch && data.Target.Epoch != currEpoch { return fmt.Errorf( @@ -137,7 +137,7 @@ func ProcessAttestationNoVerifySignature( return nil, err } - currEpoch := core.CurrentEpoch(beaconState) + currEpoch := time.CurrentEpoch(beaconState) data := att.Data s := att.Data.Slot proposerIndex, err := helpers.BeaconProposerIndex(ctx, beaconState) diff --git a/beacon-chain/core/blocks/attester_slashing.go b/beacon-chain/core/blocks/attester_slashing.go index 813013a148..c2e1d21985 100644 --- a/beacon-chain/core/blocks/attester_slashing.go +++ b/beacon-chain/core/blocks/attester_slashing.go @@ -6,8 +6,8 @@ import ( "github.com/pkg/errors" types "github.com/prysmaticlabs/eth2-types" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/container/slice" @@ -50,7 +50,7 @@ func ProcessAttesterSlashings( sort.SliceStable(slashableIndices, func(i, j int) bool { return slashableIndices[i] < slashableIndices[j] }) - currentEpoch := core.SlotToEpoch(beaconState.Slot()) + currentEpoch := time.SlotToEpoch(beaconState.Slot()) var err error var slashedAny bool var val state.ReadOnlyValidator diff --git a/beacon-chain/core/blocks/exit.go b/beacon-chain/core/blocks/exit.go index 0db626fc95..56c6788cd5 100644 --- a/beacon-chain/core/blocks/exit.go +++ b/beacon-chain/core/blocks/exit.go @@ -6,9 +6,9 @@ import ( "github.com/pkg/errors" types "github.com/prysmaticlabs/eth2-types" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/beacon-chain/core/signing" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" v "github.com/prysmaticlabs/prysm/beacon-chain/core/validators" "github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/config/params" @@ -135,7 +135,7 @@ func VerifyExitAndSignature( // # Initiate exit // initiate_validator_exit(state, voluntary_exit.validator_index) func verifyExitConditions(validator state.ReadOnlyValidator, currentSlot types.Slot, exit *ethpb.VoluntaryExit) error { - currentEpoch := core.SlotToEpoch(currentSlot) + currentEpoch := time.SlotToEpoch(currentSlot) // Verify the validator is active. if !helpers.IsActiveValidatorUsingTrie(validator, currentEpoch) { return errors.New("non-active validator cannot exit") diff --git a/beacon-chain/core/blocks/exit_test.go b/beacon-chain/core/blocks/exit_test.go index 69e0b1215c..3beca254b3 100644 --- a/beacon-chain/core/blocks/exit_test.go +++ b/beacon-chain/core/blocks/exit_test.go @@ -5,10 +5,10 @@ import ( "testing" types "github.com/prysmaticlabs/eth2-types" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/blocks" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/beacon-chain/core/signing" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" v1 "github.com/prysmaticlabs/prysm/beacon-chain/state/v1" "github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/crypto/bls" @@ -113,7 +113,7 @@ func TestProcessVoluntaryExits_AppliesCorrectStatus(t *testing.T) { require.NoError(t, err) val.PublicKey = priv.PublicKey().Marshal() require.NoError(t, state.UpdateValidatorAtIndex(0, val)) - exits[0].Signature, err = signing.ComputeDomainAndSign(state, core.CurrentEpoch(state), exits[0].Exit, params.BeaconConfig().DomainVoluntaryExit, priv) + exits[0].Signature, err = signing.ComputeDomainAndSign(state, time.CurrentEpoch(state), exits[0].Exit, params.BeaconConfig().DomainVoluntaryExit, priv) require.NoError(t, err) b := util.NewBeaconBlock() diff --git a/beacon-chain/core/blocks/header_test.go b/beacon-chain/core/blocks/header_test.go index d099d58923..904cd4f926 100644 --- a/beacon-chain/core/blocks/header_test.go +++ b/beacon-chain/core/blocks/header_test.go @@ -5,10 +5,10 @@ import ( "io/ioutil" "testing" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/blocks" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/beacon-chain/core/signing" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" p2ptypes "github.com/prysmaticlabs/prysm/beacon-chain/p2p/types" "github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/crypto/bls" @@ -48,7 +48,7 @@ func TestProcessBlockHeader_ImproperBlockSlot(t *testing.T) { latestBlockSignedRoot, err := state.LatestBlockHeader().HashTreeRoot() require.NoError(t, err) - currentEpoch := core.CurrentEpoch(state) + currentEpoch := time.CurrentEpoch(state) priv, err := bls.RandKey() require.NoError(t, err) pID, err := helpers.BeaconProposerIndex(context.Background(), state) @@ -120,7 +120,7 @@ func TestProcessBlockHeader_DifferentSlots(t *testing.T) { lbhsr, err := state.LatestBlockHeader().HashTreeRoot() require.NoError(t, err) - currentEpoch := core.CurrentEpoch(state) + currentEpoch := time.CurrentEpoch(state) priv, err := bls.RandKey() require.NoError(t, err) @@ -159,7 +159,7 @@ func TestProcessBlockHeader_PreviousBlockRootNotSignedRoot(t *testing.T) { bh := state.LatestBlockHeader() bh.Slot = 9 require.NoError(t, state.SetLatestBlockHeader(bh)) - currentEpoch := core.CurrentEpoch(state) + currentEpoch := time.CurrentEpoch(state) priv, err := bls.RandKey() require.NoError(t, err) sszBytes := p2ptypes.SSZBytes("hello") @@ -200,7 +200,7 @@ func TestProcessBlockHeader_SlashedProposer(t *testing.T) { require.NoError(t, state.SetLatestBlockHeader(bh)) parentRoot, err := state.LatestBlockHeader().HashTreeRoot() require.NoError(t, err) - currentEpoch := core.CurrentEpoch(state) + currentEpoch := time.CurrentEpoch(state) priv, err := bls.RandKey() require.NoError(t, err) sszBytes := p2ptypes.SSZBytes("hello") @@ -244,7 +244,7 @@ func TestProcessBlockHeader_OK(t *testing.T) { latestBlockSignedRoot, err := state.LatestBlockHeader().HashTreeRoot() require.NoError(t, err) - currentEpoch := core.CurrentEpoch(state) + currentEpoch := time.CurrentEpoch(state) priv, err := bls.RandKey() require.NoError(t, err) pID, err := helpers.BeaconProposerIndex(context.Background(), state) @@ -303,7 +303,7 @@ func TestBlockSignatureSet_OK(t *testing.T) { latestBlockSignedRoot, err := state.LatestBlockHeader().HashTreeRoot() require.NoError(t, err) - currentEpoch := core.CurrentEpoch(state) + currentEpoch := time.CurrentEpoch(state) priv, err := bls.RandKey() require.NoError(t, err) pID, err := helpers.BeaconProposerIndex(context.Background(), state) diff --git a/beacon-chain/core/blocks/proposer_slashing.go b/beacon-chain/core/blocks/proposer_slashing.go index 5d5bbfca5b..97c1ac7abc 100644 --- a/beacon-chain/core/blocks/proposer_slashing.go +++ b/beacon-chain/core/blocks/proposer_slashing.go @@ -6,9 +6,9 @@ import ( "github.com/pkg/errors" types "github.com/prysmaticlabs/eth2-types" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/beacon-chain/core/signing" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/config/params" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" @@ -93,12 +93,12 @@ func VerifyProposerSlashing( if err != nil { return err } - if !helpers.IsSlashableValidatorUsingTrie(proposer, core.CurrentEpoch(beaconState)) { + if !helpers.IsSlashableValidatorUsingTrie(proposer, time.CurrentEpoch(beaconState)) { return fmt.Errorf("validator with key %#x is not slashable", proposer.PublicKey()) } headers := []*ethpb.SignedBeaconBlockHeader{slashing.Header_1, slashing.Header_2} for _, header := range headers { - if err := signing.ComputeDomainVerifySigningRoot(beaconState, pIdx, core.SlotToEpoch(hSlot), + if err := signing.ComputeDomainVerifySigningRoot(beaconState, pIdx, time.SlotToEpoch(hSlot), header.Header, params.BeaconConfig().DomainBeaconProposer, header.Signature); err != nil { return errors.Wrap(err, "could not verify beacon block header") } diff --git a/beacon-chain/core/blocks/proposer_slashing_test.go b/beacon-chain/core/blocks/proposer_slashing_test.go index ffcea9b973..157a8f55ce 100644 --- a/beacon-chain/core/blocks/proposer_slashing_test.go +++ b/beacon-chain/core/blocks/proposer_slashing_test.go @@ -6,9 +6,9 @@ import ( "testing" types "github.com/prysmaticlabs/eth2-types" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/blocks" "github.com/prysmaticlabs/prysm/beacon-chain/core/signing" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" v "github.com/prysmaticlabs/prysm/beacon-chain/core/validators" "github.com/prysmaticlabs/prysm/beacon-chain/state" v1 "github.com/prysmaticlabs/prysm/beacon-chain/state/v1" @@ -329,7 +329,7 @@ func TestVerifyProposerSlashing(t *testing.T) { t.Run(tt.name, func(t *testing.T) { sk := sks[tt.args.slashing.Header_1.Header.ProposerIndex] - d, err := signing.Domain(tt.args.beaconState.Fork(), core.SlotToEpoch(tt.args.slashing.Header_1.Header.Slot), params.BeaconConfig().DomainBeaconProposer, tt.args.beaconState.GenesisValidatorRoot()) + d, err := signing.Domain(tt.args.beaconState.Fork(), time.SlotToEpoch(tt.args.slashing.Header_1.Header.Slot), params.BeaconConfig().DomainBeaconProposer, tt.args.beaconState.GenesisValidatorRoot()) require.NoError(t, err) if tt.args.slashing.Header_1.Signature == nil { sr, err := signing.ComputeSigningRoot(tt.args.slashing.Header_1.Header, d) diff --git a/beacon-chain/core/blocks/randao.go b/beacon-chain/core/blocks/randao.go index ab5d3c6ba0..c75f9b429b 100644 --- a/beacon-chain/core/blocks/randao.go +++ b/beacon-chain/core/blocks/randao.go @@ -4,8 +4,8 @@ import ( "context" "github.com/pkg/errors" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/crypto/hash" @@ -63,7 +63,7 @@ func ProcessRandaoNoVerify( beaconState state.BeaconState, randaoReveal []byte, ) (state.BeaconState, error) { - currentEpoch := core.SlotToEpoch(beaconState.Slot()) + currentEpoch := time.SlotToEpoch(beaconState.Slot()) // If block randao passed verification, we XOR the state's latest randao mix with the block's // randao and update the state's corresponding latest randao mix value. latestMixesLength := params.BeaconConfig().EpochsPerHistoricalVector diff --git a/beacon-chain/core/blocks/randao_test.go b/beacon-chain/core/blocks/randao_test.go index 6bf8f74e2d..7139cb94eb 100644 --- a/beacon-chain/core/blocks/randao_test.go +++ b/beacon-chain/core/blocks/randao_test.go @@ -6,10 +6,10 @@ import ( "testing" types "github.com/prysmaticlabs/eth2-types" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/blocks" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/beacon-chain/core/signing" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/config/params" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/wrapper" @@ -47,7 +47,7 @@ func TestProcessRandao_IncorrectProposerFailsVerification(t *testing.T) { func TestProcessRandao_SignatureVerifiesAndUpdatesLatestStateMixes(t *testing.T) { beaconState, privKeys := util.DeterministicGenesisState(t, 100) - epoch := core.CurrentEpoch(beaconState) + epoch := time.CurrentEpoch(beaconState) epochSignature, err := util.RandaoReveal(beaconState, epoch, privKeys) require.NoError(t, err) @@ -64,7 +64,7 @@ func TestProcessRandao_SignatureVerifiesAndUpdatesLatestStateMixes(t *testing.T) wrapper.WrappedPhase0SignedBeaconBlock(b), ) require.NoError(t, err, "Unexpected error processing block randao") - currentEpoch := core.CurrentEpoch(beaconState) + currentEpoch := time.CurrentEpoch(beaconState) mix := newState.RandaoMixes()[currentEpoch%params.BeaconConfig().EpochsPerHistoricalVector] assert.DeepNotEqual(t, params.BeaconConfig().ZeroHash[:], mix, "Expected empty signature to be overwritten by randao reveal") } @@ -72,7 +72,7 @@ func TestProcessRandao_SignatureVerifiesAndUpdatesLatestStateMixes(t *testing.T) func TestRandaoSignatureSet_OK(t *testing.T) { beaconState, privKeys := util.DeterministicGenesisState(t, 100) - epoch := core.CurrentEpoch(beaconState) + epoch := time.CurrentEpoch(beaconState) epochSignature, err := util.RandaoReveal(beaconState, epoch, privKeys) require.NoError(t, err) diff --git a/beacon-chain/core/blocks/signature.go b/beacon-chain/core/blocks/signature.go index 01c76a807c..40cf5646f4 100644 --- a/beacon-chain/core/blocks/signature.go +++ b/beacon-chain/core/blocks/signature.go @@ -6,9 +6,9 @@ import ( "github.com/pkg/errors" types "github.com/prysmaticlabs/eth2-types" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/beacon-chain/core/signing" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/crypto/bls" @@ -67,7 +67,7 @@ func VerifyBlockSignature(beaconState state.ReadOnlyBeaconState, proposerIndex types.ValidatorIndex, sig []byte, rootFunc func() ([32]byte, error)) error { - currentEpoch := core.SlotToEpoch(beaconState.Slot()) + currentEpoch := time.SlotToEpoch(beaconState.Slot()) domain, err := signing.Domain(beaconState.Fork(), currentEpoch, params.BeaconConfig().DomainBeaconProposer, beaconState.GenesisValidatorRoot()) if err != nil { return err @@ -82,7 +82,7 @@ func VerifyBlockSignature(beaconState state.ReadOnlyBeaconState, // VerifyBlockHeaderSignature verifies the proposer signature of a beacon block header. func VerifyBlockHeaderSignature(beaconState state.BeaconState, header *ethpb.SignedBeaconBlockHeader) error { - currentEpoch := core.SlotToEpoch(beaconState.Slot()) + currentEpoch := time.SlotToEpoch(beaconState.Slot()) domain, err := signing.Domain(beaconState.Fork(), currentEpoch, params.BeaconConfig().DomainBeaconProposer, beaconState.GenesisValidatorRoot()) if err != nil { return err @@ -99,7 +99,7 @@ func VerifyBlockHeaderSignature(beaconState state.BeaconState, header *ethpb.Sig // from the above method by not using fork data from the state and instead retrieving it // via the respective epoch. func VerifyBlockSignatureUsingCurrentFork(beaconState state.ReadOnlyBeaconState, blk block.SignedBeaconBlock) error { - currentEpoch := core.SlotToEpoch(blk.Block().Slot()) + currentEpoch := time.SlotToEpoch(blk.Block().Slot()) fork, err := forks.Fork(currentEpoch) if err != nil { return err @@ -121,7 +121,7 @@ func BlockSignatureSet(beaconState state.ReadOnlyBeaconState, proposerIndex types.ValidatorIndex, sig []byte, rootFunc func() ([32]byte, error)) (*bls.SignatureSet, error) { - currentEpoch := core.SlotToEpoch(beaconState.Slot()) + currentEpoch := time.SlotToEpoch(beaconState.Slot()) domain, err := signing.Domain(beaconState.Fork(), currentEpoch, params.BeaconConfig().DomainBeaconProposer, beaconState.GenesisValidatorRoot()) if err != nil { return nil, err @@ -160,7 +160,7 @@ func randaoSigningData(ctx context.Context, beaconState state.ReadOnlyBeaconStat } proposerPub := beaconState.PubkeyAtIndex(proposerIdx) - currentEpoch := core.SlotToEpoch(beaconState.Slot()) + currentEpoch := time.SlotToEpoch(beaconState.Slot()) buf := make([]byte, 32) binary.LittleEndian.PutUint64(buf, uint64(currentEpoch)) @@ -238,7 +238,7 @@ func AttestationSignatureSet(ctx context.Context, beaconState state.ReadOnlyBeac var preForkAtts []*ethpb.Attestation var postForkAtts []*ethpb.Attestation for _, a := range atts { - if core.SlotToEpoch(a.Data.Slot) < fork.Epoch { + if time.SlotToEpoch(a.Data.Slot) < fork.Epoch { preForkAtts = append(preForkAtts, a) } else { postForkAtts = append(postForkAtts, a) diff --git a/beacon-chain/core/epoch/BUILD.bazel b/beacon-chain/core/epoch/BUILD.bazel index 90d2463f72..641fada515 100644 --- a/beacon-chain/core/epoch/BUILD.bazel +++ b/beacon-chain/core/epoch/BUILD.bazel @@ -9,8 +9,8 @@ go_library( "//testing/spectest:__subpackages__", ], deps = [ - "//beacon-chain/core:go_default_library", "//beacon-chain/core/helpers:go_default_library", + "//beacon-chain/core/time:go_default_library", "//beacon-chain/core/validators:go_default_library", "//beacon-chain/state:go_default_library", "//config/features:go_default_library", @@ -32,8 +32,8 @@ go_test( ], embed = [":go_default_library"], deps = [ - "//beacon-chain/core:go_default_library", "//beacon-chain/core/helpers:go_default_library", + "//beacon-chain/core/time:go_default_library", "//beacon-chain/state:go_default_library", "//beacon-chain/state/v1:go_default_library", "//config/params:go_default_library", diff --git a/beacon-chain/core/epoch/epoch_processing.go b/beacon-chain/core/epoch/epoch_processing.go index e655869e6b..22d1dded6a 100644 --- a/beacon-chain/core/epoch/epoch_processing.go +++ b/beacon-chain/core/epoch/epoch_processing.go @@ -11,8 +11,8 @@ import ( "github.com/pkg/errors" types "github.com/prysmaticlabs/eth2-types" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/core/validators" "github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/config/features" @@ -88,11 +88,11 @@ func AttestingBalance(ctx context.Context, state state.ReadOnlyBeaconState, atts // validator = state.validators[index] // validator.activation_epoch = compute_activation_exit_epoch(get_current_epoch(state)) func ProcessRegistryUpdates(ctx context.Context, state state.BeaconState) (state.BeaconState, error) { - currentEpoch := core.CurrentEpoch(state) + currentEpoch := time.CurrentEpoch(state) vals := state.Validators() var err error ejectionBal := params.BeaconConfig().EjectionBalance - activationEligibilityEpoch := core.CurrentEpoch(state) + 1 + activationEligibilityEpoch := time.CurrentEpoch(state) + 1 for idx, validator := range vals { // Process the validators for activation eligibility. if helpers.IsEligibleForActivationQueue(validator) { @@ -167,7 +167,7 @@ func ProcessRegistryUpdates(ctx context.Context, state state.BeaconState) (state // penalty = penalty_numerator // total_balance * increment // decrease_balance(state, ValidatorIndex(index), penalty) func ProcessSlashings(state state.BeaconState, slashingMultiplier uint64) (state.BeaconState, error) { - currentEpoch := core.CurrentEpoch(state) + currentEpoch := time.CurrentEpoch(state) totalBalance, err := helpers.TotalActiveBalance(state) if err != nil { return nil, errors.Wrap(err, "could not get total active balance") @@ -214,7 +214,7 @@ func ProcessSlashings(state state.BeaconState, slashingMultiplier uint64) (state // if next_epoch % EPOCHS_PER_ETH1_VOTING_PERIOD == 0: // state.eth1_data_votes = [] func ProcessEth1DataReset(state state.BeaconState) (state.BeaconState, error) { - currentEpoch := core.CurrentEpoch(state) + currentEpoch := time.CurrentEpoch(state) nextEpoch := currentEpoch + 1 // Reset ETH1 data votes. @@ -312,7 +312,7 @@ func ProcessEffectiveBalanceUpdates(state state.BeaconState) (state.BeaconState, // # Reset slashings // state.slashings[next_epoch % EPOCHS_PER_SLASHINGS_VECTOR] = Gwei(0) func ProcessSlashingsReset(state state.BeaconState) (state.BeaconState, error) { - currentEpoch := core.CurrentEpoch(state) + currentEpoch := time.CurrentEpoch(state) nextEpoch := currentEpoch + 1 // Set total slashed balances. @@ -342,7 +342,7 @@ func ProcessSlashingsReset(state state.BeaconState) (state.BeaconState, error) { // # Set randao mix // state.randao_mixes[next_epoch % EPOCHS_PER_HISTORICAL_VECTOR] = get_randao_mix(state, current_epoch) func ProcessRandaoMixesReset(state state.BeaconState) (state.BeaconState, error) { - currentEpoch := core.CurrentEpoch(state) + currentEpoch := time.CurrentEpoch(state) nextEpoch := currentEpoch + 1 // Set RANDAO mix. @@ -375,7 +375,7 @@ func ProcessRandaoMixesReset(state state.BeaconState) (state.BeaconState, error) // historical_batch = HistoricalBatch(block_roots=state.block_roots, state_roots=state.state_roots) // state.historical_roots.append(hash_tree_root(historical_batch)) func ProcessHistoricalRootsUpdate(state state.BeaconState) (state.BeaconState, error) { - currentEpoch := core.CurrentEpoch(state) + currentEpoch := time.CurrentEpoch(state) nextEpoch := currentEpoch + 1 // Set historical root accumulator. diff --git a/beacon-chain/core/epoch/epoch_processing_test.go b/beacon-chain/core/epoch/epoch_processing_test.go index 7063922364..87df87c47e 100644 --- a/beacon-chain/core/epoch/epoch_processing_test.go +++ b/beacon-chain/core/epoch/epoch_processing_test.go @@ -8,9 +8,9 @@ import ( types "github.com/prysmaticlabs/eth2-types" "github.com/prysmaticlabs/go-bitfield" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/epoch" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/state" v1 "github.com/prysmaticlabs/prysm/beacon-chain/state/v1" "github.com/prysmaticlabs/prysm/config/params" @@ -243,7 +243,7 @@ func TestProcessSlashings_SlashedLess(t *testing.T) { func TestProcessFinalUpdates_CanProcess(t *testing.T) { s := buildState(t, params.BeaconConfig().SlotsPerHistoricalRoot-1, uint64(params.BeaconConfig().SlotsPerEpoch)) - ce := core.CurrentEpoch(s) + ce := time.CurrentEpoch(s) ne := ce + 1 require.NoError(t, s.SetEth1DataVotes([]*ethpb.Eth1Data{})) balances := s.Balances() @@ -317,7 +317,7 @@ func TestProcessRegistryUpdates_EligibleToActivate(t *testing.T) { } beaconState, err := v1.InitializeFromProto(base) require.NoError(t, err) - currentEpoch := core.CurrentEpoch(beaconState) + currentEpoch := time.CurrentEpoch(beaconState) newState, err := epoch.ProcessRegistryUpdates(context.Background(), beaconState) require.NoError(t, err) for i, validator := range newState.Validators() { diff --git a/beacon-chain/core/epoch/precompute/BUILD.bazel b/beacon-chain/core/epoch/precompute/BUILD.bazel index 2a76229802..45d9f8e22e 100644 --- a/beacon-chain/core/epoch/precompute/BUILD.bazel +++ b/beacon-chain/core/epoch/precompute/BUILD.bazel @@ -16,8 +16,8 @@ go_library( "//testing/spectest:__subpackages__", ], deps = [ - "//beacon-chain/core:go_default_library", "//beacon-chain/core/helpers:go_default_library", + "//beacon-chain/core/time:go_default_library", "//beacon-chain/state:go_default_library", "//config/params:go_default_library", "//math:go_default_library", @@ -41,9 +41,9 @@ go_test( ], embed = [":go_default_library"], deps = [ - "//beacon-chain/core:go_default_library", "//beacon-chain/core/epoch:go_default_library", "//beacon-chain/core/helpers:go_default_library", + "//beacon-chain/core/time:go_default_library", "//beacon-chain/state:go_default_library", "//beacon-chain/state/v1:go_default_library", "//config/params:go_default_library", diff --git a/beacon-chain/core/epoch/precompute/attestation.go b/beacon-chain/core/epoch/precompute/attestation.go index a9d3ad1cfe..6a5986cc30 100644 --- a/beacon-chain/core/epoch/precompute/attestation.go +++ b/beacon-chain/core/epoch/precompute/attestation.go @@ -6,8 +6,8 @@ import ( "github.com/pkg/errors" types "github.com/prysmaticlabs/eth2-types" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/monitoring/tracing" @@ -71,7 +71,7 @@ func ProcessAttestations( // AttestedCurrentEpoch returns true if attestation `a` attested once in current epoch and/or epoch boundary block. func AttestedCurrentEpoch(s state.ReadOnlyBeaconState, a *ethpb.PendingAttestation) (bool, bool, error) { - currentEpoch := core.CurrentEpoch(s) + currentEpoch := time.CurrentEpoch(s) var votedCurrentEpoch, votedTarget bool // Did validator vote current epoch. if a.Data.Target.Epoch == currentEpoch { @@ -89,7 +89,7 @@ func AttestedCurrentEpoch(s state.ReadOnlyBeaconState, a *ethpb.PendingAttestati // AttestedPrevEpoch returns true if attestation `a` attested once in previous epoch and epoch boundary block and/or the same head. func AttestedPrevEpoch(s state.ReadOnlyBeaconState, a *ethpb.PendingAttestation) (bool, bool, bool, error) { - prevEpoch := core.PrevEpoch(s) + prevEpoch := time.PrevEpoch(s) var votedPrevEpoch, votedTarget, votedHead bool // Did validator vote previous epoch. if a.Data.Target.Epoch == prevEpoch { diff --git a/beacon-chain/core/epoch/precompute/justification_finalization.go b/beacon-chain/core/epoch/precompute/justification_finalization.go index c5fb394c5c..909ef4b44b 100644 --- a/beacon-chain/core/epoch/precompute/justification_finalization.go +++ b/beacon-chain/core/epoch/precompute/justification_finalization.go @@ -2,8 +2,8 @@ package precompute import ( "github.com/pkg/errors" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/state" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" ) @@ -25,7 +25,7 @@ import ( // current_target_balance = get_attesting_balance(state, current_attestations) // weigh_justification_and_finalization(state, total_active_balance, previous_target_balance, current_target_balance) func ProcessJustificationAndFinalizationPreCompute(state state.BeaconState, pBal *Balance) (state.BeaconState, error) { - canProcessSlot, err := core.StartSlot(2 /*epoch*/) + canProcessSlot, err := time.StartSlot(2 /*epoch*/) if err != nil { return nil, err } @@ -78,8 +78,8 @@ func ProcessJustificationAndFinalizationPreCompute(state state.BeaconState, pBal // state.finalized_checkpoint = old_current_justified_checkpoint func weighJustificationAndFinalization(state state.BeaconState, totalActiveBalance, prevEpochTargetBalance, currEpochTargetBalance uint64) (state.BeaconState, error) { - prevEpoch := core.PrevEpoch(state) - currentEpoch := core.CurrentEpoch(state) + prevEpoch := time.PrevEpoch(state) + currentEpoch := time.CurrentEpoch(state) oldPrevJustifiedCheckpoint := state.PreviousJustifiedCheckpoint() oldCurrJustifiedCheckpoint := state.CurrentJustifiedCheckpoint() diff --git a/beacon-chain/core/epoch/precompute/new.go b/beacon-chain/core/epoch/precompute/new.go index c9a60019e2..1186213e38 100644 --- a/beacon-chain/core/epoch/precompute/new.go +++ b/beacon-chain/core/epoch/precompute/new.go @@ -7,8 +7,8 @@ import ( "context" "github.com/pkg/errors" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/config/params" "go.opencensus.io/trace" @@ -24,8 +24,8 @@ func New(ctx context.Context, s state.BeaconState) ([]*Validator, *Balance, erro pValidators := make([]*Validator, s.NumValidators()) pBal := &Balance{} - currentEpoch := core.CurrentEpoch(s) - prevEpoch := core.PrevEpoch(s) + currentEpoch := time.CurrentEpoch(s) + prevEpoch := time.PrevEpoch(s) if err := s.ReadFromEveryValidator(func(idx int, val state.ReadOnlyValidator) error { // Was validator withdrawable or slashed diff --git a/beacon-chain/core/epoch/precompute/reward_penalty.go b/beacon-chain/core/epoch/precompute/reward_penalty.go index 7de5cf7a45..aaf004748d 100644 --- a/beacon-chain/core/epoch/precompute/reward_penalty.go +++ b/beacon-chain/core/epoch/precompute/reward_penalty.go @@ -3,8 +3,8 @@ package precompute import ( "github.com/pkg/errors" types "github.com/prysmaticlabs/eth2-types" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/math" @@ -23,7 +23,7 @@ func ProcessRewardsAndPenaltiesPrecompute( proRewardsFunc proposerRewardsFunc, ) (state.BeaconState, error) { // Can't process rewards and penalties in genesis epoch. - if core.CurrentEpoch(state) == 0 { + if time.CurrentEpoch(state) == 0 { return state, nil } @@ -69,7 +69,7 @@ func AttestationsDelta(state state.ReadOnlyBeaconState, pBal *Balance, vp []*Val numOfVals := state.NumValidators() rewards := make([]uint64, numOfVals) penalties := make([]uint64, numOfVals) - prevEpoch := core.PrevEpoch(state) + prevEpoch := time.PrevEpoch(state) finalizedEpoch := state.FinalizedCheckpointEpoch() sqrtActiveCurrentEpoch := math.IntegerSquareRoot(pBal.ActiveCurrentEpoch) diff --git a/beacon-chain/core/epoch/precompute/reward_penalty_test.go b/beacon-chain/core/epoch/precompute/reward_penalty_test.go index d43cdeae3f..40808c299b 100644 --- a/beacon-chain/core/epoch/precompute/reward_penalty_test.go +++ b/beacon-chain/core/epoch/precompute/reward_penalty_test.go @@ -7,9 +7,9 @@ import ( "github.com/pkg/errors" types "github.com/prysmaticlabs/eth2-types" "github.com/prysmaticlabs/go-bitfield" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/epoch" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/state" v1 "github.com/prysmaticlabs/prysm/beacon-chain/state/v1" "github.com/prysmaticlabs/prysm/config/params" @@ -246,7 +246,7 @@ func TestProcessRewardsAndPenaltiesPrecompute_SlashedInactivePenalty(t *testing. rewards, penalties, err := AttestationsDelta(beaconState, bp, vp) require.NoError(t, err) - finalityDelay := core.PrevEpoch(beaconState) - beaconState.FinalizedCheckpointEpoch() + finalityDelay := time.PrevEpoch(beaconState) - beaconState.FinalizedCheckpointEpoch() for _, i := range slashedAttestedIndices { base, err := baseReward(beaconState, i) require.NoError(t, err, "Could not get base reward") diff --git a/beacon-chain/core/epoch/precompute/slashing.go b/beacon-chain/core/epoch/precompute/slashing.go index 4abc399bd2..698da324b2 100644 --- a/beacon-chain/core/epoch/precompute/slashing.go +++ b/beacon-chain/core/epoch/precompute/slashing.go @@ -2,8 +2,8 @@ package precompute import ( types "github.com/prysmaticlabs/eth2-types" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/math" @@ -13,7 +13,7 @@ import ( // ProcessSlashingsPrecompute processes the slashed validators during epoch processing. // This is an optimized version by passing in precomputed total epoch balances. func ProcessSlashingsPrecompute(s state.BeaconState, pBal *Balance) error { - currentEpoch := core.CurrentEpoch(s) + currentEpoch := time.CurrentEpoch(s) exitLength := params.BeaconConfig().EpochsPerSlashingsVector // Compute the sum of state slashings diff --git a/beacon-chain/core/helpers/BUILD.bazel b/beacon-chain/core/helpers/BUILD.bazel index 74c64999fd..2298a0ce57 100644 --- a/beacon-chain/core/helpers/BUILD.bazel +++ b/beacon-chain/core/helpers/BUILD.bazel @@ -37,7 +37,7 @@ go_library( ], deps = [ "//beacon-chain/cache:go_default_library", - "//beacon-chain/core:go_default_library", + "//beacon-chain/core/time:go_default_library", "//beacon-chain/state:go_default_library", "//config/params:go_default_library", "//container/slice:go_default_library", @@ -76,7 +76,7 @@ go_test( shard_count = 2, deps = [ "//beacon-chain/cache:go_default_library", - "//beacon-chain/core:go_default_library", + "//beacon-chain/core/time:go_default_library", "//beacon-chain/state:go_default_library", "//beacon-chain/state/v1:go_default_library", "//beacon-chain/state/v2:go_default_library", diff --git a/beacon-chain/core/helpers/attestation.go b/beacon-chain/core/helpers/attestation.go index d5bd8bdc45..728c341b8c 100644 --- a/beacon-chain/core/helpers/attestation.go +++ b/beacon-chain/core/helpers/attestation.go @@ -7,7 +7,7 @@ import ( "time" types "github.com/prysmaticlabs/eth2-types" - "github.com/prysmaticlabs/prysm/beacon-chain/core" + coreTime "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/crypto/bls" "github.com/prysmaticlabs/prysm/crypto/hash" @@ -40,7 +40,7 @@ func ValidateNilAttestation(attestation *ethpb.Attestation) error { // ValidateSlotTargetEpoch checks if attestation data's epoch matches target checkpoint's epoch. // It is recommended to run `ValidateNilAttestation` first to ensure `data.Target` can't be nil. func ValidateSlotTargetEpoch(data *ethpb.AttestationData) error { - if core.SlotToEpoch(data.Slot) != data.Target.Epoch { + if coreTime.SlotToEpoch(data.Slot) != data.Target.Epoch { return fmt.Errorf("slot %d does not match target epoch %d", data.Slot, data.Target.Epoch) } return nil @@ -121,7 +121,7 @@ func ComputeSubnetForAttestation(activeValCount uint64, att *ethpb.Attestation) // // return uint64((committees_since_epoch_start + committee_index) % ATTESTATION_SUBNET_COUNT) func ComputeSubnetFromCommitteeAndSlot(activeValCount uint64, comIdx types.CommitteeIndex, attSlot types.Slot) uint64 { - slotSinceStart := core.SlotsSinceEpochStarts(attSlot) + slotSinceStart := coreTime.SlotsSinceEpochStarts(attSlot) comCount := SlotCommitteeCount(activeValCount) commsSinceStart := uint64(slotSinceStart.Mul(comCount)) computedSubnet := (commsSinceStart + uint64(comIdx)) % params.BeaconNetworkConfig().AttestationSubnetCount @@ -142,14 +142,14 @@ func ComputeSubnetFromCommitteeAndSlot(activeValCount uint64, comIdx types.Commi // valid_attestation_slot = 101 // In the attestation must be within the range of 95 to 102 in the example above. func ValidateAttestationTime(attSlot types.Slot, genesisTime time.Time, clockDisparity time.Duration) error { - if err := core.ValidateSlotClock(attSlot, uint64(genesisTime.Unix())); err != nil { + if err := coreTime.ValidateSlotClock(attSlot, uint64(genesisTime.Unix())); err != nil { return err } - attTime, err := core.SlotToTime(uint64(genesisTime.Unix()), attSlot) + attTime, err := coreTime.SlotToTime(uint64(genesisTime.Unix()), attSlot) if err != nil { return err } - currentSlot := core.SlotsSince(genesisTime) + currentSlot := coreTime.SlotsSince(genesisTime) // When receiving an attestation, it can be from the future. // so the upper bounds is set to now + clockDisparity(SECONDS_PER_SLOT * 2). @@ -163,7 +163,7 @@ func ValidateAttestationTime(attSlot types.Slot, genesisTime time.Time, clockDis if currentSlot > params.BeaconNetworkConfig().AttestationPropagationSlotRange { lowerBoundsSlot = currentSlot - params.BeaconNetworkConfig().AttestationPropagationSlotRange } - lowerTime, err := core.SlotToTime(uint64(genesisTime.Unix()), lowerBoundsSlot) + lowerTime, err := coreTime.SlotToTime(uint64(genesisTime.Unix()), lowerBoundsSlot) if err != nil { return err } @@ -187,7 +187,7 @@ func VerifyCheckpointEpoch(c *ethpb.Checkpoint, genesis time.Time) bool { now := uint64(prysmTime.Now().Unix()) genesisTime := uint64(genesis.Unix()) currentSlot := types.Slot((now - genesisTime) / params.BeaconConfig().SecondsPerSlot) - currentEpoch := core.SlotToEpoch(currentSlot) + currentEpoch := coreTime.SlotToEpoch(currentSlot) var prevEpoch types.Epoch if currentEpoch > 1 { diff --git a/beacon-chain/core/helpers/attestation_test.go b/beacon-chain/core/helpers/attestation_test.go index fa9ba88499..3c43fd3c2b 100644 --- a/beacon-chain/core/helpers/attestation_test.go +++ b/beacon-chain/core/helpers/attestation_test.go @@ -7,8 +7,8 @@ import ( "time" types "github.com/prysmaticlabs/eth2-types" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" + coreTime "github.com/prysmaticlabs/prysm/beacon-chain/core/time" v1 "github.com/prysmaticlabs/prysm/beacon-chain/state/v1" "github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/crypto/bls" @@ -118,7 +118,7 @@ func TestAttestation_ComputeSubnetForAttestation(t *testing.T) { }, Signature: []byte{'B'}, } - valCount, err := helpers.ActiveValidatorCount(context.Background(), state, core.SlotToEpoch(att.Data.Slot)) + valCount, err := helpers.ActiveValidatorCount(context.Background(), state, coreTime.SlotToEpoch(att.Data.Slot)) require.NoError(t, err) sub := helpers.ComputeSubnetForAttestation(valCount, att) assert.Equal(t, uint64(6), sub, "Did not get correct subnet for attestation") diff --git a/beacon-chain/core/helpers/beacon_committee.go b/beacon-chain/core/helpers/beacon_committee.go index 29386fc626..0adcfe9829 100644 --- a/beacon-chain/core/helpers/beacon_committee.go +++ b/beacon-chain/core/helpers/beacon_committee.go @@ -12,7 +12,7 @@ import ( types "github.com/prysmaticlabs/eth2-types" "github.com/prysmaticlabs/go-bitfield" "github.com/prysmaticlabs/prysm/beacon-chain/cache" - "github.com/prysmaticlabs/prysm/beacon-chain/core" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/container/slice" @@ -73,7 +73,7 @@ func SlotCommitteeCount(activeValidatorCount uint64) uint64 { // count=committees_per_slot * SLOTS_PER_EPOCH, // ) func BeaconCommitteeFromState(ctx context.Context, state state.ReadOnlyBeaconState, slot types.Slot, committeeIndex types.CommitteeIndex) ([]types.ValidatorIndex, error) { - epoch := core.SlotToEpoch(slot) + epoch := time.SlotToEpoch(slot) seed, err := Seed(state, epoch, params.BeaconConfig().DomainBeaconAttester) if err != nil { return nil, errors.Wrap(err, "could not get seed") @@ -157,7 +157,7 @@ func CommitteeAssignments( state state.BeaconState, epoch types.Epoch, ) (map[types.ValidatorIndex]*CommitteeAssignmentContainer, map[types.ValidatorIndex][]types.Slot, error) { - nextEpoch := core.NextEpoch(state) + nextEpoch := time.NextEpoch(state) if epoch > nextEpoch { return nil, nil, fmt.Errorf( "epoch %d can't be greater than next epoch %d", @@ -169,7 +169,7 @@ func CommitteeAssignments( // We determine the slots in which proposers are supposed to act. // Some validators may need to propose multiple times per epoch, so // we use a map of proposer idx -> []slot to keep track of this possibility. - startSlot, err := core.StartSlot(epoch) + startSlot, err := time.StartSlot(epoch) if err != nil { return nil, nil, err } @@ -320,13 +320,13 @@ func UpdateCommitteeCache(state state.ReadOnlyBeaconState, epoch types.Epoch) er func UpdateProposerIndicesInCache(ctx context.Context, state state.ReadOnlyBeaconState) error { // The cache uses the state root at the (current epoch - 1)'s slot as key. (e.g. for epoch 2, the key is root at slot 63) // Which is the reason why we skip genesis epoch. - if core.CurrentEpoch(state) <= params.BeaconConfig().GenesisEpoch+params.BeaconConfig().MinSeedLookahead { + if time.CurrentEpoch(state) <= params.BeaconConfig().GenesisEpoch+params.BeaconConfig().MinSeedLookahead { return nil } // Use state root from (current_epoch - 1)) - wantedEpoch := core.PrevEpoch(state) - s, err := core.EndSlot(wantedEpoch) + wantedEpoch := time.PrevEpoch(state) + s, err := time.EndSlot(wantedEpoch) if err != nil { return err } @@ -347,7 +347,7 @@ func UpdateProposerIndicesInCache(ctx context.Context, state state.ReadOnlyBeaco return nil } - indices, err := ActiveValidatorIndices(ctx, state, core.CurrentEpoch(state)) + indices, err := ActiveValidatorIndices(ctx, state, time.CurrentEpoch(state)) if err != nil { return err } @@ -415,12 +415,12 @@ func precomputeProposerIndices(state state.ReadOnlyBeaconState, activeIndices [] hashFunc := hash.CustomSHA256Hasher() proposerIndices := make([]types.ValidatorIndex, params.BeaconConfig().SlotsPerEpoch) - e := core.CurrentEpoch(state) + e := time.CurrentEpoch(state) seed, err := Seed(state, e, params.BeaconConfig().DomainBeaconProposer) if err != nil { return nil, errors.Wrap(err, "could not generate seed") } - slot, err := core.StartSlot(e) + slot, err := time.StartSlot(e) if err != nil { return nil, err } diff --git a/beacon-chain/core/helpers/beacon_committee_test.go b/beacon-chain/core/helpers/beacon_committee_test.go index aeba49e7b2..0e0bcc4dec 100644 --- a/beacon-chain/core/helpers/beacon_committee_test.go +++ b/beacon-chain/core/helpers/beacon_committee_test.go @@ -8,7 +8,7 @@ import ( types "github.com/prysmaticlabs/eth2-types" "github.com/prysmaticlabs/go-bitfield" - "github.com/prysmaticlabs/prysm/beacon-chain/core" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" v1 "github.com/prysmaticlabs/prysm/beacon-chain/state/v1" "github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/container/slice" @@ -44,7 +44,7 @@ func TestComputeCommittee_WithoutCache(t *testing.T) { }) require.NoError(t, err) - epoch := core.CurrentEpoch(state) + epoch := time.CurrentEpoch(state) indices, err := ActiveValidatorIndices(context.Background(), state, epoch) require.NoError(t, err) seed, err := Seed(state, epoch, params.BeaconConfig().DomainBeaconAttester) @@ -190,7 +190,7 @@ func TestCommitteeAssignments_CanRetrieve(t *testing.T) { for i, tt := range tests { t.Run(fmt.Sprintf("%d", i), func(t *testing.T) { ClearCache() - validatorIndexToCommittee, proposerIndexToSlots, err := CommitteeAssignments(context.Background(), state, core.SlotToEpoch(tt.slot)) + validatorIndexToCommittee, proposerIndexToSlots, err := CommitteeAssignments(context.Background(), state, time.SlotToEpoch(tt.slot)) require.NoError(t, err, "Failed to determine CommitteeAssignments") cac := validatorIndexToCommittee[tt.index] assert.Equal(t, tt.committeeIndex, cac.CommitteeIndex, "Unexpected committeeIndex for validator index %d", tt.index) @@ -225,11 +225,11 @@ func TestCommitteeAssignments_CannotRetrieveFuture(t *testing.T) { RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector), }) require.NoError(t, err) - _, proposerIndxs, err := CommitteeAssignments(context.Background(), state, core.CurrentEpoch(state)) + _, proposerIndxs, err := CommitteeAssignments(context.Background(), state, time.CurrentEpoch(state)) require.NoError(t, err) require.NotEqual(t, 0, len(proposerIndxs), "wanted non-zero proposer index set") - _, proposerIndxs, err = CommitteeAssignments(context.Background(), state, core.CurrentEpoch(state)+1) + _, proposerIndxs, err = CommitteeAssignments(context.Background(), state, time.CurrentEpoch(state)+1) require.NoError(t, err) require.Equal(t, 0, len(proposerIndxs), "wanted empty proposer index set") } @@ -261,9 +261,9 @@ func TestCommitteeAssignments_EverySlotHasMin1Proposer(t *testing.T) { } } assert.Equal(t, uint64(params.BeaconConfig().SlotsPerEpoch), uint64(len(slotsWithProposers)), "Unexpected slots") - startSlot, err := core.StartSlot(epoch) + startSlot, err := time.StartSlot(epoch) require.NoError(t, err) - endSlot, err := core.StartSlot(epoch + 1) + endSlot, err := time.StartSlot(epoch + 1) require.NoError(t, err) for i := startSlot; i < endSlot; i++ { hasProposer := slotsWithProposers[i] @@ -385,7 +385,7 @@ func TestUpdateCommitteeCache_CanUpdate(t *testing.T) { RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector), }) require.NoError(t, err) - require.NoError(t, UpdateCommitteeCache(state, core.CurrentEpoch(state))) + require.NoError(t, UpdateCommitteeCache(state, time.CurrentEpoch(state))) epoch := types.Epoch(1) idx := types.CommitteeIndex(1) @@ -410,7 +410,7 @@ func BenchmarkComputeCommittee300000_WithPreCache(b *testing.B) { }) require.NoError(b, err) - epoch := core.CurrentEpoch(state) + epoch := time.CurrentEpoch(state) indices, err := ActiveValidatorIndices(context.Background(), state, epoch) require.NoError(b, err) seed, err := Seed(state, epoch, params.BeaconConfig().DomainBeaconAttester) @@ -444,7 +444,7 @@ func BenchmarkComputeCommittee3000000_WithPreCache(b *testing.B) { }) require.NoError(b, err) - epoch := core.CurrentEpoch(state) + epoch := time.CurrentEpoch(state) indices, err := ActiveValidatorIndices(context.Background(), state, epoch) require.NoError(b, err) seed, err := Seed(state, epoch, params.BeaconConfig().DomainBeaconAttester) @@ -478,7 +478,7 @@ func BenchmarkComputeCommittee128000_WithOutPreCache(b *testing.B) { }) require.NoError(b, err) - epoch := core.CurrentEpoch(state) + epoch := time.CurrentEpoch(state) indices, err := ActiveValidatorIndices(context.Background(), state, epoch) require.NoError(b, err) seed, err := Seed(state, epoch, params.BeaconConfig().DomainBeaconAttester) @@ -513,7 +513,7 @@ func BenchmarkComputeCommittee1000000_WithOutCache(b *testing.B) { }) require.NoError(b, err) - epoch := core.CurrentEpoch(state) + epoch := time.CurrentEpoch(state) indices, err := ActiveValidatorIndices(context.Background(), state, epoch) require.NoError(b, err) seed, err := Seed(state, epoch, params.BeaconConfig().DomainBeaconAttester) @@ -548,7 +548,7 @@ func BenchmarkComputeCommittee4000000_WithOutCache(b *testing.B) { }) require.NoError(b, err) - epoch := core.CurrentEpoch(state) + epoch := time.CurrentEpoch(state) indices, err := ActiveValidatorIndices(context.Background(), state, epoch) require.NoError(b, err) seed, err := Seed(state, epoch, params.BeaconConfig().DomainBeaconAttester) diff --git a/beacon-chain/core/helpers/block.go b/beacon-chain/core/helpers/block.go index 469a95f969..949b6c231f 100644 --- a/beacon-chain/core/helpers/block.go +++ b/beacon-chain/core/helpers/block.go @@ -5,7 +5,7 @@ import ( "github.com/pkg/errors" types "github.com/prysmaticlabs/eth2-types" - "github.com/prysmaticlabs/prysm/beacon-chain/core" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/block" @@ -65,7 +65,7 @@ func StateRootAtSlot(state state.ReadOnlyBeaconState, slot types.Slot) ([]byte, // """ // return get_block_root_at_slot(state, compute_start_slot_at_epoch(epoch)) func BlockRoot(state state.ReadOnlyBeaconState, epoch types.Epoch) ([]byte, error) { - s, err := core.StartSlot(epoch) + s, err := time.StartSlot(epoch) if err != nil { return nil, err } diff --git a/beacon-chain/core/helpers/rewards_penalties.go b/beacon-chain/core/helpers/rewards_penalties.go index d3087d7aec..0a0e9e54ad 100644 --- a/beacon-chain/core/helpers/rewards_penalties.go +++ b/beacon-chain/core/helpers/rewards_penalties.go @@ -5,7 +5,7 @@ import ( types "github.com/prysmaticlabs/eth2-types" "github.com/prysmaticlabs/prysm/beacon-chain/cache" - "github.com/prysmaticlabs/prysm/beacon-chain/core" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/config/params" mathutil "github.com/prysmaticlabs/prysm/math" @@ -66,7 +66,7 @@ func TotalActiveBalance(s state.ReadOnlyBeaconState) (uint64, error) { } total := uint64(0) - epoch := core.SlotToEpoch(s.Slot()) + epoch := time.SlotToEpoch(s.Slot()) if err := s.ReadFromEveryValidator(func(idx int, val state.ReadOnlyValidator) error { if IsActiveValidatorUsingTrie(val, epoch) { total += val.EffectiveBalance() diff --git a/beacon-chain/core/helpers/rewards_penalties_test.go b/beacon-chain/core/helpers/rewards_penalties_test.go index 87a214d3ff..9ebb60de5d 100644 --- a/beacon-chain/core/helpers/rewards_penalties_test.go +++ b/beacon-chain/core/helpers/rewards_penalties_test.go @@ -5,7 +5,7 @@ import ( "testing" types "github.com/prysmaticlabs/eth2-types" - "github.com/prysmaticlabs/prysm/beacon-chain/core" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" v1 "github.com/prysmaticlabs/prysm/beacon-chain/state/v1" "github.com/prysmaticlabs/prysm/config/features" "github.com/prysmaticlabs/prysm/config/params" @@ -158,24 +158,24 @@ func TestFinalityDelay(t *testing.T) { finalizedEpoch := types.Epoch(0) // Set values for each test case setVal := func() { - prevEpoch = core.PrevEpoch(beaconState) + prevEpoch = time.PrevEpoch(beaconState) finalizedEpoch = beaconState.FinalizedCheckpointEpoch() } setVal() d := FinalityDelay(prevEpoch, finalizedEpoch) - w := core.PrevEpoch(beaconState) - beaconState.FinalizedCheckpointEpoch() + w := time.PrevEpoch(beaconState) - beaconState.FinalizedCheckpointEpoch() assert.Equal(t, w, d, "Did not get wanted finality delay") require.NoError(t, beaconState.SetFinalizedCheckpoint(ðpb.Checkpoint{Epoch: 4})) setVal() d = FinalityDelay(prevEpoch, finalizedEpoch) - w = core.PrevEpoch(beaconState) - beaconState.FinalizedCheckpointEpoch() + w = time.PrevEpoch(beaconState) - beaconState.FinalizedCheckpointEpoch() assert.Equal(t, w, d, "Did not get wanted finality delay") require.NoError(t, beaconState.SetFinalizedCheckpoint(ðpb.Checkpoint{Epoch: 5})) setVal() d = FinalityDelay(prevEpoch, finalizedEpoch) - w = core.PrevEpoch(beaconState) - beaconState.FinalizedCheckpointEpoch() + w = time.PrevEpoch(beaconState) - beaconState.FinalizedCheckpointEpoch() assert.Equal(t, w, d, "Did not get wanted finality delay") } @@ -188,7 +188,7 @@ func TestIsInInactivityLeak(t *testing.T) { finalizedEpoch := types.Epoch(0) // Set values for each test case setVal := func() { - prevEpoch = core.PrevEpoch(beaconState) + prevEpoch = time.PrevEpoch(beaconState) finalizedEpoch = beaconState.FinalizedCheckpointEpoch() } setVal() diff --git a/beacon-chain/core/helpers/sync_committee.go b/beacon-chain/core/helpers/sync_committee.go index 7068a485fb..3974f9f75d 100644 --- a/beacon-chain/core/helpers/sync_committee.go +++ b/beacon-chain/core/helpers/sync_committee.go @@ -8,7 +8,7 @@ import ( "github.com/pkg/errors" types "github.com/prysmaticlabs/eth2-types" "github.com/prysmaticlabs/prysm/beacon-chain/cache" - "github.com/prysmaticlabs/prysm/beacon-chain/core" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/encoding/bytesutil" @@ -154,7 +154,7 @@ func UpdateSyncCommitteeCache(st state.BeaconStateAltair) error { if nextSlot%params.BeaconConfig().SlotsPerEpoch != 0 { return errors.New("not at the end of the epoch to update cache") } - if core.SlotToEpoch(nextSlot)%params.BeaconConfig().EpochsPerSyncCommitteePeriod != 0 { + if time.SlotToEpoch(nextSlot)%params.BeaconConfig().EpochsPerSyncCommitteePeriod != 0 { return errors.New("not at sync committee period boundary to update cache") } @@ -191,11 +191,11 @@ func syncPeriodBoundaryRoot(st state.ReadOnlyBeaconState) ([]byte, error) { return params.BeaconConfig().ZeroHash[:], nil } - startEpoch, err := core.SyncCommitteePeriodStartEpoch(core.CurrentEpoch(st)) + startEpoch, err := time.SyncCommitteePeriodStartEpoch(time.CurrentEpoch(st)) if err != nil { return nil, err } - startEpochSlot, err := core.StartSlot(startEpoch) + startEpochSlot, err := time.StartSlot(startEpoch) if err != nil { return nil, err } diff --git a/beacon-chain/core/helpers/validators.go b/beacon-chain/core/helpers/validators.go index ac208c2a56..124bca3aef 100644 --- a/beacon-chain/core/helpers/validators.go +++ b/beacon-chain/core/helpers/validators.go @@ -9,7 +9,7 @@ import ( "github.com/prometheus/client_golang/prometheus/promauto" types "github.com/prysmaticlabs/eth2-types" "github.com/prysmaticlabs/prysm/beacon-chain/cache" - "github.com/prysmaticlabs/prysm/beacon-chain/core" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/crypto/hash" @@ -224,12 +224,12 @@ func ValidatorChurnLimit(activeValidatorCount uint64) (uint64, error) { // indices = get_active_validator_indices(state, epoch) // return compute_proposer_index(state, indices, seed) func BeaconProposerIndex(ctx context.Context, state state.ReadOnlyBeaconState) (types.ValidatorIndex, error) { - e := core.CurrentEpoch(state) + e := time.CurrentEpoch(state) // The cache uses the state root of the previous epoch - minimum_seed_lookahead last slot as key. (e.g. Starting epoch 1, slot 32, the key would be block root at slot 31) // For simplicity, the node will skip caching of genesis epoch. if e > params.BeaconConfig().GenesisEpoch+params.BeaconConfig().MinSeedLookahead { - wantedEpoch := core.PrevEpoch(state) - s, err := core.EndSlot(wantedEpoch) + wantedEpoch := time.PrevEpoch(state) + s, err := time.EndSlot(wantedEpoch) if err != nil { return 0, err } diff --git a/beacon-chain/core/helpers/validators_test.go b/beacon-chain/core/helpers/validators_test.go index 9ed096b315..363c76e665 100644 --- a/beacon-chain/core/helpers/validators_test.go +++ b/beacon-chain/core/helpers/validators_test.go @@ -7,7 +7,7 @@ import ( types "github.com/prysmaticlabs/eth2-types" "github.com/prysmaticlabs/prysm/beacon-chain/cache" - "github.com/prysmaticlabs/prysm/beacon-chain/core" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" v1 "github.com/prysmaticlabs/prysm/beacon-chain/state/v1" "github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/crypto/hash" @@ -376,7 +376,7 @@ func TestActiveValidatorCount_Genesis(t *testing.T) { seed, err := Seed(beaconState, 0, params.BeaconConfig().DomainBeaconAttester) require.NoError(t, err) require.NoError(t, committeeCache.AddCommitteeShuffledList(&cache.Committees{Seed: seed, ShuffledIndices: []types.ValidatorIndex{1, 2, 3}})) - validatorCount, err := ActiveValidatorCount(context.Background(), beaconState, core.CurrentEpoch(beaconState)) + validatorCount, err := ActiveValidatorCount(context.Background(), beaconState, time.CurrentEpoch(beaconState)) require.NoError(t, err) assert.Equal(t, uint64(c), validatorCount, "Did not get the correct validator count") } @@ -407,7 +407,7 @@ func TestChurnLimit_OK(t *testing.T) { RandaoMixes: make([][]byte, params.BeaconConfig().EpochsPerHistoricalVector), }) require.NoError(t, err) - validatorCount, err := ActiveValidatorCount(context.Background(), beaconState, core.CurrentEpoch(beaconState)) + validatorCount, err := ActiveValidatorCount(context.Background(), beaconState, time.CurrentEpoch(beaconState)) require.NoError(t, err) resultChurn, err := ValidatorChurnLimit(validatorCount) require.NoError(t, err) diff --git a/beacon-chain/core/helpers/weak_subjectivity.go b/beacon-chain/core/helpers/weak_subjectivity.go index cf1afe2110..1d006be03c 100644 --- a/beacon-chain/core/helpers/weak_subjectivity.go +++ b/beacon-chain/core/helpers/weak_subjectivity.go @@ -10,7 +10,7 @@ import ( "strings" types "github.com/prysmaticlabs/eth2-types" - "github.com/prysmaticlabs/prysm/beacon-chain/core" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/math" @@ -58,7 +58,7 @@ func ComputeWeakSubjectivityPeriod(ctx context.Context, st state.ReadOnlyBeaconS wsp := uint64(params.BeaconConfig().MinValidatorWithdrawabilityDelay) // Cardinality of active validator set. - N, err := ActiveValidatorCount(ctx, st, core.CurrentEpoch(st)) + N, err := ActiveValidatorCount(ctx, st, time.CurrentEpoch(st)) if err != nil { return 0, fmt.Errorf("cannot obtain active valiadtor count: %w", err) } @@ -132,9 +132,9 @@ func IsWithinWeakSubjectivityPeriod( return false, fmt.Errorf("state (%#x) and checkpoint (%#x) roots do not match", wsState.LatestBlockHeader().StateRoot, wsCheckpoint.StateRoot) } - if core.SlotToEpoch(wsState.Slot()) != wsCheckpoint.Epoch { + if time.SlotToEpoch(wsState.Slot()) != wsCheckpoint.Epoch { return false, fmt.Errorf("state (%v) and checkpoint (%v) epochs do not match", - core.SlotToEpoch(wsState.Slot()), wsCheckpoint.Epoch) + time.SlotToEpoch(wsState.Slot()), wsCheckpoint.Epoch) } // Compare given epoch to state epoch + weak subjectivity period. @@ -142,7 +142,7 @@ func IsWithinWeakSubjectivityPeriod( if err != nil { return false, fmt.Errorf("cannot compute weak subjectivity period: %w", err) } - wsStateEpoch := core.SlotToEpoch(wsState.Slot()) + wsStateEpoch := time.SlotToEpoch(wsState.Slot()) return currentEpoch <= wsStateEpoch+wsPeriod, nil } diff --git a/beacon-chain/core/signing/BUILD.bazel b/beacon-chain/core/signing/BUILD.bazel index 327218571d..9a7df63040 100644 --- a/beacon-chain/core/signing/BUILD.bazel +++ b/beacon-chain/core/signing/BUILD.bazel @@ -28,8 +28,8 @@ go_test( ], embed = [":go_default_library"], deps = [ - "//beacon-chain/core:go_default_library", "//beacon-chain/core/helpers:go_default_library", + "//beacon-chain/core/time:go_default_library", "//beacon-chain/state:go_default_library", "//config/params:go_default_library", "//crypto/bls:go_default_library", diff --git a/beacon-chain/core/signing/signing_root_test.go b/beacon-chain/core/signing/signing_root_test.go index d3bbe9f7c1..b6fe6b8538 100644 --- a/beacon-chain/core/signing/signing_root_test.go +++ b/beacon-chain/core/signing/signing_root_test.go @@ -6,9 +6,9 @@ import ( "testing" fuzz "github.com/google/gofuzz" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/beacon-chain/core/signing" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/crypto/bls" @@ -86,7 +86,7 @@ func TestSigningRoot_ComputeDomainAndSign(t *testing.T) { require.NoError(t, err) block := tt.genBlock(t, beaconState, privKeys) got, err := signing.ComputeDomainAndSign( - beaconState, core.CurrentEpoch(beaconState), block, tt.domainType, privKeys[idx]) + beaconState, time.CurrentEpoch(beaconState), block, tt.domainType, privKeys[idx]) require.NoError(t, err) require.DeepEqual(t, tt.want, got, "Incorrect signature") }) diff --git a/beacon-chain/core/BUILD.bazel b/beacon-chain/core/time/BUILD.bazel similarity index 59% rename from beacon-chain/core/BUILD.bazel rename to beacon-chain/core/time/BUILD.bazel index 287454be74..be670473e5 100644 --- a/beacon-chain/core/BUILD.bazel +++ b/beacon-chain/core/time/BUILD.bazel @@ -3,26 +3,8 @@ load("@prysm//tools/go:def.bzl", "go_library", "go_test") go_library( name = "go_default_library", srcs = ["slot_epoch.go"], - importpath = "github.com/prysmaticlabs/prysm/beacon-chain/core", - visibility = [ - "//beacon-chain:__subpackages__", - "//contracts/deposit:__pkg__", - "//crypto/keystore:__pkg__", - "//fuzz:__pkg__", - "//network/forks:__pkg__", - "//proto/prysm/v1alpha1/attestation:__pkg__", - "//runtime/interop:__pkg__", - "//slasher:__subpackages__", - "//testing/altair:__pkg__", - "//testing/benchmark/benchmark_files:__subpackages__", - "//testing/endtoend/evaluators:__pkg__", - "//testing/fuzz:__pkg__", - "//testing/slasher/simulator:__subpackages__", - "//testing/spectest:__subpackages__", - "//testing/util:__pkg__", - "//tools:__subpackages__", - "//validator:__subpackages__", - ], + importpath = "github.com/prysmaticlabs/prysm/beacon-chain/core/time", + visibility = ["//visibility:public"], deps = [ "//beacon-chain/state:go_default_library", "//config/params:go_default_library", diff --git a/beacon-chain/core/slot_epoch.go b/beacon-chain/core/time/slot_epoch.go similarity index 99% rename from beacon-chain/core/slot_epoch.go rename to beacon-chain/core/time/slot_epoch.go index 602f194ab6..6ace6cffd5 100644 --- a/beacon-chain/core/slot_epoch.go +++ b/beacon-chain/core/time/slot_epoch.go @@ -1,4 +1,4 @@ -package core +package time import ( "fmt" diff --git a/beacon-chain/core/slot_epoch_test.go b/beacon-chain/core/time/slot_epoch_test.go similarity index 99% rename from beacon-chain/core/slot_epoch_test.go rename to beacon-chain/core/time/slot_epoch_test.go index 2d55c322fa..e0d51486da 100644 --- a/beacon-chain/core/slot_epoch_test.go +++ b/beacon-chain/core/time/slot_epoch_test.go @@ -1,4 +1,4 @@ -package core +package time import ( "math" diff --git a/beacon-chain/core/transition/BUILD.bazel b/beacon-chain/core/transition/BUILD.bazel index 2c9d0028e6..1da96a65ca 100644 --- a/beacon-chain/core/transition/BUILD.bazel +++ b/beacon-chain/core/transition/BUILD.bazel @@ -26,12 +26,12 @@ go_library( ], deps = [ "//beacon-chain/cache:go_default_library", - "//beacon-chain/core:go_default_library", "//beacon-chain/core/altair:go_default_library", "//beacon-chain/core/blocks:go_default_library", "//beacon-chain/core/epoch:go_default_library", "//beacon-chain/core/epoch/precompute:go_default_library", "//beacon-chain/core/helpers:go_default_library", + "//beacon-chain/core/time:go_default_library", "//beacon-chain/core/transition/interop:go_default_library", "//beacon-chain/core/validators:go_default_library", "//beacon-chain/state:go_default_library", @@ -75,11 +75,11 @@ go_test( embed = [":go_default_library"], shard_count = 3, deps = [ - "//beacon-chain/core:go_default_library", "//beacon-chain/core/altair:go_default_library", "//beacon-chain/core/blocks:go_default_library", "//beacon-chain/core/helpers:go_default_library", "//beacon-chain/core/signing:go_default_library", + "//beacon-chain/core/time:go_default_library", "//beacon-chain/p2p/types:go_default_library", "//beacon-chain/state:go_default_library", "//beacon-chain/state/v1:go_default_library", diff --git a/beacon-chain/core/transition/altair_transition_no_verify_sig_test.go b/beacon-chain/core/transition/altair_transition_no_verify_sig_test.go index 9791e63554..74bd9c0ec2 100644 --- a/beacon-chain/core/transition/altair_transition_no_verify_sig_test.go +++ b/beacon-chain/core/transition/altair_transition_no_verify_sig_test.go @@ -6,10 +6,10 @@ import ( "testing" "github.com/prysmaticlabs/go-bitfield" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/altair" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/beacon-chain/core/signing" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/core/transition" p2pType "github.com/prysmaticlabs/prysm/beacon-chain/p2p/types" "github.com/prysmaticlabs/prysm/beacon-chain/state" @@ -45,7 +45,7 @@ func TestExecuteAltairStateTransitionNoVerify_FullProcess(t *testing.T) { require.NoError(t, beaconState.SetEth1DataVotes([]*ethpb.Eth1Data{eth1Data})) require.NoError(t, beaconState.SetSlot(beaconState.Slot()+1)) - epoch := core.CurrentEpoch(beaconState) + epoch := time.CurrentEpoch(beaconState) randaoReveal, err := util.RandaoReveal(beaconState, epoch, privKeys) require.NoError(t, err) require.NoError(t, beaconState.SetSlot(beaconState.Slot()-1)) @@ -78,7 +78,7 @@ func TestExecuteAltairStateTransitionNoVerify_FullProcess(t *testing.T) { syncSigs := make([]bls.Signature, len(indices)) for i, indice := range indices { b := p2pType.SSZBytes(pbr[:]) - sb, err := signing.ComputeDomainAndSign(beaconState, core.CurrentEpoch(beaconState), &b, params.BeaconConfig().DomainSyncCommittee, privKeys[indice]) + sb, err := signing.ComputeDomainAndSign(beaconState, time.CurrentEpoch(beaconState), &b, params.BeaconConfig().DomainSyncCommittee, privKeys[indice]) require.NoError(t, err) sig, err := bls.SignatureFromBytes(sb) require.NoError(t, err) @@ -132,7 +132,7 @@ func TestExecuteAltairStateTransitionNoVerifySignature_CouldNotVerifyStateRoot(t require.NoError(t, beaconState.SetEth1DataVotes([]*ethpb.Eth1Data{eth1Data})) require.NoError(t, beaconState.SetSlot(beaconState.Slot()+1)) - epoch := core.CurrentEpoch(beaconState) + epoch := time.CurrentEpoch(beaconState) randaoReveal, err := util.RandaoReveal(beaconState, epoch, privKeys) require.NoError(t, err) require.NoError(t, beaconState.SetSlot(beaconState.Slot()-1)) @@ -165,7 +165,7 @@ func TestExecuteAltairStateTransitionNoVerifySignature_CouldNotVerifyStateRoot(t syncSigs := make([]bls.Signature, len(indices)) for i, indice := range indices { b := p2pType.SSZBytes(pbr[:]) - sb, err := signing.ComputeDomainAndSign(beaconState, core.CurrentEpoch(beaconState), &b, params.BeaconConfig().DomainSyncCommittee, privKeys[indice]) + sb, err := signing.ComputeDomainAndSign(beaconState, time.CurrentEpoch(beaconState), &b, params.BeaconConfig().DomainSyncCommittee, privKeys[indice]) require.NoError(t, err) sig, err := bls.SignatureFromBytes(sb) require.NoError(t, err) diff --git a/beacon-chain/core/transition/benchmarks_test.go b/beacon-chain/core/transition/benchmarks_test.go index 8dc3c2a150..f509d84c55 100644 --- a/beacon-chain/core/transition/benchmarks_test.go +++ b/beacon-chain/core/transition/benchmarks_test.go @@ -4,8 +4,8 @@ import ( "context" "testing" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" coreState "github.com/prysmaticlabs/prysm/beacon-chain/core/transition" "github.com/prysmaticlabs/prysm/beacon-chain/state" v1 "github.com/prysmaticlabs/prysm/beacon-chain/state/v1" @@ -47,7 +47,7 @@ func BenchmarkExecuteStateTransition_WithCache(b *testing.B) { // some attestations in block are from previous epoch currentSlot := beaconState.Slot() require.NoError(b, beaconState.SetSlot(beaconState.Slot()-params.BeaconConfig().SlotsPerEpoch)) - require.NoError(b, helpers.UpdateCommitteeCache(beaconState, core.CurrentEpoch(beaconState))) + require.NoError(b, helpers.UpdateCommitteeCache(beaconState, time.CurrentEpoch(beaconState))) require.NoError(b, beaconState.SetSlot(currentSlot)) // Run the state transition once to populate the cache. _, err = coreState.ExecuteStateTransition(context.Background(), beaconState, wrapper.WrappedPhase0SignedBeaconBlock(block)) @@ -69,7 +69,7 @@ func BenchmarkProcessEpoch_2FullEpochs(b *testing.B) { // some attestations in block are from previous epoch currentSlot := beaconState.Slot() require.NoError(b, beaconState.SetSlot(beaconState.Slot()-params.BeaconConfig().SlotsPerEpoch)) - require.NoError(b, helpers.UpdateCommitteeCache(beaconState, core.CurrentEpoch(beaconState))) + require.NoError(b, helpers.UpdateCommitteeCache(beaconState, time.CurrentEpoch(beaconState))) require.NoError(b, beaconState.SetSlot(currentSlot)) b.ResetTimer() diff --git a/beacon-chain/core/transition/transition.go b/beacon-chain/core/transition/transition.go index 7ad4e14ef2..b80f4ae4ab 100644 --- a/beacon-chain/core/transition/transition.go +++ b/beacon-chain/core/transition/transition.go @@ -11,11 +11,11 @@ import ( "github.com/pkg/errors" types "github.com/prysmaticlabs/eth2-types" "github.com/prysmaticlabs/prysm/beacon-chain/cache" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/altair" e "github.com/prysmaticlabs/prysm/beacon-chain/core/epoch" "github.com/prysmaticlabs/prysm/beacon-chain/core/epoch/precompute" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/math" @@ -282,8 +282,8 @@ func ProcessSlots(ctx context.Context, state state.BeaconState, slot types.Slot) // Spec code: // If state.slot % SLOTS_PER_EPOCH == 0 and compute_epoch_at_slot(state.slot) == ALTAIR_FORK_EPOCH func CanUpgradeToAltair(slot types.Slot) bool { - epochStart := core.IsEpochStart(slot) - altairEpoch := core.SlotToEpoch(slot) == params.BeaconConfig().AltairForkEpoch + epochStart := time.IsEpochStart(slot) + altairEpoch := time.SlotToEpoch(slot) == params.BeaconConfig().AltairForkEpoch return epochStart && altairEpoch } @@ -356,7 +356,7 @@ func CanProcessEpoch(state state.ReadOnlyBeaconState) bool { func ProcessEpochPrecompute(ctx context.Context, state state.BeaconState) (state.BeaconState, error) { ctx, span := trace.StartSpan(ctx, "core.state.ProcessEpochPrecompute") defer span.End() - span.AddAttributes(trace.Int64Attribute("epoch", int64(core.CurrentEpoch(state)))) + span.AddAttributes(trace.Int64Attribute("epoch", int64(time.CurrentEpoch(state)))) if state == nil || state.IsNil() { return nil, errors.New("nil state") diff --git a/beacon-chain/core/transition/transition_no_verify_sig_test.go b/beacon-chain/core/transition/transition_no_verify_sig_test.go index a1d2e9bcf1..9c6dc5b72a 100644 --- a/beacon-chain/core/transition/transition_no_verify_sig_test.go +++ b/beacon-chain/core/transition/transition_no_verify_sig_test.go @@ -4,8 +4,8 @@ import ( "context" "testing" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/core/transition" "github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/encoding/bytesutil" @@ -34,7 +34,7 @@ func TestExecuteStateTransitionNoVerify_FullProcess(t *testing.T) { require.NoError(t, beaconState.SetEth1DataVotes([]*ethpb.Eth1Data{eth1Data})) require.NoError(t, beaconState.SetSlot(beaconState.Slot()+1)) - epoch := core.CurrentEpoch(beaconState) + epoch := time.CurrentEpoch(beaconState) randaoReveal, err := util.RandaoReveal(beaconState, epoch, privKeys) require.NoError(t, err) require.NoError(t, beaconState.SetSlot(beaconState.Slot()-1)) @@ -86,7 +86,7 @@ func TestExecuteStateTransitionNoVerifySignature_CouldNotVerifyStateRoot(t *test require.NoError(t, beaconState.SetEth1DataVotes([]*ethpb.Eth1Data{eth1Data})) require.NoError(t, beaconState.SetSlot(beaconState.Slot()+1)) - epoch := core.CurrentEpoch(beaconState) + epoch := time.CurrentEpoch(beaconState) randaoReveal, err := util.RandaoReveal(beaconState, epoch, privKeys) require.NoError(t, err) require.NoError(t, beaconState.SetSlot(beaconState.Slot()-1)) diff --git a/beacon-chain/core/transition/transition_test.go b/beacon-chain/core/transition/transition_test.go index 6ef9be62a2..fce57a7aea 100644 --- a/beacon-chain/core/transition/transition_test.go +++ b/beacon-chain/core/transition/transition_test.go @@ -7,10 +7,10 @@ import ( types "github.com/prysmaticlabs/eth2-types" "github.com/prysmaticlabs/go-bitfield" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/blocks" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/beacon-chain/core/signing" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/core/transition" "github.com/prysmaticlabs/prysm/beacon-chain/state" v1 "github.com/prysmaticlabs/prysm/beacon-chain/state/v1" @@ -68,7 +68,7 @@ func TestExecuteStateTransition_FullProcess(t *testing.T) { require.NoError(t, err) require.NoError(t, beaconState.SetSlot(beaconState.Slot()+1)) - epoch := core.CurrentEpoch(beaconState) + epoch := time.CurrentEpoch(beaconState) randaoReveal, err := util.RandaoReveal(beaconState, epoch, privKeys) require.NoError(t, err) require.NoError(t, beaconState.SetSlot(beaconState.Slot()-1)) @@ -214,7 +214,7 @@ func createFullBlockWithOperations(t *testing.T) (state.BeaconState, err = beaconState.SetSlot(slotsPerEpoch.Mul(uint64(params.BeaconConfig().ShardCommitteePeriod)) + params.BeaconConfig().MinAttestationInclusionDelay) require.NoError(t, err) - currentEpoch := core.CurrentEpoch(beaconState) + currentEpoch := time.CurrentEpoch(beaconState) header1 := util.HydrateSignedBeaconHeader(ðpb.SignedBeaconBlockHeader{ Header: ðpb.BeaconBlockHeader{ ProposerIndex: proposerSlashIdx, @@ -232,7 +232,7 @@ func createFullBlockWithOperations(t *testing.T) (state.BeaconState, StateRoot: bytesutil.PadTo([]byte("B"), 32), }, }) - header2.Signature, err = signing.ComputeDomainAndSign(beaconState, core.CurrentEpoch(beaconState), header2.Header, params.BeaconConfig().DomainBeaconProposer, privKeys[proposerSlashIdx]) + header2.Signature, err = signing.ComputeDomainAndSign(beaconState, time.CurrentEpoch(beaconState), header2.Header, params.BeaconConfig().DomainBeaconProposer, privKeys[proposerSlashIdx]) require.NoError(t, err) proposerSlashings := []*ethpb.ProposerSlashing{ @@ -295,7 +295,7 @@ func createFullBlockWithOperations(t *testing.T) (state.BeaconState, blockAtt := util.HydrateAttestation(ðpb.Attestation{ Data: ðpb.AttestationData{ Slot: beaconState.Slot(), - Target: ðpb.Checkpoint{Epoch: core.CurrentEpoch(beaconState)}, + Target: ðpb.Checkpoint{Epoch: time.CurrentEpoch(beaconState)}, Source: ðpb.Checkpoint{Root: mockRoot[:]}}, AggregationBits: aggBits, }) diff --git a/beacon-chain/core/validators/BUILD.bazel b/beacon-chain/core/validators/BUILD.bazel index fe2ebece98..4e11e61800 100644 --- a/beacon-chain/core/validators/BUILD.bazel +++ b/beacon-chain/core/validators/BUILD.bazel @@ -9,8 +9,8 @@ go_library( "//testing/spectest:__subpackages__", ], deps = [ - "//beacon-chain/core:go_default_library", "//beacon-chain/core/helpers:go_default_library", + "//beacon-chain/core/time:go_default_library", "//beacon-chain/state:go_default_library", "//config/params:go_default_library", "//proto/prysm/v1alpha1:go_default_library", @@ -25,8 +25,8 @@ go_test( srcs = ["validator_test.go"], embed = [":go_default_library"], deps = [ - "//beacon-chain/core:go_default_library", "//beacon-chain/core/helpers:go_default_library", + "//beacon-chain/core/time:go_default_library", "//beacon-chain/state/v1:go_default_library", "//config/params:go_default_library", "//proto/prysm/v1alpha1:go_default_library", diff --git a/beacon-chain/core/validators/validator.go b/beacon-chain/core/validators/validator.go index 5b10efb944..20458a755f 100644 --- a/beacon-chain/core/validators/validator.go +++ b/beacon-chain/core/validators/validator.go @@ -9,8 +9,8 @@ import ( "github.com/pkg/errors" types "github.com/prysmaticlabs/eth2-types" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/config/params" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" @@ -57,7 +57,7 @@ func InitiateValidatorExit(ctx context.Context, s state.BeaconState, idx types.V if err != nil { return nil, err } - exitEpochs = append(exitEpochs, helpers.ActivationExitEpoch(core.CurrentEpoch(s))) + exitEpochs = append(exitEpochs, helpers.ActivationExitEpoch(time.CurrentEpoch(s))) // Obtain the exit queue epoch as the maximum number in the exit epochs array. exitQueueEpoch := types.Epoch(0) @@ -78,7 +78,7 @@ func InitiateValidatorExit(ctx context.Context, s state.BeaconState, idx types.V if err != nil { return nil, err } - activeValidatorCount, err := helpers.ActiveValidatorCount(ctx, s, core.CurrentEpoch(s)) + activeValidatorCount, err := helpers.ActiveValidatorCount(ctx, s, time.CurrentEpoch(s)) if err != nil { return nil, errors.Wrap(err, "could not get active validator count") } @@ -134,7 +134,7 @@ func SlashValidator( if err != nil { return nil, errors.Wrapf(err, "could not initiate validator %d exit", slashedIdx) } - currentEpoch := core.SlotToEpoch(s.Slot()) + currentEpoch := time.SlotToEpoch(s.Slot()) validator, err := s.ValidatorAtIndex(slashedIdx) if err != nil { return nil, err diff --git a/beacon-chain/core/validators/validator_test.go b/beacon-chain/core/validators/validator_test.go index ee4d00088c..61065678f0 100644 --- a/beacon-chain/core/validators/validator_test.go +++ b/beacon-chain/core/validators/validator_test.go @@ -5,8 +5,8 @@ import ( "testing" types "github.com/prysmaticlabs/eth2-types" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" v1 "github.com/prysmaticlabs/prysm/beacon-chain/state/v1" "github.com/prysmaticlabs/prysm/config/params" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" @@ -135,7 +135,7 @@ func TestSlashValidator_OK(t *testing.T) { v, err := state.ValidatorAtIndex(slashedIdx) require.NoError(t, err) assert.Equal(t, true, v.Slashed, "Validator not slashed despite supposed to being slashed") - assert.Equal(t, core.CurrentEpoch(state)+params.BeaconConfig().EpochsPerSlashingsVector, v.WithdrawableEpoch, "Withdrawable epoch not the expected value") + assert.Equal(t, time.CurrentEpoch(state)+params.BeaconConfig().EpochsPerSlashingsVector, v.WithdrawableEpoch, "Withdrawable epoch not the expected value") maxBalance := params.BeaconConfig().MaxEffectiveBalance slashedBalance := state.Slashings()[state.Slot().Mod(uint64(params.BeaconConfig().EpochsPerSlashingsVector))] @@ -205,7 +205,7 @@ func TestActivatedValidatorIndices(t *testing.T) { for _, tt := range tests { s, err := v1.InitializeFromProto(tt.state) require.NoError(t, err) - activatedIndices := ActivatedValidatorIndices(core.CurrentEpoch(s), tt.state.Validators) + activatedIndices := ActivatedValidatorIndices(time.CurrentEpoch(s), tt.state.Validators) assert.DeepEqual(t, tt.wanted, activatedIndices) } } @@ -259,7 +259,7 @@ func TestSlashedValidatorIndices(t *testing.T) { for _, tt := range tests { s, err := v1.InitializeFromProto(tt.state) require.NoError(t, err) - slashedIndices := SlashedValidatorIndices(core.CurrentEpoch(s), tt.state.Validators) + slashedIndices := SlashedValidatorIndices(time.CurrentEpoch(s), tt.state.Validators) assert.DeepEqual(t, tt.wanted, slashedIndices) } } @@ -319,7 +319,7 @@ func TestExitedValidatorIndices(t *testing.T) { for _, tt := range tests { s, err := v1.InitializeFromProto(tt.state) require.NoError(t, err) - activeCount, err := helpers.ActiveValidatorCount(context.Background(), s, core.PrevEpoch(s)) + activeCount, err := helpers.ActiveValidatorCount(context.Background(), s, time.PrevEpoch(s)) require.NoError(t, err) exitedIndices, err := ExitedValidatorIndices(0, tt.state.Validators, activeCount) require.NoError(t, err) diff --git a/beacon-chain/db/kv/BUILD.bazel b/beacon-chain/db/kv/BUILD.bazel index a0ac4388a8..d4644e3eba 100644 --- a/beacon-chain/db/kv/BUILD.bazel +++ b/beacon-chain/db/kv/BUILD.bazel @@ -34,9 +34,9 @@ go_library( "//tools:__subpackages__", ], deps = [ - "//beacon-chain/core:go_default_library", "//beacon-chain/core/blocks:go_default_library", "//beacon-chain/core/helpers:go_default_library", + "//beacon-chain/core/time:go_default_library", "//beacon-chain/db/filters:go_default_library", "//beacon-chain/db/iface:go_default_library", "//beacon-chain/state:go_default_library", diff --git a/beacon-chain/db/kv/blocks.go b/beacon-chain/db/kv/blocks.go index fe152c020c..f6e0f51605 100644 --- a/beacon-chain/db/kv/blocks.go +++ b/beacon-chain/db/kv/blocks.go @@ -8,7 +8,7 @@ import ( "github.com/golang/snappy" "github.com/pkg/errors" types "github.com/prysmaticlabs/eth2-types" - "github.com/prysmaticlabs/prysm/beacon-chain/core" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/db/filters" "github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/container/slice" @@ -479,11 +479,11 @@ func blockRootsBySlotRange( endEpoch, endEpochOk := endEpochEncoded.(types.Epoch) var err error if startEpochOk && endEpochOk { - startSlot, err = core.StartSlot(startEpoch) + startSlot, err = time.StartSlot(startEpoch) if err != nil { return nil, err } - endSlot, err = core.StartSlot(endEpoch) + endSlot, err = time.StartSlot(endEpoch) if err != nil { return nil, err } diff --git a/beacon-chain/db/kv/state.go b/beacon-chain/db/kv/state.go index aaa496bb9e..baa8f1c4fe 100644 --- a/beacon-chain/db/kv/state.go +++ b/beacon-chain/db/kv/state.go @@ -7,8 +7,8 @@ import ( "github.com/golang/snappy" "github.com/pkg/errors" types "github.com/prysmaticlabs/eth2-types" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/beacon-chain/state/genesis" v1 "github.com/prysmaticlabs/prysm/beacon-chain/state/v1" @@ -666,7 +666,7 @@ func (s *Store) CleanUpDirtyStates(ctx context.Context, slotsPerArchivedPoint ty if err != nil { return err } - finalizedSlot, err := core.StartSlot(f.Epoch) + finalizedSlot, err := time.StartSlot(f.Epoch) if err != nil { return err } diff --git a/beacon-chain/db/slasherkv/BUILD.bazel b/beacon-chain/db/slasherkv/BUILD.bazel index 5a3eb5f4c8..7b2fd32c1a 100644 --- a/beacon-chain/db/slasherkv/BUILD.bazel +++ b/beacon-chain/db/slasherkv/BUILD.bazel @@ -13,7 +13,7 @@ go_library( importpath = "github.com/prysmaticlabs/prysm/beacon-chain/db/slasherkv", visibility = ["//beacon-chain:__subpackages__"], deps = [ - "//beacon-chain/core:go_default_library", + "//beacon-chain/core/time:go_default_library", "//beacon-chain/db/iface:go_default_library", "//beacon-chain/slasher/types:go_default_library", "//config/params:go_default_library", @@ -43,7 +43,7 @@ go_test( ], embed = [":go_default_library"], deps = [ - "//beacon-chain/core:go_default_library", + "//beacon-chain/core/time:go_default_library", "//beacon-chain/slasher/types:go_default_library", "//config/params:go_default_library", "//encoding/bytesutil:go_default_library", diff --git a/beacon-chain/db/slasherkv/pruning.go b/beacon-chain/db/slasherkv/pruning.go index 299193e8fe..9710d580d3 100644 --- a/beacon-chain/db/slasherkv/pruning.go +++ b/beacon-chain/db/slasherkv/pruning.go @@ -7,7 +7,7 @@ import ( fssz "github.com/ferranbt/fastssz" types "github.com/prysmaticlabs/eth2-types" - "github.com/prysmaticlabs/prysm/beacon-chain/core" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" bolt "go.etcd.io/bbolt" ) @@ -88,7 +88,7 @@ func (s *Store) PruneProposalsAtEpoch( ctx context.Context, maxEpoch types.Epoch, ) (numPruned uint, err error) { var endPruneSlot types.Slot - endPruneSlot, err = core.EndSlot(maxEpoch) + endPruneSlot, err = time.EndSlot(maxEpoch) if err != nil { return } diff --git a/beacon-chain/db/slasherkv/pruning_test.go b/beacon-chain/db/slasherkv/pruning_test.go index 464cff567e..346ca315d6 100644 --- a/beacon-chain/db/slasherkv/pruning_test.go +++ b/beacon-chain/db/slasherkv/pruning_test.go @@ -6,7 +6,7 @@ import ( "testing" types "github.com/prysmaticlabs/eth2-types" - "github.com/prysmaticlabs/prysm/beacon-chain/core" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" slashertypes "github.com/prysmaticlabs/prysm/beacon-chain/slasher/types" "github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/testing/require" @@ -29,7 +29,7 @@ func TestStore_PruneProposalsAtEpoch(t *testing.T) { historyLength := types.Epoch(10) pruningLimitEpoch := currentEpoch - historyLength - lowestStoredSlot, err := core.EndSlot(pruningLimitEpoch) + lowestStoredSlot, err := time.EndSlot(pruningLimitEpoch) require.NoError(t, err) err = beaconDB.db.Update(func(tx *bolt.Tx) error { @@ -68,9 +68,9 @@ func TestStore_PruneProposalsAtEpoch(t *testing.T) { slotsPerEpoch := params.BeaconConfig().SlotsPerEpoch proposals := make([]*slashertypes.SignedBlockHeaderWrapper, 0, uint64(currentEpoch)*uint64(slotsPerEpoch)*2) for i := types.Epoch(0); i < currentEpoch; i++ { - startSlot, err := core.StartSlot(i) + startSlot, err := time.StartSlot(i) require.NoError(t, err) - endSlot, err := core.StartSlot(i + 1) + endSlot, err := time.StartSlot(i + 1) require.NoError(t, err) for j := startSlot; j < endSlot; j++ { prop1 := createProposalWrapper(t, j, 0 /* proposer index */, []byte{0}) @@ -89,9 +89,9 @@ func TestStore_PruneProposalsAtEpoch(t *testing.T) { for i := types.Epoch(0); i < pruningLimitEpoch; i++ { err = beaconDB.db.View(func(tx *bolt.Tx) error { bkt := tx.Bucket(proposalRecordsBucket) - startSlot, err := core.StartSlot(i) + startSlot, err := time.StartSlot(i) require.NoError(t, err) - endSlot, err := core.StartSlot(i + 1) + endSlot, err := time.StartSlot(i + 1) require.NoError(t, err) for j := startSlot; j < endSlot; j++ { prop1Key, err := keyForValidatorProposal(j, 0) @@ -168,9 +168,9 @@ func TestStore_PruneAttestations_OK(t *testing.T) { slotsPerEpoch := params.BeaconConfig().SlotsPerEpoch attestations := make([]*slashertypes.IndexedAttestationWrapper, 0, uint64(currentEpoch)*uint64(slotsPerEpoch)*2) for i := types.Epoch(0); i < currentEpoch; i++ { - startSlot, err := core.StartSlot(i) + startSlot, err := time.StartSlot(i) require.NoError(t, err) - endSlot, err := core.StartSlot(i + 1) + endSlot, err := time.StartSlot(i + 1) require.NoError(t, err) for j := startSlot; j < endSlot; j++ { attester1 := uint64(j + 10) @@ -196,9 +196,9 @@ func TestStore_PruneAttestations_OK(t *testing.T) { for i := types.Epoch(0); i < pruningLimitEpoch; i++ { err = beaconDB.db.View(func(tx *bolt.Tx) error { bkt := tx.Bucket(attestationDataRootsBucket) - startSlot, err := core.StartSlot(i) + startSlot, err := time.StartSlot(i) require.NoError(t, err) - endSlot, err := core.StartSlot(i + 1) + endSlot, err := time.StartSlot(i + 1) require.NoError(t, err) for j := startSlot; j < endSlot; j++ { attester1 := types.ValidatorIndex(j + 10) diff --git a/beacon-chain/operations/slashings/BUILD.bazel b/beacon-chain/operations/slashings/BUILD.bazel index 7a6987853a..f50418409d 100644 --- a/beacon-chain/operations/slashings/BUILD.bazel +++ b/beacon-chain/operations/slashings/BUILD.bazel @@ -18,9 +18,9 @@ go_library( "//testing/slasher/simulator:__pkg__", ], deps = [ - "//beacon-chain/core:go_default_library", "//beacon-chain/core/blocks:go_default_library", "//beacon-chain/core/helpers:go_default_library", + "//beacon-chain/core/time:go_default_library", "//beacon-chain/state:go_default_library", "//config/params:go_default_library", "//container/slice:go_default_library", diff --git a/beacon-chain/operations/slashings/service.go b/beacon-chain/operations/slashings/service.go index 9860ce2cca..c1652675b3 100644 --- a/beacon-chain/operations/slashings/service.go +++ b/beacon-chain/operations/slashings/service.go @@ -7,9 +7,9 @@ import ( "github.com/pkg/errors" types "github.com/prysmaticlabs/eth2-types" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/blocks" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/container/slice" @@ -275,7 +275,7 @@ func (p *Pool) validatorSlashingPreconditionCheck( return false, err } // Checking if the validator is slashable. - if !helpers.IsSlashableValidatorUsingTrie(validator, core.CurrentEpoch(state)) { + if !helpers.IsSlashableValidatorUsingTrie(validator, time.CurrentEpoch(state)) { return false, nil } return true, nil diff --git a/beacon-chain/operations/voluntaryexits/BUILD.bazel b/beacon-chain/operations/voluntaryexits/BUILD.bazel index d1619bdb71..c8a285cd83 100644 --- a/beacon-chain/operations/voluntaryexits/BUILD.bazel +++ b/beacon-chain/operations/voluntaryexits/BUILD.bazel @@ -13,7 +13,7 @@ go_library( "//testing/fuzz:__pkg__", ], deps = [ - "//beacon-chain/core:go_default_library", + "//beacon-chain/core/time:go_default_library", "//beacon-chain/state:go_default_library", "//config/params:go_default_library", "//proto/prysm/v1alpha1:go_default_library", diff --git a/beacon-chain/operations/voluntaryexits/service.go b/beacon-chain/operations/voluntaryexits/service.go index eb463e3672..72b487d151 100644 --- a/beacon-chain/operations/voluntaryexits/service.go +++ b/beacon-chain/operations/voluntaryexits/service.go @@ -6,7 +6,7 @@ import ( "sync" types "github.com/prysmaticlabs/eth2-types" - "github.com/prysmaticlabs/prysm/beacon-chain/core" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/config/params" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" @@ -49,7 +49,7 @@ func (p *Pool) PendingExits(state state.ReadOnlyBeaconState, slot types.Slot, no } pending := make([]*ethpb.SignedVoluntaryExit, 0, maxExits) for _, e := range p.pending { - if e.Exit.Epoch > core.SlotToEpoch(slot) { + if e.Exit.Epoch > time.SlotToEpoch(slot) { continue } if v, err := state.ValidatorAtIndexReadOnly(e.Exit.ValidatorIndex); err == nil && diff --git a/beacon-chain/p2p/BUILD.bazel b/beacon-chain/p2p/BUILD.bazel index 6173accc31..fb2140b141 100644 --- a/beacon-chain/p2p/BUILD.bazel +++ b/beacon-chain/p2p/BUILD.bazel @@ -42,11 +42,11 @@ go_library( deps = [ "//async:go_default_library", "//beacon-chain/cache:go_default_library", - "//beacon-chain/core:go_default_library", "//beacon-chain/core/altair:go_default_library", "//beacon-chain/core/feed:go_default_library", "//beacon-chain/core/feed/state:go_default_library", "//beacon-chain/core/helpers:go_default_library", + "//beacon-chain/core/time:go_default_library", "//beacon-chain/db:go_default_library", "//beacon-chain/p2p/encoder:go_default_library", "//beacon-chain/p2p/peers:go_default_library", diff --git a/beacon-chain/p2p/broadcaster.go b/beacon-chain/p2p/broadcaster.go index 6239312102..0e52580466 100644 --- a/beacon-chain/p2p/broadcaster.go +++ b/beacon-chain/p2p/broadcaster.go @@ -9,8 +9,8 @@ import ( ssz "github.com/ferranbt/fastssz" "github.com/pkg/errors" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/altair" + coreTime "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/crypto/hash" "github.com/prysmaticlabs/prysm/monitoring/tracing" @@ -130,7 +130,7 @@ func (s *Service) broadcastAttestation(ctx context.Context, subnet uint64, att * } // In the event our attestation is outdated and beyond the // acceptable threshold, we exit early and do not broadcast it. - currSlot := core.CurrentSlot(uint64(s.genesisTime.Unix())) + currSlot := coreTime.CurrentSlot(uint64(s.genesisTime.Unix())) if att.Data.Slot+params.BeaconConfig().SlotsPerEpoch < currSlot { log.Warnf("Attestation is too old to broadcast, discarding it. Current Slot: %d , Attestation Slot: %d", currSlot, att.Data.Slot) return diff --git a/beacon-chain/p2p/discovery.go b/beacon-chain/p2p/discovery.go index ddaf459b7f..ef1810099f 100644 --- a/beacon-chain/p2p/discovery.go +++ b/beacon-chain/p2p/discovery.go @@ -16,7 +16,7 @@ import ( "github.com/pkg/errors" "github.com/prysmaticlabs/go-bitfield" "github.com/prysmaticlabs/prysm/beacon-chain/cache" - "github.com/prysmaticlabs/prysm/beacon-chain/core" + coreTime "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/runtime/version" ) @@ -53,7 +53,7 @@ func (s *Service) RefreshENR() { return } // Compare current epoch with our fork epochs - currEpoch := core.SlotToEpoch(core.CurrentSlot(uint64(s.genesisTime.Unix()))) + currEpoch := coreTime.SlotToEpoch(coreTime.CurrentSlot(uint64(s.genesisTime.Unix()))) altairForkEpoch := params.BeaconConfig().AltairForkEpoch switch { // Altair Behaviour diff --git a/beacon-chain/p2p/fork.go b/beacon-chain/p2p/fork.go index 795a6f6934..2ecccc1fc6 100644 --- a/beacon-chain/p2p/fork.go +++ b/beacon-chain/p2p/fork.go @@ -8,7 +8,7 @@ import ( "github.com/ethereum/go-ethereum/p2p/enode" "github.com/ethereum/go-ethereum/p2p/enr" "github.com/pkg/errors" - "github.com/prysmaticlabs/prysm/beacon-chain/core" + coreTime "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/network/forks" pb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" @@ -88,8 +88,8 @@ func addForkEntry( if err != nil { return nil, err } - currentSlot := core.SlotsSince(genesisTime) - currentEpoch := core.SlotToEpoch(currentSlot) + currentSlot := coreTime.SlotsSince(genesisTime) + currentEpoch := coreTime.SlotToEpoch(currentSlot) if prysmTime.Now().Before(genesisTime) { currentEpoch = 0 } diff --git a/beacon-chain/p2p/fork_watcher.go b/beacon-chain/p2p/fork_watcher.go index 1f4ad5e284..632b890856 100644 --- a/beacon-chain/p2p/fork_watcher.go +++ b/beacon-chain/p2p/fork_watcher.go @@ -1,7 +1,7 @@ package p2p import ( - "github.com/prysmaticlabs/prysm/beacon-chain/core" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/time/slots" ) @@ -14,7 +14,7 @@ func (s *Service) forkWatcher() { for { select { case currSlot := <-slotTicker.C(): - currEpoch := core.SlotToEpoch(currSlot) + currEpoch := time.SlotToEpoch(currSlot) if currEpoch == params.BeaconConfig().AltairForkEpoch { // If we are in the fork epoch, we update our enr with // the updated fork digest. These repeatedly does diff --git a/beacon-chain/p2p/gossip_scoring_params.go b/beacon-chain/p2p/gossip_scoring_params.go index 0be84faed9..b2c510eada 100644 --- a/beacon-chain/p2p/gossip_scoring_params.go +++ b/beacon-chain/p2p/gossip_scoring_params.go @@ -10,8 +10,8 @@ import ( "github.com/libp2p/go-libp2p-core/peer" pubsub "github.com/libp2p/go-libp2p-pubsub" "github.com/pkg/errors" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" + coreTime "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/config/params" "github.com/sirupsen/logrus" ) @@ -134,7 +134,7 @@ func (s *Service) retrieveActiveValidators() (uint64, error) { if genState == nil || genState.IsNil() { return 0, errors.New("no genesis state exists") } - activeVals, err := helpers.ActiveValidatorCount(context.Background(), genState, core.CurrentEpoch(genState)) + activeVals, err := helpers.ActiveValidatorCount(context.Background(), genState, coreTime.CurrentEpoch(genState)) if err != nil { return 0, err } @@ -149,7 +149,7 @@ func (s *Service) retrieveActiveValidators() (uint64, error) { if bState == nil || bState.IsNil() { return 0, errors.Errorf("no state with root %#x exists", rt) } - activeVals, err := helpers.ActiveValidatorCount(context.Background(), bState, core.CurrentEpoch(bState)) + activeVals, err := helpers.ActiveValidatorCount(context.Background(), bState, coreTime.CurrentEpoch(bState)) if err != nil { return 0, err } diff --git a/beacon-chain/p2p/peers/BUILD.bazel b/beacon-chain/p2p/peers/BUILD.bazel index df1a77fbb2..e98e7a87c0 100644 --- a/beacon-chain/p2p/peers/BUILD.bazel +++ b/beacon-chain/p2p/peers/BUILD.bazel @@ -6,7 +6,7 @@ go_library( importpath = "github.com/prysmaticlabs/prysm/beacon-chain/p2p/peers", visibility = ["//beacon-chain:__subpackages__"], deps = [ - "//beacon-chain/core:go_default_library", + "//beacon-chain/core/time:go_default_library", "//beacon-chain/p2p/peers/peerdata:go_default_library", "//beacon-chain/p2p/peers/scorers:go_default_library", "//config/features:go_default_library", diff --git a/beacon-chain/p2p/peers/status.go b/beacon-chain/p2p/peers/status.go index d521f874cc..810af0b5a7 100644 --- a/beacon-chain/p2p/peers/status.go +++ b/beacon-chain/p2p/peers/status.go @@ -35,7 +35,7 @@ import ( manet "github.com/multiformats/go-multiaddr/net" types "github.com/prysmaticlabs/eth2-types" "github.com/prysmaticlabs/go-bitfield" - "github.com/prysmaticlabs/prysm/beacon-chain/core" + coreTime "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/p2p/peers/peerdata" "github.com/prysmaticlabs/prysm/beacon-chain/p2p/peers/scorers" "github.com/prysmaticlabs/prysm/config/features" @@ -707,7 +707,7 @@ func (p *Status) BestNonFinalized(minPeers int, ourHeadEpoch types.Epoch) (types for _, pid := range connected { peerChainState, err := p.ChainState(pid) if err == nil && peerChainState != nil && peerChainState.HeadSlot > ourHeadSlot { - epoch := core.SlotToEpoch(peerChainState.HeadSlot) + epoch := coreTime.SlotToEpoch(peerChainState.HeadSlot) epochVotes[epoch]++ pidEpoch[pid] = epoch pidHead[pid] = peerChainState.HeadSlot @@ -876,7 +876,7 @@ func (p *Status) HighestEpoch() types.Epoch { highestSlot = peerData.ChainState.HeadSlot } } - return core.SlotToEpoch(highestSlot) + return coreTime.SlotToEpoch(highestSlot) } // ConnectedPeerLimit returns the peer limit of diff --git a/beacon-chain/powchain/BUILD.bazel b/beacon-chain/powchain/BUILD.bazel index 22767f8888..e904491329 100644 --- a/beacon-chain/powchain/BUILD.bazel +++ b/beacon-chain/powchain/BUILD.bazel @@ -19,11 +19,11 @@ go_library( ], deps = [ "//beacon-chain/cache/depositcache:go_default_library", - "//beacon-chain/core:go_default_library", "//beacon-chain/core/blocks:go_default_library", "//beacon-chain/core/feed:go_default_library", "//beacon-chain/core/feed/state:go_default_library", "//beacon-chain/core/helpers:go_default_library", + "//beacon-chain/core/time:go_default_library", "//beacon-chain/core/transition:go_default_library", "//beacon-chain/db:go_default_library", "//beacon-chain/powchain/types:go_default_library", @@ -76,11 +76,11 @@ go_test( deps = [ "//async/event:go_default_library", "//beacon-chain/cache/depositcache:go_default_library", - "//beacon-chain/core:go_default_library", "//beacon-chain/core/feed:go_default_library", "//beacon-chain/core/feed/state:go_default_library", "//beacon-chain/core/helpers:go_default_library", "//beacon-chain/core/signing:go_default_library", + "//beacon-chain/core/time:go_default_library", "//beacon-chain/db:go_default_library", "//beacon-chain/db/testing:go_default_library", "//beacon-chain/powchain/testing:go_default_library", diff --git a/beacon-chain/powchain/service.go b/beacon-chain/powchain/service.go index 80c6aba607..093bbe16ee 100644 --- a/beacon-chain/powchain/service.go +++ b/beacon-chain/powchain/service.go @@ -24,8 +24,8 @@ import ( "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promauto" "github.com/prysmaticlabs/prysm/beacon-chain/cache/depositcache" - "github.com/prysmaticlabs/prysm/beacon-chain/core" statefeed "github.com/prysmaticlabs/prysm/beacon-chain/core/feed/state" + coreTime "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/core/transition" "github.com/prysmaticlabs/prysm/beacon-chain/db" "github.com/prysmaticlabs/prysm/beacon-chain/powchain/types" @@ -891,7 +891,7 @@ func (s *Service) cacheHeadersForEth1DataVote(ctx context.Context) error { // determines the earliest voting block from which to start caching all our previous headers from. func (s *Service) determineEarliestVotingBlock(ctx context.Context, followBlock uint64) (uint64, error) { genesisTime := s.chainStartData.GenesisTime - currSlot := core.CurrentSlot(genesisTime) + currSlot := coreTime.CurrentSlot(genesisTime) // In the event genesis has not occurred yet, we just request go back follow_distance blocks. if genesisTime == 0 || currSlot == 0 { @@ -901,7 +901,7 @@ func (s *Service) determineEarliestVotingBlock(ctx context.Context, followBlock } return earliestBlk, nil } - votingTime := core.VotingPeriodStartTime(genesisTime, currSlot) + votingTime := coreTime.VotingPeriodStartTime(genesisTime, currSlot) followBackDist := 2 * params.BeaconConfig().SecondsPerETH1Block * params.BeaconConfig().Eth1FollowDistance if followBackDist > votingTime { return 0, errors.Errorf("invalid genesis time provided. %d > %d", followBackDist, votingTime) diff --git a/beacon-chain/powchain/service_test.go b/beacon-chain/powchain/service_test.go index 4f0d9df903..0dbf01e677 100644 --- a/beacon-chain/powchain/service_test.go +++ b/beacon-chain/powchain/service_test.go @@ -17,7 +17,7 @@ import ( gethTypes "github.com/ethereum/go-ethereum/core/types" "github.com/prysmaticlabs/prysm/async/event" "github.com/prysmaticlabs/prysm/beacon-chain/cache/depositcache" - "github.com/prysmaticlabs/prysm/beacon-chain/core" + coreTime "github.com/prysmaticlabs/prysm/beacon-chain/core/time" dbutil "github.com/prysmaticlabs/prysm/beacon-chain/db/testing" mockPOW "github.com/prysmaticlabs/prysm/beacon-chain/powchain/testing" "github.com/prysmaticlabs/prysm/beacon-chain/state/stategen" @@ -534,7 +534,7 @@ func TestInitDepositCacheWithFinalization_OK(t *testing.T) { require.NoError(t, stateGen.SaveState(ctx, headRoot, emptyState)) require.NoError(t, beaconDB.SaveState(ctx, emptyState, headRoot)) require.NoError(t, beaconDB.SaveBlock(ctx, wrapper.WrappedPhase0SignedBeaconBlock(headBlock))) - require.NoError(t, beaconDB.SaveFinalizedCheckpoint(ctx, ðpb.Checkpoint{Epoch: core.SlotToEpoch(0), Root: headRoot[:]})) + require.NoError(t, beaconDB.SaveFinalizedCheckpoint(ctx, ðpb.Checkpoint{Epoch: coreTime.SlotToEpoch(0), Root: headRoot[:]})) s.chainStartData.Chainstarted = true require.NoError(t, s.initDepositCaches(context.Background(), ctrs)) diff --git a/beacon-chain/rpc/apimiddleware/BUILD.bazel b/beacon-chain/rpc/apimiddleware/BUILD.bazel index 379c6294a5..a2f8ec6a0f 100644 --- a/beacon-chain/rpc/apimiddleware/BUILD.bazel +++ b/beacon-chain/rpc/apimiddleware/BUILD.bazel @@ -14,7 +14,7 @@ go_library( deps = [ "//api/gateway/apimiddleware:go_default_library", "//api/grpc:go_default_library", - "//beacon-chain/core:go_default_library", + "//beacon-chain/core/time:go_default_library", "//beacon-chain/rpc/eth/events:go_default_library", "//config/params:go_default_library", "//encoding/bytesutil:go_default_library", @@ -37,7 +37,7 @@ go_test( deps = [ "//api/gateway/apimiddleware:go_default_library", "//api/grpc:go_default_library", - "//beacon-chain/core:go_default_library", + "//beacon-chain/core/time:go_default_library", "//beacon-chain/rpc/eth/events:go_default_library", "//config/params:go_default_library", "//encoding/bytesutil:go_default_library", diff --git a/beacon-chain/rpc/apimiddleware/custom_hooks.go b/beacon-chain/rpc/apimiddleware/custom_hooks.go index a0a6e0bb03..6ff94768da 100644 --- a/beacon-chain/rpc/apimiddleware/custom_hooks.go +++ b/beacon-chain/rpc/apimiddleware/custom_hooks.go @@ -12,7 +12,7 @@ import ( "github.com/pkg/errors" types "github.com/prysmaticlabs/eth2-types" "github.com/prysmaticlabs/prysm/api/gateway/apimiddleware" - "github.com/prysmaticlabs/prysm/beacon-chain/core" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/encoding/bytesutil" ethpbv2 "github.com/prysmaticlabs/prysm/proto/eth/v2" @@ -208,7 +208,7 @@ func setInitialPublishBlockPostRequest(endpoint *apimiddleware.Endpoint, if err != nil { return false, apimiddleware.InternalServerErrorWithMessage(err, "slot is not an unsigned integer") } - if core.SlotToEpoch(types.Slot(slot)) < params.BeaconConfig().AltairForkEpoch { + if time.SlotToEpoch(types.Slot(slot)) < params.BeaconConfig().AltairForkEpoch { endpoint.PostRequest = &signedBeaconBlockContainerJson{} } else { endpoint.PostRequest = &signedBeaconBlockAltairContainerJson{} diff --git a/beacon-chain/rpc/apimiddleware/custom_hooks_test.go b/beacon-chain/rpc/apimiddleware/custom_hooks_test.go index 8006dbbaf6..2973c0e53f 100644 --- a/beacon-chain/rpc/apimiddleware/custom_hooks_test.go +++ b/beacon-chain/rpc/apimiddleware/custom_hooks_test.go @@ -12,7 +12,7 @@ import ( "github.com/gogo/protobuf/types" "github.com/prysmaticlabs/prysm/api/gateway/apimiddleware" - "github.com/prysmaticlabs/prysm/beacon-chain/core" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/encoding/bytesutil" ethpbv2 "github.com/prysmaticlabs/prysm/proto/eth/v2" @@ -384,7 +384,7 @@ func TestSetInitialPublishBlockPostRequest(t *testing.T) { assert.Equal(t, reflect.TypeOf(signedBeaconBlockContainerJson{}).Name(), reflect.Indirect(reflect.ValueOf(endpoint.PostRequest)).Type().Name()) }) t.Run("Altair", func(t *testing.T) { - slot, err := core.StartSlot(params.BeaconConfig().AltairForkEpoch) + slot, err := time.StartSlot(params.BeaconConfig().AltairForkEpoch) require.NoError(t, err) s.Message = struct{ Slot string }{Slot: strconv.FormatUint(uint64(slot), 10)} j, err := json.Marshal(s) diff --git a/beacon-chain/rpc/eth/beacon/BUILD.bazel b/beacon-chain/rpc/eth/beacon/BUILD.bazel index f1d6730f62..ab5f0e0f9c 100644 --- a/beacon-chain/rpc/eth/beacon/BUILD.bazel +++ b/beacon-chain/rpc/eth/beacon/BUILD.bazel @@ -17,13 +17,13 @@ go_library( deps = [ "//api/grpc:go_default_library", "//beacon-chain/blockchain:go_default_library", - "//beacon-chain/core:go_default_library", "//beacon-chain/core/altair:go_default_library", "//beacon-chain/core/blocks:go_default_library", "//beacon-chain/core/feed:go_default_library", "//beacon-chain/core/feed/block:go_default_library", "//beacon-chain/core/feed/operation:go_default_library", "//beacon-chain/core/helpers:go_default_library", + "//beacon-chain/core/time:go_default_library", "//beacon-chain/db:go_default_library", "//beacon-chain/db/filters:go_default_library", "//beacon-chain/operations/attestations:go_default_library", @@ -76,8 +76,8 @@ go_test( deps = [ "//api/grpc:go_default_library", "//beacon-chain/blockchain/testing:go_default_library", - "//beacon-chain/core:go_default_library", "//beacon-chain/core/signing:go_default_library", + "//beacon-chain/core/time:go_default_library", "//beacon-chain/db:go_default_library", "//beacon-chain/db/testing:go_default_library", "//beacon-chain/operations/attestations:go_default_library", diff --git a/beacon-chain/rpc/eth/beacon/pool.go b/beacon-chain/rpc/eth/beacon/pool.go index bbcdf9da0a..f5cf1d109b 100644 --- a/beacon-chain/rpc/eth/beacon/pool.go +++ b/beacon-chain/rpc/eth/beacon/pool.go @@ -4,11 +4,11 @@ import ( "context" "github.com/prysmaticlabs/prysm/api/grpc" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/blocks" "github.com/prysmaticlabs/prysm/beacon-chain/core/feed" "github.com/prysmaticlabs/prysm/beacon-chain/core/feed/operation" corehelpers "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/rpc/eth/helpers" "github.com/prysmaticlabs/prysm/config/features" "github.com/prysmaticlabs/prysm/crypto/bls" @@ -99,7 +99,7 @@ func (bs *Server) SubmitAttestations(ctx context.Context, req *ethpbv1.SubmitAtt broadcastFailed := false for _, att := range validAttestations { // Determine subnet to broadcast attestation to - wantedEpoch := core.SlotToEpoch(att.Data.Slot) + wantedEpoch := time.SlotToEpoch(att.Data.Slot) vals, err := bs.HeadFetcher.HeadValidatorsIndices(ctx, wantedEpoch) if err != nil { return nil, err diff --git a/beacon-chain/rpc/eth/beacon/pool_test.go b/beacon-chain/rpc/eth/beacon/pool_test.go index 8215b3bdf5..288859ddf5 100644 --- a/beacon-chain/rpc/eth/beacon/pool_test.go +++ b/beacon-chain/rpc/eth/beacon/pool_test.go @@ -12,8 +12,8 @@ import ( grpcutil "github.com/prysmaticlabs/prysm/api/grpc" chainMock "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing" notifiermock "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/signing" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/operations/attestations" "github.com/prysmaticlabs/prysm/beacon-chain/operations/slashings" "github.com/prysmaticlabs/prysm/beacon-chain/operations/voluntaryexits" @@ -526,7 +526,7 @@ func TestSubmitProposerSlashing_Ok(t *testing.T) { for _, h := range []*ethpbv1.SignedBeaconBlockHeader{slashing.SignedHeader_1, slashing.SignedHeader_2} { sb, err := signing.ComputeDomainAndSign( state, - core.SlotToEpoch(h.Message.Slot), + time.SlotToEpoch(h.Message.Slot), h.Message, params.BeaconConfig().DomainBeaconProposer, keys[0], @@ -766,7 +766,7 @@ func TestServer_SubmitAttestations_Ok(t *testing.T) { for _, att := range []*ethpbv1.Attestation{att1, att2} { sb, err := signing.ComputeDomainAndSign( state, - core.SlotToEpoch(att.Data.Slot), + time.SlotToEpoch(att.Data.Slot), att.Data, params.BeaconConfig().DomainBeaconAttester, keys[0], @@ -873,7 +873,7 @@ func TestServer_SubmitAttestations_ValidAttestationSubmitted(t *testing.T) { // Don't sign attInvalidSignature. sb, err := signing.ComputeDomainAndSign( state, - core.SlotToEpoch(attValid.Data.Slot), + time.SlotToEpoch(attValid.Data.Slot), attValid.Data, params.BeaconConfig().DomainBeaconAttester, keys[0], diff --git a/beacon-chain/rpc/eth/beacon/state.go b/beacon-chain/rpc/eth/beacon/state.go index dea011e05b..b893a50360 100644 --- a/beacon-chain/rpc/eth/beacon/state.go +++ b/beacon-chain/rpc/eth/beacon/state.go @@ -6,7 +6,7 @@ import ( "strconv" types "github.com/prysmaticlabs/eth2-types" - "github.com/prysmaticlabs/prysm/beacon-chain/core" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/rpc/eth/helpers" "github.com/prysmaticlabs/prysm/beacon-chain/rpc/statefetcher" "github.com/prysmaticlabs/prysm/beacon-chain/state" @@ -136,7 +136,7 @@ func (bs *Server) GetFinalityCheckpoints(ctx context.Context, req *ethpb.StateRe func (bs *Server) stateFromRequest(ctx context.Context, req *stateRequest) (state.BeaconState, error) { if req.epoch != nil { - slot, err := core.StartSlot(*req.epoch) + slot, err := time.StartSlot(*req.epoch) if err != nil { return nil, status.Errorf( codes.Internal, diff --git a/beacon-chain/rpc/eth/beacon/validator.go b/beacon-chain/rpc/eth/beacon/validator.go index 0113643f58..edbdb3fb8a 100644 --- a/beacon-chain/rpc/eth/beacon/validator.go +++ b/beacon-chain/rpc/eth/beacon/validator.go @@ -6,8 +6,8 @@ import ( "github.com/pkg/errors" types "github.com/prysmaticlabs/eth2-types" - "github.com/prysmaticlabs/prysm/beacon-chain/core" corehelpers "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/rpc/eth/helpers" "github.com/prysmaticlabs/prysm/beacon-chain/state" v1 "github.com/prysmaticlabs/prysm/beacon-chain/state/v1" @@ -87,7 +87,7 @@ func (bs *Server) ListValidators(ctx context.Context, req *ethpb.StateValidators } filterStatus[ss] = true } - epoch := core.SlotToEpoch(st.Slot()) + epoch := time.SlotToEpoch(st.Slot()) filteredVals := make([]*ethpb.ValidatorContainer, 0, len(valContainers)) for _, vc := range valContainers { readOnlyVal, err := v1.NewValidator(migration.V1ValidatorToV1Alpha1(vc.Validator)) @@ -144,7 +144,7 @@ func (bs *Server) ListCommittees(ctx context.Context, req *ethpb.StateCommittees return nil, helpers.PrepareStateFetchGRPCError(err) } - epoch := core.SlotToEpoch(st.Slot()) + epoch := time.SlotToEpoch(st.Slot()) if req.Epoch != nil { epoch = *req.Epoch } @@ -153,11 +153,11 @@ func (bs *Server) ListCommittees(ctx context.Context, req *ethpb.StateCommittees return nil, status.Errorf(codes.Internal, "Could not get active validator count: %v", err) } - startSlot, err := core.StartSlot(epoch) + startSlot, err := time.StartSlot(epoch) if err != nil { return nil, status.Errorf(codes.InvalidArgument, "Invalid epoch: %v", err) } - endSlot, err := core.EndSlot(epoch) + endSlot, err := time.EndSlot(epoch) if err != nil { return nil, status.Errorf(codes.InvalidArgument, "Invalid epoch: %v", err) } @@ -189,7 +189,7 @@ func (bs *Server) ListCommittees(ctx context.Context, req *ethpb.StateCommittees // This function returns the validator object based on the passed in ID. The validator ID could be its public key, // or its index. func valContainersByRequestIds(state state.BeaconState, validatorIds [][]byte) ([]*ethpb.ValidatorContainer, error) { - epoch := core.SlotToEpoch(state.Slot()) + epoch := time.SlotToEpoch(state.Slot()) var valContainers []*ethpb.ValidatorContainer if len(validatorIds) == 0 { allValidators := state.Validators() diff --git a/beacon-chain/rpc/eth/beacon/validator_test.go b/beacon-chain/rpc/eth/beacon/validator_test.go index 19b17a6c74..b6468066d6 100644 --- a/beacon-chain/rpc/eth/beacon/validator_test.go +++ b/beacon-chain/rpc/eth/beacon/validator_test.go @@ -8,7 +8,7 @@ import ( types "github.com/prysmaticlabs/eth2-types" chainMock "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing" - "github.com/prysmaticlabs/prysm/beacon-chain/core" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" rpchelpers "github.com/prysmaticlabs/prysm/beacon-chain/rpc/eth/helpers" "github.com/prysmaticlabs/prysm/beacon-chain/rpc/statefetcher" "github.com/prysmaticlabs/prysm/beacon-chain/rpc/testutil" @@ -511,7 +511,7 @@ func TestListCommittees(t *testing.T) { var st state.BeaconState st, _ = util.DeterministicGenesisState(t, 8192) - epoch := core.SlotToEpoch(st.Slot()) + epoch := time.SlotToEpoch(st.Slot()) t.Run("Head All Committees", func(t *testing.T) { s := Server{ @@ -527,7 +527,7 @@ func TestListCommittees(t *testing.T) { assert.Equal(t, int(params.BeaconConfig().SlotsPerEpoch)*2, len(resp.Data)) for _, datum := range resp.Data { assert.Equal(t, true, datum.Index == types.CommitteeIndex(0) || datum.Index == types.CommitteeIndex(1)) - assert.Equal(t, epoch, core.SlotToEpoch(datum.Slot)) + assert.Equal(t, epoch, time.SlotToEpoch(datum.Slot)) } }) @@ -564,7 +564,7 @@ func TestListCommittees(t *testing.T) { assert.Equal(t, 2, len(resp.Data)) index := types.CommitteeIndex(0) for _, datum := range resp.Data { - assert.Equal(t, epoch, core.SlotToEpoch(datum.Slot)) + assert.Equal(t, epoch, time.SlotToEpoch(datum.Slot)) assert.Equal(t, slot, datum.Slot) assert.Equal(t, index, datum.Index) index++ @@ -587,7 +587,7 @@ func TestListCommittees(t *testing.T) { assert.Equal(t, int(params.BeaconConfig().SlotsPerEpoch), len(resp.Data)) slot := types.Slot(0) for _, datum := range resp.Data { - assert.Equal(t, epoch, core.SlotToEpoch(datum.Slot)) + assert.Equal(t, epoch, time.SlotToEpoch(datum.Slot)) assert.Equal(t, slot, datum.Slot) assert.Equal(t, index, datum.Index) slot++ @@ -611,7 +611,7 @@ func TestListCommittees(t *testing.T) { require.NoError(t, err) assert.Equal(t, 1, len(resp.Data)) for _, datum := range resp.Data { - assert.Equal(t, epoch, core.SlotToEpoch(datum.Slot)) + assert.Equal(t, epoch, time.SlotToEpoch(datum.Slot)) assert.Equal(t, slot, datum.Slot) assert.Equal(t, index, datum.Index) } diff --git a/beacon-chain/rpc/eth/validator/BUILD.bazel b/beacon-chain/rpc/eth/validator/BUILD.bazel index 2340566fc6..f1b183deed 100644 --- a/beacon-chain/rpc/eth/validator/BUILD.bazel +++ b/beacon-chain/rpc/eth/validator/BUILD.bazel @@ -11,8 +11,8 @@ go_library( deps = [ "//beacon-chain/blockchain:go_default_library", "//beacon-chain/cache:go_default_library", - "//beacon-chain/core:go_default_library", "//beacon-chain/core/helpers:go_default_library", + "//beacon-chain/core/time:go_default_library", "//beacon-chain/core/transition:go_default_library", "//beacon-chain/operations/attestations:go_default_library", "//beacon-chain/operations/synccommittee:go_default_library", @@ -47,10 +47,10 @@ go_test( deps = [ "//beacon-chain/blockchain/testing:go_default_library", "//beacon-chain/cache:go_default_library", - "//beacon-chain/core:go_default_library", "//beacon-chain/core/altair:go_default_library", "//beacon-chain/core/blocks:go_default_library", "//beacon-chain/core/signing:go_default_library", + "//beacon-chain/core/time:go_default_library", "//beacon-chain/core/transition:go_default_library", "//beacon-chain/db/testing:go_default_library", "//beacon-chain/operations/attestations:go_default_library", diff --git a/beacon-chain/rpc/eth/validator/validator.go b/beacon-chain/rpc/eth/validator/validator.go index ccd4ee01b7..4146309764 100644 --- a/beacon-chain/rpc/eth/validator/validator.go +++ b/beacon-chain/rpc/eth/validator/validator.go @@ -11,8 +11,8 @@ import ( "github.com/pkg/errors" types "github.com/prysmaticlabs/eth2-types" "github.com/prysmaticlabs/prysm/beacon-chain/cache" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" + coreTime "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/core/transition" rpchelpers "github.com/prysmaticlabs/prysm/beacon-chain/rpc/eth/helpers" "github.com/prysmaticlabs/prysm/beacon-chain/state" @@ -41,7 +41,7 @@ func (vs *Server) GetAttesterDuties(ctx context.Context, req *ethpbv1.AttesterDu } cs := vs.TimeFetcher.CurrentSlot() - currentEpoch := core.SlotToEpoch(cs) + currentEpoch := coreTime.SlotToEpoch(cs) if req.Epoch > currentEpoch+1 { return nil, status.Errorf(codes.InvalidArgument, "Request epoch %d can not be greater than next epoch %d", req.Epoch, currentEpoch+1) } @@ -115,7 +115,7 @@ func (vs *Server) GetProposerDuties(ctx context.Context, req *ethpbv1.ProposerDu } cs := vs.TimeFetcher.CurrentSlot() - currentEpoch := core.SlotToEpoch(cs) + currentEpoch := coreTime.SlotToEpoch(cs) if req.Epoch > currentEpoch { return nil, status.Errorf(codes.InvalidArgument, "Request epoch %d can not be greater than current epoch %d", req.Epoch, currentEpoch) } @@ -175,7 +175,7 @@ func (vs *Server) GetSyncCommitteeDuties(ctx context.Context, req *ethpbv2.SyncC return nil, status.Error(codes.Unavailable, "Syncing to latest head, not ready to respond") } - slot, err := core.StartSlot(req.Epoch) + slot, err := coreTime.StartSlot(req.Epoch) if err != nil { return nil, status.Errorf(codes.Internal, "Could not get sync committee slot: %v", err) } @@ -235,7 +235,7 @@ func (vs *Server) ProduceBlockV2(ctx context.Context, req *ethpbv1.ProduceBlockR _, span := trace.StartSpan(ctx, "validator.ProduceBlockV2") defer span.End() - epoch := core.SlotToEpoch(req.Slot) + epoch := coreTime.SlotToEpoch(req.Slot) if epoch < params.BeaconConfig().AltairForkEpoch { block, err := vs.v1BeaconBlock(ctx, req) if err != nil { @@ -403,7 +403,7 @@ func (vs *Server) SubmitBeaconCommitteeSubscription(ctx context.Context, req *et } fetchValsLen := func(slot types.Slot) (uint64, error) { - wantedEpoch := core.SlotToEpoch(slot) + wantedEpoch := coreTime.SlotToEpoch(slot) vals, err := vs.HeadFetcher.HeadValidatorsIndices(ctx, wantedEpoch) if err != nil { return 0, err @@ -416,16 +416,16 @@ func (vs *Server) SubmitBeaconCommitteeSubscription(ctx context.Context, req *et if err != nil { return nil, status.Errorf(codes.Internal, "Could not retrieve head validator length: %v", err) } - currEpoch := core.SlotToEpoch(req.Data[0].Slot) + currEpoch := coreTime.SlotToEpoch(req.Data[0].Slot) for _, sub := range req.Data { // If epoch has changed, re-request active validators length - if currEpoch != core.SlotToEpoch(sub.Slot) { + if currEpoch != coreTime.SlotToEpoch(sub.Slot) { currValsLen, err = fetchValsLen(sub.Slot) if err != nil { return nil, status.Errorf(codes.Internal, "Could not retrieve head validator length: %v", err) } - currEpoch = core.SlotToEpoch(sub.Slot) + currEpoch = coreTime.SlotToEpoch(sub.Slot) } subnet := helpers.ComputeSubnetFromCommitteeAndSlot(currValsLen, sub.CommitteeIndex, sub.Slot) cache.SubnetIDs.AddAttesterSubnetID(sub.Slot, subnet) @@ -465,7 +465,7 @@ func (vs *Server) SubmitSyncCommitteeSubscription(ctx context.Context, req *ethp if err != nil { return nil, status.Errorf(codes.Internal, "Could not get head state: %v", err) } - currEpoch := core.SlotToEpoch(s.Slot()) + currEpoch := coreTime.SlotToEpoch(s.Slot()) validators := make([]state.ReadOnlyValidator, len(req.Data)) for i, sub := range req.Data { val, err := s.ValidatorAtIndexReadOnly(sub.ValidatorIndex) @@ -482,7 +482,7 @@ func (vs *Server) SubmitSyncCommitteeSubscription(ctx context.Context, req *ethp validators[i] = val } - currPeriod := core.SyncCommitteePeriod(currEpoch) + currPeriod := coreTime.SyncCommitteePeriod(currEpoch) startEpoch := types.Epoch(currPeriod * uint64(params.BeaconConfig().EpochsPerSyncCommitteePeriod)) for i, sub := range req.Data { @@ -583,7 +583,7 @@ func attestationDependentRoot(s state.BeaconState, epoch types.Epoch) ([]byte, e if epoch <= 1 { dependentRootSlot = 0 } else { - prevEpochStartSlot, err := core.StartSlot(epoch.Sub(1)) + prevEpochStartSlot, err := coreTime.StartSlot(epoch.Sub(1)) if err != nil { return nil, status.Errorf(codes.Internal, "Could not obtain epoch's start slot: %v", err) } @@ -603,7 +603,7 @@ func proposalDependentRoot(s state.BeaconState, epoch types.Epoch) ([]byte, erro if epoch == 0 { dependentRootSlot = 0 } else { - epochStartSlot, err := core.StartSlot(epoch) + epochStartSlot, err := coreTime.StartSlot(epoch) if err != nil { return nil, status.Errorf(codes.Internal, "Could not obtain epoch's start slot: %v", err) } @@ -623,12 +623,12 @@ func advanceState(ctx context.Context, s state.BeaconState, requestedEpoch, curr var epochStartSlot types.Slot var err error if requestedEpoch == currentEpoch+1 { - epochStartSlot, err = core.StartSlot(requestedEpoch.Sub(1)) + epochStartSlot, err = coreTime.StartSlot(requestedEpoch.Sub(1)) if err != nil { return nil, errors.Wrap(err, "Could not obtain epoch's start slot") } } else { - epochStartSlot, err = core.StartSlot(requestedEpoch) + epochStartSlot, err = coreTime.StartSlot(requestedEpoch) if err != nil { return nil, errors.Wrap(err, "Could not obtain epoch's start slot") } diff --git a/beacon-chain/rpc/eth/validator/validator_test.go b/beacon-chain/rpc/eth/validator/validator_test.go index 4fbf30b484..3d959290a7 100644 --- a/beacon-chain/rpc/eth/validator/validator_test.go +++ b/beacon-chain/rpc/eth/validator/validator_test.go @@ -11,10 +11,10 @@ import ( "github.com/prysmaticlabs/go-bitfield" mockChain "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing" "github.com/prysmaticlabs/prysm/beacon-chain/cache" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/altair" "github.com/prysmaticlabs/prysm/beacon-chain/core/blocks" "github.com/prysmaticlabs/prysm/beacon-chain/core/signing" + coreTime "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/core/transition" dbutil "github.com/prysmaticlabs/prysm/beacon-chain/db/testing" "github.com/prysmaticlabs/prysm/beacon-chain/operations/attestations" @@ -106,7 +106,7 @@ func TestGetAttesterDuties(t *testing.T) { t.Run("Next epoch", func(t *testing.T) { req := ðpbv1.AttesterDutiesRequest{ - Epoch: core.SlotToEpoch(bs.Slot()) + 1, + Epoch: coreTime.SlotToEpoch(bs.Slot()) + 1, Index: []types.ValidatorIndex{0}, } resp, err := vs.GetAttesterDuties(ctx, req) @@ -172,7 +172,7 @@ func TestGetAttesterDuties(t *testing.T) { }) t.Run("Epoch out of bound", func(t *testing.T) { - currentEpoch := core.SlotToEpoch(bs.Slot()) + currentEpoch := coreTime.SlotToEpoch(bs.Slot()) req := ðpbv1.AttesterDutiesRequest{ Epoch: currentEpoch + 2, Index: []types.ValidatorIndex{0}, @@ -304,7 +304,7 @@ func TestGetProposerDuties(t *testing.T) { }) t.Run("Epoch out of bound", func(t *testing.T) { - currentEpoch := core.SlotToEpoch(bs.Slot()) + currentEpoch := coreTime.SlotToEpoch(bs.Slot()) req := ðpbv1.ProposerDutiesRequest{ Epoch: currentEpoch + 1, } @@ -662,7 +662,7 @@ func TestProduceBlockV2(t *testing.T) { for i, indice := range syncCommitteeIndices { if aggregationBits.BitAt(uint64(i)) { b := p2pType.SSZBytes(parentRoot[:]) - sb, err := signing.ComputeDomainAndSign(beaconState, core.CurrentEpoch(beaconState), &b, params.BeaconConfig().DomainSyncCommittee, privKeys[indice]) + sb, err := signing.ComputeDomainAndSign(beaconState, coreTime.CurrentEpoch(beaconState), &b, params.BeaconConfig().DomainSyncCommittee, privKeys[indice]) require.NoError(t, err) sig, err := bls.SignatureFromBytes(sb) require.NoError(t, err) diff --git a/beacon-chain/rpc/prysm/v1alpha1/beacon/BUILD.bazel b/beacon-chain/rpc/prysm/v1alpha1/beacon/BUILD.bazel index 9e6307d389..7c6b582fe3 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/beacon/BUILD.bazel +++ b/beacon-chain/rpc/prysm/v1alpha1/beacon/BUILD.bazel @@ -21,7 +21,6 @@ go_library( "//async/event:go_default_library", "//beacon-chain/blockchain:go_default_library", "//beacon-chain/cache/depositcache:go_default_library", - "//beacon-chain/core:go_default_library", "//beacon-chain/core/altair:go_default_library", "//beacon-chain/core/blocks:go_default_library", "//beacon-chain/core/epoch/precompute:go_default_library", @@ -30,6 +29,7 @@ go_library( "//beacon-chain/core/feed/operation:go_default_library", "//beacon-chain/core/feed/state:go_default_library", "//beacon-chain/core/helpers:go_default_library", + "//beacon-chain/core/time:go_default_library", "//beacon-chain/core/transition:go_default_library", "//beacon-chain/core/validators:go_default_library", "//beacon-chain/db:go_default_library", @@ -81,7 +81,6 @@ go_test( shard_count = 4, deps = [ "//beacon-chain/blockchain/testing:go_default_library", - "//beacon-chain/core:go_default_library", "//beacon-chain/core/epoch/precompute:go_default_library", "//beacon-chain/core/feed:go_default_library", "//beacon-chain/core/feed/block:go_default_library", @@ -89,6 +88,7 @@ go_test( "//beacon-chain/core/feed/state:go_default_library", "//beacon-chain/core/helpers:go_default_library", "//beacon-chain/core/signing:go_default_library", + "//beacon-chain/core/time:go_default_library", "//beacon-chain/db:go_default_library", "//beacon-chain/db/testing:go_default_library", "//beacon-chain/operations/attestations:go_default_library", diff --git a/beacon-chain/rpc/prysm/v1alpha1/beacon/assignments.go b/beacon-chain/rpc/prysm/v1alpha1/beacon/assignments.go index 3b760f91ba..02dade3c2d 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/beacon/assignments.go +++ b/beacon-chain/rpc/prysm/v1alpha1/beacon/assignments.go @@ -6,8 +6,8 @@ import ( types "github.com/prysmaticlabs/eth2-types" "github.com/prysmaticlabs/prysm/api/pagination" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/cmd" "github.com/prysmaticlabs/prysm/encoding/bytesutil" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" @@ -44,7 +44,7 @@ func (bs *Server) ListValidatorAssignments( requestedEpoch = q.Epoch } - currentEpoch := core.SlotToEpoch(bs.GenesisTimeFetcher.CurrentSlot()) + currentEpoch := time.SlotToEpoch(bs.GenesisTimeFetcher.CurrentSlot()) if requestedEpoch > currentEpoch { return nil, status.Errorf( codes.InvalidArgument, @@ -54,7 +54,7 @@ func (bs *Server) ListValidatorAssignments( ) } - startSlot, err := core.StartSlot(requestedEpoch) + startSlot, err := time.StartSlot(requestedEpoch) if err != nil { return nil, err } diff --git a/beacon-chain/rpc/prysm/v1alpha1/beacon/assignments_test.go b/beacon-chain/rpc/prysm/v1alpha1/beacon/assignments_test.go index 979be9588d..9c12c44e8b 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/beacon/assignments_test.go +++ b/beacon-chain/rpc/prysm/v1alpha1/beacon/assignments_test.go @@ -9,8 +9,8 @@ import ( types "github.com/prysmaticlabs/eth2-types" mock "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" dbTest "github.com/prysmaticlabs/prysm/beacon-chain/db/testing" "github.com/prysmaticlabs/prysm/beacon-chain/state/stategen" "github.com/prysmaticlabs/prysm/cmd" @@ -37,7 +37,7 @@ func TestServer_ListAssignments_CannotRequestFutureEpoch(t *testing.T) { ctx, ðpb.ListValidatorAssignmentsRequest{ QueryFilter: ðpb.ListValidatorAssignmentsRequest_Epoch{ - Epoch: core.SlotToEpoch(bs.GenesisTimeFetcher.CurrentSlot()) + 1, + Epoch: time.SlotToEpoch(bs.GenesisTimeFetcher.CurrentSlot()) + 1, }, }, ) diff --git a/beacon-chain/rpc/prysm/v1alpha1/beacon/attestations.go b/beacon-chain/rpc/prysm/v1alpha1/beacon/attestations.go index 2a948af2ef..303190e8f4 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/beacon/attestations.go +++ b/beacon-chain/rpc/prysm/v1alpha1/beacon/attestations.go @@ -7,10 +7,10 @@ import ( "strings" "github.com/prysmaticlabs/prysm/api/pagination" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/feed" "github.com/prysmaticlabs/prysm/beacon-chain/core/feed/operation" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/db/filters" "github.com/prysmaticlabs/prysm/cmd" "github.com/prysmaticlabs/prysm/config/params" @@ -302,7 +302,7 @@ func (bs *Server) StreamIndexedAttestations( } // We use the retrieved committees for the epoch to convert all attestations // into indexed form effectively. - startSlot, err := core.StartSlot(targetEpoch) + startSlot, err := time.StartSlot(targetEpoch) if err != nil { log.Error(err) continue diff --git a/beacon-chain/rpc/prysm/v1alpha1/beacon/attestations_test.go b/beacon-chain/rpc/prysm/v1alpha1/beacon/attestations_test.go index 259aeba2f8..700a89f29d 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/beacon/attestations_test.go +++ b/beacon-chain/rpc/prysm/v1alpha1/beacon/attestations_test.go @@ -12,11 +12,11 @@ import ( types "github.com/prysmaticlabs/eth2-types" "github.com/prysmaticlabs/go-bitfield" chainMock "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/feed" "github.com/prysmaticlabs/prysm/beacon-chain/core/feed/operation" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/beacon-chain/core/signing" + coreTime "github.com/prysmaticlabs/prysm/beacon-chain/core/time" dbTest "github.com/prysmaticlabs/prysm/beacon-chain/db/testing" "github.com/prysmaticlabs/prysm/beacon-chain/operations/attestations" "github.com/prysmaticlabs/prysm/beacon-chain/state/stategen" @@ -608,7 +608,7 @@ func TestServer_ListIndexedAttestations_OldEpoch(t *testing.T) { count := params.BeaconConfig().SlotsPerEpoch atts := make([]*ethpb.Attestation, 0, count) epoch := types.Epoch(50) - startSlot, err := core.StartSlot(epoch) + startSlot, err := coreTime.StartSlot(epoch) require.NoError(t, err) for i := startSlot; i < count; i++ { diff --git a/beacon-chain/rpc/prysm/v1alpha1/beacon/blocks.go b/beacon-chain/rpc/prysm/v1alpha1/beacon/blocks.go index cda2d01780..e79d14c200 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/beacon/blocks.go +++ b/beacon-chain/rpc/prysm/v1alpha1/beacon/blocks.go @@ -6,12 +6,12 @@ import ( "github.com/prysmaticlabs/prysm/api/pagination" "github.com/prysmaticlabs/prysm/async/event" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/blocks" "github.com/prysmaticlabs/prysm/beacon-chain/core/feed" blockfeed "github.com/prysmaticlabs/prysm/beacon-chain/core/feed/block" statefeed "github.com/prysmaticlabs/prysm/beacon-chain/core/feed/state" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/db/filters" "github.com/prysmaticlabs/prysm/cmd" "github.com/prysmaticlabs/prysm/config/params" @@ -523,21 +523,21 @@ func (bs *Server) chainHeadRetrieval(ctx context.Context) (*ethpb.ChainHead, err } } - fSlot, err := core.StartSlot(finalizedCheckpoint.Epoch) + fSlot, err := time.StartSlot(finalizedCheckpoint.Epoch) if err != nil { return nil, err } - jSlot, err := core.StartSlot(justifiedCheckpoint.Epoch) + jSlot, err := time.StartSlot(justifiedCheckpoint.Epoch) if err != nil { return nil, err } - pjSlot, err := core.StartSlot(prevJustifiedCheckpoint.Epoch) + pjSlot, err := time.StartSlot(prevJustifiedCheckpoint.Epoch) if err != nil { return nil, err } return ðpb.ChainHead{ HeadSlot: headBlock.Block().Slot(), - HeadEpoch: core.SlotToEpoch(headBlock.Block().Slot()), + HeadEpoch: time.SlotToEpoch(headBlock.Block().Slot()), HeadBlockRoot: headBlockRoot[:], FinalizedSlot: fSlot, FinalizedEpoch: finalizedCheckpoint.Epoch, @@ -561,7 +561,7 @@ func (bs *Server) GetWeakSubjectivityCheckpoint(ctx context.Context, _ *emptypb. if err != nil { return nil, status.Error(codes.Internal, "Could not get weak subjectivity epoch") } - wsSlot, err := core.StartSlot(wsEpoch) + wsSlot, err := time.StartSlot(wsEpoch) if err != nil { return nil, status.Error(codes.Internal, "Could not get weak subjectivity slot") } diff --git a/beacon-chain/rpc/prysm/v1alpha1/beacon/blocks_test.go b/beacon-chain/rpc/prysm/v1alpha1/beacon/blocks_test.go index 5e54d5e03a..b96df82d8d 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/beacon/blocks_test.go +++ b/beacon-chain/rpc/prysm/v1alpha1/beacon/blocks_test.go @@ -9,11 +9,11 @@ import ( "github.com/golang/mock/gomock" types "github.com/prysmaticlabs/eth2-types" chainMock "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/feed" blockfeed "github.com/prysmaticlabs/prysm/beacon-chain/core/feed/block" statefeed "github.com/prysmaticlabs/prysm/beacon-chain/core/feed/state" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" dbTest "github.com/prysmaticlabs/prysm/beacon-chain/db/testing" "github.com/prysmaticlabs/prysm/beacon-chain/state/stategen" v1 "github.com/prysmaticlabs/prysm/beacon-chain/state/v1" @@ -447,7 +447,7 @@ func TestServer_GetChainHead(t *testing.T) { require.NoError(t, err) b := util.NewBeaconBlock() - b.Block.Slot, err = core.StartSlot(s.PreviousJustifiedCheckpoint().Epoch) + b.Block.Slot, err = time.StartSlot(s.PreviousJustifiedCheckpoint().Epoch) require.NoError(t, err) b.Block.Slot++ bs := &Server{ @@ -537,7 +537,7 @@ func TestServer_StreamChainHead_OnHeadUpdated(t *testing.T) { require.NoError(t, err) b := util.NewBeaconBlock() - b.Block.Slot, err = core.StartSlot(s.PreviousJustifiedCheckpoint().Epoch) + b.Block.Slot, err = time.StartSlot(s.PreviousJustifiedCheckpoint().Epoch) require.NoError(t, err) hRoot, err := b.Block.HashTreeRoot() @@ -562,7 +562,7 @@ func TestServer_StreamChainHead_OnHeadUpdated(t *testing.T) { mockStream.EXPECT().Send( ðpb.ChainHead{ HeadSlot: b.Block.Slot, - HeadEpoch: core.SlotToEpoch(b.Block.Slot), + HeadEpoch: time.SlotToEpoch(b.Block.Slot), HeadBlockRoot: hRoot[:], FinalizedSlot: 32, FinalizedEpoch: 1, diff --git a/beacon-chain/rpc/prysm/v1alpha1/beacon/committees.go b/beacon-chain/rpc/prysm/v1alpha1/beacon/committees.go index 629cffa498..c9c8f7ee85 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/beacon/committees.go +++ b/beacon-chain/rpc/prysm/v1alpha1/beacon/committees.go @@ -5,8 +5,8 @@ import ( "fmt" types "github.com/prysmaticlabs/eth2-types" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/encoding/bytesutil" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" @@ -26,7 +26,7 @@ func (bs *Server) ListBeaconCommittees( var requestedSlot types.Slot switch q := req.QueryFilter.(type) { case *ethpb.ListCommitteesRequest_Epoch: - startSlot, err := core.StartSlot(q.Epoch) + startSlot, err := time.StartSlot(q.Epoch) if err != nil { return nil, err } @@ -37,8 +37,8 @@ func (bs *Server) ListBeaconCommittees( requestedSlot = currentSlot } - requestedEpoch := core.SlotToEpoch(requestedSlot) - currentEpoch := core.SlotToEpoch(currentSlot) + requestedEpoch := time.SlotToEpoch(requestedSlot) + currentEpoch := time.SlotToEpoch(currentSlot) if requestedEpoch > currentEpoch { return nil, status.Errorf( codes.InvalidArgument, @@ -69,7 +69,7 @@ func (bs *Server) retrieveCommitteesForEpoch( ctx context.Context, epoch types.Epoch, ) (SlotToCommiteesMap, []types.ValidatorIndex, error) { - startSlot, err := core.StartSlot(epoch) + startSlot, err := time.StartSlot(epoch) if err != nil { return nil, nil, err } @@ -91,7 +91,7 @@ func (bs *Server) retrieveCommitteesForEpoch( return nil, nil, status.Errorf( codes.InvalidArgument, "Could not compute committees for epoch %d: %v", - core.SlotToEpoch(startSlot), + time.SlotToEpoch(startSlot), err, ) } @@ -109,7 +109,7 @@ func (bs *Server) retrieveCommitteesForRoot( if err != nil { return nil, nil, status.Error(codes.Internal, fmt.Sprintf("Could not get state: %v", err)) } - epoch := core.CurrentEpoch(requestedState) + epoch := time.CurrentEpoch(requestedState) seed, err := helpers.Seed(requestedState, epoch, params.BeaconConfig().DomainBeaconAttester) if err != nil { return nil, nil, status.Error(codes.Internal, "Could not get seed") @@ -119,7 +119,7 @@ func (bs *Server) retrieveCommitteesForRoot( return nil, nil, status.Error(codes.Internal, "Could not get active indices") } - startSlot, err := core.StartSlot(epoch) + startSlot, err := time.StartSlot(epoch) if err != nil { return nil, nil, err } diff --git a/beacon-chain/rpc/prysm/v1alpha1/beacon/committees_test.go b/beacon-chain/rpc/prysm/v1alpha1/beacon/committees_test.go index 8d0b245659..3a2a279678 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/beacon/committees_test.go +++ b/beacon-chain/rpc/prysm/v1alpha1/beacon/committees_test.go @@ -7,8 +7,8 @@ import ( "time" mock "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" + coreTime "github.com/prysmaticlabs/prysm/beacon-chain/core/time" dbTest "github.com/prysmaticlabs/prysm/beacon-chain/db/testing" "github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/beacon-chain/state/stategen" @@ -107,7 +107,7 @@ func TestServer_ListBeaconCommittees_PreviousEpoch(t *testing.T) { require.NoError(t, err) attesterSeed, err := helpers.Seed(headState, 1, params.BeaconConfig().DomainBeaconAttester) require.NoError(t, err) - startSlot, err := core.StartSlot(1) + startSlot, err := coreTime.StartSlot(1) require.NoError(t, err) wanted, err := computeCommittees(context.Background(), startSlot, activeIndices, attesterSeed) require.NoError(t, err) diff --git a/beacon-chain/rpc/prysm/v1alpha1/beacon/validators.go b/beacon-chain/rpc/prysm/v1alpha1/beacon/validators.go index ef03f6e69b..a2da55b7c1 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/beacon/validators.go +++ b/beacon-chain/rpc/prysm/v1alpha1/beacon/validators.go @@ -8,10 +8,10 @@ import ( types "github.com/prysmaticlabs/eth2-types" "github.com/prysmaticlabs/prysm/api/pagination" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/altair" "github.com/prysmaticlabs/prysm/beacon-chain/core/epoch/precompute" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" + coreTime "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/core/transition" "github.com/prysmaticlabs/prysm/beacon-chain/core/validators" "github.com/prysmaticlabs/prysm/beacon-chain/state" @@ -45,7 +45,7 @@ func (bs *Server) ListValidatorBalances( if bs.GenesisTimeFetcher == nil { return nil, status.Errorf(codes.Internal, "Nil genesis time fetcher") } - currentEpoch := core.SlotToEpoch(bs.GenesisTimeFetcher.CurrentSlot()) + currentEpoch := coreTime.SlotToEpoch(bs.GenesisTimeFetcher.CurrentSlot()) requestedEpoch := currentEpoch switch q := req.QueryFilter.(type) { case *ethpb.ListValidatorBalancesRequest_Epoch: @@ -65,7 +65,7 @@ func (bs *Server) ListValidatorBalances( res := make([]*ethpb.ValidatorBalances_Balance, 0) filtered := map[types.ValidatorIndex]bool{} // Track filtered validators to prevent duplication in the response. - startSlot, err := core.StartSlot(requestedEpoch) + startSlot, err := coreTime.StartSlot(requestedEpoch) if err != nil { return nil, err } @@ -197,7 +197,7 @@ func (bs *Server) ListValidators( req.PageSize, cmd.Get().MaxRPCPageSize) } - currentEpoch := core.SlotToEpoch(bs.GenesisTimeFetcher.CurrentSlot()) + currentEpoch := coreTime.SlotToEpoch(bs.GenesisTimeFetcher.CurrentSlot()) requestedEpoch := currentEpoch switch q := req.QueryFilter.(type) { @@ -220,7 +220,7 @@ func (bs *Server) ListValidators( var err error if requestedEpoch != currentEpoch { var s types.Slot - s, err = core.StartSlot(requestedEpoch) + s, err = coreTime.StartSlot(requestedEpoch) if err != nil { return nil, err } @@ -235,7 +235,7 @@ func (bs *Server) ListValidators( return nil, status.Error(codes.Internal, "Requested state is nil") } - s, err := core.StartSlot(requestedEpoch) + s, err := coreTime.StartSlot(requestedEpoch) if err != nil { return nil, err } @@ -392,7 +392,7 @@ func (bs *Server) GetValidator( func (bs *Server) GetValidatorActiveSetChanges( ctx context.Context, req *ethpb.GetValidatorActiveSetChangesRequest, ) (*ethpb.ActiveSetChanges, error) { - currentEpoch := core.SlotToEpoch(bs.GenesisTimeFetcher.CurrentSlot()) + currentEpoch := coreTime.SlotToEpoch(bs.GenesisTimeFetcher.CurrentSlot()) var requestedEpoch types.Epoch switch q := req.QueryFilter.(type) { @@ -412,7 +412,7 @@ func (bs *Server) GetValidatorActiveSetChanges( ) } - s, err := core.StartSlot(requestedEpoch) + s, err := coreTime.StartSlot(requestedEpoch) if err != nil { return nil, err } @@ -421,18 +421,18 @@ func (bs *Server) GetValidatorActiveSetChanges( return nil, status.Errorf(codes.Internal, "Could not get state: %v", err) } - activeValidatorCount, err := helpers.ActiveValidatorCount(ctx, requestedState, core.CurrentEpoch(requestedState)) + activeValidatorCount, err := helpers.ActiveValidatorCount(ctx, requestedState, coreTime.CurrentEpoch(requestedState)) if err != nil { return nil, status.Errorf(codes.Internal, "Could not get active validator count: %v", err) } vs := requestedState.Validators() - activatedIndices := validators.ActivatedValidatorIndices(core.CurrentEpoch(requestedState), vs) - exitedIndices, err := validators.ExitedValidatorIndices(core.CurrentEpoch(requestedState), vs, activeValidatorCount) + activatedIndices := validators.ActivatedValidatorIndices(coreTime.CurrentEpoch(requestedState), vs) + exitedIndices, err := validators.ExitedValidatorIndices(coreTime.CurrentEpoch(requestedState), vs, activeValidatorCount) if err != nil { return nil, status.Errorf(codes.Internal, "Could not determine exited validator indices: %v", err) } - slashedIndices := validators.SlashedValidatorIndices(core.CurrentEpoch(requestedState), vs) - ejectedIndices, err := validators.EjectedValidatorIndices(core.CurrentEpoch(requestedState), vs, activeValidatorCount) + slashedIndices := validators.SlashedValidatorIndices(coreTime.CurrentEpoch(requestedState), vs) + ejectedIndices, err := validators.EjectedValidatorIndices(coreTime.CurrentEpoch(requestedState), vs, activeValidatorCount) if err != nil { return nil, status.Errorf(codes.Internal, "Could not determine ejected validator indices: %v", err) } @@ -478,7 +478,7 @@ func (bs *Server) GetValidatorParticipation( ctx context.Context, req *ethpb.GetValidatorParticipationRequest, ) (*ethpb.ValidatorParticipationResponse, error) { currentSlot := bs.GenesisTimeFetcher.CurrentSlot() - currentEpoch := core.SlotToEpoch(currentSlot) + currentEpoch := coreTime.SlotToEpoch(currentSlot) var requestedEpoch types.Epoch switch q := req.QueryFilter.(type) { @@ -500,7 +500,7 @@ func (bs *Server) GetValidatorParticipation( } // Get current slot state for current epoch attestations. - startSlot, err := core.StartSlot(requestedEpoch) + startSlot, err := coreTime.StartSlot(requestedEpoch) if err != nil { return nil, err } @@ -603,7 +603,7 @@ func (bs *Server) GetValidatorQueue( }) // Only activate just enough validators according to the activation churn limit. - activeValidatorCount, err := helpers.ActiveValidatorCount(ctx, headState, core.CurrentEpoch(headState)) + activeValidatorCount, err := helpers.ActiveValidatorCount(ctx, headState, coreTime.CurrentEpoch(headState)) if err != nil { return nil, status.Errorf(codes.Internal, "Could not get active validator count: %v", err) } @@ -636,7 +636,7 @@ func (bs *Server) GetValidatorQueue( for _, valIdx := range awaitingExit { val := vals[valIdx] // Ensure the validator has not yet exited before adding its index to the exit queue. - if val.WithdrawableEpoch < minEpoch && !validatorHasExited(val, core.CurrentEpoch(headState)) { + if val.WithdrawableEpoch < minEpoch && !validatorHasExited(val, coreTime.CurrentEpoch(headState)) { exitQueueIndices = append(exitQueueIndices, valIdx) } } @@ -751,7 +751,7 @@ func (bs *Server) GetValidatorPerformance( return validatorIndices[i] < validatorIndices[j] }) - currentEpoch := core.CurrentEpoch(headState) + currentEpoch := coreTime.CurrentEpoch(headState) responseCap = len(validatorIndices) pubKeys := make([][]byte, 0, responseCap) beforeTransitionBalances := make([]uint64, 0, responseCap) @@ -819,7 +819,7 @@ func (bs *Server) GetIndividualVotes( ctx context.Context, req *ethpb.IndividualVotesRequest, ) (*ethpb.IndividualVotesRespond, error) { - currentEpoch := core.SlotToEpoch(bs.GenesisTimeFetcher.CurrentSlot()) + currentEpoch := coreTime.SlotToEpoch(bs.GenesisTimeFetcher.CurrentSlot()) if req.Epoch > currentEpoch { return nil, status.Errorf( codes.InvalidArgument, @@ -829,7 +829,7 @@ func (bs *Server) GetIndividualVotes( ) } - s, err := core.StartSlot(req.Epoch) + s, err := coreTime.StartSlot(req.Epoch) if err != nil { return nil, err } diff --git a/beacon-chain/rpc/prysm/v1alpha1/beacon/validators_stream.go b/beacon-chain/rpc/prysm/v1alpha1/beacon/validators_stream.go index 37c63203bf..edba045ad6 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/beacon/validators_stream.go +++ b/beacon-chain/rpc/prysm/v1alpha1/beacon/validators_stream.go @@ -17,10 +17,10 @@ import ( "github.com/prysmaticlabs/prysm/async/event" "github.com/prysmaticlabs/prysm/beacon-chain/blockchain" "github.com/prysmaticlabs/prysm/beacon-chain/cache/depositcache" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/feed" statefeed "github.com/prysmaticlabs/prysm/beacon-chain/core/feed/state" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" + coreTime "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/db" "github.com/prysmaticlabs/prysm/beacon-chain/powchain" "github.com/prysmaticlabs/prysm/beacon-chain/state" @@ -319,7 +319,7 @@ func (is *infostream) generateValidatorInfo( return is.generatePendingValidatorInfo(info) } // Status and progression timestamp - info.Status, info.TransitionTimestamp = is.calculateStatusAndTransition(validator, core.CurrentEpoch(headState)) + info.Status, info.TransitionTimestamp = is.calculateStatusAndTransition(validator, coreTime.CurrentEpoch(headState)) // Balance info.Balance = headState.Balances()[info.Index] diff --git a/beacon-chain/rpc/prysm/v1alpha1/beacon/validators_test.go b/beacon-chain/rpc/prysm/v1alpha1/beacon/validators_test.go index 26c3909dce..b0da0aaae0 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/beacon/validators_test.go +++ b/beacon-chain/rpc/prysm/v1alpha1/beacon/validators_test.go @@ -12,9 +12,9 @@ import ( types "github.com/prysmaticlabs/eth2-types" "github.com/prysmaticlabs/go-bitfield" mock "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/epoch/precompute" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" + coreTime "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/db" dbTest "github.com/prysmaticlabs/prysm/beacon-chain/db/testing" "github.com/prysmaticlabs/prysm/beacon-chain/state" @@ -57,7 +57,7 @@ func TestServer_GetValidatorActiveSetChanges_CannotRequestFutureEpoch(t *testing ctx, ðpb.GetValidatorActiveSetChangesRequest{ QueryFilter: ðpb.GetValidatorActiveSetChangesRequest_Epoch{ - Epoch: core.SlotToEpoch(bs.GenesisTimeFetcher.CurrentSlot()) + 1, + Epoch: coreTime.SlotToEpoch(bs.GenesisTimeFetcher.CurrentSlot()) + 1, }, }, ) @@ -84,7 +84,7 @@ func TestServer_ListValidatorBalances_CannotRequestFutureEpoch(t *testing.T) { ctx, ðpb.ListValidatorBalancesRequest{ QueryFilter: ðpb.ListValidatorBalancesRequest_Epoch{ - Epoch: core.SlotToEpoch(bs.GenesisTimeFetcher.CurrentSlot()) + 1, + Epoch: coreTime.SlotToEpoch(bs.GenesisTimeFetcher.CurrentSlot()) + 1, }, }, ) @@ -1347,7 +1347,7 @@ func TestServer_GetValidatorQueue_PendingActivation(t *testing.T) { pubKey(2), pubKey(3), } - activeValidatorCount, err := helpers.ActiveValidatorCount(context.Background(), headState, core.CurrentEpoch(headState)) + activeValidatorCount, err := helpers.ActiveValidatorCount(context.Background(), headState, coreTime.CurrentEpoch(headState)) require.NoError(t, err) wantChurn, err := helpers.ValidatorChurnLimit(activeValidatorCount) require.NoError(t, err) @@ -1389,7 +1389,7 @@ func TestServer_GetValidatorQueue_ExitedValidatorLeavesQueue(t *testing.T) { wanted := [][]byte{ bytesutil.PadTo([]byte("2"), 48), } - activeValidatorCount, err := helpers.ActiveValidatorCount(context.Background(), headState, core.CurrentEpoch(headState)) + activeValidatorCount, err := helpers.ActiveValidatorCount(context.Background(), headState, coreTime.CurrentEpoch(headState)) require.NoError(t, err) wantChurn, err := helpers.ValidatorChurnLimit(activeValidatorCount) require.NoError(t, err) @@ -1449,7 +1449,7 @@ func TestServer_GetValidatorQueue_PendingExit(t *testing.T) { pubKey(2), pubKey(3), } - activeValidatorCount, err := helpers.ActiveValidatorCount(context.Background(), headState, core.CurrentEpoch(headState)) + activeValidatorCount, err := helpers.ActiveValidatorCount(context.Background(), headState, coreTime.CurrentEpoch(headState)) require.NoError(t, err) wantChurn, err := helpers.ValidatorChurnLimit(activeValidatorCount) require.NoError(t, err) @@ -1478,7 +1478,7 @@ func TestServer_GetValidatorParticipation_CannotRequestFutureEpoch(t *testing.T) ctx, ðpb.GetValidatorParticipationRequest{ QueryFilter: ðpb.GetValidatorParticipationRequest_Epoch{ - Epoch: core.SlotToEpoch(bs.GenesisTimeFetcher.CurrentSlot()) + 1, + Epoch: coreTime.SlotToEpoch(bs.GenesisTimeFetcher.CurrentSlot()) + 1, }, }, ) @@ -2094,7 +2094,7 @@ func setupValidators(t testing.TB, _ db.Database, count int) ([]*ethpb.Validator func TestServer_GetIndividualVotes_RequestFutureSlot(t *testing.T) { ds := &Server{GenesisTimeFetcher: &mock.ChainService{}} req := ðpb.IndividualVotesRequest{ - Epoch: core.SlotToEpoch(ds.GenesisTimeFetcher.CurrentSlot()) + 1, + Epoch: coreTime.SlotToEpoch(ds.GenesisTimeFetcher.CurrentSlot()) + 1, } wanted := errNoEpochInfoError _, err := ds.GetIndividualVotes(context.Background(), req) diff --git a/beacon-chain/rpc/prysm/v1alpha1/validator/BUILD.bazel b/beacon-chain/rpc/prysm/v1alpha1/validator/BUILD.bazel index 124a3f466f..738cfc9d60 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/validator/BUILD.bazel +++ b/beacon-chain/rpc/prysm/v1alpha1/validator/BUILD.bazel @@ -23,7 +23,6 @@ go_library( "//beacon-chain/blockchain:go_default_library", "//beacon-chain/cache:go_default_library", "//beacon-chain/cache/depositcache:go_default_library", - "//beacon-chain/core:go_default_library", "//beacon-chain/core/altair:go_default_library", "//beacon-chain/core/blocks:go_default_library", "//beacon-chain/core/feed:go_default_library", @@ -32,6 +31,7 @@ go_library( "//beacon-chain/core/feed/state:go_default_library", "//beacon-chain/core/helpers:go_default_library", "//beacon-chain/core/signing:go_default_library", + "//beacon-chain/core/time:go_default_library", "//beacon-chain/core/transition:go_default_library", "//beacon-chain/core/transition/interop:go_default_library", "//beacon-chain/operations/attestations:go_default_library", @@ -100,7 +100,6 @@ go_test( "//beacon-chain/blockchain/testing:go_default_library", "//beacon-chain/cache:go_default_library", "//beacon-chain/cache/depositcache:go_default_library", - "//beacon-chain/core:go_default_library", "//beacon-chain/core/altair:go_default_library", "//beacon-chain/core/blocks:go_default_library", "//beacon-chain/core/feed:go_default_library", @@ -109,6 +108,7 @@ go_test( "//beacon-chain/core/feed/state:go_default_library", "//beacon-chain/core/helpers:go_default_library", "//beacon-chain/core/signing:go_default_library", + "//beacon-chain/core/time:go_default_library", "//beacon-chain/core/transition:go_default_library", "//beacon-chain/db/testing:go_default_library", "//beacon-chain/operations/attestations:go_default_library", diff --git a/beacon-chain/rpc/prysm/v1alpha1/validator/aggregator.go b/beacon-chain/rpc/prysm/v1alpha1/validator/aggregator.go index 0d63291c38..5b49571c08 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/validator/aggregator.go +++ b/beacon-chain/rpc/prysm/v1alpha1/validator/aggregator.go @@ -4,8 +4,8 @@ import ( "bytes" "context" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/encoding/bytesutil" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" @@ -37,7 +37,7 @@ func (vs *Server) SubmitAggregateSelectionProof(ctx context.Context, req *ethpb. return nil, status.Error(codes.Internal, "Could not locate validator index in DB") } - epoch := core.SlotToEpoch(req.Slot) + epoch := time.SlotToEpoch(req.Slot) activeValidatorIndices, err := helpers.ActiveValidatorIndices(ctx, st, epoch) if err != nil { return nil, status.Errorf(codes.Internal, "Could not get validators: %v", err) diff --git a/beacon-chain/rpc/prysm/v1alpha1/validator/assignments.go b/beacon-chain/rpc/prysm/v1alpha1/validator/assignments.go index 1dcc636ee8..4794b7fe46 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/validator/assignments.go +++ b/beacon-chain/rpc/prysm/v1alpha1/validator/assignments.go @@ -7,10 +7,10 @@ import ( types "github.com/prysmaticlabs/eth2-types" "github.com/prysmaticlabs/prysm/beacon-chain/cache" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/feed" statefeed "github.com/prysmaticlabs/prysm/beacon-chain/core/feed/state" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" + coreTime "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/core/transition" beaconState "github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/config/params" @@ -108,7 +108,7 @@ func (vs *Server) StreamDuties(req *ethpb.DutiesRequest, stream ethpb.BeaconNode // Compute the validator duties from the head state's corresponding epoch // for validators public key / indices requested. func (vs *Server) duties(ctx context.Context, req *ethpb.DutiesRequest) (*ethpb.DutiesResponse, error) { - currentEpoch := core.SlotToEpoch(vs.TimeFetcher.CurrentSlot()) + currentEpoch := coreTime.SlotToEpoch(vs.TimeFetcher.CurrentSlot()) if req.Epoch > currentEpoch+1 { return nil, status.Errorf(codes.Unavailable, "Request epoch %d can not be greater than next epoch %d", req.Epoch, currentEpoch+1) } @@ -119,7 +119,7 @@ func (vs *Server) duties(ctx context.Context, req *ethpb.DutiesRequest) (*ethpb. } // Advance state with empty transitions up to the requested epoch start slot. - epochStartSlot, err := core.StartSlot(req.Epoch) + epochStartSlot, err := coreTime.StartSlot(req.Epoch) if err != nil { return nil, err } @@ -183,7 +183,7 @@ func (vs *Server) duties(ctx context.Context, req *ethpb.DutiesRequest) (*ethpb. } // Are the validators in current or next epoch sync committee. - if core.AltairCompatible(s, req.Epoch) { + if coreTime.AltairCompatible(s, req.Epoch) { assignment.IsSyncCommittee, err = helpers.IsCurrentPeriodSyncCommittee(s, idx) if err != nil { return nil, status.Errorf(codes.Internal, "Could not determine current epoch sync committee: %v", err) @@ -198,9 +198,9 @@ func (vs *Server) duties(ctx context.Context, req *ethpb.DutiesRequest) (*ethpb. // Next epoch sync committee duty is assigned with next period sync committee only during // sync period epoch boundary (ie. EPOCHS_PER_SYNC_COMMITTEE_PERIOD - 1). Else wise // next epoch sync committee duty is the same as current epoch. - nextSlotToEpoch := core.SlotToEpoch(s.Slot() + 1) - currentEpoch := core.CurrentEpoch(s) - if core.SyncCommitteePeriod(nextSlotToEpoch) == core.SyncCommitteePeriod(currentEpoch)+1 { + nextSlotToEpoch := coreTime.SlotToEpoch(s.Slot() + 1) + currentEpoch := coreTime.CurrentEpoch(s) + if coreTime.SyncCommitteePeriod(nextSlotToEpoch) == coreTime.SyncCommitteePeriod(currentEpoch)+1 { nextAssignment.IsSyncCommittee, err = helpers.IsNextPeriodSyncCommittee(s, idx) if err != nil { return nil, status.Errorf(codes.Internal, "Could not determine next epoch sync committee: %v", err) @@ -258,7 +258,7 @@ func registerSyncSubnetCurrentPeriod(s beaconState.BeaconState, epoch types.Epoc if err != nil { return err } - syncCommPeriod := core.SyncCommitteePeriod(epoch) + syncCommPeriod := coreTime.SyncCommitteePeriod(epoch) registerSyncSubnet(epoch, syncCommPeriod, pubKey, committee, status) return nil } @@ -268,7 +268,7 @@ func registerSyncSubnetNextPeriod(s beaconState.BeaconState, epoch types.Epoch, if err != nil { return err } - syncCommPeriod := core.SyncCommitteePeriod(epoch) + syncCommPeriod := coreTime.SyncCommitteePeriod(epoch) registerSyncSubnet(epoch, syncCommPeriod+1, pubKey, committee, status) return nil } @@ -281,7 +281,7 @@ func registerSyncSubnet(currEpoch types.Epoch, syncPeriod uint64, pubkey []byte, return } startEpoch := types.Epoch(syncPeriod * uint64(params.BeaconConfig().EpochsPerSyncCommitteePeriod)) - currPeriod := core.SyncCommitteePeriod(currEpoch) + currPeriod := coreTime.SyncCommitteePeriod(currEpoch) endEpoch := startEpoch + params.BeaconConfig().EpochsPerSyncCommitteePeriod _, _, ok, expTime := cache.SyncSubnetIDs.GetSyncCommitteeSubnets(pubkey, startEpoch) if ok && expTime.After(prysmTime.Now()) { diff --git a/beacon-chain/rpc/prysm/v1alpha1/validator/attester.go b/beacon-chain/rpc/prysm/v1alpha1/validator/attester.go index a79a4549ae..b746ffe240 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/validator/attester.go +++ b/beacon-chain/rpc/prysm/v1alpha1/validator/attester.go @@ -7,10 +7,10 @@ import ( types "github.com/prysmaticlabs/eth2-types" "github.com/prysmaticlabs/prysm/beacon-chain/cache" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/feed" "github.com/prysmaticlabs/prysm/beacon-chain/core/feed/operation" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/core/transition" "github.com/prysmaticlabs/prysm/config/features" "github.com/prysmaticlabs/prysm/config/params" @@ -95,7 +95,7 @@ func (vs *Server) GetAttestationData(ctx context.Context, req *ethpb.Attestation return nil, status.Error(codes.Internal, "Could not lookup parent state from head.") } - if core.CurrentEpoch(headState) < core.SlotToEpoch(req.Slot) { + if time.CurrentEpoch(headState) < time.SlotToEpoch(req.Slot) { if features.Get().EnableNextSlotStateCache { headState, err = transition.ProcessSlotsUsingNextSlotCache(ctx, headState, headRoot, req.Slot) if err != nil { @@ -109,8 +109,8 @@ func (vs *Server) GetAttestationData(ctx context.Context, req *ethpb.Attestation } } - targetEpoch := core.CurrentEpoch(headState) - epochStartSlot, err := core.StartSlot(targetEpoch) + targetEpoch := time.CurrentEpoch(headState) + epochStartSlot, err := time.StartSlot(targetEpoch) if err != nil { return nil, err } @@ -169,7 +169,7 @@ func (vs *Server) ProposeAttestation(ctx context.Context, att *ethpb.Attestation }) // Determine subnet to broadcast attestation to - wantedEpoch := core.SlotToEpoch(att.Data.Slot) + wantedEpoch := time.SlotToEpoch(att.Data.Slot) vals, err := vs.HeadFetcher.HeadValidatorsIndices(ctx, wantedEpoch) if err != nil { return nil, err @@ -208,7 +208,7 @@ func (vs *Server) SubscribeCommitteeSubnets(ctx context.Context, req *ethpb.Comm } fetchValsLen := func(slot types.Slot) (uint64, error) { - wantedEpoch := core.SlotToEpoch(slot) + wantedEpoch := time.SlotToEpoch(slot) vals, err := vs.HeadFetcher.HeadValidatorsIndices(ctx, wantedEpoch) if err != nil { return 0, err @@ -222,16 +222,16 @@ func (vs *Server) SubscribeCommitteeSubnets(ctx context.Context, req *ethpb.Comm if err != nil { return nil, status.Errorf(codes.Internal, "Could not retrieve head validator length: %v", err) } - currEpoch := core.SlotToEpoch(req.Slots[0]) + currEpoch := time.SlotToEpoch(req.Slots[0]) for i := 0; i < len(req.Slots); i++ { // If epoch has changed, re-request active validators length - if currEpoch != core.SlotToEpoch(req.Slots[i]) { + if currEpoch != time.SlotToEpoch(req.Slots[i]) { currValsLen, err = fetchValsLen(req.Slots[i]) if err != nil { return nil, status.Errorf(codes.Internal, "Could not retrieve head validator length: %v", err) } - currEpoch = core.SlotToEpoch(req.Slots[i]) + currEpoch = time.SlotToEpoch(req.Slots[i]) } subnet := helpers.ComputeSubnetFromCommitteeAndSlot(currValsLen, req.CommitteeIds[i], req.Slots[i]) cache.SubnetIDs.AddAttesterSubnetID(req.Slots[i], subnet) diff --git a/beacon-chain/rpc/prysm/v1alpha1/validator/attester_test.go b/beacon-chain/rpc/prysm/v1alpha1/validator/attester_test.go index e6f4d127ef..edda22a818 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/validator/attester_test.go +++ b/beacon-chain/rpc/prysm/v1alpha1/validator/attester_test.go @@ -10,7 +10,7 @@ import ( types "github.com/prysmaticlabs/eth2-types" mock "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing" "github.com/prysmaticlabs/prysm/beacon-chain/cache" - "github.com/prysmaticlabs/prysm/beacon-chain/core" + coreTime "github.com/prysmaticlabs/prysm/beacon-chain/core/time" dbutil "github.com/prysmaticlabs/prysm/beacon-chain/db/testing" "github.com/prysmaticlabs/prysm/beacon-chain/operations/attestations" mockp2p "github.com/prysmaticlabs/prysm/beacon-chain/p2p/testing" @@ -189,10 +189,10 @@ func TestAttestationDataAtSlot_HandlesFarAwayJustifiedEpoch(t *testing.T) { block.Block.Slot = 10000 epochBoundaryBlock := util.NewBeaconBlock() var err error - epochBoundaryBlock.Block.Slot, err = core.StartSlot(core.SlotToEpoch(10000)) + epochBoundaryBlock.Block.Slot, err = coreTime.StartSlot(coreTime.SlotToEpoch(10000)) require.NoError(t, err) justifiedBlock := util.NewBeaconBlock() - justifiedBlock.Block.Slot, err = core.StartSlot(core.SlotToEpoch(1500)) + justifiedBlock.Block.Slot, err = coreTime.StartSlot(coreTime.SlotToEpoch(1500)) require.NoError(t, err) justifiedBlock.Block.Slot -= 2 // Imagine two skip block blockRoot, err := block.Block.HashTreeRoot() @@ -207,7 +207,7 @@ func TestAttestationDataAtSlot_HandlesFarAwayJustifiedEpoch(t *testing.T) { require.NoError(t, err) require.NoError(t, beaconState.SetSlot(slot)) err = beaconState.SetCurrentJustifiedCheckpoint(ðpb.Checkpoint{ - Epoch: core.SlotToEpoch(1500), + Epoch: coreTime.SlotToEpoch(1500), Root: justifiedBlockRoot[:], }) require.NoError(t, err) @@ -243,7 +243,7 @@ func TestAttestationDataAtSlot_HandlesFarAwayJustifiedEpoch(t *testing.T) { Slot: req.Slot, BeaconBlockRoot: blockRoot[:], Source: ðpb.Checkpoint{ - Epoch: core.SlotToEpoch(1500), + Epoch: coreTime.SlotToEpoch(1500), Root: justifiedBlockRoot[:], }, Target: ðpb.Checkpoint{ diff --git a/beacon-chain/rpc/prysm/v1alpha1/validator/proposer.go b/beacon-chain/rpc/prysm/v1alpha1/validator/proposer.go index 4ef09e76f3..53bcec9030 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/validator/proposer.go +++ b/beacon-chain/rpc/prysm/v1alpha1/validator/proposer.go @@ -11,11 +11,11 @@ import ( fastssz "github.com/ferranbt/fastssz" "github.com/pkg/errors" types "github.com/prysmaticlabs/eth2-types" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/blocks" "github.com/prysmaticlabs/prysm/beacon-chain/core/feed" blockfeed "github.com/prysmaticlabs/prysm/beacon-chain/core/feed/block" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" + coreTime "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/core/transition" "github.com/prysmaticlabs/prysm/beacon-chain/core/transition/interop" "github.com/prysmaticlabs/prysm/beacon-chain/state" @@ -68,7 +68,7 @@ func (vs *Server) GetBeaconBlock(ctx context.Context, req *ethpb.BlockRequest) ( ctx, span := trace.StartSpan(ctx, "ProposerServer.GetBeaconBlock") defer span.End() span.AddAttributes(trace.Int64Attribute("slot", int64(req.Slot))) - if core.SlotToEpoch(req.Slot) < params.BeaconConfig().AltairForkEpoch { + if coreTime.SlotToEpoch(req.Slot) < params.BeaconConfig().AltairForkEpoch { blk, err := vs.getPhase0BeaconBlock(ctx, req) if err != nil { return nil, status.Errorf(codes.Internal, "Could not fetch phase0 beacon block: %v", err) @@ -460,7 +460,7 @@ func (vs *Server) eth1DataMajorityVote(ctx context.Context, beaconState state.Be func (vs *Server) slotStartTime(slot types.Slot) uint64 { startTime, _ := vs.Eth1InfoFetcher.Eth2GenesisPowchainInfo() - return core.VotingPeriodStartTime(startTime, slot) + return coreTime.VotingPeriodStartTime(startTime, slot) } func (vs *Server) mockETH1DataVote(ctx context.Context, slot types.Slot) (*ethpb.Eth1Data, error) { @@ -483,7 +483,7 @@ func (vs *Server) mockETH1DataVote(ctx context.Context, slot types.Slot) (*ethpb return nil, err } var enc []byte - enc = fastssz.MarshalUint64(enc, uint64(core.SlotToEpoch(slot))+uint64(slotInVotingPeriod)) + enc = fastssz.MarshalUint64(enc, uint64(coreTime.SlotToEpoch(slot))+uint64(slotInVotingPeriod)) depRoot := hash.Hash(enc) blockHash := hash.Hash(depRoot[:]) return ðpb.Eth1Data{ diff --git a/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_test.go b/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_test.go index 7a83634cff..cfe2170efa 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_test.go +++ b/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_test.go @@ -9,10 +9,10 @@ import ( "github.com/prysmaticlabs/go-bitfield" mock "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing" "github.com/prysmaticlabs/prysm/beacon-chain/cache/depositcache" - "github.com/prysmaticlabs/prysm/beacon-chain/core" b "github.com/prysmaticlabs/prysm/beacon-chain/core/blocks" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/beacon-chain/core/signing" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" dbutil "github.com/prysmaticlabs/prysm/beacon-chain/db/testing" "github.com/prysmaticlabs/prysm/beacon-chain/operations/attestations" "github.com/prysmaticlabs/prysm/beacon-chain/operations/slashings" @@ -316,7 +316,7 @@ func TestProposer_ComputeStateRoot_OK(t *testing.T) { require.NoError(t, err) require.NoError(t, beaconState.SetSlot(beaconState.Slot()-1)) req.Block.Body.RandaoReveal = randaoReveal - currentEpoch := core.CurrentEpoch(beaconState) + currentEpoch := time.CurrentEpoch(beaconState) req.Signature, err = signing.ComputeDomainAndSign(beaconState, currentEpoch, req.Block, params.BeaconConfig().DomainBeaconProposer, privKeys[proposerIdx]) require.NoError(t, err) @@ -2132,7 +2132,7 @@ func TestProposer_GetBeaconBlock_PostForkEpoch(t *testing.T) { require.NoError(t, db.SaveState(ctx, beaconState, parentRoot), "Could not save genesis state") require.NoError(t, db.SaveHeadBlockRoot(ctx, parentRoot), "Could not save genesis state") - altairSlot, err := core.StartSlot(params.BeaconConfig().AltairForkEpoch) + altairSlot, err := time.StartSlot(params.BeaconConfig().AltairForkEpoch) require.NoError(t, err) genAltair := ðpb.SignedBeaconBlockAltair{ diff --git a/beacon-chain/rpc/prysm/v1alpha1/validator/status.go b/beacon-chain/rpc/prysm/v1alpha1/validator/status.go index cc30870585..6c4b3c7144 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/validator/status.go +++ b/beacon-chain/rpc/prysm/v1alpha1/validator/status.go @@ -5,9 +5,9 @@ import ( "errors" types "github.com/prysmaticlabs/eth2-types" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/beacon-chain/core/signing" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/contracts/deposit" @@ -106,7 +106,7 @@ func (vs *Server) CheckDoppelGanger(ctx context.Context, req *ethpb.DoppelGanger } // We walk back from the current head state to the state at the beginning of the previous 2 epochs. // Where S_i , i := 0,1,2. i = 0 would signify the current head state in this epoch. - currEpoch := core.SlotToEpoch(headState.Slot()) + currEpoch := time.SlotToEpoch(headState.Slot()) previousEpoch, err := currEpoch.SafeSub(1) if err != nil { previousEpoch = currEpoch @@ -304,7 +304,7 @@ func (vs *Server) validatorStatus( if err != nil { return resp, idx } - if helpers.IsActiveValidatorUsingTrie(val, core.CurrentEpoch(headState)) { + if helpers.IsActiveValidatorUsingTrie(val, time.CurrentEpoch(headState)) { lastActivatedvalidatorIndex = types.ValidatorIndex(j) break } @@ -335,7 +335,7 @@ func assignmentStatus(beaconState state.ReadOnlyBeaconState, validatorIndex type if err != nil { return ethpb.ValidatorStatus_UNKNOWN_STATUS } - currentEpoch := core.CurrentEpoch(beaconState) + currentEpoch := time.CurrentEpoch(beaconState) farFutureEpoch := params.BeaconConfig().FarFutureEpoch validatorBalance := validator.EffectiveBalance() diff --git a/beacon-chain/rpc/prysm/v1alpha1/validator/status_test.go b/beacon-chain/rpc/prysm/v1alpha1/validator/status_test.go index 651422d2a0..e2cc72e3d0 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/validator/status_test.go +++ b/beacon-chain/rpc/prysm/v1alpha1/validator/status_test.go @@ -9,8 +9,8 @@ import ( types "github.com/prysmaticlabs/eth2-types" mockChain "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing" "github.com/prysmaticlabs/prysm/beacon-chain/cache/depositcache" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" + coreTime "github.com/prysmaticlabs/prysm/beacon-chain/core/time" mockPOW "github.com/prysmaticlabs/prysm/beacon-chain/powchain/testing" "github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/beacon-chain/state/stategen" @@ -300,7 +300,7 @@ func TestValidatorStatus_Exiting(t *testing.T) { // Initiated exit because validator exit epoch and withdrawable epoch are not FAR_FUTURE_EPOCH slot := types.Slot(10000) - epoch := core.SlotToEpoch(slot) + epoch := coreTime.SlotToEpoch(slot) exitEpoch := helpers.ActivationExitEpoch(epoch) withdrawableEpoch := exitEpoch + params.BeaconConfig().MinValidatorWithdrawabilityDelay block := util.NewBeaconBlock() @@ -360,7 +360,7 @@ func TestValidatorStatus_Slashing(t *testing.T) { // Exit slashed because slashed is true, exit epoch is =< current epoch and withdrawable epoch > epoch . slot := types.Slot(10000) - epoch := core.SlotToEpoch(slot) + epoch := coreTime.SlotToEpoch(slot) block := util.NewBeaconBlock() genesisRoot, err := block.Block.HashTreeRoot() require.NoError(t, err, "Could not get signing root") @@ -417,7 +417,7 @@ func TestValidatorStatus_Exited(t *testing.T) { // Exit because only exit epoch is =< current epoch. slot := types.Slot(10000) - epoch := core.SlotToEpoch(slot) + epoch := coreTime.SlotToEpoch(slot) block := util.NewBeaconBlock() genesisRoot, err := block.Block.HashTreeRoot() require.NoError(t, err, "Could not get signing root") @@ -790,7 +790,7 @@ func TestMultipleValidatorStatus_Pubkeys(t *testing.T) { func TestMultipleValidatorStatus_Indices(t *testing.T) { slot := types.Slot(10000) - epoch := core.SlotToEpoch(slot) + epoch := coreTime.SlotToEpoch(slot) pubKeys := [][]byte{pubKey(1), pubKey(2), pubKey(3), pubKey(4), pubKey(5), pubKey(6), pubKey(7)} beaconState := ðpb.BeaconState{ Slot: 4000, diff --git a/beacon-chain/slasher/BUILD.bazel b/beacon-chain/slasher/BUILD.bazel index 3c3d30141a..8808b79e98 100644 --- a/beacon-chain/slasher/BUILD.bazel +++ b/beacon-chain/slasher/BUILD.bazel @@ -26,10 +26,10 @@ go_library( deps = [ "//async/event:go_default_library", "//beacon-chain/blockchain:go_default_library", - "//beacon-chain/core:go_default_library", "//beacon-chain/core/blocks:go_default_library", "//beacon-chain/core/feed:go_default_library", "//beacon-chain/core/feed/state:go_default_library", + "//beacon-chain/core/time:go_default_library", "//beacon-chain/db:go_default_library", "//beacon-chain/operations/slashings:go_default_library", "//beacon-chain/slasher/types:go_default_library", @@ -71,10 +71,10 @@ go_test( deps = [ "//async/event:go_default_library", "//beacon-chain/blockchain/testing:go_default_library", - "//beacon-chain/core:go_default_library", "//beacon-chain/core/feed:go_default_library", "//beacon-chain/core/feed/state:go_default_library", "//beacon-chain/core/signing:go_default_library", + "//beacon-chain/core/time:go_default_library", "//beacon-chain/db/testing:go_default_library", "//beacon-chain/operations/slashings:go_default_library", "//beacon-chain/slasher/types:go_default_library", diff --git a/beacon-chain/slasher/detect_attestations_test.go b/beacon-chain/slasher/detect_attestations_test.go index 01b0f584bb..a07771bf64 100644 --- a/beacon-chain/slasher/detect_attestations_test.go +++ b/beacon-chain/slasher/detect_attestations_test.go @@ -9,8 +9,8 @@ import ( types "github.com/prysmaticlabs/eth2-types" mock "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/signing" + coreTime "github.com/prysmaticlabs/prysm/beacon-chain/core/time" dbtest "github.com/prysmaticlabs/prysm/beacon-chain/db/testing" "github.com/prysmaticlabs/prysm/beacon-chain/operations/slashings" slashertypes "github.com/prysmaticlabs/prysm/beacon-chain/slasher/types" @@ -189,7 +189,7 @@ func Test_processQueuedAttestations(t *testing.T) { beaconState, err := util.NewBeaconState() require.NoError(t, err) - slot, err := core.StartSlot(tt.args.currentEpoch) + slot, err := coreTime.StartSlot(tt.args.currentEpoch) require.NoError(t, err) require.NoError(t, beaconState.SetSlot(slot)) mockChain := &mock.ChainService{ @@ -322,7 +322,7 @@ func Test_processQueuedAttestations_MultipleChunkIndices(t *testing.T) { att := createAttestationWrapper(t, source, target, []uint64{0}, sr[:]) s.attsQueue = newAttestationsQueue() s.attsQueue.push(att) - slot, err := core.StartSlot(i) + slot, err := coreTime.StartSlot(i) require.NoError(t, err) require.NoError(t, mockChain.State.SetSlot(slot)) s.serviceCfg.HeadStateFetcher = mockChain @@ -384,7 +384,7 @@ func Test_processQueuedAttestations_OverlappingChunkIndices(t *testing.T) { s.attsQueue = newAttestationsQueue() s.attsQueue.push(att1) s.attsQueue.push(att2) - slot, err := core.StartSlot(att2.IndexedAttestation.Data.Target.Epoch) + slot, err := coreTime.StartSlot(att2.IndexedAttestation.Data.Target.Epoch) require.NoError(t, err) mockChain.Slot = &slot s.serviceCfg.HeadStateFetcher = mockChain @@ -763,7 +763,7 @@ func TestService_processQueuedAttestations(t *testing.T) { beaconState, err := util.NewBeaconState() require.NoError(t, err) - slot, err := core.StartSlot(1) + slot, err := coreTime.StartSlot(1) require.NoError(t, err) require.NoError(t, beaconState.SetSlot(slot)) mockChain := &mock.ChainService{ diff --git a/beacon-chain/slasher/receive.go b/beacon-chain/slasher/receive.go index dd3b005539..b4b103a3ac 100644 --- a/beacon-chain/slasher/receive.go +++ b/beacon-chain/slasher/receive.go @@ -6,7 +6,7 @@ import ( "github.com/pkg/errors" types "github.com/prysmaticlabs/eth2-types" - "github.com/prysmaticlabs/prysm/beacon-chain/core" + coreTime "github.com/prysmaticlabs/prysm/beacon-chain/core/time" slashertypes "github.com/prysmaticlabs/prysm/beacon-chain/slasher/types" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" "github.com/sirupsen/logrus" @@ -81,7 +81,7 @@ func (s *Service) processQueuedAttestations(ctx context.Context, slotTicker <-ch select { case currentSlot := <-slotTicker: attestations := s.attsQueue.dequeue() - currentEpoch := core.SlotToEpoch(currentSlot) + currentEpoch := coreTime.SlotToEpoch(currentSlot) // We take all the attestations in the queue and filter out // those which are valid now and valid in the future. validAtts, validInFuture, numDropped := s.filterAttestations(attestations, currentEpoch) @@ -139,7 +139,7 @@ func (s *Service) processQueuedBlocks(ctx context.Context, slotTicker <-chan typ select { case currentSlot := <-slotTicker: blocks := s.blksQueue.dequeue() - currentEpoch := core.SlotToEpoch(currentSlot) + currentEpoch := coreTime.SlotToEpoch(currentSlot) receivedBlocksTotal.Add(float64(len(blocks))) @@ -178,7 +178,7 @@ func (s *Service) pruneSlasherData(ctx context.Context, slotTicker <-chan types. for { select { case <-slotTicker: - headEpoch := core.SlotToEpoch(s.serviceCfg.HeadStateFetcher.HeadSlot()) + headEpoch := coreTime.SlotToEpoch(s.serviceCfg.HeadStateFetcher.HeadSlot()) if err := s.pruneSlasherDataWithinSlidingWindow(ctx, headEpoch); err != nil { log.WithError(err).Error("Could not prune slasher data") continue diff --git a/beacon-chain/state/stategen/BUILD.bazel b/beacon-chain/state/stategen/BUILD.bazel index 90b5a707eb..1c1a92c90c 100644 --- a/beacon-chain/state/stategen/BUILD.bazel +++ b/beacon-chain/state/stategen/BUILD.bazel @@ -23,8 +23,8 @@ go_library( "//testing/slasher/simulator:__pkg__", ], deps = [ - "//beacon-chain/core:go_default_library", "//beacon-chain/core/altair:go_default_library", + "//beacon-chain/core/time:go_default_library", "//beacon-chain/core/transition:go_default_library", "//beacon-chain/db:go_default_library", "//beacon-chain/db/filters:go_default_library", diff --git a/beacon-chain/state/stategen/replay.go b/beacon-chain/state/stategen/replay.go index fc8c50b34c..114d5de2fd 100644 --- a/beacon-chain/state/stategen/replay.go +++ b/beacon-chain/state/stategen/replay.go @@ -6,8 +6,8 @@ import ( "github.com/pkg/errors" types "github.com/prysmaticlabs/eth2-types" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/altair" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/core/transition" "github.com/prysmaticlabs/prysm/beacon-chain/db/filters" "github.com/prysmaticlabs/prysm/beacon-chain/state" @@ -208,7 +208,7 @@ func processSlotsStateGen(ctx context.Context, state state.BeaconState, slot typ return nil, err } - if core.CanUpgradeToAltair(state.Slot()) { + if time.CanUpgradeToAltair(state.Slot()) { state, err = altair.UpgradeToAltair(ctx, state) if err != nil { return nil, err diff --git a/beacon-chain/state/stategen/setter.go b/beacon-chain/state/stategen/setter.go index 8da6ab5563..a90a1430c4 100644 --- a/beacon-chain/state/stategen/setter.go +++ b/beacon-chain/state/stategen/setter.go @@ -4,7 +4,7 @@ import ( "context" "math" - "github.com/prysmaticlabs/prysm/beacon-chain/core" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/encoding/bytesutil" @@ -73,7 +73,7 @@ func (s *State) saveStateByRoot(ctx context.Context, blockRoot [32]byte, st stat } // Only on an epoch boundary slot, saves epoch boundary state in epoch boundary root state cache. - if core.IsEpochStart(st.Slot()) { + if time.IsEpochStart(st.Slot()) { if err := s.epochBoundaryStateCache.put(blockRoot, st); err != nil { return err } diff --git a/beacon-chain/sync/BUILD.bazel b/beacon-chain/sync/BUILD.bazel index 8668da504d..266363fffe 100644 --- a/beacon-chain/sync/BUILD.bazel +++ b/beacon-chain/sync/BUILD.bazel @@ -55,7 +55,6 @@ go_library( "//async/event:go_default_library", "//beacon-chain/blockchain:go_default_library", "//beacon-chain/cache:go_default_library", - "//beacon-chain/core:go_default_library", "//beacon-chain/core/altair:go_default_library", "//beacon-chain/core/blocks:go_default_library", "//beacon-chain/core/feed:go_default_library", @@ -64,6 +63,7 @@ go_library( "//beacon-chain/core/feed/state:go_default_library", "//beacon-chain/core/helpers:go_default_library", "//beacon-chain/core/signing:go_default_library", + "//beacon-chain/core/time:go_default_library", "//beacon-chain/core/transition:go_default_library", "//beacon-chain/core/transition/interop:go_default_library", "//beacon-chain/db:go_default_library", @@ -166,12 +166,12 @@ go_test( "//beacon-chain/blockchain:go_default_library", "//beacon-chain/blockchain/testing:go_default_library", "//beacon-chain/cache:go_default_library", - "//beacon-chain/core:go_default_library", "//beacon-chain/core/altair:go_default_library", "//beacon-chain/core/feed:go_default_library", "//beacon-chain/core/feed/state:go_default_library", "//beacon-chain/core/helpers:go_default_library", "//beacon-chain/core/signing:go_default_library", + "//beacon-chain/core/time:go_default_library", "//beacon-chain/core/transition:go_default_library", "//beacon-chain/db:go_default_library", "//beacon-chain/db/kv:go_default_library", diff --git a/beacon-chain/sync/fork_watcher.go b/beacon-chain/sync/fork_watcher.go index 9f7026c4cb..003d4981a1 100644 --- a/beacon-chain/sync/fork_watcher.go +++ b/beacon-chain/sync/fork_watcher.go @@ -3,7 +3,7 @@ package sync import ( "github.com/pkg/errors" types "github.com/prysmaticlabs/eth2-types" - "github.com/prysmaticlabs/prysm/beacon-chain/core" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/p2p" "github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/network/forks" @@ -20,7 +20,7 @@ func (s *Service) forkWatcher() { // topics during/after the fork epoch. This routine is to ensure correct // subscriptions for nodes running before a fork epoch. case currSlot := <-slotTicker.C(): - currEpoch := core.SlotToEpoch(currSlot) + currEpoch := time.SlotToEpoch(currSlot) if err := s.registerForUpcomingFork(currEpoch); err != nil { log.WithError(err).Error("Unable to check for fork in the next epoch") continue diff --git a/beacon-chain/sync/initial-sync/BUILD.bazel b/beacon-chain/sync/initial-sync/BUILD.bazel index 49abe81ea7..8bbe902ec8 100644 --- a/beacon-chain/sync/initial-sync/BUILD.bazel +++ b/beacon-chain/sync/initial-sync/BUILD.bazel @@ -18,10 +18,10 @@ go_library( deps = [ "//async/abool:go_default_library", "//beacon-chain/blockchain:go_default_library", - "//beacon-chain/core:go_default_library", "//beacon-chain/core/feed:go_default_library", "//beacon-chain/core/feed/block:go_default_library", "//beacon-chain/core/feed/state:go_default_library", + "//beacon-chain/core/time:go_default_library", "//beacon-chain/core/transition:go_default_library", "//beacon-chain/db:go_default_library", "//beacon-chain/p2p:go_default_library", @@ -111,9 +111,9 @@ go_test( "//async/abool:go_default_library", "//async/event:go_default_library", "//beacon-chain/blockchain/testing:go_default_library", - "//beacon-chain/core:go_default_library", "//beacon-chain/core/feed:go_default_library", "//beacon-chain/core/feed/state:go_default_library", + "//beacon-chain/core/time:go_default_library", "//beacon-chain/db:go_default_library", "//beacon-chain/db/testing:go_default_library", "//beacon-chain/p2p: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 2b040c7564..f6da74ec2f 100644 --- a/beacon-chain/sync/initial-sync/blocks_fetcher_peers.go +++ b/beacon-chain/sync/initial-sync/blocks_fetcher_peers.go @@ -7,7 +7,7 @@ import ( "time" "github.com/libp2p/go-libp2p-core/peer" - "github.com/prysmaticlabs/prysm/beacon-chain/core" + coreTime "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/p2p/peers/scorers" "github.com/prysmaticlabs/prysm/cmd/beacon-chain/flags" "github.com/prysmaticlabs/prysm/config/params" @@ -76,7 +76,7 @@ func (f *blocksFetcher) waitForMinimumPeers(ctx context.Context) ([]peer.ID, err headEpoch := f.chain.FinalizedCheckpt().Epoch _, peers = f.p2p.Peers().BestFinalized(params.BeaconConfig().MaxPeersToSync, headEpoch) } else { - headEpoch := core.SlotToEpoch(f.chain.HeadSlot()) + headEpoch := coreTime.SlotToEpoch(f.chain.HeadSlot()) _, peers = f.p2p.Peers().BestNonFinalized(flags.Get().MinimumSyncPeers, headEpoch) } if len(peers) >= required { diff --git a/beacon-chain/sync/initial-sync/blocks_fetcher_test.go b/beacon-chain/sync/initial-sync/blocks_fetcher_test.go index 08986a339e..34cdc913ad 100644 --- a/beacon-chain/sync/initial-sync/blocks_fetcher_test.go +++ b/beacon-chain/sync/initial-sync/blocks_fetcher_test.go @@ -13,7 +13,7 @@ import ( "github.com/libp2p/go-libp2p-core/network" types "github.com/prysmaticlabs/eth2-types" mock "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing" - "github.com/prysmaticlabs/prysm/beacon-chain/core" + coreTime "github.com/prysmaticlabs/prysm/beacon-chain/core/time" dbtest "github.com/prysmaticlabs/prysm/beacon-chain/db/testing" p2pm "github.com/prysmaticlabs/prysm/beacon-chain/p2p" p2pt "github.com/prysmaticlabs/prysm/beacon-chain/p2p/testing" @@ -124,7 +124,7 @@ func TestBlocksFetcher_RoundRobin(t *testing.T) { peers: []*peerData{ { blocks: makeSequence(1, 3*slotsInBatch), - finalizedEpoch: core.SlotToEpoch(3 * slotsInBatch), + finalizedEpoch: coreTime.SlotToEpoch(3 * slotsInBatch), headSlot: 3 * slotsInBatch, }, }, @@ -136,7 +136,7 @@ func TestBlocksFetcher_RoundRobin(t *testing.T) { peers: []*peerData{ { blocks: makeSequence(1, 3*slotsInBatch), - finalizedEpoch: core.SlotToEpoch(3 * slotsInBatch), + finalizedEpoch: coreTime.SlotToEpoch(3 * slotsInBatch), headSlot: 3 * slotsInBatch, }, }, @@ -148,17 +148,17 @@ func TestBlocksFetcher_RoundRobin(t *testing.T) { peers: []*peerData{ { blocks: makeSequence(1, 3*slotsInBatch), - finalizedEpoch: core.SlotToEpoch(3 * slotsInBatch), + finalizedEpoch: coreTime.SlotToEpoch(3 * slotsInBatch), headSlot: 3 * slotsInBatch, }, { blocks: makeSequence(1, 3*slotsInBatch), - finalizedEpoch: core.SlotToEpoch(3 * slotsInBatch), + finalizedEpoch: coreTime.SlotToEpoch(3 * slotsInBatch), headSlot: 3 * slotsInBatch, }, { blocks: makeSequence(1, 3*slotsInBatch), - finalizedEpoch: core.SlotToEpoch(3 * slotsInBatch), + finalizedEpoch: coreTime.SlotToEpoch(3 * slotsInBatch), headSlot: 3 * slotsInBatch, }, }, @@ -506,7 +506,7 @@ func TestBlocksFetcher_requestBeaconBlocksByRange(t *testing.T) { p2p: p2p, }) - _, peerIDs := p2p.Peers().BestFinalized(params.BeaconConfig().MaxPeersToSync, core.SlotToEpoch(mc.HeadSlot())) + _, peerIDs := p2p.Peers().BestFinalized(params.BeaconConfig().MaxPeersToSync, coreTime.SlotToEpoch(mc.HeadSlot())) req := &p2ppb.BeaconBlocksByRangeRequest{ StartSlot: 1, Step: 1, diff --git a/beacon-chain/sync/initial-sync/blocks_fetcher_utils.go b/beacon-chain/sync/initial-sync/blocks_fetcher_utils.go index be6b54375f..dc2af50000 100644 --- a/beacon-chain/sync/initial-sync/blocks_fetcher_utils.go +++ b/beacon-chain/sync/initial-sync/blocks_fetcher_utils.go @@ -8,7 +8,7 @@ import ( "github.com/libp2p/go-libp2p-core/peer" "github.com/pkg/errors" types "github.com/prysmaticlabs/eth2-types" - "github.com/prysmaticlabs/prysm/beacon-chain/core" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" p2pTypes "github.com/prysmaticlabs/prysm/beacon-chain/p2p/types" "github.com/prysmaticlabs/prysm/cmd/beacon-chain/flags" "github.com/prysmaticlabs/prysm/config/params" @@ -103,7 +103,7 @@ func (f *blocksFetcher) nonSkippedSlotAfterWithPeersTarget( // Quickly find the close enough epoch where a non-empty slot definitely exists. // Only single random slot per epoch is checked - allowing to move forward relatively quickly. slot += nonSkippedSlotsFullSearchEpochs * slotsPerEpoch - upperBoundSlot, err := core.StartSlot(targetEpoch + 1) + upperBoundSlot, err := time.StartSlot(targetEpoch + 1) if err != nil { return 0, err } @@ -124,7 +124,7 @@ func (f *blocksFetcher) nonSkippedSlotAfterWithPeersTarget( if upperBoundSlot > slotsPerEpoch { upperBoundSlot -= slotsPerEpoch } - upperBoundSlot, err = core.StartSlot(core.SlotToEpoch(upperBoundSlot)) + upperBoundSlot, err = time.StartSlot(time.SlotToEpoch(upperBoundSlot)) if err != nil { return 0, err } @@ -132,7 +132,7 @@ func (f *blocksFetcher) nonSkippedSlotAfterWithPeersTarget( if err != nil { return 0, err } - s, err := core.StartSlot(targetEpoch + 1) + s, err := time.StartSlot(targetEpoch + 1) if err != nil { return 0, err } @@ -158,12 +158,12 @@ func (f *blocksFetcher) findFork(ctx context.Context, slot types.Slot) (*forkDat // The current slot's epoch must be after the finalization epoch, // triggering backtracking on earlier epochs is unnecessary. finalizedEpoch := f.chain.FinalizedCheckpt().Epoch - epoch := core.SlotToEpoch(slot) + epoch := time.SlotToEpoch(slot) if epoch <= finalizedEpoch { return nil, errors.New("slot is not after the finalized epoch, no backtracking is necessary") } // Update slot to the beginning of the current epoch (preserve original slot for comparison). - slot, err := core.StartSlot(epoch) + slot, err := time.StartSlot(epoch) if err != nil { return nil, err } @@ -215,7 +215,7 @@ func (f *blocksFetcher) findForkWithPeer(ctx context.Context, pid peer.ID, slot return nil, fmt.Errorf("cannot obtain peer's status: %w", err) } nonSkippedSlot, err := f.nonSkippedSlotAfterWithPeersTarget( - ctx, slot-slotsPerEpoch, []peer.ID{pid}, core.SlotToEpoch(pidState.HeadSlot)) + ctx, slot-slotsPerEpoch, []peer.ID{pid}, time.SlotToEpoch(pidState.HeadSlot)) if err != nil { return nil, fmt.Errorf("cannot locate non-empty slot for a peer: %w", err) } @@ -294,7 +294,7 @@ func (f *blocksFetcher) bestFinalizedSlot() types.Slot { // bestNonFinalizedSlot returns the highest non-finalized slot of enough number of connected peers. func (f *blocksFetcher) bestNonFinalizedSlot() types.Slot { - headEpoch := core.SlotToEpoch(f.chain.HeadSlot()) + headEpoch := time.SlotToEpoch(f.chain.HeadSlot()) targetEpoch, _ := f.p2p.Peers().BestNonFinalized(flags.Get().MinimumSyncPeers*2, headEpoch) return params.BeaconConfig().SlotsPerEpoch.Mul(uint64(targetEpoch)) } @@ -306,7 +306,7 @@ func (f *blocksFetcher) calculateHeadAndTargetEpochs() (headEpoch, targetEpoch t headEpoch = f.chain.FinalizedCheckpt().Epoch targetEpoch, peers = f.p2p.Peers().BestFinalized(params.BeaconConfig().MaxPeersToSync, headEpoch) } else { - headEpoch = core.SlotToEpoch(f.chain.HeadSlot()) + headEpoch = time.SlotToEpoch(f.chain.HeadSlot()) targetEpoch, peers = f.p2p.Peers().BestNonFinalized(flags.Get().MinimumSyncPeers, headEpoch) } return headEpoch, targetEpoch, peers diff --git a/beacon-chain/sync/initial-sync/blocks_fetcher_utils_test.go b/beacon-chain/sync/initial-sync/blocks_fetcher_utils_test.go index 277372de9a..de7e38c7d7 100644 --- a/beacon-chain/sync/initial-sync/blocks_fetcher_utils_test.go +++ b/beacon-chain/sync/initial-sync/blocks_fetcher_utils_test.go @@ -12,7 +12,7 @@ import ( "github.com/libp2p/go-libp2p-core/peer" types "github.com/prysmaticlabs/eth2-types" mock "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing" - "github.com/prysmaticlabs/prysm/beacon-chain/core" + coreTime "github.com/prysmaticlabs/prysm/beacon-chain/core/time" dbtest "github.com/prysmaticlabs/prysm/beacon-chain/db/testing" p2pm "github.com/prysmaticlabs/prysm/beacon-chain/p2p" p2pt "github.com/prysmaticlabs/prysm/beacon-chain/p2p/testing" @@ -161,7 +161,7 @@ func TestBlocksFetcher_findFork(t *testing.T) { // Chain contains blocks from 8 epochs (from 0 to 7, 256 is the start slot of epoch8). chain1 := extendBlockSequence(t, []*eth.SignedBeaconBlock{}, 250) finalizedSlot := types.Slot(63) - finalizedEpoch := core.SlotToEpoch(finalizedSlot) + finalizedEpoch := coreTime.SlotToEpoch(finalizedSlot) genesisBlock := chain1[0] require.NoError(t, beaconDB.SaveBlock(context.Background(), wrapper.WrappedPhase0SignedBeaconBlock(genesisBlock))) @@ -425,7 +425,7 @@ func TestBlocksFetcher_findAncestor(t *testing.T) { knownBlocks := extendBlockSequence(t, []*eth.SignedBeaconBlock{}, 128) finalizedSlot := types.Slot(63) - finalizedEpoch := core.SlotToEpoch(finalizedSlot) + finalizedEpoch := coreTime.SlotToEpoch(finalizedSlot) genesisBlock := knownBlocks[0] require.NoError(t, beaconDB.SaveBlock(context.Background(), wrapper.WrappedPhase0SignedBeaconBlock(genesisBlock))) diff --git a/beacon-chain/sync/initial-sync/blocks_queue.go b/beacon-chain/sync/initial-sync/blocks_queue.go index 805916ab3b..77a55b97a1 100644 --- a/beacon-chain/sync/initial-sync/blocks_queue.go +++ b/beacon-chain/sync/initial-sync/blocks_queue.go @@ -7,7 +7,7 @@ import ( "github.com/libp2p/go-libp2p-core/peer" types "github.com/prysmaticlabs/eth2-types" - "github.com/prysmaticlabs/prysm/beacon-chain/core" + coreTime "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/db" "github.com/prysmaticlabs/prysm/beacon-chain/p2p" beaconsync "github.com/prysmaticlabs/prysm/beacon-chain/sync" @@ -221,7 +221,7 @@ func (q *blocksQueue) loop() { "highestExpectedSlot": q.highestExpectedSlot, "noRequiredPeersErrRetries": q.exitConditions.noRequiredPeersErrRetries, "event": eventTick, - "epoch": core.SlotToEpoch(fsm.start), + "epoch": coreTime.SlotToEpoch(fsm.start), "start": fsm.start, "error": err.Error(), }).Debug("Can not trigger event") @@ -263,7 +263,7 @@ func (q *blocksQueue) loop() { if err := fsm.trigger(eventDataReceived, response); err != nil { log.WithFields(logrus.Fields{ "event": eventDataReceived, - "epoch": core.SlotToEpoch(fsm.start), + "epoch": coreTime.SlotToEpoch(fsm.start), "error": err.Error(), }).Debug("Can not process event") fsm.setState(stateNew) @@ -419,16 +419,16 @@ func (q *blocksQueue) onProcessSkippedEvent(ctx context.Context) eventHandlerFn // All machines are skipped, FSMs need reset. startSlot := q.chain.HeadSlot() + 1 if q.mode == modeNonConstrained && startSlot > bestFinalizedSlot { - q.staleEpochs[core.SlotToEpoch(startSlot)]++ + q.staleEpochs[coreTime.SlotToEpoch(startSlot)]++ // If FSMs have been reset enough times, try to explore alternative forks. - if q.staleEpochs[core.SlotToEpoch(startSlot)] >= maxResetAttempts { - delete(q.staleEpochs, core.SlotToEpoch(startSlot)) + if q.staleEpochs[coreTime.SlotToEpoch(startSlot)] >= maxResetAttempts { + delete(q.staleEpochs, coreTime.SlotToEpoch(startSlot)) fork, err := q.blocksFetcher.findFork(ctx, startSlot) if err == nil { return stateSkipped, q.resetFromFork(ctx, fork) } log.WithFields(logrus.Fields{ - "epoch": core.SlotToEpoch(startSlot), + "epoch": coreTime.SlotToEpoch(startSlot), "error": err.Error(), }).Debug("Can not explore alternative branches") } diff --git a/beacon-chain/sync/initial-sync/blocks_queue_test.go b/beacon-chain/sync/initial-sync/blocks_queue_test.go index cf4e88ee81..a7b9110619 100644 --- a/beacon-chain/sync/initial-sync/blocks_queue_test.go +++ b/beacon-chain/sync/initial-sync/blocks_queue_test.go @@ -10,7 +10,7 @@ import ( "github.com/libp2p/go-libp2p-core/peer" types "github.com/prysmaticlabs/eth2-types" mock "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing" - "github.com/prysmaticlabs/prysm/beacon-chain/core" + coreTime "github.com/prysmaticlabs/prysm/beacon-chain/core/time" dbtest "github.com/prysmaticlabs/prysm/beacon-chain/db/testing" "github.com/prysmaticlabs/prysm/beacon-chain/p2p/peers" p2pt "github.com/prysmaticlabs/prysm/beacon-chain/p2p/testing" @@ -1035,7 +1035,7 @@ func TestBlocksQueue_stuckInUnfavourableFork(t *testing.T) { forkedSlot := types.Slot(201) chain2 := extendBlockSequence(t, chain1[:forkedSlot], 100) finalizedSlot := types.Slot(63) - finalizedEpoch := core.SlotToEpoch(finalizedSlot) + finalizedEpoch := coreTime.SlotToEpoch(finalizedSlot) genesisBlock := chain1[0] require.NoError(t, beaconDB.SaveBlock(context.Background(), wrapper.WrappedPhase0SignedBeaconBlock(genesisBlock))) @@ -1135,7 +1135,7 @@ func TestBlocksQueue_stuckInUnfavourableFork(t *testing.T) { } // Update counter, and trigger backtracking. - queue.staleEpochs[core.SlotToEpoch(machineSlots[0])] = maxResetAttempts + queue.staleEpochs[coreTime.SlotToEpoch(machineSlots[0])] = maxResetAttempts handlerFn = queue.onProcessSkippedEvent(ctx) updatedState, err = handlerFn(queue.smm.machines[machineSlots[len(machineSlots)-1]], nil) assert.ErrorContains(t, "invalid range for non-skipped slot", err) @@ -1185,7 +1185,7 @@ func TestBlocksQueue_stuckInUnfavourableFork(t *testing.T) { } // Update counter, and trigger backtracking. - queue.staleEpochs[core.SlotToEpoch(machineSlots[0])] = maxResetAttempts + queue.staleEpochs[coreTime.SlotToEpoch(machineSlots[0])] = maxResetAttempts handlerFn = queue.onProcessSkippedEvent(ctx) updatedState, err = handlerFn(queue.smm.machines[machineSlots[len(machineSlots)-1]], nil) require.NoError(t, err) @@ -1196,7 +1196,7 @@ func TestBlocksQueue_stuckInUnfavourableFork(t *testing.T) { // Alternative fork should start on slot 201, make sure that the first machine contains all // required forked data, including data on and after slot 201. - forkedEpochStartSlot, err := core.StartSlot(core.SlotToEpoch(forkedSlot)) + forkedEpochStartSlot, err := coreTime.StartSlot(coreTime.SlotToEpoch(forkedSlot)) require.NoError(t, err) firstFSM, ok := queue.smm.findStateMachine(forkedEpochStartSlot + 1) require.Equal(t, true, ok) @@ -1236,7 +1236,7 @@ func TestBlocksQueue_stuckWhenHeadIsSetToOrphanedBlock(t *testing.T) { chain := extendBlockSequence(t, []*eth.SignedBeaconBlock{}, 128) finalizedSlot := types.Slot(82) - finalizedEpoch := core.SlotToEpoch(finalizedSlot) + finalizedEpoch := coreTime.SlotToEpoch(finalizedSlot) genesisBlock := chain[0] require.NoError(t, beaconDB.SaveBlock(context.Background(), wrapper.WrappedPhase0SignedBeaconBlock(genesisBlock))) @@ -1304,7 +1304,7 @@ func TestBlocksQueue_stuckWhenHeadIsSetToOrphanedBlock(t *testing.T) { require.NoError(t, queue.start()) isProcessedBlock := func(ctx context.Context, blk block.SignedBeaconBlock, blkRoot [32]byte) bool { - finalizedSlot, err := core.StartSlot(mc.FinalizedCheckpt().Epoch) + finalizedSlot, err := coreTime.StartSlot(mc.FinalizedCheckpt().Epoch) if err != nil { return false } diff --git a/beacon-chain/sync/initial-sync/fsm.go b/beacon-chain/sync/initial-sync/fsm.go index 7ef3894090..bffc9fae0d 100644 --- a/beacon-chain/sync/initial-sync/fsm.go +++ b/beacon-chain/sync/initial-sync/fsm.go @@ -8,7 +8,7 @@ import ( "github.com/libp2p/go-libp2p-core/peer" types "github.com/prysmaticlabs/eth2-types" - "github.com/prysmaticlabs/prysm/beacon-chain/core" + coreTime "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/block" prysmTime "github.com/prysmaticlabs/prysm/time" ) @@ -189,7 +189,7 @@ func (m *stateMachine) isLast() bool { // String returns human-readable representation of a FSM state. func (m *stateMachine) String() string { - return fmt.Sprintf("{%d:%s}", core.SlotToEpoch(m.start), m.state) + return fmt.Sprintf("{%d:%s}", coreTime.SlotToEpoch(m.start), m.state) } // String returns human-readable representation of a state. diff --git a/beacon-chain/sync/initial-sync/initial_sync_test.go b/beacon-chain/sync/initial-sync/initial_sync_test.go index 84f577753b..51cee0dc5d 100644 --- a/beacon-chain/sync/initial-sync/initial_sync_test.go +++ b/beacon-chain/sync/initial-sync/initial_sync_test.go @@ -13,7 +13,7 @@ import ( "github.com/libp2p/go-libp2p-core/peer" types "github.com/prysmaticlabs/eth2-types" mock "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing" - "github.com/prysmaticlabs/prysm/beacon-chain/core" + coreTime "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/db" dbtest "github.com/prysmaticlabs/prysm/beacon-chain/db/testing" "github.com/prysmaticlabs/prysm/beacon-chain/p2p/peers" @@ -110,7 +110,7 @@ func makeGenesisTime(currentSlot types.Slot) time.Time { func TestMakeGenesisTime(t *testing.T) { currentSlot := types.Slot(64) gt := makeGenesisTime(currentSlot) - require.Equal(t, currentSlot, core.SlotsSince(gt)) + require.Equal(t, currentSlot, coreTime.SlotsSince(gt)) } // helper function for sequences of block slots @@ -320,7 +320,7 @@ func connectPeerHavingBlocks( p.Connect(host) - finalizedEpoch := core.SlotToEpoch(finalizedSlot) + finalizedEpoch := coreTime.SlotToEpoch(finalizedSlot) headRoot, err := blocks[len(blocks)-1].Block.HashTreeRoot() require.NoError(t, err) diff --git a/beacon-chain/sync/initial-sync/round_robin.go b/beacon-chain/sync/initial-sync/round_robin.go index 3608e1ccb3..d286061381 100644 --- a/beacon-chain/sync/initial-sync/round_robin.go +++ b/beacon-chain/sync/initial-sync/round_robin.go @@ -11,7 +11,7 @@ import ( "github.com/libp2p/go-libp2p-core/peer" "github.com/paulbellamy/ratecounter" types "github.com/prysmaticlabs/eth2-types" - "github.com/prysmaticlabs/prysm/beacon-chain/core" + coreTime "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/core/transition" "github.com/prysmaticlabs/prysm/encoding/bytesutil" "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/block" @@ -51,7 +51,7 @@ func (s *Service) roundRobinSync(genesis time.Time) error { } // Already at head, no need for 2nd phase. - if s.cfg.Chain.HeadSlot() == core.SlotsSince(genesis) { + if s.cfg.Chain.HeadSlot() == coreTime.SlotsSince(genesis) { return nil } @@ -62,7 +62,7 @@ func (s *Service) roundRobinSync(genesis time.Time) error { // syncToFinalizedEpoch sync from head to best known finalized epoch. func (s *Service) syncToFinalizedEpoch(ctx context.Context, genesis time.Time) error { - highestFinalizedSlot, err := core.StartSlot(s.highestFinalizedEpoch() + 1) + highestFinalizedSlot, err := coreTime.StartSlot(s.highestFinalizedEpoch() + 1) if err != nil { return err } @@ -88,7 +88,7 @@ func (s *Service) syncToFinalizedEpoch(ctx context.Context, genesis time.Time) e log.WithFields(logrus.Fields{ "syncedSlot": s.cfg.Chain.HeadSlot(), - "currentSlot": core.SlotsSince(genesis), + "currentSlot": coreTime.SlotsSince(genesis), }).Info("Synced to finalized epoch - now syncing blocks up to current head") if err := queue.stop(); err != nil { log.WithError(err).Debug("Error stopping queue") @@ -104,7 +104,7 @@ func (s *Service) syncToNonFinalizedEpoch(ctx context.Context, genesis time.Time p2p: s.cfg.P2P, db: s.cfg.DB, chain: s.cfg.Chain, - highestExpectedSlot: core.SlotsSince(genesis), + highestExpectedSlot: coreTime.SlotsSince(genesis), mode: modeNonConstrained, }) if err := queue.start(); err != nil { @@ -115,7 +115,7 @@ func (s *Service) syncToNonFinalizedEpoch(ctx context.Context, genesis time.Time } log.WithFields(logrus.Fields{ "syncedSlot": s.cfg.Chain.HeadSlot(), - "currentSlot": core.SlotsSince(genesis), + "currentSlot": coreTime.SlotsSince(genesis), }).Info("Synced to head of chain") if err := queue.stop(); err != nil { log.WithError(err).Debug("Error stopping queue") @@ -184,15 +184,15 @@ func (s *Service) logSyncStatus(genesis time.Time, blk block.BeaconBlock, blkRoo if rate == 0 { rate = 1 } - if core.IsEpochStart(blk.Slot()) { - timeRemaining := time.Duration(float64(core.SlotsSince(genesis)-blk.Slot())/rate) * time.Second + if coreTime.IsEpochStart(blk.Slot()) { + timeRemaining := time.Duration(float64(coreTime.SlotsSince(genesis)-blk.Slot())/rate) * time.Second log.WithFields(logrus.Fields{ "peers": len(s.cfg.P2P.Peers().Connected()), "blocksPerSecond": fmt.Sprintf("%.1f", rate), }).Infof( "Processing block %s %d/%d - estimated time remaining %s", fmt.Sprintf("0x%s...", hex.EncodeToString(blkRoot[:])[:8]), - blk.Slot(), core.SlotsSince(genesis), timeRemaining, + blk.Slot(), coreTime.SlotsSince(genesis), timeRemaining, ) } } @@ -205,14 +205,14 @@ func (s *Service) logBatchSyncStatus(genesis time.Time, blks []block.SignedBeaco rate = 1 } firstBlk := blks[0] - timeRemaining := time.Duration(float64(core.SlotsSince(genesis)-firstBlk.Block().Slot())/rate) * time.Second + timeRemaining := time.Duration(float64(coreTime.SlotsSince(genesis)-firstBlk.Block().Slot())/rate) * time.Second log.WithFields(logrus.Fields{ "peers": len(s.cfg.P2P.Peers().Connected()), "blocksPerSecond": fmt.Sprintf("%.1f", rate), }).Infof( "Processing block batch of size %d starting from %s %d/%d - estimated time remaining %s", len(blks), fmt.Sprintf("0x%s...", hex.EncodeToString(blkRoot[:])[:8]), - firstBlk.Block().Slot(), core.SlotsSince(genesis), timeRemaining, + firstBlk.Block().Slot(), coreTime.SlotsSince(genesis), timeRemaining, ) } @@ -300,7 +300,7 @@ func (s *Service) updatePeerScorerStats(pid peer.ID, startSlot types.Slot) { // isProcessedBlock checks DB and local cache for presence of a given block, to avoid duplicates. func (s *Service) isProcessedBlock(ctx context.Context, blk block.SignedBeaconBlock, blkRoot [32]byte) bool { - finalizedSlot, err := core.StartSlot(s.cfg.Chain.FinalizedCheckpt().Epoch) + finalizedSlot, err := coreTime.StartSlot(s.cfg.Chain.FinalizedCheckpt().Epoch) if err != nil { return false } diff --git a/beacon-chain/sync/initial-sync/service.go b/beacon-chain/sync/initial-sync/service.go index 83b528ab51..69f2a0ad60 100644 --- a/beacon-chain/sync/initial-sync/service.go +++ b/beacon-chain/sync/initial-sync/service.go @@ -11,10 +11,10 @@ import ( "github.com/pkg/errors" "github.com/prysmaticlabs/prysm/async/abool" "github.com/prysmaticlabs/prysm/beacon-chain/blockchain" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/feed" blockfeed "github.com/prysmaticlabs/prysm/beacon-chain/core/feed/block" statefeed "github.com/prysmaticlabs/prysm/beacon-chain/core/feed/state" + coreTime "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/db" "github.com/prysmaticlabs/prysm/beacon-chain/p2p" "github.com/prysmaticlabs/prysm/cmd/beacon-chain/flags" @@ -87,8 +87,8 @@ func (s *Service) Start() { log.WithField("genesisTime", genesis).Info("Genesis time has not arrived - not syncing") return } - currentSlot := core.SlotsSince(genesis) - if core.SlotToEpoch(currentSlot) == 0 { + currentSlot := coreTime.SlotsSince(genesis) + if coreTime.SlotToEpoch(currentSlot) == 0 { log.WithField("genesisTime", genesis).Info("Chain started within the last epoch - not syncing") s.markSynced(genesis) return @@ -96,7 +96,7 @@ func (s *Service) Start() { s.chainStarted.Set() log.Info("Starting initial chain sync...") // Are we already in sync, or close to it? - if core.SlotToEpoch(s.cfg.Chain.HeadSlot()) == core.SlotToEpoch(currentSlot) { + if coreTime.SlotToEpoch(s.cfg.Chain.HeadSlot()) == coreTime.SlotToEpoch(currentSlot) { log.Info("Already synced to the current chain head") s.markSynced(genesis) return diff --git a/beacon-chain/sync/initial-sync/service_test.go b/beacon-chain/sync/initial-sync/service_test.go index bc40807c5d..0afe0b8588 100644 --- a/beacon-chain/sync/initial-sync/service_test.go +++ b/beacon-chain/sync/initial-sync/service_test.go @@ -11,9 +11,9 @@ import ( "github.com/prysmaticlabs/prysm/async/abool" "github.com/prysmaticlabs/prysm/async/event" mock "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/feed" statefeed "github.com/prysmaticlabs/prysm/beacon-chain/core/feed/state" + coreTime "github.com/prysmaticlabs/prysm/beacon-chain/core/time" dbtest "github.com/prysmaticlabs/prysm/beacon-chain/db/testing" p2pt "github.com/prysmaticlabs/prysm/beacon-chain/p2p/testing" "github.com/prysmaticlabs/prysm/cmd/beacon-chain/flags" @@ -119,7 +119,7 @@ func TestService_InitStartStop(t *testing.T) { return &mock.ChainService{ State: st, FinalizedCheckPoint: ð.Checkpoint{ - Epoch: core.SlotToEpoch(futureSlot), + Epoch: coreTime.SlotToEpoch(futureSlot), }, Genesis: makeGenesisTime(futureSlot), ValidatorsRoot: [32]byte{}, @@ -407,7 +407,7 @@ func TestService_Resync(t *testing.T) { Root: genesisRoot[:], DB: beaconDB, FinalizedCheckPoint: ð.Checkpoint{ - Epoch: core.SlotToEpoch(futureSlot), + Epoch: coreTime.SlotToEpoch(futureSlot), }, Genesis: time.Now(), ValidatorsRoot: [32]byte{}, diff --git a/beacon-chain/sync/metrics.go b/beacon-chain/sync/metrics.go index af7bffaf34..8e190cbc27 100644 --- a/beacon-chain/sync/metrics.go +++ b/beacon-chain/sync/metrics.go @@ -8,7 +8,7 @@ import ( "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promauto" "github.com/prysmaticlabs/prysm/beacon-chain/cache" - "github.com/prysmaticlabs/prysm/beacon-chain/core" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/p2p" "github.com/prysmaticlabs/prysm/cmd/beacon-chain/flags" "github.com/prysmaticlabs/prysm/config/params" @@ -84,7 +84,7 @@ func (s *Service) updateMetrics() { log.WithError(err).Debugf("Could not compute fork digest") } indices := s.aggregatorSubnetIndices(s.cfg.Chain.CurrentSlot()) - syncIndices := cache.SyncSubnetIDs.GetAllSubnets(core.SlotToEpoch(s.cfg.Chain.CurrentSlot())) + syncIndices := cache.SyncSubnetIDs.GetAllSubnets(time.SlotToEpoch(s.cfg.Chain.CurrentSlot())) attTopic := p2p.GossipTypeMapping[reflect.TypeOf(&pb.Attestation{})] syncTopic := p2p.GossipTypeMapping[reflect.TypeOf(&pb.SyncCommitteeMessage{})] attTopic += s.cfg.P2P.Encoding().ProtocolSuffix() diff --git a/beacon-chain/sync/pending_attestations_queue.go b/beacon-chain/sync/pending_attestations_queue.go index 8971514d64..dcf848036f 100644 --- a/beacon-chain/sync/pending_attestations_queue.go +++ b/beacon-chain/sync/pending_attestations_queue.go @@ -8,8 +8,8 @@ import ( pubsub "github.com/libp2p/go-libp2p-pubsub" types "github.com/prysmaticlabs/eth2-types" "github.com/prysmaticlabs/prysm/async" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/crypto/rand" "github.com/prysmaticlabs/prysm/encoding/bytesutil" @@ -117,7 +117,7 @@ func (s *Service) processPendingAtts(ctx context.Context) error { } s.setSeenCommitteeIndicesSlot(att.Aggregate.Data.Slot, att.Aggregate.Data.CommitteeIndex, att.Aggregate.AggregationBits) - valCount, err := helpers.ActiveValidatorCount(ctx, preState, core.SlotToEpoch(att.Aggregate.Data.Slot)) + valCount, err := helpers.ActiveValidatorCount(ctx, preState, time.SlotToEpoch(att.Aggregate.Data.Slot)) if err != nil { log.WithError(err).Debug("Could not retrieve active validator count") continue diff --git a/beacon-chain/sync/pending_blocks_queue.go b/beacon-chain/sync/pending_blocks_queue.go index da7fbdd416..8b13a6c249 100644 --- a/beacon-chain/sync/pending_blocks_queue.go +++ b/beacon-chain/sync/pending_blocks_queue.go @@ -10,8 +10,8 @@ import ( "github.com/pkg/errors" types "github.com/prysmaticlabs/eth2-types" "github.com/prysmaticlabs/prysm/async" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" + coreTime "github.com/prysmaticlabs/prysm/beacon-chain/core/time" p2ptypes "github.com/prysmaticlabs/prysm/beacon-chain/p2p/types" "github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/crypto/rand" @@ -262,7 +262,7 @@ func (s *Service) validatePendingSlots() error { slot := cacheKeyToSlot(k) blks := s.pendingBlocksInCache(slot) for _, b := range blks { - epoch := core.SlotToEpoch(slot) + epoch := coreTime.SlotToEpoch(slot) // remove all descendant blocks of old blocks if oldBlockRoots[bytesutil.ToBytes32(b.Block().ParentRoot())] { root, err := b.Block().HashTreeRoot() diff --git a/beacon-chain/sync/rpc.go b/beacon-chain/sync/rpc.go index 8301966188..6fc894ad05 100644 --- a/beacon-chain/sync/rpc.go +++ b/beacon-chain/sync/rpc.go @@ -10,7 +10,7 @@ import ( libp2pcore "github.com/libp2p/go-libp2p-core" "github.com/libp2p/go-libp2p-core/network" "github.com/libp2p/go-libp2p-core/protocol" - "github.com/prysmaticlabs/prysm/beacon-chain/core" + coreTime "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/p2p" p2ptypes "github.com/prysmaticlabs/prysm/beacon-chain/p2p/types" "github.com/prysmaticlabs/prysm/config/params" @@ -34,7 +34,7 @@ type rpcHandler func(context.Context, interface{}, libp2pcore.Stream) error // registerRPCHandlers for p2p RPC. func (s *Service) registerRPCHandlers() { - currEpoch := core.SlotToEpoch(s.cfg.Chain.CurrentSlot()) + currEpoch := coreTime.SlotToEpoch(s.cfg.Chain.CurrentSlot()) // Register V2 handlers if we are past altair fork epoch. if currEpoch >= params.BeaconConfig().AltairForkEpoch { s.registerRPC( diff --git a/beacon-chain/sync/rpc_beacon_blocks_by_range_test.go b/beacon-chain/sync/rpc_beacon_blocks_by_range_test.go index 1e349039f5..bfae9228e0 100644 --- a/beacon-chain/sync/rpc_beacon_blocks_by_range_test.go +++ b/beacon-chain/sync/rpc_beacon_blocks_by_range_test.go @@ -12,7 +12,7 @@ import ( "github.com/libp2p/go-libp2p-core/protocol" types "github.com/prysmaticlabs/eth2-types" chainMock "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing" - "github.com/prysmaticlabs/prysm/beacon-chain/core" + coreTime "github.com/prysmaticlabs/prysm/beacon-chain/core/time" db2 "github.com/prysmaticlabs/prysm/beacon-chain/db" db "github.com/prysmaticlabs/prysm/beacon-chain/db/testing" "github.com/prysmaticlabs/prysm/beacon-chain/p2p" @@ -651,7 +651,7 @@ func TestRPCBeaconBlocksByRange_FilterBlocks(t *testing.T) { } require.NoError(t, d.SaveStateSummaries(context.Background(), stateSummaries)) require.NoError(t, d.SaveFinalizedCheckpoint(context.Background(), ðpb.Checkpoint{ - Epoch: core.SlotToEpoch(stateSummaries[len(stateSummaries)-1].Slot), + Epoch: coreTime.SlotToEpoch(stateSummaries[len(stateSummaries)-1].Slot), Root: stateSummaries[len(stateSummaries)-1].Root, })) } @@ -700,7 +700,7 @@ func TestRPCBeaconBlocksByRange_FilterBlocks(t *testing.T) { } require.NoError(t, d.SaveStateSummaries(context.Background(), stateSummaries)) require.NoError(t, d.SaveFinalizedCheckpoint(context.Background(), ðpb.Checkpoint{ - Epoch: core.SlotToEpoch(stateSummaries[len(stateSummaries)-1].Slot), + Epoch: coreTime.SlotToEpoch(stateSummaries[len(stateSummaries)-1].Slot), Root: stateSummaries[len(stateSummaries)-1].Root, })) } diff --git a/beacon-chain/sync/rpc_goodbye.go b/beacon-chain/sync/rpc_goodbye.go index 263738ef6b..4bc1588623 100644 --- a/beacon-chain/sync/rpc_goodbye.go +++ b/beacon-chain/sync/rpc_goodbye.go @@ -10,7 +10,7 @@ import ( "github.com/libp2p/go-libp2p-core/peer" types "github.com/prysmaticlabs/eth2-types" "github.com/prysmaticlabs/prysm/async" - "github.com/prysmaticlabs/prysm/beacon-chain/core" + coreTime "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/p2p" p2ptypes "github.com/prysmaticlabs/prysm/beacon-chain/p2p/types" "github.com/sirupsen/logrus" @@ -96,7 +96,7 @@ func (s *Service) sendGoodByeMessage(ctx context.Context, code p2ptypes.RPCGoodb ctx, cancel := context.WithTimeout(ctx, respTimeout) defer cancel() - topic, err := p2p.TopicFromMessage(p2p.GoodbyeMessageName, core.SlotToEpoch(s.cfg.Chain.CurrentSlot())) + topic, err := p2p.TopicFromMessage(p2p.GoodbyeMessageName, coreTime.SlotToEpoch(s.cfg.Chain.CurrentSlot())) if err != nil { return err } diff --git a/beacon-chain/sync/rpc_metadata.go b/beacon-chain/sync/rpc_metadata.go index eba906e224..a7a9831ddf 100644 --- a/beacon-chain/sync/rpc_metadata.go +++ b/beacon-chain/sync/rpc_metadata.go @@ -8,8 +8,8 @@ import ( "github.com/pkg/errors" "github.com/prysmaticlabs/go-bitfield" "github.com/prysmaticlabs/prysm/beacon-chain/blockchain" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/signing" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/p2p" "github.com/prysmaticlabs/prysm/beacon-chain/p2p/types" "github.com/prysmaticlabs/prysm/config/params" @@ -89,7 +89,7 @@ func (s *Service) sendMetaDataRequest(ctx context.Context, id peer.ID) (metadata ctx, cancel := context.WithTimeout(ctx, respTimeout) defer cancel() - topic, err := p2p.TopicFromMessage(p2p.MetadataMessageName, core.SlotToEpoch(s.cfg.Chain.CurrentSlot())) + topic, err := p2p.TopicFromMessage(p2p.MetadataMessageName, time.SlotToEpoch(s.cfg.Chain.CurrentSlot())) if err != nil { return nil, err } @@ -107,7 +107,7 @@ func (s *Service) sendMetaDataRequest(ctx context.Context, id peer.ID) (metadata return nil, errors.New(errMsg) } valRoot := s.cfg.Chain.GenesisValidatorRoot() - rpcCtx, err := forks.ForkDigestFromEpoch(core.SlotToEpoch(s.cfg.Chain.CurrentSlot()), valRoot[:]) + rpcCtx, err := forks.ForkDigestFromEpoch(time.SlotToEpoch(s.cfg.Chain.CurrentSlot()), valRoot[:]) if err != nil { return nil, err } diff --git a/beacon-chain/sync/rpc_ping.go b/beacon-chain/sync/rpc_ping.go index 7113de0389..79128e4084 100644 --- a/beacon-chain/sync/rpc_ping.go +++ b/beacon-chain/sync/rpc_ping.go @@ -9,7 +9,7 @@ import ( libp2pcore "github.com/libp2p/go-libp2p-core" "github.com/libp2p/go-libp2p-core/peer" types "github.com/prysmaticlabs/eth2-types" - "github.com/prysmaticlabs/prysm/beacon-chain/core" + coreTime "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/p2p" p2ptypes "github.com/prysmaticlabs/prysm/beacon-chain/p2p/types" "github.com/prysmaticlabs/prysm/time" @@ -78,7 +78,7 @@ func (s *Service) sendPingRequest(ctx context.Context, id peer.ID) error { defer cancel() metadataSeq := types.SSZUint64(s.cfg.P2P.MetadataSeq()) - topic, err := p2p.TopicFromMessage(p2p.PingMessageName, core.SlotToEpoch(s.cfg.Chain.CurrentSlot())) + topic, err := p2p.TopicFromMessage(p2p.PingMessageName, coreTime.SlotToEpoch(s.cfg.Chain.CurrentSlot())) if err != nil { return err } diff --git a/beacon-chain/sync/rpc_send_request.go b/beacon-chain/sync/rpc_send_request.go index 648b76dbd6..05f8506132 100644 --- a/beacon-chain/sync/rpc_send_request.go +++ b/beacon-chain/sync/rpc_send_request.go @@ -8,7 +8,7 @@ import ( "github.com/pkg/errors" types "github.com/prysmaticlabs/eth2-types" "github.com/prysmaticlabs/prysm/beacon-chain/blockchain" - "github.com/prysmaticlabs/prysm/beacon-chain/core" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/p2p" p2ptypes "github.com/prysmaticlabs/prysm/beacon-chain/p2p/types" "github.com/prysmaticlabs/prysm/config/params" @@ -28,7 +28,7 @@ func SendBeaconBlocksByRangeRequest( ctx context.Context, chain blockchain.ChainInfoFetcher, p2pProvider p2p.P2P, pid peer.ID, req *pb.BeaconBlocksByRangeRequest, blockProcessor BeaconBlockProcessor, ) ([]block.SignedBeaconBlock, error) { - topic, err := p2p.TopicFromMessage(p2p.BeaconBlocksByRangeMessageName, core.SlotToEpoch(chain.CurrentSlot())) + topic, err := p2p.TopicFromMessage(p2p.BeaconBlocksByRangeMessageName, time.SlotToEpoch(chain.CurrentSlot())) if err != nil { return nil, err } @@ -90,7 +90,7 @@ func SendBeaconBlocksByRootRequest( ctx context.Context, chain blockchain.ChainInfoFetcher, p2pProvider p2p.P2P, pid peer.ID, req *p2ptypes.BeaconBlockByRootsReq, blockProcessor BeaconBlockProcessor, ) ([]block.SignedBeaconBlock, error) { - topic, err := p2p.TopicFromMessage(p2p.BeaconBlocksByRootsMessageName, core.SlotToEpoch(chain.CurrentSlot())) + topic, err := p2p.TopicFromMessage(p2p.BeaconBlocksByRootsMessageName, time.SlotToEpoch(chain.CurrentSlot())) if err != nil { return nil, err } diff --git a/beacon-chain/sync/rpc_status.go b/beacon-chain/sync/rpc_status.go index 34a805e9b6..3929949fa4 100644 --- a/beacon-chain/sync/rpc_status.go +++ b/beacon-chain/sync/rpc_status.go @@ -12,7 +12,7 @@ import ( "github.com/pkg/errors" types "github.com/prysmaticlabs/eth2-types" "github.com/prysmaticlabs/prysm/async" - "github.com/prysmaticlabs/prysm/beacon-chain/core" + coreTime "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/p2p" "github.com/prysmaticlabs/prysm/beacon-chain/p2p/peers" p2ptypes "github.com/prysmaticlabs/prysm/beacon-chain/p2p/types" @@ -85,7 +85,7 @@ func (s *Service) resyncIfBehind() { interval := time.Duration(millisecondsPerEpoch/16) * time.Millisecond async.RunEvery(s.ctx, interval, func() { if s.shouldReSync() { - syncedEpoch := core.SlotToEpoch(s.cfg.Chain.HeadSlot()) + syncedEpoch := coreTime.SlotToEpoch(s.cfg.Chain.HeadSlot()) // Factor number of expected minimum sync peers, to make sure that enough peers are // available to resync (some peers may go away between checking non-finalized peers and // actual resyncing). @@ -93,7 +93,7 @@ func (s *Service) resyncIfBehind() { // Check if the current node is more than 1 epoch behind. if highestEpoch > (syncedEpoch + 1) { log.WithFields(logrus.Fields{ - "currentEpoch": core.SlotToEpoch(s.cfg.Chain.CurrentSlot()), + "currentEpoch": coreTime.SlotToEpoch(s.cfg.Chain.CurrentSlot()), "syncedEpoch": syncedEpoch, "peersEpoch": highestEpoch, }).Info("Fallen behind peers; reverting to initial sync to catch up") @@ -109,8 +109,8 @@ func (s *Service) resyncIfBehind() { // shouldReSync returns true if the node is not syncing and falls behind two epochs. func (s *Service) shouldReSync() bool { - syncedEpoch := core.SlotToEpoch(s.cfg.Chain.HeadSlot()) - currentEpoch := core.SlotToEpoch(s.cfg.Chain.CurrentSlot()) + syncedEpoch := coreTime.SlotToEpoch(s.cfg.Chain.HeadSlot()) + currentEpoch := coreTime.SlotToEpoch(s.cfg.Chain.CurrentSlot()) prevEpoch := types.Epoch(0) if currentEpoch > 1 { prevEpoch = currentEpoch - 1 @@ -139,7 +139,7 @@ func (s *Service) sendRPCStatusRequest(ctx context.Context, id peer.ID) error { HeadRoot: headRoot, HeadSlot: s.cfg.Chain.HeadSlot(), } - topic, err := p2p.TopicFromMessage(p2p.StatusMessageName, core.SlotToEpoch(s.cfg.Chain.CurrentSlot())) + topic, err := p2p.TopicFromMessage(p2p.StatusMessageName, coreTime.SlotToEpoch(s.cfg.Chain.CurrentSlot())) if err != nil { return err } @@ -317,11 +317,11 @@ func (s *Service) validateStatusMessage(ctx context.Context, msg *pb.Status) err if blk == nil || blk.IsNil() { return p2ptypes.ErrGeneric } - if core.SlotToEpoch(blk.Block().Slot()) == msg.FinalizedEpoch { + if coreTime.SlotToEpoch(blk.Block().Slot()) == msg.FinalizedEpoch { return nil } - startSlot, err := core.StartSlot(msg.FinalizedEpoch) + startSlot, err := coreTime.StartSlot(msg.FinalizedEpoch) if err != nil { return p2ptypes.ErrGeneric } diff --git a/beacon-chain/sync/service.go b/beacon-chain/sync/service.go index a6b782ca0f..449a455551 100644 --- a/beacon-chain/sync/service.go +++ b/beacon-chain/sync/service.go @@ -19,11 +19,11 @@ import ( "github.com/prysmaticlabs/prysm/async/abool" "github.com/prysmaticlabs/prysm/async/event" "github.com/prysmaticlabs/prysm/beacon-chain/blockchain" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/feed" blockfeed "github.com/prysmaticlabs/prysm/beacon-chain/core/feed/block" "github.com/prysmaticlabs/prysm/beacon-chain/core/feed/operation" statefeed "github.com/prysmaticlabs/prysm/beacon-chain/core/feed/state" + coreTime "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/db" "github.com/prysmaticlabs/prysm/beacon-chain/operations/attestations" "github.com/prysmaticlabs/prysm/beacon-chain/operations/slashings" @@ -203,7 +203,7 @@ func (s *Service) Stop() error { func (s *Service) Status() error { // If our head slot is on a previous epoch and our peers are reporting their head block are // in the most recent epoch, then we might be out of sync. - if headEpoch := core.SlotToEpoch(s.cfg.Chain.HeadSlot()); headEpoch+1 < core.SlotToEpoch(s.cfg.Chain.CurrentSlot()) && + if headEpoch := coreTime.SlotToEpoch(s.cfg.Chain.HeadSlot()); headEpoch+1 < coreTime.SlotToEpoch(s.cfg.Chain.CurrentSlot()) && headEpoch+1 < s.cfg.P2P.Peers().HighestEpoch() { return errors.New("out of sync") } @@ -264,7 +264,7 @@ func (s *Service) registerHandlers() { log.WithError(err).Error("Could not retrieve current fork digest") return } - currentEpoch := core.SlotToEpoch(core.CurrentSlot(uint64(s.cfg.Chain.GenesisTime().Unix()))) + currentEpoch := coreTime.SlotToEpoch(coreTime.CurrentSlot(uint64(s.cfg.Chain.GenesisTime().Unix()))) s.registerSubscribers(currentEpoch, digest) go s.forkWatcher() return diff --git a/beacon-chain/sync/subscriber.go b/beacon-chain/sync/subscriber.go index ca84b1635d..fa9ab89204 100644 --- a/beacon-chain/sync/subscriber.go +++ b/beacon-chain/sync/subscriber.go @@ -13,7 +13,7 @@ import ( pubsub "github.com/libp2p/go-libp2p-pubsub" types "github.com/prysmaticlabs/eth2-types" "github.com/prysmaticlabs/prysm/beacon-chain/cache" - "github.com/prysmaticlabs/prysm/beacon-chain/core" + coreTime "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/p2p" "github.com/prysmaticlabs/prysm/beacon-chain/p2p/peers" "github.com/prysmaticlabs/prysm/cmd/beacon-chain/flags" @@ -596,7 +596,7 @@ func (s *Service) subscribeDynamicWithSyncSubnets( return } - wantedSubs := s.retrieveActiveSyncSubnets(core.SlotToEpoch(currentSlot)) + wantedSubs := s.retrieveActiveSyncSubnets(coreTime.SlotToEpoch(currentSlot)) // Resize as appropriate. s.reValidateSubscriptions(subscriptions, wantedSubs, topicFormat, digest) diff --git a/beacon-chain/sync/subscriber_beacon_attestation.go b/beacon-chain/sync/subscriber_beacon_attestation.go index 36c525213a..e13c4038b1 100644 --- a/beacon-chain/sync/subscriber_beacon_attestation.go +++ b/beacon-chain/sync/subscriber_beacon_attestation.go @@ -7,7 +7,7 @@ import ( "github.com/pkg/errors" types "github.com/prysmaticlabs/eth2-types" "github.com/prysmaticlabs/prysm/beacon-chain/cache" - "github.com/prysmaticlabs/prysm/beacon-chain/core" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/container/slice" eth "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" @@ -41,7 +41,7 @@ func (s *Service) persistentSubnetIndices() []uint64 { } func (s *Service) aggregatorSubnetIndices(currentSlot types.Slot) []uint64 { - endEpoch := core.SlotToEpoch(currentSlot) + 1 + endEpoch := time.SlotToEpoch(currentSlot) + 1 endSlot := params.BeaconConfig().SlotsPerEpoch.Mul(uint64(endEpoch)) var commIds []uint64 for i := currentSlot; i <= endSlot; i++ { @@ -51,7 +51,7 @@ func (s *Service) aggregatorSubnetIndices(currentSlot types.Slot) []uint64 { } func (s *Service) attesterSubnetIndices(currentSlot types.Slot) []uint64 { - endEpoch := core.SlotToEpoch(currentSlot) + 1 + endEpoch := time.SlotToEpoch(currentSlot) + 1 endSlot := params.BeaconConfig().SlotsPerEpoch.Mul(uint64(endEpoch)) var commIds []uint64 for i := currentSlot; i <= endSlot; i++ { diff --git a/beacon-chain/sync/subscriber_test.go b/beacon-chain/sync/subscriber_test.go index 59991677cb..354bd3b44d 100644 --- a/beacon-chain/sync/subscriber_test.go +++ b/beacon-chain/sync/subscriber_test.go @@ -15,8 +15,8 @@ import ( "github.com/prysmaticlabs/prysm/async/abool" mockChain "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing" "github.com/prysmaticlabs/prysm/beacon-chain/cache" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/signing" + coreTime "github.com/prysmaticlabs/prysm/beacon-chain/core/time" db "github.com/prysmaticlabs/prysm/beacon-chain/db/testing" "github.com/prysmaticlabs/prysm/beacon-chain/operations/slashings" "github.com/prysmaticlabs/prysm/beacon-chain/p2p" @@ -552,7 +552,7 @@ func TestSubscribeWithSyncSubnets_DynamicOK(t *testing.T) { // Empty cache at the end of the test. defer cache.SyncSubnetIDs.EmptyAllCaches() slot := r.cfg.Chain.CurrentSlot() - currEpoch := core.SlotToEpoch(slot) + currEpoch := coreTime.SlotToEpoch(slot) cache.SyncSubnetIDs.AddSyncCommitteeSubnets([]byte("pubkey"), currEpoch, []uint64{0, 1}, 10*time.Second) digest, err := r.currentForkDigest() assert.NoError(t, err) diff --git a/beacon-chain/sync/validate_aggregate_proof.go b/beacon-chain/sync/validate_aggregate_proof.go index b4e60a00c4..bd8058355a 100644 --- a/beacon-chain/sync/validate_aggregate_proof.go +++ b/beacon-chain/sync/validate_aggregate_proof.go @@ -8,12 +8,12 @@ import ( pubsub "github.com/libp2p/go-libp2p-pubsub" "github.com/pkg/errors" types "github.com/prysmaticlabs/eth2-types" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/blocks" "github.com/prysmaticlabs/prysm/beacon-chain/core/feed" "github.com/prysmaticlabs/prysm/beacon-chain/core/feed/operation" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/beacon-chain/core/signing" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/core/transition" "github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/config/features" @@ -145,8 +145,8 @@ func (s *Service) validateAggregatedAtt(ctx context.Context, signed *ethpb.Signe attSlot := signed.Message.Aggregate.Data.Slot // Only advance state if different epoch as the committee can only change on an epoch transition. - if core.SlotToEpoch(attSlot) > core.SlotToEpoch(bs.Slot()) { - startSlot, err := core.StartSlot(core.SlotToEpoch(attSlot)) + if time.SlotToEpoch(attSlot) > time.SlotToEpoch(bs.Slot()) { + startSlot, err := time.StartSlot(time.SlotToEpoch(attSlot)) if err != nil { return pubsub.ValidationIgnore, err } @@ -282,7 +282,7 @@ func validateSelectionIndex( } domain := params.BeaconConfig().DomainSelectionProof - epoch := core.SlotToEpoch(data.Slot) + epoch := time.SlotToEpoch(data.Slot) v, err := bs.ValidatorAtIndex(validatorIndex) if err != nil { @@ -320,7 +320,7 @@ func aggSigSet(s state.ReadOnlyBeaconState, a *ethpb.SignedAggregateAttestationA return nil, err } - epoch := core.SlotToEpoch(a.Message.Aggregate.Data.Slot) + epoch := time.SlotToEpoch(a.Message.Aggregate.Data.Slot) d, err := signing.Domain(s.Fork(), epoch, params.BeaconConfig().DomainAggregateAndProof, s.GenesisValidatorRoot()) if err != nil { return nil, err diff --git a/beacon-chain/sync/validate_beacon_attestation.go b/beacon-chain/sync/validate_beacon_attestation.go index 925ef42b2f..e722c2e1b3 100644 --- a/beacon-chain/sync/validate_beacon_attestation.go +++ b/beacon-chain/sync/validate_beacon_attestation.go @@ -10,11 +10,11 @@ import ( pubsub "github.com/libp2p/go-libp2p-pubsub" "github.com/pkg/errors" types "github.com/prysmaticlabs/eth2-types" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/blocks" "github.com/prysmaticlabs/prysm/beacon-chain/core/feed" "github.com/prysmaticlabs/prysm/beacon-chain/core/feed/operation" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/p2p" "github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/config/features" @@ -171,7 +171,7 @@ func (s *Service) validateUnaggregatedAttTopic(ctx context.Context, a *eth.Attes ctx, span := trace.StartSpan(ctx, "sync.validateUnaggregatedAttTopic") defer span.End() - valCount, err := helpers.ActiveValidatorCount(ctx, bs, core.SlotToEpoch(a.Data.Slot)) + valCount, err := helpers.ActiveValidatorCount(ctx, bs, time.SlotToEpoch(a.Data.Slot)) if err != nil { tracing.AnnotateError(span, err) return pubsub.ValidationIgnore, err diff --git a/beacon-chain/sync/validate_beacon_blocks.go b/beacon-chain/sync/validate_beacon_blocks.go index 95072b5492..05ff5120e8 100644 --- a/beacon-chain/sync/validate_beacon_blocks.go +++ b/beacon-chain/sync/validate_beacon_blocks.go @@ -9,11 +9,11 @@ import ( pubsub "github.com/libp2p/go-libp2p-pubsub" "github.com/pkg/errors" types "github.com/prysmaticlabs/eth2-types" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/blocks" "github.com/prysmaticlabs/prysm/beacon-chain/core/feed" blockfeed "github.com/prysmaticlabs/prysm/beacon-chain/core/feed/block" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" + coreTime "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/core/transition" "github.com/prysmaticlabs/prysm/config/features" "github.com/prysmaticlabs/prysm/config/params" @@ -114,7 +114,7 @@ func (s *Service) validateBeaconBlockPubSub(ctx context.Context, pid peer.ID, ms // MAXIMUM_GOSSIP_CLOCK_DISPARITY in future, we tolerate blocks arriving at max two slots // earlier (SECONDS_PER_SLOT * 2 seconds). Queue such blocks and process them at the right slot. genesisTime := uint64(s.cfg.Chain.GenesisTime().Unix()) - if err := core.VerifySlotTime(genesisTime, blk.Block().Slot(), earlyBlockProcessingTolerance); err != nil { + if err := coreTime.VerifySlotTime(genesisTime, blk.Block().Slot(), earlyBlockProcessingTolerance); err != nil { log.WithError(err).WithField("blockSlot", blk.Block().Slot()).Debug("Ignored block") return pubsub.ValidationIgnore, nil } @@ -125,7 +125,7 @@ func (s *Service) validateBeaconBlockPubSub(ctx context.Context, pid peer.ID, ms return pubsub.ValidationIgnore, nil } - startSlot, err := core.StartSlot(s.cfg.Chain.FinalizedCheckpt().Epoch) + startSlot, err := coreTime.StartSlot(s.cfg.Chain.FinalizedCheckpt().Epoch) if err != nil { log.WithError(err).WithField("blockSlot", blk.Block().Slot()).Debug("Ignored block") return pubsub.ValidationIgnore, nil @@ -168,7 +168,7 @@ func (s *Service) validateBeaconBlockPubSub(ctx context.Context, pid peer.ID, ms msg.ValidatorData = blk.Proto() // Used in downstream subscriber // Log the arrival time of the accepted block - startTime, err := core.SlotToTime(genesisTime, blk.Block().Slot()) + startTime, err := coreTime.SlotToTime(genesisTime, blk.Block().Slot()) if err != nil { return pubsub.ValidationIgnore, err } @@ -266,7 +266,7 @@ func (s *Service) setBadBlock(ctx context.Context, root [32]byte) { // This captures metrics for block arrival time by subtracts slot start time. func captureArrivalTimeMetric(genesisTime uint64, currentSlot types.Slot) error { - startTime, err := core.SlotToTime(genesisTime, currentSlot) + startTime, err := coreTime.SlotToTime(genesisTime, currentSlot) if err != nil { return err } @@ -281,7 +281,7 @@ func captureArrivalTimeMetric(genesisTime uint64, currentSlot types.Slot) error // returns true if the corresponding block should be queued and false if // the block should be processed immediately. func isBlockQueueable(genesisTime uint64, slot types.Slot, receivedTime time.Time) bool { - slotTime, err := core.SlotToTime(genesisTime, slot) + slotTime, err := coreTime.SlotToTime(genesisTime, slot) if err != nil { return false } diff --git a/beacon-chain/sync/validate_beacon_blocks_test.go b/beacon-chain/sync/validate_beacon_blocks_test.go index 200bb1e38b..b5eb13477a 100644 --- a/beacon-chain/sync/validate_beacon_blocks_test.go +++ b/beacon-chain/sync/validate_beacon_blocks_test.go @@ -15,9 +15,9 @@ import ( types "github.com/prysmaticlabs/eth2-types" "github.com/prysmaticlabs/prysm/async/abool" mock "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/beacon-chain/core/signing" + coreTime "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/core/transition" dbtest "github.com/prysmaticlabs/prysm/beacon-chain/db/testing" "github.com/prysmaticlabs/prysm/beacon-chain/operations/attestations" @@ -341,7 +341,7 @@ func TestValidateBeaconBlockPubSub_WithLookahead(t *testing.T) { require.NoError(t, db.SaveStateSummary(ctx, ðpb.StateSummary{Root: bRoot[:]})) copied := beaconState.Copy() // The next block is only 1 epoch ahead so as to not induce a new seed. - blkSlot := params.BeaconConfig().SlotsPerEpoch.Mul(uint64(core.NextEpoch(copied))) + blkSlot := params.BeaconConfig().SlotsPerEpoch.Mul(uint64(coreTime.NextEpoch(copied))) copied, err = transition.ProcessSlots(context.Background(), copied, blkSlot) require.NoError(t, err) proposerIdx, err := helpers.BeaconProposerIndex(ctx, copied) diff --git a/beacon-chain/sync/validate_proposer_slashing_test.go b/beacon-chain/sync/validate_proposer_slashing_test.go index 50ddc70b6c..26d2da36ab 100644 --- a/beacon-chain/sync/validate_proposer_slashing_test.go +++ b/beacon-chain/sync/validate_proposer_slashing_test.go @@ -13,8 +13,8 @@ import ( types "github.com/prysmaticlabs/eth2-types" "github.com/prysmaticlabs/go-bitfield" mock "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/signing" + coreTime "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/p2p" p2ptest "github.com/prysmaticlabs/prysm/beacon-chain/p2p/testing" "github.com/prysmaticlabs/prysm/beacon-chain/state" @@ -76,7 +76,7 @@ func setupValidProposerSlashing(t *testing.T) (*ethpb.ProposerSlashing, state.Be BodyRoot: someRoot[:], }, } - header1.Signature, err = signing.ComputeDomainAndSign(state, core.CurrentEpoch(state), header1.Header, params.BeaconConfig().DomainBeaconProposer, privKey) + header1.Signature, err = signing.ComputeDomainAndSign(state, coreTime.CurrentEpoch(state), header1.Header, params.BeaconConfig().DomainBeaconProposer, privKey) require.NoError(t, err) header2 := ðpb.SignedBeaconBlockHeader{ @@ -88,7 +88,7 @@ func setupValidProposerSlashing(t *testing.T) (*ethpb.ProposerSlashing, state.Be BodyRoot: someRoot2[:], }, } - header2.Signature, err = signing.ComputeDomainAndSign(state, core.CurrentEpoch(state), header2.Header, params.BeaconConfig().DomainBeaconProposer, privKey) + header2.Signature, err = signing.ComputeDomainAndSign(state, coreTime.CurrentEpoch(state), header2.Header, params.BeaconConfig().DomainBeaconProposer, privKey) require.NoError(t, err) slashing := ðpb.ProposerSlashing{ diff --git a/beacon-chain/sync/validate_sync_committee_message_test.go b/beacon-chain/sync/validate_sync_committee_message_test.go index c915518e77..ae2555fccc 100644 --- a/beacon-chain/sync/validate_sync_committee_message_test.go +++ b/beacon-chain/sync/validate_sync_committee_message_test.go @@ -13,8 +13,8 @@ import ( pubsub_pb "github.com/libp2p/go-libp2p-pubsub/pb" types "github.com/prysmaticlabs/eth2-types" mockChain "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/signing" + coreTime "github.com/prysmaticlabs/prysm/beacon-chain/core/time" testingDB "github.com/prysmaticlabs/prysm/beacon-chain/db/testing" "github.com/prysmaticlabs/prysm/beacon-chain/p2p" "github.com/prysmaticlabs/prysm/beacon-chain/p2p/encoder" @@ -226,7 +226,7 @@ func TestService_ValidateSyncCommitteeMessage(t *testing.T) { msg.Signature = emptySig[:] msg.BlockRoot = headRoot[:] msg.ValidatorIndex = types.ValidatorIndex(chosenVal) - msg.Slot = core.PrevSlot(hState.Slot()) + msg.Slot = coreTime.PrevSlot(hState.Slot()) // Set Bad Topic and Subnet digest, err := s.currentForkDigest() @@ -274,7 +274,7 @@ func TestService_ValidateSyncCommitteeMessage(t *testing.T) { msg.Signature = emptySig[:] msg.BlockRoot = headRoot[:] msg.ValidatorIndex = types.ValidatorIndex(chosenVal) - msg.Slot = core.PrevSlot(hState.Slot()) + msg.Slot = coreTime.PrevSlot(hState.Slot()) digest, err := s.currentForkDigest() assert.NoError(t, err) @@ -317,9 +317,9 @@ func TestService_ValidateSyncCommitteeMessage(t *testing.T) { msg.Signature = emptySig[:] msg.BlockRoot = headRoot[:] msg.ValidatorIndex = types.ValidatorIndex(chosenVal) - msg.Slot = core.PrevSlot(hState.Slot()) + msg.Slot = coreTime.PrevSlot(hState.Slot()) - d, err := signing.Domain(hState.Fork(), core.SlotToEpoch(hState.Slot()), params.BeaconConfig().DomainSyncCommittee, hState.GenesisValidatorRoot()) + d, err := signing.Domain(hState.Fork(), coreTime.SlotToEpoch(hState.Slot()), params.BeaconConfig().DomainSyncCommittee, hState.GenesisValidatorRoot()) assert.NoError(t, err) subCommitteeSize := params.BeaconConfig().SyncCommitteeSize / params.BeaconConfig().SyncCommitteeSubnetCount s.cfg.Chain = &mockChain.ChainService{ @@ -370,7 +370,7 @@ func TestService_ValidateSyncCommitteeMessage(t *testing.T) { numOfVals := hState.NumValidators() chosenVal := numOfVals - 10 - d, err := signing.Domain(hState.Fork(), core.SlotToEpoch(hState.Slot()), params.BeaconConfig().DomainSyncCommittee, hState.GenesisValidatorRoot()) + d, err := signing.Domain(hState.Fork(), coreTime.SlotToEpoch(hState.Slot()), params.BeaconConfig().DomainSyncCommittee, hState.GenesisValidatorRoot()) assert.NoError(t, err) rawBytes := p2ptypes.SSZBytes(headRoot[:]) sigRoot, err := signing.ComputeSigningRoot(&rawBytes, d) @@ -387,7 +387,7 @@ func TestService_ValidateSyncCommitteeMessage(t *testing.T) { msg.Signature = keys[chosenVal].Sign(sigRoot[:]).Marshal() msg.BlockRoot = headRoot[:] msg.ValidatorIndex = types.ValidatorIndex(chosenVal) - msg.Slot = core.PrevSlot(hState.Slot()) + msg.Slot = coreTime.PrevSlot(hState.Slot()) // Set Topic and Subnet digest, err := s.currentForkDigest() diff --git a/beacon-chain/sync/validate_sync_contribution_proof_test.go b/beacon-chain/sync/validate_sync_contribution_proof_test.go index ff19a5dac2..5f49f144a5 100644 --- a/beacon-chain/sync/validate_sync_contribution_proof_test.go +++ b/beacon-chain/sync/validate_sync_contribution_proof_test.go @@ -13,9 +13,9 @@ import ( types "github.com/prysmaticlabs/eth2-types" "github.com/prysmaticlabs/go-bitfield" mockChain "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/altair" "github.com/prysmaticlabs/prysm/beacon-chain/core/signing" + coreTime "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/core/transition" "github.com/prysmaticlabs/prysm/beacon-chain/db" testingDB "github.com/prysmaticlabs/prysm/beacon-chain/db/testing" @@ -325,7 +325,7 @@ func TestService_ValidateSyncContributionAndProof(t *testing.T) { for _, p := range coms { idx, ok := hState.ValidatorIndexByPubkey(bytesutil.ToBytes48(p)) assert.Equal(t, true, ok) - rt, err := syncSelectionProofSigningRoot(hState, core.PrevSlot(hState.Slot()), types.CommitteeIndex(i)) + rt, err := syncSelectionProofSigningRoot(hState, coreTime.PrevSlot(hState.Slot()), types.CommitteeIndex(i)) assert.NoError(t, err) sig := keys[idx].Sign(rt[:]) isAggregator, err := altair.IsSyncCommitteeAggregator(sig.Marshal()) @@ -382,7 +382,7 @@ func TestService_ValidateSyncContributionAndProof(t *testing.T) { for _, p := range coms { idx, ok := hState.ValidatorIndexByPubkey(bytesutil.ToBytes48(p)) assert.Equal(t, true, ok) - rt, err := syncSelectionProofSigningRoot(hState, core.PrevSlot(hState.Slot()), types.CommitteeIndex(i)) + rt, err := syncSelectionProofSigningRoot(hState, coreTime.PrevSlot(hState.Slot()), types.CommitteeIndex(i)) assert.NoError(t, err) sig := keys[idx].Sign(rt[:]) isAggregator, err := altair.IsSyncCommitteeAggregator(sig.Marshal()) @@ -449,7 +449,7 @@ func TestService_ValidateSyncContributionAndProof(t *testing.T) { for _, p := range coms { idx, ok := hState.ValidatorIndexByPubkey(bytesutil.ToBytes48(p)) assert.Equal(t, true, ok) - rt, err := syncSelectionProofSigningRoot(hState, core.PrevSlot(hState.Slot()), types.CommitteeIndex(i)) + rt, err := syncSelectionProofSigningRoot(hState, coreTime.PrevSlot(hState.Slot()), types.CommitteeIndex(i)) assert.NoError(t, err) sig := keys[idx].Sign(rt[:]) isAggregator, err := altair.IsSyncCommitteeAggregator(sig.Marshal()) @@ -459,7 +459,7 @@ func TestService_ValidateSyncContributionAndProof(t *testing.T) { pubkey = keys[idx].PublicKey().Marshal() msg.Message.AggregatorIndex = idx msg.Message.SelectionProof = sig.Marshal() - msg.Message.Contribution.Slot = core.PrevSlot(hState.Slot()) + msg.Message.Contribution.Slot = coreTime.PrevSlot(hState.Slot()) msg.Message.Contribution.SubcommitteeIndex = i msg.Message.Contribution.Signature = infiniteSig[:] msg.Message.Contribution.BlockRoot = headRoot[:] @@ -470,7 +470,7 @@ func TestService_ValidateSyncContributionAndProof(t *testing.T) { } } } - d, err := signing.Domain(hState.Fork(), core.SlotToEpoch(core.PrevSlot(hState.Slot())), params.BeaconConfig().DomainSyncCommitteeSelectionProof, hState.GenesisValidatorRoot()) + d, err := signing.Domain(hState.Fork(), coreTime.SlotToEpoch(coreTime.PrevSlot(hState.Slot())), params.BeaconConfig().DomainSyncCommitteeSelectionProof, hState.GenesisValidatorRoot()) require.NoError(t, err) subCommitteeSize := params.BeaconConfig().SyncCommitteeSize / params.BeaconConfig().SyncCommitteeSubnetCount s.cfg.Chain = &mockChain.ChainService{ @@ -527,7 +527,7 @@ func TestService_ValidateSyncContributionAndProof(t *testing.T) { for _, p := range coms { idx, ok := hState.ValidatorIndexByPubkey(bytesutil.ToBytes48(p)) assert.Equal(t, true, ok) - rt, err := syncSelectionProofSigningRoot(hState, core.PrevSlot(hState.Slot()), types.CommitteeIndex(i)) + rt, err := syncSelectionProofSigningRoot(hState, coreTime.PrevSlot(hState.Slot()), types.CommitteeIndex(i)) assert.NoError(t, err) sig := keys[idx].Sign(rt[:]) isAggregator, err := altair.IsSyncCommitteeAggregator(sig.Marshal()) @@ -538,7 +538,7 @@ func TestService_ValidateSyncContributionAndProof(t *testing.T) { badSig := keys[idx].Sign(junkRoot[:]) msg.Message.AggregatorIndex = idx msg.Message.SelectionProof = sig.Marshal() - msg.Message.Contribution.Slot = core.PrevSlot(hState.Slot()) + msg.Message.Contribution.Slot = coreTime.PrevSlot(hState.Slot()) msg.Message.Contribution.SubcommitteeIndex = i msg.Message.Contribution.Signature = badSig.Marshal() msg.Message.Contribution.BlockRoot = headRoot[:] @@ -546,7 +546,7 @@ func TestService_ValidateSyncContributionAndProof(t *testing.T) { msg.Message.Contribution.AggregationBits.SetBitAt(1, true) msg.Signature = infiniteSig[:] - d, err := signing.Domain(hState.Fork(), core.SlotToEpoch(core.PrevSlot(hState.Slot())), params.BeaconConfig().DomainContributionAndProof, hState.GenesisValidatorRoot()) + d, err := signing.Domain(hState.Fork(), coreTime.SlotToEpoch(coreTime.PrevSlot(hState.Slot())), params.BeaconConfig().DomainContributionAndProof, hState.GenesisValidatorRoot()) assert.NoError(t, err) sigRoot, err := signing.ComputeSigningRoot(msg.Message, d) assert.NoError(t, err) @@ -603,7 +603,7 @@ func TestService_ValidateSyncContributionAndProof(t *testing.T) { assert.NoError(t, err) sc, err := hState.CurrentSyncCommittee() assert.NoError(t, err) - cd, err := signing.Domain(hState.Fork(), core.SlotToEpoch(core.PrevSlot(hState.Slot())), params.BeaconConfig().DomainContributionAndProof, hState.GenesisValidatorRoot()) + cd, err := signing.Domain(hState.Fork(), coreTime.SlotToEpoch(coreTime.PrevSlot(hState.Slot())), params.BeaconConfig().DomainContributionAndProof, hState.GenesisValidatorRoot()) assert.NoError(t, err) for i := uint64(0); i < params.BeaconConfig().SyncCommitteeSubnetCount; i++ { coms, err := altair.SyncSubCommitteePubkeys(sc, types.CommitteeIndex(i)) @@ -611,7 +611,7 @@ func TestService_ValidateSyncContributionAndProof(t *testing.T) { for _, p := range coms { idx, ok := hState.ValidatorIndexByPubkey(bytesutil.ToBytes48(p)) assert.Equal(t, true, ok) - rt, err := syncSelectionProofSigningRoot(hState, core.PrevSlot(hState.Slot()), types.CommitteeIndex(i)) + rt, err := syncSelectionProofSigningRoot(hState, coreTime.PrevSlot(hState.Slot()), types.CommitteeIndex(i)) assert.NoError(t, err) sig := keys[idx].Sign(rt[:]) isAggregator, err := altair.IsSyncCommitteeAggregator(sig.Marshal()) @@ -620,7 +620,7 @@ func TestService_ValidateSyncContributionAndProof(t *testing.T) { infiniteSig := [96]byte{0xC0} msg.Message.AggregatorIndex = idx msg.Message.SelectionProof = sig.Marshal() - msg.Message.Contribution.Slot = core.PrevSlot(hState.Slot()) + msg.Message.Contribution.Slot = coreTime.PrevSlot(hState.Slot()) msg.Message.Contribution.SubcommitteeIndex = i msg.Message.Contribution.Signature = infiniteSig[:] msg.Message.Contribution.BlockRoot = headRoot[:] @@ -635,7 +635,7 @@ func TestService_ValidateSyncContributionAndProof(t *testing.T) { } } - d, err := signing.Domain(hState.Fork(), core.SlotToEpoch(core.PrevSlot(hState.Slot())), params.BeaconConfig().DomainSyncCommitteeSelectionProof, hState.GenesisValidatorRoot()) + d, err := signing.Domain(hState.Fork(), coreTime.SlotToEpoch(coreTime.PrevSlot(hState.Slot())), params.BeaconConfig().DomainSyncCommitteeSelectionProof, hState.GenesisValidatorRoot()) require.NoError(t, err) subCommitteeSize := params.BeaconConfig().SyncCommitteeSize / params.BeaconConfig().SyncCommitteeSubnetCount s.cfg.Chain = &mockChain.ChainService{ @@ -687,9 +687,9 @@ func TestService_ValidateSyncContributionAndProof(t *testing.T) { assert.NoError(t, err) sc, err := hState.CurrentSyncCommittee() assert.NoError(t, err) - cd, err := signing.Domain(hState.Fork(), core.SlotToEpoch(core.PrevSlot(hState.Slot())), params.BeaconConfig().DomainContributionAndProof, hState.GenesisValidatorRoot()) + cd, err := signing.Domain(hState.Fork(), coreTime.SlotToEpoch(coreTime.PrevSlot(hState.Slot())), params.BeaconConfig().DomainContributionAndProof, hState.GenesisValidatorRoot()) assert.NoError(t, err) - d, err := signing.Domain(hState.Fork(), core.SlotToEpoch(hState.Slot()), params.BeaconConfig().DomainSyncCommittee, hState.GenesisValidatorRoot()) + d, err := signing.Domain(hState.Fork(), coreTime.SlotToEpoch(hState.Slot()), params.BeaconConfig().DomainSyncCommittee, hState.GenesisValidatorRoot()) assert.NoError(t, err) var pubkeys [][]byte for i := uint64(0); i < params.BeaconConfig().SyncCommitteeSubnetCount; i++ { @@ -699,7 +699,7 @@ func TestService_ValidateSyncContributionAndProof(t *testing.T) { for _, p := range coms { idx, ok := hState.ValidatorIndexByPubkey(bytesutil.ToBytes48(p)) assert.Equal(t, true, ok) - rt, err := syncSelectionProofSigningRoot(hState, core.PrevSlot(hState.Slot()), types.CommitteeIndex(i)) + rt, err := syncSelectionProofSigningRoot(hState, coreTime.PrevSlot(hState.Slot()), types.CommitteeIndex(i)) assert.NoError(t, err) sig := keys[idx].Sign(rt[:]) isAggregator, err := altair.IsSyncCommitteeAggregator(sig.Marshal()) @@ -707,7 +707,7 @@ func TestService_ValidateSyncContributionAndProof(t *testing.T) { if isAggregator { msg.Message.AggregatorIndex = idx msg.Message.SelectionProof = sig.Marshal() - msg.Message.Contribution.Slot = core.PrevSlot(hState.Slot()) + msg.Message.Contribution.Slot = coreTime.PrevSlot(hState.Slot()) msg.Message.Contribution.SubcommitteeIndex = i msg.Message.Contribution.BlockRoot = headRoot[:] msg.Message.Contribution.AggregationBits = bitfield.NewBitvector128() @@ -730,7 +730,7 @@ func TestService_ValidateSyncContributionAndProof(t *testing.T) { } } - pd, err := signing.Domain(hState.Fork(), core.SlotToEpoch(core.PrevSlot(hState.Slot())), params.BeaconConfig().DomainSyncCommitteeSelectionProof, hState.GenesisValidatorRoot()) + pd, err := signing.Domain(hState.Fork(), coreTime.SlotToEpoch(coreTime.PrevSlot(hState.Slot())), params.BeaconConfig().DomainSyncCommitteeSelectionProof, hState.GenesisValidatorRoot()) require.NoError(t, err) subCommitteeSize := params.BeaconConfig().SyncCommitteeSize / params.BeaconConfig().SyncCommitteeSubnetCount s.cfg.Chain = &mockChain.ChainService{ @@ -783,9 +783,9 @@ func TestService_ValidateSyncContributionAndProof(t *testing.T) { assert.NoError(t, err) sc, err := hState.CurrentSyncCommittee() assert.NoError(t, err) - cd, err := signing.Domain(hState.Fork(), core.SlotToEpoch(core.PrevSlot(hState.Slot())), params.BeaconConfig().DomainContributionAndProof, hState.GenesisValidatorRoot()) + cd, err := signing.Domain(hState.Fork(), coreTime.SlotToEpoch(coreTime.PrevSlot(hState.Slot())), params.BeaconConfig().DomainContributionAndProof, hState.GenesisValidatorRoot()) assert.NoError(t, err) - d, err := signing.Domain(hState.Fork(), core.SlotToEpoch(hState.Slot()), params.BeaconConfig().DomainSyncCommittee, hState.GenesisValidatorRoot()) + d, err := signing.Domain(hState.Fork(), coreTime.SlotToEpoch(hState.Slot()), params.BeaconConfig().DomainSyncCommittee, hState.GenesisValidatorRoot()) assert.NoError(t, err) var pubkeys [][]byte for i := uint64(0); i < params.BeaconConfig().SyncCommitteeSubnetCount; i++ { @@ -795,7 +795,7 @@ func TestService_ValidateSyncContributionAndProof(t *testing.T) { for _, p := range coms { idx, ok := hState.ValidatorIndexByPubkey(bytesutil.ToBytes48(p)) assert.Equal(t, true, ok) - rt, err := syncSelectionProofSigningRoot(hState, core.PrevSlot(hState.Slot()), types.CommitteeIndex(i)) + rt, err := syncSelectionProofSigningRoot(hState, coreTime.PrevSlot(hState.Slot()), types.CommitteeIndex(i)) assert.NoError(t, err) sig := keys[idx].Sign(rt[:]) isAggregator, err := altair.IsSyncCommitteeAggregator(sig.Marshal()) @@ -803,7 +803,7 @@ func TestService_ValidateSyncContributionAndProof(t *testing.T) { if isAggregator { msg.Message.AggregatorIndex = idx msg.Message.SelectionProof = sig.Marshal() - msg.Message.Contribution.Slot = core.PrevSlot(hState.Slot()) + msg.Message.Contribution.Slot = coreTime.PrevSlot(hState.Slot()) msg.Message.Contribution.SubcommitteeIndex = i msg.Message.Contribution.BlockRoot = headRoot[:] msg.Message.Contribution.AggregationBits = bitfield.NewBitvector128() @@ -828,7 +828,7 @@ func TestService_ValidateSyncContributionAndProof(t *testing.T) { } } - pd, err := signing.Domain(hState.Fork(), core.SlotToEpoch(core.PrevSlot(hState.Slot())), params.BeaconConfig().DomainSyncCommitteeSelectionProof, hState.GenesisValidatorRoot()) + pd, err := signing.Domain(hState.Fork(), coreTime.SlotToEpoch(coreTime.PrevSlot(hState.Slot())), params.BeaconConfig().DomainSyncCommitteeSelectionProof, hState.GenesisValidatorRoot()) require.NoError(t, err) subCommitteeSize := params.BeaconConfig().SyncCommitteeSize / params.BeaconConfig().SyncCommitteeSubnetCount s.cfg.Chain = &mockChain.ChainService{ @@ -916,7 +916,7 @@ func fillUpBlocksAndState(ctx context.Context, t *testing.T, beaconDB db.Databas } func syncSelectionProofSigningRoot(st state.BeaconState, slot types.Slot, comIdx types.CommitteeIndex) ([32]byte, error) { - dom, err := signing.Domain(st.Fork(), core.SlotToEpoch(slot), params.BeaconConfig().DomainSyncCommitteeSelectionProof, st.GenesisValidatorRoot()) + dom, err := signing.Domain(st.Fork(), coreTime.SlotToEpoch(slot), params.BeaconConfig().DomainSyncCommitteeSelectionProof, st.GenesisValidatorRoot()) if err != nil { return [32]byte{}, err } diff --git a/beacon-chain/sync/validate_voluntary_exit_test.go b/beacon-chain/sync/validate_voluntary_exit_test.go index f9df5b9469..5d701bbea1 100644 --- a/beacon-chain/sync/validate_voluntary_exit_test.go +++ b/beacon-chain/sync/validate_voluntary_exit_test.go @@ -11,8 +11,8 @@ import ( pubsub "github.com/libp2p/go-libp2p-pubsub" pubsubpb "github.com/libp2p/go-libp2p-pubsub/pb" mock "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/signing" + coreTime "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/p2p" p2ptest "github.com/prysmaticlabs/prysm/beacon-chain/p2p/testing" "github.com/prysmaticlabs/prysm/beacon-chain/state" @@ -53,7 +53,7 @@ func setupValidExit(t *testing.T) (*ethpb.SignedVoluntaryExit, state.BeaconState priv, err := bls.RandKey() require.NoError(t, err) - exit.Signature, err = signing.ComputeDomainAndSign(state, core.CurrentEpoch(state), exit.Exit, params.BeaconConfig().DomainVoluntaryExit, priv) + exit.Signature, err = signing.ComputeDomainAndSign(state, coreTime.CurrentEpoch(state), exit.Exit, params.BeaconConfig().DomainVoluntaryExit, priv) require.NoError(t, err) val, err := state.ValidatorAtIndex(0) diff --git a/network/forks/BUILD.bazel b/network/forks/BUILD.bazel index afe15257d5..f0d9d447be 100644 --- a/network/forks/BUILD.bazel +++ b/network/forks/BUILD.bazel @@ -6,8 +6,8 @@ go_library( importpath = "github.com/prysmaticlabs/prysm/network/forks", visibility = ["//visibility:public"], deps = [ - "//beacon-chain/core:go_default_library", "//beacon-chain/core/signing:go_default_library", + "//beacon-chain/core/time:go_default_library", "//config/params:go_default_library", "//encoding/bytesutil:go_default_library", "//proto/prysm/v1alpha1:go_default_library", diff --git a/network/forks/fork.go b/network/forks/fork.go index 4041aa9a03..9f91bacc25 100644 --- a/network/forks/fork.go +++ b/network/forks/fork.go @@ -8,8 +8,8 @@ import ( "github.com/pkg/errors" types "github.com/prysmaticlabs/eth2-types" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/signing" + coreTime "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/encoding/bytesutil" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" @@ -23,8 +23,8 @@ func IsForkNextEpoch(genesisTime time.Time, genesisValidatorsRoot []byte) (bool, if len(genesisValidatorsRoot) == 0 { return false, errors.New("genesis validators root is not set") } - currentSlot := core.SlotsSince(genesisTime) - currentEpoch := core.SlotToEpoch(currentSlot) + currentSlot := coreTime.SlotsSince(genesisTime) + currentEpoch := coreTime.SlotToEpoch(currentSlot) fSchedule := params.BeaconConfig().ForkVersionSchedule scheduledForks := SortedForkVersions(fSchedule) isForkEpoch := false @@ -64,8 +64,8 @@ func CreateForkDigest( if len(genesisValidatorsRoot) == 0 { return [4]byte{}, errors.New("genesis validators root is not set") } - currentSlot := core.SlotsSince(genesisTime) - currentEpoch := core.SlotToEpoch(currentSlot) + currentSlot := coreTime.SlotsSince(genesisTime) + currentEpoch := coreTime.SlotToEpoch(currentSlot) forkData, err := Fork(currentEpoch) if err != nil { diff --git a/testing/endtoend/evaluators/BUILD.bazel b/testing/endtoend/evaluators/BUILD.bazel index 7278a8593b..4b4c53555c 100644 --- a/testing/endtoend/evaluators/BUILD.bazel +++ b/testing/endtoend/evaluators/BUILD.bazel @@ -18,9 +18,9 @@ go_library( importpath = "github.com/prysmaticlabs/prysm/testing/endtoend/evaluators", visibility = ["//testing/endtoend:__subpackages__"], deps = [ - "//beacon-chain/core:go_default_library", "//beacon-chain/core/helpers:go_default_library", "//beacon-chain/core/signing:go_default_library", + "//beacon-chain/core/time:go_default_library", "//beacon-chain/p2p:go_default_library", "//config/params:go_default_library", "//container/slice:go_default_library", diff --git a/testing/endtoend/evaluators/fork.go b/testing/endtoend/evaluators/fork.go index b44e3eba61..42357a7080 100644 --- a/testing/endtoend/evaluators/fork.go +++ b/testing/endtoend/evaluators/fork.go @@ -4,7 +4,7 @@ import ( "context" "github.com/pkg/errors" - "github.com/prysmaticlabs/prysm/beacon-chain/core" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" wrapperv2 "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/wrapper" "github.com/prysmaticlabs/prysm/testing/endtoend/helpers" @@ -29,7 +29,7 @@ func forkOccurs(conns ...*grpc.ClientConn) error { if err != nil { return errors.Wrap(err, "failed to get stream") } - fSlot, err := core.StartSlot(helpers.AltairE2EForkEpoch) + fSlot, err := time.StartSlot(helpers.AltairE2EForkEpoch) if err != nil { return err } diff --git a/testing/endtoend/evaluators/validator.go b/testing/endtoend/evaluators/validator.go index a22cb5e43c..46cb61bd79 100644 --- a/testing/endtoend/evaluators/validator.go +++ b/testing/endtoend/evaluators/validator.go @@ -5,7 +5,7 @@ import ( "fmt" "github.com/pkg/errors" - "github.com/prysmaticlabs/prysm/beacon-chain/core" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/config/params" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/testing/endtoend/helpers" @@ -126,8 +126,8 @@ func validatorsSyncParticipation(conns ...*grpc.ClientConn) error { if err != nil { return errors.Wrap(err, "failed to get genesis data") } - currSlot := core.CurrentSlot(uint64(genesis.GenesisTime.AsTime().Unix())) - currEpoch := core.SlotToEpoch(currSlot) + currSlot := time.CurrentSlot(uint64(genesis.GenesisTime.AsTime().Unix())) + currEpoch := time.SlotToEpoch(currSlot) lowestBound := currEpoch - 1 if lowestBound < helpers.AltairE2EForkEpoch { @@ -145,7 +145,7 @@ func validatorsSyncParticipation(conns ...*grpc.ClientConn) error { if blk.Block == nil || blk.Block.Body == nil || blk.Block.Body.SyncAggregate == nil { return errors.New("nil block provided") } - forkSlot, err := core.StartSlot(helpers.AltairE2EForkEpoch) + forkSlot, err := time.StartSlot(helpers.AltairE2EForkEpoch) if err != nil { return err } @@ -174,7 +174,7 @@ func validatorsSyncParticipation(conns ...*grpc.ClientConn) error { if blk.Block == nil || blk.Block.Body == nil || blk.Block.Body.SyncAggregate == nil { return errors.New("nil block provided") } - forkSlot, err := core.StartSlot(helpers.AltairE2EForkEpoch) + forkSlot, err := time.StartSlot(helpers.AltairE2EForkEpoch) if err != nil { return err } diff --git a/testing/fuzz/BUILD.bazel b/testing/fuzz/BUILD.bazel index cc750b0049..d278263547 100644 --- a/testing/fuzz/BUILD.bazel +++ b/testing/fuzz/BUILD.bazel @@ -146,7 +146,7 @@ go_fuzz_test( "//proto/prysm/v1alpha1:go_default_library", "//beacon-chain/core/transition:go_default_library", "//beacon-chain/core/helpers:go_default_library", - "//beacon-chain/core:go_default_library", + "//beacon-chain/core/time:go_default_library", "//config/params:go_default_library", ] + COMMON_DEPS, ) @@ -168,7 +168,7 @@ go_library( "//beacon-chain/blockchain:go_default_library", "//beacon-chain/blockchain/testing:go_default_library", "//beacon-chain/cache:go_default_library", - "//beacon-chain/core:go_default_library", + "//beacon-chain/core/time:go_default_library", "//beacon-chain/core/blocks:go_default_library", "//beacon-chain/core/helpers:go_default_library", "//beacon-chain/core/transition:go_default_library", diff --git a/testing/fuzz/state_fuzz.go b/testing/fuzz/state_fuzz.go index f49ff7ea9f..8c274fc0dd 100644 --- a/testing/fuzz/state_fuzz.go +++ b/testing/fuzz/state_fuzz.go @@ -4,7 +4,7 @@ import ( "context" "fmt" - "github.com/prysmaticlabs/prysm/beacon-chain/core" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" stateutil "github.com/prysmaticlabs/prysm/beacon-chain/core/transition" v1 "github.com/prysmaticlabs/prysm/beacon-chain/state/v1" "github.com/prysmaticlabs/prysm/config/features" @@ -30,8 +30,8 @@ func BeaconStateFuzz(input []byte) { panic(err) } validateStateHTR(s) - nextEpoch := core.SlotToEpoch(s.Slot()) + 1 - slot, err := core.StartSlot(nextEpoch) + nextEpoch := time.SlotToEpoch(s.Slot()) + 1 + slot, err := time.StartSlot(nextEpoch) if err != nil { return } diff --git a/testing/slasher/simulator/BUILD.bazel b/testing/slasher/simulator/BUILD.bazel index 6be2b0898d..699b6dc82c 100644 --- a/testing/slasher/simulator/BUILD.bazel +++ b/testing/slasher/simulator/BUILD.bazel @@ -15,11 +15,11 @@ go_library( deps = [ "//async/event:go_default_library", "//beacon-chain/blockchain:go_default_library", - "//beacon-chain/core:go_default_library", "//beacon-chain/core/feed:go_default_library", "//beacon-chain/core/feed/state:go_default_library", "//beacon-chain/core/helpers:go_default_library", "//beacon-chain/core/signing:go_default_library", + "//beacon-chain/core/time:go_default_library", "//beacon-chain/db:go_default_library", "//beacon-chain/operations/slashings:go_default_library", "//beacon-chain/slasher:go_default_library", diff --git a/testing/slasher/simulator/attestation_generator.go b/testing/slasher/simulator/attestation_generator.go index 59082391a9..7ca9511356 100644 --- a/testing/slasher/simulator/attestation_generator.go +++ b/testing/slasher/simulator/attestation_generator.go @@ -5,9 +5,9 @@ import ( "math" types "github.com/prysmaticlabs/eth2-types" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/beacon-chain/core/signing" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/crypto/bls" @@ -22,7 +22,7 @@ func (s *Simulator) generateAttestationsForSlot( ) ([]*ethpb.IndexedAttestation, []*ethpb.AttesterSlashing, error) { attestations := make([]*ethpb.IndexedAttestation, 0) slashings := make([]*ethpb.AttesterSlashing, 0) - currentEpoch := core.SlotToEpoch(slot) + currentEpoch := time.SlotToEpoch(slot) committeesPerSlot := helpers.SlotCommitteeCount(s.srvConfig.Params.NumValidators) valsPerCommittee := s.srvConfig.Params.NumValidators / diff --git a/testing/slasher/simulator/simulator.go b/testing/slasher/simulator/simulator.go index a03a4faeeb..2d098293f8 100644 --- a/testing/slasher/simulator/simulator.go +++ b/testing/slasher/simulator/simulator.go @@ -7,9 +7,9 @@ import ( types "github.com/prysmaticlabs/eth2-types" "github.com/prysmaticlabs/prysm/async/event" "github.com/prysmaticlabs/prysm/beacon-chain/blockchain" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/feed" statefeed "github.com/prysmaticlabs/prysm/beacon-chain/core/feed/state" + coreTime "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/db" "github.com/prysmaticlabs/prysm/beacon-chain/operations/slashings" "github.com/prysmaticlabs/prysm/beacon-chain/slasher" @@ -159,13 +159,13 @@ func (s *Simulator) simulateBlocksAndAttestations(ctx context.Context) { case slot := <-ticker.C(): // We only run the simulator for a specified number of epochs. totalEpochs := types.Epoch(s.srvConfig.Params.NumEpochs) - if core.SlotToEpoch(slot) >= totalEpochs { + if coreTime.SlotToEpoch(slot) >= totalEpochs { return } // Since processing slashings requires at least one slot, we do nothing // if we are a few slots from the end of the simulation. - endSlot, err := core.StartSlot(totalEpochs) + endSlot, err := coreTime.StartSlot(totalEpochs) if err != nil { log.WithError(err).Fatal("Could not get epoch start slot") } diff --git a/testing/util/BUILD.bazel b/testing/util/BUILD.bazel index a123da4dcc..0a29c98035 100644 --- a/testing/util/BUILD.bazel +++ b/testing/util/BUILD.bazel @@ -18,11 +18,11 @@ go_library( importpath = "github.com/prysmaticlabs/prysm/testing/util", visibility = ["//visibility:public"], deps = [ - "//beacon-chain/core:go_default_library", "//beacon-chain/core/altair:go_default_library", "//beacon-chain/core/blocks:go_default_library", "//beacon-chain/core/helpers:go_default_library", "//beacon-chain/core/signing:go_default_library", + "//beacon-chain/core/time:go_default_library", "//beacon-chain/core/transition:go_default_library", "//beacon-chain/p2p/types:go_default_library", "//beacon-chain/state:go_default_library", @@ -60,9 +60,9 @@ go_test( ], embed = [":go_default_library"], deps = [ - "//beacon-chain/core:go_default_library", "//beacon-chain/core/helpers:go_default_library", "//beacon-chain/core/signing:go_default_library", + "//beacon-chain/core/time:go_default_library", "//beacon-chain/core/transition:go_default_library", "//beacon-chain/core/transition/stateutils:go_default_library", "//config/params:go_default_library", diff --git a/testing/util/altair.go b/testing/util/altair.go index 986b8655f1..4940685806 100644 --- a/testing/util/altair.go +++ b/testing/util/altair.go @@ -8,11 +8,11 @@ import ( "github.com/pkg/errors" types "github.com/prysmaticlabs/eth2-types" "github.com/prysmaticlabs/go-bitfield" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/altair" "github.com/prysmaticlabs/prysm/beacon-chain/core/blocks" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/beacon-chain/core/signing" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/core/transition" "github.com/prysmaticlabs/prysm/beacon-chain/state" v1 "github.com/prysmaticlabs/prysm/beacon-chain/state/v1" @@ -286,7 +286,7 @@ func BlockSignatureAltair( return nil, err } block.StateRoot = s[:] - domain, err := signing.Domain(bState.Fork(), core.CurrentEpoch(bState), params.BeaconConfig().DomainBeaconProposer, bState.GenesisValidatorRoot()) + domain, err := signing.Domain(bState.Fork(), time.CurrentEpoch(bState), params.BeaconConfig().DomainBeaconProposer, bState.GenesisValidatorRoot()) if err != nil { return nil, err } @@ -401,7 +401,7 @@ func GenerateFullBlockAltair( if err := bState.SetSlot(slot); err != nil { return nil, err } - reveal, err := RandaoReveal(bState, core.CurrentEpoch(bState), privs) + reveal, err := RandaoReveal(bState, time.CurrentEpoch(bState), privs) if err != nil { return nil, err } diff --git a/testing/util/attestation.go b/testing/util/attestation.go index 8c9fa996ac..fafb0d50e4 100644 --- a/testing/util/attestation.go +++ b/testing/util/attestation.go @@ -8,9 +8,9 @@ import ( types "github.com/prysmaticlabs/eth2-types" "github.com/prysmaticlabs/go-bitfield" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/beacon-chain/core/signing" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/core/transition" "github.com/prysmaticlabs/prysm/beacon-chain/state" v1 "github.com/prysmaticlabs/prysm/beacon-chain/state/v1" @@ -59,7 +59,7 @@ func GenerateAttestations( slot-- generateHeadState = true } - currentEpoch := core.SlotToEpoch(slot) + currentEpoch := time.SlotToEpoch(slot) targetRoot := make([]byte, 32) var headRoot []byte diff --git a/testing/util/block.go b/testing/util/block.go index 47f9611dd1..4720fe53bc 100644 --- a/testing/util/block.go +++ b/testing/util/block.go @@ -6,9 +6,9 @@ import ( "github.com/pkg/errors" types "github.com/prysmaticlabs/eth2-types" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/beacon-chain/core/signing" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/crypto/bls" @@ -151,7 +151,7 @@ func GenerateFullBlock( if err := bState.SetSlot(slot); err != nil { return nil, err } - reveal, err := RandaoReveal(bState, core.CurrentEpoch(bState), privs) + reveal, err := RandaoReveal(bState, time.CurrentEpoch(bState), privs) if err != nil { return nil, err } @@ -201,7 +201,7 @@ func GenerateProposerSlashingForValidator( BodyRoot: bytesutil.PadTo([]byte{0, 1, 0}, 32), }, }) - currentEpoch := core.CurrentEpoch(bState) + currentEpoch := time.CurrentEpoch(bState) var err error header1.Signature, err = signing.ComputeDomainAndSign(bState, currentEpoch, header1.Header, params.BeaconConfig().DomainBeaconProposer, priv) if err != nil { @@ -254,7 +254,7 @@ func GenerateAttesterSlashingForValidator( priv bls.SecretKey, idx types.ValidatorIndex, ) (*ethpb.AttesterSlashing, error) { - currentEpoch := core.CurrentEpoch(bState) + currentEpoch := time.CurrentEpoch(bState) att1 := ðpb.IndexedAttestation{ Data: ðpb.AttestationData{ @@ -354,7 +354,7 @@ func generateVoluntaryExits( privs []bls.SecretKey, numExits uint64, ) ([]*ethpb.SignedVoluntaryExit, error) { - currentEpoch := core.CurrentEpoch(bState) + currentEpoch := time.CurrentEpoch(bState) voluntaryExits := make([]*ethpb.SignedVoluntaryExit, numExits) for i := 0; i < len(voluntaryExits); i++ { @@ -364,7 +364,7 @@ func generateVoluntaryExits( } exit := ðpb.SignedVoluntaryExit{ Exit: ðpb.VoluntaryExit{ - Epoch: core.PrevEpoch(bState), + Epoch: time.PrevEpoch(bState), ValidatorIndex: valIndex, }, } @@ -378,7 +378,7 @@ func generateVoluntaryExits( } func randValIndex(bState state.BeaconState) (types.ValidatorIndex, error) { - activeCount, err := helpers.ActiveValidatorCount(context.Background(), bState, core.CurrentEpoch(bState)) + activeCount, err := helpers.ActiveValidatorCount(context.Background(), bState, time.CurrentEpoch(bState)) if err != nil { return 0, err } diff --git a/testing/util/helpers.go b/testing/util/helpers.go index ec01ae04d6..1613d7cd9d 100644 --- a/testing/util/helpers.go +++ b/testing/util/helpers.go @@ -7,9 +7,9 @@ import ( "github.com/pkg/errors" types "github.com/prysmaticlabs/eth2-types" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/beacon-chain/core/signing" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/core/transition" "github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/config/params" @@ -46,7 +46,7 @@ func BlockSignature( return nil, err } block.StateRoot = s[:] - domain, err := signing.Domain(bState.Fork(), core.CurrentEpoch(bState), params.BeaconConfig().DomainBeaconProposer, bState.GenesisValidatorRoot()) + domain, err := signing.Domain(bState.Fork(), time.CurrentEpoch(bState), params.BeaconConfig().DomainBeaconProposer, bState.GenesisValidatorRoot()) if err != nil { return nil, err } diff --git a/testing/util/helpers_test.go b/testing/util/helpers_test.go index 405b4bd427..26c418aabb 100644 --- a/testing/util/helpers_test.go +++ b/testing/util/helpers_test.go @@ -7,9 +7,9 @@ import ( "testing" types "github.com/prysmaticlabs/eth2-types" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/beacon-chain/core/signing" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/testing/assert" "github.com/prysmaticlabs/prysm/testing/require" @@ -25,7 +25,7 @@ func TestBlockSignature(t *testing.T) { assert.NoError(t, err) assert.NoError(t, beaconState.SetSlot(beaconState.Slot()-1)) - epoch := core.SlotToEpoch(block.Block.Slot) + epoch := time.SlotToEpoch(block.Block.Slot) blockSig, err := signing.ComputeDomainAndSign(beaconState, epoch, block.Block, params.BeaconConfig().DomainBeaconProposer, privKeys[proposerIdx]) require.NoError(t, err) @@ -40,7 +40,7 @@ func TestBlockSignature(t *testing.T) { func TestRandaoReveal(t *testing.T) { beaconState, privKeys := DeterministicGenesisState(t, 100) - epoch := core.CurrentEpoch(beaconState) + epoch := time.CurrentEpoch(beaconState) randaoReveal, err := RandaoReveal(beaconState, epoch, privKeys) assert.NoError(t, err) diff --git a/testing/util/sync_aggregate.go b/testing/util/sync_aggregate.go index e9e4f1ab05..cc0b00790b 100644 --- a/testing/util/sync_aggregate.go +++ b/testing/util/sync_aggregate.go @@ -3,8 +3,8 @@ package util import ( "github.com/pkg/errors" "github.com/prysmaticlabs/go-bitfield" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/signing" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" p2pType "github.com/prysmaticlabs/prysm/beacon-chain/p2p/types" "github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/config/params" @@ -19,12 +19,12 @@ func generateSyncAggregate(bState state.BeaconState, privs []bls.SecretKey, pare if !ok || bState.Version() == version.Phase0 { return nil, errors.Errorf("state cannot be asserted to altair state") } - nextSlotEpoch := core.SlotToEpoch(st.Slot() + 1) - currEpoch := core.SlotToEpoch(st.Slot()) + nextSlotEpoch := time.SlotToEpoch(st.Slot() + 1) + currEpoch := time.SlotToEpoch(st.Slot()) var syncCommittee *ethpb.SyncCommittee var err error - if core.SyncCommitteePeriod(currEpoch) == core.SyncCommitteePeriod(nextSlotEpoch) { + if time.SyncCommitteePeriod(currEpoch) == time.SyncCommitteePeriod(nextSlotEpoch) { syncCommittee, err = st.CurrentSyncCommittee() if err != nil { return nil, err @@ -52,7 +52,7 @@ func generateSyncAggregate(bState state.BeaconState, privs []bls.SecretKey, pare if !ok { continue } - d, err := signing.Domain(st.Fork(), core.SlotToEpoch(st.Slot()), params.BeaconConfig().DomainSyncCommittee, st.GenesisValidatorRoot()) + d, err := signing.Domain(st.Fork(), time.SlotToEpoch(st.Slot()), params.BeaconConfig().DomainSyncCommittee, st.GenesisValidatorRoot()) if err != nil { return nil, err } diff --git a/tools/benchmark-files-gen/BUILD.bazel b/tools/benchmark-files-gen/BUILD.bazel index 301593fcd5..b23aa4d89c 100644 --- a/tools/benchmark-files-gen/BUILD.bazel +++ b/tools/benchmark-files-gen/BUILD.bazel @@ -8,9 +8,9 @@ go_library( importpath = "github.com/prysmaticlabs/prysm/tools/benchmark-files-gen", visibility = ["//visibility:private"], deps = [ - "//beacon-chain/core:go_default_library", "//beacon-chain/core/helpers:go_default_library", "//beacon-chain/core/signing:go_default_library", + "//beacon-chain/core/time:go_default_library", "//beacon-chain/core/transition:go_default_library", "//beacon-chain/state:go_default_library", "//beacon-chain/state/v1:go_default_library", diff --git a/tools/benchmark-files-gen/main.go b/tools/benchmark-files-gen/main.go index a7bbdbc329..3637e2b354 100644 --- a/tools/benchmark-files-gen/main.go +++ b/tools/benchmark-files-gen/main.go @@ -10,9 +10,9 @@ import ( "github.com/pkg/errors" types "github.com/prysmaticlabs/eth2-types" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/helpers" "github.com/prysmaticlabs/prysm/beacon-chain/core/signing" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/beacon-chain/core/transition" "github.com/prysmaticlabs/prysm/beacon-chain/state" v1 "github.com/prysmaticlabs/prysm/beacon-chain/state/v1" @@ -142,7 +142,7 @@ func generateMarshalledFullStateAndBlock() error { if err != nil { return err } - block.Signature, err = signing.ComputeDomainAndSign(beaconState, core.CurrentEpoch(beaconState), block.Block, params.BeaconConfig().DomainBeaconProposer, privs[proposerIdx]) + block.Signature, err = signing.ComputeDomainAndSign(beaconState, time.CurrentEpoch(beaconState), block.Block, params.BeaconConfig().DomainBeaconProposer, privs[proposerIdx]) if err != nil { return err } diff --git a/validator/client/BUILD.bazel b/validator/client/BUILD.bazel index ed96b55a67..eb1c2fd12d 100644 --- a/validator/client/BUILD.bazel +++ b/validator/client/BUILD.bazel @@ -24,9 +24,9 @@ go_library( "//api/grpc:go_default_library", "//async:go_default_library", "//async/event:go_default_library", - "//beacon-chain/core:go_default_library", "//beacon-chain/core/altair:go_default_library", "//beacon-chain/core/signing:go_default_library", + "//beacon-chain/core/time:go_default_library", "//cache/lru:go_default_library", "//config/features:go_default_library", "//config/params:go_default_library", diff --git a/validator/client/aggregate.go b/validator/client/aggregate.go index 8fd8737573..b1000bc4de 100644 --- a/validator/client/aggregate.go +++ b/validator/client/aggregate.go @@ -6,8 +6,8 @@ import ( "time" types "github.com/prysmaticlabs/eth2-types" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/signing" + coreTime "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/crypto/bls" "github.com/prysmaticlabs/prysm/monitoring/tracing" @@ -118,7 +118,7 @@ func (v *validator) SubmitAggregateAndProof(ctx context.Context, slot types.Slot // Signs input slot with domain selection proof. This is used to create the signature for aggregator selection. func (v *validator) signSlotWithSelectionProof(ctx context.Context, pubKey [48]byte, slot types.Slot) (signature []byte, err error) { - domain, err := v.domainData(ctx, core.SlotToEpoch(slot), params.BeaconConfig().DomainSelectionProof[:]) + domain, err := v.domainData(ctx, coreTime.SlotToEpoch(slot), params.BeaconConfig().DomainSelectionProof[:]) if err != nil { return nil, err } @@ -173,7 +173,7 @@ func (v *validator) waitToSlotTwoThirds(ctx context.Context, slot types.Slot) { // This returns the signature of validator signing over aggregate and // proof object. func (v *validator) aggregateAndProofSig(ctx context.Context, pubKey [48]byte, agg *ethpb.AggregateAttestationAndProof) ([]byte, error) { - d, err := v.domainData(ctx, core.SlotToEpoch(agg.Aggregate.Data.Slot), params.BeaconConfig().DomainAggregateAndProof[:]) + d, err := v.domainData(ctx, coreTime.SlotToEpoch(agg.Aggregate.Data.Slot), params.BeaconConfig().DomainAggregateAndProof[:]) if err != nil { return nil, err } diff --git a/validator/client/log.go b/validator/client/log.go index e17a7e1fc1..d572010601 100644 --- a/validator/client/log.go +++ b/validator/client/log.go @@ -5,7 +5,7 @@ import ( "time" types "github.com/prysmaticlabs/eth2-types" - "github.com/prysmaticlabs/prysm/beacon-chain/core" + coreTime "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/encoding/bytesutil" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" @@ -73,7 +73,7 @@ func (v *validator) LogNextDutyTimeLeft(slot types.Slot) error { if nextDutySlot == 0 { log.WithField("slotInEpoch", slot%params.BeaconConfig().SlotsPerEpoch).Info("No duty until next epoch") } else { - nextDutyTime, err := core.SlotToTime(v.genesisTime, nextDutySlot) + nextDutyTime, err := coreTime.SlotToTime(v.genesisTime, nextDutySlot) if err != nil { return err } diff --git a/validator/client/metrics.go b/validator/client/metrics.go index f30cd20ffa..8ba426240e 100644 --- a/validator/client/metrics.go +++ b/validator/client/metrics.go @@ -7,7 +7,7 @@ import ( "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promauto" types "github.com/prysmaticlabs/eth2-types" - "github.com/prysmaticlabs/prysm/beacon-chain/core" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/encoding/bytesutil" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" @@ -218,7 +218,7 @@ var ( // and penalties over time, percentage gain/loss, and gives the end user a better idea // of how the validator performs with respect to the rest. func (v *validator) LogValidatorGainsAndLosses(ctx context.Context, slot types.Slot) error { - if !core.IsEpochEnd(slot) || slot <= params.BeaconConfig().SlotsPerEpoch { + if !time.IsEpochEnd(slot) || slot <= params.BeaconConfig().SlotsPerEpoch { // Do nothing unless we are at the end of the epoch, and not in the first epoch. return nil } @@ -324,7 +324,7 @@ func (v *validator) LogValidatorGainsAndLosses(ctx context.Context, slot types.S } // These fields are deprecated after Altair. - if core.SlotToEpoch(slot) < params.BeaconConfig().AltairForkEpoch { + if time.SlotToEpoch(slot) < params.BeaconConfig().AltairForkEpoch { if i < len(resp.InclusionSlots) { previousEpochSummaryFields["inclusionSlot"] = resp.InclusionSlots[i] } else { @@ -336,7 +336,7 @@ func (v *validator) LogValidatorGainsAndLosses(ctx context.Context, slot types.S log.WithField("pubKey", truncatedKey).Warn("Missing inclusion distance") } } - if core.SlotToEpoch(slot) >= params.BeaconConfig().AltairForkEpoch { + if time.SlotToEpoch(slot) >= params.BeaconConfig().AltairForkEpoch { if i < len(resp.InactivityScores) { previousEpochSummaryFields["inactivityScore"] = resp.InactivityScores[i] } else { @@ -364,7 +364,7 @@ func (v *validator) LogValidatorGainsAndLosses(ctx context.Context, slot types.S } // Phase0 specific metrics - if core.SlotToEpoch(slot) < params.BeaconConfig().AltairForkEpoch { + if time.SlotToEpoch(slot) < params.BeaconConfig().AltairForkEpoch { if i < len(resp.InclusionDistances) { ValidatorInclusionDistancesGaugeVec.WithLabelValues(fmtKey).Set(float64(resp.InclusionDistances[i])) } @@ -395,7 +395,7 @@ func (v *validator) UpdateLogAggregateStats(resp *ethpb.ValidatorPerformanceResp for i := range resp.PublicKeys { // In phase0, we consider attestations included if the inclusion slot is not max uint64. // In altair, we consider attestations included if correctlyVotedTarget is true. - if core.SlotToEpoch(slot) < params.BeaconConfig().AltairForkEpoch && i < len(resp.InclusionDistances) { + if time.SlotToEpoch(slot) < params.BeaconConfig().AltairForkEpoch && i < len(resp.InclusionDistances) { if uint64(resp.InclusionSlots[i]) != ^uint64(0) { included++ summary.includedAttestedCount++ @@ -420,7 +420,7 @@ func (v *validator) UpdateLogAggregateStats(resp *ethpb.ValidatorPerformanceResp } // Altair metrics - if core.SlotToEpoch(slot) > params.BeaconConfig().AltairForkEpoch && i < len(resp.InactivityScores) { + if time.SlotToEpoch(slot) > params.BeaconConfig().AltairForkEpoch && i < len(resp.InactivityScores) { inactivityScore += int(resp.InactivityScores[i]) } } @@ -445,7 +445,7 @@ func (v *validator) UpdateLogAggregateStats(resp *ethpb.ValidatorPerformanceResp } // Altair summary fields. - if core.SlotToEpoch(slot) > params.BeaconConfig().AltairForkEpoch && len(resp.CorrectlyVotedTarget) > 0 { + if time.SlotToEpoch(slot) > params.BeaconConfig().AltairForkEpoch && len(resp.CorrectlyVotedTarget) > 0 { epochSummaryFields["averageInactivityScore"] = fmt.Sprintf("%.0f", float64(inactivityScore)/float64(len(resp.CorrectlyVotedTarget))) } @@ -476,7 +476,7 @@ func (v *validator) UpdateLogAggregateStats(resp *ethpb.ValidatorPerformanceResp } // Add phase0 specific fields - if core.SlotToEpoch(slot) < params.BeaconConfig().AltairForkEpoch { + if time.SlotToEpoch(slot) < params.BeaconConfig().AltairForkEpoch { launchSummaryFields["averageInclusionDistance"] = fmt.Sprintf("%.2f slots", float64(summary.totalDistance)/float64(summary.includedAttestedCount)) } diff --git a/validator/client/propose.go b/validator/client/propose.go index d9c37b1eb4..0024a3a9f6 100644 --- a/validator/client/propose.go +++ b/validator/client/propose.go @@ -9,8 +9,8 @@ import ( "github.com/pkg/errors" types "github.com/prysmaticlabs/eth2-types" "github.com/prysmaticlabs/prysm/async" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/signing" + coreTime "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/crypto/bls" "github.com/prysmaticlabs/prysm/crypto/rand" @@ -39,7 +39,7 @@ const signExitErr = "could not sign voluntary exit proposal" // the state root computation, and finally signed by the validator before being // sent back to the beacon node for broadcasting. func (v *validator) ProposeBlock(ctx context.Context, slot types.Slot, pubKey [48]byte) { - currEpoch := core.SlotToEpoch(slot) + currEpoch := coreTime.SlotToEpoch(slot) switch { case currEpoch >= params.BeaconConfig().AltairForkEpoch: v.proposeBlockAltair(ctx, slot, pubKey) diff --git a/validator/client/runner.go b/validator/client/runner.go index 03f6fd502a..354b6ab7fb 100644 --- a/validator/client/runner.go +++ b/validator/client/runner.go @@ -8,7 +8,7 @@ import ( "github.com/pkg/errors" types "github.com/prysmaticlabs/eth2-types" - "github.com/prysmaticlabs/prysm/beacon-chain/core" + coreTime "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/encoding/bytesutil" "github.com/prysmaticlabs/prysm/validator/client/iface" @@ -170,7 +170,7 @@ func run(ctx context.Context, v iface.Validator) { } // Start fetching domain data for the next epoch. - if core.IsEpochEnd(slot) { + if coreTime.IsEpochEnd(slot) { go v.UpdateDomainDataCaches(ctx, slot+1) } diff --git a/validator/client/sync_committee.go b/validator/client/sync_committee.go index 4cd15eb572..4805efc153 100644 --- a/validator/client/sync_committee.go +++ b/validator/client/sync_committee.go @@ -7,9 +7,9 @@ import ( fssz "github.com/ferranbt/fastssz" emptypb "github.com/golang/protobuf/ptypes/empty" types "github.com/prysmaticlabs/eth2-types" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/altair" "github.com/prysmaticlabs/prysm/beacon-chain/core/signing" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/crypto/bls" "github.com/prysmaticlabs/prysm/encoding/bytesutil" @@ -41,7 +41,7 @@ func (v *validator) SubmitSyncCommitteeMessage(ctx context.Context, slot types.S return } - d, err := v.domainData(ctx, core.SlotToEpoch(slot), params.BeaconConfig().DomainSyncCommittee[:]) + d, err := v.domainData(ctx, time.SlotToEpoch(slot), params.BeaconConfig().DomainSyncCommittee[:]) if err != nil { log.WithError(err).Error("Could not get sync committee domain data") return @@ -191,7 +191,7 @@ func (v *validator) selectionProofs(ctx context.Context, slot types.Slot, pubKey // Signs input slot with domain sync committee selection proof. This is used to create the signature for sync committee selection. func (v *validator) signSyncSelectionData(ctx context.Context, pubKey [48]byte, index uint64, slot types.Slot) (signature []byte, err error) { - domain, err := v.domainData(ctx, core.SlotToEpoch(slot), params.BeaconConfig().DomainSyncCommitteeSelectionProof[:]) + domain, err := v.domainData(ctx, time.SlotToEpoch(slot), params.BeaconConfig().DomainSyncCommitteeSelectionProof[:]) if err != nil { return nil, err } @@ -208,7 +208,7 @@ func (v *validator) signSyncSelectionData(ctx context.Context, pubKey [48]byte, // This returns the signature of validator signing over sync committee contribution and proof object. func (v *validator) signContributionAndProof(ctx context.Context, pubKey [48]byte, c *ethpb.ContributionAndProof) ([]byte, error) { - d, err := v.domainData(ctx, core.SlotToEpoch(c.Contribution.Slot), params.BeaconConfig().DomainContributionAndProof[:]) + d, err := v.domainData(ctx, time.SlotToEpoch(c.Contribution.Slot), params.BeaconConfig().DomainContributionAndProof[:]) if err != nil { return nil, err } diff --git a/validator/client/validator.go b/validator/client/validator.go index fe5004d54c..05727c76bc 100644 --- a/validator/client/validator.go +++ b/validator/client/validator.go @@ -19,8 +19,8 @@ import ( "github.com/pkg/errors" types "github.com/prysmaticlabs/eth2-types" "github.com/prysmaticlabs/prysm/async/event" - "github.com/prysmaticlabs/prysm/beacon-chain/core" "github.com/prysmaticlabs/prysm/beacon-chain/core/altair" + coreTime "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/config/features" "github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/crypto/hash" @@ -458,7 +458,7 @@ func (v *validator) UpdateDuties(ctx context.Context, slot types.Slot) error { return nil } // Set deadline to end of epoch. - ss, err := core.StartSlot(core.SlotToEpoch(slot) + 1) + ss, err := coreTime.StartSlot(coreTime.SlotToEpoch(slot) + 1) if err != nil { return err } @@ -615,7 +615,7 @@ func (v *validator) RolesAt(ctx context.Context, slot types.Slot) (map[[48]byte] // broadcasts signatures for `slot - 1` for inclusion in `slot`. At the last slot of the epoch, // the validator checks whether it's in the sync committee of following epoch. inSyncCommittee := false - if core.IsEpochEnd(slot) { + if coreTime.IsEpochEnd(slot) { if v.duties.NextEpochDuties[validator].IsSyncCommittee { roles = append(roles, iface.RoleSyncCommittee) inSyncCommittee = true @@ -717,7 +717,7 @@ func (v *validator) UpdateDomainDataCaches(ctx context.Context, slot types.Slot) params.BeaconConfig().DomainSelectionProof[:], params.BeaconConfig().DomainAggregateAndProof[:], } { - _, err := v.domainData(ctx, core.SlotToEpoch(slot), d) + _, err := v.domainData(ctx, coreTime.SlotToEpoch(slot), d) if err != nil { log.WithError(err).Errorf("Failed to update domain data for domain %v", d) } diff --git a/validator/db/kv/BUILD.bazel b/validator/db/kv/BUILD.bazel index 813f4c9193..4701ba332a 100644 --- a/validator/db/kv/BUILD.bazel +++ b/validator/db/kv/BUILD.bazel @@ -23,7 +23,7 @@ go_library( deps = [ "//async/abool:go_default_library", "//async/event:go_default_library", - "//beacon-chain/core:go_default_library", + "//beacon-chain/core/time:go_default_library", "//config/features:go_default_library", "//config/params:go_default_library", "//encoding/bytesutil:go_default_library", diff --git a/validator/db/kv/proposer_protection.go b/validator/db/kv/proposer_protection.go index 8dd7441bd2..e8b7db5f51 100644 --- a/validator/db/kv/proposer_protection.go +++ b/validator/db/kv/proposer_protection.go @@ -6,7 +6,7 @@ import ( "github.com/pkg/errors" types "github.com/prysmaticlabs/eth2-types" - "github.com/prysmaticlabs/prysm/beacon-chain/core" + "github.com/prysmaticlabs/prysm/beacon-chain/core/time" "github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/encoding/bytesutil" bolt "go.etcd.io/bbolt" @@ -193,8 +193,8 @@ func pruneProposalHistoryBySlot(valBucket *bolt.Bucket, newestSlot types.Slot) e c := valBucket.Cursor() for k, _ := c.First(); k != nil; k, _ = c.First() { slot := bytesutil.BytesToSlotBigEndian(k) - epoch := core.SlotToEpoch(slot) - newestEpoch := core.SlotToEpoch(newestSlot) + epoch := time.SlotToEpoch(slot) + newestEpoch := time.SlotToEpoch(newestSlot) // Only delete epochs that are older than the weak subjectivity period. if epoch+params.BeaconConfig().WeakSubjectivityPeriod <= newestEpoch { if err := c.Delete(); err != nil {