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:
parent
f1614414cc
commit
09a8721598
@ -733,7 +733,7 @@ module Vote : sig
|
|||||||
context -> Protocol_hash.t -> public_key_hash ->
|
context -> Protocol_hash.t -> public_key_hash ->
|
||||||
context Lwt.t
|
context Lwt.t
|
||||||
val get_proposals:
|
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 clear_proposals: context -> context Lwt.t
|
||||||
|
|
||||||
val listings_encoding : (Signature.Public_key_hash.t * int32) list Data_encoding.t
|
val listings_encoding : (Signature.Public_key_hash.t * int32) list Data_encoding.t
|
||||||
|
@ -67,7 +67,7 @@ let check_approval_and_update_quorum ctxt =
|
|||||||
let start_new_voting_cycle ctxt =
|
let start_new_voting_cycle ctxt =
|
||||||
Vote.get_current_period_kind ctxt >>=? function
|
Vote.get_current_period_kind ctxt >>=? function
|
||||||
| Proposal -> begin
|
| Proposal -> begin
|
||||||
Vote.get_proposals ctxt >>= fun proposals ->
|
Vote.get_proposals ctxt >>=? fun proposals ->
|
||||||
Vote.clear_proposals ctxt >>= fun ctxt ->
|
Vote.clear_proposals ctxt >>= fun ctxt ->
|
||||||
Vote.clear_listings ctxt >>=? fun ctxt ->
|
Vote.clear_listings ctxt >>=? fun ctxt ->
|
||||||
match select_winning_proposal proposals with
|
match select_winning_proposal proposals with
|
||||||
|
@ -28,13 +28,18 @@ let record_proposal ctxt delegate proposal =
|
|||||||
|
|
||||||
let get_proposals ctxt =
|
let get_proposals ctxt =
|
||||||
Storage.Vote.Proposals.fold ctxt
|
Storage.Vote.Proposals.fold ctxt
|
||||||
~init:Protocol_hash.Map.empty
|
~init:(ok Protocol_hash.Map.empty)
|
||||||
~f:(fun (proposal, _delegate) acc ->
|
~f:(fun (proposal, delegate) acc ->
|
||||||
let previous =
|
(* Assuming the same listings is used at votings *)
|
||||||
match Protocol_hash.Map.find_opt proposal acc with
|
Storage.Vote.Listings.get ctxt delegate >>=? fun weight ->
|
||||||
| None -> 0l
|
Lwt.return begin acc >>? fun acc ->
|
||||||
| Some x -> x in
|
let previous =
|
||||||
Lwt.return (Protocol_hash.Map.add proposal (Int32.succ previous) acc))
|
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 =
|
let clear_proposals ctxt =
|
||||||
Storage.Vote.Proposals.clear ctxt
|
Storage.Vote.Proposals.clear ctxt
|
||||||
@ -60,6 +65,7 @@ let record_ballot = Storage.Vote.Ballots.init_set
|
|||||||
let get_ballots ctxt =
|
let get_ballots ctxt =
|
||||||
Storage.Vote.Ballots.fold ctxt
|
Storage.Vote.Ballots.fold ctxt
|
||||||
~f:(fun delegate ballot (ballots: ballots tzresult) ->
|
~f:(fun delegate ballot (ballots: ballots tzresult) ->
|
||||||
|
(* Assuming the same listings is used at votings *)
|
||||||
Storage.Vote.Listings.get ctxt delegate >>=? fun weight ->
|
Storage.Vote.Listings.get ctxt delegate >>=? fun weight ->
|
||||||
let count = Int32.add weight in
|
let count = Int32.add weight in
|
||||||
Lwt.return begin
|
Lwt.return begin
|
||||||
|
@ -28,7 +28,7 @@ val record_proposal:
|
|||||||
Raw_context.t Lwt.t
|
Raw_context.t Lwt.t
|
||||||
|
|
||||||
val get_proposals:
|
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
|
val clear_proposals: Raw_context.t -> Raw_context.t Lwt.t
|
||||||
|
|
||||||
|
@ -101,7 +101,7 @@ let register () =
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
register0 S.proposals begin fun ctxt () () ->
|
register0 S.proposals begin fun ctxt () () ->
|
||||||
Vote.get_proposals ctxt >|= ok
|
Vote.get_proposals ctxt
|
||||||
end;
|
end;
|
||||||
|
|
||||||
register0 S.listings begin fun ctxt () () ->
|
register0 S.listings begin fun ctxt () () ->
|
||||||
|
Loading…
Reference in New Issue
Block a user