From fcb78958008ee1a8ae279179609e6531aef531b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20El=20Siba=C3=AFe?= Date: Wed, 10 Aug 2022 16:41:22 +0200 Subject: [PATCH 1/7] DAL/Node: improve configuration documentation and interface --- src/bin_dal_node/configuration.ml | 8 ++++- src/bin_dal_node/configuration.mli | 50 ++++++++++++++++++++++++++++++ src/bin_dal_node/main_dal.ml | 13 +++----- 3 files changed, 62 insertions(+), 9 deletions(-) create mode 100644 src/bin_dal_node/configuration.mli diff --git a/src/bin_dal_node/configuration.ml b/src/bin_dal_node/configuration.ml index 5361e1ad744a..b1fd73750edb 100644 --- a/src/bin_dal_node/configuration.ml +++ b/src/bin_dal_node/configuration.ml @@ -42,6 +42,8 @@ let default_rpc_addr = "127.0.0.1" let default_rpc_port = 10732 +let default_unsafe_srs = false + let encoding : t Data_encoding.t = let open Data_encoding in conv @@ -50,7 +52,11 @@ let encoding : t Data_encoding.t = (fun (unsafe_srs, data_dir, rpc_addr, rpc_port) -> {unsafe_srs; data_dir; rpc_addr; rpc_port}) (obj4 - (dft "unsafe_srs" ~description:"use unsafe srs for tests" bool false) + (dft + "unsafe_srs" + ~description:"use unsafe srs for tests" + bool + default_unsafe_srs) (dft "data-dir" ~description:"Location of the data dir" diff --git a/src/bin_dal_node/configuration.mli b/src/bin_dal_node/configuration.mli new file mode 100644 index 000000000000..5c1bb2bf9704 --- /dev/null +++ b/src/bin_dal_node/configuration.mli @@ -0,0 +1,50 @@ +(*****************************************************************************) +(* *) +(* 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. *) +(* *) +(*****************************************************************************) + +type t = { + unsafe_srs : bool; + (** Run dal-node in test mode with an unsafe SRS (Trusted setup) *) + data_dir : string; (** The path to the DAL node data directory *) + rpc_addr : string; (** The address the DAL node listens to *) + rpc_port : int; (** The port the DAL node listens to *) +} + +(** [filename config] gets the path to config file *) +val filename : t -> string + +(** [data_dir_path config subpath] builds a subpath relatively to the + [config] *) +val data_dir_path : t -> string -> string + +val default_data_dir : string + +val default_rpc_addr : string + +val default_rpc_port : int + +(** [save config] writes config file in [config.data_dir] *) +val save : t -> unit tzresult Lwt.t + +val load : data_dir:string -> (t, Error_monad.tztrace) result Lwt.t diff --git a/src/bin_dal_node/main_dal.ml b/src/bin_dal_node/main_dal.ml index c0760575d318..c8f231498abc 100644 --- a/src/bin_dal_node/main_dal.ml +++ b/src/bin_dal_node/main_dal.ml @@ -23,8 +23,7 @@ (* *) (*****************************************************************************) -let group = - {Clic.name = "dal-daemon"; title = "Commands related to the DAL daemon"} +let group = {Clic.name = "dal-node"; title = "Commands related to the DAL node"} let data_dir_arg = let default = Configuration.default_data_dir in @@ -33,7 +32,7 @@ let data_dir_arg = ~placeholder:"data-dir" ~doc: (Format.sprintf - "The path to the DAL daemon data directory. Default value is %s" + "The path to the DAL node data directory. Default value is %s" default) ~default (Client_config.string_parameter ()) @@ -45,8 +44,7 @@ let rpc_addr_arg = ~placeholder:"rpc-address|ip" ~doc: (Format.sprintf - "The address the smart-contract rollup node listens to. Default value \ - is %s" + "The address the DAL node listens to. Default value is %s" default) ~default (Client_config.string_parameter ()) @@ -63,8 +61,7 @@ let rpc_port_arg = ~placeholder:"rpc-port" ~doc: (Format.sprintf - "The port the smart-contract rollup node listens to. Default value is \ - %s" + "The port the DAL node listens to. Default value is %s" default) ~default int_parameter @@ -98,7 +95,7 @@ let run_command = let open Clic in command ~group - ~desc:"Run the DAL daemon." + ~desc:"Run the DAL node." (args1 data_dir_arg) (prefixes ["run"] @@ stop) (fun data_dir cctxt -> Daemon.run ~data_dir cctxt) -- GitLab From e7c1b6014155a5aa144db0a1777ab1f8beac11c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20El=20Siba=C3=AFe?= Date: Wed, 10 Aug 2022 17:26:43 +0200 Subject: [PATCH 2/7] DAL/Node: refactor Dal_cryptobox interface - remove cryptobox.ml - move parameters into environment - use parameters type everywhere --- manifest/main.ml | 2 +- src/bin_dal_node/RPC_server.ml | 4 +- src/bin_dal_node/cryptobox.ml | 82 ------------------- src/bin_dal_node/daemon.ml | 41 +++++++++- src/bin_dal_node/dune | 3 +- src/bin_dal_node/node_context.ml | 4 +- src/bin_dal_node/node_context.mli | 6 +- src/bin_dal_node/slot_manager.ml | 40 +++++---- src/bin_dal_node/slot_manager.mli | 33 ++++---- src/lib_crypto_dal/dal_cryptobox.ml | 11 ++- src/lib_crypto_dal/dal_cryptobox.mli | 18 +++- src/lib_crypto_dal/dal_cryptobox_intf.ml | 15 ++-- src/lib_crypto_dal/test/test_dal_cryptobox.ml | 5 +- src/lib_dal_node/dal_constants_plugin.ml | 13 +-- src/lib_dal_node/dal_constants_plugin.mli | 9 +- .../environment_V7.ml | 2 + .../environment_V7.mli | 2 + src/lib_protocol_environment/sigs/v7.ml | 15 ++-- src/lib_protocol_environment/sigs/v7/dal.mli | 15 ++-- .../lib_dal/dal_plugin_registration.ml | 11 +-- tezt/lib_tezos/rollup.ml | 5 +- 21 files changed, 153 insertions(+), 183 deletions(-) delete mode 100644 src/bin_dal_node/cryptobox.ml diff --git a/manifest/main.ml b/manifest/main.ml index 4cafc00c47e9..093856421406 100644 --- a/manifest/main.ml +++ b/manifest/main.ml @@ -5472,7 +5472,7 @@ let _octez_dal_node = octez_stdlib |> open_; octez_dal_node_lib |> open_; octez_dal_node_services |> open_; - octez_crypto_dal; + octez_crypto_dal |> open_; irmin_pack; irmin_pack_unix; irmin; diff --git a/src/bin_dal_node/RPC_server.ml b/src/bin_dal_node/RPC_server.ml index b7a390f5c96a..5384ce57c19f 100644 --- a/src/bin_dal_node/RPC_server.ml +++ b/src/bin_dal_node/RPC_server.ml @@ -34,11 +34,11 @@ let handle_split_slot dal_parameters dal_constants store fill slot = let slot = String.to_bytes slot in let slot = if fill then - Slot_manager.Utils.fill_x00 dal_parameters.Cryptobox.slot_size slot + Slot_manager.Utils.fill_x00 dal_parameters.Dal_cryptobox.slot_size slot else slot in let+ commitment = Slot_manager.split_and_store dal_constants store slot in - Cryptobox.Commitment.to_b58check commitment + Dal_cryptobox.Commitment.to_b58check commitment let handle_slot initial_constants dal_constants store (_, commitment) trim () = let open Lwt_result_syntax in diff --git a/src/bin_dal_node/cryptobox.ml b/src/bin_dal_node/cryptobox.ml deleted file mode 100644 index b84bd3465a94..000000000000 --- a/src/bin_dal_node/cryptobox.ml +++ /dev/null @@ -1,82 +0,0 @@ -(*****************************************************************************) -(* *) -(* 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 Tezos_crypto_dal -include Dal_cryptobox - -type slot = bytes - -type slot_header = commitment - -let slot_header_encoding = Commitment.encoding - -type parameters = { - redundancy_factor : int; - segment_size : int; - slot_size : int; - number_of_shards : int; -} - -type error += Cryptobox_initialisation_failed of string - -let () = - register_error_kind - `Permanent - ~id:"dal.node.cryptobox.initialisation_failed" - ~title:"Cryptobox initialisation failed" - ~description:"Unable to initialise the cryptobox parameters" - ~pp:(fun ppf msg -> - Format.fprintf - ppf - "Unable to initialise the cryptobox parameters. Reason: %s" - msg) - Data_encoding.(obj1 (req "error" string)) - (function Cryptobox_initialisation_failed str -> Some str | _ -> None) - (fun str -> Cryptobox_initialisation_failed str) - -let init unsafe_srs cctxt (module Plugin : Dal_constants_plugin.T) = - let open Lwt_result_syntax in - let* Plugin.{redundancy_factor; segment_size; slot_size; number_of_shards} = - Plugin.get_constants cctxt#chain cctxt#block cctxt - in - let parameters = - {redundancy_factor; segment_size; slot_size; number_of_shards} - in - let* initialisation_parameters = - if unsafe_srs then - return - @@ Internal_for_tests.initialisation_parameters_from_slot_size ~slot_size - else - let*? g1_path, g2_path = Tezos_base.Dal_srs.find_trusted_setup_files () in - initialisation_parameters_from_files ~g1_path ~g2_path - in - let*? () = load_parameters initialisation_parameters in - let* dal_constants = - match - make ~redundancy_factor ~segment_size ~slot_size ~number_of_shards - with - | Ok cryptobox -> return cryptobox - | Error (`Fail msg) -> fail [Cryptobox_initialisation_failed msg] - in - return @@ (dal_constants, parameters) diff --git a/src/bin_dal_node/daemon.ml b/src/bin_dal_node/daemon.ml index 3e8b550ed43d..d7b22f4b23f9 100644 --- a/src/bin_dal_node/daemon.ml +++ b/src/bin_dal_node/daemon.ml @@ -35,6 +35,45 @@ let resolve_plugin cctxt = (Dal_constants_plugin.get protocols.current_protocol) (Dal_constants_plugin.get protocols.next_protocol) +open Dal_cryptobox + +type error += Cryptobox_initialisation_failed of string + +let () = + register_error_kind + `Permanent + ~id:"dal.node.cryptobox.initialisation_failed" + ~title:"Cryptobox initialisation failed" + ~description:"Unable to initialise the cryptobox parameters" + ~pp:(fun ppf msg -> + Format.fprintf + ppf + "Unable to initialise the cryptobox parameters. Reason: %s" + msg) + Data_encoding.(obj1 (req "error" string)) + (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 open Lwt_result_syntax in + let* parameters = Plugin.get_constants cctxt#chain cctxt#block cctxt in + let* initialisation_parameters = + if unsafe_srs then + return + @@ Internal_for_tests.initialisation_parameters_from_slot_size + ~slot_size:parameters.slot_size + else + let*? g1_path, g2_path = Tezos_base.Dal_srs.find_trusted_setup_files () in + initialisation_parameters_from_files ~g1_path ~g2_path + in + let*? () = load_parameters initialisation_parameters in + let* dal_constants = + match make parameters with + | Ok cryptobox -> return cryptobox + | Error (`Fail msg) -> fail [Cryptobox_initialisation_failed msg] + in + return @@ (dal_constants, parameters) + let run ~data_dir cctxt = let open Lwt_result_syntax in let*! () = Event.(emit starting_node) () in @@ -56,7 +95,7 @@ let run ~data_dir cctxt = (Format.asprintf "%a" Protocol_hash.pp_short Plugin.Proto.hash)) in let* dal_constants, dal_parameters = - Cryptobox.init config.unsafe_srs cctxt plugin + init_cryptobox config.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 diff --git a/src/bin_dal_node/dune b/src/bin_dal_node/dune index 66b66bee44c3..a0fa01a5e848 100644 --- a/src/bin_dal_node/dune +++ b/src/bin_dal_node/dune @@ -40,6 +40,7 @@ -open Tezos_stdlib_unix -open Tezos_stdlib -open Tezos_dal_node_lib - -open Tezos_dal_node_services)) + -open Tezos_dal_node_services + -open Tezos_crypto_dal)) (rule (action (progn (write-file void_for_linking-tezos-dal-alpha.empty "")))) diff --git a/src/bin_dal_node/node_context.ml b/src/bin_dal_node/node_context.ml index 9c592a633a80..fd12459d99db 100644 --- a/src/bin_dal_node/node_context.ml +++ b/src/bin_dal_node/node_context.ml @@ -25,8 +25,8 @@ type t = { config : Configuration.t; - dal_constants : Cryptobox.t; - dal_parameters : Cryptobox.parameters; + dal_constants : Dal_cryptobox.t; + dal_parameters : Dal_cryptobox.parameters; } let make config dal_constants dal_parameters = diff --git a/src/bin_dal_node/node_context.mli b/src/bin_dal_node/node_context.mli index 3afb13c23926..3dd9388ee138 100644 --- a/src/bin_dal_node/node_context.mli +++ b/src/bin_dal_node/node_context.mli @@ -25,8 +25,8 @@ type t = { config : Configuration.t; - dal_constants : Cryptobox.t; - dal_parameters : Cryptobox.parameters; + dal_constants : Dal_cryptobox.t; + dal_parameters : Dal_cryptobox.parameters; } -val make : Configuration.t -> Cryptobox.t -> Cryptobox.parameters -> t +val make : Configuration.t -> Dal_cryptobox.t -> Dal_cryptobox.parameters -> t diff --git a/src/bin_dal_node/slot_manager.ml b/src/bin_dal_node/slot_manager.ml index b281c7127fdd..1525f62ac561 100644 --- a/src/bin_dal_node/slot_manager.ml +++ b/src/bin_dal_node/slot_manager.ml @@ -88,6 +88,8 @@ let () = (function Illformed_shard -> Some () | _ -> None) (fun () -> Illformed_shard) +type slot = bytes + let wrap_encoding_error = Result.map_error (fun e -> [Tezos_base.Data_encoding_wrapper.Encoding_error e]) @@ -97,17 +99,17 @@ let encode enc v = Data_encoding.Binary.to_string enc v |> wrap_encoding_error let share_path slot_header shard_id = [slot_header; string_of_int shard_id] let decode_share s = - Data_encoding.Binary.of_string Cryptobox.share_encoding s + Data_encoding.Binary.of_string Dal_cryptobox.share_encoding s |> Result.map_error (fun e -> [Tezos_base.Data_encoding_wrapper.Decoding_error e]) let save store slot_header shards = let open Lwt_result_syntax in - let slot_header = Cryptobox.Commitment.to_b58check slot_header in - Cryptobox.IntMap.iter_es + let slot_header = Dal_cryptobox.Commitment.to_b58check slot_header in + Dal_cryptobox.IntMap.iter_es (fun i share -> let path = share_path slot_header i in - let*? share = encode Cryptobox.share_encoding share in + let*? share = encode Dal_cryptobox.share_encoding share in let*! metadata = Store.set ~msg:"Share stored" store path share in return metadata) shards @@ -115,25 +117,29 @@ let save store slot_header shards = let split_and_store cb_constants store slot = let r = let open Result_syntax in - let* polynomial = Cryptobox.polynomial_from_slot cb_constants slot in - let commitment = Cryptobox.commit cb_constants polynomial in + let* polynomial = Dal_cryptobox.polynomial_from_slot cb_constants slot in + let commitment = Dal_cryptobox.commit cb_constants polynomial in return (polynomial, commitment) in let open Lwt_result_syntax in match r with | Ok (polynomial, commitment) -> - let shards = Cryptobox.shards_from_polynomial cb_constants polynomial in + let shards = + Dal_cryptobox.shards_from_polynomial cb_constants polynomial + in let* () = save store commitment shards in let*! () = Event.( - emit stored_slot (Bytes.length slot, Cryptobox.IntMap.cardinal shards)) + emit + stored_slot + (Bytes.length slot, Dal_cryptobox.IntMap.cardinal shards)) in Lwt.return_ok commitment | Error (`Slot_wrong_size msg) -> Lwt.return_error [Splitting_failed msg] let get_shard store slot_header shard_id = let open Lwt_result_syntax in - let*? slot_header = encode Cryptobox.slot_header_encoding slot_header in + let*? slot_header = encode Dal_cryptobox.Commitment.encoding slot_header in let* share = Lwt.catch (fun () -> @@ -143,20 +149,20 @@ let get_shard store slot_header shard_id = | Invalid_argument _ -> fail [Slot_not_found] | e -> fail [Exn e]) in let*? share = decode_share share in - return Cryptobox.{index = shard_id; share} + return Dal_cryptobox.{index = shard_id; share} let check_shards initial_constants shards = let open Result_syntax in if shards = [] then fail [Slot_not_found] else if Compare.List_length_with.( - shards = initial_constants.Cryptobox.number_of_shards) + shards = initial_constants.Dal_cryptobox.number_of_shards) then Ok () else fail [Missing_shards] let get_slot initial_constants dal_constants store slot_header = let open Lwt_result_syntax in - let slot_header = Cryptobox.Commitment.to_b58check slot_header in + let slot_header = Dal_cryptobox.Commitment.to_b58check slot_header in let*! shards = Store.list store [slot_header] in let*? () = check_shards initial_constants shards in let* shards = @@ -172,20 +178,20 @@ let get_slot initial_constants dal_constants store slot_header = return share in let*? share = decode_share share in - return (Cryptobox.IntMap.add i share shards)) - Cryptobox.IntMap.empty + return (Dal_cryptobox.IntMap.add i share shards)) + Dal_cryptobox.IntMap.empty shards in let*? polynomial = - match Cryptobox.polynomial_from_shards dal_constants shards with + match Dal_cryptobox.polynomial_from_shards dal_constants shards with | Ok p -> Ok p | Error (`Invert_zero msg | `Not_enough_shards msg) -> Error [Merging_failed msg] in - let slot = Cryptobox.polynomial_to_bytes dal_constants polynomial in + let slot = Dal_cryptobox.polynomial_to_bytes dal_constants polynomial in let*! () = Event.( - emit fetched_slot (Bytes.length slot, Cryptobox.IntMap.cardinal shards)) + emit fetched_slot (Bytes.length slot, Dal_cryptobox.IntMap.cardinal shards)) in return slot diff --git a/src/bin_dal_node/slot_manager.mli b/src/bin_dal_node/slot_manager.mli index c338b0932e0d..214beaf99270 100644 --- a/src/bin_dal_node/slot_manager.mli +++ b/src/bin_dal_node/slot_manager.mli @@ -30,36 +30,41 @@ - reading a slot means rebuild it from the shards *) +type slot = bytes + (** [split_and_store dal_constants ts store slot] splits [slot] in shards, stores it onto the disk and returns the corresponding [slot_header], using [dal_constants] and trusted setup [ts] *) val split_and_store : - Cryptobox.t -> + Dal_cryptobox.t -> Store.t -> - Cryptobox.slot -> - Cryptobox.slot_header tzresult Lwt.t + slot -> + Dal_cryptobox.Commitment.t tzresult Lwt.t (** [get_shard store slot_header shard_id] gets the shard associated to [slot_header] at the range [shard_id] *) val get_shard : - Store.t -> Cryptobox.slot_header -> int -> Cryptobox.shard tzresult Lwt.t + Store.t -> + Dal_cryptobox.commitment -> + int -> + Dal_cryptobox.shard tzresult Lwt.t (** [get_slot dal_parameters dal_constants store slot_header] fetches from disk the shards associated to [slot_header], gathers them, rebuilds and returns the [slot]. *) val get_slot : - Cryptobox.parameters -> - Cryptobox.t -> + Dal_cryptobox.parameters -> + Dal_cryptobox.t -> Store.t -> - Cryptobox.slot_header -> - Cryptobox.slot tzresult Lwt.t + Dal_cryptobox.commitment -> + slot tzresult Lwt.t module Utils : sig - (** [trim_x00 b] removes trailing '\000' at the end of a [b] and returns a new - [bytes]. This function in needed to debug the fetching a slot and remove - spurious uneeded data form it. *) - val trim_x00 : bytes -> bytes + (** [trim_x00 s] removes trailing '\000' at the end of [s] and returns + a new [slot]. This function is needed to debug the fetched slot and + remove spurious uneeded data form it. *) + val trim_x00 : slot -> slot - (** [fill_x00 slot_size b] fills a bytes with '\000' to match [slot_size] *) - val fill_x00 : int -> bytes -> bytes + (** [fill_x00 slot_size s] fills [s] with '\000' to match [slot_size] *) + val fill_x00 : int -> slot -> slot end diff --git a/src/lib_crypto_dal/dal_cryptobox.ml b/src/lib_crypto_dal/dal_cryptobox.ml index 02986daaa48a..2f042718b1c7 100644 --- a/src/lib_crypto_dal/dal_cryptobox.ml +++ b/src/lib_crypto_dal/dal_cryptobox.ml @@ -325,9 +325,16 @@ module Inner = struct let slot_as_polynomial_length ~slot_size = 1 lsl Z.(log2up (of_int slot_size / of_int scalar_bytes_amount)) + type parameters = { + redundancy_factor : int; + segment_size : int; + slot_size : int; + number_of_shards : int; + } + (* Error cases of this functions are not encapsulated into `tzresult` for modularity reasons. *) - let make ~redundancy_factor ~slot_size ~segment_size ~number_of_shards = + let make {redundancy_factor; slot_size; segment_size; number_of_shards} = let open Result_syntax in let k = slot_as_polynomial_length ~slot_size in let n = redundancy_factor * k in @@ -383,7 +390,7 @@ module Inner = struct (* We encode by segments of [segment_size] bytes each. The segments are arranged in cosets to evaluate in batch with Kate amortized. *) - let polynomial_from_bytes' t slot = + let polynomial_from_bytes' (t : t) slot = if Bytes.length slot <> t.slot_size then Error (`Slot_wrong_size diff --git a/src/lib_crypto_dal/dal_cryptobox.mli b/src/lib_crypto_dal/dal_cryptobox.mli index 48ce065de76a..a3c7909a0610 100644 --- a/src/lib_crypto_dal/dal_cryptobox.mli +++ b/src/lib_crypto_dal/dal_cryptobox.mli @@ -25,8 +25,18 @@ open Dal_cryptobox_intf -(** Encapsulates parameters required to use the cryptographic primitives exported - by this module. *) +(** Initial values to parametrize dal cryptographic primitives. It used to build + a value of type [t] *) +type parameters = { + redundancy_factor : int; + segment_size : int; + slot_size : int; + number_of_shards : int; +} + +(** Encapsulates parameters required to use the cryptographic primitives + exported by this module. A value of type [t] contains both initial + [parameters] and computed values depending on it. *) type t (** Because of the shell/protocol separation, cryptographic primitives @@ -49,9 +59,9 @@ type t that both the [Verifier] and the [Builder] are instantiated with the same parameters and use the same trusted setup. *) -module Verifier : VERIFIER +module Verifier : VERIFIER with type parameters = parameters -include VERIFIER with type t := t +include VERIFIER with type t := t and type parameters := parameters (** The primitives exposed in this modules require some preprocessing. This preprocessing generates data from an unknown diff --git a/src/lib_crypto_dal/dal_cryptobox_intf.ml b/src/lib_crypto_dal/dal_cryptobox_intf.ml index 6937559ec4f1..6504a0cfc0d2 100644 --- a/src/lib_crypto_dal/dal_cryptobox_intf.ml +++ b/src/lib_crypto_dal/dal_cryptobox_intf.ml @@ -48,14 +48,17 @@ module type VERIFIER = sig (** A precomputed set of constants *) type t + (** Parameters to build a value of type [t] *) + type parameters = { + redundancy_factor : int; + segment_size : int; + slot_size : int; + number_of_shards : int; + } + (** [make] precomputes the set of values needed by the cryptographic primitives defined in this module and stores them in a value of type [t] *) - val make : - redundancy_factor:int -> - slot_size:int -> - segment_size:int -> - number_of_shards:int -> - (t, [> `Fail of string]) result + val make : parameters -> (t, [> `Fail of string]) result (** Commitment to a polynomial. *) type commitment diff --git a/src/lib_crypto_dal/test/test_dal_cryptobox.ml b/src/lib_crypto_dal/test/test_dal_cryptobox.ml index 8e0286b7c4c5..03ab539a49a2 100644 --- a/src/lib_crypto_dal/test/test_dal_cryptobox.ml +++ b/src/lib_crypto_dal/test/test_dal_cryptobox.ml @@ -43,10 +43,7 @@ module Test = struct (fun redundancy_factor -> let* t = Dal_cryptobox.make - ~redundancy_factor - ~slot_size - ~segment_size - ~number_of_shards + {redundancy_factor; slot_size; segment_size; number_of_shards} in let* p = Dal_cryptobox.polynomial_from_slot t msg in let cm = Dal_cryptobox.commit t p in diff --git a/src/lib_dal_node/dal_constants_plugin.ml b/src/lib_dal_node/dal_constants_plugin.ml index 1e5553f51eed..ad8831e566eb 100644 --- a/src/lib_dal_node/dal_constants_plugin.ml +++ b/src/lib_dal_node/dal_constants_plugin.ml @@ -26,22 +26,11 @@ module type T = sig module Proto : Registered_protocol.T - (* FIXME: https://gitlab.com/tezos/tezos/-/issues/3497 - - Move those constants into lib_crypto_dal and environment ? *) - - type constants = { - redundancy_factor : int; - segment_size : int; - slot_size : int; - number_of_shards : int; - } - val get_constants : Tezos_shell_services.Chain_services.chain -> Tezos_shell_services.Block_services.block -> Client_context.full -> - constants tzresult Lwt.t + Tezos_crypto_dal.Dal_cryptobox.Verifier.parameters 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 681828468a5d..cbb756286ecd 100644 --- a/src/lib_dal_node/dal_constants_plugin.mli +++ b/src/lib_dal_node/dal_constants_plugin.mli @@ -26,18 +26,11 @@ module type T = sig module Proto : Registered_protocol.T - type constants = { - redundancy_factor : int; - segment_size : int; - slot_size : int; - number_of_shards : int; - } - val get_constants : Tezos_shell_services.Chain_services.chain -> Tezos_shell_services.Block_services.block -> Client_context.full -> - constants tzresult Lwt.t + Tezos_crypto_dal.Dal_cryptobox.Verifier.parameters tzresult Lwt.t end val register : (module T) -> unit diff --git a/src/lib_protocol_environment/environment_V7.ml b/src/lib_protocol_environment/environment_V7.ml index beb388e79fe0..1aba7d75589c 100644 --- a/src/lib_protocol_environment/environment_V7.ml +++ b/src/lib_protocol_environment/environment_V7.ml @@ -104,6 +104,8 @@ module type T = sig and type Plonk.public_parameters = Plonk.Main_protocol.verifier_public_parameters * Plonk.Main_protocol.transcript + and type Dal.parameters = + Tezos_crypto_dal.Dal_cryptobox.Verifier.parameters 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 0cd0c7cdeaf8..1527b8f2f13e 100644 --- a/src/lib_protocol_environment/environment_V7.mli +++ b/src/lib_protocol_environment/environment_V7.mli @@ -104,6 +104,8 @@ module type T = sig and type Plonk.public_parameters = Plonk.Main_protocol.verifier_public_parameters * Plonk.Main_protocol.transcript + and type Dal.parameters = + Tezos_crypto_dal.Dal_cryptobox.Verifier.parameters (** An [Ecoproto_error e] is a shell error that carry a protocol error. diff --git a/src/lib_protocol_environment/sigs/v7.ml b/src/lib_protocol_environment/sigs/v7.ml index 2204b3e433ac..4d6725b31caa 100644 --- a/src/lib_protocol_environment/sigs/v7.ml +++ b/src/lib_protocol_environment/sigs/v7.ml @@ -11549,14 +11549,17 @@ end (** A precomputed set of constants *) type t +(** Parameters to build a value of type [t] *) +type parameters = { + redundancy_factor : int; + segment_size : int; + slot_size : int; + number_of_shards : int; +} + (** [make] precomputes the set of values needed by cryptographic primitives defined in this module and store them in a value of type [t] *) -val make : - redundancy_factor:int -> - slot_size:int -> - segment_size:int -> - number_of_shards:int -> - (t, [> `Fail of string]) result +val make : parameters -> (t, [> `Fail of string]) result (** Commitment to a polynomial. *) type commitment diff --git a/src/lib_protocol_environment/sigs/v7/dal.mli b/src/lib_protocol_environment/sigs/v7/dal.mli index 23d561e164ea..3435c92f28f7 100644 --- a/src/lib_protocol_environment/sigs/v7/dal.mli +++ b/src/lib_protocol_environment/sigs/v7/dal.mli @@ -26,14 +26,17 @@ (** A precomputed set of constants *) type t +(** Parameters to build a value of type [t] *) +type parameters = { + redundancy_factor : int; + segment_size : int; + slot_size : int; + number_of_shards : int; +} + (** [make] precomputes the set of values needed by cryptographic primitives defined in this module and store them in a value of type [t] *) -val make : - redundancy_factor:int -> - slot_size:int -> - segment_size:int -> - number_of_shards:int -> - (t, [> `Fail of string]) result +val make : parameters -> (t, [> `Fail of string]) result (** Commitment to a polynomial. *) type commitment diff --git a/src/proto_alpha/lib_dal/dal_plugin_registration.ml b/src/proto_alpha/lib_dal/dal_plugin_registration.ml index 60fbca2b1cc8..17490442a541 100644 --- a/src/proto_alpha/lib_dal/dal_plugin_registration.ml +++ b/src/proto_alpha/lib_dal/dal_plugin_registration.ml @@ -26,13 +26,6 @@ module Plugin = struct module Proto = Registerer.Registered - type constants = { - redundancy_factor : int; - segment_size : int; - slot_size : int; - number_of_shards : int; - } - let get_constants chain block ctxt = let cpctxt = new Protocol_client_context.wrap_full ctxt in let open Lwt_result_syntax in @@ -41,7 +34,9 @@ module Plugin = struct {redundancy_factor; segment_size; slot_size; number_of_shards; _} = constants.parametric.dal in - return {redundancy_factor; segment_size; slot_size; number_of_shards} + return + Environment.Dal. + {redundancy_factor; segment_size; slot_size; number_of_shards} end let () = Dal_constants_plugin.register (module Plugin) diff --git a/tezt/lib_tezos/rollup.ml b/tezt/lib_tezos/rollup.ml index 580a877fbccc..864011b84988 100644 --- a/tezt/lib_tezos/rollup.ml +++ b/tezt/lib_tezos/rollup.ml @@ -543,10 +543,7 @@ module Dal = struct Cryptobox.Internal_for_tests.load_parameters initialisation_parameters ; match Cryptobox.make - ~redundancy_factor - ~slot_size - ~segment_size - ~number_of_shards + {redundancy_factor; slot_size; segment_size; number_of_shards} with | Ok cryptobox -> cryptobox | Error (`Fail msg) -> on_error msg -- GitLab From 2e952802d8a034fe0d7d5b8a00b4c804a53a4390 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20El=20Siba=C3=AFe?= Date: Thu, 11 Aug 2022 10:27:48 +0200 Subject: [PATCH 3/7] DAL/Node: improve interface for Layer1 and cleanup Daemon --- src/bin_dal_node/daemon.ml | 76 ++++++++++++++++++-------------- src/bin_dal_node/event.ml | 6 +++ src/bin_dal_node/layer1.ml | 22 +++------ src/bin_dal_node/layer1.mli | 35 +++++++++++++++ src/bin_dal_node/slot_manager.ml | 2 +- 5 files changed, 92 insertions(+), 49 deletions(-) create mode 100644 src/bin_dal_node/layer1.mli diff --git a/src/bin_dal_node/daemon.ml b/src/bin_dal_node/daemon.ml index d7b22f4b23f9..4f71b5fd4498 100644 --- a/src/bin_dal_node/daemon.ml +++ b/src/bin_dal_node/daemon.ml @@ -23,8 +23,6 @@ (* *) (*****************************************************************************) -let daemonize cctxt handle = Lwt.no_cancel @@ Layer1.iter_events cctxt handle - let resolve_plugin cctxt = let open Lwt_result_syntax in let* protocols = @@ -60,20 +58,33 @@ let init_cryptobox unsafe_srs cctxt (module Plugin : Dal_constants_plugin.T) = let* initialisation_parameters = if unsafe_srs then return - @@ Internal_for_tests.initialisation_parameters_from_slot_size + @@ Cryptobox.Internal_for_tests.initialisation_parameters_from_slot_size ~slot_size:parameters.slot_size else let*? g1_path, g2_path = Tezos_base.Dal_srs.find_trusted_setup_files () in - initialisation_parameters_from_files ~g1_path ~g2_path + Cryptobox.initialisation_parameters_from_files ~g1_path ~g2_path in - let*? () = load_parameters initialisation_parameters in + let*? () = Cryptobox.load_parameters initialisation_parameters in let* dal_constants = - match make parameters with + match Cryptobox.make parameters with | Ok cryptobox -> return cryptobox | Error (`Fail msg) -> fail [Cryptobox_initialisation_failed msg] in return @@ (dal_constants, parameters) +let daemonize cctxt handle = + let open Lwt_result_syntax in + let* t, stopper = Layer1.on_new_head cctxt handle in + let (_ : Lwt_exit.clean_up_callback_id) = + Lwt_exit.register_clean_up_callback ~loc:__LOC__ (fun _exit_status -> + stopper () ; + Lwt.return_unit) + in + (* The no_cancel might not be necessary. Lwt_exit cancels the + main promise upon receiving a signal or other form of interruption. The + no_cancel renders this cancelation into a no-op.*) + Lwt.no_cancel t + let run ~data_dir cctxt = let open Lwt_result_syntax in let*! () = Event.(emit starting_node) () in @@ -82,29 +93,30 @@ let run ~data_dir cctxt = let*! store = Store.init config in let ready = ref false in let*! () = Event.(emit layer1_node_tracking_started ()) in - daemonize cctxt @@ fun (_hash, (_block_header : Tezos_base.Block_header.t)) -> - 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 - (Format.asprintf "%a" Protocol_hash.pp_short Plugin.Proto.hash)) - in - let* dal_constants, dal_parameters = - init_cryptobox config.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 return_unit + daemonize cctxt (fun (_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.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) diff --git a/src/bin_dal_node/event.ml b/src/bin_dal_node/event.ml index d3b99aa2f036..e1301dd9e0c8 100644 --- a/src/bin_dal_node/event.ml +++ b/src/bin_dal_node/event.ml @@ -120,3 +120,9 @@ let protocol_plugin_resolved = ~msg:"Resolved plugin on protocol {proto_hash}" ~level:Notice ("proto_hash", Data_encoding.string) + +let proto_short_hash_string hash = + Format.asprintf "%a" Protocol_hash.pp_short hash + +let emit_protocol_plugin_resolved hash = + emit protocol_plugin_resolved (proto_short_hash_string hash) diff --git a/src/bin_dal_node/layer1.ml b/src/bin_dal_node/layer1.ml index 1362f41c6a8a..a269c7fc2286 100644 --- a/src/bin_dal_node/layer1.ml +++ b/src/bin_dal_node/layer1.ml @@ -23,24 +23,14 @@ (* *) (*****************************************************************************) -(** FIXME: https://gitlab.com/tezos/tezos/-/issues/3517 - +(* FIXME: https://gitlab.com/tezos/tezos/-/issues/3517 If the layer1 node reboots, the rpc stream breaks. *) -let chain_events cctxt = - let open Lwt_result_syntax in - let* heads, _ = Tezos_shell_services.Monitor_services.heads cctxt `Main in - return heads - -let handle_event (hash, (block_header : Tezos_base.Block_header.t)) = +let on_new_head cctxt handle = let open Lwt_result_syntax in - let level = block_header.shell.level in - let*! () = Event.(emit layer1_node_new_head (hash, level)) in - return_true - -let iter_events cctxt handle = - let open Lwt_result_syntax in - let* stream = chain_events cctxt in + let* stream, stopper = + Tezos_shell_services.Monitor_services.heads cctxt `Main + in let rec go () = Lwt.bind (Lwt_stream.get stream) @@ fun tok -> match tok with @@ -49,4 +39,4 @@ let iter_events cctxt handle = let* () = handle element in go () in - go () + return (go (), stopper) diff --git a/src/bin_dal_node/layer1.mli b/src/bin_dal_node/layer1.mli new file mode 100644 index 000000000000..fec865062cf5 --- /dev/null +++ b/src/bin_dal_node/layer1.mli @@ -0,0 +1,35 @@ +(*****************************************************************************) +(* *) +(* 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. *) +(* *) +(*****************************************************************************) + +(** [on_new_head cctxt handler] opens a [Monitor_services.heads] stream on the + targeted layer 1 node and calls [handler] each time a new head is received. + + It returns a couple [(p, stopper)] where [p] is a promise resolving when the + stream closes and [stopper] a function closing the stream. +*) +val on_new_head : + #RPC_context.streamed -> + (Block_hash.t * Block_header.t -> unit tzresult Lwt.t) -> + (unit tzresult Lwt.t * (unit -> unit)) tzresult Lwt.t diff --git a/src/bin_dal_node/slot_manager.ml b/src/bin_dal_node/slot_manager.ml index 1525f62ac561..2dc15a4b6774 100644 --- a/src/bin_dal_node/slot_manager.ml +++ b/src/bin_dal_node/slot_manager.ml @@ -195,7 +195,7 @@ let get_slot initial_constants dal_constants store slot_header = in return slot -(* FIXME https://gitlab.com/tezos/tezos/-/issues/3405 +(* FIXME: https://gitlab.com/tezos/tezos/-/issues/3405 This can work only if a slot never ends with a `\000`. But I am not sure in general such thing is required. *) -- GitLab From d72b1adf388ebff0f2354638a39456bf49a606ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20El=20Siba=C3=AFe?= Date: Fri, 19 Aug 2022 11:41:49 +0200 Subject: [PATCH 4/7] Dal/Crypto: rename Dal_cryptobox -> Cryptobox --- src/bin_dal_node/RPC_server.ml | 4 +- src/bin_dal_node/daemon.ml | 3 +- src/bin_dal_node/node_context.ml | 4 +- src/bin_dal_node/node_context.mli | 6 +-- src/bin_dal_node/slot_manager.ml | 38 ++++++++--------- src/bin_dal_node/slot_manager.mli | 16 +++---- src/bin_node/node_config_file.ml | 2 +- src/lib_base/dal_srs.mli | 2 +- .../{dal_cryptobox.ml => cryptobox.ml} | 2 +- .../{dal_cryptobox.mli => cryptobox.mli} | 4 +- ...al_cryptobox_intf.ml => cryptobox_intf.ml} | 0 src/lib_crypto_dal/test/test_dal_cryptobox.ml | 42 +++++++++---------- src/lib_dal_node/dal_constants_plugin.ml | 2 +- src/lib_dal_node/dal_constants_plugin.mli | 2 +- src/lib_dal_node_services/services.ml | 8 ++-- .../environment_V7.ml | 5 +-- .../environment_V7.mli | 3 +- tezt/lib_tezos/operation_core.ml | 4 +- tezt/lib_tezos/operation_core.mli | 2 +- tezt/lib_tezos/rollup.ml | 2 +- tezt/lib_tezos/rollup.mli | 2 +- 21 files changed, 68 insertions(+), 85 deletions(-) rename src/lib_crypto_dal/{dal_cryptobox.ml => cryptobox.ml} (99%) rename src/lib_crypto_dal/{dal_cryptobox.mli => cryptobox.mli} (99%) rename src/lib_crypto_dal/{dal_cryptobox_intf.ml => cryptobox_intf.ml} (100%) diff --git a/src/bin_dal_node/RPC_server.ml b/src/bin_dal_node/RPC_server.ml index 5384ce57c19f..b7a390f5c96a 100644 --- a/src/bin_dal_node/RPC_server.ml +++ b/src/bin_dal_node/RPC_server.ml @@ -34,11 +34,11 @@ let handle_split_slot dal_parameters dal_constants store fill slot = let slot = String.to_bytes slot in let slot = if fill then - Slot_manager.Utils.fill_x00 dal_parameters.Dal_cryptobox.slot_size slot + Slot_manager.Utils.fill_x00 dal_parameters.Cryptobox.slot_size slot else slot in let+ commitment = Slot_manager.split_and_store dal_constants store slot in - Dal_cryptobox.Commitment.to_b58check commitment + Cryptobox.Commitment.to_b58check commitment let handle_slot initial_constants dal_constants store (_, commitment) trim () = let open Lwt_result_syntax in diff --git a/src/bin_dal_node/daemon.ml b/src/bin_dal_node/daemon.ml index 4f71b5fd4498..8daa3d08081f 100644 --- a/src/bin_dal_node/daemon.ml +++ b/src/bin_dal_node/daemon.ml @@ -33,8 +33,6 @@ let resolve_plugin cctxt = (Dal_constants_plugin.get protocols.current_protocol) (Dal_constants_plugin.get protocols.next_protocol) -open Dal_cryptobox - type error += Cryptobox_initialisation_failed of string let () = @@ -53,6 +51,7 @@ let () = (fun str -> Cryptobox_initialisation_failed str) let init_cryptobox unsafe_srs cctxt (module Plugin : Dal_constants_plugin.T) = + let open Cryptobox in let open Lwt_result_syntax in let* parameters = Plugin.get_constants cctxt#chain cctxt#block cctxt in let* initialisation_parameters = diff --git a/src/bin_dal_node/node_context.ml b/src/bin_dal_node/node_context.ml index fd12459d99db..9c592a633a80 100644 --- a/src/bin_dal_node/node_context.ml +++ b/src/bin_dal_node/node_context.ml @@ -25,8 +25,8 @@ type t = { config : Configuration.t; - dal_constants : Dal_cryptobox.t; - dal_parameters : Dal_cryptobox.parameters; + dal_constants : Cryptobox.t; + dal_parameters : Cryptobox.parameters; } let make config dal_constants dal_parameters = diff --git a/src/bin_dal_node/node_context.mli b/src/bin_dal_node/node_context.mli index 3dd9388ee138..3afb13c23926 100644 --- a/src/bin_dal_node/node_context.mli +++ b/src/bin_dal_node/node_context.mli @@ -25,8 +25,8 @@ type t = { config : Configuration.t; - dal_constants : Dal_cryptobox.t; - dal_parameters : Dal_cryptobox.parameters; + dal_constants : Cryptobox.t; + dal_parameters : Cryptobox.parameters; } -val make : Configuration.t -> Dal_cryptobox.t -> Dal_cryptobox.parameters -> t +val make : Configuration.t -> Cryptobox.t -> Cryptobox.parameters -> t diff --git a/src/bin_dal_node/slot_manager.ml b/src/bin_dal_node/slot_manager.ml index 2dc15a4b6774..b05757ae53aa 100644 --- a/src/bin_dal_node/slot_manager.ml +++ b/src/bin_dal_node/slot_manager.ml @@ -99,17 +99,17 @@ let encode enc v = Data_encoding.Binary.to_string enc v |> wrap_encoding_error let share_path slot_header shard_id = [slot_header; string_of_int shard_id] let decode_share s = - Data_encoding.Binary.of_string Dal_cryptobox.share_encoding s + Data_encoding.Binary.of_string Cryptobox.share_encoding s |> Result.map_error (fun e -> [Tezos_base.Data_encoding_wrapper.Decoding_error e]) let save store slot_header shards = let open Lwt_result_syntax in - let slot_header = Dal_cryptobox.Commitment.to_b58check slot_header in - Dal_cryptobox.IntMap.iter_es + let slot_header = Cryptobox.Commitment.to_b58check slot_header in + Cryptobox.IntMap.iter_es (fun i share -> let path = share_path slot_header i in - let*? share = encode Dal_cryptobox.share_encoding share in + let*? share = encode Cryptobox.share_encoding share in let*! metadata = Store.set ~msg:"Share stored" store path share in return metadata) shards @@ -117,29 +117,25 @@ let save store slot_header shards = let split_and_store cb_constants store slot = let r = let open Result_syntax in - let* polynomial = Dal_cryptobox.polynomial_from_slot cb_constants slot in - let commitment = Dal_cryptobox.commit cb_constants polynomial in + let* polynomial = Cryptobox.polynomial_from_slot cb_constants slot in + let commitment = Cryptobox.commit cb_constants polynomial in return (polynomial, commitment) in let open Lwt_result_syntax in match r with | Ok (polynomial, commitment) -> - let shards = - Dal_cryptobox.shards_from_polynomial cb_constants polynomial - in + let shards = Cryptobox.shards_from_polynomial cb_constants polynomial in let* () = save store commitment shards in let*! () = Event.( - emit - stored_slot - (Bytes.length slot, Dal_cryptobox.IntMap.cardinal shards)) + emit stored_slot (Bytes.length slot, Cryptobox.IntMap.cardinal shards)) in Lwt.return_ok commitment | Error (`Slot_wrong_size msg) -> Lwt.return_error [Splitting_failed msg] let get_shard store slot_header shard_id = let open Lwt_result_syntax in - let*? slot_header = encode Dal_cryptobox.Commitment.encoding slot_header in + let*? slot_header = encode Cryptobox.Commitment.encoding slot_header in let* share = Lwt.catch (fun () -> @@ -149,20 +145,20 @@ let get_shard store slot_header shard_id = | Invalid_argument _ -> fail [Slot_not_found] | e -> fail [Exn e]) in let*? share = decode_share share in - return Dal_cryptobox.{index = shard_id; share} + return Cryptobox.{index = shard_id; share} let check_shards initial_constants shards = let open Result_syntax in if shards = [] then fail [Slot_not_found] else if Compare.List_length_with.( - shards = initial_constants.Dal_cryptobox.number_of_shards) + shards = initial_constants.Cryptobox.number_of_shards) then Ok () else fail [Missing_shards] let get_slot initial_constants dal_constants store slot_header = let open Lwt_result_syntax in - let slot_header = Dal_cryptobox.Commitment.to_b58check slot_header in + let slot_header = Cryptobox.Commitment.to_b58check slot_header in let*! shards = Store.list store [slot_header] in let*? () = check_shards initial_constants shards in let* shards = @@ -178,20 +174,20 @@ let get_slot initial_constants dal_constants store slot_header = return share in let*? share = decode_share share in - return (Dal_cryptobox.IntMap.add i share shards)) - Dal_cryptobox.IntMap.empty + return (Cryptobox.IntMap.add i share shards)) + Cryptobox.IntMap.empty shards in let*? polynomial = - match Dal_cryptobox.polynomial_from_shards dal_constants shards with + match Cryptobox.polynomial_from_shards dal_constants shards with | Ok p -> Ok p | Error (`Invert_zero msg | `Not_enough_shards msg) -> Error [Merging_failed msg] in - let slot = Dal_cryptobox.polynomial_to_bytes dal_constants polynomial in + let slot = Cryptobox.polynomial_to_bytes dal_constants polynomial in let*! () = Event.( - emit fetched_slot (Bytes.length slot, Dal_cryptobox.IntMap.cardinal shards)) + emit fetched_slot (Bytes.length slot, Cryptobox.IntMap.cardinal shards)) in return slot diff --git a/src/bin_dal_node/slot_manager.mli b/src/bin_dal_node/slot_manager.mli index 214beaf99270..e4e6bd1d3c9e 100644 --- a/src/bin_dal_node/slot_manager.mli +++ b/src/bin_dal_node/slot_manager.mli @@ -36,27 +36,21 @@ type slot = bytes it onto the disk and returns the corresponding [slot_header], using [dal_constants] and trusted setup [ts] *) val split_and_store : - Dal_cryptobox.t -> - Store.t -> - slot -> - Dal_cryptobox.Commitment.t tzresult Lwt.t + Cryptobox.t -> Store.t -> slot -> Cryptobox.Commitment.t tzresult Lwt.t (** [get_shard store slot_header shard_id] gets the shard associated to [slot_header] at the range [shard_id] *) val get_shard : - Store.t -> - Dal_cryptobox.commitment -> - int -> - Dal_cryptobox.shard tzresult Lwt.t + Store.t -> Cryptobox.commitment -> int -> Cryptobox.shard tzresult Lwt.t (** [get_slot dal_parameters dal_constants store slot_header] fetches from disk the shards associated to [slot_header], gathers them, rebuilds and returns the [slot]. *) val get_slot : - Dal_cryptobox.parameters -> - Dal_cryptobox.t -> + Cryptobox.parameters -> + Cryptobox.t -> Store.t -> - Dal_cryptobox.commitment -> + Cryptobox.commitment -> slot tzresult Lwt.t module Utils : sig diff --git a/src/bin_node/node_config_file.ml b/src/bin_node/node_config_file.ml index 2b6231a3fb57..c7d77d8a0848 100644 --- a/src/bin_node/node_config_file.ml +++ b/src/bin_node/node_config_file.ml @@ -1649,7 +1649,7 @@ let bootstrap_peers config = let init_dal dal_config = let open Lwt_result_syntax in if dal_config.activated then - let open Tezos_crypto_dal.Dal_cryptobox in + let open Tezos_crypto_dal.Cryptobox in let* initialisation_parameters = match dal_config.srs_size with | None -> diff --git a/src/lib_base/dal_srs.mli b/src/lib_base/dal_srs.mli index 4942d10e074c..ef9f37c14e44 100644 --- a/src/lib_base/dal_srs.mli +++ b/src/lib_base/dal_srs.mli @@ -25,7 +25,7 @@ (** [find_trusted_setup_files] returns the path of the two files necessary to initialize cryptographic primitives used by the - DAL. See {!module:Tezos-crypto_dal.Dal_cryptobox}. *) + DAL. See {!module:Tezos-crypto_dal.Cryptobox}. *) val find_trusted_setup_files : ?getenv_opt:(string -> string option) -> ?getcwd:(unit -> string) -> diff --git a/src/lib_crypto_dal/dal_cryptobox.ml b/src/lib_crypto_dal/cryptobox.ml similarity index 99% rename from src/lib_crypto_dal/dal_cryptobox.ml rename to src/lib_crypto_dal/cryptobox.ml index 2f042718b1c7..352393adbc27 100644 --- a/src/lib_crypto_dal/dal_cryptobox.ml +++ b/src/lib_crypto_dal/cryptobox.ml @@ -24,7 +24,7 @@ (*****************************************************************************) open Error_monad -include Dal_cryptobox_intf +include Cryptobox_intf module Base58 = Tezos_crypto.Base58 module Srs_g1 = Bls12_381_polynomial.Polynomial.Srs_g1 module Srs_g2 = Bls12_381_polynomial.Polynomial.Srs_g2 diff --git a/src/lib_crypto_dal/dal_cryptobox.mli b/src/lib_crypto_dal/cryptobox.mli similarity index 99% rename from src/lib_crypto_dal/dal_cryptobox.mli rename to src/lib_crypto_dal/cryptobox.mli index a3c7909a0610..90fdcb513fa5 100644 --- a/src/lib_crypto_dal/dal_cryptobox.mli +++ b/src/lib_crypto_dal/cryptobox.mli @@ -23,7 +23,7 @@ (* *) (*****************************************************************************) -open Dal_cryptobox_intf +open Cryptobox_intf (** Initial values to parametrize dal cryptographic primitives. It used to build a value of type [t] *) @@ -84,7 +84,7 @@ val initialisation_parameters_from_files : val load_parameters : initialisation_parameters -> unit Error_monad.tzresult module Commitment : sig - include Dal_cryptobox_intf.COMMITMENT with type t = commitment + include COMMITMENT with type t = commitment val rpc_arg : commitment Resto.Arg.t end diff --git a/src/lib_crypto_dal/dal_cryptobox_intf.ml b/src/lib_crypto_dal/cryptobox_intf.ml similarity index 100% rename from src/lib_crypto_dal/dal_cryptobox_intf.ml rename to src/lib_crypto_dal/cryptobox_intf.ml diff --git a/src/lib_crypto_dal/test/test_dal_cryptobox.ml b/src/lib_crypto_dal/test/test_dal_cryptobox.ml index 03ab539a49a2..eb77c32ffe51 100644 --- a/src/lib_crypto_dal/test/test_dal_cryptobox.ml +++ b/src/lib_crypto_dal/test/test_dal_cryptobox.ml @@ -35,26 +35,26 @@ module Test = struct Bytes.set_int64_le msg (i * 8) (Random.int64 Int64.max_int) done ; let parameters = - Dal_cryptobox.Internal_for_tests.initialisation_parameters_from_slot_size + Cryptobox.Internal_for_tests.initialisation_parameters_from_slot_size ~slot_size in - let () = Dal_cryptobox.Internal_for_tests.load_parameters parameters in + let () = Cryptobox.Internal_for_tests.load_parameters parameters in Tezos_lwt_result_stdlib.Lwtreslib.Bare.List.iter_e (fun redundancy_factor -> let* t = - Dal_cryptobox.make + Cryptobox.make {redundancy_factor; slot_size; segment_size; number_of_shards} in - let* p = Dal_cryptobox.polynomial_from_slot t msg in - let cm = Dal_cryptobox.commit t p in - let* pi = Dal_cryptobox.prove_segment t p 1 in + let* p = Cryptobox.polynomial_from_slot t msg in + let cm = Cryptobox.commit t p in + let* pi = Cryptobox.prove_segment t p 1 in let segment = Bytes.sub msg segment_size segment_size in let* check = - Dal_cryptobox.verify_segment t cm {index = 1; content = segment} pi + Cryptobox.verify_segment t cm {index = 1; content = segment} pi in assert check ; - let enc_shards = Dal_cryptobox.shards_from_polynomial t p in + let enc_shards = Cryptobox.shards_from_polynomial t p in let c_indices = random_indices (number_of_shards - 1) @@ -62,45 +62,43 @@ module Test = struct |> Array.of_list in let c = - Dal_cryptobox.IntMap.filter - (fun i _ -> Array.mem i c_indices) - enc_shards + Cryptobox.IntMap.filter (fun i _ -> Array.mem i c_indices) enc_shards in - let* dec = Dal_cryptobox.polynomial_from_shards t c in + let* dec = Cryptobox.polynomial_from_shards t c in assert ( Bytes.compare msg (Bytes.sub - (Dal_cryptobox.polynomial_to_bytes t dec) + (Cryptobox.polynomial_to_bytes t dec) 0 (min slot_size msg_size)) = 0) ; - let comm = Dal_cryptobox.commit t p in - let shard_proofs = Dal_cryptobox.prove_shards t p in - match Dal_cryptobox.IntMap.find 0 enc_shards with + let comm = Cryptobox.commit t p in + let shard_proofs = Cryptobox.prove_shards t p in + match Cryptobox.IntMap.find 0 enc_shards with | None -> Ok () | Some eval -> let check = - Dal_cryptobox.verify_shard + Cryptobox.verify_shard t comm {index = 0; share = eval} shard_proofs.(0) in assert check ; - let pi = Dal_cryptobox.prove_commitment t p in - let check = Dal_cryptobox.verify_commitment t comm pi in + let pi = Cryptobox.prove_commitment t p in + let check = Cryptobox.verify_commitment t comm pi in assert check ; Ok () (* let point = Scalar.random () in *) - (* let+ pi_slot = Dal_cryptobox.prove_single trusted_setup p point in + (* let+ pi_slot = Cryptobox.prove_single trusted_setup p point in * * assert ( - * Dal_cryptobox.verify_single + * Cryptobox.verify_single * trusted_setup * comm * ~point - * ~evaluation:(Dal_cryptobox.polynomial_evaluate p point) + * ~evaluation:(Cryptobox.polynomial_evaluate p point) * pi_slot) *)) [2] |> fun x -> match x with Ok () -> () | Error _ -> assert false diff --git a/src/lib_dal_node/dal_constants_plugin.ml b/src/lib_dal_node/dal_constants_plugin.ml index ad8831e566eb..c607bc7ecbef 100644 --- a/src/lib_dal_node/dal_constants_plugin.ml +++ b/src/lib_dal_node/dal_constants_plugin.ml @@ -30,7 +30,7 @@ module type T = sig Tezos_shell_services.Chain_services.chain -> Tezos_shell_services.Block_services.block -> Client_context.full -> - Tezos_crypto_dal.Dal_cryptobox.Verifier.parameters tzresult Lwt.t + Tezos_crypto_dal.Cryptobox.Verifier.parameters 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 cbb756286ecd..38c2fb4ce10d 100644 --- a/src/lib_dal_node/dal_constants_plugin.mli +++ b/src/lib_dal_node/dal_constants_plugin.mli @@ -30,7 +30,7 @@ module type T = sig Tezos_shell_services.Chain_services.chain -> Tezos_shell_services.Block_services.block -> Client_context.full -> - Tezos_crypto_dal.Dal_cryptobox.Verifier.parameters tzresult Lwt.t + Tezos_crypto_dal.Cryptobox.Verifier.parameters tzresult Lwt.t end val register : (module T) -> unit diff --git a/src/lib_dal_node_services/services.ml b/src/lib_dal_node_services/services.ml index 09c5ced7ef34..2ac54048f2d8 100644 --- a/src/lib_dal_node_services/services.ml +++ b/src/lib_dal_node_services/services.ml @@ -50,14 +50,12 @@ let slot () = ~description:"Show content of a slot" ~query:slot_query ~output:Data_encoding.string - RPC_path.( - open_root / "slot" / "content" /: Dal_cryptobox.Commitment.rpc_arg) + RPC_path.(open_root / "slot" / "content" /: Cryptobox.Commitment.rpc_arg) let shard () = let shard_arg = RPC_arg.int in RPC_service.get_service ~description:"Fetch shard as bytes" ~query:RPC_query.empty - ~output:Dal_cryptobox.shard_encoding - RPC_path.( - open_root / "shard" /: Dal_cryptobox.Commitment.rpc_arg /: shard_arg) + ~output:Cryptobox.shard_encoding + RPC_path.(open_root / "shard" /: Cryptobox.Commitment.rpc_arg /: shard_arg) diff --git a/src/lib_protocol_environment/environment_V7.ml b/src/lib_protocol_environment/environment_V7.ml index 1aba7d75589c..f3285c370d78 100644 --- a/src/lib_protocol_environment/environment_V7.ml +++ b/src/lib_protocol_environment/environment_V7.ml @@ -104,8 +104,7 @@ module type T = sig and type Plonk.public_parameters = Plonk.Main_protocol.verifier_public_parameters * Plonk.Main_protocol.transcript - and type Dal.parameters = - Tezos_crypto_dal.Dal_cryptobox.Verifier.parameters + and type Dal.parameters = Tezos_crypto_dal.Cryptobox.Verifier.parameters type error += Ecoproto_error of Error_monad.error @@ -1475,5 +1474,5 @@ struct module Equality_witness = Environment_context.Equality_witness module Plonk = Tezos_protocol_environment_structs.V7.Plonk - module Dal = Tezos_crypto_dal.Dal_cryptobox.Verifier + module Dal = Tezos_crypto_dal.Cryptobox.Verifier end diff --git a/src/lib_protocol_environment/environment_V7.mli b/src/lib_protocol_environment/environment_V7.mli index 1527b8f2f13e..c4d676636cbf 100644 --- a/src/lib_protocol_environment/environment_V7.mli +++ b/src/lib_protocol_environment/environment_V7.mli @@ -104,8 +104,7 @@ module type T = sig and type Plonk.public_parameters = Plonk.Main_protocol.verifier_public_parameters * Plonk.Main_protocol.transcript - and type Dal.parameters = - Tezos_crypto_dal.Dal_cryptobox.Verifier.parameters + and type Dal.parameters = Tezos_crypto_dal.Cryptobox.Verifier.parameters (** An [Ecoproto_error e] is a shell error that carry a protocol error. diff --git a/tezt/lib_tezos/operation_core.ml b/tezt/lib_tezos/operation_core.ml index 13a17cfa2f3a..1973da05194d 100644 --- a/tezt/lib_tezos/operation_core.ml +++ b/tezt/lib_tezos/operation_core.ml @@ -267,7 +267,7 @@ module Manager = struct let json_of_commitment commitment = Data_encoding.Json.construct - Tezos_crypto_dal.Dal_cryptobox.Commitment.encoding + Tezos_crypto_dal.Cryptobox.Commitment.encoding commitment let get_next_counter ?(source = Constant.bootstrap1) client = @@ -334,7 +334,7 @@ module Manager = struct | Dal_publish_slot_header of { level : int; index : int; - header : Tezos_crypto_dal.Dal_cryptobox.commitment; + header : Tezos_crypto_dal.Cryptobox.commitment; } | Sc_rollup_dal_slot_subscribe of {rollup : string; slot_index : int} | Delegation of {delegate : Account.key} diff --git a/tezt/lib_tezos/operation_core.mli b/tezt/lib_tezos/operation_core.mli index 3db2246e0e84..2e10e8fb9eab 100644 --- a/tezt/lib_tezos/operation_core.mli +++ b/tezt/lib_tezos/operation_core.mli @@ -270,7 +270,7 @@ module Manager : sig val dal_publish_slot_header : level:int -> index:int -> - header:Tezos_crypto_dal.Dal_cryptobox.commitment -> + header:Tezos_crypto_dal.Cryptobox.commitment -> payload (** [sc_rollup_dal_slot_subscribe ~rollup ~slot_index] builds an diff --git a/tezt/lib_tezos/rollup.ml b/tezt/lib_tezos/rollup.ml index 864011b84988..75805b056e04 100644 --- a/tezt/lib_tezos/rollup.ml +++ b/tezt/lib_tezos/rollup.ml @@ -529,7 +529,7 @@ module Dal = struct return {number_of_shards; redundancy_factor; slot_size; segment_size} end - module Cryptobox = Tezos_crypto_dal.Dal_cryptobox + module Cryptobox = Tezos_crypto_dal.Cryptobox let make ?(on_error = diff --git a/tezt/lib_tezos/rollup.mli b/tezt/lib_tezos/rollup.mli index 9e67f42924dd..7ab9a02d9c4f 100644 --- a/tezt/lib_tezos/rollup.mli +++ b/tezt/lib_tezos/rollup.mli @@ -228,7 +228,7 @@ module Dal : sig val from_client : Client.t -> t Lwt.t end - module Cryptobox = Tezos_crypto_dal.Dal_cryptobox + module Cryptobox = Tezos_crypto_dal.Cryptobox val make : ?on_error:(string -> Cryptobox.t) -> Parameters.t -> Cryptobox.t -- GitLab From 07a6f9880f6a058b2f4a44b534416b201b8c2490 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20El=20Siba=C3=AFe?= Date: Mon, 22 Aug 2022 10:05:36 +0200 Subject: [PATCH 5/7] Dal/Node: name head_handler callback --- src/bin_dal_node/daemon.ml | 65 +++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 33 deletions(-) diff --git a/src/bin_dal_node/daemon.ml b/src/bin_dal_node/daemon.ml index 8daa3d08081f..c41ed3948cc9 100644 --- a/src/bin_dal_node/daemon.ml +++ b/src/bin_dal_node/daemon.ml @@ -64,17 +64,15 @@ let init_cryptobox unsafe_srs cctxt (module Plugin : Dal_constants_plugin.T) = Cryptobox.initialisation_parameters_from_files ~g1_path ~g2_path in let*? () = Cryptobox.load_parameters initialisation_parameters in - let* dal_constants = - match Cryptobox.make parameters with - | Ok cryptobox -> return cryptobox - | Error (`Fail msg) -> fail [Cryptobox_initialisation_failed msg] - in - return @@ (dal_constants, parameters) + match Cryptobox.make parameters with + | Ok cryptobox -> return (cryptobox, parameters) + | Error (`Fail msg) -> fail [Cryptobox_initialisation_failed msg] let daemonize cctxt handle = let open Lwt_result_syntax in let* t, stopper = Layer1.on_new_head cctxt handle in let (_ : Lwt_exit.clean_up_callback_id) = + (* close the stream when an exit signal is received *) Lwt_exit.register_clean_up_callback ~loc:__LOC__ (fun _exit_status -> stopper () ; Lwt.return_unit) @@ -92,30 +90,31 @@ let run ~data_dir cctxt = let*! store = Store.init config in let ready = ref false in let*! () = Event.(emit layer1_node_tracking_started ()) in - daemonize cctxt (fun (_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.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) + let new_head_handler (_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.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 + in + daemonize cctxt new_head_handler -- GitLab From 8473f3a5ac9f38d70b941121fbefb8507f6714e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20El=20Siba=C3=AFe?= Date: Mon, 22 Aug 2022 10:15:50 +0200 Subject: [PATCH 6/7] Dal/Node: rename unsafe_srs -> use_unsafe_srs --- src/bin_dal_node/configuration.ml | 16 ++++++++-------- src/bin_dal_node/configuration.mli | 2 +- src/bin_dal_node/daemon.ml | 2 +- src/bin_dal_node/main_dal.ml | 10 +++++----- tezt/lib_tezos/dal_node.ml | 8 ++++---- tezt/lib_tezos/dal_node.mli | 4 ++-- 6 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/bin_dal_node/configuration.ml b/src/bin_dal_node/configuration.ml index b1fd73750edb..e08bb5a9cc5b 100644 --- a/src/bin_dal_node/configuration.ml +++ b/src/bin_dal_node/configuration.ml @@ -24,7 +24,7 @@ (*****************************************************************************) type t = { - unsafe_srs : bool; + use_unsafe_srs : bool; data_dir : string; rpc_addr : string; rpc_port : int; @@ -42,21 +42,21 @@ let default_rpc_addr = "127.0.0.1" let default_rpc_port = 10732 -let default_unsafe_srs = false +let default_use_unsafe_srs = false let encoding : t Data_encoding.t = let open Data_encoding in conv - (fun {unsafe_srs; data_dir; rpc_addr; rpc_port} -> - (unsafe_srs, data_dir, rpc_addr, rpc_port)) - (fun (unsafe_srs, data_dir, rpc_addr, rpc_port) -> - {unsafe_srs; data_dir; rpc_addr; rpc_port}) + (fun {use_unsafe_srs; data_dir; rpc_addr; rpc_port} -> + (use_unsafe_srs, data_dir, rpc_addr, rpc_port)) + (fun (use_unsafe_srs, data_dir, rpc_addr, rpc_port) -> + {use_unsafe_srs; data_dir; rpc_addr; rpc_port}) (obj4 (dft - "unsafe_srs" + "use_unsafe_srs" ~description:"use unsafe srs for tests" bool - default_unsafe_srs) + default_use_unsafe_srs) (dft "data-dir" ~description:"Location of the data dir" diff --git a/src/bin_dal_node/configuration.mli b/src/bin_dal_node/configuration.mli index 5c1bb2bf9704..fcfcb7c054c2 100644 --- a/src/bin_dal_node/configuration.mli +++ b/src/bin_dal_node/configuration.mli @@ -24,7 +24,7 @@ (*****************************************************************************) type t = { - unsafe_srs : bool; + use_unsafe_srs : bool; (** Run dal-node in test mode with an unsafe SRS (Trusted setup) *) data_dir : string; (** The path to the DAL node data directory *) rpc_addr : string; (** The address the DAL node listens to *) diff --git a/src/bin_dal_node/daemon.ml b/src/bin_dal_node/daemon.ml index c41ed3948cc9..4df175fc547f 100644 --- a/src/bin_dal_node/daemon.ml +++ b/src/bin_dal_node/daemon.ml @@ -100,7 +100,7 @@ let run ~data_dir cctxt = 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.unsafe_srs cctxt plugin + 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 diff --git a/src/bin_dal_node/main_dal.ml b/src/bin_dal_node/main_dal.ml index c8f231498abc..fe93429fb1be 100644 --- a/src/bin_dal_node/main_dal.ml +++ b/src/bin_dal_node/main_dal.ml @@ -66,9 +66,9 @@ let rpc_port_arg = ~default int_parameter -let unsafe_srs_for_tests_arg = +let use_unsafe_srs_for_tests_arg = Clic.switch - ~long:"unsafe-srs-for-tests" + ~long:"use-unsafe-srs-for-tests" ~doc: (Format.sprintf "Run dal-node in test mode with an unsafe SRS (Trusted setup)") @@ -80,11 +80,11 @@ let config_init_command = command ~group ~desc:"Configure DAL node." - (args4 data_dir_arg rpc_addr_arg rpc_port_arg unsafe_srs_for_tests_arg) + (args4 data_dir_arg rpc_addr_arg rpc_port_arg use_unsafe_srs_for_tests_arg) (prefixes ["init-config"] stop) - (fun (data_dir, rpc_addr, rpc_port, unsafe_srs) cctxt -> + (fun (data_dir, rpc_addr, rpc_port, use_unsafe_srs) cctxt -> let open Configuration in - let config = {data_dir; rpc_addr; rpc_port; unsafe_srs} in + let config = {data_dir; rpc_addr; rpc_port; use_unsafe_srs} in let* () = save config in let*! _ = cctxt#message "DAL node configuration written in %s" (filename config) diff --git a/tezt/lib_tezos/dal_node.ml b/tezt/lib_tezos/dal_node.ml index e035651aa8bf..373c8680bec3 100644 --- a/tezt/lib_tezos/dal_node.ml +++ b/tezt/lib_tezos/dal_node.ml @@ -73,7 +73,7 @@ let data_dir dal_node = dal_node.persistent_state.data_dir let spawn_command dal_node = Process.spawn ~name:dal_node.name ~color:dal_node.color dal_node.path -let spawn_config_init ?(unsafe_srs = true) dal_node = +let spawn_config_init ?(use_unsafe_srs = true) dal_node = spawn_command dal_node @@ List.filter_map Fun.id @@ -85,11 +85,11 @@ let spawn_config_init ?(unsafe_srs = true) dal_node = Some (string_of_int (rpc_port dal_node)); Some "--rpc-addr"; Some (rpc_host dal_node); - (if unsafe_srs then Some "--unsafe-srs-for-tests" else None); + (if use_unsafe_srs then Some "--use-unsafe-srs-for-tests" else None); ] -let init_config ?unsafe_srs dal_node = - let process = spawn_config_init ?unsafe_srs dal_node in +let init_config ?use_unsafe_srs dal_node = + let process = spawn_config_init ?use_unsafe_srs dal_node in let* output = Process.check_and_read_stdout process in match output =~* rex "DAL node configuration written in ([^\n]*)" with | None -> failwith "DAL node configuration initialization failed" diff --git a/tezt/lib_tezos/dal_node.mli b/tezt/lib_tezos/dal_node.mli index 55eaf6526dd2..aecde5dda198 100644 --- a/tezt/lib_tezos/dal_node.mli +++ b/tezt/lib_tezos/dal_node.mli @@ -85,11 +85,11 @@ val wait : t -> Unix.process_status Lwt.t (** Run [tezos-dal-node init-config]. Returns the name of the resulting configuration file. - If [unsafe_srs] is [true], the dal node runs with unsafe computed SRS + If [use_unsafe_srs] is [true], the dal node runs with unsafe computed SRS allowing tests to run faster, without the need of large file. Default is [true] in tezt. *) -val init_config : ?unsafe_srs:bool -> t -> string Lwt.t +val init_config : ?use_unsafe_srs:bool -> t -> string Lwt.t (** [split_slot_rpc dal_node data] spawns curl process on slot/split on [data] *) val split_slot_rpc : t -> string -> string Lwt.t -- GitLab From 43bbcb472b3fc627de137ca8e18cfe1a70731f55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20El=20Siba=C3=AFe?= Date: Mon, 22 Aug 2022 10:41:24 +0200 Subject: [PATCH 7/7] Dal/Node: add fixme for the next refactoring --- src/bin_dal_node/daemon.ml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/bin_dal_node/daemon.ml b/src/bin_dal_node/daemon.ml index 4df175fc547f..b1d42131a46c 100644 --- a/src/bin_dal_node/daemon.ml +++ b/src/bin_dal_node/daemon.ml @@ -82,6 +82,10 @@ let daemonize cctxt handle = no_cancel renders this cancelation into a no-op.*) Lwt.no_cancel t +(* FIXME: https://gitlab.com/tezos/tezos/-/issues/3605 + + Improve general architecture, handle L1 disconnection etc +*) let run ~data_dir cctxt = let open Lwt_result_syntax in let*! () = Event.(emit starting_node) () in -- GitLab