erigon-pulse/cmd/lightclient/utils/time.go

24 lines
512 B
Go
Raw Normal View History

package utils
import "time"
// compute current slot.
func GetCurrentSlot(genesisTime uint64, secondsPerSlot uint64) uint64 {
now := uint64(time.Now().Unix())
if now < genesisTime {
return 0
}
return (now - genesisTime) / secondsPerSlot
}
// compute current epoch.
func GetCurrentEpoch(genesisTime uint64, secondsPerSlot uint64, slotsPerEpoch uint64) uint64 {
now := uint64(time.Now().Unix())
if now < genesisTime {
return 0
}
return GetCurrentSlot(genesisTime, secondsPerSlot) / slotsPerEpoch
}