diff --git a/.gitlab/ci/pipelines/schedule_extended_test.yml b/.gitlab/ci/pipelines/schedule_extended_test.yml index d3a78f8bf4bc4223e0f624bba6a6122d974c62ad..0bb19457dcd3749c14b146ec0582c1d9d737163b 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/CHANGES.rst b/CHANGES.rst index f918b2512ffdf01382897b93accce5cc3b234428..b7bc06175562d5eb37f3853ca33a1ac0c4f7ab3f 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`) diff --git a/dune-project b/dune-project index 62873642efcbc0ea642e46cba98b36971d4597db..d9e9a719a8b6226392a0676040331442006750ca 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 6e7f7581684ac8d3e2e2eb85819804cfbbf62e25..7d8b91b8da6d335e282c30b97556d7c1544efbed 100644 --- a/manifest/product_octez.ml +++ b/manifest/product_octez.ml @@ -5341,6 +5341,24 @@ 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_client_base_unix |> open_; + octez_node_config; + octez_client_commands |> open_; + ] + (* PROTOCOL PACKAGES *) module Protocol : sig @@ -7179,12 +7197,10 @@ 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 in @@ -8278,13 +8294,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 0000000000000000000000000000000000000000..ee8a3184911cfc10bfe52a14b2d92e2bddd7e23d --- /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 5375685d1f8d21e349700ccc0d4fb74c4f6325bc..bc418220acd15ced0dc7aeaf182d5f7e068ce0bf 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 21608311b45182323e1e67521dde06c4a52b08e4..75dbe05ce0cebb06838a62306e29322738f017b0 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 e99eb6f2bf97e2c15e2f17998d2a25001e095240..e12636f45443d4d671a9acbae2a37e760e27b1ce 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 abf269f56ce02fb2997e2c8f8094f30a23d800cd..e12f3edf49551712d74ae4e605ed7c6f85b79450 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 a2c8f759c7592730b745025cf8a55a6262071b0c..3518bd39e4061733f8e0668e7426391145b4e507 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 6f180040393dde4710a8491d35edddea4eb5a689..d836df1c327ce14c22a47aa2af4a6c640c20d4b6 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 82% rename from src/bin_agnostic_baker/agnostic_baker_errors.ml rename to src/lib_agnostic_baker/agnostic_baker_errors.ml index ab4ebb55d04b2a92defeaf73cdcf2b503994d84f..f0545bc1875d2452035e8014efe5ec132e694011 100644 --- a/src/bin_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/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/lib_agnostic_baker/commands.ml b/src/lib_agnostic_baker/commands.ml new file mode 100644 index 0000000000000000000000000000000000000000..2c8ca0c60bc6471d0a29a220a134b73d6071967c --- /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 0000000000000000000000000000000000000000..cb8993868b919ef77e75147585463cfd537aeb5b --- /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/configuration.ml b/src/lib_agnostic_baker/configuration.ml new file mode 100644 index 0000000000000000000000000000000000000000..b627e9a1c31127cda49e33c1949c4c3adaffeb3e --- /dev/null +++ b/src/lib_agnostic_baker/configuration.ml @@ -0,0 +1,425 @@ +(*****************************************************************************) +(* *) +(* 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) + +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; + 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 0000000000000000000000000000000000000000..92edf903dab0e7b560a55cb5611817bd15f8eabc --- /dev/null +++ b/src/lib_agnostic_baker/configuration.mli @@ -0,0 +1,92 @@ +(*****************************************************************************) +(* *) +(* SPDX-License-Identifier: MIT *) +(* Copyright (c) 2025 Trilitech *) +(* *) +(*****************************************************************************) + +val pidfile_arg : + (string option, Tezos_client_base.Client_context.full) Tezos_clic.arg + +val may_lock_pidfile : + string option -> + (unit -> 'a Error_monad.tzresult Lwt.t) -> + 'a Error_monad.tzresult Lwt.t + +val keep_alive_arg : + (bool, Tezos_client_base.Client_context.full) Tezos_clic.arg + +val http_headers_env_variable : string + +val http_headers : (string * string) list option + +val baker_args : + ( string option + * bool + * string option + * int64 + * Q.t + * Q.t + * int option + * bool + * string option + * string option + * string option + * Uri.t option + * Uri.t option + * bool + * bool + * Q.t option + * Q.t option, + Tezos_client_base.Client_context.full ) + Tezos_clic.options + +val directory_parameter : + (string, Tezos_client_base.Client_context.full) Tezos_clic.parameter + +val sources_param : + ( Tezos_crypto.Signature.Public_key_hash.t list -> + Tezos_client_base.Client_context.full -> + unit Error_monad.tzresult Lwt.t, + Tezos_client_base.Client_context.full ) + Tezos_clic.params + +type t = { + pidfile : string option; + node_version_check_bypass : bool; + node_version_allowed : string option; + minimal_fees : int64; + minimal_nanotez_per_gas_unit : Q.t; + minimal_nanotez_per_byte : Q.t; + force_apply_from_round : int option; + keep_alive : bool; + liquidity_baking_vote : string option; + adaptive_issuance_vote : string option; + per_block_vote_file : string option; + extra_operations : Uri.t option; + dal_node_endpoint : Uri.t option; + without_dal : bool; + state_recorder : bool; + pre_emptive_forge_time : Q.t option; + remote_calls_timeout : Q.t option; +} + +val create_config : + string option + * bool + * string option + * int64 + * Q.t + * Q.t + * int option + * bool + * string option + * string option + * string option + * Uri.t option + * Uri.t option + * bool + * bool + * Q.t option + * Q.t option -> + t diff --git a/src/bin_agnostic_baker/daemon.ml b/src/lib_agnostic_baker/daemon.ml similarity index 87% rename from src/bin_agnostic_baker/daemon.ml rename to src/lib_agnostic_baker/daemon.ml index 539c896afa35a7339eaf48ca898a8d319db0098b..943ad04f62190cbb94f3e2dadf9b3ea0de4206f2 100644 --- a/src/bin_agnostic_baker/daemon.ml +++ b/src/lib_agnostic_baker/daemon.ml @@ -18,21 +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 Agnostic_baker_plugin : Protocol_plugin.AGNOSTIC_BAKER_PLUGIN) - ~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 Agnostic_baker_plugin.hash @@ fun _network -> - Agnostic_baker_plugin.map_commands () + Client_commands.register protocol_hash @@ fun _network -> baker_commands in - let select_commands _ _ = - Lwt_result_syntax.return @@ Agnostic_baker_plugin.map_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 @@ -78,21 +76,18 @@ 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 + let baker_commands = Commands.baker_commands plugin in + return + @@ run_thread + ~protocol_hash + ~baker_commands + ~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/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 0000000000000000000000000000000000000000..ba71b4b59caba9b155a450638a774b774602dc90 --- /dev/null +++ b/src/lib_agnostic_baker/dune @@ -0,0 +1,24 @@ +; 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.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_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/lib_agnostic_baker/protocol_plugin_sig.ml b/src/lib_agnostic_baker/protocol_plugin_sig.ml new file mode 100644 index 0000000000000000000000000000000000000000..a2f73794b821ed9a2de82e73ccfa6a7004bb4c29 --- /dev/null +++ b/src/lib_agnostic_baker/protocol_plugin_sig.ml @@ -0,0 +1,35 @@ +(*****************************************************************************) +(* *) +(* SPDX-License-Identifier: MIT *) +(* Copyright (c) 2025 Trilitech *) +(* *) +(*****************************************************************************) + +module type BAKER_COMMANDS_HELPERS = sig + (** [run_baker ~configuration ~baking_mode ~sources ~cctxt] is the main running + function signature that all protocol plugins will need to implement. It + requires the [~configuration] which contains all the possible CLI arguments + for the agnostic baker, together with a [~baking_mode] argument and delegates + list given by [~sources] in the client context [~cctxt]. + + 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.public_key_hash list -> + cctxt:Tezos_client_base.Client_context.full -> + unit Error_monad.tzresult Lwt.t + + val run_vdf_daemon : + cctxt:Tezos_client_base.Client_context.full -> + keep_alive:bool -> + unit tzresult Lwt.t +end + +module type S = sig + val protocol_hash : Protocol_hash.t + + module Baker_commands_helpers : BAKER_COMMANDS_HELPERS +end diff --git a/src/lib_agnostic_baker/protocol_plugins.ml b/src/lib_agnostic_baker/protocol_plugins.ml new file mode 100644 index 0000000000000000000000000000000000000000..2ed10e0e265d35dd5f835d50ddefa7cadf574366 --- /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 0000000000000000000000000000000000000000..7a6ac00d2fbb78448fa9d44e8c2c83905c4523a4 --- /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/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/lib_validation/protocol_plugin.ml b/src/lib_validation/protocol_plugin.ml index 07cdbd9b2b8d3329326187ca58c7280915507440..b2f842aff4e3b8cd08df120ab4ec80698f2aba69 100644 --- a/src/lib_validation/protocol_plugin.ml +++ b/src/lib_validation/protocol_plugin.ml @@ -165,15 +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 name : string - - val map_commands : - unit -> Tezos_client_base.Client_context.full Tezos_clic.command list -end - let rpc_table : (module RPC) Protocol_hash.Table.t = Protocol_hash.Table.create 5 @@ -187,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) @@ -215,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 @@ -235,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 b6d4bf61c5b6053e79051a7021a1e520d9bc5eff..8b28e18ada03ff34d518813dd05971575e65413e 100644 --- a/src/lib_validation/protocol_plugin.mli +++ b/src/lib_validation/protocol_plugin.mli @@ -212,17 +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 name : string - - val map_commands : - unit -> Tezos_client_base.Client_context.full Tezos_clic.command list -end - (** Register a validation plugin for a specific protocol (according to its [Proto.hash]). *) val register_validation_plugin : (module T) -> unit @@ -239,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. @@ -272,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_registration.ml b/src/proto_021_PsQuebec/lib_agnostic_baker/agnostic_baker_plugin.ml similarity index 59% 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 index 147a175016a76c883c75670ead64bb530deda189..fcc9eb4a3be99bdaafcd7f892524257e01fb6072 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.ml @@ -5,15 +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 name = Protocol.name - - 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_args_parser.ml b/src/proto_021_PsQuebec/lib_agnostic_baker/baker_args_parser.ml new file mode 100644 index 0000000000000000000000000000000000000000..764f7803957a129ff4aa855a8007458ecc8acef8 --- /dev/null +++ b/src/proto_021_PsQuebec/lib_agnostic_baker/baker_args_parser.ml @@ -0,0 +1,86 @@ +(*****************************************************************************) +(* *) +(* SPDX-License-Identifier: MIT *) +(* Copyright (c) 2025 Trilitech *) +(* *) +(*****************************************************************************) + +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 + | "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) + +(** [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 -> + 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}) + +(** [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 + +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 + +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 new file mode 100644 index 0000000000000000000000000000000000000000..cd2af5efebd562170e7f458e26eee4aaf5da8f11 --- /dev/null +++ b/src/proto_021_PsQuebec/lib_agnostic_baker/baker_args_parser.mli @@ -0,0 +1,47 @@ +(*****************************************************************************) +(* *) +(* SPDX-License-Identifier: MIT *) +(* Copyright (c) 2025 Trilitech *) +(* *) +(*****************************************************************************) + +(** This module offers transformation tools from protocol-independent types to + protocol specific ones. In this particular instance, the agnostic baker CLI + arguments are defined in a single place, outside the protocol code, and then + they are mapped, depending on the protocol context. +*) + +open Protocol.Alpha_context + +(** [parse_configuration] simply transforms a configuration record type into a + tuple containing the same values. *) +val parse_configuration : + Configuration.t -> + string option + * bool + * string option + * Tez.t + * Q.t + * Q.t + * int option + * bool + * Per_block_votes.per_block_vote option + * Per_block_votes.per_block_vote option + * string option + * Baking_configuration.Operations_source.t option + * Uri.t option + * bool + * Baking_configuration.state_recorder_config + * Q.t option + * Q.t option + +(** [parse_baking_mode baking_mode] maps a optional value to a [Local] or [Remote] + baking mode option. *) +val parse_baking_mode : string option -> Baking_commands.baking_mode + +(** [parse_sources sources] maps all public key hashes to the version expected + by the protocol-specific baking main running function. *) +val parse_sources : + Tezos_base.TzPervasives.Signature.public_key_hash list -> + (Tezos_base.TzPervasives.Signature.V1.public_key_hash list, tztrace) result + Lwt.t diff --git a/src/proto_021_PsQuebec/lib_agnostic_baker/baker_commands_helpers.ml b/src/proto_021_PsQuebec/lib_agnostic_baker/baker_commands_helpers.ml new file mode 100644 index 0000000000000000000000000000000000000000..89fe030096a9aa605701c77f5ccfdad575825488 --- /dev/null +++ b/src/proto_021_PsQuebec/lib_agnostic_baker/baker_commands_helpers.ml @@ -0,0 +1,18 @@ +(*****************************************************************************) +(* *) +(* SPDX-License-Identifier: MIT *) +(* Copyright (c) 2025 Trilitech *) +(* *) +(*****************************************************************************) + +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 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_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 0000000000000000000000000000000000000000..60fdac49d1dcf948e44b882b3c7de4e3a80afbb9 --- /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_021_PsQuebec/lib_agnostic_baker/dune b/src/proto_021_PsQuebec/lib_agnostic_baker/dune index 09ef392b712c906553c9cd6a860fc314e8a53f42..d12bd39185a2230d121266e6977d478cb56f70fa 100644 --- a/src/proto_021_PsQuebec/lib_agnostic_baker/dune +++ b/src/proto_021_PsQuebec/lib_agnostic_baker/dune @@ -8,20 +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_021_PsQuebec/lib_delegate/baking_commands.mli b/src/proto_021_PsQuebec/lib_delegate/baking_commands.mli index 02e2819da4b960f650fc50621ecbb9d053512bcc..c808d30553300e0051930ef11470845e00660c7b 100644 --- a/src/proto_021_PsQuebec/lib_delegate/baking_commands.mli +++ b/src/proto_021_PsQuebec/lib_delegate/baking_commands.mli @@ -23,6 +23,31 @@ (* *) (*****************************************************************************) +type baking_mode = Local of {local_data_dir_path : string} | Remote + +val run_baker : + string option + * bool + * string option + * Protocol.Alpha_context.Tez.t + * Q.t + * Q.t + * int option + * bool + * Protocol.Per_block_votes_repr.per_block_vote option + * Protocol.Per_block_votes_repr.per_block_vote option + * string option + * Baking_configuration.Operations_source.t option + * Uri.t option + * bool + * Baking_configuration.state_recorder_config + * Q.t option + * Q.t option -> + baking_mode -> + Environment.Signature.public_key_hash list -> + 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/agnostic_baker_plugin_registration.ml b/src/proto_022_PsRiotum/lib_agnostic_baker/agnostic_baker_plugin.ml similarity index 59% 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 index 147a175016a76c883c75670ead64bb530deda189..fcc9eb4a3be99bdaafcd7f892524257e01fb6072 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.ml @@ -5,15 +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 name = Protocol.name - - 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_args_parser.ml b/src/proto_022_PsRiotum/lib_agnostic_baker/baker_args_parser.ml new file mode 100644 index 0000000000000000000000000000000000000000..764f7803957a129ff4aa855a8007458ecc8acef8 --- /dev/null +++ b/src/proto_022_PsRiotum/lib_agnostic_baker/baker_args_parser.ml @@ -0,0 +1,86 @@ +(*****************************************************************************) +(* *) +(* SPDX-License-Identifier: MIT *) +(* Copyright (c) 2025 Trilitech *) +(* *) +(*****************************************************************************) + +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 + | "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) + +(** [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 -> + 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}) + +(** [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 + +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 + +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 new file mode 100644 index 0000000000000000000000000000000000000000..cd2af5efebd562170e7f458e26eee4aaf5da8f11 --- /dev/null +++ b/src/proto_022_PsRiotum/lib_agnostic_baker/baker_args_parser.mli @@ -0,0 +1,47 @@ +(*****************************************************************************) +(* *) +(* SPDX-License-Identifier: MIT *) +(* Copyright (c) 2025 Trilitech *) +(* *) +(*****************************************************************************) + +(** This module offers transformation tools from protocol-independent types to + protocol specific ones. In this particular instance, the agnostic baker CLI + arguments are defined in a single place, outside the protocol code, and then + they are mapped, depending on the protocol context. +*) + +open Protocol.Alpha_context + +(** [parse_configuration] simply transforms a configuration record type into a + tuple containing the same values. *) +val parse_configuration : + Configuration.t -> + string option + * bool + * string option + * Tez.t + * Q.t + * Q.t + * int option + * bool + * Per_block_votes.per_block_vote option + * Per_block_votes.per_block_vote option + * string option + * Baking_configuration.Operations_source.t option + * Uri.t option + * bool + * Baking_configuration.state_recorder_config + * Q.t option + * Q.t option + +(** [parse_baking_mode baking_mode] maps a optional value to a [Local] or [Remote] + baking mode option. *) +val parse_baking_mode : string option -> Baking_commands.baking_mode + +(** [parse_sources sources] maps all public key hashes to the version expected + by the protocol-specific baking main running function. *) +val parse_sources : + Tezos_base.TzPervasives.Signature.public_key_hash list -> + (Tezos_base.TzPervasives.Signature.V1.public_key_hash list, tztrace) result + Lwt.t diff --git a/src/proto_022_PsRiotum/lib_agnostic_baker/baker_commands_helpers.ml b/src/proto_022_PsRiotum/lib_agnostic_baker/baker_commands_helpers.ml new file mode 100644 index 0000000000000000000000000000000000000000..89fe030096a9aa605701c77f5ccfdad575825488 --- /dev/null +++ b/src/proto_022_PsRiotum/lib_agnostic_baker/baker_commands_helpers.ml @@ -0,0 +1,18 @@ +(*****************************************************************************) +(* *) +(* SPDX-License-Identifier: MIT *) +(* Copyright (c) 2025 Trilitech *) +(* *) +(*****************************************************************************) + +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 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.mli b/src/proto_022_PsRiotum/lib_agnostic_baker/baker_commands_helpers.mli new file mode 100644 index 0000000000000000000000000000000000000000..60fdac49d1dcf948e44b882b3c7de4e3a80afbb9 --- /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_022_PsRiotum/lib_agnostic_baker/dune b/src/proto_022_PsRiotum/lib_agnostic_baker/dune index 593e525dd92406b7b9bd275bb09ece1781a8b4b3..1b6322dfa982df08c8d120b77d758e60c368e39c 100644 --- a/src/proto_022_PsRiotum/lib_agnostic_baker/dune +++ b/src/proto_022_PsRiotum/lib_agnostic_baker/dune @@ -8,20 +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_022_PsRiotum/lib_delegate/baking_commands.mli b/src/proto_022_PsRiotum/lib_delegate/baking_commands.mli index 02e2819da4b960f650fc50621ecbb9d053512bcc..c808d30553300e0051930ef11470845e00660c7b 100644 --- a/src/proto_022_PsRiotum/lib_delegate/baking_commands.mli +++ b/src/proto_022_PsRiotum/lib_delegate/baking_commands.mli @@ -23,6 +23,31 @@ (* *) (*****************************************************************************) +type baking_mode = Local of {local_data_dir_path : string} | Remote + +val run_baker : + string option + * bool + * string option + * Protocol.Alpha_context.Tez.t + * Q.t + * Q.t + * int option + * bool + * Protocol.Per_block_votes_repr.per_block_vote option + * Protocol.Per_block_votes_repr.per_block_vote option + * string option + * Baking_configuration.Operations_source.t option + * Uri.t option + * bool + * Baking_configuration.state_recorder_config + * Q.t option + * Q.t option -> + baking_mode -> + Environment.Signature.public_key_hash list -> + 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/agnostic_baker_plugin_registration.ml b/src/proto_alpha/lib_agnostic_baker/agnostic_baker_plugin.ml similarity index 59% 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 index 147a175016a76c883c75670ead64bb530deda189..fcc9eb4a3be99bdaafcd7f892524257e01fb6072 100644 --- a/src/proto_alpha/lib_agnostic_baker/agnostic_baker_plugin_registration.ml +++ b/src/proto_alpha/lib_agnostic_baker/agnostic_baker_plugin.ml @@ -5,15 +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 name = Protocol.name - - 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_args_parser.ml b/src/proto_alpha/lib_agnostic_baker/baker_args_parser.ml new file mode 100644 index 0000000000000000000000000000000000000000..3ea1a51283a98eae97561e9f6fd54c19bab467ac --- /dev/null +++ b/src/proto_alpha/lib_agnostic_baker/baker_args_parser.ml @@ -0,0 +1,80 @@ +(*****************************************************************************) +(* *) +(* SPDX-License-Identifier: MIT *) +(* Copyright (c) 2025 Trilitech *) +(* *) +(*****************************************************************************) + +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 + | "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) + +(** [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 -> + 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}) + +(** [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 + +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 0000000000000000000000000000000000000000..9e58b64f5ef33a08e520bfb036b29cd8a69ce121 --- /dev/null +++ b/src/proto_alpha/lib_agnostic_baker/baker_args_parser.mli @@ -0,0 +1,40 @@ +(*****************************************************************************) +(* *) +(* SPDX-License-Identifier: MIT *) +(* Copyright (c) 2025 Trilitech *) +(* *) +(*****************************************************************************) + +(** This module offers transformation tools from protocol-independent types to + protocol specific ones. In this particular instance, the agnostic baker CLI + arguments are defined in a single place, outside the protocol code, and then + they are mapped, depending on the protocol context. +*) + +open Protocol.Alpha_context + +(** [parse_configuration] simply transforms a configuration record type into a + tuple containing the same values. *) +val parse_configuration : + Configuration.t -> + string option + * bool + * string option + * Tez.t + * Q.t + * Q.t + * int option + * bool + * Per_block_votes.per_block_vote option + * Per_block_votes.per_block_vote option + * string option + * Baking_configuration.Operations_source.t option + * Uri.t option + * bool + * Baking_configuration.state_recorder_config + * Q.t option + * Q.t option + +(** [parse_baking_mode baking_mode] maps a optional value to a [Local] or [Remote] + baking mode option. *) +val parse_baking_mode : string option -> Baking_commands.baking_mode diff --git a/src/proto_alpha/lib_agnostic_baker/baker_commands_helpers.ml b/src/proto_alpha/lib_agnostic_baker/baker_commands_helpers.ml new file mode 100644 index 0000000000000000000000000000000000000000..9996e3999da54d04f06ef5a33b8a98c9a6de157d --- /dev/null +++ b/src/proto_alpha/lib_agnostic_baker/baker_commands_helpers.ml @@ -0,0 +1,16 @@ +(*****************************************************************************) +(* *) +(* SPDX-License-Identifier: MIT *) +(* Copyright (c) 2025 Trilitech *) +(* *) +(*****************************************************************************) + +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 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.mli b/src/proto_alpha/lib_agnostic_baker/baker_commands_helpers.mli new file mode 100644 index 0000000000000000000000000000000000000000..60fdac49d1dcf948e44b882b3c7de4e3a80afbb9 --- /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 diff --git a/src/proto_alpha/lib_agnostic_baker/dune b/src/proto_alpha/lib_agnostic_baker/dune index f1483edf2d59b588f27ccc28047608795254d1e6..592b925cf9299b35db9bfbd763a95caf7f40ffa6 100644 --- a/src/proto_alpha/lib_agnostic_baker/dune +++ b/src/proto_alpha/lib_agnostic_baker/dune @@ -8,20 +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)) diff --git a/src/proto_alpha/lib_delegate/baking_commands.mli b/src/proto_alpha/lib_delegate/baking_commands.mli index 02e2819da4b960f650fc50621ecbb9d053512bcc..c808d30553300e0051930ef11470845e00660c7b 100644 --- a/src/proto_alpha/lib_delegate/baking_commands.mli +++ b/src/proto_alpha/lib_delegate/baking_commands.mli @@ -23,6 +23,31 @@ (* *) (*****************************************************************************) +type baking_mode = Local of {local_data_dir_path : string} | Remote + +val run_baker : + string option + * bool + * string option + * Protocol.Alpha_context.Tez.t + * Q.t + * Q.t + * int option + * bool + * Protocol.Per_block_votes_repr.per_block_vote option + * Protocol.Per_block_votes_repr.per_block_vote option + * string option + * Baking_configuration.Operations_source.t option + * Uri.t option + * bool + * Baking_configuration.state_recorder_config + * Q.t option + * Q.t option -> + baking_mode -> + Environment.Signature.public_key_hash list -> + 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/tobi/config b/tobi/config index b94f3e687d29515032aa52d65e2abc87a693a52f..e6cb52194beffdb5df4cd89b6e8966047071ef80 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