From 8905050cd87260a32ed1793eb422c1f59d8d0e0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Thir=C3=A9?= Date: Mon, 19 Jun 2023 12:09:26 +0200 Subject: [PATCH 1/9] DAL/Node: Rename "main_dal" into "main" --- manifest/main.ml | 2 +- src/bin_dal_node/dune | 2 +- src/bin_dal_node/{main_dal.ml => main.ml} | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename src/bin_dal_node/{main_dal.ml => main.ml} (100%) diff --git a/manifest/main.ml b/manifest/main.ml index 78730ac87e70..2c0e23e89a6c 100644 --- a/manifest/main.ml +++ b/manifest/main.ml @@ -7242,7 +7242,7 @@ let _octez_dal_node = public_exe "octez-dal-node" ~path:"src/bin_dal_node" - ~internal_name:"main_dal" + ~internal_name:"main" ~synopsis:"Tezos: `octez-dal-node` binary" ~release_status:Experimental ~with_macos_security_framework:true diff --git a/src/bin_dal_node/dune b/src/bin_dal_node/dune index a5cd2a1b0c55..1df9f83c4ac2 100644 --- a/src/bin_dal_node/dune +++ b/src/bin_dal_node/dune @@ -2,7 +2,7 @@ ; Edit file manifest/main.ml instead. (executable - (name main_dal) + (name main) (public_name octez-dal-node) (package octez-dal-node) (instrumentation (backend bisect_ppx)) diff --git a/src/bin_dal_node/main_dal.ml b/src/bin_dal_node/main.ml similarity index 100% rename from src/bin_dal_node/main_dal.ml rename to src/bin_dal_node/main.ml -- GitLab From 6ec74b926497e8bff53ee4faa2c27773b0158c0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Thir=C3=A9?= Date: Mon, 19 Jun 2023 12:17:27 +0200 Subject: [PATCH 2/9] DAL/Node: Add a default configuration --- src/bin_dal_node/configuration.ml | 12 ++++++++++++ src/bin_dal_node/configuration.mli | 3 +++ 2 files changed, 15 insertions(+) diff --git a/src/bin_dal_node/configuration.ml b/src/bin_dal_node/configuration.ml index 28638a840505..deaff1514275 100644 --- a/src/bin_dal_node/configuration.ml +++ b/src/bin_dal_node/configuration.ml @@ -64,6 +64,18 @@ let default_expected_pow = let default_network_name = "dal-sandbox" +let default = + { + use_unsafe_srs = false; + data_dir = default_data_dir; + rpc_addr = default_rpc_addr; + neighbors = default_neighbors; + listen_addr = default_listen_addr; + peers = default_peers; + expected_pow = default_expected_pow; + network_name = default_network_name; + } + let neighbor_encoding : neighbor Data_encoding.t = let open Data_encoding in conv diff --git a/src/bin_dal_node/configuration.mli b/src/bin_dal_node/configuration.mli index f35751a2b432..7b31d1e6eb74 100644 --- a/src/bin_dal_node/configuration.mli +++ b/src/bin_dal_node/configuration.mli @@ -40,6 +40,9 @@ type t = { (** A string that identifies the network's name. E.g. dal-sandbox. *) } +(** [default] is the default configuration. *) +val default : t + (** [filename config] gets the path to config file *) val filename : t -> string -- GitLab From a2870e6c7198ebeb3c75daf20a112e5699f6fb63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Thir=C3=A9?= Date: Mon, 19 Jun 2023 12:24:24 +0200 Subject: [PATCH 3/9] DAL/Node: Rename `configuration` into `configuration_file` --- src/bin_dal_node/RPC_server.ml | 2 +- src/bin_dal_node/cli.ml | 8 ++++---- .../{configuration.ml => configuration_file.ml} | 2 +- .../{configuration.mli => configuration_file.mli} | 2 +- src/bin_dal_node/daemon.ml | 6 ++++-- src/bin_dal_node/main.ml | 4 ++-- src/bin_dal_node/node_context.ml | 6 +++--- src/bin_dal_node/node_context.mli | 4 ++-- src/bin_dal_node/store.ml | 2 +- src/bin_dal_node/transport_layer_parameters.ml | 6 +++--- src/bin_dal_node/transport_layer_parameters.mli | 2 +- 11 files changed, 23 insertions(+), 21 deletions(-) rename src/bin_dal_node/{configuration.ml => configuration_file.ml} (99%) rename src/bin_dal_node/{configuration.mli => configuration_file.mli} (98%) diff --git a/src/bin_dal_node/RPC_server.ml b/src/bin_dal_node/RPC_server.ml index 8989c1e3b522..891502307bb8 100644 --- a/src/bin_dal_node/RPC_server.ml +++ b/src/bin_dal_node/RPC_server.ml @@ -227,7 +227,7 @@ let merge dir plugin_dir = Tezos_rpc.Directory.merge dir plugin_dir let start configuration ctxt = let open Lwt_syntax in - let Configuration.{rpc_addr; _} = configuration in + let Configuration_file.{rpc_addr; _} = configuration in let dir = register ctxt in let rpc_port = snd rpc_addr in let rpc_addr = fst rpc_addr in diff --git a/src/bin_dal_node/cli.ml b/src/bin_dal_node/cli.ml index d0393391c3f7..fd7ed225a1d6 100644 --- a/src/bin_dal_node/cli.ml +++ b/src/bin_dal_node/cli.ml @@ -38,7 +38,7 @@ module Term = struct let data_dir = let open Cmdliner in - let default = Configuration.default_data_dir in + let default = Configuration_file.default_data_dir in let doc = Format.sprintf "The directory where the octez DAL node will store all its data. \ @@ -49,7 +49,7 @@ module Term = struct let rpc_addr = let open Cmdliner in - let default = Configuration.default_rpc_addr in + let default = Configuration_file.default_rpc_addr in let doc = Format.asprintf "The TCP socket point at which this RPC server of this instance can be \ @@ -64,14 +64,14 @@ module Term = struct let expected_pow = let open Cmdliner in - let default = Configuration.default_expected_pow in + let default = Configuration_file.default_expected_pow in let doc = "Expected level of proof-of-work for peers identity." in Arg.( value & opt float default & info ~docs ~doc ~docv:"FLOAT" ["expected-pow"]) let net_addr = let open Cmdliner in - let default = Configuration.default_listen_addr in + let default = Configuration_file.default_listen_addr in let doc = Format.asprintf "The TCP address and port at which this instance can be reached by \ diff --git a/src/bin_dal_node/configuration.ml b/src/bin_dal_node/configuration_file.ml similarity index 99% rename from src/bin_dal_node/configuration.ml rename to src/bin_dal_node/configuration_file.ml index deaff1514275..c0c3b42533d2 100644 --- a/src/bin_dal_node/configuration.ml +++ b/src/bin_dal_node/configuration_file.ml @@ -1,7 +1,7 @@ (*****************************************************************************) (* *) (* Open Source License *) -(* Copyright (c) 2021-2022 Nomadic Labs, *) +(* Copyright (c) 2021-2023 Nomadic Labs, *) (* *) (* Permission is hereby granted, free of charge, to any person obtaining a *) (* copy of this software and associated documentation files (the "Software"),*) diff --git a/src/bin_dal_node/configuration.mli b/src/bin_dal_node/configuration_file.mli similarity index 98% rename from src/bin_dal_node/configuration.mli rename to src/bin_dal_node/configuration_file.mli index 7b31d1e6eb74..644be9269865 100644 --- a/src/bin_dal_node/configuration.mli +++ b/src/bin_dal_node/configuration_file.mli @@ -1,7 +1,7 @@ (*****************************************************************************) (* *) (* Open Source License *) -(* Copyright (c) 2022 Nomadic Labs, *) +(* Copyright (c) 2023 Nomadic Labs, *) (* *) (* Permission is hereby granted, free of charge, to any person obtaining a *) (* copy of this software and associated documentation files (the "Software"),*) diff --git a/src/bin_dal_node/daemon.ml b/src/bin_dal_node/daemon.ml index 1a0cc1391d83..197003183591 100644 --- a/src/bin_dal_node/daemon.ml +++ b/src/bin_dal_node/daemon.ml @@ -161,7 +161,9 @@ module Handler = struct Dal_plugin.get_constants `Main (`Head 0) cctxt in let* cryptobox = - init_cryptobox config.Configuration.use_unsafe_srs proto_parameters + init_cryptobox + config.Configuration_file.use_unsafe_srs + proto_parameters in Node_context.set_ready ctxt plugin cryptobox proto_parameters ; (* FIXME: https://gitlab.com/tezos/tezos/-/issues/4441 @@ -333,7 +335,7 @@ let run ~data_dir cctxt = in let*! () = Event.(emit starting_node) () in let* ({network_name; rpc_addr; peers; _} as config) = - Configuration.load ~data_dir + Configuration_file.load ~data_dir in let*! () = Event.(emit configuration_loaded) () in let config = {config with data_dir} in diff --git a/src/bin_dal_node/main.ml b/src/bin_dal_node/main.ml index e058c9b62a66..ffcd44776d84 100644 --- a/src/bin_dal_node/main.ml +++ b/src/bin_dal_node/main.ml @@ -39,7 +39,7 @@ let run subcommand Lwt_main.run @@ Daemon.run ~data_dir rpc_context | Config_init -> let config = - Configuration. + Configuration_file. { data_dir; rpc_addr; @@ -51,7 +51,7 @@ let run subcommand network_name = default_network_name; } in - Lwt_main.run @@ Configuration.save config + Lwt_main.run @@ Configuration_file.save config let _ = let commands = Cli.make ~run in diff --git a/src/bin_dal_node/node_context.ml b/src/bin_dal_node/node_context.ml index 67ee03419851..33066bb037c8 100644 --- a/src/bin_dal_node/node_context.ml +++ b/src/bin_dal_node/node_context.ml @@ -36,7 +36,7 @@ type status = Ready of ready_ctxt | Starting type t = { mutable status : status; - config : Configuration.t; + config : Configuration_file.t; store : Store.node_store; tezos_node_cctxt : Tezos_rpc.Context.generic; neighbors_cctxts : Dal_node_client.cctxt list; @@ -48,12 +48,12 @@ type t = { let init config store gs_worker transport_layer cctxt = let neighbors_cctxts = List.map - (fun Configuration.{addr; port} -> + (fun Configuration_file.{addr; port} -> let endpoint = Uri.of_string ("http://" ^ addr ^ ":" ^ string_of_int port) in Dal_node_client.make_unix_cctxt endpoint) - config.Configuration.neighbors + config.Configuration_file.neighbors in { status = Starting; diff --git a/src/bin_dal_node/node_context.mli b/src/bin_dal_node/node_context.mli index 73f2f86dce4e..26086a2e0300 100644 --- a/src/bin_dal_node/node_context.mli +++ b/src/bin_dal_node/node_context.mli @@ -49,7 +49,7 @@ type t node store [store], gossipsub worker instance [gs_worker], transport layer instance [transport_layer], and tezos node client context [cctx]. *) val init : - Configuration.t -> + Configuration_file.t -> Store.node_store -> Gossipsub.Worker.t -> Gossipsub.Transport_layer.t -> @@ -79,7 +79,7 @@ type error += Node_not_ready val get_ready : t -> ready_ctxt tzresult (** [get_config ctxt] returns the dal node configuration *) -val get_config : t -> Configuration.t +val get_config : t -> Configuration_file.t (** [get_status ctxt] returns the dal node status *) val get_status : t -> status diff --git a/src/bin_dal_node/store.ml b/src/bin_dal_node/store.ml index 6b7d7fbeb3c0..a6d4df79bfef 100644 --- a/src/bin_dal_node/store.ml +++ b/src/bin_dal_node/store.ml @@ -125,7 +125,7 @@ let open_shards_stream {shards_watcher; _} = given [config] and [gs_worker]. *) let init gs_worker config = let open Lwt_result_syntax in - let base_dir = Configuration.data_dir_path config path in + let base_dir = Configuration_file.data_dir_path config path in let shards_watcher = Lwt_watcher.create_input () in let*! repo = Repo.v (Irmin_pack.config base_dir) in let*! store = main repo in diff --git a/src/bin_dal_node/transport_layer_parameters.ml b/src/bin_dal_node/transport_layer_parameters.ml index f4329d2f0dce..ea70d9d7c235 100644 --- a/src/bin_dal_node/transport_layer_parameters.ml +++ b/src/bin_dal_node/transport_layer_parameters.ml @@ -33,10 +33,10 @@ let init_identity_file ~data_dir ~expected_pow = node ? *) return_unit in - let identity_file = Configuration.identity_file ~data_dir in + let identity_file = Configuration_file.identity_file ~data_dir in Identity_file.init ~check_data_dir ~identity_file ~expected_pow -let p2p_config Configuration.{expected_pow; data_dir; listen_addr; _} = +let p2p_config Configuration_file.{expected_pow; data_dir; listen_addr; _} = let open Lwt_result_syntax in let open Gossipsub.Transport_layer.Default_parameters in let* identity = init_identity_file ~data_dir ~expected_pow in @@ -56,7 +56,7 @@ let p2p_config Configuration.{expected_pow; data_dir; listen_addr; _} = discovery_addr; advertised_port = Some p2p_port; trusted_points; - peers_file = Configuration.peers_file ~data_dir; + peers_file = Configuration_file.peers_file ~data_dir; private_mode; identity; proof_of_work_target = proof_of_work_target'; diff --git a/src/bin_dal_node/transport_layer_parameters.mli b/src/bin_dal_node/transport_layer_parameters.mli index 3afac58ea90d..8adf4fc9c24b 100644 --- a/src/bin_dal_node/transport_layer_parameters.mli +++ b/src/bin_dal_node/transport_layer_parameters.mli @@ -24,6 +24,6 @@ (* *) (*****************************************************************************) -val p2p_config : Configuration.t -> (P2p.config, tztrace) result Lwt.t +val p2p_config : Configuration_file.t -> (P2p.config, tztrace) result Lwt.t val p2p_limits : P2p_limits.t -- GitLab From 98cff5e5067228f66690271054864b1e5eaa6971 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Thir=C3=A9?= Date: Mon, 19 Jun 2023 12:25:44 +0200 Subject: [PATCH 4/9] DAL/Node: Add an option to set an endpoint in the configuration --- src/bin_dal_node/cli.ml | 8 +++--- src/bin_dal_node/cli.mli | 2 +- src/bin_dal_node/configuration_file.ml | 35 ++++++++++++++++++++++--- src/bin_dal_node/configuration_file.mli | 3 +++ src/bin_dal_node/main.ml | 5 ++-- 5 files changed, 42 insertions(+), 11 deletions(-) diff --git a/src/bin_dal_node/cli.ml b/src/bin_dal_node/cli.ml index fd7ed225a1d6..c074ce250198 100644 --- a/src/bin_dal_node/cli.ml +++ b/src/bin_dal_node/cli.ml @@ -95,7 +95,7 @@ module Term = struct let endpoint = let open Cmdliner in - let doc = "The octez-node that the DAL node should connect to." in + let doc = "The Tezos node that the DAL node should connect to." in Arg.( value & opt endpoint_arg (Uri.of_string "http://localhost:9732") @@ -169,14 +169,14 @@ type options = { rpc_addr : P2p_point.Id.t; expected_pow : float; net_addr : P2p_point.Id.t; - octez_node : Uri.t; + endpoint : Uri.t; use_unsafe_srs_for_tests : bool; } type t = Run | Config_init let make ~run = - let run subcommand data_dir rpc_addr expected_pow net_addr octez_node + let run subcommand data_dir rpc_addr expected_pow net_addr endpoint use_unsafe_srs_for_tests = run subcommand @@ -185,7 +185,7 @@ let make ~run = rpc_addr; expected_pow; net_addr; - octez_node; + endpoint; use_unsafe_srs_for_tests; } |> function diff --git a/src/bin_dal_node/cli.mli b/src/bin_dal_node/cli.mli index 6c997544089e..ff227da12125 100644 --- a/src/bin_dal_node/cli.mli +++ b/src/bin_dal_node/cli.mli @@ -37,7 +37,7 @@ type options = { expected_pow : float; (** The expected proof of work for the P2P identity. *) net_addr : P2p_point.Id.t; (** The endpoint on which the DAL node can be contacted by other DAL nodes. *) - octez_node : Uri.t; (** The endpoint on which to contact the L1 node. *) + endpoint : Uri.t; (** The endpoint on which to contact the L1 node. *) use_unsafe_srs_for_tests : bool; } diff --git a/src/bin_dal_node/configuration_file.ml b/src/bin_dal_node/configuration_file.ml index c0c3b42533d2..64fdfd220041 100644 --- a/src/bin_dal_node/configuration_file.ml +++ b/src/bin_dal_node/configuration_file.ml @@ -34,6 +34,7 @@ type t = { peers : P2p_point.Id.t list; expected_pow : float; network_name : string; + endpoint : Uri.t; } let default_data_dir = Filename.concat (Sys.getenv "HOME") ".tezos-dal-node" @@ -64,6 +65,8 @@ let default_expected_pow = let default_network_name = "dal-sandbox" +let default_endpoint = Uri.of_string "http://localhost:9732" + let default = { use_unsafe_srs = false; @@ -74,6 +77,7 @@ let default = peers = default_peers; expected_pow = default_expected_pow; network_name = default_network_name; + endpoint = default_endpoint; } let neighbor_encoding : neighbor Data_encoding.t = @@ -83,6 +87,20 @@ let neighbor_encoding : neighbor Data_encoding.t = (fun (addr, port) -> {addr; port}) (obj2 (req "rpc-addr" string) (req "rpc-port" uint16)) +let endpoint_encoding : Uri.t Data_encoding.t = + let open Data_encoding in + conv_with_guard + (fun uri -> Uri.to_string uri) + (fun str -> + try Uri.of_string str |> Result.ok + with exn -> + Format.asprintf + "endpoint decoding failed:@.%a@." + Error_monad.pp_print_trace + [Exn exn] + |> Result.error) + string + let encoding : t Data_encoding.t = let open Data_encoding in conv @@ -95,6 +113,7 @@ let encoding : t Data_encoding.t = peers; expected_pow; network_name; + endpoint; } -> ( use_unsafe_srs, data_dir, @@ -103,7 +122,8 @@ let encoding : t Data_encoding.t = neighbors, peers, expected_pow, - network_name )) + network_name, + endpoint )) (fun ( use_unsafe_srs, data_dir, rpc_addr, @@ -111,7 +131,8 @@ let encoding : t Data_encoding.t = neighbors, peers, expected_pow, - network_name ) -> + network_name, + endpoint ) -> { use_unsafe_srs; data_dir; @@ -121,8 +142,9 @@ let encoding : t Data_encoding.t = peers; expected_pow; network_name; + endpoint; }) - (obj8 + (obj9 (dft "use_unsafe_srs" ~description:"use unsafe srs for tests" @@ -162,7 +184,12 @@ let encoding : t Data_encoding.t = "network-name" ~description:"The name that identifies the network" string - default_network_name)) + default_network_name) + (dft + "endpoint" + ~description:"The Tezos node endpoint" + endpoint_encoding + default_endpoint)) 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 644be9269865..f6dd3c33a453 100644 --- a/src/bin_dal_node/configuration_file.mli +++ b/src/bin_dal_node/configuration_file.mli @@ -38,6 +38,7 @@ type t = { expected_pow : float; (** Expected P2P identity's PoW. *) network_name : string; (** A string that identifies the network's name. E.g. dal-sandbox. *) + endpoint : Uri.t; (** Endpoint of a Tezos node *) } (** [default] is the default configuration. *) @@ -58,6 +59,8 @@ val default_expected_pow : float val default_network_name : string +val default_endpoint : Uri.t + (** The default TCP address and port at which this instance can be reached. *) val default_listen_addr : P2p_point.Id.t diff --git a/src/bin_dal_node/main.ml b/src/bin_dal_node/main.ml index ffcd44776d84..e0e592a7b1ba 100644 --- a/src/bin_dal_node/main.ml +++ b/src/bin_dal_node/main.ml @@ -27,7 +27,7 @@ let run subcommand Cli. { data_dir; - octez_node; + endpoint; rpc_addr; expected_pow; net_addr; @@ -35,7 +35,7 @@ let run subcommand } = match subcommand with | Cli.Run -> - let rpc_context = Rpc_context.make octez_node in + let rpc_context = Rpc_context.make endpoint in Lwt_main.run @@ Daemon.run ~data_dir rpc_context | Config_init -> let config = @@ -49,6 +49,7 @@ let run subcommand listen_addr = net_addr; expected_pow; network_name = default_network_name; + endpoint = default_endpoint; } in Lwt_main.run @@ Configuration_file.save config -- GitLab From 5092ade8ffc8182e95e37bd0618df704af3833d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Thir=C3=A9?= Date: Mon, 19 Jun 2023 15:13:29 +0200 Subject: [PATCH 5/9] DAL/Node: Only export default value --- src/bin_dal_node/cli.ml | 8 ++++---- src/bin_dal_node/configuration_file.mli | 13 ------------- src/bin_dal_node/main.ml | 8 ++++---- 3 files changed, 8 insertions(+), 21 deletions(-) diff --git a/src/bin_dal_node/cli.ml b/src/bin_dal_node/cli.ml index c074ce250198..5957926cecd7 100644 --- a/src/bin_dal_node/cli.ml +++ b/src/bin_dal_node/cli.ml @@ -38,7 +38,7 @@ module Term = struct let data_dir = let open Cmdliner in - let default = Configuration_file.default_data_dir in + let default = Configuration_file.default.data_dir in let doc = Format.sprintf "The directory where the octez DAL node will store all its data. \ @@ -49,7 +49,7 @@ module Term = struct let rpc_addr = let open Cmdliner in - let default = Configuration_file.default_rpc_addr in + let default = Configuration_file.default.rpc_addr in let doc = Format.asprintf "The TCP socket point at which this RPC server of this instance can be \ @@ -64,14 +64,14 @@ module Term = struct let expected_pow = let open Cmdliner in - let default = Configuration_file.default_expected_pow in + let default = Configuration_file.default.expected_pow in let doc = "Expected level of proof-of-work for peers identity." in Arg.( value & opt float default & info ~docs ~doc ~docv:"FLOAT" ["expected-pow"]) let net_addr = let open Cmdliner in - let default = Configuration_file.default_listen_addr in + let default = Configuration_file.default.listen_addr in let doc = Format.asprintf "The TCP address and port at which this instance can be reached by \ diff --git a/src/bin_dal_node/configuration_file.mli b/src/bin_dal_node/configuration_file.mli index f6dd3c33a453..fdf2be094518 100644 --- a/src/bin_dal_node/configuration_file.mli +++ b/src/bin_dal_node/configuration_file.mli @@ -51,19 +51,6 @@ val filename : t -> string [config] *) val data_dir_path : t -> string -> string -val default_data_dir : string - -val default_rpc_addr : P2p_point.Id.t - -val default_expected_pow : float - -val default_network_name : string - -val default_endpoint : Uri.t - -(** The default TCP address and port at which this instance can be reached. *) -val default_listen_addr : P2p_point.Id.t - (** [save config] writes config file in [config.data_dir] *) val save : t -> unit tzresult Lwt.t diff --git a/src/bin_dal_node/main.ml b/src/bin_dal_node/main.ml index e0e592a7b1ba..5460df621de5 100644 --- a/src/bin_dal_node/main.ml +++ b/src/bin_dal_node/main.ml @@ -44,12 +44,12 @@ let run subcommand data_dir; rpc_addr; use_unsafe_srs = use_unsafe_srs_for_tests; - neighbors = []; - peers = []; + neighbors = default.neighbors; + peers = default.peers; listen_addr = net_addr; expected_pow; - network_name = default_network_name; - endpoint = default_endpoint; + network_name = default.network_name; + endpoint = default.endpoint; } in Lwt_main.run @@ Configuration_file.save config -- GitLab From f4e9726c1ce987831d3d279eaa2d4284cd18ed75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Thir=C3=A9?= Date: Mon, 19 Jun 2023 15:22:44 +0200 Subject: [PATCH 6/9] DAL/Node: Simplify handling of configuration filename --- src/bin_dal_node/configuration_file.ml | 10 ++++------ src/bin_dal_node/configuration_file.mli | 3 --- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/bin_dal_node/configuration_file.ml b/src/bin_dal_node/configuration_file.ml index 64fdfd220041..822f597fd55e 100644 --- a/src/bin_dal_node/configuration_file.ml +++ b/src/bin_dal_node/configuration_file.ml @@ -41,10 +41,6 @@ let default_data_dir = Filename.concat (Sys.getenv "HOME") ".tezos-dal-node" let data_dir_path config subpath = Filename.concat config.data_dir subpath -let relative_filename data_dir = Filename.concat data_dir "config.json" - -let filename config = relative_filename config.data_dir - let default_rpc_addr = P2p_point.Id.of_string_exn ~default_port:10732 "127.0.0.1" @@ -207,9 +203,11 @@ let () = | _ -> None) (fun path -> DAL_node_unable_to_write_configuration_file path) +let filename ~data_dir = Filename.concat data_dir "config.json" + let save config = let open Lwt_syntax in - let file = filename config in + let file = filename ~data_dir:config.data_dir in protect @@ fun () -> let* v = let* () = Lwt_utils_unix.create_dir config.data_dir in @@ -226,7 +224,7 @@ let save config = let load ~data_dir = let open Lwt_result_syntax in let+ json = - let*! json = Lwt_utils_unix.Json.read_file (relative_filename data_dir) in + let*! json = Lwt_utils_unix.Json.read_file (filename ~data_dir) in match json with | Ok json -> return json | Error (Exn _ :: _ as e) -> diff --git a/src/bin_dal_node/configuration_file.mli b/src/bin_dal_node/configuration_file.mli index fdf2be094518..9b027558353a 100644 --- a/src/bin_dal_node/configuration_file.mli +++ b/src/bin_dal_node/configuration_file.mli @@ -44,9 +44,6 @@ type t = { (** [default] is the default configuration. *) val default : t -(** [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 -- GitLab From 1df3cd61bd7d27e54692a298e7d6a12c5f528cb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Thir=C3=A9?= Date: Mon, 19 Jun 2023 15:24:56 +0200 Subject: [PATCH 7/9] DAL/Node: Simplify the store path handling --- src/bin_dal_node/configuration_file.ml | 2 +- src/bin_dal_node/configuration_file.mli | 5 ++--- src/bin_dal_node/store.ml | 5 +---- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/bin_dal_node/configuration_file.ml b/src/bin_dal_node/configuration_file.ml index 822f597fd55e..b601cdc0e5c9 100644 --- a/src/bin_dal_node/configuration_file.ml +++ b/src/bin_dal_node/configuration_file.ml @@ -39,7 +39,7 @@ type t = { let default_data_dir = Filename.concat (Sys.getenv "HOME") ".tezos-dal-node" -let data_dir_path config subpath = Filename.concat config.data_dir subpath +let store_path {data_dir; _} = Filename.concat data_dir "store" let default_rpc_addr = P2p_point.Id.of_string_exn ~default_port:10732 "127.0.0.1" diff --git a/src/bin_dal_node/configuration_file.mli b/src/bin_dal_node/configuration_file.mli index 9b027558353a..d6ba165f1776 100644 --- a/src/bin_dal_node/configuration_file.mli +++ b/src/bin_dal_node/configuration_file.mli @@ -44,9 +44,8 @@ type t = { (** [default] is the default configuration. *) val default : t -(** [data_dir_path config subpath] builds a subpath relatively to the - [config] *) -val data_dir_path : t -> string -> string +(** [store_path config] returns a path for the store *) +val store_path : t -> string (** [save config] writes config file in [config.data_dir] *) val save : t -> unit tzresult Lwt.t diff --git a/src/bin_dal_node/store.ml b/src/bin_dal_node/store.ml index a6d4df79bfef..daf41a642f25 100644 --- a/src/bin_dal_node/store.ml +++ b/src/bin_dal_node/store.ml @@ -29,9 +29,6 @@ (* FIXME: https://gitlab.com/tezos/tezos/-/issues/4097 Add an interface to this module *) -(* Relative path to store directory from base-dir *) -let path = "store" - module StoreMaker = Irmin_pack_unix.KV (Tezos_context_encoding.Context.Conf) include StoreMaker.Make (Irmin.Contents.String) @@ -125,7 +122,7 @@ let open_shards_stream {shards_watcher; _} = given [config] and [gs_worker]. *) let init gs_worker config = let open Lwt_result_syntax in - let base_dir = Configuration_file.data_dir_path config path in + let base_dir = Configuration_file.store_path config in let shards_watcher = Lwt_watcher.create_input () in let*! repo = Repo.v (Irmin_pack.config base_dir) in let*! store = main repo in -- GitLab From 243ebe053de537fe16eba9574cb54e6b397ea0e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Thir=C3=A9?= Date: Mon, 19 Jun 2023 15:29:24 +0200 Subject: [PATCH 8/9] DAL/Node: Simplify handling of configuration file in P2P part --- src/bin_dal_node/configuration_file.ml | 4 ++-- src/bin_dal_node/configuration_file.mli | 15 ++++++------- .../transport_layer_parameters.ml | 21 ++++++++++++------- 3 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/bin_dal_node/configuration_file.ml b/src/bin_dal_node/configuration_file.ml index b601cdc0e5c9..df9fb8392e47 100644 --- a/src/bin_dal_node/configuration_file.ml +++ b/src/bin_dal_node/configuration_file.ml @@ -235,6 +235,6 @@ let load ~data_dir = let config = Data_encoding.Json.destruct encoding json in {config with data_dir} -let identity_file ~data_dir = Filename.concat data_dir "identity.json" +let identity_file {data_dir; _} = Filename.concat data_dir "identity.json" -let peers_file ~data_dir = Filename.concat data_dir "peers.json" +let peers_file {data_dir; _} = Filename.concat data_dir "peers.json" diff --git a/src/bin_dal_node/configuration_file.mli b/src/bin_dal_node/configuration_file.mli index d6ba165f1776..8fa0265dc24d 100644 --- a/src/bin_dal_node/configuration_file.mli +++ b/src/bin_dal_node/configuration_file.mli @@ -52,10 +52,11 @@ val save : t -> unit tzresult Lwt.t val load : data_dir:string -> (t, Error_monad.tztrace) result Lwt.t -(** [identity_file data_dir] returns the absolute path to the "identity.json" - file of the DAL node, based on the given [data_dir]. *) -val identity_file : data_dir:string -> string - -(** [peers_file data_dir] returns the absolute path to the "peers.json" file of - the DAL node, based on the given [data_dir]. *) -val peers_file : data_dir:string -> string +(** [identity_file t] returns the absolute path to the "identity.json" + file of the DAL node, based on the configuration [t]. *) +val identity_file : t -> string + +(** [peers_file data_dir] returns the absolute path to the + "peers.json" file of the DAL node, based on the configuration + [t]. *) +val peers_file : t -> string diff --git a/src/bin_dal_node/transport_layer_parameters.ml b/src/bin_dal_node/transport_layer_parameters.ml index ea70d9d7c235..f744651bf519 100644 --- a/src/bin_dal_node/transport_layer_parameters.ml +++ b/src/bin_dal_node/transport_layer_parameters.ml @@ -24,7 +24,7 @@ (* *) (*****************************************************************************) -let init_identity_file ~data_dir ~expected_pow = +let init_identity_file configuration = let open Lwt_result_syntax in let check_data_dir ~data_dir:_ = (* FIXME: https://gitlab.com/tezos/tezos/-/issues/5566 @@ -33,20 +33,25 @@ let init_identity_file ~data_dir ~expected_pow = node ? *) return_unit in - let identity_file = Configuration_file.identity_file ~data_dir in - Identity_file.init ~check_data_dir ~identity_file ~expected_pow + let identity_file = Configuration_file.identity_file configuration in + Identity_file.init + ~check_data_dir + ~identity_file + ~expected_pow:configuration.expected_pow -let p2p_config Configuration_file.{expected_pow; data_dir; listen_addr; _} = +let p2p_config configuration = let open Lwt_result_syntax in let open Gossipsub.Transport_layer.Default_parameters in - let* identity = init_identity_file ~data_dir ~expected_pow in - let p2p_addr, p2p_port = listen_addr in + let* identity = init_identity_file configuration in + let p2p_addr, p2p_port = configuration.listen_addr in let reconnection_config = let open P2p_reconnection_config in Point_reconnection_config. {factor; initial_delay; disconnection_delay; increase_cap} in - let proof_of_work_target' = Crypto_box.make_pow_target expected_pow in + let proof_of_work_target' = + Crypto_box.make_pow_target configuration.expected_pow + in let config = let open P2p_config in { @@ -56,7 +61,7 @@ let p2p_config Configuration_file.{expected_pow; data_dir; listen_addr; _} = discovery_addr; advertised_port = Some p2p_port; trusted_points; - peers_file = Configuration_file.peers_file ~data_dir; + peers_file = Configuration_file.peers_file configuration; private_mode; identity; proof_of_work_target = proof_of_work_target'; -- GitLab From c1b8937498a527670ac2c55b3560743dd5efe054 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Thir=C3=A9?= Date: Mon, 19 Jun 2023 15:48:05 +0200 Subject: [PATCH 9/9] DAL/Node: Rename net_addr option internally into listen_addr --- src/bin_dal_node/cli.ml | 6 +++--- src/bin_dal_node/cli.mli | 2 +- src/bin_dal_node/main.ml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/bin_dal_node/cli.ml b/src/bin_dal_node/cli.ml index 5957926cecd7..76f2cc40c223 100644 --- a/src/bin_dal_node/cli.ml +++ b/src/bin_dal_node/cli.ml @@ -168,7 +168,7 @@ type options = { data_dir : string; rpc_addr : P2p_point.Id.t; expected_pow : float; - net_addr : P2p_point.Id.t; + listen_addr : P2p_point.Id.t; endpoint : Uri.t; use_unsafe_srs_for_tests : bool; } @@ -176,7 +176,7 @@ type options = { type t = Run | Config_init let make ~run = - let run subcommand data_dir rpc_addr expected_pow net_addr endpoint + let run subcommand data_dir rpc_addr expected_pow listen_addr endpoint use_unsafe_srs_for_tests = run subcommand @@ -184,7 +184,7 @@ let make ~run = data_dir; rpc_addr; expected_pow; - net_addr; + listen_addr; endpoint; use_unsafe_srs_for_tests; } diff --git a/src/bin_dal_node/cli.mli b/src/bin_dal_node/cli.mli index ff227da12125..e556210b0f70 100644 --- a/src/bin_dal_node/cli.mli +++ b/src/bin_dal_node/cli.mli @@ -35,7 +35,7 @@ type options = { rpc_addr : P2p_point.Id.t; (** The endpoint on which the DAL node can be contacted for RPCs. *) expected_pow : float; (** The expected proof of work for the P2P identity. *) - net_addr : P2p_point.Id.t; + listen_addr : P2p_point.Id.t; (** The endpoint on which the DAL node can be contacted by other DAL nodes. *) endpoint : Uri.t; (** The endpoint on which to contact the L1 node. *) use_unsafe_srs_for_tests : bool; diff --git a/src/bin_dal_node/main.ml b/src/bin_dal_node/main.ml index 5460df621de5..7ea695fd91de 100644 --- a/src/bin_dal_node/main.ml +++ b/src/bin_dal_node/main.ml @@ -30,7 +30,7 @@ let run subcommand endpoint; rpc_addr; expected_pow; - net_addr; + listen_addr; use_unsafe_srs_for_tests; } = match subcommand with @@ -46,7 +46,7 @@ let run subcommand use_unsafe_srs = use_unsafe_srs_for_tests; neighbors = default.neighbors; peers = default.peers; - listen_addr = net_addr; + listen_addr; expected_pow; network_name = default.network_name; endpoint = default.endpoint; -- GitLab