Skip to content

Commit

Permalink
Call on_tick on every skipped slot for spectests (#11262)
Browse files Browse the repository at this point in the history
New spectests ensure that we call on_tick for every slot between the
last tick and the current one. This PR fixes that

Co-authored-by: Raul Jordan <raul@prysmaticlabs.com>
Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Aug 19, 2022
1 parent 8fecfae commit 1775cf8
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions testing/spectest/shared/common/forkchoice/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,17 @@ func NewBuilder(t testing.TB, initialState state.BeaconState, initialBlock inter
// Tick resets the genesis time to now()-tick and adjusts the slot to the appropriate value.
func (bb *Builder) Tick(t testing.TB, tick int64) {
bb.service.SetGenesisTime(time.Unix(time.Now().Unix()-tick, 0))
bb.service.ForkChoicer().SetGenesisTime(uint64(time.Now().Unix() - tick))
if tick > bb.lastTick {
slot := uint64(tick) / params.BeaconConfig().SecondsPerSlot
require.NoError(t, bb.service.ForkChoicer().NewSlot(context.TODO(), types.Slot(slot)))
bb.lastTick = tick
lastSlot := uint64(bb.lastTick) / params.BeaconConfig().SecondsPerSlot
currentSlot := uint64(tick) / params.BeaconConfig().SecondsPerSlot
for lastSlot < currentSlot {
lastSlot++
bb.service.ForkChoicer().SetGenesisTime(uint64(time.Now().Unix() - int64(params.BeaconConfig().SecondsPerSlot*lastSlot)))
require.NoError(t, bb.service.ForkChoicer().NewSlot(context.TODO(), types.Slot(lastSlot)))
}
if tick > int64(params.BeaconConfig().SecondsPerSlot*lastSlot) {
bb.service.ForkChoicer().SetGenesisTime(uint64(time.Now().Unix() - tick))
}
bb.lastTick = tick
}

// block returns the block root.
Expand Down

0 comments on commit 1775cf8

Please sign in to comment.