diff --git a/src/lib_agnostic_baker/commands.ml b/src/lib_agnostic_baker/commands.ml index 71973ebb29a373c5511608f91b5b34a31e9c6106..3a5d1ccca9c7a53d711aa243fa876ccff9a670cd 100644 --- a/src/lib_agnostic_baker/commands.ml +++ b/src/lib_agnostic_baker/commands.ml @@ -29,6 +29,11 @@ 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 run_accuser (module Plugin : Protocol_plugin_sig.S) + (pidfile, preserved_levels, keep_alive) cctxt = + Configuration.may_lock_pidfile pidfile @@ fun () -> + Plugin.Accuser_commands_helpers.run ~cctxt ~preserved_levels ~keep_alive + let baker_commands ?plugin () = let open Configuration in let open Tezos_clic in @@ -68,4 +73,12 @@ let baker_commands ?plugin () = (match plugin with | Some plugin -> run_vdf plugin | None -> fun _ _ -> Lwt_result_syntax.return_unit); + command + ~group + ~desc:"Launch the accuser daemon" + (args3 pidfile_arg preserved_levels_arg keep_alive_arg) + (prefixes ["run"; "accuser"] @@ stop) + (match plugin with + | Some plugin -> run_accuser plugin + | None -> fun _ _ -> Lwt_result_syntax.return_unit); ] diff --git a/src/lib_agnostic_baker/configuration.ml b/src/lib_agnostic_baker/configuration.ml index b627e9a1c31127cda49e33c1949c4c3adaffeb3e..d0a9667f630d921342666718297c77d2a3cb6890 100644 --- a/src/lib_agnostic_baker/configuration.ml +++ b/src/lib_agnostic_baker/configuration.ml @@ -13,6 +13,8 @@ type error += Block_vote_file_not_found of string type error += Bad_minimal_fees of string +type error += Bad_preserved_levels of string + let () = register_error_kind `Permanent @@ -41,7 +43,21 @@ let () = Format.fprintf ppf "invalid minimal fees '%s'" literal) Data_encoding.(obj1 (req "parameter" string)) (function Bad_minimal_fees parameter -> Some parameter | _ -> None) - (fun parameter -> Bad_minimal_fees parameter) + (fun parameter -> Bad_minimal_fees parameter) ; + register_error_kind + `Permanent + ~id:"badPreservedLevelsArg" + ~title:"Bad -preserved-levels arg" + ~description:"invalid number of levels in -preserved-levels" + ~pp:(fun ppf literal -> + Format.fprintf + ppf + "Bad argument value for -preserved_levels. Expected a positive \ + integer, but given '%s'" + literal) + Data_encoding.(obj1 (req "parameter" string)) + (function Bad_preserved_levels parameter -> Some parameter | _ -> None) + (fun parameter -> Bad_preserved_levels parameter) (* Primitive argument parsers *) let string_parameter = @@ -365,6 +381,21 @@ let sources_param = "name of the delegate owning the attestation/baking right or name of \ the consensus key signing on the delegate's behalf") +let preserved_levels_arg = + let open Lwt_result_syntax in + Tezos_clic.default_arg + ~long:"preserved-levels" + ~placeholder:"threshold" + ~doc:"Number of effective levels kept in the accuser's memory" + ~default:"200" + (Tezos_clic.parameter + (fun (_cctxt : Tezos_client_base.Client_context.full) s -> + try + let preserved_levels = int_of_string s in + if preserved_levels < 0 then tzfail (Bad_preserved_levels s) + else return preserved_levels + with _ -> tzfail (Bad_preserved_levels s))) + type t = { pidfile : string option; node_version_check_bypass : bool; diff --git a/src/lib_agnostic_baker/configuration.mli b/src/lib_agnostic_baker/configuration.mli index 92edf903dab0e7b560a55cb5611817bd15f8eabc..32e77234a5bd974f93f6c6ac84048b062fd8e8ab 100644 --- a/src/lib_agnostic_baker/configuration.mli +++ b/src/lib_agnostic_baker/configuration.mli @@ -51,6 +51,9 @@ val sources_param : Tezos_client_base.Client_context.full ) Tezos_clic.params +val preserved_levels_arg : + (int, Tezos_client_base.Client_context.full) Tezos_clic.arg + type t = { pidfile : string option; node_version_check_bypass : bool; diff --git a/src/lib_agnostic_baker/protocol_plugin_sig.ml b/src/lib_agnostic_baker/protocol_plugin_sig.ml index a2f73794b821ed9a2de82e73ccfa6a7004bb4c29..16c276e168b6dd9a0853f197bfa61647e8774970 100644 --- a/src/lib_agnostic_baker/protocol_plugin_sig.ml +++ b/src/lib_agnostic_baker/protocol_plugin_sig.ml @@ -28,8 +28,20 @@ module type BAKER_COMMANDS_HELPERS = sig unit tzresult Lwt.t end +module type ACCUSER_COMMANDS_HELPERS = sig + (** [run ~cctxt ~preserved_levels ~keep_alive] is the main running function signature + that all protocol plugins will implement for the accuser. *) + val run : + cctxt:Tezos_client_base.Client_context.full -> + preserved_levels:int -> + keep_alive:bool -> + unit tzresult Lwt.t +end + module type S = sig val protocol_hash : Protocol_hash.t module Baker_commands_helpers : BAKER_COMMANDS_HELPERS + + module Accuser_commands_helpers : ACCUSER_COMMANDS_HELPERS end diff --git a/src/proto_021_PsQuebec/lib_agnostic_baker/accuser_commands_helpers.ml b/src/proto_021_PsQuebec/lib_agnostic_baker/accuser_commands_helpers.ml new file mode 100644 index 0000000000000000000000000000000000000000..7952ede35851e532551f9b1635559703197a8c4c --- /dev/null +++ b/src/proto_021_PsQuebec/lib_agnostic_baker/accuser_commands_helpers.ml @@ -0,0 +1,14 @@ +(*****************************************************************************) +(* *) +(* SPDX-License-Identifier: MIT *) +(* Copyright (c) 2025 Trilitech *) +(* *) +(*****************************************************************************) + +let run ~cctxt ~preserved_levels ~keep_alive = + let cctxt = new Protocol_client_context.wrap_full cctxt in + Client_daemon.Accuser.run + cctxt + ~chain:cctxt#chain + ~preserved_levels + ~keep_alive diff --git a/src/proto_021_PsQuebec/lib_agnostic_baker/agnostic_baker_plugin.ml b/src/proto_021_PsQuebec/lib_agnostic_baker/agnostic_baker_plugin.ml index fcc9eb4a3be99bdaafcd7f892524257e01fb6072..9d6200f8d096fe5bfeb09403f54cee5af43ada68 100644 --- a/src/proto_021_PsQuebec/lib_agnostic_baker/agnostic_baker_plugin.ml +++ b/src/proto_021_PsQuebec/lib_agnostic_baker/agnostic_baker_plugin.ml @@ -9,6 +9,7 @@ module Plugin : Protocol_plugin_sig.S = struct let protocol_hash = Protocol.hash module Baker_commands_helpers = Baker_commands_helpers + module Accuser_commands_helpers = Accuser_commands_helpers end let () = Protocol_plugins.register (module Plugin) diff --git a/src/proto_022_PsRiotum/lib_agnostic_baker/accuser_commands_helpers.ml b/src/proto_022_PsRiotum/lib_agnostic_baker/accuser_commands_helpers.ml new file mode 100644 index 0000000000000000000000000000000000000000..7952ede35851e532551f9b1635559703197a8c4c --- /dev/null +++ b/src/proto_022_PsRiotum/lib_agnostic_baker/accuser_commands_helpers.ml @@ -0,0 +1,14 @@ +(*****************************************************************************) +(* *) +(* SPDX-License-Identifier: MIT *) +(* Copyright (c) 2025 Trilitech *) +(* *) +(*****************************************************************************) + +let run ~cctxt ~preserved_levels ~keep_alive = + let cctxt = new Protocol_client_context.wrap_full cctxt in + Client_daemon.Accuser.run + cctxt + ~chain:cctxt#chain + ~preserved_levels + ~keep_alive diff --git a/src/proto_022_PsRiotum/lib_agnostic_baker/agnostic_baker_plugin.ml b/src/proto_022_PsRiotum/lib_agnostic_baker/agnostic_baker_plugin.ml index fcc9eb4a3be99bdaafcd7f892524257e01fb6072..9d6200f8d096fe5bfeb09403f54cee5af43ada68 100644 --- a/src/proto_022_PsRiotum/lib_agnostic_baker/agnostic_baker_plugin.ml +++ b/src/proto_022_PsRiotum/lib_agnostic_baker/agnostic_baker_plugin.ml @@ -9,6 +9,7 @@ module Plugin : Protocol_plugin_sig.S = struct let protocol_hash = Protocol.hash module Baker_commands_helpers = Baker_commands_helpers + module Accuser_commands_helpers = Accuser_commands_helpers end let () = Protocol_plugins.register (module Plugin) diff --git a/src/proto_alpha/lib_agnostic_baker/accuser_commands_helpers.ml b/src/proto_alpha/lib_agnostic_baker/accuser_commands_helpers.ml new file mode 100644 index 0000000000000000000000000000000000000000..7952ede35851e532551f9b1635559703197a8c4c --- /dev/null +++ b/src/proto_alpha/lib_agnostic_baker/accuser_commands_helpers.ml @@ -0,0 +1,14 @@ +(*****************************************************************************) +(* *) +(* SPDX-License-Identifier: MIT *) +(* Copyright (c) 2025 Trilitech *) +(* *) +(*****************************************************************************) + +let run ~cctxt ~preserved_levels ~keep_alive = + let cctxt = new Protocol_client_context.wrap_full cctxt in + Client_daemon.Accuser.run + cctxt + ~chain:cctxt#chain + ~preserved_levels + ~keep_alive diff --git a/src/proto_alpha/lib_agnostic_baker/agnostic_baker_plugin.ml b/src/proto_alpha/lib_agnostic_baker/agnostic_baker_plugin.ml index fcc9eb4a3be99bdaafcd7f892524257e01fb6072..9d6200f8d096fe5bfeb09403f54cee5af43ada68 100644 --- a/src/proto_alpha/lib_agnostic_baker/agnostic_baker_plugin.ml +++ b/src/proto_alpha/lib_agnostic_baker/agnostic_baker_plugin.ml @@ -9,6 +9,7 @@ module Plugin : Protocol_plugin_sig.S = struct let protocol_hash = Protocol.hash module Baker_commands_helpers = Baker_commands_helpers + module Accuser_commands_helpers = Accuser_commands_helpers end let () = Protocol_plugins.register (module Plugin) diff --git a/tezt/tests/expected/agnostic_baker_test.ml/Agnostic baker man.out b/tezt/tests/expected/agnostic_baker_test.ml/Agnostic baker man.out index 894cab99c974a0a82027b60e24482dff2023c124..9222451f555a19e25fa8ec8beaf1cbf8feeef562 100644 --- a/tezt/tests/expected/agnostic_baker_test.ml/Agnostic baker man.out +++ b/tezt/tests/expected/agnostic_baker_test.ml/Agnostic baker man.out @@ -185,6 +185,9 @@ Commands related to the agnostic baker daemon.: run vdf Launch the VDF daemon + + run accuser + Launch the accuser daemon Miscellaneous commands: