diff --git a/src/bin_agnostic_baker/main_agnostic_baker.ml b/src/bin_agnostic_baker/main_agnostic_baker.ml index 3cfa5ea7b1b677dd836b1556c35a699c462f2b9d..88c054c752d62e8b6ccac7044fd9eb8896c997df 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 2c8ca0c60bc6471d0a29a220a134b73d6071967c..71973ebb29a373c5511608f91b5b34a31e9c6106 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 cb8993868b919ef77e75147585463cfd537aeb5b..c81df40406745ef99039e5d478ef56d9b9608445 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 c44da0537addb63101368757ce8af0618bc96c4d..0647353d0e051569dba6782fde78016ef23f233c 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