From ec79241adb2ff8e6f617c0ff0d95b7f827747dd6 Mon Sep 17 00:00:00 2001 From: Vincent Bernardoff Date: Mon, 24 Oct 2016 14:10:17 +0200 Subject: [PATCH] reject invalid protocols --- src/node/shell/node.ml | 11 ++++++++--- src/node/updater/updater.mli | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/node/shell/node.ml b/src/node/shell/node.ml index 67291fac5..49872995c 100644 --- a/src/node/shell/node.ml +++ b/src/node/shell/node.ml @@ -25,11 +25,16 @@ let inject_operation validator ?force bytes = Lwt.return (hash, t) let inject_protocol state ?force:_ proto = - (* TODO: Validate the protocol *) let proto_bytes = Store.Protocol.to_bytes proto in let hash = Protocol_hash.hash_bytes [proto_bytes] in - let t = State.Protocol.store state proto_bytes >>|? ignore in - Lwt.return (hash, t) + let validation = Updater.compile hash proto >>= function + | false -> Lwt.fail_with (Format.asprintf "Invalid protocol %a: compilation failed" Protocol_hash.pp_short hash) + | true -> + State.Protocol.store state proto_bytes >>= function + | Ok None -> Lwt.fail_with "Previously registred protocol" + | t -> t >|? ignore |> Lwt.return + in + Lwt.return (hash, validation) let process_operation state validator bytes = State.Operation.store state bytes >>= function diff --git a/src/node/updater/updater.mli b/src/node/updater/updater.mli index 05f90454e..e82447228 100644 --- a/src/node/updater/updater.mli +++ b/src/node/updater/updater.mli @@ -70,7 +70,7 @@ module type REGISTRED_PROTOCOL = sig and type 'a tzresult := 'a tzresult end -type component = { +type component = Store.component = { name : string ; interface : string option ; implementation : string ;