create next round from last round

This commit is contained in:
Mark Spanbroek 2024-10-17 14:42:40 +02:00
parent db46e9927f
commit 6250be0d97
2 changed files with 8 additions and 6 deletions

View File

@ -59,12 +59,7 @@ func wave(rounds: Rounds): auto =
none (Round, Round, Round)
func nextRound*(validator: Validator) =
type Round = typeof(validator.rounds.last)
let previous = validator.rounds.last
let next = Round.new(previous.number + 1, validator.committee.size)
next.previous = some previous
previous.next = some next
validator.rounds.last = next
validator.rounds.last = validator.rounds.last.createNext()
func remove(rounds: var Rounds, round: Round) =
if previous =? round.previous:

View File

@ -11,5 +11,12 @@ func new*(T: type Round, number: uint64, slots: int): T =
let slots = newSeqWith(slots, Slot.new())
T(number: number, slots: slots)
func createNext*(round: Round): auto =
assert round.next.isNone
let next = Round.new(round.number + 1, round.slots.len)
next.previous = some round
round.next = some next
next
func number*(round: Round): uint64 =
round.number