From 6495fb388ae616c0078c363b4a7d3e4b115dfb4e Mon Sep 17 00:00:00 2001 From: Diane Gallois-Wong Date: Wed, 10 Jul 2024 16:08:58 +0200 Subject: [PATCH 1/5] Proto: move contracts & delegates RPCs to plugin --- src/proto_alpha/lib_client/client_proto_context.ml | 1 + src/proto_alpha/lib_client/client_proto_contracts.ml | 2 +- .../lib_client/client_proto_contracts.mli | 2 +- src/proto_alpha/lib_client/injection.ml | 6 ++++-- .../lib_client/michelson_v1_entrypoints.ml | 4 ++-- .../client_proto_context_commands.ml | 4 ++-- .../client_proto_stresstest_commands.ml | 1 + src/proto_alpha/lib_client_sapling/context.ml | 2 +- .../contract_services.ml | 5 ++++- .../contract_services.mli | 5 ++++- .../delegate_services.ml | 5 ++++- .../delegate_services.mli | 5 ++++- src/proto_alpha/lib_plugin/plugin.ml | 6 ++++++ src/proto_alpha/lib_protocol/TEZOS_PROTOCOL | 2 -- src/proto_alpha/lib_protocol/alpha_services.ml | 4 ---- src/proto_alpha/lib_protocol/alpha_services.mli | 2 -- src/proto_alpha/lib_protocol/dune | 8 -------- src/proto_alpha/lib_protocol/test/helpers/context.ml | 1 + .../lib_protocol/test/helpers/context.mli | 2 +- .../lib_protocol/test/helpers/sapling_helpers.ml | 2 +- .../lib_protocol/test/helpers/scenario_bake.ml | 2 +- .../test/integration/michelson/test_sapling.ml | 12 ++++++++---- src/proto_alpha/lib_sc_rollup_node/layer1_helpers.ml | 5 ++++- 23 files changed, 51 insertions(+), 37 deletions(-) rename src/proto_alpha/{lib_protocol => lib_plugin}/contract_services.ml (99%) rename src/proto_alpha/{lib_protocol => lib_plugin}/contract_services.mli (98%) rename src/proto_alpha/{lib_protocol => lib_plugin}/delegate_services.ml (99%) rename src/proto_alpha/{lib_protocol => lib_plugin}/delegate_services.mli (98%) diff --git a/src/proto_alpha/lib_client/client_proto_context.ml b/src/proto_alpha/lib_client/client_proto_context.ml index 9a071294f152..1d3f63ee6480 100644 --- a/src/proto_alpha/lib_client/client_proto_context.ml +++ b/src/proto_alpha/lib_client/client_proto_context.ml @@ -30,6 +30,7 @@ open Protocol_client_context open Tezos_micheline open Client_proto_contracts open Client_keys +module Alpha_services = Plugin.Alpha_services let get_balance (rpc : #rpc_context) ~chain ~block contract = Alpha_services.Contract.balance rpc (chain, block) contract diff --git a/src/proto_alpha/lib_client/client_proto_contracts.ml b/src/proto_alpha/lib_client/client_proto_contracts.ml index 0b880123c786..7dcc870c2f59 100644 --- a/src/proto_alpha/lib_client/client_proto_contracts.ml +++ b/src/proto_alpha/lib_client/client_proto_contracts.ml @@ -260,4 +260,4 @@ let list_contracts cctxt = return (contracts @ accounts) let get_delegate cctxt ~chain ~block source = - Alpha_services.Contract.delegate_opt cctxt (chain, block) source + Plugin.Alpha_services.Contract.delegate_opt cctxt (chain, block) source diff --git a/src/proto_alpha/lib_client/client_proto_contracts.mli b/src/proto_alpha/lib_client/client_proto_contracts.mli index a342408ec37e..ad1639574ca2 100644 --- a/src/proto_alpha/lib_client/client_proto_contracts.mli +++ b/src/proto_alpha/lib_client/client_proto_contracts.mli @@ -99,7 +99,7 @@ val list_contracts : #Client_context.wallet -> (string * string * Raw_contract_alias.t) list tzresult Lwt.t -(** Calls {!Alpha_services.Contract.delegate_opt} *) +(** Calls {!Plugin.Alpha_services.Contract.delegate_opt} *) val get_delegate : #Protocol_client_context.rpc_context -> chain:Shell_services.chain -> diff --git a/src/proto_alpha/lib_client/injection.ml b/src/proto_alpha/lib_client/injection.ml index eb7fa79c4f81..8ee944c6907a 100644 --- a/src/proto_alpha/lib_client/injection.ml +++ b/src/proto_alpha/lib_client/injection.ml @@ -1480,13 +1480,15 @@ let inject_manager_operation cctxt ~chain ~block ?successor_level ?branch match counter with | None -> let* pcounter = - Alpha_services.Contract.counter cctxt (chain, block) source + Plugin.Alpha_services.Contract.counter cctxt (chain, block) source in let counter = Manager_counter.succ pcounter in return counter | Some counter -> return counter in - let* key = Alpha_services.Contract.manager_key cctxt (chain, block) source in + let* key = + Plugin.Alpha_services.Contract.manager_key cctxt (chain, block) source + in (* [has_reveal] assumes that a Reveal operation only appears as the first of a batch *) let has_reveal : type kind. kind Annotated_manager_operation.annotated_list -> bool = diff --git a/src/proto_alpha/lib_client/michelson_v1_entrypoints.ml b/src/proto_alpha/lib_client/michelson_v1_entrypoints.ml index 026827f63ddc..4c56fa7f16e4 100644 --- a/src/proto_alpha/lib_client/michelson_v1_entrypoints.ml +++ b/src/proto_alpha/lib_client/michelson_v1_entrypoints.ml @@ -70,7 +70,7 @@ let contract_entrypoint_type cctxt ~(chain : Chain_services.chain) ~block ~contract ~entrypoint ~normalize_types = let open Lwt_result_syntax in let*! ty_opt = - Alpha_services.Contract.entrypoint_type + Plugin.Alpha_services.Contract.entrypoint_type cctxt (chain, block) contract @@ -123,7 +123,7 @@ let print_entrypoint_type (cctxt : #Client_context.printer) let list_contract_unreachables_and_entrypoints cctxt ~chain ~block ~contract ~normalize_types = - Alpha_services.Contract.list_entrypoints + Plugin.Alpha_services.Contract.list_entrypoints cctxt (chain, block) contract diff --git a/src/proto_alpha/lib_client_commands/client_proto_context_commands.ml b/src/proto_alpha/lib_client_commands/client_proto_context_commands.ml index 50022b31076d..e71ea075a93a 100644 --- a/src/proto_alpha/lib_client_commands/client_proto_context_commands.ml +++ b/src/proto_alpha/lib_client_commands/client_proto_context_commands.ml @@ -2567,7 +2567,7 @@ let commands_rw () = in let* has_voting_power = let*! r = - Alpha_services.Delegate.voting_power + Plugin.Alpha_services.Delegate.voting_power cctxt (cctxt#chain, cctxt#block) src_pkh @@ -2770,7 +2770,7 @@ let commands_rw () = in let* has_voting_power = let*! r = - Alpha_services.Delegate.voting_power + Plugin.Alpha_services.Delegate.voting_power cctxt (cctxt#chain, cctxt#block) src_pkh diff --git a/src/proto_alpha/lib_client_commands/client_proto_stresstest_commands.ml b/src/proto_alpha/lib_client_commands/client_proto_stresstest_commands.ml index 66177c69a2f7..9c5d0405619c 100644 --- a/src/proto_alpha/lib_client_commands/client_proto_stresstest_commands.ml +++ b/src/proto_alpha/lib_client_commands/client_proto_stresstest_commands.ml @@ -26,6 +26,7 @@ open Protocol open Alpha_context module Smart_contracts = Client_proto_stresstest_contracts +module Alpha_services = Plugin.Alpha_services type transfer_strategy = | Fixed_amount of {mutez : Tez.t} (** Amount to transfer *) diff --git a/src/proto_alpha/lib_client_sapling/context.ml b/src/proto_alpha/lib_client_sapling/context.ml index 86bfca88e8e5..9ff45eedf356 100644 --- a/src/proto_alpha/lib_client_sapling/context.ml +++ b/src/proto_alpha/lib_client_sapling/context.ml @@ -386,7 +386,7 @@ module Client_state = struct (** Call the node RPC to obtain the storage diff of a contract *) let get_diff cctxt contract offset_commitment offset_nullifier = - Protocol.Alpha_services.Contract.single_sapling_get_diff + Plugin.Alpha_services.Contract.single_sapling_get_diff cctxt (cctxt#chain, cctxt#block) contract diff --git a/src/proto_alpha/lib_protocol/contract_services.ml b/src/proto_alpha/lib_plugin/contract_services.ml similarity index 99% rename from src/proto_alpha/lib_protocol/contract_services.ml rename to src/proto_alpha/lib_plugin/contract_services.ml index 90d9527e0497..bf1d296627a7 100644 --- a/src/proto_alpha/lib_protocol/contract_services.ml +++ b/src/proto_alpha/lib_plugin/contract_services.ml @@ -24,7 +24,10 @@ (* *) (*****************************************************************************) -open Alpha_context +open Environment +open Environment.Error_monad +open Protocol +open Protocol.Alpha_context let custom_root = (RPC_path.(open_root / "context" / "contracts") diff --git a/src/proto_alpha/lib_protocol/contract_services.mli b/src/proto_alpha/lib_plugin/contract_services.mli similarity index 98% rename from src/proto_alpha/lib_protocol/contract_services.mli rename to src/proto_alpha/lib_plugin/contract_services.mli index ead26032367e..70a5d42332a6 100644 --- a/src/proto_alpha/lib_protocol/contract_services.mli +++ b/src/proto_alpha/lib_plugin/contract_services.mli @@ -28,7 +28,10 @@ contracts (balance, delegate, script, etc.). *) -open Alpha_context +open Environment +open Environment.Error_monad +open Protocol +open Protocol.Alpha_context val list : 'a #RPC_context.simple -> 'a -> Contract.t list shell_tzresult Lwt.t diff --git a/src/proto_alpha/lib_protocol/delegate_services.ml b/src/proto_alpha/lib_plugin/delegate_services.ml similarity index 99% rename from src/proto_alpha/lib_protocol/delegate_services.ml rename to src/proto_alpha/lib_plugin/delegate_services.ml index ca10222f56f7..09d709aed1a3 100644 --- a/src/proto_alpha/lib_protocol/delegate_services.ml +++ b/src/proto_alpha/lib_plugin/delegate_services.ml @@ -25,7 +25,10 @@ (* *) (*****************************************************************************) -open Alpha_context +open Environment +open Environment.Error_monad +open Protocol +open Protocol.Alpha_context type error += Balance_rpc_non_delegate of public_key_hash diff --git a/src/proto_alpha/lib_protocol/delegate_services.mli b/src/proto_alpha/lib_plugin/delegate_services.mli similarity index 98% rename from src/proto_alpha/lib_protocol/delegate_services.mli rename to src/proto_alpha/lib_plugin/delegate_services.mli index f09f70e8a4e3..08b9b39054a6 100644 --- a/src/proto_alpha/lib_protocol/delegate_services.mli +++ b/src/proto_alpha/lib_plugin/delegate_services.mli @@ -29,7 +29,10 @@ delegates (who they are, their delegators, their different kinds of balances, their activity, etc.). *) -open Alpha_context +open Environment +open Environment.Error_monad +open Protocol +open Protocol.Alpha_context type error += (* `Temporary *) Not_registered of Signature.Public_key_hash.t diff --git a/src/proto_alpha/lib_plugin/plugin.ml b/src/proto_alpha/lib_plugin/plugin.ml index a43e98f0dd76..743fe32e7656 100644 --- a/src/proto_alpha/lib_plugin/plugin.ml +++ b/src/proto_alpha/lib_plugin/plugin.ml @@ -31,3 +31,9 @@ module RPC = RPC module Metrics = Metrics_plugin module Script_interpreter_logging = Script_interpreter_logging module Http_cache_headers = Http_cache_headers + +module Alpha_services = struct + include Protocol.Alpha_services + module Contract = Contract_services + module Delegate = Delegate_services +end diff --git a/src/proto_alpha/lib_protocol/TEZOS_PROTOCOL b/src/proto_alpha/lib_protocol/TEZOS_PROTOCOL index feea36bc792c..5cb8ffb7458c 100644 --- a/src/proto_alpha/lib_protocol/TEZOS_PROTOCOL +++ b/src/proto_alpha/lib_protocol/TEZOS_PROTOCOL @@ -283,8 +283,6 @@ "Services_registration", "Constants_services", "Sapling_services", - "Contract_services", - "Delegate_services", "Voting_services", "Dal_services", "Adaptive_issuance_services", diff --git a/src/proto_alpha/lib_protocol/alpha_services.ml b/src/proto_alpha/lib_protocol/alpha_services.ml index 000d36a5f3fb..23f05797805a 100644 --- a/src/proto_alpha/lib_protocol/alpha_services.ml +++ b/src/proto_alpha/lib_protocol/alpha_services.ml @@ -150,9 +150,7 @@ module Nonce = struct let get ctxt block level = RPC_context.make_call1 S.get ctxt block level () () end -module Contract = Contract_services module Constants = Constants_services -module Delegate = Delegate_services module Voting = Voting_services module Sapling = Sapling_services module Adaptive_issuance = Adaptive_issuance_services @@ -270,9 +268,7 @@ module Denunciations = struct end let register () = - Contract.register () ; Constants.register () ; - Delegate.register () ; Nonce.register () ; Voting.register () ; Sapling.register () ; diff --git a/src/proto_alpha/lib_protocol/alpha_services.mli b/src/proto_alpha/lib_protocol/alpha_services.mli index 049064397e29..83c4848d5858 100644 --- a/src/proto_alpha/lib_protocol/alpha_services.mli +++ b/src/proto_alpha/lib_protocol/alpha_services.mli @@ -53,9 +53,7 @@ module Nonce : sig 'a #RPC_context.simple -> 'a -> Raw_level.t -> info shell_tzresult Lwt.t end -module Contract = Contract_services module Constants = Constants_services -module Delegate = Delegate_services module Voting = Voting_services module Sapling = Sapling_services diff --git a/src/proto_alpha/lib_protocol/dune b/src/proto_alpha/lib_protocol/dune index fede92899f90..24f8b2a0e103 100644 --- a/src/proto_alpha/lib_protocol/dune +++ b/src/proto_alpha/lib_protocol/dune @@ -285,8 +285,6 @@ Services_registration Constants_services Sapling_services - Contract_services - Delegate_services Voting_services Dal_services Adaptive_issuance_services @@ -585,8 +583,6 @@ services_registration.ml services_registration.mli constants_services.ml constants_services.mli sapling_services.ml - contract_services.ml contract_services.mli - delegate_services.ml delegate_services.mli voting_services.ml voting_services.mli dal_services.ml dal_services.mli adaptive_issuance_services.ml adaptive_issuance_services.mli @@ -886,8 +882,6 @@ services_registration.ml services_registration.mli constants_services.ml constants_services.mli sapling_services.ml - contract_services.ml contract_services.mli - delegate_services.ml delegate_services.mli voting_services.ml voting_services.mli dal_services.ml dal_services.mli adaptive_issuance_services.ml adaptive_issuance_services.mli @@ -1171,8 +1165,6 @@ services_registration.ml services_registration.mli constants_services.ml constants_services.mli sapling_services.ml - contract_services.ml contract_services.mli - delegate_services.ml delegate_services.mli voting_services.ml voting_services.mli dal_services.ml dal_services.mli adaptive_issuance_services.ml adaptive_issuance_services.mli diff --git a/src/proto_alpha/lib_protocol/test/helpers/context.ml b/src/proto_alpha/lib_protocol/test/helpers/context.ml index b8d17f56dc66..bf866b7c221d 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/context.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/context.ml @@ -27,6 +27,7 @@ open Protocol open Alpha_context +open Plugin type t = B of Block.t | I of Incremental.t diff --git a/src/proto_alpha/lib_protocol/test/helpers/context.mli b/src/proto_alpha/lib_protocol/test/helpers/context.mli index 542ae960b458..818d3b916e52 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/context.mli +++ b/src/proto_alpha/lib_protocol/test/helpers/context.mli @@ -288,7 +288,7 @@ module Delegate : sig val unstaked_frozen_deposits : t -> public_key_hash -> - Protocol.Delegate_services.deposit_per_cycle list tzresult Lwt.t + Plugin.Alpha_services.Delegate.deposit_per_cycle list tzresult Lwt.t val staking_denominator : t -> public_key_hash -> Z.t tzresult Lwt.t diff --git a/src/proto_alpha/lib_protocol/test/helpers/sapling_helpers.ml b/src/proto_alpha/lib_protocol/test/helpers/sapling_helpers.ml index 25100ebcb406..cb832ea9d188 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/sapling_helpers.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/sapling_helpers.ml @@ -436,7 +436,7 @@ module Interpreter_helpers = struct let* incr = Incremental.add_operation incr operation in let* block = Incremental.finalize_block incr in let+ diff = - Alpha_services.Contract.single_sapling_get_diff + Plugin.Alpha_services.Contract.single_sapling_get_diff Block.rpc_ctxt block dst diff --git a/src/proto_alpha/lib_protocol/test/helpers/scenario_bake.ml b/src/proto_alpha/lib_protocol/test/helpers/scenario_bake.ml index d8d8781204ce..03e61a13f903 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/scenario_bake.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/scenario_bake.ml @@ -106,7 +106,7 @@ let check_misc block state : unit tzresult Lwt.t = let u_rpc = List.map (fun ({cycle; deposit} : - Protocol.Delegate_services.deposit_per_cycle) -> + Plugin.Alpha_services.Delegate.deposit_per_cycle) -> (cycle, deposit)) u_rpc in diff --git a/src/proto_alpha/lib_protocol/test/integration/michelson/test_sapling.ml b/src/proto_alpha/lib_protocol/test/integration/michelson/test_sapling.ml index f1865ea26c60..c578315df60a 100644 --- a/src/proto_alpha/lib_protocol/test/integration/michelson/test_sapling.ml +++ b/src/proto_alpha/lib_protocol/test/integration/michelson/test_sapling.ml @@ -987,7 +987,7 @@ module Interpreter_tests = struct in let final_root = Tezos_sapling.Storage.get_root state_1 in let* _root, diff_1 = - Alpha_services.Contract.single_sapling_get_diff + Plugin.Alpha_services.Contract.single_sapling_get_diff Block.rpc_ctxt block_1 dst @@ -1033,7 +1033,7 @@ module Interpreter_tests = struct let* incr = Incremental.add_operation incr operation in let* block_2 = Incremental.finalize_block incr in let* _root, diff_2 = - Alpha_services.Contract.single_sapling_get_diff + Plugin.Alpha_services.Contract.single_sapling_get_diff Block.rpc_ctxt block_2 dst @@ -1046,7 +1046,9 @@ module Interpreter_tests = struct let is_root_in block dst root = let* incr = Incremental.begin_construction block in let ctx_2 = Incremental.alpha_ctxt incr in - let* script = Alpha_services.Contract.script Block.rpc_ctxt block dst in + let* script = + Plugin.Alpha_services.Contract.script Block.rpc_ctxt block dst + in let ctx_without_gas_2 = Alpha_context.Gas.set_unlimited ctx_2 in let*@ Ex_script (Script script), ctxt = Script_ir_translator.parse_script @@ -1185,7 +1187,9 @@ module Interpreter_tests = struct let* incr = Incremental.begin_construction b in let ctx = Incremental.alpha_ctxt incr in let ctx_without_gas = Alpha_context.Gas.set_unlimited ctx in - let* storage = Alpha_services.Contract.storage Block.rpc_ctxt b dst in + let* storage = + Plugin.Alpha_services.Contract.storage Block.rpc_ctxt b dst + in let storage_lazy_expr = Alpha_context.Script.lazy_expr storage in let*?@ (Ty_ex_c tytype) = let memo_size = memo_size_of_int memo_size in diff --git a/src/proto_alpha/lib_sc_rollup_node/layer1_helpers.ml b/src/proto_alpha/lib_sc_rollup_node/layer1_helpers.ml index e22943fc4503..1f4ef7b394fa 100644 --- a/src/proto_alpha/lib_sc_rollup_node/layer1_helpers.ml +++ b/src/proto_alpha/lib_sc_rollup_node/layer1_helpers.ml @@ -276,6 +276,9 @@ let get_balance_mutez cctxt ?block pkh = new Protocol_client_context.wrap_full (cctxt :> Client_context.full) in let+ balance = - Protocol.Contract_services.balance cctxt (cctxt#chain, block) (Implicit pkh) + Plugin.Alpha_services.Contract.balance + cctxt + (cctxt#chain, block) + (Implicit pkh) in Protocol.Alpha_context.Tez.to_mutez balance -- GitLab From 3eff09b951f0a6c058d644f7f20f3b87b233abe2 Mon Sep 17 00:00:00 2001 From: Diane Gallois-Wong Date: Thu, 11 Jul 2024 09:15:04 +0200 Subject: [PATCH 2/5] Testnet_experiment_tools: update RPC calls --- devtools/testnet_experiment_tools/dune | 3 ++- devtools/testnet_experiment_tools/tool_alpha.ml | 1 + manifest/product_octez.ml | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/devtools/testnet_experiment_tools/dune b/devtools/testnet_experiment_tools/dune index b7c398c976c6..2809658e4f04 100644 --- a/devtools/testnet_experiment_tools/dune +++ b/devtools/testnet_experiment_tools/dune @@ -12,7 +12,8 @@ octez-libs.base.unix octez-libs.stdlib-unix octez-protocol-alpha-libs.client - tezos-protocol-alpha.protocol) + tezos-protocol-alpha.protocol + octez-protocol-alpha-libs.plugin) (link_flags (:standard) (:include %{workspace_root}/macos-link-flags.sexp)) diff --git a/devtools/testnet_experiment_tools/tool_alpha.ml b/devtools/testnet_experiment_tools/tool_alpha.ml index f7ca9ced0851..73cd452f2c1f 100644 --- a/devtools/testnet_experiment_tools/tool_alpha.ml +++ b/devtools/testnet_experiment_tools/tool_alpha.ml @@ -30,6 +30,7 @@ open Tezos_baking_alpha open Tezos_protocol_alpha open Protocol open Alpha_context +module Alpha_services = Tezos_protocol_plugin_alpha.Plugin.Alpha_services (** Sync node *) diff --git a/manifest/product_octez.ml b/manifest/product_octez.ml index 0551a82aa444..d488c6003cb7 100644 --- a/manifest/product_octez.ml +++ b/manifest/product_octez.ml @@ -7365,6 +7365,7 @@ let _testnet_experiment_tools = octez_stdlib_unix |> open_; Protocol.(client_exn alpha); Protocol.(main alpha); + Protocol.(plugin alpha) |> if_some; ] ~modules:["testnet_experiment_tools"; "format_baker_accounts"] -- GitLab From 9b1acd4c08a7e2732a52af1582ee40e12a5b507e Mon Sep 17 00:00:00 2001 From: Diane Gallois-Wong Date: Wed, 10 Jul 2024 18:22:55 +0200 Subject: [PATCH 3/5] Plugin: move RPC.Registration to a separate file --- src/proto_alpha/lib_plugin/RPC.ml | 123 +----------------- .../services_registration_plugin.ml | 105 +++++++++++++++ 2 files changed, 108 insertions(+), 120 deletions(-) create mode 100644 src/proto_alpha/lib_plugin/services_registration_plugin.ml diff --git a/src/proto_alpha/lib_plugin/RPC.ml b/src/proto_alpha/lib_plugin/RPC.ml index f6a6865c761b..02ac7a5793fd 100644 --- a/src/proto_alpha/lib_plugin/RPC.ml +++ b/src/proto_alpha/lib_plugin/RPC.ml @@ -1,28 +1,10 @@ (*****************************************************************************) (* *) -(* Open Source License *) +(* SPDX-License-Identifier: MIT *) (* Copyright (c) 2018 Nomadic Development. *) -(* Copyright (c) 2021-2022 Nomadic Labs, *) +(* Copyright (c) 2021 Nomadic Labs, *) (* Copyright (c) 2022 TriliTech *) (* *) -(* Permission is hereby granted, free of charge, to any person obtaining a *) -(* copy of this software and associated documentation files (the "Software"),*) -(* to deal in the Software without restriction, including without limitation *) -(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *) -(* and/or sell copies of the Software, and to permit persons to whom the *) -(* Software is furnished to do so, subject to the following conditions: *) -(* *) -(* The above copyright notice and this permission notice shall be included *) -(* in all copies or substantial portions of the Software. *) -(* *) -(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*) -(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *) -(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *) -(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*) -(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *) -(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *) -(* DEALINGS IN THE SOFTWARE. *) -(* *) (*****************************************************************************) open Protocol @@ -57,106 +39,7 @@ let elab_conf = Script_ir_translator_config.make ~keep_extra_types_for_interpreter_logging:true -module Registration = struct - let patched_services = - ref (RPC_directory.empty : Updater.rpc_context RPC_directory.t) - - let register0_fullctxt ~chunked s f = - let open Lwt_result_syntax in - patched_services := - RPC_directory.register ~chunked !patched_services s (fun ctxt q i -> - let* ctxt = Services_registration.rpc_init ctxt `Head_level in - f ctxt q i) - - let register0 ~chunked s f = - register0_fullctxt ~chunked s (fun {context; _} -> f context) - - let register0_fullctxt_successor_level ~chunked s f = - let open Lwt_result_syntax in - patched_services := - RPC_directory.register ~chunked !patched_services s (fun ctxt q i -> - let mode = - if q#successor_level then `Successor_level else `Head_level - in - let* ctxt = Services_registration.rpc_init ctxt mode in - f ctxt q i) - - let register0_successor_level ~chunked s f = - register0_fullctxt_successor_level ~chunked s (fun {context; _} -> - f context) - - let register0_noctxt ~chunked s f = - patched_services := - RPC_directory.register ~chunked !patched_services s (fun _ q i -> f q i) - - let opt_register0_fullctxt ~chunked s f = - let open Lwt_result_syntax in - patched_services := - RPC_directory.opt_register ~chunked !patched_services s (fun ctxt q i -> - let* ctxt = Services_registration.rpc_init ctxt `Head_level in - f ctxt q i) - - let opt_register0 ~chunked s f = - opt_register0_fullctxt ~chunked s (fun {context; _} -> f context) - - let register1_fullctxt ~chunked s f = - let open Lwt_result_syntax in - patched_services := - RPC_directory.register - ~chunked - !patched_services - s - (fun (ctxt, arg) q i -> - let* ctxt = Services_registration.rpc_init ctxt `Head_level in - f ctxt arg q i) - - let opt_register1_fullctxt ~chunked s f = - let open Lwt_result_syntax in - patched_services := - RPC_directory.opt_register - ~chunked - !patched_services - s - (fun (ctxt, arg) q i -> - let* ctxt = Services_registration.rpc_init ctxt `Head_level in - f ctxt arg q i) - - let register1 ~chunked s f = - register1_fullctxt ~chunked s (fun {context; _} x -> f context x) - - let opt_register1 ~chunked s f = - opt_register1_fullctxt ~chunked s (fun {context; _} x -> f context x) - - let register2_fullctxt ~chunked s f = - let open Lwt_result_syntax in - patched_services := - RPC_directory.register - ~chunked - !patched_services - s - (fun ((ctxt, arg1), arg2) q i -> - let* ctxt = Services_registration.rpc_init ctxt `Head_level in - f ctxt arg1 arg2 q i) - - let register2 ~chunked s f = - register2_fullctxt ~chunked s (fun {context; _} a1 a2 q i -> - f context a1 a2 q i) - - let register3_fullctxt ~chunked s f = - let open Lwt_result_syntax in - patched_services := - RPC_directory.register - ~chunked - !patched_services - s - (fun (((ctxt, arg1), arg2), arg3) q i -> - let* ctxt = Services_registration.rpc_init ctxt `Head_level in - f ctxt arg1 arg2 arg3 q i) - - let register3 ~chunked s f = - register3_fullctxt ~chunked s (fun {context; _} a1 a2 a3 q i -> - f context a1 a2 a3 q i) -end +module Registration = Services_registration_plugin let unparsing_mode_encoding = let open Script_ir_unparser in diff --git a/src/proto_alpha/lib_plugin/services_registration_plugin.ml b/src/proto_alpha/lib_plugin/services_registration_plugin.ml new file mode 100644 index 000000000000..90ad160d3b49 --- /dev/null +++ b/src/proto_alpha/lib_plugin/services_registration_plugin.ml @@ -0,0 +1,105 @@ +(*****************************************************************************) +(* *) +(* SPDX-License-Identifier: MIT *) +(* Copyright (c) 2018 Nomadic Development. *) +(* Copyright (c) 2021 Nomadic Labs, *) +(* Copyright (c) 2022 TriliTech *) +(* *) +(*****************************************************************************) + +open Protocol +open Environment + +let patched_services = + ref (RPC_directory.empty : Updater.rpc_context RPC_directory.t) + +let register0_fullctxt ~chunked s f = + let open Lwt_result_syntax in + patched_services := + RPC_directory.register ~chunked !patched_services s (fun ctxt q i -> + let* ctxt = Services_registration.rpc_init ctxt `Head_level in + f ctxt q i) + +let register0 ~chunked s f = + register0_fullctxt ~chunked s (fun {context; _} -> f context) + +let register0_fullctxt_successor_level ~chunked s f = + let open Lwt_result_syntax in + patched_services := + RPC_directory.register ~chunked !patched_services s (fun ctxt q i -> + let mode = + if q#successor_level then `Successor_level else `Head_level + in + let* ctxt = Services_registration.rpc_init ctxt mode in + f ctxt q i) + +let register0_successor_level ~chunked s f = + register0_fullctxt_successor_level ~chunked s (fun {context; _} -> f context) + +let register0_noctxt ~chunked s f = + patched_services := + RPC_directory.register ~chunked !patched_services s (fun _ q i -> f q i) + +let opt_register0_fullctxt ~chunked s f = + let open Lwt_result_syntax in + patched_services := + RPC_directory.opt_register ~chunked !patched_services s (fun ctxt q i -> + let* ctxt = Services_registration.rpc_init ctxt `Head_level in + f ctxt q i) + +let opt_register0 ~chunked s f = + opt_register0_fullctxt ~chunked s (fun {context; _} -> f context) + +let register1_fullctxt ~chunked s f = + let open Lwt_result_syntax in + patched_services := + RPC_directory.register ~chunked !patched_services s (fun (ctxt, arg) q i -> + let* ctxt = Services_registration.rpc_init ctxt `Head_level in + f ctxt arg q i) + +let opt_register1_fullctxt ~chunked s f = + let open Lwt_result_syntax in + patched_services := + RPC_directory.opt_register + ~chunked + !patched_services + s + (fun (ctxt, arg) q i -> + let* ctxt = Services_registration.rpc_init ctxt `Head_level in + f ctxt arg q i) + +let register1 ~chunked s f = + register1_fullctxt ~chunked s (fun {context; _} x -> f context x) + +let opt_register1 ~chunked s f = + opt_register1_fullctxt ~chunked s (fun {context; _} x -> f context x) + +let register2_fullctxt ~chunked s f = + let open Lwt_result_syntax in + patched_services := + RPC_directory.register + ~chunked + !patched_services + s + (fun ((ctxt, arg1), arg2) q i -> + let* ctxt = Services_registration.rpc_init ctxt `Head_level in + f ctxt arg1 arg2 q i) + +let register2 ~chunked s f = + register2_fullctxt ~chunked s (fun {context; _} a1 a2 q i -> + f context a1 a2 q i) + +let register3_fullctxt ~chunked s f = + let open Lwt_result_syntax in + patched_services := + RPC_directory.register + ~chunked + !patched_services + s + (fun (((ctxt, arg1), arg2), arg3) q i -> + let* ctxt = Services_registration.rpc_init ctxt `Head_level in + f ctxt arg1 arg2 arg3 q i) + +let register3 ~chunked s f = + register3_fullctxt ~chunked s (fun {context; _} a1 a2 a3 q i -> + f context a1 a2 a3 q i) -- GitLab From 029675998f732e62aaff83cdd4724970645f0d0f Mon Sep 17 00:00:00 2001 From: Diane Gallois-Wong Date: Wed, 10 Jul 2024 18:39:32 +0200 Subject: [PATCH 4/5] Plugin: handle registration of moved RPCs --- src/proto_alpha/lib_plugin/RPC.ml | 3 ++ .../lib_plugin/contract_services.ml | 28 +++---------------- .../lib_plugin/delegate_services.ml | 22 ++------------- .../services_registration_plugin.ml | 17 +++++++++++ 4 files changed, 26 insertions(+), 44 deletions(-) diff --git a/src/proto_alpha/lib_plugin/RPC.ml b/src/proto_alpha/lib_plugin/RPC.ml index 02ac7a5793fd..e2838c602d00 100644 --- a/src/proto_alpha/lib_plugin/RPC.ml +++ b/src/proto_alpha/lib_plugin/RPC.ml @@ -4379,6 +4379,9 @@ let () = let register () = let open Lwt_result_syntax in + (* TODO: https://gitlab.com/tezos/tezos/-/issues/7369 *) + Contract_services.register () ; + Delegate_services.register () ; Scripts.register () ; Forge.register () ; Parse.register () ; diff --git a/src/proto_alpha/lib_plugin/contract_services.ml b/src/proto_alpha/lib_plugin/contract_services.ml index bf1d296627a7..44ca40316334 100644 --- a/src/proto_alpha/lib_plugin/contract_services.ml +++ b/src/proto_alpha/lib_plugin/contract_services.ml @@ -1,26 +1,8 @@ (*****************************************************************************) (* *) -(* Open Source License *) +(* SPDX-License-Identifier: MIT *) (* Copyright (c) 2018 Dynamic Ledger Solutions, Inc. *) -(* Copyright (c) 2019-2020 Nomadic Labs *) -(* *) -(* Permission is hereby granted, free of charge, to any person obtaining a *) -(* copy of this software and associated documentation files (the "Software"),*) -(* to deal in the Software without restriction, including without limitation *) -(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *) -(* and/or sell copies of the Software, and to permit persons to whom the *) -(* Software is furnished to do so, subject to the following conditions: *) -(* *) -(* The above copyright notice and this permission notice shall be included *) -(* in all copies or substantial portions of the Software. *) -(* *) -(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*) -(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *) -(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *) -(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*) -(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *) -(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *) -(* DEALINGS IN THE SOFTWARE. *) +(* Copyright (c) 2019 Nomadic Labs *) (* *) (*****************************************************************************) @@ -28,6 +10,7 @@ open Environment open Environment.Error_monad open Protocol open Protocol.Alpha_context +open Services_registration_plugin let custom_root = (RPC_path.(open_root / "context" / "contracts") @@ -363,9 +346,7 @@ module S = struct let get_diff = make_service Sapling_services.S.Args.get_diff let register () = - let reg chunked (service, f) = - Services_registration.opt_register1 ~chunked service f - in + let reg chunked (service, f) = opt_register1 ~chunked service f in reg false get_diff let mk_call1 (service, _f) ctxt block id q = @@ -375,7 +356,6 @@ end let register () = let open Lwt_result_syntax in - let open Services_registration in register0 ~chunked:true S.list (fun ctxt () () -> let*! result = Contract.list ctxt in return result) ; diff --git a/src/proto_alpha/lib_plugin/delegate_services.ml b/src/proto_alpha/lib_plugin/delegate_services.ml index 09d709aed1a3..39439cab8550 100644 --- a/src/proto_alpha/lib_plugin/delegate_services.ml +++ b/src/proto_alpha/lib_plugin/delegate_services.ml @@ -1,34 +1,17 @@ (*****************************************************************************) (* *) -(* Open Source License *) +(* SPDX-License-Identifier: MIT *) (* Copyright (c) 2018 Dynamic Ledger Solutions, Inc. *) (* Copyright (c) 2020 Metastate AG *) (* Copyright (c) 2021 Nomadic Labs, *) (* *) -(* Permission is hereby granted, free of charge, to any person obtaining a *) -(* copy of this software and associated documentation files (the "Software"),*) -(* to deal in the Software without restriction, including without limitation *) -(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *) -(* and/or sell copies of the Software, and to permit persons to whom the *) -(* Software is furnished to do so, subject to the following conditions: *) -(* *) -(* The above copyright notice and this permission notice shall be included *) -(* in all copies or substantial portions of the Software. *) -(* *) -(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*) -(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *) -(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *) -(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*) -(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *) -(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *) -(* DEALINGS IN THE SOFTWARE. *) -(* *) (*****************************************************************************) open Environment open Environment.Error_monad open Protocol open Protocol.Alpha_context +open Services_registration_plugin type error += Balance_rpc_non_delegate of public_key_hash @@ -421,7 +404,6 @@ let check_delegate_registered ctxt pkh = | false -> tzfail (Not_registered pkh) let register () = - let open Services_registration in let open Lwt_result_syntax in register0 ~chunked:true S.list_delegate (fun ctxt q () -> let*! delegates = Delegate.list ctxt in diff --git a/src/proto_alpha/lib_plugin/services_registration_plugin.ml b/src/proto_alpha/lib_plugin/services_registration_plugin.ml index 90ad160d3b49..f018d5de0fb6 100644 --- a/src/proto_alpha/lib_plugin/services_registration_plugin.ml +++ b/src/proto_alpha/lib_plugin/services_registration_plugin.ml @@ -7,6 +7,8 @@ (* *) (*****************************************************************************) +(* TODO: https://gitlab.com/tezos/tezos/-/issues/7369 *) + open Protocol open Environment @@ -89,6 +91,21 @@ let register2 ~chunked s f = register2_fullctxt ~chunked s (fun {context; _} a1 a2 q i -> f context a1 a2 q i) +let opt_register2_fullctxt ~chunked s f = + let open Lwt_result_syntax in + patched_services := + RPC_directory.opt_register + ~chunked + !patched_services + s + (fun ((ctxt, arg1), arg2) q i -> + let* ctxt = Services_registration.rpc_init ctxt `Head_level in + f ctxt arg1 arg2 q i) + +let opt_register2 ~chunked s f = + opt_register2_fullctxt ~chunked s (fun {context; _} a1 a2 q i -> + f context a1 a2 q i) + let register3_fullctxt ~chunked s f = let open Lwt_result_syntax in patched_services := -- GitLab From b9363b22bbfad969ee8558e75e030f75ee85c052 Mon Sep 17 00:00:00 2001 From: Diane Gallois-Wong Date: Wed, 10 Jul 2024 18:49:01 +0200 Subject: [PATCH 5/5] Docs/changelog: add internal entry --- docs/protocols/alpha.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/protocols/alpha.rst b/docs/protocols/alpha.rst index 3008e8de7408..d17b19bd7dd8 100644 --- a/docs/protocols/alpha.rst +++ b/docs/protocols/alpha.rst @@ -141,3 +141,7 @@ Internal - Encoding that supports ``endorsement`` kind in operation JSON has been removed. (MR :gl:`!13976`) + +- Moved the RPC files ``contract_services.ml*`` and + ``delegate_services.ml*`` from ``lib_protocol`` to + ``lib_plugin``. (MR :gl:`!14094`) -- GitLab