diff --git a/contrib/kaitai-struct-files/files/alpha__constants.ksy b/contrib/kaitai-struct-files/files/alpha__constants.ksy index a8ba2ca95fe4929dbb0edf78d82d60dcb91c3bb4..ea6dbc136a105d6ee935c9f98f6682cbee2178f0 100644 --- a/contrib/kaitai-struct-files/files/alpha__constants.ksy +++ b/contrib/kaitai-struct-files/files/alpha__constants.ksy @@ -212,8 +212,6 @@ seq: type: int31 - id: smart_rollup_max_number_of_messages_per_level type: n -- id: preserved_cycles - type: u1 - id: consensus_rights_delay type: u1 - id: blocks_preservation_cycles diff --git a/contrib/kaitai-struct-files/files/alpha__constants__parametric.ksy b/contrib/kaitai-struct-files/files/alpha__constants__parametric.ksy index 17a5db4e9cd7c690006dc553df007101e38daa33..fde9e41fd9ed4e5bb932483e26f5d50c218f11a5 100644 --- a/contrib/kaitai-struct-files/files/alpha__constants__parametric.ksy +++ b/contrib/kaitai-struct-files/files/alpha__constants__parametric.ksy @@ -184,8 +184,6 @@ enums: 2: p256 3: bls seq: -- id: preserved_cycles - type: u1 - id: consensus_rights_delay type: u1 - id: blocks_preservation_cycles diff --git a/contrib/kaitai-struct-files/files/alpha__parameters.ksy b/contrib/kaitai-struct-files/files/alpha__parameters.ksy index f773406ecaab8a5dafc1a7b40741369a7d72246d..9752e50d273a0ed09fedc178fd6cb3c6a22abc14 100644 --- a/contrib/kaitai-struct-files/files/alpha__parameters.ksy +++ b/contrib/kaitai-struct-files/files/alpha__parameters.ksy @@ -462,8 +462,6 @@ seq: - id: no_reward_cycles type: int31 if: (no_reward_cycles_tag == bool::true) -- id: preserved_cycles - type: u1 - id: consensus_rights_delay type: u1 - id: blocks_preservation_cycles diff --git a/docs/alpha/adaptive_issuance.rst b/docs/alpha/adaptive_issuance.rst index 391e1a125c4783a530e0b09b8aa5ea63aa75b51a..a11537153768c5ad57887f98ceeb682cf8d421fa 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 2bd1e8fbc9078929178332a49e6e98696b018da8..7364c3142c7fb93ec34a356b6f6c0032c7844d68 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 5c703b678e19e9436dc7effab19c90697344e5a1..4d8cf890bf5ce0f1369e86d69f985ed038e5c999 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 e25d94569123942971545de287751d4e9032efbf..5f9bdc669b4ddc8a409702885e25c8818d3edccb 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 84ec859b59e2d077e1a261bd223c9bf9395c1b86..5752e59801879dd007fbffaa097e7092d1a9e6d9 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 6ebeb4a33b28149b38703e7527df9d4a86ecca64..b4ab3a30fc3662979f2d244bec11d20c32ed07b9 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. diff --git a/docs/introduction/howtorun.rst b/docs/introduction/howtorun.rst index 8b9166dab0189f766abc4dea481b992444ec7d17..00824becf86959722858c13ad929350cd3458882 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/protocols/alpha.rst b/docs/protocols/alpha.rst index 5b31633f0718888d4a39cc0b10779cb266977d45..e6376554a648186d5fb41a2fd8dd0dc575da3d0e 100644 --- a/docs/protocols/alpha.rst +++ b/docs/protocols/alpha.rst @@ -82,11 +82,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`, :gl:`!11220`) - Set the number of blocks preservation cycles to 1. (MR :gl:`!11325`) @@ -157,3 +156,11 @@ 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``, ``tolerated_inactivity_period``, + ``consensus_key_activation_delay``, ``slashable_deposits_period`` (MR + :gl:`!11188`, :gl:`!11280`, :gl:`!11279`, :gl:`!11629`) diff --git a/docs/user/key-management.rst b/docs/user/key-management.rst index 67aa4018b0571f97f3deabd3fc7252fffdc3e641..0e09b01c883d8761b671e80737b42c4565d7c76e 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. diff --git a/src/proto_alpha/lib_delegate/baking_nonces.ml b/src/proto_alpha/lib_delegate/baking_nonces.ml index 515e429e75056f1b9b5bb7ac3d7ce17aac368d97..56cd2e990f4cc2f0cc43d059f79a6f26df691573 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 3fa2f03dc6af6ea75f2a5e1a9c58b7d0ecc16428..3feb1ddcf0254b5ad9d1f81b1c64dcce2f3535dd 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 92466e1c6776b650ec352d8c96b4d0900ed5b1f8..2ea7877721f755da6f157d3a1e12b93d3afbe1c1 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; @@ -255,7 +254,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; @@ -335,7 +334,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; @@ -371,7 +369,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/adaptive_issuance_services.mli b/src/proto_alpha/lib_protocol/adaptive_issuance_services.mli index 4f10608fc2d1acb9674f4840ee0db33a538d8835..04c6c96b10726b6a0133843cf8ede6a9b8478814 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 7644e6df755087c12a318ba5a160a558bc0f12fd..f7f77fab71e015c11c389dc73550a249f22c2182 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 4f007628d215fe67b2b4267a1ee2fc87cbefcaf3..ac58aa860691362dfe95584e7f0acf0e8b8fd850 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 409b938cdf175777745894f6a062745ecb299ab8..4d06cd4ab584c1cf50b8cf87d4d7777da40576fd 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -890,7 +890,6 @@ module Constants : sig } type t = { - preserved_cycles : int; consensus_rights_delay : int; blocks_preservation_cycles : int; delegate_parameters_activation_delay : int; @@ -956,8 +955,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 @@ -2346,9 +2343,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. *) @@ -2358,7 +2355,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. @@ -2499,7 +2496,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/constants_parametric_repr.ml b/src/proto_alpha/lib_protocol/constants_parametric_repr.ml index cea14f53859b02c60df4d8eebe049d7f914bd442..345a9ed22897bde583fb0f0b0ff418b400a6f455 100644 --- a/src/proto_alpha/lib_protocol/constants_parametric_repr.ml +++ b/src/proto_alpha/lib_protocol/constants_parametric_repr.ml @@ -172,7 +172,6 @@ type issuance_weights = { } type t = { - preserved_cycles : int; consensus_rights_delay : int; blocks_preservation_cycles : int; delegate_parameters_activation_delay : int; @@ -519,8 +518,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, @@ -559,8 +557,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, @@ -600,7 +597,6 @@ let encoding = (adaptive_issuance, direct_ticket_spending_enable) ) ) ) ) ) ) ) -> { - preserved_cycles; consensus_rights_delay; blocks_preservation_cycles; delegate_parameters_activation_delay; @@ -644,8 +640,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 7bb25c0804263cf3f2594ef658610ea1c4eb59b2..b3f4d88a41b71ccf69342a664c89253b0e572495 100644 --- a/src/proto_alpha/lib_protocol/constants_parametric_repr.mli +++ b/src/proto_alpha/lib_protocol/constants_parametric_repr.mli @@ -171,7 +171,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 1a20937146cf52ee9016422cb82510031ab23420..aca507fd1ba359cad6d6dd31422019384a1738cf 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 e79f27fb406f472ea133a4291241f236006ae607..d64fe88584ec3e355631007505681bde7279c981 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/delegate_activation_storage.ml b/src/proto_alpha/lib_protocol/delegate_activation_storage.ml index 357d339d144a815618537265bc17428bc2e69221..0f064f4955208708abd30a5adef64ce375ba43f4 100644 --- a/src/proto_alpha/lib_protocol/delegate_activation_storage.ml +++ b/src/proto_alpha/lib_protocol/delegate_activation_storage.ml @@ -60,13 +60,13 @@ let set_active ctxt delegate = let* inactive = is_inactive ctxt delegate in let current_cycle = (Raw_context.current_level ctxt).cycle in let tolerance = Constants_storage.tolerated_inactivity_period ctxt in - let preserved_cycles = Constants_storage.preserved_cycles ctxt in + 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 `tolerance` cycles after the current cycle before to be deactivated. - if the delegate is new or inactive, we give it additionally - `preserved_cycles` because the delegate needs this number of cycles to - receive rights, so `tolerance + preserved_cycles` in total. *) + `consensus_rights_delay` because the delegate needs this number of cycles to + receive rights, so `tolerance + 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 @@ -75,10 +75,10 @@ let set_active ctxt delegate = in let last_active_cycle = match current_last_active_cycle with - | None -> Cycle_repr.add current_cycle (tolerance + preserved_cycles) + | None -> Cycle_repr.add current_cycle (tolerance + consensus_rights_delay) | Some current_last_active_cycle -> let delay = - if inactive then tolerance + preserved_cycles else tolerance + 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 diff --git a/src/proto_alpha/lib_protocol/delegate_consensus_key.ml b/src/proto_alpha/lib_protocol/delegate_consensus_key.ml index 230c091660d3362e1c77655df1a7cb41b2bcd42b..e08d7a6327fb6e884d7f50b5d20c1b4e8a28f709 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 bc72d26f6ec36b51b60aad70599bf48437b7a0ca..5244a8052c98a2b8417712a597a767a26c8f4344 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 @@ -227,10 +229,10 @@ let cycle_end ctxt last_cycle = return (ctxt, balance_updates, deactivated_delegates) let init_first_cycles ctxt = - 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 Delegate_sampler.select_distribution_for_cycle ctxt 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 a28d60bcdd0a1d4beae8679f650dd8684406f8a1..c1ae9833055638128c342607a27fca56dd4468ab 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 82a31b4058350c798544a6cf59c5342848e01607..d0adde3d981b887506b77fcd57ffce260b279d36 100644 --- a/src/proto_alpha/lib_protocol/delegate_sampler.ml +++ b/src/proto_alpha/lib_protocol/delegate_sampler.ml @@ -227,8 +227,8 @@ let select_distribution_for_cycle ctxt cycle = Lwt.return (Raw_context.init_sampler_for_cycle ctxt cycle seed state) let select_new_distribution_at_cycle_end ctxt ~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 for_cycle let clear_outdated_sampling_data ctxt ~new_cycle = diff --git a/src/proto_alpha/lib_protocol/raw_context.ml b/src/proto_alpha/lib_protocol/raw_context.ml index b452b6a22ff9c8fe9489201d50800d2a7d666571..d5350aad160b37b244b12ca83899701d5aecf3bc 100644 --- a/src/proto_alpha/lib_protocol/raw_context.ml +++ b/src/proto_alpha/lib_protocol/raw_context.ml @@ -1193,7 +1193,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; diff --git a/src/proto_alpha/lib_protocol/seed_storage.ml b/src/proto_alpha/lib_protocol/seed_storage.ml index 978929d90b32a82bc525a89ce95c4fdfacbadd0c..9409d20883cd5a3a0da83e4fceff8b2f625f4041 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 05bfce77d2acb8c28ce5ea92c3a12a13ad64ca85..f99b047eb9e9a0ead58c62e68faee1bbff8d2ca5 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 e637b4f9d55846a7d024aa87298b06753a940bfe..90fc59695f5e553947a304826dec852ac6a0dd6a 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 e7ab0f8c340e6ebc9191ac29c6a5d1b1facb2cf0..e3b6925fae187bd4149063a363c80fa428af3aec 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 d9a463767bfe4748d42364c8c284653a58600f26..dbd3fabb56b44fb1edbd75d08045ff1d358c9560 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/test/helpers/adaptive_issuance_helpers.ml b/src/proto_alpha/lib_protocol/test/helpers/adaptive_issuance_helpers.ml index e3e9c17c5aca76dee7d704fca927d5f1443ee062..f529f3d33d50bbfc9a8512bfe1594fd1dd95f98b 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 let slashed_pct = Q.(100 // 1 * slashed_pct_q |> to_int) 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 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 b32653e0f9d8bcb2d5d179daca02e76c34bcb38c..bb80ffdd5de67b1637cdb7cf19540787953ee2d2 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 f340de730bb001780bad730b84a4ff738b9c4f3b..6ed7a0b5c9378d7b92be7e9d8ee4b710cd7237e2 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 12207188ba2cccd2b209ba00a0de48f3f82c9755..a603b289a95afa24976050d97f922598613c268b 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 @@ -710,7 +710,6 @@ 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. *) @@ -832,20 +831,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 a20ee2eda10a9fa264224920a1a8dece587e7989..6dec06831d79bbdbf59ddb42c9abc4c6a25f2f9c 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 a3e31178aecda798228bd7d92a8f05a55476a0bb..112454d07b3cf8737706ea8ee880116a6fc810fc 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 9df2150df26672356802de469715264472c6c4ca..21eb46c06729bd571098880d28d890b8f9343b11 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 9af0c2c7c22fce5bac8cbcd7d076daaa4f2f557c..bba07acba2e9bb28404bf467f8da39601c44abf1 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 @@ -522,7 +521,7 @@ let test_launch_without_vote () = (fun block -> let current_cycle = Block.current_cycle block in Protocol.Alpha_context.Cycle.( - current_cycle <= add start_cycle constants.preserved_cycles)) + current_cycle <= add start_cycle constants.consensus_rights_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 0a4db254fc426385bf812540d1b938585fb9f5e4..561088f9eaa2509d277db8ed54bea1efbff49efb 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,9 +43,10 @@ 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 crd = constants.consensus_rights_delay in + let dpad = constants.delegate_parameters_activation_delay in let msp = Protocol.Constants_repr.max_slashing_period in - (pc + 1, pc + msp) + (dpad, crd + msp) (** Contains the functions and constants relative to logging.*) module Log_module = struct @@ -193,11 +194,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 +261,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 @@ -591,7 +593,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 *) @@ -1159,7 +1163,8 @@ let begin_test ~activate_ai ?(burn_rewards = false) ?(ns_enable_fork = 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 = @@ -1229,7 +1234,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 @@ -2016,7 +2021,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)) @@ -2026,7 +2031,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" @@ -2282,7 +2287,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 @@ -2303,7 +2308,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; @@ -2815,7 +2820,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 ~ns_enable_fork:false @@ -2831,11 +2836,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) + |+ Tag "wait enough cycles (consensus_rights_delay + 1)" + --> wait_n_cycles (consensus_rights_delay + 1) --> stake "delegate" amount --> check_snapshot_balances "init") @@ -2844,7 +2849,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 ~ns_enable_fork:false @@ -2858,7 +2863,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 () --> exclude_bakers ["delegate"] --> next_cycle @@ -2891,7 +2896,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 1581845e7cde2679a9054d08573bfac36a706d23..e8630f4a317e099f7c8125c532af5d1c71782aa5 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/unstaked_frozen_deposits_repr.mli b/src/proto_alpha/lib_protocol/unstaked_frozen_deposits_repr.mli index e37cb275602158e4ee840b6f70189387500cdc69..3e0f889edee87c6faf8fc13213b828c83c825078 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 b7da51a8c69e84710a21fe54096f5587e258f981..a1a622059d126ee4f906492a6620815f2c2c97d6 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. diff --git a/tezt/tests/consensus_key.ml b/tezt/tests/consensus_key.ml index e6cc9e6d41f27abaea4e5fc29691522f37305bb2..c9e192f5ec9649b548a0e675ad4f14614fa53a39 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 @@ -96,16 +96,16 @@ let test_update_consensus_key = let parameters = (* we update paramaters for faster testing: no need to wait 5 cycles for the consensus key to activate. *) - let p = - [ - (["blocks_per_cycle"], `Int blocks_per_cycle); - (["nonce_revelation_threshold"], `Int 2); - (["preserved_cycles"], `Int preserved_cycles); - ] + let consensus_rights_delay_str = + if Protocol.number protocol > Protocol.number Protocol.Oxford then + "consensus_rights_delay" + else "preserved_cycles" in - if Protocol.number protocol > Protocol.number Protocol.Oxford then - (["consensus_rights_delay"], `Int preserved_cycles) :: p - else p + [ + (["blocks_per_cycle"], `Int blocks_per_cycle); + (["nonce_revelation_threshold"], `Int 2); + ([consensus_rights_delay_str], `Int consensus_rights_delay); + ] in let* parameter_file = Protocol.write_parameter_file ~base:(Right (protocol, None)) parameters @@ -220,7 +220,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..." ; @@ -243,7 +246,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." ; @@ -261,7 +267,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 @@ -290,7 +298,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 @@ -474,7 +482,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 @@ -484,7 +492,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 @@ -598,7 +606,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 @@ -630,16 +638,16 @@ let register ?(regression = true) title test = let parameters = (* we update paramaters for faster testing: no need to wait 5 cycles for the consensus key to activate. *) - let p = - [ - (["blocks_per_cycle"], `Int blocks_per_cycle); - (["nonce_revelation_threshold"], `Int 2); - (["preserved_cycles"], `Int preserved_cycles); - ] + let consensus_rights_delay_str = + if Protocol.number protocol > Protocol.number Protocol.Oxford then + "consensus_rights_delay" + else "preserved_cycles" in - if Protocol.number protocol > Protocol.number Protocol.Oxford then - (["consensus_rights_delay"], `Int preserved_cycles) :: p - else p + [ + (["blocks_per_cycle"], `Int blocks_per_cycle); + (["nonce_revelation_threshold"], `Int 2); + ([consensus_rights_delay_str], `Int consensus_rights_delay); + ] in let* parameter_file = Protocol.write_parameter_file ~base:(Right (protocol, None)) parameters @@ -692,7 +700,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 @@ -718,7 +726,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 @@ -740,7 +748,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 @@ -767,10 +775,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 212c2fab70f9270a6f3dffbc49d9f064df292004..81655fa3668cd7ea84aec51719af0eb7d288373c 100644 --- a/tezt/tests/dal.ml +++ b/tezt/tests/dal.ml @@ -945,7 +945,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. *) @@ -964,7 +964,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 (* With [consensus_committee_size = 1024] slots in total, the new baker should get roughly n / 64 = 16 TB slots on average. So the probability that it is @@ -986,7 +990,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/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 0ef3de11e7d619f432ef27d54f9676767ba43828..94f53d83d55db4ca1e41dd349cd2a6bb56d06087 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,10 @@ "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, "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, + "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 dc78a7fa0ea2da6ec07735ece857af4a00d8276b..6209acaea7a305e8ee65c366abacb122a6cd908d 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,10 @@ "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, "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, + "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 567fb640fab7f5e07b4b7f7beb7d6475b0c85dc0..e014ca9015b2119ab63ad425785e54adb4c27c50 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,10 @@ "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, "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, + "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 866fdd6154de98c768e946e5f079dd0c0f7a40a9..224a13d8af43eb90a45bd75e0ae4a51f16c2ee20 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,10 @@ "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, "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, + "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 866fdd6154de98c768e946e5f079dd0c0f7a40a9..224a13d8af43eb90a45bd75e0ae4a51f16c2ee20 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,10 @@ "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, "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, + "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/protocol_migration.ml b/tezt/tests/protocol_migration.ml index 20012152fd762694cc0e18e7c5c66c2571fd6d41..fa1636a4181432a924543fe912b487392b6ef7bf 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