From bbb0338bf5db60d388f1ed071c8c20ef749dc50c Mon Sep 17 00:00:00 2001 From: Gabriel Moise Date: Mon, 31 Mar 2025 10:48:41 +0100 Subject: [PATCH 1/5] Tezt: Protocol_migration: Change Baker to Agnostic_baker --- tezt/tests/protocol_migration.ml | 282 ++++++------------------------- 1 file changed, 47 insertions(+), 235 deletions(-) diff --git a/tezt/tests/protocol_migration.ml b/tezt/tests/protocol_migration.ml index f650580d8925..7c8111827494 100644 --- a/tezt/tests/protocol_migration.ml +++ b/tezt/tests/protocol_migration.ml @@ -518,28 +518,19 @@ let start_protocol ?consensus_threshold ?round_duration ~parameter_file client -(** Test that migration occuring through (agnostic) baker daemons +(** Test that migration occurring through agnostic baker daemons does not halt the + chain. - - does not halt the chain; - - and that the migration block is not attested by the newer - protocol's baker (if not using agnostic baker). + This has become an issue of sort after updating the consensus protocol to + Tenderbake. For one, attestations have become mandatory, and not only a sign + of healthiness. Then, a special case for the migration block was built-in as + a way to deal with first ever migration, in terms of consensus protocol, was + from Emmy* to Tenderbake. - This has become an issue of sort after updating the consensus protocol to - Tenderbake. For one, attestations have become mandatory, and not only a sign - of healthiness. Then, a special case for the migration block was built-in as - a way to deal with first ever migration, in terms of consensus protocol, was - from Emmy* to Tenderbake. - - Revisit this test, as it may start to fail, whenever a new (family of) - consensus protocol is put into place in Tezos. **) + Revisit this test, as it may start to fail, whenever a new (family of) + consensus protocol is put into place in Tezos. **) let test_migration_with_bakers ?(migration_level = 4) - ?(num_blocks_post_migration = 5) ~migrate_from ~migrate_to - ~use_agnostic_baker () = - let baker_string, uses = - if use_agnostic_baker then - ("agnostic_baker", [Constant.octez_experimental_agnostic_baker]) - else ("baker", [Protocol.baker migrate_from; Protocol.baker migrate_to]) - in + ?(num_blocks_post_migration = 5) ~migrate_from ~migrate_to () = Test.register ~__FILE__ ~title: @@ -548,19 +539,19 @@ let test_migration_with_bakers ?(migration_level = 4) daemon(s)" (Protocol.tag migrate_from) (Protocol.tag migrate_to) - baker_string) + "agnostic_baker") ~tags: [ team; "protocol"; "migration"; - baker_string; + "agnostic_baker"; "attesting"; "metadata"; "from_" ^ Protocol.tag migrate_from; "to_" ^ Protocol.tag migrate_to; ] - ~uses + ~uses:[Constant.octez_experimental_agnostic_baker] @@ fun () -> let* client, node = user_migratable_node_init ~migration_level ~migrate_to () @@ -579,27 +570,9 @@ let test_migration_with_bakers ?(migration_level = 4) (fun account -> account.Account.alias) (Array.to_list Account.Bootstrap.keys) in - - let* () = - if use_agnostic_baker then ( - Log.info "Launching agnostic baker" ; - let* _agnostic_baker = - Agnostic_baker.init ~name:"agnostic_baker" node client ~delegates - in - unit) - else ( - Log.info - "Launching 2 bakers, one for %s (pre-migration protocol), one for \ - %s(post-migration protocol)" - (Protocol.name migrate_from) - (Protocol.name migrate_to) ; - let baker_for_proto protocol = - let name = Printf.sprintf "baker-proto-%s" (Protocol.name protocol) in - Baker.init ~protocol ~name node client ~delegates - in - let* _baker_from_proto = baker_for_proto migrate_from in - let* _baker_to_proto = baker_for_proto migrate_to in - unit) + Log.info "Launching an agnostic baker" ; + let* _agnostic_baker = + Agnostic_baker.init ~name:"agnostic_baker" node client ~delegates in let* _ret = Node.wait_for_level node migration_level in let* () = @@ -829,18 +802,7 @@ let test_forked_migration_manual ?(migration_level = 4) "qc_reached". This is because there is little time between both events, so there would be a risk that "qc_reached" happens before the second waiter has been registered. *) -let wait_for_qc_at_level : - type baker. - wait_for: - (?where:string -> - baker -> - string -> - (JSON.t -> unit option) -> - unit Lwt.t) -> - int -> - baker -> - unit Lwt.t = - fun ~wait_for level baker -> +let wait_for_qc_at_level baker level = Log.info "Wait for a quorum event on a proposal at pre-migration level %d. At this \ point, we know that attestations on this proposal have been propagated, \ @@ -850,7 +812,7 @@ let wait_for_qc_at_level : let where = sf "level = %d" level in let level_seen = ref false in let proposal_waiter = - wait_for baker "new_valid_proposal.v0" ~where (fun json -> + Agnostic_baker.wait_for baker "new_valid_proposal.v0" ~where (fun json -> let proposal_level = JSON.(json |-> "level" |> as_int) in if proposal_level = level then ( level_seen := true ; @@ -863,7 +825,7 @@ let wait_for_qc_at_level : else None) in Background.register proposal_waiter ; - wait_for baker "qc_reached.v0" ~where (fun (_ : JSON.t) -> + Agnostic_baker.wait_for baker "qc_reached.v0" ~where (fun (_ : JSON.t) -> if !level_seen then Some () else None) let get_block_at_level level client = @@ -871,61 +833,30 @@ let get_block_at_level level client = client (RPC.get_chain_block ~version:"1" ~block:(string_of_int level) ()) -let wait_for_post_migration_proposal : - type baker. - wait_for: - (?where:string -> - baker -> - string -> - (JSON.t -> unit option) -> - unit Lwt.t) -> - int -> - baker -> - unit Lwt.t = - fun ~wait_for post_migration_level baker -> - wait_for baker "new_valid_proposal.v0" (fun json -> +let wait_for_post_migration_proposal baker post_migration_level = + Agnostic_baker.wait_for baker "new_valid_proposal.v0" (fun json -> let level = JSON.(json |-> "level" |> as_int) in if level = post_migration_level then Some () else if level > post_migration_level then Test.fail "Reached level %d with a split network." level else None) -let test_forked_migration_bakers bakers ~migrate_from ~migrate_to = - let baker_name, baker_tags, baker_uses = - match bakers with - | `Bakers -> - ( "baker", - ["baker"], - [Protocol.baker migrate_from; Protocol.baker migrate_to] ) - | `Agnostic_bakers -> - ( "agnostic baker", - ["agnostic_baker"], - [Constant.octez_experimental_agnostic_baker] ) - | `Mixed -> - ( "baker and agnostic baker", - ["baker"; "agnostic_baker"], - [ - Protocol.baker migrate_from; - Protocol.baker migrate_to; - Constant.octez_experimental_agnostic_baker; - ] ) - in +let test_forked_migration_bakers ~migrate_from ~migrate_to = Test.register ~__FILE__ ~tags: ([team; "protocol"; "migration"] - @ baker_tags @ [ + "agnostic_baker"; "attesting"; "fork"; "from_" ^ Protocol.tag migrate_from; "to_" ^ Protocol.tag migrate_to; ]) - ~uses:baker_uses + ~uses:[Constant.octez_experimental_agnostic_baker] ~title: (Printf.sprintf - "%s forked migration blocks from %s to %s" - baker_name + "agnostic baker forked migration blocks from %s to %s" (Protocol.tag migrate_from) (Protocol.tag migrate_to)) @@ fun () -> @@ -958,9 +889,8 @@ let test_forked_migration_bakers bakers ~migrate_from ~migrate_to = and* () = connect cn2 cn3 in Log.info - "Partition bootstrap delegates into 3 groups. Start bakers for pre- and \ - post-migration protocols or agnostic bakers, on a separate node for each \ - group of delegates." ; + "Partition bootstrap delegates into 3 groups. Start agnostic bakers, on a \ + separate node for each group of delegates." ; (* The groups are chosen considering baker rights at levels 4 and 5, see comment further below. *) let group1 = @@ -974,21 +904,6 @@ let test_forked_migration_bakers bakers ~migrate_from ~migrate_to = let pp_sep fmt () = Format.fprintf fmt " and " in Format.pp_print_list ~pp_sep Format.pp_print_string in - let baker_for_proto protocol (node, client, delegates) = - let name = sf "baker_%s_%s" (Protocol.tag protocol) (Node.name node) in - Log.info "Start %s for %a." name pp_delegates delegates ; - let event_sections_levels = - [(String.concat "." [Protocol.encoding_prefix protocol; "baker"], `Debug)] - in - (* We copy the code in {!Baker.init}, except that we don't wait - for the baker to be ready. Indeed, bakers aren't ready until - their protocol has been activated. *) - let* () = Node.wait_for_ready node in - let baker = Baker.create ~protocol ~name ~delegates node client in - let* () = Baker.run ~event_sections_levels baker in - Baker.log_block_injection ~color:Log.Color.FG.yellow baker ; - return baker - in let agnostic_baker (node, client, delegates) = let name = sf "agnostic_baker_%s" (Node.name node) in @@ -1054,116 +969,24 @@ let test_forked_migration_bakers bakers ~migrate_from ~migrate_to = in let* () = - match bakers with - | `Bakers -> - let* baker1_from = baker_for_proto migrate_from group1 - and* _baker2_from = baker_for_proto migrate_from group2 - and* _baker3_from = baker_for_proto migrate_from group3 - and* baker1_to = baker_for_proto migrate_to group1 - and* _baker2_to = baker_for_proto migrate_to group2 - and* baker3_to = baker_for_proto migrate_to group3 in - - let* () = start_protocol () in - let* () = - check_adaptive_issuance_launch_cycle - ~loc:__LOC__ - ~migrate_from - client1 - in - let* () = - wait_for_qc_at_level - pre_migration_level - ~wait_for:Baker.wait_for - baker1_from - in - let* () = disconnect_clusters () in - - let wait_for () = - let* () = - wait_for_post_migration_proposal - post_migration_level - ~wait_for:Baker.wait_for - baker1_to - and* () = - wait_for_post_migration_proposal - post_migration_level - ~wait_for:Baker.wait_for - baker3_to - in - unit - in - check_post_migration_proposal ~wait_for - | `Agnostic_bakers -> - let* agnostic_baker1 = agnostic_baker group1 - and* _agnostic_baker2 = agnostic_baker group2 - and* agnostic_baker3 = agnostic_baker group3 in - - let* () = start_protocol () in - let* () = - check_adaptive_issuance_launch_cycle - ~loc:__LOC__ - ~migrate_from - client1 - in - let* () = - wait_for_qc_at_level - pre_migration_level - ~wait_for:Agnostic_baker.wait_for - agnostic_baker1 - in - let* () = disconnect_clusters () in - - let wait_for () = - let* () = - wait_for_post_migration_proposal - post_migration_level - ~wait_for:Agnostic_baker.wait_for - agnostic_baker1 - and* () = - wait_for_post_migration_proposal - post_migration_level - ~wait_for:Agnostic_baker.wait_for - agnostic_baker3 - in - unit - in - check_post_migration_proposal ~wait_for - | `Mixed -> - let* baker1_from = baker_for_proto migrate_from group1 - and* baker1_to = baker_for_proto migrate_to group1 - and* _agnostic_baker2 = agnostic_baker group2 - and* agnostic_baker3 = agnostic_baker group3 in - - let* () = start_protocol () in - let* () = - check_adaptive_issuance_launch_cycle - ~loc:__LOC__ - ~migrate_from - client1 - in - let* () = - wait_for_qc_at_level - pre_migration_level - ~wait_for:Baker.wait_for - baker1_from - in - let* () = disconnect_clusters () in - - let wait_for () = - let* () = - wait_for_post_migration_proposal - post_migration_level - ~wait_for:Baker.wait_for - baker1_to - and* () = - wait_for_post_migration_proposal - post_migration_level - ~wait_for:Agnostic_baker.wait_for - agnostic_baker3 - in - unit - in - check_post_migration_proposal ~wait_for + let* agnostic_baker1 = agnostic_baker group1 + and* _agnostic_baker2 = agnostic_baker group2 + and* agnostic_baker3 = agnostic_baker group3 in + let* () = start_protocol () in + let* () = + check_adaptive_issuance_launch_cycle ~loc:__LOC__ ~migrate_from client1 + in + let* () = wait_for_qc_at_level agnostic_baker1 pre_migration_level in + let* () = disconnect_clusters () in + let wait_for () = + let* () = + wait_for_post_migration_proposal agnostic_baker1 post_migration_level + and* () = + wait_for_post_migration_proposal agnostic_baker3 post_migration_level + in + unit + in + check_post_migration_proposal ~wait_for in let* () = @@ -1979,19 +1802,8 @@ let test_unstaked_requests_and_min_delegated () = let register ~migrate_from ~migrate_to = test_migration_for_whole_cycle ~migrate_from ~migrate_to ; - test_migration_with_bakers - ~migrate_from - ~migrate_to - ~use_agnostic_baker:false - () ; - test_migration_with_bakers - ~migrate_from - ~migrate_to - ~use_agnostic_baker:true - () ; - List.iter - (test_forked_migration_bakers ~migrate_from ~migrate_to) - [`Bakers; `Agnostic_bakers; `Mixed] ; + test_migration_with_bakers ~migrate_from ~migrate_to () ; + test_forked_migration_bakers ~migrate_from ~migrate_to ; test_forked_migration_manual ~migrate_from ~migrate_to () ; test_migration_with_snapshots ~migrate_from ~migrate_to ; test_tolerated_inactivity_period () ; -- GitLab From 071b1b8c57df647cf45b09fad75f4f01b89594c8 Mon Sep 17 00:00:00 2001 From: Gabriel Moise Date: Mon, 31 Mar 2025 11:39:27 +0100 Subject: [PATCH 2/5] Tezt: Add protocol-specific baker binaries to unused --- tezt/lib_tezos/constant.ml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tezt/lib_tezos/constant.ml b/tezt/lib_tezos/constant.ml index 5592f18a3291..f864662c354b 100644 --- a/tezt/lib_tezos/constant.ml +++ b/tezt/lib_tezos/constant.ml @@ -88,6 +88,18 @@ let teztale_server = let _teztale_snitch = Uses.make ~tag:"teztale_snitch" ~path:"./octez-teztale-snitch" () +(* TODO: Remove these once the binaries are completely removed from + [released-executables]. *) + +let octez_baker_quebec = + Uses.make ~tag:"baker_psquebec" ~path:"./octez-baker-PsQuebec" () + +let octez_baker_rio = + Uses.make ~tag:"baker_psriotum" ~path:"./octez-baker-PsRiotum" () + +let octez_baker_alpha = + Uses.make ~tag:"baker_alpha" ~path:"./octez-baker-alpha" () + let yes_wallet = Uses.make ~tag:"yes_wallet" -- GitLab From 7925ea747fe979c7d4945722dd174f9c1c6970e9 Mon Sep 17 00:00:00 2001 From: Gabriel Moise Date: Mon, 31 Mar 2025 11:08:52 +0100 Subject: [PATCH 3/5] Tezt: Remove Baker module --- tezt/lib_tezos/baker.ml | 497 --------------------------------------- tezt/lib_tezos/baker.mli | 304 ------------------------ 2 files changed, 801 deletions(-) delete mode 100644 tezt/lib_tezos/baker.ml delete mode 100644 tezt/lib_tezos/baker.mli diff --git a/tezt/lib_tezos/baker.ml b/tezt/lib_tezos/baker.ml deleted file mode 100644 index 2e00622c82a0..000000000000 --- a/tezt/lib_tezos/baker.ml +++ /dev/null @@ -1,497 +0,0 @@ -(*****************************************************************************) -(* *) -(* Open Source License *) -(* Copyright (c) 2021 Nomadic Labs *) -(* *) -(* Permission is hereby granted, free of charge, to any person obtaining a *) -(* copy of this software and associated documentation files (the "Software"),*) -(* to deal in the Software without restriction, including without limitation *) -(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *) -(* and/or sell copies of the Software, and to permit persons to whom the *) -(* Software is furnished to do so, subject to the following conditions: *) -(* *) -(* The above copyright notice and this permission notice shall be included *) -(* in all copies or substantial portions of the Software. *) -(* *) -(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*) -(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *) -(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *) -(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*) -(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *) -(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *) -(* DEALINGS IN THE SOFTWARE. *) -(* *) -(*****************************************************************************) - -type liquidity_baking_vote = Off | On | Pass - -let liquidity_baking_vote_to_string = function - | Off -> "off" - | On -> "on" - | Pass -> "pass" - -let liquidity_baking_vote_of_string_opt = function - | "off" -> Some Off - | "on" -> Some On - | "pass" -> Some Pass - | _ -> None - -module Parameters = struct - type persistent_state = { - protocol : Protocol.t; - delegates : string list; - runner : Runner.t option; - base_dir : string; - node_data_dir : string; - node_rpc_endpoint : Endpoint.t; - dal_node_rpc_endpoint : Endpoint.t option; - dal_node_timeout_percentage : int option; - mutable pending_ready : unit option Lwt.u list; - votefile : string option; - liquidity_baking_toggle_vote : liquidity_baking_vote option; - force_apply_from_round : int option; - remote_mode : bool; - operations_pool : string option; - minimal_nanotez_per_gas_unit : int option; - state_recorder : bool; - node_version_check_bypass : bool; - node_version_allowed : string option; - } - - type session_state = {mutable ready : bool} - - let base_default_name = "baker" - - let default_colors = Log.Color.[|FG.green|] -end - -open Parameters -include Daemon.Make (Parameters) - -let trigger_ready baker value = - let pending = baker.persistent_state.pending_ready in - baker.persistent_state.pending_ready <- [] ; - List.iter (fun pending -> Lwt.wakeup_later pending value) pending - -let set_ready baker = - (match baker.status with - | Not_running -> () - | Running status -> status.session_state.ready <- true) ; - trigger_ready baker (Some ()) - -let handle_raw_stdout baker line = - if line =~ rex "^Baker .+ for .+ started.$" then set_ready baker - -let liquidity_baking_votefile ?path vote = - let votefile = - Option.value - path - ~default:(Temp.file "liquidity_baking_toggle_votefile.json") - in - JSON.encode_to_file_u - votefile - (`O - [ - ( "liquidity_baking_toggle_vote", - `String (liquidity_baking_vote_to_string vote) ); - ]) ; - votefile - -let create_from_uris ?runner ~protocol - ?(path = Uses.path (Protocol.baker protocol)) ?name ?color ?event_pipe - ?(delegates = []) ?votefile ?(liquidity_baking_toggle_vote = Some Pass) - ?force_apply_from_round ?(remote_mode = false) ?operations_pool - ?dal_node_rpc_endpoint ?dal_node_timeout_percentage - ?minimal_nanotez_per_gas_unit ?(state_recorder = false) - ?(node_version_check_bypass = false) ?node_version_allowed ~base_dir - ~node_data_dir ~node_rpc_endpoint () = - let baker = - create - ~path - ?name - ?color - ?event_pipe - ?runner - { - protocol; - delegates; - runner; - base_dir; - node_data_dir; - node_rpc_endpoint; - pending_ready = []; - votefile; - liquidity_baking_toggle_vote; - remote_mode; - force_apply_from_round; - operations_pool; - dal_node_rpc_endpoint; - dal_node_timeout_percentage; - minimal_nanotez_per_gas_unit; - state_recorder; - node_version_check_bypass; - node_version_allowed; - } - in - on_stdout baker (handle_raw_stdout baker) ; - baker - -let create ?runner ~protocol ?path ?name ?color ?event_pipe ?(delegates = []) - ?votefile ?(liquidity_baking_toggle_vote = Some Pass) - ?force_apply_from_round ?(remote_mode = false) ?operations_pool ?dal_node - ?dal_node_timeout_percentage ?minimal_nanotez_per_gas_unit - ?(state_recorder = false) ?(node_version_check_bypass = false) - ?node_version_allowed node client = - let dal_node_rpc_endpoint = Option.map Dal_node.as_rpc_endpoint dal_node in - create_from_uris - ?runner - ~protocol - ?path - ?name - ?color - ?event_pipe - ~delegates - ?votefile - ~liquidity_baking_toggle_vote - ?force_apply_from_round - ~remote_mode - ?operations_pool - ?minimal_nanotez_per_gas_unit - ?dal_node_rpc_endpoint - ?dal_node_timeout_percentage - ~state_recorder - ~node_version_check_bypass - ?node_version_allowed - ~base_dir:(Client.base_dir client) - ~node_data_dir:(Node.data_dir node) - ~node_rpc_endpoint:(Node.as_rpc_endpoint node) - () - -let run ?env ?event_level ?event_sections_levels (baker : t) = - (match baker.status with - | Not_running -> () - | Running _ -> Test.fail "baker %s is already running" baker.name) ; - let delegates = baker.persistent_state.delegates in - let runner = baker.persistent_state.runner in - let node_data_dir = baker.persistent_state.node_data_dir in - let base_dir = baker.persistent_state.base_dir in - let node_addr = Endpoint.as_string baker.persistent_state.node_rpc_endpoint in - let votefile = - Cli_arg.optional_arg "votefile" Fun.id baker.persistent_state.votefile - in - let liquidity_baking_toggle_vote = - Cli_arg.optional_arg - "liquidity-baking-toggle-vote" - liquidity_baking_vote_to_string - baker.persistent_state.liquidity_baking_toggle_vote - in - let force_apply_from_round = - (* From Protocol Q, the flag --force-apply has been replaced by - --force-apply-from-round, the following maintains back-compatibility with - ParisC tests. *) - Cli_arg.optional_arg - "force-apply-from-round" - string_of_int - baker.persistent_state.force_apply_from_round - in - let operations_pool = - Cli_arg.optional_arg - "operations-pool" - Fun.id - baker.persistent_state.operations_pool - in - let dal_node_endpoint = - Cli_arg.optional_arg - "dal-node" - Endpoint.as_string - baker.persistent_state.dal_node_rpc_endpoint - in - let without_dal = - Cli_arg.optional_switch - "without-dal" - (Protocol.number baker.persistent_state.protocol - > Protocol.number Protocol.Quebec - && Option.is_none baker.persistent_state.dal_node_rpc_endpoint) - in - let dal_node_timeout_percentage = - Cli_arg.optional_arg - "dal-node-timeout-percentage" - string_of_int - baker.persistent_state.dal_node_timeout_percentage - in - let minimal_nanotez_per_gas_unit = - Cli_arg.optional_arg - "minimal-nanotez-per-gas-unit" - (fun nanotez_per_gas -> string_of_int nanotez_per_gas) - baker.persistent_state.minimal_nanotez_per_gas_unit - in - let state_recorder = - Cli_arg.optional_switch "record-state" baker.persistent_state.state_recorder - in - let node_version_check_bypass = - Cli_arg.optional_switch - "node-version-check-bypass" - baker.persistent_state.node_version_check_bypass - in - let node_version_allowed = - Cli_arg.optional_arg - "node-version-allowed" - Fun.id - baker.persistent_state.node_version_allowed - in - let run_args = - if baker.persistent_state.remote_mode then ["remotely"] - else ["with"; "local"; "node"; node_data_dir] - in - let arguments = - ["--endpoint"; node_addr; "--base-dir"; base_dir; "run"] - @ run_args @ liquidity_baking_toggle_vote @ votefile - @ force_apply_from_round @ operations_pool @ dal_node_endpoint @ without_dal - @ dal_node_timeout_percentage @ delegates @ minimal_nanotez_per_gas_unit - @ state_recorder @ node_version_check_bypass @ node_version_allowed - in - - let on_terminate _ = - (* Cancel all [Ready] event listeners. *) - trigger_ready baker None ; - unit - in - run - ?env - ?event_level - ?event_sections_levels - baker - {ready = false} - arguments - ~on_terminate - ?runner - -let check_event ?where baker name promise = - let* result = promise in - match result with - | None -> - raise (Terminated_before_event {daemon = baker.name; event = name; where}) - | Some x -> return x - -let wait_for_ready baker = - match baker.status with - | Running {session_state = {ready = true; _}; _} -> unit - | Not_running | Running {session_state = {ready = false; _}; _} -> - let promise, resolver = Lwt.task () in - baker.persistent_state.pending_ready <- - resolver :: baker.persistent_state.pending_ready ; - check_event baker "Baker started." promise - -let init ?env ?runner ~protocol ?(path = Uses.path (Protocol.baker protocol)) - ?name ?color ?event_level ?event_pipe ?event_sections_levels - ?(delegates = []) ?votefile ?liquidity_baking_toggle_vote - ?force_apply_from_round ?remote_mode ?operations_pool ?dal_node - ?dal_node_timeout_percentage ?minimal_nanotez_per_gas_unit ?state_recorder - ?node_version_check_bypass ?node_version_allowed node client = - let* () = Node.wait_for_ready node in - let baker = - create - ?runner - ~path - ~protocol - ?name - ?color - ?event_pipe - ?votefile - ?liquidity_baking_toggle_vote - ?force_apply_from_round - ?remote_mode - ?operations_pool - ?dal_node - ?dal_node_timeout_percentage - ?minimal_nanotez_per_gas_unit - ?state_recorder - ?node_version_check_bypass - ?node_version_allowed - ~delegates - node - client - in - let* () = run ?env ?event_level ?event_sections_levels baker in - let* () = wait_for_ready baker in - return baker - -(** Logging helpers for baker events. *) - -let log_block_injection ?color baker = - on_event baker (fun event -> - if String.equal event.name "block_injected.v0" then - let open JSON in - let level = event.value |-> "level" |> as_int in - let round = event.value |-> "round" |> as_int in - let delegate = event.value |-> "delegate" |-> "alias" |> as_string in - Log.info - ?color - "[%s] Block injected at level %d round %d for %s." - (name baker) - level - round - delegate) - -(** Short and readable logging of all baker events, for debugging purposes. *) - -let encode_mini json = - Ezjsonm.value_to_string ~minify:true (JSON.unannotate json) - -(* Only keep the first 10 characters of hashes to print. *) -let shorten s = try String.sub s 0 10 with Invalid_argument _ -> s - -let shorten_json_string json = - let s = JSON.as_string json in - if String.length s <= 10 then json - else JSON.annotate ~origin:"shorten" (Ezjsonm.string (shorten s)) - -let try_simplify_delegate_object json = - let open JSON in - try - let alias = json |-> "alias" in - if is_string alias then ( - let obj = as_object json in - let _ = json |-> "public_key" |> as_string in - let _ = json |-> "public_key_hash" |> as_string in - let _ = json |-> "secret_key_uri" |> as_string in - let _ = json |-> "delegate" |> as_string in - if List.length obj <> 5 then - Log.warn "%s: unexpected fields: %s" __LOC__ (encode_mini json) ; - Some alias) - else None - with _ -> - Log.warn - "%s: has field alias but not all expected fields for delegate: %s" - __LOC__ - (encode_mini json) ; - None - -let rec make_readable json = - let open JSON in - if is_string json then shorten_json_string json - else if is_object json then - match try_simplify_delegate_object json with - | Some output -> output - | None -> filter_map_object json make_field_readable - else json - -and make_field_readable field_name value = - (match field_name with - | "timestamp" -> (* Usually a string: do not shorten it. *) value - | "timespan" -> ( - match Option.bind (JSON.as_float_opt value) Ptime.Span.of_float_s with - | None -> value - | Some span -> - let rounded = Ptime.Span.(to_float_s (round ~frac_s:2 span)) in - JSON.annotate ~origin:"rounded timespan" (Ezjsonm.float rounded)) - | _ -> make_readable value) - |> Option.some - -let encode_readable json = encode_mini (make_readable json) - -let show_operations ~loc ?expected_kind ?expected_level_and_round ops = - let open JSON in - let rec aux expected_kind expected_level_and_round acc_slots = function - | [] -> (expected_kind, expected_level_and_round, acc_slots) - | op :: remaining_ops -> - let contents = op |-> "contents" |=> 0 in - let kind = contents |-> "kind" |> as_string in - let level = contents |-> "level" |> as_int in - let round = contents |-> "round" |> as_int in - (match expected_kind with - | Some expected_kind when not (String.equal expected_kind kind) -> - Log.warn "%s: expected %s but got %s" loc expected_kind kind ; - assert false - | _ -> ()) ; - (match expected_level_and_round with - | Some (expected_level, expected_round) - when not (expected_level = level && expected_round = round) -> - Log.warn - "%s expected op with (level %d, round %d) but got (%d, %d)" - loc - expected_level - level - expected_round - round ; - assert false - | _ -> ()) ; - let slot = contents |-> "slot" |> as_int in - aux (Some kind) (Some (level, round)) (slot :: acc_slots) remaining_ops - in - match aux expected_kind expected_level_and_round [] ops with - | _, _, [] -> "(0 operations)" - | Some kind, Some (level, round), rev_slots -> - sf - "(%d %ss on level %d round %d with slots [%s])" - (List.length ops) - kind - level - round - (String.concat ";" (List.map string_of_int (List.rev rev_slots))) - | _ -> assert false - -let show_block json = - let open JSON in - let prequorum = - let prequorum = json |-> "prequorum" in - if is_null prequorum then "None" - else - let ops = prequorum |-> "preattestation" |> as_list in - let expected_level_and_round = - (prequorum |-> "level" |> as_int, prequorum |-> "round" |> as_int) - in - let expected_kind = "preattestation" in - show_operations ~loc:__LOC__ ~expected_kind ~expected_level_and_round ops - in - let quorum = - match json |-> "quorum" |> as_list with - | [] -> "[]" - | ops -> show_operations ~loc:__LOC__ ~expected_kind:"attestation" ops - in - sf - "block={hash=%s, level=%d, round=%d, prequorum=%s, quorum=%s}" - (json |-> "hash" |> as_string |> shorten) - (json |-> "shell" |-> "level" |> as_int) - (json |-> "round" |> as_int) - prequorum - quorum - -let show_step_event_data json = - let open JSON in - try - let block = json |-> "block" in - if not (is_null block) then show_block block - else - match as_list_opt json with - | Some ops -> show_operations ~loc:__LOC__ ops - | None -> encode_readable json - with _ -> encode_readable json - -let log_step_current_phase_exn prefix json = - let open JSON in - let phase = json |-> "phase" |> as_string in - let event_name, event_data_list = - match json |-> "event" |> as_list with - | name :: infos -> (as_string name, infos) - | _ -> assert false - in - Log.info - "%s phase=%s, event=%s %s" - prefix - phase - event_name - (String.concat " " (List.map show_step_event_data event_data_list)) - -let log_step_current_phase prefix json = - try log_step_current_phase_exn prefix json - with _ -> Log.warn "%s Unexpected format: %s" prefix (JSON.encode json) - -let log_shortened_events baker = - let handler (event : event) = - let prefix = Format.sprintf "[%s] %s:" baker.name event.name in - match event.name with - | "step_current_phase.v0" -> log_step_current_phase prefix event.value - | _ -> Log.info "%s %s" prefix (encode_readable event.value) - in - on_event baker handler diff --git a/tezt/lib_tezos/baker.mli b/tezt/lib_tezos/baker.mli deleted file mode 100644 index ab253aa7fbd9..000000000000 --- a/tezt/lib_tezos/baker.mli +++ /dev/null @@ -1,304 +0,0 @@ -(*****************************************************************************) -(* *) -(* Open Source License *) -(* Copyright (c) 2021 Nomadic Labs *) -(* *) -(* Permission is hereby granted, free of charge, to any person obtaining a *) -(* copy of this software and associated documentation files (the "Software"),*) -(* to deal in the Software without restriction, including without limitation *) -(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *) -(* and/or sell copies of the Software, and to permit persons to whom the *) -(* Software is furnished to do so, subject to the following conditions: *) -(* *) -(* The above copyright notice and this permission notice shall be included *) -(* in all copies or substantial portions of the Software. *) -(* *) -(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*) -(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *) -(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *) -(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*) -(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *) -(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *) -(* DEALINGS IN THE SOFTWARE. *) -(* *) -(*****************************************************************************) - -(** A baker instance *) -type t - -(** See [Daemon.Make.name] *) -val name : t -> string - -(** Send SIGTERM and wait for the process to terminate. - - Default [timeout] is 30 seconds, after which SIGKILL is sent. *) -val terminate : ?timeout:float -> t -> unit Lwt.t - -(** Send SIGKILL and wait for the process to terminate. *) -val kill : t -> unit Lwt.t - -(** Send SIGSTOP to the process. *) -val stop : t -> unit Lwt.t - -(** Send SIGCONT to the process. *) -val continue : t -> unit Lwt.t - -(** See [Daemon.Make.log_events]. *) -val log_events : ?max_length:int -> t -> unit - -(** See [Daemon.Make.wait_for]. *) -val wait_for : ?where:string -> t -> string -> (JSON.t -> 'a option) -> 'a Lwt.t - -(** Wait until the baker is ready. - - More precisely, wait until a "Baker started" event occurs. - If this event alreay happened, return immediately. - *) -val wait_for_ready : t -> unit Lwt.t - -(** Raw events. *) -type event = {name : string; value : JSON.t; timestamp : float} - -(** See [Daemon.Make.on_event]. *) -val on_event : t -> (event -> unit) -> unit - -(** Spawn [octez-baker run]. - - The resulting promise is fulfilled as soon as the baker has been - spawned. It continues running in the background. *) -val run : - ?env:string String_map.t -> - ?event_level:Daemon.Level.default_level -> - ?event_sections_levels:(string * Daemon.Level.level) list -> - t -> - unit Lwt.t - -(** Liquidity baking vote values. *) -type liquidity_baking_vote = Off | On | Pass - -(** Returns the [liquidity_baking_vote] corresponding to a string, or None if the - string is not a valid liquidity baking vote. *) -val liquidity_baking_vote_of_string_opt : string -> liquidity_baking_vote option - -(** Returns the string representation of a [liquidity_baking_vote]. *) -val liquidity_baking_vote_to_string : liquidity_baking_vote -> string - -(** Writes a liquidity baking votefile, as read by the bakers [--votefile] - argument. - - If [path] is set, the vote file is written there. Otherwise, it is written - to a temporary file. - - Returns the path to the file that was written. *) -val liquidity_baking_votefile : ?path:string -> liquidity_baking_vote -> string - -(** Create a baker. - - This function just creates a value of type [t], it does not call {!val:run}. - - [path] provides the path to the baker binary, the default being the one - derived from the [protocol]. - - The standard output and standard error output of the baker will - be logged with prefix [name] and color [color]. - - Default [event_pipe] is a temporary file whose name is derived - from [name]. It will be created as a named pipe so that baker - events can be received. - - The [Node.t] parameter is the node used by the baker. The baker - is configured to use the node's data dir. - - The [Client.t] parameter is the client used by the baker. The baker - is configured to use the client's base directory. - - If [runner] is specified, the baker will be spawned on this - runner using SSH. - - [delegates] is a list of account aliases (see {!val:Account.key.alias}), e.g., - bootstrap accounts (see {!val:Constant.bootstrap_keys}), delegated to this - baker. This defaults to the empty list, which is a shortcut for "every known - account". - - [votefile] and [liquidity_baking_toggle_vote] are passed to the baker daemon - through the flags [--votefile] and [--liquidity-baking-toggle-vote]. If - [--liquidity-baking-toggle-vote] is [None], then - [--liquidity-baking-toggle-vote] - is not passed. If it is [Some x] then [--liquidity-baking-toggle-vote x] is - passed. The default value is [Some Pass]. - - [operations_pool], [force_apply_from_round], [state_recorder], - [node_version_check_bypass] and [node_version_allowed] are passed to the - baker daemon through the flag [--operations-pool], - [--force_apply_from_round], - [--record-state], [--node-version-check-bypass] and - [--node-version-allowed]. - - If [remote_mode] is specified, the baker will run in RPC-only mode. - - If [dal_node] is specified, then it is the DAL node that the baker queries - in order to determine the attestations it sends to the L1 node. A - [--dal_node] argument is passed to specify the DAL node's endpoint. - - [minimal_nanotez_per_gas_unit] is an integer passed to the baker daemon - through the flag [--minimal-nanotez-per-gas-unit]. - *) -val create : - ?runner:Runner.t -> - protocol:Protocol.t -> - ?path:string -> - ?name:string -> - ?color:Log.Color.t -> - ?event_pipe:string -> - ?delegates:string list -> - ?votefile:string -> - ?liquidity_baking_toggle_vote:liquidity_baking_vote option -> - ?force_apply_from_round:int -> - ?remote_mode:bool -> - ?operations_pool:string -> - ?dal_node:Dal_node.t -> - ?dal_node_timeout_percentage:int -> - ?minimal_nanotez_per_gas_unit:int -> - ?state_recorder:bool -> - ?node_version_check_bypass:bool -> - ?node_version_allowed:string -> - Node.t -> - Client.t -> - t - -(** Similar to {!create}, but nodes RPCs addresses, wallet base directory and L1 - data directory are directly provided instead of a {!Client.t}, a {!Node.t} - and optionally a {!Dal_node.t}. - - The [node_data_dir] parameter provides the (local) node's data directory - used for baking. - - The [node_rpc_endpoint] parameter provides the (local) node's RPC server - endpoint to which the baker will connect to. - - The [base_dir] parameter contains needed information about the wallets used - by the baker. - - If [dal_node_rpc_endpoint] is specified, then it provides the DAL node RPC - server's endpoint that the baker queries in order to determine the - attestations it sends to the L1 node. A [--dal_node] argument is passed - to specify the DAL node's endpoint. - *) -val create_from_uris : - ?runner:Runner.t -> - protocol:Protocol.t -> - ?path:string -> - ?name:string -> - ?color:Log.Color.t -> - ?event_pipe:string -> - ?delegates:string list -> - ?votefile:string -> - ?liquidity_baking_toggle_vote:liquidity_baking_vote option -> - ?force_apply_from_round:int -> - ?remote_mode:bool -> - ?operations_pool:string -> - ?dal_node_rpc_endpoint:Endpoint.t -> - ?dal_node_timeout_percentage:int -> - ?minimal_nanotez_per_gas_unit:int -> - ?state_recorder:bool -> - ?node_version_check_bypass:bool -> - ?node_version_allowed:string -> - base_dir:string -> - node_data_dir:string -> - node_rpc_endpoint:Endpoint.t -> - unit -> - t - -(** Initialize a baker. - - This creates a baker, waits for it to be ready, and then returns it. - - As the baker usually relies on a node, we first - wait for the node to be ready and then, run the baker. - - The path to the baker binary is chosen from the [protocol]. - - The standard output and standard error output of the baker will - be logged with prefix [name] and color [color]. - - Default [event_pipe] is a temporary file whose name is derived - from [name]. It will be created as a named pipe so that baker - events can be received. - - The [Node.t] parameter is the node used by the baker. The baker - is configured to use the node's data dir. - - The [Client.t] parameter is the client used by the baker. The baker - is configured to use the client's base directory. - - If [runner] is specified, the baker will be spawned on this - runner using SSH. - - [delegates] is a list of account aliases (see {!val:Account.key.alias}), e.g., - bootstrap accounts (see {!val:Constant.bootstrap_keys}), delegated to this - baker. This defaults to the empty list, which is a shortcut for "every known - account". - - [votefile], [liquidity_baking_toggle_vote], [force_apply_from_round], - [state_recorder], [node_version_check_bypass], [node_version_allowed] - respectively [operations_pool] are passed to the baker daemon through the - flags [--votefile], [--liquidity-baking-toggle-vote], [--should-apply], - [--record-state], [--node-version-check-bypass], [--node-version-allowed] - respectively [--operations-pool]. - - If [remote_mode] is specified, the baker will run in RPC-only mode. - - If [dal_node] is specified, then it is the DAL node that the baker queries - in order to determine the attestations it sends to the L1 node. A - [--dal_node] argument is passed to specify the DAL node's endpoint. *) -val init : - ?env:string String_map.t -> - ?runner:Runner.t -> - protocol:Protocol.t -> - ?path:string -> - ?name:string -> - ?color:Log.Color.t -> - ?event_level:Daemon.Level.default_level -> - ?event_pipe:string -> - ?event_sections_levels:(string * Daemon.Level.level) list -> - ?delegates:string list -> - ?votefile:string -> - ?liquidity_baking_toggle_vote:liquidity_baking_vote option -> - ?force_apply_from_round:int -> - ?remote_mode:bool -> - ?operations_pool:string -> - ?dal_node:Dal_node.t -> - ?dal_node_timeout_percentage:int -> - ?minimal_nanotez_per_gas_unit:int -> - ?state_recorder:bool -> - ?node_version_check_bypass:bool -> - ?node_version_allowed:string -> - Node.t -> - Client.t -> - t Lwt.t - -(** Log block injection events. - - Show the baker daemon name, level and round of the block, and - delegate for which it was injected. - - This log is relatively lightweight and a good indicator of chain - progress during a test. It can also be useful to observe baking - rights at the levels and rounds featured in a test. *) -val log_block_injection : ?color:Log.Color.t -> t -> unit - -(** Log all baker events with [Log.info] on a single line each, which - should be easily readable by a human. - - This function should not be called by any test on a permanent - basis, but is available for debugging. - - If an event has an unexpected format, the anomaly is signaled with - [Log.warn]. - - If you want to see all events, don't forget to launch the baker with -{[ -~event_sections_levels: - [(String.concat "." [Protocol.encoding_prefix protocol; "baker"], `Debug)] -]} *) -val log_shortened_events : t -> unit -- GitLab From 3c1259ee459f2604610fc867b0a072c749763a2c Mon Sep 17 00:00:00 2001 From: Gabriel Moise Date: Mon, 31 Mar 2025 11:09:51 +0100 Subject: [PATCH 4/5] Tezt: Remove protocol baker binary path in tezt tests --- tezt/lib_tezos/protocol.ml | 2 -- tezt/lib_tezos/protocol.mli | 3 --- 2 files changed, 5 deletions(-) diff --git a/tezt/lib_tezos/protocol.ml b/tezt/lib_tezos/protocol.ml index 30a28720accb..1053db50c314 100644 --- a/tezt/lib_tezos/protocol.ml +++ b/tezt/lib_tezos/protocol.ml @@ -98,8 +98,6 @@ let protocol_dependent_uses ~tag ~path = let accuser = protocol_dependent_uses ~tag:"accuser_" ~path:"./octez-accuser-" -let baker = protocol_dependent_uses ~tag:"baker_" ~path:"./octez-baker-" - let encoding_prefix = function | Alpha -> "alpha" | p -> sf "%03d-%s" (number p) (String.sub (hash p) 0 8) diff --git a/tezt/lib_tezos/protocol.mli b/tezt/lib_tezos/protocol.mli index 7ef6f6a2a9b4..b29840cdea14 100644 --- a/tezt/lib_tezos/protocol.mli +++ b/tezt/lib_tezos/protocol.mli @@ -88,9 +88,6 @@ val parameter_file : ?constants:constants -> t -> string (** Get the path of the accuser of a protocol, such as ["./octez-accuser-alpha"]. *) val accuser : t -> Uses.t -(** Get the path of the baker of a protocol, such as ["./octez-baker-alpha"]. *) -val baker : t -> Uses.t - (** Get the part of the daemon name that is specific to a protocol (e.g. ["PtEdo2Zk"]). This should not be used for anything except to compute the name of executables. *) -- GitLab From 3816b603176c2b57f71ed63b06542ac7d14f330e Mon Sep 17 00:00:00 2001 From: Gabriel Moise Date: Tue, 8 Apr 2025 09:43:53 +0100 Subject: [PATCH 5/5] Tezt: Agnostic_baker: Add issue to TODO --- tezt/lib_tezos/constant.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tezt/lib_tezos/constant.ml b/tezt/lib_tezos/constant.ml index f864662c354b..33376eb36173 100644 --- a/tezt/lib_tezos/constant.ml +++ b/tezt/lib_tezos/constant.ml @@ -89,7 +89,7 @@ let _teztale_snitch = Uses.make ~tag:"teztale_snitch" ~path:"./octez-teztale-snitch" () (* TODO: Remove these once the binaries are completely removed from - [released-executables]. *) + [released-executables]. (issue : https://gitlab.com/tezos/tezos/-/issues/7763) *) let octez_baker_quebec = Uses.make ~tag:"baker_psquebec" ~path:"./octez-baker-PsQuebec" () -- GitLab