Alpha/Vote: do not allow multiple votes

This commit is contained in:
Grégoire Henry 2018-11-21 15:52:37 +01:00 committed by Pierre Boutillier
parent 17b258b92c
commit 09e3881c6b
No known key found for this signature in database
GPG Key ID: C2F73508B56A193C
5 changed files with 17 additions and 4 deletions

View File

@ -759,8 +759,10 @@ module Vote : sig
val ballots_encoding : ballots Data_encoding.t
val has_recorded_ballot :
context -> public_key_hash -> bool Lwt.t
val record_ballot:
context -> public_key_hash -> ballot -> context Lwt.t
context -> public_key_hash -> ballot -> context tzresult Lwt.t
val get_ballots: context -> ballots tzresult Lwt.t
val get_ballot_list: context -> (Signature.Public_key_hash.t * ballot) list Lwt.t
val clear_ballots: context -> context Lwt.t

View File

@ -227,9 +227,11 @@ let record_ballot ctxt delegate proposal ballot =
Vote.get_current_proposal ctxt >>=? fun current_proposal ->
fail_unless (Protocol_hash.equal proposal current_proposal)
Invalid_proposal >>=? fun () ->
Vote.has_recorded_ballot ctxt delegate >>= fun has_ballot ->
fail_when has_ballot Unauthorized_ballot >>=? fun () ->
Vote.in_listings ctxt delegate >>= fun in_listings ->
if in_listings then
Vote.record_ballot ctxt delegate ballot >>= return
Vote.record_ballot ctxt delegate ballot
else
fail Unauthorized_ballot
| Testing | Proposal ->

View File

@ -74,7 +74,8 @@ let ballots_encoding =
(req "nay" int32)
(req "pass" int32)
let record_ballot = Storage.Vote.Ballots.init_set
let has_recorded_ballot = Storage.Vote.Ballots.mem
let record_ballot = Storage.Vote.Ballots.init
let get_ballots ctxt =
Storage.Vote.Ballots.fold ctxt

View File

@ -45,9 +45,10 @@ type ballots = {
val ballots_encoding : ballots Data_encoding.t
val has_recorded_ballot : Raw_context.t -> Signature.Public_key_hash.t -> bool Lwt.t
val record_ballot:
Raw_context.t -> Signature.Public_key_hash.t -> Vote_repr.ballot ->
Raw_context.t Lwt.t
Raw_context.t tzresult Lwt.t
val get_ballots: Raw_context.t -> ballots tzresult Lwt.t
val get_ballot_list :
Raw_context.t -> (Signature.Public_key_hash.t * Vote_repr.ballot) list Lwt.t

View File

@ -201,6 +201,13 @@ let test_voting () =
delegates >>=? fun operations ->
Block.bake ~operations b >>=? fun b ->
Op.ballot (B b) del1 Protocol_hash.zero Vote.Nay >>=? fun op ->
Block.bake ~operations:[op] b >>= fun res ->
Assert.proto_error ~loc:__LOC__ res begin function
| Amendment.Unauthorized_ballot -> true
| _ -> false
end >>=? fun () ->
fold_left_s (fun v acc -> return Int32.(add v acc))
0l rolls >>=? fun rolls_sum ->