diff --git a/src/bin_dal_node/configuration_file.ml b/src/bin_dal_node/configuration_file.ml index 38fd918fc406a4a9c72a749e0e0cdb1979ee3267..872f43630893905bb2d955f8095df01a769e9c35 100644 --- a/src/bin_dal_node/configuration_file.ml +++ b/src/bin_dal_node/configuration_file.ml @@ -106,7 +106,7 @@ let default_peers = [] let default_expected_pow = Gossipsub.Transport_layer.Default_parameters.P2p_config.expected_pow -let default_network_name = "dal-sandbox" +let legacy_network_name = "dal-sandbox" let default_endpoint = Uri.of_string "http://localhost:8732" @@ -372,7 +372,7 @@ module V0 = struct (dft "neighbors" (list neighbor_encoding) default_neighbors) (dft "peers" (list string) default_peers) (dft "expected-pow" float default_expected_pow) - (dft "network-name" string default_network_name) + (dft "network-name" string legacy_network_name) (dft "endpoint" endpoint_encoding default_endpoint) (dft "metrics-addr" P2p_point.Id.encoding default_metrics_addr)) (obj2 @@ -463,7 +463,7 @@ module V1 = struct (dft "neighbors" (list neighbor_encoding) default_neighbors) (dft "peers" (list string) default_peers) (dft "expected-pow" float default_expected_pow) - (dft "network-name" string default_network_name) + (dft "network-name" string legacy_network_name) (dft "endpoint" endpoint_encoding default_endpoint) (dft "metrics-addr" (Encoding.option P2p_point.Id.encoding) None)) (obj8 diff --git a/src/bin_dal_node/configuration_file.mli b/src/bin_dal_node/configuration_file.mli index f378c2382c3b288a794ae26483816e9643a6ad98..2c05ffc89ae5c0cc13811db52301bf9884b9aace 100644 --- a/src/bin_dal_node/configuration_file.mli +++ b/src/bin_dal_node/configuration_file.mli @@ -92,4 +92,4 @@ val identity_file : t -> string file of the DAL node, based on the configuration [config]. *) val peers_file : t -> string -val default_network_name : string +val legacy_network_name : string diff --git a/src/bin_dal_node/daemon.ml b/src/bin_dal_node/daemon.ml index fa0614bdbcff3e1bfc719d5acb115b0e93c4660b..eedd1fcedb2c45e426cb426acc20e85e77cb2e7c 100644 --- a/src/bin_dal_node/daemon.ml +++ b/src/bin_dal_node/daemon.ml @@ -58,6 +58,40 @@ let fetch_dal_config cctxt = ~rpc:Config_services.dal_config ~requested_info:"DAL config" +let fetch_l1_version_info cctxt = + fetch_info_from_l1 + cctxt + ~rpc:Version_services.version + ~requested_info:"version info" + +(* TODO: https://gitlab.com/tezos/tezos/-/issues/7851 + + Remove the legacy case from this function once the migration to V23 is complete. + + The function below infers the DAL network name based on the L1 chain name and + the DAL node version. + + - For DAL node versions <= V22, the legacy "dal-sandbox" network name is used. + - For versions >= V23, the new naming scheme "DAL_" is used. + + This ensures a smooth transition during the migration period. + + For the new naming scheme, the function queries the L1 node to retrieve its + chain name and constructs the corresponding DAL network name by prefixing + it with "DAL_". +*) +let infer_dal_network_name cctxt = + let open Lwt_result_syntax in + let version = Tezos_version_value.Current_git_info.octez_version in + if version.major <= 22 then + return + (Distributed_db_version.Name.of_string + Configuration_file.legacy_network_name) (* legacy "dal-sandbox" *) + else + let+ l1_version = fetch_l1_version_info cctxt in + Format.sprintf "DAL_%s" (l1_version.network_version.chain_name :> string) + |> Distributed_db_version.Name.of_string + let init_cryptobox config proto_parameters = let open Lwt_result_syntax in let prover_srs = @@ -1451,6 +1485,7 @@ let run ~data_dir ~configuration_override = let*! () = Event.emit_configuration_loaded () in let cctxt = Rpc_context.make endpoint in let* dal_config = fetch_dal_config cctxt in + let* network_name = infer_dal_network_name cctxt in let bootstrap_names = points @ dal_config.bootstrap_peers in let*! () = if bootstrap_names = [] then Event.emit_config_error_no_bootstrap () @@ -1543,8 +1578,6 @@ let run ~data_dir ~configuration_override = let points = get_bootstrap_points () in (* Create a transport (P2P) layer instance. *) let* transport_layer = - (* WIP: will be fixed in the next MR. *) - let network_name = Configuration_file.default_network_name in Gossipsub.Transport_layer.create ~public_addr ~is_bootstrap_peer:(profile = Profile_manager.bootstrap) @@ -1629,6 +1662,7 @@ let run ~data_dir ~configuration_override = transport_layer cctxt ~last_finalized_level:head_level + ~network_name in let* () = match Profile_manager.get_profiles profile_ctxt with diff --git a/src/bin_dal_node/node_context.ml b/src/bin_dal_node/node_context.ml index ed6222141b83512469e77e3e7b130d59a3c94abb..60c243ceda9a890118a9d2bb32c093290badcce2 100644 --- a/src/bin_dal_node/node_context.ml +++ b/src/bin_dal_node/node_context.ml @@ -26,6 +26,7 @@ type t = { config : Configuration_file.t; + network_name : Distributed_db_version.Name.t; cryptobox : Cryptobox.t; shards_proofs_precomputation : Cryptobox.shards_proofs_precomputation option; mutable proto_plugins : Proto_plugins.t; @@ -44,8 +45,9 @@ type t = { it is the highest level the node is aware of) *) } -let init config profile_ctxt cryptobox shards_proofs_precomputation - proto_plugins store gs_worker transport_layer cctxt ~last_finalized_level = +let init config ~network_name profile_ctxt cryptobox + shards_proofs_precomputation proto_plugins store gs_worker transport_layer + cctxt ~last_finalized_level = let neighbors_cctxts = (* TODO: This early feature is not used anymore. An MR that cleans this part of the code has been opened here: @@ -54,6 +56,7 @@ let init config profile_ctxt cryptobox shards_proofs_precomputation in { config; + network_name; cryptobox; shards_proofs_precomputation; proto_plugins; @@ -212,9 +215,7 @@ let get_fetched_assigned_shard_indices ctxt ~level ~pkh = |> Option.value ~default:[]) (Committee_cache.find ctxt.committee_cache ~level) -let version _t = - (* WIP: will be fixed in the next MR. *) - let network_name = Configuration_file.default_network_name in +let version {network_name; _} = Types.Version.make ~network_version:(Gossipsub.version ~network_name) let warn_if_attesters_not_delegates ctxt operator_profiles = diff --git a/src/bin_dal_node/node_context.mli b/src/bin_dal_node/node_context.mli index e3666648a30d97d6d12d604af038dc477b73b8b7..7afa2f5a8855c7230d8f144c99ab0ecf8bfe2523 100644 --- a/src/bin_dal_node/node_context.mli +++ b/src/bin_dal_node/node_context.mli @@ -31,6 +31,7 @@ type t (** [init] creates a [t] value based on the given arguments. *) val init : Configuration_file.t -> + network_name:Distributed_db_version.Name.t -> Profile_manager.t -> Cryptobox.t -> Cryptobox.shards_proofs_precomputation option -> diff --git a/src/lib_dal_node/gossipsub/gossipsub.mli b/src/lib_dal_node/gossipsub/gossipsub.mli index f5bef9de2d5ef8c04c28adca61b75897e337b60b..49cf272b60341ea30efe4b71cfe7942b4c919905 100644 --- a/src/lib_dal_node/gossipsub/gossipsub.mli +++ b/src/lib_dal_node/gossipsub/gossipsub.mli @@ -85,7 +85,7 @@ module Transport_layer : sig creates a new instance of type {!t}. It is a wrapper on top of {!P2p.create}. *) val create : - network_name:string -> + network_name:Distributed_db_version.Name.t -> public_addr:P2p_point.Id.t -> is_bootstrap_peer:bool -> P2p.config -> @@ -198,4 +198,4 @@ module Transport_layer_hooks : sig end (** [version ~network_name] returns the current version of the P2P. *) -val version : network_name:string -> Network_version.t +val version : network_name:Distributed_db_version.Name.t -> Network_version.t diff --git a/src/lib_dal_node/gossipsub/transport_layer_interface.ml b/src/lib_dal_node/gossipsub/transport_layer_interface.ml index f8a0323b0670f29f82dcf91b266033fafce308c5..a59fd98a6dc337f53db15637ea4aed6f676e8e06 100644 --- a/src/lib_dal_node/gossipsub/transport_layer_interface.ml +++ b/src/lib_dal_node/gossipsub/transport_layer_interface.ml @@ -210,14 +210,17 @@ module P2p_message_V1 = struct let distributed_db_versions = [distributed_db_version] let message_config ~network_name : p2p_message P2p_params.message_config = - let chain_name = Distributed_db_version.Name.of_string network_name in - {encoding = p2p_message_app_encoding; chain_name; distributed_db_versions} + { + encoding = p2p_message_app_encoding; + chain_name = network_name; + distributed_db_versions; + } end let version ~network_name = Network_version. { - chain_name = Distributed_db_version.Name.of_string network_name; + chain_name = network_name; distributed_db_version = P2p_message_V1.distributed_db_version; p2p_version = P2p_version.one; } diff --git a/src/lib_dal_node/gossipsub/transport_layer_interface.mli b/src/lib_dal_node/gossipsub/transport_layer_interface.mli index 508275946999237a8e20654e6b3201729eef939c..c99e531791ccd42b60ed2cc013bf11b87a3d7ecb 100644 --- a/src/lib_dal_node/gossipsub/transport_layer_interface.mli +++ b/src/lib_dal_node/gossipsub/transport_layer_interface.mli @@ -51,7 +51,7 @@ val pp_p2p_message : (** A P2P message config is parameterized by the network's name. *) val message_config : - network_name:string -> + network_name:Distributed_db_version.Name.t -> Gs_interface.Worker_instance.p2p_message P2p_params.message_config -val version : network_name:string -> Network_version.t +val version : network_name:Distributed_db_version.Name.t -> Network_version.t