From 0b81d396d2fec2169c6f08b88fc4454e4b5bd62a Mon Sep 17 00:00:00 2001 From: Gabriel Moise Date: Wed, 26 Mar 2025 11:17:45 +0000 Subject: [PATCH 01/20] Agnostic_baker: Refactor parameters module --- scripts/proto_manager.sh | 5 +- src/lib_agnostic_baker/daemon.ml | 8 +-- src/lib_agnostic_baker/parameters.ml | 90 +++++++++++++++------------ src/lib_agnostic_baker/parameters.mli | 16 +++-- 4 files changed, 64 insertions(+), 55 deletions(-) diff --git a/scripts/proto_manager.sh b/scripts/proto_manager.sh index 0d150b3a9a03..02bc2731e519 100755 --- a/scripts/proto_manager.sh +++ b/scripts/proto_manager.sh @@ -779,9 +779,8 @@ function copy_source() { ## update agnostic_baker ## add protocol as active before alpha in parameters.ml if ! grep -q "${long_hash}" src/lib_agnostic_baker/parameters.ml; then - ## look for | "ProtoALphaALphaALphaALphaALphaALphaALphaALphaDdp3zK" -> ("alpha", Active) - ## and add | "${longhash}" ) as full_hash -> (String.sub full_hash 0 8, Active) - sed -i.old -e "/| \"ProtoALphaALphaALphaALphaALphaALphaALphaALphaDdp3zK\" ->/a \ | \"${long_hash}\" as full_hash -> (String.sub full_hash 0 8, Active)" src/lib_agnostic_baker/parameters.ml + ## look for "ProtoALphaALphaALphaALphaALphaALphaALphaALphaDdp3zK" and add "${longhash};" + sed -i.old -e "/ \"ProtoALphaALphaALphaALphaALphaALphaALphaALphaDdp3zK\" /a \"${long_hash}\"; " src/lib_agnostic_baker/parameters.ml ocamlformat -i src/lib_agnostic_baker/parameters.ml commit "src: add protocol to agnostic_baker" fi diff --git a/src/lib_agnostic_baker/daemon.ml b/src/lib_agnostic_baker/daemon.ml index 0647353d0e05..d5d92df913cc 100644 --- a/src/lib_agnostic_baker/daemon.ml +++ b/src/lib_agnostic_baker/daemon.ml @@ -16,11 +16,6 @@ end open Agnostic_baker_errors -(* Number of extra levels to keep the old baker alive before shutting it down. - This extra time is used to avoid halting the chain in cases such as - reorganization or high round migration blocks. *) -let extra_levels_for_old_baker = 3 - type process = {thread : int Lwt.t; canceller : int Lwt.u} type baker = {protocol_hash : Protocol_hash.t; process : process} @@ -228,7 +223,8 @@ let monitor_voting_periods ~state head_stream = ~state ~current_protocol_hash ~next_protocol_hash - ~level_to_kill_old_baker:(head_level + extra_levels_for_old_baker) + ~level_to_kill_old_baker: + (head_level + Parameters.extra_levels_for_old_baker) [@profiler.record_s {verbosity = Notice} "hot_swap_baker"]) else return_unit in diff --git a/src/lib_agnostic_baker/parameters.ml b/src/lib_agnostic_baker/parameters.ml index 7e67520deb12..a353bf47b7f3 100644 --- a/src/lib_agnostic_baker/parameters.ml +++ b/src/lib_agnostic_baker/parameters.ml @@ -6,6 +6,8 @@ (* *) (*****************************************************************************) +(* Default parameter values *) + let default_node_endpoint = Format.sprintf "http://localhost:%d" @@ -23,6 +25,10 @@ let log_config ~base_dir = ~log_cfg:Tezos_base_unix.Logs_simple_config.default_cfg () +let extra_levels_for_old_baker = 3 + +(* Protocol status *) + type status = Active | Frozen let pp_status fmt status = @@ -42,9 +48,7 @@ let status_encoding = [ case ~title:"active" - ~description: - "Active protocols are currently used on a network, and thus, they \ - have dedicated delegate binaries." + ~description:"Active protocols are currently used on a network." (Tag 0) (constant "active") (function Active -> Some () | _ -> None) @@ -52,48 +56,54 @@ let status_encoding = case ~title:"frozen" ~description: - "Frozen protocols are currently unused on any network, and thus, \ - they do not have dedicated delegate binaries." + "Frozen protocols are not currently used on any network." (Tag 1) (constant "frozen") (function Frozen -> Some () | _ -> None) (fun () -> Frozen); ]) -(* From Manifest/Product_octez/Protocol*) -let protocol_info = function - | ( "ProtoGenesisGenesisGenesisGenesisGenesisGenesk612im" - | "Ps9mPmXaRzmzk35gbAYNCAw6UXdE2qoABTHbN2oEEc1qM7CwT9P" - | "PtCJ7pwoxe8JasnHY8YonnLYjcVHmhiARPJvqcC6VfHT5s8k8sY" - | "PsYLVpVvgbLhAhoqAkMFUo6gudkJ9weNXhUYCiLDzcUpFpkk8Wt" - | "PsddFKi32cMJ2qPjf43Qv5GDWLDPZb3T3bF6fLKiF5HtvHNU7aP" - | "Pt24m4xiPbLDhVgVfABUjirbmda3yohdN82Sp9FeuAXJ4eV9otd" - | "PsBABY5HQTSkA4297zNHfsZNKtxULfL18y95qb3m53QJiXGmrbU" - | "PsBabyM1eUXZseaJdmXFApDSBqj8YBfwELoxZHHW77EMcAbbwAS" - | "PsCARTHAGazKbHtnKfLzQg3kms52kSRpgnDY982a9oYsSXRLQEb" - | "PsDELPH1Kxsxt8f9eWbxQeRxkjfbxoqM52jvs5Y5fBxWWh4ifpo" - | "PtEdoTezd3RHSC31mpxxo1npxFjoWWcFgQtxapi51Z8TLu6v6Uq" - | "PtEdo2ZkT9oKpimTah6x2embF25oss54njMuPzkJTEi5RqfdZFA" - | "PsFLorenaUUuikDWvMDr6fGBRG8kt3e3D3fHoXK1j1BFRxeSH4i" - | "PtGRANADsDU8R9daYKAgWnQYAJ64omN1o3KMGVCykShA97vQbvV" - | "PtHangz2aRngywmSRGGvrcTyMbbdpWdpFKuS4uMWxg2RaH9i1qx" - | "Psithaca2MLRFYargivpo7YvUr7wUDqyxrdhC5CQq78mRvimz6A" - | "PtJakart2xVj7pYXJBXrqHgd82rdkLey5ZeeGwDgPp9rhQUbSqY" - | "PtKathmankSpLLDALzWw7CGD2j2MtyveTwboEYokqUCP4a1LxMg" - | "PtLimaPtLMwfNinJi9rCfDPWea8dFgTZ1MeJ9f1m2SRic6ayiwW" - | "PtMumbai2TmsJHNGRkD8v8YDbtao7BLUC3wjASn1inAKLFCjaH1" - | "PtNairobiyssHuh87hEhfVBGCVrK3WnS8Z2FT4ymB5tAa4r1nQf" - | "ProxfordYmVfjWnRcgjWH36fW6PArwqykTFzotUxRs6gmTcZDuH" - | "PtParisBxoLz5gzMmn3d9WBQNoPSZakgnkMC2VNuQ3KXfUtUQeZ" ) as full_hash -> - (String.sub full_hash 0 8, Frozen) - | ( "PsParisCZo7KAh1Z1smVd9ZMZ1HHn5gkzbM94V3PLCpknFWhUAi" - | "PsQuebecnLByd3JwTiGadoG4nGWi3HYiLXUjkibeFV8dCFeVMUg" ) as full_hash -> - (String.sub full_hash 0 8, Active) - | "ProtoALphaALphaALphaALphaALphaALphaALphaALphaDdp3zK" -> ("alpha", Active) - | "PsRiotumaAMotcRoDWW1bysEhQy2n1M5fy8JgRp8jjRfHGmfeA7" as full_hash -> - (String.sub full_hash 0 8, Active) - | _ -> (*We assume that unmatched protocols are next ones*) ("next", Active) +(** Lists of known protocol hashes for [Frozen] and [Active] protocols, corresponding + to [Manifest/Product_octez/Protocol] module. *) +let frozen_protocols = + [ + "ProtoGenesisGenesisGenesisGenesisGenesisGenesk612im"; + "Ps9mPmXaRzmzk35gbAYNCAw6UXdE2qoABTHbN2oEEc1qM7CwT9P"; + "PtCJ7pwoxe8JasnHY8YonnLYjcVHmhiARPJvqcC6VfHT5s8k8sY"; + "PsYLVpVvgbLhAhoqAkMFUo6gudkJ9weNXhUYCiLDzcUpFpkk8Wt"; + "PsddFKi32cMJ2qPjf43Qv5GDWLDPZb3T3bF6fLKiF5HtvHNU7aP"; + "Pt24m4xiPbLDhVgVfABUjirbmda3yohdN82Sp9FeuAXJ4eV9otd"; + "PsBABY5HQTSkA4297zNHfsZNKtxULfL18y95qb3m53QJiXGmrbU"; + "PsBabyM1eUXZseaJdmXFApDSBqj8YBfwELoxZHHW77EMcAbbwAS"; + "PsCARTHAGazKbHtnKfLzQg3kms52kSRpgnDY982a9oYsSXRLQEb"; + "PsDELPH1Kxsxt8f9eWbxQeRxkjfbxoqM52jvs5Y5fBxWWh4ifpo"; + "PtEdoTezd3RHSC31mpxxo1npxFjoWWcFgQtxapi51Z8TLu6v6Uq"; + "PtEdo2ZkT9oKpimTah6x2embF25oss54njMuPzkJTEi5RqfdZFA"; + "PsFLorenaUUuikDWvMDr6fGBRG8kt3e3D3fHoXK1j1BFRxeSH4i"; + "PtGRANADsDU8R9daYKAgWnQYAJ64omN1o3KMGVCykShA97vQbvV"; + "PtHangz2aRngywmSRGGvrcTyMbbdpWdpFKuS4uMWxg2RaH9i1qx"; + "Psithaca2MLRFYargivpo7YvUr7wUDqyxrdhC5CQq78mRvimz6A"; + "PtJakart2xVj7pYXJBXrqHgd82rdkLey5ZeeGwDgPp9rhQUbSqY"; + "PtKathmankSpLLDALzWw7CGD2j2MtyveTwboEYokqUCP4a1LxMg"; + "PtLimaPtLMwfNinJi9rCfDPWea8dFgTZ1MeJ9f1m2SRic6ayiwW"; + "PtMumbai2TmsJHNGRkD8v8YDbtao7BLUC3wjASn1inAKLFCjaH1"; + "PtNairobiyssHuh87hEhfVBGCVrK3WnS8Z2FT4ymB5tAa4r1nQf"; + "ProxfordYmVfjWnRcgjWH36fW6PArwqykTFzotUxRs6gmTcZDuH"; + "PtParisBxoLz5gzMmn3d9WBQNoPSZakgnkMC2VNuQ3KXfUtUQeZ"; + "PsParisCZo7KAh1Z1smVd9ZMZ1HHn5gkzbM94V3PLCpknFWhUAi"; + ] -let protocol_short_hash h = fst (protocol_info (Protocol_hash.to_b58check h)) +(** If this list format is modified, subsequent modifications must be carried onto + the agnostic baker section from [scripts/proto_manager.sh]. *) +let active_protocols = + [ + "PsQuebecnLByd3JwTiGadoG4nGWi3HYiLXUjkibeFV8dCFeVMUg"; + "PsRiotumaAMotcRoDWW1bysEhQy2n1M5fy8JgRp8jjRfHGmfeA7"; + "ProtoALphaALphaALphaALphaALphaALphaALphaALphaDdp3zK"; + ] -let protocol_status h = snd (protocol_info (Protocol_hash.to_b58check h)) +let protocol_status proto_hash = + match Protocol_hash.to_b58check proto_hash with + | hash when List.mem ~equal:String.equal hash active_protocols -> Active + | hash when List.mem ~equal:String.equal hash frozen_protocols -> Frozen + | _ -> (* We assume that unmatched protocols are "next" ones *) Active diff --git a/src/lib_agnostic_baker/parameters.mli b/src/lib_agnostic_baker/parameters.mli index 79f7c870b154..3675d5ecfe54 100644 --- a/src/lib_agnostic_baker/parameters.mli +++ b/src/lib_agnostic_baker/parameters.mli @@ -15,10 +15,14 @@ val default_daily_logs_path : string option val log_config : base_dir:string -> Tezos_base.Internal_event_config.t -(** Status of a protocol, based on Manifest/Product_octez/Protocol. A - protocol is considered as [Active] while it is running on a network, - and thus, have dedicated binaries. Otherwise, the protocol is - [Frozen] as not running anymore and no associated binaries. +(** Number of extra levels to keep the old baker alive before shutting it down. + This extra time is used to avoid halting the chain in cases such as + reorganization or high round migration blocks. *) +val extra_levels_for_old_baker : int + +(** Status of a protocol, based on [Manifest/Product_octez/Protocol]. A + protocol is considered as [Active] while it is running on a network. + Otherwise, the protocol is [Frozen]. Warning, it is needed to update status for each new protocol added. *) @@ -28,6 +32,6 @@ val pp_status : Format.formatter -> status -> unit val status_encoding : status t -val protocol_short_hash : Protocol_hash.t -> string - +(** [protocol_status proto_hash] returns whether the given [proto_hash] is + [Active] or [Frozen]. *) val protocol_status : Protocol_hash.t -> status -- GitLab From e6bb5ff7b6692dabb4f54b3e2db59cf3b40ff560 Mon Sep 17 00:00:00 2001 From: Gabriel Moise Date: Wed, 26 Mar 2025 11:51:58 +0000 Subject: [PATCH 02/20] Agnostic_baker: Refactor daemon module --- src/lib_agnostic_baker/daemon.ml | 123 +++++++++++++++--------------- src/lib_agnostic_baker/daemon.mli | 12 +-- 2 files changed, 66 insertions(+), 69 deletions(-) diff --git a/src/lib_agnostic_baker/daemon.ml b/src/lib_agnostic_baker/daemon.ml index d5d92df913cc..67aa07adfb5f 100644 --- a/src/lib_agnostic_baker/daemon.ml +++ b/src/lib_agnostic_baker/daemon.ml @@ -6,6 +6,9 @@ (* *) (*****************************************************************************) +open Agnostic_baker_errors +module Events = Agnostic_baker_events + module Profiler = struct include (val Profiler.wrap Agnostic_baker_profiler.agnostic_baker_profiler) @@ -14,14 +17,24 @@ module Profiler = struct Agnostic_baker_profiler.agnostic_baker_profiler end -open Agnostic_baker_errors - type process = {thread : int Lwt.t; canceller : int Lwt.u} type baker = {protocol_hash : Protocol_hash.t; process : process} +type baker_to_kill = {baker : baker; level_to_kill : int} + +type state = { + node_endpoint : string; + mutable current_baker : baker option; + mutable old_baker : baker_to_kill option; +} + +type t = state + +(* ---- Baker Process Management ---- *) + (** [run_thread ~protocol_hash ~baker_commands ~cancel_promise ~logs_path] - returns the main running thread for the baker given its protocol [~procol_hash], + returns the main running thread for the baker given its protocol [~protocol_hash], corresponding commands [~baker_commands] and Lwt cancellation promise [~cancel_promise]. The event logs are stored according to [~logs_path]. *) @@ -30,8 +43,6 @@ let run_thread ~protocol_hash ~baker_commands ~cancel_promise ~logs_path = Client_commands.register protocol_hash @@ fun _network -> baker_commands in - let select_commands _ _ = Lwt_result_syntax.return baker_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. @@ -50,7 +61,7 @@ let run_thread ~protocol_hash ~baker_commands ~cancel_promise ~logs_path = [ Client_main_run.lwt_run (module Config) - ~select_commands + ~select_commands:(fun _ _ -> Lwt_result_syntax.return baker_commands) (* The underlying logging from the baker must not be initialised, otherwise we double log. *) ~disable_logging:true (); @@ -60,7 +71,7 @@ let run_thread ~protocol_hash ~baker_commands ~cancel_promise ~logs_path = (** [spawn_baker protocol_hash] spawns a new baker process for the given [protocol_hash]. *) let spawn_baker protocol_hash = let open Lwt_result_syntax in - let*! () = Agnostic_baker_events.(emit starting_baker) protocol_hash in + let*! () = Events.(emit starting_baker) protocol_hash in let cancel_promise, canceller = Lwt.wait () in let* thread = let*? plugin = @@ -76,46 +87,9 @@ let spawn_baker protocol_hash = ~cancel_promise ~logs_path:Parameters.default_daily_logs_path in - let*! () = Agnostic_baker_events.(emit baker_running) protocol_hash in + let*! () = Events.(emit baker_running) protocol_hash in return {protocol_hash; process = {thread; canceller}} -type baker_to_kill = {baker : baker; level_to_kill : int} - -type 'a state = { - node_endpoint : string; - mutable current_baker : baker option; - mutable old_baker : baker_to_kill option; -} - -type 'a t = 'a state - -(** [monitor_heads ~node_addr] creates a stream which returns the data - of the heads of the current network; this information is received - from the RPC calls at the endpoint given by [~node_addr]. *) -let monitor_heads ~node_addr = - let open Lwt_result_syntax in - let uri = Format.sprintf "%s/monitor/heads/main" node_addr in - let* _, body = Rpc_services.request_uri ~node_addr ~uri in - let cohttp_stream = Cohttp_lwt.Body.to_stream body in - let buffer = Buffer.create 2048 in - let stream, push = Lwt_stream.create () in - let on_chunk v = push (Some v) and on_close () = push None in - let rec loop () = - let*! v = Lwt_stream.get cohttp_stream in - match v with - | None -> - on_close () ; - Lwt.return_unit - | Some chunk -> - Buffer.add_string buffer chunk ; - let data = Buffer.contents buffer in - Buffer.reset buffer ; - on_chunk data ; - loop () - in - ignore (loop () : unit Lwt.t) ; - return stream - (** [hot_swap_baker ~state ~current_protocol_hash ~next_protocol_hash ~level_to_kill_old_baker] moves the current baker into the old baker slot (to be killed later) and spawns a new baker for [~next_protocol_hash] *) @@ -129,11 +103,10 @@ let hot_swap_baker ~state ~current_protocol_hash ~next_protocol_hash in let next_proto_status = Parameters.protocol_status next_protocol_hash in let*! () = - Agnostic_baker_events.(emit protocol_encountered) - (next_proto_status, next_protocol_hash) + Events.(emit protocol_encountered) (next_proto_status, next_protocol_hash) in let*! () = - Agnostic_baker_events.(emit become_old_baker) + Events.(emit become_old_baker) (current_protocol_hash, level_to_kill_old_baker) in state.old_baker <- @@ -156,9 +129,7 @@ let maybe_kill_old_baker state node_addr = ~node_addr [@profiler.record_s {verbosity = Notice} "get_level"]) in if head_level >= level_to_kill then ( - let*! () = - Agnostic_baker_events.(emit stopping_baker) baker.protocol_hash - in + let*! () = Events.(emit stopping_baker) baker.protocol_hash in Lwt.wakeup baker.process.canceller 0 [@profiler.record_f {verbosity = Notice} "kill old baker"] ; @@ -166,6 +137,35 @@ let maybe_kill_old_baker state node_addr = return_unit) else return_unit +(* ---- Baker and Chain Monitoring ---- *) + +(** [monitor_heads ~node_addr] creates a stream which returns the data + of the heads of the current network; this information is received + from the RPC calls at the endpoint given by [~node_addr]. *) +let monitor_heads ~node_addr = + let open Lwt_result_syntax in + let uri = Format.sprintf "%s/monitor/heads/main" node_addr in + let* _, body = Rpc_services.request_uri ~node_addr ~uri in + let cohttp_stream = Cohttp_lwt.Body.to_stream body in + let buffer = Buffer.create 2048 in + let stream, push = Lwt_stream.create () in + let on_chunk v = push (Some v) and on_close () = push None in + let rec loop () = + let*! v = Lwt_stream.get cohttp_stream in + match v with + | None -> + on_close () ; + Lwt.return_unit + | Some chunk -> + Buffer.add_string buffer chunk ; + let data = Buffer.contents buffer in + Buffer.reset buffer ; + on_chunk data ; + loop () + in + ignore (loop () : unit Lwt.t) ; + return stream + (** [monitor_voting_periods ~state head_stream] continuously monitors [heads_stream] to detect protocol changes. It will: - Shut down an old baker it its time has come; @@ -192,8 +192,7 @@ let monitor_voting_periods ~state head_stream = [@profiler.record_s {verbosity = Notice} "get_current_period"]) in let*! () = - Agnostic_baker_events.(emit period_status) - (block_hash, period_kind, remaining) + Events.(emit period_status) (block_hash, period_kind, remaining) in let* () = (maybe_kill_old_baker @@ -243,12 +242,14 @@ let baker_thread ~state = in if retcode = 0 then return_unit else tzfail Baker_process_error +(* ---- Agnostic Baker Bootstrap ---- *) + (** [may_start_initial_baker state] recursively waits for an [active] protocol and spawns a baker for it. If the protocol is [frozen] (not [active] anymore), it waits for a head with an [active] protocol. *) let may_start_initial_baker state = let open Lwt_result_syntax in - let*! () = Agnostic_baker_events.(emit experimental_binary) () in + let*! () = Events.(emit experimental_binary) () in let rec may_start ?last_known_proto ~head_stream () = let* protocol_hash = Rpc_services.get_next_protocol_hash ~node_addr:state.node_endpoint @@ -259,8 +260,7 @@ let may_start_initial_baker state = | None -> Lwt.return_unit | Some h -> if not (Protocol_hash.equal h protocol_hash) then - Agnostic_baker_events.(emit protocol_encountered) - (proto_status, protocol_hash) + Events.(emit protocol_encountered) (proto_status, protocol_hash) else Lwt.return_unit in match proto_status with @@ -274,12 +274,9 @@ let may_start_initial_baker state = | Some v -> return v | None -> let*! () = - Agnostic_baker_events.(emit protocol_encountered) - (proto_status, protocol_hash) - in - let*! () = - Agnostic_baker_events.(emit waiting_for_active_protocol) () + Events.(emit protocol_encountered) (proto_status, protocol_hash) in + let*! () = Events.(emit waiting_for_active_protocol) () in monitor_heads ~node_addr:state.node_endpoint in let*! v = Lwt_stream.get head_stream in @@ -299,10 +296,10 @@ let create ~node_endpoint = let run state = let open Lwt_result_syntax in let node_addr = state.node_endpoint in - let*! () = Agnostic_baker_events.(emit starting_daemon) () in + let*! () = Events.(emit starting_daemon) () in let _ccid = Lwt_exit.register_clean_up_callback ~loc:__LOC__ (fun _ -> - let*! () = Agnostic_baker_events.(emit stopping_daemon) () in + let*! () = Events.(emit stopping_daemon) () in Lwt.return_unit) in let* () = may_start_initial_baker state in diff --git a/src/lib_agnostic_baker/daemon.mli b/src/lib_agnostic_baker/daemon.mli index 618a7547cd7f..bbc1bfabd215 100644 --- a/src/lib_agnostic_baker/daemon.mli +++ b/src/lib_agnostic_baker/daemon.mli @@ -9,7 +9,7 @@ (** Daemon handling the baker's life cycle. It is used to [create] and [run] a protocol-agnostic process which uses the existing - baking binaries in an adaptive way, depending on the current protocol obtained + baking processes in an adaptive way, depending on the current protocol obtained from the chain. It relies on a [state] which contains the [endpoint] to contact the running node, @@ -18,14 +18,14 @@ To do so, it also spawns a "monitoring" process which follows the heads of the chain, as reported by the node from the [state], more precisely which monitors the voting period. By doing that, it decides when to swap to a different baking - binary. + process. *) -type 'a t +type t (** [create ~node_endpoint] returns a non initialized daemon. *) -val create : node_endpoint:string -> 'a t +val create : node_endpoint:string -> t -(** [run t] Runs the daemon responsible for the spawn/stop of the +(** [run daemon] Runs the daemon responsible for the spawn/stop of the baker daemons. *) -val run : 'a t -> unit tzresult Lwt.t +val run : t -> unit tzresult Lwt.t -- GitLab From 1e01f34cc66bca29d980544574e0de42319a5329 Mon Sep 17 00:00:00 2001 From: Gabriel Moise Date: Wed, 26 Mar 2025 12:13:46 +0000 Subject: [PATCH 03/20] Agnostic_baker: Refactor main module --- manifest/product_octez.ml | 1 + opam/octez-experimental-agnostic-baker.opam | 1 + src/bin_agnostic_baker/dune | 2 ++ src/bin_agnostic_baker/main_agnostic_baker.ml | 17 +++++++------- .../agnostic_baker_config.ml | 13 +++++++++++ src/lib_agnostic_baker/daemon.ml | 22 +++++-------------- 6 files changed, 31 insertions(+), 25 deletions(-) create mode 100644 src/lib_agnostic_baker/agnostic_baker_config.ml diff --git a/manifest/product_octez.ml b/manifest/product_octez.ml index 830f199187f2..5f3eb0d04b81 100644 --- a/manifest/product_octez.ml +++ b/manifest/product_octez.ml @@ -8616,6 +8616,7 @@ let _octez_experimental_agnostic_baker = bls12_381_archive; octez_base |> open_ ~m:"TzPervasives" |> open_; octez_base_unix |> open_; + octez_client_base_unix |> open_; octez_experimental_agnostic_baker_lib |> open_; octez_profiler |> open_; ] diff --git a/opam/octez-experimental-agnostic-baker.opam b/opam/octez-experimental-agnostic-baker.opam index eab07475ebd5..8924250713f5 100644 --- a/opam/octez-experimental-agnostic-baker.opam +++ b/opam/octez-experimental-agnostic-baker.opam @@ -13,6 +13,7 @@ depends: [ "octez-libs" { = version } "octez-rust-deps" { = version } "bls12-381" { = version } + "octez-shell-libs" { = version } "octez-experimental-agnostic-baker-lib" { = version } "octez-protocol-021-PsQuebec-libs" { = version } "octez-protocol-022-PsRiotum-libs" { = version } diff --git a/src/bin_agnostic_baker/dune b/src/bin_agnostic_baker/dune index d184c7a2c707..73b805b34530 100644 --- a/src/bin_agnostic_baker/dune +++ b/src/bin_agnostic_baker/dune @@ -11,6 +11,7 @@ bls12-381.archive octez-libs.base octez-libs.base.unix + octez-shell-libs.client-base-unix octez-experimental-agnostic-baker-lib octez-libs.octez-profiler octez-protocol-021-PsQuebec-libs.agnostic-baker @@ -30,6 +31,7 @@ -open Tezos_base.TzPervasives -open Tezos_base -open Tezos_base_unix + -open Tezos_client_base_unix -open Octez_experimental_agnostic_baker -open Tezos_profiler)) diff --git a/src/bin_agnostic_baker/main_agnostic_baker.ml b/src/bin_agnostic_baker/main_agnostic_baker.ml index 88c054c752d6..29e8d1e38c17 100644 --- a/src/bin_agnostic_baker/main_agnostic_baker.ml +++ b/src/bin_agnostic_baker/main_agnostic_baker.ml @@ -26,7 +26,7 @@ let lwt_run ~args () = let open Lwt_result_syntax in let base_dir = Option.value - ~default:Tezos_client_base_unix.Client_config.Cfg_file.default.base_dir + ~default:Client_config.Cfg_file.default.base_dir (Run_args.get_base_dir args) in let*! () = @@ -41,7 +41,7 @@ let lwt_run ~args () = return_unit let run ~args () = - let open Lwt_result_syntax in + let open Lwt_syntax in let main_promise = Lwt.catch (lwt_run ~args) (function | Failure msg -> failwith "%s" msg @@ -49,8 +49,8 @@ let run ~args () = in Stdlib.exit (Tezos_base_unix.Event_loop.main_run (fun () -> - let*! retcode = - let*! r = Lwt_exit.wrap_and_exit main_promise in + let* retcode = + let* r = Lwt_exit.wrap_and_exit main_promise in match r with | Ok () -> Lwt.return 0 | Error errs -> @@ -59,15 +59,16 @@ let run ~args () = in Format.pp_print_flush Format.err_formatter () ; Format.pp_print_flush Format.std_formatter () ; - let*! () = Tezos_base_unix.Internal_event_unix.close () in - Lwt.return retcode)) + let* () = Tezos_base_unix.Internal_event_unix.close () in + return retcode)) let () = - let open Tezos_client_base_unix in let args = Array.to_list Sys.argv in if Run_args.(is_help_cmd args || is_version_cmd args || is_man_cmd args) then + (* No need to run the baker commands, we just need to get their description, + therefore we do not obtain the protocol plugin. *) Client_main_run.run - (module Daemon_config) + (module Agnostic_baker_config) ~select_commands:(fun _ _ -> Lwt_result_syntax.return @@ Commands.baker_commands ()) else run ~args () diff --git a/src/lib_agnostic_baker/agnostic_baker_config.ml b/src/lib_agnostic_baker/agnostic_baker_config.ml new file mode 100644 index 000000000000..8a7524c646ca --- /dev/null +++ b/src/lib_agnostic_baker/agnostic_baker_config.ml @@ -0,0 +1,13 @@ +(*****************************************************************************) +(* *) +(* SPDX-License-Identifier: MIT *) +(* Copyright (c) 2025 Trilitech *) +(* *) +(*****************************************************************************) + +(* Agnostic Baker Daemon configuration *) + +include Tezos_client_base_unix.Daemon_config + +(* All logging must be centralised in a single place. *) +let default_daily_logs_path = Parameters.default_daily_logs_path diff --git a/src/lib_agnostic_baker/daemon.ml b/src/lib_agnostic_baker/daemon.ml index 67aa07adfb5f..0e0a6232660e 100644 --- a/src/lib_agnostic_baker/daemon.ml +++ b/src/lib_agnostic_baker/daemon.ml @@ -33,12 +33,10 @@ type t = state (* ---- Baker Process Management ---- *) -(** [run_thread ~protocol_hash ~baker_commands ~cancel_promise ~logs_path] +(** [run_thread ~protocol_hash ~baker_commands ~cancel_promise] returns the main running thread for the baker given its protocol [~protocol_hash], - corresponding commands [~baker_commands] and Lwt cancellation promise [~cancel_promise]. - - The event logs are stored according to [~logs_path]. *) -let run_thread ~protocol_hash ~baker_commands ~cancel_promise ~logs_path = + corresponding commands [~baker_commands] and cancellation [~cancel_promise]. *) +let run_thread ~protocol_hash ~baker_commands ~cancel_promise = let () = Client_commands.register protocol_hash @@ fun _network -> baker_commands in @@ -52,15 +50,10 @@ let run_thread ~protocol_hash ~baker_commands ~cancel_promise ~logs_path = 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) + (module Agnostic_baker_config) ~select_commands:(fun _ _ -> Lwt_result_syntax.return baker_commands) (* The underlying logging from the baker must not be initialised, otherwise we double log. *) ~disable_logging:true @@ -80,12 +73,7 @@ let spawn_baker protocol_hash = [@profiler.record_f {verbosity = Notice} "proto_plugin_for_protocol"]) in let baker_commands = Commands.baker_commands ~plugin () in - return - @@ run_thread - ~protocol_hash - ~baker_commands - ~cancel_promise - ~logs_path:Parameters.default_daily_logs_path + return @@ run_thread ~protocol_hash ~baker_commands ~cancel_promise in let*! () = Events.(emit baker_running) protocol_hash in return {protocol_hash; process = {thread; canceller}} -- GitLab From 0b8716bdc10461b3becc4bd15ef6fd9f1c122a39 Mon Sep 17 00:00:00 2001 From: Gabriel Moise Date: Tue, 1 Apr 2025 10:34:17 +0100 Subject: [PATCH 04/20] Agnostic_baker: Refactor Client_main_run logging and remove duplicated code --- src/bin_agnostic_baker/main_agnostic_baker.ml | 6 +- src/lib_agnostic_baker/parameters.ml | 10 --- src/lib_agnostic_baker/parameters.mli | 2 - src/lib_client_base_unix/client_main_run.ml | 65 ++++++++++--------- src/lib_client_base_unix/client_main_run.mli | 12 ++++ 5 files changed, 49 insertions(+), 46 deletions(-) diff --git a/src/bin_agnostic_baker/main_agnostic_baker.ml b/src/bin_agnostic_baker/main_agnostic_baker.ml index 29e8d1e38c17..8012ba1a2252 100644 --- a/src/bin_agnostic_baker/main_agnostic_baker.ml +++ b/src/bin_agnostic_baker/main_agnostic_baker.ml @@ -26,13 +26,11 @@ let lwt_run ~args () = let open Lwt_result_syntax in let base_dir = Option.value - ~default:Client_config.Cfg_file.default.base_dir + ~default:Agnostic_baker_config.default_base_dir (Run_args.get_base_dir args) in let*! () = - Tezos_base_unix.Internal_event_unix.init - ~config:(Parameters.log_config ~base_dir) - () + Client_main_run.init_logging (module Agnostic_baker_config) ~base_dir () in () [@profiler.overwrite may_start_profiler base_dir] ; let daemon = Daemon.create ~node_endpoint:(Run_args.get_endpoint args) in diff --git a/src/lib_agnostic_baker/parameters.ml b/src/lib_agnostic_baker/parameters.ml index a353bf47b7f3..3dafdfffd569 100644 --- a/src/lib_agnostic_baker/parameters.ml +++ b/src/lib_agnostic_baker/parameters.ml @@ -15,16 +15,6 @@ let default_node_endpoint = let default_daily_logs_path = Some "octez-experimental-agnostic-baker" -let log_config ~base_dir = - let daily_logs_path = - default_daily_logs_path - |> Option.map Filename.Infix.(fun logdir -> base_dir // "logs" // logdir) - in - Tezos_base_unix.Internal_event_unix.make_with_defaults - ?enable_default_daily_logs_at:daily_logs_path - ~log_cfg:Tezos_base_unix.Logs_simple_config.default_cfg - () - let extra_levels_for_old_baker = 3 (* Protocol status *) diff --git a/src/lib_agnostic_baker/parameters.mli b/src/lib_agnostic_baker/parameters.mli index 3675d5ecfe54..6c14efc8c06a 100644 --- a/src/lib_agnostic_baker/parameters.mli +++ b/src/lib_agnostic_baker/parameters.mli @@ -13,8 +13,6 @@ val default_node_endpoint : string (** Default logs path for the agnostic baker. *) val default_daily_logs_path : string option -val log_config : base_dir:string -> Tezos_base.Internal_event_config.t - (** Number of extra levels to keep the old baker alive before shutting it down. This extra time is used to avoid halting the chain in cases such as reorganization or high round migration blocks. *) diff --git a/src/lib_client_base_unix/client_main_run.ml b/src/lib_client_base_unix/client_main_run.ml index d0b5af5c0191..57c1115e5888 100644 --- a/src/lib_client_base_unix/client_main_run.ml +++ b/src/lib_client_base_unix/client_main_run.ml @@ -419,6 +419,35 @@ let warn_if_argv0_name_not_octez () = expected_name executable_name +let init_logging (module C : M) ?(parsed_args : Client_config.cli_args option) + ?parsed_config_file ~base_dir () = + let open Tezos_base_unix.Internal_event_unix in + let daily_logs_path = + C.default_daily_logs_path + |> Option.map Filename.Infix.(fun logdir -> base_dir // "logs" // logdir) + in + (* Update config with color logging switch and advertise levels *) + let log_cfg = + let colors = + match parsed_args with + | None -> None + | Some parsed_args -> parsed_args.log_coloring + in + Tezos_base_unix.Logs_simple_config.create_cfg + ?advertise_levels:C.advertise_log_levels + ?colors + () + in + let config = + make_with_defaults ?enable_default_daily_logs_at:daily_logs_path ~log_cfg () + in + match parsed_config_file with + | None -> init ~config () + | Some cf -> ( + match cf.Client_config.Cfg_file.internal_events with + | None -> init ~config () + | Some config -> init ~config ()) + (* Main (lwt) entry *) let main (module C : M) ~select_commands ?(disable_logging = false) () = let open Lwt_result_syntax in @@ -481,36 +510,12 @@ let main (module C : M) ~select_commands ?(disable_logging = false) () = let*! () = if disable_logging then Lwt.return_unit else - let open Tezos_base_unix.Internal_event_unix in - let daily_logs_path = - C.default_daily_logs_path - |> Option.map - Filename.Infix.(fun logdir -> base_dir // "logs" // logdir) - in - (* Update config with color logging switch and advertise levels *) - let log_cfg = - let colors = - match parsed_args with - | None -> None - | Some parsed_args -> parsed_args.log_coloring - in - Tezos_base_unix.Logs_simple_config.create_cfg - ?advertise_levels:C.advertise_log_levels - ?colors - () - in - let config = - make_with_defaults - ?enable_default_daily_logs_at:daily_logs_path - ~log_cfg - () - in - match parsed_config_file with - | None -> init ~config () - | Some cf -> ( - match cf.Client_config.Cfg_file.internal_events with - | None -> init ~config () - | Some config -> init ~config ()) + init_logging + (module C) + ?parsed_args + ?parsed_config_file + ~base_dir + () in let rpc_config = let rpc_config : RPC_client_unix.config = diff --git a/src/lib_client_base_unix/client_main_run.mli b/src/lib_client_base_unix/client_main_run.mli index 33ac0a77d4b6..4848e81b35d4 100644 --- a/src/lib_client_base_unix/client_main_run.mli +++ b/src/lib_client_base_unix/client_main_run.mli @@ -95,6 +95,18 @@ val register_default_signer : Client_context.io_wallet -> unit +(** [init_logging (module M) ?parsed_args ?parsed_config_file ~base_dir ()] + starts the logging process based on optional parsed arguments [?parse_args], + optional configuration file [?parsed_config_file], with output in the + [~base_dir] directory. *) +val init_logging : + (module M) -> + ?parsed_args:Client_config.cli_args -> + ?parsed_config_file:Client_config.Cfg_file.t -> + base_dir:string -> + unit -> + unit Lwt.t + val run : (module M) -> select_commands: -- GitLab From 221a457d4fc2721e6bbba59e0c2999987e30b5cc Mon Sep 17 00:00:00 2001 From: Gabriel Moise Date: Wed, 26 Mar 2025 13:44:35 +0000 Subject: [PATCH 05/20] Agnostic_baker: Add commands module documentation --- src/lib_agnostic_baker/commands.mli | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/lib_agnostic_baker/commands.mli b/src/lib_agnostic_baker/commands.mli index c81df4040674..ded33916227f 100644 --- a/src/lib_agnostic_baker/commands.mli +++ b/src/lib_agnostic_baker/commands.mli @@ -5,6 +5,13 @@ (* *) (*****************************************************************************) +(** [baker_commands ?plugin ()] returns a list of CLI commands available for + controlling a baker process in the Tezos client context. + + - If [?plugin] is provided, the returned commands are fully functional and use + the protocol-specific baking implementation defined in the plugin. + - If [?plugin] is omitted, the function returns only the command specifications, + which can be used for documentation without actual execution. *) val baker_commands : ?plugin:(module Protocol_plugin_sig.S) -> unit -> -- GitLab From 3ad7ce98ea075094484687a736c6866bb3c02c76 Mon Sep 17 00:00:00 2001 From: Gabriel Moise Date: Wed, 26 Mar 2025 14:32:32 +0000 Subject: [PATCH 06/20] Agnostic_baker: Refactor Rpc_services module --- src/lib_agnostic_baker/rpc_services.ml | 128 ++++++++---------------- src/lib_agnostic_baker/rpc_services.mli | 26 +++-- 2 files changed, 59 insertions(+), 95 deletions(-) diff --git a/src/lib_agnostic_baker/rpc_services.ml b/src/lib_agnostic_baker/rpc_services.ml index c2415fc5cbc1..e959b25d9106 100644 --- a/src/lib_agnostic_baker/rpc_services.ml +++ b/src/lib_agnostic_baker/rpc_services.ml @@ -2,18 +2,21 @@ (* *) (* SPDX-License-Identifier: MIT *) (* Copyright (c) 2024 Nomadic Labs, *) +(* Copyright (c) 2025 Trilitech *) (* *) (*****************************************************************************) open Cohttp_lwt_unix open Agnostic_baker_errors +(* RPC helper functions *) + let request_uri ~node_addr ~uri = let open Lwt_result_syntax in Lwt.catch (fun () -> - let*! r = Client.get (Uri.of_string uri) in - return r) + let*! resp = Client.get (Uri.of_string uri) in + return resp) (function | Unix.(Unix_error (ECONNREFUSED, _, _)) -> tzfail (Cannot_connect_to_node node_addr) @@ -43,103 +46,60 @@ let call_and_wrap_rpc ~node_addr ~uri ~f = in raise Not_found -let get_level ~node_addr = +(* Field extraction helpers *) + +(** [get_field ~name json] extracts the field [~name] from the JSON object [json]. + It fails if [json] is not an object or if the field is missing. *) +let get_field ~name = let open Lwt_result_syntax in - let f json = - (* Level field in the RPC result *) - let name = "level" in - let* v = - match json with - | `O fields -> ( - match List.assoc_opt ~equal:( = ) name fields with - | None -> tzfail (Cannot_decode_node_data ("missing field " ^ name)) - | Some node -> return node) - | _ -> tzfail (Cannot_decode_node_data "not an object") - in - let level = Ezjsonm.get_int v in - return level - in + function + | `O fields -> ( + match List.assoc_opt ~equal:( = ) name fields with + | None -> tzfail (Cannot_decode_node_data ("missing field " ^ name)) + | Some v -> return v) + | _ -> tzfail (Cannot_decode_node_data "not an object") + +(** [get_int_field ~name json] extracts an integer field named [~name] from [json]. *) +let get_int_field ~name json = + let open Lwt_result_syntax in + let+ v = get_field ~name json in + Ezjsonm.get_int v + +(** [get_string_field ~name json] extracts a string field named [~name] from [json]. *) +let get_string_field ~name json = + let open Lwt_result_syntax in + let+ v = get_field ~name json in + Ezjsonm.get_string v + +(* RPC specific functions *) + +let get_level ~node_addr = let uri = Format.sprintf "%s/chains/main/blocks/head/header/shell" node_addr in - call_and_wrap_rpc ~node_addr ~uri ~f + call_and_wrap_rpc ~node_addr ~uri ~f:(get_int_field ~name:"level") let get_block_hash ~node_addr = let open Lwt_result_syntax in - let f json = - (* Hash field in the RPC result *) - let name = "hash" in - let* v = - match json with - | `O fields -> ( - match List.assoc_opt ~equal:( = ) name fields with - | None -> tzfail (Cannot_decode_node_data ("missing field " ^ name)) - | Some node -> return node) - | _ -> tzfail (Cannot_decode_node_data "not an object") - in - let block_hash = Block_hash.of_b58check_exn @@ Ezjsonm.get_string v in - return block_hash - in let uri = Format.sprintf "%s/chains/main/blocks/head/header" node_addr in - call_and_wrap_rpc ~node_addr ~uri ~f + call_and_wrap_rpc ~node_addr ~uri ~f:(fun json -> + let+ block_hash = get_string_field ~name:"hash" json in + Block_hash.of_b58check_exn block_hash) let get_next_protocol_hash ~node_addr = let open Lwt_result_syntax in - let f json = - (* Next_protocol hash field in the RPC result *) - let name = "next_protocol" in - let* v = - match json with - | `O fields -> ( - match List.assoc_opt ~equal:( = ) name fields with - | None -> tzfail (Cannot_decode_node_data ("missing field " ^ name)) - | Some node -> return node) - | _ -> tzfail (Cannot_decode_node_data "not an object") - in - let hash = Protocol_hash.of_b58check_exn (Ezjsonm.get_string v) in - return hash - in let uri = Format.sprintf "%s/chains/main/blocks/head/metadata" node_addr in - call_and_wrap_rpc ~node_addr ~uri ~f + call_and_wrap_rpc ~node_addr ~uri ~f:(fun json -> + let+ next_protocol = get_string_field ~name:"next_protocol" json in + Protocol_hash.of_b58check_exn next_protocol) let get_current_period ~node_addr = let open Lwt_result_syntax in - let voting_period_field = "voting_period" in - let kind_field = "kind" in - let remaining_field = "remaining" in - let f json = - let* kind = - match json with - | `O fields -> ( - match List.assoc_opt ~equal:( = ) voting_period_field fields with - | None -> - tzfail - (Cannot_decode_node_data ("missing field " ^ voting_period_field)) - | Some node -> ( - match node with - | `O fields -> ( - match List.assoc_opt ~equal:( = ) kind_field fields with - | None -> - tzfail - (Cannot_decode_node_data - ("missing field " ^ voting_period_field)) - | Some node -> return @@ Ezjsonm.get_string node) - | _ -> tzfail (Cannot_decode_node_data "not an object"))) - | _ -> tzfail (Cannot_decode_node_data "not an object") - in - let* remaining = - match json with - | `O fields -> ( - match List.assoc_opt ~equal:( = ) remaining_field fields with - | None -> - tzfail - (Cannot_decode_node_data ("missing field " ^ remaining_field)) - | Some node -> return @@ Ezjsonm.get_int node) - | _ -> tzfail (Cannot_decode_node_data "not an object") - in - return (kind, remaining) - in let uri = Format.sprintf "%s/chains/main/blocks/head/votes/current_period" node_addr in - call_and_wrap_rpc ~node_addr ~uri ~f + call_and_wrap_rpc ~node_addr ~uri ~f:(fun json -> + let* voting_period = get_field ~name:"voting_period" json in + let* kind = get_string_field ~name:"kind" voting_period in + let+ remaining = get_int_field ~name:"remaining" json in + (kind, remaining)) diff --git a/src/lib_agnostic_baker/rpc_services.mli b/src/lib_agnostic_baker/rpc_services.mli index 904ac48456d9..b8e1acb6a995 100644 --- a/src/lib_agnostic_baker/rpc_services.mli +++ b/src/lib_agnostic_baker/rpc_services.mli @@ -2,30 +2,34 @@ (* *) (* SPDX-License-Identifier: MIT *) (* Copyright (c) 2024 Nomadic Labs, *) +(* Copyright (c) 2025 Trilitech *) (* *) (*****************************************************************************) -(** [request_uri ~node_addr ~uri] is a raw call that will return the - Cohttp response of an RPC call, given a [~uri], against the - [~node_addr]. *) +(** [request_uri ~node_addr ~uri] issues an HTTP [GET] request to the [~uri] and + returns the response and its body. In case the connection is refused, + it fails with a connection error on [~node_addr]. *) val request_uri : node_addr:string -> uri:string -> (Cohttp_lwt_unix.Response.t * Cohttp_lwt.Body.t) tzresult Lwt.t -(** [get_level ~node_addr] returns the level of the block. *) +(** [get_level ~node_addr] retrieves the current block level from the node at + [~node_addr]. *) val get_level : node_addr:string -> (int, error trace) result Lwt.t -(** [get_level ~node_addr] returns the hash of the block. *) +(** [get_block_hash ~node_addr] retrieves the hash of the current block from the node + at [~node_addr]. *) val get_block_hash : node_addr:string -> (Block_hash.t, error trace) result Lwt.t -(** [get_next_protocol_hash ~node_addr] returns the protocol hash - contained in the [next_protocol] field of the metadata of a - block. *) +(** [get_next_protocol_hash ~node_addr] retrieves the protocol hash from the [next_protocol] + field in the metadata of the current block, as seen by the node at [~node_addr]. *) val get_next_protocol_hash : node_addr:string -> Protocol_hash.t tzresult Lwt.t -(** [get_current_period ~node_addr] returns the current voting - period in addition to the number of remaining blocks until the end - of the period. *) +(** [get_current_period ~node_addr] retrieves the current voting period information + from the node at [~node_addr]. It returns a pair [(kind, remaining)] where: + - [kind] is a string representing the voting period kind, and + - [remaining] is the number of blocks remaining until the end of the voting period. *) + val get_current_period : node_addr:string -> (string * int) tzresult Lwt.t -- GitLab From d4a5150257786f90b43bd13167132339ae9ebbc2 Mon Sep 17 00:00:00 2001 From: Gabriel Moise Date: Wed, 26 Mar 2025 14:57:32 +0000 Subject: [PATCH 07/20] Agnostic_baker: Fix documentation for Run_args module --- src/lib_agnostic_baker/run_args.mli | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib_agnostic_baker/run_args.mli b/src/lib_agnostic_baker/run_args.mli index 8483915b1e85..73cb30d6d98c 100644 --- a/src/lib_agnostic_baker/run_args.mli +++ b/src/lib_agnostic_baker/run_args.mli @@ -19,6 +19,6 @@ val is_man_cmd : string list -> bool amongst [args], and in its absence using the default node RPC port. *) val get_endpoint : string list -> string -(** [get_base_dir] returns the value associated to the [--base-dir] argument - amonsgst [args]. *) +(** [get_base_dir args] returns the value associated to the [--base-dir] argument + amongst [args]. *) val get_base_dir : string list -> string option -- GitLab From 0e6a61e478a1bf7b14ef446382dc16fb73ed9ff7 Mon Sep 17 00:00:00 2001 From: Gabriel Moise Date: Tue, 1 Apr 2025 16:31:05 +0100 Subject: [PATCH 08/20] Agnostic_baker: Rename Configuration module to Cli --- .../{configuration.ml => cli.ml} | 7 +- src/lib_agnostic_baker/commands.ml | 8 +- src/lib_agnostic_baker/configuration.mli | 92 ------------------- src/lib_agnostic_baker/protocol_plugin_sig.ml | 2 +- .../lib_agnostic_baker/baker_args_parser.ml | 2 +- .../lib_agnostic_baker/baker_args_parser.mli | 2 +- .../lib_agnostic_baker/baker_args_parser.ml | 2 +- .../lib_agnostic_baker/baker_args_parser.mli | 2 +- .../lib_agnostic_baker/baker_args_parser.ml | 2 +- .../lib_agnostic_baker/baker_args_parser.mli | 2 +- 10 files changed, 17 insertions(+), 104 deletions(-) rename src/lib_agnostic_baker/{configuration.ml => cli.ml} (98%) delete mode 100644 src/lib_agnostic_baker/configuration.mli diff --git a/src/lib_agnostic_baker/configuration.ml b/src/lib_agnostic_baker/cli.ml similarity index 98% rename from src/lib_agnostic_baker/configuration.ml rename to src/lib_agnostic_baker/cli.ml index b627e9a1c311..58305dc73acd 100644 --- a/src/lib_agnostic_baker/configuration.ml +++ b/src/lib_agnostic_baker/cli.ml @@ -357,7 +357,12 @@ let directory_parameter = if not exists then failwith "Directory doesn't exist: '%s'" p else return p) -let sources_param = +let sources_param : + ( Signature.Public_key_hash.t list -> + Tezos_client_base.Client_context.full -> + unit Error_monad.tzresult Lwt.t, + Tezos_client_base.Client_context.full ) + Tezos_clic.params = Tezos_clic.seq_of_param (Tezos_client_base.Client_keys.Public_key_hash.source_param ~name:"baker" diff --git a/src/lib_agnostic_baker/commands.ml b/src/lib_agnostic_baker/commands.ml index 71973ebb29a3..10b235075d49 100644 --- a/src/lib_agnostic_baker/commands.ml +++ b/src/lib_agnostic_baker/commands.ml @@ -8,7 +8,7 @@ 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 + let configuration = Cli.create_config args in Plugin.Baker_commands_helpers.run_baker ~configuration ~baking_mode @@ -17,7 +17,7 @@ let run_with_local_node (module Plugin : Protocol_plugin_sig.S) args let run_remotely (module Plugin : Protocol_plugin_sig.S) args sources cctxt = let baking_mode = None in - let configuration = Configuration.create_config args in + let configuration = Cli.create_config args in Plugin.Baker_commands_helpers.run_baker ~configuration ~baking_mode @@ -26,11 +26,11 @@ let run_remotely (module Plugin : Protocol_plugin_sig.S) args sources cctxt = let run_vdf (module Plugin : Protocol_plugin_sig.S) (pidfile, keep_alive) cctxt = - Configuration.may_lock_pidfile pidfile @@ fun () -> + Cli.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 Cli in let open Tezos_clic in let group = { diff --git a/src/lib_agnostic_baker/configuration.mli b/src/lib_agnostic_baker/configuration.mli deleted file mode 100644 index 92edf903dab0..000000000000 --- a/src/lib_agnostic_baker/configuration.mli +++ /dev/null @@ -1,92 +0,0 @@ -(*****************************************************************************) -(* *) -(* SPDX-License-Identifier: MIT *) -(* Copyright (c) 2025 Trilitech *) -(* *) -(*****************************************************************************) - -val pidfile_arg : - (string option, Tezos_client_base.Client_context.full) Tezos_clic.arg - -val may_lock_pidfile : - string option -> - (unit -> 'a Error_monad.tzresult Lwt.t) -> - 'a Error_monad.tzresult Lwt.t - -val keep_alive_arg : - (bool, Tezos_client_base.Client_context.full) Tezos_clic.arg - -val http_headers_env_variable : string - -val http_headers : (string * string) list option - -val baker_args : - ( string option - * bool - * string option - * int64 - * Q.t - * Q.t - * int option - * bool - * string option - * string option - * string option - * Uri.t option - * Uri.t option - * bool - * bool - * Q.t option - * Q.t option, - Tezos_client_base.Client_context.full ) - Tezos_clic.options - -val directory_parameter : - (string, Tezos_client_base.Client_context.full) Tezos_clic.parameter - -val sources_param : - ( Tezos_crypto.Signature.Public_key_hash.t list -> - Tezos_client_base.Client_context.full -> - unit Error_monad.tzresult Lwt.t, - Tezos_client_base.Client_context.full ) - Tezos_clic.params - -type t = { - pidfile : string option; - node_version_check_bypass : bool; - node_version_allowed : string option; - minimal_fees : int64; - minimal_nanotez_per_gas_unit : Q.t; - minimal_nanotez_per_byte : Q.t; - force_apply_from_round : int option; - keep_alive : bool; - liquidity_baking_vote : string option; - adaptive_issuance_vote : string option; - per_block_vote_file : string option; - extra_operations : Uri.t option; - dal_node_endpoint : Uri.t option; - without_dal : bool; - state_recorder : bool; - pre_emptive_forge_time : Q.t option; - remote_calls_timeout : Q.t option; -} - -val create_config : - string option - * bool - * string option - * int64 - * Q.t - * Q.t - * int option - * bool - * string option - * string option - * string option - * Uri.t option - * Uri.t option - * bool - * bool - * Q.t option - * Q.t option -> - t diff --git a/src/lib_agnostic_baker/protocol_plugin_sig.ml b/src/lib_agnostic_baker/protocol_plugin_sig.ml index a2f73794b821..70c5abcf12c9 100644 --- a/src/lib_agnostic_baker/protocol_plugin_sig.ml +++ b/src/lib_agnostic_baker/protocol_plugin_sig.ml @@ -16,7 +16,7 @@ module type BAKER_COMMANDS_HELPERS = sig plugin, but the structure of the list of arguments will not grow or shrink, to prevent incompatibilities at migrations. *) val run_baker : - configuration:Configuration.t -> + configuration:Cli.t -> baking_mode:string option -> sources:Tezos_crypto.Signature.public_key_hash list -> cctxt:Tezos_client_base.Client_context.full -> diff --git a/src/proto_021_PsQuebec/lib_agnostic_baker/baker_args_parser.ml b/src/proto_021_PsQuebec/lib_agnostic_baker/baker_args_parser.ml index 764f7803957a..2d3fbaf6c8bc 100644 --- a/src/proto_021_PsQuebec/lib_agnostic_baker/baker_args_parser.ml +++ b/src/proto_021_PsQuebec/lib_agnostic_baker/baker_args_parser.ml @@ -5,7 +5,7 @@ (* *) (*****************************************************************************) -open Configuration +open Cli open Protocol.Alpha_context (** [parse_minimal_fees] parses integer valued fees to [Tez] values. *) diff --git a/src/proto_021_PsQuebec/lib_agnostic_baker/baker_args_parser.mli b/src/proto_021_PsQuebec/lib_agnostic_baker/baker_args_parser.mli index cd2af5efebd5..4c9dc00826ed 100644 --- a/src/proto_021_PsQuebec/lib_agnostic_baker/baker_args_parser.mli +++ b/src/proto_021_PsQuebec/lib_agnostic_baker/baker_args_parser.mli @@ -16,7 +16,7 @@ open Protocol.Alpha_context (** [parse_configuration] simply transforms a configuration record type into a tuple containing the same values. *) val parse_configuration : - Configuration.t -> + Cli.t -> string option * bool * string option diff --git a/src/proto_022_PsRiotum/lib_agnostic_baker/baker_args_parser.ml b/src/proto_022_PsRiotum/lib_agnostic_baker/baker_args_parser.ml index 764f7803957a..2d3fbaf6c8bc 100644 --- a/src/proto_022_PsRiotum/lib_agnostic_baker/baker_args_parser.ml +++ b/src/proto_022_PsRiotum/lib_agnostic_baker/baker_args_parser.ml @@ -5,7 +5,7 @@ (* *) (*****************************************************************************) -open Configuration +open Cli open Protocol.Alpha_context (** [parse_minimal_fees] parses integer valued fees to [Tez] values. *) diff --git a/src/proto_022_PsRiotum/lib_agnostic_baker/baker_args_parser.mli b/src/proto_022_PsRiotum/lib_agnostic_baker/baker_args_parser.mli index cd2af5efebd5..4c9dc00826ed 100644 --- a/src/proto_022_PsRiotum/lib_agnostic_baker/baker_args_parser.mli +++ b/src/proto_022_PsRiotum/lib_agnostic_baker/baker_args_parser.mli @@ -16,7 +16,7 @@ open Protocol.Alpha_context (** [parse_configuration] simply transforms a configuration record type into a tuple containing the same values. *) val parse_configuration : - Configuration.t -> + Cli.t -> string option * bool * string option diff --git a/src/proto_alpha/lib_agnostic_baker/baker_args_parser.ml b/src/proto_alpha/lib_agnostic_baker/baker_args_parser.ml index 3ea1a51283a9..6e82ecce099c 100644 --- a/src/proto_alpha/lib_agnostic_baker/baker_args_parser.ml +++ b/src/proto_alpha/lib_agnostic_baker/baker_args_parser.ml @@ -5,7 +5,7 @@ (* *) (*****************************************************************************) -open Configuration +open Cli open Protocol.Alpha_context (** [parse_minimal_fees] parses integer valued fees to [Tez] values. *) diff --git a/src/proto_alpha/lib_agnostic_baker/baker_args_parser.mli b/src/proto_alpha/lib_agnostic_baker/baker_args_parser.mli index 9e58b64f5ef3..f58a59caa13e 100644 --- a/src/proto_alpha/lib_agnostic_baker/baker_args_parser.mli +++ b/src/proto_alpha/lib_agnostic_baker/baker_args_parser.mli @@ -16,7 +16,7 @@ open Protocol.Alpha_context (** [parse_configuration] simply transforms a configuration record type into a tuple containing the same values. *) val parse_configuration : - Configuration.t -> + Cli.t -> string option * bool * string option -- GitLab From e3a40d74974574848462295255fa2fa56271d4ee Mon Sep 17 00:00:00 2001 From: Gabriel Moise Date: Tue, 1 Apr 2025 16:42:29 +0100 Subject: [PATCH 09/20] Agnostic_baker: Refactor baker commands into separate functions --- src/lib_agnostic_baker/commands.ml | 85 +++++++++++++++++------------- 1 file changed, 49 insertions(+), 36 deletions(-) diff --git a/src/lib_agnostic_baker/commands.ml b/src/lib_agnostic_baker/commands.ml index 10b235075d49..0e28b8453e93 100644 --- a/src/lib_agnostic_baker/commands.ml +++ b/src/lib_agnostic_baker/commands.ml @@ -5,6 +5,12 @@ (* *) (*****************************************************************************) +let group = + { + Tezos_clic.name = "delegate.baker"; + title = "Commands related to the agnostic baker daemon"; + } + 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 @@ -15,6 +21,23 @@ let run_with_local_node (module Plugin : Protocol_plugin_sig.S) args ~sources ~cctxt +let run_with_local_node_command ?plugin () = + let open Cli in + let open Tezos_clic in + command + ~group + ~desc:"Launch the baker daemon." + baker_args + (prefixes ["run"; "with"; "local"; "node"] + @@ param + ~name:"node_data_path" + ~desc:"Path to the node data directory (e.g. $HOME/.tezos-node)" + directory_parameter + @@ sources_param) + (match plugin with + | Some plugin -> run_with_local_node plugin + | None -> fun _ _ _ _ -> Lwt_result_syntax.return_unit) + let run_remotely (module Plugin : Protocol_plugin_sig.S) args sources cctxt = let baking_mode = None in let configuration = Cli.create_config args in @@ -24,48 +47,38 @@ let run_remotely (module Plugin : Protocol_plugin_sig.S) args sources cctxt = ~sources ~cctxt +let run_remotely_command ?plugin () = + let open Cli in + let open Tezos_clic in + command + ~group + ~desc:"Launch the baker daemon using RPCs only." + baker_args + (prefixes ["run"; "remotely"] @@ sources_param) + (match plugin with + | Some plugin -> run_remotely plugin + | None -> fun _ _ _ -> Lwt_result_syntax.return_unit) + let run_vdf (module Plugin : Protocol_plugin_sig.S) (pidfile, keep_alive) cctxt = Cli.may_lock_pidfile pidfile @@ fun () -> Plugin.Baker_commands_helpers.run_vdf_daemon ~cctxt ~keep_alive -let baker_commands ?plugin () = +let run_vdf_command ?plugin () = let open Cli in let open Tezos_clic in - let group = - { - name = "delegate.baker"; - title = "Commands related to the agnostic baker daemon."; - } - in + command + ~group + ~desc:"Launch the VDF daemon" + (args2 pidfile_arg keep_alive_arg) + (prefixes ["run"; "vdf"] @@ stop) + (match plugin with + | Some plugin -> run_vdf plugin + | None -> fun _ _ -> Lwt_result_syntax.return_unit) + +let baker_commands ?plugin () = [ - command - ~group - ~desc:"Launch the baker daemon." - baker_args - (prefixes ["run"; "with"; "local"; "node"] - @@ param - ~name:"node_data_path" - ~desc:"Path to the node data directory (e.g. $HOME/.tezos-node)" - directory_parameter - @@ sources_param) - (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) - (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) - (match plugin with - | Some plugin -> run_vdf plugin - | None -> fun _ _ -> Lwt_result_syntax.return_unit); + run_with_local_node_command ?plugin (); + run_remotely_command ?plugin (); + run_vdf_command ?plugin (); ] -- GitLab From 8245990f8cda677f474cb3964f8f806a1c79fae8 Mon Sep 17 00:00:00 2001 From: Gabriel Moise Date: Tue, 1 Apr 2025 16:49:01 +0100 Subject: [PATCH 10/20] Agnostic_baker: Move baker_args from Cli to Commands --- src/lib_agnostic_baker/cli.ml | 20 -------------------- src/lib_agnostic_baker/commands.ml | 21 +++++++++++++++++++++ 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/lib_agnostic_baker/cli.ml b/src/lib_agnostic_baker/cli.ml index 58305dc73acd..523300c36074 100644 --- a/src/lib_agnostic_baker/cli.ml +++ b/src/lib_agnostic_baker/cli.ml @@ -329,26 +329,6 @@ let remote_calls_timeout_arg = try return (Q.of_string s) with _ -> failwith "remote-calls-timeout expected int or float.")) -let baker_args = - Tezos_clic.args17 - pidfile_arg - node_version_check_bypass_arg - node_version_allowed_arg - minimal_fees_arg - minimal_nanotez_per_gas_unit_arg - minimal_nanotez_per_byte_arg - force_apply_from_round_arg - keep_alive_arg - liquidity_baking_toggle_vote_arg - adaptive_issuance_vote_arg - per_block_vote_file_arg - operations_arg - dal_node_endpoint_arg - without_dal_arg - state_recorder_switch_arg - pre_emptive_forge_time_arg - remote_calls_timeout_arg - let directory_parameter = let open Lwt_result_syntax in Tezos_clic.parameter diff --git a/src/lib_agnostic_baker/commands.ml b/src/lib_agnostic_baker/commands.ml index 0e28b8453e93..df3c107692bc 100644 --- a/src/lib_agnostic_baker/commands.ml +++ b/src/lib_agnostic_baker/commands.ml @@ -11,6 +11,27 @@ let group = title = "Commands related to the agnostic baker daemon"; } +let baker_args = + let open Cli in + Tezos_clic.args17 + pidfile_arg + node_version_check_bypass_arg + node_version_allowed_arg + minimal_fees_arg + minimal_nanotez_per_gas_unit_arg + minimal_nanotez_per_byte_arg + force_apply_from_round_arg + keep_alive_arg + liquidity_baking_toggle_vote_arg + adaptive_issuance_vote_arg + per_block_vote_file_arg + operations_arg + dal_node_endpoint_arg + without_dal_arg + state_recorder_switch_arg + pre_emptive_forge_time_arg + remote_calls_timeout_arg + 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 -- GitLab From c05197042b0df075c0aba7ff21f27cbbd818c271 Mon Sep 17 00:00:00 2001 From: Gabriel Moise Date: Thu, 3 Apr 2025 12:18:47 +0200 Subject: [PATCH 11/20] Agnostic_baker: Remove configuration commands borrowed from client --- src/lib_agnostic_baker/agnostic_baker_config.ml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/lib_agnostic_baker/agnostic_baker_config.ml b/src/lib_agnostic_baker/agnostic_baker_config.ml index 8a7524c646ca..d2fe3083b4f7 100644 --- a/src/lib_agnostic_baker/agnostic_baker_config.ml +++ b/src/lib_agnostic_baker/agnostic_baker_config.ml @@ -11,3 +11,7 @@ include Tezos_client_base_unix.Daemon_config (* All logging must be centralised in a single place. *) let default_daily_logs_path = Parameters.default_daily_logs_path + +let clic_commands ~base_dir:_ ~config_commands:_ ~builtin_commands + ~other_commands ~require_auth:_ = + builtin_commands @ other_commands -- GitLab From 548f48205786a51854669ad109cd0ae97c99b87a Mon Sep 17 00:00:00 2001 From: Gabriel Moise Date: Wed, 2 Apr 2025 12:32:40 +0100 Subject: [PATCH 12/20] Agnostic_baker: Introduce new Configuration module --- src/lib_agnostic_baker/cli.ml | 59 ----------------- src/lib_agnostic_baker/commands.ml | 4 +- src/lib_agnostic_baker/configuration.ml | 66 +++++++++++++++++++ src/lib_agnostic_baker/protocol_plugin_sig.ml | 2 +- .../lib_agnostic_baker/baker_args_parser.ml | 39 +++++------ .../lib_agnostic_baker/baker_args_parser.mli | 2 +- .../lib_agnostic_baker/baker_args_parser.ml | 39 +++++------ .../lib_agnostic_baker/baker_args_parser.mli | 2 +- .../lib_agnostic_baker/baker_args_parser.ml | 39 +++++------ .../lib_agnostic_baker/baker_args_parser.mli | 2 +- 10 files changed, 132 insertions(+), 122 deletions(-) create mode 100644 src/lib_agnostic_baker/configuration.ml diff --git a/src/lib_agnostic_baker/cli.ml b/src/lib_agnostic_baker/cli.ml index 523300c36074..2e4230093a4e 100644 --- a/src/lib_agnostic_baker/cli.ml +++ b/src/lib_agnostic_baker/cli.ml @@ -349,62 +349,3 @@ let sources_param : ~desc: "name of the delegate owning the attestation/baking right or name of \ the consensus key signing on the delegate's behalf") - -type t = { - pidfile : string option; - node_version_check_bypass : bool; - node_version_allowed : string option; - minimal_fees : int64; - minimal_nanotez_per_gas_unit : Q.t; - minimal_nanotez_per_byte : Q.t; - force_apply_from_round : int option; - keep_alive : bool; - liquidity_baking_vote : string option; - adaptive_issuance_vote : string option; - per_block_vote_file : string option; - extra_operations : Uri.t option; - dal_node_endpoint : Uri.t option; - without_dal : bool; - state_recorder : bool; - pre_emptive_forge_time : Q.t option; - remote_calls_timeout : Q.t option; -} - -(** Create the configuration from the given arguments. *) -let create_config - ( pidfile, - node_version_check_bypass, - node_version_allowed, - minimal_fees, - minimal_nanotez_per_gas_unit, - minimal_nanotez_per_byte, - force_apply_from_round, - keep_alive, - liquidity_baking_vote, - adaptive_issuance_vote, - per_block_vote_file, - extra_operations, - dal_node_endpoint, - without_dal, - state_recorder, - pre_emptive_forge_time, - remote_calls_timeout ) = - { - pidfile; - node_version_check_bypass; - node_version_allowed; - minimal_fees; - minimal_nanotez_per_gas_unit; - minimal_nanotez_per_byte; - force_apply_from_round; - keep_alive; - liquidity_baking_vote; - adaptive_issuance_vote; - per_block_vote_file; - extra_operations; - dal_node_endpoint; - without_dal; - state_recorder; - pre_emptive_forge_time; - remote_calls_timeout; - } diff --git a/src/lib_agnostic_baker/commands.ml b/src/lib_agnostic_baker/commands.ml index df3c107692bc..a3b6d5004d6d 100644 --- a/src/lib_agnostic_baker/commands.ml +++ b/src/lib_agnostic_baker/commands.ml @@ -35,7 +35,7 @@ let baker_args = 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 = Cli.create_config args in + let configuration = Configuration.Cli.configuration_from_args args in Plugin.Baker_commands_helpers.run_baker ~configuration ~baking_mode @@ -61,7 +61,7 @@ let run_with_local_node_command ?plugin () = let run_remotely (module Plugin : Protocol_plugin_sig.S) args sources cctxt = let baking_mode = None in - let configuration = Cli.create_config args in + let configuration = Configuration.Cli.configuration_from_args args in Plugin.Baker_commands_helpers.run_baker ~configuration ~baking_mode diff --git a/src/lib_agnostic_baker/configuration.ml b/src/lib_agnostic_baker/configuration.ml new file mode 100644 index 000000000000..5ac5ec034bd7 --- /dev/null +++ b/src/lib_agnostic_baker/configuration.ml @@ -0,0 +1,66 @@ +(*****************************************************************************) +(* *) +(* SPDX-License-Identifier: MIT *) +(* Copyright (c) 2025 Trilitech *) +(* *) +(*****************************************************************************) + +type t = { + pidfile : string option; + node_version_check_bypass : bool; + node_version_allowed : string option; + minimal_fees : int64; + minimal_nanotez_per_gas_unit : Q.t; + minimal_nanotez_per_byte : Q.t; + force_apply_from_round : int option; + keep_alive : bool; + liquidity_baking_vote : string option; + adaptive_issuance_vote : string option; + per_block_vote_file : string option; + extra_operations : Uri.t option; + dal_node_endpoint : Uri.t option; + without_dal : bool; + state_recorder : bool; + pre_emptive_forge_time : Q.t option; + remote_calls_timeout : Q.t option; +} + +module Cli = struct + let configuration_from_args + ( pidfile, + node_version_check_bypass, + node_version_allowed, + minimal_fees, + minimal_nanotez_per_gas_unit, + minimal_nanotez_per_byte, + force_apply_from_round, + keep_alive, + liquidity_baking_vote, + adaptive_issuance_vote, + per_block_vote_file, + extra_operations, + dal_node_endpoint, + without_dal, + state_recorder, + pre_emptive_forge_time, + remote_calls_timeout ) = + { + pidfile; + node_version_check_bypass; + node_version_allowed; + minimal_fees; + minimal_nanotez_per_gas_unit; + minimal_nanotez_per_byte; + force_apply_from_round; + keep_alive; + liquidity_baking_vote; + adaptive_issuance_vote; + per_block_vote_file; + extra_operations; + dal_node_endpoint; + without_dal; + state_recorder; + pre_emptive_forge_time; + remote_calls_timeout; + } +end diff --git a/src/lib_agnostic_baker/protocol_plugin_sig.ml b/src/lib_agnostic_baker/protocol_plugin_sig.ml index 70c5abcf12c9..a2f73794b821 100644 --- a/src/lib_agnostic_baker/protocol_plugin_sig.ml +++ b/src/lib_agnostic_baker/protocol_plugin_sig.ml @@ -16,7 +16,7 @@ module type BAKER_COMMANDS_HELPERS = sig plugin, but the structure of the list of arguments will not grow or shrink, to prevent incompatibilities at migrations. *) val run_baker : - configuration:Cli.t -> + configuration:Configuration.t -> baking_mode:string option -> sources:Tezos_crypto.Signature.public_key_hash list -> cctxt:Tezos_client_base.Client_context.full -> diff --git a/src/proto_021_PsQuebec/lib_agnostic_baker/baker_args_parser.ml b/src/proto_021_PsQuebec/lib_agnostic_baker/baker_args_parser.ml index 2d3fbaf6c8bc..8ae0fb65568d 100644 --- a/src/proto_021_PsQuebec/lib_agnostic_baker/baker_args_parser.ml +++ b/src/proto_021_PsQuebec/lib_agnostic_baker/baker_args_parser.ml @@ -37,25 +37,26 @@ let parse_state_recorder state_recorder = if state_recorder then Baking_configuration.Filesystem else Memory let parse_configuration - { - pidfile; - node_version_check_bypass; - node_version_allowed; - minimal_fees; - minimal_nanotez_per_gas_unit; - minimal_nanotez_per_byte; - force_apply_from_round; - keep_alive; - liquidity_baking_vote; - adaptive_issuance_vote; - per_block_vote_file; - extra_operations; - dal_node_endpoint; - without_dal; - state_recorder; - pre_emptive_forge_time; - remote_calls_timeout; - } = + Configuration. + { + pidfile; + node_version_check_bypass; + node_version_allowed; + minimal_fees; + minimal_nanotez_per_gas_unit; + minimal_nanotez_per_byte; + force_apply_from_round; + keep_alive; + liquidity_baking_vote; + adaptive_issuance_vote; + per_block_vote_file; + extra_operations; + dal_node_endpoint; + without_dal; + state_recorder; + pre_emptive_forge_time; + remote_calls_timeout; + } = ( pidfile, node_version_check_bypass, node_version_allowed, diff --git a/src/proto_021_PsQuebec/lib_agnostic_baker/baker_args_parser.mli b/src/proto_021_PsQuebec/lib_agnostic_baker/baker_args_parser.mli index 4c9dc00826ed..cd2af5efebd5 100644 --- a/src/proto_021_PsQuebec/lib_agnostic_baker/baker_args_parser.mli +++ b/src/proto_021_PsQuebec/lib_agnostic_baker/baker_args_parser.mli @@ -16,7 +16,7 @@ open Protocol.Alpha_context (** [parse_configuration] simply transforms a configuration record type into a tuple containing the same values. *) val parse_configuration : - Cli.t -> + Configuration.t -> string option * bool * string option diff --git a/src/proto_022_PsRiotum/lib_agnostic_baker/baker_args_parser.ml b/src/proto_022_PsRiotum/lib_agnostic_baker/baker_args_parser.ml index 2d3fbaf6c8bc..8ae0fb65568d 100644 --- a/src/proto_022_PsRiotum/lib_agnostic_baker/baker_args_parser.ml +++ b/src/proto_022_PsRiotum/lib_agnostic_baker/baker_args_parser.ml @@ -37,25 +37,26 @@ let parse_state_recorder state_recorder = if state_recorder then Baking_configuration.Filesystem else Memory let parse_configuration - { - pidfile; - node_version_check_bypass; - node_version_allowed; - minimal_fees; - minimal_nanotez_per_gas_unit; - minimal_nanotez_per_byte; - force_apply_from_round; - keep_alive; - liquidity_baking_vote; - adaptive_issuance_vote; - per_block_vote_file; - extra_operations; - dal_node_endpoint; - without_dal; - state_recorder; - pre_emptive_forge_time; - remote_calls_timeout; - } = + Configuration. + { + pidfile; + node_version_check_bypass; + node_version_allowed; + minimal_fees; + minimal_nanotez_per_gas_unit; + minimal_nanotez_per_byte; + force_apply_from_round; + keep_alive; + liquidity_baking_vote; + adaptive_issuance_vote; + per_block_vote_file; + extra_operations; + dal_node_endpoint; + without_dal; + state_recorder; + pre_emptive_forge_time; + remote_calls_timeout; + } = ( pidfile, node_version_check_bypass, node_version_allowed, diff --git a/src/proto_022_PsRiotum/lib_agnostic_baker/baker_args_parser.mli b/src/proto_022_PsRiotum/lib_agnostic_baker/baker_args_parser.mli index 4c9dc00826ed..cd2af5efebd5 100644 --- a/src/proto_022_PsRiotum/lib_agnostic_baker/baker_args_parser.mli +++ b/src/proto_022_PsRiotum/lib_agnostic_baker/baker_args_parser.mli @@ -16,7 +16,7 @@ open Protocol.Alpha_context (** [parse_configuration] simply transforms a configuration record type into a tuple containing the same values. *) val parse_configuration : - Cli.t -> + Configuration.t -> string option * bool * string option diff --git a/src/proto_alpha/lib_agnostic_baker/baker_args_parser.ml b/src/proto_alpha/lib_agnostic_baker/baker_args_parser.ml index 6e82ecce099c..48ccc5bdab4e 100644 --- a/src/proto_alpha/lib_agnostic_baker/baker_args_parser.ml +++ b/src/proto_alpha/lib_agnostic_baker/baker_args_parser.ml @@ -37,25 +37,26 @@ let parse_state_recorder state_recorder = if state_recorder then Baking_configuration.Filesystem else Memory let parse_configuration - { - pidfile; - node_version_check_bypass; - node_version_allowed; - minimal_fees; - minimal_nanotez_per_gas_unit; - minimal_nanotez_per_byte; - force_apply_from_round; - keep_alive; - liquidity_baking_vote; - adaptive_issuance_vote; - per_block_vote_file; - extra_operations; - dal_node_endpoint; - without_dal; - state_recorder; - pre_emptive_forge_time; - remote_calls_timeout; - } = + Configuration. + { + pidfile; + node_version_check_bypass; + node_version_allowed; + minimal_fees; + minimal_nanotez_per_gas_unit; + minimal_nanotez_per_byte; + force_apply_from_round; + keep_alive; + liquidity_baking_vote; + adaptive_issuance_vote; + per_block_vote_file; + extra_operations; + dal_node_endpoint; + without_dal; + state_recorder; + pre_emptive_forge_time; + remote_calls_timeout; + } = ( pidfile, node_version_check_bypass, node_version_allowed, diff --git a/src/proto_alpha/lib_agnostic_baker/baker_args_parser.mli b/src/proto_alpha/lib_agnostic_baker/baker_args_parser.mli index f58a59caa13e..9e58b64f5ef3 100644 --- a/src/proto_alpha/lib_agnostic_baker/baker_args_parser.mli +++ b/src/proto_alpha/lib_agnostic_baker/baker_args_parser.mli @@ -16,7 +16,7 @@ open Protocol.Alpha_context (** [parse_configuration] simply transforms a configuration record type into a tuple containing the same values. *) val parse_configuration : - Cli.t -> + Configuration.t -> string option * bool * string option -- GitLab From 4ab6bc5413719b3f194ee7d232d7f1dea6dc2264 Mon Sep 17 00:00:00 2001 From: Gabriel Moise Date: Wed, 2 Apr 2025 13:28:44 +0100 Subject: [PATCH 13/20] Agnostic_baker: Refactor run_baker function --- .../lib_agnostic_baker/baker_args_parser.ml | 39 ------ .../lib_agnostic_baker/baker_args_parser.mli | 47 -------- .../baker_commands_helpers.ml | 30 ++++- .../lib_delegate/baking_commands.ml | 111 ++++++++++++++---- .../lib_delegate/baking_commands.mli | 40 ++++--- .../lib_agnostic_baker/baker_args_parser.ml | 39 ------ .../lib_agnostic_baker/baker_args_parser.mli | 47 -------- .../baker_commands_helpers.ml | 30 ++++- .../lib_delegate/baking_commands.ml | 111 ++++++++++++++---- .../lib_delegate/baking_commands.mli | 40 ++++--- .../lib_agnostic_baker/baker_args_parser.ml | 39 ------ .../lib_agnostic_baker/baker_args_parser.mli | 40 ------- .../baker_commands_helpers.ml | 28 ++++- .../lib_delegate/baking_commands.ml | 111 ++++++++++++++---- .../lib_delegate/baking_commands.mli | 40 ++++--- 15 files changed, 401 insertions(+), 391 deletions(-) delete mode 100644 src/proto_021_PsQuebec/lib_agnostic_baker/baker_args_parser.mli delete mode 100644 src/proto_022_PsRiotum/lib_agnostic_baker/baker_args_parser.mli delete mode 100644 src/proto_alpha/lib_agnostic_baker/baker_args_parser.mli diff --git a/src/proto_021_PsQuebec/lib_agnostic_baker/baker_args_parser.ml b/src/proto_021_PsQuebec/lib_agnostic_baker/baker_args_parser.ml index 8ae0fb65568d..84a68fb5dbba 100644 --- a/src/proto_021_PsQuebec/lib_agnostic_baker/baker_args_parser.ml +++ b/src/proto_021_PsQuebec/lib_agnostic_baker/baker_args_parser.ml @@ -36,45 +36,6 @@ let parse_operations = let parse_state_recorder state_recorder = if state_recorder then Baking_configuration.Filesystem else Memory -let parse_configuration - Configuration. - { - pidfile; - node_version_check_bypass; - node_version_allowed; - minimal_fees; - minimal_nanotez_per_gas_unit; - minimal_nanotez_per_byte; - force_apply_from_round; - keep_alive; - liquidity_baking_vote; - adaptive_issuance_vote; - per_block_vote_file; - extra_operations; - dal_node_endpoint; - without_dal; - state_recorder; - pre_emptive_forge_time; - remote_calls_timeout; - } = - ( pidfile, - node_version_check_bypass, - node_version_allowed, - parse_minimal_fees minimal_fees, - minimal_nanotez_per_gas_unit, - minimal_nanotez_per_byte, - force_apply_from_round, - keep_alive, - parse_per_block_vote liquidity_baking_vote, - parse_per_block_vote adaptive_issuance_vote, - per_block_vote_file, - parse_operations extra_operations, - dal_node_endpoint, - without_dal, - parse_state_recorder state_recorder, - pre_emptive_forge_time, - remote_calls_timeout ) - let parse_baking_mode baking_mode = match baking_mode with | Some local_data_dir_path -> Baking_commands.Local {local_data_dir_path} diff --git a/src/proto_021_PsQuebec/lib_agnostic_baker/baker_args_parser.mli b/src/proto_021_PsQuebec/lib_agnostic_baker/baker_args_parser.mli deleted file mode 100644 index cd2af5efebd5..000000000000 --- a/src/proto_021_PsQuebec/lib_agnostic_baker/baker_args_parser.mli +++ /dev/null @@ -1,47 +0,0 @@ -(*****************************************************************************) -(* *) -(* SPDX-License-Identifier: MIT *) -(* Copyright (c) 2025 Trilitech *) -(* *) -(*****************************************************************************) - -(** This module offers transformation tools from protocol-independent types to - protocol specific ones. In this particular instance, the agnostic baker CLI - arguments are defined in a single place, outside the protocol code, and then - they are mapped, depending on the protocol context. -*) - -open Protocol.Alpha_context - -(** [parse_configuration] simply transforms a configuration record type into a - tuple containing the same values. *) -val parse_configuration : - Configuration.t -> - string option - * bool - * string option - * Tez.t - * Q.t - * Q.t - * int option - * bool - * Per_block_votes.per_block_vote option - * Per_block_votes.per_block_vote option - * string option - * Baking_configuration.Operations_source.t option - * Uri.t option - * bool - * Baking_configuration.state_recorder_config - * Q.t option - * Q.t option - -(** [parse_baking_mode baking_mode] maps a optional value to a [Local] or [Remote] - baking mode option. *) -val parse_baking_mode : string option -> Baking_commands.baking_mode - -(** [parse_sources sources] maps all public key hashes to the version expected - by the protocol-specific baking main running function. *) -val parse_sources : - Tezos_base.TzPervasives.Signature.public_key_hash list -> - (Tezos_base.TzPervasives.Signature.V1.public_key_hash list, tztrace) result - Lwt.t diff --git a/src/proto_021_PsQuebec/lib_agnostic_baker/baker_commands_helpers.ml b/src/proto_021_PsQuebec/lib_agnostic_baker/baker_commands_helpers.ml index 89fe030096a9..4927dd25f810 100644 --- a/src/proto_021_PsQuebec/lib_agnostic_baker/baker_commands_helpers.ml +++ b/src/proto_021_PsQuebec/lib_agnostic_baker/baker_commands_helpers.ml @@ -7,11 +7,33 @@ let run_baker ~configuration ~baking_mode ~sources ~cctxt = let open Lwt_result_syntax in - let args = Baker_args_parser.parse_configuration configuration in - let baking_mode = Baker_args_parser.parse_baking_mode baking_mode in - let* sources = Baker_args_parser.parse_sources sources in + let open Baker_args_parser in + let open Configuration in + let* sources = parse_sources sources in let cctxt = new Protocol_client_context.wrap_full cctxt in - Baking_commands.run_baker args baking_mode sources cctxt + Baking_commands.run_baker + ~pidfile:configuration.pidfile + ~node_version_check_bypass:configuration.node_version_check_bypass + ~node_version_allowed:configuration.node_version_allowed + ~minimal_fees:(parse_minimal_fees configuration.minimal_fees) + ~minimal_nanotez_per_gas_unit:configuration.minimal_nanotez_per_gas_unit + ~minimal_nanotez_per_byte:configuration.minimal_nanotez_per_byte + ~force_apply_from_round:configuration.force_apply_from_round + ~keep_alive:configuration.keep_alive + ~liquidity_baking_vote: + (parse_per_block_vote configuration.liquidity_baking_vote) + ~adaptive_issuance_vote: + (parse_per_block_vote configuration.adaptive_issuance_vote) + ~per_block_vote_file:configuration.per_block_vote_file + ~extra_operations:(parse_operations configuration.extra_operations) + ~dal_node_endpoint:configuration.dal_node_endpoint + ~without_dal:configuration.without_dal + ~state_recorder:(parse_state_recorder configuration.state_recorder) + ~pre_emptive_forge_time:configuration.pre_emptive_forge_time + ~remote_calls_timeout:configuration.remote_calls_timeout + ~baking_mode:(parse_baking_mode baking_mode) + ~sources + cctxt let run_vdf_daemon ~cctxt ~keep_alive = let cctxt = new Protocol_client_context.wrap_full cctxt in diff --git a/src/proto_021_PsQuebec/lib_delegate/baking_commands.ml b/src/proto_021_PsQuebec/lib_delegate/baking_commands.ml index c50621ba586f..8b48a9880d19 100644 --- a/src/proto_021_PsQuebec/lib_delegate/baking_commands.ml +++ b/src/proto_021_PsQuebec/lib_delegate/baking_commands.ml @@ -733,24 +733,12 @@ let baker_args = pre_emptive_forge_time_arg remote_calls_timeout_arg -let run_baker - ( pidfile, - node_version_check_bypass, - node_version_allowed, - minimal_fees, - minimal_nanotez_per_gas_unit, - minimal_nanotez_per_byte, - force_apply_from_round, - keep_alive, - liquidity_baking_vote, - adaptive_issuance_vote, - per_block_vote_file, - extra_operations, - dal_node_endpoint, - without_dal, - state_recorder, - pre_emptive_forge_time, - remote_calls_timeout ) baking_mode sources cctxt = +let run_baker ~pidfile ~node_version_check_bypass ~node_version_allowed + ~minimal_fees ~minimal_nanotez_per_gas_unit ~minimal_nanotez_per_byte + ~force_apply_from_round ~keep_alive ~liquidity_baking_vote + ~adaptive_issuance_vote ~per_block_vote_file ~extra_operations + ~dal_node_endpoint ~without_dal ~state_recorder ~pre_emptive_forge_time + ~remote_calls_timeout ~baking_mode ~sources cctxt = let open Lwt_result_syntax in may_lock_pidfile pidfile @@ fun () -> let* () = @@ -818,17 +806,92 @@ let baker_commands () : Protocol_client_context.full Tezos_clic.command list = ~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 = Local {local_data_dir_path} in - run_baker args baking_mode sources cctxt); + (fun ( pidfile, + node_version_check_bypass, + node_version_allowed, + minimal_fees, + minimal_nanotez_per_gas_unit, + minimal_nanotez_per_byte, + force_apply_from_round, + keep_alive, + liquidity_baking_vote, + adaptive_issuance_vote, + per_block_vote_file, + extra_operations, + dal_node_endpoint, + without_dal, + state_recorder, + pre_emptive_forge_time, + remote_calls_timeout ) + local_data_dir_path + sources + cctxt -> + run_baker + ~pidfile + ~node_version_check_bypass + ~node_version_allowed + ~minimal_fees + ~minimal_nanotez_per_gas_unit + ~minimal_nanotez_per_byte + ~force_apply_from_round + ~keep_alive + ~liquidity_baking_vote + ~adaptive_issuance_vote + ~per_block_vote_file + ~extra_operations + ~dal_node_endpoint + ~without_dal + ~state_recorder + ~pre_emptive_forge_time + ~remote_calls_timeout + ~baking_mode:(Local {local_data_dir_path}) + ~sources + cctxt); command ~group ~desc:"Launch the baker daemon using RPCs only." baker_args (prefixes ["run"; "remotely"] @@ sources_param) - (fun args sources cctxt -> - let baking_mode = Remote in - run_baker args baking_mode sources cctxt); + (fun ( pidfile, + node_version_check_bypass, + node_version_allowed, + minimal_fees, + minimal_nanotez_per_gas_unit, + minimal_nanotez_per_byte, + force_apply_from_round, + keep_alive, + liquidity_baking_vote, + adaptive_issuance_vote, + per_block_vote_file, + extra_operations, + dal_node_endpoint, + without_dal, + state_recorder, + pre_emptive_forge_time, + remote_calls_timeout ) + sources + cctxt -> + run_baker + ~pidfile + ~node_version_check_bypass + ~node_version_allowed + ~minimal_fees + ~minimal_nanotez_per_gas_unit + ~minimal_nanotez_per_byte + ~force_apply_from_round + ~keep_alive + ~liquidity_baking_vote + ~adaptive_issuance_vote + ~per_block_vote_file + ~extra_operations + ~dal_node_endpoint + ~without_dal + ~state_recorder + ~pre_emptive_forge_time + ~remote_calls_timeout + ~baking_mode:Remote + ~sources + cctxt); command ~group ~desc:"Launch the VDF daemon" diff --git a/src/proto_021_PsQuebec/lib_delegate/baking_commands.mli b/src/proto_021_PsQuebec/lib_delegate/baking_commands.mli index c808d3055330..dd3e1d3ee658 100644 --- a/src/proto_021_PsQuebec/lib_delegate/baking_commands.mli +++ b/src/proto_021_PsQuebec/lib_delegate/baking_commands.mli @@ -26,25 +26,27 @@ type baking_mode = Local of {local_data_dir_path : string} | Remote val run_baker : - string option - * bool - * string option - * Protocol.Alpha_context.Tez.t - * Q.t - * Q.t - * int option - * bool - * Protocol.Per_block_votes_repr.per_block_vote option - * Protocol.Per_block_votes_repr.per_block_vote option - * string option - * Baking_configuration.Operations_source.t option - * Uri.t option - * bool - * Baking_configuration.state_recorder_config - * Q.t option - * Q.t option -> - baking_mode -> - Environment.Signature.public_key_hash list -> + pidfile:string option -> + node_version_check_bypass:bool -> + node_version_allowed:string option -> + minimal_fees:Tezos_raw_protocol_021_PsQuebec.Alpha_context.Tez.t -> + minimal_nanotez_per_gas_unit:Q.t -> + minimal_nanotez_per_byte:Q.t -> + force_apply_from_round:int option -> + keep_alive:bool -> + liquidity_baking_vote: + Tezos_raw_protocol_021_PsQuebec.Per_block_votes_repr.per_block_vote option -> + adaptive_issuance_vote: + Tezos_raw_protocol_021_PsQuebec.Per_block_votes_repr.per_block_vote option -> + per_block_vote_file:string option -> + extra_operations:Baking_configuration.Operations_source.t option -> + dal_node_endpoint:Uri.t option -> + without_dal:bool -> + state_recorder:Baking_configuration.state_recorder_config -> + pre_emptive_forge_time:Q.t option -> + remote_calls_timeout:Q.t option -> + baking_mode:baking_mode -> + sources:Environment.Signature.public_key_hash list -> Protocol_client_context.full -> unit Error_monad.tzresult Lwt.t diff --git a/src/proto_022_PsRiotum/lib_agnostic_baker/baker_args_parser.ml b/src/proto_022_PsRiotum/lib_agnostic_baker/baker_args_parser.ml index 8ae0fb65568d..84a68fb5dbba 100644 --- a/src/proto_022_PsRiotum/lib_agnostic_baker/baker_args_parser.ml +++ b/src/proto_022_PsRiotum/lib_agnostic_baker/baker_args_parser.ml @@ -36,45 +36,6 @@ let parse_operations = let parse_state_recorder state_recorder = if state_recorder then Baking_configuration.Filesystem else Memory -let parse_configuration - Configuration. - { - pidfile; - node_version_check_bypass; - node_version_allowed; - minimal_fees; - minimal_nanotez_per_gas_unit; - minimal_nanotez_per_byte; - force_apply_from_round; - keep_alive; - liquidity_baking_vote; - adaptive_issuance_vote; - per_block_vote_file; - extra_operations; - dal_node_endpoint; - without_dal; - state_recorder; - pre_emptive_forge_time; - remote_calls_timeout; - } = - ( pidfile, - node_version_check_bypass, - node_version_allowed, - parse_minimal_fees minimal_fees, - minimal_nanotez_per_gas_unit, - minimal_nanotez_per_byte, - force_apply_from_round, - keep_alive, - parse_per_block_vote liquidity_baking_vote, - parse_per_block_vote adaptive_issuance_vote, - per_block_vote_file, - parse_operations extra_operations, - dal_node_endpoint, - without_dal, - parse_state_recorder state_recorder, - pre_emptive_forge_time, - remote_calls_timeout ) - let parse_baking_mode baking_mode = match baking_mode with | Some local_data_dir_path -> Baking_commands.Local {local_data_dir_path} diff --git a/src/proto_022_PsRiotum/lib_agnostic_baker/baker_args_parser.mli b/src/proto_022_PsRiotum/lib_agnostic_baker/baker_args_parser.mli deleted file mode 100644 index cd2af5efebd5..000000000000 --- a/src/proto_022_PsRiotum/lib_agnostic_baker/baker_args_parser.mli +++ /dev/null @@ -1,47 +0,0 @@ -(*****************************************************************************) -(* *) -(* SPDX-License-Identifier: MIT *) -(* Copyright (c) 2025 Trilitech *) -(* *) -(*****************************************************************************) - -(** This module offers transformation tools from protocol-independent types to - protocol specific ones. In this particular instance, the agnostic baker CLI - arguments are defined in a single place, outside the protocol code, and then - they are mapped, depending on the protocol context. -*) - -open Protocol.Alpha_context - -(** [parse_configuration] simply transforms a configuration record type into a - tuple containing the same values. *) -val parse_configuration : - Configuration.t -> - string option - * bool - * string option - * Tez.t - * Q.t - * Q.t - * int option - * bool - * Per_block_votes.per_block_vote option - * Per_block_votes.per_block_vote option - * string option - * Baking_configuration.Operations_source.t option - * Uri.t option - * bool - * Baking_configuration.state_recorder_config - * Q.t option - * Q.t option - -(** [parse_baking_mode baking_mode] maps a optional value to a [Local] or [Remote] - baking mode option. *) -val parse_baking_mode : string option -> Baking_commands.baking_mode - -(** [parse_sources sources] maps all public key hashes to the version expected - by the protocol-specific baking main running function. *) -val parse_sources : - Tezos_base.TzPervasives.Signature.public_key_hash list -> - (Tezos_base.TzPervasives.Signature.V1.public_key_hash list, tztrace) result - Lwt.t diff --git a/src/proto_022_PsRiotum/lib_agnostic_baker/baker_commands_helpers.ml b/src/proto_022_PsRiotum/lib_agnostic_baker/baker_commands_helpers.ml index 89fe030096a9..4927dd25f810 100644 --- a/src/proto_022_PsRiotum/lib_agnostic_baker/baker_commands_helpers.ml +++ b/src/proto_022_PsRiotum/lib_agnostic_baker/baker_commands_helpers.ml @@ -7,11 +7,33 @@ let run_baker ~configuration ~baking_mode ~sources ~cctxt = let open Lwt_result_syntax in - let args = Baker_args_parser.parse_configuration configuration in - let baking_mode = Baker_args_parser.parse_baking_mode baking_mode in - let* sources = Baker_args_parser.parse_sources sources in + let open Baker_args_parser in + let open Configuration in + let* sources = parse_sources sources in let cctxt = new Protocol_client_context.wrap_full cctxt in - Baking_commands.run_baker args baking_mode sources cctxt + Baking_commands.run_baker + ~pidfile:configuration.pidfile + ~node_version_check_bypass:configuration.node_version_check_bypass + ~node_version_allowed:configuration.node_version_allowed + ~minimal_fees:(parse_minimal_fees configuration.minimal_fees) + ~minimal_nanotez_per_gas_unit:configuration.minimal_nanotez_per_gas_unit + ~minimal_nanotez_per_byte:configuration.minimal_nanotez_per_byte + ~force_apply_from_round:configuration.force_apply_from_round + ~keep_alive:configuration.keep_alive + ~liquidity_baking_vote: + (parse_per_block_vote configuration.liquidity_baking_vote) + ~adaptive_issuance_vote: + (parse_per_block_vote configuration.adaptive_issuance_vote) + ~per_block_vote_file:configuration.per_block_vote_file + ~extra_operations:(parse_operations configuration.extra_operations) + ~dal_node_endpoint:configuration.dal_node_endpoint + ~without_dal:configuration.without_dal + ~state_recorder:(parse_state_recorder configuration.state_recorder) + ~pre_emptive_forge_time:configuration.pre_emptive_forge_time + ~remote_calls_timeout:configuration.remote_calls_timeout + ~baking_mode:(parse_baking_mode baking_mode) + ~sources + cctxt let run_vdf_daemon ~cctxt ~keep_alive = let cctxt = new Protocol_client_context.wrap_full cctxt in diff --git a/src/proto_022_PsRiotum/lib_delegate/baking_commands.ml b/src/proto_022_PsRiotum/lib_delegate/baking_commands.ml index 46b48fc5c7e3..168b85e1d686 100644 --- a/src/proto_022_PsRiotum/lib_delegate/baking_commands.ml +++ b/src/proto_022_PsRiotum/lib_delegate/baking_commands.ml @@ -746,24 +746,12 @@ let baker_args = pre_emptive_forge_time_arg remote_calls_timeout_arg -let run_baker - ( pidfile, - node_version_check_bypass, - node_version_allowed, - minimal_fees, - minimal_nanotez_per_gas_unit, - minimal_nanotez_per_byte, - force_apply_from_round, - keep_alive, - liquidity_baking_vote, - adaptive_issuance_vote, - per_block_vote_file, - extra_operations, - dal_node_endpoint, - without_dal, - state_recorder, - pre_emptive_forge_time, - remote_calls_timeout ) baking_mode sources cctxt = +let run_baker ~pidfile ~node_version_check_bypass ~node_version_allowed + ~minimal_fees ~minimal_nanotez_per_gas_unit ~minimal_nanotez_per_byte + ~force_apply_from_round ~keep_alive ~liquidity_baking_vote + ~adaptive_issuance_vote ~per_block_vote_file ~extra_operations + ~dal_node_endpoint ~without_dal ~state_recorder ~pre_emptive_forge_time + ~remote_calls_timeout ~baking_mode ~sources cctxt = let open Lwt_result_syntax in may_lock_pidfile pidfile @@ fun () -> let* () = @@ -831,17 +819,92 @@ let baker_commands () : Protocol_client_context.full Tezos_clic.command list = ~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 = Local {local_data_dir_path} in - run_baker args baking_mode sources cctxt); + (fun ( pidfile, + node_version_check_bypass, + node_version_allowed, + minimal_fees, + minimal_nanotez_per_gas_unit, + minimal_nanotez_per_byte, + force_apply_from_round, + keep_alive, + liquidity_baking_vote, + adaptive_issuance_vote, + per_block_vote_file, + extra_operations, + dal_node_endpoint, + without_dal, + state_recorder, + pre_emptive_forge_time, + remote_calls_timeout ) + local_data_dir_path + sources + cctxt -> + run_baker + ~pidfile + ~node_version_check_bypass + ~node_version_allowed + ~minimal_fees + ~minimal_nanotez_per_gas_unit + ~minimal_nanotez_per_byte + ~force_apply_from_round + ~keep_alive + ~liquidity_baking_vote + ~adaptive_issuance_vote + ~per_block_vote_file + ~extra_operations + ~dal_node_endpoint + ~without_dal + ~state_recorder + ~pre_emptive_forge_time + ~remote_calls_timeout + ~baking_mode:(Local {local_data_dir_path}) + ~sources + cctxt); command ~group ~desc:"Launch the baker daemon using RPCs only." baker_args (prefixes ["run"; "remotely"] @@ sources_param) - (fun args sources cctxt -> - let baking_mode = Remote in - run_baker args baking_mode sources cctxt); + (fun ( pidfile, + node_version_check_bypass, + node_version_allowed, + minimal_fees, + minimal_nanotez_per_gas_unit, + minimal_nanotez_per_byte, + force_apply_from_round, + keep_alive, + liquidity_baking_vote, + adaptive_issuance_vote, + per_block_vote_file, + extra_operations, + dal_node_endpoint, + without_dal, + state_recorder, + pre_emptive_forge_time, + remote_calls_timeout ) + sources + cctxt -> + run_baker + ~pidfile + ~node_version_check_bypass + ~node_version_allowed + ~minimal_fees + ~minimal_nanotez_per_gas_unit + ~minimal_nanotez_per_byte + ~force_apply_from_round + ~keep_alive + ~liquidity_baking_vote + ~adaptive_issuance_vote + ~per_block_vote_file + ~extra_operations + ~dal_node_endpoint + ~without_dal + ~state_recorder + ~pre_emptive_forge_time + ~remote_calls_timeout + ~baking_mode:Remote + ~sources + cctxt); command ~group ~desc:"Launch the VDF daemon" diff --git a/src/proto_022_PsRiotum/lib_delegate/baking_commands.mli b/src/proto_022_PsRiotum/lib_delegate/baking_commands.mli index c808d3055330..1ae49c6b400e 100644 --- a/src/proto_022_PsRiotum/lib_delegate/baking_commands.mli +++ b/src/proto_022_PsRiotum/lib_delegate/baking_commands.mli @@ -26,25 +26,27 @@ type baking_mode = Local of {local_data_dir_path : string} | Remote val run_baker : - string option - * bool - * string option - * Protocol.Alpha_context.Tez.t - * Q.t - * Q.t - * int option - * bool - * Protocol.Per_block_votes_repr.per_block_vote option - * Protocol.Per_block_votes_repr.per_block_vote option - * string option - * Baking_configuration.Operations_source.t option - * Uri.t option - * bool - * Baking_configuration.state_recorder_config - * Q.t option - * Q.t option -> - baking_mode -> - Environment.Signature.public_key_hash list -> + pidfile:string option -> + node_version_check_bypass:bool -> + node_version_allowed:string option -> + minimal_fees:Tezos_raw_protocol_022_PsRiotum.Alpha_context.Tez.t -> + minimal_nanotez_per_gas_unit:Q.t -> + minimal_nanotez_per_byte:Q.t -> + force_apply_from_round:int option -> + keep_alive:bool -> + liquidity_baking_vote: + Tezos_raw_protocol_022_PsRiotum.Per_block_votes_repr.per_block_vote option -> + adaptive_issuance_vote: + Tezos_raw_protocol_022_PsRiotum.Per_block_votes_repr.per_block_vote option -> + per_block_vote_file:string option -> + extra_operations:Baking_configuration.Operations_source.t option -> + dal_node_endpoint:Uri.t option -> + without_dal:bool -> + state_recorder:Baking_configuration.state_recorder_config -> + pre_emptive_forge_time:Q.t option -> + remote_calls_timeout:Q.t option -> + baking_mode:baking_mode -> + sources:Environment.Signature.public_key_hash list -> Protocol_client_context.full -> unit Error_monad.tzresult Lwt.t diff --git a/src/proto_alpha/lib_agnostic_baker/baker_args_parser.ml b/src/proto_alpha/lib_agnostic_baker/baker_args_parser.ml index 48ccc5bdab4e..daa0400300ad 100644 --- a/src/proto_alpha/lib_agnostic_baker/baker_args_parser.ml +++ b/src/proto_alpha/lib_agnostic_baker/baker_args_parser.ml @@ -36,45 +36,6 @@ let parse_operations = let parse_state_recorder state_recorder = if state_recorder then Baking_configuration.Filesystem else Memory -let parse_configuration - Configuration. - { - pidfile; - node_version_check_bypass; - node_version_allowed; - minimal_fees; - minimal_nanotez_per_gas_unit; - minimal_nanotez_per_byte; - force_apply_from_round; - keep_alive; - liquidity_baking_vote; - adaptive_issuance_vote; - per_block_vote_file; - extra_operations; - dal_node_endpoint; - without_dal; - state_recorder; - pre_emptive_forge_time; - remote_calls_timeout; - } = - ( pidfile, - node_version_check_bypass, - node_version_allowed, - parse_minimal_fees minimal_fees, - minimal_nanotez_per_gas_unit, - minimal_nanotez_per_byte, - force_apply_from_round, - keep_alive, - parse_per_block_vote liquidity_baking_vote, - parse_per_block_vote adaptive_issuance_vote, - per_block_vote_file, - parse_operations extra_operations, - dal_node_endpoint, - without_dal, - parse_state_recorder state_recorder, - pre_emptive_forge_time, - remote_calls_timeout ) - let parse_baking_mode baking_mode = match baking_mode with | Some local_data_dir_path -> Baking_commands.Local {local_data_dir_path} diff --git a/src/proto_alpha/lib_agnostic_baker/baker_args_parser.mli b/src/proto_alpha/lib_agnostic_baker/baker_args_parser.mli deleted file mode 100644 index 9e58b64f5ef3..000000000000 --- a/src/proto_alpha/lib_agnostic_baker/baker_args_parser.mli +++ /dev/null @@ -1,40 +0,0 @@ -(*****************************************************************************) -(* *) -(* SPDX-License-Identifier: MIT *) -(* Copyright (c) 2025 Trilitech *) -(* *) -(*****************************************************************************) - -(** This module offers transformation tools from protocol-independent types to - protocol specific ones. In this particular instance, the agnostic baker CLI - arguments are defined in a single place, outside the protocol code, and then - they are mapped, depending on the protocol context. -*) - -open Protocol.Alpha_context - -(** [parse_configuration] simply transforms a configuration record type into a - tuple containing the same values. *) -val parse_configuration : - Configuration.t -> - string option - * bool - * string option - * Tez.t - * Q.t - * Q.t - * int option - * bool - * Per_block_votes.per_block_vote option - * Per_block_votes.per_block_vote option - * string option - * Baking_configuration.Operations_source.t option - * Uri.t option - * bool - * Baking_configuration.state_recorder_config - * Q.t option - * Q.t option - -(** [parse_baking_mode baking_mode] maps a optional value to a [Local] or [Remote] - baking mode option. *) -val parse_baking_mode : string option -> Baking_commands.baking_mode diff --git a/src/proto_alpha/lib_agnostic_baker/baker_commands_helpers.ml b/src/proto_alpha/lib_agnostic_baker/baker_commands_helpers.ml index 9996e3999da5..b65a0e670e96 100644 --- a/src/proto_alpha/lib_agnostic_baker/baker_commands_helpers.ml +++ b/src/proto_alpha/lib_agnostic_baker/baker_commands_helpers.ml @@ -6,10 +6,32 @@ (*****************************************************************************) let run_baker ~configuration ~baking_mode ~sources ~cctxt = - let args = Baker_args_parser.parse_configuration configuration in - let baking_mode = Baker_args_parser.parse_baking_mode baking_mode in + let open Baker_args_parser in + let open Configuration in let cctxt = new Protocol_client_context.wrap_full cctxt in - Baking_commands.run_baker args baking_mode sources cctxt + Baking_commands.run_baker + ~pidfile:configuration.pidfile + ~node_version_check_bypass:configuration.node_version_check_bypass + ~node_version_allowed:configuration.node_version_allowed + ~minimal_fees:(parse_minimal_fees configuration.minimal_fees) + ~minimal_nanotez_per_gas_unit:configuration.minimal_nanotez_per_gas_unit + ~minimal_nanotez_per_byte:configuration.minimal_nanotez_per_byte + ~force_apply_from_round:configuration.force_apply_from_round + ~keep_alive:configuration.keep_alive + ~liquidity_baking_vote: + (parse_per_block_vote configuration.liquidity_baking_vote) + ~adaptive_issuance_vote: + (parse_per_block_vote configuration.adaptive_issuance_vote) + ~per_block_vote_file:configuration.per_block_vote_file + ~extra_operations:(parse_operations configuration.extra_operations) + ~dal_node_endpoint:configuration.dal_node_endpoint + ~without_dal:configuration.without_dal + ~state_recorder:(parse_state_recorder configuration.state_recorder) + ~pre_emptive_forge_time:configuration.pre_emptive_forge_time + ~remote_calls_timeout:configuration.remote_calls_timeout + ~baking_mode:(parse_baking_mode baking_mode) + ~sources + cctxt let run_vdf_daemon ~cctxt ~keep_alive = let cctxt = new Protocol_client_context.wrap_full cctxt in diff --git a/src/proto_alpha/lib_delegate/baking_commands.ml b/src/proto_alpha/lib_delegate/baking_commands.ml index 8cb1cbd68229..102b6c9b3d31 100644 --- a/src/proto_alpha/lib_delegate/baking_commands.ml +++ b/src/proto_alpha/lib_delegate/baking_commands.ml @@ -756,24 +756,12 @@ let baker_args = pre_emptive_forge_time_arg remote_calls_timeout_arg -let run_baker - ( pidfile, - node_version_check_bypass, - node_version_allowed, - minimal_fees, - minimal_nanotez_per_gas_unit, - minimal_nanotez_per_byte, - force_apply_from_round, - keep_alive, - liquidity_baking_vote, - adaptive_issuance_vote, - per_block_vote_file, - extra_operations, - dal_node_endpoint, - without_dal, - state_recorder, - pre_emptive_forge_time, - remote_calls_timeout ) baking_mode sources cctxt = +let run_baker ~pidfile ~node_version_check_bypass ~node_version_allowed + ~minimal_fees ~minimal_nanotez_per_gas_unit ~minimal_nanotez_per_byte + ~force_apply_from_round ~keep_alive ~liquidity_baking_vote + ~adaptive_issuance_vote ~per_block_vote_file ~extra_operations + ~dal_node_endpoint ~without_dal ~state_recorder ~pre_emptive_forge_time + ~remote_calls_timeout ~baking_mode ~sources cctxt = let open Lwt_result_syntax in may_lock_pidfile pidfile @@ fun () -> let* () = @@ -841,17 +829,92 @@ let baker_commands () : Protocol_client_context.full Tezos_clic.command list = ~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 = Local {local_data_dir_path} in - run_baker args baking_mode sources cctxt); + (fun ( pidfile, + node_version_check_bypass, + node_version_allowed, + minimal_fees, + minimal_nanotez_per_gas_unit, + minimal_nanotez_per_byte, + force_apply_from_round, + keep_alive, + liquidity_baking_vote, + adaptive_issuance_vote, + per_block_vote_file, + extra_operations, + dal_node_endpoint, + without_dal, + state_recorder, + pre_emptive_forge_time, + remote_calls_timeout ) + local_data_dir_path + sources + cctxt -> + run_baker + ~pidfile + ~node_version_check_bypass + ~node_version_allowed + ~minimal_fees + ~minimal_nanotez_per_gas_unit + ~minimal_nanotez_per_byte + ~force_apply_from_round + ~keep_alive + ~liquidity_baking_vote + ~adaptive_issuance_vote + ~per_block_vote_file + ~extra_operations + ~dal_node_endpoint + ~without_dal + ~state_recorder + ~pre_emptive_forge_time + ~remote_calls_timeout + ~baking_mode:(Local {local_data_dir_path}) + ~sources + cctxt); command ~group ~desc:"Launch the baker daemon using RPCs only." baker_args (prefixes ["run"; "remotely"] @@ sources_param) - (fun args sources cctxt -> - let baking_mode = Remote in - run_baker args baking_mode sources cctxt); + (fun ( pidfile, + node_version_check_bypass, + node_version_allowed, + minimal_fees, + minimal_nanotez_per_gas_unit, + minimal_nanotez_per_byte, + force_apply_from_round, + keep_alive, + liquidity_baking_vote, + adaptive_issuance_vote, + per_block_vote_file, + extra_operations, + dal_node_endpoint, + without_dal, + state_recorder, + pre_emptive_forge_time, + remote_calls_timeout ) + sources + cctxt -> + run_baker + ~pidfile + ~node_version_check_bypass + ~node_version_allowed + ~minimal_fees + ~minimal_nanotez_per_gas_unit + ~minimal_nanotez_per_byte + ~force_apply_from_round + ~keep_alive + ~liquidity_baking_vote + ~adaptive_issuance_vote + ~per_block_vote_file + ~extra_operations + ~dal_node_endpoint + ~without_dal + ~state_recorder + ~pre_emptive_forge_time + ~remote_calls_timeout + ~baking_mode:Remote + ~sources + cctxt); command ~group ~desc:"Launch the VDF daemon" diff --git a/src/proto_alpha/lib_delegate/baking_commands.mli b/src/proto_alpha/lib_delegate/baking_commands.mli index c808d3055330..d2ae5b9ec128 100644 --- a/src/proto_alpha/lib_delegate/baking_commands.mli +++ b/src/proto_alpha/lib_delegate/baking_commands.mli @@ -26,25 +26,27 @@ type baking_mode = Local of {local_data_dir_path : string} | Remote val run_baker : - string option - * bool - * string option - * Protocol.Alpha_context.Tez.t - * Q.t - * Q.t - * int option - * bool - * Protocol.Per_block_votes_repr.per_block_vote option - * Protocol.Per_block_votes_repr.per_block_vote option - * string option - * Baking_configuration.Operations_source.t option - * Uri.t option - * bool - * Baking_configuration.state_recorder_config - * Q.t option - * Q.t option -> - baking_mode -> - Environment.Signature.public_key_hash list -> + pidfile:string option -> + node_version_check_bypass:bool -> + node_version_allowed:string option -> + minimal_fees:Tezos_raw_protocol_alpha.Alpha_context.Tez.t -> + minimal_nanotez_per_gas_unit:Q.t -> + minimal_nanotez_per_byte:Q.t -> + force_apply_from_round:int option -> + keep_alive:bool -> + liquidity_baking_vote: + Tezos_raw_protocol_alpha.Per_block_votes_repr.per_block_vote option -> + adaptive_issuance_vote: + Tezos_raw_protocol_alpha.Per_block_votes_repr.per_block_vote option -> + per_block_vote_file:string option -> + extra_operations:Baking_configuration.Operations_source.t option -> + dal_node_endpoint:Uri.t option -> + without_dal:bool -> + state_recorder:Baking_configuration.state_recorder_config -> + pre_emptive_forge_time:Q.t option -> + remote_calls_timeout:Q.t option -> + baking_mode:baking_mode -> + sources:Environment.Signature.public_key_hash list -> Protocol_client_context.full -> unit Error_monad.tzresult Lwt.t -- GitLab From 952b4ef18d2a11105ae9fe817e38e36a4bfe5c63 Mon Sep 17 00:00:00 2001 From: Gabriel Moise Date: Fri, 4 Apr 2025 10:27:58 +0200 Subject: [PATCH 14/20] Agnostic_baker: Add sources to configuration --- src/lib_agnostic_baker/commands.ml | 16 ++++------------ src/lib_agnostic_baker/configuration.ml | 4 +++- src/lib_agnostic_baker/protocol_plugin_sig.ml | 5 ++--- .../lib_agnostic_baker/baker_commands_helpers.ml | 4 ++-- .../lib_agnostic_baker/baker_commands_helpers.ml | 4 ++-- .../lib_agnostic_baker/baker_commands_helpers.ml | 4 ++-- 6 files changed, 15 insertions(+), 22 deletions(-) diff --git a/src/lib_agnostic_baker/commands.ml b/src/lib_agnostic_baker/commands.ml index a3b6d5004d6d..c93cc332479d 100644 --- a/src/lib_agnostic_baker/commands.ml +++ b/src/lib_agnostic_baker/commands.ml @@ -35,12 +35,8 @@ let baker_args = 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.Cli.configuration_from_args args in - Plugin.Baker_commands_helpers.run_baker - ~configuration - ~baking_mode - ~sources - ~cctxt + let configuration = Configuration.Cli.configuration_from_args args sources in + Plugin.Baker_commands_helpers.run_baker ~configuration ~baking_mode ~cctxt let run_with_local_node_command ?plugin () = let open Cli in @@ -61,12 +57,8 @@ let run_with_local_node_command ?plugin () = let run_remotely (module Plugin : Protocol_plugin_sig.S) args sources cctxt = let baking_mode = None in - let configuration = Configuration.Cli.configuration_from_args args in - Plugin.Baker_commands_helpers.run_baker - ~configuration - ~baking_mode - ~sources - ~cctxt + let configuration = Configuration.Cli.configuration_from_args args sources in + Plugin.Baker_commands_helpers.run_baker ~configuration ~baking_mode ~cctxt let run_remotely_command ?plugin () = let open Cli in diff --git a/src/lib_agnostic_baker/configuration.ml b/src/lib_agnostic_baker/configuration.ml index 5ac5ec034bd7..f1c37218f5ab 100644 --- a/src/lib_agnostic_baker/configuration.ml +++ b/src/lib_agnostic_baker/configuration.ml @@ -23,6 +23,7 @@ type t = { state_recorder : bool; pre_emptive_forge_time : Q.t option; remote_calls_timeout : Q.t option; + sources : Signature.public_key_hash list; } module Cli = struct @@ -43,7 +44,7 @@ module Cli = struct without_dal, state_recorder, pre_emptive_forge_time, - remote_calls_timeout ) = + remote_calls_timeout ) sources = { pidfile; node_version_check_bypass; @@ -62,5 +63,6 @@ module Cli = struct state_recorder; pre_emptive_forge_time; remote_calls_timeout; + sources; } end diff --git a/src/lib_agnostic_baker/protocol_plugin_sig.ml b/src/lib_agnostic_baker/protocol_plugin_sig.ml index a2f73794b821..05d96e6bffb4 100644 --- a/src/lib_agnostic_baker/protocol_plugin_sig.ml +++ b/src/lib_agnostic_baker/protocol_plugin_sig.ml @@ -9,8 +9,8 @@ module type BAKER_COMMANDS_HELPERS = sig (** [run_baker ~configuration ~baking_mode ~sources ~cctxt] is the main running function signature that all protocol plugins will need to implement. It requires the [~configuration] which contains all the possible CLI arguments - for the agnostic baker, together with a [~baking_mode] argument and delegates - list given by [~sources] in the client context [~cctxt]. + for the agnostic baker, together with a [~baking_mode] argument, in the + client context [~cctxt]. Depending on the protocol, the arguments can be transformed in the corresponding plugin, but the structure of the list of arguments will not grow or shrink, to @@ -18,7 +18,6 @@ module type BAKER_COMMANDS_HELPERS = sig val run_baker : configuration:Configuration.t -> baking_mode:string option -> - sources:Tezos_crypto.Signature.public_key_hash list -> cctxt:Tezos_client_base.Client_context.full -> unit Error_monad.tzresult Lwt.t diff --git a/src/proto_021_PsQuebec/lib_agnostic_baker/baker_commands_helpers.ml b/src/proto_021_PsQuebec/lib_agnostic_baker/baker_commands_helpers.ml index 4927dd25f810..0a629fe457fe 100644 --- a/src/proto_021_PsQuebec/lib_agnostic_baker/baker_commands_helpers.ml +++ b/src/proto_021_PsQuebec/lib_agnostic_baker/baker_commands_helpers.ml @@ -5,11 +5,11 @@ (* *) (*****************************************************************************) -let run_baker ~configuration ~baking_mode ~sources ~cctxt = +let run_baker ~configuration ~baking_mode ~cctxt = let open Lwt_result_syntax in let open Baker_args_parser in let open Configuration in - let* sources = parse_sources sources in + let* sources = parse_sources configuration.sources in let cctxt = new Protocol_client_context.wrap_full cctxt in Baking_commands.run_baker ~pidfile:configuration.pidfile diff --git a/src/proto_022_PsRiotum/lib_agnostic_baker/baker_commands_helpers.ml b/src/proto_022_PsRiotum/lib_agnostic_baker/baker_commands_helpers.ml index 4927dd25f810..0a629fe457fe 100644 --- a/src/proto_022_PsRiotum/lib_agnostic_baker/baker_commands_helpers.ml +++ b/src/proto_022_PsRiotum/lib_agnostic_baker/baker_commands_helpers.ml @@ -5,11 +5,11 @@ (* *) (*****************************************************************************) -let run_baker ~configuration ~baking_mode ~sources ~cctxt = +let run_baker ~configuration ~baking_mode ~cctxt = let open Lwt_result_syntax in let open Baker_args_parser in let open Configuration in - let* sources = parse_sources sources in + let* sources = parse_sources configuration.sources in let cctxt = new Protocol_client_context.wrap_full cctxt in Baking_commands.run_baker ~pidfile:configuration.pidfile diff --git a/src/proto_alpha/lib_agnostic_baker/baker_commands_helpers.ml b/src/proto_alpha/lib_agnostic_baker/baker_commands_helpers.ml index b65a0e670e96..056f4fff8a18 100644 --- a/src/proto_alpha/lib_agnostic_baker/baker_commands_helpers.ml +++ b/src/proto_alpha/lib_agnostic_baker/baker_commands_helpers.ml @@ -5,7 +5,7 @@ (* *) (*****************************************************************************) -let run_baker ~configuration ~baking_mode ~sources ~cctxt = +let run_baker ~configuration ~baking_mode ~cctxt = let open Baker_args_parser in let open Configuration in let cctxt = new Protocol_client_context.wrap_full cctxt in @@ -30,7 +30,7 @@ let run_baker ~configuration ~baking_mode ~sources ~cctxt = ~pre_emptive_forge_time:configuration.pre_emptive_forge_time ~remote_calls_timeout:configuration.remote_calls_timeout ~baking_mode:(parse_baking_mode baking_mode) - ~sources + ~sources:configuration.sources cctxt let run_vdf_daemon ~cctxt ~keep_alive = -- GitLab From 52c4ceb0fa032d853c9d0387b8c7cbb62eff7658 Mon Sep 17 00:00:00 2001 From: Gabriel Moise Date: Fri, 4 Apr 2025 10:36:30 +0200 Subject: [PATCH 15/20] Agnostic_baker: Add baking_mode to configuration --- src/lib_agnostic_baker/commands.ml | 12 ++++++++---- src/lib_agnostic_baker/configuration.ml | 4 +++- src/lib_agnostic_baker/protocol_plugin_sig.ml | 4 +--- .../lib_agnostic_baker/baker_commands_helpers.ml | 4 ++-- .../lib_agnostic_baker/baker_commands_helpers.ml | 4 ++-- .../lib_agnostic_baker/baker_commands_helpers.ml | 4 ++-- 6 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/lib_agnostic_baker/commands.ml b/src/lib_agnostic_baker/commands.ml index c93cc332479d..351fa58d70ea 100644 --- a/src/lib_agnostic_baker/commands.ml +++ b/src/lib_agnostic_baker/commands.ml @@ -35,8 +35,10 @@ let baker_args = 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.Cli.configuration_from_args args sources in - Plugin.Baker_commands_helpers.run_baker ~configuration ~baking_mode ~cctxt + let configuration = + Configuration.Cli.configuration_from_args args baking_mode sources + in + Plugin.Baker_commands_helpers.run_baker ~configuration ~cctxt let run_with_local_node_command ?plugin () = let open Cli in @@ -57,8 +59,10 @@ let run_with_local_node_command ?plugin () = let run_remotely (module Plugin : Protocol_plugin_sig.S) args sources cctxt = let baking_mode = None in - let configuration = Configuration.Cli.configuration_from_args args sources in - Plugin.Baker_commands_helpers.run_baker ~configuration ~baking_mode ~cctxt + let configuration = + Configuration.Cli.configuration_from_args args baking_mode sources + in + Plugin.Baker_commands_helpers.run_baker ~configuration ~cctxt let run_remotely_command ?plugin () = let open Cli in diff --git a/src/lib_agnostic_baker/configuration.ml b/src/lib_agnostic_baker/configuration.ml index f1c37218f5ab..7aa316c46e43 100644 --- a/src/lib_agnostic_baker/configuration.ml +++ b/src/lib_agnostic_baker/configuration.ml @@ -23,6 +23,7 @@ type t = { state_recorder : bool; pre_emptive_forge_time : Q.t option; remote_calls_timeout : Q.t option; + baking_mode : string option; sources : Signature.public_key_hash list; } @@ -44,7 +45,7 @@ module Cli = struct without_dal, state_recorder, pre_emptive_forge_time, - remote_calls_timeout ) sources = + remote_calls_timeout ) baking_mode sources = { pidfile; node_version_check_bypass; @@ -63,6 +64,7 @@ module Cli = struct state_recorder; pre_emptive_forge_time; remote_calls_timeout; + baking_mode; sources; } end diff --git a/src/lib_agnostic_baker/protocol_plugin_sig.ml b/src/lib_agnostic_baker/protocol_plugin_sig.ml index 05d96e6bffb4..f37746d860b5 100644 --- a/src/lib_agnostic_baker/protocol_plugin_sig.ml +++ b/src/lib_agnostic_baker/protocol_plugin_sig.ml @@ -9,15 +9,13 @@ module type BAKER_COMMANDS_HELPERS = sig (** [run_baker ~configuration ~baking_mode ~sources ~cctxt] is the main running function signature that all protocol plugins will need to implement. It requires the [~configuration] which contains all the possible CLI arguments - for the agnostic baker, together with a [~baking_mode] argument, in the - client context [~cctxt]. + for the agnostic baker in the client context [~cctxt]. Depending on the protocol, the arguments can be transformed in the corresponding plugin, but the structure of the list of arguments will not grow or shrink, to prevent incompatibilities at migrations. *) val run_baker : configuration:Configuration.t -> - baking_mode:string option -> cctxt:Tezos_client_base.Client_context.full -> unit Error_monad.tzresult Lwt.t diff --git a/src/proto_021_PsQuebec/lib_agnostic_baker/baker_commands_helpers.ml b/src/proto_021_PsQuebec/lib_agnostic_baker/baker_commands_helpers.ml index 0a629fe457fe..6d7380cf98e1 100644 --- a/src/proto_021_PsQuebec/lib_agnostic_baker/baker_commands_helpers.ml +++ b/src/proto_021_PsQuebec/lib_agnostic_baker/baker_commands_helpers.ml @@ -5,7 +5,7 @@ (* *) (*****************************************************************************) -let run_baker ~configuration ~baking_mode ~cctxt = +let run_baker ~configuration ~cctxt = let open Lwt_result_syntax in let open Baker_args_parser in let open Configuration in @@ -31,7 +31,7 @@ let run_baker ~configuration ~baking_mode ~cctxt = ~state_recorder:(parse_state_recorder configuration.state_recorder) ~pre_emptive_forge_time:configuration.pre_emptive_forge_time ~remote_calls_timeout:configuration.remote_calls_timeout - ~baking_mode:(parse_baking_mode baking_mode) + ~baking_mode:(parse_baking_mode configuration.baking_mode) ~sources cctxt diff --git a/src/proto_022_PsRiotum/lib_agnostic_baker/baker_commands_helpers.ml b/src/proto_022_PsRiotum/lib_agnostic_baker/baker_commands_helpers.ml index 0a629fe457fe..6d7380cf98e1 100644 --- a/src/proto_022_PsRiotum/lib_agnostic_baker/baker_commands_helpers.ml +++ b/src/proto_022_PsRiotum/lib_agnostic_baker/baker_commands_helpers.ml @@ -5,7 +5,7 @@ (* *) (*****************************************************************************) -let run_baker ~configuration ~baking_mode ~cctxt = +let run_baker ~configuration ~cctxt = let open Lwt_result_syntax in let open Baker_args_parser in let open Configuration in @@ -31,7 +31,7 @@ let run_baker ~configuration ~baking_mode ~cctxt = ~state_recorder:(parse_state_recorder configuration.state_recorder) ~pre_emptive_forge_time:configuration.pre_emptive_forge_time ~remote_calls_timeout:configuration.remote_calls_timeout - ~baking_mode:(parse_baking_mode baking_mode) + ~baking_mode:(parse_baking_mode configuration.baking_mode) ~sources cctxt diff --git a/src/proto_alpha/lib_agnostic_baker/baker_commands_helpers.ml b/src/proto_alpha/lib_agnostic_baker/baker_commands_helpers.ml index 056f4fff8a18..4c7622b6871a 100644 --- a/src/proto_alpha/lib_agnostic_baker/baker_commands_helpers.ml +++ b/src/proto_alpha/lib_agnostic_baker/baker_commands_helpers.ml @@ -5,7 +5,7 @@ (* *) (*****************************************************************************) -let run_baker ~configuration ~baking_mode ~cctxt = +let run_baker ~configuration ~cctxt = let open Baker_args_parser in let open Configuration in let cctxt = new Protocol_client_context.wrap_full cctxt in @@ -29,7 +29,7 @@ let run_baker ~configuration ~baking_mode ~cctxt = ~state_recorder:(parse_state_recorder configuration.state_recorder) ~pre_emptive_forge_time:configuration.pre_emptive_forge_time ~remote_calls_timeout:configuration.remote_calls_timeout - ~baking_mode:(parse_baking_mode baking_mode) + ~baking_mode:(parse_baking_mode configuration.baking_mode) ~sources:configuration.sources cctxt -- GitLab From 9e8cbc8bafa78625436c7477428817da1bebfdf6 Mon Sep 17 00:00:00 2001 From: Gabriel Moise Date: Wed, 2 Apr 2025 15:22:56 +0100 Subject: [PATCH 16/20] Agnostic_baker: Refactor run_args get_base_dir function --- src/bin_agnostic_baker/main_agnostic_baker.ml | 6 +----- src/lib_agnostic_baker/run_args.ml | 4 +++- src/lib_agnostic_baker/run_args.mli | 2 +- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/bin_agnostic_baker/main_agnostic_baker.ml b/src/bin_agnostic_baker/main_agnostic_baker.ml index 8012ba1a2252..e9b8324b75e3 100644 --- a/src/bin_agnostic_baker/main_agnostic_baker.ml +++ b/src/bin_agnostic_baker/main_agnostic_baker.ml @@ -24,11 +24,7 @@ let[@warning "-32"] may_start_profiler baking_dir = let lwt_run ~args () = let open Lwt_result_syntax in - let base_dir = - Option.value - ~default:Agnostic_baker_config.default_base_dir - (Run_args.get_base_dir args) - in + let base_dir = Run_args.get_base_dir args in let*! () = Client_main_run.init_logging (module Agnostic_baker_config) ~base_dir () in diff --git a/src/lib_agnostic_baker/run_args.ml b/src/lib_agnostic_baker/run_args.ml index c9e53a829831..5bf2dcc372b9 100644 --- a/src/lib_agnostic_baker/run_args.ml +++ b/src/lib_agnostic_baker/run_args.ml @@ -43,4 +43,6 @@ let get_endpoint args = Option.value ~default:Parameters.default_node_endpoint @@ get_arg_value ~arg:endpoint_arg ~short_arg:endpoint_short_arg args -let get_base_dir = get_arg_value ~arg:base_dir_arg ~short_arg:base_dir_short_arg +let get_base_dir args = + Option.value ~default:Agnostic_baker_config.default_base_dir + @@ get_arg_value ~arg:base_dir_arg ~short_arg:base_dir_short_arg args diff --git a/src/lib_agnostic_baker/run_args.mli b/src/lib_agnostic_baker/run_args.mli index 73cb30d6d98c..d613a32ae415 100644 --- a/src/lib_agnostic_baker/run_args.mli +++ b/src/lib_agnostic_baker/run_args.mli @@ -21,4 +21,4 @@ val get_endpoint : string list -> string (** [get_base_dir args] returns the value associated to the [--base-dir] argument amongst [args]. *) -val get_base_dir : string list -> string option +val get_base_dir : string list -> string -- GitLab From 7dbcab9d55a6a7d242ec908680ddeb695b8b0424 Mon Sep 17 00:00:00 2001 From: Gabriel Moise Date: Fri, 4 Apr 2025 10:50:14 +0200 Subject: [PATCH 17/20] Agnostic_baker: Change baking_mode type to be more explicit --- src/lib_agnostic_baker/commands.ml | 4 ++-- src/lib_agnostic_baker/configuration.ml | 4 +++- .../lib_agnostic_baker/baker_args_parser.ml | 5 +++-- .../lib_agnostic_baker/baker_args_parser.ml | 5 +++-- src/proto_alpha/lib_agnostic_baker/baker_args_parser.ml | 5 +++-- 5 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/lib_agnostic_baker/commands.ml b/src/lib_agnostic_baker/commands.ml index 351fa58d70ea..f4ac135e2796 100644 --- a/src/lib_agnostic_baker/commands.ml +++ b/src/lib_agnostic_baker/commands.ml @@ -34,7 +34,7 @@ let baker_args = 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 baking_mode = Configuration.Local {local_data_dir_path} in let configuration = Configuration.Cli.configuration_from_args args baking_mode sources in @@ -58,7 +58,7 @@ let run_with_local_node_command ?plugin () = | None -> fun _ _ _ _ -> Lwt_result_syntax.return_unit) let run_remotely (module Plugin : Protocol_plugin_sig.S) args sources cctxt = - let baking_mode = None in + let baking_mode = Configuration.Remote in let configuration = Configuration.Cli.configuration_from_args args baking_mode sources in diff --git a/src/lib_agnostic_baker/configuration.ml b/src/lib_agnostic_baker/configuration.ml index 7aa316c46e43..2aa7976bb31a 100644 --- a/src/lib_agnostic_baker/configuration.ml +++ b/src/lib_agnostic_baker/configuration.ml @@ -5,6 +5,8 @@ (* *) (*****************************************************************************) +type baking_mode = Local of {local_data_dir_path : string} | Remote + type t = { pidfile : string option; node_version_check_bypass : bool; @@ -23,7 +25,7 @@ type t = { state_recorder : bool; pre_emptive_forge_time : Q.t option; remote_calls_timeout : Q.t option; - baking_mode : string option; + baking_mode : baking_mode; sources : Signature.public_key_hash list; } diff --git a/src/proto_021_PsQuebec/lib_agnostic_baker/baker_args_parser.ml b/src/proto_021_PsQuebec/lib_agnostic_baker/baker_args_parser.ml index 84a68fb5dbba..a5093e4b691f 100644 --- a/src/proto_021_PsQuebec/lib_agnostic_baker/baker_args_parser.ml +++ b/src/proto_021_PsQuebec/lib_agnostic_baker/baker_args_parser.ml @@ -38,8 +38,9 @@ let parse_state_recorder state_recorder = let parse_baking_mode baking_mode = match baking_mode with - | Some local_data_dir_path -> Baking_commands.Local {local_data_dir_path} - | None -> Remote + | Configuration.Local {local_data_dir_path} -> + Baking_commands.Local {local_data_dir_path} + | Configuration.Remote -> Baking_commands.Remote let parse_sources = List.map_es (fun source -> diff --git a/src/proto_022_PsRiotum/lib_agnostic_baker/baker_args_parser.ml b/src/proto_022_PsRiotum/lib_agnostic_baker/baker_args_parser.ml index 84a68fb5dbba..a5093e4b691f 100644 --- a/src/proto_022_PsRiotum/lib_agnostic_baker/baker_args_parser.ml +++ b/src/proto_022_PsRiotum/lib_agnostic_baker/baker_args_parser.ml @@ -38,8 +38,9 @@ let parse_state_recorder state_recorder = let parse_baking_mode baking_mode = match baking_mode with - | Some local_data_dir_path -> Baking_commands.Local {local_data_dir_path} - | None -> Remote + | Configuration.Local {local_data_dir_path} -> + Baking_commands.Local {local_data_dir_path} + | Configuration.Remote -> Baking_commands.Remote let parse_sources = List.map_es (fun source -> diff --git a/src/proto_alpha/lib_agnostic_baker/baker_args_parser.ml b/src/proto_alpha/lib_agnostic_baker/baker_args_parser.ml index daa0400300ad..2a0c59b14c3b 100644 --- a/src/proto_alpha/lib_agnostic_baker/baker_args_parser.ml +++ b/src/proto_alpha/lib_agnostic_baker/baker_args_parser.ml @@ -38,5 +38,6 @@ let parse_state_recorder state_recorder = let parse_baking_mode baking_mode = match baking_mode with - | Some local_data_dir_path -> Baking_commands.Local {local_data_dir_path} - | None -> Remote + | Configuration.Local {local_data_dir_path} -> + Baking_commands.Local {local_data_dir_path} + | Configuration.Remote -> Baking_commands.Remote -- GitLab From 273ddb32896828df2a8b442aabae78df937cd547 Mon Sep 17 00:00:00 2001 From: Gabriel Moise Date: Fri, 4 Apr 2025 10:59:42 +0200 Subject: [PATCH 18/20] Agnostic_baker: Add interface for configuration module --- src/lib_agnostic_baker/configuration.mli | 54 ++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/lib_agnostic_baker/configuration.mli diff --git a/src/lib_agnostic_baker/configuration.mli b/src/lib_agnostic_baker/configuration.mli new file mode 100644 index 000000000000..b204da12542e --- /dev/null +++ b/src/lib_agnostic_baker/configuration.mli @@ -0,0 +1,54 @@ +(*****************************************************************************) +(* *) +(* SPDX-License-Identifier: MIT *) +(* Copyright (c) 2025 Trilitech *) +(* *) +(*****************************************************************************) + +type baking_mode = Local of {local_data_dir_path : string} | Remote + +type t = { + pidfile : string option; + node_version_check_bypass : bool; + node_version_allowed : string option; + minimal_fees : int64; + minimal_nanotez_per_gas_unit : Q.t; + minimal_nanotez_per_byte : Q.t; + force_apply_from_round : int option; + keep_alive : bool; + liquidity_baking_vote : string option; + adaptive_issuance_vote : string option; + per_block_vote_file : string option; + extra_operations : Uri.t option; + dal_node_endpoint : Uri.t option; + without_dal : bool; + state_recorder : bool; + pre_emptive_forge_time : Q.t option; + remote_calls_timeout : Q.t option; + baking_mode : baking_mode; + sources : Signature.public_key_hash trace; +} + +module Cli : sig + val configuration_from_args : + string option + * bool + * string option + * int64 + * Q.t + * Q.t + * int option + * bool + * string option + * string option + * string option + * Uri.t option + * Uri.t option + * bool + * bool + * Q.t option + * Q.t option -> + baking_mode -> + Signature.public_key_hash trace -> + t +end -- GitLab From 5f58be99f5d6d7bd120eea1a1f8dc812b565aea6 Mon Sep 17 00:00:00 2001 From: Gabriel Moise Date: Fri, 4 Apr 2025 14:14:58 +0200 Subject: [PATCH 19/20] Agnostic_baker: Add data encoding for configuration --- src/lib_agnostic_baker/configuration.ml | 131 ++++++++++++++++++++++++ 1 file changed, 131 insertions(+) diff --git a/src/lib_agnostic_baker/configuration.ml b/src/lib_agnostic_baker/configuration.ml index 2aa7976bb31a..1f0d6319a32d 100644 --- a/src/lib_agnostic_baker/configuration.ml +++ b/src/lib_agnostic_baker/configuration.ml @@ -29,6 +29,137 @@ type t = { sources : Signature.public_key_hash list; } +let q_encoding = conv (fun q -> Q.to_string q) (fun s -> Q.of_string s) string + +let baking_mode_encoding : baking_mode Data_encoding.t = + let open Data_encoding in + let remote_case = + case + ~title:"remote" + ~description:"Baker runs in remote baking mode." + (Tag 0) + (constant "remote") + (function Remote -> Some () | _ -> None) + (fun () -> Remote) + in + let local_case = + case + ~title:"local" + ~description:"Baker runs in local baking mode." + (Tag 1) + (obj1 (req "local" (obj1 (req "node-dir" string)))) + (function + | Local {local_data_dir_path} -> Some local_data_dir_path | _ -> None) + (fun local_data_dir_path -> Local {local_data_dir_path}) + in + union [local_case; remote_case] + +let[@warning "-32"] encoding : t Data_encoding.t = + let open Data_encoding in + conv + (fun { + pidfile; + node_version_check_bypass; + node_version_allowed; + minimal_fees; + minimal_nanotez_per_gas_unit; + minimal_nanotez_per_byte; + force_apply_from_round; + keep_alive; + liquidity_baking_vote; + adaptive_issuance_vote; + per_block_vote_file; + extra_operations; + dal_node_endpoint; + without_dal; + state_recorder; + pre_emptive_forge_time; + remote_calls_timeout; + baking_mode; + sources; + } -> + ( ( pidfile, + node_version_check_bypass, + node_version_allowed, + minimal_fees, + minimal_nanotez_per_gas_unit, + minimal_nanotez_per_byte, + force_apply_from_round, + keep_alive, + liquidity_baking_vote, + adaptive_issuance_vote ), + ( per_block_vote_file, + extra_operations, + dal_node_endpoint, + without_dal, + state_recorder, + pre_emptive_forge_time, + remote_calls_timeout, + baking_mode, + sources ) )) + (fun ( ( pidfile, + node_version_check_bypass, + node_version_allowed, + minimal_fees, + minimal_nanotez_per_gas_unit, + minimal_nanotez_per_byte, + force_apply_from_round, + keep_alive, + liquidity_baking_vote, + adaptive_issuance_vote ), + ( per_block_vote_file, + extra_operations, + dal_node_endpoint, + without_dal, + state_recorder, + pre_emptive_forge_time, + remote_calls_timeout, + baking_mode, + sources ) ) -> + { + pidfile; + node_version_check_bypass; + node_version_allowed; + minimal_fees; + minimal_nanotez_per_gas_unit; + minimal_nanotez_per_byte; + force_apply_from_round; + keep_alive; + liquidity_baking_vote; + adaptive_issuance_vote; + per_block_vote_file; + extra_operations; + dal_node_endpoint; + without_dal; + state_recorder; + pre_emptive_forge_time; + remote_calls_timeout; + baking_mode; + sources; + }) + (merge_objs + (obj10 + (opt "pidfile" string) + (req "node_version_check_bypass" bool) + (opt "node_version_allowed" string) + (req "minimal_fees" int64) + (req "minimal_nanotez_per_gas_unit" q_encoding) + (req "minimal_nanotez_per_byte" q_encoding) + (opt "force_apply_from_round" int31) + (req "keep_alive" bool) + (opt "liquidity_baking_vote" string) + (opt "adaptive_issuance_vote" string)) + (obj9 + (opt "per_block_vote_file" string) + (opt "extra_operations" Tezos_rpc.Encoding.uri_encoding) + (opt "dal_node_endpoint" Tezos_rpc.Encoding.uri_encoding) + (req "without_dal" bool) + (req "state_recorder" bool) + (opt "pre_emptive_forge_time" q_encoding) + (opt "remote_calls_timeout" q_encoding) + (req "baking_mode" baking_mode_encoding) + (req "sources" (list Signature.Public_key_hash.encoding)))) + module Cli = struct let configuration_from_args ( pidfile, -- GitLab From c0ba5162f2b8bf3ab94576bdda0214f5b942b8f9 Mon Sep 17 00:00:00 2001 From: Gabriel Moise Date: Fri, 4 Apr 2025 15:45:00 +0200 Subject: [PATCH 20/20] Agnostic_baker: Add config init command --- src/lib_agnostic_baker/cli.ml | 32 +++++++++++++ src/lib_agnostic_baker/commands.ml | 39 +++++++++++++++ src/lib_agnostic_baker/configuration.ml | 61 ++++++++++++++++++++++++ src/lib_agnostic_baker/configuration.mli | 9 ++++ 4 files changed, 141 insertions(+) diff --git a/src/lib_agnostic_baker/cli.ml b/src/lib_agnostic_baker/cli.ml index 2e4230093a4e..2d1b5f8d2cbe 100644 --- a/src/lib_agnostic_baker/cli.ml +++ b/src/lib_agnostic_baker/cli.ml @@ -349,3 +349,35 @@ let sources_param : ~desc: "name of the delegate owning the attestation/baking right or name of \ the consensus key signing on the delegate's behalf") + +let force_switch : (bool, Tezos_client_base.Client_context.full) Tezos_clic.arg + = + Tezos_clic.switch + ~long:"force" + ~doc:"Overwrites the baker configuration file when it exists." + () + +let baking_config_file_arg = + Tezos_clic.arg + ~long:"config-file" + ~placeholder:"baker.json" + ~doc: + "Location of the configuration file for the agnostic baker. Defaults to \ + `/baker.json`." + string_parameter + +let local_baking_mode_arg = + Tezos_clic.arg + ~long:"local" + ~placeholder:"path" + ~doc: + "Set the baking mode of the baker to be local with the provided node \ + directory path" + directory_parameter + +let remote_baking_mode_arg : + (bool, Tezos_client_base.Client_context.full) Tezos_clic.arg = + Tezos_clic.switch + ~long:"remote" + ~doc:"Set the baking mode of the baker to be remote." + () diff --git a/src/lib_agnostic_baker/commands.ml b/src/lib_agnostic_baker/commands.ml index f4ac135e2796..d3f99ca2a60f 100644 --- a/src/lib_agnostic_baker/commands.ml +++ b/src/lib_agnostic_baker/commands.ml @@ -32,6 +32,44 @@ let baker_args = pre_emptive_forge_time_arg remote_calls_timeout_arg +let config_init_command = + let open Lwt_result_syntax in + let open Cli in + let open Tezos_clic in + command + ~group + ~desc:"Configure the agnostic baker." + (merge_options + (args4 + force_switch + baking_config_file_arg + local_baking_mode_arg + remote_baking_mode_arg) + baker_args) + (prefixes ["config"; "init"; "for"; "keys"] @@ sources_param) + (fun ( (force, baking_config_file, local_baking_mode, remote_baking_mode), + args ) + sources + cctxt -> + let* baking_mode = + Configuration.resolve_baking_mode ~local_baking_mode ~remote_baking_mode + in + let config = + Configuration.Cli.configuration_from_args args baking_mode sources + in + let baking_config_file = + Configuration.config_filename + ~data_dir:(Run_args.get_base_dir @@ Array.to_list Sys.argv) + baking_config_file + in + let* () = Configuration.save ~force ~baking_config_file config in + let*! () = + cctxt#message + "Agnostic baker configuration written in %s" + baking_config_file + in + return_unit) + let run_with_local_node (module Plugin : Protocol_plugin_sig.S) args local_data_dir_path sources cctxt = let baking_mode = Configuration.Local {local_data_dir_path} in @@ -95,6 +133,7 @@ let run_vdf_command ?plugin () = let baker_commands ?plugin () = [ + config_init_command; run_with_local_node_command ?plugin (); run_remotely_command ?plugin (); run_vdf_command ?plugin (); diff --git a/src/lib_agnostic_baker/configuration.ml b/src/lib_agnostic_baker/configuration.ml index 1f0d6319a32d..804076e5dac3 100644 --- a/src/lib_agnostic_baker/configuration.ml +++ b/src/lib_agnostic_baker/configuration.ml @@ -7,6 +7,48 @@ type baking_mode = Local of {local_data_dir_path : string} | Remote +type error += Too_many_baking_nodes + +type error += Missing_baking_mode + +let () = + register_error_kind + ~id:"agnostic_baker.too_many_baking_modes" + ~title:"Cannot decide which baking mode to use" + ~description: + "More than one baking mode has been chosen. Please choose exactly one." + ~pp:(fun ppf () -> + Format.pp_print_string + ppf + "More than one baking mode has been chosen. Please choose exactly one.") + `Permanent + Data_encoding.empty + (function Too_many_baking_nodes -> Some () | _ -> None) + (fun () -> Too_many_baking_nodes) ; + register_error_kind + ~id:"agnostic_baker.missing_baking_mode" + ~title:"No baking mode has been chosen." + ~description: + "No baking mode has been chosen. Please check documentation to choose \ + one." + ~pp:(fun ppf () -> + Format.pp_print_string + ppf + "No baking mode has been chosen. Please check documentation to choose \ + one.") + `Permanent + Data_encoding.empty + (function Missing_baking_mode -> Some () | _ -> None) + (fun () -> Missing_baking_mode) + +let resolve_baking_mode ~local_baking_mode ~remote_baking_mode = + let open Lwt_result_syntax in + match (local_baking_mode, remote_baking_mode) with + | Some _, true -> tzfail Too_many_baking_nodes + | Some local_data_dir_path, false -> return @@ Local {local_data_dir_path} + | None, true -> return Remote + | None, false -> tzfail Missing_baking_mode + type t = { pidfile : string option; node_version_check_bypass : bool; @@ -160,6 +202,25 @@ let[@warning "-32"] encoding : t Data_encoding.t = (req "baking_mode" baking_mode_encoding) (req "sources" (list Signature.Public_key_hash.encoding)))) +let config_filename ~data_dir = function + | Some path -> path + | None -> Filename.concat data_dir "baker.json" + +let save ~force ~baking_config_file config = + let open Lwt_result_syntax in + let json = Data_encoding.Json.construct encoding config in + let*! exists = Lwt_unix.file_exists baking_config_file in + if exists && not force then + failwith + "Configuration file %S already exists. Use --force to overwrite." + baking_config_file + else + let*! () = + Tezos_stdlib_unix.Lwt_utils_unix.create_dir + (Filename.dirname baking_config_file) + in + Tezos_stdlib_unix.Lwt_utils_unix.Json.write_file baking_config_file json + module Cli = struct let configuration_from_args ( pidfile, diff --git a/src/lib_agnostic_baker/configuration.mli b/src/lib_agnostic_baker/configuration.mli index b204da12542e..309e5939150a 100644 --- a/src/lib_agnostic_baker/configuration.mli +++ b/src/lib_agnostic_baker/configuration.mli @@ -7,6 +7,11 @@ type baking_mode = Local of {local_data_dir_path : string} | Remote +val resolve_baking_mode : + local_baking_mode:string option -> + remote_baking_mode:bool -> + baking_mode tzresult Lwt.t + type t = { pidfile : string option; node_version_check_bypass : bool; @@ -29,6 +34,10 @@ type t = { sources : Signature.public_key_hash trace; } +val config_filename : data_dir:string -> string option -> string + +val save : force:bool -> baking_config_file:string -> t -> unit tzresult Lwt.t + module Cli : sig val configuration_from_args : string option -- GitLab