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 987f775cccb34546fb2ba4bc4dbb93724b583a6a..dd725d1da048a48784453fd26f30218ef859312c 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 634598caf311ff82001f41ea8d3f4bca21f10d6c..1d95e4018c862fd5c4a8e29c98df91a85c6a9722 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`) 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/lib_shell_services/history_mode.ml b/src/lib_shell_services/history_mode.ml index d8931e385a3647e45b5179ecde758cd59025b076..93189e6de0e7a3009911ad83ca721a83379444fb 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 diff --git a/src/lib_store/unix/test/test_snapshots.ml b/src/lib_store/unix/test/test_snapshots.ml index c37eb88ac417a5ed6f1bc938ba57f43eacee615c..c61252c6d0eec84239c338bdaef360db7d0879ca 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 diff --git a/src/proto_alpha/lib_client/client_proto_args.ml b/src/proto_alpha/lib_client/client_proto_args.ml index 3c182ec5ae19252cd362e59c2466c837d7885594..5b86f37a491278fdfd665b443fd2e695f015bfed 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 = 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 1fd837f2dab9750baac7cd271cf7bdecd5ff2194..9cbe48cb23884e3451b54c1150d5cc7a224d72fa 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; @@ -256,7 +255,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; @@ -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/adaptive_issuance_services.ml b/src/proto_alpha/lib_protocol/adaptive_issuance_services.ml index 1386e85cdf8680a0d8c4e72ac3b563d7a28f11d2..7477b06ace46c83573bd73487453190a830c04ea 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_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 23fb8d1ef4e177e85bc6447d7a9a695544ed3148..c0b5b0193accf43bcd98be80a1e322226a1c0a54 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 @@ -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 @@ -293,7 +294,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) @@ -305,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/adaptive_issuance_storage.mli b/src/proto_alpha/lib_protocol/adaptive_issuance_storage.mli index 5305a216b73f16f36557eea8b1b6d2f339beae55..51da68de548cad0f5ee2f70b1a4d2dfd1345a8e8 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 e5e9609a1d7ecaa30303beea4bbb8d7e144d070f..92c43049d399f478d6a34af64095deaa86c05a7e 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,14 +943,16 @@ 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 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 val blocks_per_commitment : context -> int32 @@ -2326,9 +2327,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 +2339,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 +2463,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 b7b33e8b7bf8b27b18f21eaa595e6da952ee2f0a..6c8b2a14cc463fd1d80b0703cfd867e921c87e10 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/constants_parametric_repr.ml b/src/proto_alpha/lib_protocol/constants_parametric_repr.ml index d2765ea3a0e57edf22be4e61937e6f2bb8fefcbb..a716206129c45f74fcdf523162b2145b078963ea 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 5f93956f4291492f69b717f430b481aa8aea6535..f400a9af828e6916d67d0264ffa409ff7965d1f7 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 87755106dee6ad7257f3854c47cebe32bc5c52a5..a49027acbfc7c6dd3ba5a97c225f4bec16b5a48f 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 @@ -40,6 +36,26 @@ 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 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 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 77fa0186cf98abcb916af6a7521e61c5b4baa773..1a692a85f21e3c4a69650bc077bb56a5f0124f27 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 @@ -160,3 +158,24 @@ 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 + +(** 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 + +(** 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_activation_storage.ml b/src/proto_alpha/lib_protocol/delegate_activation_storage.ml index b34e822262d074126292b45972b108f25bdcc67d..dc8659bf7027d4bc24fc43a55a1777b8323e16d4 100644 --- a/src/proto_alpha/lib_protocol/delegate_activation_storage.ml +++ b/src/proto_alpha/lib_protocol/delegate_activation_storage.ml @@ -59,13 +59,14 @@ let set_active ctxt delegate = let open Lwt_result_syntax in let* inactive = is_inactive ctxt delegate in let current_cycle = (Raw_context.current_level ctxt).cycle in - let preserved_cycles = Constants_storage.preserved_cycles ctxt 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 + 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 +75,10 @@ let set_active ctxt delegate = in let last_active_cycle = match current_last_active_cycle with - | None -> Cycle_repr.add current_cycle (1 + (2 * preserved_cycles)) + | None -> Cycle_repr.add current_cycle (tolerance + consensus_rights_delay) | Some current_last_active_cycle -> let delay = - if inactive then 1 + (2 * preserved_cycles) else 1 + preserved_cycles + 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 495293c7d76019d4624f9f40cf31b9cda97e1be8..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 = @@ -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 = diff --git a/src/proto_alpha/lib_protocol/delegate_cycles.ml b/src/proto_alpha/lib_protocol/delegate_cycles.ml index 94510caa4530c691889c544a0b13bb6fbda111c4..3c31e6eacdfebb56d2b38e7fa4e726e1f520ff28 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 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 9ea36b58ec1cb608b20cd62011c063ea4da371b8..3a27129a7fda462a1c1813bd6f000b7e6b7b509a 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/delegate_services.ml b/src/proto_alpha/lib_protocol/delegate_services.ml index 748b4b89810d6d589301a31eb1fdd764496d5b05..cc45332438348a81cebac2814e1e47354663efd3 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 28af64f699446b9fe5fcc233e88321db3810ba35..7947b4917f3568b976259d33da00543da3f212d7 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/delegate_staking_parameters.ml b/src/proto_alpha/lib_protocol/delegate_staking_parameters.ml index 972394b65478545cc04f3ecf2cf3a01226d4864a..f74aafccb109230069d26ba8b804abb95977cec7 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 diff --git a/src/proto_alpha/lib_protocol/raw_context.ml b/src/proto_alpha/lib_protocol/raw_context.ml index 6379f8b5204235c7e065c500274267eefc455084..59d22719b2292e0265e9bc21e4492cadae5203c1 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; 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 8e7800a6959d26f3f45b1c0216957c75aa1a07d4..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 @@ -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/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 54319f6a6d59c96559036922d768b608cacc3838..f601b557e852a1b87bac6cc96606e4f0200eb4d9 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 c4c97f770f24b42d80392958af3897e543cb25c9..7fd753ec58b75ae751f9bf44430bf1049e5a38f4 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 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 110f98d24122ab51d563c9f9db015f7a5755ae16..0cf9e1a8b0cee1552bfa3ea153dd9d1e9c587d97 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 f888b375669e989643967126aa1dd6b9ac25854d..2f095db4db9ef07b5188fcdebeb4e95457a2155f 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 cbb75e645266483ef571f6f0e0533926c2cda56f..7878dbe7e9edc531b3ecafc901e71b2270a14b07 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 d3a487e4319ab4f0c6032fcf9291910a4cb10e7a..1bc783728a71344633939fbbb66edf47b06ac383 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" @@ -2092,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 @@ -2157,7 +2161,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 +2182,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 +2667,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 +2678,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 +2691,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 +2701,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 +2724,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/test/unit/test_consensus_key.ml b/src/proto_alpha/lib_protocol/test/unit/test_consensus_key.ml index 3fceadd3e376e6c0f4855938f0e849658ada5de0..2e90fbdf462f7e11b9ba0c6a3132423d0ba43168 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 diff --git a/src/proto_alpha/lib_protocol/unstake_requests_storage.ml b/src/proto_alpha/lib_protocol/unstake_requests_storage.ml index 044c2d643fde4bcb1b12601048020be25043f25e..a51b70645fde5506240e605af2d016fac964dd1b 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_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.ml b/src/proto_alpha/lib_protocol/unstaked_frozen_deposits_storage.ml index 2018e3c8cdb48edef85d7fe43b0179008bae4375..782d27216aded7fa1c6e1289c8f6e0d7b57d6402 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 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/bootstrap.ml b/tezt/tests/bootstrap.ml index b94998e4a0819dd5680c4d98b0315c77123a4652..02f0bf01a93275d02063dbc630d9182780abaaf5 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 diff --git a/tezt/tests/consensus_key.ml b/tezt/tests/consensus_key.ml index 59a377105c5a47c2f95ff5e3d21a6bb7447fabe4..d36f20298a8e47e347fe449b92e175a5c7e901d3 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 178a92f9f9771d81f0a52e5a2b0aaba49ed8bc84..ee88ae475b91b2cb72583e35a75cfa5d55802dc2 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/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 a20f0c53dcd66c4b784dedcf54740de25393a35d..cf277da737304a2df201ec7418754101cb99974b 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 0951e336ff0d262ee1caa242ffdbc8d64ac2ec52..bd0715b7929c5f0a83577a8c58367e9de8832b17 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 793d37798206b265b1444549f3e0ddfe9bd44927..3c664598220a0d89daee8ac3d9fed8655f8dfa48 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 4c760b0af97f198d203ff28c997e85ae70768dd1..5f3c3c8c8640217cf1ddf25c0a7250f9a6802d84 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 4c760b0af97f198d203ff28c997e85ae70768dd1..5f3c3c8c8640217cf1ddf25c0a7250f9a6802d84 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", 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