From 41f18893ca75b7557d35e84cab7f269a12055ff0 Mon Sep 17 00:00:00 2001 From: Eugen Zalinescu Date: Wed, 9 Oct 2024 15:34:56 +0200 Subject: [PATCH 1/2] Tezt/Cloud: run accuser when accuser_slot_indices CLI arg given --- tezt/lib_tezos/accuser.ml | 26 +++++++-- tezt/lib_tezos/accuser.mli | 2 + tezt/tests/cloud/dal.ml | 87 ++++++++++++++++++++++++++++++- tezt/tests/cloud/scenarios_cli.ml | 26 +++++++++ tezt/tests/cloud/tezos.ml | 13 ++++- 5 files changed, 147 insertions(+), 7 deletions(-) diff --git a/tezt/lib_tezos/accuser.ml b/tezt/lib_tezos/accuser.ml index 5140b8257269..a58438659a86 100644 --- a/tezt/lib_tezos/accuser.ml +++ b/tezt/lib_tezos/accuser.ml @@ -30,6 +30,7 @@ module Parameters = struct node : Node.t; mutable pending_ready : unit option Lwt.u list; preserved_levels : int option; + dal_node_rpc_endpoint : Endpoint.t option; } type session_state = {mutable ready : bool} @@ -61,7 +62,8 @@ let handle_raw_stdout accuser line = if line =~ rex "^Waiting for protocol .+ to start...$" then set_ready accuser let create ~protocol ?(path = Uses.path (Protocol.accuser protocol)) ?name - ?color ?event_pipe ?base_dir ?runner ?preserved_levels node = + ?color ?event_pipe ?base_dir ?runner ?preserved_levels + ?dal_node_rpc_endpoint node = let name = match name with None -> fresh_name () | Some name -> name in let base_dir = match base_dir with None -> Temp.dir name | Some dir -> dir @@ -73,7 +75,14 @@ let create ~protocol ?(path = Uses.path (Protocol.accuser protocol)) ?name ?color ?event_pipe ?runner - {runner; base_dir; node; pending_ready = []; preserved_levels} + { + runner; + base_dir; + node; + pending_ready = []; + preserved_levels; + dal_node_rpc_endpoint; + } in on_stdout accuser (handle_raw_stdout accuser) ; accuser @@ -92,6 +101,12 @@ let run ?event_level accuser = string_of_int accuser.persistent_state.preserved_levels in + let dal_node_endpoint = + Cli_arg.optional_arg + "dal-node" + Endpoint.as_string + accuser.persistent_state.dal_node_rpc_endpoint + in let arguments = [ "-E"; @@ -100,7 +115,7 @@ let run ?event_level accuser = accuser.persistent_state.base_dir; "run"; ] - @ preserved_levels + @ preserved_levels @ dal_node_endpoint in let on_terminate _ = (* Cancel all [Ready] event listeners. *) @@ -127,18 +142,19 @@ let wait_for_ready accuser = check_event accuser "Accuser started." promise let init ~protocol ?path ?name ?color ?event_pipe ?event_level ?base_dir ?runner - ?preserved_levels node = + ?preserved_levels ?dal_node_rpc_endpoint node = let* () = Node.wait_for_ready node in let accuser = create - ?path ~protocol + ?path ?name ?color ?event_pipe ?base_dir ?runner ?preserved_levels + ?dal_node_rpc_endpoint node in let* () = run ?event_level accuser in diff --git a/tezt/lib_tezos/accuser.mli b/tezt/lib_tezos/accuser.mli index 46a0d4b2ba5b..f583a38cc29e 100644 --- a/tezt/lib_tezos/accuser.mli +++ b/tezt/lib_tezos/accuser.mli @@ -66,6 +66,7 @@ val create : ?base_dir:string -> ?runner:Runner.t -> ?preserved_levels:int -> + ?dal_node_rpc_endpoint:Endpoint.t -> Node.t -> t @@ -169,6 +170,7 @@ val init : ?base_dir:string -> ?runner:Runner.t -> ?preserved_levels:int -> + ?dal_node_rpc_endpoint:Endpoint.t -> Node.t -> t Lwt.t diff --git a/tezt/tests/cloud/dal.ml b/tezt/tests/cloud/dal.ml index 97e30fbd9253..0f745b0e376f 100644 --- a/tezt/tests/cloud/dal.ml +++ b/tezt/tests/cloud/dal.ml @@ -382,6 +382,7 @@ type configuration = { dal_node_producers : int list; (* slot indices *) observer_slot_indices : int list; observer_pkhs : string list; + accuser_slot_indices : int list; protocol : Protocol.t; producer_machine_type : string option; (* The first argument is the deconnection frequency, the second is the @@ -416,6 +417,13 @@ type baker = { stake : int; } +type accuser = { + node : Node.t; + dal_node : Dal_node.t; + accuser : Accuser.t; + slot_index : int; +} + type producer = { node : Node.t; dal_node : Dal_node.t; @@ -516,6 +524,7 @@ type t = { bakers : baker list; producers : producer list; observers : observer list; + accusers : accuser list; etherlink : etherlink option; time_between_blocks : int; parameters : Dal_common.Parameters.t; @@ -1673,6 +1682,64 @@ let init_observer cloud configuration ~bootstrap teztale ~topic i agent = in Lwt.return {node; dal_node; topic} +let init_accuser cloud configuration ~bootstrap teztale ~slot_index i agent = + let name = Format.asprintf "accuser-node-%i" i in + let data_dir = + Cli.data_dir |> Option.map (fun data_dir -> data_dir // name) + in + let* node = + Node.init + ?data_dir + ~name + ~arguments:[Peer bootstrap.node_p2p_endpoint] + configuration.network + agent + in + let* dal_node = + Dal_node.Agent.create + ~name:(Format.asprintf "accuser-dal-node-%i" i) + ~node + agent + in + let* () = + Dal_node.init_config + ~expected_pow:(Network.expected_pow Cli.network) + ~observer_profiles:[slot_index] + ~peers:[bootstrap.dal_node_p2p_endpoint |> Option.get] + (* Invariant: Option.get don't fail because t.configuration.dal is true *) + dal_node + in + let otel = Cloud.open_telemetry_endpoint cloud in + let* () = + Dal_node.Agent.run + ?otel + ~memtrace:configuration.memtrace + ~event_level:`Notice + dal_node + in + let* () = + match teztale with + | None -> Lwt.return_unit + | Some teztale -> + Teztale.add_archiver + teztale + agent + ~node_name:(Node.name node) + ~node_port:(Node.rpc_port node) + in + let dal_node_rpc_endpoint = Dal_node.as_rpc_endpoint dal_node in + let* client = Client.Agent.create agent in + let* accuser = + Accuser.Agent.init + ~name:(Format.asprintf "accuser-%d" i) + ~protocol:configuration.protocol + ~base_dir:(Client.base_dir client) + ~dal_node_rpc_endpoint + node + agent + in + Lwt.return {node; dal_node; accuser; slot_index} + let init_etherlink_dal_node ~bootstrap ~next_agent ~name ~dal_slots ~network ~otel ~memtrace = match dal_slots with @@ -2138,6 +2205,14 @@ let init ~(configuration : configuration) etherlink_configuration cloud configuration.observer_pkhs |> Lwt.all in + let* accuser_agents = + List.map + (fun i -> + let name = Format.asprintf "accuser-%d" i in + next_agent ~name) + configuration.accuser_slot_indices + |> Lwt.all + in let* teztale = match bootstrap_agent with | None -> Lwt.return_none @@ -2200,8 +2275,15 @@ let init ~(configuration : configuration) etherlink_configuration cloud (fun i (topic, agent) -> init_observer cloud configuration ~bootstrap teztale ~topic i agent) (observers_slot_index_agents @ observers_bakers_agents) + and* accusers = + Lwt_list.mapi_p + (fun i (agent, slot_index) -> + init_accuser cloud configuration ~bootstrap teztale ~slot_index i agent) + (List.combine accuser_agents configuration.accuser_slot_indices) + in + let () = + toplog "Init: all producers, observers, and accusers have been initialized" in - let () = toplog "Init: all producers and observers have been initialized" in let* etherlink = match etherlink_configuration with | Some etherlink_configuration -> @@ -2276,6 +2358,7 @@ let init ~(configuration : configuration) etherlink_configuration cloud bootstrap; some_node_rpc_endpoint; bakers; + accusers; producers; observers; etherlink; @@ -2507,6 +2590,7 @@ let configuration, etherlink_configuration = in let observer_slot_indices = Cli.observer_slot_indices in let observer_pkhs = Cli.observer_pkhs in + let accuser_slot_indices = Cli.accuser_slot_indices in let protocol = Cli.protocol in let producer_machine_type = Cli.producer_machine_type in let etherlink = Cli.etherlink in @@ -2543,6 +2627,7 @@ let configuration, etherlink_configuration = dal_node_producers; observer_slot_indices; observer_pkhs; + accuser_slot_indices; protocol; producer_machine_type; disconnect; diff --git a/tezt/tests/cloud/scenarios_cli.ml b/tezt/tests/cloud/scenarios_cli.ml index 9718017db6c5..e999e7a5accf 100644 --- a/tezt/tests/cloud/scenarios_cli.ml +++ b/tezt/tests/cloud/scenarios_cli.ml @@ -166,6 +166,32 @@ let observer_slot_indices = (Clap.list_of_int "observer_slot_indices") [] +let accuser_slot_indices = + let slot_indices_typ = + let parse string = + try + string |> String.split_on_char ',' |> List.map int_of_string + |> Option.some + with _ -> + raise + (Invalid_argument + (Printf.sprintf + "Cli.accuser_slot_indices: could not parse %s" + string)) + in + let show l = l |> List.map string_of_int |> String.concat "," in + Clap.typ ~name:"accuser-slot-indices" ~dummy:[] ~parse ~show + in + Clap.default + ~section + ~long:"accuser-slot-indices" + ~placeholder:",,, ..." + ~description: + "For each slot index specified, an accuser will be created to monitor \ + this slot index." + slot_indices_typ + [] + let observer_pkhs = Clap.list_string ~section diff --git a/tezt/tests/cloud/tezos.ml b/tezt/tests/cloud/tezos.ml index 6ca0a05e859b..56cd2778c88b 100644 --- a/tezt/tests/cloud/tezos.ml +++ b/tezt/tests/cloud/tezos.ml @@ -290,10 +290,21 @@ module Accuser = struct module Agent = struct let init ?name ~protocol ?(path = Uses.path (Protocol.accuser protocol)) + ?color ?event_pipe ?base_dir ?preserved_levels ?dal_node_rpc_endpoint node agent = let* path = Agent.copy agent ~source:path in let runner = Agent.runner agent in - init ?name ~event_level:`Notice ?runner ~path ~protocol node + init + ~protocol + ~path + ?name + ?color + ?event_pipe (* ~event_level:`Notice *) + ?base_dir + ?preserved_levels + ?dal_node_rpc_endpoint + node + ?runner end end -- GitLab From 4cd4266da3330892e7c273c4bc797f04a2b2042a Mon Sep 17 00:00:00 2001 From: Eugen Zalinescu Date: Thu, 10 Oct 2024 16:29:36 +0200 Subject: [PATCH 2/2] Tezt: support --dal-slot-index --- tezt/lib_tezos/accuser.ml | 15 ++++++++++++--- tezt/lib_tezos/accuser.mli | 2 ++ tezt/tests/cloud/dal.ml | 1 + tezt/tests/cloud/tezos.ml | 3 ++- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/tezt/lib_tezos/accuser.ml b/tezt/lib_tezos/accuser.ml index a58438659a86..740eb0c01a5e 100644 --- a/tezt/lib_tezos/accuser.ml +++ b/tezt/lib_tezos/accuser.ml @@ -31,6 +31,7 @@ module Parameters = struct mutable pending_ready : unit option Lwt.u list; preserved_levels : int option; dal_node_rpc_endpoint : Endpoint.t option; + dal_slot_index : int option; } type session_state = {mutable ready : bool} @@ -63,7 +64,7 @@ let handle_raw_stdout accuser line = let create ~protocol ?(path = Uses.path (Protocol.accuser protocol)) ?name ?color ?event_pipe ?base_dir ?runner ?preserved_levels - ?dal_node_rpc_endpoint node = + ?dal_node_rpc_endpoint ?dal_slot_index node = let name = match name with None -> fresh_name () | Some name -> name in let base_dir = match base_dir with None -> Temp.dir name | Some dir -> dir @@ -82,6 +83,7 @@ let create ~protocol ?(path = Uses.path (Protocol.accuser protocol)) ?name pending_ready = []; preserved_levels; dal_node_rpc_endpoint; + dal_slot_index; } in on_stdout accuser (handle_raw_stdout accuser) ; @@ -107,6 +109,12 @@ let run ?event_level accuser = Endpoint.as_string accuser.persistent_state.dal_node_rpc_endpoint in + let dal_slot_index = + Cli_arg.optional_arg + "dal-slot-index" + string_of_int + accuser.persistent_state.dal_slot_index + in let arguments = [ "-E"; @@ -115,7 +123,7 @@ let run ?event_level accuser = accuser.persistent_state.base_dir; "run"; ] - @ preserved_levels @ dal_node_endpoint + @ preserved_levels @ dal_node_endpoint @ dal_slot_index in let on_terminate _ = (* Cancel all [Ready] event listeners. *) @@ -142,7 +150,7 @@ let wait_for_ready accuser = check_event accuser "Accuser started." promise let init ~protocol ?path ?name ?color ?event_pipe ?event_level ?base_dir ?runner - ?preserved_levels ?dal_node_rpc_endpoint node = + ?preserved_levels ?dal_node_rpc_endpoint ?dal_slot_index node = let* () = Node.wait_for_ready node in let accuser = create @@ -155,6 +163,7 @@ let init ~protocol ?path ?name ?color ?event_pipe ?event_level ?base_dir ?runner ?runner ?preserved_levels ?dal_node_rpc_endpoint + ?dal_slot_index node in let* () = run ?event_level accuser in diff --git a/tezt/lib_tezos/accuser.mli b/tezt/lib_tezos/accuser.mli index f583a38cc29e..a596ffb6458a 100644 --- a/tezt/lib_tezos/accuser.mli +++ b/tezt/lib_tezos/accuser.mli @@ -67,6 +67,7 @@ val create : ?runner:Runner.t -> ?preserved_levels:int -> ?dal_node_rpc_endpoint:Endpoint.t -> + ?dal_slot_index:int -> Node.t -> t @@ -171,6 +172,7 @@ val init : ?runner:Runner.t -> ?preserved_levels:int -> ?dal_node_rpc_endpoint:Endpoint.t -> + ?dal_slot_index:int -> Node.t -> t Lwt.t diff --git a/tezt/tests/cloud/dal.ml b/tezt/tests/cloud/dal.ml index 0f745b0e376f..356eadf5868f 100644 --- a/tezt/tests/cloud/dal.ml +++ b/tezt/tests/cloud/dal.ml @@ -1735,6 +1735,7 @@ let init_accuser cloud configuration ~bootstrap teztale ~slot_index i agent = ~protocol:configuration.protocol ~base_dir:(Client.base_dir client) ~dal_node_rpc_endpoint + ~dal_slot_index:slot_index node agent in diff --git a/tezt/tests/cloud/tezos.ml b/tezt/tests/cloud/tezos.ml index 56cd2778c88b..b2c3f352f31e 100644 --- a/tezt/tests/cloud/tezos.ml +++ b/tezt/tests/cloud/tezos.ml @@ -291,7 +291,7 @@ module Accuser = struct module Agent = struct let init ?name ~protocol ?(path = Uses.path (Protocol.accuser protocol)) ?color ?event_pipe ?base_dir ?preserved_levels ?dal_node_rpc_endpoint - node agent = + ?dal_slot_index node agent = let* path = Agent.copy agent ~source:path in let runner = Agent.runner agent in init @@ -303,6 +303,7 @@ module Accuser = struct ?base_dir ?preserved_levels ?dal_node_rpc_endpoint + ?dal_slot_index node ?runner end -- GitLab