From 73dc14e74bc5de2386c5acbc414e957c5f257714 Mon Sep 17 00:00:00 2001 From: Gabriel Moise Date: Fri, 25 Jul 2025 11:54:46 +0100 Subject: [PATCH 1/7] Tezt_cloud: Layer1: Use yes_wallet from Node_helpers --- tezt/tests/cloud/layer1.ml | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/tezt/tests/cloud/layer1.ml b/tezt/tests/cloud/layer1.ml index d528a52ed3da..41b64e542e74 100644 --- a/tezt/tests/cloud/layer1.ml +++ b/tezt/tests/cloud/layer1.ml @@ -196,10 +196,6 @@ module Node = struct let name = Tezt_cloud.Agent.name agent ^ "-client" in Client.Agent.create ~name ~endpoint:(Client.Node node) agent - let yes_wallet agent = - let name = Tezt_cloud.Agent.name agent ^ "-yes-wallet" in - Yes_wallet.Agent.create ~name agent - (** Initialize the node, create the associated client, create the yes-wallet. @@ -216,7 +212,7 @@ module Node = struct migration_offset in let* client = client ~node agent in - let* yes_wallet = yes_wallet agent in + let* yes_wallet = Node_helpers.yes_wallet agent in let* _filename = Yes_wallet.create_from_context ~node @@ -247,7 +243,7 @@ module Node = struct (agent, node, name) in let* client = client ~node agent in - let* yes_wallet = yes_wallet agent in + let* yes_wallet = Node_helpers.yes_wallet agent in let* () = Lwt_list.iter_s (fun {pkh = alias; pk = public_key} -> @@ -270,7 +266,7 @@ module Node = struct (agent, node, name) in let* client = client ~node agent in - let* yes_wallet = yes_wallet agent in + let* yes_wallet = Node_helpers.yes_wallet agent in let* () = Client.forget_all_keys client in let* () = Client.import_public_key ~alias:pkh ~public_key:pk client in let* () = Yes_wallet.convert_wallet_inplace ~client yes_wallet in -- GitLab From d2207f2d16335a650ea7f1db3f075ab27e2b6b46 Mon Sep 17 00:00:00 2001 From: Gabriel Moise Date: Fri, 25 Jul 2025 16:04:54 +0100 Subject: [PATCH 2/7] Tezt_cloud: Layer1: Move add_migration_offset_to_config to Node_helpers --- tezt/tests/cloud/layer1.ml | 42 ++++++++----------------------- tezt/tests/cloud/network.ml | 4 +++ tezt/tests/cloud/network.mli | 2 ++ tezt/tests/cloud/node_helpers.ml | 26 +++++++++++++++++++ tezt/tests/cloud/node_helpers.mli | 11 ++++++++ 5 files changed, 53 insertions(+), 32 deletions(-) diff --git a/tezt/tests/cloud/layer1.ml b/tezt/tests/cloud/layer1.ml index 41b64e542e74..b37401ba1e99 100644 --- a/tezt/tests/cloud/layer1.ml +++ b/tezt/tests/cloud/layer1.ml @@ -82,36 +82,6 @@ module Node = struct [Allow_yes_crypto; Force_history_mode_switch] peers - (** [add_migration_offset_to_config node snapshot ~migration_offset ~network] adds an - entry in the configuration file of [node] to trigger a UAU at level [~migration_offset] - to upgrade to the next protocol of [~network]. This entry is is parametrised by the - information obtained from [snapshot]. *) - let add_migration_offset_to_config node snapshot ~migration_offset ~network = - let* level = get_snapshot_info_level node snapshot in - match migration_offset with - | None -> Lwt.return_unit - | Some migration_offset -> - let* network_config = - match network with - | `Mainnet -> Lwt.return Node.Config_file.mainnet_network_config - | `Ghostnet -> Lwt.return Node.Config_file.ghostnet_network_config - | _ -> - Lwt.fail_with - "Migration scenarios are only supported for Mainnet and \ - Ghostnet." - in - let migration_level = level + migration_offset in - toplog "Add UAU entry for level : %d" migration_level ; - Node.Config_file.update node (fun json -> - JSON.put - ( "network", - JSON.annotate - ~origin:"add_migration_offset_to_config" - network_config ) - json - |> Node.Config_file.update_network_with_user_activated_upgrades - [(migration_level, Protocol.Alpha)]) - (* If trying to only bootstrap the network from a snapshot, you will have errors about missing block metadata, which is likely (I guess?) to be because of data not included in the snapshot. @@ -161,7 +131,11 @@ module Node = struct let config = isolated_config ~peers ~network ~delay:0 in let* () = Node.config_reset node config in let* () = - add_migration_offset_to_config node snapshot ~migration_offset ~network + Node_helpers.may_add_migration_offset_to_config + node + snapshot + ~migration_offset + ~network in let arguments = isolated_args peers in let* () = run ~env:yes_crypto_env node arguments in @@ -180,7 +154,11 @@ module Node = struct let config = isolated_config ~peers ~network ~delay in let* () = Node.config_init node config in let* () = - add_migration_offset_to_config node snapshot ~migration_offset ~network + Node_helpers.may_add_migration_offset_to_config + node + snapshot + ~migration_offset + ~network in let* () = import_snapshot ~no_check:true ~name node snapshot in let arguments = isolated_args peers in diff --git a/tezt/tests/cloud/network.ml b/tezt/tests/cloud/network.ml index c124fde40d80..c5f2cf9c9168 100644 --- a/tezt/tests/cloud/network.ml +++ b/tezt/tests/cloud/network.ml @@ -173,6 +173,10 @@ let block_time : t -> int = function | `Ghostnet -> 5 | _ -> failwith "Block times are only available for Mainnet and Ghostnet." +let next_protocol : t -> Protocol.t = function + | `Mainnet | `Ghostnet | `Rionet -> S023 + | _ -> Alpha + let public_rpc_endpoint testnet = Endpoint.make ~scheme:"https" diff --git a/tezt/tests/cloud/network.mli b/tezt/tests/cloud/network.mli index fd31070bb349..40f9ea22470d 100644 --- a/tezt/tests/cloud/network.mli +++ b/tezt/tests/cloud/network.mli @@ -45,6 +45,8 @@ val default_protocol : t -> Protocol.t (** Block time value for the network *) val block_time : t -> int +val next_protocol : t -> Protocol.t + (** Endpoint publicly available with RPC opened *) val public_rpc_endpoint : public -> Endpoint.t diff --git a/tezt/tests/cloud/node_helpers.ml b/tezt/tests/cloud/node_helpers.ml index c4f277fb7483..cb62935ef237 100644 --- a/tezt/tests/cloud/node_helpers.ml +++ b/tezt/tests/cloud/node_helpers.ml @@ -23,6 +23,32 @@ let yes_wallet agent = let name = Tezt_cloud.Agent.name agent ^ "-yes-wallet" in Yes_wallet.Agent.create ~name agent +let may_add_migration_offset_to_config node snapshot ~migration_offset ~network + = + let* level = get_snapshot_info_level node snapshot in + match migration_offset with + | None -> Lwt.return_unit + | Some migration_offset -> + let* network_config = + match network with + | `Mainnet -> Lwt.return Node.Config_file.mainnet_network_config + | `Ghostnet -> Lwt.return Node.Config_file.ghostnet_network_config + | _ -> + Lwt.fail_with + "Migration scenarios are only supported for Mainnet and Ghostnet." + in + let migration_level = level + migration_offset in + toplog "Add UAU entry for level : %d" migration_level ; + Node.Config_file.update node (fun json -> + JSON.put + ( "network", + JSON.annotate + ~origin:"add_migration_offset_to_config" + network_config ) + json + |> Node.Config_file.update_network_with_user_activated_upgrades + [(migration_level, Network.next_protocol network)]) + let init ?(arguments = []) ?data_dir ?identity_file ?dal_config ?env ~rpc_external ~name network ~with_yes_crypto ~snapshot ?ppx_profiling cloud agent = diff --git a/tezt/tests/cloud/node_helpers.mli b/tezt/tests/cloud/node_helpers.mli index d6627ff08f06..07766847d682 100644 --- a/tezt/tests/cloud/node_helpers.mli +++ b/tezt/tests/cloud/node_helpers.mli @@ -28,6 +28,17 @@ val yes_wallet : Agent.t -> Yes_wallet.t Lwt.t whereas for private networks, it binds to [127.0.0.1]. *) +(** [may_add_migration_offset_to_config node snapshot ~migration_offset ~network] may add an + entry in the configuration file of [node] to trigger a UAU at level [~migration_offset] + to upgrade to the next protocol of [~network]. This entry is is parametrised by the + information obtained from [snapshot]. *) +val may_add_migration_offset_to_config : + Node.t -> + string -> + migration_offset:int option -> + network:Network.t -> + unit Lwt.t + val init : ?arguments:Node.argument list -> ?data_dir:string -> -- GitLab From 95ed1052fc814928c2687fab780a46199cee20aa Mon Sep 17 00:00:00 2001 From: Gabriel Moise Date: Mon, 28 Jul 2025 15:15:34 +0100 Subject: [PATCH 3/7] Tezt_cloud: Node_helpers: Extract agent creation --- tezt/tests/cloud/network.ml | 2 + tezt/tests/cloud/network.mli | 2 + tezt/tests/cloud/node_helpers.ml | 85 +++++++++++--------------------- 3 files changed, 34 insertions(+), 55 deletions(-) diff --git a/tezt/tests/cloud/network.ml b/tezt/tests/cloud/network.ml index c5f2cf9c9168..24824859ffbd 100644 --- a/tezt/tests/cloud/network.ml +++ b/tezt/tests/cloud/network.ml @@ -130,6 +130,8 @@ let stake_repartition_encoding = (fun (network, max_nb_bakers) -> Mimic {network; max_nb_bakers}); ] +let is_public = function #public -> true | _ -> false + let to_public = function | `Sandbox -> failwith "Sandbox is not public" | #public as p -> p diff --git a/tezt/tests/cloud/network.mli b/tezt/tests/cloud/network.mli index 40f9ea22470d..c0182eab8b84 100644 --- a/tezt/tests/cloud/network.mli +++ b/tezt/tests/cloud/network.mli @@ -34,6 +34,8 @@ type stake_repartition = val stake_repartition_encoding : stake_repartition Data_encoding.t +val is_public : t -> bool + val to_public : t -> public (** Parse the given [string] into an available network option. *) diff --git a/tezt/tests/cloud/node_helpers.ml b/tezt/tests/cloud/node_helpers.ml index cb62935ef237..7e240b1abd44 100644 --- a/tezt/tests/cloud/node_helpers.ml +++ b/tezt/tests/cloud/node_helpers.ml @@ -6,6 +6,7 @@ (* *) (*****************************************************************************) +open Network open Scenarios_helpers open Snapshot_helpers open Tezos @@ -53,54 +54,44 @@ let init ?(arguments = []) ?data_dir ?identity_file ?dal_config ?env ~rpc_external ~name network ~with_yes_crypto ~snapshot ?ppx_profiling cloud agent = toplog "Initializing an L1 node for %s" name ; + let net_addr = + if is_public network then + (* for public networks deployments, we listen on all interfaces on both + ipv4 and ipv6 *) + "[::]" + (* For sandbox deployments, we only listen on local interface, hence + no connection could be made to us from outside networks. *) + else "127.0.0.1" + in + let arguments = + if is_public network then + Node.Network (to_octez_network_options @@ to_public network) :: arguments + else arguments + in + toplog "Creating the agent %s." name ; + let* node = + Node.Agent.create + ~rpc_external + ~net_addr + ~arguments + ?data_dir + ~name + cloud + agent + in match network with | #Network.public -> ( let network = Network.to_public network in - (* for public networks deployments, we listen on all interfaces on both - ipv4 and ipv6 *) - let net_addr = "[::]" in match data_dir with - | Some data_dir -> - let* node = - Node.Agent.create - ~rpc_external - ~net_addr - ~arguments - ~data_dir - ~name - cloud - agent - in + | Some _ -> let* () = may_copy_node_identity_file agent node identity_file in - let* () = - Node.Agent.run - ?ppx_profiling - ?env - node - [Network (Network.to_octez_network_options network)] - in + let* () = Node.Agent.run ?ppx_profiling ?env node arguments in let* () = Node.wait_for_ready node in Lwt.return node | None -> toplog "No data dir given, we will attempt to bootstrap the node from a \ rolling snapshot." ; - toplog "Creating the agent %s." name ; - let* node = - Node.Agent.create - ~rpc_external - ~net_addr - ~arguments: - [ - Network (Network.to_octez_network_options network); - Expected_pow 26; - Cors_origin "*"; - ] - ?data_dir - ~name - cloud - agent - in let* () = may_copy_node_identity_file agent node identity_file in toplog "Initializing node configuration for %s" name ; let* () = Node.config_init node [] in @@ -126,7 +117,7 @@ let init ?(arguments = []) ?data_dir ?identity_file ?dal_config ?env longer history, we need the --force-history-mode-switch option. *) (Force_history_mode_switch :: Synchronisation_threshold 1 - :: arguments) + :: Expected_pow 26 :: Cors_origin "*" :: arguments) in toplog "Waiting for the node %s to be ready." name ; let* () = Node.wait_for_ready node in @@ -135,17 +126,11 @@ let init ?(arguments = []) ?data_dir ?identity_file ?dal_config ?env toplog "Node %s is bootstrapped" name ; Lwt.return node) | _ (* private network *) -> ( - (* For sandbox deployments, we only listen on local interface, hence - no connection could be made to us from outside networks *) - let net_addr = "127.0.0.1" in let yes_crypto_arg = if with_yes_crypto then [Node.Allow_yes_crypto] else [] in match data_dir with | None -> - let* node = - Node.Agent.create ~net_addr ~rpc_external ~name cloud agent - in let* () = Node.config_init node [Cors_origin "*"] in let* snapshot_path = ensure_snapshot_opt ~agent ~name snapshot in let* snapshot_network = @@ -201,22 +186,12 @@ let init ?(arguments = []) ?data_dir ?identity_file ?dal_config ?env in let* () = Node.wait_for_ready node in Lwt.return node - | Some data_dir -> + | Some _ -> let arguments = Node. [No_bootstrap_peers; Synchronisation_threshold 0; Cors_origin "*"] @ yes_crypto_arg @ arguments in - let* node = - Node.Agent.create - ~rpc_external - ~net_addr - ~arguments - ~data_dir - ~name - cloud - agent - in let* () = may_copy_node_identity_file agent node identity_file in let* () = Node.Agent.run ?env ?ppx_profiling node arguments in let* () = Node.wait_for_ready node in -- GitLab From fdb526394b0bd1ad96b80efed4bc93da208046f8 Mon Sep 17 00:00:00 2001 From: Gabriel Moise Date: Mon, 28 Jul 2025 15:34:17 +0100 Subject: [PATCH 4/7] Tezt_cloud: Node_helpers: Extract snapshot importing mechanism --- tezt/tests/cloud/node_helpers.ml | 134 +++++++++++++++++------------- tezt/tests/cloud/node_helpers.mli | 1 + 2 files changed, 78 insertions(+), 57 deletions(-) diff --git a/tezt/tests/cloud/node_helpers.ml b/tezt/tests/cloud/node_helpers.ml index 7e240b1abd44..295808e850b2 100644 --- a/tezt/tests/cloud/node_helpers.ml +++ b/tezt/tests/cloud/node_helpers.ml @@ -50,9 +50,72 @@ let may_add_migration_offset_to_config node snapshot ~migration_offset ~network |> Node.Config_file.update_network_with_user_activated_upgrades [(migration_level, Network.next_protocol network)]) +let may_init_from_snapshot node ?data_dir ?dal_config ~network ~snapshot + ?migration_offset ~name agent = + match data_dir with + | Some _ -> Lwt.return_unit + | None -> ( + toplog + "No data dir given, we will attempt to bootstrap the node from a \ + rolling snapshot." ; + toplog "Initializing node configuration for %s" name ; + let* () = Node.config_init node [Cors_origin "*"] in + let* snapshot_file_path = + if is_public network then + let* snapshot_file_path = + ensure_snapshot ~agent ~name ~network:(to_public network) snapshot + in + Lwt.return_some snapshot_file_path + else + let* snapshot_file_path = ensure_snapshot_opt ~agent ~name snapshot in + let* snapshot_network = + match snapshot_file_path with + | Some path -> + let* network = get_snapshot_info_network node path in + Lwt.return_some network + | None -> Lwt.return_none + in + (* Set network *) + let* () = + Node.Config_file.( + update + node + (match snapshot_network with + | Some "mainnet" -> set_mainnet_network () + | Some "ghostnet" -> set_ghostnet_network () + | Some "rionet" -> set_rionet_network () + | Some "seoulnet" -> set_seoulnet_network () + | _ -> set_sandbox_network)) + in + let* () = + match dal_config with + | None -> Lwt.return_unit + | Some config -> + Node.Config_file.( + update node (set_network_with_dal_config config)) + in + Lwt.return snapshot_file_path + in + match snapshot_file_path with + | Some snapshot_file_path -> + let* () = + add_migration_offset_to_config + ~migration_offset + ~network + node + snapshot_file_path + in + import_snapshot + ~delete_snapshot_file:(snapshot = No_snapshot) + ~no_check:true + ~name + node + snapshot_file_path + | None -> Lwt.return_unit) + let init ?(arguments = []) ?data_dir ?identity_file ?dal_config ?env - ~rpc_external ~name network ~with_yes_crypto ~snapshot ?ppx_profiling cloud - agent = + ?migration_offset ~rpc_external ~name network ~with_yes_crypto ~snapshot + ?ppx_profiling cloud agent = toplog "Initializing an L1 node for %s" name ; let net_addr = if is_public network then @@ -79,33 +142,26 @@ let init ?(arguments = []) ?data_dir ?identity_file ?dal_config ?env cloud agent in + let* () = + may_init_from_snapshot + node + ?data_dir + ?dal_config + ~network + ~snapshot + ?migration_offset + ~name + agent + in + let* () = may_copy_node_identity_file agent node identity_file in match network with | #Network.public -> ( - let network = Network.to_public network in match data_dir with | Some _ -> - let* () = may_copy_node_identity_file agent node identity_file in let* () = Node.Agent.run ?ppx_profiling ?env node arguments in let* () = Node.wait_for_ready node in Lwt.return node | None -> - toplog - "No data dir given, we will attempt to bootstrap the node from a \ - rolling snapshot." ; - let* () = may_copy_node_identity_file agent node identity_file in - toplog "Initializing node configuration for %s" name ; - let* () = Node.config_init node [] in - let* snapshot_file_path = - ensure_snapshot ~agent ~name ~network snapshot - in - let* () = - import_snapshot - ~delete_snapshot_file:(snapshot = No_snapshot) - ~no_check:true - ~name - node - snapshot_file_path - in toplog "Launching the node %s." name ; let* () = Node.Agent.run @@ -131,41 +187,6 @@ let init ?(arguments = []) ?data_dir ?identity_file ?dal_config ?env in match data_dir with | None -> - let* () = Node.config_init node [Cors_origin "*"] in - let* snapshot_path = ensure_snapshot_opt ~agent ~name snapshot in - let* snapshot_network = - match snapshot_path with - | Some path -> - let* network = get_snapshot_info_network node path in - Lwt.return_some network - | None -> Lwt.return_none - in - (* Set network *) - let* () = - Node.Config_file.update - node - (match snapshot_network with - | Some "mainnet" -> Node.Config_file.set_mainnet_network () - | Some "ghostnet" -> Node.Config_file.set_ghostnet_network () - | Some "rionet" -> Node.Config_file.set_rionet_network () - | Some "seoulnet" -> Node.Config_file.set_seoulnet_network () - | _ -> Node.Config_file.set_sandbox_network) - in - let* () = - match dal_config with - | None -> Lwt.return_unit - | Some config -> - Node.Config_file.update - node - (Node.Config_file.set_network_with_dal_config config) - in - let* () = may_copy_node_identity_file agent node identity_file in - let* () = - match snapshot_path with - | Some snapshot_path -> - import_snapshot ~no_check:true ~name node snapshot_path - | None -> Lwt.return_unit - in let* () = Node.Agent.run ?ppx_profiling @@ -192,7 +213,6 @@ let init ?(arguments = []) ?data_dir ?identity_file ?dal_config ?env [No_bootstrap_peers; Synchronisation_threshold 0; Cors_origin "*"] @ yes_crypto_arg @ arguments in - let* () = may_copy_node_identity_file agent node identity_file in let* () = Node.Agent.run ?env ?ppx_profiling node arguments in let* () = Node.wait_for_ready node in Lwt.return node) diff --git a/tezt/tests/cloud/node_helpers.mli b/tezt/tests/cloud/node_helpers.mli index 07766847d682..64a82cc87b56 100644 --- a/tezt/tests/cloud/node_helpers.mli +++ b/tezt/tests/cloud/node_helpers.mli @@ -45,6 +45,7 @@ val init : ?identity_file:string -> ?dal_config:Tezos_crypto_dal_octez_dal_config.Dal_config.t -> ?env:string String_map.t -> + ?migration_offset:int -> rpc_external:bool -> name:string -> Network.t -> -- GitLab From c74d89586e85ab19c3012f35f0bf879263432314 Mon Sep 17 00:00:00 2001 From: Gabriel Moise Date: Mon, 28 Jul 2025 15:52:22 +0100 Subject: [PATCH 5/7] Tezt_cloud: Node_helpers: Extract arguments calculation --- tezt/tests/cloud/node_helpers.ml | 59 ++++++++++++-------------------- 1 file changed, 21 insertions(+), 38 deletions(-) diff --git a/tezt/tests/cloud/node_helpers.ml b/tezt/tests/cloud/node_helpers.ml index 295808e850b2..64f92052c3ab 100644 --- a/tezt/tests/cloud/node_helpers.ml +++ b/tezt/tests/cloud/node_helpers.ml @@ -154,6 +154,25 @@ let init ?(arguments = []) ?data_dir ?identity_file ?dal_config ?env agent in let* () = may_copy_node_identity_file agent node identity_file in + let arguments = + if Option.is_none data_dir then + (* We've just imported a rolling snapshot keeping few history. + To switch to the configured history mode, which may have + longer history, we need the --force-history-mode-switch + option. *) Node.Force_history_mode_switch :: arguments + else arguments + in + let arguments = + if is_public network then + Node.[Synchronisation_threshold 1; Cors_origin "*"; Expected_pow 26] + @ arguments + else + let yes_crypto_arg = + if with_yes_crypto then Node.[Allow_yes_crypto] else [] + in + Node.[No_bootstrap_peers; Synchronisation_threshold 0; Cors_origin "*"] + @ yes_crypto_arg @ arguments + in match network with | #Network.public -> ( match data_dir with @@ -163,18 +182,7 @@ let init ?(arguments = []) ?data_dir ?identity_file ?dal_config ?env Lwt.return node | None -> toplog "Launching the node %s." name ; - let* () = - Node.Agent.run - ?ppx_profiling - ?env - node - (* We've just imported a rolling snapshot keeping few history. - To switch to the configured history mode, which may have - longer history, we need the --force-history-mode-switch - option. *) - (Force_history_mode_switch :: Synchronisation_threshold 1 - :: Expected_pow 26 :: Cors_origin "*" :: arguments) - in + let* () = Node.Agent.run ?ppx_profiling ?env node arguments in toplog "Waiting for the node %s to be ready." name ; let* () = Node.wait_for_ready node in toplog "Node %s is ready." name ; @@ -182,37 +190,12 @@ let init ?(arguments = []) ?data_dir ?identity_file ?dal_config ?env toplog "Node %s is bootstrapped" name ; Lwt.return node) | _ (* private network *) -> ( - let yes_crypto_arg = - if with_yes_crypto then [Node.Allow_yes_crypto] else [] - in match data_dir with | None -> - let* () = - Node.Agent.run - ?ppx_profiling - ?env - node - (Node. - [ - No_bootstrap_peers; - Synchronisation_threshold 0; - Cors_origin "*"; - (* We've just imported a rolling snapshot keeping few - history. To switch to the configured history mode, which - may have longer history, we need the - --force-history-mode-switch option. *) - Force_history_mode_switch; - ] - @ yes_crypto_arg @ arguments) - in + let* () = Node.Agent.run ?ppx_profiling ?env node arguments in let* () = Node.wait_for_ready node in Lwt.return node | Some _ -> - let arguments = - Node. - [No_bootstrap_peers; Synchronisation_threshold 0; Cors_origin "*"] - @ yes_crypto_arg @ arguments - in let* () = Node.Agent.run ?env ?ppx_profiling node arguments in let* () = Node.wait_for_ready node in Lwt.return node) -- GitLab From 551345145525299aa38bcfa9350bc174f7ca05a9 Mon Sep 17 00:00:00 2001 From: Gabriel Moise Date: Mon, 28 Jul 2025 15:56:32 +0100 Subject: [PATCH 6/7] Tezt_cloud: Node_helpers: Extract node running --- tezt/tests/cloud/layer1.ml | 41 ++++--------------- tezt/tests/cloud/node_helpers.ml | 66 ++++++++++++++++++------------- tezt/tests/cloud/node_helpers.mli | 5 +++ 3 files changed, 52 insertions(+), 60 deletions(-) diff --git a/tezt/tests/cloud/layer1.ml b/tezt/tests/cloud/layer1.ml index b37401ba1e99..c30b4646ffd6 100644 --- a/tezt/tests/cloud/layer1.ml +++ b/tezt/tests/cloud/layer1.ml @@ -55,33 +55,6 @@ module Node = struct open Snapshot_helpers include Node - (** We are running a private network with yes-crypto enabled. - We don't want to connect with the real network. - *) - let isolated_config ~peers ~network ~delay = - [ - No_bootstrap_peers; - Connections (List.length peers); - Synchronisation_threshold (if List.length peers < 2 then 1 else 2); - Network Network.(to_octez_network_options @@ to_public network); - Expected_pow 0; - Cors_origin "*"; - Storage_maintenance_delay (string_of_int delay); - ] - - (** [--private-mode] is mainly useful for the bootstrap node - because it is used first to bootstrap a node with real network peers - before being disconnected. - For the other node, it's an extra security but their ip/identity should - not be advertised to the external world anyway. - *) - let isolated_args peers = - Private_mode - :: List.fold_left - (fun acc peer -> Peer peer :: acc) - [Allow_yes_crypto; Force_history_mode_switch] - peers - (* If trying to only bootstrap the network from a snapshot, you will have errors about missing block metadata, which is likely (I guess?) to be because of data not included in the snapshot. @@ -128,7 +101,7 @@ module Node = struct Lwt.return_unit in toplog "Reset node config for private a yes-crypto network" ; - let config = isolated_config ~peers ~network ~delay:0 in + let config = Node_helpers.isolated_config ~peers ~network ~delay:0 in let* () = Node.config_reset node config in let* () = Node_helpers.may_add_migration_offset_to_config @@ -137,7 +110,7 @@ module Node = struct ~migration_offset ~network in - let arguments = isolated_args peers in + let arguments = Node_helpers.isolated_args peers in let* () = run ~env:yes_crypto_env node arguments in wait_for_ready node @@ -151,7 +124,7 @@ module Node = struct let* snapshot = ensure_snapshot ~agent ~name ~network:(Network.to_public network) snapshot in - let config = isolated_config ~peers ~network ~delay in + let config = Node_helpers.isolated_config ~peers ~network ~delay in let* () = Node.config_init node config in let* () = Node_helpers.may_add_migration_offset_to_config @@ -161,7 +134,7 @@ module Node = struct ~network in let* () = import_snapshot ~no_check:true ~name node snapshot in - let arguments = isolated_args peers in + let arguments = Node_helpers.isolated_args peers in let* () = run ~env:yes_crypto_env node arguments in let* () = wait_for_ready node in (* As we are playing with dates in the past, @@ -586,12 +559,14 @@ let number_of_bakers ~snapshot ~network cloud agent name = snapshot in let* () = - Node.config_init node (Node.isolated_config ~peers:[] ~network ~delay:0) + Node.config_init + node + (Node_helpers.isolated_config ~peers:[] ~network ~delay:0) in let* () = Snapshot_helpers.import_snapshot ~no_check:true ~name node snapshot in - let* () = Node.Agent.run node (Node.isolated_args []) in + let* () = Node.Agent.run node (Node_helpers.isolated_args []) in let* () = Node.wait_for_ready node in let* client = Client.Agent.create ~name:"tmp-client" ~endpoint:(Node node) agent diff --git a/tezt/tests/cloud/node_helpers.ml b/tezt/tests/cloud/node_helpers.ml index 64f92052c3ab..edd1c109bbfd 100644 --- a/tezt/tests/cloud/node_helpers.ml +++ b/tezt/tests/cloud/node_helpers.ml @@ -24,6 +24,33 @@ let yes_wallet agent = let name = Tezt_cloud.Agent.name agent ^ "-yes-wallet" in Yes_wallet.Agent.create ~name agent +(** We are running a private network with yes-crypto enabled. + We don't want to connect with the real network. *) +let isolated_config ~peers ~network ~delay = + Node. + [ + No_bootstrap_peers; + Connections (List.length peers); + Synchronisation_threshold (if List.length peers < 2 then 1 else 2); + Network Network.(to_octez_network_options @@ to_public network); + Expected_pow 0; + Cors_origin "*"; + Storage_maintenance_delay (string_of_int delay); + ] + +(** [--private-mode] is mainly useful for the bootstrap node + because it is used first to bootstrap a node with real network peers + before being disconnected. + For the other node, it's an extra security but their ip/identity should + not be advertised to the external world anyway. *) +let isolated_args peers = + Node.( + Private_mode + :: List.fold_left + (fun acc peer -> Peer peer :: acc) + [Allow_yes_crypto; Force_history_mode_switch] + peers) + let may_add_migration_offset_to_config node snapshot ~migration_offset ~network = let* level = get_snapshot_info_level node snapshot in @@ -99,7 +126,7 @@ let may_init_from_snapshot node ?data_dir ?dal_config ~network ~snapshot match snapshot_file_path with | Some snapshot_file_path -> let* () = - add_migration_offset_to_config + may_add_migration_offset_to_config ~migration_offset ~network node @@ -173,29 +200,14 @@ let init ?(arguments = []) ?data_dir ?identity_file ?dal_config ?env Node.[No_bootstrap_peers; Synchronisation_threshold 0; Cors_origin "*"] @ yes_crypto_arg @ arguments in - match network with - | #Network.public -> ( - match data_dir with - | Some _ -> - let* () = Node.Agent.run ?ppx_profiling ?env node arguments in - let* () = Node.wait_for_ready node in - Lwt.return node - | None -> - toplog "Launching the node %s." name ; - let* () = Node.Agent.run ?ppx_profiling ?env node arguments in - toplog "Waiting for the node %s to be ready." name ; - let* () = Node.wait_for_ready node in - toplog "Node %s is ready." name ; - let* () = Node.wait_for_synchronisation ~statuses:["synced"] node in - toplog "Node %s is bootstrapped" name ; - Lwt.return node) - | _ (* private network *) -> ( - match data_dir with - | None -> - let* () = Node.Agent.run ?ppx_profiling ?env node arguments in - let* () = Node.wait_for_ready node in - Lwt.return node - | Some _ -> - let* () = Node.Agent.run ?env ?ppx_profiling node arguments in - let* () = Node.wait_for_ready node in - Lwt.return node) + toplog "Launching the node %s." name ; + let* () = Node.Agent.run ?ppx_profiling ?env node arguments in + toplog "Waiting for the node %s to be ready." name ; + let* () = Node.wait_for_ready node in + toplog "Node %s is ready." name ; + let* () = + if is_public network && Option.is_none data_dir then + Node.wait_for_synchronisation ~statuses:["synced"] node + else Lwt.return_unit + in + Lwt.return node diff --git a/tezt/tests/cloud/node_helpers.mli b/tezt/tests/cloud/node_helpers.mli index 64a82cc87b56..c814404858ef 100644 --- a/tezt/tests/cloud/node_helpers.mli +++ b/tezt/tests/cloud/node_helpers.mli @@ -18,6 +18,11 @@ (** Shortcut to create a "yes-wallet" for the given agent. *) val yes_wallet : Agent.t -> Yes_wallet.t Lwt.t +val isolated_config : + peers:string list -> network:Network.t -> delay:int -> Node.argument list + +val isolated_args : string list -> Node.argument list + (** Initialize an L1 node for the given configuration. If a [~snapshot] is provided and [?data_dir] is omitted, the node will be -- GitLab From 94d799a6dab5132d493f2ab0c2cb10c730e879fd Mon Sep 17 00:00:00 2001 From: Gabriel Moise Date: Sun, 27 Jul 2025 18:53:35 +0100 Subject: [PATCH 7/7] Tezt_cloud: Layer1: Use yes_crypto and scenarios_helpers modules --- tezt/tests/cloud/layer1.ml | 21 ++++++++------------- tezt/tests/cloud/yes_crypto.mli | 2 ++ 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/tezt/tests/cloud/layer1.ml b/tezt/tests/cloud/layer1.ml index c30b4646ffd6..7ac8bd25d140 100644 --- a/tezt/tests/cloud/layer1.ml +++ b/tezt/tests/cloud/layer1.ml @@ -18,21 +18,13 @@ not requiring this data *) -open Tezos open Scenarios_helpers +open Tezos +open Yes_crypto (** A baker account is its public key (pk) and its hash (pkh) *) type baker_account = {pk : string; pkh : string} -let add_prometheus_source node cloud agent = - Scenarios_helpers.add_prometheus_source ~node cloud agent (Agent.name agent) - -let yes_crypto_env = - String_map.add - Tezos_crypto.Helpers.yes_crypto_environment_variable - "y" - String_map.empty - let wait_next_level ?(offset = 1) node = Lwt.bind (Network.get_level (Node.as_rpc_endpoint node)) @@ -762,16 +754,19 @@ let init ~(configuration : configuration) cloud next_agent = in Lwt.return stresstesters in - let* () = add_prometheus_source bootstrap_node cloud bootstrap_agent in + let* () = + add_prometheus_source ~node:bootstrap_node cloud bootstrap_agent "bootstrap" + in let* () = Lwt_list.iter_s - (fun ({agent; node; _} : baker) -> add_prometheus_source node cloud agent) + (fun ({agent; node; _} : baker) -> + add_prometheus_source ~node cloud agent (Agent.name agent)) bakers in let* () = Lwt_list.iter_s (fun ({agent; node; _} : stresstester) -> - add_prometheus_source node cloud agent) + add_prometheus_source ~node cloud agent (Agent.name agent)) stresstesters in Lwt.return {cloud; configuration; bootstrap; bakers; stresstesters} diff --git a/tezt/tests/cloud/yes_crypto.mli b/tezt/tests/cloud/yes_crypto.mli index d20798d390f5..ee88fd6a84c4 100644 --- a/tezt/tests/cloud/yes_crypto.mli +++ b/tezt/tests/cloud/yes_crypto.mli @@ -12,6 +12,8 @@ open Scenarios_configuration +val yes_crypto_env : string String_map.t + (** [should_enable_yes_crypto config] returns a flag indicating whether "yes-crypto" mode should be enabled (for [Scatter] and [Map]) or disabled (for [Disabled]). *) -- GitLab