From 66f242b0e1a223ebf2e2a9228b836205a638108d Mon Sep 17 00:00:00 2001 From: Gabriel Moise Date: Tue, 25 Mar 2025 12:08:48 +0000 Subject: [PATCH] Agnostic_baker: Fix manual command --- src/bin_agnostic_baker/main_agnostic_baker.ml | 5 +- src/lib_agnostic_baker/commands.ml | 55 ++++++++++++------- src/lib_agnostic_baker/commands.mli | 3 +- src/lib_agnostic_baker/daemon.ml | 2 +- 4 files changed, 40 insertions(+), 25 deletions(-) diff --git a/src/bin_agnostic_baker/main_agnostic_baker.ml b/src/bin_agnostic_baker/main_agnostic_baker.ml index 3cfa5ea7b1b6..88c054c752d6 100644 --- a/src/bin_agnostic_baker/main_agnostic_baker.ml +++ b/src/bin_agnostic_baker/main_agnostic_baker.ml @@ -9,7 +9,7 @@ (* Main entrypoint for the agnostic baker binary. We distinguish two cases: - 1. If the binary is called against a `--help` or `--version` command, then + 1. If the binary is called against a `--help`, `--version` or `man` command, then there is no reason to connect to a node, find the current protocol etc. 2. Otherwise, we run the agnostic baker daemon, which first obtains the current protocol from the connected node, and then it monitors the chain @@ -68,5 +68,6 @@ let () = if Run_args.(is_help_cmd args || is_version_cmd args || is_man_cmd args) then Client_main_run.run (module Daemon_config) - ~select_commands:(fun _ _ -> Lwt_result_syntax.return_nil) + ~select_commands:(fun _ _ -> + Lwt_result_syntax.return @@ Commands.baker_commands ()) else run ~args () diff --git a/src/lib_agnostic_baker/commands.ml b/src/lib_agnostic_baker/commands.ml index 2c8ca0c60bc6..71973ebb29a3 100644 --- a/src/lib_agnostic_baker/commands.ml +++ b/src/lib_agnostic_baker/commands.ml @@ -5,8 +5,31 @@ (* *) (*****************************************************************************) -let baker_commands (module Plugin : Protocol_plugin_sig.S) : - Tezos_client_base.Client_context.full Tezos_clic.command list = +let run_with_local_node (module Plugin : Protocol_plugin_sig.S) args + local_data_dir_path sources cctxt = + let baking_mode = Some local_data_dir_path in + let configuration = Configuration.create_config args in + Plugin.Baker_commands_helpers.run_baker + ~configuration + ~baking_mode + ~sources + ~cctxt + +let run_remotely (module Plugin : Protocol_plugin_sig.S) args sources cctxt = + let baking_mode = None in + let configuration = Configuration.create_config args in + Plugin.Baker_commands_helpers.run_baker + ~configuration + ~baking_mode + ~sources + ~cctxt + +let run_vdf (module Plugin : Protocol_plugin_sig.S) (pidfile, keep_alive) cctxt + = + Configuration.may_lock_pidfile pidfile @@ fun () -> + Plugin.Baker_commands_helpers.run_vdf_daemon ~cctxt ~keep_alive + +let baker_commands ?plugin () = let open Configuration in let open Tezos_clic in let group = @@ -26,33 +49,23 @@ let baker_commands (module Plugin : Protocol_plugin_sig.S) : ~desc:"Path to the node data directory (e.g. $HOME/.tezos-node)" directory_parameter @@ sources_param) - (fun args local_data_dir_path sources cctxt -> - let baking_mode = Some local_data_dir_path in - let configuration = create_config args in - Plugin.Baker_commands_helpers.run_baker - ~configuration - ~baking_mode - ~sources - ~cctxt); + (match plugin with + | Some plugin -> run_with_local_node plugin + | None -> fun _ _ _ _ -> Lwt_result_syntax.return_unit); command ~group ~desc:"Launch the baker daemon using RPCs only." baker_args (prefixes ["run"; "remotely"] @@ sources_param) - (fun args sources cctxt -> - let baking_mode = None in - let configuration = create_config args in - Plugin.Baker_commands_helpers.run_baker - ~configuration - ~baking_mode - ~sources - ~cctxt); + (match plugin with + | Some plugin -> run_remotely plugin + | None -> fun _ _ _ -> Lwt_result_syntax.return_unit); command ~group ~desc:"Launch the VDF daemon" (args2 pidfile_arg keep_alive_arg) (prefixes ["run"; "vdf"] @@ stop) - (fun (pidfile, keep_alive) cctxt -> - may_lock_pidfile pidfile @@ fun () -> - Plugin.Baker_commands_helpers.run_vdf_daemon ~cctxt ~keep_alive); + (match plugin with + | Some plugin -> run_vdf plugin + | None -> fun _ _ -> Lwt_result_syntax.return_unit); ] diff --git a/src/lib_agnostic_baker/commands.mli b/src/lib_agnostic_baker/commands.mli index cb8993868b91..c81df4040674 100644 --- a/src/lib_agnostic_baker/commands.mli +++ b/src/lib_agnostic_baker/commands.mli @@ -6,5 +6,6 @@ (*****************************************************************************) val baker_commands : - (module Protocol_plugin_sig.S) -> + ?plugin:(module Protocol_plugin_sig.S) -> + unit -> Tezos_client_base.Client_context.full Tezos_clic.command list diff --git a/src/lib_agnostic_baker/daemon.ml b/src/lib_agnostic_baker/daemon.ml index c44da0537add..0647353d0e05 100644 --- a/src/lib_agnostic_baker/daemon.ml +++ b/src/lib_agnostic_baker/daemon.ml @@ -73,7 +73,7 @@ let spawn_baker protocol_hash = protocol_hash [@profiler.record_f {verbosity = Notice} "proto_plugin_for_protocol"]) in - let baker_commands = Commands.baker_commands plugin in + let baker_commands = Commands.baker_commands ~plugin () in return @@ run_thread ~protocol_hash -- GitLab