mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-09 19:21:19 +00:00
a8e501b3cf
* update deps * update deps * update protos/* * update deps * reset protos * update protos * update shared/params/config * update protos * update /shared * update shared/slotutil and shared/testutil * update beacon-chain/core/helpers * updates beacon-chain/state * update beacon-chain/forkchoice * update beacon-chain/blockchain * update beacon-chain/cache * update beacon-chain/core * update beacon-chain/db * update beacon-chain/node * update beacon-chain/p2p * update beacon-chain/rpc * update beacon-chain/sync * go mod tidy * make sure that beacon-chain build suceeds * go fmt * update e2e tests * update slasher * remove redundant alias * update validator * gazelle * fix build errors in unit tests * go fmt * update deps * update fuzz/BUILD.bazel * fix unit tests * more unit test fixes * fix blockchain UTs * more unit test fixes
41 lines
1.4 KiB
Go
41 lines
1.4 KiB
Go
package slotutil
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/prysmaticlabs/eth2-types"
|
|
"github.com/prysmaticlabs/prysm/shared/params"
|
|
"github.com/prysmaticlabs/prysm/shared/timeutils"
|
|
)
|
|
|
|
// SlotStartTime returns the start time in terms of its unix epoch
|
|
// value.
|
|
func SlotStartTime(genesis, slot uint64) time.Time {
|
|
duration := time.Second * time.Duration(slot*params.BeaconConfig().SecondsPerSlot)
|
|
startTime := time.Unix(int64(genesis), 0).Add(duration)
|
|
return startTime
|
|
}
|
|
|
|
// SlotsSinceGenesis returns the number of slots since
|
|
// the provided genesis time.
|
|
func SlotsSinceGenesis(genesis time.Time) uint64 {
|
|
if genesis.After(timeutils.Now()) { // Genesis has not occurred yet.
|
|
return 0
|
|
}
|
|
return uint64(timeutils.Since(genesis).Seconds()) / params.BeaconConfig().SecondsPerSlot
|
|
}
|
|
|
|
// EpochsSinceGenesis returns the number of slots since
|
|
// the provided genesis time.
|
|
func EpochsSinceGenesis(genesis time.Time) types.Epoch {
|
|
return types.Epoch(SlotsSinceGenesis(genesis) / params.BeaconConfig().SlotsPerEpoch)
|
|
}
|
|
|
|
// DivideSlotBy divides the SECONDS_PER_SLOT configuration
|
|
// parameter by a specified number. It returns a value of time.Duration
|
|
// in milliseconds, useful for dividing values such as 1 second into
|
|
// millisecond-based durations.
|
|
func DivideSlotBy(timesPerSlot int64) time.Duration {
|
|
return time.Duration(int64(params.BeaconConfig().SecondsPerSlot*1000)/timesPerSlot) * time.Millisecond
|
|
}
|