From 2dede094c861c856cf76d087195d7a4a1b13dd1c Mon Sep 17 00:00:00 2001 From: Mark Spanbroek Date: Thu, 17 Oct 2024 14:46:40 +0200 Subject: [PATCH] move Rounds to rounds module --- mysticeti/validator.nim | 12 ------------ mysticeti/validator/rounds.nim | 21 +++++++++++++++++---- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/mysticeti/validator.nim b/mysticeti/validator.nim index 916e056..fb0afef 100644 --- a/mysticeti/validator.nim +++ b/mysticeti/validator.nim @@ -13,8 +13,6 @@ type committee: Committee[Signing] membership: CommitteeMember rounds: Rounds[Hashing] - Rounds[Hashing] = object - first, last: Round[Hashing] func new*(T: type Validator; identity: Identity, committee: Committee): ?!T = let round = Round[T.Hashing].new(0, committee.size) @@ -61,16 +59,6 @@ func wave(rounds: Rounds): auto = func nextRound*(validator: Validator) = validator.rounds.last = validator.rounds.last.createNext() -func remove(rounds: var Rounds, round: Round) = - if previous =? round.previous: - previous.next = round.next - else: - rounds.first = !round.next - if next =? round.next: - next.previous = round.previous - else: - rounds.last = !round.previous - func skips(blck: Block, round: uint64, author: CommitteeMember): bool = for parent in blck.parents: if parent.round == round and parent.author == author: diff --git a/mysticeti/validator/rounds.nim b/mysticeti/validator/rounds.nim index 5128ff0..3d6f947 100644 --- a/mysticeti/validator/rounds.nim +++ b/mysticeti/validator/rounds.nim @@ -1,10 +1,23 @@ import ../basics import ./slots -type Round*[Hashing] = ref object - number: uint64 - previous*, next*: ?Round[Hashing] - slots*: seq[ProposerSlot[Hashing]] +type + Rounds*[Hashing] = object + first*, last*: Round[Hashing] + Round*[Hashing] = ref object + number: uint64 + previous*, next*: ?Round[Hashing] + slots*: seq[ProposerSlot[Hashing]] + +func remove*(rounds: var Rounds, round: Round) = + if previous =? round.previous: + previous.next = round.next + else: + rounds.first = !round.next + if next =? round.next: + next.previous = round.previous + else: + rounds.last = !round.previous func new*(T: type Round, number: uint64, slots: int): T = type Slot = ProposerSlot[T.Hashing]