Alpha/Vote: fix proposal voting to be stake propotional

Co-authored-by: Jun FURUSE <jun.furuse@dailambda.jp>
Co-authored-by: Marco Stronati <marco@stronati.org>
This commit is contained in:
Jun FURUSE 2018-11-18 09:24:31 +00:00 committed by Pierre Boutillier
parent f1614414cc
commit 09a8721598
No known key found for this signature in database
GPG Key ID: C2F73508B56A193C
5 changed files with 17 additions and 11 deletions

View File

@ -733,7 +733,7 @@ module Vote : sig
context -> Protocol_hash.t -> public_key_hash ->
context Lwt.t
val get_proposals:
context -> int32 Protocol_hash.Map.t Lwt.t
context -> int32 Protocol_hash.Map.t tzresult Lwt.t
val clear_proposals: context -> context Lwt.t
val listings_encoding : (Signature.Public_key_hash.t * int32) list Data_encoding.t

View File

@ -67,7 +67,7 @@ let check_approval_and_update_quorum ctxt =
let start_new_voting_cycle ctxt =
Vote.get_current_period_kind ctxt >>=? function
| Proposal -> begin
Vote.get_proposals ctxt >>= fun proposals ->
Vote.get_proposals ctxt >>=? fun proposals ->
Vote.clear_proposals ctxt >>= fun ctxt ->
Vote.clear_listings ctxt >>=? fun ctxt ->
match select_winning_proposal proposals with

View File

@ -28,13 +28,18 @@ let record_proposal ctxt delegate proposal =
let get_proposals ctxt =
Storage.Vote.Proposals.fold ctxt
~init:Protocol_hash.Map.empty
~f:(fun (proposal, _delegate) acc ->
let previous =
match Protocol_hash.Map.find_opt proposal acc with
| None -> 0l
| Some x -> x in
Lwt.return (Protocol_hash.Map.add proposal (Int32.succ previous) acc))
~init:(ok Protocol_hash.Map.empty)
~f:(fun (proposal, delegate) acc ->
(* Assuming the same listings is used at votings *)
Storage.Vote.Listings.get ctxt delegate >>=? fun weight ->
Lwt.return begin acc >>? fun acc ->
let previous =
match Protocol_hash.Map.find_opt proposal acc with
| None -> 0l
| Some x -> x
in
ok (Protocol_hash.Map.add proposal (Int32.add weight previous) acc)
end)
let clear_proposals ctxt =
Storage.Vote.Proposals.clear ctxt
@ -60,6 +65,7 @@ let record_ballot = Storage.Vote.Ballots.init_set
let get_ballots ctxt =
Storage.Vote.Ballots.fold ctxt
~f:(fun delegate ballot (ballots: ballots tzresult) ->
(* Assuming the same listings is used at votings *)
Storage.Vote.Listings.get ctxt delegate >>=? fun weight ->
let count = Int32.add weight in
Lwt.return begin

View File

@ -28,7 +28,7 @@ val record_proposal:
Raw_context.t Lwt.t
val get_proposals:
Raw_context.t -> int32 Protocol_hash.Map.t Lwt.t
Raw_context.t -> int32 Protocol_hash.Map.t tzresult Lwt.t
val clear_proposals: Raw_context.t -> Raw_context.t Lwt.t

View File

@ -101,7 +101,7 @@ let register () =
end;
register0 S.proposals begin fun ctxt () () ->
Vote.get_proposals ctxt >|= ok
Vote.get_proposals ctxt
end;
register0 S.listings begin fun ctxt () () ->