From baa30e7bb0ca06dafa702febcc3fec6e63ca3fa2 Mon Sep 17 00:00:00 2001 From: Andrea Cerone Date: Tue, 31 Jan 2023 20:26:22 +0100 Subject: [PATCH 1/2] Dac Node/Configuration: General improvements --- src/bin_dac_node/main_dac.ml | 38 ++-- src/lib_dac_node/configuration.ml | 309 +++++++++++++++----------- src/lib_dac_node/configuration.mli | 120 ++++++---- src/lib_dac_node/daemon.ml | 30 ++- src/lib_dac_node/node_context.ml | 19 +- src/lib_dac_node/node_context.mli | 6 +- src/lib_dac_node/signature_manager.ml | 2 +- 7 files changed, 324 insertions(+), 200 deletions(-) diff --git a/src/bin_dac_node/main_dac.ml b/src/bin_dac_node/main_dac.ml index e6506f4dd6c1..5e8b87a6a3b5 100644 --- a/src/bin_dac_node/main_dac.ml +++ b/src/bin_dac_node/main_dac.ml @@ -136,11 +136,14 @@ 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 config : Configuration.t = + {data_dir; rpc_address; rpc_port; mode; reveal_data_dir} + in + let* () = Configuration.save config in let*! _ = - cctxt#message "DAC node configuration written in %s" (filename config) + cctxt#message + "DAC node configuration written in %s" + (Configuration.filename config) in return () @@ -156,15 +159,14 @@ module Config_init = struct @@ seq_of_param @@ tz4_address_param) (fun (data_dir, rpc_address, rpc_port, reveal_data_dir) threshold - dac_members_addresses + committee_members_addresses cctxt -> create_configuration ~data_dir ~reveal_data_dir ~rpc_address ~rpc_port - (Configuration.Legacy - {threshold; dac_members_addresses; dac_cctxt_config = None}) + (Configuration.make_legacy threshold committee_members_addresses) cctxt) let coordinator_command = @@ -179,17 +181,17 @@ module Config_init = struct @@ seq_of_param @@ tz4_address_param) (fun (data_dir, rpc_address, rpc_port, reveal_data_dir) threshold - dac_members_addresses + committee_members_addresses cctxt -> create_configuration ~data_dir ~reveal_data_dir ~rpc_address ~rpc_port - (Coordinator {threshold; dac_members_addresses}) + (Configuration.make_coordinator threshold committee_members_addresses) cctxt) - let dac_member_command = + let committee_member_command = let open Tezos_clic in command ~group @@ -209,7 +211,10 @@ module Config_init = struct ~reveal_data_dir ~rpc_address ~rpc_port - (Dac_member {coordinator_rpc_address; coordinator_rpc_port; address}) + (Configuration.make_committee_member + coordinator_rpc_address + coordinator_rpc_port + address) cctxt) let observer_command = @@ -228,11 +233,18 @@ module Config_init = struct ~reveal_data_dir ~rpc_address ~rpc_port - (Observer {coordinator_rpc_address; coordinator_rpc_port}) + (Configuration.make_observer + coordinator_rpc_address + coordinator_rpc_port) cctxt) let commands = - [legacy_command; coordinator_command; dac_member_command; observer_command] + [ + legacy_command; + coordinator_command; + committee_member_command; + observer_command; + ] end let run_command = diff --git a/src/lib_dac_node/configuration.ml b/src/lib_dac_node/configuration.ml index b1f2455ab127..900510b4affd 100644 --- a/src/lib_dac_node/configuration.ml +++ b/src/lib_dac_node/configuration.ml @@ -26,47 +26,10 @@ type host_and_port = {host : string; port : int} -type coordinator = { - threshold : int; - dac_members_addresses : Tezos_crypto.Aggregate_signature.public_key_hash list; -} - -type dac_member = { - coordinator_rpc_address : string; - coordinator_rpc_port : int; - address : Tezos_crypto.Aggregate_signature.public_key_hash; -} - -type observer = {coordinator_rpc_address : string; coordinator_rpc_port : int} - -type legacy = { - threshold : int; - dac_members_addresses : Tezos_crypto.Aggregate_signature.public_key_hash list; - dac_cctxt_config : host_and_port option; -} - -type mode = - | Coordinator of coordinator - | Dac_member of dac_member - | Observer of observer - | Legacy of legacy - -type t = { - data_dir : string; - rpc_address : string; - rpc_port : int; - reveal_data_dir : string; - mode : mode; -} - let default_data_dir = Filename.concat (Sys.getenv "HOME") ".tezos-dac-node" -let data_dir_path config subpath = Filename.concat config.data_dir subpath - let relative_filename data_dir = Filename.concat data_dir "config.json" -let filename config = relative_filename config.data_dir - let default_rpc_address = "127.0.0.1" let default_rpc_port = 10832 @@ -80,98 +43,196 @@ let default_reveal_data_dir = (Filename.concat (Sys.getenv "HOME") ".tezos-smart-rollup-node") "wasm_2_0_0" -let host_and_port_encoding = - let open Data_encoding in - conv - (fun {host; port} -> (host, port)) - (fun (host, port) -> {host; port}) - (obj2 (req "rpc-host" string) (req "rpc-port" uint16)) - -let coordinator_encoding = - Data_encoding.( - conv_with_guard - (fun ({threshold; dac_members_addresses} : coordinator) -> - (threshold, dac_members_addresses, false)) - (fun (threshold, dac_members_addresses, legacy) -> - if legacy then Error "legacy flag should be set to false" - else Ok {threshold; dac_members_addresses}) - (obj3 - (req "threshold" uint8) - (req - "dac_members" - (list Tezos_crypto.Aggregate_signature.Public_key_hash.encoding)) - (req "legacy" bool))) - -let dac_member_encoding = - Data_encoding.( - conv - (fun {coordinator_rpc_address; coordinator_rpc_port; address} -> - (coordinator_rpc_address, coordinator_rpc_port, address)) - (fun (coordinator_rpc_address, coordinator_rpc_port, address) -> - {coordinator_rpc_address; coordinator_rpc_port; address}) - (obj3 - (req "coordinator_rpc_address" string) - (req "coordinator_rpc_port" int16) - (req - "address" - Tezos_crypto.Aggregate_signature.Public_key_hash.encoding))) - -let observer_encoding = - Data_encoding.( +module Coordinator = struct + type t = { + threshold : int; + committee_members_addresses : + Tezos_crypto.Aggregate_signature.public_key_hash list; + } + + let make threshold committee_members_addresses = + {threshold; committee_members_addresses} + + let encoding = + Data_encoding.( + conv + (fun {threshold; committee_members_addresses} -> + (threshold, committee_members_addresses)) + (fun (threshold, committee_members_addresses) -> + {threshold; committee_members_addresses}) + (obj2 + (req "threshold" uint8) + (req + "committee_members" + (list Tezos_crypto.Aggregate_signature.Public_key_hash.encoding)))) + + let committee_members_addresses t = t.committee_members_addresses +end + +module Committee_member = struct + type t = { + coordinator_rpc_address : string; + coordinator_rpc_port : int; + address : Tezos_crypto.Aggregate_signature.public_key_hash; + } + + let make coordinator_rpc_address coordinator_rpc_port address = + {coordinator_rpc_address; coordinator_rpc_port; address} + + let encoding = + Data_encoding.( + conv + (fun {coordinator_rpc_address; coordinator_rpc_port; address} -> + (coordinator_rpc_address, coordinator_rpc_port, address)) + (fun (coordinator_rpc_address, coordinator_rpc_port, address) -> + {coordinator_rpc_address; coordinator_rpc_port; address}) + (obj3 + (req "coordinator_rpc_address" string) + (req "coordinator_rpc_port" int16) + (req + "address" + Tezos_crypto.Aggregate_signature.Public_key_hash.encoding))) +end + +module Observer = struct + type t = {coordinator_rpc_address : string; coordinator_rpc_port : int} + + let make coordinator_rpc_address coordinator_rpc_port = + {coordinator_rpc_address; coordinator_rpc_port} + + let encoding = + Data_encoding.( + conv + (fun {coordinator_rpc_address; coordinator_rpc_port} -> + (coordinator_rpc_address, coordinator_rpc_port)) + (fun (coordinator_rpc_address, coordinator_rpc_port) -> + {coordinator_rpc_address; coordinator_rpc_port}) + (obj2 + (req "coordinator_rpc_address" string) + (req "coordinator_rpc_port" uint16))) +end + +module Legacy = struct + type t = { + threshold : int; + committee_members_addresses : + Tezos_crypto.Aggregate_signature.public_key_hash list; + dac_cctxt_config : host_and_port option; + } + + let make ?coordinator_host_and_port threshold committee_members_addresses = + { + threshold; + committee_members_addresses; + dac_cctxt_config = coordinator_host_and_port; + } + + let committee_members_addresses t = t.committee_members_addresses + + let threshold t = t.threshold + + let dac_cctxt_config t = t.dac_cctxt_config + + let host_and_port_encoding = + let open Data_encoding in conv - (fun {coordinator_rpc_address; coordinator_rpc_port} -> - (coordinator_rpc_address, coordinator_rpc_port)) - (fun (coordinator_rpc_address, coordinator_rpc_port) -> - {coordinator_rpc_address; coordinator_rpc_port}) - (obj2 - (req "coordinator_rpc_address" string) - (req "coordinator_rpc_port" int16))) - -let legacy_encoding = - Data_encoding.( - conv_with_guard - (fun {threshold; dac_members_addresses; dac_cctxt_config} -> - (threshold, dac_members_addresses, dac_cctxt_config, true)) - (fun (threshold, dac_members_addresses, dac_cctxt_config, legacy) -> - if legacy then Ok {threshold; dac_members_addresses; dac_cctxt_config} - else Error "'legacy' flag should be set to true") - (obj4 - (dft "threshold" uint8 default_dac_threshold) - (dft - "dac_members" - (list Tezos_crypto.Aggregate_signature.Public_key_hash.encoding) - default_dac_addresses) - (opt "dac_cctxt_config" host_and_port_encoding) - (req "legacy" bool))) - -let mode_config_encoding = - Data_encoding.( + (fun {host; port} -> (host, port)) + (fun (host, port) -> {host; port}) + (obj2 (req "rpc-host" string) (req "rpc-port" uint16)) + + let encoding = + Data_encoding.( + conv + (fun {threshold; committee_members_addresses; dac_cctxt_config} -> + (threshold, committee_members_addresses, dac_cctxt_config)) + (fun (threshold, committee_members_addresses, dac_cctxt_config) -> + {threshold; committee_members_addresses; dac_cctxt_config}) + (obj3 + (dft "threshold" uint8 default_dac_threshold) + (dft + "committee_members" + (list Tezos_crypto.Aggregate_signature.Public_key_hash.encoding) + default_dac_addresses) + (opt "dac_cctxt_config" host_and_port_encoding))) +end + +type mode = + | Coordinator of Coordinator.t + | Committee_member of Committee_member.t + | Observer of Observer.t + | Legacy of Legacy.t + +let make_coordinator threshold committee_members_addresses = + Coordinator (Coordinator.make threshold committee_members_addresses) + +let make_committee_member coordinator_rpc_address coordinator_rpc_port + committee_member_address = + Committee_member + (Committee_member.make + coordinator_rpc_address + coordinator_rpc_port + committee_member_address) + +let make_observer coordinator_rpc_address coordinator_rpc_port = + Observer (Observer.make coordinator_rpc_address coordinator_rpc_port) + +let make_legacy ?coordinator_host_and_port threshold committee_members_addresses + = + Legacy + (Legacy.make + ?coordinator_host_and_port + threshold + committee_members_addresses) + +type t = { + data_dir : string; (** The path to the DAC node data directory. *) + rpc_address : string; (** The address the DAC node listens to. *) + rpc_port : int; (** The port the DAC node listens to. *) + reveal_data_dir : string; + (** The directory where the DAC node saves pages. *) + mode : mode; + (** Configuration parameters specific to the operating mode of the + DAC. *) +} + +let data_dir_path config subpath = Filename.concat config.data_dir subpath + +let filename config = relative_filename config.data_dir + +let data_dir config = config.data_dir + +let reveal_data_dir config = config.reveal_data_dir + +let mode config = config.mode + +let mode_encoding = + Data_encoding.With_JSON_discriminant.( union [ case - ~title:"coordinator" - (Tag 0) - coordinator_encoding - (function Coordinator config -> Some config | _ -> None) - (function config -> Coordinator config); + ~title:"Coordinator" + (Tag (0, "coordinator")) + Coordinator.encoding + (function Coordinator t -> Some t | _ -> None) + (fun t -> Coordinator t); case - ~title:"dac_member" - (Tag 1) - dac_member_encoding - (function Dac_member config -> Some config | _ -> None) - (function config -> Dac_member config); + ~title:"Committee_member" + (Tag (1, "committee_member")) + Committee_member.encoding + (function Committee_member t -> Some t | _ -> None) + (fun t -> Committee_member t); case - ~title:"observer" - (Tag 2) - observer_encoding - (function Observer config -> Some config | _ -> None) - (function config -> Observer config); + ~title:"Observer" + (Tag (2, "observer")) + Observer.encoding + (function Observer t -> Some t | _ -> None) + (fun t -> Observer t); case - ~title:"legacy" - (Tag 3) - legacy_encoding - (function Legacy config -> Some config | _ -> None) - (function config -> Legacy config); + ~title:"Legacy" + (Tag (3, "legacy")) + Legacy.encoding + (function Legacy t -> Some t | _ -> None) + (fun t -> Legacy t); ]) let encoding : t Data_encoding.t = @@ -194,7 +255,7 @@ let encoding : t Data_encoding.t = ~description:"Reveal data directory" string default_reveal_data_dir) - (req "mode" ~description:"Running mode" mode_config_encoding)) + (req "mode" ~description:"Running mode" mode_encoding)) type error += DAC_node_unable_to_write_configuration_file of string @@ -217,7 +278,7 @@ let save config = let file = filename config in protect @@ fun () -> let* v = - let* () = Lwt_utils_unix.create_dir config.data_dir in + let* () = Lwt_utils_unix.create_dir @@ data_dir config in Lwt_utils_unix.with_atomic_open_out file @@ fun chan -> let json = Data_encoding.Json.construct encoding config in let content = Data_encoding.Json.to_string json in diff --git a/src/lib_dac_node/configuration.mli b/src/lib_dac_node/configuration.mli index 166c67eeba75..0258e6f4e294 100644 --- a/src/lib_dac_node/configuration.mli +++ b/src/lib_dac_node/configuration.mli @@ -28,49 +28,55 @@ required to instantiate [Dac_node_client.(#cctxt)]. *) type host_and_port = {host : string; port : int} -(** Configuration type for coordinators. *) -type coordinator = { - threshold : int; - (** The number of signatures required from DAC members to consider a - message valid. *) - dac_members_addresses : Tezos_crypto.Aggregate_signature.public_key_hash list; - (** The list of tz4 addresses denoting the dac members. *) -} +(** Coordinator specific configuration. *) +module Coordinator : sig + (** The type of a coordinator specific configuration mode. *) + type t -(** Configuration type for dac members. *) -type dac_member = { - coordinator_rpc_address : string; (** RPC address of the coordinator. *) - coordinator_rpc_port : int; (** RPC port of the coordinator. *) - address : Tezos_crypto.Aggregate_signature.public_key_hash; - (** Tz4 address of the DAC member. *) -} + (* [committee_members_addresses t] retrieves the addresses of the committee + members from the coordinator configuration [t].*) + val committee_members_addresses : + t -> Tezos_crypto.Aggregate_signature.public_key_hash list +end -(** Configuation type for observers. *) -type observer = { - coordinator_rpc_address : string; (** RPC address of the coordinator. *) - coordinator_rpc_port : int; (** RPC port of the coordinator. *) -} +(** Committee_member specific configuration. *) +module Committee_member : sig + (** The type of a Committee_member specific configuration mode. *) + type t +end -(** Configuration type for legacy mode. *) -type legacy = { - threshold : int; - (** The number of signatures required from DAC members to consider a - message valid. *) - dac_members_addresses : Tezos_crypto.Aggregate_signature.public_key_hash list; - (** The list of tz4 addresses denoting the dac members. *) - dac_cctxt_config : host_and_port option; - (** When running integration tests with multiple dac nodes in the - [legacy] mode [dac_cctxt_config] is used to create - [Dac_node_client.cctxt] for the node that mimics coordinator. *) -} +(** Observer specific configuration. *) +module Observer : sig + (** The type of an Observer specific configuration mode. *) + type t +end + +(** Legacy specific configuration. *) +module Legacy : sig + (** The type of a legacy-specific configuration mode. *) + type t + + (* [committee_members_addresses t] retrieves the addresses of the committee + members from the legacy configuration [t].*) + val committee_members_addresses : + t -> Tezos_crypto.Aggregate_signature.public_key_hash list + + (* [threshold t] retrieves the Data Availability Committee threshold from + the legacy configuration [t]. *) + val threshold : t -> int -(* TODO: https://gitlab.com/tezos/tezos/-/issues/4707. - Remove legacy mode once other DAC operating modes are fully functional. *) -type mode = - | Coordinator of coordinator - | Dac_member of dac_member - | Observer of observer - | Legacy of legacy + (* [host_and_port t] retrieves the host and port of the node that serves + as a coordinator for the DAC, if any is specified in the legacy node + condiguration. *) + val dac_cctxt_config : t -> host_and_port option +end + +(** Mode specific fragment of a configuration. *) +type mode = private + | Coordinator of Coordinator.t + | Committee_member of Committee_member.t + | Observer of Observer.t + | Legacy of Legacy.t type t = { data_dir : string; (** The path to the DAC node data directory. *) @@ -83,6 +89,35 @@ type t = { DAC. *) } +(** [make_coordinator threshold dac_members_addresses] creates a new coordinator + configuration mode using the given [threshold] and [dac_members_addresses]. +*) +val make_coordinator : + int -> Tezos_crypto.Aggregate_signature.public_key_hash list -> mode + +(** [make_committee_member coordinator_rpc_address coordinator_rpc_port + committee_member_address] creates a new committee-member configuration + mode using the given address and port for the coordinator, and the given + [committee_member_address]. *) +val make_committee_member : + string -> int -> Tezos_crypto.Aggregate_signature.public_key_hash -> mode + +(** [make_observer coordinator_rpc_address coordinator_rpc_port] + creates a new observer configuration using the given address and + port for the coordinator, and the given [committee_member_address]. *) +val make_observer : string -> int -> mode + +(** [make_legacy ?coordinator_host_and_port threshold + committee_members_addresses] + creates a new legacy configuration mode with the specified input + parameters. If [host_and_port] is specified, then it will use as the + address of the coordinator node for the Data Availability Committee. *) +val make_legacy : + ?coordinator_host_and_port:host_and_port -> + int -> + Tezos_crypto.Aggregate_signature.public_key_hash trace -> + mode + (** [filename config] gets the path to config file *) val filename : t -> string @@ -90,6 +125,10 @@ val filename : t -> string [config] *) val data_dir_path : t -> string -> string +(* [reveal_data_dir config] returns the reveal data directory of + [config]. *) +val reveal_data_dir : t -> string + (** [default_data_dir] is the data directory that the DAC node will use, when one is not specified in the configuration: currently set to "${HOME}/.tezos-dac-node." *) @@ -114,3 +153,6 @@ val save : t -> unit tzresult Lwt.t (** [load ~data_dir] config tries to load the configuration of the DAC node from [data_dir]. *) val load : data_dir:string -> (t, Error_monad.tztrace) result Lwt.t + +(** [mode config] returns the mode specific configuration of [config]. *) +val mode : t -> mode diff --git a/src/lib_dac_node/daemon.ml b/src/lib_dac_node/daemon.ml index 1d421c1287fe..fb50edef76ab 100644 --- a/src/lib_dac_node/daemon.ml +++ b/src/lib_dac_node/daemon.ml @@ -178,18 +178,26 @@ let daemonize handlers = let run ~data_dir cctxt = let open Lwt_result_syntax in let*! () = Event.(emit starting_node) () in - let* ({rpc_address; rpc_port; reveal_data_dir; mode; _} as config) = + let* (Configuration. + {rpc_address; rpc_port; reveal_data_dir; mode; data_dir = _} as + config) = Configuration.load ~data_dir in let* () = Dac_manager.Storage.ensure_reveal_data_dir_exists reveal_data_dir in - let* addresses, threshold, coordinator_config_opt = + let* addresses, threshold, coordinator_cctxt_opt = match mode with - | Configuration.Legacy {dac_members_addresses; threshold; dac_cctxt_config} - -> - return (dac_members_addresses, threshold, dac_cctxt_config) - | Configuration.Coordinator _ -> tzfail @@ Mode_not_supported "coordinator" - | Configuration.Dac_member _ -> tzfail @@ Mode_not_supported "dac_member" - | Configuration.Observer _ -> tzfail @@ Mode_not_supported "observer" + | Legacy configuration -> + let committee_members_addresses = + Configuration.Legacy.committee_members_addresses configuration + in + let threshold = Configuration.Legacy.threshold configuration in + let dac_cctxt_config = + Configuration.Legacy.dac_cctxt_config configuration + in + return (committee_members_addresses, threshold, dac_cctxt_config) + | Coordinator _ -> tzfail @@ Mode_not_supported "coordinator" + | Committee_member _ -> tzfail @@ Mode_not_supported "committee_member" + | Observer _ -> tzfail @@ Mode_not_supported "observer" in (* TODO: https://gitlab.com/tezos/tezos/-/issues/4725 Stop DAC node when in Legacy mode, if threshold is not reached. *) @@ -206,7 +214,7 @@ let run ~data_dir cctxt = Option.map (fun Configuration.{host; port} -> Dac_node_client.make_unix_cctxt ~scheme:"http" ~host ~port) - coordinator_config_opt + coordinator_cctxt_opt in let* ctxt = Node_context.init config cctxt coordinator_cctxt_opt in let* rpc_server = @@ -221,9 +229,7 @@ let run ~data_dir cctxt = dac_sk_uris) in let _ = RPC_server.install_finalizer rpc_server in - let*! () = - Event.(emit rpc_server_is_ready (config.rpc_address, config.rpc_port)) - in + let*! () = Event.(emit rpc_server_is_ready (rpc_address, rpc_port)) in (* Start daemon to resolve current protocol plugin *) let* () = daemonize [Handler.resolve_plugin_and_set_ready ctxt cctxt] in (* Start never-ending monitoring daemons. [coordinator_cctxt] is required to diff --git a/src/lib_dac_node/node_context.ml b/src/lib_dac_node/node_context.ml index 24f20408123b..a2d5be51a135 100644 --- a/src/lib_dac_node/node_context.ml +++ b/src/lib_dac_node/node_context.ml @@ -69,7 +69,8 @@ let init config cctxt coordinator_opt = config; tezos_node_cctxt = cctxt; coordinator_opt; - page_store = Page_store.Filesystem.init config.reveal_data_dir; + page_store = + Page_store.Filesystem.init (Configuration.reveal_data_dir config); node_store; } @@ -146,16 +147,18 @@ let get_node_store (type a) ctxt (access_mode : a Store_sigs.mode) : | Store_sigs.Read_only -> Store.Irmin_store.readonly ctxt.node_store | Store_sigs.Read_write -> ctxt.node_store -let get_dac_committee ctxt = +let get_committee_members ctxt = let open Result_syntax in - match ctxt.config.mode with - | Legacy legacy -> Ok legacy.dac_members_addresses - | Coordinator coordinator -> Ok coordinator.dac_members_addresses + match Configuration.mode ctxt.config with + | Legacy legacy -> + Ok (Configuration.Legacy.committee_members_addresses legacy) + | Coordinator coordinator -> + Ok (Configuration.Coordinator.committee_members_addresses coordinator) | Observer _ -> tzfail @@ Invalid_operation_for_mode - {mode = "observer"; operation = "get_dac_committee"} - | Dac_member _ -> + {mode = "observer"; operation = "get_committee_members"} + | Committee_member _ -> tzfail @@ Invalid_operation_for_mode - {mode = "dac_member"; operation = "get_dac_committee"} + {mode = "dac_member"; operation = "get_committee_members"} diff --git a/src/lib_dac_node/node_context.mli b/src/lib_dac_node/node_context.mli index 684bf8e5cf3f..c8ae5cb3cff8 100644 --- a/src/lib_dac_node/node_context.mli +++ b/src/lib_dac_node/node_context.mli @@ -90,8 +90,8 @@ val get_page_store : t -> Page_store.Filesystem.t [access_mode] used by Dac components. *) val get_node_store : t -> 'a Store_sigs.mode -> 'a Store.Irmin_store.t -(** [get_dac_committee ctxt] returns the Dac committee public key hashes from - [Configuration.Legacy.dac_members_addresses] or +(** [get_committee_members ctxt] returns the Dac committee public key hashes from + [Configuration.Legacy.dac_members_addresses] or [Configuration.Coordinator.dac_members_addresses] *) -val get_dac_committee : +val get_committee_members : t -> Tezos_crypto.Aggregate_signature.public_key_hash list tzresult diff --git a/src/lib_dac_node/signature_manager.ml b/src/lib_dac_node/signature_manager.ml index e1848085fec6..672b4bf9756c 100644 --- a/src/lib_dac_node/signature_manager.ml +++ b/src/lib_dac_node/signature_manager.ml @@ -317,7 +317,7 @@ module Coordinator = struct let Signature_repr.{signer_pkh; root_hash; signature} = dac_member_signature in - let*? dac_committee = Node_context.get_dac_committee ctx in + let*? dac_committee = Node_context.get_committee_members ctx in let* () = fail_unless (check_is_dac_member dac_committee signer_pkh) -- GitLab From b826ba17142e3be210cff6bd276997e55476afc7 Mon Sep 17 00:00:00 2001 From: Andrea Cerone Date: Fri, 10 Mar 2023 11:00:12 +0000 Subject: [PATCH 2/2] Tezt/Dac: rename Dac_member -> Committee_member --- tezt/lib_tezos/dac_node.ml | 41 +++++++++------- tezt/lib_tezos/dac_node.mli | 10 ++-- tezt/tests/dac.ml | 98 ++++++++++++++++++++----------------- 3 files changed, 80 insertions(+), 69 deletions(-) diff --git a/tezt/lib_tezos/dac_node.ml b/tezt/lib_tezos/dac_node.ml index edb0bcfb7b3e..f83e16d133a3 100644 --- a/tezt/lib_tezos/dac_node.ml +++ b/tezt/lib_tezos/dac_node.ml @@ -24,11 +24,14 @@ (*****************************************************************************) module Parameters = struct - type legacy_mode_settings = {threshold : int; dac_members : string list} + type legacy_mode_settings = {threshold : int; committee_members : string list} - type coordinator_mode_settings = {threshold : int; dac_members : string list} + type coordinator_mode_settings = { + threshold : int; + committee_members : string list; + } - type dac_member_mode_settings = { + type committee_member_mode_settings = { address : string; coordinator_rpc_host : string; coordinator_rpc_port : int; @@ -42,7 +45,7 @@ module Parameters = struct type mode_settings = | Legacy of legacy_mode_settings | Coordinator of coordinator_mode_settings - | Dac_member of dac_member_mode_settings + | Committee_member of committee_member_mode_settings | Observer of observer_mode_settings type persistent_state = { @@ -85,7 +88,7 @@ let mode dac_node = match dac_node.persistent_state.mode with | Legacy _ -> "Legacy" | Coordinator _ -> "Coordinator" - | Dac_member _ -> "Dac_member" + | Committee_member _ -> "Committee_member" | Observer _ -> "Observer" let rpc_host dac_node = dac_node.persistent_state.rpc_host @@ -135,7 +138,7 @@ let spawn_config_init dac_node = "committee"; "members"; ] - @ legacy_params.dac_members + @ legacy_params.committee_members | Coordinator coordinator_params -> [ "configure"; @@ -150,11 +153,11 @@ let spawn_config_init dac_node = "committee"; "members"; ] - @ coordinator_params.dac_members - | Dac_member dac_member_params -> + @ coordinator_params.committee_members + | Committee_member committee_member_params -> let coordinator_host = - dac_member_params.coordinator_rpc_host ^ ":" - ^ Int.to_string dac_member_params.coordinator_rpc_port + committee_member_params.coordinator_rpc_host ^ ":" + ^ Int.to_string committee_member_params.coordinator_rpc_port in [ "configure"; @@ -166,7 +169,7 @@ let spawn_config_init dac_node = coordinator_host; "and"; "signer"; - dac_member_params.address; + committee_member_params.address; ] | Observer observer_params -> let coordinator_host = @@ -271,9 +274,9 @@ let create ?(path = Constant.dac_node) ?name ?color ?data_dir ?event_pipe 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 + ?(rpc_host = "127.0.0.1") ?rpc_port ?reveal_data_dir ~threshold + ~committee_members ~node ~client () = + let mode = Legacy {threshold; committee_members} in create ~path ?name @@ -290,8 +293,8 @@ let create_legacy ?(path = Constant.dac_node) ?name ?color ?data_dir ?event_pipe 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 + ~committee_members ~node ~client () = + let mode = Coordinator {threshold; committee_members} in create ~path ?name @@ -306,14 +309,16 @@ let create_coordinator ?(path = Constant.dac_node) ?name ?color ?data_dir ~client () -let create_dac_member ?(path = Constant.dac_node) ?name ?color ?data_dir +let create_committee_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 + let mode = + Committee_member {address; coordinator_rpc_host; coordinator_rpc_port} + in create ~path ?name diff --git a/tezt/lib_tezos/dac_node.mli b/tezt/lib_tezos/dac_node.mli index 6ea3101c414b..c9bf15fe2b1f 100644 --- a/tezt/lib_tezos/dac_node.mli +++ b/tezt/lib_tezos/dac_node.mli @@ -40,7 +40,7 @@ val create_legacy : ?rpc_port:int -> ?reveal_data_dir:string -> threshold:int -> - dac_members:string list -> + committee_members:string list -> node:Node.t -> client:Client.t -> unit -> @@ -58,15 +58,15 @@ val create_coordinator : ?rpc_port:int -> ?reveal_data_dir:string -> threshold:int -> - dac_members:string list -> + committee_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, +(** Creates a DAC node to run in committee_member mode, using the specified address, coordinator rpc host and port. *) -val create_dac_member : +val create_committee_member : ?path:string -> ?name:string -> ?color:Log.Color.t -> @@ -105,7 +105,7 @@ val create_observer : 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". *) + be either "Legacy", "Coordinator", "Commitee_member" or "Observer". *) val mode : t -> string (** Get the RPC host given as [--rpc-addr] to an dac node. *) diff --git a/tezt/tests/dac.ml b/tezt/tests/dac.ml index f91192e6db09..eab2b993f7d4 100644 --- a/tezt/tests/dac.ml +++ b/tezt/tests/dac.ml @@ -163,7 +163,7 @@ let with_layer1 ?additional_bootstrap_accounts ?commitment_period f node 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 = + ?(wait_ready = true) ~threshold ~committee_members tezos_client f = let range i = List.init i Fun.id in let reveal_data_dir = Option.map @@ -171,7 +171,7 @@ let with_legacy_dac_node tezos_node ?sc_rollup_node ?(pvm_name = "arith") Filename.concat (Sc_rollup_node.data_dir sc_rollup_node) pvm_name) sc_rollup_node in - let* dac_members = + let* committee_members = List.fold_left (fun keys i -> let* keys in @@ -182,7 +182,7 @@ let with_legacy_dac_node tezos_node ?sc_rollup_node ?(pvm_name = "arith") in return (key :: keys)) (return []) - (range dac_members) + (range committee_members) in let dac_node = Dac_node.create_legacy @@ -190,15 +190,15 @@ let with_legacy_dac_node tezos_node ?sc_rollup_node ?(pvm_name = "arith") ~client:tezos_client ?reveal_data_dir ~threshold - ~dac_members: + ~committee_members: (List.map (fun (dc : Account.aggregate_key) -> dc.aggregate_public_key_hash) - dac_members) + committee_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 + f dac_node committee_members (* TODO: https://gitlab.com/tezos/tezos/-/issues/4706 Keep pvm name value in Sc_rollup.t. *) @@ -248,7 +248,7 @@ let scenario_with_layer1_node ?(tags = ["dac"; "layer1"]) ?commitment_period let scenario_with_layer1_and_legacy_dac_nodes ?(tags = ["dac"; "layer1"; "legacy"]) ?commitment_period ?challenge_window - ~threshold ~dac_members variant scenario = + ~threshold ~committee_members variant scenario = let description = "Testing DAC node" in test ~__FILE__ @@ -257,13 +257,13 @@ let scenario_with_layer1_and_legacy_dac_nodes (fun protocol -> with_layer1 ?commitment_period ?challenge_window ~protocol @@ 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) + with_legacy_dac_node ~threshold ~committee_members node client + @@ fun dac_node committee_members -> + scenario protocol node client dac_node threshold committee_members) let scenario_with_all_nodes ?(tags = ["dac"; "dac_node"; "legacy"]) ?(pvm_name = "arith") ?commitment_period ?challenge_window ~threshold - ~dac_members variant scenario = + ~committee_members variant scenario = let description = "Testing DAC rollup and node with L1" in regression_test ~__FILE__ @@ -281,9 +281,9 @@ let scenario_with_all_nodes ?(tags = ["dac"; "dac_node"; "legacy"]) ~sc_rollup_node ~pvm_name ~threshold - ~dac_members + ~committee_members client - @@ fun dac_node dac_members -> + @@ fun dac_node committee_members -> scenario protocol dac_node @@ -293,7 +293,7 @@ let scenario_with_all_nodes ?(tags = ["dac"; "dac_node"; "legacy"]) client pvm_name threshold - dac_members) + committee_members) node client key) @@ -364,7 +364,7 @@ let test_dac_node_startup = () in let dac_node = - Dac_node.create_legacy ~node ~client ~threshold:0 ~dac_members:[] () + Dac_node.create_legacy ~node ~client ~threshold:0 ~committee_members:[] () in let* _dir = Dac_node.init_config dac_node in let* () = run_dac dac_node in @@ -419,7 +419,7 @@ let check_preimage expected_preimage actual_preimage = let test_dac_node_handles_dac_store_preimage_merkle_V0 _protocol dac_node sc_rollup_node _sc_rollup_address _node _client pvm_name _threshold - _dac_members = + _committee_members = let payload = "test" in let* actual_rh, l1_operation = RPC.call @@ -459,7 +459,7 @@ let test_dac_node_handles_dac_store_preimage_merkle_V0 _protocol dac_node let test_dac_node_handles_dac_store_preimage_hash_chain_V0 _protocol dac_node sc_rollup_node _sc_rollup_address _node _client pvm_name _threshold - _dac_members = + _committee_members = let payload = "test" in let* actual_rh, _l1_operation = RPC.call @@ -491,7 +491,7 @@ let test_dac_node_handles_dac_store_preimage_hash_chain_V0 _protocol dac_node let test_dac_node_handles_dac_retrieve_preimage_merkle_V0 _protocol dac_node sc_rollup_node _sc_rollup_address _node _client pvm_name _threshold - _dac_members = + _committee_members = let payload = "test" in let* actual_rh, _l1_operation = RPC.call @@ -528,7 +528,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 _threshold _dac_members = + sc_rollup_address _node client _pvm_name _threshold _committee_members = let* genesis_info = RPC.Client.call ~hooks client @@ RPC.get_chain_block_context_smart_rollups_smart_rollup_genesis_info @@ -593,7 +593,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 _threshold _dac_members = + sc_rollup_address _node client _pvm_name _threshold _committee_members = let payload = "Some data that is not related to the hash" in let _actual_rh = RPC.call @@ -634,7 +634,7 @@ let test_reveals_fails_on_wrong_hash _protocol dac_node sc_rollup_node in expect_failure -let test_dac_node_imports_dac_member = +let test_dac_node_imports_committee_members = Protocol.register_test ~__FILE__ ~title:"dac node imports dac members sk_uris" @@ -643,15 +643,21 @@ let test_dac_node_imports_dac_member = @@ fun protocol -> let* node, client = Client.init_with_protocol `Client ~protocol () in let run_dac = Dac_node.run ~wait_ready:false 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* committee_member = + Client.bls_gen_keys ~alias:"committee_member" client + in + let* committee_member_info = + Client.bls_show_address ~alias:committee_member client + in + let committee_member_address = + committee_member_info.aggregate_public_key_hash + in let dac_node = Dac_node.create_legacy ~node ~client ~threshold:1 - ~dac_members:[dac_member_address] + ~committee_members:[committee_member_address] () in let* _dir = Dac_node.init_config dac_node in @@ -672,7 +678,7 @@ let test_dac_node_dac_threshold_not_reached = @@ fun protocol -> let* node, client = Client.init_with_protocol `Client ~protocol () in let dac_node = - Dac_node.create_legacy ~node ~client ~threshold:1 ~dac_members:[] () + Dac_node.create_legacy ~node ~client ~threshold:1 ~committee_members:[] () in let* _dir = Dac_node.init_config dac_node in let run_dac = Dac_node.run ~wait_ready:false in @@ -718,21 +724,21 @@ module Legacy = struct return @@ check_valid_root_hash expected_rh actual_rh let test_streaming_of_root_hashes _protocol node client coordinator threshold - dac_members = + committee_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 dac_members = + let committee_members = List.map (fun (a : Account.aggregate_key) -> a.aggregate_public_key_hash) - dac_members + committee_members in let observer_1 = - Dac_node.create_legacy ~threshold ~dac_members ~node ~client () + Dac_node.create_legacy ~threshold ~committee_members ~node ~client () in let observer_2 = - Dac_node.create_legacy ~threshold ~dac_members ~node ~client () + Dac_node.create_legacy ~threshold ~committee_members ~node ~client () in let* _ = Dac_node.init_config observer_1 in let* _ = Dac_node.init_config observer_2 in @@ -886,22 +892,22 @@ module Legacy = struct (payload, root_hash) let test_observer_downloads_pages _protocol node client coordinator threshold - dac_members = + committee_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 dac_members = + let committee_members = List.map (fun (dc : Account.aggregate_key) -> dc.aggregate_public_key_hash) - dac_members + committee_members in let observer = Dac_node.create_legacy ~threshold - ~dac_members + ~committee_members ~name:"observer" ~node ~client @@ -1132,7 +1138,7 @@ let test_get_certificate _protocol _tezos_node _tz_client coordinator _threshold let register ~protocols = (* Tests with layer1 and dac nodes *) test_dac_node_startup protocols ; - test_dac_node_imports_dac_member protocols ; + test_dac_node_imports_committee_members protocols ; test_dac_node_dac_threshold_not_reached protocols ; scenario_with_all_nodes ~tags:["dac"; "dac_node"] @@ -1140,18 +1146,18 @@ let register ~protocols = test_dac_node_handles_dac_store_preimage_merkle_V0 protocols ~threshold:1 - ~dac_members:1 ; + ~committee_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 ~threshold:1 - ~dac_members:1 ; + ~committee_members:1 ; scenario_with_all_nodes ~tags:["dac"; "dac_node"] ~threshold:0 - ~dac_members:0 + ~committee_members:0 "dac_retrieve_preimage" test_dac_node_handles_dac_retrieve_preimage_merkle_V0 protocols ; @@ -1161,45 +1167,45 @@ let register ~protocols = test_rollup_arith_uses_reveals protocols ~threshold:1 - ~dac_members:1 ; + ~committee_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 + ~committee_members:1 protocols ; scenario_with_layer1_and_legacy_dac_nodes ~threshold:0 - ~dac_members:0 + ~committee_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_legacy_dac_nodes ~threshold:0 - ~dac_members:0 + ~committee_members:0 ~tags:["dac"; "dac_node"] "committee member downloads pages from coordinator" Legacy.test_observer_downloads_pages protocols ; scenario_with_layer1_and_legacy_dac_nodes ~threshold:0 - ~dac_members:3 + ~committee_members:2 ~tags:["dac"; "dac_node"] "dac_get_certificate" test_get_certificate protocols ; scenario_with_layer1_and_legacy_dac_nodes ~threshold:0 - ~dac_members:0 + ~committee_members:0 ~tags:["dac"; "dac_node"] "dac_coordinator_post_preimage_endpoint" Legacy.test_coordinator_post_preimage_endpoint protocols ; scenario_with_layer1_and_legacy_dac_nodes ~threshold:0 - ~dac_members:3 + ~committee_members:3 ~tags:["dac"; "dac_node"] "dac_store_member_signature" Signature_manager.Coordinator.test_handle_store_signature -- GitLab