Skip to content

Commit

Permalink
raise assertion in Validator.new
Browse files Browse the repository at this point in the history
reason: it's a programmer error when the identity
doesn't match the committee, not a runtime error
  • Loading branch information
markspanbroek committed Nov 28, 2024
1 parent 8974ea3 commit 824d3a2
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions mysticeti/validator.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion tests/mysticeti/simulator.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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] =
Expand Down
2 changes: 1 addition & 1 deletion tests/mysticeti/validator/testValidator.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/mysticeti/validator/testValidatorNetwork.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 824d3a2

Please sign in to comment.