diff --git a/src/lib_protocol_compiler/main_embedded_packer.ml b/src/lib_protocol_compiler/main_embedded_packer.ml index 80adbe051..1eaf329a5 100644 --- a/src/lib_protocol_compiler/main_embedded_packer.ml +++ b/src/lib_protocol_compiler/main_embedded_packer.ml @@ -31,7 +31,7 @@ end let () = Format.printf {| let () = - let module Ignored = Tezos_protocol_updater.Registered_protocol.Register + let module Ignored = Tezos_protocol_updater.Registered_protocol.Register_embedded (Tezos_embedded_protocol_environment_%s.Environment) (Tezos_embedded_raw_protocol_%s.Main) (Source) in diff --git a/src/lib_protocol_updater/registered_protocol.ml b/src/lib_protocol_updater/registered_protocol.ml index 5abb6d0c5..e0f9e0a92 100644 --- a/src/lib_protocol_updater/registered_protocol.ml +++ b/src/lib_protocol_updater/registered_protocol.ml @@ -42,6 +42,9 @@ module VersionTable = Protocol_hash.Table let versions : (module T) VersionTable.t = VersionTable.create 20 +let sources : Protocol.t VersionTable.t = + VersionTable.create 20 + let mem hash = VersionTable.mem versions hash || Tezos_protocol_registerer.Registerer.mem hash @@ -57,7 +60,17 @@ let get hash = try Some (get_exn hash) with Not_found -> None -module Register +let list_embedded () = + VersionTable.fold (fun k _ acc -> k :: acc) sources [] + +let get_embedded_sources_exn hash = + VersionTable.find sources hash + +let get_embedded_sources hash = + try Some (get_embedded_sources_exn hash) + with Not_found -> None + +module Register_embedded (Env : Tezos_protocol_environment_shell.V1) (Proto : Env.Updater.PROTOCOL) (Source : sig @@ -73,7 +86,8 @@ module Register let module Name = struct let name = Protocol_hash.to_b58check hash end in - (* TODO add a memory table for "embedded" sources... *) + VersionTable.add + sources hash Source.sources ; VersionTable.add versions hash (module struct diff --git a/src/lib_protocol_updater/registered_protocol.mli b/src/lib_protocol_updater/registered_protocol.mli index 1905765fe..fa6765e75 100644 --- a/src/lib_protocol_updater/registered_protocol.mli +++ b/src/lib_protocol_updater/registered_protocol.mli @@ -25,8 +25,12 @@ val mem: Protocol_hash.t -> bool val get: Protocol_hash.t -> t option val get_exn: Protocol_hash.t -> t +val list_embedded: unit -> Protocol_hash.t list -module Register +val get_embedded_sources: Protocol_hash.t -> Protocol.t option +val get_embedded_sources_exn: Protocol_hash.t -> Protocol.t + +module Register_embedded (Env : Tezos_protocol_environment_shell.V1) (Proto : Env.Updater.PROTOCOL) (Source : sig diff --git a/src/lib_shell/protocol_directory.ml b/src/lib_shell/protocol_directory.ml index 0aff34ced..54a67de02 100644 --- a/src/lib_shell/protocol_directory.ml +++ b/src/lib_shell/protocol_directory.ml @@ -17,12 +17,16 @@ let build_rpc_directory state = gen_register0 Protocol_services.S.list begin fun () () -> State.Protocol.list state >>= fun set -> - let protocols = Protocol_hash.Set.elements set in + let protocols = + Protocol_hash.Set.elements set @ + Registered_protocol.list_embedded () in RPC_answer.return protocols end ; register1 Protocol_services.S.contents begin fun hash () () -> - State.Protocol.read state hash + match Registered_protocol.get_embedded_sources hash with + | Some p -> return p + | None -> State.Protocol.read state hash end ; !dir