From 2723828445995a76fde557c7bd421d47ac6e656c Mon Sep 17 00:00:00 2001 From: Guillaume Genestier Date: Fri, 14 Feb 2025 15:39:50 +0100 Subject: [PATCH 1/2] DAL: Add option to limit file descriptor creation --- src/bin_dal_node/cli.ml | 15 +++++++++++++-- src/bin_dal_node/cli.mli | 2 ++ src/bin_dal_node/configuration_file.ml | 22 ++++++++++++++++++---- src/bin_dal_node/configuration_file.mli | 2 ++ src/bin_dal_node/daemon.ml | 7 +++++++ src/bin_dal_node/main.ml | 6 ++++++ src/lib_dal_node/gossipsub/gossipsub.ml | 3 ++- src/lib_dal_node/gossipsub/gossipsub.mli | 1 + tezt/lib_tezos/dal_node.ml | 18 ++++++++++++++---- tezt/lib_tezos/dal_node.mli | 2 ++ 10 files changed, 67 insertions(+), 11 deletions(-) diff --git a/src/bin_dal_node/cli.ml b/src/bin_dal_node/cli.ml index 2f66b83699a8..431b74827486 100644 --- a/src/bin_dal_node/cli.ml +++ b/src/bin_dal_node/cli.ml @@ -350,6 +350,14 @@ module Term = struct in Arg.(value & flag & info ~docs ~doc ["verbose"]) + let max_opened_p2p_connections = + let open Cmdliner in + let doc = "Maximum number of concurrent P2P connections allowed." in + Arg.( + value + & opt (some int) None + & info ~docs ~doc ~docv:"NAT" ["max-opened-p2p-connections"]) + (* Experimental features. *) let term process = @@ -359,7 +367,7 @@ module Term = struct $ public_addr $ endpoint $ metrics_addr $ attester_profile $ producer_profile $ observer_profile $ bootstrap_profile $ peers $ history_mode $ service_name $ service_namespace $ fetch_trusted_setup - $ verbose)) + $ verbose $ max_opened_p2p_connections)) end type t = Run | Config_init | Config_update | Debug_print_store_schemas @@ -518,12 +526,14 @@ type options = { experimental_features : experimental_features; fetch_trusted_setup : bool option; verbose : bool; + max_opened_p2p_connections : int option; } let make ~run = let run subcommand data_dir rpc_addr expected_pow listen_addr public_addr endpoint metrics_addr attesters producers observers bootstrap_flag peers - history_mode service_name service_namespace fetch_trusted_setup verbose = + history_mode service_name service_namespace fetch_trusted_setup verbose + max_opened_p2p_connections = let run profile = run subcommand @@ -543,6 +553,7 @@ let make ~run = experimental_features = (); fetch_trusted_setup; verbose; + max_opened_p2p_connections; } in let profile = Operator_profile.make ~attesters ~producers ?observers () in diff --git a/src/bin_dal_node/cli.mli b/src/bin_dal_node/cli.mli index fa631cebb91e..8bf5ad7fb2d8 100644 --- a/src/bin_dal_node/cli.mli +++ b/src/bin_dal_node/cli.mli @@ -60,6 +60,8 @@ type options = { In case of [None] at init it is considered as yes.*) verbose : bool; (** Emit events related to connections. Default value is false. *) + max_opened_p2p_connections : int option; + (** Maximum number of concurrent P2P connections allowed. *) } (** Subcommands that can be used by the DAL node. In the future this type diff --git a/src/bin_dal_node/configuration_file.ml b/src/bin_dal_node/configuration_file.ml index 87bb9543cb5b..ee69d15293ee 100644 --- a/src/bin_dal_node/configuration_file.ml +++ b/src/bin_dal_node/configuration_file.ml @@ -81,6 +81,7 @@ type t = { experimental_features : experimental_features; fetch_trusted_setup : bool; verbose : bool; + max_opened_p2p_connections : int option; } let default_data_dir = Filename.concat (Sys.getenv "HOME") ".tezos-dal-node" @@ -140,6 +141,7 @@ let default = experimental_features = default_experimental_features; fetch_trusted_setup = default_fetch_trusted_setup; verbose = false; + max_opened_p2p_connections = None; } let neighbor_encoding : neighbor Data_encoding.t = @@ -186,6 +188,7 @@ let encoding : t Data_encoding.t = experimental_features; fetch_trusted_setup; verbose; + max_opened_p2p_connections; } -> ( ( data_dir, rpc_addr, @@ -202,7 +205,8 @@ let encoding : t Data_encoding.t = service_namespace, experimental_features, fetch_trusted_setup, - verbose ) )) + verbose, + max_opened_p2p_connections ) )) (fun ( ( data_dir, rpc_addr, listen_addr, @@ -218,7 +222,8 @@ let encoding : t Data_encoding.t = service_namespace, experimental_features, fetch_trusted_setup, - verbose ) ) -> + verbose, + max_opened_p2p_connections ) ) -> { data_dir; rpc_addr; @@ -236,6 +241,7 @@ let encoding : t Data_encoding.t = experimental_features; fetch_trusted_setup; verbose; + max_opened_p2p_connections; }) (merge_objs (obj8 @@ -279,7 +285,7 @@ let encoding : t Data_encoding.t = ~description:"The point for the DAL node metrics server" (Encoding.option P2p_point.Id.encoding) None)) - (obj8 + (obj9 (dft "history_mode" ~description:"The history mode for the DAL node" @@ -316,7 +322,13 @@ let encoding : t Data_encoding.t = ~description: "Whether to emit details about frequent logging events" bool - default.verbose))) + default.verbose) + (dft + "max_opened_p2p_connections" + ~description: + "Maximum number of established P2P connections allowed." + (option int31) + None))) module V0 = struct type v0_profile = @@ -436,6 +448,7 @@ module V0 = struct experimental_features = default_experimental_features; fetch_trusted_setup = true; verbose = false; + max_opened_p2p_connections = None; } end @@ -549,6 +562,7 @@ module V1 = struct experimental_features; fetch_trusted_setup; verbose; + max_opened_p2p_connections = None; } end diff --git a/src/bin_dal_node/configuration_file.mli b/src/bin_dal_node/configuration_file.mli index ef5c027f1cbd..259e88168495 100644 --- a/src/bin_dal_node/configuration_file.mli +++ b/src/bin_dal_node/configuration_file.mli @@ -67,6 +67,8 @@ type t = { verbose : bool; (** Whether to emit detailed events for frequently received control messages from remote peers. *) + max_opened_p2p_connections : int option; + (** Maximum number of concurrent P2P connections allowed. *) } (** [default] is the default configuration. *) diff --git a/src/bin_dal_node/daemon.ml b/src/bin_dal_node/daemon.ml index fd1cb6c39c22..f0e6e92ebc9d 100644 --- a/src/bin_dal_node/daemon.ml +++ b/src/bin_dal_node/daemon.ml @@ -1468,6 +1468,7 @@ let run ~data_dir ~configuration_override = profile; listen_addr; public_addr; + max_opened_p2p_connections; _; } as config) = let*! result = Configuration_file.load ~data_dir in @@ -1480,6 +1481,11 @@ let run ~data_dir ~configuration_override = let* () = Configuration_file.save configuration in return configuration in + let fd_pool = + Option.map + (fun capacity -> P2p_fd.create_fd_pool ~capacity) + max_opened_p2p_connections + in let*! () = Event.emit_configuration_loaded () in let cctxt = Rpc_context.make endpoint in let* dal_config = fetch_dal_config cctxt in @@ -1605,6 +1611,7 @@ let run ~data_dir ~configuration_override = (* Create a transport (P2P) layer instance. *) let* transport_layer = Gossipsub.Transport_layer.create + ?fd_pool ~public_addr ~is_bootstrap_peer:(profile = Profile_manager.bootstrap) p2p_config diff --git a/src/bin_dal_node/main.ml b/src/bin_dal_node/main.ml index d06f65dcf6bc..64f181b2a25c 100644 --- a/src/bin_dal_node/main.ml +++ b/src/bin_dal_node/main.ml @@ -43,6 +43,7 @@ let merge experimental_features; fetch_trusted_setup; verbose; + max_opened_p2p_connections; } configuration = let profile = match profile with @@ -81,6 +82,11 @@ let merge experimental_features configuration.experimental_features; verbose = configuration.verbose || verbose; + max_opened_p2p_connections = + Option.fold + ~none:configuration.max_opened_p2p_connections + ~some:Option.some + max_opened_p2p_connections; } let wrap_with_error main_promise = diff --git a/src/lib_dal_node/gossipsub/gossipsub.ml b/src/lib_dal_node/gossipsub/gossipsub.ml index 1ab97097c0b6..3677a882523d 100644 --- a/src/lib_dal_node/gossipsub/gossipsub.ml +++ b/src/lib_dal_node/gossipsub/gossipsub.ml @@ -48,7 +48,7 @@ module Transport_layer = struct let special_addresses = ["0.0.0.0"; "127.0.0.1"; "localhost"; "[::]"; "::1"] in - fun ~network_name ~public_addr ~is_bootstrap_peer config limits -> + fun ?fd_pool ~network_name ~public_addr ~is_bootstrap_peer config limits -> let advertised_net_addr = if not @@ -71,6 +71,7 @@ module Transport_layer = struct in let config = {config with advertised_port = advertised_net_port} in P2p.create + ?fd_pool ~config ~limits Types.P2P.Metadata.Peer.config diff --git a/src/lib_dal_node/gossipsub/gossipsub.mli b/src/lib_dal_node/gossipsub/gossipsub.mli index 737f486eb276..d2a109bf53d5 100644 --- a/src/lib_dal_node/gossipsub/gossipsub.mli +++ b/src/lib_dal_node/gossipsub/gossipsub.mli @@ -85,6 +85,7 @@ module Transport_layer : sig creates a new instance of type {!t}. It is a wrapper on top of {!P2p.create}. *) val create : + ?fd_pool:P2p_fd.fd_pool -> network_name:Distributed_db_version.Name.t -> public_addr:P2p_point.Id.t -> is_bootstrap_peer:bool -> diff --git a/tezt/lib_tezos/dal_node.ml b/tezt/lib_tezos/dal_node.ml index 918b90b05eff..9c2613c47b31 100644 --- a/tezt/lib_tezos/dal_node.ml +++ b/tezt/lib_tezos/dal_node.ml @@ -99,7 +99,7 @@ let spawn_command dal_node = let spawn_config_init ?(expected_pow = 0.) ?(peers = []) ?(attester_profiles = []) ?(producer_profiles = []) ?(observer_profiles = []) ?(bootstrap_profile = false) ?history_mode - dal_node = + ?max_p2p_connections dal_node = spawn_command dal_node @@ [ "config"; @@ -134,6 +134,9 @@ let spawn_config_init ?(expected_pow = 0.) ?(peers = []) String.concat "," (List.map string_of_int producer_profiles); ]) @ (if bootstrap_profile then ["--bootstrap-profile"] else []) + @ (match max_p2p_connections with + | None -> [] + | Some n -> ["--max-opened-p2p-connections"; string_of_int n]) @ match history_mode with | None -> [] @@ -143,7 +146,7 @@ let spawn_config_init ?(expected_pow = 0.) ?(peers = []) let spawn_config_update ?(peers = []) ?(attester_profiles = []) ?(producer_profiles = []) ?(observer_profiles = []) - ?(bootstrap_profile = false) ?history_mode dal_node = + ?(bootstrap_profile = false) ?history_mode ?max_p2p_connections dal_node = spawn_command dal_node @@ ["config"; "update"] @ (if peers = [] then [] else ["--peers"; String.concat "," peers]) @ (if attester_profiles = [] then [] @@ -161,6 +164,9 @@ let spawn_config_update ?(peers = []) ?(attester_profiles = []) String.concat "," (List.map string_of_int producer_profiles); ]) @ (if bootstrap_profile then ["--bootstrap-profile"] else []) + @ (match max_p2p_connections with + | None -> [] + | Some n -> ["--max-opened-p2p-connections"; string_of_int n]) @ match history_mode with | None -> [] @@ -179,7 +185,8 @@ module Config_file = struct end let init_config ?expected_pow ?peers ?attester_profiles ?producer_profiles - ?observer_profiles ?bootstrap_profile ?history_mode dal_node = + ?observer_profiles ?bootstrap_profile ?history_mode ?max_p2p_connections + dal_node = let process = spawn_config_init ?expected_pow @@ -189,12 +196,14 @@ let init_config ?expected_pow ?peers ?attester_profiles ?producer_profiles ?observer_profiles ?bootstrap_profile ?history_mode + ?max_p2p_connections dal_node in Process.check process let update_config ?peers ?attester_profiles ?producer_profiles - ?observer_profiles ?bootstrap_profile ?history_mode dal_node = + ?observer_profiles ?bootstrap_profile ?history_mode ?max_p2p_connections + dal_node = let process = spawn_config_update ?peers @@ -203,6 +212,7 @@ let update_config ?peers ?attester_profiles ?producer_profiles ?observer_profiles ?bootstrap_profile ?history_mode + ?max_p2p_connections dal_node in Process.check process diff --git a/tezt/lib_tezos/dal_node.mli b/tezt/lib_tezos/dal_node.mli index fcc8735eacba..bc5b7992fc29 100644 --- a/tezt/lib_tezos/dal_node.mli +++ b/tezt/lib_tezos/dal_node.mli @@ -157,6 +157,7 @@ val init_config : ?observer_profiles:int list -> ?bootstrap_profile:bool -> ?history_mode:history_mode -> + ?max_p2p_connections:int -> t -> unit Lwt.t @@ -167,6 +168,7 @@ val update_config : ?observer_profiles:int list -> ?bootstrap_profile:bool -> ?history_mode:history_mode -> + ?max_p2p_connections:int -> t -> unit Lwt.t -- GitLab From 91c4d0db96632d22f18826ee65f3942a027e70c2 Mon Sep 17 00:00:00 2001 From: Guillaume Genestier Date: Fri, 14 Feb 2025 15:39:54 +0100 Subject: [PATCH 2/2] Changelog: Add description of --max-opened-connections option of DAL node --- CHANGES.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index 0cf4665a57af..da20ac630fa8 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -188,6 +188,10 @@ DAL node from the layer 1 node (MR :gl:`!17284`). Profile encoding has been modified (MR :gl:`!17200`). +- **Feature** The DAL node can be launched with the `--max-opened-p2p-connections ` + option, which allows to limit the number of network connections which can be + simultaneously opened by the DAL node. (MR :gl:`!16350`) + Protocol ~~~~~~~~ -- GitLab