Do not downcast time in currentslot (#10897)

* Do not downcast time in currentslot

* no magic constants

Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
This commit is contained in:
Potuz
2022-06-16 19:26:55 -03:00
committed by GitHub
parent 8888fa4bb3
commit 3a7117dcbf
3 changed files with 7 additions and 4 deletions

View File

@@ -164,12 +164,11 @@ func Since(time time.Time) types.Slot {
// CurrentSlot returns the current slot as determined by the local clock and
// provided genesis time.
func CurrentSlot(genesisTimeSec uint64) types.Slot {
now := prysmTime.Now().Unix()
genesis := int64(genesisTimeSec) // lint:ignore uintcast -- Genesis timestamp will not exceed int64 in your lifetime.
if now < genesis {
now := uint64(prysmTime.Now().Unix())
if now < genesisTimeSec {
return 0
}
return types.Slot(uint64(now-genesis) / params.BeaconConfig().SecondsPerSlot)
return types.Slot((now - genesisTimeSec) / params.BeaconConfig().SecondsPerSlot)
}
// ValidateClock validates a provided slot against the local