diff --git a/.gitlab/ci/opam-ci.yml b/.gitlab/ci/opam-ci.yml index f31ac02b6dcb36b919bae44253f2a39dacd1526f..8b212aed4efdf949c831ecfa13e2ce9a59f76ea3 100644 --- a/.gitlab/ci/opam-ci.yml +++ b/.gitlab/ci/opam-ci.yml @@ -7,6 +7,8 @@ # Ignoring package tezos-dal-node, it only contains tests or private targets +# Ignoring package tezos-dal-node-lib, it only contains tests or private targets + # Ignoring package tezos-protocol-012-Psithaca-tests, it only contains tests or private targets # Ignoring package tezos-protocol-013-PtJakart-tests, it only contains tests or private targets diff --git a/dune-project b/dune-project index e486fa460f750b3de942ac3c75e741c71253e60f..e5988cfd41cf0baec90363553167a2472a071c62 100644 --- a/dune-project +++ b/dune-project @@ -70,6 +70,7 @@ (package (name tezos-crypto-dal)) (package (name tezos-dal-alpha)) (package (name tezos-dal-node)) +(package (name tezos-dal-node-lib)(allow_empty)) (package (name tezos-embedded-protocol-000-Ps9mPmXa)) (package (name tezos-embedded-protocol-001-PtCJ7pwo)) (package (name tezos-embedded-protocol-002-PsYLVpVv)) diff --git a/manifest/main.ml b/manifest/main.ml index ab5d2254c5858262f247a953afa2b07c116b6026..7d7d41ba6f6ec3675baf9f6ea22fca547c9a88d2 100644 --- a/manifest/main.ml +++ b/manifest/main.ml @@ -3001,6 +3001,20 @@ let _octez_embedded_protocol_packer = ~linkall:true ~modules:["Main_embedded_packer"] +let octez_dal_node_lib = + private_lib + "tezos_dal_node_lib" + ~path:"src/lib_dal_node" + ~opam:"tezos-dal-node-lib" + ~synopsis:"Tezos: `tezos-dal-node` library" + ~deps: + [ + octez_base |> open_ ~m:"TzPervasives"; + octez_base_unix; + octez_client_base |> open_; + octez_protocol_updater |> open_; + ] + (* PROTOCOL PACKAGES *) module Protocol : sig @@ -3051,6 +3065,8 @@ module Protocol : sig val plugin_registerer : t -> target option + val dal : t -> target option + val parameters_exn : t -> target val benchmarks_proto_exn : t -> target @@ -3155,6 +3171,7 @@ end = struct baking_commands_registration : target option; plugin : target option; plugin_registerer : target option; + dal : target option; test_helpers : target option; parameters : target option; benchmarks_proto : target option; @@ -3162,8 +3179,9 @@ end = struct } let make ?client ?client_commands ?client_commands_registration - ?baking_commands_registration ?plugin ?plugin_registerer ?test_helpers - ?parameters ?benchmarks_proto ?baking ~status ~name ~main ~embedded () = + ?baking_commands_registration ?plugin ?plugin_registerer ?dal + ?test_helpers ?parameters ?benchmarks_proto ?baking ~status ~name ~main + ~embedded () = { status; name; @@ -3175,6 +3193,7 @@ end = struct baking_commands_registration; plugin; plugin_registerer; + dal; test_helpers; parameters; benchmarks_proto; @@ -3225,6 +3244,8 @@ end = struct let plugin_registerer p = p.plugin_registerer + let dal p = p.dal + let parameters_exn p = mandatory "parameters" p p.parameters let benchmarks_proto_exn p = mandatory "benchmarks_proto" p p.benchmarks_proto @@ -4508,6 +4529,10 @@ module Protocol = Protocol [ octez_base |> open_ ~m:"TzPervasives" |> open_ ~m:"TzPervasives.Error_monad.Legacy_monad_globals"; + octez_protocol_compiler_registerer |> open_; + octez_dal_node_lib |> open_; + client |> if_some |> open_; + embedded |> open_; main |> open_; ] ~inline_tests:ppx_expect @@ -4699,6 +4724,7 @@ module Protocol = Protocol ?baking_commands_registration ?plugin ?plugin_registerer + ?dal ?test_helpers ?parameters ?benchmarks_proto @@ -5371,29 +5397,53 @@ let _octez_tps_evaluation = ]; ] -let _tezos_dal_node = +let _octez_dal_node = + let protocol_deps = + let deps_for_protocol protocol = + let is_optional = + match (Protocol.status protocol, Protocol.number protocol) with + | _, V 000 -> + (* The node always needs to be linked with this protocol for Mainnet. *) + false + | Active, V _ -> + (* Active protocols cannot be optional because of a bug + that results in inconsistent hashes. Once this bug is fixed, + this exception can be removed. *) + false + | (Frozen | Overridden | Not_mainnet), _ | Active, (Alpha | Other) -> + (* Other protocols are optional. *) + true + in + let targets = List.filter_map Fun.id [Protocol.dal protocol] in + if is_optional then List.map optional targets else targets + in + List.map deps_for_protocol Protocol.all |> List.flatten + in public_exe "tezos-dal-node" ~path:"src/bin_dal_node" ~internal_name:"main_dal" ~synopsis:"Tezos: `tezos-dal-node` binary" ~deps: - [ - octez_base |> open_ ~m:"TzPervasives"; - octez_base_unix; - octez_client_base |> open_; - octez_client_base_unix |> open_; - octez_client_commands |> open_; - octez_rpc_http |> open_; - octez_rpc_http_server |> open_; - octez_rpc_http_client_unix |> open_; - octez_stdlib_unix |> open_; - octez_stdlib |> open_; - octez_crypto_dal; - irmin_pack; - irmin_pack_unix; - irmin; - ] + ([ + octez_base |> open_ ~m:"TzPervasives"; + octez_base_unix; + octez_client_base |> open_; + octez_client_base_unix |> open_; + octez_client_commands |> open_; + octez_rpc_http |> open_; + octez_rpc_http_server |> open_; + octez_protocol_updater |> open_; + octez_rpc_http_client_unix |> open_; + octez_stdlib_unix |> open_; + octez_stdlib |> open_; + octez_dal_node_lib |> open_; + octez_crypto_dal; + irmin_pack; + irmin_pack_unix; + irmin; + ] + @ protocol_deps) (* Add entries to this function to declare that some dune and .opam files are not generated by the manifest on purpose. diff --git a/opam/tezos-dal-alpha.opam b/opam/tezos-dal-alpha.opam index 86dc57b6addf5f14e7705fe70bca1d7914c9bffa..230e05c30100fc51f6af696d3840f799ebbec96c 100644 --- a/opam/tezos-dal-alpha.opam +++ b/opam/tezos-dal-alpha.opam @@ -11,6 +11,10 @@ depends: [ "dune" { >= "3.0" } "ppx_expect" "tezos-base" + "tezos-protocol-compiler" + "tezos-dal-node-lib" + "tezos-client-alpha" + "tezos-embedded-protocol-alpha" "tezos-protocol-alpha" "tezos-base-test-helpers" {with-test} "tezos-alpha-test-helpers" {with-test} diff --git a/opam/tezos-dal-node-lib.opam b/opam/tezos-dal-node-lib.opam new file mode 100644 index 0000000000000000000000000000000000000000..8aaf6967757c00d5b97ba181e72fdf40666ab421 --- /dev/null +++ b/opam/tezos-dal-node-lib.opam @@ -0,0 +1,21 @@ +# This file was automatically generated, do not edit. +# Edit file manifest/main.ml instead. +opam-version: "2.0" +maintainer: "contact@tezos.com" +authors: ["Tezos devteam"] +homepage: "https://www.tezos.com/" +bug-reports: "https://gitlab.com/tezos/tezos/issues" +dev-repo: "git+https://gitlab.com/tezos/tezos.git" +license: "MIT" +depends: [ + "dune" { >= "3.0" } + "tezos-base" + "tezos-client-base" + "tezos-protocol-updater" +] +build: [ + ["rm" "-r" "vendors"] + ["dune" "build" "-p" name "-j" jobs] + ["dune" "runtest" "-p" name "-j" jobs] {with-test} +] +synopsis: "Tezos: `tezos-dal-node` library" diff --git a/opam/tezos-dal-node.opam b/opam/tezos-dal-node.opam index a3d2f19795350de6c3d4b43fc3a031393f27fef4..3fbf8f22b3077d11d834f6609161bde769efe24a 100644 --- a/opam/tezos-dal-node.opam +++ b/opam/tezos-dal-node.opam @@ -15,13 +15,18 @@ depends: [ "tezos-client-commands" "tezos-rpc-http" "tezos-rpc-http-server" + "tezos-protocol-updater" "tezos-rpc-http-client-unix" "tezos-stdlib-unix" "tezos-stdlib" + "tezos-dal-node-lib" "tezos-crypto-dal" "irmin-pack" { >= "3.3.1" & < "3.4.0" } "irmin" { >= "3.3.2" & < "3.4.0" } ] +depopts: [ + "tezos-dal-alpha" +] build: [ ["rm" "-r" "vendors"] ["dune" "build" "-p" name "-j" jobs] diff --git a/src/bin_dal_node/cryptobox.ml b/src/bin_dal_node/cryptobox.ml index 2763c5eda8831958ca47b70ac08197e8aa55f3e5..fc2f7f668a5bf1fa37b65430026c55e212becbc3 100644 --- a/src/bin_dal_node/cryptobox.ml +++ b/src/bin_dal_node/cryptobox.ml @@ -23,19 +23,6 @@ (* *) (*****************************************************************************) open Tezos_crypto_dal - -module Constants = struct - let redundancy_factor = 2 - - let segment_size = 4096 - - let slot_size = 1048576 (* 1Mb *) - - let number_of_shards = 2048 - - let trusted_setup_logarithm_size = 21 -end - include Dal_cryptobox type slot = bytes @@ -44,6 +31,13 @@ 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 () = @@ -61,9 +55,19 @@ let () = (function Cryptobox_initialisation_failed str -> Some str | _ -> None) (fun str -> Cryptobox_initialisation_failed str) -let init () = - let open Constants in - let open Result_syntax in - match make ~redundancy_factor ~segment_size ~slot_size ~number_of_shards with - | Ok cryptobox -> return cryptobox - | Error (`Fail msg) -> fail [Cryptobox_initialisation_failed msg] +let init 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* 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 1671a9f25162219d43e3fcb2cecedfcc4e38407b..89322fcd4415b30835218aaa771f93ccb0a9742b 100644 --- a/src/bin_dal_node/daemon.ml +++ b/src/bin_dal_node/daemon.ml @@ -23,20 +23,24 @@ (* *) (*****************************************************************************) -type ctxt = {config : Configuration.t; dal_constants : Cryptobox.t} +type ctxt = { + config : Configuration.t; + dal_constants : Cryptobox.t; + dal_parameters : Cryptobox.parameters; +} module RPC_server = struct let register_split_slot ctxt store dir = RPC_directory.register0 dir (Services.split_slot ()) - (Services.handle_split_slot ctxt.dal_constants store) + (Services.handle_split_slot ctxt.dal_parameters ctxt.dal_constants store) let register_show_slot ctxt store dir = RPC_directory.register dir (Services.slot ()) - (Services.handle_slot ctxt.dal_constants store) + (Services.handle_slot ctxt.dal_parameters ctxt.dal_constants store) let register_shard store dir = RPC_directory.register dir (Services.shard ()) (Services.handle_shard store) @@ -77,7 +81,19 @@ module RPC_server = struct Tezos_base_unix.Internal_event_unix.close () end -let run ~data_dir ~no_trusted_setup:_ _ctxt = +let daemonize cctxt handle = Lwt.no_cancel @@ Layer1.iter_events cctxt handle + +let resolve_plugin cctxt = + let open Lwt_result_syntax in + let* protocols = + Tezos_shell_services.Chain_services.Blocks.protocols cctxt () + in + return + @@ Option.either + (Dal_constants_plugin.get protocols.current_protocol) + (Dal_constants_plugin.get protocols.next_protocol) + +let run ~data_dir ~no_trusted_setup:_ cctxt = let open Lwt_result_syntax in let*! () = Event.(emit starting_node) () in let* config = Configuration.load ~data_dir in @@ -88,12 +104,29 @@ let run ~data_dir ~no_trusted_setup:_ _ctxt = Cryptobox.initialisation_parameters_from_files ~g1_path ~g2_path in let*? () = Cryptobox.load_parameters initialisation_parameters in - let*? dal_constants = Cryptobox.init () in - let ctxt = {config; dal_constants} 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 - Lwt_utils.never_ending () + 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 = Cryptobox.init cctxt plugin in + let ctxt = {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 diff --git a/src/bin_dal_node/dune b/src/bin_dal_node/dune index 1578f7fff3aadbe5231b9ce74c5dd6204467a84f..fff15068b43f6a2eb669ed6674f5f4963a0fdd93 100644 --- a/src/bin_dal_node/dune +++ b/src/bin_dal_node/dune @@ -14,13 +14,18 @@ tezos-client-commands tezos-rpc-http tezos-rpc-http-server + tezos-protocol-updater tezos-rpc-http-client-unix tezos-stdlib-unix tezos-stdlib + tezos_dal_node_lib tezos-crypto-dal irmin-pack irmin-pack.unix - irmin) + irmin + (select void_for_linking-tezos-dal-alpha from + (tezos-dal-alpha -> void_for_linking-tezos-dal-alpha.empty) + (-> void_for_linking-tezos-dal-alpha.empty))) (link_flags (:standard) (:include %{workspace_root}/static-link-flags.sexp)) @@ -32,6 +37,10 @@ -open Tezos_client_commands -open Tezos_rpc_http -open Tezos_rpc_http_server + -open Tezos_protocol_updater -open Tezos_rpc_http_client_unix -open Tezos_stdlib_unix - -open Tezos_stdlib)) + -open Tezos_stdlib + -open Tezos_dal_node_lib)) + +(rule (action (progn (write-file void_for_linking-tezos-dal-alpha.empty "")))) diff --git a/src/bin_dal_node/event.ml b/src/bin_dal_node/event.ml index 1e8b762463f116bbd3cad6d335cd852f89f2492a..25a4d66b047b516b2ccc9be4b05bad1a976db4c2 100644 --- a/src/bin_dal_node/event.ml +++ b/src/bin_dal_node/event.ml @@ -95,3 +95,28 @@ let fetched_slot = ~level:Notice ("size", Data_encoding.int31) ("shards", Data_encoding.int31) + +let layer1_node_new_head = + declare_2 + ~section + ~name:"dal_node_layer_1_new_head" + ~msg:"Head of layer 1's node updated to {hash} at level {level}" + ~level:Notice + ("hash", Block_hash.encoding) + ("level", Data_encoding.int32) + +let layer1_node_tracking_started = + declare_0 + ~section + ~name:"dal_node_layer_1_start_tracking" + ~msg:"Started tracking layer 1's node" + ~level:Notice + () + +let protocol_plugin_resolved = + declare_1 + ~section + ~name:"dal_node_pluging_resolved" + ~msg:"Resolved plugin on protocol {proto_hash}" + ~level:Notice + ("proto_hash", Data_encoding.string) diff --git a/src/bin_dal_node/layer1.ml b/src/bin_dal_node/layer1.ml new file mode 100644 index 0000000000000000000000000000000000000000..1362f41c6a8a5c6c7cb7c8c69199032b62467b95 --- /dev/null +++ b/src/bin_dal_node/layer1.ml @@ -0,0 +1,52 @@ +(*****************************************************************************) +(* *) +(* 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. *) +(* *) +(*****************************************************************************) + +(** 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 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 rec go () = + Lwt.bind (Lwt_stream.get stream) @@ fun tok -> + match tok with + | None -> return_unit + | Some element -> + let* () = handle element in + go () + in + go () diff --git a/src/bin_dal_node/services.ml b/src/bin_dal_node/services.ml index 994e0b5da4cdbf128282199ed7f7b2ee0822910b..c3d9a85bd62249d0b51a94af3f5e4c92ed4ba1df 100644 --- a/src/bin_dal_node/services.ml +++ b/src/bin_dal_node/services.ml @@ -59,16 +59,22 @@ let shard () = ~output:Cryptobox.shard_encoding RPC_path.(open_root / "shard" /: Cryptobox.Commitment.rpc_arg /: shard_arg) -let handle_split_slot dal_constants store fill slot = +let handle_split_slot dal_parameters dal_constants store fill slot = let open Lwt_result_syntax in let slot = String.to_bytes slot in - let slot = if fill then Slot_manager.Utils.fill_x00 slot else slot in + let slot = + if fill then + 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 Cryptobox.Commitment.to_b58check commitment -let handle_slot dal_constants store (_, commitment) trim () = +let handle_slot initial_constants dal_constants store (_, commitment) trim () = let open Lwt_result_syntax in - let* slot = Slot_manager.get_slot dal_constants store commitment in + let* slot = + Slot_manager.get_slot initial_constants dal_constants store commitment + in let slot = if trim then Slot_manager.Utils.trim_x00 slot else slot in return (String.of_bytes slot) diff --git a/src/bin_dal_node/slot_manager.ml b/src/bin_dal_node/slot_manager.ml index fc9172a5c3e886f695eb038acd21050b48ded203..b281c7127fddd390412c736c34632af40ca164de 100644 --- a/src/bin_dal_node/slot_manager.ml +++ b/src/bin_dal_node/slot_manager.ml @@ -145,19 +145,20 @@ let get_shard store slot_header shard_id = let*? share = decode_share share in return Cryptobox.{index = shard_id; share} -let check_shards shards = +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 = Cryptobox.Constants.number_of_shards) + Compare.List_length_with.( + shards = initial_constants.Cryptobox.number_of_shards) then Ok () else fail [Missing_shards] -let get_slot cb_constants store slot_header = +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*! shards = Store.list store [slot_header] in - let*? () = check_shards shards in + let*? () = check_shards initial_constants shards in let* shards = List.fold_left_es (fun shards (i, tree) -> @@ -176,12 +177,12 @@ let get_slot cb_constants store slot_header = shards in let*? polynomial = - match Cryptobox.polynomial_from_shards cb_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 = Cryptobox.polynomial_to_bytes cb_constants polynomial in + let slot = Cryptobox.polynomial_to_bytes dal_constants polynomial in let*! () = Event.( emit fetched_slot (Bytes.length slot, Cryptobox.IntMap.cardinal shards)) @@ -205,7 +206,7 @@ module Utils = struct in Bytes.sub b 0 (Bytes.length b - !len) - let fill_x00 b = + let fill_x00 slot_size b = let len = Bytes.length b in - Bytes.extend b 0 (Cryptobox.Constants.slot_size - len) + Bytes.extend b 0 (slot_size - len) end diff --git a/src/bin_dal_node/slot_manager.mli b/src/bin_dal_node/slot_manager.mli index 794606a494f8729547838b241e83caa2400af46e..c338b0932e0d30bb307ed47b49499ab595f4d42a 100644 --- a/src/bin_dal_node/slot_manager.mli +++ b/src/bin_dal_node/slot_manager.mli @@ -30,9 +30,9 @@ - reading a slot means rebuild it from the shards *) -(** [split_and_store cb_constants ts store slot] splits [slot] in shards, stores +(** [split_and_store dal_constants ts store slot] splits [slot] in shards, stores it onto the disk and returns the corresponding [slot_header], using - [cb_constants] and trusted setup [ts] *) + [dal_constants] and trusted setup [ts] *) val split_and_store : Cryptobox.t -> Store.t -> @@ -44,9 +44,11 @@ val split_and_store : val get_shard : Store.t -> Cryptobox.slot_header -> int -> Cryptobox.shard tzresult Lwt.t -(** [get_slot cb_constants store slot_header] fetches from disk the shards associated to - [slot_header], gathers them, rebuilds and returns the [slot]. *) +(** [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 -> Store.t -> Cryptobox.slot_header -> @@ -58,7 +60,6 @@ module Utils : sig spurious uneeded data form it. *) val trim_x00 : bytes -> bytes - (** [fill_x00 b] fills a bytes with '\000' to match - [Cryptobox.Constants.slot_size] *) - val fill_x00 : bytes -> bytes + (** [fill_x00 slot_size b] fills a bytes with '\000' to match [slot_size] *) + val fill_x00 : int -> bytes -> bytes end diff --git a/src/lib_dal_node/dal_constants_plugin.ml b/src/lib_dal_node/dal_constants_plugin.ml new file mode 100644 index 0000000000000000000000000000000000000000..1e5553f51eed4e3b7cf7038f0d907214fa85d5a0 --- /dev/null +++ b/src/lib_dal_node/dal_constants_plugin.ml @@ -0,0 +1,53 @@ +(*****************************************************************************) +(* *) +(* 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. *) +(* *) +(*****************************************************************************) + +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 +end + +let table : (module T) Protocol_hash.Table.t = Protocol_hash.Table.create 5 + +let register (module Plugin : T) = + assert (not (Protocol_hash.Table.mem table Plugin.Proto.hash)) ; + Protocol_hash.Table.add table Plugin.Proto.hash (module Plugin) + +let get hash = Protocol_hash.Table.find table hash diff --git a/src/lib_dal_node/dal_constants_plugin.mli b/src/lib_dal_node/dal_constants_plugin.mli new file mode 100644 index 0000000000000000000000000000000000000000..681828468a5d7361b314163596a7e06e3820f4b2 --- /dev/null +++ b/src/lib_dal_node/dal_constants_plugin.mli @@ -0,0 +1,45 @@ +(*****************************************************************************) +(* *) +(* 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. *) +(* *) +(*****************************************************************************) + +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 +end + +val register : (module T) -> unit + +val get : Protocol_hash.Table.key -> (module T) option diff --git a/src/lib_dal_node/dune b/src/lib_dal_node/dune new file mode 100644 index 0000000000000000000000000000000000000000..b1917119ba9f4428832751211bc46325c35ff914 --- /dev/null +++ b/src/lib_dal_node/dune @@ -0,0 +1,17 @@ +; This file was automatically generated, do not edit. +; Edit file manifest/main.ml instead. + +(library + (name tezos_dal_node_lib) + (package tezos-dal-node-lib) + (instrumentation (backend bisect_ppx)) + (libraries + tezos-base + tezos-base.unix + tezos-client-base + tezos-protocol-updater) + (flags + (:standard) + -open Tezos_base.TzPervasives + -open Tezos_client_base + -open Tezos_protocol_updater)) diff --git a/src/proto_alpha/lib_dal/dal_plugin_registration.ml b/src/proto_alpha/lib_dal/dal_plugin_registration.ml new file mode 100644 index 0000000000000000000000000000000000000000..60fbca2b1cc8a310cd3d093ad913284220a40564 --- /dev/null +++ b/src/proto_alpha/lib_dal/dal_plugin_registration.ml @@ -0,0 +1,47 @@ +(*****************************************************************************) +(* *) +(* 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. *) +(* *) +(*****************************************************************************) + +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 + let* constants = Protocol.Constants_services.all cpctxt (chain, block) in + let Protocol.Alpha_context.Constants.Parametric. + {redundancy_factor; segment_size; slot_size; number_of_shards; _} = + constants.parametric.dal + in + return {redundancy_factor; segment_size; slot_size; number_of_shards} +end + +let () = Dal_constants_plugin.register (module Plugin) diff --git a/src/proto_alpha/lib_dal/dune b/src/proto_alpha/lib_dal/dune index 12b4c6d4f4aeb5d9d73e999e062808daa29fbef0..2518782cb07b82e15b0cd4e1e26878254db25557 100644 --- a/src/proto_alpha/lib_dal/dune +++ b/src/proto_alpha/lib_dal/dune @@ -7,6 +7,10 @@ (instrumentation (backend bisect_ppx)) (libraries tezos-base + tezos-protocol-compiler.registerer + tezos_dal_node_lib + tezos-client-alpha + tezos-embedded-protocol-alpha tezos-protocol-alpha) (inline_tests (flags -verbose) (modes native)) (preprocess (pps ppx_expect)) @@ -15,4 +19,8 @@ (:standard) -open Tezos_base.TzPervasives -open Tezos_base.TzPervasives.Error_monad.Legacy_monad_globals + -open Tezos_protocol_registerer + -open Tezos_dal_node_lib + -open Tezos_client_alpha + -open Tezos_embedded_protocol_alpha -open Tezos_protocol_alpha))