From 6f6f37ae2a408ee50b73f3b835abd042245439b6 Mon Sep 17 00:00:00 2001 From: Gabriel Moise Date: Mon, 24 Feb 2025 11:26:25 +0000 Subject: [PATCH 01/13] Agnostic_baker: Remove name function --- src/lib_validation/protocol_plugin.ml | 2 -- src/lib_validation/protocol_plugin.mli | 2 -- .../lib_agnostic_baker/agnostic_baker_plugin_registration.ml | 2 -- .../lib_agnostic_baker/agnostic_baker_plugin_registration.ml | 2 -- .../lib_agnostic_baker/agnostic_baker_plugin_registration.ml | 2 -- 5 files changed, 10 deletions(-) diff --git a/src/lib_validation/protocol_plugin.ml b/src/lib_validation/protocol_plugin.ml index 07cdbd9b2b8d..29c2569505f0 100644 --- a/src/lib_validation/protocol_plugin.ml +++ b/src/lib_validation/protocol_plugin.ml @@ -168,8 +168,6 @@ end module type AGNOSTIC_BAKER_PLUGIN = sig val hash : Protocol_hash.t - val name : string - val map_commands : unit -> Tezos_client_base.Client_context.full Tezos_clic.command list end diff --git a/src/lib_validation/protocol_plugin.mli b/src/lib_validation/protocol_plugin.mli index b6d4bf61c5b6..adf0ec3d874e 100644 --- a/src/lib_validation/protocol_plugin.mli +++ b/src/lib_validation/protocol_plugin.mli @@ -217,8 +217,6 @@ end module type AGNOSTIC_BAKER_PLUGIN = sig val hash : Protocol_hash.t - val name : string - val map_commands : unit -> Tezos_client_base.Client_context.full Tezos_clic.command list end diff --git a/src/proto_021_PsQuebec/lib_agnostic_baker/agnostic_baker_plugin_registration.ml b/src/proto_021_PsQuebec/lib_agnostic_baker/agnostic_baker_plugin_registration.ml index 147a175016a7..7b81c0e8f433 100644 --- a/src/proto_021_PsQuebec/lib_agnostic_baker/agnostic_baker_plugin_registration.ml +++ b/src/proto_021_PsQuebec/lib_agnostic_baker/agnostic_baker_plugin_registration.ml @@ -8,8 +8,6 @@ module Agnostic_baker_plugin = struct let hash = Registerer.Registered.hash - let name = Protocol.name - let map_commands () = List.map (Tezos_clic.map_command (new Protocol_client_context.wrap_full)) @@ Baking_commands.baker_commands () diff --git a/src/proto_022_PsRiotum/lib_agnostic_baker/agnostic_baker_plugin_registration.ml b/src/proto_022_PsRiotum/lib_agnostic_baker/agnostic_baker_plugin_registration.ml index 147a175016a7..7b81c0e8f433 100644 --- a/src/proto_022_PsRiotum/lib_agnostic_baker/agnostic_baker_plugin_registration.ml +++ b/src/proto_022_PsRiotum/lib_agnostic_baker/agnostic_baker_plugin_registration.ml @@ -8,8 +8,6 @@ module Agnostic_baker_plugin = struct let hash = Registerer.Registered.hash - let name = Protocol.name - let map_commands () = List.map (Tezos_clic.map_command (new Protocol_client_context.wrap_full)) @@ Baking_commands.baker_commands () diff --git a/src/proto_alpha/lib_agnostic_baker/agnostic_baker_plugin_registration.ml b/src/proto_alpha/lib_agnostic_baker/agnostic_baker_plugin_registration.ml index 147a175016a7..7b81c0e8f433 100644 --- a/src/proto_alpha/lib_agnostic_baker/agnostic_baker_plugin_registration.ml +++ b/src/proto_alpha/lib_agnostic_baker/agnostic_baker_plugin_registration.ml @@ -8,8 +8,6 @@ module Agnostic_baker_plugin = struct let hash = Registerer.Registered.hash - let name = Protocol.name - let map_commands () = List.map (Tezos_clic.map_command (new Protocol_client_context.wrap_full)) @@ Baking_commands.baker_commands () -- GitLab From 77c4a60f2a6ccb8c939b81fe141e5ff4c0bd929d Mon Sep 17 00:00:00 2001 From: Gabriel Moise Date: Mon, 24 Feb 2025 13:08:48 +0000 Subject: [PATCH 02/13] Agnostic_baker: Move code to lib_agnostic_baker --- dune-project | 1 + manifest/product_octez.ml | 26 ++++++++++++--- ...octez-experimental-agnostic-baker-lib.opam | 25 ++++++++++++++ opam/octez-experimental-agnostic-baker.opam | 3 +- opam/octez-protocol-021-PsQuebec-libs.opam | 1 + opam/octez-protocol-022-PsRiotum-libs.opam | 1 + opam/octez-protocol-alpha-libs.opam | 1 + script-inputs/ci-opam-package-tests | 33 ++++++++++--------- src/bin_agnostic_baker/dune | 11 ++----- .../agnostic_baker_errors.ml | 0 .../agnostic_baker_events.ml | 0 .../daemon.ml | 0 .../daemon.mli | 0 src/lib_agnostic_baker/dune | 26 +++++++++++++++ .../parameters.ml | 0 .../parameters.mli | 0 .../rpc_services.ml | 0 .../rpc_services.mli | 0 .../run_args.ml | 0 .../run_args.mli | 0 .../lib_agnostic_baker/dune | 6 ++-- .../lib_agnostic_baker/dune | 6 ++-- src/proto_alpha/lib_agnostic_baker/dune | 6 ++-- 23 files changed, 108 insertions(+), 38 deletions(-) create mode 100644 opam/octez-experimental-agnostic-baker-lib.opam rename src/{bin_agnostic_baker => lib_agnostic_baker}/agnostic_baker_errors.ml (100%) rename src/{bin_agnostic_baker => lib_agnostic_baker}/agnostic_baker_events.ml (100%) rename src/{bin_agnostic_baker => lib_agnostic_baker}/daemon.ml (100%) rename src/{bin_agnostic_baker => lib_agnostic_baker}/daemon.mli (100%) create mode 100644 src/lib_agnostic_baker/dune rename src/{bin_agnostic_baker => lib_agnostic_baker}/parameters.ml (100%) rename src/{bin_agnostic_baker => lib_agnostic_baker}/parameters.mli (100%) rename src/{bin_agnostic_baker => lib_agnostic_baker}/rpc_services.ml (100%) rename src/{bin_agnostic_baker => lib_agnostic_baker}/rpc_services.mli (100%) rename src/{bin_agnostic_baker => lib_agnostic_baker}/run_args.ml (100%) rename src/{bin_agnostic_baker => lib_agnostic_baker}/run_args.mli (100%) diff --git a/dune-project b/dune-project index 62873642efcb..d9e9a719a8b6 100644 --- a/dune-project +++ b/dune-project @@ -34,6 +34,7 @@ (package (name octez-evm-node-tests)(allow_empty)) (package (name octez-evm-wasm-runtime-tests)(allow_empty)) (package (name octez-experimental-agnostic-baker)) +(package (name octez-experimental-agnostic-baker-lib)) (package (name octez-injector)) (package (name octez-injector-server)) (package (name octez-internal-libs)) diff --git a/manifest/product_octez.ml b/manifest/product_octez.ml index 6e7f7581684a..401ed1248663 100644 --- a/manifest/product_octez.ml +++ b/manifest/product_octez.ml @@ -5341,6 +5341,25 @@ let _octez_scoru_wasm_fast_tests = ] ~preprocess:(staged_pps [ppx_import; ppx_deriving_show]) +let octez_experimental_agnostic_baker_lib = + public_lib + "octez-experimental-agnostic-baker-lib" + ~path:"src/lib_agnostic_baker" + ~internal_name:"octez_experimental_agnostic_baker" + ~synopsis:"Octez: library for Agnostic Baker" + ~deps: + [ + octez_rustzcash_deps; + bls12_381_archive; + data_encoding |> open_; + octez_base |> open_ ~m:"TzPervasives" |> open_; + octez_base_unix |> open_; + octez_validation |> open_; + octez_client_base_unix |> open_; + octez_node_config; + octez_client_commands |> open_; + ] + (* PROTOCOL PACKAGES *) module Protocol : sig @@ -7185,6 +7204,7 @@ let hash = Protocol.hash baking_commands |> if_some |> open_; octez_client_commands |> open_; octez_client_base_unix |> open_; + octez_experimental_agnostic_baker_lib |> open_; ] ~linkall:true in @@ -8278,13 +8298,9 @@ let _octez_experimental_agnostic_baker = ([ octez_rust_deps; bls12_381_archive; - data_encoding |> open_; octez_base |> open_ ~m:"TzPervasives" |> open_; octez_base_unix |> open_; - octez_validation |> open_; - octez_client_base_unix |> open_; - octez_node_config; - octez_client_commands |> open_; + octez_experimental_agnostic_baker_lib |> open_; ] @ protocol_deps) ~linkall:true diff --git a/opam/octez-experimental-agnostic-baker-lib.opam b/opam/octez-experimental-agnostic-baker-lib.opam new file mode 100644 index 000000000000..ee8a3184911c --- /dev/null +++ b/opam/octez-experimental-agnostic-baker-lib.opam @@ -0,0 +1,25 @@ +# This file was automatically generated, do not edit. +# Edit file manifest/main.ml instead. +opam-version: "2.0" +maintainer: "contact@tezos.com" +authors: ["Tezos devteam"] +homepage: "https://www.tezos.com/" +bug-reports: "https://gitlab.com/tezos/tezos/issues" +dev-repo: "git+https://gitlab.com/tezos/tezos.git" +license: "MIT" +depends: [ + "dune" { >= "3.11.1" } + "ocaml" { >= "4.14" } + "octez-rustzcash-deps" { = version } + "bls12-381" { = version } + "octez-libs" { = version } + "octez-shell-libs" { = version } + "octez-node-config" { = version } +] +build: [ + ["rm" "-r" "vendors" "contrib"] + ["dune" "build" "-p" name "-j" jobs] + ["dune" "runtest" "-p" name "-j" jobs] {with-test} +] +available: os-family != "windows" +synopsis: "Octez: library for Agnostic Baker" diff --git a/opam/octez-experimental-agnostic-baker.opam b/opam/octez-experimental-agnostic-baker.opam index 5375685d1f8d..bc418220acd1 100644 --- a/opam/octez-experimental-agnostic-baker.opam +++ b/opam/octez-experimental-agnostic-baker.opam @@ -13,8 +13,7 @@ depends: [ "octez-rust-deps" { = version } "bls12-381" { = version } "octez-libs" { = version } - "octez-shell-libs" { = version } - "octez-node-config" { = version } + "octez-experimental-agnostic-baker-lib" { = version } "octez-protocol-021-PsQuebec-libs" { = version } "octez-protocol-022-PsRiotum-libs" { = version } ] diff --git a/opam/octez-protocol-021-PsQuebec-libs.opam b/opam/octez-protocol-021-PsQuebec-libs.opam index 21608311b451..75dbe05ce0ce 100644 --- a/opam/octez-protocol-021-PsQuebec-libs.opam +++ b/opam/octez-protocol-021-PsQuebec-libs.opam @@ -29,6 +29,7 @@ depends: [ "memtrace" "octez-protocol-compiler" { = version } "tezos-dal-node-lib" { = version } + "octez-experimental-agnostic-baker-lib" { = version } "octez-injector" { = version } "octez-l2-libs" { = version } "octez-rustzcash-deps" { with-test & = version } diff --git a/opam/octez-protocol-022-PsRiotum-libs.opam b/opam/octez-protocol-022-PsRiotum-libs.opam index e99eb6f2bf97..e12636f45443 100644 --- a/opam/octez-protocol-022-PsRiotum-libs.opam +++ b/opam/octez-protocol-022-PsRiotum-libs.opam @@ -29,6 +29,7 @@ depends: [ "memtrace" "octez-protocol-compiler" { = version } "tezos-dal-node-lib" { = version } + "octez-experimental-agnostic-baker-lib" { = version } "octez-injector" { = version } "octez-l2-libs" { = version } "octez-rustzcash-deps" { with-test & = version } diff --git a/opam/octez-protocol-alpha-libs.opam b/opam/octez-protocol-alpha-libs.opam index abf269f56ce0..e12f3edf4955 100644 --- a/opam/octez-protocol-alpha-libs.opam +++ b/opam/octez-protocol-alpha-libs.opam @@ -29,6 +29,7 @@ depends: [ "memtrace" "octez-protocol-compiler" { = version } "tezos-dal-node-lib" { = version } + "octez-experimental-agnostic-baker-lib" { = version } "octez-injector" { = version } "octez-l2-libs" { = version } "octez-alcotezt" { with-test & = version } diff --git a/script-inputs/ci-opam-package-tests b/script-inputs/ci-opam-package-tests index a2c8f759c759..3518bd39e406 100644 --- a/script-inputs/ci-opam-package-tests +++ b/script-inputs/ci-opam-package-tests @@ -13,16 +13,17 @@ octez-dal-node exec 1 octez-distributed-internal all 7 octez-distributed-lwt-internal all 7 octez-experimental-agnostic-baker exec 1 +octez-experimental-agnostic-baker-lib all 2 octez-injector all 2 octez-internal-libs all 7 octez-l2-libs all 6 -octez-libs all 7 +octez-libs all 6 octez-node exec 1 octez-node-config all 4 octez-performance-metrics all 6 octez-proto-libs all 6 octez-protocol-000-Ps9mPmXa-libs all 2 -octez-protocol-001-PtCJ7pwo-libs all 3 +octez-protocol-001-PtCJ7pwo-libs all 2 octez-protocol-002-PsYLVpVv-libs all 3 octez-protocol-003-PsddFKi3-libs all 3 octez-protocol-004-Pt24m4xi-libs all 3 @@ -49,7 +50,7 @@ octez-protocol-compiler exec 6 octez-protocol-compiler-compat all 7 octez-riscv-api all 7 octez-riscv-pvm all 6 -octez-rpc-process all 4 +octez-rpc-process all 3 octez-rust-deps all 7 octez-rustzcash-deps all 7 octez-shell-libs all 6 @@ -59,7 +60,7 @@ octez-smart-rollup-node-Proxford all 1 octez-smart-rollup-node-PsParisC all 1 octez-smart-rollup-node-PsQuebec all 1 octez-smart-rollup-node-PsRiotum all 1 -octez-smart-rollup-node-PtNairob all 2 +octez-smart-rollup-node-PtNairob all 1 octez-smart-rollup-node-PtParisB all 2 octez-smart-rollup-node-alpha all 2 octez-smart-rollup-node-lib all 2 @@ -67,12 +68,12 @@ octez-smart-rollup-wasm-debugger exec 1 octez-smart-rollup-wasm-debugger-lib all 2 octez-smart-rollup-wasm-debugger-plugin all 7 octez-version exec 6 -tezos-benchmark all 7 -tezos-client-demo-counter all 4 +tezos-benchmark all 6 +tezos-client-demo-counter all 3 tezos-client-genesis all 4 tezos-dal-node-lib all 4 -tezos-dal-node-services all 7 -tezos-openapi all 7 +tezos-dal-node-services all 6 +tezos-openapi all 6 tezos-protocol-000-Ps9mPmXa all 4 tezos-protocol-001-PtCJ7pwo all 4 tezos-protocol-002-PsYLVpVv all 4 @@ -81,9 +82,9 @@ tezos-protocol-004-Pt24m4xi all 4 tezos-protocol-005-PsBABY5H all 4 tezos-protocol-005-PsBabyM1 all 4 tezos-protocol-006-PsCARTHA all 4 -tezos-protocol-007-PsDELPH1 all 5 -tezos-protocol-008-PtEdo2Zk all 5 -tezos-protocol-008-PtEdoTez all 5 +tezos-protocol-007-PsDELPH1 all 4 +tezos-protocol-008-PtEdo2Zk all 4 +tezos-protocol-008-PtEdoTez all 4 tezos-protocol-009-PsFLoren all 5 tezos-protocol-010-PtGRANAD all 5 tezos-protocol-011-PtHangz2 all 5 @@ -96,10 +97,10 @@ tezos-protocol-017-PtNairob all 5 tezos-protocol-018-Proxford all 5 tezos-protocol-019-PtParisB all 5 tezos-protocol-020-PsParisC all 5 -tezos-protocol-021-PsQuebec all 6 -tezos-protocol-022-PsRiotum all 6 -tezos-protocol-alpha all 6 -tezos-protocol-demo-counter all 6 +tezos-protocol-021-PsQuebec all 5 +tezos-protocol-022-PsRiotum all 5 +tezos-protocol-alpha all 5 +tezos-protocol-demo-counter all 5 tezos-protocol-demo-noops all 6 tezos-protocol-genesis all 6 -tezt-tezos all 7 +tezt-tezos all 6 diff --git a/src/bin_agnostic_baker/dune b/src/bin_agnostic_baker/dune index 6f180040393d..d836df1c327c 100644 --- a/src/bin_agnostic_baker/dune +++ b/src/bin_agnostic_baker/dune @@ -9,13 +9,9 @@ (libraries octez-rust-deps bls12-381.archive - octez-libs.data-encoding octez-libs.base octez-libs.base.unix - octez-shell-libs.validation - octez-shell-libs.client-base-unix - octez-node-config - octez-shell-libs.client-commands + octez-experimental-agnostic-baker-lib octez-protocol-021-PsQuebec-libs.agnostic-baker octez-protocol-022-PsRiotum-libs.agnostic-baker (select void_for_linking-octez-protocol-alpha-libs-agnostic-baker from @@ -28,13 +24,10 @@ (-linkall)) (flags (:standard) - -open Data_encoding -open Tezos_base.TzPervasives -open Tezos_base -open Tezos_base_unix - -open Tezos_validation - -open Tezos_client_base_unix - -open Tezos_client_commands)) + -open Octez_experimental_agnostic_baker)) (rule (action diff --git a/src/bin_agnostic_baker/agnostic_baker_errors.ml b/src/lib_agnostic_baker/agnostic_baker_errors.ml similarity index 100% rename from src/bin_agnostic_baker/agnostic_baker_errors.ml rename to src/lib_agnostic_baker/agnostic_baker_errors.ml diff --git a/src/bin_agnostic_baker/agnostic_baker_events.ml b/src/lib_agnostic_baker/agnostic_baker_events.ml similarity index 100% rename from src/bin_agnostic_baker/agnostic_baker_events.ml rename to src/lib_agnostic_baker/agnostic_baker_events.ml diff --git a/src/bin_agnostic_baker/daemon.ml b/src/lib_agnostic_baker/daemon.ml similarity index 100% rename from src/bin_agnostic_baker/daemon.ml rename to src/lib_agnostic_baker/daemon.ml diff --git a/src/bin_agnostic_baker/daemon.mli b/src/lib_agnostic_baker/daemon.mli similarity index 100% rename from src/bin_agnostic_baker/daemon.mli rename to src/lib_agnostic_baker/daemon.mli diff --git a/src/lib_agnostic_baker/dune b/src/lib_agnostic_baker/dune new file mode 100644 index 000000000000..0ed43f8e45fb --- /dev/null +++ b/src/lib_agnostic_baker/dune @@ -0,0 +1,26 @@ +; This file was automatically generated, do not edit. +; Edit file manifest/main.ml instead. + +(library + (name octez_experimental_agnostic_baker) + (public_name octez-experimental-agnostic-baker-lib) + (instrumentation (backend bisect_ppx)) + (libraries + octez-rustzcash-deps + bls12-381.archive + octez-libs.data-encoding + octez-libs.base + octez-libs.base.unix + octez-shell-libs.validation + octez-shell-libs.client-base-unix + octez-node-config + octez-shell-libs.client-commands) + (flags + (:standard) + -open Data_encoding + -open Tezos_base.TzPervasives + -open Tezos_base + -open Tezos_base_unix + -open Tezos_validation + -open Tezos_client_base_unix + -open Tezos_client_commands)) diff --git a/src/bin_agnostic_baker/parameters.ml b/src/lib_agnostic_baker/parameters.ml similarity index 100% rename from src/bin_agnostic_baker/parameters.ml rename to src/lib_agnostic_baker/parameters.ml diff --git a/src/bin_agnostic_baker/parameters.mli b/src/lib_agnostic_baker/parameters.mli similarity index 100% rename from src/bin_agnostic_baker/parameters.mli rename to src/lib_agnostic_baker/parameters.mli diff --git a/src/bin_agnostic_baker/rpc_services.ml b/src/lib_agnostic_baker/rpc_services.ml similarity index 100% rename from src/bin_agnostic_baker/rpc_services.ml rename to src/lib_agnostic_baker/rpc_services.ml diff --git a/src/bin_agnostic_baker/rpc_services.mli b/src/lib_agnostic_baker/rpc_services.mli similarity index 100% rename from src/bin_agnostic_baker/rpc_services.mli rename to src/lib_agnostic_baker/rpc_services.mli diff --git a/src/bin_agnostic_baker/run_args.ml b/src/lib_agnostic_baker/run_args.ml similarity index 100% rename from src/bin_agnostic_baker/run_args.ml rename to src/lib_agnostic_baker/run_args.ml diff --git a/src/bin_agnostic_baker/run_args.mli b/src/lib_agnostic_baker/run_args.mli similarity index 100% rename from src/bin_agnostic_baker/run_args.mli rename to src/lib_agnostic_baker/run_args.mli diff --git a/src/proto_021_PsQuebec/lib_agnostic_baker/dune b/src/proto_021_PsQuebec/lib_agnostic_baker/dune index 09ef392b712c..e15489e2aed2 100644 --- a/src/proto_021_PsQuebec/lib_agnostic_baker/dune +++ b/src/proto_021_PsQuebec/lib_agnostic_baker/dune @@ -13,7 +13,8 @@ octez-shell-libs.validation octez-protocol-021-PsQuebec-libs.baking-commands octez-shell-libs.client-commands - octez-shell-libs.client-base-unix) + octez-shell-libs.client-base-unix + octez-experimental-agnostic-baker-lib) (library_flags (:standard -linkall)) (flags (:standard) @@ -24,4 +25,5 @@ -open Tezos_validation -open Tezos_baking_021_PsQuebec_commands -open Tezos_client_commands - -open Tezos_client_base_unix)) + -open Tezos_client_base_unix + -open Octez_experimental_agnostic_baker)) diff --git a/src/proto_022_PsRiotum/lib_agnostic_baker/dune b/src/proto_022_PsRiotum/lib_agnostic_baker/dune index 593e525dd924..c06e2c4e8cf8 100644 --- a/src/proto_022_PsRiotum/lib_agnostic_baker/dune +++ b/src/proto_022_PsRiotum/lib_agnostic_baker/dune @@ -13,7 +13,8 @@ octez-shell-libs.validation octez-protocol-022-PsRiotum-libs.baking-commands octez-shell-libs.client-commands - octez-shell-libs.client-base-unix) + octez-shell-libs.client-base-unix + octez-experimental-agnostic-baker-lib) (library_flags (:standard -linkall)) (flags (:standard) @@ -24,4 +25,5 @@ -open Tezos_validation -open Tezos_baking_022_PsRiotum_commands -open Tezos_client_commands - -open Tezos_client_base_unix)) + -open Tezos_client_base_unix + -open Octez_experimental_agnostic_baker)) diff --git a/src/proto_alpha/lib_agnostic_baker/dune b/src/proto_alpha/lib_agnostic_baker/dune index f1483edf2d59..a34f0f4aa8f0 100644 --- a/src/proto_alpha/lib_agnostic_baker/dune +++ b/src/proto_alpha/lib_agnostic_baker/dune @@ -13,7 +13,8 @@ octez-shell-libs.validation octez-protocol-alpha-libs.baking-commands octez-shell-libs.client-commands - octez-shell-libs.client-base-unix) + octez-shell-libs.client-base-unix + octez-experimental-agnostic-baker-lib) (library_flags (:standard -linkall)) (flags (:standard) @@ -24,4 +25,5 @@ -open Tezos_validation -open Tezos_baking_alpha_commands -open Tezos_client_commands - -open Tezos_client_base_unix)) + -open Tezos_client_base_unix + -open Octez_experimental_agnostic_baker)) -- GitLab From 95068ed4e2856b87186882ec1ea2afa9190f6d48 Mon Sep 17 00:00:00 2001 From: Gabriel Moise Date: Mon, 24 Feb 2025 13:11:18 +0000 Subject: [PATCH 03/13] Agnostic_baker: Rename agnostic baker plugin --- ...stic_baker_plugin_registration.ml => agnostic_baker_plugin.ml} | 0 ...stic_baker_plugin_registration.ml => agnostic_baker_plugin.ml} | 0 ...stic_baker_plugin_registration.ml => agnostic_baker_plugin.ml} | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename src/proto_021_PsQuebec/lib_agnostic_baker/{agnostic_baker_plugin_registration.ml => agnostic_baker_plugin.ml} (100%) rename src/proto_022_PsRiotum/lib_agnostic_baker/{agnostic_baker_plugin_registration.ml => agnostic_baker_plugin.ml} (100%) rename src/proto_alpha/lib_agnostic_baker/{agnostic_baker_plugin_registration.ml => agnostic_baker_plugin.ml} (100%) diff --git a/src/proto_021_PsQuebec/lib_agnostic_baker/agnostic_baker_plugin_registration.ml b/src/proto_021_PsQuebec/lib_agnostic_baker/agnostic_baker_plugin.ml similarity index 100% rename from src/proto_021_PsQuebec/lib_agnostic_baker/agnostic_baker_plugin_registration.ml rename to src/proto_021_PsQuebec/lib_agnostic_baker/agnostic_baker_plugin.ml diff --git a/src/proto_022_PsRiotum/lib_agnostic_baker/agnostic_baker_plugin_registration.ml b/src/proto_022_PsRiotum/lib_agnostic_baker/agnostic_baker_plugin.ml similarity index 100% rename from src/proto_022_PsRiotum/lib_agnostic_baker/agnostic_baker_plugin_registration.ml rename to src/proto_022_PsRiotum/lib_agnostic_baker/agnostic_baker_plugin.ml diff --git a/src/proto_alpha/lib_agnostic_baker/agnostic_baker_plugin_registration.ml b/src/proto_alpha/lib_agnostic_baker/agnostic_baker_plugin.ml similarity index 100% rename from src/proto_alpha/lib_agnostic_baker/agnostic_baker_plugin_registration.ml rename to src/proto_alpha/lib_agnostic_baker/agnostic_baker_plugin.ml -- GitLab From 132d5e021a9749c2ff1902e674b1e4fe5954e974 Mon Sep 17 00:00:00 2001 From: Gabriel Moise Date: Mon, 24 Feb 2025 13:46:38 +0000 Subject: [PATCH 04/13] Agnostic_baker: Move plugin registration and create baker commands helpers --- manifest/product_octez.ml | 1 - .../agnostic_baker_errors.ml | 15 ----- src/lib_agnostic_baker/daemon.ml | 36 +++++------- src/lib_agnostic_baker/dune | 2 - src/lib_agnostic_baker/protocol_plugin_sig.ml | 17 ++++++ src/lib_agnostic_baker/protocol_plugins.ml | 55 +++++++++++++++++++ src/lib_agnostic_baker/protocol_plugins.mli | 29 ++++++++++ src/lib_validation/protocol_plugin.ml | 26 --------- src/lib_validation/protocol_plugin.mli | 16 ------ .../agnostic_baker_plugin.ml | 11 ++-- .../baker_commands_helpers.ml | 10 ++++ .../baker_commands_helpers.mli | 8 +++ .../agnostic_baker_plugin.ml | 11 ++-- .../baker_commands_helpers.ml | 10 ++++ .../baker_commands_helpers.mli | 8 +++ .../agnostic_baker_plugin.ml | 11 ++-- .../baker_commands_helpers.ml | 10 ++++ .../baker_commands_helpers.mli | 8 +++ 18 files changed, 182 insertions(+), 102 deletions(-) create mode 100644 src/lib_agnostic_baker/protocol_plugin_sig.ml create mode 100644 src/lib_agnostic_baker/protocol_plugins.ml create mode 100644 src/lib_agnostic_baker/protocol_plugins.mli create mode 100644 src/proto_021_PsQuebec/lib_agnostic_baker/baker_commands_helpers.ml create mode 100644 src/proto_021_PsQuebec/lib_agnostic_baker/baker_commands_helpers.mli create mode 100644 src/proto_022_PsRiotum/lib_agnostic_baker/baker_commands_helpers.ml create mode 100644 src/proto_022_PsRiotum/lib_agnostic_baker/baker_commands_helpers.mli create mode 100644 src/proto_alpha/lib_agnostic_baker/baker_commands_helpers.ml create mode 100644 src/proto_alpha/lib_agnostic_baker/baker_commands_helpers.mli diff --git a/manifest/product_octez.ml b/manifest/product_octez.ml index 401ed1248663..1c5caa5f09e9 100644 --- a/manifest/product_octez.ml +++ b/manifest/product_octez.ml @@ -5354,7 +5354,6 @@ let octez_experimental_agnostic_baker_lib = data_encoding |> open_; octez_base |> open_ ~m:"TzPervasives" |> open_; octez_base_unix |> open_; - octez_validation |> open_; octez_client_base_unix |> open_; octez_node_config; octez_client_commands |> open_; diff --git a/src/lib_agnostic_baker/agnostic_baker_errors.ml b/src/lib_agnostic_baker/agnostic_baker_errors.ml index ab4ebb55d04b..f0545bc1875d 100644 --- a/src/lib_agnostic_baker/agnostic_baker_errors.ml +++ b/src/lib_agnostic_baker/agnostic_baker_errors.ml @@ -11,7 +11,6 @@ type error += | Cannot_connect_to_node of string | Cannot_decode_node_data of string | Missing_current_baker - | Missing_agnostic_baker_plugin of string | Baker_process_error let () = @@ -55,20 +54,6 @@ let () = Data_encoding.(unit) (function Missing_current_baker -> Some () | _ -> None) (fun () -> Missing_current_baker) ; - Error_monad.register_error_kind - `Permanent - ~id:"agnostic_baker.missing_agnostic_baker_plugin" - ~title:"Missing agnostic baker plugin" - ~description:"Missing agnostic baker plugin." - ~pp:(fun ppf proto_hash -> - Format.fprintf - ppf - "Cannot find agnostic baker plugin for protocol %s" - proto_hash) - Data_encoding.(obj1 (req "proto_hash" string)) - (function - | Missing_agnostic_baker_plugin proto_hash -> Some proto_hash | _ -> None) - (fun proto_hash -> Missing_agnostic_baker_plugin proto_hash) ; Error_monad.register_error_kind `Permanent ~id:"agnostic_baker.baker_process_error" diff --git a/src/lib_agnostic_baker/daemon.ml b/src/lib_agnostic_baker/daemon.ml index 539c896afa35..15cc8b6abb51 100644 --- a/src/lib_agnostic_baker/daemon.ml +++ b/src/lib_agnostic_baker/daemon.ml @@ -22,16 +22,15 @@ let shutdown baker = running thread for the baker given its corresponding [plugin], with the command line arguments given by [~baker_args] and cancellation Lwt promise [~cancel_promise]. The event logs are stored according to [~logs_path]. *) -let run_thread - (module Agnostic_baker_plugin : Protocol_plugin.AGNOSTIC_BAKER_PLUGIN) - ~baker_args ~cancel_promise ~logs_path = +let run_thread (module Plugin : Protocol_plugin_sig.S) ~baker_args + ~cancel_promise ~logs_path = let () = - Client_commands.register Agnostic_baker_plugin.hash @@ fun _network -> - Agnostic_baker_plugin.map_commands () + Client_commands.register Plugin.protocol_hash @@ fun _network -> + Plugin.Baker_commands_helpers.map_commands () in let select_commands _ _ = - Lwt_result_syntax.return @@ Agnostic_baker_plugin.map_commands () + Lwt_result_syntax.return @@ Plugin.Baker_commands_helpers.map_commands () in (* This call is not strictly necessary as the parameters are initialized @@ -78,21 +77,16 @@ let spawn_baker protocol_hash ~baker_args = let baker_args = "./mock-binary" :: baker_args in let cancel_promise, canceller = Lwt.wait () in let* thread = - match Protocol_plugin.find_agnostic_baker_plugin protocol_hash with - | Some plugin -> - (* The internal event logging needs to be closed, because another one will be - initialised in the [run_baker_binary]. *) - let*! () = Tezos_base_unix.Internal_event_unix.close () in - return - @@ run_thread - plugin - ~baker_args - ~cancel_promise - ~logs_path:Parameters.default_daily_logs_path - | None -> - tzfail - (Missing_agnostic_baker_plugin - (Protocol_hash.to_short_b58check protocol_hash)) + let*? plugin = Protocol_plugins.proto_plugin_for_protocol protocol_hash in + (* The internal event logging needs to be closed, because another one will be + initialised in the [run_baker_binary]. *) + let*! () = Tezos_base_unix.Internal_event_unix.close () in + return + @@ run_thread + plugin + ~baker_args + ~cancel_promise + ~logs_path:Parameters.default_daily_logs_path in let*! () = Agnostic_baker_events.(emit baker_running) protocol_hash in return {protocol_hash; process = {thread; canceller}} diff --git a/src/lib_agnostic_baker/dune b/src/lib_agnostic_baker/dune index 0ed43f8e45fb..ba71b4b59cab 100644 --- a/src/lib_agnostic_baker/dune +++ b/src/lib_agnostic_baker/dune @@ -11,7 +11,6 @@ octez-libs.data-encoding octez-libs.base octez-libs.base.unix - octez-shell-libs.validation octez-shell-libs.client-base-unix octez-node-config octez-shell-libs.client-commands) @@ -21,6 +20,5 @@ -open Tezos_base.TzPervasives -open Tezos_base -open Tezos_base_unix - -open Tezos_validation -open Tezos_client_base_unix -open Tezos_client_commands)) diff --git a/src/lib_agnostic_baker/protocol_plugin_sig.ml b/src/lib_agnostic_baker/protocol_plugin_sig.ml new file mode 100644 index 000000000000..718ee352a3b6 --- /dev/null +++ b/src/lib_agnostic_baker/protocol_plugin_sig.ml @@ -0,0 +1,17 @@ +(*****************************************************************************) +(* *) +(* SPDX-License-Identifier: MIT *) +(* Copyright (c) 2025 Trilitech *) +(* *) +(*****************************************************************************) + +module type BAKER_COMMANDS_HELPERS = sig + val map_commands : + unit -> Tezos_client_base.Client_context.full Tezos_clic.command list +end + +module type S = sig + val protocol_hash : Protocol_hash.t + + module Baker_commands_helpers : BAKER_COMMANDS_HELPERS +end diff --git a/src/lib_agnostic_baker/protocol_plugins.ml b/src/lib_agnostic_baker/protocol_plugins.ml new file mode 100644 index 000000000000..2ed10e0e265d --- /dev/null +++ b/src/lib_agnostic_baker/protocol_plugins.ml @@ -0,0 +1,55 @@ +(*****************************************************************************) +(* *) +(* SPDX-License-Identifier: MIT *) +(* Copyright (c) 2025 Trilitech *) +(* *) +(*****************************************************************************) + +type error += Unsupported_protocol of Protocol_hash.t + +let () = + register_error_kind + ~id:"agnostic_baker.unsupported_protocol" + ~title:"Protocol not supported by agnostic baker" + ~description:"Protocol not supported by agnostic baker." + ~pp:(fun ppf proto -> + Format.fprintf + ppf + "Protocol %a is not supported by the agnostic baker." + Protocol_hash.pp + proto) + `Permanent + Data_encoding.(obj1 (req "protocol" Protocol_hash.encoding)) + (function Unsupported_protocol p -> Some p | _ -> None) + (fun p -> Unsupported_protocol p) + +type proto_plugin = (module Protocol_plugin_sig.S) + +let proto_plugins : proto_plugin Protocol_hash.Table.t = + Protocol_hash.Table.create 7 + +let last_registered = ref None + +let register (plugin : proto_plugin) = + let module Plugin = (val plugin) in + if Protocol_hash.Table.mem proto_plugins Plugin.protocol_hash then + Format.kasprintf + invalid_arg + "The agnostic baker protocol plugin for protocol %a is already \ + registered. Did you register it manually multiple times?" + Protocol_hash.pp + Plugin.protocol_hash ; + last_registered := Some Plugin.protocol_hash ; + Protocol_hash.Table.add proto_plugins Plugin.protocol_hash plugin + +let registered_protocols () = + Protocol_hash.Table.to_seq_keys proto_plugins |> List.of_seq + +let last_registered () = + match !last_registered with + | None -> Stdlib.failwith "No protocol plugins registered" + | Some p -> p + +let proto_plugin_for_protocol protocol = + Protocol_hash.Table.find proto_plugins protocol + |> Option.to_result ~none:[Unsupported_protocol protocol] diff --git a/src/lib_agnostic_baker/protocol_plugins.mli b/src/lib_agnostic_baker/protocol_plugins.mli new file mode 100644 index 000000000000..7a6ac00d2fbb --- /dev/null +++ b/src/lib_agnostic_baker/protocol_plugins.mli @@ -0,0 +1,29 @@ +(*****************************************************************************) +(* *) +(* SPDX-License-Identifier: MIT *) +(* Copyright (c) 2025 Trilitech *) +(* *) +(*****************************************************************************) + +(** {2 Protocol registration logic} *) + +type proto_plugin = (module Protocol_plugin_sig.S) + +(** Register a protocol plugin for a specific protocol to be used by the + agnostic baker. *) +val register : proto_plugin -> unit + +(** Returns the list of registered protocols. *) +val registered_protocols : unit -> Protocol_hash.t list + +(** Returns the last registered protocol. + + NOTE: This is the last protocol with which the agnostic baker is linked + against, and this is decided only by the order in [manifest/main.ml]. *) +val last_registered : unit -> Protocol_hash.t + +(** {2 Using the correct protocol plugin} *) + +(** Return the protocol plugin for a given protocol (or an error if not + supported). *) +val proto_plugin_for_protocol : Protocol_hash.t -> proto_plugin tzresult diff --git a/src/lib_validation/protocol_plugin.ml b/src/lib_validation/protocol_plugin.ml index 29c2569505f0..b2f842aff4e3 100644 --- a/src/lib_validation/protocol_plugin.ml +++ b/src/lib_validation/protocol_plugin.ml @@ -165,13 +165,6 @@ module type SHELL_HELPERS = sig Tezos_protocol_environment.Context.t -> int32 option Lwt.t end -module type AGNOSTIC_BAKER_PLUGIN = sig - val hash : Protocol_hash.t - - val map_commands : - unit -> Tezos_client_base.Client_context.full Tezos_clic.command list -end - let rpc_table : (module RPC) Protocol_hash.Table.t = Protocol_hash.Table.create 5 @@ -185,10 +178,6 @@ let http_cache_headers_table : (module HTTP_CACHE_HEADERS) Protocol_hash.Table.t let shell_helpers_table : (module SHELL_HELPERS) Protocol_hash.Table.t = Protocol_hash.Table.create 5 -let agnostic_baker_plugin_table : - (module AGNOSTIC_BAKER_PLUGIN) Protocol_hash.Table.t = - Protocol_hash.Table.create 5 - let register_rpc (module Rpc : RPC) = assert (not (Protocol_hash.Table.mem rpc_table Rpc.Proto.hash)) ; Protocol_hash.Table.add rpc_table Rpc.Proto.hash (module Rpc) @@ -213,18 +202,6 @@ let register_shell_helpers (module Shell_helpers : SHELL_HELPERS) = Shell_helpers.hash (module Shell_helpers) -let register_agnostic_baker_plugin - (module Agnostic_baker_plugin : AGNOSTIC_BAKER_PLUGIN) = - assert ( - not - (Protocol_hash.Table.mem - agnostic_baker_plugin_table - Agnostic_baker_plugin.hash)) ; - Protocol_hash.Table.add - agnostic_baker_plugin_table - Agnostic_baker_plugin.hash - (module Agnostic_baker_plugin) - let find_rpc = Protocol_hash.Table.find rpc_table let find_metrics = Protocol_hash.Table.find metrics_table @@ -233,9 +210,6 @@ let find_http_cache_headers = Protocol_hash.Table.find http_cache_headers_table let find_shell_helpers = Protocol_hash.Table.find shell_helpers_table -let find_agnostic_baker_plugin = - Protocol_hash.Table.find agnostic_baker_plugin_table - let safe_find_metrics hash = match find_metrics hash with | Some proto_metrics -> Lwt.return proto_metrics diff --git a/src/lib_validation/protocol_plugin.mli b/src/lib_validation/protocol_plugin.mli index adf0ec3d874e..8b28e18ada03 100644 --- a/src/lib_validation/protocol_plugin.mli +++ b/src/lib_validation/protocol_plugin.mli @@ -212,15 +212,6 @@ module type SHELL_HELPERS = sig Tezos_protocol_environment.Context.t -> int32 option Lwt.t end -(** Protocol specific plugin to expose functions helpful in the scope - of the agnostic baker binary. *) -module type AGNOSTIC_BAKER_PLUGIN = sig - val hash : Protocol_hash.t - - val map_commands : - unit -> Tezos_client_base.Client_context.full Tezos_clic.command list -end - (** Register a validation plugin for a specific protocol (according to its [Proto.hash]). *) val register_validation_plugin : (module T) -> unit @@ -237,9 +228,6 @@ val register_http_cache_headers_plugin : (module HTTP_CACHE_HEADERS) -> unit (** Register a Shell_helpers plugin module *) val register_shell_helpers : (module SHELL_HELPERS) -> unit -(** Register an Agnostic_baker_plugin module *) -val register_agnostic_baker_plugin : (module AGNOSTIC_BAKER_PLUGIN) -> unit - (** Retrieves the registered protocol with the provided hash and wraps it together with its validation plugin. @@ -270,7 +258,3 @@ val find_http_cache_headers : (** Looks for a shell helpers plugin module for a specific protocol *) val find_shell_helpers : Protocol_hash.t -> (module SHELL_HELPERS) option - -(** Looks for an agnostic baker plugin module for a specific protocol *) -val find_agnostic_baker_plugin : - Protocol_hash.t -> (module AGNOSTIC_BAKER_PLUGIN) option diff --git a/src/proto_021_PsQuebec/lib_agnostic_baker/agnostic_baker_plugin.ml b/src/proto_021_PsQuebec/lib_agnostic_baker/agnostic_baker_plugin.ml index 7b81c0e8f433..fcc9eb4a3be9 100644 --- a/src/proto_021_PsQuebec/lib_agnostic_baker/agnostic_baker_plugin.ml +++ b/src/proto_021_PsQuebec/lib_agnostic_baker/agnostic_baker_plugin.ml @@ -5,13 +5,10 @@ (* *) (*****************************************************************************) -module Agnostic_baker_plugin = struct - let hash = Registerer.Registered.hash +module Plugin : Protocol_plugin_sig.S = struct + let protocol_hash = Protocol.hash - let map_commands () = - List.map (Tezos_clic.map_command (new Protocol_client_context.wrap_full)) - @@ Baking_commands.baker_commands () + module Baker_commands_helpers = Baker_commands_helpers end -let () = - Protocol_plugin.register_agnostic_baker_plugin (module Agnostic_baker_plugin) +let () = Protocol_plugins.register (module Plugin) 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 new file mode 100644 index 000000000000..5d753de5e538 --- /dev/null +++ b/src/proto_021_PsQuebec/lib_agnostic_baker/baker_commands_helpers.ml @@ -0,0 +1,10 @@ +(*****************************************************************************) +(* *) +(* SPDX-License-Identifier: MIT *) +(* Copyright (c) 2025 Trilitech *) +(* *) +(*****************************************************************************) + +let map_commands () = + List.map (Tezos_clic.map_command (new Protocol_client_context.wrap_full)) + @@ Baking_commands.baker_commands () diff --git a/src/proto_021_PsQuebec/lib_agnostic_baker/baker_commands_helpers.mli b/src/proto_021_PsQuebec/lib_agnostic_baker/baker_commands_helpers.mli new file mode 100644 index 000000000000..60fdac49d1dc --- /dev/null +++ b/src/proto_021_PsQuebec/lib_agnostic_baker/baker_commands_helpers.mli @@ -0,0 +1,8 @@ +(*****************************************************************************) +(* *) +(* SPDX-License-Identifier: MIT *) +(* Copyright (c) 2025 Trilitech *) +(* *) +(*****************************************************************************) + +include Protocol_plugin_sig.BAKER_COMMANDS_HELPERS diff --git a/src/proto_022_PsRiotum/lib_agnostic_baker/agnostic_baker_plugin.ml b/src/proto_022_PsRiotum/lib_agnostic_baker/agnostic_baker_plugin.ml index 7b81c0e8f433..fcc9eb4a3be9 100644 --- a/src/proto_022_PsRiotum/lib_agnostic_baker/agnostic_baker_plugin.ml +++ b/src/proto_022_PsRiotum/lib_agnostic_baker/agnostic_baker_plugin.ml @@ -5,13 +5,10 @@ (* *) (*****************************************************************************) -module Agnostic_baker_plugin = struct - let hash = Registerer.Registered.hash +module Plugin : Protocol_plugin_sig.S = struct + let protocol_hash = Protocol.hash - let map_commands () = - List.map (Tezos_clic.map_command (new Protocol_client_context.wrap_full)) - @@ Baking_commands.baker_commands () + module Baker_commands_helpers = Baker_commands_helpers end -let () = - Protocol_plugin.register_agnostic_baker_plugin (module Agnostic_baker_plugin) +let () = Protocol_plugins.register (module Plugin) 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 new file mode 100644 index 000000000000..5d753de5e538 --- /dev/null +++ b/src/proto_022_PsRiotum/lib_agnostic_baker/baker_commands_helpers.ml @@ -0,0 +1,10 @@ +(*****************************************************************************) +(* *) +(* SPDX-License-Identifier: MIT *) +(* Copyright (c) 2025 Trilitech *) +(* *) +(*****************************************************************************) + +let map_commands () = + List.map (Tezos_clic.map_command (new Protocol_client_context.wrap_full)) + @@ Baking_commands.baker_commands () diff --git a/src/proto_022_PsRiotum/lib_agnostic_baker/baker_commands_helpers.mli b/src/proto_022_PsRiotum/lib_agnostic_baker/baker_commands_helpers.mli new file mode 100644 index 000000000000..60fdac49d1dc --- /dev/null +++ b/src/proto_022_PsRiotum/lib_agnostic_baker/baker_commands_helpers.mli @@ -0,0 +1,8 @@ +(*****************************************************************************) +(* *) +(* SPDX-License-Identifier: MIT *) +(* Copyright (c) 2025 Trilitech *) +(* *) +(*****************************************************************************) + +include Protocol_plugin_sig.BAKER_COMMANDS_HELPERS diff --git a/src/proto_alpha/lib_agnostic_baker/agnostic_baker_plugin.ml b/src/proto_alpha/lib_agnostic_baker/agnostic_baker_plugin.ml index 7b81c0e8f433..fcc9eb4a3be9 100644 --- a/src/proto_alpha/lib_agnostic_baker/agnostic_baker_plugin.ml +++ b/src/proto_alpha/lib_agnostic_baker/agnostic_baker_plugin.ml @@ -5,13 +5,10 @@ (* *) (*****************************************************************************) -module Agnostic_baker_plugin = struct - let hash = Registerer.Registered.hash +module Plugin : Protocol_plugin_sig.S = struct + let protocol_hash = Protocol.hash - let map_commands () = - List.map (Tezos_clic.map_command (new Protocol_client_context.wrap_full)) - @@ Baking_commands.baker_commands () + module Baker_commands_helpers = Baker_commands_helpers end -let () = - Protocol_plugin.register_agnostic_baker_plugin (module Agnostic_baker_plugin) +let () = Protocol_plugins.register (module Plugin) diff --git a/src/proto_alpha/lib_agnostic_baker/baker_commands_helpers.ml b/src/proto_alpha/lib_agnostic_baker/baker_commands_helpers.ml new file mode 100644 index 000000000000..5d753de5e538 --- /dev/null +++ b/src/proto_alpha/lib_agnostic_baker/baker_commands_helpers.ml @@ -0,0 +1,10 @@ +(*****************************************************************************) +(* *) +(* SPDX-License-Identifier: MIT *) +(* Copyright (c) 2025 Trilitech *) +(* *) +(*****************************************************************************) + +let map_commands () = + List.map (Tezos_clic.map_command (new Protocol_client_context.wrap_full)) + @@ Baking_commands.baker_commands () diff --git a/src/proto_alpha/lib_agnostic_baker/baker_commands_helpers.mli b/src/proto_alpha/lib_agnostic_baker/baker_commands_helpers.mli new file mode 100644 index 000000000000..60fdac49d1dc --- /dev/null +++ b/src/proto_alpha/lib_agnostic_baker/baker_commands_helpers.mli @@ -0,0 +1,8 @@ +(*****************************************************************************) +(* *) +(* SPDX-License-Identifier: MIT *) +(* Copyright (c) 2025 Trilitech *) +(* *) +(*****************************************************************************) + +include Protocol_plugin_sig.BAKER_COMMANDS_HELPERS -- GitLab From aad9295ceb44a593365dfd8da137556cff9e60be Mon Sep 17 00:00:00 2001 From: Gabriel Moise Date: Wed, 26 Feb 2025 13:06:15 +0000 Subject: [PATCH 05/13] Agnostic_baker: Expose baker_commands function in plugin --- manifest/product_octez.ml | 1 + .../baker_commands_helpers.ml | 44 ++++++++++++- .../lib_agnostic_baker/dune | 2 + .../lib_delegate/baking_commands.mli | 65 +++++++++++++++++++ .../baker_commands_helpers.ml | 44 ++++++++++++- .../lib_agnostic_baker/dune | 2 + .../lib_delegate/baking_commands.mli | 65 +++++++++++++++++++ .../baker_commands_helpers.ml | 44 ++++++++++++- src/proto_alpha/lib_agnostic_baker/dune | 2 + .../lib_delegate/baking_commands.mli | 65 +++++++++++++++++++ 10 files changed, 331 insertions(+), 3 deletions(-) diff --git a/manifest/product_octez.ml b/manifest/product_octez.ml index 1c5caa5f09e9..4e3992336d97 100644 --- a/manifest/product_octez.ml +++ b/manifest/product_octez.ml @@ -7200,6 +7200,7 @@ let hash = Protocol.hash embedded |> open_; main |> open_; octez_validation |> open_; + baking |> if_some |> open_; baking_commands |> if_some |> open_; octez_client_commands |> open_; octez_client_base_unix |> open_; 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 5d753de5e538..9f44772213ac 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,6 +5,48 @@ (* *) (*****************************************************************************) +open Baking_commands + +let baker_commands () : Protocol_client_context.full Tezos_clic.command list = + let open Tezos_clic in + let group = + { + Tezos_clic.name = "delegate.baker"; + title = "Commands related to the baker daemon."; + } + 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) + (fun args local_data_dir_path sources cctxt -> + let baking_mode = Local {local_data_dir_path} in + run_baker args baking_mode 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); + command + ~group + ~desc:"Launch the VDF daemon" + (args2 pidfile_arg keep_alive_arg) + (prefixes ["run"; "vdf"] @@ stop) + (fun (pidfile, keep_alive) cctxt -> + may_lock_pidfile pidfile @@ fun () -> + Client_daemon.VDF.run cctxt ~chain:cctxt#chain ~keep_alive); + ] + let map_commands () = List.map (Tezos_clic.map_command (new Protocol_client_context.wrap_full)) - @@ Baking_commands.baker_commands () + @@ baker_commands () diff --git a/src/proto_021_PsQuebec/lib_agnostic_baker/dune b/src/proto_021_PsQuebec/lib_agnostic_baker/dune index e15489e2aed2..c2ae1c3637c3 100644 --- a/src/proto_021_PsQuebec/lib_agnostic_baker/dune +++ b/src/proto_021_PsQuebec/lib_agnostic_baker/dune @@ -11,6 +11,7 @@ tezos-protocol-021-PsQuebec.embedded-protocol tezos-protocol-021-PsQuebec.protocol octez-shell-libs.validation + octez-protocol-021-PsQuebec-libs.baking octez-protocol-021-PsQuebec-libs.baking-commands octez-shell-libs.client-commands octez-shell-libs.client-base-unix @@ -23,6 +24,7 @@ -open Tezos_embedded_protocol_021_PsQuebec -open Tezos_protocol_021_PsQuebec -open Tezos_validation + -open Tezos_baking_021_PsQuebec -open Tezos_baking_021_PsQuebec_commands -open Tezos_client_commands -open Tezos_client_base_unix diff --git a/src/proto_021_PsQuebec/lib_delegate/baking_commands.mli b/src/proto_021_PsQuebec/lib_delegate/baking_commands.mli index 02e2819da4b9..8c6d6ef5dc4f 100644 --- a/src/proto_021_PsQuebec/lib_delegate/baking_commands.mli +++ b/src/proto_021_PsQuebec/lib_delegate/baking_commands.mli @@ -23,6 +23,71 @@ (* *) (*****************************************************************************) +val pidfile_arg : (string option, Protocol_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, Protocol_client_context.full) Tezos_clic.arg + +val sources_param : + ( Environment.Signature.public_key_hash list -> + Protocol_client_context.full -> + unit Error_monad.tzresult Lwt.t, + Protocol_client_context.full ) + Tezos_clic.params + +val directory_parameter : + (string, Protocol_client_context.full) Tezos_clic.parameter + +type baking_mode = Local of {local_data_dir_path : string} | Remote + +val baker_args : + ( 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, + Protocol_client_context.full ) + Tezos_clic.options + +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 -> + Protocol_client_context.full -> + unit Error_monad.tzresult Lwt.t + val delegate_commands : unit -> Protocol_client_context.full Tezos_clic.command list 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 5d753de5e538..9f44772213ac 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,6 +5,48 @@ (* *) (*****************************************************************************) +open Baking_commands + +let baker_commands () : Protocol_client_context.full Tezos_clic.command list = + let open Tezos_clic in + let group = + { + Tezos_clic.name = "delegate.baker"; + title = "Commands related to the baker daemon."; + } + 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) + (fun args local_data_dir_path sources cctxt -> + let baking_mode = Local {local_data_dir_path} in + run_baker args baking_mode 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); + command + ~group + ~desc:"Launch the VDF daemon" + (args2 pidfile_arg keep_alive_arg) + (prefixes ["run"; "vdf"] @@ stop) + (fun (pidfile, keep_alive) cctxt -> + may_lock_pidfile pidfile @@ fun () -> + Client_daemon.VDF.run cctxt ~chain:cctxt#chain ~keep_alive); + ] + let map_commands () = List.map (Tezos_clic.map_command (new Protocol_client_context.wrap_full)) - @@ Baking_commands.baker_commands () + @@ baker_commands () diff --git a/src/proto_022_PsRiotum/lib_agnostic_baker/dune b/src/proto_022_PsRiotum/lib_agnostic_baker/dune index c06e2c4e8cf8..e746fe35f29b 100644 --- a/src/proto_022_PsRiotum/lib_agnostic_baker/dune +++ b/src/proto_022_PsRiotum/lib_agnostic_baker/dune @@ -11,6 +11,7 @@ tezos-protocol-022-PsRiotum.embedded-protocol tezos-protocol-022-PsRiotum.protocol octez-shell-libs.validation + octez-protocol-022-PsRiotum-libs.baking octez-protocol-022-PsRiotum-libs.baking-commands octez-shell-libs.client-commands octez-shell-libs.client-base-unix @@ -23,6 +24,7 @@ -open Tezos_embedded_protocol_022_PsRiotum -open Tezos_protocol_022_PsRiotum -open Tezos_validation + -open Tezos_baking_022_PsRiotum -open Tezos_baking_022_PsRiotum_commands -open Tezos_client_commands -open Tezos_client_base_unix diff --git a/src/proto_022_PsRiotum/lib_delegate/baking_commands.mli b/src/proto_022_PsRiotum/lib_delegate/baking_commands.mli index 02e2819da4b9..8c6d6ef5dc4f 100644 --- a/src/proto_022_PsRiotum/lib_delegate/baking_commands.mli +++ b/src/proto_022_PsRiotum/lib_delegate/baking_commands.mli @@ -23,6 +23,71 @@ (* *) (*****************************************************************************) +val pidfile_arg : (string option, Protocol_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, Protocol_client_context.full) Tezos_clic.arg + +val sources_param : + ( Environment.Signature.public_key_hash list -> + Protocol_client_context.full -> + unit Error_monad.tzresult Lwt.t, + Protocol_client_context.full ) + Tezos_clic.params + +val directory_parameter : + (string, Protocol_client_context.full) Tezos_clic.parameter + +type baking_mode = Local of {local_data_dir_path : string} | Remote + +val baker_args : + ( 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, + Protocol_client_context.full ) + Tezos_clic.options + +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 -> + Protocol_client_context.full -> + unit Error_monad.tzresult Lwt.t + val delegate_commands : unit -> Protocol_client_context.full Tezos_clic.command list 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 5d753de5e538..9f44772213ac 100644 --- a/src/proto_alpha/lib_agnostic_baker/baker_commands_helpers.ml +++ b/src/proto_alpha/lib_agnostic_baker/baker_commands_helpers.ml @@ -5,6 +5,48 @@ (* *) (*****************************************************************************) +open Baking_commands + +let baker_commands () : Protocol_client_context.full Tezos_clic.command list = + let open Tezos_clic in + let group = + { + Tezos_clic.name = "delegate.baker"; + title = "Commands related to the baker daemon."; + } + 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) + (fun args local_data_dir_path sources cctxt -> + let baking_mode = Local {local_data_dir_path} in + run_baker args baking_mode 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); + command + ~group + ~desc:"Launch the VDF daemon" + (args2 pidfile_arg keep_alive_arg) + (prefixes ["run"; "vdf"] @@ stop) + (fun (pidfile, keep_alive) cctxt -> + may_lock_pidfile pidfile @@ fun () -> + Client_daemon.VDF.run cctxt ~chain:cctxt#chain ~keep_alive); + ] + let map_commands () = List.map (Tezos_clic.map_command (new Protocol_client_context.wrap_full)) - @@ Baking_commands.baker_commands () + @@ baker_commands () diff --git a/src/proto_alpha/lib_agnostic_baker/dune b/src/proto_alpha/lib_agnostic_baker/dune index a34f0f4aa8f0..cef205fd4a55 100644 --- a/src/proto_alpha/lib_agnostic_baker/dune +++ b/src/proto_alpha/lib_agnostic_baker/dune @@ -11,6 +11,7 @@ tezos-protocol-alpha.embedded-protocol tezos-protocol-alpha.protocol octez-shell-libs.validation + octez-protocol-alpha-libs.baking octez-protocol-alpha-libs.baking-commands octez-shell-libs.client-commands octez-shell-libs.client-base-unix @@ -23,6 +24,7 @@ -open Tezos_embedded_protocol_alpha -open Tezos_protocol_alpha -open Tezos_validation + -open Tezos_baking_alpha -open Tezos_baking_alpha_commands -open Tezos_client_commands -open Tezos_client_base_unix diff --git a/src/proto_alpha/lib_delegate/baking_commands.mli b/src/proto_alpha/lib_delegate/baking_commands.mli index 02e2819da4b9..8c6d6ef5dc4f 100644 --- a/src/proto_alpha/lib_delegate/baking_commands.mli +++ b/src/proto_alpha/lib_delegate/baking_commands.mli @@ -23,6 +23,71 @@ (* *) (*****************************************************************************) +val pidfile_arg : (string option, Protocol_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, Protocol_client_context.full) Tezos_clic.arg + +val sources_param : + ( Environment.Signature.public_key_hash list -> + Protocol_client_context.full -> + unit Error_monad.tzresult Lwt.t, + Protocol_client_context.full ) + Tezos_clic.params + +val directory_parameter : + (string, Protocol_client_context.full) Tezos_clic.parameter + +type baking_mode = Local of {local_data_dir_path : string} | Remote + +val baker_args : + ( 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, + Protocol_client_context.full ) + Tezos_clic.options + +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 -> + Protocol_client_context.full -> + unit Error_monad.tzresult Lwt.t + val delegate_commands : unit -> Protocol_client_context.full Tezos_clic.command list -- GitLab From 57862097ed8831254a2cd440d48dd6c031fa28b9 Mon Sep 17 00:00:00 2001 From: Gabriel Moise Date: Wed, 26 Feb 2025 14:07:45 +0000 Subject: [PATCH 06/13] Agnostic_baker: Add protocol agnostic running function with CLI arguments parsing --- src/lib_agnostic_baker/configuration.ml | 417 ++++++++++++++++++ src/lib_agnostic_baker/configuration.mli | 85 ++++ src/lib_agnostic_baker/daemon.ml | 4 +- src/lib_agnostic_baker/protocol_plugin_sig.ml | 18 +- .../lib_agnostic_baker/baker_args_parser.ml | 74 ++++ .../lib_agnostic_baker/baker_args_parser.mli | 30 ++ .../baker_commands_helpers.ml | 38 +- .../lib_agnostic_baker/baker_args_parser.ml | 74 ++++ .../lib_agnostic_baker/baker_args_parser.mli | 30 ++ .../baker_commands_helpers.ml | 38 +- .../lib_agnostic_baker/baker_args_parser.ml | 74 ++++ .../lib_agnostic_baker/baker_args_parser.mli | 30 ++ .../baker_commands_helpers.ml | 38 +- 13 files changed, 905 insertions(+), 45 deletions(-) create mode 100644 src/lib_agnostic_baker/configuration.ml create mode 100644 src/lib_agnostic_baker/configuration.mli create mode 100644 src/proto_021_PsQuebec/lib_agnostic_baker/baker_args_parser.ml create mode 100644 src/proto_021_PsQuebec/lib_agnostic_baker/baker_args_parser.mli create mode 100644 src/proto_022_PsRiotum/lib_agnostic_baker/baker_args_parser.ml create mode 100644 src/proto_022_PsRiotum/lib_agnostic_baker/baker_args_parser.mli create mode 100644 src/proto_alpha/lib_agnostic_baker/baker_args_parser.ml create mode 100644 src/proto_alpha/lib_agnostic_baker/baker_args_parser.mli diff --git a/src/lib_agnostic_baker/configuration.ml b/src/lib_agnostic_baker/configuration.ml new file mode 100644 index 000000000000..205a4c6ec2f2 --- /dev/null +++ b/src/lib_agnostic_baker/configuration.ml @@ -0,0 +1,417 @@ +(*****************************************************************************) +(* *) +(* SPDX-License-Identifier: MIT *) +(* Copyright (c) 2025 Trilitech *) +(* *) +(*****************************************************************************) + +(** This is the module where the type of the CLI arguments configuration is + created. An argument of this type will be passed to the main running + function of the agnostic baker. *) + +type error += Block_vote_file_not_found of string + +type error += Bad_minimal_fees of string + +let () = + register_error_kind + `Permanent + ~id:"agnostic_baker.configuration.block_vote_file_not_found" + ~title: + "The provided block vote file path does not point to an existing file." + ~description: + "A block vote file path was provided on the command line but the path \ + does not point to an existing file." + ~pp:(fun ppf file_path -> + Format.fprintf + ppf + "@[The provided block vote file path \"%s\" does not point to an \ + existing file.@]" + file_path) + Data_encoding.(obj1 (req "file_path" string)) + (function + | Block_vote_file_not_found file_path -> Some file_path | _ -> None) + (fun file_path -> Block_vote_file_not_found file_path) ; + register_error_kind + `Permanent + ~id:"agnostic_baker.configuration.badMinimalFeesArg" + ~title:"Bad -minimal-fees arg" + ~description:"invalid fee threshold in -fee-threshold" + ~pp:(fun ppf literal -> + Format.fprintf ppf "invalid minimal fees '%s'" literal) + Data_encoding.(obj1 (req "parameter" string)) + (function Bad_minimal_fees parameter -> Some parameter | _ -> None) + (fun parameter -> Bad_minimal_fees parameter) + +(* Primitive argument parsers *) +let string_parameter = + Tezos_clic.parameter + (fun (_cctxt : Tezos_client_base.Client_context.full) x -> + Lwt_result.return x) + +let int_parameter = + Tezos_clic.parameter (fun (cctxt : Tezos_client_base.Client_context.full) p -> + try Lwt_result.return (int_of_string p) + with _ -> cctxt#error "Cannot read int") + +let uri_parameter = + Tezos_clic.parameter + (fun (_cctxt : Tezos_client_base.Client_context.full) x -> + Lwt_result.return (Uri.of_string x)) + +let per_block_vote_parameter = + let open Lwt_result_syntax in + Tezos_clic.parameter + ~autocomplete:(fun _ctxt -> return ["on"; "off"; "pass"]) + (fun (_cctxt : Tezos_client_base.Client_context.full) -> function + | ("on" | "off" | "pass") as s -> return s + | s -> + failwith + "unexpected vote: %s, expected either \"on\", \"off\", or \"pass\"." + s) + +(* Baker arguments *) +let pidfile_arg = + let open Lwt_result_syntax in + Tezos_clic.arg + ~doc:"write process id in file" + ~short:'P' + ~long:"pidfile" + ~placeholder:"filename" + (Tezos_clic.parameter + (fun (_cctxt : Tezos_client_base.Client_context.full) s -> return s)) + +let may_lock_pidfile pidfile_opt f = + match pidfile_opt with + | None -> f () + | Some pidfile -> + Tezos_stdlib_unix.Lwt_lock_file.with_lock + ~when_locked: + (`Fail (Exn (Failure ("Failed to create the pidfile: " ^ pidfile)))) + ~filename:pidfile + f + +let node_version_check_bypass_arg : + (bool, Tezos_client_base.Client_context.full) Tezos_clic.arg = + Tezos_clic.switch + ~long:"node-version-check-bypass" + ~doc: + "If node-version-check-bypass flag is set, the baker will not check its \ + compatibility with the version of the node to which it is connected." + () + +let node_version_allowed_arg = + Tezos_clic.arg + ~long:"node-version-allowed" + ~placeholder:"-[v].[.0][:]" + ~doc: + "When specified the baker will accept to run with a node of this \ + version. The specified version is composed of the product, for example \ + 'octez'; the major and the minor versions that are positive integers; \ + the info, for example '-rc', '-beta1+dev' or realese if none is \ + provided; optionally the commit that is the hash of the last git commit \ + or a prefix of at least 8 characters long." + string_parameter + +let default_minimal_fees = 100L + +let default_minimal_nanotez_per_gas_unit = Q.of_int 100 + +let default_minimal_nanotez_per_byte = Q.of_int 1000 + +let minimal_fees_arg = + let open Lwt_result_syntax in + Tezos_clic.default_arg + ~long:"minimal-fees" + ~placeholder:"amount" + ~doc:"exclude operations with fees lower than this threshold (in tez)" + ~default:(Int64.to_string default_minimal_fees) + (Tezos_clic.parameter + (fun (_cctxt : Tezos_client_base.Client_context.full) s -> + match Int64.of_string_opt s with + | Some t -> return t + | None -> tzfail (Bad_minimal_fees s))) + +let minimal_nanotez_per_gas_unit_arg = + let open Lwt_result_syntax in + Tezos_clic.default_arg + ~long:"minimal-nanotez-per-gas-unit" + ~placeholder:"amount" + ~doc: + "exclude operations with fees per gas lower than this threshold (in \ + nanotez)" + ~default:(Q.to_string default_minimal_nanotez_per_gas_unit) + (Tezos_clic.parameter + (fun (_cctxt : Tezos_client_base.Client_context.full) s -> + try return (Q.of_string s) with _ -> tzfail (Bad_minimal_fees s))) + +let minimal_nanotez_per_byte_arg = + let open Lwt_result_syntax in + Tezos_clic.default_arg + ~long:"minimal-nanotez-per-byte" + ~placeholder:"amount" + ~default:(Q.to_string default_minimal_nanotez_per_byte) + ~doc: + "exclude operations with fees per byte lower than this threshold (in \ + nanotez)" + (Tezos_clic.parameter + (fun (_cctxt : Tezos_client_base.Client_context.full) s -> + try return (Q.of_string s) with _ -> tzfail (Bad_minimal_fees s))) + +let force_apply_from_round_arg = + Tezos_clic.arg + ~long:"force-apply-from-round" + ~placeholder:"round" + ~doc: + "Force the baker to not only validate but also apply operations starting \ + from the specified round." + int_parameter + +let keep_alive_arg : + (bool, Tezos_client_base.Client_context.full) Tezos_clic.arg = + Tezos_clic.switch + ~doc: + "Keep the daemon process alive: when the connection with the node is \ + lost, the daemon periodically tries to reach it." + ~short:'K' + ~long:"keep-alive" + () + +let liquidity_baking_toggle_vote_arg = + Tezos_clic.arg + ~doc: + "Vote to continue or end the liquidity baking subsidy. The possible \ + values for this option are: \"off\" to request ending the subsidy, \ + \"on\" to request continuing or restarting the subsidy, and \"pass\" to \ + abstain. Note that this \"option\" is mandatory!" + ~long:"liquidity-baking-toggle-vote" + ~placeholder:"vote" + per_block_vote_parameter + +let adaptive_issuance_vote_arg = + Tezos_clic.arg + ~doc: + "Vote to adopt or not the adaptive issuance feature. The possible values \ + for this option are: \"off\" to request not activating it, \"on\" to \ + request activating it, and \"pass\" to abstain. If you do not vote, \ + default value is \"pass\"." + ~long:"adaptive-issuance-vote" + ~placeholder:"vote" + per_block_vote_parameter + +let per_block_vote_file_arg = + Tezos_clic.arg + ~doc:"read per block votes as json file" + ~short:'V' + ~long:"votefile" + ~placeholder:"filename" + (Tezos_clic.parameter + (fun (_cctxt : Tezos_client_base.Client_context.full) file -> + let open Lwt_result_syntax in + let* file_exists = + protect + ~on_error:(fun _ -> tzfail (Block_vote_file_not_found file)) + (fun () -> + let*! b = Lwt_unix.file_exists file in + return b) + in + if file_exists then return file + else tzfail (Block_vote_file_not_found file))) + +let http_headers_env_variable = + "TEZOS_CLIENT_REMOTE_OPERATIONS_POOL_HTTP_HEADERS" + +let http_headers = + match Sys.getenv_opt http_headers_env_variable with + | None -> None + | Some contents -> + let lines = String.split_on_char '\n' contents in + Some + (List.fold_left + (fun acc line -> + match String.index_opt line ':' with + | None -> + invalid_arg + (Printf.sprintf + "Http headers: invalid %s environment variable, missing \ + colon" + http_headers_env_variable) + | Some pos -> + let header = String.trim (String.sub line 0 pos) in + let header = String.lowercase_ascii header in + if header <> "host" then + invalid_arg + (Printf.sprintf + "Http headers: invalid %s environment variable, only \ + 'host' headers are supported" + http_headers_env_variable) ; + let value = + String.trim + (String.sub line (pos + 1) (String.length line - pos - 1)) + in + (header, value) :: acc) + [] + lines) + +let operations_arg = + Tezos_clic.arg + ~long:"operations-pool" + ~placeholder:"file|uri" + ~doc: + (Printf.sprintf + "When specified, the baker will try to fetch operations from this \ + file (or uri) and to include retrieved operations in the block. The \ + expected format of the contents is a list of operations [ \ + alpha.operation ]. Environment variable '%s' may also be specified \ + to add headers to the requests (only 'host' headers are supported). \ + If the resource cannot be retrieved, e.g., if the file is absent, \ + unreadable, or the web service returns a 404 error, the resource is \ + simply ignored." + http_headers_env_variable) + uri_parameter + +let dal_node_endpoint_arg = + Tezos_clic.arg + ~long:"dal-node" + ~placeholder:"uri" + ~doc:"endpoint of the DAL node, e.g. 'http://localhost:8933'" + uri_parameter + +let without_dal_arg : + (bool, Tezos_client_base.Client_context.full) Tezos_clic.arg = + Tezos_clic.switch + ~long:"without-dal" + ~doc: + "If without-dal flag is set, the daemon will not try to connect to a DAL \ + node." + () + +let state_recorder_switch_arg : + (bool, Tezos_client_base.Client_context.full) Tezos_clic.arg = + Tezos_clic.switch + ~long:"record-state" + ~doc: + "If record-state flag is set, the baker saves all its internal consensus \ + state in the filesystem, otherwise just in memory." + () + +let pre_emptive_forge_time_arg = + let open Lwt_result_syntax in + Tezos_clic.arg + ~long:"pre-emptive-forge-time" + ~placeholder:"seconds" + ~doc: + "Sets the pre-emptive forge time optimization, in seconds. When set, the \ + baker, if it is the next level round 0 proposer, will start forging \ + after quorum has been reached in the current level while idly waiting \ + for it to end. When it is its time to propose, the baker will inject \ + the pre-emptively forged block immediately, allowing more time for the \ + network to reach quorum on it. Operators should note that the higher \ + this value `t`, the lower the operation inclusion window (specifically \ + `block_time - t`) which may lead to lower baking rewards. Defaults to \ + 15/% of block time. Set to 0 to ignore pre-emptive forging." + (Tezos_clic.parameter + (fun (_cctxt : Tezos_client_base.Client_context.full) s -> + try return (Q.of_string s) + with _ -> failwith "pre-emptive-forge-time expected int or float.")) + +let remote_calls_timeout_arg = + let open Lwt_result_syntax in + Tezos_clic.arg + ~long:"remote-calls-timeout" + ~placeholder:"seconds" + ~doc: + "Sets a timeout for client calls such as signing block header or \ + attestation and for the creation of deterministic nonce. Use only if \ + your remote signer can handle concurrent requests." + (Tezos_clic.parameter + (fun (_cctxt : Tezos_client_base.Client_context.full) s -> + 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 + (fun (_cctxt : Tezos_client_base.Client_context.full) p -> + let*! exists = Tezos_stdlib_unix.Lwt_utils_unix.dir_exists p in + if not exists then failwith "Directory doesn't exist: '%s'" p + else return p) + +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/configuration.mli b/src/lib_agnostic_baker/configuration.mli new file mode 100644 index 000000000000..89b2588ad532 --- /dev/null +++ b/src/lib_agnostic_baker/configuration.mli @@ -0,0 +1,85 @@ +(*****************************************************************************) +(* *) +(* 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 + +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/daemon.ml b/src/lib_agnostic_baker/daemon.ml index 15cc8b6abb51..4eb09fd25f37 100644 --- a/src/lib_agnostic_baker/daemon.ml +++ b/src/lib_agnostic_baker/daemon.ml @@ -26,11 +26,11 @@ let run_thread (module Plugin : Protocol_plugin_sig.S) ~baker_args ~cancel_promise ~logs_path = let () = Client_commands.register Plugin.protocol_hash @@ fun _network -> - Plugin.Baker_commands_helpers.map_commands () + Plugin.Baker_commands_helpers.baker_commands () in let select_commands _ _ = - Lwt_result_syntax.return @@ Plugin.Baker_commands_helpers.map_commands () + Lwt_result_syntax.return @@ Plugin.Baker_commands_helpers.baker_commands () in (* This call is not strictly necessary as the parameters are initialized diff --git a/src/lib_agnostic_baker/protocol_plugin_sig.ml b/src/lib_agnostic_baker/protocol_plugin_sig.ml index 718ee352a3b6..5d1e027d06f7 100644 --- a/src/lib_agnostic_baker/protocol_plugin_sig.ml +++ b/src/lib_agnostic_baker/protocol_plugin_sig.ml @@ -6,7 +6,23 @@ (*****************************************************************************) module type BAKER_COMMANDS_HELPERS = sig - val map_commands : + (** [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]. + + 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 -> + sources:Tezos_crypto.Signature.V1.public_key_hash list -> + cctxt:Tezos_client_base.Client_context.full -> + unit Error_monad.tzresult Lwt.t + + val baker_commands : unit -> Tezos_client_base.Client_context.full Tezos_clic.command list end 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 new file mode 100644 index 000000000000..3260cfb0cdfd --- /dev/null +++ b/src/proto_021_PsQuebec/lib_agnostic_baker/baker_args_parser.ml @@ -0,0 +1,74 @@ +(*****************************************************************************) +(* *) +(* SPDX-License-Identifier: MIT *) +(* Copyright (c) 2025 Trilitech *) +(* *) +(*****************************************************************************) + +open Configuration +open Protocol.Alpha_context + +let parse_minimal_fees = Tez.of_mutez_exn + +let parse_per_block_vote = + Option.map (function + | "on" -> Per_block_votes.Per_block_vote_on + | "off" -> Per_block_vote_off + | "pass" -> Per_block_vote_pass + (* This is unreachable because any other value would fail in CLI configuration parsing *) + | _ -> assert false) + +let parse_operations = + let open Baking_configuration.Operations_source in + Option.map (fun uri -> + match Uri.scheme uri with + | Some "http" | Some "https" -> Remote {uri; http_headers} + | None | Some _ -> + (* acts as if it were file even though it might no be *) + Local {filename = Uri.to_string uri}) + +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; + } = + ( 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} + | None -> Remote 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 new file mode 100644 index 000000000000..d70f3aa2a6b6 --- /dev/null +++ b/src/proto_021_PsQuebec/lib_agnostic_baker/baker_args_parser.mli @@ -0,0 +1,30 @@ +(*****************************************************************************) +(* *) +(* SPDX-License-Identifier: MIT *) +(* Copyright (c) 2025 Trilitech *) +(* *) +(*****************************************************************************) + +open Protocol.Alpha_context + +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 + +val parse_baking_mode : string option -> Baking_commands.baking_mode 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 9f44772213ac..c6166ec6ac0f 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,15 +5,26 @@ (* *) (*****************************************************************************) -open Baking_commands +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 cctxt = new Protocol_client_context.wrap_full cctxt in + Baking_commands.run_baker args baking_mode sources cctxt -let baker_commands () : Protocol_client_context.full Tezos_clic.command list = +let sources_param = + Tezos_clic.seq_of_param + (Client_keys.Public_key_hash.source_param + ~name:"baker" + ~desc: + "name of the delegate owning the attestation/baking right or name of \ + the consensus key signing on the delegate's behalf") + +let baker_commands () : + Tezos_client_base.Client_context.full Tezos_clic.command list = + let open Configuration in let open Tezos_clic in let group = - { - Tezos_clic.name = "delegate.baker"; - title = "Commands related to the baker daemon."; - } + {name = "delegate.baker"; title = "Commands related to the baker daemon."} in [ command @@ -27,26 +38,25 @@ let baker_commands () : Protocol_client_context.full Tezos_clic.command list = 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); + let baking_mode = Some local_data_dir_path in + let configuration = create_config args in + run_baker ~configuration ~baking_mode ~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); + let baking_mode = None in + let configuration = create_config args in + run_baker ~configuration ~baking_mode ~sources ~cctxt); command ~group ~desc:"Launch the VDF daemon" (args2 pidfile_arg keep_alive_arg) (prefixes ["run"; "vdf"] @@ stop) (fun (pidfile, keep_alive) cctxt -> + let cctxt = new Protocol_client_context.wrap_full cctxt in may_lock_pidfile pidfile @@ fun () -> Client_daemon.VDF.run cctxt ~chain:cctxt#chain ~keep_alive); ] - -let map_commands () = - List.map (Tezos_clic.map_command (new Protocol_client_context.wrap_full)) - @@ baker_commands () 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 new file mode 100644 index 000000000000..3260cfb0cdfd --- /dev/null +++ b/src/proto_022_PsRiotum/lib_agnostic_baker/baker_args_parser.ml @@ -0,0 +1,74 @@ +(*****************************************************************************) +(* *) +(* SPDX-License-Identifier: MIT *) +(* Copyright (c) 2025 Trilitech *) +(* *) +(*****************************************************************************) + +open Configuration +open Protocol.Alpha_context + +let parse_minimal_fees = Tez.of_mutez_exn + +let parse_per_block_vote = + Option.map (function + | "on" -> Per_block_votes.Per_block_vote_on + | "off" -> Per_block_vote_off + | "pass" -> Per_block_vote_pass + (* This is unreachable because any other value would fail in CLI configuration parsing *) + | _ -> assert false) + +let parse_operations = + let open Baking_configuration.Operations_source in + Option.map (fun uri -> + match Uri.scheme uri with + | Some "http" | Some "https" -> Remote {uri; http_headers} + | None | Some _ -> + (* acts as if it were file even though it might no be *) + Local {filename = Uri.to_string uri}) + +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; + } = + ( 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} + | None -> Remote 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 new file mode 100644 index 000000000000..d70f3aa2a6b6 --- /dev/null +++ b/src/proto_022_PsRiotum/lib_agnostic_baker/baker_args_parser.mli @@ -0,0 +1,30 @@ +(*****************************************************************************) +(* *) +(* SPDX-License-Identifier: MIT *) +(* Copyright (c) 2025 Trilitech *) +(* *) +(*****************************************************************************) + +open Protocol.Alpha_context + +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 + +val parse_baking_mode : string option -> Baking_commands.baking_mode 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 9f44772213ac..c6166ec6ac0f 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,15 +5,26 @@ (* *) (*****************************************************************************) -open Baking_commands +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 cctxt = new Protocol_client_context.wrap_full cctxt in + Baking_commands.run_baker args baking_mode sources cctxt -let baker_commands () : Protocol_client_context.full Tezos_clic.command list = +let sources_param = + Tezos_clic.seq_of_param + (Client_keys.Public_key_hash.source_param + ~name:"baker" + ~desc: + "name of the delegate owning the attestation/baking right or name of \ + the consensus key signing on the delegate's behalf") + +let baker_commands () : + Tezos_client_base.Client_context.full Tezos_clic.command list = + let open Configuration in let open Tezos_clic in let group = - { - Tezos_clic.name = "delegate.baker"; - title = "Commands related to the baker daemon."; - } + {name = "delegate.baker"; title = "Commands related to the baker daemon."} in [ command @@ -27,26 +38,25 @@ let baker_commands () : Protocol_client_context.full Tezos_clic.command list = 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); + let baking_mode = Some local_data_dir_path in + let configuration = create_config args in + run_baker ~configuration ~baking_mode ~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); + let baking_mode = None in + let configuration = create_config args in + run_baker ~configuration ~baking_mode ~sources ~cctxt); command ~group ~desc:"Launch the VDF daemon" (args2 pidfile_arg keep_alive_arg) (prefixes ["run"; "vdf"] @@ stop) (fun (pidfile, keep_alive) cctxt -> + let cctxt = new Protocol_client_context.wrap_full cctxt in may_lock_pidfile pidfile @@ fun () -> Client_daemon.VDF.run cctxt ~chain:cctxt#chain ~keep_alive); ] - -let map_commands () = - List.map (Tezos_clic.map_command (new Protocol_client_context.wrap_full)) - @@ baker_commands () diff --git a/src/proto_alpha/lib_agnostic_baker/baker_args_parser.ml b/src/proto_alpha/lib_agnostic_baker/baker_args_parser.ml new file mode 100644 index 000000000000..3260cfb0cdfd --- /dev/null +++ b/src/proto_alpha/lib_agnostic_baker/baker_args_parser.ml @@ -0,0 +1,74 @@ +(*****************************************************************************) +(* *) +(* SPDX-License-Identifier: MIT *) +(* Copyright (c) 2025 Trilitech *) +(* *) +(*****************************************************************************) + +open Configuration +open Protocol.Alpha_context + +let parse_minimal_fees = Tez.of_mutez_exn + +let parse_per_block_vote = + Option.map (function + | "on" -> Per_block_votes.Per_block_vote_on + | "off" -> Per_block_vote_off + | "pass" -> Per_block_vote_pass + (* This is unreachable because any other value would fail in CLI configuration parsing *) + | _ -> assert false) + +let parse_operations = + let open Baking_configuration.Operations_source in + Option.map (fun uri -> + match Uri.scheme uri with + | Some "http" | Some "https" -> Remote {uri; http_headers} + | None | Some _ -> + (* acts as if it were file even though it might no be *) + Local {filename = Uri.to_string uri}) + +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; + } = + ( 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} + | None -> Remote diff --git a/src/proto_alpha/lib_agnostic_baker/baker_args_parser.mli b/src/proto_alpha/lib_agnostic_baker/baker_args_parser.mli new file mode 100644 index 000000000000..d70f3aa2a6b6 --- /dev/null +++ b/src/proto_alpha/lib_agnostic_baker/baker_args_parser.mli @@ -0,0 +1,30 @@ +(*****************************************************************************) +(* *) +(* SPDX-License-Identifier: MIT *) +(* Copyright (c) 2025 Trilitech *) +(* *) +(*****************************************************************************) + +open Protocol.Alpha_context + +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 + +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 9f44772213ac..c6166ec6ac0f 100644 --- a/src/proto_alpha/lib_agnostic_baker/baker_commands_helpers.ml +++ b/src/proto_alpha/lib_agnostic_baker/baker_commands_helpers.ml @@ -5,15 +5,26 @@ (* *) (*****************************************************************************) -open Baking_commands +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 cctxt = new Protocol_client_context.wrap_full cctxt in + Baking_commands.run_baker args baking_mode sources cctxt -let baker_commands () : Protocol_client_context.full Tezos_clic.command list = +let sources_param = + Tezos_clic.seq_of_param + (Client_keys.Public_key_hash.source_param + ~name:"baker" + ~desc: + "name of the delegate owning the attestation/baking right or name of \ + the consensus key signing on the delegate's behalf") + +let baker_commands () : + Tezos_client_base.Client_context.full Tezos_clic.command list = + let open Configuration in let open Tezos_clic in let group = - { - Tezos_clic.name = "delegate.baker"; - title = "Commands related to the baker daemon."; - } + {name = "delegate.baker"; title = "Commands related to the baker daemon."} in [ command @@ -27,26 +38,25 @@ let baker_commands () : Protocol_client_context.full Tezos_clic.command list = 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); + let baking_mode = Some local_data_dir_path in + let configuration = create_config args in + run_baker ~configuration ~baking_mode ~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); + let baking_mode = None in + let configuration = create_config args in + run_baker ~configuration ~baking_mode ~sources ~cctxt); command ~group ~desc:"Launch the VDF daemon" (args2 pidfile_arg keep_alive_arg) (prefixes ["run"; "vdf"] @@ stop) (fun (pidfile, keep_alive) cctxt -> + let cctxt = new Protocol_client_context.wrap_full cctxt in may_lock_pidfile pidfile @@ fun () -> Client_daemon.VDF.run cctxt ~chain:cctxt#chain ~keep_alive); ] - -let map_commands () = - List.map (Tezos_clic.map_command (new Protocol_client_context.wrap_full)) - @@ baker_commands () -- GitLab From d97938b7d0318f013d3c15a92ee765914e97b6c8 Mon Sep 17 00:00:00 2001 From: Gabriel Moise Date: Thu, 27 Feb 2025 15:40:07 +0000 Subject: [PATCH 07/13] Agnostic_baker: Move delegate sources argument to agnostic baker configuration --- src/lib_agnostic_baker/configuration.ml | 8 ++++++++ src/lib_agnostic_baker/configuration.mli | 7 +++++++ src/lib_agnostic_baker/protocol_plugin_sig.ml | 2 +- .../lib_agnostic_baker/baker_args_parser.ml | 6 ++++++ .../lib_agnostic_baker/baker_args_parser.mli | 5 +++++ .../lib_agnostic_baker/baker_commands_helpers.ml | 10 ++-------- .../lib_agnostic_baker/baker_args_parser.ml | 6 ++++++ .../lib_agnostic_baker/baker_args_parser.mli | 5 +++++ .../lib_agnostic_baker/baker_commands_helpers.ml | 10 ++-------- .../lib_agnostic_baker/baker_commands_helpers.ml | 8 -------- 10 files changed, 42 insertions(+), 25 deletions(-) diff --git a/src/lib_agnostic_baker/configuration.ml b/src/lib_agnostic_baker/configuration.ml index 205a4c6ec2f2..b627e9a1c311 100644 --- a/src/lib_agnostic_baker/configuration.ml +++ b/src/lib_agnostic_baker/configuration.ml @@ -357,6 +357,14 @@ let directory_parameter = if not exists then failwith "Directory doesn't exist: '%s'" p else return p) +let sources_param = + Tezos_clic.seq_of_param + (Tezos_client_base.Client_keys.Public_key_hash.source_param + ~name:"baker" + ~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; diff --git a/src/lib_agnostic_baker/configuration.mli b/src/lib_agnostic_baker/configuration.mli index 89b2588ad532..92edf903dab0 100644 --- a/src/lib_agnostic_baker/configuration.mli +++ b/src/lib_agnostic_baker/configuration.mli @@ -44,6 +44,13 @@ val baker_args : 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; diff --git a/src/lib_agnostic_baker/protocol_plugin_sig.ml b/src/lib_agnostic_baker/protocol_plugin_sig.ml index 5d1e027d06f7..dc62344818bd 100644 --- a/src/lib_agnostic_baker/protocol_plugin_sig.ml +++ b/src/lib_agnostic_baker/protocol_plugin_sig.ml @@ -18,7 +18,7 @@ module type BAKER_COMMANDS_HELPERS = sig val run_baker : configuration:Configuration.t -> baking_mode:string option -> - sources:Tezos_crypto.Signature.V1.public_key_hash list -> + 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_args_parser.ml b/src/proto_021_PsQuebec/lib_agnostic_baker/baker_args_parser.ml index 3260cfb0cdfd..7ec8d3510d26 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 @@ -72,3 +72,9 @@ let parse_baking_mode baking_mode = match baking_mode with | Some local_data_dir_path -> Baking_commands.Local {local_data_dir_path} | None -> Remote + +let parse_sources = + List.map_es (fun source -> + match Tezos_crypto.Signature.V1.Of_V_latest.public_key_hash source with + | Some source -> Lwt_result_syntax.return source + | None -> failwith "Cannot convert from V_latest signature to V1.") 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 d70f3aa2a6b6..4aa83665ccc4 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 @@ -28,3 +28,8 @@ val parse_configuration : * Q.t option val parse_baking_mode : string option -> Baking_commands.baking_mode + +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 c6166ec6ac0f..dd02d5b986c7 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 @@ -6,19 +6,13 @@ (*****************************************************************************) 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 cctxt = new Protocol_client_context.wrap_full cctxt in Baking_commands.run_baker args baking_mode sources cctxt -let sources_param = - Tezos_clic.seq_of_param - (Client_keys.Public_key_hash.source_param - ~name:"baker" - ~desc: - "name of the delegate owning the attestation/baking right or name of \ - the consensus key signing on the delegate's behalf") - let baker_commands () : Tezos_client_base.Client_context.full Tezos_clic.command list = let open Configuration in 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 3260cfb0cdfd..7ec8d3510d26 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 @@ -72,3 +72,9 @@ let parse_baking_mode baking_mode = match baking_mode with | Some local_data_dir_path -> Baking_commands.Local {local_data_dir_path} | None -> Remote + +let parse_sources = + List.map_es (fun source -> + match Tezos_crypto.Signature.V1.Of_V_latest.public_key_hash source with + | Some source -> Lwt_result_syntax.return source + | None -> failwith "Cannot convert from V_latest signature to V1.") 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 d70f3aa2a6b6..4aa83665ccc4 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 @@ -28,3 +28,8 @@ val parse_configuration : * Q.t option val parse_baking_mode : string option -> Baking_commands.baking_mode + +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 c6166ec6ac0f..dd02d5b986c7 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 @@ -6,19 +6,13 @@ (*****************************************************************************) 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 cctxt = new Protocol_client_context.wrap_full cctxt in Baking_commands.run_baker args baking_mode sources cctxt -let sources_param = - Tezos_clic.seq_of_param - (Client_keys.Public_key_hash.source_param - ~name:"baker" - ~desc: - "name of the delegate owning the attestation/baking right or name of \ - the consensus key signing on the delegate's behalf") - let baker_commands () : Tezos_client_base.Client_context.full Tezos_clic.command list = let open Configuration in 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 c6166ec6ac0f..da4b29fccb95 100644 --- a/src/proto_alpha/lib_agnostic_baker/baker_commands_helpers.ml +++ b/src/proto_alpha/lib_agnostic_baker/baker_commands_helpers.ml @@ -11,14 +11,6 @@ let run_baker ~configuration ~baking_mode ~sources ~cctxt = let cctxt = new Protocol_client_context.wrap_full cctxt in Baking_commands.run_baker args baking_mode sources cctxt -let sources_param = - Tezos_clic.seq_of_param - (Client_keys.Public_key_hash.source_param - ~name:"baker" - ~desc: - "name of the delegate owning the attestation/baking right or name of \ - the consensus key signing on the delegate's behalf") - let baker_commands () : Tezos_client_base.Client_context.full Tezos_clic.command list = let open Configuration in -- GitLab From 3f5b30e14b76ffcb9e4ba63ee266224e2a5ab07b Mon Sep 17 00:00:00 2001 From: Gabriel Moise Date: Thu, 27 Feb 2025 15:56:33 +0000 Subject: [PATCH 08/13] Agnostic_baker: Move baker_commands and Tezos_clic away from plugin --- src/lib_agnostic_baker/commands.ml | 58 +++++++++++++++++++ src/lib_agnostic_baker/commands.mli | 10 ++++ src/lib_agnostic_baker/daemon.ml | 25 ++++---- src/lib_agnostic_baker/protocol_plugin_sig.ml | 6 +- .../baker_commands_helpers.ml | 44 +------------- .../baker_commands_helpers.ml | 44 +------------- .../baker_commands_helpers.ml | 44 +------------- 7 files changed, 94 insertions(+), 137 deletions(-) create mode 100644 src/lib_agnostic_baker/commands.ml create mode 100644 src/lib_agnostic_baker/commands.mli diff --git a/src/lib_agnostic_baker/commands.ml b/src/lib_agnostic_baker/commands.ml new file mode 100644 index 000000000000..2c8ca0c60bc6 --- /dev/null +++ b/src/lib_agnostic_baker/commands.ml @@ -0,0 +1,58 @@ +(*****************************************************************************) +(* *) +(* SPDX-License-Identifier: MIT *) +(* Copyright (c) 2025 Trilitech *) +(* *) +(*****************************************************************************) + +let baker_commands (module Plugin : Protocol_plugin_sig.S) : + Tezos_client_base.Client_context.full Tezos_clic.command list = + let open Configuration 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 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) + (fun args local_data_dir_path sources cctxt -> + let baking_mode = Some local_data_dir_path in + let configuration = create_config args in + Plugin.Baker_commands_helpers.run_baker + ~configuration + ~baking_mode + ~sources + ~cctxt); + command + ~group + ~desc:"Launch the baker daemon using RPCs only." + baker_args + (prefixes ["run"; "remotely"] @@ sources_param) + (fun args sources cctxt -> + let baking_mode = None in + let configuration = create_config args in + Plugin.Baker_commands_helpers.run_baker + ~configuration + ~baking_mode + ~sources + ~cctxt); + command + ~group + ~desc:"Launch the VDF daemon" + (args2 pidfile_arg keep_alive_arg) + (prefixes ["run"; "vdf"] @@ stop) + (fun (pidfile, keep_alive) cctxt -> + may_lock_pidfile pidfile @@ fun () -> + Plugin.Baker_commands_helpers.run_vdf_daemon ~cctxt ~keep_alive); + ] diff --git a/src/lib_agnostic_baker/commands.mli b/src/lib_agnostic_baker/commands.mli new file mode 100644 index 000000000000..cb8993868b91 --- /dev/null +++ b/src/lib_agnostic_baker/commands.mli @@ -0,0 +1,10 @@ +(*****************************************************************************) +(* *) +(* SPDX-License-Identifier: MIT *) +(* Copyright (c) 2025 Trilitech *) +(* *) +(*****************************************************************************) + +val baker_commands : + (module Protocol_plugin_sig.S) -> + Tezos_client_base.Client_context.full Tezos_clic.command list diff --git a/src/lib_agnostic_baker/daemon.ml b/src/lib_agnostic_baker/daemon.ml index 4eb09fd25f37..943ad04f6219 100644 --- a/src/lib_agnostic_baker/daemon.ml +++ b/src/lib_agnostic_baker/daemon.ml @@ -18,20 +18,19 @@ let shutdown baker = Lwt.wakeup baker.process.canceller 0 ; return_unit -(** [run_thread plugin ~baker_args ~cancel_promise ~logs_path] returns the main - running thread for the baker given its corresponding [plugin], with the command - line arguments given by [~baker_args] and cancellation Lwt promise - [~cancel_promise]. The event logs are stored according to [~logs_path]. *) -let run_thread (module Plugin : Protocol_plugin_sig.S) ~baker_args - ~cancel_promise ~logs_path = +(** [run_thread ~protocol_hash ~baker_commands ~baker_args ~cancel_promise ~logs_path] + returns the main running thread for the baker given its protocol [~procol_hash], + corresponding commands [~baker_commands], with the command line arguments given by + [~baker_args] and Lwt cancellation promise [~cancel_promise]. + + The event logs are stored according to [~logs_path]. *) +let run_thread ~protocol_hash ~baker_commands ~baker_args ~cancel_promise + ~logs_path = let () = - Client_commands.register Plugin.protocol_hash @@ fun _network -> - Plugin.Baker_commands_helpers.baker_commands () + Client_commands.register protocol_hash @@ fun _network -> baker_commands in - let select_commands _ _ = - Lwt_result_syntax.return @@ Plugin.Baker_commands_helpers.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 @@ -81,9 +80,11 @@ let spawn_baker protocol_hash ~baker_args = (* The internal event logging needs to be closed, because another one will be initialised in the [run_baker_binary]. *) let*! () = Tezos_base_unix.Internal_event_unix.close () in + let baker_commands = Commands.baker_commands plugin in return @@ run_thread - plugin + ~protocol_hash + ~baker_commands ~baker_args ~cancel_promise ~logs_path:Parameters.default_daily_logs_path diff --git a/src/lib_agnostic_baker/protocol_plugin_sig.ml b/src/lib_agnostic_baker/protocol_plugin_sig.ml index dc62344818bd..a2f73794b821 100644 --- a/src/lib_agnostic_baker/protocol_plugin_sig.ml +++ b/src/lib_agnostic_baker/protocol_plugin_sig.ml @@ -22,8 +22,10 @@ module type BAKER_COMMANDS_HELPERS = sig cctxt:Tezos_client_base.Client_context.full -> unit Error_monad.tzresult Lwt.t - val baker_commands : - unit -> Tezos_client_base.Client_context.full Tezos_clic.command list + val run_vdf_daemon : + cctxt:Tezos_client_base.Client_context.full -> + keep_alive:bool -> + unit tzresult Lwt.t end module type S = sig 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 dd02d5b986c7..89fe030096a9 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 @@ -13,44 +13,6 @@ let run_baker ~configuration ~baking_mode ~sources ~cctxt = let cctxt = new Protocol_client_context.wrap_full cctxt in Baking_commands.run_baker args baking_mode sources cctxt -let baker_commands () : - Tezos_client_base.Client_context.full Tezos_clic.command list = - let open Configuration in - let open Tezos_clic in - let group = - {name = "delegate.baker"; title = "Commands related to the baker daemon."} - 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) - (fun args local_data_dir_path sources cctxt -> - let baking_mode = Some local_data_dir_path in - let configuration = create_config args in - run_baker ~configuration ~baking_mode ~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 = None in - let configuration = create_config args in - run_baker ~configuration ~baking_mode ~sources ~cctxt); - command - ~group - ~desc:"Launch the VDF daemon" - (args2 pidfile_arg keep_alive_arg) - (prefixes ["run"; "vdf"] @@ stop) - (fun (pidfile, keep_alive) cctxt -> - let cctxt = new Protocol_client_context.wrap_full cctxt in - may_lock_pidfile pidfile @@ fun () -> - Client_daemon.VDF.run cctxt ~chain:cctxt#chain ~keep_alive); - ] +let run_vdf_daemon ~cctxt ~keep_alive = + let cctxt = new Protocol_client_context.wrap_full cctxt in + Client_daemon.VDF.run cctxt ~chain:cctxt#chain ~keep_alive 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 dd02d5b986c7..89fe030096a9 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 @@ -13,44 +13,6 @@ let run_baker ~configuration ~baking_mode ~sources ~cctxt = let cctxt = new Protocol_client_context.wrap_full cctxt in Baking_commands.run_baker args baking_mode sources cctxt -let baker_commands () : - Tezos_client_base.Client_context.full Tezos_clic.command list = - let open Configuration in - let open Tezos_clic in - let group = - {name = "delegate.baker"; title = "Commands related to the baker daemon."} - 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) - (fun args local_data_dir_path sources cctxt -> - let baking_mode = Some local_data_dir_path in - let configuration = create_config args in - run_baker ~configuration ~baking_mode ~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 = None in - let configuration = create_config args in - run_baker ~configuration ~baking_mode ~sources ~cctxt); - command - ~group - ~desc:"Launch the VDF daemon" - (args2 pidfile_arg keep_alive_arg) - (prefixes ["run"; "vdf"] @@ stop) - (fun (pidfile, keep_alive) cctxt -> - let cctxt = new Protocol_client_context.wrap_full cctxt in - may_lock_pidfile pidfile @@ fun () -> - Client_daemon.VDF.run cctxt ~chain:cctxt#chain ~keep_alive); - ] +let run_vdf_daemon ~cctxt ~keep_alive = + let cctxt = new Protocol_client_context.wrap_full cctxt in + Client_daemon.VDF.run cctxt ~chain:cctxt#chain ~keep_alive 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 da4b29fccb95..9996e3999da5 100644 --- a/src/proto_alpha/lib_agnostic_baker/baker_commands_helpers.ml +++ b/src/proto_alpha/lib_agnostic_baker/baker_commands_helpers.ml @@ -11,44 +11,6 @@ let run_baker ~configuration ~baking_mode ~sources ~cctxt = let cctxt = new Protocol_client_context.wrap_full cctxt in Baking_commands.run_baker args baking_mode sources cctxt -let baker_commands () : - Tezos_client_base.Client_context.full Tezos_clic.command list = - let open Configuration in - let open Tezos_clic in - let group = - {name = "delegate.baker"; title = "Commands related to the baker daemon."} - 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) - (fun args local_data_dir_path sources cctxt -> - let baking_mode = Some local_data_dir_path in - let configuration = create_config args in - run_baker ~configuration ~baking_mode ~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 = None in - let configuration = create_config args in - run_baker ~configuration ~baking_mode ~sources ~cctxt); - command - ~group - ~desc:"Launch the VDF daemon" - (args2 pidfile_arg keep_alive_arg) - (prefixes ["run"; "vdf"] @@ stop) - (fun (pidfile, keep_alive) cctxt -> - let cctxt = new Protocol_client_context.wrap_full cctxt in - may_lock_pidfile pidfile @@ fun () -> - Client_daemon.VDF.run cctxt ~chain:cctxt#chain ~keep_alive); - ] +let run_vdf_daemon ~cctxt ~keep_alive = + let cctxt = new Protocol_client_context.wrap_full cctxt in + Client_daemon.VDF.run cctxt ~chain:cctxt#chain ~keep_alive -- GitLab From 62be8c112fd81094ed390afe8bdd407732be8e00 Mon Sep 17 00:00:00 2001 From: Gabriel Moise Date: Thu, 27 Feb 2025 16:02:47 +0000 Subject: [PATCH 09/13] Baker: Expose less functions from baking_commands --- .../lib_delegate/baking_commands.mli | 40 ------------------- .../lib_delegate/baking_commands.mli | 40 ------------------- .../lib_delegate/baking_commands.mli | 40 ------------------- 3 files changed, 120 deletions(-) diff --git a/src/proto_021_PsQuebec/lib_delegate/baking_commands.mli b/src/proto_021_PsQuebec/lib_delegate/baking_commands.mli index 8c6d6ef5dc4f..c808d3055330 100644 --- a/src/proto_021_PsQuebec/lib_delegate/baking_commands.mli +++ b/src/proto_021_PsQuebec/lib_delegate/baking_commands.mli @@ -23,48 +23,8 @@ (* *) (*****************************************************************************) -val pidfile_arg : (string option, Protocol_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, Protocol_client_context.full) Tezos_clic.arg - -val sources_param : - ( Environment.Signature.public_key_hash list -> - Protocol_client_context.full -> - unit Error_monad.tzresult Lwt.t, - Protocol_client_context.full ) - Tezos_clic.params - -val directory_parameter : - (string, Protocol_client_context.full) Tezos_clic.parameter - type baking_mode = Local of {local_data_dir_path : string} | Remote -val baker_args : - ( 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, - Protocol_client_context.full ) - Tezos_clic.options - val run_baker : string option * bool diff --git a/src/proto_022_PsRiotum/lib_delegate/baking_commands.mli b/src/proto_022_PsRiotum/lib_delegate/baking_commands.mli index 8c6d6ef5dc4f..c808d3055330 100644 --- a/src/proto_022_PsRiotum/lib_delegate/baking_commands.mli +++ b/src/proto_022_PsRiotum/lib_delegate/baking_commands.mli @@ -23,48 +23,8 @@ (* *) (*****************************************************************************) -val pidfile_arg : (string option, Protocol_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, Protocol_client_context.full) Tezos_clic.arg - -val sources_param : - ( Environment.Signature.public_key_hash list -> - Protocol_client_context.full -> - unit Error_monad.tzresult Lwt.t, - Protocol_client_context.full ) - Tezos_clic.params - -val directory_parameter : - (string, Protocol_client_context.full) Tezos_clic.parameter - type baking_mode = Local of {local_data_dir_path : string} | Remote -val baker_args : - ( 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, - Protocol_client_context.full ) - Tezos_clic.options - val run_baker : string option * bool diff --git a/src/proto_alpha/lib_delegate/baking_commands.mli b/src/proto_alpha/lib_delegate/baking_commands.mli index 8c6d6ef5dc4f..c808d3055330 100644 --- a/src/proto_alpha/lib_delegate/baking_commands.mli +++ b/src/proto_alpha/lib_delegate/baking_commands.mli @@ -23,48 +23,8 @@ (* *) (*****************************************************************************) -val pidfile_arg : (string option, Protocol_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, Protocol_client_context.full) Tezos_clic.arg - -val sources_param : - ( Environment.Signature.public_key_hash list -> - Protocol_client_context.full -> - unit Error_monad.tzresult Lwt.t, - Protocol_client_context.full ) - Tezos_clic.params - -val directory_parameter : - (string, Protocol_client_context.full) Tezos_clic.parameter - type baking_mode = Local of {local_data_dir_path : string} | Remote -val baker_args : - ( 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, - Protocol_client_context.full ) - Tezos_clic.options - val run_baker : string option * bool -- GitLab From b9f2c111978181e4aa3678a52e486b04b0e14c86 Mon Sep 17 00:00:00 2001 From: Gabriel Moise Date: Thu, 27 Feb 2025 16:11:48 +0000 Subject: [PATCH 10/13] Agnostic_baker: Update changelog --- CHANGES.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index f918b2512ffd..b7bc06175562 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -40,6 +40,10 @@ Baker Agnostic Baker -------------- +- The agnostic baker has a unified CLI such that incompatibilities between baking arguments + for consecutive protocols can occur much harder, and will probably generate compilation + errors. (MR :gl:`!16968`) + - The agnostic baker no longer requires the protocol specific baking binaries, instead it directly spawns baking processes using a protocol plugin to retrieve the necessary functionalities. (MR :gl:`!16583`) -- GitLab From 2456ab19823f370afab2441530870777fce32a72 Mon Sep 17 00:00:00 2001 From: Gabriel Moise Date: Wed, 12 Mar 2025 10:04:54 +0000 Subject: [PATCH 11/13] Agnostic_baker: Fix CI --- .../ci/pipelines/schedule_extended_test.yml | 33 ++++++++++--------- tobi/config | 1 + 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/.gitlab/ci/pipelines/schedule_extended_test.yml b/.gitlab/ci/pipelines/schedule_extended_test.yml index d3a78f8bf4bc..0bb19457dcd3 100644 --- a/.gitlab/ci/pipelines/schedule_extended_test.yml +++ b/.gitlab/ci/pipelines/schedule_extended_test.yml @@ -1193,16 +1193,17 @@ opam:all_6: parallel: matrix: - package: + - tezt-tezos - tezos-protocol-genesis - tezos-protocol-demo-noops - - tezos-protocol-demo-counter - - tezos-protocol-alpha - - tezos-protocol-022-PsRiotum - - tezos-protocol-021-PsQuebec + - tezos-openapi + - tezos-dal-node-services + - tezos-benchmark - octez-shell-libs - octez-riscv-pvm - octez-proto-libs - octez-performance-metrics + - octez-libs - octez-l2-libs - efunc_core - dal_node_migrations @@ -1320,7 +1321,6 @@ opam:all_2: - octez-smart-rollup-node-lib - octez-smart-rollup-node-alpha - octez-smart-rollup-node-PtParisB - - octez-smart-rollup-node-PtNairob - octez-protocol-alpha-libs - octez-protocol-022-PsRiotum-libs - octez-protocol-021-PsQuebec-libs @@ -1329,8 +1329,10 @@ opam:all_2: - octez-protocol-018-Proxford-libs - octez-protocol-017-PtNairob-libs - octez-protocol-016-PtMumbai-libs + - octez-protocol-001-PtCJ7pwo-libs - octez-protocol-000-Ps9mPmXa-libs - octez-injector + - octez-experimental-agnostic-baker-lib opam:all_1: image: ${ci_image_name}/prebuild:${ci_image_tag} @@ -1385,6 +1387,7 @@ opam:all_1: parallel: matrix: - package: + - octez-smart-rollup-node-PtNairob - octez-smart-rollup-node-PsRiotum - octez-smart-rollup-node-PsQuebec - octez-smart-rollup-node-PsParisC @@ -1443,6 +1446,8 @@ opam:all_3: parallel: matrix: - package: + - tezos-client-demo-counter + - octez-rpc-process - octez-protocol-015-PtLimaPt-libs - octez-protocol-014-PtKathma-libs - octez-protocol-013-PtJakart-libs @@ -1457,7 +1462,6 @@ opam:all_3: - octez-protocol-004-Pt24m4xi-libs - octez-protocol-003-PsddFKi3-libs - octez-protocol-002-PsYLVpVv-libs - - octez-protocol-001-PtCJ7pwo-libs opam:exec_4: image: ${ci_image_name}/prebuild:${ci_image_tag} @@ -1567,6 +1571,9 @@ opam:all_4: parallel: matrix: - package: + - tezos-protocol-008-PtEdoTez + - tezos-protocol-008-PtEdo2Zk + - tezos-protocol-007-PsDELPH1 - tezos-protocol-006-PsCARTHA - tezos-protocol-005-PsBabyM1 - tezos-protocol-005-PsBABY5H @@ -1577,8 +1584,6 @@ opam:all_4: - tezos-protocol-000-Ps9mPmXa - tezos-dal-node-lib - tezos-client-genesis - - tezos-client-demo-counter - - octez-rpc-process - octez-node-config - octez-crawler @@ -1700,6 +1705,10 @@ opam:all_5: parallel: matrix: - package: + - tezos-protocol-demo-counter + - tezos-protocol-alpha + - tezos-protocol-022-PsRiotum + - tezos-protocol-021-PsQuebec - tezos-protocol-020-PsParisC - tezos-protocol-019-PtParisB - tezos-protocol-018-Proxford @@ -1712,9 +1721,6 @@ opam:all_5: - tezos-protocol-011-PtHangz2 - tezos-protocol-010-PtGRANAD - tezos-protocol-009-PsFLoren - - tezos-protocol-008-PtEdoTez - - tezos-protocol-008-PtEdo2Zk - - tezos-protocol-007-PsDELPH1 opam:all_7: image: ${ci_image_name}/prebuild:${ci_image_tag} @@ -1769,16 +1775,11 @@ opam:all_7: parallel: matrix: - package: - - tezt-tezos - - tezos-openapi - - tezos-dal-node-services - - tezos-benchmark - octez-smart-rollup-wasm-debugger-plugin - octez-rustzcash-deps - octez-rust-deps - octez-riscv-api - octez-protocol-compiler-compat - - octez-libs - octez-internal-libs - octez-distributed-lwt-internal - octez-distributed-internal diff --git a/tobi/config b/tobi/config index b94f3e687d29..e6cb52194bef 100644 --- a/tobi/config +++ b/tobi/config @@ -32,6 +32,7 @@ octez-evm-node-libs: etherlink/bin_node/config, etherlink/bin_node/installers, e octez-evm-node-tests: etherlink/bin_node/test octez-evm-wasm-runtime-tests: etherlink/lib_wasm_runtime_callbacks/test octez-experimental-agnostic-baker: src/bin_agnostic_baker +octez-experimental-agnostic-baker-lib: src/lib_agnostic_baker octez-injector: src/lib_injector octez-injector-server: contrib/octez_injector_server octez-internal-libs: irmin/lib_irmin, irmin/lib_irmin/data, irmin/lib_irmin/mem, irmin/lib_irmin_pack, irmin/lib_irmin_pack/mem, irmin/lib_irmin_pack/unix, irmin/lib_irmin_tezos, irmin/lib_ppx_irmin, irmin/lib_ppx_irmin/internal, irmin/test/helpers -- GitLab From 948c14b2d07b48e9f6cb941d6ce4fe097dba4cbe Mon Sep 17 00:00:00 2001 From: Gabriel Moise Date: Mon, 3 Mar 2025 09:58:08 +0000 Subject: [PATCH 12/13] Agnostic_baker: Remove unnecessary dependencies --- manifest/product_octez.ml | 4 ---- src/proto_021_PsQuebec/lib_agnostic_baker/dune | 8 -------- src/proto_022_PsRiotum/lib_agnostic_baker/dune | 8 -------- src/proto_alpha/lib_agnostic_baker/dune | 8 -------- 4 files changed, 28 deletions(-) diff --git a/manifest/product_octez.ml b/manifest/product_octez.ml index 4e3992336d97..7d8b91b8da6d 100644 --- a/manifest/product_octez.ml +++ b/manifest/product_octez.ml @@ -7197,13 +7197,9 @@ let hash = Protocol.hash [ octez_base |> open_ ~m:"TzPervasives"; client |> if_some |> open_; - embedded |> open_; main |> open_; - octez_validation |> open_; baking |> if_some |> open_; baking_commands |> if_some |> open_; - octez_client_commands |> open_; - octez_client_base_unix |> open_; octez_experimental_agnostic_baker_lib |> open_; ] ~linkall:true diff --git a/src/proto_021_PsQuebec/lib_agnostic_baker/dune b/src/proto_021_PsQuebec/lib_agnostic_baker/dune index c2ae1c3637c3..d12bd39185a2 100644 --- a/src/proto_021_PsQuebec/lib_agnostic_baker/dune +++ b/src/proto_021_PsQuebec/lib_agnostic_baker/dune @@ -8,24 +8,16 @@ (libraries octez-libs.base octez-protocol-021-PsQuebec-libs.client - tezos-protocol-021-PsQuebec.embedded-protocol tezos-protocol-021-PsQuebec.protocol - octez-shell-libs.validation octez-protocol-021-PsQuebec-libs.baking octez-protocol-021-PsQuebec-libs.baking-commands - octez-shell-libs.client-commands - octez-shell-libs.client-base-unix octez-experimental-agnostic-baker-lib) (library_flags (:standard -linkall)) (flags (:standard) -open Tezos_base.TzPervasives -open Tezos_client_021_PsQuebec - -open Tezos_embedded_protocol_021_PsQuebec -open Tezos_protocol_021_PsQuebec - -open Tezos_validation -open Tezos_baking_021_PsQuebec -open Tezos_baking_021_PsQuebec_commands - -open Tezos_client_commands - -open Tezos_client_base_unix -open Octez_experimental_agnostic_baker)) diff --git a/src/proto_022_PsRiotum/lib_agnostic_baker/dune b/src/proto_022_PsRiotum/lib_agnostic_baker/dune index e746fe35f29b..1b6322dfa982 100644 --- a/src/proto_022_PsRiotum/lib_agnostic_baker/dune +++ b/src/proto_022_PsRiotum/lib_agnostic_baker/dune @@ -8,24 +8,16 @@ (libraries octez-libs.base octez-protocol-022-PsRiotum-libs.client - tezos-protocol-022-PsRiotum.embedded-protocol tezos-protocol-022-PsRiotum.protocol - octez-shell-libs.validation octez-protocol-022-PsRiotum-libs.baking octez-protocol-022-PsRiotum-libs.baking-commands - octez-shell-libs.client-commands - octez-shell-libs.client-base-unix octez-experimental-agnostic-baker-lib) (library_flags (:standard -linkall)) (flags (:standard) -open Tezos_base.TzPervasives -open Tezos_client_022_PsRiotum - -open Tezos_embedded_protocol_022_PsRiotum -open Tezos_protocol_022_PsRiotum - -open Tezos_validation -open Tezos_baking_022_PsRiotum -open Tezos_baking_022_PsRiotum_commands - -open Tezos_client_commands - -open Tezos_client_base_unix -open Octez_experimental_agnostic_baker)) diff --git a/src/proto_alpha/lib_agnostic_baker/dune b/src/proto_alpha/lib_agnostic_baker/dune index cef205fd4a55..592b925cf929 100644 --- a/src/proto_alpha/lib_agnostic_baker/dune +++ b/src/proto_alpha/lib_agnostic_baker/dune @@ -8,24 +8,16 @@ (libraries octez-libs.base octez-protocol-alpha-libs.client - tezos-protocol-alpha.embedded-protocol tezos-protocol-alpha.protocol - octez-shell-libs.validation octez-protocol-alpha-libs.baking octez-protocol-alpha-libs.baking-commands - octez-shell-libs.client-commands - octez-shell-libs.client-base-unix octez-experimental-agnostic-baker-lib) (library_flags (:standard -linkall)) (flags (:standard) -open Tezos_base.TzPervasives -open Tezos_client_alpha - -open Tezos_embedded_protocol_alpha -open Tezos_protocol_alpha - -open Tezos_validation -open Tezos_baking_alpha -open Tezos_baking_alpha_commands - -open Tezos_client_commands - -open Tezos_client_base_unix -open Octez_experimental_agnostic_baker)) -- GitLab From aa111fde03c3986aff404d5691486fa627528473 Mon Sep 17 00:00:00 2001 From: Gabriel Moise Date: Mon, 3 Mar 2025 10:53:56 +0000 Subject: [PATCH 13/13] Agnostic_baker: Add documentation to parsing module --- .../lib_agnostic_baker/baker_args_parser.ml | 6 ++++++ .../lib_agnostic_baker/baker_args_parser.mli | 12 ++++++++++++ .../lib_agnostic_baker/baker_args_parser.ml | 6 ++++++ .../lib_agnostic_baker/baker_args_parser.mli | 12 ++++++++++++ .../lib_agnostic_baker/baker_args_parser.ml | 6 ++++++ .../lib_agnostic_baker/baker_args_parser.mli | 10 ++++++++++ 6 files changed, 52 insertions(+) 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 7ec8d3510d26..764f7803957a 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 @@ -8,8 +8,11 @@ open Configuration open Protocol.Alpha_context +(** [parse_minimal_fees] parses integer valued fees to [Tez] values. *) let parse_minimal_fees = Tez.of_mutez_exn +(** [parse_per_block_vote] parses string valued voting options to protocol + specific [Per_block_votes] values. *) let parse_per_block_vote = Option.map (function | "on" -> Per_block_votes.Per_block_vote_on @@ -18,6 +21,7 @@ let parse_per_block_vote = (* This is unreachable because any other value would fail in CLI configuration parsing *) | _ -> assert false) +(** [parse_operations] parses uri's to either [Remote] or [Local] operations sources. *) let parse_operations = let open Baking_configuration.Operations_source in Option.map (fun uri -> @@ -27,6 +31,8 @@ let parse_operations = (* acts as if it were file even though it might no be *) Local {filename = Uri.to_string uri}) +(** [parse_state_recorder] parses a boolean flag to either [Filesystem] or [Memory] + baking configuration. *) let parse_state_recorder state_recorder = if state_recorder then Baking_configuration.Filesystem else Memory 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 4aa83665ccc4..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 @@ -5,8 +5,16 @@ (* *) (*****************************************************************************) +(** 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 @@ -27,8 +35,12 @@ val parse_configuration : * 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 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 7ec8d3510d26..764f7803957a 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 @@ -8,8 +8,11 @@ open Configuration open Protocol.Alpha_context +(** [parse_minimal_fees] parses integer valued fees to [Tez] values. *) let parse_minimal_fees = Tez.of_mutez_exn +(** [parse_per_block_vote] parses string valued voting options to protocol + specific [Per_block_votes] values. *) let parse_per_block_vote = Option.map (function | "on" -> Per_block_votes.Per_block_vote_on @@ -18,6 +21,7 @@ let parse_per_block_vote = (* This is unreachable because any other value would fail in CLI configuration parsing *) | _ -> assert false) +(** [parse_operations] parses uri's to either [Remote] or [Local] operations sources. *) let parse_operations = let open Baking_configuration.Operations_source in Option.map (fun uri -> @@ -27,6 +31,8 @@ let parse_operations = (* acts as if it were file even though it might no be *) Local {filename = Uri.to_string uri}) +(** [parse_state_recorder] parses a boolean flag to either [Filesystem] or [Memory] + baking configuration. *) let parse_state_recorder state_recorder = if state_recorder then Baking_configuration.Filesystem else Memory 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 4aa83665ccc4..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 @@ -5,8 +5,16 @@ (* *) (*****************************************************************************) +(** 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 @@ -27,8 +35,12 @@ val parse_configuration : * 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 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 3260cfb0cdfd..3ea1a51283a9 100644 --- a/src/proto_alpha/lib_agnostic_baker/baker_args_parser.ml +++ b/src/proto_alpha/lib_agnostic_baker/baker_args_parser.ml @@ -8,8 +8,11 @@ open Configuration open Protocol.Alpha_context +(** [parse_minimal_fees] parses integer valued fees to [Tez] values. *) let parse_minimal_fees = Tez.of_mutez_exn +(** [parse_per_block_vote] parses string valued voting options to protocol + specific [Per_block_votes] values. *) let parse_per_block_vote = Option.map (function | "on" -> Per_block_votes.Per_block_vote_on @@ -18,6 +21,7 @@ let parse_per_block_vote = (* This is unreachable because any other value would fail in CLI configuration parsing *) | _ -> assert false) +(** [parse_operations] parses uri's to either [Remote] or [Local] operations sources. *) let parse_operations = let open Baking_configuration.Operations_source in Option.map (fun uri -> @@ -27,6 +31,8 @@ let parse_operations = (* acts as if it were file even though it might no be *) Local {filename = Uri.to_string uri}) +(** [parse_state_recorder] parses a boolean flag to either [Filesystem] or [Memory] + baking configuration. *) let parse_state_recorder state_recorder = if state_recorder then Baking_configuration.Filesystem else Memory 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 d70f3aa2a6b6..9e58b64f5ef3 100644 --- a/src/proto_alpha/lib_agnostic_baker/baker_args_parser.mli +++ b/src/proto_alpha/lib_agnostic_baker/baker_args_parser.mli @@ -5,8 +5,16 @@ (* *) (*****************************************************************************) +(** 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 @@ -27,4 +35,6 @@ val parse_configuration : * 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 -- GitLab