From 8885aabb2732f0357c4ed903289beea76eebb81f Mon Sep 17 00:00:00 2001 From: Martin Tomazic Date: Mon, 24 Apr 2023 11:51:23 +0200 Subject: [PATCH 1/3] DAC: Add missing license to RPC_services.mli --- src/lib_dac/RPC_services.mli | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/lib_dac/RPC_services.mli b/src/lib_dac/RPC_services.mli index e933f6a45896..02f238260cfa 100644 --- a/src/lib_dac/RPC_services.mli +++ b/src/lib_dac/RPC_services.mli @@ -1,3 +1,29 @@ +(*****************************************************************************) +(* *) +(* 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. *) +(* *) +(*****************************************************************************) + (** 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. *) -- GitLab From 65474dcd636bcb2ed83befb4a3a360d3aebc96d1 Mon Sep 17 00:00:00 2001 From: Martin Tomazic Date: Mon, 24 Apr 2023 12:22:04 +0200 Subject: [PATCH 2/3] DAC: Define `Api` module for versioning DAC API --- src/lib_dac/RPC_services.ml | 6 ++++++ src/lib_dac/RPC_services.mli | 12 ++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/lib_dac/RPC_services.ml b/src/lib_dac/RPC_services.ml index 10fc16ae4275..8da96023799a 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 = diff --git a/src/lib_dac/RPC_services.mli b/src/lib_dac/RPC_services.mli index 02f238260cfa..7d269be9cde1 100644 --- a/src/lib_dac/RPC_services.mli +++ b/src/lib_dac/RPC_services.mli @@ -24,6 +24,18 @@ (* *) (*****************************************************************************) +(** [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. *) -- GitLab From bf1f86102fbe580130214427f8a0bd68950fb3f2 Mon Sep 17 00:00:00 2001 From: Martin Tomazic Date: Mon, 24 Apr 2023 12:01:54 +0200 Subject: [PATCH 3/3] DAC: Prefix endpoints with "v1" for first release API --- src/lib_dac/RPC_services.ml | 13 ++++++++----- src/lib_dac_node/monitor_services.ml | 8 ++++++-- tezt/lib_tezos/dac_rpc.ml | 18 +++++++++++++----- tezt/tests/dac.ml | 2 +- 4 files changed, 28 insertions(+), 13 deletions(-) diff --git a/src/lib_dac/RPC_services.ml b/src/lib_dac/RPC_services.ml index 8da96023799a..07c1d89da4b5 100644 --- a/src/lib_dac/RPC_services.ml +++ b/src/lib_dac/RPC_services.ml @@ -72,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 @@ -81,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 @@ -89,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 @@ -100,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 @@ -120,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_node/monitor_services.ml b/src/lib_dac_node/monitor_services.ml index afdc42970ecc..649d8da78bd8 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 6314faed3f95..715a05c762cd 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 7c94cd01a850..7340ae043a20 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 -- GitLab