diff --git a/src/bin_dal_node/cli.ml b/src/bin_dal_node/cli.ml index 760d4d46186caddbaf1b3d17626fa85c69d2b38e..42f716dcd534a2669f6a7b2aa5ec60cced52f479 100644 --- a/src/bin_dal_node/cli.ml +++ b/src/bin_dal_node/cli.ml @@ -99,17 +99,19 @@ module Term = struct & opt (some endpoint_arg) None & info ~docs ~doc ~docv:"[ADDR:PORT]" ["endpoint"]) + let profile_printer fmt = function + | Services.Types.Attestor pkh -> + Format.fprintf fmt "%a" Signature.Public_key_hash.pp pkh + | Producer {slot_index} -> Format.fprintf fmt "%d" slot_index + let attestor_profile_arg = let open Cmdliner in let decoder string = match Signature.Public_key_hash.of_b58check_opt string with | None -> Error (`Msg "Unrecognized profile") - | Some pkh -> `Attestor pkh |> Result.ok - in - let printer fmt profile = - match profile with `Attestor pkh -> Signature.Public_key_hash.pp fmt pkh + | Some pkh -> Services.Types.Attestor pkh |> Result.ok in - Arg.conv (decoder, printer) + Arg.conv (decoder, profile_printer) let producer_profile_arg = let open Cmdliner in @@ -124,13 +126,9 @@ module Term = struct match int_of_string_opt string with | None -> error () | Some i when i < 0 -> error () - | Some slot_index -> Result.ok (`Producer slot_index) - in - let printer fmt profile = - match profile with - | `Producer slot_index -> Format.fprintf fmt "%d" slot_index + | Some slot_index -> Services.Types.Producer {slot_index} |> Result.ok in - Arg.conv (decoder, printer) + Arg.conv (decoder, profile_printer) let attestor_profile = let open Cmdliner in @@ -139,7 +137,7 @@ module Term = struct in Arg.( value - & opt (some attestor_profile_arg) None + & opt (list attestor_profile_arg) [] & info ~docs ~doc ~docv:"[PKH]" ["attestor-profile"]) let producer_profile = @@ -147,7 +145,7 @@ module Term = struct let doc = "The Octez DAL node producer profile for a given slot index." in Arg.( value - & opt (some producer_profile_arg) None + & opt (list producer_profile_arg) [] & info ~docs ~doc ~docv:"[slot index]" ["producer-profile"]) let peers = @@ -239,7 +237,7 @@ type options = { expected_pow : float option; listen_addr : P2p_point.Id.t option; endpoint : Uri.t option; - profile : Services.Types.profile option; + profiles : Services.Types.profiles; metrics_addr : P2p_point.Id.t option; peers : string list; } @@ -248,22 +246,8 @@ type t = Run | Config_init let make ~run = let run subcommand data_dir rpc_addr expected_pow listen_addr endpoint - metrics_addr attestor_opt producer_opt peers = - let profile = - match (attestor_opt, producer_opt) with - | None, None -> None - | None, Some (`Producer slot_index) -> - Some (Services.Types.Producer {slot_index}) - | Some (`Attestor pkh), _ -> - (* If both attestor and producer are present on the commandline, we - prioritize the attestor argument. - - TODO: https://gitlab.com/tezos/tezos/-/issues/5967 - The DAL node is able to handle several profiles concurrently. The commandline - should allow that. - *) - Some (Services.Types.Attestor pkh) - in + metrics_addr attestors producers peers = + let profiles = attestors @ producers in run subcommand { @@ -272,7 +256,7 @@ let make ~run = expected_pow; listen_addr; endpoint; - profile; + profiles; metrics_addr; peers; } diff --git a/src/bin_dal_node/cli.mli b/src/bin_dal_node/cli.mli index 530d30441171b489873193ae9abe883137b45bca..04332f84ab3c045a9187daa2631e158141c0bf60 100644 --- a/src/bin_dal_node/cli.mli +++ b/src/bin_dal_node/cli.mli @@ -40,8 +40,8 @@ type options = { listen_addr : P2p_point.Id.t option; (** The endpoint on which the DAL node can be contacted by other DAL nodes. *) endpoint : Uri.t option; (** The endpoint on which to contact the L1 node. *) - profile : Services.Types.profile option; - (** Profile of the DAL node used for tracking shards. *) + profiles : Services.Types.profiles; + (** Profiles of the DAL node used for tracking shards. *) metrics_addr : P2p_point.Id.t option; (** Metrics server endpoint. *) peers : string list; (** DAL nodes to connect to. *) } diff --git a/src/bin_dal_node/configuration_file.ml b/src/bin_dal_node/configuration_file.ml index 5b1e351409aedd5f47623ca9f4e5362ec6011e30..8daaed0622d8bdeca8638ce7013fa89c060b1b65 100644 --- a/src/bin_dal_node/configuration_file.ml +++ b/src/bin_dal_node/configuration_file.ml @@ -35,7 +35,7 @@ type t = { network_name : string; endpoint : Uri.t; metrics_addr : P2p_point.Id.t; - profile : Services.Types.profile option; + profiles : Services.Types.profiles; } let default_data_dir = Filename.concat (Sys.getenv "HOME") ".tezos-dal-node" @@ -79,7 +79,7 @@ let default = network_name = default_network_name; endpoint = default_endpoint; metrics_addr = default_metrics_addr; - profile = None; + profiles = []; } let neighbor_encoding : neighbor Data_encoding.t = @@ -116,7 +116,7 @@ let encoding : t Data_encoding.t = network_name; endpoint; metrics_addr; - profile; + profiles; } -> ( data_dir, rpc_addr, @@ -127,7 +127,7 @@ let encoding : t Data_encoding.t = network_name, endpoint, metrics_addr, - profile )) + profiles )) (fun ( data_dir, rpc_addr, listen_addr, @@ -137,7 +137,7 @@ let encoding : t Data_encoding.t = network_name, endpoint, metrics_addr, - profile ) -> + profiles ) -> { data_dir; rpc_addr; @@ -148,7 +148,7 @@ let encoding : t Data_encoding.t = network_name; endpoint; metrics_addr; - profile; + profiles; }) (obj10 (dft @@ -197,10 +197,10 @@ let encoding : t Data_encoding.t = P2p_point.Id.encoding default_metrics_addr) (dft - "profile" - ~description:"The Octez DAL node profile" - (option Services.Types.profile_encoding) - None)) + "profiles" + ~description:"The Octez DAL node profiles" + Services.Types.profiles_encoding + [])) type error += DAL_node_unable_to_write_configuration_file of string diff --git a/src/bin_dal_node/configuration_file.mli b/src/bin_dal_node/configuration_file.mli index 230462cb29788609b5b847f0ae8fc8d1c19d0e4c..481d8495e6b56c6a9325976617b1156a6c8b7d1d 100644 --- a/src/bin_dal_node/configuration_file.mli +++ b/src/bin_dal_node/configuration_file.mli @@ -38,7 +38,7 @@ type t = { endpoint : Uri.t; (** Endpoint of a Tezos node *) metrics_addr : P2p_point.Id.t; (** The metrics server used to export metrics *) - profile : Services.Types.profile option; + profiles : Services.Types.profiles; (** Profile allowing to know the topics of interest. *) } diff --git a/src/bin_dal_node/daemon.ml b/src/bin_dal_node/daemon.ml index 08dd6675a2169640c079dc0dcf54c1ef538621e0..dc1cbc3977eaa926ec5c4f5b365118ea3db83ce5 100644 --- a/src/bin_dal_node/daemon.ml +++ b/src/bin_dal_node/daemon.ml @@ -184,18 +184,19 @@ module Handler = struct in let* cryptobox = init_cryptobox dal_config proto_parameters in let* () = - match config.Configuration_file.profile with - | None -> return_unit - | Some profile -> - let+ pctxt = + let+ pctxt = + List.fold_left_es + (fun profile_ctxt profile -> Profile_manager.add_profile - (Node_context.get_profile_ctxt ctxt) + profile_ctxt proto_parameters (Node_context.get_store ctxt) (Node_context.get_gs_worker ctxt) - profile - in - Node_context.set_profile_ctxt ctxt pctxt + profile) + (Node_context.get_profile_ctxt ctxt) + config.Configuration_file.profiles + in + Node_context.set_profile_ctxt ctxt pctxt in Node_context.set_ready ctxt diff --git a/src/bin_dal_node/main.ml b/src/bin_dal_node/main.ml index 3aaa4766ef1391f0a58ebff150832579de1ff6ae..c74d6671c8c170f226deaf9eefa62e297d663adc 100644 --- a/src/bin_dal_node/main.ml +++ b/src/bin_dal_node/main.ml @@ -32,7 +32,7 @@ let merge listen_addr; endpoint; metrics_addr; - profile; + profiles; peers; } configuration = Configuration_file. @@ -44,7 +44,7 @@ let merge expected_pow = Option.value ~default:configuration.expected_pow expected_pow; endpoint = Option.value ~default:configuration.endpoint endpoint; - profile = Option.either profile configuration.profile; + profiles = profiles @ configuration.profiles; metrics_addr = Option.value ~default:configuration.metrics_addr metrics_addr; peers = peers @ configuration.peers; diff --git a/src/lib_dal_node_services/services.ml b/src/lib_dal_node_services/services.ml index 73e95db4fa5bdbcb51d7c222bc7b4b039a5cc8f6..b104aaec17848816699737d4d12bcf1d768b7764 100644 --- a/src/lib_dal_node_services/services.ml +++ b/src/lib_dal_node_services/services.ml @@ -67,6 +67,8 @@ module Types = struct | Attestor of Tezos_crypto.Signature.public_key_hash | Producer of {slot_index : int} + type profiles = profile list + type with_proof = {with_proof : bool} (* Auxiliary functions. *) @@ -181,6 +183,10 @@ module Types = struct (function (), slot_index -> Producer {slot_index}); ] + let profiles_encoding = + let open Data_encoding in + list profile_encoding + let with_proof_encoding = let open Data_encoding in conv @@ -347,7 +353,7 @@ let get_published_level_headers : let patch_profiles : < meth : [`PATCH] - ; input : Types.profile list + ; input : Types.profiles ; output : unit ; prefix : unit ; params : unit @@ -356,14 +362,14 @@ let patch_profiles : Tezos_rpc.Service.patch_service ~description:"Update the list of profiles tracked by the DAL node" ~query:Tezos_rpc.Query.empty - ~input:(Data_encoding.list Types.profile_encoding) + ~input:Types.profiles_encoding ~output:Data_encoding.unit Tezos_rpc.Path.(open_root / "profiles") let get_profiles : < meth : [`GET] ; input : unit - ; output : Types.profile list + ; output : Types.profiles ; prefix : unit ; params : unit ; query : unit > @@ -371,7 +377,7 @@ let get_profiles : Tezos_rpc.Service.get_service ~description:"Return the list of current profiles tracked by the DAL node" ~query:Tezos_rpc.Query.empty - ~output:(Data_encoding.list Types.profile_encoding) + ~output:Types.profiles_encoding Tezos_rpc.Path.(open_root / "profiles") let get_assigned_shard_indices : diff --git a/src/lib_dal_node_services/services.mli b/src/lib_dal_node_services/services.mli index cbc2c3c61add9c1c50611bc6b3f3303c537d8ffd..841ba7a86c27be799a2a3da5d8f48f62e3787620 100644 --- a/src/lib_dal_node_services/services.mli +++ b/src/lib_dal_node_services/services.mli @@ -91,6 +91,8 @@ module Types : sig | Attestor of Tezos_crypto.Signature.public_key_hash | Producer of {slot_index : int} + type profiles = profile list + (** Information associated to a slot header in the RPC services of the DAL node. *) type slot_header = { @@ -109,6 +111,8 @@ module Types : sig val profile_encoding : profile Data_encoding.t + val profiles_encoding : profiles Data_encoding.t + val with_proof_encoding : with_proof Data_encoding.t val equal_profile : profile -> profile -> bool @@ -203,7 +207,7 @@ val get_published_level_headers : (** Update the list of profiles tracked by the DAL node *) val patch_profiles : < meth : [`PATCH] - ; input : Types.profile list + ; input : Types.profiles ; output : unit ; prefix : unit ; params : unit @@ -214,7 +218,7 @@ val patch_profiles : val get_profiles : < meth : [`GET] ; input : unit - ; output : Types.profile list + ; output : Types.profiles ; prefix : unit ; params : unit ; query : unit >