diff --git a/tezt/lib_tezos/accuser.ml b/tezt/lib_tezos/accuser.ml index 5140b8257269dceaed0237b0a71371b6aa1c242f..740eb0c01a5e92a3ecf711a81de439cdc2621d28 100644 --- a/tezt/lib_tezos/accuser.ml +++ b/tezt/lib_tezos/accuser.ml @@ -30,6 +30,8 @@ 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; + dal_slot_index : int option; } type session_state = {mutable ready : bool} @@ -61,7 +63,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 ?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 @@ -73,7 +76,15 @@ 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; + dal_slot_index; + } in on_stdout accuser (handle_raw_stdout accuser) ; accuser @@ -92,6 +103,18 @@ 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 dal_slot_index = + Cli_arg.optional_arg + "dal-slot-index" + string_of_int + accuser.persistent_state.dal_slot_index + in let arguments = [ "-E"; @@ -100,7 +123,7 @@ let run ?event_level accuser = accuser.persistent_state.base_dir; "run"; ] - @ preserved_levels + @ preserved_levels @ dal_node_endpoint @ dal_slot_index in let on_terminate _ = (* Cancel all [Ready] event listeners. *) @@ -127,18 +150,20 @@ 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 ?dal_slot_index 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 + ?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 46a0d4b2ba5b87ce0cd089c496c8c8c51fc7eddb..a596ffb6458af3764463b6d9a08952e697d89108 100644 --- a/tezt/lib_tezos/accuser.mli +++ b/tezt/lib_tezos/accuser.mli @@ -66,6 +66,8 @@ val create : ?base_dir:string -> ?runner:Runner.t -> ?preserved_levels:int -> + ?dal_node_rpc_endpoint:Endpoint.t -> + ?dal_slot_index:int -> Node.t -> t @@ -169,6 +171,8 @@ val init : ?base_dir:string -> ?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 97e30fbd925372c396f3ddd24f37035416186df8..356eadf5868fd8e9b938f0909267bbdec4135abe 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,65 @@ 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 + ~dal_slot_index:slot_index + 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 +2206,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 +2276,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 +2359,7 @@ let init ~(configuration : configuration) etherlink_configuration cloud bootstrap; some_node_rpc_endpoint; bakers; + accusers; producers; observers; etherlink; @@ -2507,6 +2591,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 +2628,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 9718017db6c59421bb0bfc5fede9bc93457771aa..e999e7a5accff30618f3479d452eb66aeb7793e8 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 6ca0a05e859bb534fb5bf91755b33bf4ca3f0a29..b2c3f352f31ed827be99c6706edd29ec2ecdafeb 100644 --- a/tezt/tests/cloud/tezos.ml +++ b/tezt/tests/cloud/tezos.ml @@ -290,10 +290,22 @@ module Accuser = struct module Agent = struct let init ?name ~protocol ?(path = Uses.path (Protocol.accuser protocol)) - node agent = + ?color ?event_pipe ?base_dir ?preserved_levels ?dal_node_rpc_endpoint + ?dal_slot_index 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 + ?dal_slot_index + node + ?runner end end