diff --git a/tezt/tests/cloud/dal.ml b/tezt/tests/cloud/dal.ml index c15d73c407d283877b34767be8543fff4479d3bf..00a55944bfcd18576f10bc7532353a38994ce4fb 100644 --- a/tezt/tests/cloud/dal.ml +++ b/tezt/tests/cloud/dal.ml @@ -35,6 +35,8 @@ type agent_kind = | Etherlink_dal_operator | Etherlink_dal_observer of {slot_index : int} | Etherlink_producer of int + | Echo_rollup_operator + | Echo_rollup_dal_observer let name_of = function | Bootstrap -> "bootstrap" @@ -50,6 +52,8 @@ let name_of = function | 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 -> "echo-rollup-dal-node" type snapshot_config = | Docker_embedded of string @@ -589,6 +593,7 @@ type configuration = { producer_machine_type : string option; (* The first argument is the deconnection frequency, the second is the reconnection delay *) + echo_rollup : bool; disconnect : (int * int) option; network : Network.t; simulate_network : Cli.network_simulation_config; @@ -643,6 +648,14 @@ type observer = { topic : [`Slot_index of int | `Pkh of string]; } +type echo_operator = { + node : Node.t; + client : Client.t; + sc_rollup_node : Sc_rollup_node.t; + sc_rollup_address : string; + operator : Account.key; +} + type etherlink_operator_setup = { node : Node.t; client : Client.t; @@ -746,6 +759,7 @@ type t = { producers : producer list; (* NOTE: they have the observer profile*) observers : observer list; etherlink : etherlink option; + echo_rollup : echo_operator option; time_between_blocks : int; parameters : Dal_common.Parameters.t; infos : (int, per_level_info) Hashtbl.t; @@ -2537,6 +2551,19 @@ let init_producer_accounts (bootstrap : bootstrap) configuration = "A producer key can only be used if there is exactly one slot on \ which data are produced.") +let init_echo_rollup_account (bootstrap : bootstrap) + (configuration : configuration) = + if configuration.echo_rollup then + let () = toplog "Initializing the echo rollup key" in + let* key = + Client.stresstest_gen_keys + ~alias_prefix:"echo_operator" + 1 + bootstrap.client + in + Lwt.return_some (List.hd key) + else Lwt.return_none + let init_etherlink_operators (bootstrap : bootstrap) etherlink_configuration = let* etherlink_rollup_operator_key = if etherlink_configuration <> None then @@ -2700,6 +2727,7 @@ let init_public_network cloud (configuration : configuration) let* etherlink_rollup_operator_key, etherlink_batching_operator_keys = init_etherlink_operators bootstrap etherlink_configuration in + let* echo_rollup_key = init_echo_rollup_account bootstrap configuration in let accounts_to_fund = (if configuration.producer_key = None then List.map (fun producer -> (producer, 10 * 1_000_000)) producer_accounts @@ -2712,6 +2740,10 @@ let init_public_network cloud (configuration : configuration) @ List.map (fun batcher -> (batcher, 10 * 1_000_000)) etherlink_batching_operator_keys + @ Option.fold + ~none:[] + ~some:(fun operator -> [(operator, 11_000 * 1_000_000)]) + echo_rollup_key in let* () = fund_producers_accounts bootstrap configuration accounts_to_fund in let etherlink_rollup_operator_key = @@ -2722,7 +2754,8 @@ let init_public_network cloud (configuration : configuration) baker_accounts, producer_accounts, etherlink_rollup_operator_key, - etherlink_batching_operator_keys ) + etherlink_batching_operator_keys, + echo_rollup_key ) let round_robin_split m lst = assert (m > 0) ; @@ -2959,6 +2992,15 @@ let init_sandbox_and_activate_protocol cloud (configuration : configuration) Client.stresstest_gen_keys ~alias_prefix:"etherlink_batching" 20 client else Lwt.return [] in + let* echo_rollup_key = + if configuration.echo_rollup then + let* keys = + Client.stresstest_gen_keys ~alias_prefix:"echo_rollup_key" 1 client + in + Lwt.return_some (List.hd keys) + else Lwt.return_none + in + let* () = if configuration.simulate_network = Disabled then let* parameter_file = @@ -2974,7 +3016,8 @@ let init_sandbox_and_activate_protocol cloud (configuration : configuration) List.map (fun key -> (key, Some 1_000_000_000_000, false)) (producer_accounts @ etherlink_rollup_operator_key - @ etherlink_batching_operator_keys) + @ etherlink_batching_operator_keys + @ Option.fold ~none:[] ~some:(fun k -> [k]) echo_rollup_key) in let overrides = [] in Protocol.write_parameter_file @@ -3056,7 +3099,8 @@ let init_sandbox_and_activate_protocol cloud (configuration : configuration) baker_accounts, producer_accounts, etherlink_rollup_operator_key, - etherlink_batching_operator_keys ) + etherlink_batching_operator_keys, + echo_rollup_key ) let init_baker ?stake cloud (configuration : configuration) ~bootstrap teztale ~baker_accounts i agent = @@ -3927,6 +3971,146 @@ let init_etherlink cloud configuration etherlink_configuration ~bootstrap in return {configuration = etherlink_configuration; operator; accounts} +let init_echo_rollup cloud configuration ~bootstrap operator dal_slots + next_agent = + let name = name_of Echo_rollup_operator in + let* agent = next_agent ~name in + let data_dir = + configuration.data_dir |> Option.map (fun data_dir -> data_dir // name) + in + let with_yes_crypto = + match configuration.simulate_network with + | Scatter _ | Map _ -> true + | Disabled -> false + in + let* node = + Node.init + ?data_dir + ~name + ~arguments: + (* Keeping enough data for refutation games -- might be adjusted if need. *) + [Peer bootstrap.node_p2p_endpoint; History_mode (Rolling (Some 79))] + ~rpc_external:configuration.external_rpc + configuration.network + ~snapshot:configuration.snapshot + ~with_yes_crypto + cloud + agent + in + let endpoint = Client.Node node in + let* client = Client.Agent.create ~endpoint agent in + let () = toplog "Init Echo rollup: importing the operator secret key" in + let* () = + Client.import_secret_key + client + ~endpoint + operator.Account.secret_key + ~alias:operator.Account.alias + in + + let l = Node.get_last_seen_level node in + let () = toplog "Init Echo rollup: revealing the operator account" in + let*! () = Client.reveal client ~endpoint ~src:operator.Account.alias in + let () = toplog "Init Echo rollup: waiting for level %d" (l + 2) in + let* _ = Node.wait_for_level node (l + 2) in + let () = toplog "Init Echo rollup: waiting for level %d: done" (l + 2) in + + let otel = Cloud.open_telemetry_endpoint cloud in + let* dal_node = + let name = name_of Echo_rollup_dal_observer in + let* agent = next_agent ~name in + let* dal_node = Dal_node.Agent.create ~name ~node cloud agent in + let* () = + Dal_node.init_config + ~expected_pow:(Network.expected_pow configuration.network) + ~observer_profiles:dal_slots + ~peers:(Option.to_list bootstrap.dal_node_p2p_endpoint) + dal_node + in + let* () = + Dal_node.Agent.run + ?otel + ~ppx_profiling:configuration.ppx_profiling + ~ppx_profiling_backends:configuration.ppx_profiling_backends + dal_node + in + some dal_node + in + let* sc_rollup_node = + Sc_rollup_node.Agent.create + ~name:(Format.asprintf "%s-rollup-node" name) + ~base_dir:(Client.base_dir client) + ~default_operator:operator.alias + ~operators:[(Sc_rollup_node.Operating, operator.Account.alias)] + ?dal_node + cloud + agent + Operator + node + in + let preimages_dir = + Filename.concat (Sc_rollup_node.data_dir sc_rollup_node) "wasm_2_0_0" + in + let slots_bitvector = + List.fold_left + (fun vec slot -> Z.logor vec (Z.of_int (1 lsl slot))) + Z.zero + dal_slots + in + let config = + Format.sprintf + {|instructions: +- set: + value: %s + to: /slots + |} + (Z.to_bits slots_bitvector |> Hex.of_string |> Hex.show) + in + let output_config = Temp.file "config.yaml" in + write_file output_config ~contents:config ; + let* remote_output_config = Agent.copy agent ~source:output_config in + let* {output; _} = + Sc_rollup_helpers.Agent.prepare_installer_kernel + ~config:(`Path remote_output_config) + ~preimages_dir + Constant.WASM.dal_echo_kernel_bandwidth + agent + in + let pvm_kind = "wasm_2_0_0" in + let l = Node.get_last_seen_level node in + let () = toplog "Init Echo rollup: originating the rollup" in + let* sc_rollup_address = + Sc_rollup_helpers.Agent.originate_sc_rollup + ~kind:pvm_kind + ~boot_sector:output + ~parameters_ty:"unit" + ~src:operator.alias + client + in + let () = toplog "Init Echo rollup: waiting again, for level %d" (l + 2) in + let* _ = Node.wait_for_level node (l + 2) in + let () = + toplog "Init Echo rollup: waiting again, for level %d: done" (l + 2) + in + let () = toplog "Init Echo rollup: launching the rollup node" in + let* () = + Sc_rollup_node.run sc_rollup_node sc_rollup_address [Log_kernel_debug] + in + let () = toplog "Init Echo rollup: launching the rollup node: done" in + let operator : echo_operator = + {node; client; sc_rollup_node; operator; sc_rollup_address} + in + let* () = + add_prometheus_source + ?dal_node + ~node + ~sc_rollup_node + cloud + agent + (Format.asprintf "echo-%s" name) + in + return operator + let obtain_some_node_rpc_endpoint agent network (bootstrap : bootstrap) (bakers : baker list) (producers : producer list) (observers : observer list) etherlink = @@ -4026,7 +4210,8 @@ let init ~(configuration : configuration) etherlink_configuration cloud baker_accounts, producer_accounts, etherlink_rollup_operator_key, - etherlink_batching_operator_keys ) = + etherlink_batching_operator_keys, + echo_rollup_key ) = match configuration.network with | `Sandbox -> let bootstrap_agent = Option.get bootstrap_agent in @@ -4122,6 +4307,24 @@ let init ~(configuration : configuration) etherlink_configuration cloud (observers_slot_index_agents @ observers_bakers_agents) in let () = toplog "Init: all producers and observers have been initialized" in + let* echo_rollup = + match echo_rollup_key with + | Some operator -> + let dal_slots = List.map (fun p -> p.slot_index) producers in + let* echo_rollup = + init_echo_rollup + cloud + configuration + ~bootstrap + operator + dal_slots + next_agent + in + Lwt.return_some echo_rollup + | _ -> Lwt.return_none + in + + let () = toplog "Init: Echo rollup has been initialized" in let* etherlink = match etherlink_configuration with | Some etherlink_configuration -> @@ -4219,6 +4422,7 @@ let init ~(configuration : configuration) etherlink_configuration cloud bakers; producers; observers; + echo_rollup; etherlink; time_between_blocks; parameters; @@ -4601,6 +4805,7 @@ let register (module Cli : Scenarios_cli.Dal) = let etherlink = Cli.etherlink in let etherlink_sequencer = Cli.etherlink_sequencer in let etherlink_producers = Cli.etherlink_producers in + let echo_rollup = Cli.echo_rollup in let disconnect = Cli.disconnect in let network = Cli.network in let snapshot = parse_snapshot_arg Cli.snapshot in @@ -4655,6 +4860,7 @@ let register (module Cli : Scenarios_cli.Dal) = observer_pkhs; protocol; producer_machine_type; + echo_rollup; disconnect; network; simulate_network; @@ -4716,6 +4922,9 @@ let register (module Cli : Scenarios_cli.Dal) = | None -> [] | Some {etherlink_producers; _} -> List.init etherlink_producers (fun i -> Etherlink_producer i)); + (if configuration.echo_rollup then + [Echo_rollup_operator; Echo_rollup_dal_observer] + else []); ] in let docker_image = @@ -4749,8 +4958,10 @@ let register (module Cli : Scenarios_cli.Dal) = | Producer _ -> let machine_type = configuration.producer_machine_type in Agent.Configuration.make ?docker_image ?machine_type ~name () - | Observer _ | Etherlink_dal_operator | Etherlink_dal_observer _ -> + | Observer _ | Etherlink_dal_operator | Etherlink_dal_observer _ + | Echo_rollup_dal_observer -> Agent.Configuration.make ?docker_image ~name () + | Echo_rollup_operator -> default_vm_configuration ~name | Etherlink_operator -> default_vm_configuration ~name | Etherlink_producer _ -> default_vm_configuration ~name | Reverse_proxy -> default_vm_configuration ~name) diff --git a/tezt/tests/cloud/scenarios_cli.ml b/tezt/tests/cloud/scenarios_cli.ml index e77e2c6535bf9e0642724776b3cdd878c7a88490..140e9603c145cb05641c2d71bbcf8585d21f7551 100644 --- a/tezt/tests/cloud/scenarios_cli.ml +++ b/tezt/tests/cloud/scenarios_cli.ml @@ -149,6 +149,8 @@ module type Dal = sig val etherlink_chain_id : int option + val echo_rollup : bool + val disconnect : (int * int) option val etherlink_dal_slots : int list @@ -482,6 +484,8 @@ module Dal () : Dal = struct let etherlink_chain_id = Clap.optional_int ~section ~long:"etherlink-chain-id" () + let echo_rollup = Clap.flag ~section ~set_long:"echo-rollup" false + let disconnect = let disconnect_typ = let parse string =