mirror of
https://github.com/logos-storage/nim-mysticeti.git
synced 2026-01-08 08:33:08 +00:00
move more functions to round module
This commit is contained in:
parent
70f61d1ef6
commit
33773f3e56
@ -26,18 +26,6 @@ func new*(T: type Validator; identity: Identity, committee: Committee): ?!T =
|
||||
rounds: rounds
|
||||
)
|
||||
|
||||
func `[]`(round: Round, member: CommitteeMember): auto =
|
||||
round.slots[int(member)]
|
||||
|
||||
func add(round: Round, blck: Block): auto =
|
||||
if slot =? round[blck.author]:
|
||||
slot.add(blck)
|
||||
|
||||
iterator proposals(round: Round): auto =
|
||||
for slot in round.slots:
|
||||
for proposal in slot.proposals:
|
||||
yield proposal
|
||||
|
||||
func identifier*(validator: Validator): auto =
|
||||
validator.identity.identifier
|
||||
|
||||
@ -47,15 +35,6 @@ func membership*(validator: Validator): CommitteeMember =
|
||||
func round*(validator: Validator): uint64 =
|
||||
validator.rounds.last.number
|
||||
|
||||
func wave(rounds: Rounds): auto =
|
||||
# A wave consists of 3 rounds: proposing -> voting -> certifying
|
||||
type Round = typeof(rounds.last)
|
||||
let certifying = rounds.last
|
||||
if voting =? certifying.previous:
|
||||
if proposing =? voting.previous:
|
||||
return some (proposing, voting, certifying)
|
||||
none (Round, Round, Round)
|
||||
|
||||
func nextRound*(validator: Validator) =
|
||||
validator.rounds.last = validator.rounds.last.createNext()
|
||||
|
||||
@ -107,13 +86,6 @@ func receive*(validator: Validator, signed: SignedBlock) =
|
||||
validator.updateSkipped(signed.blck)
|
||||
validator.updateCertified(signed.blck)
|
||||
|
||||
func round(validator: Validator, number: uint64): auto =
|
||||
var round = validator.rounds.last
|
||||
while round.number > number and previous =? round.previous:
|
||||
round = previous
|
||||
if round.number == number:
|
||||
return some round
|
||||
|
||||
func status*(validator: Validator, blck: Block): ?SlotStatus =
|
||||
if round =? validator.rounds.first.find(blck.round):
|
||||
some round[blck.author].status
|
||||
|
||||
@ -1,4 +1,6 @@
|
||||
import ../basics
|
||||
import ../committee
|
||||
import ../blocks
|
||||
import ./slots
|
||||
|
||||
type
|
||||
@ -9,6 +11,15 @@ type
|
||||
previous, next: ?Round[Hashing]
|
||||
slots*: seq[ProposerSlot[Hashing]]
|
||||
|
||||
func wave*(rounds: Rounds): auto =
|
||||
# A wave consists of 3 rounds: proposing -> voting -> certifying
|
||||
type Round = typeof(rounds.last)
|
||||
let certifying = rounds.last
|
||||
if voting =? certifying.previous:
|
||||
if proposing =? voting.previous:
|
||||
return some (proposing, voting, certifying)
|
||||
none (Round, Round, Round)
|
||||
|
||||
func remove*(rounds: var Rounds, round: Round) =
|
||||
if previous =? round.previous:
|
||||
previous.next = round.next
|
||||
@ -33,6 +44,14 @@ func next*(round: Round): auto =
|
||||
func number*(round: Round): uint64 =
|
||||
round.number
|
||||
|
||||
func `[]`*(round: Round, member: CommitteeMember): auto =
|
||||
round.slots[int(member)]
|
||||
|
||||
iterator proposals*(round: Round): auto =
|
||||
for slot in round.slots:
|
||||
for proposal in slot.proposals:
|
||||
yield proposal
|
||||
|
||||
func find*(round: Round, number: uint64): ?Round =
|
||||
var current = round
|
||||
while true:
|
||||
@ -53,3 +72,7 @@ func createNext*(round: Round): auto =
|
||||
next.previous = some round
|
||||
round.next = some next
|
||||
next
|
||||
|
||||
func add*(round: Round, blck: Block): auto =
|
||||
if slot =? round[blck.author]:
|
||||
slot.add(blck)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user