Client: fix validation of proposals before submission

for a proposal to be valid it must either a protocol that was already
proposed by somebody else or a protocol known by the node, because the
user is the first proposer and just injected it with
tezos-admin-client
This commit is contained in:
Marco Stronati 2019-01-20 10:35:43 +01:00 committed by Grégoire Henry
parent 344f8d3e5f
commit b09e89f9f3
No known key found for this signature in database
GPG Key ID: 50D984F20BD445D2

View File

@ -665,20 +665,32 @@ let commands version () =
| _ -> cctxt#error "Not in a proposal period" | _ -> cctxt#error "Not in a proposal period"
end >>=? fun () -> end >>=? fun () ->
Shell_services.Protocol.list cctxt >>=? fun known_protos -> Shell_services.Protocol.list cctxt >>=? fun known_protos ->
let check_proposals proposals : unit tzresult Lwt.t = get_proposals ~chain:`Main ~block:cctxt#block cctxt >>=? fun known_proposals ->
(* for a proposal to be valid it must either a protocol that was already
proposed by somebody else or a protocol known by the node, because
the user is the first proposer and just injected it with
tezos-admin-client *)
let check_proposals proposals : bool tzresult Lwt.t =
let n = List.length proposals in let n = List.length proposals in
if n = 0 then cctxt#error "Empty proposal" if n = 0 then cctxt#error "Empty proposal"
else if n > Constants.fixed.max_proposals_per_delegate then else if n > Constants.fixed.max_proposals_per_delegate then
cctxt#error "Too many proposals" cctxt#error "Too many proposals"
else else
iter_s (fun p -> fold_left_s (fun acc (p : Protocol_hash.t) ->
if List.mem p known_protos then if (List.mem p known_protos) ||
cctxt#message "All proposals are valid" >>= fun () -> return_unit (Alpha_environment.Protocol_hash.Map.mem p known_proposals)
else cctxt#error "Protocol %a is not known by the node" then return acc
Protocol_hash.pp p) else cctxt#message "Protocol %a is not a known proposal"
proposals Protocol_hash.pp p >>= fun () ->
return false)
true proposals
in in
check_proposals proposals >>=? fun () -> check_proposals proposals >>=? fun all_valid ->
begin if all_valid then
cctxt#message "All proposals are valid"
else
cctxt#error "Submission failed because of invalid proposals"
end >>= fun () ->
Client_proto_context.get_manager Client_proto_context.get_manager
cctxt ~chain:`Main ~block:cctxt#block cctxt ~chain:`Main ~block:cctxt#block
source >>=? fun (_src_name, src_pkh, _src_pk, src_sk) -> source >>=? fun (_src_name, src_pkh, _src_pk, src_sk) ->