From f6b029213369a97956e3629af9aa699374f3202a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20El=20Siba=C3=AFe?= Date: Wed, 31 Aug 2022 14:29:26 +0200 Subject: [PATCH 01/10] Dal/Scoru: add layer2 utils as a dependency to DAL --- manifest/main.ml | 2 ++ opam/tezos-dal-alpha.opam | 1 + opam/tezos-dal-node.opam | 1 + src/bin_dal_node/dune | 2 ++ src/proto_alpha/lib_dal/dune | 2 ++ 5 files changed, 8 insertions(+) diff --git a/manifest/main.ml b/manifest/main.ml index 2af67f7ec81a..01a1b49ccde6 100644 --- a/manifest/main.ml +++ b/manifest/main.ml @@ -4679,6 +4679,7 @@ module Protocol = Protocol octez_dal_node_lib |> open_; client |> if_some |> open_; embedded |> open_; + layer2_utils |> if_some |> open_; main |> open_; ] ~inline_tests:ppx_expect @@ -5588,6 +5589,7 @@ let _octez_dal_node = octez_stdlib |> open_; octez_dal_node_lib |> open_; octez_dal_node_services |> open_; + octez_layer2_store |> open_; octez_crypto_dal |> open_; irmin_pack; irmin_pack_unix; diff --git a/opam/tezos-dal-alpha.opam b/opam/tezos-dal-alpha.opam index 230e05c30100..f61c674963f7 100644 --- a/opam/tezos-dal-alpha.opam +++ b/opam/tezos-dal-alpha.opam @@ -15,6 +15,7 @@ depends: [ "tezos-dal-node-lib" "tezos-client-alpha" "tezos-embedded-protocol-alpha" + "tezos-layer2-utils-alpha" "tezos-protocol-alpha" "tezos-base-test-helpers" {with-test} "tezos-alpha-test-helpers" {with-test} diff --git a/opam/tezos-dal-node.opam b/opam/tezos-dal-node.opam index 864750fa9753..b63f927979d0 100644 --- a/opam/tezos-dal-node.opam +++ b/opam/tezos-dal-node.opam @@ -21,6 +21,7 @@ depends: [ "tezos-stdlib" "tezos-dal-node-lib" "tezos-dal-node-services" + "tezos-layer2-store" "tezos-crypto-dal" "irmin-pack" { >= "3.4.0" & < "3.5.0" } "irmin" { >= "3.4.0" & < "3.5.0" } diff --git a/src/bin_dal_node/dune b/src/bin_dal_node/dune index a0fa01a5e848..013a58da9c92 100644 --- a/src/bin_dal_node/dune +++ b/src/bin_dal_node/dune @@ -20,6 +20,7 @@ tezos-stdlib tezos_dal_node_lib tezos_dal_node_services + tezos_layer2_store tezos-crypto-dal irmin-pack irmin-pack.unix @@ -41,6 +42,7 @@ -open Tezos_stdlib -open Tezos_dal_node_lib -open Tezos_dal_node_services + -open Tezos_layer2_store -open Tezos_crypto_dal)) (rule (action (progn (write-file void_for_linking-tezos-dal-alpha.empty "")))) diff --git a/src/proto_alpha/lib_dal/dune b/src/proto_alpha/lib_dal/dune index 2518782cb07b..9d0b533102e8 100644 --- a/src/proto_alpha/lib_dal/dune +++ b/src/proto_alpha/lib_dal/dune @@ -11,6 +11,7 @@ tezos_dal_node_lib tezos-client-alpha tezos-embedded-protocol-alpha + tezos-layer2-utils-alpha tezos-protocol-alpha) (inline_tests (flags -verbose) (modes native)) (preprocess (pps ppx_expect)) @@ -23,4 +24,5 @@ -open Tezos_dal_node_lib -open Tezos_client_alpha -open Tezos_embedded_protocol_alpha + -open Tezos_layer2_utils_alpha -open Tezos_protocol_alpha)) -- GitLab From 7e4551b9376dc4a4e331247a78da9f870eda8e36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20El=20Siba=C3=AFe?= Date: Tue, 13 Sep 2022 10:15:51 +0200 Subject: [PATCH 02/10] Dal/Plugin: add slot headers store --- src/bin_dal_node/slot_headers_store.ml | 57 ++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/bin_dal_node/slot_headers_store.ml diff --git a/src/bin_dal_node/slot_headers_store.ml b/src/bin_dal_node/slot_headers_store.ml new file mode 100644 index 000000000000..feff7f3062e0 --- /dev/null +++ b/src/bin_dal_node/slot_headers_store.ml @@ -0,0 +1,57 @@ +(*****************************************************************************) +(* *) +(* Open Source License *) +(* Copyright (c) 2022 Nomadic Labs, *) +(* *) +(* 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. *) +(* *) +(*****************************************************************************) + +open Protocol.Alpha_context +include Store_utils + +(* Published slot headers per block hash, + stored as a list of bindings from `Dal_slot_index.t` + to `Dal.Slot.t`. The encoding function converts this + list into a `Dal.Slot_index.t`-indexed map. *) +module Dal_slots = Make_nested_map (struct + let path = ["dal"; "slot_headers"] + + (* FIXME/DAL: https://gitlab.com/tezos/tezos/-/issues/3527 + This value is currently not used, but required by the module type. *) + let keep_last_n_entries_in_memory = 10 + + type key = Block_hash.t + + let string_of_key = Block_hash.to_b58check + + type secondary_key = Dal.Slot_index.t + + let compare_secondary_keys = Dal.Slot_index.compare + + type value = Dal.Slot.t + + let secondary_key_encoding = Dal.Slot_index.encoding + + let secondary_key_name = "slot_index" + + let value_encoding = Dal.Slot.encoding + + let value_name = "slots_metadata" +end) -- GitLab From e05363dfce20a94ea0bd891d5a8b08fa447c79c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20El=20Siba=C3=AFe?= Date: Wed, 31 Aug 2022 14:31:17 +0200 Subject: [PATCH 03/10] Dal: make some type repr available in proto and env --- src/lib_protocol_environment/environment_V7.ml | 2 +- .../environment_V7.mli | 2 +- .../bin_sc_rollup_node/dal_node_client.mli | 4 ++-- src/proto_alpha/lib_protocol/alpha_context.ml | 2 -- src/proto_alpha/lib_protocol/alpha_context.mli | 18 ++++++++++-------- .../test/helpers/operation_generator.ml | 2 +- .../validate/manager_operation_helpers.ml | 2 +- 7 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/lib_protocol_environment/environment_V7.ml b/src/lib_protocol_environment/environment_V7.ml index 6cc621ea0506..6f43324a37e8 100644 --- a/src/lib_protocol_environment/environment_V7.ml +++ b/src/lib_protocol_environment/environment_V7.ml @@ -101,7 +101,7 @@ module type T = sig Tezos_protocol_environment_structs.V7.Plonk.verifier_public_parameters * Tezos_protocol_environment_structs.V7.Plonk.transcript and type Dal.parameters = Tezos_crypto_dal.Cryptobox.Verifier.parameters - and type Dal.commitment = Tezos_crypto_dal.Cryptobox.commitment + and type Dal.commitment = Tezos_crypto_dal.Cryptobox.Verifier.commitment type error += Ecoproto_error of Error_monad.error diff --git a/src/lib_protocol_environment/environment_V7.mli b/src/lib_protocol_environment/environment_V7.mli index 10e1eb5f86ec..86c63b663cf6 100644 --- a/src/lib_protocol_environment/environment_V7.mli +++ b/src/lib_protocol_environment/environment_V7.mli @@ -101,7 +101,7 @@ module type T = sig Tezos_protocol_environment_structs.V7.Plonk.verifier_public_parameters * Tezos_protocol_environment_structs.V7.Plonk.transcript and type Dal.parameters = Tezos_crypto_dal.Cryptobox.Verifier.parameters - and type Dal.commitment = Tezos_crypto_dal.Cryptobox.commitment + and type Dal.commitment = Tezos_crypto_dal.Cryptobox.Verifier.commitment (** An [Ecoproto_error e] is a shell error that carry a protocol error. diff --git a/src/proto_alpha/bin_sc_rollup_node/dal_node_client.mli b/src/proto_alpha/bin_sc_rollup_node/dal_node_client.mli index b7a769149ed6..7a0e3dc8ff7a 100644 --- a/src/proto_alpha/bin_sc_rollup_node/dal_node_client.mli +++ b/src/proto_alpha/bin_sc_rollup_node/dal_node_client.mli @@ -44,7 +44,7 @@ class unix_cctxt : val make_unix_cctxt : Configuration.t -> cctxt val get_slot : - #cctxt -> ?trim_slot:bool -> Dal.Slot_header.t -> string tzresult Lwt.t + #cctxt -> ?trim_slot:bool -> Dal.Slot.Header.t -> string tzresult Lwt.t val get_shard : - #cctxt -> Dal.Slot_header.t -> int -> Cryptobox.shard tzresult Lwt.t + #cctxt -> Dal.Slot.Header.t -> int -> Cryptobox.shard tzresult Lwt.t diff --git a/src/proto_alpha/lib_protocol/alpha_context.ml b/src/proto_alpha/lib_protocol/alpha_context.ml index e2b6d4436f09..eed5bc39554b 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.ml +++ b/src/proto_alpha/lib_protocol/alpha_context.ml @@ -109,8 +109,6 @@ module Dal = struct include Dal_slot_repr.Page end - module Slot_header = Dal_slot_repr.Header - module Slot = struct include Dal_slot_repr include Dal_slot_storage diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index 19c8289a7b53..6b511666a73b 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -2823,19 +2823,21 @@ module Dal : sig val equal : t -> t -> bool end - (** This module re-exports definitions from {!Dal_slot_repr.Header}. *) - module Slot_header : sig - type t = Dal.commitment - - val zero : t - end - (** This module re-exports definitions from {!Dal_slot_repr}, {!Dal_slot_storage} and {!Raw_context.Dal}. *) module Slot : sig + (** This module re-exports definitions from {!Dal_slot_repr.Header}. *) + module Header : sig + type t = Dal.commitment + + val encoding : t Data_encoding.t + + val zero : t + end + type id = {published_level : Raw_level.t; index : Slot_index.t} - type t = {id : id; header : Slot_header.t} + type t = {id : id; header : Header.t} val encoding : t Data_encoding.t diff --git a/src/proto_alpha/lib_protocol/test/helpers/operation_generator.ml b/src/proto_alpha/lib_protocol/test/helpers/operation_generator.ml index 9cb8fc76f58b..55409f25e192 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/operation_generator.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/operation_generator.ml @@ -662,7 +662,7 @@ let generate_dal_publish_slot_header random_state : let gen_dal_publish _ = let published_level = Alpha_context.Raw_level.of_int32_exn Int32.zero in let index = Alpha_context.Dal.Slot_index.zero in - let header = Alpha_context.Dal.Slot_header.zero in + let header = Alpha_context.Dal.Slot.Header.zero in let slot = Alpha_context.Dal.Slot.{id = {published_level; index}; header} in Dal_publish_slot_header {slot} in diff --git a/src/proto_alpha/lib_protocol/test/integration/validate/manager_operation_helpers.ml b/src/proto_alpha/lib_protocol/test/integration/validate/manager_operation_helpers.ml index df515965ba12..66743e0a8b08 100644 --- a/src/proto_alpha/lib_protocol/test/integration/validate/manager_operation_helpers.ml +++ b/src/proto_alpha/lib_protocol/test/integration/validate/manager_operation_helpers.ml @@ -1051,7 +1051,7 @@ let mk_sc_rollup_return_bond (oinfos : operation_req) (infos : infos) = let mk_dal_publish_slot_header (oinfos : operation_req) (infos : infos) = let published_level = Alpha_context.Raw_level.of_int32_exn Int32.zero in let index = Alpha_context.Dal.Slot_index.zero in - let header = Alpha_context.Dal.Slot_header.zero in + let header = Alpha_context.Dal.Slot.Header.zero in let slot = Alpha_context.Dal.Slot.{id = {published_level; index}; header} in Op.dal_publish_slot_header ?fee:oinfos.fee -- GitLab From 6831ccbd6c7645098328087eb6a9abbfd8bbf421 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20El=20Siba=C3=AFe?= Date: Wed, 31 Aug 2022 14:33:38 +0200 Subject: [PATCH 04/10] Dal/Plugin: add utility to access published slots from plugin --- src/lib_dal_node/dal_constants_plugin.ml | 5 ++++ src/lib_dal_node/dal_constants_plugin.mli | 5 ++++ .../lib_dal/dal_plugin_registration.ml | 24 +++++++++++++++++++ 3 files changed, 34 insertions(+) diff --git a/src/lib_dal_node/dal_constants_plugin.ml b/src/lib_dal_node/dal_constants_plugin.ml index c607bc7ecbef..750cedd3290c 100644 --- a/src/lib_dal_node/dal_constants_plugin.ml +++ b/src/lib_dal_node/dal_constants_plugin.ml @@ -31,6 +31,11 @@ module type T = sig Tezos_shell_services.Block_services.block -> Client_context.full -> Tezos_crypto_dal.Cryptobox.Verifier.parameters tzresult Lwt.t + + val get_published_slot_headers : + Tezos_shell_services.Block_services.block -> + Client_context.full -> + (int * Tezos_crypto_dal.Cryptobox.Verifier.commitment) list tzresult Lwt.t end let table : (module T) Protocol_hash.Table.t = Protocol_hash.Table.create 5 diff --git a/src/lib_dal_node/dal_constants_plugin.mli b/src/lib_dal_node/dal_constants_plugin.mli index 38c2fb4ce10d..eee5de9b3cf5 100644 --- a/src/lib_dal_node/dal_constants_plugin.mli +++ b/src/lib_dal_node/dal_constants_plugin.mli @@ -31,6 +31,11 @@ module type T = sig Tezos_shell_services.Block_services.block -> Client_context.full -> Tezos_crypto_dal.Cryptobox.Verifier.parameters tzresult Lwt.t + + val get_published_slot_headers : + Tezos_shell_services.Block_services.block -> + Client_context.full -> + (int * Tezos_crypto_dal.Cryptobox.Verifier.commitment) list tzresult Lwt.t end val register : (module T) -> unit diff --git a/src/proto_alpha/lib_dal/dal_plugin_registration.ml b/src/proto_alpha/lib_dal/dal_plugin_registration.ml index 5419fac02d36..e37026342b0a 100644 --- a/src/proto_alpha/lib_dal/dal_plugin_registration.ml +++ b/src/proto_alpha/lib_dal/dal_plugin_registration.ml @@ -37,6 +37,30 @@ module Plugin = struct return Environment.Dal. {redundancy_factor; page_size; slot_size; number_of_shards} + + let get_published_slot_headers block ctxt = + let open Lwt_result_syntax in + let open Protocol.Alpha_context in + let cpctxt = new Protocol_client_context.wrap_full ctxt in + let+ block = + Protocol_client_context.Alpha_block_services.info + cpctxt + ~block + ~metadata:`Always + () + in + let apply_internal acc ~source:_ _op _res = acc in + let apply (type kind) acc ~source:_ (op : kind manager_operation) _res = + match op with + | Dal_publish_slot_header {slot = {index; header; _}} -> + (Dal.Slot_index.to_int index, header) :: acc + | _ -> acc + in + let slot_headers = + Layer1_services.( + process_manager_operations [] block.operations {apply; apply_internal}) + in + slot_headers end let () = Dal_constants_plugin.register (module Plugin) -- GitLab From e2720931ecb127b8ec94d57c47d946b91eb370e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20El=20Siba=C3=AFe?= Date: Wed, 31 Aug 2022 15:07:59 +0200 Subject: [PATCH 05/10] Dal/Node: add a status to ctxt, start RPC server at launch --- src/bin_dal_node/RPC_server.ml | 43 +++++++++++++++++++-------- src/bin_dal_node/daemon.ml | 49 +++++++++++++++---------------- src/bin_dal_node/node_context.ml | 11 ++++--- src/bin_dal_node/node_context.mli | 10 +++++-- 4 files changed, 69 insertions(+), 44 deletions(-) diff --git a/src/bin_dal_node/RPC_server.ml b/src/bin_dal_node/RPC_server.ml index 0477087de050..6b7bb03d2df9 100644 --- a/src/bin_dal_node/RPC_server.ml +++ b/src/bin_dal_node/RPC_server.ml @@ -29,8 +29,31 @@ open Tezos_rpc_http open Tezos_rpc_http_server open Tezos_dal_node_services -let handle_split_slot dal_parameters dal_constants store fill slot = +type error += Node_not_ready + +let () = + register_error_kind + `Permanent + ~id:"dal.node.not.ready" + ~title:"DAL Node not ready" + ~description:"DAL node is starting. It's not ready to respond to RPCs" + ~pp:(fun ppf () -> + Format.fprintf + ppf + "DAL node is starting. It's not ready to respond to RPCs") + Data_encoding.(unit) + (function Node_not_ready -> Some () | _ -> None) + (fun () -> Node_not_ready) + +let ready_ctxt ctxt = + let open Result_syntax in + match ctxt.Node_context.status with + | Ready ctxt -> Ok ctxt + | Starting -> fail [Node_not_ready] + +let handle_split_slot ctxt store fill slot = let open Lwt_result_syntax in + let*? {dal_parameters; dal_constants; _} = ready_ctxt ctxt in let slot = String.to_bytes slot in let slot = if fill then @@ -40,10 +63,11 @@ let handle_split_slot dal_parameters dal_constants store fill slot = let+ commitment = Slot_manager.split_and_store dal_constants store slot in Cryptobox.Commitment.to_b58check commitment -let handle_slot initial_constants dal_constants store (_, commitment) trim () = +let handle_slot ctxt store (_, commitment) trim () = let open Lwt_result_syntax in + let*? {dal_parameters; dal_constants; _} = ready_ctxt ctxt in let* slot = - Slot_manager.get_slot initial_constants dal_constants store commitment + Slot_manager.get_slot dal_parameters dal_constants store commitment in let slot = if trim then Slot_manager.Utils.trim_x00 slot else slot in return (String.of_bytes slot) @@ -55,19 +79,14 @@ let handle_slot_pages initial_constants dal_constants store (_, commitment) () let handle_shard store ((_, commitment), shard) () () = Slot_manager.get_shard store commitment shard -let register_split_slot {Node_context.dal_parameters; dal_constants; _} store - dir = +let register_split_slot ctxt store dir = RPC_directory.register0 dir (Services.split_slot ()) - (handle_split_slot dal_parameters dal_constants store) + (handle_split_slot ctxt store) -let register_show_slot {Node_context.dal_parameters; dal_constants; _} store dir - = - RPC_directory.register - dir - (Services.slot ()) - (handle_slot dal_parameters dal_constants store) +let register_show_slot ctxt store dir = + RPC_directory.register dir (Services.slot ()) (handle_slot ctxt store) let register_show_slot_pages {Node_context.dal_parameters; dal_constants; _} store dir = diff --git a/src/bin_dal_node/daemon.ml b/src/bin_dal_node/daemon.ml index b1d42131a46c..cf968a709b7f 100644 --- a/src/bin_dal_node/daemon.ml +++ b/src/bin_dal_node/daemon.ml @@ -91,34 +91,33 @@ let run ~data_dir cctxt = let*! () = Event.(emit starting_node) () in let* config = Configuration.load ~data_dir in let config = {config with data_dir} in + let ctxt = Node_context.make config in let*! store = Store.init config in - let ready = ref false in + let* rpc_server = RPC_server.(start config (register ctxt store)) in + let _ = RPC_server.install_finalizer rpc_server in + let*! () = + Event.(emit rpc_server_is_ready (config.rpc_addr, config.rpc_port)) + in let*! () = Event.(emit layer1_node_tracking_started ()) in - let new_head_handler (_hash, (_block_header : Tezos_base.Block_header.t)) = + let new_head_handler (_block_hash, (_block_header : Tezos_base.Block_header.t)) + = (* Try to resolve the protocol plugin corresponding to the protocol of the targeted node. *) - if not !ready then - let* plugin = resolve_plugin cctxt in - match plugin with - | Some plugin -> - let (module Plugin : Dal_constants_plugin.T) = plugin in - let*! () = Event.emit_protocol_plugin_resolved Plugin.Proto.hash in - let* dal_constants, dal_parameters = - init_cryptobox config.use_unsafe_srs cctxt plugin - in - let ctxt = Node_context.make config dal_constants dal_parameters in - let* rpc_server = RPC_server.(start config (register ctxt store)) in - let _ = RPC_server.install_finalizer rpc_server in - let*! () = - Event.(emit rpc_server_is_ready (config.rpc_addr, config.rpc_port)) - in - let*! () = Event.(emit node_is_ready ()) in - ready := true ; - return_unit - | None -> return_unit - else - (* If rpc and plugin are ready, there is nothing else to do. - Future work will update this part of the code *) - return_unit + match ctxt.status with + | Starting -> ( + let* plugin = resolve_plugin cctxt in + match plugin with + | Some plugin -> + let (module Plugin : Dal_constants_plugin.T) = plugin in + let*! () = Event.emit_protocol_plugin_resolved Plugin.Proto.hash in + let* dal_constants, dal_parameters = + init_cryptobox config.use_unsafe_srs cctxt plugin + in + ctxt.status <- + Ready {plugin = (module Plugin); dal_constants; dal_parameters} ; + let*! () = Event.(emit node_is_ready ()) in + return_unit + | None -> return_unit) + | Ready _ready_ctxt -> return_unit in daemonize cctxt new_head_handler diff --git a/src/bin_dal_node/node_context.ml b/src/bin_dal_node/node_context.ml index 9c592a633a80..aa06bec1fe32 100644 --- a/src/bin_dal_node/node_context.ml +++ b/src/bin_dal_node/node_context.ml @@ -23,11 +23,14 @@ (* *) (*****************************************************************************) -type t = { - config : Configuration.t; +type ready_ctxt = { dal_constants : Cryptobox.t; dal_parameters : Cryptobox.parameters; + plugin : (module Dal_constants_plugin.T); } -let make config dal_constants dal_parameters = - {config; dal_constants; dal_parameters} +type status = Ready of ready_ctxt | Starting + +type t = {mutable status : status; config : Configuration.t} + +let make config = {status = Starting; config} diff --git a/src/bin_dal_node/node_context.mli b/src/bin_dal_node/node_context.mli index 3afb13c23926..a8127cc2209c 100644 --- a/src/bin_dal_node/node_context.mli +++ b/src/bin_dal_node/node_context.mli @@ -23,10 +23,14 @@ (* *) (*****************************************************************************) -type t = { - config : Configuration.t; +type ready_ctxt = { dal_constants : Cryptobox.t; dal_parameters : Cryptobox.parameters; + plugin : (module Dal_constants_plugin.T); } -val make : Configuration.t -> Cryptobox.t -> Cryptobox.parameters -> t +type status = Ready of ready_ctxt | Starting + +type t = {mutable status : status; config : Configuration.t} + +val make : Configuration.t -> t -- GitLab From d096708935790a18bd2e86d2c314e7befa90a9fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20El=20Siba=C3=AFe?= Date: Tue, 6 Sep 2022 11:47:27 +0200 Subject: [PATCH 06/10] Dal/Node: store slot headers on publish --- src/bin_dal_node/RPC_server.ml | 38 ++++--------------- src/bin_dal_node/daemon.ml | 34 ++++++++++++++--- src/bin_dal_node/node_context.ml | 38 ++++++++++++++++++- src/bin_dal_node/node_context.mli | 19 +++++++++- src/bin_dal_node/slot_headers_store.ml | 13 +++---- .../lib_dal/dal_plugin_registration.ml | 17 ++++----- 6 files changed, 103 insertions(+), 56 deletions(-) diff --git a/src/bin_dal_node/RPC_server.ml b/src/bin_dal_node/RPC_server.ml index 6b7bb03d2df9..00ba97250d0f 100644 --- a/src/bin_dal_node/RPC_server.ml +++ b/src/bin_dal_node/RPC_server.ml @@ -29,31 +29,9 @@ open Tezos_rpc_http open Tezos_rpc_http_server open Tezos_dal_node_services -type error += Node_not_ready - -let () = - register_error_kind - `Permanent - ~id:"dal.node.not.ready" - ~title:"DAL Node not ready" - ~description:"DAL node is starting. It's not ready to respond to RPCs" - ~pp:(fun ppf () -> - Format.fprintf - ppf - "DAL node is starting. It's not ready to respond to RPCs") - Data_encoding.(unit) - (function Node_not_ready -> Some () | _ -> None) - (fun () -> Node_not_ready) - -let ready_ctxt ctxt = - let open Result_syntax in - match ctxt.Node_context.status with - | Ready ctxt -> Ok ctxt - | Starting -> fail [Node_not_ready] - let handle_split_slot ctxt store fill slot = let open Lwt_result_syntax in - let*? {dal_parameters; dal_constants; _} = ready_ctxt ctxt in + let*? {dal_parameters; dal_constants; _} = Node_context.get_ready ctxt in let slot = String.to_bytes slot in let slot = if fill then @@ -65,16 +43,17 @@ let handle_split_slot ctxt store fill slot = let handle_slot ctxt store (_, commitment) trim () = let open Lwt_result_syntax in - let*? {dal_parameters; dal_constants; _} = ready_ctxt ctxt in + let*? {dal_parameters; dal_constants; _} = Node_context.get_ready ctxt in let* slot = Slot_manager.get_slot dal_parameters dal_constants store commitment in let slot = if trim then Slot_manager.Utils.trim_x00 slot else slot in return (String.of_bytes slot) -let handle_slot_pages initial_constants dal_constants store (_, commitment) () - () = - Slot_manager.get_slot_pages initial_constants dal_constants store commitment +let handle_slot_pages ctxt store (_, commitment) () () = + let open Lwt_result_syntax in + let*? {dal_parameters; dal_constants; _} = Node_context.get_ready ctxt in + Slot_manager.get_slot_pages dal_parameters dal_constants store commitment let handle_shard store ((_, commitment), shard) () () = Slot_manager.get_shard store commitment shard @@ -88,12 +67,11 @@ let register_split_slot ctxt store dir = let register_show_slot ctxt store dir = RPC_directory.register dir (Services.slot ()) (handle_slot ctxt store) -let register_show_slot_pages {Node_context.dal_parameters; dal_constants; _} - store dir = +let register_show_slot_pages ctxt store dir = RPC_directory.register dir (Services.slot_pages ()) - (handle_slot_pages dal_parameters dal_constants store) + (handle_slot_pages ctxt store) let register_shard store dir = RPC_directory.register dir (Services.shard ()) (handle_shard store) diff --git a/src/bin_dal_node/daemon.ml b/src/bin_dal_node/daemon.ml index cf968a709b7f..d54007f80b12 100644 --- a/src/bin_dal_node/daemon.ml +++ b/src/bin_dal_node/daemon.ml @@ -91,7 +91,7 @@ let run ~data_dir cctxt = let*! () = Event.(emit starting_node) () in let* config = Configuration.load ~data_dir in let config = {config with data_dir} in - let ctxt = Node_context.make config in + let ctxt = Node_context.init config in let*! store = Store.init config in let* rpc_server = RPC_server.(start config (register ctxt store)) in let _ = RPC_server.install_finalizer rpc_server in @@ -99,11 +99,11 @@ let run ~data_dir cctxt = Event.(emit rpc_server_is_ready (config.rpc_addr, config.rpc_port)) in let*! () = Event.(emit layer1_node_tracking_started ()) in - let new_head_handler (_block_hash, (_block_header : Tezos_base.Block_header.t)) + let new_head_handler (block_hash, (_block_header : Tezos_base.Block_header.t)) = (* Try to resolve the protocol plugin corresponding to the protocol of the targeted node. *) - match ctxt.status with + match Node_context.get_status ctxt with | Starting -> ( let* plugin = resolve_plugin cctxt in match plugin with @@ -113,11 +113,33 @@ let run ~data_dir cctxt = let* dal_constants, dal_parameters = init_cryptobox config.use_unsafe_srs cctxt plugin in - ctxt.status <- - Ready {plugin = (module Plugin); dal_constants; dal_parameters} ; + let*! slot_header_store = + Slot_headers_store.load + (Configuration.data_dir_path config "slot_header_store") + in + Node_context.set_ready + ctxt + slot_header_store + (module Plugin) + dal_constants + dal_parameters ; let*! () = Event.(emit node_is_ready ()) in return_unit | None -> return_unit) - | Ready _ready_ctxt -> return_unit + | Ready {plugin = (module Plugin); slot_header_store; _} -> + let* slot_headers = + Plugin.get_published_slot_headers (`Hash (block_hash, 0)) cctxt + in + let*! () = + List.iter_s + (fun (slot_index, slot_header) -> + Slot_headers_store.add + slot_header_store + ~primary_key:block_hash + ~secondary_key:slot_index + slot_header) + slot_headers + in + return_unit in daemonize cctxt new_head_handler diff --git a/src/bin_dal_node/node_context.ml b/src/bin_dal_node/node_context.ml index aa06bec1fe32..bb5f767c9808 100644 --- a/src/bin_dal_node/node_context.ml +++ b/src/bin_dal_node/node_context.ml @@ -23,14 +23,50 @@ (* *) (*****************************************************************************) +exception Status_already_ready + type ready_ctxt = { dal_constants : Cryptobox.t; dal_parameters : Cryptobox.parameters; plugin : (module Dal_constants_plugin.T); + slot_header_store : Slot_headers_store.t; } type status = Ready of ready_ctxt | Starting type t = {mutable status : status; config : Configuration.t} -let make config = {status = Starting; config} +let init config = {status = Starting; config} + +let set_ready ctxt slot_header_store plugin dal_constants dal_parameters = + match ctxt.status with + | Starting -> + ctxt.status <- + Ready {slot_header_store; plugin; dal_constants; dal_parameters} + | Ready _ -> raise Status_already_ready + +type error += Node_not_ready + +let () = + register_error_kind + `Permanent + ~id:"dal.node.not.ready" + ~title:"DAL Node not ready" + ~description:"DAL node is starting. It's not ready to respond to RPCs." + ~pp:(fun ppf () -> + Format.fprintf + ppf + "DAL node is starting. It's not ready to respond to RPCs.") + Data_encoding.(unit) + (function Node_not_ready -> Some () | _ -> None) + (fun () -> Node_not_ready) + +let get_ready ctxt = + let open Result_syntax in + match ctxt.status with + | Ready ctxt -> Ok ctxt + | Starting -> fail [Node_not_ready] + +let get_config ctxt = ctxt.config + +let get_status ctxt = ctxt.status diff --git a/src/bin_dal_node/node_context.mli b/src/bin_dal_node/node_context.mli index a8127cc2209c..57e7ff4d27f2 100644 --- a/src/bin_dal_node/node_context.mli +++ b/src/bin_dal_node/node_context.mli @@ -27,10 +27,25 @@ type ready_ctxt = { dal_constants : Cryptobox.t; dal_parameters : Cryptobox.parameters; plugin : (module Dal_constants_plugin.T); + slot_header_store : Slot_headers_store.t; } type status = Ready of ready_ctxt | Starting -type t = {mutable status : status; config : Configuration.t} +type t -val make : Configuration.t -> t +val init : Configuration.t -> t + +val set_ready : + t -> + Slot_headers_store.t -> + (module Dal_constants_plugin.T) -> + Cryptobox.t -> + Cryptobox.parameters -> + unit + +val get_ready : t -> ready_ctxt tzresult + +val get_config : t -> Configuration.t + +val get_status : t -> status diff --git a/src/bin_dal_node/slot_headers_store.ml b/src/bin_dal_node/slot_headers_store.ml index feff7f3062e0..b55df96448ef 100644 --- a/src/bin_dal_node/slot_headers_store.ml +++ b/src/bin_dal_node/slot_headers_store.ml @@ -23,14 +23,13 @@ (* *) (*****************************************************************************) -open Protocol.Alpha_context include Store_utils (* Published slot headers per block hash, stored as a list of bindings from `Dal_slot_index.t` to `Dal.Slot.t`. The encoding function converts this list into a `Dal.Slot_index.t`-indexed map. *) -module Dal_slots = Make_nested_map (struct +include Make_nested_map (struct let path = ["dal"; "slot_headers"] (* FIXME/DAL: https://gitlab.com/tezos/tezos/-/issues/3527 @@ -41,17 +40,17 @@ module Dal_slots = Make_nested_map (struct let string_of_key = Block_hash.to_b58check - type secondary_key = Dal.Slot_index.t + type secondary_key = int - let compare_secondary_keys = Dal.Slot_index.compare + let compare_secondary_keys = Int.compare - type value = Dal.Slot.t + type value = Cryptobox.commitment - let secondary_key_encoding = Dal.Slot_index.encoding + let secondary_key_encoding = Data_encoding.int31 let secondary_key_name = "slot_index" - let value_encoding = Dal.Slot.encoding + let value_encoding = Cryptobox.Commitment.encoding let value_name = "slots_metadata" end) diff --git a/src/proto_alpha/lib_dal/dal_plugin_registration.ml b/src/proto_alpha/lib_dal/dal_plugin_registration.ml index e37026342b0a..ed1d1f0cf42a 100644 --- a/src/proto_alpha/lib_dal/dal_plugin_registration.ml +++ b/src/proto_alpha/lib_dal/dal_plugin_registration.ml @@ -42,7 +42,7 @@ module Plugin = struct let open Lwt_result_syntax in let open Protocol.Alpha_context in let cpctxt = new Protocol_client_context.wrap_full ctxt in - let+ block = + let* block = Protocol_client_context.Alpha_block_services.info cpctxt ~block @@ -51,16 +51,13 @@ module Plugin = struct in let apply_internal acc ~source:_ _op _res = acc in let apply (type kind) acc ~source:_ (op : kind manager_operation) _res = - match op with - | Dal_publish_slot_header {slot = {index; header; _}} -> - (Dal.Slot_index.to_int index, header) :: acc - | _ -> acc + match op with Dal_publish_slot_header {slot} -> slot :: acc | _ -> acc in - let slot_headers = - Layer1_services.( - process_manager_operations [] block.operations {apply; apply_internal}) - in - slot_headers + Layer1_services.( + process_manager_operations [] block.operations {apply; apply_internal}) + |> List.map_es (fun slot -> + return + (Dal.Slot_index.to_int slot.Dal.Slot.id.index, slot.Dal.Slot.header)) end let () = Dal_constants_plugin.register (module Plugin) -- GitLab From 796b96feb37bb42122e14d265d6bce3b301b4a50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20El=20Siba=C3=AFe?= Date: Wed, 14 Sep 2022 15:55:25 +0200 Subject: [PATCH 07/10] Dal/Node: rpc to list stored slot_header --- src/bin_dal_node/RPC_server.ml | 19 +++++++++++++++++++ src/lib_dal_node_services/services.ml | 12 ++++++++++++ 2 files changed, 31 insertions(+) diff --git a/src/bin_dal_node/RPC_server.ml b/src/bin_dal_node/RPC_server.ml index 00ba97250d0f..8af87431a331 100644 --- a/src/bin_dal_node/RPC_server.ml +++ b/src/bin_dal_node/RPC_server.ml @@ -50,6 +50,18 @@ let handle_slot ctxt store (_, commitment) trim () = let slot = if trim then Slot_manager.Utils.trim_x00 slot else slot in return (String.of_bytes slot) +let handle_stored_slot_headers ctxt (_, block_hash) () () = + let open Lwt_result_syntax in + let*? {plugin = (module Plugin); slot_header_store; _} = + Node_context.get_ready ctxt + in + let*! shs = + Slot_headers_store.list_secondary_keys_with_values + slot_header_store + ~primary_key:block_hash + in + return @@ shs + let handle_slot_pages ctxt store (_, commitment) () () = let open Lwt_result_syntax in let*? {dal_parameters; dal_constants; _} = Node_context.get_ready ctxt in @@ -58,6 +70,12 @@ let handle_slot_pages ctxt store (_, commitment) () () = let handle_shard store ((_, commitment), shard) () () = Slot_manager.get_shard store commitment shard +let register_stored_slot_headers ctxt dir = + RPC_directory.register + dir + (Services.stored_slot_headers ()) + (handle_stored_slot_headers ctxt) + let register_split_slot ctxt store dir = RPC_directory.register0 dir @@ -78,6 +96,7 @@ let register_shard store dir = let register ctxt store = RPC_directory.empty + |> register_stored_slot_headers ctxt |> register_split_slot ctxt store |> register_show_slot ctxt store |> register_shard store diff --git a/src/lib_dal_node_services/services.ml b/src/lib_dal_node_services/services.ml index da0f86a53da7..48098cf56a69 100644 --- a/src/lib_dal_node_services/services.ml +++ b/src/lib_dal_node_services/services.ml @@ -59,6 +59,18 @@ let slot_pages () = ~output:(Data_encoding.list Data_encoding.string) RPC_path.(open_root / "slot" / "pages" /: Cryptobox.Commitment.rpc_arg) +let stored_slot_headers () = + RPC_service.get_service + ~description:"List slot headers for a given block hash" + ~query:RPC_query.empty + ~output: + Data_encoding.( + list + (obj2 + (req "index" int31) + (req "slot_header" Cryptobox.Commitment.encoding))) + RPC_path.(open_root / "stored_slot_headers" /: Block_hash.rpc_arg) + let shard () = let shard_arg = RPC_arg.int in RPC_service.get_service -- GitLab From b0608e1fd2d153236ddb385de83169b8f83dfce3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20El=20Siba=C3=AFe?= Date: Wed, 14 Sep 2022 15:55:13 +0200 Subject: [PATCH 08/10] Dal/Tezt: published slot header tracking and storage from dal node --- tezt/lib_tezos/rollup.ml | 9 +++++ tezt/lib_tezos/rollup.mli | 5 +++ tezt/tests/dal.ml | 72 ++++++++++++++++++++++++++++++++------- 3 files changed, 74 insertions(+), 12 deletions(-) diff --git a/tezt/lib_tezos/rollup.ml b/tezt/lib_tezos/rollup.ml index 6e44527f53f3..c02bf6e366be 100644 --- a/tezt/lib_tezos/rollup.ml +++ b/tezt/lib_tezos/rollup.ml @@ -555,6 +555,15 @@ module Dal = struct let slot_pages slot_header = make GET ["slot"; "pages"; slot_header] (fun pages -> pages |> JSON.as_list |> List.map JSON.as_string) + + let stored_slot_headers block_hash = + make GET ["stored_slot_headers"; block_hash] @@ fun json -> + let open JSON in + let l = as_list json in + List.map + (fun json -> + (json |-> "index" |> as_int, json |-> "slot_header" |> as_string)) + l end module Cryptobox = Tezos_crypto_dal.Cryptobox diff --git a/tezt/lib_tezos/rollup.mli b/tezt/lib_tezos/rollup.mli index ea717b79c063..fd14d1047c28 100644 --- a/tezt/lib_tezos/rollup.mli +++ b/tezt/lib_tezos/rollup.mli @@ -237,6 +237,11 @@ module Dal : sig (** [slot_pages slot_header] gets slot/pages of [slot_header] *) val slot_pages : string -> (Dal_node.t, string list) RPC_core.t + + (** [stored_slot_headers slot_header] gets slot_headers stored for a given + block hash *) + val stored_slot_headers : + string -> (Dal_node.t, (int * string) list) RPC_core.t end module Cryptobox = Tezos_crypto_dal.Cryptobox diff --git a/tezt/tests/dal.ml b/tezt/tests/dal.ml index f229d2a6ea1d..58c9905e1ee1 100644 --- a/tezt/tests/dal.ml +++ b/tezt/tests/dal.ml @@ -51,6 +51,9 @@ let regression_test ~__FILE__ ?(tags = []) title f = let tags = "dal" :: tags in Protocol.register_regression_test ~__FILE__ ~title ~tags f +let dal_enable_param dal_enable = + make_bool_parameter ["dal_parametric"; "feature_enable"] dal_enable + let setup ?commitment_period ?challenge_window ?dal_enable f ~protocol = let parameters = make_int_parameter @@ -61,7 +64,7 @@ let setup ?commitment_period ?challenge_window ?dal_enable f ~protocol = challenge_window (* this will produce the empty list if dal_enable is not passed to the function invocation, hence the value from the protocol constants will be used. *) - @ make_bool_parameter ["dal_parametric"; "feature_enable"] dal_enable + @ dal_enable_param dal_enable @ [(["sc_rollup_enable"], `Bool true)] in let base = Either.right (protocol, None) in @@ -223,16 +226,19 @@ let test_feature_flag _protocol _sc_rollup_node sc_rollup_address node client = Test.fail "Unexpected entry dal in the context when DAL is disabled" ; unit -let publish_slot ~source ?fee ~index ~message parameters cryptobox node client = +let publish_slot ~source ?fee ~index ~header node client = let level = Node.get_level node in - let header = - Rollup.Dal.Commitment.dummy_commitment parameters cryptobox message - in Operation.Manager.( inject [make ~source ?fee @@ dal_publish_slot_header ~index ~level ~header] client) +let publish_dummy_slot ~source ?fee ~index ~message parameters cryptobox = + let header = + Rollup.Dal.Commitment.dummy_commitment parameters cryptobox message + in + publish_slot ~source ?fee ~index ~header + let slot_availability ~signer availability client = (* FIXME/DAL: fetch the constant from protocol parameters. *) let default_size = 256 in @@ -316,7 +322,7 @@ let test_slot_management_logic = setup ~dal_enable:true ~protocol @@ fun parameters cryptobox node client _bootstrap -> let* (`OpHash oph1) = - publish_slot + publish_dummy_slot ~source:Constant.bootstrap1 ~fee:1_000 ~index:0 @@ -327,7 +333,7 @@ let test_slot_management_logic = client in let* (`OpHash oph2) = - publish_slot + publish_dummy_slot ~source:Constant.bootstrap2 ~fee:1_500 ~index:1 @@ -338,7 +344,7 @@ let test_slot_management_logic = client in let* (`OpHash oph3) = - publish_slot + publish_dummy_slot ~source:Constant.bootstrap3 ~fee:2_000 ~index:0 @@ -349,7 +355,7 @@ let test_slot_management_logic = client in let* (`OpHash oph4) = - publish_slot + publish_dummy_slot ~source:Constant.bootstrap4 ~fee:1_200 ~index:1 @@ -496,6 +502,47 @@ let test_dal_node_slot_management = assert (slot_content = received_slot_content) ; return () +let test_dal_node_slots_headers_tracking = + Protocol.register_test + ~__FILE__ + ~title:"dal node slot headers tracking" + ~tags:["dal"; "dal_node"] + ~supports:Protocol.(From_protocol (Protocol.number Alpha)) + @@ fun protocol -> + let* node, client = + let base = Either.right (protocol, None) in + let* parameter_file = + Protocol.write_parameter_file ~base (dal_enable_param (Some true)) + in + let nodes_args = Node.[Synchronisation_threshold 0] in + Client.init_with_protocol `Client ~parameter_file ~protocol ~nodes_args () + in + let dal_node = Dal_node.create ~node () in + let* _dir = Dal_node.init_config dal_node in + let* () = Dal_node.run dal_node in + let publish_slot source index content = + let* slot_header = RPC.call dal_node (Rollup.Dal.RPC.split_slot content) in + let header = + Tezos_crypto_dal.Cryptobox.Commitment.of_b58check_opt slot_header + |> mandatory "The b58check-encoded slot header is not valid" + in + let* _ = publish_slot ~source ~fee:1_200 ~index ~header node client in + return (index, slot_header) + in + let* slot0 = publish_slot Constant.bootstrap1 0 "test0" in + let* slot1 = publish_slot Constant.bootstrap2 1 "test1" in + let* slot2 = publish_slot Constant.bootstrap3 4 "test4" in + let* () = Client.bake_for_and_wait client in + let* _level = Node.wait_for_level node 1 in + let* block = RPC.call node (RPC.get_chain_block_hash ()) in + let* slot_headers = + RPC.call dal_node (Rollup.Dal.RPC.stored_slot_headers block) + in + Check.([slot0; slot1; slot2] = slot_headers) + Check.(list (tuple2 int string)) + ~error_msg:"Published header is different from stored header (%L = %R)" ; + return () + let test_dal_node_startup = Protocol.register_test ~__FILE__ @@ -583,7 +630,7 @@ let rollup_node_stores_dal_slots _protocol sc_rollup_node sc_rollup_address node Sc_rollup_node.wait_for_level sc_rollup_node (first_subscription_level + 1) in let* _ = - publish_slot + publish_dummy_slot ~source:Constant.bootstrap1 ~fee:1_200 ~index:0 @@ -594,7 +641,7 @@ let rollup_node_stores_dal_slots _protocol sc_rollup_node sc_rollup_address node client in let* _ = - publish_slot + publish_dummy_slot ~source:Constant.bootstrap2 ~fee:1_200 ~index:1 @@ -605,7 +652,7 @@ let rollup_node_stores_dal_slots _protocol sc_rollup_node sc_rollup_address node client in let* _ = - publish_slot + publish_dummy_slot ~source:Constant.bootstrap3 ~fee:1_200 ~index:2 @@ -672,6 +719,7 @@ let register ~protocols = protocols ; test_slot_management_logic protocols ; test_dal_node_slot_management protocols ; + test_dal_node_slots_headers_tracking protocols ; test_dal_node_startup protocols ; test_dal_scenario ~dal_enable:true -- GitLab From 0333944719084277e3219a2a7d4b7998adfeea57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20El=20Siba=C3=AFe?= Date: Wed, 7 Sep 2022 16:19:05 +0200 Subject: [PATCH 09/10] Dal/Node: rename Dal_constants_plugin -> Dal_plugin --- src/bin_dal_node/daemon.ml | 8 ++++---- src/bin_dal_node/node_context.ml | 2 +- src/bin_dal_node/node_context.mli | 4 ++-- .../{dal_constants_plugin.ml => dal_plugin.ml} | 0 .../{dal_constants_plugin.mli => dal_plugin.mli} | 0 src/proto_alpha/lib_dal/dal_plugin_registration.ml | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) rename src/lib_dal_node/{dal_constants_plugin.ml => dal_plugin.ml} (100%) rename src/lib_dal_node/{dal_constants_plugin.mli => dal_plugin.mli} (100%) diff --git a/src/bin_dal_node/daemon.ml b/src/bin_dal_node/daemon.ml index d54007f80b12..2a0669a28c36 100644 --- a/src/bin_dal_node/daemon.ml +++ b/src/bin_dal_node/daemon.ml @@ -30,8 +30,8 @@ let resolve_plugin cctxt = in return @@ Option.either - (Dal_constants_plugin.get protocols.current_protocol) - (Dal_constants_plugin.get protocols.next_protocol) + (Dal_plugin.get protocols.current_protocol) + (Dal_plugin.get protocols.next_protocol) type error += Cryptobox_initialisation_failed of string @@ -50,7 +50,7 @@ let () = (function Cryptobox_initialisation_failed str -> Some str | _ -> None) (fun str -> Cryptobox_initialisation_failed str) -let init_cryptobox unsafe_srs cctxt (module Plugin : Dal_constants_plugin.T) = +let init_cryptobox unsafe_srs cctxt (module Plugin : Dal_plugin.T) = let open Cryptobox in let open Lwt_result_syntax in let* parameters = Plugin.get_constants cctxt#chain cctxt#block cctxt in @@ -108,7 +108,7 @@ let run ~data_dir cctxt = let* plugin = resolve_plugin cctxt in match plugin with | Some plugin -> - let (module Plugin : Dal_constants_plugin.T) = plugin in + let (module Plugin : Dal_plugin.T) = plugin in let*! () = Event.emit_protocol_plugin_resolved Plugin.Proto.hash in let* dal_constants, dal_parameters = init_cryptobox config.use_unsafe_srs cctxt plugin diff --git a/src/bin_dal_node/node_context.ml b/src/bin_dal_node/node_context.ml index bb5f767c9808..c7d9615e7b90 100644 --- a/src/bin_dal_node/node_context.ml +++ b/src/bin_dal_node/node_context.ml @@ -28,7 +28,7 @@ exception Status_already_ready type ready_ctxt = { dal_constants : Cryptobox.t; dal_parameters : Cryptobox.parameters; - plugin : (module Dal_constants_plugin.T); + plugin : (module Dal_plugin.T); slot_header_store : Slot_headers_store.t; } diff --git a/src/bin_dal_node/node_context.mli b/src/bin_dal_node/node_context.mli index 57e7ff4d27f2..7adfa05c4248 100644 --- a/src/bin_dal_node/node_context.mli +++ b/src/bin_dal_node/node_context.mli @@ -26,7 +26,7 @@ type ready_ctxt = { dal_constants : Cryptobox.t; dal_parameters : Cryptobox.parameters; - plugin : (module Dal_constants_plugin.T); + plugin : (module Dal_plugin.T); slot_header_store : Slot_headers_store.t; } @@ -39,7 +39,7 @@ val init : Configuration.t -> t val set_ready : t -> Slot_headers_store.t -> - (module Dal_constants_plugin.T) -> + (module Dal_plugin.T) -> Cryptobox.t -> Cryptobox.parameters -> unit diff --git a/src/lib_dal_node/dal_constants_plugin.ml b/src/lib_dal_node/dal_plugin.ml similarity index 100% rename from src/lib_dal_node/dal_constants_plugin.ml rename to src/lib_dal_node/dal_plugin.ml diff --git a/src/lib_dal_node/dal_constants_plugin.mli b/src/lib_dal_node/dal_plugin.mli similarity index 100% rename from src/lib_dal_node/dal_constants_plugin.mli rename to src/lib_dal_node/dal_plugin.mli diff --git a/src/proto_alpha/lib_dal/dal_plugin_registration.ml b/src/proto_alpha/lib_dal/dal_plugin_registration.ml index ed1d1f0cf42a..ebcf861ab312 100644 --- a/src/proto_alpha/lib_dal/dal_plugin_registration.ml +++ b/src/proto_alpha/lib_dal/dal_plugin_registration.ml @@ -60,4 +60,4 @@ module Plugin = struct (Dal.Slot_index.to_int slot.Dal.Slot.id.index, slot.Dal.Slot.header)) end -let () = Dal_constants_plugin.register (module Plugin) +let () = Dal_plugin.register (module Plugin) -- GitLab From 29b576624f145e70bbe6527392f961c2b0638d5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20El=20Siba=C3=AFe?= Date: Mon, 19 Sep 2022 15:49:47 +0200 Subject: [PATCH 10/10] Dal/Node: node context documentation --- src/bin_dal_node/node_context.mli | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/bin_dal_node/node_context.mli b/src/bin_dal_node/node_context.mli index 7adfa05c4248..0e2a97b53970 100644 --- a/src/bin_dal_node/node_context.mli +++ b/src/bin_dal_node/node_context.mli @@ -23,6 +23,9 @@ (* *) (*****************************************************************************) +(** A [ready_ctx] value contains globally needed informations for a running dal + node. It is available when both cryptobox is initialized and dal plugin is + loaded. *) type ready_ctxt = { dal_constants : Cryptobox.t; dal_parameters : Cryptobox.parameters; @@ -30,12 +33,25 @@ type ready_ctxt = { slot_header_store : Slot_headers_store.t; } +(** The status of the dal node *) type status = Ready of ready_ctxt | Starting +(** A [t] value contains both the status and the dal node configuration. It's + field are available through accessors *) type t +(** [init config] creates a [t] with a status set to [Starting] with a given dal + node configuration.*) val init : Configuration.t -> t +(** Raised by [set_ready] when the status is already [Ready _] *) +exception Status_already_ready + +(** [set_ready ctxt slot_header_store plugin dal_constants dal_params] updates + in place the status value to ready, and initializes the inner [ready_ctxt] + value with the given parameters. + + @raise Status_already_ready when the status is already [Ready _] *) val set_ready : t -> Slot_headers_store.t -> @@ -44,8 +60,15 @@ val set_ready : Cryptobox.parameters -> unit +type error += Node_not_ready + +(** [get_ready ctxt] extracts the [ready_ctxt] value from a context [t]. It + propagates [Node_not_ready] if status is not ready yet. If called multiple + times, it replaces current values for [ready_ctxt] with new ones *) val get_ready : t -> ready_ctxt tzresult +(** [get_config ctxt] returns the dal node configuration *) val get_config : t -> Configuration.t +(** [get_status ctxt] returns the dal node status *) val get_status : t -> status -- GitLab