From 8b92c33b193369221c66cbd37cb69e5df4e98893 Mon Sep 17 00:00:00 2001 From: "iguerNL@Functori" Date: Mon, 28 Nov 2022 11:08:13 +0100 Subject: [PATCH 1/6] DAL node: improve existing code for PATCH /slots --- src/bin_dal_node/RPC_server.ml | 4 ++-- src/bin_dal_node/slot_manager.ml | 22 +++++++++++----------- src/bin_dal_node/slot_manager.mli | 9 ++++----- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/src/bin_dal_node/RPC_server.ml b/src/bin_dal_node/RPC_server.ml index 7010aca12d8b..34133d3b6b64 100644 --- a/src/bin_dal_node/RPC_server.ml +++ b/src/bin_dal_node/RPC_server.ml @@ -38,9 +38,9 @@ module Slots_handlers = struct let patch_slot ctxt commitment () slot_id = call_handler - (fun store cryptobox -> + (fun store _cryptobox -> let open Lwt_result_syntax in - let*! r = Slot_manager.add_slot_id commitment slot_id store cryptobox in + let*! r = Slot_manager.add_slot_id commitment slot_id store in match r with Ok () -> return_some () | Error `Not_found -> return_none) ctxt end diff --git a/src/bin_dal_node/slot_manager.ml b/src/bin_dal_node/slot_manager.ml index 073656b67748..c6de2f82638e 100644 --- a/src/bin_dal_node/slot_manager.ml +++ b/src/bin_dal_node/slot_manager.ml @@ -57,6 +57,11 @@ let polynomial_from_slot cryptobox slot = let {slot_size = expected; _} = parameters cryptobox in tzfail @@ Invalid_slot_size {provided; expected} +let commitment_should_exist node_store commitment = + let open Lwt_result_syntax in + let*! exists = Store.Legacy.exists_slot_by_commitment node_store commitment in + if not exists then fail `Not_found else return_unit + (* Main functions *) let add_slots slot node_store cryptobox = @@ -70,15 +75,10 @@ let add_slots slot node_store cryptobox = in return commitment -let add_slot_id commitment slot_id node_store _cryptobox = +let add_slot_id commitment slot_id node_store = let open Lwt_result_syntax in - let*! exists = Store.Legacy.exists_slot_by_commitment node_store commitment in - if not exists then fail `Not_found - else - let*! () = - Store.Legacy.associate_slot_id_with_commitment - node_store - commitment - slot_id - in - return_unit + let* () = commitment_should_exist node_store commitment in + let*! () = + Store.Legacy.associate_slot_id_with_commitment node_store commitment slot_id + in + return_unit diff --git a/src/bin_dal_node/slot_manager.mli b/src/bin_dal_node/slot_manager.mli index 71214c238459..91c7bab64f43 100644 --- a/src/bin_dal_node/slot_manager.mli +++ b/src/bin_dal_node/slot_manager.mli @@ -45,14 +45,13 @@ val add_slots : Cryptobox.t -> Cryptobox.commitment tzresult Lwt.t -(** [add_slot_id commitment slot_id node_Store cryptobox] associates a [slot_id] - to a [commitment] in [node_store]. The function returns [Error `Not_found] - if there is no entry for [commitment] in [node_store]. Otherwise, [Ok ()] - is returned. +(** [add_slot_id commitment slot_id node_Store] associates a [slot_id] to a + [commitment] in [node_store]. The function returns [Error `Not_found] if + there is no entry for [commitment] in [node_store]. Otherwise, [Ok ()] is + returned. *) val add_slot_id : Cryptobox.commitment -> Services.Types.slot_id -> Store.node_store -> - Cryptobox.t -> (unit, [> `Not_found]) result Lwt.t -- GitLab From b365231575d73ee40e1dbef3eda9cd9d2e8c8a30 Mon Sep 17 00:00:00 2001 From: "iguerNL@Functori" Date: Mon, 28 Nov 2022 12:06:40 +0100 Subject: [PATCH 2/6] DAL node: add a new GET /slots service --- src/lib_dal_node_services/services.ml | 15 +++++++++++++++ src/lib_dal_node_services/services.mli | 10 ++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/lib_dal_node_services/services.ml b/src/lib_dal_node_services/services.ml index 4a32ce7c880c..ab3cf9e2366c 100644 --- a/src/lib_dal_node_services/services.ml +++ b/src/lib_dal_node_services/services.ml @@ -84,3 +84,18 @@ let patch_slot : ~input:Types.slot_id_encoding ~output:Data_encoding.unit Tezos_rpc.Path.(open_root / "slots" /: Cryptobox.Commitment.rpc_arg) + +let get_slot : + < meth : [`GET] + ; input : unit + ; output : Cryptobox.slot + ; prefix : unit + ; params : unit * Cryptobox.commitment + ; query : unit > + service = + Tezos_rpc.Service.get_service + ~description: + "Retrieve the content of the slot associated with the given commitment." + ~query:Tezos_rpc.Query.empty + ~output:Types.slot_content + Tezos_rpc.Path.(open_root / "slots" /: Cryptobox.Commitment.rpc_arg) diff --git a/src/lib_dal_node_services/services.mli b/src/lib_dal_node_services/services.mli index eea096c3dadc..4cb2e299c956 100644 --- a/src/lib_dal_node_services/services.mli +++ b/src/lib_dal_node_services/services.mli @@ -71,3 +71,13 @@ val patch_slot : ; params : unit * Cryptobox.commitment ; query : unit > service + +(** Retrieve the content of the slot associated with the given commitment. *) +val get_slot : + < meth : [`GET] + ; input : unit + ; output : Cryptobox.slot + ; prefix : unit + ; params : unit * Cryptobox.commitment + ; query : unit > + service -- GitLab From 0f808228df9a7aa3b8c16c3302337e0a536bfb0a Mon Sep 17 00:00:00 2001 From: "iguerNL@Functori" Date: Mon, 28 Nov 2022 12:07:21 +0100 Subject: [PATCH 3/6] DAL node: implement a handler for GET /slots service --- src/bin_dal_node/slot_manager.ml | 7 +++++++ src/bin_dal_node/slot_manager.mli | 9 +++++++++ src/bin_dal_node/store.ml | 7 +++++++ 3 files changed, 23 insertions(+) diff --git a/src/bin_dal_node/slot_manager.ml b/src/bin_dal_node/slot_manager.ml index c6de2f82638e..99225e119918 100644 --- a/src/bin_dal_node/slot_manager.ml +++ b/src/bin_dal_node/slot_manager.ml @@ -82,3 +82,10 @@ let add_slot_id commitment slot_id node_store = Store.Legacy.associate_slot_id_with_commitment node_store commitment slot_id in return_unit + +let get_slot_content commitment node_store = + let open Lwt_result_syntax in + let*! slot_opt = Store.Legacy.find_slot_by_commitment node_store commitment in + match slot_opt with + | None -> fail `Not_found + | Some slot_content -> return slot_content diff --git a/src/bin_dal_node/slot_manager.mli b/src/bin_dal_node/slot_manager.mli index 91c7bab64f43..f37f11d947f1 100644 --- a/src/bin_dal_node/slot_manager.mli +++ b/src/bin_dal_node/slot_manager.mli @@ -55,3 +55,12 @@ val add_slot_id : Services.Types.slot_id -> Store.node_store -> (unit, [> `Not_found]) result Lwt.t + +(** [get_slot_content commitment node_Store] returns the slot content associated + with the given [commitment] in [node_store]. The function returns [Error + `Not_found] if there is no slot content for [commitment] in [node_store]. +*) +val get_slot_content : + Cryptobox.commitment -> + Store.node_store -> + (slot, [> `Not_found]) result Lwt.t diff --git a/src/bin_dal_node/store.ml b/src/bin_dal_node/store.ml index c43e493f2fe1..dd6964a665b7 100644 --- a/src/bin_dal_node/store.ml +++ b/src/bin_dal_node/store.ml @@ -174,4 +174,11 @@ module Legacy = struct let commitment_b58 = Cryptobox.Commitment.to_b58check commitment in let path = Legacy_paths.slot_by_commitment commitment_b58 in mem node_store.slots_store path + + let find_slot_by_commitment node_store commitment = + let open Lwt_syntax in + let commitment_b58 = Cryptobox.Commitment.to_b58check commitment in + let path = Legacy_paths.slot_by_commitment commitment_b58 in + let* res_opt = find node_store.slots_store path in + Option.map Bytes.of_string res_opt |> Lwt.return end -- GitLab From 57664e09ffffd6bd5baaed7678e699a4e5362bd3 Mon Sep 17 00:00:00 2001 From: "iguerNL@Functori" Date: Mon, 28 Nov 2022 12:07:40 +0100 Subject: [PATCH 4/6] DAL node: register new service for GET /slots --- src/bin_dal_node/RPC_server.ml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/bin_dal_node/RPC_server.ml b/src/bin_dal_node/RPC_server.ml index 34133d3b6b64..685da56c3f74 100644 --- a/src/bin_dal_node/RPC_server.ml +++ b/src/bin_dal_node/RPC_server.ml @@ -43,6 +43,14 @@ module Slots_handlers = struct let*! r = Slot_manager.add_slot_id commitment slot_id store in match r with Ok () -> return_some () | Error `Not_found -> return_none) ctxt + + let get_slot_content ctxt commitment () () = + call_handler + (fun store _cryptobox -> + let open Lwt_result_syntax in + let*! r = Slot_manager.get_slot_content commitment store in + match r with Ok s -> return_some s | Error `Not_found -> return_none) + ctxt end let add_service registerer service handler directory = @@ -62,6 +70,10 @@ let register_new : Tezos_rpc.Directory.opt_register1 Services.patch_slot (Slots_handlers.patch_slot ctxt) + |> add_service + Tezos_rpc.Directory.opt_register1 + Services.get_slot + (Slots_handlers.get_slot_content ctxt) let register_legacy ctxt = let open RPC_server_legacy in -- GitLab From 34fb473a41872ed90542409b5ebedc9d0e50cf6b Mon Sep 17 00:00:00 2001 From: "iguerNL@Functori" Date: Mon, 28 Nov 2022 12:08:19 +0100 Subject: [PATCH 5/6] Tezt/lib_tezos: bind GET /slots service in DAL RPCs --- tezt/lib_tezos/rollup.ml | 3 +++ tezt/lib_tezos/rollup.mli | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/tezt/lib_tezos/rollup.ml b/tezt/lib_tezos/rollup.ml index a62599ea0917..8b92e11487ae 100644 --- a/tezt/lib_tezos/rollup.ml +++ b/tezt/lib_tezos/rollup.ml @@ -650,6 +650,9 @@ module Dal = struct ] in make ~data PATCH ["slots"; commitment] as_empty_object_or_fail + + let get_slot commitment = + make GET ["slots"; commitment] get_bytes_from_json_string_node end let make diff --git a/tezt/lib_tezos/rollup.mli b/tezt/lib_tezos/rollup.mli index 8a70ad991bfe..04a484c1172d 100644 --- a/tezt/lib_tezos/rollup.mli +++ b/tezt/lib_tezos/rollup.mli @@ -295,6 +295,10 @@ module Dal : sig slot_level:int -> slot_index:int -> (Dal_node.t, unit) RPC_core.t + + (** Call RPC "GET /slots/" to retrieve the slot content associated with the + given commitment. *) + val get_slot : commitment -> (Dal_node.t, slot) RPC_core.t end val make : -- GitLab From 849b4135d36d28991e48886b273a5076059aaf71 Mon Sep 17 00:00:00 2001 From: "iguerNL@Functori" Date: Mon, 28 Nov 2022 12:16:48 +0100 Subject: [PATCH 6/6] Tezt/DAL: add a test for GET /posts service --- tezt/tests/dal.ml | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tezt/tests/dal.ml b/tezt/tests/dal.ml index cb694a31d09a..262616a7c7a7 100644 --- a/tezt/tests/dal.ml +++ b/tezt/tests/dal.ml @@ -1001,6 +1001,27 @@ let test_dal_node_test_patch_slots _protocol parameters cryptobox _node client let* () = patch_slot_rpc ~slot_level:0 ~slot_index:1 in patch_slot_rpc ~slot_level:(-4) ~slot_index:3 +let test_dal_node_test_get_slots _protocol parameters cryptobox _node client + dal_node = + let size = parameters.Rollup.Dal.Parameters.cryptobox.slot_size in + let* slot = Rollup.Dal.make_slot (generate_dummy_slot size) client in + let commit = + Cryptobox.Commitment.to_b58check @@ commitment_of_slot cryptobox slot + in + let* () = + let* response = RPC.call_raw dal_node @@ Rollup.Dal.RPC.get_slot commit in + return @@ RPC.check_string_response ~code:404 response + in + let* _commitment = RPC.call dal_node (Rollup.Dal.RPC.post_slot slot) in + (* commit = _commitment already test in /POST test. *) + let* got_slot = RPC.call dal_node (Rollup.Dal.RPC.get_slot commit) in + Check.(Rollup.Dal.content_of_slot slot = Rollup.Dal.content_of_slot got_slot) + Check.string + ~error_msg: + "The slot content retrieved from the node is not as expected (expected = \ + %L, got = %R)" ; + unit + let test_dal_node_startup = Protocol.register_test ~__FILE__ @@ -1585,6 +1606,10 @@ let register ~protocols = "dal node PATCH /slots" test_dal_node_test_patch_slots protocols ; + scenario_with_layer1_and_dal_nodes + "dal node GET /slots" + test_dal_node_test_get_slots + protocols ; (* Tests with all nodes *) test_dal_node_dac_threshold_not_reached protocols ; -- GitLab