From 5d767cfab012edb4a7f481d24425dc72353283ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Proust?= Date: Thu, 8 Jun 2023 09:59:08 +0200 Subject: [PATCH 1/5] Proto: Staking-parameters repr module --- src/proto_alpha/lib_protocol/TEZOS_PROTOCOL | 1 + src/proto_alpha/lib_protocol/dune | 4 + .../lib_protocol/staking_parameters_repr.ml | 73 +++++++++++++++++++ .../lib_protocol/staking_parameters_repr.mli | 38 ++++++++++ 4 files changed, 116 insertions(+) create mode 100644 src/proto_alpha/lib_protocol/staking_parameters_repr.ml create mode 100644 src/proto_alpha/lib_protocol/staking_parameters_repr.mli diff --git a/src/proto_alpha/lib_protocol/TEZOS_PROTOCOL b/src/proto_alpha/lib_protocol/TEZOS_PROTOCOL index 967a974461a9..e41760d2be6f 100644 --- a/src/proto_alpha/lib_protocol/TEZOS_PROTOCOL +++ b/src/proto_alpha/lib_protocol/TEZOS_PROTOCOL @@ -109,6 +109,7 @@ "Stake_repr", "Carbonated_map_costs", "Carbonated_map", + "Staking_parameters_repr", "Raw_context_intf", "Raw_context", diff --git a/src/proto_alpha/lib_protocol/dune b/src/proto_alpha/lib_protocol/dune index 68b91814b853..bf48a985aadd 100644 --- a/src/proto_alpha/lib_protocol/dune +++ b/src/proto_alpha/lib_protocol/dune @@ -132,6 +132,7 @@ Stake_repr Carbonated_map_costs Carbonated_map + Staking_parameters_repr Raw_context_intf Raw_context Storage_costs @@ -399,6 +400,7 @@ stake_repr.ml stake_repr.mli carbonated_map_costs.ml carbonated_map_costs.mli carbonated_map.ml carbonated_map.mli + staking_parameters_repr.ml staking_parameters_repr.mli raw_context_intf.ml raw_context.ml raw_context.mli storage_costs.ml storage_costs.mli @@ -668,6 +670,7 @@ stake_repr.ml stake_repr.mli carbonated_map_costs.ml carbonated_map_costs.mli carbonated_map.ml carbonated_map.mli + staking_parameters_repr.ml staking_parameters_repr.mli raw_context_intf.ml raw_context.ml raw_context.mli storage_costs.ml storage_costs.mli @@ -921,6 +924,7 @@ stake_repr.ml stake_repr.mli carbonated_map_costs.ml carbonated_map_costs.mli carbonated_map.ml carbonated_map.mli + staking_parameters_repr.ml staking_parameters_repr.mli raw_context_intf.ml raw_context.ml raw_context.mli storage_costs.ml storage_costs.mli diff --git a/src/proto_alpha/lib_protocol/staking_parameters_repr.ml b/src/proto_alpha/lib_protocol/staking_parameters_repr.ml new file mode 100644 index 000000000000..5393f26bfb9b --- /dev/null +++ b/src/proto_alpha/lib_protocol/staking_parameters_repr.ml @@ -0,0 +1,73 @@ +(*****************************************************************************) +(* *) +(* Open Source License *) +(* Copyright (c) 2023 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. *) +(* *) +(*****************************************************************************) + +type t = { + staking_over_baking_limit : int32; (* in 1/1_000_000th *) + baking_over_staking_edge : int32; (* as a portion of 1_000_000_000 *) +} + +let maximum_baking_over_staking_edge = + (* max is 1 expressed in portions of 1_000_000_000 *) + 1_000_000_000l + +type error += Invalid_staking_parameters + +let () = + register_error_kind + `Permanent + ~id:"operations.invalid_staking_parameters" + ~title:"Invalid parameters for staking parameters" + ~description:"The staking parameters are invalid." + ~pp:(fun ppf () -> Format.fprintf ppf "Invalid staking parameters") + Data_encoding.empty + (function Invalid_staking_parameters -> Some () | _ -> None) + (fun () -> Invalid_staking_parameters) + +let make ~staking_over_baking_limit ~baking_over_staking_edge = + if + Compare.Int32.(staking_over_baking_limit < 0l) + || Compare.Int32.(baking_over_staking_edge < 0l) + || Compare.Int32.( + baking_over_staking_edge > maximum_baking_over_staking_edge) + then Error () + else Ok {staking_over_baking_limit; baking_over_staking_edge} + +let encoding = + let open Data_encoding in + conv_with_guard + (fun {staking_over_baking_limit; baking_over_staking_edge} -> + (staking_over_baking_limit, baking_over_staking_edge)) + (fun (staking_over_baking_limit, baking_over_staking_edge) -> + Result.map_error + (fun () -> "Invalid staking parameters") + (make ~staking_over_baking_limit ~baking_over_staking_edge)) + (obj2 + (req "staking_over_baking_limit" int32) + (req "baking_over_staking_edge" int32)) + +let make ~staking_over_baking_limit ~baking_over_staking_edge = + match make ~staking_over_baking_limit ~baking_over_staking_edge with + | Error () -> Result_syntax.tzfail Invalid_staking_parameters + | Ok _ as ok -> ok diff --git a/src/proto_alpha/lib_protocol/staking_parameters_repr.mli b/src/proto_alpha/lib_protocol/staking_parameters_repr.mli new file mode 100644 index 000000000000..1e371c973c08 --- /dev/null +++ b/src/proto_alpha/lib_protocol/staking_parameters_repr.mli @@ -0,0 +1,38 @@ +(*****************************************************************************) +(* *) +(* Open Source License *) +(* Copyright (c) 2023 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. *) +(* *) +(*****************************************************************************) + +type t = private { + staking_over_baking_limit : int32; (* in 1/1_000_000th *) + baking_over_staking_edge : int32; (* as a portion of 1_000_000_000 *) +} + +type error += Invalid_staking_parameters + +val make : + staking_over_baking_limit:int32 -> + baking_over_staking_edge:int32 -> + t tzresult + +val encoding : t Data_encoding.t -- GitLab From 4243b85cf6d678d012e31aa4f21ed3de4c105479 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Proust?= Date: Thu, 8 Jun 2023 10:00:30 +0200 Subject: [PATCH 2/5] Proto: Staking-parameters storage --- src/proto_alpha/lib_protocol/storage.ml | 17 +++++++++++++++++ src/proto_alpha/lib_protocol/storage.mli | 12 ++++++++++++ 2 files changed, 29 insertions(+) diff --git a/src/proto_alpha/lib_protocol/storage.ml b/src/proto_alpha/lib_protocol/storage.ml index 13ec99c65698..9eb6815ca16c 100644 --- a/src/proto_alpha/lib_protocol/storage.ml +++ b/src/proto_alpha/lib_protocol/storage.ml @@ -293,6 +293,23 @@ module Contract = struct (Make_index (Cycle_repr.Index)) (Signature.Public_key) + module Staking_parameters = + Indexed_context.Make_map + (Registered) + (struct + let name = ["staking_parameters"; "active"] + end) + (Staking_parameters_repr) + + module Pending_staking_parameters = + Make_indexed_data_storage + (Make_subcontext (Registered) (Indexed_context.Raw_context) + (struct + let name = ["staking_parameters"; "pendings"] + end)) + (Make_index (Cycle_repr.Index)) + (Staking_parameters_repr) + module Delegate = Indexed_context.Make_map (Registered) diff --git a/src/proto_alpha/lib_protocol/storage.mli b/src/proto_alpha/lib_protocol/storage.mli index 1d207dcf7c2c..e6c24e52e50d 100644 --- a/src/proto_alpha/lib_protocol/storage.mli +++ b/src/proto_alpha/lib_protocol/storage.mli @@ -161,6 +161,18 @@ module Contract : sig and type value = Signature.Public_key_hash.t and type t := Raw_context.t + module Staking_parameters : + Indexed_data_storage + with type key = Contract_repr.t + and type value = Staking_parameters_repr.t + and type t := Raw_context.t + + module Pending_staking_parameters : + Indexed_data_storage + with type key = Cycle_repr.t + and type value = Staking_parameters_repr.t + and type t := Raw_context.t * Contract_repr.t + (** All contracts (implicit and originated) that are delegated, if any *) module Delegated : Data_set_storage -- GitLab From 2936ec24d58c4a00dcc26db30b5ac145cf5a1eec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Proust?= Date: Thu, 8 Jun 2023 10:01:07 +0200 Subject: [PATCH 3/5] Proto: Staking-parameters preserved-cycle delay --- src/proto_alpha/lib_protocol/TEZOS_PROTOCOL | 1 + .../delegate_staking_parameters.ml | 101 ++++++++++++++++++ .../delegate_staking_parameters.mli | 51 +++++++++ src/proto_alpha/lib_protocol/dune | 4 + 4 files changed, 157 insertions(+) create mode 100644 src/proto_alpha/lib_protocol/delegate_staking_parameters.ml create mode 100644 src/proto_alpha/lib_protocol/delegate_staking_parameters.mli diff --git a/src/proto_alpha/lib_protocol/TEZOS_PROTOCOL b/src/proto_alpha/lib_protocol/TEZOS_PROTOCOL index e41760d2be6f..74d825cef995 100644 --- a/src/proto_alpha/lib_protocol/TEZOS_PROTOCOL +++ b/src/proto_alpha/lib_protocol/TEZOS_PROTOCOL @@ -145,6 +145,7 @@ "Token", "Fees_storage", "Adaptive_inflation_storage", + "Delegate_staking_parameters", "Delegate_consensus_key", "Delegate_storage", "Delegate_sampler", diff --git a/src/proto_alpha/lib_protocol/delegate_staking_parameters.ml b/src/proto_alpha/lib_protocol/delegate_staking_parameters.ml new file mode 100644 index 000000000000..7982a66ac465 --- /dev/null +++ b/src/proto_alpha/lib_protocol/delegate_staking_parameters.ml @@ -0,0 +1,101 @@ +(*****************************************************************************) +(* *) +(* Open Source License *) +(* Copyright (c) 2023 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. *) +(* *) +(*****************************************************************************) + +let of_delegate ctxt delegate = + Storage.Contract.Staking_parameters.get ctxt (Contract_repr.Implicit delegate) + +let raw_pending_updates ctxt delegate = + Storage.Contract.Pending_staking_parameters.bindings + (ctxt, Contract_repr.Implicit delegate) + +let pending_updates ctxt delegate = + let open Lwt_syntax in + let* updates = raw_pending_updates ctxt delegate in + let updates = + List.sort (fun (c1, _) (c2, _) -> Cycle_repr.compare c1 c2) updates + in + return updates + +let raw_of_delegate_for_cycle ctxt delegate cycle = + let open Lwt_result_syntax in + let*! pendings = raw_pending_updates ctxt delegate in + let* active = of_delegate ctxt delegate in + let current_level = Raw_context.current_level ctxt in + let active_for_cycle = + List.fold_left + (fun (c1, active) (c2, update) -> + if Cycle_repr.(c1 < c2 && c2 <= cycle) then (c2, update) + else (c1, active)) + (current_level.cycle, active) + pendings + in + return active_for_cycle + +let of_delegate_for_cycle ctxt delegate cycle = + let open Lwt_result_syntax in + let* _, t = raw_of_delegate_for_cycle ctxt delegate cycle in + return t + +let register_update ctxt delegate t = + let open Lwt_result_syntax in + let update_cycle = + let current_level = Raw_context.current_level ctxt in + let preserved_cycles = Constants_storage.preserved_cycles ctxt in + Cycle_repr.add current_level.cycle (preserved_cycles + 1) + in + let*! ctxt = + Storage.Contract.Pending_staking_parameters.add + (ctxt, Contract_repr.Implicit delegate) + update_cycle + t + in + return ctxt + +let activate ctxt ~new_cycle = + let open Lwt_result_syntax in + Storage.Delegates.fold + ctxt + ~order:`Undefined + ~init:(ok ctxt) + ~f:(fun delegate ctxt -> + let*? ctxt in + let delegate = Contract_repr.Implicit delegate in + let* update = + Storage.Contract.Pending_staking_parameters.find + (ctxt, delegate) + new_cycle + in + match update with + | None -> return ctxt + | Some t -> + let*! ctxt = + Storage.Contract.Staking_parameters.add ctxt delegate t + in + let*! ctxt = + Storage.Contract.Pending_staking_parameters.remove + (ctxt, delegate) + new_cycle + in + return ctxt) diff --git a/src/proto_alpha/lib_protocol/delegate_staking_parameters.mli b/src/proto_alpha/lib_protocol/delegate_staking_parameters.mli new file mode 100644 index 000000000000..8e08af9ff6b1 --- /dev/null +++ b/src/proto_alpha/lib_protocol/delegate_staking_parameters.mli @@ -0,0 +1,51 @@ +(*****************************************************************************) +(* *) +(* Open Source License *) +(* Copyright (c) 2023 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. *) +(* *) +(*****************************************************************************) + +val of_delegate : + Raw_context.t -> + Signature.Public_key_hash.t -> + Staking_parameters_repr.t tzresult Lwt.t + +val of_delegate_for_cycle : + Raw_context.t -> + Signature.Public_key_hash.t -> + Cycle_repr.t -> + Staking_parameters_repr.t tzresult Lwt.t + +val pending_updates : + Raw_context.t -> + Signature.Public_key_hash.t -> + (Cycle_repr.t * Staking_parameters_repr.t) list Lwt.t + +val register_update : + Raw_context.t -> + Signature.Public_key_hash.t -> + Staking_parameters_repr.t -> + Raw_context.t tzresult Lwt.t + +(** Maintenance of staking parameters at the beginning of cycle [new_cycle]. + This function iterates on all registered delegates. *) +val activate : + Raw_context.t -> new_cycle:Cycle_repr.t -> Raw_context.t tzresult Lwt.t diff --git a/src/proto_alpha/lib_protocol/dune b/src/proto_alpha/lib_protocol/dune index bf48a985aadd..97c19e484dbf 100644 --- a/src/proto_alpha/lib_protocol/dune +++ b/src/proto_alpha/lib_protocol/dune @@ -163,6 +163,7 @@ Token Fees_storage Adaptive_inflation_storage + Delegate_staking_parameters Delegate_consensus_key Delegate_storage Delegate_sampler @@ -431,6 +432,7 @@ token.ml token.mli fees_storage.ml fees_storage.mli adaptive_inflation_storage.ml adaptive_inflation_storage.mli + delegate_staking_parameters.ml delegate_staking_parameters.mli delegate_consensus_key.ml delegate_consensus_key.mli delegate_storage.ml delegate_storage.mli delegate_sampler.ml delegate_sampler.mli @@ -701,6 +703,7 @@ token.ml token.mli fees_storage.ml fees_storage.mli adaptive_inflation_storage.ml adaptive_inflation_storage.mli + delegate_staking_parameters.ml delegate_staking_parameters.mli delegate_consensus_key.ml delegate_consensus_key.mli delegate_storage.ml delegate_storage.mli delegate_sampler.ml delegate_sampler.mli @@ -955,6 +958,7 @@ token.ml token.mli fees_storage.ml fees_storage.mli adaptive_inflation_storage.ml adaptive_inflation_storage.mli + delegate_staking_parameters.ml delegate_staking_parameters.mli delegate_consensus_key.ml delegate_consensus_key.mli delegate_storage.ml delegate_storage.mli delegate_sampler.ml delegate_sampler.mli -- GitLab From 3d07430cdc80fa5752a860a74d1ba186b59e02de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Proust?= Date: Thu, 8 Jun 2023 10:02:16 +0200 Subject: [PATCH 4/5] Proto: Staking-parameters in the context --- src/proto_alpha/lib_protocol/alpha_context.ml | 2 ++ src/proto_alpha/lib_protocol/alpha_context.mli | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/src/proto_alpha/lib_protocol/alpha_context.ml b/src/proto_alpha/lib_protocol/alpha_context.ml index 844c28b7439f..f6fd7e0e4275 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.ml +++ b/src/proto_alpha/lib_protocol/alpha_context.ml @@ -504,6 +504,8 @@ module Delegate = struct include Delegate_rewards module For_RPC = Adaptive_inflation_storage.For_RPC end + + module Staking_parameters = Delegate_staking_parameters end module Stake_distribution = struct diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index f4c7393f237c..3acfa6802f07 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -2263,6 +2263,14 @@ module Delegate : sig val get_reward_coeff : t -> cycle:Cycle.t -> Q.t tzresult Lwt.t end end + + module Staking_parameters : sig + val register_update : + context -> + Signature.Public_key_hash.t -> + Staking_parameters_repr.t -> + context tzresult Lwt.t + end end (** This module re-exports definitions from {!Voting_period_repr} and -- GitLab From 2b5714d7eaa637b55d9e0f22e8bbea3d00c41f00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Proust?= Date: Thu, 8 Jun 2023 10:04:02 +0200 Subject: [PATCH 5/5] Proto: set_delegate_paramters pseudo-operation --- src/proto_alpha/lib_protocol/apply.ml | 70 ++++++++++++++++++- .../lib_protocol/delegate_cycles.ml | 2 + 2 files changed, 69 insertions(+), 3 deletions(-) diff --git a/src/proto_alpha/lib_protocol/apply.ml b/src/proto_alpha/lib_protocol/apply.ml index 3da6215c27e2..0c579c9b19a8 100644 --- a/src/proto_alpha/lib_protocol/apply.ml +++ b/src/proto_alpha/lib_protocol/apply.ml @@ -47,6 +47,7 @@ type error += | Staking_for_nondelegate_while_costaking_disabled | Invalid_nonzero_transaction_amount of Tez.t | Invalid_unstake_request_amount of {requested_amount : Z.t} + | Invalid_staking_parameters_sender let () = register_error_kind @@ -285,7 +286,16 @@ let () = | Invalid_unstake_request_amount {requested_amount} -> Some requested_amount | _ -> None) - (fun requested_amount -> Invalid_unstake_request_amount {requested_amount}) + (fun requested_amount -> Invalid_unstake_request_amount {requested_amount}) ; + register_error_kind + `Permanent + ~id:"operations.invalid_staking_parameters_sender" + ~title:"Invalid staking parameters sender" + ~description:"The staking parameters can only be set by delegates." + ~pp:(fun ppf () -> Format.fprintf ppf "Invalid staking parameters sender") + Data_encoding.empty + (function Invalid_staking_parameters_sender -> Some () | _ -> None) + (fun () -> Invalid_staking_parameters_sender) open Apply_results open Apply_operation_result @@ -449,6 +459,35 @@ let apply_finalize_unstake ~ctxt ~sender ~amount ~destination ~before_operation in return (ctxt, result, []) +let apply_set_delegate_parameters ~ctxt ~delegate ~staking_over_baking_limit + ~baking_over_staking_edge ~before_operation = + let open Lwt_result_syntax in + let staking_over_baking_limit = Z.to_int32 staking_over_baking_limit in + let baking_over_staking_edge = Z.to_int32 baking_over_staking_edge in + let*? t = + Staking_parameters_repr.make + ~staking_over_baking_limit + ~baking_over_staking_edge + in + let* is_delegate = Contract.is_delegate ctxt delegate in + let*? () = error_unless is_delegate Invalid_staking_parameters_sender in + let* ctxt = Delegate.Staking_parameters.register_update ctxt delegate t in + let result = + Transaction_to_contract_result + { + storage = None; + lazy_storage_diff = None; + balance_updates = []; + ticket_receipt = []; + originated_contracts = []; + consumed_gas = Gas.consumed ~since:before_operation ~until:ctxt; + storage_size = Z.zero; + paid_storage_size_diff = Z.zero; + allocated_destination_contract = false; + } + in + return (ctxt, result, []) + let transfer_from_any_address ctxt sender destination amount = match sender with | Destination.Contract sender -> @@ -949,11 +988,36 @@ let apply_manager_operation : ~amount ~destination:pkh ~before_operation:ctxt_before_op - | ("default" | "stake" | "unstake" | "finalize_unstake"), _ -> + | ( "set_delegate_parameters", + Prim + ( _, + D_Pair, + [ + Int (_, staking_over_baking_limit); + Prim + ( _, + D_Pair, + [ + Int (_, baking_over_staking_edge); Prim (_, D_Unit, [], []); + ], + [] ); + ], + [] ) ) -> + apply_set_delegate_parameters + ~ctxt + ~delegate:source + ~staking_over_baking_limit + ~baking_over_staking_edge + ~before_operation:ctxt_before_op + | ( ( "default" | "stake" | "unstake" | "finalize_unstake" + | "set_delegate_parameters" ), + _ ) -> (* Only allow: - [unit] parameter to implicit accounts' default, stake, and finalize_unstake entrypoints; - - [nat] parameter to implicit accounts' unstake entrypoint. *) + - [nat] parameter to implicit accounts' unstake entrypoint; + - [pair nat nat unit] parameter to implicit accounts' + set_delegate_parameters entrypoint.*) tzfail (Script_interpreter.Bad_contract_parameter source_contract) | _ -> tzfail (Script_tc_errors.No_such_entrypoint entrypoint)) >|=? fun (ctxt, res, ops) -> (ctxt, Transaction_result res, ops) diff --git a/src/proto_alpha/lib_protocol/delegate_cycles.ml b/src/proto_alpha/lib_protocol/delegate_cycles.ml index 58f7a14e1774..a3c979c34763 100644 --- a/src/proto_alpha/lib_protocol/delegate_cycles.ml +++ b/src/proto_alpha/lib_protocol/delegate_cycles.ml @@ -232,6 +232,8 @@ let distribute_endorsing_rewards ctxt last_cycle unrevealed_nonces = let cycle_end ctxt last_cycle = Seed_storage.cycle_end ctxt last_cycle >>=? fun (ctxt, unrevealed_nonces) -> let new_cycle = Cycle_repr.add last_cycle 1 in + (* TODO #5807: is this the right place?? *) + Delegate_staking_parameters.activate ctxt ~new_cycle >>=? fun ctxt -> Delegate_sampler.select_new_distribution_at_cycle_end ctxt ~new_cycle >>=? fun ctxt -> Delegate_consensus_key.activate ctxt ~new_cycle >>=? fun ctxt -> -- GitLab