From d1f34d408dcbf4a8cc13459ca2860ad84d571e82 Mon Sep 17 00:00:00 2001 From: Victor Allombert Date: Tue, 10 Jun 2025 16:10:01 +0200 Subject: [PATCH 1/2] Tezt/Cloud/DAL: avoid polluting PKH over string types --- tezt/tests/cloud/dal.ml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tezt/tests/cloud/dal.ml b/tezt/tests/cloud/dal.ml index d76594a9ba4c..02b78026dfb3 100644 --- a/tezt/tests/cloud/dal.ml +++ b/tezt/tests/cloud/dal.ml @@ -543,7 +543,7 @@ type etherlink = { accounts : Tezt_etherlink.Eth_account.t Array.t; } -type public_key_hash = string +type public_key_hash = PKH of string type commitment_info = {commitment : string; publisher_pkh : string} @@ -690,7 +690,9 @@ let pp_metrics t t.bakers |> List.iter (fun {account; stake; _} -> let pkh = account.Account.public_key_hash in - match Hashtbl.find_opt ratio_attested_commitments_per_baker pkh with + match + Hashtbl.find_opt ratio_attested_commitments_per_baker (PKH pkh) + with | None -> Log.info "We lack information about %s" pkh | Some {published_slots; attested_slots; _} -> let alias = @@ -774,7 +776,7 @@ let push_metrics t (if value then 1. else 0.) in Hashtbl.iter - (fun public_key_hash + (fun (PKH public_key_hash) {attested_slots; published_slots; in_committee; attestation_with_dal} -> if in_committee then ( let labels = get_labels public_key_hash in @@ -2067,7 +2069,7 @@ let get_infos_per_level t ~level ~metadata = |> Seq.map (fun operation -> let public_key_hash = get_public_key_hash operation in let dal_attestation = get_dal_attestation operation in - (public_key_hash, dal_attestation)) + (PKH public_key_hash, dal_attestation)) |> Hashtbl.of_seq in let* etherlink_operator_balance_sum = -- GitLab From c9d10219cce9ac7b91a3233f913665882dc7dfc4 Mon Sep 17 00:00:00 2001 From: Victor Allombert Date: Tue, 10 Jun 2025 17:00:28 +0200 Subject: [PATCH 2/2] Tezt/Cloud/DAL: add `--snapshot` to init test with local snapshot --- tezt/tests/cloud/dal.ml | 137 +++++++++++++++++++----------- tezt/tests/cloud/scenarios_cli.ml | 11 +++ 2 files changed, 97 insertions(+), 51 deletions(-) diff --git a/tezt/tests/cloud/dal.ml b/tezt/tests/cloud/dal.ml index 02b78026dfb3..ec0d0a32a0fc 100644 --- a/tezt/tests/cloud/dal.ml +++ b/tezt/tests/cloud/dal.ml @@ -136,7 +136,7 @@ module Node = struct include Node let init ?(arguments = []) ?data_dir ?identity_file ?dal_config ~rpc_external - ~name network cloud agent = + ~name network ~snapshot cloud agent = toplog "Inititializing an L1 node for %s" name ; match network with | #Network.public -> ( @@ -187,61 +187,83 @@ module Node = struct let* () = may_copy_node_identity_file agent node identity_file in toplog "Initializing node configuration for %s" name ; let* () = Node.config_init node [] in - toplog "Trying to download a rolling snapshot for %s" name ; - let* exit_status = - Process.spawn - ?runner:(runner_of_agent agent) - "wget" - [ - "-O"; - "snapshot_file"; - sf "%s/rolling" (Network.snapshot_service network); - ] - |> Process.wait + let* snapshot_file_path = + match snapshot with + | Some snapshot_path -> + toplog "Using locally stored snapshot file: %s" snapshot_path ; + Tezt_cloud.Agent.copy + agent + ~destination:snapshot_path + ~source:snapshot_path + | None -> + toplog "Trying to download a rolling snapshot for %s" name ; + let downloaded_snapshot_file_path = "snapshot_file" in + let* exit_status = + Process.spawn + ?runner:(runner_of_agent agent) + "wget" + [ + "-O"; + downloaded_snapshot_file_path; + sf "%s/rolling" (Network.snapshot_service network); + ] + |> Process.wait + in + let* () = + match exit_status with + | WEXITED 0 -> Lwt.return_unit + | WEXITED code -> + toplog + "Could not download the snapshot for %s: wget exit \ + code: %d\n\ + Starting without snapshot. It could last long \ + before the node is bootstrapped" + name + code ; + Lwt.return_unit + | status -> ( + match Process.validate_status status with + | Ok () -> Lwt.return_unit + | Error (`Invalid_status reason) -> + failwith @@ Format.sprintf "wget: %s" reason) + in + return downloaded_snapshot_file_path in let* () = - match exit_status with - | WEXITED 0 -> - toplog "Importing the snapshot for %s" name ; + toplog "Importing the snapshot for %s" name ; + let* () = + try let* () = - try - let* () = - Node.snapshot_import ~no_check:true node "snapshot_file" - in - let () = - toplog "Snapshot import succeeded for %s." name - in - let* _ = - Process.wait (Process.spawn "rm" ["snapshot_file"]) - in - Lwt.return_unit - with _ -> - (* Failing to import the snapshot could happen on a - very young Weeklynet, before the first snapshot is - available. In this case bootstrapping from the - genesis block is OK. *) - let () = + Node.snapshot_import ~no_check:true node snapshot_file_path + in + let () = toplog "Snapshot import succeeded for %s." name in + let* () = + match snapshot with + | Some _ -> Lwt.return_unit + | None -> + (* Delete the snapshot downloaded locally *) toplog - "Snapshot import failed for %s, the node will be \ - bootstrapped from genesis." - name - in - Lwt.return_unit + "Deleting downloaded snapshot (%s)" + snapshot_file_path ; + let* (_ignored_exit_status : Unix.process_status) = + Process.wait (Process.spawn "rm" [snapshot_file_path]) + in + Lwt.return_unit in Lwt.return_unit - | WEXITED code -> - toplog - "Could not download the snapshot for %s: wget exit code: %d\n\ - Starting without snapshot. It could last long before the \ - node is bootstrapped" - name - code ; + with _ -> + (* Failing to import the snapshot could happen on a very young + Weeklynet, before the first snapshot is available. In this + case bootstrapping from the genesis block is OK. *) + let () = + toplog + "Snapshot import failed for %s, the node will be \ + bootstrapped from genesis." + name + in Lwt.return_unit - | status -> ( - match Process.validate_status status with - | Ok () -> Lwt.return_unit - | Error (`Invalid_status reason) -> - failwith @@ Format.sprintf "wget: %s" reason) + in + Lwt.return_unit in toplog "Launching the node %s." name ; let* () = @@ -479,6 +501,7 @@ type configuration = { reconnection delay *) disconnect : (int * int) option; network : Network.t; + snapshot : string option; bootstrap : bool; teztale : bool; memtrace : bool; @@ -2158,6 +2181,7 @@ let init_public_network cloud (configuration : configuration) ~rpc_external:configuration.external_rpc ~name:"bootstrap-node" configuration.network + ~snapshot:configuration.snapshot cloud agent in @@ -2387,6 +2411,7 @@ let init_sandbox_and_activate_protocol cloud (configuration : configuration) ~dal_config ~name configuration.network + ~snapshot:configuration.snapshot cloud agent in @@ -2559,6 +2584,7 @@ let init_baker ?stake cloud (configuration : configuration) ~bootstrap teztale ~name:(Format.asprintf "baker-node-%d" i) ~rpc_external:configuration.external_rpc configuration.network + ~snapshot:configuration.snapshot cloud agent in @@ -2652,6 +2678,7 @@ let init_producer cloud configuration ~bootstrap teztale account i slot_index ~arguments:Node.[Peer bootstrap.node_p2p_endpoint] ~rpc_external:configuration.external_rpc configuration.network + ~snapshot:configuration.snapshot cloud agent in @@ -2745,6 +2772,7 @@ let init_observer cloud configuration ~bootstrap teztale ~topic i agent = ~arguments:[Peer bootstrap.node_p2p_endpoint] ~rpc_external:configuration.external_rpc configuration.network + ~snapshot:configuration.snapshot cloud agent in @@ -2801,8 +2829,8 @@ let init_observer cloud configuration ~bootstrap teztale ~topic i agent = in Lwt.return {node; dal_node; topic} -let init_etherlink_dal_node ~bootstrap ~next_agent ~dal_slots ~network ~otel - ~memtrace ~rpc_external ~cloud = +let init_etherlink_dal_node ~bootstrap ~next_agent ~dal_slots ~network ~snapshot + ~otel ~memtrace ~rpc_external ~cloud = match dal_slots with | [] -> toplog "Etherlink will run without DAL support" ; @@ -2821,6 +2849,7 @@ let init_etherlink_dal_node ~bootstrap ~next_agent ~dal_slots ~network ~otel [Peer bootstrap.node_p2p_endpoint; History_mode (Rolling (Some 79))] ~rpc_external network + ~snapshot cloud agent in @@ -2856,6 +2885,7 @@ let init_etherlink_dal_node ~bootstrap ~next_agent ~dal_slots ~network ~otel [Peer bootstrap.node_p2p_endpoint; History_mode (Rolling (Some 79))] ~rpc_external network + ~snapshot cloud agent in @@ -2884,6 +2914,7 @@ let init_etherlink_dal_node ~bootstrap ~next_agent ~dal_slots ~network ~otel ] ~rpc_external network + ~snapshot cloud agent in @@ -2921,6 +2952,7 @@ let init_etherlink_operator_setup cloud configuration etherlink_configuration [Peer bootstrap.node_p2p_endpoint; History_mode (Rolling (Some 79))] ~rpc_external:configuration.external_rpc configuration.network + ~snapshot:configuration.snapshot cloud agent in @@ -2975,6 +3007,7 @@ let init_etherlink_operator_setup cloud configuration etherlink_configuration ~next_agent ~dal_slots:etherlink_configuration.etherlink_dal_slots ~network:configuration.network + ~snapshot:configuration.snapshot ~rpc_external:configuration.external_rpc ~otel ~memtrace:configuration.memtrace @@ -3695,6 +3728,7 @@ let register (module Cli : Scenarios_cli.Dal) = let etherlink_producers = Cli.etherlink_producers in let disconnect = Cli.disconnect in let network = Cli.network in + let snapshot = Cli.snapshot in let bootstrap = Cli.bootstrap in let etherlink_dal_slots = Cli.etherlink_dal_slots in let teztale = Cli.teztale in @@ -3743,6 +3777,7 @@ let register (module Cli : Scenarios_cli.Dal) = producer_machine_type; disconnect; network; + snapshot; bootstrap; teztale; memtrace; diff --git a/tezt/tests/cloud/scenarios_cli.ml b/tezt/tests/cloud/scenarios_cli.ml index a345ddfa8f7e..a31917252f5e 100644 --- a/tezt/tests/cloud/scenarios_cli.ml +++ b/tezt/tests/cloud/scenarios_cli.ml @@ -30,6 +30,8 @@ module type Dal = sig val network : Network.t + val snapshot : string option + val bootstrap : bool val stake : int list @@ -157,6 +159,15 @@ module Dal () : Dal = struct network_typ `Sandbox + let snapshot = + Clap.optional_string + ~section + ~long:"snapshot" + ~description: + "Snapshot file, which is stored locally, to initiate the scenario with \ + some data" + () + let bootstrap = Clap.flag ~section -- GitLab