raise assertion in Validator.new

reason: it's a programmer error when the identity
doesn't match the committee, not a runtime error
This commit is contained in:
Mark Spanbroek 2024-11-28 14:24:35 +01:00
parent 8974ea38b3
commit 824d3a2f3b
4 changed files with 6 additions and 6 deletions

View File

@ -18,10 +18,10 @@ func new*[Dependencies](
_: type Validator[Dependencies],
identity: Dependencies.Identity,
committee: Committee[Dependencies.Identifier]
): ?!Validator[Dependencies] =
): Validator[Dependencies] =
without membership =? committee.membership(identity.identifier):
return failure "identity is not a member of the committee"
success Validator[Dependencies](
raiseAssert "identity is not a member of the committee"
Validator[Dependencies](
identity: identity,
committee: committee,
membership: membership,

View File

@ -16,7 +16,7 @@ proc init*(_: type NetworkSimulator, numberOfValidators = 4): NetworkSimulator =
let identities = newSeqWith(numberOfValidators, Identity.init())
let stakes = identities.mapIt( (it.identifier, 1/numberOfValidators) )
let committee = Committee.new(stakes)
let validators = identities.mapIt(!Validator.new(it, committee))
let validators = identities.mapIt(Validator.new(it, committee))
NetworkSimulator(identities: identities, validators: validators)
func identities*(simulator: NetworkSimulator): seq[Identity] =

View File

@ -13,7 +13,7 @@ suite "Validator":
setup:
let identity = Identity.init()
let committee = Committee.new({identity.identifier: 1/1})
validator = !Validator.new(identity, committee)
validator = Validator.new(identity, committee)
test "starts at round 0":
check validator.round == 0

View File

@ -69,7 +69,7 @@ suite "Validator Network":
test "refuses proposals that are not signed by a committee member":
let otherIdentity = Identity.example
let otherCommittee = Committee.new({otherIdentity.identifier: 1/1})
let otherValidator = !Validator.new(otherIdentity, otherCommittee)
let otherValidator = Validator.new(otherIdentity, otherCommittee)
let proposal = !otherValidator.propose(seq[Transaction].example)
let checked = simulator.validators[0].check(proposal)
check checked.verdict == BlockVerdict.invalid