diff --git a/src/proto_alpha/lib_protocol/src/alpha_context.mli b/src/proto_alpha/lib_protocol/src/alpha_context.mli index 8ae23b416..1f297a7fb 100644 --- a/src/proto_alpha/lib_protocol/src/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/src/alpha_context.mli @@ -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 diff --git a/src/proto_alpha/lib_protocol/src/amendment.ml b/src/proto_alpha/lib_protocol/src/amendment.ml index f4163c499..6b833ca3b 100644 --- a/src/proto_alpha/lib_protocol/src/amendment.ml +++ b/src/proto_alpha/lib_protocol/src/amendment.ml @@ -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 diff --git a/src/proto_alpha/lib_protocol/src/vote_storage.ml b/src/proto_alpha/lib_protocol/src/vote_storage.ml index 3655f762b..b8f9be0e3 100644 --- a/src/proto_alpha/lib_protocol/src/vote_storage.ml +++ b/src/proto_alpha/lib_protocol/src/vote_storage.ml @@ -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 diff --git a/src/proto_alpha/lib_protocol/src/vote_storage.mli b/src/proto_alpha/lib_protocol/src/vote_storage.mli index e01d3635f..9d1eb00c4 100644 --- a/src/proto_alpha/lib_protocol/src/vote_storage.mli +++ b/src/proto_alpha/lib_protocol/src/vote_storage.mli @@ -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 diff --git a/src/proto_alpha/lib_protocol/src/voting_services.ml b/src/proto_alpha/lib_protocol/src/voting_services.ml index 26c93ca4b..f4588caac 100644 --- a/src/proto_alpha/lib_protocol/src/voting_services.ml +++ b/src/proto_alpha/lib_protocol/src/voting_services.ml @@ -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 () () ->