mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-09 19:21:19 +00:00
a069738c20
* update shared/params * update eth2-types deps * update protobufs * update shared/* * fix testutil/state * update beacon-chain/state * update beacon-chain/db * update tests * fix test * update beacon-chain/core * update beacon-chain/blockchain * update beacon-chain/cache * beacon-chain/forkchoice * update beacon-chain/operations * update beacon-chain/p2p * update beacon-chain/rpc * update sync/initial-sync * update deps * update deps * go fmt * update beacon-chain/sync * update endtoend/ * bazel build //beacon-chain - works w/o issues * update slasher code * udpate tools/ * update validator/ * update fastssz * fix build * fix test building * update tests * update ethereumapis deps * fix tests * update state/stategen * fix build * fix test * add FarFutureSlot * go imports * Radek's suggestions * Ivan's suggestions * type conversions * Nishant's suggestions * add more tests to rpc_send_request * fix test * clean up * fix conflicts Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com> Co-authored-by: nisdas <nishdas93@gmail.com>
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 uint64, slot types.Slot) time.Time {
|
|
duration := time.Second * time.Duration(slot.Mul(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) types.Slot {
|
|
if genesis.After(timeutils.Now()) { // Genesis has not occurred yet.
|
|
return 0
|
|
}
|
|
return types.Slot(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
|
|
}
|