From 5248d7d7f8fc1eb66506615b64a2c2f9fec128ff Mon Sep 17 00:00:00 2001 From: Martin Tomazic Date: Wed, 17 May 2023 17:51:18 +0200 Subject: [PATCH 1/3] DAC: Introduce `Api_version` module --- src/lib_dac/api_version.ml | 31 +++++++++++++++++++++++++++++++ src/lib_dac/api_version.mli | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 src/lib_dac/api_version.ml create mode 100644 src/lib_dac/api_version.mli diff --git a/src/lib_dac/api_version.ml b/src/lib_dac/api_version.ml new file mode 100644 index 000000000000..b8f0d77de4d1 --- /dev/null +++ b/src/lib_dac/api_version.ml @@ -0,0 +1,31 @@ +(*****************************************************************************) +(* *) +(* 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. *) +(* *) +(*****************************************************************************) + +type t = V0 + +let to_rpc_path_prefix = function V0 -> Tezos_rpc.Path.(open_root / "v0") + +let v0_prefix = to_rpc_path_prefix V0 diff --git a/src/lib_dac/api_version.mli b/src/lib_dac/api_version.mli new file mode 100644 index 000000000000..597d9f739ef2 --- /dev/null +++ b/src/lib_dac/api_version.mli @@ -0,0 +1,33 @@ +(*****************************************************************************) +(* *) +(* 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_version] module is used for versioning DAC API. *) + +(** [t] type is used to version DAC API. *) +type t = V0 (** [V0] is experimental DAC API. Use at your own risk! *) + +(** [v0_prefix] is [V0] API RPC prefix. *) +val v0_prefix : (unit, unit) Tezos_rpc.Path.t -- GitLab From 94329b8c5120fd55a124b4bb7579d34b3fb663ff Mon Sep 17 00:00:00 2001 From: Martin Tomazic Date: Wed, 17 May 2023 17:52:24 +0200 Subject: [PATCH 2/3] DAC: Replace `version_rpc_arg` with `v0_api_prefix` --- src/lib_dac/RPC_services.ml | 187 ++++++++++++-------------- src/lib_dac/RPC_services.mli | 140 +++++++++---------- src/lib_dac/monitor_services.ml | 77 +++++------ src/lib_dac/monitor_services.mli | 78 ++++++----- src/lib_dac_client/dac_node_client.ml | 38 ++---- src/lib_dac_node/RPC_server.ml | 57 ++++---- src/lib_dac_node/handler.ml | 6 +- tezt/tests/dac.ml | 31 +---- 8 files changed, 266 insertions(+), 348 deletions(-) diff --git a/src/lib_dac/RPC_services.ml b/src/lib_dac/RPC_services.ml index d69b2c5074aa..4665025c6523 100644 --- a/src/lib_dac/RPC_services.ml +++ b/src/lib_dac/RPC_services.ml @@ -24,120 +24,101 @@ (* *) (*****************************************************************************) -module Api = struct - type version = V0 +module V0 = struct + let v0_prefix = Api_version.v0_prefix - let version_rpc_arg = - let construct = function V0 -> "v0" in - let destruct version = - match version with - | "v0" -> Ok V0 - | invalid_version -> Error invalid_version - in - Tezos_rpc.Arg.make - ~descr:"API version" - ~name:"api_version" - ~destruct - ~construct - () -end - -(* A variant of [Sc_rollup_reveal_hash.encoding] that prefers hex - encoding over b58check encoding for JSON. *) -let store_preimage_request_encoding = - let pagination_scheme_encoding = Pagination_scheme.encoding in - Data_encoding.( - obj2 - (req "payload" Data_encoding.(bytes' Hex)) - (req "pagination_scheme" pagination_scheme_encoding)) + (* A variant of [Sc_rollup_reveal_hash.encoding] that prefers hex + encoding over b58check encoding for JSON. *) + let store_preimage_request_encoding = + let pagination_scheme_encoding = Pagination_scheme.encoding in + Data_encoding.( + obj2 + (req "payload" Data_encoding.(bytes' Hex)) + (req "pagination_scheme" pagination_scheme_encoding)) -let store_preimage_response_encoding = - Data_encoding.( - obj2 - (req "root_hash" Dac_plugin.raw_hash_encoding) - (req "external_message" (bytes' Hex))) + let store_preimage_response_encoding = + Data_encoding.( + obj2 + (req "root_hash" Dac_plugin.raw_hash_encoding) + (req "external_message" (bytes' Hex))) -let external_message_query = - let open Tezos_rpc.Query in - query (fun hex_string -> hex_string) - |+ opt_field "external_message" Tezos_rpc.Arg.string (fun s -> s) - |> seal + let external_message_query = + let open Tezos_rpc.Query in + query (fun hex_string -> hex_string) + |+ opt_field "external_message" Tezos_rpc.Arg.string (fun s -> s) + |> seal -let post_store_preimage = - Tezos_rpc.Service.post_service - ~description:"Split DAC reveal data" - ~query:Tezos_rpc.Query.empty - ~input:store_preimage_request_encoding - ~output:store_preimage_response_encoding - Tezos_rpc.Path.(open_root /: Api.version_rpc_arg / "store_preimage") + let post_store_preimage = + Tezos_rpc.Service.post_service + ~description:"Split DAC reveal data" + ~query:Tezos_rpc.Query.empty + ~input:store_preimage_request_encoding + ~output:store_preimage_response_encoding + Tezos_rpc.Path.(v0_prefix / "store_preimage") -(* DAC/FIXME: https://gitlab.com/tezos/tezos/-/issues/4263 - remove this endpoint once end-to-end tests are in place. *) -let get_verify_signature = - Tezos_rpc.Service.get_service - ~description:"Verify signature of an external message to inject in L1" - ~query:external_message_query - ~output:Data_encoding.bool - Tezos_rpc.Path.(open_root /: Api.version_rpc_arg / "verify_signature") + (* DAC/FIXME: https://gitlab.com/tezos/tezos/-/issues/4263 + remove this endpoint once end-to-end tests are in place. *) + let get_verify_signature = + Tezos_rpc.Service.get_service + ~description:"Verify signature of an external message to inject in L1" + ~query:external_message_query + ~output:Data_encoding.bool + Tezos_rpc.Path.(v0_prefix / "verify_signature") -let get_preimage = - Tezos_rpc.Service.get_service - ~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 /: Api.version_rpc_arg / "preimage" - /: Dac_plugin.raw_hash_rpc_arg) + let get_preimage = + Tezos_rpc.Service.get_service + ~description:"Retrieves a page by its page hash and returns its contents" + ~query:Tezos_rpc.Query.empty + ~output:Data_encoding.bytes + Tezos_rpc.Path.(v0_prefix / "preimage" /: Dac_plugin.raw_hash_rpc_arg) -let put_dac_member_signature = - Tezos_rpc.Service.put_service - ~description: - "Verifies and stores the Dac member signature of a root page hash" - ~query:Tezos_rpc.Query.empty - ~input:Signature_repr.encoding - ~output:Data_encoding.empty - Tezos_rpc.Path.(open_root /: Api.version_rpc_arg / "dac_member_signature") + let put_dac_member_signature = + Tezos_rpc.Service.put_service + ~description: + "Verifies and stores the Dac member signature of a root page hash" + ~query:Tezos_rpc.Query.empty + ~input:Signature_repr.encoding + ~output:Data_encoding.empty + Tezos_rpc.Path.(v0_prefix / "dac_member_signature") -let get_certificate = - Tezos_rpc.Service.get_service - ~description: - "Retrieve the Dac certificate associated with the given root page hash" - ~query:Tezos_rpc.Query.empty - ~output:(Data_encoding.option Certificate_repr.encoding) - Tezos_rpc.Path.( - open_root /: Api.version_rpc_arg / "certificates" - /: Dac_plugin.raw_hash_rpc_arg) + let get_certificate = + Tezos_rpc.Service.get_service + ~description: + "Retrieve the Dac certificate associated with the given root page hash" + ~query:Tezos_rpc.Query.empty + ~output:(Data_encoding.option Certificate_repr.encoding) + Tezos_rpc.Path.(v0_prefix / "certificates" /: Dac_plugin.raw_hash_rpc_arg) -let get_missing_page = - Tezos_rpc.Service.get_service - ~description: - "Fetch a given page by forwarding the request to a Coordinator's GET \ - /preimage. The page is then saved to the node's page store before being \ - returned in the response. The endpoint should only be exposed in \ - Observer mode." - ~query:Tezos_rpc.Query.empty - ~output:Data_encoding.bytes - Tezos_rpc.Path.( - open_root /: Api.version_rpc_arg / "missing_page" - /: Dac_plugin.raw_hash_rpc_arg) + let get_missing_page = + Tezos_rpc.Service.get_service + ~description: + "Fetch a given page by forwarding the request to a Coordinator's GET \ + /preimage. The page is then saved to the node's page store before \ + being returned in the response. The endpoint should only be exposed \ + in Observer mode." + ~query:Tezos_rpc.Query.empty + ~output:Data_encoding.bytes + Tezos_rpc.Path.(v0_prefix / "missing_page" /: Dac_plugin.raw_hash_rpc_arg) -(* TODO: https://gitlab.com/tezos/tezos/-/issues/4935 - Coordinator's "POST /preimage" endpoint should in addition to root page hash - also return expiration level. Additionally, when it pushes a new root hash to - all attached subscribers, it should push it together with expiration level. *) + (* TODO: https://gitlab.com/tezos/tezos/-/issues/4935 + Coordinator's "POST /preimage" endpoint should in addition to root page hash + also return expiration level. Additionally, when it pushes a new root hash to + all attached subscribers, it should push it together with expiration level. *) -module Coordinator = struct - (** [Coordinator]'s endpoint for serializing dac payload. In addition to + module Coordinator = struct + (** [Coordinator]'s endpoint for serializing dac payload. In addition to returning a root page hash, it also pushes it to the subscribed [Observer]s and [Dac_member]s. *) - let post_preimage = - Tezos_rpc.Service.post_service - ~description: - "Stores the preimage in a sequence of pages. Returns a root page hash \ - representing the stored preimage. Additionally, it triggers streaming \ - of root page hash to subscribed committee members and observers. " - ~query:Tezos_rpc.Query.empty - ~input:Data_encoding.bytes - ~output:Dac_plugin.raw_hash_encoding - Tezos_rpc.Path.(open_root /: Api.version_rpc_arg / "preimage") + let post_preimage = + Tezos_rpc.Service.post_service + ~description: + "Stores the preimage in a sequence of pages. Returns a root page \ + hash representing the stored preimage. Additionally, it triggers \ + streaming of root page hash to subscribed committee members and \ + observers. " + ~query:Tezos_rpc.Query.empty + ~input:Data_encoding.bytes + ~output:Dac_plugin.raw_hash_encoding + Tezos_rpc.Path.(v0_prefix / "preimage") + end end diff --git a/src/lib_dac/RPC_services.mli b/src/lib_dac/RPC_services.mli index 234e172c8503..84be536172f5 100644 --- a/src/lib_dac/RPC_services.mli +++ b/src/lib_dac/RPC_services.mli @@ -23,106 +23,86 @@ (* *) (*****************************************************************************) -(** [Api] module is used for versioning DAC API. *) -module Api : sig - (** [version] type is used to version DAC API. *) - type version = - | V0 - (** [V0] is experimental DAC API. [V0] is deprecated, however for the - time being the API will be binding. It will be used by - 1M/tps demo. The plan is to remove it once we get rid of the - [Legacy] mode. Use at your own risk! *) +(* TODO: https://gitlab.com/tezos/tezos/-/issues/5579 + Add support for first publicly released DAC API [V1]. *) - (* TODO: https://gitlab.com/tezos/tezos/-/issues/5579 - Add support for first publicly released DAC API [V1]. *) - - (** [version_rpc_arg] is a API version argument for the RPCs.*) - val version_rpc_arg : version Tezos_rpc.Arg.arg -end - -(** "POST [api_version]/store_preimage" stores a payload using a given +(** [V0] is experimental DAC API. [V0] is deprecated, however for the + time being the API will be binding. It will be used by + 1M/tps demo. The plan is to remove it once we get rid of the + [Legacy] mode. Use at your own risk! *) +module V0 : sig + (** "POST v0/store_preimage" stores a payload using a given [pagination_scheme]. It returns the base58 encoded root page hash and the raw bytes. *) -val post_store_preimage : - ( [`POST], - unit, - unit * Api.version, - unit, - Bytes.t * Pagination_scheme.t, - Dac_plugin.raw_hash * Bytes.t ) - Tezos_rpc.Service.service + val post_store_preimage : + ( [`POST], + unit, + unit, + unit, + Bytes.t * Pagination_scheme.t, + Dac_plugin.raw_hash * Bytes.t ) + Tezos_rpc.Service.service -(** "GET [api_version]/verify_signature" endpoint requests the DAL node to verify + (** "GET v0/verify_signature" endpoint requests the DAL node to verify the signature of the external message [external_message]. The DAC committee of the DAL node must be the same that was used to produce the [external_message]. *) -val get_verify_signature : - ( [`GET], - unit, - unit * Api.version, - string option, - unit, - bool ) - Tezos_rpc.Service.service + val get_verify_signature : + ([`GET], unit, unit, string option, unit, bool) Tezos_rpc.Service.service -(** "GET [api_version]/preimage" requests the preimage of hash, consisting of a + (** "GET v0/preimage" requests the preimage of hash, consisting of a single page, from cctxt. When the request succeeds, the raw page will be returned as a sequence of bytes. *) -val get_preimage : - ( [`GET], - unit, - (unit * Api.version) * Dac_plugin.raw_hash, - unit, - unit, - Bytes.t ) - Tezos_rpc.Service.service + val get_preimage : + ( [`GET], + unit, + unit * Dac_plugin.raw_hash, + unit, + unit, + Bytes.t ) + Tezos_rpc.Service.service -(** "PUT [api_version]/member_signature" endpoint stores the [signature] + (** "PUT v0/member_signature" endpoint stores the [signature] generated from signing [hex_root_hash] by [dac_member_pkh]. *) -val put_dac_member_signature : - ( [`PUT], - unit, - unit * Api.version, - unit, - Signature_repr.t, - unit ) - Tezos_rpc.Service.service + val put_dac_member_signature : + ([`PUT], unit, unit, unit, Signature_repr.t, unit) Tezos_rpc.Service.service -(** "GET [api_version]/certificate" endpoint returns the DAC certificate for the + (** "GET v0/certificate" endpoint returns the DAC certificate for the provided [root_page_hash]. *) -val get_certificate : - ( [`GET], - unit, - (unit * Api.version) * Dac_plugin.raw_hash, - unit, - unit, - Certificate_repr.t option ) - Tezos_rpc.Service.service + val get_certificate : + ( [`GET], + unit, + unit * Dac_plugin.raw_hash, + unit, + unit, + Certificate_repr.t option ) + Tezos_rpc.Service.service -(** "GET [api_version]/missing_page/[page_hash]" Observer fetches the missing page + (** "GET v0/missing_page/[page_hash]" Observer fetches the missing page from a Coordinator node. The missing page is then saved to a page store before returning the page as a response. *) -val get_missing_page : - ( [`GET], - unit, - (unit * Api.version) * Dac_plugin.raw_hash, - unit, - unit, - Bytes.t ) - Tezos_rpc.Service.service + val get_missing_page : + ( [`GET], + unit, + unit * Dac_plugin.raw_hash, + unit, + unit, + Bytes.t ) + Tezos_rpc.Service.service -module Coordinator : sig - (** "POST [api_version]/preimage" sends a [payload] to the DAC + module Coordinator : sig + (** "POST v0/preimage" sends a [payload] to the DAC [Coordinator]. It returns a hex encoded root page hash, produced by [Merkle_tree_V0] pagination scheme. On the backend side it also pushes root page hash of the preimage to all the subscribed DAC Members and Observers. *) - val post_preimage : - ( [`POST], - unit, - unit * Api.version, - unit, - Bytes.t, - Dac_plugin.raw_hash ) - Tezos_rpc.Service.service + val post_preimage : + ( [`POST], + unit, + unit, + unit, + Bytes.t, + Dac_plugin.raw_hash ) + Tezos_rpc.Service.service + end end diff --git a/src/lib_dac/monitor_services.ml b/src/lib_dac/monitor_services.ml index cc0e7d2a6974..bf6dc7479198 100644 --- a/src/lib_dac/monitor_services.ml +++ b/src/lib_dac/monitor_services.ml @@ -23,46 +23,43 @@ (* *) (*****************************************************************************) -module S = struct - let root_hashes = - Tezos_rpc.Service.get_service - ~description: - "Monitor a stream of root hashes that are produced by another dac node \ - responsible for the serialization of the dac payload (coordinator). " - ~query:Tezos_rpc.Query.empty - ~output:Dac_plugin.raw_hash_encoding - Tezos_rpc.Path.( - open_root /: RPC_services.Api.version_rpc_arg / "monitor" - / "root_hashes") +module V0 = struct + module S = struct + let v0_prefix = Api_version.v0_prefix - let certificate = - Tezos_rpc.Service.get_service - ~description: - "Monitor a stream of updates to certificates for a given root hash. \ - Every time a new signature for the root hash is received by the \ - coordinator node, the corresponding certificate is updated and \ - streamed via this endpoint. This monitor endpoint guarantees at least \ - once delivery, i.e. a certificate update could be streamed multiple \ - times." - ~query:Tezos_rpc.Query.empty - ~output:Certificate_repr.encoding - Tezos_rpc.Path.( - open_root /: RPC_services.Api.version_rpc_arg / "monitor" - / "certificate" /: Dac_plugin.raw_hash_rpc_arg) -end + let root_hashes = + Tezos_rpc.Service.get_service + ~description: + "Monitor a stream of root hashes that are produced by another dac \ + node responsible for the serialization of the dac payload \ + (coordinator). " + ~query:Tezos_rpc.Query.empty + ~output:Dac_plugin.raw_hash_encoding + Tezos_rpc.Path.(v0_prefix / "monitor" / "root_hashes") + + let certificate = + Tezos_rpc.Service.get_service + ~description: + "Monitor a stream of updates to certificates for a given root hash. \ + Every time a new signature for the root hash is received by the \ + coordinator node, the corresponding certificate is updated and \ + streamed via this endpoint. This monitor endpoint guarantees at \ + least once delivery, i.e. a certificate update could be streamed \ + multiple times." + ~query:Tezos_rpc.Query.empty + ~output:Certificate_repr.encoding + Tezos_rpc.Path.( + v0_prefix / "monitor" / "certificate" /: Dac_plugin.raw_hash_rpc_arg) + end -let root_hashes dac_node_cctxt api_version = - Tezos_rpc.Context.make_streamed_call - S.root_hashes - dac_node_cctxt - ((), api_version) - () - () + let root_hashes dac_node_cctxt = + Tezos_rpc.Context.make_streamed_call S.root_hashes dac_node_cctxt () () () -let certificate dac_node_cctxt root_hash api_version = - Tezos_rpc.Context.make_streamed_call - S.certificate - dac_node_cctxt - (((), api_version), root_hash) - () - () + let certificate dac_node_cctxt root_hash = + Tezos_rpc.Context.make_streamed_call + S.certificate + dac_node_cctxt + ((), root_hash) + () + () +end diff --git a/src/lib_dac/monitor_services.mli b/src/lib_dac/monitor_services.mli index c491ee7e8f92..f1e838c17a85 100644 --- a/src/lib_dac/monitor_services.mli +++ b/src/lib_dac/monitor_services.mli @@ -23,49 +23,53 @@ (* *) (*****************************************************************************) -module S : sig - (** Define RPC "GET [api_version]/monitor/root_hashes". *) - val root_hashes : - ( [`GET], - unit, - unit * RPC_services.Api.version, - unit, - unit, - Dac_plugin.raw_hash ) - Tezos_rpc.Service.service +(** [V0] is experimental DAC API. [V0] is deprecated, however for the + time being the API will be binding. It will be used by + 1M/tps demo. The plan is to remove it once we get rid of the + [Legacy] mode. Use at your own risk! *) +module V0 : sig + module S : sig + (** Define RPC "GET v0/monitor/root_hashes". *) + val root_hashes : + ( [`GET], + unit, + unit, + unit, + unit, + Dac_plugin.raw_hash ) + Tezos_rpc.Service.service - (** Define RPC GET [api_version]/monitor/certificate/hex_root_hash. *) - val certificate : - ( [`GET], - unit, - (unit * RPC_services.Api.version) * Dac_plugin.raw_hash, - unit, - unit, - Certificate_repr.t ) - Tezos_rpc.Service.service -end + (** Define RPC "GET v0/monitor/certificate/hex_root_hash". *) + val certificate : + ( [`GET], + unit, + unit * Dac_plugin.raw_hash, + unit, + unit, + Certificate_repr.t ) + Tezos_rpc.Service.service + end -(** [root_hashes streamed_cctxt raw_hash api_version] returns a stream + (** [root_hashes streamed_cctxt raw_hash] returns a stream of root hashes and a stopper for it. - Stream is produced by calling RPC "GET [api_version]/monitor/root_hashes". + Stream is produced by calling RPC "GET v0/monitor/root_hashes". *) -val root_hashes : - #Tezos_rpc.Context.streamed -> - RPC_services.Api.version -> - (Dac_plugin.raw_hash Lwt_stream.t * Tezos_rpc.Context.stopper) - Error_monad.tzresult - Lwt.t + val root_hashes : + #Tezos_rpc.Context.streamed -> + (Dac_plugin.raw_hash Lwt_stream.t * Tezos_rpc.Context.stopper) + Error_monad.tzresult + Lwt.t -(** [certificate streamed_cctxt raw_hash api_version] returns a stream and a + (** [certificate streamed_cctxt raw_hash] returns a stream and a stopper for monitoring certificate updates for a given root hash. - Stream is produced by calling RPC "GET [api_version]/monitor/certificate". + Stream is produced by calling RPC "GET v0/monitor/certificate". *) -val certificate : - #Tezos_rpc.Context.streamed -> - Dac_plugin.raw_hash -> - RPC_services.Api.version -> - (Certificate_repr.t Lwt_stream.t * Tezos_rpc.Context.stopper) - Error_monad.tzresult - Lwt.t + val certificate : + #Tezos_rpc.Context.streamed -> + Dac_plugin.raw_hash -> + (Certificate_repr.t Lwt_stream.t * Tezos_rpc.Context.stopper) + Error_monad.tzresult + Lwt.t +end diff --git a/src/lib_dac_client/dac_node_client.ml b/src/lib_dac_client/dac_node_client.ml index 3c191403fe4f..d1dfdd65d756 100644 --- a/src/lib_dac_client/dac_node_client.ml +++ b/src/lib_dac_client/dac_node_client.ml @@ -52,58 +52,42 @@ module V0 = struct was computed. *) let get_preimage (cctxt : #cctxt) ~page_hash = - cctxt#call_service - RPC_services.get_preimage - (((), RPC_services.Api.V0), page_hash) - () - () + cctxt#call_service RPC_services.V0.get_preimage ((), page_hash) () () let post_store_preimage (cctxt : #cctxt) ~payload ~pagination_scheme = cctxt#call_service - RPC_services.post_store_preimage - ((), RPC_services.Api.V0) + RPC_services.V0.post_store_preimage + () () (payload, pagination_scheme) let get_verify_signature (cctxt : #cctxt) ~external_message = cctxt#call_service - RPC_services.get_verify_signature - ((), RPC_services.Api.V0) + RPC_services.V0.get_verify_signature + () external_message () let put_dac_member_signature (cctxt : #cctxt) ~signature = - cctxt#call_service - RPC_services.put_dac_member_signature - ((), RPC_services.Api.V0) - () - signature + cctxt#call_service RPC_services.V0.put_dac_member_signature () () signature let get_certificate (cctxt : #cctxt) ~root_page_hash = cctxt#call_service - RPC_services.get_certificate - (((), RPC_services.Api.V0), root_page_hash) + RPC_services.V0.get_certificate + ((), root_page_hash) () () let monitor_certificate (cctxt : #cctxt) ~root_hash = - Monitor_services.certificate cctxt root_hash RPC_services.Api.V0 + Monitor_services.V0.certificate cctxt root_hash module Coordinator = struct let post_preimage (cctxt : #cctxt) ~payload = - cctxt#call_service - RPC_services.Coordinator.post_preimage - ((), RPC_services.Api.V0) - () - payload + cctxt#call_service RPC_services.V0.Coordinator.post_preimage () () payload end module Observer = struct let get_missing_page (cctxt : #cctxt) page_hash = - cctxt#call_service - RPC_services.get_missing_page - (((), RPC_services.Api.V0), page_hash) - () - () + cctxt#call_service RPC_services.V0.get_missing_page ((), page_hash) () () end end diff --git a/src/lib_dac_node/RPC_server.ml b/src/lib_dac_node/RPC_server.ml index 8d6d7a741172..b6d2800fb404 100644 --- a/src/lib_dac_node/RPC_server.ml +++ b/src/lib_dac_node/RPC_server.ml @@ -165,9 +165,9 @@ let register_post_store_preimage ctx cctxt dac_sk_uris page_store hash_streamer directory = directory |> add_service - Tezos_rpc.Directory.register1 - RPC_services.post_store_preimage - (fun _api_version () input -> + Tezos_rpc.Directory.register0 + RPC_services.V0.post_store_preimage + (fun () input -> handle_post_store_preimage ctx cctxt @@ -179,36 +179,35 @@ let register_post_store_preimage ctx cctxt dac_sk_uris page_store hash_streamer let register_get_verify_signature dac_plugin public_keys_opt directory = directory |> add_service - Tezos_rpc.Directory.register1 - RPC_services.get_verify_signature - (fun _api_version external_message () -> + Tezos_rpc.Directory.register0 + RPC_services.V0.get_verify_signature + (fun external_message () -> handle_get_verify_signature dac_plugin public_keys_opt external_message) let register_get_preimage dac_plugin page_store = add_service - Tezos_rpc.Directory.register2 - RPC_services.get_preimage - (fun _api_version hash () () -> - handle_get_preimage dac_plugin page_store hash) + Tezos_rpc.Directory.register1 + RPC_services.V0.get_preimage + (fun hash () () -> handle_get_preimage dac_plugin page_store hash) let register_monitor_root_hashes hash_streamer dir = Tezos_rpc.Directory.gen_register dir - Monitor_services.S.root_hashes - (fun _api_version () () -> handle_monitor_root_hashes hash_streamer) + Monitor_services.V0.S.root_hashes + (fun () () () -> handle_monitor_root_hashes hash_streamer) let register_get_certificate node_store dac_plugin = add_service - Tezos_rpc.Directory.register2 - RPC_services.get_certificate - (fun _api_version root_hash () () -> + Tezos_rpc.Directory.register1 + RPC_services.V0.get_certificate + (fun root_hash () () -> handle_get_certificate dac_plugin node_store root_hash) let register_get_missing_page dac_plugin page_store cctxt = add_service - Tezos_rpc.Directory.register2 - RPC_services.get_missing_page - (fun _api_version root_hash () () -> + Tezos_rpc.Directory.register1 + RPC_services.V0.get_missing_page + (fun root_hash () () -> handle_get_missing_page cctxt page_store dac_plugin root_hash) module Coordinator = struct @@ -285,8 +284,8 @@ module Coordinator = struct certificate_streamers committee_members dir = Tezos_rpc.Directory.gen_register dir - Monitor_services.S.certificate - (fun (((), _api_version), root_hash) () () -> + Monitor_services.V0.S.certificate + (fun ((), root_hash) () () -> let open Lwt_result_syntax in let*! handler = handle_monitor_certificate @@ -302,17 +301,17 @@ module Coordinator = struct let register_post_preimage dac_plugin hash_streamer page_store = add_service - Tezos_rpc.Directory.register1 - RPC_services.Coordinator.post_preimage - (fun _api_version () payload -> + Tezos_rpc.Directory.register0 + RPC_services.V0.Coordinator.post_preimage + (fun () payload -> handle_post_preimage dac_plugin page_store hash_streamer payload) let register_put_dac_member_signature ctx dac_plugin rw_node_store page_store cctxt = add_service - Tezos_rpc.Directory.register1 - RPC_services.put_dac_member_signature - (fun _api_version () dac_member_signature -> + Tezos_rpc.Directory.register0 + RPC_services.V0.put_dac_member_signature + (fun () dac_member_signature -> Signature_manager.Coordinator.handle_put_dac_member_signature ctx dac_plugin @@ -362,9 +361,9 @@ module Legacy = struct let register_put_dac_member_signature ctx dac_plugin rw_node_store page_store cctxt = add_service - Tezos_rpc.Directory.register1 - RPC_services.put_dac_member_signature - (fun _api_version () dac_member_signature -> + Tezos_rpc.Directory.register0 + RPC_services.V0.put_dac_member_signature + (fun () dac_member_signature -> Signature_manager.Legacy.handle_put_dac_member_signature ctx dac_plugin diff --git a/src/lib_dac_node/handler.ml b/src/lib_dac_node/handler.ml index 63042cea6e97..5b4dddc23e4a 100644 --- a/src/lib_dac_node/handler.ml +++ b/src/lib_dac_node/handler.ml @@ -206,7 +206,7 @@ module Committee_member = struct let*! () = Event.(emit subscribed_to_root_hashes_stream ()) in make_stream_daemon (handler dac_plugin remote_store) - (Monitor_services.root_hashes coordinator_cctxt RPC_services.Api.V0) + (Monitor_services.V0.root_hashes coordinator_cctxt) end (** Handlers specific to an [Observer]. An [Observer] is responsible for @@ -249,7 +249,7 @@ module Observer = struct let*! () = Event.(emit subscribed_to_root_hashes_stream ()) in make_stream_daemon (handler dac_plugin remote_store) - (Monitor_services.root_hashes coordinator_cctxt RPC_services.Api.V0) + (Monitor_services.V0.root_hashes coordinator_cctxt) end (** Handlers specific to a [Legacy] DAC node. If no @@ -362,7 +362,7 @@ module Legacy = struct let*! () = Event.(emit subscribed_to_root_hashes_stream ()) in make_stream_daemon (handler dac_plugin remote_store) - (Monitor_services.root_hashes coordinator_cctxt RPC_services.Api.V0) + (Monitor_services.V0.root_hashes coordinator_cctxt) end let handlers node_ctxt = diff --git a/tezt/tests/dac.ml b/tezt/tests/dac.ml index 7c57bacfe59e..f50d5bde3b87 100644 --- a/tezt/tests/dac.ml +++ b/tezt/tests/dac.ml @@ -2510,26 +2510,6 @@ module Tx_kernel_e2e = struct (test_tx_kernel_e2e_with_dac_observer_missing_pages commitment_period) end -(** [Api] module consist of tests about valid API calls and API versioning. *) -module Api = struct - (** Test that existing endpoints only support valid API version prefix. *) - let test_only_valid_api_version_prefix_is_supported - Scenarios.{coordinator_node; _} = - (* We want to test that [api_version_rpc_arg] only captures - valid api version. For this we choose a concrete endpoint from V0 API, - and pass it invalid [api_version]. *) - let* response = - RPC.call_raw - coordinator_node - Dac_rpc.( - post_store_preimage - ~payload:"test" - ~pagination_scheme:"Merkle_tree_V0" - ~api_version:"Invalid API version prefix") - in - Lwt.return @@ RPC.check_string_response ~code:400 response -end - let register ~protocols = (* Tests with layer1 and dac nodes *) Legacy.test_dac_node_startup protocols ; @@ -2656,12 +2636,5 @@ let register ~protocols = Full_infrastructure.test_client protocols ; Tx_kernel_e2e.test_tx_kernel_e2e_with_dac_observer_synced_with_dac protocols ; - Tx_kernel_e2e.test_tx_kernel_e2e_with_dac_observer_missing_pages protocols ; - scenario_with_full_dac_infrastructure - ~__FILE__ - ~committee_size:0 - ~observers:0 - ~tags:["dac"; "dac_node"] - "only valid api version prefix is supported" - Api.test_only_valid_api_version_prefix_is_supported - protocols + Tx_kernel_e2e.test_tx_kernel_e2e_with_dac_observer_missing_pages protocols + \ No newline at end of file -- GitLab From 18eae787aff6f8330307aaa1912b177b6d61739e Mon Sep 17 00:00:00 2001 From: martintomazic Date: Tue, 16 May 2023 01:37:00 +0200 Subject: [PATCH 3/3] DAC/tezt: Encapsulate Dac_rpc onto V0 module --- tezt/lib_tezos/dac_rpc.ml | 113 +++++++++++++------------ tezt/lib_tezos/dac_rpc.mli | 102 ++++++++++------------ tezt/tests/dac.ml | 169 +++++++++++++------------------------ 3 files changed, 160 insertions(+), 224 deletions(-) diff --git a/tezt/lib_tezos/dac_rpc.ml b/tezt/lib_tezos/dac_rpc.ml index 0560dd089016..9832cc08cdc2 100644 --- a/tezt/lib_tezos/dac_rpc.ml +++ b/tezt/lib_tezos/dac_rpc.ml @@ -23,10 +23,6 @@ (* *) (*****************************************************************************) -module Api = struct - let v0 = "v0" -end - let make ?data ?query_string = RPC.make ?data @@ -44,64 +40,69 @@ 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 ~api_version = - make GET [api_version; "preimage"; page_hash] JSON.as_string +module V0 = struct + let api_prefix = "v0" -let post_store_preimage ~payload ~pagination_scheme ~api_version = - let preimage = - JSON.parse - ~origin:"dal_node_dac_store_preimage_rpc" - (Format.sprintf - {|{"payload":%s,"pagination_scheme":"%s"}|} - (encode_bytes_to_hex_string payload) - pagination_scheme) - in - let data : RPC_core.data = Data (JSON.unannotate preimage) in - make ~data POST [api_version; "store_preimage"] @@ fun json -> - JSON. - ( json |-> "root_hash" |> as_string, - json |-> "external_message" |> get_bytes_from_json_string_node ) + let get_preimage page_hash = + make GET [api_prefix; "preimage"; page_hash] JSON.as_string -let get_verify_signature external_msg ~api_version = - let query_string = - [("external_message", match Hex.of_string external_msg with `Hex s -> s)] - in - make ~query_string GET [api_version; "verify_signature"] JSON.as_bool + let post_store_preimage ~payload ~pagination_scheme = + let preimage = + JSON.parse + ~origin:"dal_node_dac_store_preimage_rpc" + (Format.sprintf + {|{"payload":%s,"pagination_scheme":"%s"}|} + (encode_bytes_to_hex_string payload) + pagination_scheme) + in + let data : RPC_core.data = Data (JSON.unannotate preimage) in + make ~data POST [api_prefix; "store_preimage"] @@ fun json -> + JSON. + ( json |-> "root_hash" |> as_string, + json |-> "external_message" |> get_bytes_from_json_string_node ) -let put_dac_member_signature ~hex_root_hash ~dac_member_pkh ~signature - ~api_version = - let (`Hex root_hash) = hex_root_hash in - let payload = - `O + let get_verify_signature external_msg = + let query_string = [ - ("root_hash", `String root_hash); - ("signer_pkh", `String dac_member_pkh); - ( "signature", - `String (Tezos_crypto.Aggregate_signature.to_b58check signature) ); + ("external_message", match Hex.of_string external_msg with `Hex s -> s); ] - in - let data : RPC_core.data = Data payload in - make ~data PUT [api_version; "dac_member_signature"] @@ fun _resp -> () + in + make ~query_string GET [api_prefix; "verify_signature"] JSON.as_bool -let get_missing_page ~hex_root_hash ~api_version = - make GET [api_version; "missing_page"; Hex.show hex_root_hash] JSON.as_string + let put_dac_member_signature ~hex_root_hash ~dac_member_pkh ~signature = + let (`Hex root_hash) = hex_root_hash in + let payload = + `O + [ + ("root_hash", `String root_hash); + ("signer_pkh", `String dac_member_pkh); + ( "signature", + `String (Tezos_crypto.Aggregate_signature.to_b58check signature) ); + ] + in + let data : RPC_core.data = Data payload in + make ~data PUT [api_prefix; "dac_member_signature"] @@ fun _resp -> () -let get_certificate ~hex_root_hash ~api_version = - let (`Hex page_hash) = hex_root_hash in - make GET [api_version; "certificates"; page_hash] @@ fun json -> - JSON. - ( json |-> "witnesses" |> as_int, - json |-> "aggregate_signature" |> as_string, - json |-> "root_hash" |> as_string, - json |-> "version" |> as_int ) + let get_missing_page ~hex_root_hash = + make GET [api_prefix; "missing_page"; Hex.show hex_root_hash] JSON.as_string -module Coordinator = struct - let post_preimage ~payload ~api_version = - let preimage = - JSON.parse - ~origin:"Rollup.DAC.RPC.coordinator_post_preimage" - (encode_bytes_to_hex_string payload) - in - let data : RPC_core.data = Data (JSON.unannotate preimage) in - make ~data POST [api_version; "preimage"] JSON.as_string + let get_certificate ~hex_root_hash = + let (`Hex page_hash) = hex_root_hash in + make GET [api_prefix; "certificates"; page_hash] @@ fun json -> + JSON. + ( json |-> "witnesses" |> as_int, + json |-> "aggregate_signature" |> as_string, + json |-> "root_hash" |> as_string, + json |-> "version" |> as_int ) + + module Coordinator = struct + let post_preimage ~payload = + let preimage = + JSON.parse + ~origin:"Rollup.DAC.RPC.coordinator_post_preimage" + (encode_bytes_to_hex_string payload) + in + let data : RPC_core.data = Data (JSON.unannotate preimage) in + make ~data POST [api_prefix; "preimage"] JSON.as_string + end end diff --git a/tezt/lib_tezos/dac_rpc.mli b/tezt/lib_tezos/dac_rpc.mli index fa5b2b92e506..5aed5456b2ec 100644 --- a/tezt/lib_tezos/dac_rpc.mli +++ b/tezt/lib_tezos/dac_rpc.mli @@ -23,68 +23,56 @@ (* *) (*****************************************************************************) -(** [Api] module is used for versioning DAC API. *) -module Api : sig - (** [v0] is experimental DAC API, which will be deprecated soon. However, for - the time being the API is binding. It will be used by 1M/tps demo. - The plan is to remove it once we get rid of the [Legacy] mode. - Do not use it! *) - val v0 : string -end +(** [V0] is experimental DAC API. *) +module V0 : sig + (** [api_prefix] is a URL prefix of the [V0] API endpoints. *) + val api_prefix : string -(** [get_preimage hash ~api_version] requests the preimage of hash, consisting of a - single page, from cctxt. When the request succeeds, the raw page will be - returned as a sequence of bytes. *) -val get_preimage : - string -> api_version:string -> (Dac_node.t, string) RPC_core.t + (** [get_preimage hash] requests the preimage of hash, consisting of a + single page, from cctxt. When the request succeeds, the raw page will be + returned as a sequence of bytes. *) + val get_preimage : string -> (Dac_node.t, string) RPC_core.t -(** [post_store_preimage cctxt ~payload ~pagination_scheme ~api_version] posts a - [payload] to [api_version]/store_preimage using a given [pagination_scheme]. - It returns the hex encoded root page hash and the raw bytes that can be used - as contents of a rollup message to trigger the request of the payload in a - WASM rollup. *) -val post_store_preimage : - payload:string -> - pagination_scheme:string -> - api_version:string -> - (Dac_node.t, string * string) RPC_core.t + (** [post_store_preimage cctxt ~payload ~pagination_scheme] posts a + [payload] to "v0/store_preimage" using a given [pagination_scheme]. + It returns the hex encoded root page hash and the raw bytes that can be used + as contents of a rollup message to trigger the request of the payload in a + WASM rollup. *) + val post_store_preimage : + payload:string -> + pagination_scheme:string -> + (Dac_node.t, string * string) RPC_core.t -(** [get_verify_signature cctxt external_message ~api_version] requests the DAL - node to verify the signature of the external message [external_message] via - the plugin/dac/verify_signature endpoint. The DAC committee - of the DAL node must be the same that was used to produce the - [external_message]. *) -val get_verify_signature : - string -> api_version:string -> (Dac_node.t, bool) RPC_core.t + (** [get_verify_signature cctxt external_message] requests the DAC + node to verify the signature of the external message [external_message] via + the v0/verify_signature endpoint. The DAC committee of the DAC node must + be the same that was used to produce the [external_message]. *) + val get_verify_signature : string -> (Dac_node.t, bool) RPC_core.t -(** [put_dac_member_signature hex_root_hash dac_member_pkh signature ~api_version] - stores the [signature] generated from signing [hex_root_hash] by - [dac_member_pkh]. *) -val put_dac_member_signature : - hex_root_hash:Hex.t -> - dac_member_pkh:string -> - signature:Tezos_crypto.Aggregate_signature.t -> - api_version:string -> - (Dac_node.t, unit) RPC_core.t + (** [put_dac_member_signature hex_root_hash dac_member_pkh signature] + stores the [signature] generated from signing [hex_root_hash] by + [dac_member_pkh]. *) + val put_dac_member_signature : + hex_root_hash:Hex.t -> + dac_member_pkh:string -> + signature:Tezos_crypto.Aggregate_signature.t -> + (Dac_node.t, unit) RPC_core.t -(** [get_missing_page ~hex_root_hash ~api_version] calls GET - [api_version]/missing_page/[page_hash] endpoint. *) -val get_missing_page : - hex_root_hash:Hex.t -> api_version:string -> (Dac_node.t, string) RPC_core.t + (** [get_missing_page ~hex_root_hash] calls + "GET v0/missing_page/[page_hash]" endpoint. *) + val get_missing_page : hex_root_hash:Hex.t -> (Dac_node.t, string) RPC_core.t -(** [get_certificate ~hex_root_hash ~api_version] fetches the DAC certificate - for the provided [hex_root_hash]. *) -val get_certificate : - hex_root_hash:Hex.t -> - api_version:string -> - (Dac_node.t, int * string * string * int) RPC_core.t + (** [get_certificate ~hex_root_hash] fetches the DAC certificate + for the provided [hex_root_hash]. *) + val get_certificate : + hex_root_hash:Hex.t -> (Dac_node.t, int * string * string * int) RPC_core.t -module Coordinator : sig - (** [post_preimage ~payload ~api_version] sends a [payload] to the DAC - [Coordinator] via a POST RPC call to dac/preimage. It returns a hex - encoded root page hash, produced by [Merkle_tree_V0] pagination scheme. - On the backend side it also pushes root page hash of the preimage to all - the subscribed DAC Members and Observers. *) - val post_preimage : - payload:string -> api_version:string -> (Dac_node.t, string) RPC_core.t + module Coordinator : sig + (** [post_preimage ~payload] sends a [payload] to the DAC [Coordinator] via + a POST RPC call to v0/preimage. It returns a hex encoded root page hash, + produced by [Merkle_tree_V0] pagination scheme. On the backend side it + also pushes root page hash of the preimage to all the subscribed + DAC Members and Observers. *) + val post_preimage : payload:string -> (Dac_node.t, string) RPC_core.t + end end diff --git a/tezt/tests/dac.ml b/tezt/tests/dac.ml index f50d5bde3b87..93bd8b66acc5 100644 --- a/tezt/tests/dac.ml +++ b/tezt/tests/dac.ml @@ -44,15 +44,14 @@ let assert_lwt_failure ?__LOC__ msg lwt_under_inspection = in if passed then unit else Test.fail ?__LOC__ msg -let init_hex_root_hash ?payload coordinator_node ~api_version = +let init_hex_root_hash ?payload coordinator_node = let payload = Option.value payload ~default:"hello test message" in let* root_hash, _l1_op = RPC.call coordinator_node - (Dac_rpc.post_store_preimage + (Dac_rpc.V0.post_store_preimage ~payload - ~pagination_scheme:"Merkle_tree_V0" - ~api_version) + ~pagination_scheme:"Merkle_tree_V0") in let hex_root_hash = `Hex root_hash in return hex_root_hash @@ -97,13 +96,13 @@ let parse_certificate json = (* Helper process that listens to certificate updates through a RPC request. Upon termination, the list of certificate updates is returned *) -let streamed_certificates_client coordinator_node root_hash api_version = +let streamed_certificates_client coordinator_node root_hash = let endpoint = Format.sprintf "http://%s:%d/%s/monitor/certificate/%s" (Dac_node.rpc_host coordinator_node) (Dac_node.rpc_port coordinator_node) - api_version + Dac_rpc.V0.api_prefix root_hash in RPC.Curl.get_raw endpoint @@ -201,14 +200,14 @@ let check_preimage expected_preimage actual_preimage = [coordinator]. It returns the list of the hashes contained in the [page_hash], if the page corresponds to a hash page. Otherwise, it returns the empty list. *) -let check_downloaded_page coordinator observer page_hash ~api_version = +let check_downloaded_page coordinator observer page_hash = let* coordinator_hex_encoded_page = - RPC.call coordinator Dac_rpc.(get_preimage page_hash ~api_version) + RPC.call coordinator (Dac_rpc.V0.get_preimage page_hash) in let coordinator_page = Hex.to_string (`Hex coordinator_hex_encoded_page) in (* Check that the page has been saved by the observer. *) let* observer_hex_encoded_page = - RPC.call observer (Dac_rpc.get_preimage page_hash ~api_version) + RPC.call observer (Dac_rpc.V0.get_preimage page_hash) in let observer_page = Hex.to_string (`Hex observer_hex_encoded_page) in (* Check that the raw page for the root hash stored in the coordinator @@ -244,14 +243,12 @@ let check_downloaded_page coordinator observer page_hash ~api_version = in return @@ split_hashes concatenated_hashes [] -let check_downloaded_preimage coordinator observer root_hash ~api_version = +let check_downloaded_preimage coordinator observer root_hash = let rec go hashes = match hashes with | [] -> return () | hash :: hashes -> - let* next_hashes = - check_downloaded_page coordinator observer hash ~api_version - in + let* next_hashes = check_downloaded_page coordinator observer hash in go (hashes @ next_hashes) in go [root_hash] @@ -300,8 +297,6 @@ let sample_payload example_filename = module should be refactored. *) module Legacy = struct (** [Legacy] test suite uses [v0] DAC API. *) - let api_version = Dac_rpc.Api.v0 - let set_coordinator dac_node coordinator = let coordinator = `O @@ -323,10 +318,9 @@ module Legacy = struct let* actual_rh, _l1_operation = RPC.call coordinator - (Dac_rpc.post_store_preimage + (Dac_rpc.V0.post_store_preimage ~payload - ~pagination_scheme:"Merkle_tree_V0" - ~api_version) + ~pagination_scheme:"Merkle_tree_V0") in return @@ check_valid_root_hash expected_rh actual_rh @@ -444,10 +438,9 @@ module Legacy = struct let* actual_rh, l1_operation = RPC.call dac_node - (Dac_rpc.post_store_preimage + (Dac_rpc.V0.post_store_preimage ~payload - ~pagination_scheme:"Merkle_tree_V0" - ~api_version) + ~pagination_scheme:"Merkle_tree_V0") in (* Expected reveal hash equals to the result of [Tezos_dac_alpha.Dac_pages_encoding.Merkle_tree.V0.serialize_payload "test"]. @@ -470,7 +463,7 @@ module Legacy = struct in check_preimage payload recovered_preimage ; let* is_signature_valid = - RPC.call dac_node (Dac_rpc.get_verify_signature l1_operation ~api_version) + RPC.call dac_node (Dac_rpc.V0.get_verify_signature l1_operation) in Check.( (is_signature_valid = true) @@ -485,10 +478,9 @@ module Legacy = struct let* actual_rh, _l1_operation = RPC.call dac_node - (Dac_rpc.post_store_preimage + (Dac_rpc.V0.post_store_preimage ~payload - ~pagination_scheme:"Hash_chain_V0" - ~api_version) + ~pagination_scheme:"Hash_chain_V0") in (* Expected reveal hash equals to the result of [Tezos_dac_alpha.Dac_pages_encoding.Hash_chain.V0.serialize_payload "test"]. @@ -518,10 +510,9 @@ module Legacy = struct let* actual_rh, _l1_operation = RPC.call dac_node - (Dac_rpc.post_store_preimage + (Dac_rpc.V0.post_store_preimage ~payload - ~pagination_scheme:"Merkle_tree_V0" - ~api_version) + ~pagination_scheme:"Merkle_tree_V0") in (* Expected reveal hash equals to the result of [Tezos_dac_alpha.Dac_pages_encoding.Merkle_tree.V0.serialize_payload "test"]. @@ -539,9 +530,7 @@ module Legacy = struct let recovered_payload = really_input_string cin (in_channel_length cin) in let () = close_in cin in let recovered_preimage = Hex.of_string recovered_payload in - let* preimage = - RPC.call dac_node (Dac_rpc.get_preimage expected_rh ~api_version) - in + let* preimage = RPC.call dac_node (Dac_rpc.V0.get_preimage expected_rh) in Check.( (preimage = Hex.show recovered_preimage) string @@ -579,10 +568,9 @@ module Legacy = struct let* actual_rh, _l1_operation = RPC.call dac_node - (Dac_rpc.post_store_preimage + (Dac_rpc.V0.post_store_preimage ~payload - ~pagination_scheme:"Hash_chain_V0" - ~api_version) + ~pagination_scheme:"Hash_chain_V0") in let expected_rh = "0027782d2a7020be332cc42c4e66592ec50305f559a4011981f1d5af81428e7aa3" @@ -622,10 +610,9 @@ module Legacy = struct let _actual_rh = RPC.call dac_node - (Dac_rpc.post_store_preimage + (Dac_rpc.V0.post_store_preimage ~payload - ~pagination_scheme:"Hash_chain_V0" - ~api_version) + ~pagination_scheme:"Hash_chain_V0") in let errorneous_hash = "0027782d2a7020be332cc42c4e66592ec50305f559a4011981f1d5af81428ecafe" @@ -883,7 +870,7 @@ module Legacy = struct let* () = push_promise in (* Assert [observer] emitted event of received [expected_rh]. *) let* () = fetch_root_hash_promise in - check_downloaded_preimage coordinator observer expected_rh ~api_version + check_downloaded_preimage coordinator observer expected_rh (* 1. Observer should fetch missing page from Coordinator when GET /missing_page/{hash} is called. @@ -899,11 +886,9 @@ module Legacy = struct wait_for_root_hash_pushed_to_data_streamer coordinator root_hash in let* hex_root_hash = - init_hex_root_hash - ~payload:"test payload abc 123" - coordinator - ~api_version + init_hex_root_hash ~payload:"test payload abc 123" coordinator in + assert (root_hash = Hex.show hex_root_hash) ; let* () = root_hash_stream_promise in let observer = @@ -916,23 +901,17 @@ module Legacy = struct assert_lwt_failure ~__LOC__ "Expected retrieve_preimage" - (RPC.call - observer - (Dac_rpc.get_preimage (Hex.show hex_root_hash) ~api_version)) + (RPC.call observer (Dac_rpc.V0.get_preimage (Hex.show hex_root_hash))) in let* missing_page = - RPC.call observer (Dac_rpc.get_missing_page ~hex_root_hash ~api_version) + RPC.call observer (Dac_rpc.V0.get_missing_page ~hex_root_hash) in let* coordinator_page = - RPC.call - coordinator - (Dac_rpc.get_preimage (Hex.show hex_root_hash) ~api_version) + RPC.call coordinator (Dac_rpc.V0.get_preimage (Hex.show hex_root_hash)) in check_preimage coordinator_page missing_page ; let* observer_preimage = - RPC.call - observer - (Dac_rpc.get_preimage (Hex.show hex_root_hash) ~api_version) + RPC.call observer (Dac_rpc.V0.get_preimage (Hex.show hex_root_hash)) in check_preimage coordinator_page observer_preimage ; unit @@ -947,11 +926,10 @@ module Legacy = struct let result = RPC.call coordinator_node - (Dac_rpc.put_dac_member_signature + (Dac_rpc.V0.put_dac_member_signature ~hex_root_hash ~dac_member_pkh:invalid_signer_key.aggregate_public_key_hash - ~signature - ~api_version) + ~signature) in assert_lwt_failure ~__LOC__ @@ -973,11 +951,10 @@ module Legacy = struct let result = RPC.call coordinator_node - (Dac_rpc.put_dac_member_signature + (Dac_rpc.V0.put_dac_member_signature ~hex_root_hash ~dac_member_pkh:memberj.aggregate_public_key_hash - ~signature - ~api_version) + ~signature) in assert_lwt_failure ~__LOC__ @@ -1005,20 +982,17 @@ module Legacy = struct let* () = RPC.call coordinator_node - (Dac_rpc.put_dac_member_signature + (Dac_rpc.V0.put_dac_member_signature ~hex_root_hash ~dac_member_pkh:member.aggregate_public_key_hash - ~signature - ~api_version) + ~signature) in return (member :: keys)) (return []) members in let* witnesses, certificate, _root_hash, _version = - RPC.call - coordinator_node - (Dac_rpc.get_certificate ~hex_root_hash ~api_version) + RPC.call coordinator_node (Dac_rpc.V0.get_certificate ~hex_root_hash) in assert_witnesses ~__LOC__ 3 witnesses ; assert_verify_aggregate_signature members_keys hex_root_hash certificate ; @@ -1027,11 +1001,9 @@ module Legacy = struct let test_store_same_signature_more_than_once_should_be_noop (coordinator_node, _hex_root_hash, dac_committee) = let* hex_root_hash = - init_hex_root_hash - ~payload:"noop test abc 3210" - coordinator_node - ~api_version + init_hex_root_hash ~payload:"noop test abc 3210" coordinator_node in + let member_i = 2 in let member = List.nth dac_committee member_i in let signature = bls_sign_hex_hash member hex_root_hash in @@ -1039,18 +1011,15 @@ module Legacy = struct let call () = RPC.call coordinator_node - (Dac_rpc.put_dac_member_signature + (Dac_rpc.V0.put_dac_member_signature ~hex_root_hash ~dac_member_pkh - ~signature - ~api_version) + ~signature) in let* () = call () in let* () = call () in let* witnesses, certificate, _root_hash, _version = - RPC.call - coordinator_node - (Dac_rpc.get_certificate ~hex_root_hash ~api_version) + RPC.call coordinator_node (Dac_rpc.V0.get_certificate ~hex_root_hash) in assert_witnesses ~__LOC__ 4 witnesses ; assert_verify_aggregate_signature [member] hex_root_hash certificate ; @@ -1069,11 +1038,10 @@ module Legacy = struct let result = RPC.call coordinator_node - (Dac_rpc.put_dac_member_signature + (Dac_rpc.V0.put_dac_member_signature ~hex_root_hash:false_root_hash ~dac_member_pkh - ~signature - ~api_version) + ~signature) in assert_lwt_failure ~__LOC__ @@ -1082,7 +1050,7 @@ module Legacy = struct let test_handle_store_signature _protocol _tezos_node tz_client coordinator _threshold dac_committee = - let* hex_root_hash = init_hex_root_hash coordinator ~api_version in + let* hex_root_hash = init_hex_root_hash coordinator in let dac_env = (coordinator, hex_root_hash, dac_committee) in let* () = test_non_committee_signer_should_fail tz_client dac_env in let* () = test_signature_verification_failure_should_fail dac_env in @@ -1105,23 +1073,19 @@ module Legacy = struct let* hex_root_hash = init_hex_root_hash ~payload:"test get certificate payload 123" - ~api_version coordinator in let signature = bls_sign_hex_hash member hex_root_hash in let* () = RPC.call coordinator - (Dac_rpc.put_dac_member_signature + (Dac_rpc.V0.put_dac_member_signature ~hex_root_hash ~dac_member_pkh:member.aggregate_public_key_hash - ~signature - ~api_version) + ~signature) in let* witnesses, certificate, _root_hash, _version = - RPC.call - coordinator - (Dac_rpc.get_certificate ~hex_root_hash ~api_version) + RPC.call coordinator (Dac_rpc.V0.get_certificate ~hex_root_hash) in let expected_witnesses = Z.shift_left Z.one i in assert_witnesses ~__LOC__ (Z.to_int expected_witnesses) witnesses ; @@ -1136,13 +1100,10 @@ module Full_infrastructure = struct (* TODO: https://gitlab.com/tezos/tezos/-/issues/5577 Once we introduce DAC API ("v1"), [Full_infrastructure] test suite should be refactored to use [v1] api as well. *) - let api_version = Dac_rpc.Api.v0 let coordinator_serializes_payload coordinator ~payload ~expected_rh = let* actual_rh = - RPC.call - coordinator - (Dac_rpc.Coordinator.post_preimage ~payload ~api_version) + RPC.call coordinator (Dac_rpc.V0.Coordinator.post_preimage ~payload) in return @@ check_valid_root_hash expected_rh actual_rh @@ -1159,9 +1120,7 @@ module Full_infrastructure = struct wait_for_root_hash_pushed_to_data_streamer coordinator_node expected_rh in let* actual_rh = - RPC.call - coordinator_node - (Dac_rpc.Coordinator.post_preimage ~payload ~api_version) + RPC.call coordinator_node (Dac_rpc.V0.Coordinator.post_preimage ~payload) in let () = check_valid_root_hash expected_rh actual_rh in let* () = root_hash_pushed_to_data_streamer_promise in @@ -1244,11 +1203,7 @@ module Full_infrastructure = struct This might be inefficient *) Lwt_list.iter_s (fun dac_node -> - check_downloaded_preimage - coordinator_node - dac_node - expected_rh - ~api_version) + check_downloaded_preimage coordinator_node dac_node expected_rh) (committee_members_nodes @ observer_nodes) let test_streaming_certificates @@ -1277,8 +1232,7 @@ module Full_infrastructure = struct assert (List.length committee_members > 0) ; let payload, expected_rh = sample_payload "preimage" in let certificate_stream_client = - Runnable.run - @@ streamed_certificates_client coordinator_node expected_rh api_version + Runnable.run @@ streamed_certificates_client coordinator_node expected_rh in let push_promise = wait_for_root_hash_pushed_to_data_streamer coordinator_node expected_rh @@ -1344,19 +1298,18 @@ module Full_infrastructure = struct List.nth certificate_updates (List.length certificate_updates - 1) in (* 5. Check that certificate is consistent with the one returned - from the GET [api_version]/certificate endpoint. *) + from the GET v0/certificate endpoint. *) let* get_certificate = RPC.call coordinator_node - (Dac_rpc.get_certificate ~hex_root_hash:(`Hex expected_rh) ~api_version) + (Dac_rpc.V0.get_certificate ~hex_root_hash:(`Hex expected_rh)) in check_certificate get_certificate last_certificate_update ; (* 6. Request certificate via streamed endpoints again, check that one item is returned with the same certificate returned by the GET endpoint. *) let* second_certificates_stream = - Runnable.run - @@ streamed_certificates_client coordinator_node expected_rh api_version + Runnable.run @@ streamed_certificates_client coordinator_node expected_rh in Check.( (1 = List.length second_certificates_stream) @@ -1563,7 +1516,6 @@ module Tx_kernel_e2e = struct (* TODO: https://gitlab.com/tezos/tezos/-/issues/5577 Once we introduce DAC API ("v1"), [Tx_kernel_e2e] test suite should be refactored to use [v1] api as well. *) - let api_version = Dac_rpc.Api.v0 let send_message ?(src = Constant.bootstrap2.alias) client msg = let* () = Client.Sc_rollup.send_message ~hooks ~src ~msg client in @@ -2078,17 +2030,13 @@ module Tx_kernel_e2e = struct else unit in let* preimage_hash = - RPC.call - coordinator_node - (Dac_rpc.Coordinator.post_preimage ~payload ~api_version) + RPC.call coordinator_node (Dac_rpc.V0.Coordinator.post_preimage ~payload) in let* () = Lwt.join wait_for_member_signature_pushed_to_coordinator in let* witnesses, signature, root_hash, _version = RPC.call coordinator_node - (Dac_rpc.get_certificate - ~hex_root_hash:(`Hex preimage_hash) - ~api_version) + (Dac_rpc.V0.get_certificate ~hex_root_hash:(`Hex preimage_hash)) in let root_hash = `Hex root_hash |> Hex.to_string |> String.to_bytes in let signature = @@ -2637,4 +2585,3 @@ let register ~protocols = protocols ; Tx_kernel_e2e.test_tx_kernel_e2e_with_dac_observer_synced_with_dac protocols ; Tx_kernel_e2e.test_tx_kernel_e2e_with_dac_observer_missing_pages protocols - \ No newline at end of file -- GitLab