diff --git a/manifest/product_octez.ml b/manifest/product_octez.ml index 1423a8c7ac5b54d72426fe801ce10f052626003c..eda14f92a14269e8d1543c215849902b259f4ae2 100644 --- a/manifest/product_octez.ml +++ b/manifest/product_octez.ml @@ -3714,6 +3714,45 @@ let octez_protocol_updater = dynlink; ] +let octez_client_base = + octez_shell_lib + "client-base" + ~internal_name:"tezos_client_base" + ~path:"src/lib_client_base" + ~synopsis:"Tezos: common helpers for `octez-client`" + ~deps: + [ + octez_base |> open_ ~m:"TzPervasives"; + octez_clic; + octez_rpc; + octez_shell_services |> open_; + octez_sapling; + uri; + ] + ~modules:[":standard"; "bip39_english"] + ~linkall:true + ~dune: + Dune. + [ + targets_rule + ["bip39_english.ml"] + ~deps: + [ + [S ":exe"; S "gen/bip39_generator.exe"]; + S "gen/bip39_english.txt"; + ] + ~action:[S "run"; S "%{exe}"; S "%{targets}"]; + ] + +let _octez_client_base_tests = + tezt + ["bip39_tests"; "pbkdf_tests"] + ~path:"src/lib_client_base/test" + ~opam:"octez-shell-libs" + ~with_macos_security_framework:true + ~deps: + [octez_rustzcash_deps; octez_base; octez_client_base |> open_; alcotezt] + let octez_validation = let (PPX {preprocess; preprocessor_deps}) = ppx_profiler in octez_shell_lib @@ -3727,8 +3766,10 @@ let octez_validation = ~deps: [ octez_base |> open_ ~m:"TzPervasives"; + octez_client_base |> open_; octez_crypto |> open_; octez_rpc; + octez_clic; octez_context_ops |> open_; octez_shell_services |> open_; octez_protocol_updater |> open_; @@ -4053,45 +4094,6 @@ let _octez_rpc_http_server_tests = alcotezt; ] -let octez_client_base = - octez_shell_lib - "client-base" - ~internal_name:"tezos_client_base" - ~path:"src/lib_client_base" - ~synopsis:"Tezos: common helpers for `octez-client`" - ~deps: - [ - octez_base |> open_ ~m:"TzPervasives"; - octez_clic; - octez_rpc; - octez_shell_services |> open_; - octez_sapling; - uri; - ] - ~modules:[":standard"; "bip39_english"] - ~linkall:true - ~dune: - Dune. - [ - targets_rule - ["bip39_english.ml"] - ~deps: - [ - [S ":exe"; S "gen/bip39_generator.exe"]; - S "gen/bip39_english.txt"; - ] - ~action:[S "run"; S "%{exe}"; S "%{targets}"]; - ] - -let _octez_client_base_tests = - tezt - ["bip39_tests"; "pbkdf_tests"] - ~path:"src/lib_client_base/test" - ~opam:"octez-shell-libs" - ~with_macos_security_framework:true - ~deps: - [octez_rustzcash_deps; octez_base; octez_client_base |> open_; alcotezt] - let _bip39_generator = private_exe "bip39_generator" @@ -8225,6 +8227,7 @@ let _octez_experimental_agnostic_baker = octez_validation |> open_; octez_client_base_unix |> open_; octez_node_config; + octez_client_commands |> open_; ] @ protocol_deps) ~linkall:true diff --git a/opam/octez-shell-libs.opam b/opam/octez-shell-libs.opam index 8cd4d8fb885c65949c16823cd71ae33b65977512..e3f8e49b9eb51158573a074a5499862dd1f4a5f3 100644 --- a/opam/octez-shell-libs.opam +++ b/opam/octez-shell-libs.opam @@ -23,6 +23,7 @@ depends: [ "octez-proto-libs" { = version } "octez-protocol-compiler" { = version } "lwt-exit" + "uri" { >= "3.1.0" } "octez-version" { = version } "aches-lwt" { >= "1.1.0" } "index" { >= "1.6.0" & < "1.7.0" } @@ -31,7 +32,6 @@ depends: [ "tar-unix" { >= "2.0.1" & < "3.0.0" } "ppx_expect" "octez-rustzcash-deps" { with-test & = version } - "uri" { >= "3.1.0" } "ocplib-endian" "fmt" { >= "0.8.7" } "tezos-benchmark" { = version } diff --git a/src/bin_agnostic_baker/daemon.ml b/src/bin_agnostic_baker/daemon.ml index d731b934192fdec1f4e8f536e7e696b1eeff2658..539c896afa35a7339eaf48ca898a8d319db0098b 100644 --- a/src/bin_agnostic_baker/daemon.ml +++ b/src/bin_agnostic_baker/daemon.ml @@ -18,6 +18,46 @@ let shutdown baker = Lwt.wakeup baker.process.canceller 0 ; return_unit +(** [run_thread plugin ~baker_args ~cancel_promise ~logs_path] returns the main + running thread for the baker given its corresponding [plugin], with the command + line arguments given by [~baker_args] and cancellation Lwt promise + [~cancel_promise]. The event logs are stored according to [~logs_path]. *) +let run_thread + (module Agnostic_baker_plugin : Protocol_plugin.AGNOSTIC_BAKER_PLUGIN) + ~baker_args ~cancel_promise ~logs_path = + let () = + Client_commands.register Agnostic_baker_plugin.hash @@ fun _network -> + Agnostic_baker_plugin.map_commands () + in + + let select_commands _ _ = + Lwt_result_syntax.return @@ Agnostic_baker_plugin.map_commands () + in + + (* This call is not strictly necessary as the parameters are initialized + lazily the first time a Sapling operation (validation or forging) is + done. This is what the client does. + For a long running binary however it is important to make sure that the + parameters files are there at the start and avoid failing much later while + validating an operation. Plus paying this cost upfront means that the first + validation will not be more expensive. *) + let () = Tezos_sapling.Core.Validator.init_params () in + + let module Config = struct + include Daemon_config + + let default_daily_logs_path = logs_path + end in + Lwt.pick + [ + Client_main_run.lwt_run + (module Config) + ~select_commands + ~cmd_args:baker_args + (); + cancel_promise; + ] + (** [spawn_baker protocol_hash ~baker_args] spawns a baker for the given [protocol_hash] with [~baker_args] as command line arguments. *) let spawn_baker protocol_hash ~baker_args = @@ -39,12 +79,13 @@ let spawn_baker protocol_hash ~baker_args = let cancel_promise, canceller = Lwt.wait () in let* thread = match Protocol_plugin.find_agnostic_baker_plugin protocol_hash with - | Some (module Agnostic_baker_plugin) -> + | Some plugin -> (* The internal event logging needs to be closed, because another one will be initialised in the [run_baker_binary]. *) let*! () = Tezos_base_unix.Internal_event_unix.close () in return - @@ Agnostic_baker_plugin.run_baker_binary + @@ run_thread + plugin ~baker_args ~cancel_promise ~logs_path:Parameters.default_daily_logs_path diff --git a/src/bin_agnostic_baker/dune b/src/bin_agnostic_baker/dune index 35dcc526cb82069745e180d87719e0781e7d878a..2a9f42a666f7bb9e29da6d3e63e1220a5e63597d 100644 --- a/src/bin_agnostic_baker/dune +++ b/src/bin_agnostic_baker/dune @@ -15,6 +15,7 @@ octez-shell-libs.validation octez-shell-libs.client-base-unix octez-node-config + octez-shell-libs.client-commands octez-protocol-021-PsQuebec-libs.agnostic-baker octez-protocol-022-PsRiotum-libs.agnostic-baker (select void_for_linking-octez-protocol-alpha-libs-agnostic-baker from @@ -32,7 +33,8 @@ -open Tezos_base -open Tezos_base_unix -open Tezos_validation - -open Tezos_client_base_unix)) + -open Tezos_client_base_unix + -open Tezos_client_commands)) (rule (action diff --git a/src/lib_validation/dune b/src/lib_validation/dune index 3cb171ad3d55a43a4820cf8135818fe05b3df437..59aa640f845824eca0afcca4504027d5c26f44b3 100644 --- a/src/lib_validation/dune +++ b/src/lib_validation/dune @@ -8,8 +8,10 @@ (instrumentation (backend tezos-time-measurement)) (libraries octez-libs.base + octez-shell-libs.client-base octez-libs.crypto octez-libs.rpc + octez-libs.clic octez-shell-libs.context-ops octez-shell-libs.shell-services octez-shell-libs.protocol-updater @@ -22,6 +24,7 @@ (flags (:standard) -open Tezos_base.TzPervasives + -open Tezos_client_base -open Tezos_crypto -open Tezos_context_ops -open Tezos_shell_services diff --git a/src/lib_validation/protocol_plugin.ml b/src/lib_validation/protocol_plugin.ml index 71bbcd6c394347d44c90a9014218689e7d84640f..07cdbd9b2b8d3329326187ca58c7280915507440 100644 --- a/src/lib_validation/protocol_plugin.ml +++ b/src/lib_validation/protocol_plugin.ml @@ -168,11 +168,10 @@ end module type AGNOSTIC_BAKER_PLUGIN = sig val hash : Protocol_hash.t - val run_baker_binary : - baker_args:string list -> - cancel_promise:int Lwt.t -> - logs_path:string option -> - int Lwt.t + val name : string + + val map_commands : + unit -> Tezos_client_base.Client_context.full Tezos_clic.command list end let rpc_table : (module RPC) Protocol_hash.Table.t = diff --git a/src/lib_validation/protocol_plugin.mli b/src/lib_validation/protocol_plugin.mli index 213ef58277b570141d6909e5b9ad2d7bc1f5487f..b6d4bf61c5b6053e79051a7021a1e520d9bc5eff 100644 --- a/src/lib_validation/protocol_plugin.mli +++ b/src/lib_validation/protocol_plugin.mli @@ -217,11 +217,10 @@ end module type AGNOSTIC_BAKER_PLUGIN = sig val hash : Protocol_hash.t - val run_baker_binary : - baker_args:string list -> - cancel_promise:int Lwt.t -> - logs_path:string option -> - int Lwt.t + val name : string + + val map_commands : + unit -> Tezos_client_base.Client_context.full Tezos_clic.command list end (** Register a validation plugin for a specific protocol diff --git a/src/proto_021_PsQuebec/lib_agnostic_baker/agnostic_baker_plugin_registration.ml b/src/proto_021_PsQuebec/lib_agnostic_baker/agnostic_baker_plugin_registration.ml index 2cda851a511ff4b6c65e0a5af14f608d727740c5..147a175016a76c883c75670ead64bb530deda189 100644 --- a/src/proto_021_PsQuebec/lib_agnostic_baker/agnostic_baker_plugin_registration.ml +++ b/src/proto_021_PsQuebec/lib_agnostic_baker/agnostic_baker_plugin_registration.ml @@ -8,44 +8,11 @@ module Agnostic_baker_plugin = struct let hash = Registerer.Registered.hash - let register_commands () = - Client_commands.register Protocol.hash @@ fun _network -> + let name = Protocol.name + + let map_commands () = List.map (Tezos_clic.map_command (new Protocol_client_context.wrap_full)) @@ Baking_commands.baker_commands () - - let select_commands _ _ = - let open Lwt_result_syntax in - return - (List.map - (Tezos_clic.map_command (new Protocol_client_context.wrap_full)) - (Baking_commands.baker_commands ())) - - (* This call is not strictly necessary as the parameters are initialized - lazily the first time a Sapling operation (validation or forging) is - done. This is what the client does. - For a long running binary however it is important to make sure that the - parameters files are there at the start and avoid failing much later while - validating an operation. Plus paying this cost upfront means that the first - validation will not be more expensive. *) - let init_sapling_params () = Tezos_sapling.Core.Validator.init_params () - - let run_baker_binary ~baker_args ~cancel_promise ~logs_path = - let module Config = struct - include Daemon_config - - let default_daily_logs_path = logs_path - end in - register_commands () ; - init_sapling_params () ; - Lwt.pick - [ - Client_main_run.lwt_run - (module Config) - ~select_commands - ~cmd_args:baker_args - (); - cancel_promise; - ] end let () = diff --git a/src/proto_022_PsRiotum/lib_agnostic_baker/agnostic_baker_plugin_registration.ml b/src/proto_022_PsRiotum/lib_agnostic_baker/agnostic_baker_plugin_registration.ml index 2cda851a511ff4b6c65e0a5af14f608d727740c5..147a175016a76c883c75670ead64bb530deda189 100644 --- a/src/proto_022_PsRiotum/lib_agnostic_baker/agnostic_baker_plugin_registration.ml +++ b/src/proto_022_PsRiotum/lib_agnostic_baker/agnostic_baker_plugin_registration.ml @@ -8,44 +8,11 @@ module Agnostic_baker_plugin = struct let hash = Registerer.Registered.hash - let register_commands () = - Client_commands.register Protocol.hash @@ fun _network -> + let name = Protocol.name + + let map_commands () = List.map (Tezos_clic.map_command (new Protocol_client_context.wrap_full)) @@ Baking_commands.baker_commands () - - let select_commands _ _ = - let open Lwt_result_syntax in - return - (List.map - (Tezos_clic.map_command (new Protocol_client_context.wrap_full)) - (Baking_commands.baker_commands ())) - - (* This call is not strictly necessary as the parameters are initialized - lazily the first time a Sapling operation (validation or forging) is - done. This is what the client does. - For a long running binary however it is important to make sure that the - parameters files are there at the start and avoid failing much later while - validating an operation. Plus paying this cost upfront means that the first - validation will not be more expensive. *) - let init_sapling_params () = Tezos_sapling.Core.Validator.init_params () - - let run_baker_binary ~baker_args ~cancel_promise ~logs_path = - let module Config = struct - include Daemon_config - - let default_daily_logs_path = logs_path - end in - register_commands () ; - init_sapling_params () ; - Lwt.pick - [ - Client_main_run.lwt_run - (module Config) - ~select_commands - ~cmd_args:baker_args - (); - cancel_promise; - ] end let () = diff --git a/src/proto_alpha/lib_agnostic_baker/agnostic_baker_plugin_registration.ml b/src/proto_alpha/lib_agnostic_baker/agnostic_baker_plugin_registration.ml index 2cda851a511ff4b6c65e0a5af14f608d727740c5..147a175016a76c883c75670ead64bb530deda189 100644 --- a/src/proto_alpha/lib_agnostic_baker/agnostic_baker_plugin_registration.ml +++ b/src/proto_alpha/lib_agnostic_baker/agnostic_baker_plugin_registration.ml @@ -8,44 +8,11 @@ module Agnostic_baker_plugin = struct let hash = Registerer.Registered.hash - let register_commands () = - Client_commands.register Protocol.hash @@ fun _network -> + let name = Protocol.name + + let map_commands () = List.map (Tezos_clic.map_command (new Protocol_client_context.wrap_full)) @@ Baking_commands.baker_commands () - - let select_commands _ _ = - let open Lwt_result_syntax in - return - (List.map - (Tezos_clic.map_command (new Protocol_client_context.wrap_full)) - (Baking_commands.baker_commands ())) - - (* This call is not strictly necessary as the parameters are initialized - lazily the first time a Sapling operation (validation or forging) is - done. This is what the client does. - For a long running binary however it is important to make sure that the - parameters files are there at the start and avoid failing much later while - validating an operation. Plus paying this cost upfront means that the first - validation will not be more expensive. *) - let init_sapling_params () = Tezos_sapling.Core.Validator.init_params () - - let run_baker_binary ~baker_args ~cancel_promise ~logs_path = - let module Config = struct - include Daemon_config - - let default_daily_logs_path = logs_path - end in - register_commands () ; - init_sapling_params () ; - Lwt.pick - [ - Client_main_run.lwt_run - (module Config) - ~select_commands - ~cmd_args:baker_args - (); - cancel_promise; - ] end let () =