diff --git a/src/lib_dac/RPC_services.ml b/src/lib_dac/RPC_services.ml index 10fc16ae42757f63f034ea476c3ddb40bf52da6e..07c1d89da4b58b20f211731f5cadc289a476064b 100644 --- a/src/lib_dac/RPC_services.ml +++ b/src/lib_dac/RPC_services.ml @@ -24,6 +24,12 @@ (* *) (*****************************************************************************) +module Api = struct + type version = V1 + + let to_string = function V1 -> "v1" +end + (* A variant of [Sc_rollup_reveal_hash.encoding] that prefers hex encoding over b58check encoding for JSON. *) let store_preimage_request_encoding = @@ -66,7 +72,8 @@ let get_preimage ((module P) : Dac_plugin.t) = ~description:"Retrieves a page by its page hash and returns its contents" ~query:Tezos_rpc.Query.empty ~output:Data_encoding.bytes - Tezos_rpc.Path.(open_root / "preimage" /: P.hash_rpc_arg) + Tezos_rpc.Path.( + open_root / Api.(to_string V1) / "preimage" /: P.hash_rpc_arg) let put_dac_member_signature dac_plugin = Tezos_rpc.Service.put_service @@ -75,7 +82,7 @@ let put_dac_member_signature dac_plugin = ~query:Tezos_rpc.Query.empty ~input:(Signature_repr.encoding dac_plugin) ~output:Data_encoding.empty - Tezos_rpc.Path.(open_root / "dac_member_signature") + Tezos_rpc.Path.(open_root / Api.(to_string V1) / "dac_member_signature") let get_certificate ((module P) : Dac_plugin.t) = Tezos_rpc.Service.get_service @@ -83,7 +90,8 @@ let get_certificate ((module P) : Dac_plugin.t) = "Retrieve the Dac certificate associated with the given root page hash" ~query:Tezos_rpc.Query.empty ~output:(Data_encoding.option (Certificate_repr.encoding (module P))) - Tezos_rpc.Path.(open_root / "certificates" /: P.hash_rpc_arg) + Tezos_rpc.Path.( + open_root / Api.(to_string V1) / "certificates" /: P.hash_rpc_arg) let get_missing_page ((module P) : Dac_plugin.t) = Tezos_rpc.Service.get_service @@ -94,7 +102,8 @@ let get_missing_page ((module P) : Dac_plugin.t) = Observer mode." ~query:Tezos_rpc.Query.empty ~output:Data_encoding.bytes - Tezos_rpc.Path.(open_root / "missing_page" /: P.hash_rpc_arg) + Tezos_rpc.Path.( + open_root / Api.(to_string V1) / "missing_page" /: P.hash_rpc_arg) (* TODO: https://gitlab.com/tezos/tezos/-/issues/4935 Coordinator's "POST /preimage" endpoint should in addition to root page hash @@ -114,5 +123,5 @@ module Coordinator = struct ~query:Tezos_rpc.Query.empty ~input:Data_encoding.bytes ~output:P.encoding - Tezos_rpc.Path.(open_root / "preimage") + Tezos_rpc.Path.(open_root / Api.(to_string V1) / "preimage") end diff --git a/src/lib_dac/RPC_services.mli b/src/lib_dac/RPC_services.mli index e933f6a458962df5478ddaa794866c65c9bb3cf7..7d269be9cde1271c1ede6b4f9b10e00056169860 100644 --- a/src/lib_dac/RPC_services.mli +++ b/src/lib_dac/RPC_services.mli @@ -1,3 +1,41 @@ +(*****************************************************************************) +(* *) +(* Open Source License *) +(* Copyright (c) 2023 Trili Tech, *) +(* Copyright (c) 2023 Marigold *) +(* *) +(* Permission is hereby granted, free of charge, to any person obtaining a *) +(* copy of this software and associated documentation files (the "Software"),*) +(* to deal in the Software without restriction, including without limitation *) +(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *) +(* and/or sell copies of the Software, and to permit persons to whom the *) +(* Software is furnished to do so, subject to the following conditions: *) +(* *) +(* The above copyright notice and this permission notice shall be included *) +(* in all copies or substantial portions of the Software. *) +(* *) +(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*) +(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *) +(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *) +(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*) +(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *) +(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *) +(* DEALINGS IN THE SOFTWARE. *) +(* *) +(*****************************************************************************) + +(** [Api] module is used for versioning DAC API. *) +module Api : sig + (** [version] type is used to version DAC API. *) + type version = + | V1 + (** [V1] is a version that corresponds to the first public release of + the DAC API. *) + + (** [to_string version] gives a string representation of the DAC API version. *) + val to_string : version -> string +end + (** POST dac/store_preimage to post a payload using a given [pagination_scheme]. It returns the base58 encoded root page hash and the raw bytes. *) diff --git a/src/lib_dac_node/monitor_services.ml b/src/lib_dac_node/monitor_services.ml index afdc42970eccd589a56f0866f4dace9d97701211..649d8da78bd848ed7b5e047daa8093feb3a97ffe 100644 --- a/src/lib_dac_node/monitor_services.ml +++ b/src/lib_dac_node/monitor_services.ml @@ -31,7 +31,8 @@ module S = struct responsible for the serialization of the dac payload (coordinator). " ~query:Tezos_rpc.Query.empty ~output:P.encoding - Tezos_rpc.Path.(open_root / "monitor" / "root_hashes") + Tezos_rpc.Path.( + open_root / RPC_services.Api.(to_string V1) / "monitor" / "root_hashes") let certificate ((module P) : Dac_plugin.t) = Tezos_rpc.Service.get_service @@ -44,7 +45,10 @@ module S = struct times." ~query:Tezos_rpc.Query.empty ~output:(Certificate_repr.encoding (module P)) - Tezos_rpc.Path.(open_root / "monitor" / "certificate" /: P.hash_rpc_arg) + Tezos_rpc.Path.( + open_root + / RPC_services.Api.(to_string V1) + / "monitor" / "certificate" /: P.hash_rpc_arg) end let root_hashes dac_node_cctxt dac_plugin = diff --git a/tezt/lib_tezos/dac_rpc.ml b/tezt/lib_tezos/dac_rpc.ml index 6314faed3f95e3082fd93370d92afc50070a9766..715a05c762cdb4fffb6db7b6171bd9508aa1f967 100644 --- a/tezt/lib_tezos/dac_rpc.ml +++ b/tezt/lib_tezos/dac_rpc.ml @@ -23,6 +23,13 @@ (* *) (*****************************************************************************) +(** [Api] module is used for versioning DAC API. *) +module Api = struct + (** [v1] is a version that corresponds to the first public release of the DAC + API. *) + let v1 = "v1" +end + let make ?data ?query_string = RPC.make ?data @@ -40,7 +47,8 @@ let decode_hex_string_to_bytes s = Hex.to_string (`Hex s) let get_bytes_from_json_string_node json = JSON.as_string json |> decode_hex_string_to_bytes -let get_preimage page_hash = make GET ["preimage"; page_hash] JSON.as_string +let get_preimage page_hash = + make GET [Api.v1; "preimage"; page_hash] JSON.as_string let post_store_preimage ~payload ~pagination_scheme = let preimage = @@ -75,18 +83,18 @@ let put_dac_member_signature ~hex_root_hash ~dac_member_pkh ~signature = ] in let data : RPC_core.data = Data payload in - make ~data PUT ["dac_member_signature"] @@ fun _resp -> () + make ~data PUT [Api.v1; "dac_member_signature"] @@ fun _resp -> () let get_certificate ~hex_root_hash = let (`Hex page_hash) = hex_root_hash in - make GET ["certificates"; page_hash] @@ fun json -> + make GET [Api.v1; "certificates"; page_hash] @@ fun json -> JSON. ( json |-> "witnesses" |> as_int, json |-> "aggregate_signature" |> as_string, json |-> "root_hash" |> as_string ) let get_missing_page ~hex_root_hash = - make GET ["missing_page"; Hex.show hex_root_hash] JSON.as_string + make GET [Api.v1; "missing_page"; Hex.show hex_root_hash] JSON.as_string module Coordinator = struct let post_preimage ~payload = @@ -96,5 +104,5 @@ module Coordinator = struct (encode_bytes_to_hex_string payload) in let data : RPC_core.data = Data (JSON.unannotate preimage) in - make ~data POST ["preimage"] JSON.as_string + make ~data POST [Api.v1; "preimage"] JSON.as_string end diff --git a/tezt/tests/dac.ml b/tezt/tests/dac.ml index 7c94cd01a85089fdb0bdef5534ae95f4b88cb340..7340ae043a20836c33d9b53a90c6d62ee4e550dd 100644 --- a/tezt/tests/dac.ml +++ b/tezt/tests/dac.ml @@ -129,7 +129,7 @@ let parse_certificate json = let streamed_certificates_client coordinator_node root_hash = let endpoint = Format.sprintf - "http://%s:%d/monitor/certificate/%s" + "http://%s:%d/v1/monitor/certificate/%s" (Dac_node.rpc_host coordinator_node) (Dac_node.rpc_port coordinator_node) root_hash