From 9b979c41a20f701bf8dba79da61f334758153514 Mon Sep 17 00:00:00 2001 From: Julien Tesson Date: Thu, 7 Dec 2023 16:50:19 +0100 Subject: [PATCH 01/21] proto/adaptive_issuance_storage: remove useless qualified path --- src/proto_alpha/lib_protocol/adaptive_issuance_storage.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/proto_alpha/lib_protocol/adaptive_issuance_storage.ml b/src/proto_alpha/lib_protocol/adaptive_issuance_storage.ml index 23fb8d1ef4e1..38e5e37f0d91 100644 --- a/src/proto_alpha/lib_protocol/adaptive_issuance_storage.ml +++ b/src/proto_alpha/lib_protocol/adaptive_issuance_storage.ml @@ -293,7 +293,7 @@ let update_ema ctxt ~vote = let open Constants_storage in let+ ctxt, launch_cycle = if - (not (Constants_storage.adaptive_issuance_activation_vote_enable ctxt)) + (not (adaptive_issuance_activation_vote_enable ctxt)) || Per_block_votes_repr.Adaptive_issuance_launch_EMA.( new_ema < adaptive_issuance_launch_ema_threshold ctxt) then return (ctxt, launch_cycle) -- GitLab From 53dc50a646d92c8d1ae88bf941466d7a5aa79c7c Mon Sep 17 00:00:00 2001 From: Julien Tesson Date: Tue, 19 Dec 2023 09:45:38 +0100 Subject: [PATCH 02/21] tezt/tests: use blocks_preservation_cycles --- tezt/tests/bootstrap.ml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tezt/tests/bootstrap.ml b/tezt/tests/bootstrap.ml index b94998e4a081..02f0bf01a932 100644 --- a/tezt/tests/bootstrap.ml +++ b/tezt/tests/bootstrap.ml @@ -93,7 +93,7 @@ let check_bootstrap_with_history_modes hmode1 hmode2 = starts. - When the checkpoint is set, its level is [preserved_blocks = - preserved_cycles * blocks_per_cycle] behind the current level of + blocks_preservation_cycles * blocks_per_cycle] behind the current level of the head - When the [caboose] is set, its level is [max(0, (checkpoint - @@ -106,7 +106,7 @@ let check_bootstrap_with_history_modes hmode1 hmode2 = mod blocks_per_cycle] (the modulo 1 comes from the activation block). - In sandbox mode, we have [preserved_cycles = 2] and + In sandbox mode, we have [blocks_preservation_cycles = 2] and [blocks_per_cycle = 8]. Hence, when [node_1] has baked [49] blocks, the checkpoint should -- GitLab From 92c1de98dc1f43421279992642890fe395217519 Mon Sep 17 00:00:00 2001 From: Julien Tesson Date: Tue, 19 Dec 2023 21:03:47 +0100 Subject: [PATCH 03/21] shell_services/history_mode: change comment referencing preserved_cycles --- src/lib_shell_services/history_mode.ml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib_shell_services/history_mode.ml b/src/lib_shell_services/history_mode.ml index d8931e385a36..93189e6de0e7 100644 --- a/src/lib_shell_services/history_mode.ml +++ b/src/lib_shell_services/history_mode.ml @@ -42,9 +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 allowed fork level of the current - head, which is set to [preserved_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 e78560b979019e9ef509b25821fbb37cdb1deb91 Mon Sep 17 00:00:00 2001 From: Julien Tesson Date: Wed, 10 Jan 2024 21:24:06 +0100 Subject: [PATCH 04/21] proto: use consensus_rights_delay --- src/proto_alpha/lib_delegate/baking_nonces.ml | 10 ++++---- .../test/tenderbrute/lib/tenderbrute.ml | 4 ++-- .../lib_parameters/default_parameters.ml | 2 +- .../adaptive_issuance_services.mli | 2 +- .../lib_protocol/adaptive_issuance_storage.ml | 4 ++-- .../adaptive_issuance_storage.mli | 6 ++--- .../lib_protocol/alpha_context.mli | 8 +++---- .../lib_protocol/alpha_services.ml | 9 ++++--- .../delegate_activation_storage.ml | 13 +++++----- .../lib_protocol/delegate_consensus_key.ml | 2 +- .../lib_protocol/delegate_cycles.ml | 12 ++++++---- .../lib_protocol/delegate_cycles.mli | 2 +- .../lib_protocol/delegate_sampler.ml | 4 ++-- src/proto_alpha/lib_protocol/seed_storage.ml | 24 +++++++++---------- src/proto_alpha/lib_protocol/seed_storage.mli | 2 +- src/proto_alpha/lib_protocol/staking.ml | 2 +- src/proto_alpha/lib_protocol/staking.mli | 2 +- src/proto_alpha/lib_protocol/storage.mli | 8 +++---- .../unstaked_frozen_deposits_repr.mli | 4 ++-- .../unstaked_frozen_deposits_storage.mli | 2 +- 20 files changed, 63 insertions(+), 59 deletions(-) diff --git a/src/proto_alpha/lib_delegate/baking_nonces.ml b/src/proto_alpha/lib_delegate/baking_nonces.ml index 515e429e7505..56cd2e990f4c 100644 --- a/src/proto_alpha/lib_delegate/baking_nonces.ml +++ b/src/proto_alpha/lib_delegate/baking_nonces.ml @@ -119,7 +119,8 @@ let get_block_level_opt cctxt ~chain ~block = let get_outdated_nonces {cctxt; constants; chain; _} nonces = let open Lwt_result_syntax in - let {Constants.parametric = {blocks_per_cycle; preserved_cycles; _}; _} = + let {Constants.parametric = {blocks_per_cycle; consensus_rights_delay; _}; _} + = constants in let*! current_level = get_block_level_opt cctxt ~chain ~block:(`Head 0) in @@ -129,9 +130,10 @@ let get_outdated_nonces {cctxt; constants; chain; _} nonces = return (empty, empty) | Some current_level -> let current_cycle = Int32.(div current_level blocks_per_cycle) in - let is_older_than_preserved_cycles block_level = + let is_older_than_consensus_rights_delay block_level = let block_cycle = Int32.(div block_level blocks_per_cycle) in - Int32.sub current_cycle block_cycle > Int32.of_int preserved_cycles + Int32.sub current_cycle block_cycle + > Int32.of_int consensus_rights_delay in Block_hash.Map.fold (fun hash nonce acc -> @@ -141,7 +143,7 @@ let get_outdated_nonces {cctxt; constants; chain; _} nonces = in match level with | Some level -> - if is_older_than_preserved_cycles level then + if is_older_than_consensus_rights_delay level then return (orphans, add outdated hash nonce) else acc | None -> return (add orphans hash nonce, outdated)) diff --git a/src/proto_alpha/lib_delegate/test/tenderbrute/lib/tenderbrute.ml b/src/proto_alpha/lib_delegate/test/tenderbrute/lib/tenderbrute.ml index 3fa2f03dc6af..3feb1ddcf025 100644 --- a/src/proto_alpha/lib_delegate/test/tenderbrute/lib/tenderbrute.ml +++ b/src/proto_alpha/lib_delegate/test/tenderbrute/lib/tenderbrute.ml @@ -73,7 +73,7 @@ let init_context ?constants_overrides_json ?bootstrap_accounts_json parameters = function is always called after {!init_context}. *) let change_seed ?initial_seed ctxt = let open Lwt_result_syntax in - let preserved = Constants_storage.preserved_cycles ctxt in + let delay = Constants_storage.consensus_rights_delay ctxt in let+ (_ : int), ctxt = List.fold_left_es (fun (c, ctxt) seed -> @@ -82,7 +82,7 @@ let change_seed ?initial_seed ctxt = let+ ctxt = Storage.Seed.For_cycle.init ctxt cycle seed in (c + 1, ctxt)) (0, ctxt) - (Seed_repr.initial_seeds ?initial_seed (preserved + 2)) + (Seed_repr.initial_seeds ?initial_seed (delay + 2)) in ctxt diff --git a/src/proto_alpha/lib_parameters/default_parameters.ml b/src/proto_alpha/lib_parameters/default_parameters.ml index 1fd837f2dab9..71b10fa0a770 100644 --- a/src/proto_alpha/lib_parameters/default_parameters.ml +++ b/src/proto_alpha/lib_parameters/default_parameters.ml @@ -256,7 +256,7 @@ let constants_mainnet = chosen not too exceed 100 000 000 bytes. *) cache_script_size = 100_000_000; (* A cache for the stake distribution for all cycles stored at any - moment: preserved_cycles + max_slashing_period + 1 = 8 currently. *) + moment: consensus_rights_delay + max_slashing_period + 1 = 8 currently. *) cache_stake_distribution_cycles = 8; (* One for the sampler state for all cycles stored at any moment (as above). *) cache_sampler_state_cycles = 8; diff --git a/src/proto_alpha/lib_protocol/adaptive_issuance_services.mli b/src/proto_alpha/lib_protocol/adaptive_issuance_services.mli index 4f10608fc2d1..04c6c96b1072 100644 --- a/src/proto_alpha/lib_protocol/adaptive_issuance_services.mli +++ b/src/proto_alpha/lib_protocol/adaptive_issuance_services.mli @@ -58,7 +58,7 @@ val launch_cycle : 'a #RPC_context.simple -> 'a -> Cycle.t option shell_tzresult Lwt.t (** Returns the list of expected issued tez for the current cycle and for the next - [preserved_cycles] cycles. *) + [consensus_rights_delay] cycles. *) val expected_issuance : 'a #RPC_context.simple -> 'a -> expected_rewards list shell_tzresult Lwt.t diff --git a/src/proto_alpha/lib_protocol/adaptive_issuance_storage.ml b/src/proto_alpha/lib_protocol/adaptive_issuance_storage.ml index 38e5e37f0d91..72012dc4e5e9 100644 --- a/src/proto_alpha/lib_protocol/adaptive_issuance_storage.ml +++ b/src/proto_alpha/lib_protocol/adaptive_issuance_storage.ml @@ -40,8 +40,8 @@ let () = let open Data_encoding in let undetermined_issuance_coeff_for_cycle_description = "Issuance coefficient is only determined for the current cycle and the \ - next [preserved_cycles] cycles to come. Requested cycle is not in this \ - window." + next [consensus_rights_delay] cycles to come. Requested cycle is not in \ + this window." in register_error_kind `Permanent diff --git a/src/proto_alpha/lib_protocol/adaptive_issuance_storage.mli b/src/proto_alpha/lib_protocol/adaptive_issuance_storage.mli index 5305a216b73f..51da68de548c 100644 --- a/src/proto_alpha/lib_protocol/adaptive_issuance_storage.mli +++ b/src/proto_alpha/lib_protocol/adaptive_issuance_storage.mli @@ -36,7 +36,7 @@ val load_reward_coeff : Raw_context.t -> Raw_context.t tzresult Lwt.t (** [update_stored_rewards_at_cycle_end ctxt ~new_cycle] updates {!Storage.Issuance_coeff} with a new coefficient that will be applied - [preserved_cycles] cycles after the given [new_cycle]. This new coefficient + [consensus_rights_delay] cycles after the given [new_cycle]. This new coefficient depends on the current {!Storage.Total_supply}, and the total active stake for when this coefficient is computed. @@ -72,7 +72,7 @@ module For_RPC : sig from the storage. Fails if the given cycle is not between [current_cycle] and - [current_cycle + preserved_cycles]. + [current_cycle + consensus_rights_delay]. If adaptive issuance has not been activated, then this function returns [Q.one]. @@ -84,7 +84,7 @@ module For_RPC : sig from the storage. If [cycle] is [None], returns 0. Returns 0 if the given cycle is not between [current_cycle] and - [current_cycle + preserved_cycles]. + [current_cycle + consensus_rights_delay]. If adaptive issuance has not been activated, then this function returns 0. diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index e5e9609a1d7e..117173d0a17a 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -2326,9 +2326,9 @@ module Delegate : sig (** [get_reward_coeff ctxt cycle] reads the reward coeff for the given cycle from the storage. Returns [Q.one] if the given cycle is not between [current_cycle] and - [current_cycle + preserved_cycles]. + [current_cycle + consensus_rights_delay]. If adaptive issuance has not been activated, or has been activated and the - given cycle is less than [preserved_cycles] after the activation cycle, + given cycle is less than [consensus_rights_delay] after the activation cycle, then this function returns [Q.one]. Used only for RPCs. To get the actual rewards, use the reward functions defined above. *) @@ -2338,7 +2338,7 @@ module Delegate : sig from the storage. If cycle is [None], returns 0. Returns 0 if the given cycle is not between [current_cycle] and - [current_cycle + preserved_cycles]. + [current_cycle + consensus_rights_delay]. If adaptive issuance has not been activated, then this function returns 0. @@ -2462,7 +2462,7 @@ module Staking : sig requests from [contract] that can be finalized. An unstake request can be finalized if it is old enough, specifically the requested amount must not be at stake anymore and must not be slashable - anymore, i.e. after [preserved_cycles + max_slashing_period] after the + anymore, i.e. after [consensus_rights_delay + max_slashing_period] after the request. Amounts are transferred from the [contract]'s delegate (at request time) unstaked frozen deposits to [contract]'s spendable balance, minus slashing diff --git a/src/proto_alpha/lib_protocol/alpha_services.ml b/src/proto_alpha/lib_protocol/alpha_services.ml index b7b33e8b7bf8..6c8b2a14cc46 100644 --- a/src/proto_alpha/lib_protocol/alpha_services.ml +++ b/src/proto_alpha/lib_protocol/alpha_services.ml @@ -191,19 +191,18 @@ module Snapshot_index = struct Alpha_context.Constants.blocks_per_stake_snapshot ctxt in let blocks_per_cycle = Alpha_context.Constants.blocks_per_cycle ctxt in - let preserved_cycles = - Int32.of_int (Alpha_context.Constants.preserved_cycles ctxt) + let cycles_delay = + Int32.of_int (Alpha_context.Constants.consensus_rights_delay ctxt) in let cycle = match cycle with | None -> Level.(current ctxt).cycle | Some cycle -> cycle in - if Compare.Int32.(Cycle.to_int32 cycle <= Int32.succ preserved_cycles) - then + if Compare.Int32.(Cycle.to_int32 cycle <= Int32.succ cycles_delay) then (* Early cycles are corner cases, fail if requested *) tzfail - (No_available_snapshots {min_cycle = Int32.add preserved_cycles 2l}) + (No_available_snapshots {min_cycle = Int32.add cycles_delay 2l}) else let max_snapshot_index = Int32.div blocks_per_cycle blocks_per_stake_snapshot |> Int32.to_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..0c635597ca2f 100644 --- a/src/proto_alpha/lib_protocol/delegate_activation_storage.ml +++ b/src/proto_alpha/lib_protocol/delegate_activation_storage.ml @@ -59,13 +59,13 @@ 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 preserved_cycles = Constants_storage.preserved_cycles ctxt in + let consensus_rights_delay = Constants_storage.consensus_rights_delay 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 `1 + consensus_rights_delay` 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. *) + `consensus_rights_delay` because the delegate needs this number of cycles to + receive rights, so `1 + 2 * consensus_rights_delay` 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 +74,11 @@ 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 (2 * consensus_rights_delay) | Some current_last_active_cycle -> let delay = - if inactive then 1 + (2 * preserved_cycles) else 1 + preserved_cycles + if inactive then 1 + (2 * consensus_rights_delay) + else 1 + consensus_rights_delay in let updated = Cycle_repr.add current_cycle delay in Cycle_repr.max current_last_active_cycle updated diff --git a/src/proto_alpha/lib_protocol/delegate_consensus_key.ml b/src/proto_alpha/lib_protocol/delegate_consensus_key.ml index 495293c7d760..259c38927a4f 100644 --- a/src/proto_alpha/lib_protocol/delegate_consensus_key.ml +++ b/src/proto_alpha/lib_protocol/delegate_consensus_key.ml @@ -104,7 +104,7 @@ let pp ppf {delegate; consensus_pkh} = No two delegates use the same active consensus key at a given time. To ensure that, {!Storage.Consensus_keys} contains keys that will be active - at cycle `current + preserved_cycles + 1`. + at cycle `current + consensus_rights_delay + 1`. *) let check_unused ctxt pkh = diff --git a/src/proto_alpha/lib_protocol/delegate_cycles.ml b/src/proto_alpha/lib_protocol/delegate_cycles.ml index 94510caa4530..3c31e6eacdfe 100644 --- a/src/proto_alpha/lib_protocol/delegate_cycles.ml +++ b/src/proto_alpha/lib_protocol/delegate_cycles.ml @@ -27,9 +27,11 @@ let update_activity ctxt last_cycle = let open Lwt_result_syntax in - let preserved = Constants_storage.preserved_cycles ctxt in - match Cycle_repr.sub last_cycle preserved with - | None -> return (ctxt, []) + let rights_delay = Constants_storage.consensus_rights_delay ctxt in + match Cycle_repr.sub last_cycle rights_delay with + | None -> + (* do not update activity in the first cycles of a network.*) + return (ctxt, []) | Some _unfrozen_cycle -> Stake_storage.fold_on_active_delegates_with_minimal_stake_s ctxt @@ -229,7 +231,7 @@ let cycle_end ctxt last_cycle = let init_first_cycles ctxt = let open Lwt_result_syntax in - let preserved = Constants_storage.preserved_cycles ctxt in + let consensus_rights_delay = Constants_storage.consensus_rights_delay ctxt in List.fold_left_es (fun ctxt c -> let cycle = Cycle_repr.of_int32_exn (Int32.of_int c) in @@ -241,4 +243,4 @@ let init_first_cycles ctxt = ~slashings:Signature.Public_key_hash.Map.empty cycle) ctxt - Misc.(0 --> preserved) + Misc.(0 --> consensus_rights_delay) diff --git a/src/proto_alpha/lib_protocol/delegate_cycles.mli b/src/proto_alpha/lib_protocol/delegate_cycles.mli index a28d60bcdd0a..c1ae98330556 100644 --- a/src/proto_alpha/lib_protocol/delegate_cycles.mli +++ b/src/proto_alpha/lib_protocol/delegate_cycles.mli @@ -43,6 +43,6 @@ val cycle_end : (** [init_first_cycles ctxt] computes and records the distribution of the total active stake among active delegates. This concerns the total active stake involved in the calculation of baking rights for all cycles - in the range [0, preserved_cycles]. It also freezes the deposits for all + in the range [0, consensus_rights_delay]. It also freezes the deposits for all the active delegates. *) val init_first_cycles : Raw_context.t -> Raw_context.t tzresult Lwt.t diff --git a/src/proto_alpha/lib_protocol/delegate_sampler.ml b/src/proto_alpha/lib_protocol/delegate_sampler.ml index 9ea36b58ec1c..3a27129a7fda 100644 --- a/src/proto_alpha/lib_protocol/delegate_sampler.ml +++ b/src/proto_alpha/lib_protocol/delegate_sampler.ml @@ -244,8 +244,8 @@ let select_distribution_for_cycle ctxt ~slashings cycle = Lwt.return (Raw_context.init_sampler_for_cycle ctxt cycle seed state) let select_new_distribution_at_cycle_end ctxt ~slashings ~new_cycle = - let preserved = Constants_storage.preserved_cycles ctxt in - let for_cycle = Cycle_repr.add new_cycle preserved in + let consensus_rights_delay = Constants_storage.consensus_rights_delay ctxt in + let for_cycle = Cycle_repr.add new_cycle consensus_rights_delay in select_distribution_for_cycle ctxt ~slashings for_cycle let clear_outdated_sampling_data ctxt ~new_cycle = diff --git a/src/proto_alpha/lib_protocol/seed_storage.ml b/src/proto_alpha/lib_protocol/seed_storage.ml index 978929d90b32..9409d20883cd 100644 --- a/src/proto_alpha/lib_protocol/seed_storage.ml +++ b/src/proto_alpha/lib_protocol/seed_storage.ml @@ -123,8 +123,8 @@ let purge_nonces_and_get_unrevealed ctxt ~cycle = let compute_randao ctxt = let open Lwt_result_syntax in let current_cycle = (Level_storage.current ctxt).cycle in - let preserved = Constants_storage.preserved_cycles ctxt in - let cycle_computed = Cycle_repr.add current_cycle (preserved + 1) in + let delay = Constants_storage.consensus_rights_delay ctxt in + let cycle_computed = Cycle_repr.add current_cycle (delay + 1) in let*! seed_computed = Storage.Seed.For_cycle.mem ctxt cycle_computed in (* Check if seed has already been computed, and not in cycle 0. *) match Cycle_repr.(pred current_cycle, pred cycle_computed) with @@ -160,9 +160,9 @@ let get_seed_computation_status ctxt = let* status = Storage.Seed.get_status ctxt in match status with | RANDAO_seed -> - let preserved = Constants_storage.preserved_cycles ctxt in - let cycle_computed = Cycle_repr.add current_cycle (preserved + 1) in - let previous_cycle = Cycle_repr.add current_cycle preserved in + let delay = Constants_storage.consensus_rights_delay ctxt in + let cycle_computed = Cycle_repr.add current_cycle (delay + 1) in + let previous_cycle = Cycle_repr.add current_cycle delay in let* seed_discriminant = Storage.Seed.For_cycle.get ctxt previous_cycle in @@ -207,8 +207,8 @@ let update_seed ctxt vdf_solution = (* compute and update seed and change seed status from RANDAO to VDF *) let current_cycle = (Level_storage.current ctxt).cycle in - let preserved = Constants_storage.preserved_cycles ctxt in - let cycle_computed = Cycle_repr.add current_cycle (preserved + 1) in + let delay = Constants_storage.consensus_rights_delay ctxt in + let cycle_computed = Cycle_repr.add current_cycle (delay + 1) in let* seed_challenge = Storage.Seed.For_cycle.get ctxt cycle_computed in let new_seed = Seed_repr.vdf_to_seed seed_challenge vdf_solution in Storage.Seed.For_cycle.update ctxt cycle_computed new_seed Seed_repr.VDF_seed @@ -217,13 +217,13 @@ let raw_for_cycle = Storage.Seed.For_cycle.get let for_cycle ctxt cycle = let open Lwt_result_syntax in - let preserved = Constants_storage.preserved_cycles ctxt in + let delay = Constants_storage.consensus_rights_delay ctxt in let max_slashing_period = Constants_repr.max_slashing_period in let current_cycle = (Level_storage.current ctxt).cycle in let latest = if Cycle_repr.(current_cycle = root) then - Cycle_repr.add current_cycle (preserved + 1) - else Cycle_repr.add current_cycle preserved + Cycle_repr.add current_cycle (delay + 1) + else Cycle_repr.add current_cycle delay in let oldest = match Cycle_repr.sub current_cycle (max_slashing_period - 1) with @@ -239,7 +239,7 @@ let for_cycle ctxt cycle = let init ?initial_seed ctxt = let open Lwt_result_syntax in - let preserved = Constants_storage.preserved_cycles ctxt in + let delay = Constants_storage.consensus_rights_delay ctxt in let* ctxt = Storage.Seed_status.init ctxt Seed_repr.RANDAO_seed in let+ (_ : int), ctxt = List.fold_left_es @@ -248,7 +248,7 @@ let init ?initial_seed ctxt = let+ ctxt = Storage.Seed.For_cycle.init ctxt cycle seed in (c + 1, ctxt)) (0, ctxt) - (Seed_repr.initial_seeds ?initial_seed (preserved + 2)) + (Seed_repr.initial_seeds ?initial_seed (delay + 2)) in ctxt diff --git a/src/proto_alpha/lib_protocol/seed_storage.mli b/src/proto_alpha/lib_protocol/seed_storage.mli index 05bfce77d2ac..f99b047eb9e9 100644 --- a/src/proto_alpha/lib_protocol/seed_storage.mli +++ b/src/proto_alpha/lib_protocol/seed_storage.mli @@ -47,7 +47,7 @@ type error += | Unverified_vdf | Too_early_revelation -(** Generates the first [preserved_cycles+2] seeds for which +(** Generates the first [consensus_rights_delay+2] seeds for which there are no nonces. *) val init : ?initial_seed:State_hash.t -> Raw_context.t -> Raw_context.t tzresult Lwt.t diff --git a/src/proto_alpha/lib_protocol/staking.ml b/src/proto_alpha/lib_protocol/staking.ml index 8e7800a6959d..5d8c959e11f5 100644 --- a/src/proto_alpha/lib_protocol/staking.ml +++ b/src/proto_alpha/lib_protocol/staking.ml @@ -31,7 +31,7 @@ let () = let description = "A contract tries to stake to its delegate while having unstake requests \ to a previous delegate that cannot be finalized yet. Try again in a later \ - cycle (no more than preserved_cycles + max_slashing_period)." + cycle (no more than consensus_rights_delay + max_slashing_period)." in register_error_kind `Permanent diff --git a/src/proto_alpha/lib_protocol/staking.mli b/src/proto_alpha/lib_protocol/staking.mli index e7ab0f8c340e..e3b6925fae18 100644 --- a/src/proto_alpha/lib_protocol/staking.mli +++ b/src/proto_alpha/lib_protocol/staking.mli @@ -58,7 +58,7 @@ val request_unstake : be finalized. An unstake request can be finalized if it is old enough, specifically the requested amount must not be at stake anymore and must not be slashable - anymore, i.e. after [preserved_cycles + max_slashing_period] after the + anymore, i.e. after [consensus_rights_delay + max_slashing_period] after the request. Amounts are transferred from the [contract]'s delegate (at request time) unstaked frozen deposits to [contract]'s spendable balance, minus slashing diff --git a/src/proto_alpha/lib_protocol/storage.mli b/src/proto_alpha/lib_protocol/storage.mli index 54319f6a6d59..f601b557e852 100644 --- a/src/proto_alpha/lib_protocol/storage.mli +++ b/src/proto_alpha/lib_protocol/storage.mli @@ -174,9 +174,9 @@ module Contract : sig [staked_frozen] in {!Staking_balance}) but have been requested to be unstaked by a staker. They won't be part of the stake for future distributions. - For cycles [current_cycle - preserved_cycles - max_slashing_period + 1] to + For cycles [current_cycle - consensus_rights_delay - max_slashing_period + 1] to [current_cycle] they are still slashable. - For cycle [current_cycle - preserved_cycles - max_slashing_period] they are + For cycle [current_cycle - consensus_rights_delay - max_slashing_period] they are not slashable anymore and hence any other older cycles must be squashed into this one at cycle end. *) module Unstaked_frozen_deposits : @@ -208,7 +208,7 @@ module Contract : sig and type t := Raw_context.t (** If there is a value, the frozen balance for the contract won't - exceed it (starting in preserved_cycles + 1). *) + exceed it (starting in consensus_rights_delay + 1). *) module Frozen_deposits_limit : Indexed_data_storage with type key = Contract_repr.t @@ -452,7 +452,7 @@ module Delegates : with type t := Raw_context.t and type elt = Signature.Public_key_hash.t -(** Set of all active consensus keys in cycle `current + preserved_cycles + 1` *) +(** Set of all active consensus keys in cycle `current + consensus_rights_delay + 1` *) module Consensus_keys : Data_set_storage with type t := Raw_context.t diff --git a/src/proto_alpha/lib_protocol/unstaked_frozen_deposits_repr.mli b/src/proto_alpha/lib_protocol/unstaked_frozen_deposits_repr.mli index e37cb2756021..3e0f889edee8 100644 --- a/src/proto_alpha/lib_protocol/unstaked_frozen_deposits_repr.mli +++ b/src/proto_alpha/lib_protocol/unstaked_frozen_deposits_repr.mli @@ -25,9 +25,9 @@ (** Datatype for a map from cycle to deposits, where all unslashable cycles are squashed. - + Expected to be used for a small number of cycles at a time, typically - bounded by [preserved_cycles + max_slashing_period] plus a small constant. + bounded by [consensus_rights_delay + max_slashing_period] plus a small constant. See {!Unstaked_frozen_deposits_storage} for more info on unstaked frozen deposits. diff --git a/src/proto_alpha/lib_protocol/unstaked_frozen_deposits_storage.mli b/src/proto_alpha/lib_protocol/unstaked_frozen_deposits_storage.mli index b7da51a8c69e..a1a622059d12 100644 --- a/src/proto_alpha/lib_protocol/unstaked_frozen_deposits_storage.mli +++ b/src/proto_alpha/lib_protocol/unstaked_frozen_deposits_storage.mli @@ -32,7 +32,7 @@ - when a delegator changes delegate. The amounts are attached to a given cycle, the cycle at which the unstake happened, and are slashable for another - [preserved_cycles + max_slashing_period - 1] cycles. After this, they can be + [consensus_rights_delay + max_slashing_period - 1] cycles. After this, they can be finalized either with the "finalize_unstake" pseudo-operation, via auto-staking (for bakers only), or when staking or unstaking. -- GitLab From 1ac4e6f5855dacf14305c81237368a92d0e3b8ca Mon Sep 17 00:00:00 2001 From: Julien Tesson Date: Tue, 19 Dec 2023 09:46:45 +0100 Subject: [PATCH 05/21] tezt/tests: use consensus_rights_delay --- tezt/tests/consensus_key.ml | 38 +++++++++++++++++++------------- tezt/tests/dal.ml | 10 ++++++--- tezt/tests/protocol_migration.ml | 9 ++++++-- 3 files changed, 37 insertions(+), 20 deletions(-) diff --git a/tezt/tests/consensus_key.ml b/tezt/tests/consensus_key.ml index 59a377105c5a..d36f20298a8e 100644 --- a/tezt/tests/consensus_key.ml +++ b/tezt/tests/consensus_key.ml @@ -36,7 +36,7 @@ let hooks = Tezos_regression.hooks let blocks_per_cycle = 4 -let preserved_cycles = 1 +let consensus_rights_delay = 1 let manual_staking (_ : Protocol.t) = (* Currently all protocols use autostaking by default; this will @@ -99,7 +99,7 @@ let test_update_consensus_key = [ (["blocks_per_cycle"], `Int blocks_per_cycle); (["nonce_revelation_threshold"], `Int 2); - (["preserved_cycles"], `Int preserved_cycles); + (["consensus_rights_delay"], `Int consensus_rights_delay); ] in let* parameter_file = @@ -215,7 +215,10 @@ let test_update_consensus_key = Log.info "Bake until the end of the next cycle with bootstrap1..." ; let* () = - bake_n_cycles preserved_cycles ~keys:[Constant.bootstrap1.alias] client + bake_n_cycles + consensus_rights_delay + ~keys:[Constant.bootstrap1.alias] + client in Log.info "Bootstrap1 should not be able to bake anymore..." ; @@ -238,7 +241,10 @@ let test_update_consensus_key = Log.info "Bake until the end of the next cycle, again." ; let* () = - bake_n_cycles preserved_cycles ~keys:[Constant.bootstrap2.alias] client + bake_n_cycles + consensus_rights_delay + ~keys:[Constant.bootstrap2.alias] + client in Log.info "`key_c` is now able to bake as well." ; @@ -256,7 +262,9 @@ let test_update_consensus_key = in Log.info "Bake until the end of the next cycle..." ; - let* () = bake_n_cycles (preserved_cycles + 1) ~keys:[key_a.alias] client in + let* () = + bake_n_cycles (consensus_rights_delay + 1) ~keys:[key_a.alias] client + in Log.info "We are not able to bake with `key_a` nor `key_c` anymore..." ; let* () = Client.bake_for ~expect_failure:true ~keys:[key_a.alias] client in @@ -285,7 +293,7 @@ let test_update_consensus_key = Log.info "Bake until the end of the next cycle..." ; let* () = bake_n_cycles - (preserved_cycles + 1) + (consensus_rights_delay + 1) ~keys:[Constant.bootstrap1.alias] client in @@ -469,7 +477,7 @@ let update_consensus_key ?(expect_failure = false) Client.RPC.call ~hooks client @@ RPC.get_chain_block_context_delegate src.public_key_hash in - let* () = bake_n_cycles (preserved_cycles + 1) client in + let* () = bake_n_cycles (consensus_rights_delay + 1) client in let* _ = Client.RPC.call ~hooks client @@ RPC.get_chain_block_context_delegate src.public_key_hash @@ -479,7 +487,7 @@ let update_consensus_key ?(expect_failure = false) let test_consensus_key_update ?(expect_failure = false) ?(baker = Constant.bootstrap1.alias) ~(src : Account.key) ~(consensus_key : Account.key) client = - (* Update the consensus key and go past [preserved_cycles + 1] *) + (* Update the consensus key and go past [consensus_rights_delay + 1] *) let* () = update_consensus_key ~expect_failure ~baker ~src ~consensus_key client in @@ -593,7 +601,7 @@ let register_key_as_delegate ?(expect_failure = false) in (* Wait for consensus key to be active *) - let* () = bake_n_cycles preserved_cycles client in + let* () = bake_n_cycles consensus_rights_delay client in let* _ = Client.RPC.call ~hooks client @@ RPC.get_chain_block_context_delegate owner.public_key_hash @@ -628,7 +636,7 @@ let register ?(regression = true) title test = [ (["blocks_per_cycle"], `Int blocks_per_cycle); (["nonce_revelation_threshold"], `Int 2); - (["preserved_cycles"], `Int preserved_cycles); + (["consensus_rights_delay"], `Int consensus_rights_delay); ] in let* parameter_file = @@ -682,7 +690,7 @@ let test_register_delegate_with_consensus_key ~manual_staking in Log.info "Bake until the end of the next cycle with `baker`..." ; - bake_n_cycles (preserved_cycles + 1) ~keys:[baker] client) + bake_n_cycles (consensus_rights_delay + 1) ~keys:[baker] client) else return () in @@ -708,7 +716,7 @@ let register_key_as_delegate_no_reg ?(baker = Constant.bootstrap1.alias) ~__LOC__ owner ~expected_pending: - [(level_information.cycle + preserved_cycles + 1, consensus_key)] + [(level_information.cycle + consensus_rights_delay + 1, consensus_key)] client in @@ -730,7 +738,7 @@ let register_key_as_delegate_no_reg ?(baker = Constant.bootstrap1.alias) in (* Wait for consensus key to be active *) - let* () = bake_n_cycles preserved_cycles client in + let* () = bake_n_cycles consensus_rights_delay client in let* () = check_consensus_key ~__LOC__ owner ~expected_active:consensus_key client in @@ -757,10 +765,10 @@ let update_consensus_key_no_reg ?(baker = Constant.bootstrap1.alias) src ~expected_active ~expected_pending: - [(level_information.cycle + preserved_cycles + 1, consensus_key)] + [(level_information.cycle + consensus_rights_delay + 1, consensus_key)] client in - let* () = bake_n_cycles (preserved_cycles + 1) client in + let* () = bake_n_cycles (consensus_rights_delay + 1) client in check_consensus_key ~__LOC__ consensus_key diff --git a/tezt/tests/dal.ml b/tezt/tests/dal.ml index 178a92f9f977..ee88ae475b91 100644 --- a/tezt/tests/dal.ml +++ b/tezt/tests/dal.ml @@ -956,7 +956,7 @@ let test_slots_attestation_operation_behavior _protocol parameters cryptobox [List.hd] on an empty list), though care was taken to avoid this as much as possible, as it is a bit hard to make sure an attester is in the TB committee but not in the DAL committee).*) -let test_slots_attestation_operation_dal_committee_membership_check _protocol +let test_slots_attestation_operation_dal_committee_membership_check protocol parameters _cryptobox node client _bootstrap_key = (* The attestation from the bootstrap account should succeed as the bootstrap node has sufficient stake to be in the DAL committee. *) @@ -975,7 +975,11 @@ let test_slots_attestation_operation_dal_committee_membership_check _protocol let* proto_params = Node.RPC.call node @@ RPC.get_chain_block_context_constants () in - let preserved_cycles = JSON.(proto_params |-> "preserved_cycles" |> as_int) in + let consensus_rights_delay = + if Protocol.number protocol > Protocol.number Protocol.Oxford then + JSON.(proto_params |-> "consensus_rights_delay" |> as_int) + else JSON.(proto_params |-> "preserved_cycles" |> as_int) + in let blocks_per_cycle = JSON.(proto_params |-> "blocks_per_cycle" |> as_int) in let blocks_per_epoch = parameters.Dal.Parameters.blocks_per_epoch in (* With [consensus_committee_size = 1024] slots in total, the new baker should @@ -998,7 +1002,7 @@ let test_slots_attestation_operation_dal_committee_membership_check _protocol let* () = bake_for client in let* () = Client.register_key new_account.alias client in let* () = bake_for client in - let num_cycles = 2 + preserved_cycles in + let num_cycles = 2 + consensus_rights_delay in Log.info "Bake for %d cycles for %s to be a baker" num_cycles diff --git a/tezt/tests/protocol_migration.ml b/tezt/tests/protocol_migration.ml index 20012152fd76..fa1636a41814 100644 --- a/tezt/tests/protocol_migration.ml +++ b/tezt/tests/protocol_migration.ml @@ -129,7 +129,11 @@ let perform_protocol_migration ?node_name ?client_name ~blocks_per_cycle let test_migration_for_whole_cycle ~migrate_from ~migrate_to = let parameters = JSON.parse_file (Protocol.parameter_file migrate_to) in let blocks_per_cycle = JSON.(get "blocks_per_cycle" parameters |> as_int) in - let preserved_cycles = JSON.(get "preserved_cycles" parameters |> as_int) in + let consensus_rights_delay = + if Protocol.number migrate_to > Protocol.number Protocol.Oxford then + JSON.(get "consensus_rights_delay" parameters |> as_int) + else JSON.(get "preserved_cycles" parameters |> as_int) + in for migration_level = blocks_per_cycle to 2 * blocks_per_cycle do Test.register ~__FILE__ @@ -142,7 +146,8 @@ let test_migration_for_whole_cycle ~migrate_from ~migrate_to = ~migration_level ~migrate_from ~migrate_to - ~baked_blocks_after_migration:(2 * preserved_cycles * blocks_per_cycle) + ~baked_blocks_after_migration: + (2 * consensus_rights_delay * blocks_per_cycle) () in unit -- GitLab From 42d72ca201e67b612d60dae0886c8a70c3cd9834 Mon Sep 17 00:00:00 2001 From: Julien Tesson Date: Wed, 13 Dec 2023 22:18:53 +0100 Subject: [PATCH 06/21] proto/tests: use consensus_rights_delay in tests --- .../test/helpers/adaptive_issuance_helpers.ml | 18 +++++---- .../consensus/test_consensus_key.ml | 2 +- .../consensus/test_deactivation.ml | 6 +-- .../consensus/test_double_attestation.ml | 10 ++--- .../consensus/test_frozen_deposits.ml | 34 +++++++++-------- .../test/integration/consensus/test_seed.ml | 4 +- .../integration/operations/test_voting.ml | 2 +- .../test_adaptive_issuance_launch.ml | 7 ++-- .../test_adaptive_issuance_roundtrip.ml | 37 ++++++++++--------- .../validate/generator_descriptors.ml | 5 ++- .../test/unit/test_consensus_key.ml | 2 +- 11 files changed, 67 insertions(+), 60 deletions(-) diff --git a/src/proto_alpha/lib_protocol/test/helpers/adaptive_issuance_helpers.ml b/src/proto_alpha/lib_protocol/test/helpers/adaptive_issuance_helpers.ml index c4c97f770f24..7fd753ec58b7 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/adaptive_issuance_helpers.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/adaptive_issuance_helpers.ml @@ -397,7 +397,7 @@ module Unstaked_frozen = struct let info, rest = pop_cycle cycle t in (info, h :: rest) - let slash ~preserved_cycles slashed_cycle pct_times_100 a = + let slash ~slashable_deposits_period slashed_cycle pct_times_100 a = remove_zeros a |> List.map (fun @@ -407,7 +407,7 @@ module Unstaked_frozen = struct if Cycle.( cycle > slashed_cycle - || add cycle preserved_cycles < slashed_cycle) + || add cycle slashable_deposits_period < slashed_cycle) then (r, Tez.zero) else let new_current = @@ -814,13 +814,13 @@ let apply_transfer amount src_name dst_name account_map = update_account ~f:f_dst dst_name account_map | _ -> raise Not_found -let stake_from_unstake amount current_cycle preserved_cycles delegate_name +let stake_from_unstake amount current_cycle consensus_rights_delay delegate_name account_map = match String.Map.find delegate_name account_map with | None -> raise Not_found | Some ({unstaked_frozen; frozen_deposits; slashed_cycles; _} as account) -> let oldest_slashable_cycle = - Cycle.(sub current_cycle (preserved_cycles + 1)) + Cycle.(sub current_cycle (consensus_rights_delay + 1)) |> Option.value ~default:Cycle.root in if @@ -864,7 +864,8 @@ let stake_from_unstake amount current_cycle preserved_cycles delegate_name in (account_map, rem_amount) -let apply_stake amount current_cycle preserved_cycles staker_name account_map = +let apply_stake amount current_cycle consensus_rights_delay staker_name + account_map = match String.Map.find staker_name account_map with | None -> raise Not_found | Some staker -> ( @@ -879,7 +880,7 @@ let apply_stake amount current_cycle preserved_cycles staker_name account_map = stake_from_unstake amount current_cycle - preserved_cycles + consensus_rights_delay staker_name account_map else (account_map, amount) @@ -1088,7 +1089,7 @@ let apply_slashing in let unstaked_frozen, slashed_unstaked = Unstaked_frozen.slash - ~preserved_cycles:constants.preserved_cycles + ~slashable_deposits_period:constants.consensus_rights_delay slashed_cycle (slashed_pct :> int) unstaked_frozen @@ -1127,7 +1128,8 @@ let apply_slashing in (account_map, actual_total_burnt_amount) -(* Given cycle is the cycle for which the rights are computed, usually current + preserved cycles *) +(* Given cycle is the cycle for which the rights are computed, usually current + + consensus rights delay *) let update_frozen_rights_cycle cycle account_map = String.Map.map (fun ({frozen_deposits; frozen_rights; _} as acc) -> diff --git a/src/proto_alpha/lib_protocol/test/integration/consensus/test_consensus_key.ml b/src/proto_alpha/lib_protocol/test/integration/consensus/test_consensus_key.ml index b32653e0f9d8..bb80ffdd5de6 100644 --- a/src/proto_alpha/lib_protocol/test/integration/consensus/test_consensus_key.ml +++ b/src/proto_alpha/lib_protocol/test/integration/consensus/test_consensus_key.ml @@ -77,7 +77,7 @@ let check_delegate_staking_invariant blk delegate_pkh = let update_consensus_key blk delegate public_key = let open Lwt_result_syntax in - let nb_delay_cycles = constants.preserved_cycles + 1 in + let nb_delay_cycles = constants.consensus_rights_delay + 1 in let* update_ck = Op.update_consensus_key (B blk) (Contract.Implicit delegate) public_key in diff --git a/src/proto_alpha/lib_protocol/test/integration/consensus/test_deactivation.ml b/src/proto_alpha/lib_protocol/test/integration/consensus/test_deactivation.ml index f340de730bb0..6ed7a0b5c937 100644 --- a/src/proto_alpha/lib_protocol/test/integration/consensus/test_deactivation.ml +++ b/src/proto_alpha/lib_protocol/test/integration/consensus/test_deactivation.ml @@ -168,7 +168,7 @@ let test_deactivation_then_bake () = b deactivated_account -(** check that an account which is deactivated for [preserved_cycles] cannot be +(** check that an account which is deactivated for [consensus_rights_delay] cannot be part of a committee *) let test_a_really_deactivated_account_is_not_in_the_committee () = let open Lwt_result_syntax in @@ -179,12 +179,12 @@ let test_a_really_deactivated_account_is_not_in_the_committee () = in (* at this point, the deactivated account can either bake (because it still has rights) and become active again, or, in case it is inactive for another - [preserved_cycles], it has no more rights, thus cannot be part of the + [consensus_rights_delay], it has no more rights, thus cannot be part of the committee. *) let constants = Default_parameters.constants_test in let* b = Block.bake_until_n_cycle_end - (constants.preserved_cycles + 1) + (constants.consensus_rights_delay + 1) ~policy:(By_account m2.pkh) b in 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 110f98d24122..0cf9e1a8b0ce 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 @@ -706,7 +706,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. *) Int_percentage.p50; @@ -828,20 +828,20 @@ let test_freeze_more_with_low_balance = let* () = Assert.equal_tez ~loc:__LOC__ info6.current_frozen_deposits Tez.zero in - (* We bake [2 * preserved_cycles - 1] additional cycles only with [account2]. + (* We bake [2 * consensus_rights_delay - 1] additional cycles only with [account2]. Because [account1] does not bake during this period, it loses its rights. *) let* d1 = Block.bake_until_n_cycle_end ~policy:(By_account account2) - ((2 * constants.preserved_cycles) - 1) + ((2 * constants.consensus_rights_delay) - 1) c3 in let* info7 = Context.Delegate.info (B d1) account1 in - (* [account1] is only deactivated after 1 + [2 * preserved_cycles] (see + (* [account1] is only deactivated after 1 + [2 * consensus_rights_delay] (see [Delegate_activation_storage.set_active] since the last time it was active, that is, since the first cycle. Thus the cycle at which - [account1] is deactivated is 2 + [2 * preserved_cycles] from genesis. *) + [account1] is deactivated is 2 + [2 * consensus_rights_delay] from genesis. *) let* () = Assert.equal_bool ~loc:__LOC__ info7.deactivated false in (* account1 is still active, but has no rights. *) let* () = check_unique_attester d1 account2 in diff --git a/src/proto_alpha/lib_protocol/test/integration/consensus/test_frozen_deposits.ml b/src/proto_alpha/lib_protocol/test/integration/consensus/test_frozen_deposits.ml index f888b375669e..2f095db4db9e 100644 --- a/src/proto_alpha/lib_protocol/test/integration/consensus/test_frozen_deposits.ml +++ b/src/proto_alpha/lib_protocol/test/integration/consensus/test_frozen_deposits.ml @@ -60,7 +60,7 @@ let get_first_2_accounts_contracts (a1, a2) = balance; it is computed in [Delegate_sampler.select_distribution_for_cycle] - frozen deposits = represents frozen_deposits_percentage of the maximum stake during - preserved_cycles + max_slashing_period cycles; obtained with + consensus_rights_delay + max_slashing_period cycles; obtained with Delegate.current_frozen_deposits - spendable balance = full balance - frozen deposits; obtained with Contract.balance @@ -250,7 +250,7 @@ let test_limit_with_overdelegation () = Assert.equal_tez ~loc:__LOC__ frozen_deposits expected_new_frozen_deposits in let cycles_to_bake = - 2 * (constants.preserved_cycles + Constants.max_slashing_period) + 2 * (constants.consensus_rights_delay + Constants.max_slashing_period) in let rec loop b n = if n = 0 then return b @@ -484,7 +484,7 @@ let test_cannot_bake_with_zero_deposits_limit () = in let* b = Block.bake ~policy:(By_account account2) ~operation genesis in let expected_number_of_cycles_with_rights_from_previous_deposit = - constants.preserved_cycles + Constants.max_slashing_period - 1 + constants.consensus_rights_delay + Constants.max_slashing_period - 1 in let* b = Block.bake_until_n_cycle_end @@ -601,7 +601,7 @@ let test_deposits_after_stake_removal () = (* the frozen deposits for account1 do not change until [preserved cycles + max_slashing_period] are baked (-1 because we already baked a cycle) *) let* b = - loop b (constants.preserved_cycles + Constants.max_slashing_period - 1) + loop b (constants.consensus_rights_delay + Constants.max_slashing_period - 1) in (* and still after preserved cycles + max_slashing_period, the frozen_deposits for account1 won't reflect the decrease in account1's active stake @@ -631,15 +631,17 @@ let test_deposits_unfrozen_after_deactivation () = expected last cycles at which it is considered active and at which it has non-zero deposits *) let last_active_cycle = - 1 + (2 * constants.preserved_cycles) + 1 + (2 * constants.consensus_rights_delay) (* according to [Delegate_storage.set_active] *) in let last_cycle_with_deposits = - last_active_cycle + constants.preserved_cycles + last_active_cycle + constants.consensus_rights_delay + Constants.max_slashing_period (* according to [Delegate_storage.freeze_deposits] *) in - let cycles_to_bake = last_cycle_with_deposits + constants.preserved_cycles in + let cycles_to_bake = + last_cycle_with_deposits + constants.consensus_rights_delay + in let rec loop b n = if n = 0 then return b else @@ -733,7 +735,7 @@ let test_frozen_deposits_with_delegation () = expected_new_frozen_deposits in let cycles_to_bake = - 2 * (constants.preserved_cycles + Constants.max_slashing_period) + 2 * (constants.consensus_rights_delay + Constants.max_slashing_period) in let rec loop b n = if n = 0 then return b @@ -835,7 +837,7 @@ let test_frozen_deposits_with_overdelegation () = expected_new_frozen_deposits in let cycles_to_bake = - 2 * (constants.preserved_cycles + Constants.max_slashing_period) + 2 * (constants.consensus_rights_delay + Constants.max_slashing_period) in let* frozen_deposits = Context.Delegate.current_frozen_deposits (B b) account1 @@ -929,7 +931,7 @@ let test_set_limit_with_overdelegation () = Assert.equal_tez ~loc:__LOC__ frozen_deposits expected_new_frozen_deposits in let cycles_to_bake = - 2 * (constants.preserved_cycles + Constants.max_slashing_period) + 2 * (constants.consensus_rights_delay + Constants.max_slashing_period) in let rec loop b n = if n = 0 then return b @@ -952,7 +954,7 @@ let test_set_limit_with_overdelegation () = return_unit (** This test fails when [to_cycle] in [Delegate.freeze_deposits] is smaller than - [new_cycle + preserved_cycles]. *) + [new_cycle + consensus_rights_delay]. *) let test_error_is_thrown_when_smaller_upper_bound_for_frozen_window () = let open Lwt_result_syntax in let* genesis, contracts = Context.init_with_constants2 constants in @@ -960,10 +962,10 @@ let test_error_is_thrown_when_smaller_upper_bound_for_frozen_window () = let account1 = Context.Contract.pkh contract1 in (* [account2] delegates (through [new_account]) to [account1] its spendable balance. The point is to make [account1] have a lot of staking balance so - that, after [preserved_cycles] when the active stake reflects this increase + that, after [consensus_rights_delay] when the active stake reflects this increase in staking balance, its [maximum_stake_to_be_deposited] is bigger than the frozen deposit which is computed on a smaller window because [to_cycle] is smaller - than [new_cycle + preserved_cycles]. *) + than [new_cycle + consensus_rights_delay]. *) let* delegated_amount = Context.Contract.balance (B genesis) contract2 in let new_account = Account.new_account () in let new_contract = Contract.Implicit new_account.pkh in @@ -989,9 +991,9 @@ let test_error_is_thrown_when_smaller_upper_bound_for_frozen_window () = in let* b = Block.bake ~operation b in let* (_ : Block.t) = - Block.bake_until_n_cycle_end constants.preserved_cycles b + Block.bake_until_n_cycle_end constants.consensus_rights_delay b in - (* By this time, after [preserved_cycles] passed after [account1] has emptied + (* By this time, after [consensus_rights_delay] passed after [account1] has emptied its spendable balance, because [account1] had a big staking balance at cycle 0, at this cycle it has a big active stake, and so its [maximum_stake_to_be_deposited] too is bigger than [frozen_deposits.current_amount], @@ -999,7 +1001,7 @@ let test_error_is_thrown_when_smaller_upper_bound_for_frozen_window () = Because the spendable balance of [account1] is 0, an error "Underflowing subtraction" is raised at the end of the cycle when updating the balance by subtracting [to_freeze] in [freeze_deposits]. - Note that by taking [to_cycle] is [new_cycle + preserved_cycles], + Note that by taking [to_cycle] is [new_cycle + consensus_rights_delay], [frozen_deposits.current_amount] can no longer be smaller than [maximum_stake_to_be_deposited], that is, the invariant maximum_stake_to_be_deposited <= frozen_deposits + balance is preserved. diff --git a/src/proto_alpha/lib_protocol/test/integration/consensus/test_seed.ml b/src/proto_alpha/lib_protocol/test/integration/consensus/test_seed.ml index a3e31178aecd..112454d07b3c 100644 --- a/src/proto_alpha/lib_protocol/test/integration/consensus/test_seed.ml +++ b/src/proto_alpha/lib_protocol/test/integration/consensus/test_seed.ml @@ -581,7 +581,7 @@ let test_early_incorrect_unverified_correct_already_vdf () = let* b = Block.bake_until_n_cycle_end ~policy - (csts.parametric.preserved_cycles + 1) + (csts.parametric.consensus_rights_delay + 1) b in let* stored_seed = Context.get_seed (B b) in @@ -604,7 +604,7 @@ let test_cycle_bounds () = let* b, _accounts = Context.init1 ~consensus_threshold:0 () in let* csts = Context.get_constants (B b) in let past_offset = Constants_repr.max_slashing_period - 1 in - let future_offset = csts.parametric.preserved_cycles in + let future_offset = csts.parametric.consensus_rights_delay in let open Alpha_context.Cycle in let expected_error_message direction current_cycle = match direction with diff --git a/src/proto_alpha/lib_protocol/test/integration/operations/test_voting.ml b/src/proto_alpha/lib_protocol/test/integration/operations/test_voting.ml index 9df2150df266..21eb46c06729 100644 --- a/src/proto_alpha/lib_protocol/test/integration/operations/test_voting.ml +++ b/src/proto_alpha/lib_protocol/test/integration/operations/test_voting.ml @@ -263,7 +263,7 @@ let context_init_tup tup ?(blocks_per_cycle = 4l) = (* Note that some of these tests assume (more or less) that the accounts remain active during a voting period, which roughly translates to the following condition being assumed to hold: - `blocks_per_voting_period <= preserved_cycles * blocks_per_cycle.` + `blocks_per_voting_period <= consensus_rights_delay * blocks_per_cycle.` We also set baking and attesting rewards to zero in order to ease accounting of exact baker stake. *) Context.init_gen diff --git a/src/proto_alpha/lib_protocol/test/integration/test_adaptive_issuance_launch.ml b/src/proto_alpha/lib_protocol/test/integration/test_adaptive_issuance_launch.ml index cbb75e645266..7878dbe7e9ed 100644 --- a/src/proto_alpha/lib_protocol/test/integration/test_adaptive_issuance_launch.ml +++ b/src/proto_alpha/lib_protocol/test/integration/test_adaptive_issuance_launch.ml @@ -147,7 +147,7 @@ let test_launch threshold expected_vote_duration () = cost_per_byte; } in - let preserved_cycles = constants.preserved_cycles in + let delay = constants.consensus_rights_delay in let* block, delegate = Context.init_with_constants1 constants in let delegate_pkh = Context.Contract.pkh delegate in let* () = assert_is_not_yet_set_to_launch ~loc:__LOC__ block in @@ -350,7 +350,7 @@ let test_launch threshold expected_vote_duration () = let* operation = stake (B block) wannabe_staker balance_to_stake in let* block = Block.bake ~operation block in (* The staking operation leads to an increase of the - total_frozen_stake but only preserved_cycles after the + total_frozen_stake but only consensus_rights_delay after the operation. *) let start_cycle = Block.current_cycle block in let* block = @@ -362,8 +362,7 @@ let test_launch threshold expected_vote_duration () = (Protocol.Alpha_context.Tez.of_mutez_exn 2_000_000_000_000L)) (fun block -> let current_cycle = Block.current_cycle block in - Protocol.Alpha_context.Cycle.( - current_cycle <= add start_cycle preserved_cycles)) + Protocol.Alpha_context.Cycle.(current_cycle <= add start_cycle delay)) block in let* block = Block.bake block in diff --git a/src/proto_alpha/lib_protocol/test/integration/test_adaptive_issuance_roundtrip.ml b/src/proto_alpha/lib_protocol/test/integration/test_adaptive_issuance_roundtrip.ml index d3a487e4319a..c66c13d70cb2 100644 --- a/src/proto_alpha/lib_protocol/test/integration/test_adaptive_issuance_roundtrip.ml +++ b/src/proto_alpha/lib_protocol/test/integration/test_adaptive_issuance_roundtrip.ml @@ -43,7 +43,7 @@ type error += Unexpected_error let default_param_wait, default_unstake_wait = let constants = Default_parameters.constants_test in - let pc = constants.preserved_cycles in + let pc = constants.consensus_rights_delay in let msp = Protocol.Constants_repr.max_slashing_period in (pc + 1, pc + msp) @@ -193,11 +193,12 @@ module State = struct } (** Expected number of cycles before staking parameters get applied *) - let param_wait state = state.constants.preserved_cycles + 1 + let param_wait state = + state.constants.delegate_parameters_activation_delay + 1 (** Expected number of cycles before staking unstaked funds get unfrozen *) let unstake_wait state = - let pc = state.constants.preserved_cycles in + let pc = state.constants.consensus_rights_delay in let msp = Protocol.Constants_repr.max_slashing_period in pc + msp @@ -259,7 +260,7 @@ module State = struct apply_stake amount current_cycle - state.constants.preserved_cycles + state.constants.consensus_rights_delay staker_name in update_map ~log_updates:[staker_name] ~f state @@ -571,7 +572,9 @@ module State = struct update_map ~f: (update_frozen_rights_cycle - (Cycle.add current_cycle (state.constants.preserved_cycles + 1))) + (Cycle.add + current_cycle + (state.constants.consensus_rights_delay + 1))) state in (* Apply autostaking *) @@ -1111,7 +1114,7 @@ let begin_test ~activate_ai ?(burn_rewards = false) List.fold_left (fun map cycle -> CycleMap.add cycle init_staked map) CycleMap.empty - Cycle.(root ---> add root constants.preserved_cycles) + Cycle.(root ---> add root constants.consensus_rights_delay) in let pkh = Context.Contract.pkh contract in let account = @@ -1173,7 +1176,7 @@ let set_delegate_params delegate_name parameters : (t, t) scenarios = set_delegate_parameters (B block) delegate.contract ~parameters in (* Update state *) - let wait = state.constants.preserved_cycles - 1 in + let wait = state.constants.delegate_parameters_activation_delay - 1 in let state = { state with @@ -1917,7 +1920,7 @@ module Roundtrip = struct let shorter_roundtrip_for_baker = let constants = init_constants ~autostaking_enable:false () in let amount = Amount (Tez.of_mutez 333_000_000_000L) in - let preserved_cycles = constants.preserved_cycles in + let consensus_rights_delay = constants.consensus_rights_delay in begin_test ~activate_ai:true constants ["delegate"] --> next_block --> wait_ai_activation --> stake "delegate" (Amount (Tez.of_mutez 1_800_000_000_000L)) @@ -1927,7 +1930,7 @@ module Roundtrip = struct --> List.fold_left (fun acc i -> acc |+ Tag (fs "wait %i cycles" i) --> wait_n_cycles i) (Tag "wait 0 cycles" --> Empty) - (Stdlib.List.init (preserved_cycles + 1) (fun i -> i + 1)) + (Stdlib.List.init (consensus_rights_delay + 1) (fun i -> i + 1)) --> stake "delegate" amount --> check_snapshot_balances "init" @@ -2157,7 +2160,7 @@ module Rewards = struct ~autostaking_enable:false () in - let pc = constants.preserved_cycles in + let pc = constants.consensus_rights_delay in begin_test ~activate_ai:true ~burn_rewards:true constants [""] --> next_block --> save_current_rate (* before AI rate *) --> wait_ai_activation @@ -2178,7 +2181,7 @@ module Rewards = struct ~autostaking_enable:false () in - let rate_var_lag = constants.preserved_cycles in + let rate_var_lag = constants.consensus_rights_delay in let init_params = { limit_of_staking_over_baking = Q.one; @@ -2663,7 +2666,7 @@ module Slashing = struct let test_no_shortcut_for_cheaters = let constants = init_constants ~autostaking_enable:false () in let amount = Amount (Tez.of_mutez 333_000_000_000L) in - let preserved_cycles = constants.preserved_cycles in + let consensus_rights_delay = constants.consensus_rights_delay in begin_test ~activate_ai:true constants ["delegate"] --> next_block --> wait_ai_activation --> stake "delegate" (Amount (Tez.of_mutez 1_800_000_000_000L)) @@ -2674,11 +2677,11 @@ module Slashing = struct --> (List.fold_left (fun acc i -> acc |+ Tag (fs "wait %i cycles" i) --> wait_n_cycles i) (Tag "wait 0 cycles" --> Empty) - (Stdlib.List.init (preserved_cycles - 1) (fun i -> i + 1)) + (Stdlib.List.init (consensus_rights_delay - 1) (fun i -> i + 1)) --> stake "delegate" amount --> assert_failure (check_snapshot_balances "init") |+ Tag "wait enough cycles (preserved cycles + 1)" - --> wait_n_cycles (preserved_cycles + 1) + --> wait_n_cycles (consensus_rights_delay + 1) --> stake "delegate" amount --> check_snapshot_balances "init") @@ -2687,7 +2690,7 @@ module Slashing = struct let amount_to_unstake = Amount (Tez.of_mutez 200_000_000_000L) in let amount_to_restake = Amount (Tez.of_mutez 100_000_000_000L) in let amount_expected_in_unstake_after_slash = Tez.of_mutez 50_000_000_000L in - let preserved_cycles = constants.preserved_cycles in + let consensus_rights_delay = constants.consensus_rights_delay in begin_test ~activate_ai:true constants ["delegate"] --> next_block --> wait_ai_activation --> stake "delegate" (Amount (Tez.of_mutez 1_800_000_000_000L)) @@ -2697,7 +2700,7 @@ module Slashing = struct --> List.fold_left (fun acc i -> acc |+ Tag (fs "wait %i cycles" i) --> wait_n_cycles i) (Tag "wait 0 cycles" --> Empty) - (Stdlib.List.init (preserved_cycles - 2) (fun i -> i + 1)) + (Stdlib.List.init (consensus_rights_delay - 2) (fun i -> i + 1)) --> double_attest "delegate" --> make_denunciations () --> next_cycle --> check_balance_field "delegate" @@ -2720,7 +2723,7 @@ module Slashing = struct --> make_denunciations ()) --> next_cycle --> check_balance_field "delegate" `Unstaked_frozen_total Tez.zero) - --> wait_n_cycles (constants.preserved_cycles + 1) + --> wait_n_cycles (constants.consensus_rights_delay + 1) let test_slash_rounding = let constants = init_constants ~autostaking_enable:false () in diff --git a/src/proto_alpha/lib_protocol/test/integration/validate/generator_descriptors.ml b/src/proto_alpha/lib_protocol/test/integration/validate/generator_descriptors.ml index 1581845e7cde..e8630f4a317e 100644 --- a/src/proto_alpha/lib_protocol/test/integration/validate/generator_descriptors.ml +++ b/src/proto_alpha/lib_protocol/test/integration/validate/generator_descriptors.ml @@ -521,10 +521,11 @@ let drain_delegate_prelude state = let drain_delegate_descriptor = { parameters = Fun.id; - required_cycle = (fun params -> params.constants.preserved_cycles + 1); + required_cycle = (fun params -> params.constants.consensus_rights_delay + 1); required_block = (fun _ -> 0); prelude = - (On (init_params.constants.preserved_cycles + 1), drain_delegate_prelude); + ( On (init_params.constants.consensus_rights_delay + 1), + drain_delegate_prelude ); opt_prelude = None; candidates_generator = (fun state -> 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..2b338d605161 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,7 +121,7 @@ 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 preserved_cycles = Constants_storage.preserved_cycles_ ctxt in let* () = Assert.equal_int ~loc:__LOC__ preserved_cycles 3 in let* () = let* active_pkh = Consensus_key.active_key ctxt del1.pkh in -- GitLab From 807a3550ba46bb4021febb8479a86aa603d657be Mon Sep 17 00:00:00 2001 From: Julien Tesson Date: Thu, 7 Dec 2023 17:47:40 +0100 Subject: [PATCH 07/21] proto/constants: use delegate_parameters_activation_delay --- .../lib_protocol/delegate_staking_parameters.ml | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/proto_alpha/lib_protocol/delegate_staking_parameters.ml b/src/proto_alpha/lib_protocol/delegate_staking_parameters.ml index 972394b65478..f74aafccb109 100644 --- a/src/proto_alpha/lib_protocol/delegate_staking_parameters.ml +++ b/src/proto_alpha/lib_protocol/delegate_staking_parameters.ml @@ -36,9 +36,11 @@ let of_delegate ctxt delegate = let pending_updates ctxt delegate = let contract = Contract_repr.Implicit delegate in - let preserved_cycles = Constants_storage.preserved_cycles ctxt in + let activation_delay = + Constants_storage.delegate_parameters_activation_delay ctxt + in let current_cycle = (Raw_context.current_level ctxt).cycle in - let to_cycle = Cycle_repr.add current_cycle (preserved_cycles + 1) in + let to_cycle = Cycle_repr.add current_cycle (activation_delay + 1) in List.filter_map_es (fun cycle -> let open Lwt_result_syntax in @@ -52,8 +54,10 @@ 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) + let activation_delay = + Constants_storage.delegate_parameters_activation_delay ctxt + in + Cycle_repr.add current_level.cycle (activation_delay + 1) in let*! ctxt = Storage.Pending_staking_parameters.add -- GitLab From 7ca797760b885b54c0e0f96a34190f3bbc32eb5e Mon Sep 17 00:00:00 2001 From: Julien Tesson Date: Mon, 18 Dec 2023 18:55:35 +0100 Subject: [PATCH 08/21] proto/tests: use delegate_parameters_activation_delay --- .../test/integration/test_adaptive_issuance_roundtrip.ml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/proto_alpha/lib_protocol/test/integration/test_adaptive_issuance_roundtrip.ml b/src/proto_alpha/lib_protocol/test/integration/test_adaptive_issuance_roundtrip.ml index c66c13d70cb2..1bc783728a71 100644 --- a/src/proto_alpha/lib_protocol/test/integration/test_adaptive_issuance_roundtrip.ml +++ b/src/proto_alpha/lib_protocol/test/integration/test_adaptive_issuance_roundtrip.ml @@ -2095,7 +2095,8 @@ module Roundtrip = struct --> set_delegate_params "delegate" no_costake_params (* The changes are not immediate *) --> stake "staker" amount - (* The parameters change is applied exactly [preserved_cycles + 1] after the request *) + (* The parameters change is applied exactly + [delegate_parameters_activation_delay + 1] after the request *) --> wait_n_cycles (default_param_wait - 1) (* Not yet... *) --> stake "staker" amount -- GitLab From 07702902c235eb355d2ff2389e15fb9ffac31689 Mon Sep 17 00:00:00 2001 From: Julien Tesson Date: Wed, 10 Jan 2024 21:28:56 +0100 Subject: [PATCH 09/21] 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 | 6 ++++++ 5 files changed, 22 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 72012dc4e5e9..85bb96fe053a 100644 --- a/src/proto_alpha/lib_protocol/adaptive_issuance_storage.ml +++ b/src/proto_alpha/lib_protocol/adaptive_issuance_storage.ml @@ -64,10 +64,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 @@ -184,8 +183,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 117173d0a17a..3babd63958be 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -952,6 +952,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 87755106dee6..828eb83fbfed 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 77fa0186cf98..67664f34866c 100644 --- a/src/proto_alpha/lib_protocol/constants_storage.mli +++ b/src/proto_alpha/lib_protocol/constants_storage.mli @@ -160,3 +160,9 @@ val adaptive_issuance_rewards_params : val adaptive_issuance_autostaking_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 impact the issuance.*) +val issuance_modification_delay : Raw_context.t -> int -- GitLab From 97813b51b8f5e335716fb785e17797589a401d75 Mon Sep 17 00:00:00 2001 From: Julien Tesson Date: Wed, 10 Jan 2024 21:33:08 +0100 Subject: [PATCH 10/21] 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 85bb96fe053a..c0b5b0193acc 100644 --- a/src/proto_alpha/lib_protocol/adaptive_issuance_storage.ml +++ b/src/proto_alpha/lib_protocol/adaptive_issuance_storage.ml @@ -306,9 +306,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 828eb83fbfed..0a718bc5b726 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 67664f34866c..af3aa87de06b 100644 --- a/src/proto_alpha/lib_protocol/constants_storage.mli +++ b/src/proto_alpha/lib_protocol/constants_storage.mli @@ -166,3 +166,7 @@ val direct_ticket_spending_enable : Raw_context.t -> bool (** Delay in cycle before the current state of the stake impact the issuance.*) 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 7dc69acfd52840bfae7bc49dd6bf59f93b54575c Mon Sep 17 00:00:00 2001 From: Julien Tesson Date: Wed, 10 Jan 2024 21:38:19 +0100 Subject: [PATCH 11/21] proto/constants,delegate_activation_storage: add tolerated_inactivity_period constant --- src/proto_alpha/lib_protocol/constants_storage.ml | 4 ++++ src/proto_alpha/lib_protocol/constants_storage.mli | 4 ++++ src/proto_alpha/lib_protocol/delegate_activation_storage.ml | 6 +++--- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/proto_alpha/lib_protocol/constants_storage.ml b/src/proto_alpha/lib_protocol/constants_storage.ml index 0a718bc5b726..0a5f43690cf2 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 af3aa87de06b..3827fb515b64 100644 --- a/src/proto_alpha/lib_protocol/constants_storage.mli +++ b/src/proto_alpha/lib_protocol/constants_storage.mli @@ -170,3 +170,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 0c635597ca2f..dc8659bf7027 100644 --- a/src/proto_alpha/lib_protocol/delegate_activation_storage.ml +++ b/src/proto_alpha/lib_protocol/delegate_activation_storage.ml @@ -59,6 +59,7 @@ 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 consensus_rights_delay = Constants_storage.consensus_rights_delay 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 + consensus_rights_delay` @@ -74,11 +75,10 @@ let set_active ctxt delegate = in let last_active_cycle = match current_last_active_cycle with - | None -> Cycle_repr.add current_cycle (2 * consensus_rights_delay) + | None -> Cycle_repr.add current_cycle (tolerance + consensus_rights_delay) | Some current_last_active_cycle -> let delay = - if inactive then 1 + (2 * consensus_rights_delay) - else 1 + consensus_rights_delay + if inactive then tolerance + consensus_rights_delay else tolerance in let updated = Cycle_repr.add current_cycle delay in Cycle_repr.max current_last_active_cycle updated -- GitLab From c7e96f860c00b8dbbbe47dfb533e20b9b363d5ce Mon Sep 17 00:00:00 2001 From: Julien Tesson Date: Thu, 7 Dec 2023 17:27:02 +0100 Subject: [PATCH 12/21] 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 0a5f43690cf2..ac4c031a7872 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 3827fb515b64..08d102a5b3cd 100644 --- a/src/proto_alpha/lib_protocol/constants_storage.mli +++ b/src/proto_alpha/lib_protocol/constants_storage.mli @@ -174,3 +174,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 259c38927a4f..e08d7a6327fb 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 5e697493c24831ae5e2f54c0da16aa3ec11544a6 Mon Sep 17 00:00:00 2001 From: Julien Tesson Date: Wed, 13 Dec 2023 22:19:19 +0100 Subject: [PATCH 13/21] 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 2b338d605161..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 e4a3b5ce325bc9c6fb83b1fb220ce81da5c85edf Mon Sep 17 00:00:00 2001 From: Julien Tesson Date: Thu, 7 Dec 2023 17:35:21 +0100 Subject: [PATCH 14/21] 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 3babd63958be..217f17385af8 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -952,6 +952,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 ac4c031a7872..c27466accc80 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 08d102a5b3cd..080ad0dd9c11 100644 --- a/src/proto_alpha/lib_protocol/constants_storage.mli +++ b/src/proto_alpha/lib_protocol/constants_storage.mli @@ -177,3 +177,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 remains 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 748b4b89810d..cc4533243834 100644 --- a/src/proto_alpha/lib_protocol/delegate_services.ml +++ b/src/proto_alpha/lib_protocol/delegate_services.ml @@ -622,12 +622,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 28af64f69944..7947b4917f35 100644 --- a/src/proto_alpha/lib_protocol/delegate_slashed_deposits_storage.ml +++ b/src/proto_alpha/lib_protocol/delegate_slashed_deposits_storage.ml @@ -162,7 +162,9 @@ let apply_and_clear_current_cycle_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 @@ -269,7 +271,7 @@ let apply_and_clear_current_cycle_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 5d8c959e11f5..90fc59695f5e 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 044c2d643fde..a51b70645fde 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 @@ -219,7 +228,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 05c8555edb489340b61a378e2916f0896d4d123d Mon Sep 17 00:00:00 2001 From: Julien Tesson Date: Mon, 18 Dec 2023 16:45:31 +0100 Subject: [PATCH 15/21] proto/client_proto_args: variable renaming This variable has nothing to do with cycles --- src/proto_alpha/lib_client/client_proto_args.ml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/proto_alpha/lib_client/client_proto_args.ml b/src/proto_alpha/lib_client/client_proto_args.ml index 3c182ec5ae19..5b86f37a4912 100644 --- a/src/proto_alpha/lib_client/client_proto_args.ml +++ b/src/proto_alpha/lib_client/client_proto_args.ml @@ -684,9 +684,9 @@ let preserved_levels_arg = ~default:"200" (Tezos_clic.parameter (fun _ s -> try - let preserved_cycles = int_of_string s in - if preserved_cycles < 0 then tzfail (Bad_preserved_levels s) - else return preserved_cycles + let preserved_levels = int_of_string s in + if preserved_levels < 0 then tzfail (Bad_preserved_levels s) + else return preserved_levels with _ -> tzfail (Bad_preserved_levels s))) let no_print_source_flag = -- GitLab From 3ab086d7e562728f5d4e936f34ccffb0a7706dfa Mon Sep 17 00:00:00 2001 From: Julien Tesson Date: Tue, 19 Dec 2023 21:03:04 +0100 Subject: [PATCH 16/21] store/tests: use blocks_preservation_cycles --- src/lib_store/unix/test/test_snapshots.ml | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/lib_store/unix/test/test_snapshots.ml b/src/lib_store/unix/test/test_snapshots.ml index c37eb88ac417..c61252c6d0ee 100644 --- a/src/lib_store/unix/test/test_snapshots.ml +++ b/src/lib_store/unix/test/test_snapshots.ml @@ -391,11 +391,7 @@ let make_tests speed genesis_parameters = let open Tezos_protocol_alpha.Protocol.Alpha_context in let { Parameters.constants = - { - Constants.Parametric.blocks_per_cycle; - blocks_preservation_cycles = preserved_cycles; - _; - }; + {Constants.Parametric.blocks_per_cycle; blocks_preservation_cycles; _}; _; } = genesis_parameters @@ -406,13 +402,13 @@ let make_tests speed genesis_parameters = match speed with | `Slow -> [ - preserved_cycles * blocks_per_cycle; - ((2 * preserved_cycles) + 1) * blocks_per_cycle; + blocks_preservation_cycles * blocks_per_cycle; + ((2 * blocks_preservation_cycles) + 1) * blocks_per_cycle; 65; 77; 89; ] - | `Quick -> [((2 * preserved_cycles) + 1) * blocks_per_cycle; 77] + | `Quick -> [((2 * blocks_preservation_cycles) + 1) * blocks_per_cycle; 77] in let exporter_history_modes = let open History_mode in -- GitLab From b86a78a7ede9432ecf4891766a6a0f5958c33308 Mon Sep 17 00:00:00 2001 From: Julien Tesson Date: Wed, 13 Dec 2023 21:42:42 +0100 Subject: [PATCH 17/21] proto: remove preserved_cycles parameter --- src/proto_alpha/lib_parameters/default_parameters.ml | 5 +---- src/proto_alpha/lib_protocol/alpha_context.mli | 3 --- .../lib_protocol/constants_parametric_repr.ml | 11 +++-------- .../lib_protocol/constants_parametric_repr.mli | 1 - src/proto_alpha/lib_protocol/constants_storage.ml | 4 ---- src/proto_alpha/lib_protocol/constants_storage.mli | 2 -- src/proto_alpha/lib_protocol/raw_context.ml | 1 - 7 files changed, 4 insertions(+), 23 deletions(-) diff --git a/src/proto_alpha/lib_parameters/default_parameters.ml b/src/proto_alpha/lib_parameters/default_parameters.ml index 71b10fa0a770..9cbe48cb2388 100644 --- a/src/proto_alpha/lib_parameters/default_parameters.ml +++ b/src/proto_alpha/lib_parameters/default_parameters.ml @@ -147,7 +147,7 @@ let default_dal = cryptobox_parameters = default_cryptobox_parameters; } -let constants_mainnet = +let constants_mainnet : Constants.Parametric.t = let block_time = 10 in let consensus_committee_size = 7000 in let Constants.Generated. @@ -180,7 +180,6 @@ let constants_mainnet = in let sc_rollup = make_sc_rollup_parameter ~dal_activation_level block_time in { - Constants.Parametric.preserved_cycles = 5; consensus_rights_delay = 5; blocks_preservation_cycles = 1; delegate_parameters_activation_delay = 5; @@ -331,7 +330,6 @@ let constants_sandbox = ~mainnet_constants_divider:32; }; issuance_weights; - Constants.Parametric.preserved_cycles = 2; blocks_preservation_cycles = 1; consensus_rights_delay = 2; delegate_parameters_activation_delay = 2; @@ -368,7 +366,6 @@ let constants_test = ~mainnet_constants_divider:64; }; issuance_weights; - Constants.Parametric.preserved_cycles = 3; consensus_rights_delay = 3; delegate_parameters_activation_delay = 3; blocks_preservation_cycles = 1; diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index 217f17385af8..92c43049d399 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -882,7 +882,6 @@ module Constants : sig } type t = { - preserved_cycles : int; consensus_rights_delay : int; blocks_preservation_cycles : int; delegate_parameters_activation_delay : int; @@ -944,8 +943,6 @@ module Constants : sig val sc_rollup : context -> Parametric.sc_rollup - val preserved_cycles : context -> int - val consensus_rights_delay : context -> int val blocks_preservation_cycles : context -> int diff --git a/src/proto_alpha/lib_protocol/constants_parametric_repr.ml b/src/proto_alpha/lib_protocol/constants_parametric_repr.ml index d2765ea3a0e5..a716206129c4 100644 --- a/src/proto_alpha/lib_protocol/constants_parametric_repr.ml +++ b/src/proto_alpha/lib_protocol/constants_parametric_repr.ml @@ -166,7 +166,6 @@ type issuance_weights = { } type t = { - preserved_cycles : int; consensus_rights_delay : int; blocks_preservation_cycles : int; delegate_parameters_activation_delay : int; @@ -485,8 +484,7 @@ let encoding = let open Data_encoding in conv (fun c -> - ( ( ( c.preserved_cycles, - c.consensus_rights_delay, + ( ( ( c.consensus_rights_delay, c.blocks_preservation_cycles, c.delegate_parameters_activation_delay ), ( c.blocks_per_cycle, @@ -526,8 +524,7 @@ let encoding = ( (c.sc_rollup, c.zk_rollup), (c.adaptive_issuance, c.direct_ticket_spending_enable) ) ) ) ) ) ) )) - (fun ( ( ( preserved_cycles, - consensus_rights_delay, + (fun ( ( ( consensus_rights_delay, blocks_preservation_cycles, delegate_parameters_activation_delay ), ( blocks_per_cycle, @@ -568,7 +565,6 @@ let encoding = (adaptive_issuance, direct_ticket_spending_enable) ) ) ) ) ) ) ) -> { - preserved_cycles; consensus_rights_delay; blocks_preservation_cycles; delegate_parameters_activation_delay; @@ -613,8 +609,7 @@ let encoding = }) (merge_objs (merge_objs - (obj4 - (req "preserved_cycles" uint8) + (obj3 (req "consensus_rights_delay" uint8) (req "blocks_preservation_cycles" uint8) (req "delegate_parameters_activation_delay" uint8)) diff --git a/src/proto_alpha/lib_protocol/constants_parametric_repr.mli b/src/proto_alpha/lib_protocol/constants_parametric_repr.mli index 5f93956f4291..f400a9af828e 100644 --- a/src/proto_alpha/lib_protocol/constants_parametric_repr.mli +++ b/src/proto_alpha/lib_protocol/constants_parametric_repr.mli @@ -153,7 +153,6 @@ type issuance_weights = { } type t = { - preserved_cycles : int; (* Number of cycles after which computed consensus rights are used to actually participate in the consensus *) consensus_rights_delay : int; diff --git a/src/proto_alpha/lib_protocol/constants_storage.ml b/src/proto_alpha/lib_protocol/constants_storage.ml index c27466accc80..a49027acbfc7 100644 --- a/src/proto_alpha/lib_protocol/constants_storage.ml +++ b/src/proto_alpha/lib_protocol/constants_storage.ml @@ -24,10 +24,6 @@ (* *) (*****************************************************************************) -let preserved_cycles c = - let constants = Raw_context.constants c in - constants.preserved_cycles - let consensus_rights_delay 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 080ad0dd9c11..1a692a85f21e 100644 --- a/src/proto_alpha/lib_protocol/constants_storage.mli +++ b/src/proto_alpha/lib_protocol/constants_storage.mli @@ -29,8 +29,6 @@ from the context. See {!Constant_repr.parametric} for more details about these values. *) -val preserved_cycles : Raw_context.t -> int - val consensus_rights_delay : Raw_context.t -> int val blocks_preservation_cycles : Raw_context.t -> int diff --git a/src/proto_alpha/lib_protocol/raw_context.ml b/src/proto_alpha/lib_protocol/raw_context.ml index 6379f8b52042..59d22719b229 100644 --- a/src/proto_alpha/lib_protocol/raw_context.ml +++ b/src/proto_alpha/lib_protocol/raw_context.ml @@ -1195,7 +1195,6 @@ let prepare_first_block ~level ~timestamp _chain_id ctxt = let constants = Constants_parametric_repr. { - preserved_cycles = c.preserved_cycles; consensus_rights_delay = c.preserved_cycles; blocks_preservation_cycles = 1; delegate_parameters_activation_delay = c.preserved_cycles; -- GitLab From 8b3cd20b3c795a42505afdee53c07edd89214928 Mon Sep 17 00:00:00 2001 From: Julien Tesson Date: Wed, 20 Dec 2023 14:27:26 +0100 Subject: [PATCH 18/21] tezt/RPC: reset trace with preserved_cycles removal --- ...ode client) RPC regression tests- misc_protocol.out | 10 +++++----- ...mode light) RPC regression tests- misc_protocol.out | 10 +++++----- ...mode proxy) RPC regression tests- misc_protocol.out | 10 +++++----- ...r_data_dir) RPC regression tests- misc_protocol.out | 10 +++++----- ...server_rpc) RPC regression tests- misc_protocol.out | 10 +++++----- 5 files changed, 25 insertions(+), 25 deletions(-) diff --git a/tezt/tests/expected/RPC_test.ml/Alpha- (mode client) RPC regression tests- misc_protocol.out b/tezt/tests/expected/RPC_test.ml/Alpha- (mode client) RPC regression tests- misc_protocol.out index a20f0c53dcd6..cf277da73730 100644 --- a/tezt/tests/expected/RPC_test.ml/Alpha- (mode client) RPC regression tests- misc_protocol.out +++ b/tezt/tests/expected/RPC_test.ml/Alpha- (mode client) RPC regression tests- misc_protocol.out @@ -9,11 +9,11 @@ "smart_rollup_max_wrapped_proof_binary_size": 30000, "smart_rollup_message_size_limit": 4096, "smart_rollup_max_number_of_messages_per_level": "1000000", - "preserved_cycles": 2, "consensus_rights_delay": 2, - "blocks_preservation_cycles": 1, "delegate_parameters_activation_delay": 2, - "blocks_per_cycle": 8, "blocks_per_commitment": 4, - "nonce_revelation_threshold": 4, "blocks_per_stake_snapshot": 4, - "cycles_per_voting_period": 8, "hard_gas_limit_per_operation": "1040000", + "consensus_rights_delay": 2, "blocks_preservation_cycles": 1, + "delegate_parameters_activation_delay": 2, "blocks_per_cycle": 8, + "blocks_per_commitment": 4, "nonce_revelation_threshold": 4, + "blocks_per_stake_snapshot": 4, "cycles_per_voting_period": 8, + "hard_gas_limit_per_operation": "1040000", "hard_gas_limit_per_block": "1733333", "proof_of_work_threshold": "4611686018427387903", "minimal_stake": "6000000000", "minimal_frozen_stake": "600000000", diff --git a/tezt/tests/expected/RPC_test.ml/Alpha- (mode light) RPC regression tests- misc_protocol.out b/tezt/tests/expected/RPC_test.ml/Alpha- (mode light) RPC regression tests- misc_protocol.out index 0951e336ff0d..bd0715b7929c 100644 --- a/tezt/tests/expected/RPC_test.ml/Alpha- (mode light) RPC regression tests- misc_protocol.out +++ b/tezt/tests/expected/RPC_test.ml/Alpha- (mode light) RPC regression tests- misc_protocol.out @@ -9,11 +9,11 @@ "smart_rollup_max_wrapped_proof_binary_size": 30000, "smart_rollup_message_size_limit": 4096, "smart_rollup_max_number_of_messages_per_level": "1000000", - "preserved_cycles": 2, "consensus_rights_delay": 2, - "blocks_preservation_cycles": 1, "delegate_parameters_activation_delay": 2, - "blocks_per_cycle": 8, "blocks_per_commitment": 4, - "nonce_revelation_threshold": 4, "blocks_per_stake_snapshot": 4, - "cycles_per_voting_period": 8, "hard_gas_limit_per_operation": "1040000", + "consensus_rights_delay": 2, "blocks_preservation_cycles": 1, + "delegate_parameters_activation_delay": 2, "blocks_per_cycle": 8, + "blocks_per_commitment": 4, "nonce_revelation_threshold": 4, + "blocks_per_stake_snapshot": 4, "cycles_per_voting_period": 8, + "hard_gas_limit_per_operation": "1040000", "hard_gas_limit_per_block": "1733333", "proof_of_work_threshold": "4611686018427387903", "minimal_stake": "6000000000", "minimal_frozen_stake": "600000000", diff --git a/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy) RPC regression tests- misc_protocol.out b/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy) RPC regression tests- misc_protocol.out index 793d37798206..3c664598220a 100644 --- a/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy) RPC regression tests- misc_protocol.out +++ b/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy) RPC regression tests- misc_protocol.out @@ -9,11 +9,11 @@ "smart_rollup_max_wrapped_proof_binary_size": 30000, "smart_rollup_message_size_limit": 4096, "smart_rollup_max_number_of_messages_per_level": "1000000", - "preserved_cycles": 2, "consensus_rights_delay": 2, - "blocks_preservation_cycles": 1, "delegate_parameters_activation_delay": 2, - "blocks_per_cycle": 8, "blocks_per_commitment": 4, - "nonce_revelation_threshold": 4, "blocks_per_stake_snapshot": 4, - "cycles_per_voting_period": 8, "hard_gas_limit_per_operation": "1040000", + "consensus_rights_delay": 2, "blocks_preservation_cycles": 1, + "delegate_parameters_activation_delay": 2, "blocks_per_cycle": 8, + "blocks_per_commitment": 4, "nonce_revelation_threshold": 4, + "blocks_per_stake_snapshot": 4, "cycles_per_voting_period": 8, + "hard_gas_limit_per_operation": "1040000", "hard_gas_limit_per_block": "1733333", "proof_of_work_threshold": "4611686018427387903", "minimal_stake": "6000000000", "minimal_frozen_stake": "600000000", diff --git a/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy_server_data_dir) RPC regression tests- misc_protocol.out b/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy_server_data_dir) RPC regression tests- misc_protocol.out index 4c760b0af97f..5f3c3c8c8640 100644 --- a/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy_server_data_dir) RPC regression tests- misc_protocol.out +++ b/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy_server_data_dir) RPC regression tests- misc_protocol.out @@ -9,11 +9,11 @@ "smart_rollup_max_wrapped_proof_binary_size": 30000, "smart_rollup_message_size_limit": 4096, "smart_rollup_max_number_of_messages_per_level": "1000000", - "preserved_cycles": 2, "consensus_rights_delay": 2, - "blocks_preservation_cycles": 1, "delegate_parameters_activation_delay": 2, - "blocks_per_cycle": 8, "blocks_per_commitment": 4, - "nonce_revelation_threshold": 4, "blocks_per_stake_snapshot": 4, - "cycles_per_voting_period": 8, "hard_gas_limit_per_operation": "1040000", + "consensus_rights_delay": 2, "blocks_preservation_cycles": 1, + "delegate_parameters_activation_delay": 2, "blocks_per_cycle": 8, + "blocks_per_commitment": 4, "nonce_revelation_threshold": 4, + "blocks_per_stake_snapshot": 4, "cycles_per_voting_period": 8, + "hard_gas_limit_per_operation": "1040000", "hard_gas_limit_per_block": "1733333", "proof_of_work_threshold": "4611686018427387903", "minimal_stake": "6000000000", "minimal_frozen_stake": "600000000", diff --git a/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy_server_rpc) RPC regression tests- misc_protocol.out b/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy_server_rpc) RPC regression tests- misc_protocol.out index 4c760b0af97f..5f3c3c8c8640 100644 --- a/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy_server_rpc) RPC regression tests- misc_protocol.out +++ b/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy_server_rpc) RPC regression tests- misc_protocol.out @@ -9,11 +9,11 @@ "smart_rollup_max_wrapped_proof_binary_size": 30000, "smart_rollup_message_size_limit": 4096, "smart_rollup_max_number_of_messages_per_level": "1000000", - "preserved_cycles": 2, "consensus_rights_delay": 2, - "blocks_preservation_cycles": 1, "delegate_parameters_activation_delay": 2, - "blocks_per_cycle": 8, "blocks_per_commitment": 4, - "nonce_revelation_threshold": 4, "blocks_per_stake_snapshot": 4, - "cycles_per_voting_period": 8, "hard_gas_limit_per_operation": "1040000", + "consensus_rights_delay": 2, "blocks_preservation_cycles": 1, + "delegate_parameters_activation_delay": 2, "blocks_per_cycle": 8, + "blocks_per_commitment": 4, "nonce_revelation_threshold": 4, + "blocks_per_stake_snapshot": 4, "cycles_per_voting_period": 8, + "hard_gas_limit_per_operation": "1040000", "hard_gas_limit_per_block": "1733333", "proof_of_work_threshold": "4611686018427387903", "minimal_stake": "6000000000", "minimal_frozen_stake": "600000000", -- GitLab From f9c21c6ec127c254005057769a223d13b584faf6 Mon Sep 17 00:00:00 2001 From: Julien Tesson Date: Wed, 20 Dec 2023 14:12:53 +0100 Subject: [PATCH 19/21] docs/alpha: remove preserved_cycles --- docs/alpha/adaptive_issuance.rst | 2 +- docs/alpha/consensus.rst | 16 ++++++++-------- docs/alpha/proof_of_stake.rst | 14 +++++++------- docs/alpha/randomness_generation.rst | 8 ++++---- docs/alpha/token_management.rst | 2 +- docs/alpha/validation.rst | 2 +- 6 files changed, 22 insertions(+), 22 deletions(-) diff --git a/docs/alpha/adaptive_issuance.rst b/docs/alpha/adaptive_issuance.rst index 391e1a125c47..a11537153768 100644 --- a/docs/alpha/adaptive_issuance.rst +++ b/docs/alpha/adaptive_issuance.rst @@ -392,7 +392,7 @@ Delegates can modify these staking parameters at all times, using the ``set_delegate_parameters`` pseudo-operation: that is, by transferring 0 tez to their own ``set_delegate_parameters`` entry-point. The chosen values for both parameters need to be supplied. The new parameters are then applied -``PRESERVED_CYCLES`` (currently 5) cycles later. +``DELEGATE_PARAMETERS_ACTIVATION_DELAY`` (currently 5) cycles later. :: diff --git a/docs/alpha/consensus.rst b/docs/alpha/consensus.rst index 2bd1e8fbc907..7364c3142c7f 100644 --- a/docs/alpha/consensus.rst +++ b/docs/alpha/consensus.rst @@ -187,21 +187,21 @@ unset deposits limit for ``. These commands are implemented using a new manager operation ``Set_deposits_limit``. When emitting such a command in cycle ``c``, it affects the automatic deposit at the end of this cycle, and thus the consensus rights set for cycle ``(c + 1) + -PRESERVED_CYCLES + 1``. +CONSENSUS_RIGHTS_DELAY + 1``. Since the deposit will be adjusted at the end of cycle ``c``, unstaked tokens -will be available at cycle ``c + 1 + PRESERVED_CYCLES + MAX_SLASHING_PERIOD``. +will be available at cycle ``c + 1 + CONSENSUS_RIGHTS_DELAY + MAX_SLASHING_PERIOD``. -The active stake is computed ``PRESERVED_CYCLES`` in advance: at -the end of cycle ``c`` for cycle ``c + 1 + PRESERVED_CYCLES`` (as in Emmy*), +The active stake is computed ``CONSENSUS_RIGHTS_DELAY`` in advance: at +the end of cycle ``c`` for cycle ``c + 1 + CONSENSUS_RIGHTS_DELAY`` (as in Emmy*), before updating the delegates' :ref:`activity status`. .. This entails that a delegate which was participating until cycle ``c - 1`` and is no longer participating in cycle ``c`, will lose its rights from cycle - ``c + 2 * PRESERVED_CYCLES + 2`` onwards -- at the end of cycle ``c + - PRESERVED_CYCLES``, the rights for cycle ``c + 2 * - PRESERVED_CYCLES + 1`` are computed, and only then is the delegate + ``c + 2 * CONSENSUS_RIGHTS_DELAY + 2`` onwards -- at the end of cycle ``c + + CONSENSUS_RIGHTS_DELAY``, the rights for cycle ``c + 2 * + CONSENSUS_RIGHTS_DELAY + 1`` are computed, and only then is the delegate declared passive. Here "participation" means *having baked a final block* or *having a preattestation or attestation included in a final block*. @@ -276,7 +276,7 @@ behavior. Notable changes however are as follows: * Validators are rewarded instantaneously for baking blocks and including extra attestations, and not at the end of the cycle like in Emmy*. * At the end of a cycle ``c``, the following actions happen: - - the selection of the consensus committee cycle ``c + PRESERVED_CYCLES``, based on the current active stake distribution, + - the selection of the consensus committee cycle ``c + CONSENSUS_RIGHTS_DELAY``, based on the current active stake distribution, - the distribution of attesting rewards, - the adjustment of frozen deposits. diff --git a/docs/alpha/proof_of_stake.rst b/docs/alpha/proof_of_stake.rst index 5c703b678e19..4d8cf890bf5c 100644 --- a/docs/alpha/proof_of_stake.rst +++ b/docs/alpha/proof_of_stake.rst @@ -36,8 +36,8 @@ as delegates. Any :ref:`account ` (implicit or originated) can specify a delegate through a delegation operation. Any account can change or revoke its delegate at any time, again through a delegation operation. However, the change only -becomes effective after ``PRESERVED_CYCLES + 2`` :ref:`cycles `. The -value ``PRESERVED_CYCLES`` is a :ref:`protocol constant +becomes effective after ``CONSENSUS_RIGHTS_DELAY + 2`` :ref:`cycles `. The +value ``CONSENSUS_RIGHTS_DELAY`` is a :ref:`protocol constant `. A delegate participates in consensus and in governance with a weight @@ -83,8 +83,8 @@ A delegate is marked as active at its registration. A delegate becomes passive at the end of cycle ``n`` when it has failed to participate in the consensus algorithm in -the past ``PRESERVED_CYCLES + 1`` cycles. That is, in cycles ``n``, ``n-1``, -``n-2``, ..., ``n - PRESERVED_CYCLES``. +the past ``CONSENSUS_RIGHTS_DELAY + 1`` cycles. That is, in cycles ``n``, ``n-1``, +``n-2``, ..., ``n - CONSENSUS_RIGHTS_DELAY``. Delegates' rights selection --------------------------- @@ -117,9 +117,9 @@ position modulo ``BLOCKS_PER_STAKE_SNAPSHOT`` is ``BLOCKS_PER_STAKE_SNAPSHOT - 1 Therefore, at the end of a cycle there are ``BLOCKS_PER_CYCLE / BLOCKS_PER_STAKE_SNAPSHOT`` stored snapshots. -At the end of cycle ``n-1-PRESERVED_CYCLES``, the snapshot for cycle +At the end of cycle ``n-1-CONSENSUS_RIGHTS_DELAY``, the snapshot for cycle ``n`` is randomly selected from the snapshots stored in cycle -``n-1-PRESERVED_CYCLES``. The selection is done through a very simple +``n-1-CONSENSUS_RIGHTS_DELAY``. The selection is done through a very simple PRNG having as seed the :ref:`random seed` for cycle ``n``. @@ -171,7 +171,7 @@ Proof-of-stake parameters - Parameter value * - ``BLOCKS_PER_CYCLE`` - 24576 blocks - * - ``PRESERVED_CYCLES`` + * - ``CONSENSUS_RIGHTS_DELAY`` - 5 cycles * - ``MINIMAL_STAKE`` - 6,000 ꜩ diff --git a/docs/alpha/randomness_generation.rst b/docs/alpha/randomness_generation.rst index e25d94569123..5f9bdc669b4d 100644 --- a/docs/alpha/randomness_generation.rst +++ b/docs/alpha/randomness_generation.rst @@ -90,9 +90,9 @@ time ends). To ensure liveness, we fallback to RANDAO entropy if no VDF output was published and verified on-chain. Concretely, the random seed for cycle ``n`` is a 256-bit long number computed -at the end of cycle ``n-1-PRESERVED_CYCLES``. It is the VDF output (or, in its +at the end of cycle ``n-1-CONSENSUS_RIGHTS_DELAY``. It is the VDF output (or, in its absence, the RANDAO output) computed from nonces to which delegates commit -during cycle ``n-2-PRESERVED_CYCLES``. +during cycle ``n-2-CONSENSUS_RIGHTS_DELAY``. Every ``BLOCKS_PER_COMMITMENT`` levels, the corresponding block contains a nonce commitment. More precisely, a block contains a commitment if and only if @@ -103,7 +103,7 @@ commitment is simply the hash of the nonce. The committed nonce must be revealed by the original block proposer during the nonce revelation phase, that is during the first ``NONCE_REVELATION_THRESHOLD`` -blocks, of cycle ``n-1-PRESERVED_CYCLES`` under penalty of forfeiting all of +blocks, of cycle ``n-1-CONSENSUS_RIGHTS_DELAY`` under penalty of forfeiting all of its expected attesting rewards for that cycle. The associated security deposit and baking rewards are not affected. The RANDAO output is then computed and stored on-chain as the temporary seed for cycle ``n``. The RANDAO output is the @@ -162,5 +162,5 @@ Randomness generation parameters * - ``VDF_DIFFICULTY`` - 8,000,000,000 -The variables ``BLOCKS_PER_CYCLE`` and ``PRESERVED_CYCLES`` are already defined +The variables ``BLOCKS_PER_CYCLE`` and ``CONSENSUS_RIGHTS_DELAY`` are already defined in the :doc:`proof of stake ` page. diff --git a/docs/alpha/token_management.rst b/docs/alpha/token_management.rst index 84ec859b59e2..5752e5980187 100644 --- a/docs/alpha/token_management.rst +++ b/docs/alpha/token_management.rst @@ -105,7 +105,7 @@ The field ``kind`` allows to identify the type of container account, it can have stakers and the delegate itself. - the field ``"cycle"`` contains either the cycle at which the funds have been unstaked or the last unslashable cycle (``MAX_SLASHING_PERIOD + - PRESERVED_CYCLES`` before current cycle) if it is greater than the unstaking + CONSENSUS_RIGHTS_DELAY`` before current cycle) if it is greater than the unstaking cycle. - ``"bonds"`` represents the accounts of frozen bonds. Bonds are like deposits. diff --git a/docs/alpha/validation.rst b/docs/alpha/validation.rst index 6ebeb4a33b28..b4ab3a30fc36 100644 --- a/docs/alpha/validation.rst +++ b/docs/alpha/validation.rst @@ -201,7 +201,7 @@ Indeed, by relying on the ancestor context, this mode can *only* assert the validity of consensus-related preconditions (attesting power, block fitness, etc.), as future consensus slots are known in advance -- how much in advance being specified by the -```` protocol constant. Thus, the ``Partial +```` protocol constant. Thus, the ``Partial application`` mode provides an over-approximation of the branch's validity, and as a result intermediate results are not committed on disk in order to prevent potential attacks. -- GitLab From 5efe5d1a87489c06f020b1aff2306cec89fb14bc Mon Sep 17 00:00:00 2001 From: Julien Tesson Date: Wed, 20 Dec 2023 14:14:41 +0100 Subject: [PATCH 20/21] docs: replace preserved_cycles in non-protocol specific parts --- docs/introduction/howtorun.rst | 4 ++-- docs/user/key-management.rst | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/introduction/howtorun.rst b/docs/introduction/howtorun.rst index 987f775cccb3..dd725d1da048 100644 --- a/docs/introduction/howtorun.rst +++ b/docs/introduction/howtorun.rst @@ -125,7 +125,7 @@ your implicit account:: octez-client register key bob as delegate -Once registered, you need to wait ``preserved_cycles + 2 = 7`` cycles +Once registered, you need to wait ``consensus_rights_delay + 2 = 7`` cycles for your rights to be considered. There is a simple rpc that can be used to check your rights for every @@ -143,7 +143,7 @@ baking rights at higher rounds, like 2 in the example above. Inactive delegates ~~~~~~~~~~~~~~~~~~ -If a delegate doesn't show any sign of activity for ``preserved_cycles`` +If a delegate doesn't show any sign of activity for ``consensus_rights_delay`` it is marked **inactive** and its rights are removed. This mechanism is important to remove inactive delegates and reallocate their rights to the active ones so that the network is always working diff --git a/docs/user/key-management.rst b/docs/user/key-management.rst index 67aa4018b057..0e09b01c883d 100644 --- a/docs/user/key-management.rst +++ b/docs/user/key-management.rst @@ -299,7 +299,7 @@ The command to update the consensus key is:: octez-client set consensus key for to consensus -The update becomes active after ``PRESERVED_CYCLES + 1`` cycles. We therefore distinguish +The update becomes active after ``CONSENSUS_RIGHTS_DELAY + 1`` cycles. We therefore distinguish the active consensus key and the pending consensus keys. The active consensus key is by default the delegate’s manager key, which cannot change. -- GitLab From d43c385a427832440bcb0cea626edc116d249998 Mon Sep 17 00:00:00 2001 From: Julien Tesson Date: Fri, 15 Dec 2023 09:42:25 +0100 Subject: [PATCH 21/21] docs/alpha changelog: one entry for preserved_cycles splitting --- docs/protocols/alpha.rst | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/docs/protocols/alpha.rst b/docs/protocols/alpha.rst index 634598caf311..1d95e4018c86 100644 --- a/docs/protocols/alpha.rst +++ b/docs/protocols/alpha.rst @@ -57,11 +57,10 @@ Operation receipts Protocol parameters ------------------- -- Added ``consensus_rights_delay`` parametric constant. (MR :gl:`!11188`) - -- Added ``blocks_preservation_cycles`` parametric constant. (MR :gl:`!11280`) - -- Added ``delegate_parameters_activation_delay`` parametric constant. (MR :gl:`!11279`) +- replace ``preserved_cycles`` with 3 constants ``consensus_rights_delay``, + ``blocks_preservation_cycles`` and + ``delegate_parameters_activation_delay``. (MR :gl:`!11188`,:gl:`!11280`, + :gl:`!11279`, !11220) - Set the number of blocks preservation cycles to 1. (MR :gl:`!11325`) @@ -128,3 +127,12 @@ Minor Changes Internal -------- + +- On top of the 3 new parametric constants ``consensus_rights_delay``, + ``blocks_preservation_cycles`` and ``delegate_parameters_activation_delay`` + which replace ``preserved_cycles``, we added pseudo-constants that derive from + them : ``issuance_modification_delay``, + ``adaptive_issuance_activation_delay``, ``randao_delay``, + ``slashable_deposits_period``, ``tolerated_inactivity_period``, + ``consensus_key_activation_delay`` (MR :gl:`!11188`,:gl:`!11280`, + :gl:`!11279`, :gl:`!11220`) -- GitLab