From c3141112a6b220a37dc903048b683636033dbe4b Mon Sep 17 00:00:00 2001 From: Julien Tesson Date: Tue, 19 Dec 2023 21:03:47 +0100 Subject: [PATCH 1/9] shell_services/history_mode: change comment referencing preserved_cycles --- src/lib_shell_services/history_mode.ml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/lib_shell_services/history_mode.ml b/src/lib_shell_services/history_mode.ml index 90254796cc04..ac87314677ff 100644 --- a/src/lib_shell_services/history_mode.ml +++ b/src/lib_shell_services/history_mode.ml @@ -42,10 +42,9 @@ type t = | Rolling of additional_cycles option (* The default_offset value defines a window of stored cycles which is - suitable for baking services. It currently corresponds to 6 as we + suitable for baking services. It currently corresponds to 2 as we store 1 cycle below the last preserved block level of the current - head, which is set to [blocks_preservation_cycles] cycles in the - past. + head, which is set to [blocks_preservation_cycles] cycles in the past. TODO: https://gitlab.com/tezos/tezos/-/issues/1406 As this value is potentially both network and protocol specific, it could be lifted as a protocol value or an hardcoded node -- GitLab From e17f14d505c30310f1b92d9df61c50b1f55a7ee2 Mon Sep 17 00:00:00 2001 From: Julien Tesson Date: Wed, 10 Jan 2024 21:28:56 +0100 Subject: [PATCH 2/9] proto/constants,ai_storage: add issuance_modification_delay constant --- .../lib_protocol/adaptive_issuance_services.ml | 6 ++++-- .../lib_protocol/adaptive_issuance_storage.ml | 11 ++++++----- src/proto_alpha/lib_protocol/alpha_context.mli | 2 ++ src/proto_alpha/lib_protocol/constants_storage.ml | 4 ++++ src/proto_alpha/lib_protocol/constants_storage.mli | 7 +++++++ 5 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/proto_alpha/lib_protocol/adaptive_issuance_services.ml b/src/proto_alpha/lib_protocol/adaptive_issuance_services.ml index 1386e85cdf86..7477b06ace46 100644 --- a/src/proto_alpha/lib_protocol/adaptive_issuance_services.ml +++ b/src/proto_alpha/lib_protocol/adaptive_issuance_services.ml @@ -220,7 +220,7 @@ let collect_expected_rewards ~ctxt = } else (* This coeff is correct only when applied to Cycle lesser than - [preserved_cycles] after the current context, otherwise the coeff will + [issuance_modification_delay] after the current context, otherwise the coeff will not be set and thus we get the default values. *) let open Delegate.Rewards.For_RPC in let* coeff = get_reward_coeff ctxt ~cycle in @@ -261,7 +261,9 @@ let collect_expected_rewards ~ctxt = } in let queried_cycles = - Cycle.(ctxt_cycle ---> add ctxt_cycle csts.preserved_cycles) + Cycle.( + ctxt_cycle + ---> add ctxt_cycle (Constants.issuance_modification_delay ctxt)) in List.map_es reward_of_cycle queried_cycles diff --git a/src/proto_alpha/lib_protocol/adaptive_issuance_storage.ml b/src/proto_alpha/lib_protocol/adaptive_issuance_storage.ml index c9968fac1f91..82e9ab49e1a9 100644 --- a/src/proto_alpha/lib_protocol/adaptive_issuance_storage.ml +++ b/src/proto_alpha/lib_protocol/adaptive_issuance_storage.ml @@ -66,10 +66,9 @@ let check_determined_cycle ctxt cycle = let ai_enable = Constants_storage.adaptive_issuance_enable ctxt in if ai_enable then let ctxt_cycle = (Raw_context.current_level ctxt).cycle in - let preserved_cycles = Constants_storage.preserved_cycles ctxt in + let cycles_delay = Constants_storage.issuance_modification_delay ctxt in fail_unless - Cycle_repr.( - ctxt_cycle <= cycle && cycle <= add ctxt_cycle preserved_cycles) + Cycle_repr.(ctxt_cycle <= cycle && cycle <= add ctxt_cycle cycles_delay) (Undetermined_issuance_coeff_for_cycle cycle) else return_unit @@ -242,8 +241,10 @@ let compute_and_store_reward_coeff_at_cycle_end ctxt ~new_cycle = let reward_params = Constants_storage.adaptive_issuance_rewards_params ctxt in - let preserved = Constants_storage.preserved_cycles ctxt in - let for_cycle = Cycle_repr.add new_cycle preserved in + let modification_delay = + Constants_storage.issuance_modification_delay ctxt + in + let for_cycle = Cycle_repr.add new_cycle modification_delay in let before_for_cycle = Cycle_repr.pred for_cycle in let* total_supply = Storage.Contract.Total_supply.get ctxt in let* total_stake = Stake_storage.get_total_active_stake ctxt for_cycle in diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index abe5e3d38406..989dcdf34dab 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -965,6 +965,8 @@ module Constants : sig val delegate_parameters_activation_delay : context -> int + val issuance_modification_delay : context -> int + val blocks_per_cycle : context -> int32 val blocks_per_commitment : context -> int32 diff --git a/src/proto_alpha/lib_protocol/constants_storage.ml b/src/proto_alpha/lib_protocol/constants_storage.ml index 83da05502109..f87b06db3afa 100644 --- a/src/proto_alpha/lib_protocol/constants_storage.ml +++ b/src/proto_alpha/lib_protocol/constants_storage.ml @@ -40,6 +40,10 @@ let delegate_parameters_activation_delay c = let constants = Raw_context.constants c in constants.delegate_parameters_activation_delay +let issuance_modification_delay c = + let constants = Raw_context.constants c in + constants.consensus_rights_delay + let blocks_per_cycle c = let constants = Raw_context.constants c in constants.blocks_per_cycle diff --git a/src/proto_alpha/lib_protocol/constants_storage.mli b/src/proto_alpha/lib_protocol/constants_storage.mli index f254c88e8002..dba7b9dca3b8 100644 --- a/src/proto_alpha/lib_protocol/constants_storage.mli +++ b/src/proto_alpha/lib_protocol/constants_storage.mli @@ -164,3 +164,10 @@ val adaptive_issuance_force_activation : Raw_context.t -> bool val adaptive_issuance_ns_enable : Raw_context.t -> bool val direct_ticket_spending_enable : Raw_context.t -> bool + +(** The following accessor are not actual parameters, but constants that + derives from the protocol parameter. *) + +(** Delay in cycle before the current state of the stake impacts the + issuance rate.*) +val issuance_modification_delay : Raw_context.t -> int -- GitLab From 92356bfb67cd7a3bdcec5b1f4bf9ddebc7c544ec Mon Sep 17 00:00:00 2001 From: Julien Tesson Date: Wed, 10 Jan 2024 21:33:08 +0100 Subject: [PATCH 3/9] proto/constants,ai_storage: add adaptive_issuance_activation_delay constant --- src/proto_alpha/lib_protocol/adaptive_issuance_storage.ml | 4 +--- src/proto_alpha/lib_protocol/constants_storage.ml | 4 ++++ src/proto_alpha/lib_protocol/constants_storage.mli | 4 ++++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/proto_alpha/lib_protocol/adaptive_issuance_storage.ml b/src/proto_alpha/lib_protocol/adaptive_issuance_storage.ml index 82e9ab49e1a9..7644e6df7550 100644 --- a/src/proto_alpha/lib_protocol/adaptive_issuance_storage.ml +++ b/src/proto_alpha/lib_protocol/adaptive_issuance_storage.ml @@ -370,9 +370,7 @@ let update_ema ctxt ~vote = | None -> (* set the feature to activate in a few cycles *) let current_cycle = (Level_storage.current ctxt).cycle in - let delay = - 1 + preserved_cycles ctxt + Constants_repr.max_slashing_period - in + let delay = adaptive_issuance_activation_delay ctxt in let cycle = Cycle_repr.add current_cycle delay in let+ ctxt = activate ctxt ~cycle in (ctxt, Some cycle) diff --git a/src/proto_alpha/lib_protocol/constants_storage.ml b/src/proto_alpha/lib_protocol/constants_storage.ml index f87b06db3afa..7af73d28a8f3 100644 --- a/src/proto_alpha/lib_protocol/constants_storage.ml +++ b/src/proto_alpha/lib_protocol/constants_storage.ml @@ -44,6 +44,10 @@ let issuance_modification_delay c = let constants = Raw_context.constants c in constants.consensus_rights_delay +let adaptive_issuance_activation_delay c = + let constants = Raw_context.constants c in + 1 + constants.consensus_rights_delay + Constants_repr.max_slashing_period + let blocks_per_cycle c = let constants = Raw_context.constants c in constants.blocks_per_cycle diff --git a/src/proto_alpha/lib_protocol/constants_storage.mli b/src/proto_alpha/lib_protocol/constants_storage.mli index dba7b9dca3b8..8a937c832549 100644 --- a/src/proto_alpha/lib_protocol/constants_storage.mli +++ b/src/proto_alpha/lib_protocol/constants_storage.mli @@ -171,3 +171,7 @@ val direct_ticket_spending_enable : Raw_context.t -> bool (** Delay in cycle before the current state of the stake impacts the issuance rate.*) val issuance_modification_delay : Raw_context.t -> int + +(** Time in cycle before activation of AI after the voting EMA threshold is + reached *) +val adaptive_issuance_activation_delay : Raw_context.t -> int -- GitLab From 890a35b15bd2900d85ff210cdbe3116c03e6420f Mon Sep 17 00:00:00 2001 From: Julien Tesson Date: Wed, 10 Jan 2024 21:38:19 +0100 Subject: [PATCH 4/9] proto/constants,delegate_activation_storage: add tolerated_inactivity_period constant The pseudo-constant is set to `1 + consensus_rights_delay` --- src/proto_alpha/lib_protocol/constants_storage.ml | 4 ++++ src/proto_alpha/lib_protocol/constants_storage.mli | 4 ++++ .../lib_protocol/delegate_activation_storage.ml | 9 +++++---- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/proto_alpha/lib_protocol/constants_storage.ml b/src/proto_alpha/lib_protocol/constants_storage.ml index 7af73d28a8f3..8bd4a8505e37 100644 --- a/src/proto_alpha/lib_protocol/constants_storage.ml +++ b/src/proto_alpha/lib_protocol/constants_storage.ml @@ -48,6 +48,10 @@ let adaptive_issuance_activation_delay c = let constants = Raw_context.constants c in 1 + constants.consensus_rights_delay + Constants_repr.max_slashing_period +let tolerated_inactivity_period c = + let constants = Raw_context.constants c in + 1 + constants.consensus_rights_delay + let blocks_per_cycle c = let constants = Raw_context.constants c in constants.blocks_per_cycle diff --git a/src/proto_alpha/lib_protocol/constants_storage.mli b/src/proto_alpha/lib_protocol/constants_storage.mli index 8a937c832549..9370ea3f3e33 100644 --- a/src/proto_alpha/lib_protocol/constants_storage.mli +++ b/src/proto_alpha/lib_protocol/constants_storage.mli @@ -175,3 +175,7 @@ val issuance_modification_delay : Raw_context.t -> int (** Time in cycle before activation of AI after the voting EMA threshold is reached *) val adaptive_issuance_activation_delay : Raw_context.t -> int + +(** Tolerated period of inactivity, in cycles, before a delegate is + deactivated *) +val tolerated_inactivity_period : Raw_context.t -> int diff --git a/src/proto_alpha/lib_protocol/delegate_activation_storage.ml b/src/proto_alpha/lib_protocol/delegate_activation_storage.ml index b34e822262d0..357d339d144a 100644 --- a/src/proto_alpha/lib_protocol/delegate_activation_storage.ml +++ b/src/proto_alpha/lib_protocol/delegate_activation_storage.ml @@ -59,13 +59,14 @@ let set_active ctxt delegate = let open Lwt_result_syntax in let* inactive = is_inactive ctxt delegate in let current_cycle = (Raw_context.current_level ctxt).cycle in + let tolerance = Constants_storage.tolerated_inactivity_period ctxt in let preserved_cycles = Constants_storage.preserved_cycles ctxt in (* We allow a number of cycles before a delegate is deactivated as follows: - - if the delegate is active, we give it at least `1 + preserved_cycles` + - if the delegate is active, we give it at least `tolerance` cycles after the current cycle before to be deactivated. - if the delegate is new or inactive, we give it additionally `preserved_cycles` because the delegate needs this number of cycles to - receive rights, so `1 + 2 * preserved_cycles` in total. *) + receive rights, so `tolerance + preserved_cycles` in total. *) let delegate_contract = Contract_repr.Implicit delegate in let* current_last_active_cycle = Storage.Contract.Delegate_last_cycle_before_deactivation.find @@ -74,10 +75,10 @@ let set_active ctxt delegate = in let last_active_cycle = match current_last_active_cycle with - | None -> Cycle_repr.add current_cycle (1 + (2 * preserved_cycles)) + | None -> Cycle_repr.add current_cycle (tolerance + preserved_cycles) | Some current_last_active_cycle -> let delay = - if inactive then 1 + (2 * preserved_cycles) else 1 + preserved_cycles + if inactive then tolerance + preserved_cycles else tolerance in let updated = Cycle_repr.add current_cycle delay in Cycle_repr.max current_last_active_cycle updated -- GitLab From 996f88de2ca1a12ce5af4a7f5e9369551ec0265b Mon Sep 17 00:00:00 2001 From: Julien Tesson Date: Thu, 7 Dec 2023 17:27:02 +0100 Subject: [PATCH 5/9] proto/constants,delegate_consensus_key: add key_activation_delay constant --- src/proto_alpha/lib_protocol/constants_storage.ml | 4 ++++ src/proto_alpha/lib_protocol/constants_storage.mli | 3 +++ src/proto_alpha/lib_protocol/delegate_consensus_key.ml | 10 ++++++---- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/proto_alpha/lib_protocol/constants_storage.ml b/src/proto_alpha/lib_protocol/constants_storage.ml index 8bd4a8505e37..79099d624567 100644 --- a/src/proto_alpha/lib_protocol/constants_storage.ml +++ b/src/proto_alpha/lib_protocol/constants_storage.ml @@ -52,6 +52,10 @@ let tolerated_inactivity_period c = let constants = Raw_context.constants c in 1 + constants.consensus_rights_delay +let consensus_key_activation_delay c = + let constants = Raw_context.constants c in + constants.consensus_rights_delay + let blocks_per_cycle c = let constants = Raw_context.constants c in constants.blocks_per_cycle diff --git a/src/proto_alpha/lib_protocol/constants_storage.mli b/src/proto_alpha/lib_protocol/constants_storage.mli index 9370ea3f3e33..051b18396704 100644 --- a/src/proto_alpha/lib_protocol/constants_storage.mli +++ b/src/proto_alpha/lib_protocol/constants_storage.mli @@ -179,3 +179,6 @@ val adaptive_issuance_activation_delay : Raw_context.t -> int (** Tolerated period of inactivity, in cycles, before a delegate is deactivated *) val tolerated_inactivity_period : Raw_context.t -> int + +(** Delay before the activation of a consensus key, in cycles *) +val consensus_key_activation_delay : Raw_context.t -> int diff --git a/src/proto_alpha/lib_protocol/delegate_consensus_key.ml b/src/proto_alpha/lib_protocol/delegate_consensus_key.ml index 495293c7d760..230c091660d3 100644 --- a/src/proto_alpha/lib_protocol/delegate_consensus_key.ml +++ b/src/proto_alpha/lib_protocol/delegate_consensus_key.ml @@ -151,8 +151,10 @@ let raw_pending_updates ctxt ?up_to_cycle delegate = let last_cycle = match up_to_cycle with | None -> - let preserved_cycles = Constants_storage.preserved_cycles ctxt in - Cycle_repr.add first_cycle preserved_cycles + let cycles_delay = + Constants_storage.consensus_key_activation_delay ctxt + in + Cycle_repr.add first_cycle cycles_delay | Some cycle -> cycle in Cycle_repr.(first_cycle ---> last_cycle) @@ -194,8 +196,8 @@ let register_update ctxt delegate pk = 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) + let cycles_delay = Constants_storage.consensus_key_activation_delay ctxt in + Cycle_repr.add current_level.cycle (cycles_delay + 1) in let* () = let* first_active_cycle, active_pubkey = -- GitLab From 2277f4e30a96751b4f9956b62142188b18b9cac8 Mon Sep 17 00:00:00 2001 From: Julien Tesson Date: Wed, 13 Dec 2023 22:19:19 +0100 Subject: [PATCH 6/9] proto/tests: uses consensus_key_activation_delay in test --- .../lib_protocol/test/unit/test_consensus_key.ml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/proto_alpha/lib_protocol/test/unit/test_consensus_key.ml b/src/proto_alpha/lib_protocol/test/unit/test_consensus_key.ml index 3fceadd3e376..2e90fbdf462f 100644 --- a/src/proto_alpha/lib_protocol/test/unit/test_consensus_key.ml +++ b/src/proto_alpha/lib_protocol/test/unit/test_consensus_key.ml @@ -121,8 +121,10 @@ let test_consensus_key_storage () = let* ctxt, del1, del2 = create () in let a1 = Account.new_account () in let a2 = Account.new_account () in - let preserved_cycles = Constants_storage.preserved_cycles ctxt in - let* () = Assert.equal_int ~loc:__LOC__ preserved_cycles 3 in + let consensus_key_activation_delay = + Constants_storage.consensus_key_activation_delay ctxt + in + let* () = Assert.equal_int ~loc:__LOC__ consensus_key_activation_delay 3 in let* () = let* active_pkh = Consensus_key.active_key ctxt del1.pkh in Assert.equal_pkh ~__LOC__ active_pkh.consensus_pkh del1.pkh -- GitLab From cf6c1d4a69b015e5c0fe78724187af40333d82e5 Mon Sep 17 00:00:00 2001 From: Julien Tesson Date: Thu, 7 Dec 2023 17:35:21 +0100 Subject: [PATCH 7/9] proto/constants: add slashable_deposits_period constant --- .../lib_protocol/alpha_context.mli | 2 ++ .../lib_protocol/constants_storage.ml | 4 +++ .../lib_protocol/constants_storage.mli | 4 +++ .../lib_protocol/delegate_services.ml | 4 +-- .../delegate_slashed_deposits_storage.ml | 6 +++-- src/proto_alpha/lib_protocol/staking.ml | 6 +++-- .../lib_protocol/unstake_requests_storage.ml | 25 +++++++++++++------ .../unstaked_frozen_deposits_storage.ml | 6 +++-- 8 files changed, 41 insertions(+), 16 deletions(-) diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index 989dcdf34dab..e4b23ce9463a 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -965,6 +965,8 @@ module Constants : sig val delegate_parameters_activation_delay : context -> int + val slashable_deposits_period : context -> int + val issuance_modification_delay : context -> int val blocks_per_cycle : context -> int32 diff --git a/src/proto_alpha/lib_protocol/constants_storage.ml b/src/proto_alpha/lib_protocol/constants_storage.ml index 79099d624567..bd408d6c0eff 100644 --- a/src/proto_alpha/lib_protocol/constants_storage.ml +++ b/src/proto_alpha/lib_protocol/constants_storage.ml @@ -56,6 +56,10 @@ let consensus_key_activation_delay c = let constants = Raw_context.constants c in constants.consensus_rights_delay +let slashable_deposits_period c = + let constants = Raw_context.constants c in + constants.consensus_rights_delay + let blocks_per_cycle c = let constants = Raw_context.constants c in constants.blocks_per_cycle diff --git a/src/proto_alpha/lib_protocol/constants_storage.mli b/src/proto_alpha/lib_protocol/constants_storage.mli index 051b18396704..23f71471d8f3 100644 --- a/src/proto_alpha/lib_protocol/constants_storage.mli +++ b/src/proto_alpha/lib_protocol/constants_storage.mli @@ -182,3 +182,7 @@ val tolerated_inactivity_period : Raw_context.t -> int (** Delay before the activation of a consensus key, in cycles *) val consensus_key_activation_delay : Raw_context.t -> int + +(** Period, in cycles, during which frozen tokens remain slashable after the + cycle of their deposit *) +val slashable_deposits_period : Raw_context.t -> int diff --git a/src/proto_alpha/lib_protocol/delegate_services.ml b/src/proto_alpha/lib_protocol/delegate_services.ml index 486f90e25433..ad13cc74a005 100644 --- a/src/proto_alpha/lib_protocol/delegate_services.ml +++ b/src/proto_alpha/lib_protocol/delegate_services.ml @@ -629,12 +629,12 @@ let register () = register1 ~chunked:false S.unstaked_frozen_deposits (fun ctxt pkh () () -> let* () = check_delegate_registered ctxt pkh in let ctxt_cycle = (Alpha_context.Level.current ctxt).cycle in - let csts = (Constants.all ctxt).parametric in let last_unslashable_cycle = Option.value ~default:Cycle.root @@ Cycle.sub ctxt_cycle - (csts.preserved_cycles + Constants_repr.max_slashing_period) + (Constants.slashable_deposits_period ctxt + + Constants_repr.max_slashing_period) in let cycles = Cycle.(last_unslashable_cycle ---> ctxt_cycle) in let* requests = diff --git a/src/proto_alpha/lib_protocol/delegate_slashed_deposits_storage.ml b/src/proto_alpha/lib_protocol/delegate_slashed_deposits_storage.ml index 2c6300cb622d..f14b5231cbba 100644 --- a/src/proto_alpha/lib_protocol/delegate_slashed_deposits_storage.ml +++ b/src/proto_alpha/lib_protocol/delegate_slashed_deposits_storage.ml @@ -146,7 +146,9 @@ let apply_and_clear_denunciations ctxt = | None -> current_cycle | Some previous_cycle -> previous_cycle in - let preserved_cycles = Constants_storage.preserved_cycles ctxt in + let slashable_deposits_period = + Constants_storage.slashable_deposits_period ctxt + in let global_limit_of_staking_over_baking_plus_two = let global_limit_of_staking_over_baking = Constants_storage.adaptive_issuance_global_limit_of_staking_over_baking @@ -283,7 +285,7 @@ let apply_and_clear_denunciations ctxt = in let* to_burn, to_reward = let oldest_slashable_cycle = - Cycle_repr.sub misbehaviour_cycle preserved_cycles + Cycle_repr.sub misbehaviour_cycle slashable_deposits_period |> Option.value ~default:Cycle_repr.root in let slashable_cycles = diff --git a/src/proto_alpha/lib_protocol/staking.ml b/src/proto_alpha/lib_protocol/staking.ml index 8e7800a6959d..e637b4f9d558 100644 --- a/src/proto_alpha/lib_protocol/staking.ml +++ b/src/proto_alpha/lib_protocol/staking.ml @@ -142,9 +142,11 @@ let can_stake_from_unstake ctxt ~for_next_cycle_use_only_after_slashing if for_next_cycle_use_only_after_slashing then Cycle_repr.succ current_cycle else current_cycle in - let preserved_cycles = Constants_storage.preserved_cycles ctxt in + let slashable_deposits_period = + Constants_storage.slashable_deposits_period ctxt + in let oldest_slashable_cycle = - Cycle_repr.sub current_cycle (preserved_cycles + 1) + Cycle_repr.sub current_cycle (slashable_deposits_period + 1) |> Option.value ~default:Cycle_repr.root in return diff --git a/src/proto_alpha/lib_protocol/unstake_requests_storage.ml b/src/proto_alpha/lib_protocol/unstake_requests_storage.ml index f4309bf55b38..ec1e78f7fdf9 100644 --- a/src/proto_alpha/lib_protocol/unstake_requests_storage.ml +++ b/src/proto_alpha/lib_protocol/unstake_requests_storage.ml @@ -68,9 +68,12 @@ let prepared_finalize_unstake_encoding : (req "finalizable" finalizable_encoding) (req "unfinalizable" stored_requests_encoding)) -let apply_slashes ~preserved_cycles slashing_history ~from_cycle amount = +let apply_slashes ~slashable_deposits_period slashing_history ~from_cycle amount + = let first_cycle_to_apply_slash = from_cycle in - let last_cycle_to_apply_slash = Cycle_repr.add from_cycle preserved_cycles in + let last_cycle_to_apply_slash = + Cycle_repr.add from_cycle slashable_deposits_period + in (* [slashing_history] is sorted so slashings always happen in the same order. *) List.fold_left (fun remain (slashing_cycle, slashing_percentage) -> @@ -91,9 +94,13 @@ let apply_slashes ~preserved_cycles slashing_history ~from_cycle amount = let prepare_finalize_unstake ctxt ~for_next_cycle_use_only_after_slashing contract = let open Lwt_result_syntax in - let preserved_cycles = Constants_storage.preserved_cycles ctxt in + let slashable_deposits_period = + Constants_storage.slashable_deposits_period ctxt + in let max_slashing_period = Constants_repr.max_slashing_period in - let preserved_plus_slashing = preserved_cycles + max_slashing_period in + let slashable_plus_denunciation_delay = + slashable_deposits_period + max_slashing_period + in let current_cycle = (Raw_context.current_level ctxt).cycle in let current_cycle = if for_next_cycle_use_only_after_slashing then Cycle_repr.succ current_cycle @@ -103,7 +110,7 @@ let prepare_finalize_unstake ctxt ~for_next_cycle_use_only_after_slashing match requests_opt with | None | Some {delegate = _; requests = []} -> return_none | Some {delegate; requests} -> ( - match Cycle_repr.sub current_cycle preserved_plus_slashing with + match Cycle_repr.sub current_cycle slashable_plus_denunciation_delay with | None (* no finalizable cycle *) -> return_some {finalizable = []; unfinalizable = {delegate; requests}} | Some greatest_finalizable_cycle -> @@ -122,7 +129,7 @@ let prepare_finalize_unstake ctxt ~for_next_cycle_use_only_after_slashing if Cycle_repr.(request_cycle <= greatest_finalizable_cycle) then let new_amount = apply_slashes - ~preserved_cycles + ~slashable_deposits_period slashing_history ~from_cycle:request_cycle request_amount @@ -162,7 +169,9 @@ module For_RPC = struct let current_level = Raw_context.current_level ctxt in let cycle_eras = Raw_context.cycle_eras ctxt in let is_last_of_cycle = Level_repr.last_of_cycle ~cycle_eras current_level in - let preserved_cycles = Constants_storage.preserved_cycles ctxt in + let slashable_deposits_period = + Constants_storage.slashable_deposits_period ctxt + in let* slashing_history_opt = Storage.Contract.Slashed_deposits.find ctxt @@ -239,7 +248,7 @@ module For_RPC = struct (fun (request_cycle, request_amount) -> let new_amount = apply_slashes - ~preserved_cycles + ~slashable_deposits_period slashing_history ~from_cycle:request_cycle request_amount diff --git a/src/proto_alpha/lib_protocol/unstaked_frozen_deposits_storage.ml b/src/proto_alpha/lib_protocol/unstaked_frozen_deposits_storage.ml index 2018e3c8cdb4..782d27216ade 100644 --- a/src/proto_alpha/lib_protocol/unstaked_frozen_deposits_storage.ml +++ b/src/proto_alpha/lib_protocol/unstaked_frozen_deposits_storage.ml @@ -25,9 +25,11 @@ let current_unslashable_cycle ctxt = let cycle = (Raw_context.current_level ctxt).cycle in - let preserved_cycles = Constants_storage.preserved_cycles ctxt in + let slashable_deposits_period = + Constants_storage.slashable_deposits_period ctxt + in let max_slashing_period = Constants_repr.max_slashing_period in - Cycle_repr.sub cycle (preserved_cycles + max_slashing_period) + Cycle_repr.sub cycle (slashable_deposits_period + max_slashing_period) let get_all ctxt contract = let open Lwt_result_syntax in -- GitLab From d1ae9f6024c27d31a42e4660394fe9dab641484d Mon Sep 17 00:00:00 2001 From: Julien Tesson Date: Mon, 5 Feb 2024 11:53:52 +0100 Subject: [PATCH 8/9] proto/constants_storage: document pseudo constants --- .../lib_protocol/constants_storage.ml | 16 ++++++++++++++++ .../lib_protocol/constants_storage.mli | 13 +++++++------ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/proto_alpha/lib_protocol/constants_storage.ml b/src/proto_alpha/lib_protocol/constants_storage.ml index bd408d6c0eff..4feb06a9a8d1 100644 --- a/src/proto_alpha/lib_protocol/constants_storage.ml +++ b/src/proto_alpha/lib_protocol/constants_storage.ml @@ -40,22 +40,38 @@ let delegate_parameters_activation_delay c = let constants = Raw_context.constants c in constants.delegate_parameters_activation_delay +(** Issuance modification delay: + number of cycles after which the issuance rate -- computed from current stake + over total supply -- will be used. + + We use consensus_rights_delay so that the issuance rate in one cycle + corresponds to the "active" staking rights. +*) let issuance_modification_delay c = let constants = Raw_context.constants c in constants.consensus_rights_delay +(** Adaptive Issuance activation delay: + After the e.m.a. of AI votes reaches the threshold, we wait for this delay + before effectively activating AI. +*) let adaptive_issuance_activation_delay c = let constants = Raw_context.constants c in 1 + constants.consensus_rights_delay + Constants_repr.max_slashing_period +(** Tolerated inactivity period for delegates before being deactivated. *) let tolerated_inactivity_period c = let constants = Raw_context.constants c in 1 + constants.consensus_rights_delay +(** Delay between consensus key declaration by the delegate and the cycle where + it has to be used to sign on behalf of the delegate. *) let consensus_key_activation_delay c = let constants = Raw_context.constants c in constants.consensus_rights_delay +(** Number of cycles during which a misbehavior of the delegate will induce a + slashing of the funds that are currently in its frozen deposits. *) let slashable_deposits_period c = let constants = Raw_context.constants c in constants.consensus_rights_delay diff --git a/src/proto_alpha/lib_protocol/constants_storage.mli b/src/proto_alpha/lib_protocol/constants_storage.mli index 23f71471d8f3..0c9ad1857919 100644 --- a/src/proto_alpha/lib_protocol/constants_storage.mli +++ b/src/proto_alpha/lib_protocol/constants_storage.mli @@ -165,14 +165,14 @@ val adaptive_issuance_ns_enable : Raw_context.t -> bool val direct_ticket_spending_enable : Raw_context.t -> bool -(** The following accessor are not actual parameters, but constants that - derives from the protocol parameter. *) +(** The following accessors are not actual parameters, but constants that + derive from the protocol parameter. *) -(** Delay in cycle before the current state of the stake impacts the +(** Delay, in cycles, before the current state of the stake impacts the issuance rate.*) val issuance_modification_delay : Raw_context.t -> int -(** Time in cycle before activation of AI after the voting EMA threshold is +(** Delay, in cycles, before activation of AI after the voting EMA threshold is reached *) val adaptive_issuance_activation_delay : Raw_context.t -> int @@ -183,6 +183,7 @@ val tolerated_inactivity_period : Raw_context.t -> int (** Delay before the activation of a consensus key, in cycles *) val consensus_key_activation_delay : Raw_context.t -> int -(** Period, in cycles, during which frozen tokens remain slashable after the - cycle of their deposit *) +(** Number of cycles during which a misbehavior of a delegate will induce a + slashing of the funds that are currently in its frozen deposit. *) + val slashable_deposits_period : Raw_context.t -> int -- GitLab From 9c56934de780849e7ab3bdf8ccc7656d87be16da Mon Sep 17 00:00:00 2001 From: Marina Polubelova Date: Tue, 6 Feb 2024 18:02:03 +0100 Subject: [PATCH 9/9] tezt/tests: fix tests consensus_rights_delay and preserved_cycles should be equal --- .../consensus/test_double_attestation.ml | 1 + tezt/tests/consensus_key.ml | 30 ++++++++++++------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/proto_alpha/lib_protocol/test/integration/consensus/test_double_attestation.ml b/src/proto_alpha/lib_protocol/test/integration/consensus/test_double_attestation.ml index 7d7e4c3f3641..12207188ba2c 100644 --- a/src/proto_alpha/lib_protocol/test/integration/consensus/test_double_attestation.ml +++ b/src/proto_alpha/lib_protocol/test/integration/consensus/test_double_attestation.ml @@ -711,6 +711,7 @@ let test_freeze_more_with_low_balance = consensus_threshold = 0; origination_size = 0; preserved_cycles = 5; + consensus_rights_delay = 5; percentage_of_frozen_deposits_slashed_per_double_attestation = (* enforce that percentage is 50% in the test's params. *) Percentage.p50; diff --git a/tezt/tests/consensus_key.ml b/tezt/tests/consensus_key.ml index 59a377105c5a..e6cc9e6d41f2 100644 --- a/tezt/tests/consensus_key.ml +++ b/tezt/tests/consensus_key.ml @@ -96,11 +96,16 @@ let test_update_consensus_key = let parameters = (* we update paramaters for faster testing: no need to wait 5 cycles for the consensus key to activate. *) - [ - (["blocks_per_cycle"], `Int blocks_per_cycle); - (["nonce_revelation_threshold"], `Int 2); - (["preserved_cycles"], `Int preserved_cycles); - ] + let p = + [ + (["blocks_per_cycle"], `Int blocks_per_cycle); + (["nonce_revelation_threshold"], `Int 2); + (["preserved_cycles"], `Int preserved_cycles); + ] + in + if Protocol.number protocol > Protocol.number Protocol.Oxford then + (["consensus_rights_delay"], `Int preserved_cycles) :: p + else p in let* parameter_file = Protocol.write_parameter_file ~base:(Right (protocol, None)) parameters @@ -625,11 +630,16 @@ let register ?(regression = true) title test = let parameters = (* we update paramaters for faster testing: no need to wait 5 cycles for the consensus key to activate. *) - [ - (["blocks_per_cycle"], `Int blocks_per_cycle); - (["nonce_revelation_threshold"], `Int 2); - (["preserved_cycles"], `Int preserved_cycles); - ] + let p = + [ + (["blocks_per_cycle"], `Int blocks_per_cycle); + (["nonce_revelation_threshold"], `Int 2); + (["preserved_cycles"], `Int preserved_cycles); + ] + in + if Protocol.number protocol > Protocol.number Protocol.Oxford then + (["consensus_rights_delay"], `Int preserved_cycles) :: p + else p in let* parameter_file = Protocol.write_parameter_file ~base:(Right (protocol, None)) parameters -- GitLab