diff --git a/src/bin_dal_node/RPC_server.ml b/src/bin_dal_node/RPC_server.ml index ea46f686faac9772c682766047c1cd9742883ad3..7010aca12d8b165d858b8c8e69a70b6cf0f2fb3d 100644 --- a/src/bin_dal_node/RPC_server.ml +++ b/src/bin_dal_node/RPC_server.ml @@ -30,7 +30,7 @@ open Tezos_rpc_http_server module Slots_handlers = struct let call_handler handler ctxt = let open Lwt_result_syntax in - let*? {dal_constants = cryptobox; _} = Node_context.get_ready ctxt in + let*? {cryptobox; _} = Node_context.get_ready ctxt in let store = Node_context.get_store ctxt in handler store cryptobox diff --git a/src/bin_dal_node/RPC_server_legacy.ml b/src/bin_dal_node/RPC_server_legacy.ml index c8b1b7a71e2d1c293e711b33d44f4f373819dc43..6992170d8c6c637c58e91d2b05cca5cd7754c3d4 100644 --- a/src/bin_dal_node/RPC_server_legacy.ml +++ b/src/bin_dal_node/RPC_server_legacy.ml @@ -28,12 +28,12 @@ open Tezos_dal_node_services let handle_split_slot ctxt () slot = let open Lwt_result_syntax in - let*? {dal_constants; _} = Node_context.get_ready ctxt in + let*? {cryptobox; _} = Node_context.get_ready ctxt in let store = Node_context.get_store ctxt in let+ commitment, proof = Slot_manager.split_and_store store.slots_watcher - dal_constants + cryptobox store.slots_store slot in @@ -41,10 +41,9 @@ let handle_split_slot ctxt () slot = let handle_slot ctxt (_, commitment) () () = let open Lwt_result_syntax in - let*? {dal_parameters; dal_constants; _} = Node_context.get_ready ctxt in + let*? {cryptobox; _} = Node_context.get_ready ctxt in Slot_manager.get_slot - dal_parameters - dal_constants + cryptobox (Node_context.get_store ctxt).slots_store commitment @@ -59,10 +58,9 @@ let handle_stored_slot_headers ctxt (_, block_hash) () () = let handle_slot_pages ctxt (_, commitment) () () = let open Lwt_result_syntax in - let*? {dal_parameters; dal_constants; _} = Node_context.get_ready ctxt in + let*? {cryptobox; _} = Node_context.get_ready ctxt in Slot_manager.get_slot_pages - dal_parameters - dal_constants + cryptobox (Node_context.get_store ctxt).slots_store commitment @@ -74,7 +72,8 @@ let handle_shard ctxt ((_, commitment), shard) () () = let handle_shards ctxt (_, commitment) () shards = let open Lwt_result_syntax in - let*? {dal_parameters; _} = Node_context.get_ready ctxt in + let*? {cryptobox; _} = Node_context.get_ready ctxt in + let dal_parameters = Cryptobox.parameters cryptobox in let shards = let open Slot_manager in List.fold_left diff --git a/src/bin_dal_node/daemon.ml b/src/bin_dal_node/daemon.ml index 667ca9cae8b756d66d7a08be0ee72c0c5c3e447a..42c97b576815d6443500b463cb9e2b9e82c5a5f2 100644 --- a/src/bin_dal_node/daemon.ml +++ b/src/bin_dal_node/daemon.ml @@ -68,7 +68,7 @@ let init_cryptobox unsafe_srs cctxt (module Plugin : Dal_plugin.T) = in let*? () = Cryptobox.load_parameters initialisation_parameters in match Cryptobox.make parameters with - | Ok cryptobox -> return (cryptobox, parameters) + | Ok cryptobox -> return cryptobox | Error (`Fail msg) -> fail [Cryptobox_initialisation_failed msg] module Handler = struct @@ -111,14 +111,10 @@ module Handler = struct | Some plugin -> let (module Plugin : Dal_plugin.T) = plugin in let*! () = Event.emit_protocol_plugin_resolved Plugin.Proto.hash in - let* dal_constants, dal_parameters = + let* cryptobox = init_cryptobox config.Configuration.use_unsafe_srs cctxt plugin in - Node_context.set_ready - ctxt - (module Plugin) - dal_constants - dal_parameters ; + Node_context.set_ready ctxt (module Plugin) cryptobox ; let*! () = Event.(emit node_is_ready ()) in stopper () ; return_unit @@ -164,9 +160,12 @@ module Handler = struct (* Monitor neighbor DAL nodes and download published slots as shards. *) let open Lwt_result_syntax in let handler n_cctxt ready_ctxt slot_header = - let params = ready_ctxt.Node_context.dal_parameters in + let cryptobox = ready_ctxt.Node_context.cryptobox in + let dal_parameters = Cryptobox.parameters cryptobox in let downloaded_shard_ids = - 0 -- ((params.number_of_shards / params.redundancy_factor) - 1) + 0 + -- ((dal_parameters.number_of_shards / dal_parameters.redundancy_factor) + - 1) in let* shards = RPC_server_legacy.shards_rpc n_cctxt slot_header downloaded_shard_ids @@ -182,7 +181,7 @@ module Handler = struct Slot_manager.save_shards (Node_context.get_store ctxt).slots_store (Node_context.get_store ctxt).slots_watcher - ready_ctxt.dal_constants + ready_ctxt.Node_context.cryptobox slot_header shards in diff --git a/src/bin_dal_node/node_context.ml b/src/bin_dal_node/node_context.ml index 8823cd8fb8120a6b8bda0fdd675e4cf59fe992af..d9de1fe1286948ab75b9669c832c5952ae6332d6 100644 --- a/src/bin_dal_node/node_context.ml +++ b/src/bin_dal_node/node_context.ml @@ -25,11 +25,7 @@ exception Status_already_ready -type ready_ctxt = { - dal_constants : Cryptobox.t; - dal_parameters : Cryptobox.parameters; - plugin : (module Dal_plugin.T); -} +type ready_ctxt = {cryptobox : Cryptobox.t; plugin : (module Dal_plugin.T)} type status = Ready of ready_ctxt | Starting @@ -49,9 +45,9 @@ let init config store = in {status = Starting; config; store; neighbors_cctxts} -let set_ready ctxt plugin dal_constants dal_parameters = +let set_ready ctxt plugin cryptobox = match ctxt.status with - | Starting -> ctxt.status <- Ready {plugin; dal_constants; dal_parameters} + | Starting -> ctxt.status <- Ready {plugin; cryptobox} | Ready _ -> raise Status_already_ready type error += Node_not_ready diff --git a/src/bin_dal_node/node_context.mli b/src/bin_dal_node/node_context.mli index cb628eaafb23257e4cf9dae23f4cfb8839d24e56..3a88e2b0da7a2a727aa8e4966dfa633e4f5d2403 100644 --- a/src/bin_dal_node/node_context.mli +++ b/src/bin_dal_node/node_context.mli @@ -26,11 +26,7 @@ (** A [ready_ctx] value contains globally needed informations for a running dal node. It is available when both cryptobox is initialized and dal plugin is loaded. *) -type ready_ctxt = { - dal_constants : Cryptobox.t; - dal_parameters : Cryptobox.parameters; - plugin : (module Dal_plugin.T); -} +type ready_ctxt = {cryptobox : Cryptobox.t; plugin : (module Dal_plugin.T)} (** The status of the dal node *) type status = Ready of ready_ctxt | Starting @@ -46,17 +42,13 @@ val init : Configuration.t -> Store.node_store -> t (** Raised by [set_ready] when the status is already [Ready _] *) exception Status_already_ready -(** [set_ready ctxt plugin dal_constants dal_params] updates in place the status +(** [set_ready ctxt plugin dal_constants] updates in place the status value to [Ready], and initializes the inner [ready_ctxt] value with the given parameters. @raise Status_already_ready when the status is already [Ready _] *) val set_ready : - t -> - (module Tezos_dal_node_lib.Dal_plugin.T) -> - Cryptobox.t -> - Cryptobox.parameters -> - unit + t -> (module Tezos_dal_node_lib.Dal_plugin.T) -> Cryptobox.t -> unit type error += Node_not_ready diff --git a/src/bin_dal_node/slot_manager_legacy.ml b/src/bin_dal_node/slot_manager_legacy.ml index f66afaaa06b44376fe534af10de024ffa20a0302..05ce8607234da02942965196bfccb55657a9f48d 100644 --- a/src/bin_dal_node/slot_manager_legacy.ml +++ b/src/bin_dal_node/slot_manager_legacy.ml @@ -153,18 +153,18 @@ let save store watcher slot_header shards = Lwt_watcher.notify watcher slot_header ; return_unit -let split_and_store watcher dal_constants store slot = +let split_and_store watcher cryptobox store slot = let r = let open Result_syntax in - let* polynomial = Cryptobox.polynomial_from_slot dal_constants slot in - let commitment = Cryptobox.commit dal_constants polynomial in - let proof = Cryptobox.prove_commitment dal_constants polynomial in + let* polynomial = Cryptobox.polynomial_from_slot cryptobox slot in + let commitment = Cryptobox.commit cryptobox polynomial in + let proof = Cryptobox.prove_commitment cryptobox polynomial in return (polynomial, commitment, proof) in let open Lwt_result_syntax in match r with | Ok (polynomial, commitment, commitment_proof) -> - let shards = Cryptobox.shards_from_polynomial dal_constants polynomial in + let shards = Cryptobox.shards_from_polynomial cryptobox polynomial in let* () = save store watcher commitment shards in Lwt.return_ok (commitment, commitment_proof) | Error (`Slot_wrong_size msg) -> Lwt.return_error [Splitting_failed msg] @@ -185,16 +185,16 @@ let check_slot_consistency dal_parameters shards = {provided = List.length shards; required = required_shards}; ] -let polynomial_from_shards dal_constants shards = - match Cryptobox.polynomial_from_shards dal_constants shards with +let polynomial_from_shards cryptobox shards = + match Cryptobox.polynomial_from_shards cryptobox shards with | Ok p -> Ok p | Error (`Invert_zero msg | `Not_enough_shards msg) -> Error [Merging_failed msg] -let save_shards store watcher dal_constants slot_header shards = +let save_shards store watcher cryptobox slot_header shards = let open Lwt_result_syntax in - let*? polynomial = polynomial_from_shards dal_constants shards in - let rebuilt_slot_header = Cryptobox.commit dal_constants polynomial in + let*? polynomial = polynomial_from_shards cryptobox shards in + let rebuilt_slot_header = Cryptobox.commit cryptobox polynomial in let*? () = if Cryptobox.Commitment.equal slot_header rebuilt_slot_header then Ok () else Result_syntax.fail [Invalid_shards_slot_header_association] @@ -253,8 +253,9 @@ let get_shards store dal_parameters slot_header shard_ids = [] slot_header -let get_slot dal_parameters dal_constants store slot_header = +let get_slot cryptobox store slot_header = let open Lwt_result_syntax in + let dal_parameters = Cryptobox.parameters cryptobox in let* shards = fold_stored_shards ~check_shards:true @@ -264,18 +265,18 @@ let get_slot dal_parameters dal_constants store slot_header = Cryptobox.IntMap.empty slot_header in - let*? polynomial = polynomial_from_shards dal_constants shards in - let slot = Cryptobox.polynomial_to_bytes dal_constants polynomial in + let*? polynomial = polynomial_from_shards cryptobox shards in + let slot = Cryptobox.polynomial_to_bytes cryptobox polynomial in let*! () = Event.( emit fetched_slot (Bytes.length slot, Cryptobox.IntMap.cardinal shards)) in return slot -let get_slot_pages ({Cryptobox.page_size; _} as initial_constants) dal_constants - store slot_header = +let get_slot_pages cryptobox store slot_header = let open Lwt_result_syntax in - let* slot = get_slot initial_constants dal_constants store slot_header in + let dal_parameters = Cryptobox.parameters cryptobox in + let* slot = get_slot cryptobox store slot_header in (* The slot size `Bytes.length slot` should be an exact multiple of `page_size`. If this is not the case, we throw an `Illformed_pages` error. *) @@ -283,7 +284,7 @@ let get_slot_pages ({Cryptobox.page_size; _} as initial_constants) dal_constants Implement `Bytes.chunk_bytes` which returns a list of bytes directly. *) let*? pages = String.chunk_bytes - page_size + dal_parameters.page_size slot ~error_on_partial_chunk:(TzTrace.make Illformed_pages) in diff --git a/src/bin_dal_node/slot_manager_legacy.mli b/src/bin_dal_node/slot_manager_legacy.mli index 00277ec5e09601ed6998b4891f442829500c3bfb..f255013b1b32d9a602395143b95e12645e4c1634 100644 --- a/src/bin_dal_node/slot_manager_legacy.mli +++ b/src/bin_dal_node/slot_manager_legacy.mli @@ -69,11 +69,7 @@ val get_shards : disk the shards associated to [slot_header], gathers them, rebuilds and returns the [slot]. *) val get_slot : - Cryptobox.parameters -> - Cryptobox.t -> - Store.t -> - Cryptobox.commitment -> - slot tzresult Lwt.t + Cryptobox.t -> Store.t -> Cryptobox.commitment -> slot tzresult Lwt.t (** [get_slot_pages] behaves as [get_slot], except that it also splits the slot into pages before returning them. @@ -83,11 +79,7 @@ val get_slot : length is not a multiple of the page-size specified in the [Cryptobox.parameters] argument. *) val get_slot_pages : - Cryptobox.parameters -> - Cryptobox.t -> - Store.t -> - Cryptobox.commitment -> - bytes list tzresult Lwt.t + Cryptobox.t -> Store.t -> Cryptobox.commitment -> bytes list tzresult Lwt.t (** [save_shards store slot_header shards] stores [shards] onto the [store] associated to the given [slot_header] *)