From 10682870b1715689e4fc1369b5f86c20535b91cf Mon Sep 17 00:00:00 2001 From: Andrea Cerone Date: Thu, 26 Jan 2023 15:17:17 +0000 Subject: [PATCH 1/2] Dac: change client commands to handle multiple running modes --- src/bin_dac_node/main_dac.ml | 314 ++++++++++++++++++----------------- tezt/tests/dac.ml | 6 +- 2 files changed, 170 insertions(+), 150 deletions(-) diff --git a/src/bin_dac_node/main_dac.ml b/src/bin_dac_node/main_dac.ml index 4f5215735940..e6506f4dd6c1 100644 --- a/src/bin_dac_node/main_dac.ml +++ b/src/bin_dac_node/main_dac.ml @@ -24,6 +24,23 @@ (* *) (*****************************************************************************) +type error += Invalid_positive_int_parameter of string + +let () = + register_error_kind + `Permanent + ~id:"dac.node.dac.invalid_positive_int_parameter" + ~title:"Argument is not a positive integer" + ~description:"Argument must be a positive integer" + ~pp:(fun ppf reveal_data_path -> + Format.fprintf + ppf + "Expected a valid positive integer, provided %s instead" + reveal_data_path) + Data_encoding.(obj1 (req "arg" string)) + (function Invalid_positive_int_parameter s -> Some s | _ -> None) + (fun s -> Invalid_positive_int_parameter s) + let group = {Tezos_clic.name = "dac-node"; title = "Commands related to the DAC node"} @@ -39,6 +56,43 @@ let data_dir_arg = ~default (Client_config.string_parameter ()) +let reveal_data_dir_arg = + let default = Configuration.default_reveal_data_dir in + Tezos_clic.default_arg + ~long:"reveal-data-dir" + ~placeholder:"reveal-data-dir" + ~doc:"The directory where reveal preimage pages are saved." + ~default + (Client_config.string_parameter ()) + +let tz4_address_parameter = + Tezos_clic.parameter (fun _cctxt s -> + let open Lwt_result_syntax in + let*? bls_pkh = Signature.Bls.Public_key_hash.of_b58check s in + let pkh : Tezos_crypto.Aggregate_signature.public_key_hash = + Tezos_crypto.Aggregate_signature.Bls12_381 bls_pkh + in + return pkh) + +let tz4_address_param ?(name = "public key hash") + ?(desc = "bls public key hash to use") = + let desc = String.concat "\n" [desc; "A tz4 address"] in + Tezos_clic.param ~name ~desc tz4_address_parameter + +let positive_int_parameter = + Tezos_clic.parameter (fun _cctxt p -> + let open Lwt_result_syntax in + let* i = + try Lwt.return_ok (int_of_string p) + with _ -> tzfail @@ Invalid_positive_int_parameter p + in + if i < 0 then tzfail @@ Invalid_positive_int_parameter p else return i) + +let threshold_param ?(name = "DAC threshold parameter") + ?(desc = + "Number of DAC member signatures required to validate a root page hash") = + Tezos_clic.param ~name ~desc positive_int_parameter + let rpc_address_arg = let default = Configuration.default_rpc_address in Tezos_clic.default_arg @@ -51,16 +105,6 @@ let rpc_address_arg = ~default (Client_config.string_parameter ()) -let int_parameter = - let open Tezos_clic in - parameter (fun _ p -> - let open Lwt_result_syntax in - let* i = - try Lwt.return_ok (int_of_string p) - with _ -> failwith "Cannot read int" - in - if i < 0 then failwith "Parameter must be non-negative" else return i) - let rpc_port_arg = let default = Configuration.default_rpc_port |> string_of_int in Tezos_clic.default_arg @@ -71,152 +115,124 @@ let rpc_port_arg = "The port the DAC node listens to. Default value is %s" default) ~default - int_parameter - -let config_init_command = - let open Lwt_result_syntax in - let open Tezos_clic in - command - ~group - ~desc:"Configure DAC node." - (args3 data_dir_arg rpc_address_arg rpc_port_arg) - (prefixes ["init-config"] stop) - (fun (data_dir, rpc_address, rpc_port) cctxt -> - let open Configuration in - let config = - { - data_dir; - rpc_address; - rpc_port; - mode = - Legacy - { - threshold = 0; - dac_members_addresses = []; - dac_cctxt_config = None; - }; - reveal_data_dir = default_reveal_data_dir; - } - in - let* () = save config in - let*! _ = - cctxt#message "DAC node configuration written in %s" (filename config) - in - return ()) - -(* DAC/FIXME: https://gitlab.com/tezos/tezos/-/issues/4125 - Move the following commands to a dac node once we have one. *) -module Dac_client = struct - let reveal_data_dir_arg = - Tezos_clic.arg - ~long:"reveal-data-dir" - ~placeholder:"reveal-data-dir" - ~doc:"The directory where reveal preimage pages are saved." - (Client_config.string_parameter ()) - - let threshold_arg = - Tezos_clic.arg - ~long:"threshold" - ~placeholder:"threshold" - ~doc: - "The number of signatures needed from the Data Availability Committee \ - members to validate reveal data.)" - int_parameter - - let tz4_address_parameter () = - Tezos_clic.parameter (fun _cctxt s -> - let open Lwt_result_syntax in - let*? bls_pkh = Signature.Bls.Public_key_hash.of_b58check s in - let pkh : Tezos_crypto.Aggregate_signature.public_key_hash = - Tezos_crypto.Aggregate_signature.Bls12_381 bls_pkh - in - return pkh) - - let tz4_address_param ?(name = "public key hash") - ?(desc = "bls public key hash to use") = - let desc = String.concat "\n" [desc; "A tz4 address"] in - Tezos_clic.param ~name ~desc (tz4_address_parameter ()) - - (** Add an account alias as a member of the Data availability Committee in the - configuration of the Dac node. *) - let add_dac_alias_command = + positive_int_parameter + +let coordinator_rpc_parameter = + Tezos_clic.parameter (fun _cctxt h -> + match String.split ':' h with + | [host_name; port] -> ( + try Lwt.return_ok (host_name, int_of_string port) + with _ -> failwith "Address not in format :") + | _ -> failwith "Address not in format :") + +let coordinator_rpc_param ?(name = "DAC coordinator rpc address parameter") + ?(desc = "The address of the DAC coordinator") = + let desc = + String.concat "\n" [desc; "An address of the form :"] + in + Tezos_clic.param ~name ~desc coordinator_rpc_parameter + +module Config_init = struct + let create_configuration ~data_dir ~reveal_data_dir ~rpc_address ~rpc_port + mode (cctxt : Client_context.full) = let open Lwt_result_syntax in + let open Configuration in + let config = {data_dir; rpc_address; rpc_port; reveal_data_dir; mode} in + let* () = save config in + let*! _ = + cctxt#message "DAC node configuration written in %s" (filename config) + in + return () + + let legacy_command = + let open Tezos_clic in + command + ~group + ~desc:"Configure DAC node in legacy mode." + (args4 data_dir_arg rpc_address_arg rpc_port_arg reveal_data_dir_arg) + (prefixes ["configure"; "as"; "legacy"; "with"; "threshold"] + @@ threshold_param + @@ prefixes ["and"; "data"; "availability"; "committee"; "members"] + @@ seq_of_param @@ tz4_address_param) + (fun (data_dir, rpc_address, rpc_port, reveal_data_dir) + threshold + dac_members_addresses + cctxt -> + create_configuration + ~data_dir + ~reveal_data_dir + ~rpc_address + ~rpc_port + (Configuration.Legacy + {threshold; dac_members_addresses; dac_cctxt_config = None}) + cctxt) + + let coordinator_command = let open Tezos_clic in command ~group - ~desc:"Add an account alias as Data Availability Committee member" - (args1 data_dir_arg) - (prefixes ["add"; "data"; "availability"; "committee"; "member"] + ~desc:"Configure DAC node in coordinator mode." + (args4 data_dir_arg rpc_address_arg rpc_port_arg reveal_data_dir_arg) + (prefixes ["configure"; "as"; "coordinator"; "with"; "threshold"] + @@ threshold_param + @@ prefixes ["and"; "data"; "availability"; "committee"; "members"] + @@ seq_of_param @@ tz4_address_param) + (fun (data_dir, rpc_address, rpc_port, reveal_data_dir) + threshold + dac_members_addresses + cctxt -> + create_configuration + ~data_dir + ~reveal_data_dir + ~rpc_address + ~rpc_port + (Coordinator {threshold; dac_members_addresses}) + cctxt) + + let dac_member_command = + let open Tezos_clic in + command + ~group + ~desc:"Configure DAC node in committee member mode." + (args4 data_dir_arg rpc_address_arg rpc_port_arg reveal_data_dir_arg) + (prefixes + ["configure"; "as"; "commmittee"; "member"; "with"; "coordinator"] + @@ coordinator_rpc_param + @@ prefixes ["and"; "signer"] @@ tz4_address_param @@ stop) - (fun data_dir dac_member_address cctxt -> - let open Configuration in - let* config = load ~data_dir in - let* ({dac_members_addresses = old_dac_members_addresses; _} as - legacy_config) = - match config.mode with - | Legacy config -> return config - | _ -> failwith "Configuration is not in legacy mode" - in - if - List.mem - ~equal:Tezos_crypto.Aggregate_signature.Public_key_hash.equal - dac_member_address - old_dac_members_addresses - then - let*! _ = - cctxt#message - "Alias is already listed as a DAC member %s" - (filename config) - in - return_unit - else - let dac_members_addresses = - old_dac_members_addresses @ [dac_member_address] - in - let mode = Legacy {legacy_config with dac_members_addresses} in - let* () = save {config with mode} in - let*! _ = - cctxt#message - "DAC address added to configuration in %s" - (filename config) - in - return_unit) - - (* DAC/TODO: https://gitlab.com/tezos/tezos/-/issues/4136 - Add option to specify a list of addresses from a file. *) - let set_parameters_command = - let open Lwt_result_syntax in + (fun (data_dir, rpc_address, rpc_port, reveal_data_dir) + (coordinator_rpc_address, coordinator_rpc_port) + address + cctxt -> + create_configuration + ~data_dir + ~reveal_data_dir + ~rpc_address + ~rpc_port + (Dac_member {coordinator_rpc_address; coordinator_rpc_port; address}) + cctxt) + + let observer_command = let open Tezos_clic in command ~group - ~desc:"Configure DAC parameters." - (args3 data_dir_arg threshold_arg reveal_data_dir_arg) - (prefixes ["set"; "dac"; "parameters"] stop) - (fun (data_dir, threshold, reveal_data_dir) cctxt -> - let open Configuration in - let* config = load ~data_dir in - let* legacy_config = - match config.mode with - | Legacy config -> return config - | _ -> failwith "Only legacy mode supported." - in - let threshold = - Option.value threshold ~default:legacy_config.threshold - in - let reveal_data_dir = - Option.value reveal_data_dir ~default:config.reveal_data_dir - in - let mode = Legacy {legacy_config with threshold} in - let config = {config with reveal_data_dir; mode} in - let* () = save config in - let*! _ = - cctxt#message - "DAC parameters set for configuration in %s" - (filename config) - in - return ()) - - let commands = [add_dac_alias_command; set_parameters_command] + ~desc:"Configure DAC node in observer mode." + (args4 data_dir_arg rpc_address_arg rpc_port_arg reveal_data_dir_arg) + (prefixes ["configure"; "as"; "observer"; "with"; "coordinator"] + @@ coordinator_rpc_param @@ stop) + (fun (data_dir, rpc_address, rpc_port, reveal_data_dir) + (coordinator_rpc_address, coordinator_rpc_port) + cctxt -> + create_configuration + ~data_dir + ~reveal_data_dir + ~rpc_address + ~rpc_port + (Observer {coordinator_rpc_address; coordinator_rpc_port}) + cctxt) + + let commands = + [legacy_command; coordinator_command; dac_member_command; observer_command] end let run_command = @@ -228,7 +244,7 @@ let run_command = (prefixes ["run"] @@ stop) (fun data_dir cctxt -> Daemon.run ~data_dir cctxt) -let commands () = [run_command; config_init_command] @ Dac_client.commands +let commands () = [run_command] @ Config_init.commands let select_commands _ _ = let open Lwt_result_syntax in diff --git a/tezt/tests/dac.ml b/tezt/tests/dac.ml index 47fcba7e384c..837a86441730 100644 --- a/tezt/tests/dac.ml +++ b/tezt/tests/dac.ml @@ -3,6 +3,7 @@ (* Open Source License *) (* Copyright (c) 2022 Nomadic Labs *) (* Copyright (c) 2023 Marigold *) +(* Copyright (c) 2023 Trili Tech *) (* *) (* Permission is hereby granted, free of charge, to any person obtaining a *) (* copy of this software and associated documentation files (the "Software"),*) @@ -408,7 +409,8 @@ let test_dac_node_handles_dac_store_preimage_hash_chain_V0 _protocol dac_node unit let test_dac_node_handles_dac_retrieve_preimage_merkle_V0 _protocol dac_node - sc_rollup_node _sc_rollup_address _node _client pvm_name = + sc_rollup_node _sc_rollup_address _node _client pvm_name _threshold + _dac_members = let payload = "test" in let* actual_rh, _l1_operation = RPC.call @@ -863,6 +865,8 @@ let register ~protocols = protocols ; scenario_with_all_nodes ~tags:["dac"; "dac_node"] + ~threshold:0 + ~dac_members:0 "dac_retrieve_preimage" test_dac_node_handles_dac_retrieve_preimage_merkle_V0 protocols ; -- GitLab From 08072eb3e2755a5d03640ef97d68707fbfb89739 Mon Sep 17 00:00:00 2001 From: Andrea Cerone Date: Thu, 2 Feb 2023 16:01:40 +0000 Subject: [PATCH 2/2] DAC/Tezt: fix tezts using legacy DAC node commands --- tezt/lib_tezos/dac_node.ml | 245 +++++++++++++++++++++++++++++------- tezt/lib_tezos/dac_node.mli | 91 ++++++++++---- tezt/tests/dac.ml | 226 +++++++++++++++++++-------------- tezt/tests/evm_rollup.ml | 25 ++-- tezt/tests/sc_rollup.ml | 25 ++-- 5 files changed, 426 insertions(+), 186 deletions(-) diff --git a/tezt/lib_tezos/dac_node.ml b/tezt/lib_tezos/dac_node.ml index 64f24395c7a8..edb0bcfb7b3e 100644 --- a/tezt/lib_tezos/dac_node.ml +++ b/tezt/lib_tezos/dac_node.ml @@ -24,10 +24,33 @@ (*****************************************************************************) module Parameters = struct + type legacy_mode_settings = {threshold : int; dac_members : string list} + + type coordinator_mode_settings = {threshold : int; dac_members : string list} + + type dac_member_mode_settings = { + address : string; + coordinator_rpc_host : string; + coordinator_rpc_port : int; + } + + type observer_mode_settings = { + coordinator_rpc_host : string; + coordinator_rpc_port : int; + } + + type mode_settings = + | Legacy of legacy_mode_settings + | Coordinator of coordinator_mode_settings + | Dac_member of dac_member_mode_settings + | Observer of observer_mode_settings + type persistent_state = { data_dir : string; + reveal_data_dir : string; rpc_host : string; rpc_port : int; + mode : mode_settings; node : Node.t; client : Client.t; mutable pending_ready : unit option Lwt.u list; @@ -58,6 +81,13 @@ let is_running_not_ready dac_node = let name dac_node = dac_node.name +let mode dac_node = + match dac_node.persistent_state.mode with + | Legacy _ -> "Legacy" + | Coordinator _ -> "Coordinator" + | Dac_member _ -> "Dac_member" + | Observer _ -> "Observer" + let rpc_host dac_node = dac_node.persistent_state.rpc_host let rpc_port dac_node = dac_node.persistent_state.rpc_port @@ -71,20 +101,81 @@ let endpoint dac_node = let data_dir dac_node = dac_node.persistent_state.data_dir +let reveal_data_dir dac_node = dac_node.persistent_state.reveal_data_dir + let spawn_command dac_node = Process.spawn ~name:dac_node.name ~color:dac_node.color dac_node.path let spawn_config_init dac_node = - spawn_command dac_node - @@ [ - "init-config"; - "--data-dir"; - data_dir dac_node; - "--rpc-port"; - string_of_int (rpc_port dac_node); - "--rpc-addr"; - rpc_host dac_node; - ] + let arg_command = + [ + "--data-dir"; + data_dir dac_node; + "--rpc-port"; + string_of_int (rpc_port dac_node); + "--rpc-addr"; + rpc_host dac_node; + "--reveal-data-dir"; + reveal_data_dir dac_node; + ] + in + let mode_command = + match dac_node.persistent_state.mode with + | Legacy legacy_params -> + [ + "configure"; + "as"; + "legacy"; + "with"; + "threshold"; + Int.to_string legacy_params.threshold; + "and"; + "data"; + "availability"; + "committee"; + "members"; + ] + @ legacy_params.dac_members + | Coordinator coordinator_params -> + [ + "configure"; + "as"; + "coordinator"; + "with"; + "threshold"; + Int.to_string coordinator_params.threshold; + "and"; + "data"; + "availability"; + "committee"; + "members"; + ] + @ coordinator_params.dac_members + | Dac_member dac_member_params -> + let coordinator_host = + dac_member_params.coordinator_rpc_host ^ ":" + ^ Int.to_string dac_member_params.coordinator_rpc_port + in + [ + "configure"; + "as"; + "committee"; + "member"; + "with"; + "coordinator"; + coordinator_host; + "and"; + "signer"; + dac_member_params.address; + ] + | Observer observer_params -> + let coordinator_host = + observer_params.coordinator_rpc_host ^ ":" + ^ Int.to_string observer_params.coordinator_rpc_port + in + ["configure"; "as"; "observer"; "with"; "coordinator"; coordinator_host] + in + spawn_command dac_node (mode_command @ arg_command) let init_config dac_node = let process = spawn_config_init dac_node in @@ -93,41 +184,6 @@ let init_config dac_node = | None -> failwith "DAC node configuration initialization failed" | Some filename -> return filename -module Dac = struct - let spawn_set_parameters ?threshold ?reveal_data_dir dac_node = - let threshold_arg = - match threshold with - | None -> [] - | Some threshold -> ["--threshold"; Int.to_string threshold] - in - let reveal_data_dir_arg = - match reveal_data_dir with - | None -> [] - | Some reveal_data_dir -> ["--reveal-data-dir"; reveal_data_dir] - in - let data_dir_arg = ["--data-dir"; data_dir dac_node] in - spawn_command dac_node - @@ ["set"; "dac"; "parameters"] - @ threshold_arg @ reveal_data_dir_arg @ data_dir_arg - - let set_parameters ?threshold ?reveal_data_dir dac_node = - spawn_set_parameters ?threshold ?reveal_data_dir dac_node |> Process.check - - let spawn_add_committee_member ~address dac_node = - let base_dir_argument = - ["--base-dir"; Client.base_dir dac_node.persistent_state.client] - in - spawn_command - dac_node - (base_dir_argument - @ ["add"; "data"; "availability"; "committee"; "member"] - @ [address] - @ ["--data-dir"; dac_node.persistent_state.data_dir]) - - let add_committee_member ~address dac_node = - spawn_add_committee_member ~address dac_node |> Process.check -end - module Config_file = struct let filename dac_node = sf "%s/config.json" @@ data_dir dac_node @@ -180,11 +236,17 @@ let handle_event dac_node {name; value = _; timestamp = _} = match name with "dac_node_is_ready.v0" -> set_ready dac_node | _ -> () let create ?(path = Constant.dac_node) ?name ?color ?data_dir ?event_pipe - ?(rpc_host = "127.0.0.1") ?rpc_port ~node ~client () = + ?(rpc_host = "127.0.0.1") ?rpc_port ?reveal_data_dir ~mode ~node ~client () + = let name = match name with None -> fresh_name () | Some name -> name in let data_dir = match data_dir with None -> Temp.dir name | Some dir -> dir in + let reveal_data_dir = + match reveal_data_dir with + | None -> Temp.dir (name ^ "preimages") + | Some dir -> dir + in let rpc_port = match rpc_port with None -> Port.fresh () | Some port -> port in @@ -194,11 +256,100 @@ let create ?(path = Constant.dac_node) ?name ?color ?data_dir ?event_pipe ~name ?color ?event_pipe - {data_dir; rpc_host; rpc_port; pending_ready = []; node; client} + { + data_dir; + reveal_data_dir; + rpc_host; + rpc_port; + mode; + pending_ready = []; + node; + client; + } in on_event dac_node (handle_event dac_node) ; dac_node +let create_legacy ?(path = Constant.dac_node) ?name ?color ?data_dir ?event_pipe + ?(rpc_host = "127.0.0.1") ?rpc_port ?reveal_data_dir ~threshold ~dac_members + ~node ~client () = + let mode = Legacy {threshold; dac_members} in + create + ~path + ?name + ?color + ?data_dir + ?event_pipe + ~rpc_host + ?rpc_port + ?reveal_data_dir + ~mode + ~node + ~client + () + +let create_coordinator ?(path = Constant.dac_node) ?name ?color ?data_dir + ?event_pipe ?(rpc_host = "127.0.0.1") ?rpc_port ?reveal_data_dir ~threshold + ~dac_members ~node ~client () = + let mode = Coordinator {threshold; dac_members} in + create + ~path + ?name + ?color + ?data_dir + ?event_pipe + ~rpc_host + ?rpc_port + ?reveal_data_dir + ~mode + ~node + ~client + () + +let create_dac_member ?(path = Constant.dac_node) ?name ?color ?data_dir + ?event_pipe ?(rpc_host = "127.0.0.1") ?rpc_port ?reveal_data_dir + ?(coordinator_rpc_host = "127.0.0.1") ?coordinator_rpc_port ~address ~node + ~client () = + let coordinator_rpc_port = + match coordinator_rpc_port with None -> Port.fresh () | Some port -> port + in + let mode = Dac_member {address; coordinator_rpc_host; coordinator_rpc_port} in + create + ~path + ?name + ?color + ?data_dir + ?event_pipe + ~rpc_host + ?rpc_port + ?reveal_data_dir + ~mode + ~node + ~client + () + +let create_observer ?(path = Constant.dac_node) ?name ?color ?data_dir + ?event_pipe ?(rpc_host = "127.0.0.1") ?rpc_port ?reveal_data_dir + ?(coordinator_rpc_host = "127.0.0.1") ?coordinator_rpc_port ~node ~client () + = + let coordinator_rpc_port = + match coordinator_rpc_port with None -> Port.fresh () | Some port -> port + in + let mode = Observer {coordinator_rpc_host; coordinator_rpc_port} in + create + ~path + ?name + ?color + ?data_dir + ?event_pipe + ~rpc_host + ?rpc_port + ?reveal_data_dir + ~mode + ~node + ~client + () + let make_arguments node = let base_dir_args = ["--base-dir"; Client.base_dir node.persistent_state.client] diff --git a/tezt/lib_tezos/dac_node.mli b/tezt/lib_tezos/dac_node.mli index fbd9a6dfbeb9..6ea3101c414b 100644 --- a/tezt/lib_tezos/dac_node.mli +++ b/tezt/lib_tezos/dac_node.mli @@ -25,12 +25,30 @@ (** Spawn Data-availability-committee (DAC) nodes and control them. *) -(** DAC Node state *) +(** DAC Node state. *) type t -(** Creates a DAC node *) +(** Creates a DAC node to run in legacy mode, using the specified threshold + and list of dac members. *) +val create_legacy : + ?path:string -> + ?name:string -> + ?color:Log.Color.t -> + ?data_dir:string -> + ?event_pipe:string -> + ?rpc_host:string -> + ?rpc_port:int -> + ?reveal_data_dir:string -> + threshold:int -> + dac_members:string list -> + node:Node.t -> + client:Client.t -> + unit -> + t -val create : +(** Creates a DAC node to run in coordinator mode, using the specified + threshold, list of dac members and operator. *) +val create_coordinator : ?path:string -> ?name:string -> ?color:Log.Color.t -> @@ -38,6 +56,46 @@ val create : ?event_pipe:string -> ?rpc_host:string -> ?rpc_port:int -> + ?reveal_data_dir:string -> + threshold:int -> + dac_members:string list -> + node:Node.t -> + client:Client.t -> + unit -> + t + +(** Creates a DAC node to run in dac_member mode, using the specified address, + coordinator rpc host and port. *) +val create_dac_member : + ?path:string -> + ?name:string -> + ?color:Log.Color.t -> + ?data_dir:string -> + ?event_pipe:string -> + ?rpc_host:string -> + ?rpc_port:int -> + ?reveal_data_dir:string -> + ?coordinator_rpc_host:string -> + ?coordinator_rpc_port:int -> + address:string -> + node:Node.t -> + client:Client.t -> + unit -> + t + +(** Creates a DAC node to run in observer mode, using the specified coordinator + rpc host and port. *) +val create_observer : + ?path:string -> + ?name:string -> + ?color:Log.Color.t -> + ?data_dir:string -> + ?event_pipe:string -> + ?rpc_host:string -> + ?rpc_port:int -> + ?reveal_data_dir:string -> + ?coordinator_rpc_host:string -> + ?coordinator_rpc_port:int -> node:Node.t -> client:Client.t -> unit -> @@ -46,6 +104,10 @@ val create : (** Get the name of an dac node. *) val name : t -> string +(** Get the mode in which a dac node is configured to run. Returned values can + be either "Legacy", "Coordinator", "Dac_member" or "Observer". *) +val mode : t -> string + (** Get the RPC host given as [--rpc-addr] to an dac node. *) val rpc_host : t -> string @@ -58,6 +120,9 @@ val endpoint : t -> string (** Get the data-dir of an dac node. *) val data_dir : t -> string +(** Get the reveal-data-dir of an dac node. *) +val reveal_data_dir : t -> string + (** [run ?wait_ready ?env node] launches the given dac node where env is a map of environment variable. @@ -93,26 +158,6 @@ val wait : t -> Unix.process_status Lwt.t *) val init_config : t -> string Lwt.t -(** DAC related functions. *) -module Dac : sig - (** [set_parameters ?threshold dac_node] Runs - [octez-dac-node set dac parameters --data-dir data_dir], where - [data_dir = dac_node.persistent_state.data_dir]. If the optional integer - parameter [~threshold] is passed, then the dac node configuration file is - updated with the dac threshold indicated. If the [~reveal_data_dir] - optional argument is passed, then the dac node configuration file is - updated with the corresponding reveal_data_dir. If no optional arguments are - passed, the configuration file of the dac node is left unchanged. -*) - val set_parameters : - ?threshold:int -> ?reveal_data_dir:string -> t -> unit Lwt.t - - (** [add_committee_member dac_node] runs - [octez-dac-node add data availability committee member alias --data-dir data-dir], - where [data-dir = dac_node.persistent_state.data_dir]. *) - val add_committee_member : address:string -> t -> unit Lwt.t -end - module Config_file : sig (** C node configuration files. *) diff --git a/tezt/tests/dac.ml b/tezt/tests/dac.ml index 837a86441730..0f52247a67d6 100644 --- a/tezt/tests/dac.ml +++ b/tezt/tests/dac.ml @@ -112,8 +112,47 @@ let with_layer1 ?additional_bootstrap_accounts ?commitment_period let bootstrap1_key = Constant.bootstrap1.public_key_hash in f node client bootstrap1_key -let with_fresh_rollup ~protocol ?(pvm_name = "arith") ?dac_node f tezos_node - tezos_client bootstrap1_key = +let with_legacy_dac_node tezos_node ?sc_rollup_node ?(pvm_name = "arith") + ?(wait_ready = true) ~threshold ~dac_members tezos_client f = + let range i = List.init i Fun.id in + let reveal_data_dir = + Option.map + (fun sc_rollup_node -> + Filename.concat (Sc_rollup_node.data_dir sc_rollup_node) pvm_name) + sc_rollup_node + in + + let* dac_members = + Lwt_list.map_p + (fun i -> + let* dac_member = + Client.bls_gen_keys + ~alias:("dac_member_" ^ Int.to_string i) + tezos_client + in + let* dac_member_info = + Client.bls_show_address ~alias:dac_member tezos_client + in + return dac_member_info.aggregate_public_key_hash) + (range dac_members) + in + let dac_node = + Dac_node.create_legacy + ~node:tezos_node + ~client:tezos_client + ?reveal_data_dir + ~threshold + ~dac_members + () + in + let* _dir = Dac_node.init_config dac_node in + let* () = Dac_node.run dac_node ~wait_ready in + f dac_node dac_members + +(* TODO: https://gitlab.com/tezos/tezos/-/issues/4706 + Keep pvm name value in Sc_rollup.t. *) +let with_fresh_rollup ~protocol ?(pvm_name = "arith") f tezos_node tezos_client + bootstrap1_key = let* rollup_address = Client.Sc_rollup.originate ~hooks @@ -135,26 +174,9 @@ let with_fresh_rollup ~protocol ?(pvm_name = "arith") ?dac_node f tezos_node let* configuration_filename = Sc_rollup_node.config_init sc_rollup_node rollup_address in - let* () = - match dac_node with - | None -> return () - | Some dac_node -> - let* () = Dac_node.terminate dac_node in - let reveal_data_dir = - Filename.concat (Sc_rollup_node.data_dir sc_rollup_node) pvm_name - in - let* () = Dac_node.Dac.set_parameters ~reveal_data_dir dac_node in - Dac_node.run dac_node ~wait_ready:true - in let* () = Client.bake_for_and_wait tezos_client in f rollup_address sc_rollup_node configuration_filename -let with_dac_node tezos_node tezos_client f key = - let dac_node = Dac_node.create ~node:tezos_node ~client:tezos_client () in - let* _dir = Dac_node.init_config dac_node in - let* () = Dac_node.run dac_node ~wait_ready:true in - f key dac_node - (* Wrapper scenario functions that should be re-used as much as possible when writing tests. *) let scenario_with_layer1_node ?(tags = ["dac"; "layer1"]) ?commitment_period @@ -171,10 +193,11 @@ let scenario_with_layer1_node ?(tags = ["dac"; "layer1"]) ?commitment_period ?event_sections_levels ?node_arguments ~protocol - @@ fun cryptobox node client -> scenario protocol cryptobox node client) + @@ fun node client key -> scenario protocol node client key) -let scenario_with_layer1_and_dac_nodes ?(tags = ["dac"; "layer1"]) - ?commitment_period ?challenge_window variant scenario = +let scenario_with_layer1_and_legacy_dac_nodes + ?(tags = ["dac"; "layer1"; "legacy"]) ?commitment_period ?challenge_window + ~threshold ~dac_members variant scenario = let description = "Testing DAC node" in test ~__FILE__ @@ -182,12 +205,14 @@ let scenario_with_layer1_and_dac_nodes ?(tags = ["dac"; "layer1"]) (Printf.sprintf "%s (%s)" description variant) (fun protocol -> with_layer1 ?commitment_period ?challenge_window ~protocol - @@ fun node client -> - with_dac_node node client @@ fun _key dac_node -> - scenario protocol node client dac_node) - -let scenario_with_all_nodes ?(tags = ["dac"; "dac_node"]) ?(pvm_name = "arith") - ?commitment_period ?challenge_window variant scenario = + @@ fun node client _key -> + with_legacy_dac_node ~threshold ~dac_members node client + @@ fun dac_node dac_members -> + scenario protocol node client dac_node threshold dac_members) + +let scenario_with_all_nodes ?(tags = ["dac"; "dac_node"; "legacy"]) + ?(pvm_name = "arith") ?commitment_period ?challenge_window ~threshold + ~dac_members variant scenario = let description = "Testing DAC rollup and node with L1" in regression_test ~__FILE__ @@ -195,18 +220,29 @@ let scenario_with_all_nodes ?(tags = ["dac"; "dac_node"]) ?(pvm_name = "arith") (Printf.sprintf "%s (%s)" description variant) (fun protocol -> with_layer1 ?commitment_period ?challenge_window ~protocol - @@ fun node client -> - with_dac_node node client @@ fun key dac_node -> - ( with_fresh_rollup ~protocol ~pvm_name ~dac_node - @@ fun sc_rollup_address sc_rollup_node _filename -> - scenario - protocol - dac_node - sc_rollup_node - sc_rollup_address - node - client - pvm_name ) + @@ fun node client key -> + with_fresh_rollup + ~protocol + ~pvm_name + (fun sc_rollup_address sc_rollup_node _configuration_filename -> + with_legacy_dac_node + node + ~sc_rollup_node + ~pvm_name + ~threshold + ~dac_members + client + @@ fun dac_node dac_members -> + scenario + protocol + dac_node + sc_rollup_node + sc_rollup_address + node + client + pvm_name + threshold + dac_members) node client key) @@ -266,20 +302,17 @@ let test_dac_node_startup = ~nodes_args () in - let () = Printf.printf "test was here 0." in - let dac_node = Dac_node.create ~node ~client () in + let dac_node = + Dac_node.create_legacy ~node ~client ~threshold:0 ~dac_members:[] () + in let* _dir = Dac_node.init_config dac_node in let* () = run_dac dac_node in - let () = Printf.printf "test was here 1." in let* () = Dac_node.wait_for dac_node "dac_node_layer_1_start_tracking.v0" (fun _ -> Some ()) in - let () = Printf.printf "test was here 2." in assert (Dac_node.is_running_not_ready dac_node) ; - let () = Printf.printf "test was here 3." in let* () = Dac_node.terminate dac_node in - let () = Printf.printf "test was here 4." in let* () = Node.terminate node in Node.Config_file.update node @@ -287,10 +320,7 @@ let test_dac_node_startup = [(Protocol.hash previous_protocol, Protocol.hash protocol)]) ; let* () = Node.run node nodes_args in let* () = Node.wait_for_ready node in - let () = Printf.printf "test was here 5." in let* () = run_dac dac_node in - let () = Printf.printf "test was here 6." in - let* () = Lwt.join [ @@ -299,9 +329,7 @@ let test_dac_node_startup = Client.bake_for_and_wait client; ] in - let () = Printf.printf "test was here 7." in let* () = Dac_node.terminate dac_node in - let () = Printf.printf "test was here 8." in return () let send_messages ?(src = Constant.bootstrap2.alias) ?(alter_final_msg = Fun.id) @@ -329,17 +357,8 @@ let check_preimage expected_preimage actual_preimage = "Preimage does not match expected value (Current: %L <> Expected: %R)") let test_dac_node_handles_dac_store_preimage_merkle_V0 _protocol dac_node - sc_rollup_node _sc_rollup_address _node client pvm_name = - (* Terminate the dac node before setting dac parameters. *) - let* () = Dac_node.terminate dac_node in - let* dac_member = Client.bls_gen_keys ~alias:"dac_member" client in - let* dac_member_info = Client.bls_show_address ~alias:dac_member client in - let dac_member_address = dac_member_info.aggregate_public_key_hash in - let* () = Dac_node.Dac.set_parameters ~threshold:1 dac_node in - let* () = - Dac_node.Dac.add_committee_member ~address:dac_member_address dac_node - in - let* () = Dac_node.run dac_node in + sc_rollup_node _sc_rollup_address _node _client pvm_name _threshold + _dac_members = let payload = "test" in let* actual_rh, l1_operation = RPC.call @@ -378,7 +397,8 @@ let test_dac_node_handles_dac_store_preimage_merkle_V0 _protocol dac_node unit let test_dac_node_handles_dac_store_preimage_hash_chain_V0 _protocol dac_node - sc_rollup_node _sc_rollup_address _node _client pvm_name = + sc_rollup_node _sc_rollup_address _node _client pvm_name _threshold + _dac_members = let payload = "test" in let* actual_rh, _l1_operation = RPC.call @@ -447,7 +467,7 @@ let test_dac_node_handles_dac_retrieve_preimage_merkle_V0 _protocol dac_node unit let test_rollup_arith_uses_reveals protocol dac_node sc_rollup_node - sc_rollup_address _node client _pvm_name = + sc_rollup_address _node client _pvm_name _threshold _dac_members = let* genesis_info = RPC.Client.call ~hooks client @@ RPC.get_chain_block_context_smart_rollups_smart_rollup_genesis_info @@ -512,7 +532,7 @@ let test_rollup_arith_uses_reveals protocol dac_node sc_rollup_node unit let test_reveals_fails_on_wrong_hash _protocol dac_node sc_rollup_node - sc_rollup_address _node client _pvm_name = + sc_rollup_address _node client _pvm_name _threshold _dac_members = let payload = "Some data that is not related to the hash" in let _actual_rh = RPC.call @@ -565,12 +585,15 @@ let test_dac_node_imports_dac_member = let* dac_member = Client.bls_gen_keys ~alias:"dac_member" client in let* dac_member_info = Client.bls_show_address ~alias:dac_member client in let dac_member_address = dac_member_info.aggregate_public_key_hash in - let dac_node = Dac_node.create ~node ~client () in - let* _dir = Dac_node.init_config dac_node in - let* () = Dac_node.Dac.set_parameters ~threshold:1 dac_node in - let* () = - Dac_node.Dac.add_committee_member ~address:dac_member_address dac_node + let dac_node = + Dac_node.create_legacy + ~node + ~client + ~threshold:1 + ~dac_members:[dac_member_address] + () in + let* _dir = Dac_node.init_config dac_node in let ready_promise = Dac_node.wait_for dac_node "dac_is_ready.v0" (fun _ -> Some ()) in @@ -587,10 +610,11 @@ let test_dac_node_dac_threshold_not_reached = ~supports:Protocol.(From_protocol (Protocol.number Alpha)) @@ fun protocol -> let* node, client = Client.init_with_protocol `Client ~protocol () in - let run_dac = Dac_node.run ~wait_ready:false in - let dac_node = Dac_node.create ~node ~client () in + let dac_node = + Dac_node.create_legacy ~node ~client ~threshold:1 ~dac_members:[] () + in let* _dir = Dac_node.init_config dac_node in - let* () = Dac_node.Dac.set_parameters ~threshold:1 dac_node in + let run_dac = Dac_node.run ~wait_ready:false in let error_promise = Dac_node.wait_for dac_node "dac_threshold_not_reached.v0" (fun _ -> Some ()) in @@ -632,13 +656,18 @@ module Legacy = struct in return @@ check_valid_root_hash expected_rh actual_rh - let test_streaming_of_root_hashes _protocol node client coordinator = + let test_streaming_of_root_hashes _protocol node client coordinator threshold + dac_members = (* 1. Create two new dac nodes; [observer_1] and [observer_2]. 2. Initialize their default configuration. 3. Update their configuration so that their dac node client context points to [coordinator]. *) - let observer_1 = Dac_node.create ~node ~client () in - let observer_2 = Dac_node.create ~node ~client () in + let observer_1 = + Dac_node.create_legacy ~threshold ~dac_members ~node ~client () + in + let observer_2 = + Dac_node.create_legacy ~threshold ~dac_members ~node ~client () + in let* _ = Dac_node.init_config observer_1 in let* _ = Dac_node.init_config observer_2 in let () = set_coordinator observer_1 coordinator in @@ -790,24 +819,24 @@ module Legacy = struct let root_hash = JSON.(json |-> "root_hash" |> as_string) in (payload, root_hash) - let test_observer_downloads_pages _protocol node client coordinator = + let test_observer_downloads_pages _protocol node client coordinator threshold + dac_members = (* 1. Create one new dac nodes; [observer_1], 2. Initialize the default configuration, 3. Specify a temporary directory within the test data for the observer reveal data dir, 4. Update the configuration of the observer so that the dac node client context points to [coordinator]. *) - let observer = Dac_node.create ~name:"observer" ~node ~client () in - let* _ = Dac_node.init_config observer in - let observer_data_dir = Dac_node.data_dir observer in - let observer_reveal_data_dir = - Filename.concat observer_data_dir "preimages" - in - let* () = - Dac_node.Dac.set_parameters - ~reveal_data_dir:observer_reveal_data_dir - observer + let observer = + Dac_node.create_legacy + ~threshold + ~dac_members + ~name:"observer" + ~node + ~client + () in + let* _ = Dac_node.init_config observer in let () = set_coordinator observer coordinator in (* Payload with more than 4091 bytes to check recursive calls of the committee member to the coordinator. @@ -853,16 +882,21 @@ let register ~protocols = (* Tests with layer1 and dac nodes *) test_dac_node_startup protocols ; test_dac_node_imports_dac_member protocols ; + test_dac_node_dac_threshold_not_reached protocols ; scenario_with_all_nodes ~tags:["dac"; "dac_node"] "dac_reveals_data_merkle_tree_v0" test_dac_node_handles_dac_store_preimage_merkle_V0 - protocols ; + protocols + ~threshold:1 + ~dac_members:1 ; scenario_with_all_nodes ~tags:["dac"; "dac_node"] "dac_reveals_data_hash_chain_v0" test_dac_node_handles_dac_store_preimage_hash_chain_V0 - protocols ; + protocols + ~threshold:1 + ~dac_members:1 ; scenario_with_all_nodes ~tags:["dac"; "dac_node"] ~threshold:0 @@ -874,18 +908,26 @@ let register ~protocols = ~tags:["dac"; "dac_node"] "dac_rollup_arith_uses_reveals" test_rollup_arith_uses_reveals - protocols ; + protocols + ~threshold:1 + ~dac_members:1 ; scenario_with_all_nodes ~tags:["dac"; "dac_node"] "dac_rollup_arith_wrong_hash" test_reveals_fails_on_wrong_hash + ~threshold:1 + ~dac_members:1 protocols ; - scenario_with_layer1_and_dac_nodes + scenario_with_layer1_and_legacy_dac_nodes + ~threshold:0 + ~dac_members:0 ~tags:["dac"; "dac_node"] "dac_streaming_of_root_hashes_in_legacy_mode" Legacy.test_streaming_of_root_hashes protocols ; - scenario_with_layer1_and_dac_nodes + scenario_with_layer1_and_legacy_dac_nodes + ~threshold:0 + ~dac_members:0 ~tags:["dac"; "dac_node"] "committee member downloads pages from coordinator" Legacy.test_observer_downloads_pages diff --git a/tezt/tests/evm_rollup.ml b/tezt/tests/evm_rollup.ml index 2b062dc1e18c..508ea624bf1c 100644 --- a/tezt/tests/evm_rollup.ml +++ b/tezt/tests/evm_rollup.ml @@ -2,6 +2,7 @@ (* *) (* Open Source License *) (* Copyright (c) 2023 Nomadic Labs *) +(* Copyright (c) 2023 TriliTech *) (* *) (* Permission is hereby granted, free of charge, to any person obtaining a *) (* copy of this software and associated documentation files (the "Software"),*) @@ -26,6 +27,7 @@ (* Testing ------- Component: Smart Optimistic Rollups: EVM Kernel + Requirement: make -f kernels.mk build-kernels Invocation: dune exec tezt/tests/main.exe -- --file evm_rollup.ml *) @@ -55,24 +57,27 @@ let evm_proxy_server_version proxy_server = let setup_evm_kernel ?(originator_key = Constant.bootstrap1.public_key_hash) ?(rollup_operator_key = Constant.bootstrap1.public_key_hash) protocol = let* node, client = setup_l1 protocol in - let with_dac_node node client key f = Dac.with_dac_node node client f key in - with_dac_node node client rollup_operator_key @@ fun operator_key dac_node -> - (* Start a rollup node *) let sc_rollup_node = Sc_rollup_node.create ~protocol Operator node ~base_dir:(Client.base_dir client) - ~default_operator:operator_key + ~default_operator:rollup_operator_key in - (* Prepare DAL/DAC: put reveal data in rollup node directory. *) - let* () = Dac_node.terminate dac_node in - let reveal_data_dir = - Filename.concat (Sc_rollup_node.data_dir sc_rollup_node) pvm_kind + let with_dac_node node client f = + Dac.with_legacy_dac_node + ~sc_rollup_node + node + client + f + ~pvm_name:pvm_kind + ~threshold:0 + ~dac_members:0 in - let* () = Dac_node.Dac.set_parameters ~reveal_data_dir dac_node in - let* () = Dac_node.run dac_node ~wait_ready:true in + with_dac_node node client @@ fun dac_node _dac_members -> + (* Start a rollup node *) + (* Prepare DAL/DAC: put reveal data in rollup node directory. *) let* installer_kernel = prepare_installer_kernel ~base_installee:"./" ~dac_node "evm_mockup_kernel" in diff --git a/tezt/tests/sc_rollup.ml b/tezt/tests/sc_rollup.ml index accbf6386ae3..6c33fa640367 100644 --- a/tezt/tests/sc_rollup.ml +++ b/tezt/tests/sc_rollup.ml @@ -3539,10 +3539,8 @@ let test_deposit ~client ~sc_rollup_node ~sc_rollup_client ~sc_rollup_address let test_tx_kernel_e2e protocol = let commitment_period = 2 and challenge_window = 5 in - Dal.with_layer1 ~protocol ~commitment_period ~challenge_window - @@ fun _parameters _cryptobox node client -> - Dac.with_dac_node node client @@ fun bootstrap1_key dac_node -> - (* Start a rollup node *) + Dac.with_layer1 ~protocol ~commitment_period ~challenge_window + @@ fun node client bootstrap1_key -> let sc_rollup_node = Sc_rollup_node.create ~protocol @@ -3551,20 +3549,19 @@ let test_tx_kernel_e2e protocol = ~base_dir:(Client.base_dir client) ~default_operator:bootstrap1_key in + Dac.with_legacy_dac_node + ~threshold:0 + ~dac_members:1 + ~sc_rollup_node + ~pvm_name:"wasm_2_0_0" + node + client + @@ fun dac_node _dac_members -> + (* Start a rollup node *) (* Prepare DAL/DAC: put reveal data in rollup node directory. *) let* () = Dac_node.terminate dac_node in - let reveal_data_dir = - Filename.concat (Sc_rollup_node.data_dir sc_rollup_node) "wasm_2_0_0" - in - let* () = Dac_node.Dac.set_parameters ~reveal_data_dir dac_node in let* () = Dac_node.run dac_node ~wait_ready:true in - let* dac_member = Client.bls_gen_keys ~alias:"dac_member" client in - let* dac_member_info = Client.bls_show_address ~alias:dac_member client in - let dac_member_address = dac_member_info.aggregate_public_key_hash in let* _dir = Dac_node.init_config dac_node in - let* () = - Dac_node.Dac.add_committee_member ~address:dac_member_address dac_node - in (* We can now produce our installer *) let* installer_kernel = prepare_installer_kernel ~dac_node "tx-kernel" in let boot_sector = hex_encode installer_kernel in -- GitLab