mirror of
https://github.com/logos-storage/nim-mysticeti.git
synced 2026-01-03 22:23:10 +00:00
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:
parent
8974ea38b3
commit
824d3a2f3b
@ -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,
|
||||
|
||||
@ -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] =
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user