move Committee to its own module

This commit is contained in:
Mark Spanbroek 2024-09-19 10:32:39 +02:00
parent c063e9f52f
commit f84c01f967
3 changed files with 19 additions and 10 deletions

View File

@ -1,7 +1,6 @@
import ./mysticeti/validator
export validator.Validator
export validator.Committee
export validator.ProposalStatus
export validator.new
export validator.identifier
@ -11,6 +10,11 @@ export validator.propose
export validator.receive
export validator.status
import ./mysticeti/committee
export committee.Committee
export committee.new
import ./mysticeti/blocks
export blocks.Transaction

13
mysticeti/committee.nim Normal file
View File

@ -0,0 +1,13 @@
import ./basics
import ./signing
type
Committee*[Signing] = ref object
stakes: Table[Identifier[Signing], Stake]
Stake* = float64
func new*(_: type Committee, stakes: openArray[(Identifier, Stake)]): auto =
Committee[Identifier.Signing](stakes: stakes.toTable)
func stake*(committee: Committee, identifier: Identifier): Stake =
committee.stakes.getOrDefault(identifier)

View File

@ -1,5 +1,6 @@
import ./basics
import ./signing
import ./committee
import ./blocks
type
@ -7,9 +8,6 @@ type
identity: Identity[Signing]
committee: Committee[Signing]
round: Round[Signing, Hashing]
Committee*[Signing] = ref object
stakes: Table[Identifier[Signing], Stake]
Stake = float64
Round[Signing, Hashing] = ref object
number: uint64
previous: ?Round[Signing, Hashing]
@ -28,9 +26,6 @@ func new*(T: type Validator; identity: Identity, committee: Committee): T =
let round = Round[T.Signing, T.Hashing](number: 0)
T(identity: identity, committee: committee, round: round)
func new*(_: type Committee, stakes: openArray[(Identifier, Stake)]): auto =
Committee[Identifier.Signing](stakes: stakes.toTable)
func new*(_: type Round, number: uint64, previous: Round): auto =
Round(number: number, previous: some previous)
@ -43,9 +38,6 @@ func identifier*(validator: Validator): auto =
func round*(validator: Validator): uint64 =
validator.round.number
func stake(committee: Committee, identifier: Identifier): Stake =
committee.stakes.getOrDefault(identifier)
func nextRound*(validator: Validator) =
let previous = validator.round
validator.round = Round.new(previous.number + 1, previous)