diff --git a/manifest/main.ml b/manifest/main.ml index 78730ac87e70083bab1de4b8f245d850fe3aa265..2c0e23e89a6c82e1b169655a4d7231c547e6f8e9 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/RPC_server.ml b/src/bin_dal_node/RPC_server.ml index 8989c1e3b5226eb4f0e00daf8d4590e9ef8737c1..891502307bb80339827bf389aa312b49a874934e 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 d0393391c3f7960db6678893456af58e42219325..76f2cc40c223e53f23caf7b6cbe71d7122d73c08 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 \ @@ -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") @@ -168,15 +168,15 @@ type options = { data_dir : string; rpc_addr : P2p_point.Id.t; expected_pow : float; - net_addr : P2p_point.Id.t; - octez_node : Uri.t; + listen_addr : P2p_point.Id.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 listen_addr endpoint use_unsafe_srs_for_tests = run subcommand @@ -184,8 +184,8 @@ let make ~run = data_dir; rpc_addr; expected_pow; - net_addr; - octez_node; + listen_addr; + endpoint; use_unsafe_srs_for_tests; } |> function diff --git a/src/bin_dal_node/cli.mli b/src/bin_dal_node/cli.mli index 6c997544089e12a2af9b8c6cb61b8f2f20a44c4a..e556210b0f702fd73496b0b11e61fd1d63542ec6 100644 --- a/src/bin_dal_node/cli.mli +++ b/src/bin_dal_node/cli.mli @@ -35,9 +35,9 @@ 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. *) - 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.ml b/src/bin_dal_node/configuration_file.ml similarity index 80% rename from src/bin_dal_node/configuration.ml rename to src/bin_dal_node/configuration_file.ml index 28638a840505f9184ba15fa7d4121bd7b1b3769c..df9fb8392e47776d6883c776453b5cfc64d59af5 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"),*) @@ -34,15 +34,12 @@ 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" -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 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" @@ -64,6 +61,21 @@ 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; + 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; + endpoint = default_endpoint; + } + let neighbor_encoding : neighbor Data_encoding.t = let open Data_encoding in conv @@ -71,6 +83,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 @@ -83,6 +109,7 @@ let encoding : t Data_encoding.t = peers; expected_pow; network_name; + endpoint; } -> ( use_unsafe_srs, data_dir, @@ -91,7 +118,8 @@ let encoding : t Data_encoding.t = neighbors, peers, expected_pow, - network_name )) + network_name, + endpoint )) (fun ( use_unsafe_srs, data_dir, rpc_addr, @@ -99,7 +127,8 @@ let encoding : t Data_encoding.t = neighbors, peers, expected_pow, - network_name ) -> + network_name, + endpoint ) -> { use_unsafe_srs; data_dir; @@ -109,8 +138,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" @@ -150,7 +180,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 @@ -168,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 @@ -187,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) -> @@ -198,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.mli b/src/bin_dal_node/configuration_file.mli similarity index 75% rename from src/bin_dal_node/configuration.mli rename to src/bin_dal_node/configuration_file.mli index f35751a2b43255de58aaa1c250b481d6de0e4ab7..8fa0265dc24dca53be2a24fb3f0f445cdebdca79 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"),*) @@ -38,35 +38,25 @@ 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 *) } -(** [filename config] gets the path to config file *) -val filename : t -> string +(** [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 - -val default_data_dir : string - -val default_rpc_addr : P2p_point.Id.t - -val default_expected_pow : float - -val default_network_name : string - -(** The default TCP address and port at which this instance can be reached. *) -val default_listen_addr : P2p_point.Id.t +(** [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 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 +(** [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 given [data_dir]. *) -val peers_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 configuration + [t]. *) +val peers_file : t -> string diff --git a/src/bin_dal_node/daemon.ml b/src/bin_dal_node/daemon.ml index 1a0cc1391d833a9e95688776ae505793491ee838..19700318359194b0639f88fc0cb13348437bc539 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/dune b/src/bin_dal_node/dune index a5cd2a1b0c55923484e9fb39a23b75bc259954bc..1df9f83c4ac2e36db1e867f002014790f8b91e0b 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 86% rename from src/bin_dal_node/main_dal.ml rename to src/bin_dal_node/main.ml index e058c9b62a662ac98080595a3218d0dc209ca085..7ea695fd91de63f44ac70976057093e530ffe257 100644 --- a/src/bin_dal_node/main_dal.ml +++ b/src/bin_dal_node/main.ml @@ -27,31 +27,32 @@ let run subcommand Cli. { data_dir; - octez_node; + endpoint; rpc_addr; expected_pow; - net_addr; + listen_addr; use_unsafe_srs_for_tests; } = 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 = - Configuration. + Configuration_file. { data_dir; rpc_addr; use_unsafe_srs = use_unsafe_srs_for_tests; - neighbors = []; - peers = []; - listen_addr = net_addr; + neighbors = default.neighbors; + peers = default.peers; + listen_addr; expected_pow; - network_name = default_network_name; + network_name = default.network_name; + endpoint = default.endpoint; } 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 67ee03419851780cf7e016d8491cfbf99ab93dea..33066bb037c8fb7ee3e6097bf1b7b6566b22d044 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 73f2f86dce4e91fdb6562bd598e24bf833289868..26086a2e030020d0da4c7dcf0b373b1275f49d35 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 6b7d7fbeb3c06405fcc390cf2f643ad861d44a16..daf41a642f25e5fd52c8fd5aca102010cc52b490 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.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 diff --git a/src/bin_dal_node/transport_layer_parameters.ml b/src/bin_dal_node/transport_layer_parameters.ml index f4329d2f0dce29663f35dae600bb0431273b97fb..f744651bf5190fb1ccd462eea0dbe9fcb1eef87a 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.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.{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.{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 configuration; 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 3afac58ea90d9463db0dc4c25da608b54467461c..8adf4fc9c24b6d51b3ad424663bdb440375fe01f 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