From a23b3b3e983b2de843ee443c7b75f82c38950518 Mon Sep 17 00:00:00 2001 From: Gabriel Moise Date: Mon, 21 Jul 2025 17:10:32 +0100 Subject: [PATCH 1/4] Tezt_cloud: Refactor yes_crypto --- tezt/tests/cloud/dal.ml | 32 +++++++++++--------------------- tezt/tests/cloud/yes_crypto.ml | 19 +++++++++++++++++++ tezt/tests/cloud/yes_crypto.mli | 23 +++++++++++++++++++++++ 3 files changed, 53 insertions(+), 21 deletions(-) create mode 100644 tezt/tests/cloud/yes_crypto.ml create mode 100644 tezt/tests/cloud/yes_crypto.mli diff --git a/tezt/tests/cloud/dal.ml b/tezt/tests/cloud/dal.ml index bb0188d7a4d8..be1de20cc08f 100644 --- a/tezt/tests/cloud/dal.ml +++ b/tezt/tests/cloud/dal.ml @@ -25,6 +25,7 @@ module Helpers = Dal_common.Helpers module Cli = Scenarios_cli open Scenarios_helpers open Tezos +open Yes_crypto type agent_kind = | Bootstrap @@ -152,11 +153,6 @@ module Node = struct let name = Tezt_cloud.Agent.name agent ^ "-yes-wallet" in Yes_wallet.Agent.create ~name agent - let yes_crypto_env = - String_map.singleton - Tezos_crypto.Helpers.yes_crypto_environment_variable - "y" - let init ?(arguments = []) ?data_dir ?identity_file ?dal_config ?env ~rpc_external ~name network ~with_yes_crypto ~snapshot ?ppx_profiling cloud agent = @@ -2540,9 +2536,7 @@ let init_public_network cloud (configuration : configuration) let () = toplog "Some agent given (%s)" (Agent.name agent) in let () = toplog "Initializing the bootstrap node agent" in let with_yes_crypto = - match configuration.simulate_network with - | Scatter _ | Map _ -> true - | Disabled -> false + should_enable_yes_crypto configuration.simulate_network in let* node = Node.init @@ -2694,10 +2688,6 @@ let round_robin_split m lst = (List.rev lst) ; Array.to_list buckets |> List.rev -let may_set_yes_crypto = function - | Cli.Scatter _ | Map _ -> (Some Node.yes_crypto_env, true) - | Disabled -> (None, false) - let init_sandbox_and_activate_protocol cloud (configuration : configuration) ?(etherlink_configuration : etherlink_configuration option) agent = let dal_bootstrap_node_net_port = Agent.next_available_port agent in @@ -2713,7 +2703,7 @@ let init_sandbox_and_activate_protocol cloud (configuration : configuration) configuration.data_dir |> Option.map (fun data_dir -> data_dir // name) in let env, with_yes_crypto = - may_set_yes_crypto configuration.simulate_network + may_set_yes_crypto_env configuration.simulate_network in let* bootstrap_node = Node.init @@ -3072,7 +3062,7 @@ let init_baker ?stake cloud (configuration : configuration) ~bootstrap teztale configuration.data_dir |> Option.map (fun data_dir -> data_dir // name) in let env, with_yes_crypto = - may_set_yes_crypto configuration.simulate_network + may_set_yes_crypto_env configuration.simulate_network in let* node = Node.init @@ -3204,7 +3194,7 @@ let init_producer cloud configuration ~bootstrap teztale account i slot_index in let () = toplog "Init producer %s: init L1 node" name in let env, with_yes_crypto = - may_set_yes_crypto configuration.simulate_network + may_set_yes_crypto_env configuration.simulate_network in let* node = Node.init @@ -3317,7 +3307,7 @@ let init_observer cloud configuration ~bootstrap teztale ~topic i agent = configuration.data_dir |> Option.map (fun data_dir -> data_dir // name) in let env, with_yes_crypto = - may_set_yes_crypto configuration.simulate_network + may_set_yes_crypto_env configuration.simulate_network in let* node = Node.init @@ -3407,7 +3397,7 @@ let init_dal_reverse_proxy_observers |> Lwt_list.map_p (fun slot_index -> let name = name_of slot_index in let* agent = next_agent ~name in - let env, with_yes_crypto = may_set_yes_crypto simulate_network in + let env, with_yes_crypto = may_set_yes_crypto_env simulate_network in let* node = Node.init ?env @@ -3477,7 +3467,7 @@ let init_etherlink_dal_node toplog "Etherlink sequencer will run its own DAL node" ; let name = name_of Etherlink_dal_operator in let* agent = next_agent ~name in - let env, with_yes_crypto = may_set_yes_crypto simulate_network in + let env, with_yes_crypto = may_set_yes_crypto_env simulate_network in let* node = Node.init ?env @@ -3521,7 +3511,7 @@ let init_etherlink_dal_node toplog "Etherlink sequencer will use a reverse proxy" ; let name = name_of Etherlink_dal_operator in let* agent = next_agent ~name in - let env, with_yes_crypto = may_set_yes_crypto simulate_network in + let env, with_yes_crypto = may_set_yes_crypto_env simulate_network in let* node = Node.init ?env @@ -3577,7 +3567,7 @@ let init_etherlink_operator_setup cloud configuration etherlink_configuration configuration.data_dir |> Option.map (fun data_dir -> data_dir // name) in let env, with_yes_crypto = - may_set_yes_crypto configuration.simulate_network + may_set_yes_crypto_env configuration.simulate_network in let* node = Node.init @@ -3969,7 +3959,7 @@ let init_echo_rollup cloud configuration ~bootstrap operator dal_slots configuration.data_dir |> Option.map (fun data_dir -> data_dir // name) in let env, with_yes_crypto = - may_set_yes_crypto configuration.simulate_network + may_set_yes_crypto_env configuration.simulate_network in let* node = Node.init diff --git a/tezt/tests/cloud/yes_crypto.ml b/tezt/tests/cloud/yes_crypto.ml new file mode 100644 index 000000000000..db5548e204ab --- /dev/null +++ b/tezt/tests/cloud/yes_crypto.ml @@ -0,0 +1,19 @@ +(*****************************************************************************) +(* *) +(* SPDX-License-Identifier: MIT *) +(* Copyright (c) 2025 Trilitech *) +(* *) +(*****************************************************************************) + +open Scenarios_cli + +let yes_crypto_env = + String_map.singleton Tezos_crypto.Helpers.yes_crypto_environment_variable "y" + +let should_enable_yes_crypto = function + | Scatter _ | Map _ -> true + | Disabled -> false + +let may_set_yes_crypto_env = function + | Scatter _ | Map _ -> (Some yes_crypto_env, true) + | Disabled -> (None, false) diff --git a/tezt/tests/cloud/yes_crypto.mli b/tezt/tests/cloud/yes_crypto.mli new file mode 100644 index 000000000000..5c74a3b25c05 --- /dev/null +++ b/tezt/tests/cloud/yes_crypto.mli @@ -0,0 +1,23 @@ +(*****************************************************************************) +(* *) +(* SPDX-License-Identifier: MIT *) +(* Copyright (c) 2025 Trilitech *) +(* *) +(*****************************************************************************) + +(** This module provides utilities for enabling the "yes-crypto" testing mode, + which bypasses certain cryptographic confirmations in Octez nodes. +*) + +open Scenarios_cli + +(** [should_enable_yes_crypto config] returns a flag + indicating whether "yes-crypto" mode should be enabled (for [Scatter] and [Map]) + or disabled (for [Disabled]). *) +val should_enable_yes_crypto : network_simulation_config -> bool + +(** [may_set_yes_crypto_env config] is similar to [should_enable_yes_crypto], + but also returns the environment variable that needs to be set to enable + the yes-crypto mechanism. *) +val may_set_yes_crypto_env : + network_simulation_config -> string String_map.t option * bool -- GitLab From cb5d1ee64044795265eec1fd7f8ee9e939f0ac19 Mon Sep 17 00:00:00 2001 From: Gabriel Moise Date: Mon, 21 Jul 2025 17:13:40 +0100 Subject: [PATCH 2/4] Tezt_cloud: Refactor agent_kind --- tezt/tests/cloud/agent_kind.ml | 37 +++++++++++++++++++++++++++++++++ tezt/tests/cloud/agent_kind.mli | 37 +++++++++++++++++++++++++++++++++ tezt/tests/cloud/dal.ml | 32 +--------------------------- 3 files changed, 75 insertions(+), 31 deletions(-) create mode 100644 tezt/tests/cloud/agent_kind.ml create mode 100644 tezt/tests/cloud/agent_kind.mli diff --git a/tezt/tests/cloud/agent_kind.ml b/tezt/tests/cloud/agent_kind.ml new file mode 100644 index 000000000000..c444223e1427 --- /dev/null +++ b/tezt/tests/cloud/agent_kind.ml @@ -0,0 +1,37 @@ +(*****************************************************************************) +(* *) +(* SPDX-License-Identifier: MIT *) +(* Copyright (c) 2025 Trilitech *) +(* *) +(*****************************************************************************) + +type t = + | Bootstrap + | Baker of int + | Producer of int + | Observer of [`Index of int | `Pkh of string] + | Reverse_proxy + | Etherlink_operator + | Etherlink_dal_operator + | Etherlink_dal_observer of {slot_index : int} + | Etherlink_producer of int + | Echo_rollup_operator + | Echo_rollup_dal_observer of {slot_index : int} + +let name_of = function + | Bootstrap -> "bootstrap" + | Baker i -> Format.asprintf "attester-%d" i + | Producer i -> Format.asprintf "dal-producer-%d" i + | Observer (`Index i) -> Format.asprintf "dal-observer-%d" i + | Observer (`Pkh pkh) -> + (* Shorting the pkh enables to get better logs. *) + Format.asprintf "dal-observer-%s" (String.sub pkh 0 8) + | Reverse_proxy -> "dal-reverse-proxy" + | Etherlink_operator -> "etherlink-operator" + | Etherlink_dal_operator -> "etherlink-dal-operator" + | Etherlink_dal_observer {slot_index} -> + Format.asprintf "etherlink-dal-operator-%d" slot_index + | Etherlink_producer i -> Format.asprintf "etherlink-producer-%d" i + | Echo_rollup_operator -> "echo-rollup-operator" + | Echo_rollup_dal_observer {slot_index} -> + Format.sprintf "echo-rollup-dal-node-%d" slot_index diff --git a/tezt/tests/cloud/agent_kind.mli b/tezt/tests/cloud/agent_kind.mli new file mode 100644 index 000000000000..d13d54db75c9 --- /dev/null +++ b/tezt/tests/cloud/agent_kind.mli @@ -0,0 +1,37 @@ +(*****************************************************************************) +(* *) +(* SPDX-License-Identifier: MIT *) +(* Copyright (c) 2025 Trilitech *) +(* *) +(*****************************************************************************) + +(** Here are defined various roles that agents (like L1 nodes, DAL nodes, + Bakers etc.) can assume in the tezt-cloud test scenarios. + + These roles are used to systematically name and distinguish + agents and their responsibilities across different configurations. +*) + +type t = + | Bootstrap + (** The main bootstrap node and client, typically the entry point of the network. *) + | Baker of int + (** A node responsible for block production, identified by index. *) + | Producer of int (** A DAL slot producer node, identified by index. *) + | Observer of [`Index of int | `Pkh of string] + (** A DAL observer node, either indexed or associated with a public key hash. *) + | Reverse_proxy + (** A reverse proxy between rollup nodes and multiple DAL nodes. *) + | Etherlink_operator (** The main Etherlink rollup operator node. *) + | Etherlink_dal_operator + (** A DAL node running alongside the Etherlink operator. *) + | Etherlink_dal_observer of {slot_index : int} + (** An Etherlink DAL observer responsible for a specific slot index. *) + | Etherlink_producer of int (** A DAL slot producer used by Etherlink. *) + | Echo_rollup_operator (** The main rollup operator for the Echo rollup. *) + | Echo_rollup_dal_observer of {slot_index : int} + (** A DAL observer node for the Echo rollup, indexed by slot. *) + +(** [name_of agent] returns the standard name associated with a given [agent]. + Used for consistent naming of VMs, logs and artifacts. *) +val name_of : t -> string diff --git a/tezt/tests/cloud/dal.ml b/tezt/tests/cloud/dal.ml index be1de20cc08f..b014703d320d 100644 --- a/tezt/tests/cloud/dal.ml +++ b/tezt/tests/cloud/dal.ml @@ -23,41 +23,11 @@ module Cryptobox = Dal_common.Cryptobox module Helpers = Dal_common.Helpers module Cli = Scenarios_cli +open Agent_kind open Scenarios_helpers open Tezos open Yes_crypto -type agent_kind = - | Bootstrap - | Baker of int - | Producer of int - | Observer of [`Index of int | `Pkh of string] - | Reverse_proxy - | Etherlink_operator - | Etherlink_dal_operator - | Etherlink_dal_observer of {slot_index : int} - | Etherlink_producer of int - | Echo_rollup_operator - | Echo_rollup_dal_observer of {slot_index : int} - -let name_of = function - | Bootstrap -> "bootstrap" - | Baker i -> Format.asprintf "attester-%d" i - | Producer i -> Format.asprintf "dal-producer-%d" i - | Observer (`Index i) -> Format.asprintf "dal-observer-%d" i - | Observer (`Pkh pkh) -> - (* Shorting the pkh enables to get better logs. *) - Format.asprintf "dal-observer-%s" (String.sub pkh 0 8) - | Reverse_proxy -> "dal-reverse-proxy" - | Etherlink_operator -> "etherlink-operator" - | Etherlink_dal_operator -> "etherlink-dal-operator" - | Etherlink_dal_observer {slot_index} -> - Format.asprintf "etherlink-dal-operator-%d" slot_index - | Etherlink_producer i -> Format.asprintf "etherlink-producer-%d" i - | Echo_rollup_operator -> "echo-rollup-operator" - | Echo_rollup_dal_observer {slot_index} -> - Format.sprintf "echo-rollup-dal-node-%d" slot_index - (* Some DAL nodes (those in operator mode) refuse to start unless they are connected to an Octez node keeping enough history to play refutation games. *) -- GitLab From 19a4ba9c41c4250347ea55280cb3fe9e2bee9ed0 Mon Sep 17 00:00:00 2001 From: Gabriel Moise Date: Mon, 21 Jul 2025 17:18:08 +0100 Subject: [PATCH 3/4] Tezt_cloud: Refactor node_helpers --- tezt/tests/cloud/dal.ml | 216 ++---------------------------- tezt/tests/cloud/node_helpers.ml | 196 +++++++++++++++++++++++++++ tezt/tests/cloud/node_helpers.mli | 44 ++++++ 3 files changed, 253 insertions(+), 203 deletions(-) create mode 100644 tezt/tests/cloud/node_helpers.ml create mode 100644 tezt/tests/cloud/node_helpers.mli diff --git a/tezt/tests/cloud/dal.ml b/tezt/tests/cloud/dal.ml index b014703d320d..005da18b5fbc 100644 --- a/tezt/tests/cloud/dal.ml +++ b/tezt/tests/cloud/dal.ml @@ -105,196 +105,6 @@ module Disconnect = struct Lwt.return {t with disconnected_bakers = bakers_to_keep_disconnected} end -module Node = struct - open Snapshot_helpers - - let may_copy_node_identity_file agent node = function - | None -> Lwt.return_unit - | Some source -> - toplog "Copying the node identity file" ; - let* _ = - Agent.copy agent ~source ~destination:(Node.identity_file node) - in - Lwt.return_unit - - include Node - - let yes_wallet agent = - let name = Tezt_cloud.Agent.name agent ^ "-yes-wallet" in - Yes_wallet.Agent.create ~name agent - - 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 ; - 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 - 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.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 - 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 - ?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 - :: arguments) - in - toplog "Waiting for the node %s to be ready." name ; - let* () = 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 *) -> ( - (* 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 [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 = - 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 - ?env - 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* () = wait_for_ready node in - Lwt.return node - | Some data_dir -> - let arguments = - [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 - Lwt.return node) -end - module Dal_reverse_proxy = struct (** This module allows to configure NginX as a reverse proxy in front of a collection of DAL nodes. This allows to balance the @@ -2509,7 +2319,7 @@ let init_public_network cloud (configuration : configuration) should_enable_yes_crypto configuration.simulate_network in let* node = - Node.init + Node_helpers.init ?identity_file:configuration.bootstrap_node_identity_file ~rpc_external:configuration.external_rpc ~name:"bootstrap-node" @@ -2676,7 +2486,7 @@ let init_sandbox_and_activate_protocol cloud (configuration : configuration) may_set_yes_crypto_env configuration.simulate_network in let* bootstrap_node = - Node.init + Node_helpers.init ?env ?data_dir ?identity_file:configuration.bootstrap_node_identity_file @@ -2717,7 +2527,7 @@ let init_sandbox_and_activate_protocol cloud (configuration : configuration) ~endpoint:(Client.Node bootstrap_node) agent in - let* yes_wallet = Node.yes_wallet agent in + let* yes_wallet = Node_helpers.yes_wallet agent in let* snapshot_network = match configuration.snapshot with | Docker_embedded path | Local_file path -> @@ -2824,7 +2634,7 @@ let init_sandbox_and_activate_protocol cloud (configuration : configuration) |> return | Map _ | Scatter _ -> (* Substitute consensus pkh with delegate pkh *) - let* yw = Node.yes_wallet agent in + let* yw = Node_helpers.yes_wallet agent in let* ckm = Yes_wallet.load_consensus_key_mapping yw ~client in List.map (fun l -> @@ -3035,7 +2845,7 @@ let init_baker ?stake cloud (configuration : configuration) ~bootstrap teztale may_set_yes_crypto_env configuration.simulate_network in let* node = - Node.init + Node_helpers.init ?env ?data_dir ~arguments:Node.[Peer bootstrap.node_p2p_endpoint] @@ -3110,7 +2920,7 @@ let init_baker ?stake cloud (configuration : configuration) ~bootstrap teztale let* () = match configuration.simulate_network with | Scatter _ | Map _ -> - let* yes_wallet = Node.yes_wallet agent in + let* yes_wallet = Node_helpers.yes_wallet agent in let* () = Lwt_list.iter_s (fun account -> @@ -3167,7 +2977,7 @@ let init_producer cloud configuration ~bootstrap teztale account i slot_index may_set_yes_crypto_env configuration.simulate_network in let* node = - Node.init + Node_helpers.init ?env ?data_dir ~name @@ -3280,7 +3090,7 @@ let init_observer cloud configuration ~bootstrap teztale ~topic i agent = may_set_yes_crypto_env configuration.simulate_network in let* node = - Node.init + Node_helpers.init ?env ?data_dir ~name @@ -3369,7 +3179,7 @@ let init_dal_reverse_proxy_observers let* agent = next_agent ~name in let env, with_yes_crypto = may_set_yes_crypto_env simulate_network in let* node = - Node.init + Node_helpers.init ?env ~name ~arguments: @@ -3439,7 +3249,7 @@ let init_etherlink_dal_node let* agent = next_agent ~name in let env, with_yes_crypto = may_set_yes_crypto_env simulate_network in let* node = - Node.init + Node_helpers.init ?env ~name ~arguments: @@ -3483,7 +3293,7 @@ let init_etherlink_dal_node let* agent = next_agent ~name in let env, with_yes_crypto = may_set_yes_crypto_env simulate_network in let* node = - Node.init + Node_helpers.init ?env ~name ~arguments: @@ -3540,7 +3350,7 @@ let init_etherlink_operator_setup cloud configuration etherlink_configuration may_set_yes_crypto_env configuration.simulate_network in let* node = - Node.init + Node_helpers.init ?env ?data_dir ~name @@ -3932,7 +3742,7 @@ let init_echo_rollup cloud configuration ~bootstrap operator dal_slots may_set_yes_crypto_env configuration.simulate_network in let* node = - Node.init + Node_helpers.init ?env ?data_dir ~name diff --git a/tezt/tests/cloud/node_helpers.ml b/tezt/tests/cloud/node_helpers.ml new file mode 100644 index 000000000000..5770b89e8e71 --- /dev/null +++ b/tezt/tests/cloud/node_helpers.ml @@ -0,0 +1,196 @@ +(*****************************************************************************) +(* *) +(* SPDX-License-Identifier: MIT *) +(* Copyright (c) 2025 Trilitech *) +(* *) +(*****************************************************************************) + +open Scenarios_helpers +open Snapshot_helpers +open Tezos + +let may_copy_node_identity_file agent node = function + | None -> Lwt.return_unit + | Some source -> + toplog "Copying the node identity file" ; + let* _ = + Agent.copy agent ~source ~destination:(Node.identity_file node) + in + Lwt.return_unit + +let yes_wallet agent = + let name = Tezt_cloud.Agent.name agent ^ "-yes-wallet" in + Yes_wallet.Agent.create ~name agent + +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 ; + 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 + 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.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 + 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 + ?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 + :: 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 *) -> ( + (* 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 = + 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 + ?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.wait_for_ready node in + Lwt.return node + | Some data_dir -> + 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 + Lwt.return node) diff --git a/tezt/tests/cloud/node_helpers.mli b/tezt/tests/cloud/node_helpers.mli new file mode 100644 index 000000000000..b472ded517eb --- /dev/null +++ b/tezt/tests/cloud/node_helpers.mli @@ -0,0 +1,44 @@ +(*****************************************************************************) +(* *) +(* SPDX-License-Identifier: MIT *) +(* Copyright (c) 2025 Trilitech *) +(* *) +(*****************************************************************************) + +(** This module provides high-level utilities for initializing + Tezos L1 nodes in both public and private network configurations, + as used in Tezt cloud-based scenarios. + + It wraps the lower-level [Node] and [Node.Agent] modules with additional + logic for snapshot handling, identity propagation, DAL configuration, + "yes-crypto" simulation, and automatic bootstrapping behavior. +*) + +(** Shortcut to create a "yes-wallet" for the given agent. *) +val yes_wallet : Agent.t -> Yes_wallet.t Lwt.t + +(** Initialize an L1 node for the given configuration. + + If a [~snapshot] is provided and [?data_dir] is omitted, the node will be + bootstrapped using the snapshot. Otherwise, a normal configuration + initialization is used. + + In public networks, the node listens on all interfaces ([::]), + whereas for private networks, it binds to [127.0.0.1]. +*) + +val init : + ?arguments:Node.argument list -> + ?data_dir:string -> + ?identity_file:string -> + ?dal_config:Tezos_crypto_dal_octez_dal_config.Dal_config.t -> + ?env:string String_map.t -> + rpc_external:bool -> + name:string -> + Network.t -> + with_yes_crypto:bool -> + snapshot:Snapshot_helpers.t -> + ?ppx_profiling:bool -> + Cloud.t -> + Agent.t -> + Node.t Lwt.t -- GitLab From 74c76ed554a33114f317d6c599cde8ffa7ecccab Mon Sep 17 00:00:00 2001 From: Gabriel Moise Date: Mon, 21 Jul 2025 10:00:20 +0100 Subject: [PATCH 4/4] Tezt_cloud: Update copyrights --- tezt/tests/cloud/agent_kind.ml | 1 + tezt/tests/cloud/agent_kind.mli | 1 + tezt/tests/cloud/node_helpers.ml | 1 + tezt/tests/cloud/node_helpers.mli | 1 + tezt/tests/cloud/yes_crypto.ml | 1 + tezt/tests/cloud/yes_crypto.mli | 1 + 6 files changed, 6 insertions(+) diff --git a/tezt/tests/cloud/agent_kind.ml b/tezt/tests/cloud/agent_kind.ml index c444223e1427..b3cfa44811da 100644 --- a/tezt/tests/cloud/agent_kind.ml +++ b/tezt/tests/cloud/agent_kind.ml @@ -1,6 +1,7 @@ (*****************************************************************************) (* *) (* SPDX-License-Identifier: MIT *) +(* Copyright (c) 2025 Nomadic Labs, *) (* Copyright (c) 2025 Trilitech *) (* *) (*****************************************************************************) diff --git a/tezt/tests/cloud/agent_kind.mli b/tezt/tests/cloud/agent_kind.mli index d13d54db75c9..6c97b36aaf06 100644 --- a/tezt/tests/cloud/agent_kind.mli +++ b/tezt/tests/cloud/agent_kind.mli @@ -1,6 +1,7 @@ (*****************************************************************************) (* *) (* SPDX-License-Identifier: MIT *) +(* Copyright (c) 2025 Nomadic Labs, *) (* Copyright (c) 2025 Trilitech *) (* *) (*****************************************************************************) diff --git a/tezt/tests/cloud/node_helpers.ml b/tezt/tests/cloud/node_helpers.ml index 5770b89e8e71..c4f277fb7483 100644 --- a/tezt/tests/cloud/node_helpers.ml +++ b/tezt/tests/cloud/node_helpers.ml @@ -1,6 +1,7 @@ (*****************************************************************************) (* *) (* SPDX-License-Identifier: MIT *) +(* Copyright (c) 2025 Nomadic Labs, *) (* Copyright (c) 2025 Trilitech *) (* *) (*****************************************************************************) diff --git a/tezt/tests/cloud/node_helpers.mli b/tezt/tests/cloud/node_helpers.mli index b472ded517eb..d6627ff08f06 100644 --- a/tezt/tests/cloud/node_helpers.mli +++ b/tezt/tests/cloud/node_helpers.mli @@ -1,6 +1,7 @@ (*****************************************************************************) (* *) (* SPDX-License-Identifier: MIT *) +(* Copyright (c) 2025 Nomadic Labs, *) (* Copyright (c) 2025 Trilitech *) (* *) (*****************************************************************************) diff --git a/tezt/tests/cloud/yes_crypto.ml b/tezt/tests/cloud/yes_crypto.ml index db5548e204ab..000015d56a6e 100644 --- a/tezt/tests/cloud/yes_crypto.ml +++ b/tezt/tests/cloud/yes_crypto.ml @@ -1,6 +1,7 @@ (*****************************************************************************) (* *) (* SPDX-License-Identifier: MIT *) +(* Copyright (c) 2025 Nomadic Labs, *) (* Copyright (c) 2025 Trilitech *) (* *) (*****************************************************************************) diff --git a/tezt/tests/cloud/yes_crypto.mli b/tezt/tests/cloud/yes_crypto.mli index 5c74a3b25c05..86cac33b28e8 100644 --- a/tezt/tests/cloud/yes_crypto.mli +++ b/tezt/tests/cloud/yes_crypto.mli @@ -1,6 +1,7 @@ (*****************************************************************************) (* *) (* SPDX-License-Identifier: MIT *) +(* Copyright (c) 2025 Nomadic Labs, *) (* Copyright (c) 2025 Trilitech *) (* *) (*****************************************************************************) -- GitLab