From ff8c3bac509724ec2154bec6d37dc6d3f9cad417 Mon Sep 17 00:00:00 2001 From: Victor Allombert Date: Mon, 12 Aug 2024 09:49:49 +0200 Subject: [PATCH] Paris/bake: check node version --- .../lib_delegate/baking_commands.ml | 57 ++++++++++++++++++- .../lib_delegate/baking_errors.ml | 54 ++++++++++++++++++ .../lib_delegate/baking_events.ml | 39 +++++++++++++ 3 files changed, 149 insertions(+), 1 deletion(-) diff --git a/src/proto_020_PsParisC/lib_delegate/baking_commands.ml b/src/proto_020_PsParisC/lib_delegate/baking_commands.ml index f4707998fbd6..89dc129c8e83 100644 --- a/src/proto_020_PsParisC/lib_delegate/baking_commands.ml +++ b/src/proto_020_PsParisC/lib_delegate/baking_commands.ml @@ -25,6 +25,7 @@ open Client_proto_args open Baking_errors +module Events = Baking_events.Commands let pidfile_arg = let open Lwt_result_syntax in @@ -45,6 +46,49 @@ let may_lock_pidfile pidfile_opt f = ~filename:pidfile f +let check_node_version cctxt check_node_version_bypass = + let open Lwt_result_syntax in + if check_node_version_bypass then + let*! () = Events.(emit node_version_check_bypass ()) in + return_unit + else + let baker_version = Tezos_version_value.Current_git_info.octez_version in + let (baker_commit_info + : Tezos_version.Octez_node_version.commit_info option) = + Some + { + commit_hash = Tezos_version_value.Current_git_info.commit_hash; + commit_date = Tezos_version_value.Current_git_info.committer_date; + } + in + let* node_version = Version_services.version cctxt in + let*! () = + Events.( + emit + node_version_check + ( node_version.version, + node_version.commit_info, + baker_version, + baker_commit_info )) + in + match + Tezos_version.Octez_node_version.partially_compare + baker_version + baker_commit_info + node_version.version + node_version.commit_info + with + | Some r when r <= 0 -> return_unit + | _ -> + tzfail + (Node_version_incompatible + { + node_version = node_version.version; + node_commit_info = node_version.commit_info; + baker_version; + baker_commit_info; + }) + let http_headers_env_variable = "TEZOS_CLIENT_REMOTE_OPERATIONS_POOL_HTTP_HEADERS" @@ -198,6 +242,14 @@ let state_recorder_switch_arg = consensus state in the filesystem, otherwise just in memory." ()) +let node_version_check_bypass_arg = + Tezos_clic.switch + ~long:"node-version-check-bypass" + ~doc: + "If node-version-check-bypass flag is set, the baker will not check its \ + compatibility with the version of the node to which it is connected." + () + let get_delegates (cctxt : Protocol_client_context.full) (pkhs : Signature.public_key_hash list) = let open Lwt_result_syntax in @@ -583,8 +635,9 @@ let lookup_default_vote_file_path (cctxt : Protocol_client_context.full) = type baking_mode = Local of {local_data_dir_path : string} | Remote let baker_args = - Tezos_clic.args13 + Tezos_clic.args14 pidfile_arg + node_version_check_bypass_arg minimal_fees_arg minimal_nanotez_per_gas_unit_arg minimal_nanotez_per_byte_arg @@ -600,6 +653,7 @@ let baker_args = let run_baker ( pidfile, + check_node_version_bypass, minimal_fees, minimal_nanotez_per_gas_unit, minimal_nanotez_per_byte, @@ -614,6 +668,7 @@ let run_baker pre_emptive_forge_time ) baking_mode sources cctxt = let open Lwt_result_syntax in may_lock_pidfile pidfile @@ fun () -> + let* () = check_node_version cctxt check_node_version_bypass in let*! per_block_vote_file = if per_block_vote_file = None then (* If the votes file was not explicitly given, we diff --git a/src/proto_020_PsParisC/lib_delegate/baking_errors.ml b/src/proto_020_PsParisC/lib_delegate/baking_errors.ml index 537462a771e3..54f2ddb40e19 100644 --- a/src/proto_020_PsParisC/lib_delegate/baking_errors.ml +++ b/src/proto_020_PsParisC/lib_delegate/baking_errors.ml @@ -25,6 +25,14 @@ type error += Node_connection_lost +type error += + | Node_version_incompatible of { + node_version : Tezos_version_parser.t; + node_commit_info : Tezos_version.Octez_node_version.commit_info option; + baker_version : Tezos_version_parser.t; + baker_commit_info : Tezos_version.Octez_node_version.commit_info option; + } + type error += Cannot_load_local_file of string type error += Broken_locked_values_invariant @@ -51,6 +59,52 @@ let () = Data_encoding.empty (function Node_connection_lost -> Some () | _ -> None) (fun () -> Node_connection_lost) ; + register_error_kind + `Temporary + ~id:"Baking_commands.node_version_incompatible" + ~title:"Node version is incompatible" + ~description:"The node version is incompatible with this baker" + ~pp:(fun fmt + ((node_version, node_commit_info, baker_version, baker_commit_info) : + Tezos_version_parser.t + * Tezos_version.Octez_node_version.commit_info option + * Tezos_version_parser.t + * Tezos_version.Octez_node_version.commit_info option) -> + Format.fprintf + fmt + "@[Node version is %a (%a) but it is expected to be more recent than \ + %a (%a).@ This check can be bypassed at your own risk with the flag \ + --node-version-check-bypass.@]" + Tezos_version.Version.pp_simple + node_version + (Format.pp_print_option + ~none:(fun ppf () -> Format.pp_print_string ppf "none") + Tezos_version.Octez_node_version.commit_info_pp_short) + node_commit_info + Tezos_version.Version.pp_simple + baker_version + (Format.pp_print_option + ~none:(fun ppf () -> Format.pp_print_string ppf "none") + Tezos_version.Octez_node_version.commit_info_pp_short) + baker_commit_info) + Data_encoding.( + obj4 + (req "node_version" Tezos_version.Octez_node_version.version_encoding) + (opt + "node_commit_info" + Tezos_version.Octez_node_version.commit_info_encoding) + (req "baker_version" Tezos_version.Octez_node_version.version_encoding) + (opt + "baker_commit_info" + Tezos_version.Octez_node_version.commit_info_encoding)) + (function + | Node_version_incompatible + {node_version; node_commit_info; baker_version; baker_commit_info} -> + Some (node_version, node_commit_info, baker_version, baker_commit_info) + | _ -> None) + (fun (node_version, node_commit_info, baker_version, baker_commit_info) -> + Node_version_incompatible + {node_version; node_commit_info; baker_version; baker_commit_info}) ; register_error_kind `Temporary ~id:"Baking_scheduling.cannot_load_local_file" diff --git a/src/proto_020_PsParisC/lib_delegate/baking_events.ml b/src/proto_020_PsParisC/lib_delegate/baking_events.ml index 8d462de00fec..9b629607e8b2 100644 --- a/src/proto_020_PsParisC/lib_delegate/baking_events.ml +++ b/src/proto_020_PsParisC/lib_delegate/baking_events.ml @@ -34,6 +34,45 @@ let pp_int64 fmt n = Format.fprintf fmt "%Ld" n let waiting_color = Internal_event.Magenta +module Commands = struct + include Internal_event.Simple + + let section = section @ ["commands"] + + let node_version_check_bypass = + declare_0 + ~section + ~name:"node_version_check_bypass" + ~level:Warning + ~msg:"Compatibility between node version and baker version by passed" + () + + let node_version_check = + declare_4 + ~section + ~name:"node_version_check" + ~level:Debug + ~msg: + "Checking compatibility between node version {node_version} \ + ({node_commit}) and baker version {baker_version} ({baker_commit})" + ~pp1:Tezos_version.Version.pp_simple + ("node_version", Tezos_version.Octez_node_version.version_encoding) + ~pp2: + (Format.pp_print_option + Tezos_version.Octez_node_version.commit_info_pp_short) + ( "node_commit", + Data_encoding.option + Tezos_version.Octez_node_version.commit_info_encoding ) + ~pp3:Tezos_version.Version.pp_simple + ("baker_version", Tezos_version.Octez_node_version.version_encoding) + ~pp4: + (Format.pp_print_option + Tezos_version.Octez_node_version.commit_info_pp_short) + ( "baker_commit", + Data_encoding.option + Tezos_version.Octez_node_version.commit_info_encoding ) +end + module State_transitions = struct include Internal_event.Simple -- GitLab