diff --git a/beacon-chain/blockchain/execution_engine_test.go b/beacon-chain/blockchain/execution_engine_test.go index fa033d698..c2aba785c 100644 --- a/beacon-chain/blockchain/execution_engine_test.go +++ b/beacon-chain/blockchain/execution_engine_test.go @@ -409,6 +409,8 @@ func Test_NotifyNewPayload(t *testing.T) { require.NoError(t, err) service, err := NewService(ctx, opts...) require.NoError(t, err) + st := params.BeaconConfig().SlotsPerEpoch.Mul(uint64(epochsSinceFinalitySaveHotStateDB)) + service.genesisTime = time.Now().Add(time.Duration(-1*int64(st)*int64(params.BeaconConfig().SecondsPerSlot)) * time.Second) r, err := bellatrixBlk.Block().HashTreeRoot() require.NoError(t, err) ojc := ðpb.Checkpoint{Root: params.BeaconConfig().ZeroHash[:]} diff --git a/beacon-chain/blockchain/receive_block_test.go b/beacon-chain/blockchain/receive_block_test.go index 08a103b51..a96b2f2d5 100644 --- a/beacon-chain/blockchain/receive_block_test.go +++ b/beacon-chain/blockchain/receive_block_test.go @@ -322,6 +322,8 @@ func TestCheckSaveHotStateDB_Disabling(t *testing.T) { opts := testServiceOptsWithDB(t) s, err := NewService(context.Background(), opts...) require.NoError(t, err) + st := params.BeaconConfig().SlotsPerEpoch.Mul(uint64(epochsSinceFinalitySaveHotStateDB)) + s.genesisTime = time.Now().Add(time.Duration(-1*int64(st)*int64(params.BeaconConfig().SecondsPerSlot)) * time.Second) s.store.SetFinalizedCheckptAndPayloadHash(ðpb.Checkpoint{}, [32]byte{}) require.NoError(t, s.checkSaveHotStateDB(context.Background())) s.genesisTime = time.Now() diff --git a/time/slots/slottime.go b/time/slots/slottime.go index ce7fffb74..847b4af9c 100644 --- a/time/slots/slottime.go +++ b/time/slots/slottime.go @@ -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