mirror of
https://github.com/logos-storage/nim-mysticeti.git
synced 2026-01-04 06:33:11 +00:00
primary proposer for a round
This commit is contained in:
parent
7218991f31
commit
a8122cb27c
@ -10,6 +10,7 @@ export validator.new
|
||||
export validator.identifier
|
||||
export validator.membership
|
||||
export validator.round
|
||||
export validator.primaryProposer
|
||||
export validator.nextRound
|
||||
export validator.propose
|
||||
export validator.check
|
||||
|
||||
@ -33,6 +33,9 @@ func membership*(validator: Validator): CommitteeMember =
|
||||
func round*(validator: Validator): uint64 =
|
||||
validator.rounds.latest.number
|
||||
|
||||
func primaryProposer*(validator: Validator): CommitteeMember =
|
||||
validator.rounds.latest.primaryProposer
|
||||
|
||||
func nextRound*(validator: Validator) =
|
||||
validator.rounds.addNewRound()
|
||||
|
||||
|
||||
@ -32,6 +32,9 @@ func next*(round: Round): auto =
|
||||
func `[]`*(round: Round, member: CommitteeMember): auto =
|
||||
round.slots[int(member)]
|
||||
|
||||
func primaryProposer*(round: Round): CommitteeMember =
|
||||
CommitteeMember((round.number mod round.slots.len.uint64).int)
|
||||
|
||||
iterator proposers*(round: Round): CommitteeMember =
|
||||
let length = round.slots.len
|
||||
let offset = (round.number mod length.uint64).int
|
||||
|
||||
@ -120,6 +120,19 @@ suite "Validator Round":
|
||||
check third.previous == none Round
|
||||
check third.next == none Round
|
||||
|
||||
test "primary proposer rotates on a round-robin schedule":
|
||||
var round: Round
|
||||
round = Round.new(0, 4)
|
||||
check round.primaryProposer == CommitteeMember(0)
|
||||
round = Round.new(1, 4)
|
||||
check round.primaryProposer == CommitteeMember(1)
|
||||
round = Round.new(2, 4)
|
||||
check round.primaryProposer == CommitteeMember(2)
|
||||
round = Round.new(3, 4)
|
||||
check round.primaryProposer == CommitteeMember(3)
|
||||
round = Round.new(4, 4)
|
||||
check round.primaryProposer == CommitteeMember(0)
|
||||
|
||||
test "proposers are ordered round-robin for each round":
|
||||
var round: Round
|
||||
round = Round.new(0, 4)
|
||||
|
||||
@ -19,6 +19,17 @@ suite "Validator Network":
|
||||
setup:
|
||||
simulator = NetworkSimulator.init()
|
||||
|
||||
test "primary proposer rotates on a round-robin schedule":
|
||||
check simulator.validators.allIt(it.primaryProposer == CommitteeMember(0))
|
||||
simulator.nextRound()
|
||||
check simulator.validators.allIt(it.primaryProposer == CommitteeMember(1))
|
||||
simulator.nextRound()
|
||||
check simulator.validators.allIt(it.primaryProposer == CommitteeMember(2))
|
||||
simulator.nextRound()
|
||||
check simulator.validators.allIt(it.primaryProposer == CommitteeMember(3))
|
||||
simulator.nextRound()
|
||||
check simulator.validators.allIt(it.primaryProposer == CommitteeMember(0))
|
||||
|
||||
test "validators include blocks from previous round as parents":
|
||||
let previous = !simulator.exchangeProposals()
|
||||
simulator.nextRound()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user