prysm-pulse/beacon-chain/core/helpers/slot_epoch.go
terence tsao 8c04ced1a6 Name Changes to Align with V0.3 (#1621)
* fixed epoch_processing

* penalize->slash

* exit -> voluntary_exit

*  SEED_LOOKAHEAD -> MIN_SEED_LOOKAHED

* ENTRY_EXIT_DELAY -> ACTIVATION_EXIT_DELAY

* `INCLUDER_REWARD_QUOTIENT` -> `ATTESTATION_INCLUSION_REWARD_QUOTIEN`

* LatestIndexRoots -> LatestActiveIndexRoots

* `MIN_VALIDATOR_WITHDRAWAL_EPOCHS` -> `MIN_VALIDATOR_WITHDRAWAL_DELAY`

* MAX_WITHDRAWALS_PER_EPOCH -> MAX_EXIT_DEQUEUES_PER_EPOCH

* ETH1_DATA_VOTING_PERIOD -> EPOCHS_PER_ETH1_VOTING_PERIOD

* SLOT_DURATION -> SECONDS_PER_SLOT

* EPOCH_LENGTH -> SLOTS_PER_EPOCH

* SLOT_DURATION -> SECONDS_PER_SLOT take 2

* rest of the misc fixes for config name changes

* remove tools/bootnode/.!74296!bootnode.go

* `current_epoch_start_shard` -> `current_shuffling_start_shard`, `current_shuffling_epoch`, `current_shuffling_see`

* go fmt

* fixed comment

* updated pseudocode comments

* merged master
2019-02-18 10:52:16 -06:00

57 lines
1.7 KiB
Go

package helpers
import (
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/params"
)
// SlotToEpoch returns the epoch number of the input slot.
//
// Spec pseudocode definition:
// def slot_to_epoch(slot: SlotNumber) -> EpochNumber:
// return slot // SLOTS_PER_EPOCH
func SlotToEpoch(slot uint64) uint64 {
return slot / params.BeaconConfig().SlotsPerEpoch
}
// CurrentEpoch returns the current epoch number calculated from
// the slot number stored in beacon state.
//
// Spec pseudocode definition:
// def get_current_epoch(state: BeaconState) -> EpochNumber:
// return slot_to_epoch(state.slot)
func CurrentEpoch(state *pb.BeaconState) uint64 {
return SlotToEpoch(state.Slot)
}
// PrevEpoch returns the previous epoch number calculated from
// the slot number stored in beacon state. It also checks for
// underflow condition.
func PrevEpoch(state *pb.BeaconState) uint64 {
if SlotToEpoch(state.Slot) == 0 {
return 0
}
return SlotToEpoch(state.Slot) - 1
}
// NextEpoch returns the next epoch number calculated form
// the slot number stored in beacon state.
func NextEpoch(state *pb.BeaconState) uint64 {
return SlotToEpoch(state.Slot) + 1
}
// StartSlot returns the first slot number of the
// current epoch.
//
// Spec pseudocode definition:
// def get_epoch_start_slot(epoch: EpochNumber) -> SlotNumber:
// return epoch * SLOTS_PER_EPOCH
func StartSlot(epoch uint64) uint64 {
return epoch * params.BeaconConfig().SlotsPerEpoch
}
// AttestationCurrentEpoch returns the current epoch referenced by the attestation.
func AttestationCurrentEpoch(att *pb.AttestationData) uint64 {
return SlotToEpoch(att.Slot)
}