From 0c17075cbde26a44d6a7ea9a350de18ba451a678 Mon Sep 17 00:00:00 2001 From: Gabriel Moise Date: Mon, 17 Feb 2025 10:49:15 +0000 Subject: [PATCH 1/5] Agnostic_baker: Expose all functions from plugin --- manifest/product_octez.ml | 80 +++++++++++++------------- opam/octez-shell-libs.opam | 2 +- src/lib_validation/dune | 3 + src/lib_validation/protocol_plugin.ml | 10 ++++ src/lib_validation/protocol_plugin.mli | 10 ++++ 5 files changed, 65 insertions(+), 40 deletions(-) diff --git a/manifest/product_octez.ml b/manifest/product_octez.ml index 1423a8c7ac5b..b518cbda296e 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" diff --git a/opam/octez-shell-libs.opam b/opam/octez-shell-libs.opam index 8cd4d8fb885c..e3f8e49b9eb5 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/lib_validation/dune b/src/lib_validation/dune index 3cb171ad3d55..59aa640f8458 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 71bbcd6c3943..5a76a96cd84d 100644 --- a/src/lib_validation/protocol_plugin.ml +++ b/src/lib_validation/protocol_plugin.ml @@ -168,6 +168,16 @@ end module type AGNOSTIC_BAKER_PLUGIN = sig val hash : Protocol_hash.t + val register_commands : unit -> unit + + val select_commands : + 'a -> + 'b -> + (Tezos_client_base.Client_context.full Tezos_clic.command trace, 'c) result + Lwt.t + + val init_sapling_params : unit -> unit + val run_baker_binary : baker_args:string list -> cancel_promise:int Lwt.t -> diff --git a/src/lib_validation/protocol_plugin.mli b/src/lib_validation/protocol_plugin.mli index 213ef58277b5..39752427afe9 100644 --- a/src/lib_validation/protocol_plugin.mli +++ b/src/lib_validation/protocol_plugin.mli @@ -217,6 +217,16 @@ end module type AGNOSTIC_BAKER_PLUGIN = sig val hash : Protocol_hash.t + val register_commands : unit -> unit + + val select_commands : + 'a -> + 'b -> + (Tezos_client_base.Client_context.full Tezos_clic.command trace, 'c) result + Lwt.t + + val init_sapling_params : unit -> unit + val run_baker_binary : baker_args:string list -> cancel_promise:int Lwt.t -> -- GitLab From a8b8a4a7aed36dc57056216c6e4a755eee7bc6cb Mon Sep 17 00:00:00 2001 From: Gabriel Moise Date: Wed, 19 Feb 2025 23:36:47 +0000 Subject: [PATCH 2/5] Agnostic_baker: Move running function from plugin to agnostic baker --- src/bin_agnostic_baker/daemon.ml | 30 +++++++++++++++++-- src/lib_validation/protocol_plugin.ml | 8 ++--- src/lib_validation/protocol_plugin.mli | 8 ++--- .../agnostic_baker_plugin_registration.ml | 20 ++----------- .../agnostic_baker_plugin_registration.ml | 20 ++----------- .../agnostic_baker_plugin_registration.ml | 20 ++----------- 6 files changed, 38 insertions(+), 68 deletions(-) diff --git a/src/bin_agnostic_baker/daemon.ml b/src/bin_agnostic_baker/daemon.ml index d731b934192f..182babd1d7d5 100644 --- a/src/bin_agnostic_baker/daemon.ml +++ b/src/bin_agnostic_baker/daemon.ml @@ -18,6 +18,31 @@ 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 open Agnostic_baker_plugin in + register_commands () ; + init_sapling_params () ; + 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 +64,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/lib_validation/protocol_plugin.ml b/src/lib_validation/protocol_plugin.ml index 5a76a96cd84d..2c71d419b174 100644 --- a/src/lib_validation/protocol_plugin.ml +++ b/src/lib_validation/protocol_plugin.ml @@ -168,6 +168,8 @@ end module type AGNOSTIC_BAKER_PLUGIN = sig val hash : Protocol_hash.t + val name : string + val register_commands : unit -> unit val select_commands : @@ -177,12 +179,6 @@ module type AGNOSTIC_BAKER_PLUGIN = sig Lwt.t val init_sapling_params : unit -> unit - - val run_baker_binary : - baker_args:string list -> - cancel_promise:int Lwt.t -> - logs_path:string option -> - int Lwt.t 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 39752427afe9..c6bf560bb88e 100644 --- a/src/lib_validation/protocol_plugin.mli +++ b/src/lib_validation/protocol_plugin.mli @@ -217,6 +217,8 @@ end module type AGNOSTIC_BAKER_PLUGIN = sig val hash : Protocol_hash.t + val name : string + val register_commands : unit -> unit val select_commands : @@ -226,12 +228,6 @@ module type AGNOSTIC_BAKER_PLUGIN = sig Lwt.t val init_sapling_params : unit -> unit - - val run_baker_binary : - baker_args:string list -> - cancel_promise:int Lwt.t -> - logs_path:string option -> - int Lwt.t 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 2cda851a511f..335f66ad0ac1 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,6 +8,8 @@ module Agnostic_baker_plugin = struct let hash = Registerer.Registered.hash + let name = Protocol.name + let register_commands () = Client_commands.register Protocol.hash @@ fun _network -> List.map (Tezos_clic.map_command (new Protocol_client_context.wrap_full)) @@ -28,24 +30,6 @@ module Agnostic_baker_plugin = struct 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 2cda851a511f..335f66ad0ac1 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,6 +8,8 @@ module Agnostic_baker_plugin = struct let hash = Registerer.Registered.hash + let name = Protocol.name + let register_commands () = Client_commands.register Protocol.hash @@ fun _network -> List.map (Tezos_clic.map_command (new Protocol_client_context.wrap_full)) @@ -28,24 +30,6 @@ module Agnostic_baker_plugin = struct 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 2cda851a511f..335f66ad0ac1 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,6 +8,8 @@ module Agnostic_baker_plugin = struct let hash = Registerer.Registered.hash + let name = Protocol.name + let register_commands () = Client_commands.register Protocol.hash @@ fun _network -> List.map (Tezos_clic.map_command (new Protocol_client_context.wrap_full)) @@ -28,24 +30,6 @@ module Agnostic_baker_plugin = struct 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 () = -- GitLab From d0fce13560e90e5e0ff99b4245e3793b98b268a0 Mon Sep 17 00:00:00 2001 From: Gabriel Moise Date: Mon, 17 Feb 2025 10:56:07 +0000 Subject: [PATCH 3/5] Agnostic_baker: Move init_sapling function from plugin to agnostic baker --- src/bin_agnostic_baker/daemon.ml | 11 ++++++++++- src/lib_validation/protocol_plugin.ml | 2 -- src/lib_validation/protocol_plugin.mli | 2 -- .../agnostic_baker_plugin_registration.ml | 9 --------- .../agnostic_baker_plugin_registration.ml | 9 --------- .../agnostic_baker_plugin_registration.ml | 9 --------- 6 files changed, 10 insertions(+), 32 deletions(-) diff --git a/src/bin_agnostic_baker/daemon.ml b/src/bin_agnostic_baker/daemon.ml index 182babd1d7d5..9cb5357766ad 100644 --- a/src/bin_agnostic_baker/daemon.ml +++ b/src/bin_agnostic_baker/daemon.ml @@ -27,7 +27,16 @@ let run_thread ~baker_args ~cancel_promise ~logs_path = let open Agnostic_baker_plugin in register_commands () ; - init_sapling_params () ; + + (* 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 diff --git a/src/lib_validation/protocol_plugin.ml b/src/lib_validation/protocol_plugin.ml index 2c71d419b174..036292599304 100644 --- a/src/lib_validation/protocol_plugin.ml +++ b/src/lib_validation/protocol_plugin.ml @@ -177,8 +177,6 @@ module type AGNOSTIC_BAKER_PLUGIN = sig 'b -> (Tezos_client_base.Client_context.full Tezos_clic.command trace, 'c) result Lwt.t - - val init_sapling_params : unit -> unit 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 c6bf560bb88e..bd63680b9d98 100644 --- a/src/lib_validation/protocol_plugin.mli +++ b/src/lib_validation/protocol_plugin.mli @@ -226,8 +226,6 @@ module type AGNOSTIC_BAKER_PLUGIN = sig 'b -> (Tezos_client_base.Client_context.full Tezos_clic.command trace, 'c) result Lwt.t - - val init_sapling_params : unit -> unit 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 335f66ad0ac1..02c1668e2676 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 @@ -21,15 +21,6 @@ module Agnostic_baker_plugin = struct (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 () 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 335f66ad0ac1..02c1668e2676 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 @@ -21,15 +21,6 @@ module Agnostic_baker_plugin = struct (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 () 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 335f66ad0ac1..02c1668e2676 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 @@ -21,15 +21,6 @@ module Agnostic_baker_plugin = struct (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 () end let () = -- GitLab From 82cb1ee5f1e73a974ffd030080f46ff6d1808366 Mon Sep 17 00:00:00 2001 From: Gabriel Moise Date: Mon, 17 Feb 2025 10:58:33 +0000 Subject: [PATCH 4/5] Agnostic_baker_plugin: Refactor code in plugin --- .../agnostic_baker_plugin_registration.ml | 13 +++++-------- .../agnostic_baker_plugin_registration.ml | 13 +++++-------- .../agnostic_baker_plugin_registration.ml | 13 +++++-------- 3 files changed, 15 insertions(+), 24 deletions(-) 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 02c1668e2676..e9812583db16 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 @@ -10,17 +10,14 @@ module Agnostic_baker_plugin = struct let name = Protocol.name - let register_commands () = - Client_commands.register Protocol.hash @@ fun _network -> + 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 ())) + let register_commands () = + Client_commands.register Protocol.hash @@ fun _network -> map_commands () + + let select_commands _ _ = Lwt_result_syntax.return @@ map_commands () 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 02c1668e2676..e9812583db16 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 @@ -10,17 +10,14 @@ module Agnostic_baker_plugin = struct let name = Protocol.name - let register_commands () = - Client_commands.register Protocol.hash @@ fun _network -> + 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 ())) + let register_commands () = + Client_commands.register Protocol.hash @@ fun _network -> map_commands () + + let select_commands _ _ = Lwt_result_syntax.return @@ map_commands () 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 02c1668e2676..e9812583db16 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 @@ -10,17 +10,14 @@ module Agnostic_baker_plugin = struct let name = Protocol.name - let register_commands () = - Client_commands.register Protocol.hash @@ fun _network -> + 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 ())) + let register_commands () = + Client_commands.register Protocol.hash @@ fun _network -> map_commands () + + let select_commands _ _ = Lwt_result_syntax.return @@ map_commands () end let () = -- GitLab From 167a15d7f199cc63ac0d447d99c3286a3fbe00af Mon Sep 17 00:00:00 2001 From: Gabriel Moise Date: Wed, 19 Feb 2025 23:41:41 +0000 Subject: [PATCH 5/5] Agnostic_baker: Move register_commands and select_commands from plugin to agnostic baker --- manifest/product_octez.ml | 1 + src/bin_agnostic_baker/daemon.ml | 10 ++++++++-- src/bin_agnostic_baker/dune | 4 +++- src/lib_validation/protocol_plugin.ml | 9 ++------- src/lib_validation/protocol_plugin.mli | 9 ++------- .../agnostic_baker_plugin_registration.ml | 5 ----- .../agnostic_baker_plugin_registration.ml | 5 ----- .../agnostic_baker_plugin_registration.ml | 5 ----- 8 files changed, 16 insertions(+), 32 deletions(-) diff --git a/manifest/product_octez.ml b/manifest/product_octez.ml index b518cbda296e..eda14f92a142 100644 --- a/manifest/product_octez.ml +++ b/manifest/product_octez.ml @@ -8227,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/src/bin_agnostic_baker/daemon.ml b/src/bin_agnostic_baker/daemon.ml index 9cb5357766ad..539c896afa35 100644 --- a/src/bin_agnostic_baker/daemon.ml +++ b/src/bin_agnostic_baker/daemon.ml @@ -25,8 +25,14 @@ let shutdown baker = let run_thread (module Agnostic_baker_plugin : Protocol_plugin.AGNOSTIC_BAKER_PLUGIN) ~baker_args ~cancel_promise ~logs_path = - let open Agnostic_baker_plugin in - register_commands () ; + 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 diff --git a/src/bin_agnostic_baker/dune b/src/bin_agnostic_baker/dune index 35dcc526cb82..2a9f42a666f7 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/protocol_plugin.ml b/src/lib_validation/protocol_plugin.ml index 036292599304..07cdbd9b2b8d 100644 --- a/src/lib_validation/protocol_plugin.ml +++ b/src/lib_validation/protocol_plugin.ml @@ -170,13 +170,8 @@ module type AGNOSTIC_BAKER_PLUGIN = sig val name : string - val register_commands : unit -> unit - - val select_commands : - 'a -> - 'b -> - (Tezos_client_base.Client_context.full Tezos_clic.command trace, 'c) result - Lwt.t + 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 bd63680b9d98..b6d4bf61c5b6 100644 --- a/src/lib_validation/protocol_plugin.mli +++ b/src/lib_validation/protocol_plugin.mli @@ -219,13 +219,8 @@ module type AGNOSTIC_BAKER_PLUGIN = sig val name : string - val register_commands : unit -> unit - - val select_commands : - 'a -> - 'b -> - (Tezos_client_base.Client_context.full Tezos_clic.command trace, 'c) result - Lwt.t + 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 e9812583db16..147a175016a7 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 @@ -13,11 +13,6 @@ module Agnostic_baker_plugin = struct let map_commands () = List.map (Tezos_clic.map_command (new Protocol_client_context.wrap_full)) @@ Baking_commands.baker_commands () - - let register_commands () = - Client_commands.register Protocol.hash @@ fun _network -> map_commands () - - let select_commands _ _ = Lwt_result_syntax.return @@ map_commands () 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 e9812583db16..147a175016a7 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 @@ -13,11 +13,6 @@ module Agnostic_baker_plugin = struct let map_commands () = List.map (Tezos_clic.map_command (new Protocol_client_context.wrap_full)) @@ Baking_commands.baker_commands () - - let register_commands () = - Client_commands.register Protocol.hash @@ fun _network -> map_commands () - - let select_commands _ _ = Lwt_result_syntax.return @@ map_commands () 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 e9812583db16..147a175016a7 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 @@ -13,11 +13,6 @@ module Agnostic_baker_plugin = struct let map_commands () = List.map (Tezos_clic.map_command (new Protocol_client_context.wrap_full)) @@ Baking_commands.baker_commands () - - let register_commands () = - Client_commands.register Protocol.hash @@ fun _network -> map_commands () - - let select_commands _ _ = Lwt_result_syntax.return @@ map_commands () end let () = -- GitLab