diff --git a/docs/alpha/adaptive_issuance.rst b/docs/alpha/adaptive_issuance.rst index 47ce7d3309b5c1e79c13b982fd67febf829a65f5..05100a590f81c3b004542d644d658222d3b99cd3 100644 --- a/docs/alpha/adaptive_issuance.rst +++ b/docs/alpha/adaptive_issuance.rst @@ -429,7 +429,7 @@ each block, but rather every 192 blocks. Where: -- ``blocks_per_commitment`` (192) is the interval in blocks between each revelation, both VDF and nonce. +- ``blocks_per_commitment`` (14) is the interval in blocks between each revelation, both VDF and nonce. The `RPC endpoint diff --git a/docs/alpha/consensus.rst b/docs/alpha/consensus.rst index d1e312c6c77ffcbeac9f59faca30e8b8c33d6e30..7fa87459863cd0f4a847fd37158ea3f263ea3409 100644 --- a/docs/alpha/consensus.rst +++ b/docs/alpha/consensus.rst @@ -271,11 +271,11 @@ that B only included attestations corresponding to ``584 = 5251 - 4667`` additio maximum ``2333`` extra attestations it could have theoretically included.) Finally, consider some delegate C, whose baking power at some cycle is 1% of the total stake. Note that his expected number of validator slots for that cycle is -``1/100 * BLOCKS_PER_CYCLE * CONSENSUS_COMMITTEE_SIZE = 1/100 * 10800 * 7000 = 756,000`` +``1/100 * BLOCKS_PER_CYCLE * CONSENSUS_COMMITTEE_SIZE = 1/100 * 1800 * 7000 = 126,000`` slots. Assume also that the attesting power of C's attestations -included during that cycle has been ``651,456`` slots. Given that this number is -bigger than the minimum required (``756,000 * 2 / 3``), it receives an attesting -reward of ``756,000 * 0.000761 = 575.316`` tez for that cycle. +included during that cycle has been ``91,456`` slots. Given that this number is +bigger than the minimum required (``126,000 * 2 / 3``), it receives an attesting +reward of ``126,000 * 0.000761 = 95.886`` tez for that cycle. .. _slashing_alpha: @@ -382,7 +382,7 @@ Consensus related protocol parameters * - ``MINIMAL_BLOCK_DELAY`` - 8s * - ``BLOCKS_PER_CYCLE`` - - 10800 + - 1800 * - ``DELAY_INCREMENT_PER_ROUND`` - 4s * - ``CONSENSUS_RIGHTS_DELAY`` diff --git a/docs/alpha/proof_of_stake.rst b/docs/alpha/proof_of_stake.rst index c1a19a55dd1a08d2a64aae85b82b31e1939825ef..67c8200643a910cbc949b5e118c1f851fe7e229c 100644 --- a/docs/alpha/proof_of_stake.rst +++ b/docs/alpha/proof_of_stake.rst @@ -185,7 +185,7 @@ Proof-of-stake parameters * - Parameter name - Parameter value * - ``BLOCKS_PER_CYCLE`` - - 10800 blocks + - 1800 blocks * - ``CONSENSUS_RIGHTS_DELAY`` - 2 cycles * - ``MINIMAL_STAKE`` diff --git a/docs/alpha/randomness_generation.rst b/docs/alpha/randomness_generation.rst index 824e1961efa8ada27e08b2db80b0049033753302..ded54c7d1851effe337370d9a4b790e46a425b00 100644 --- a/docs/alpha/randomness_generation.rst +++ b/docs/alpha/randomness_generation.rst @@ -154,15 +154,15 @@ Randomness generation parameters * - Parameter name - Parameter value * - ``BLOCKS_PER_COMMITMENT`` - - 84 blocks + - 14 blocks * - ``NONCE_REVELATION_THRESHOLD`` - - 300 blocks + - 150 blocks * - ``MAX_ANON_OPS_PER_BLOCK`` - 132 revelations * - ``SEED_NONCE_REVELATION_TIP_WEIGHT`` - 1 * - ``VDF_DIFFICULTY`` - - 2,400,000,000 + - 1,200,000,000 The variables ``BLOCKS_PER_CYCLE`` and ``CONSENSUS_RIGHTS_DELAY`` are already defined in the :doc:`proof of stake ` page. diff --git a/docs/alpha/staking.rst b/docs/alpha/staking.rst index 6a3c8fbad9efe6556e3100c4adc94b65fb6685dd..979e8c9058064903a59d3899b647f03c754a33ee 100644 --- a/docs/alpha/staking.rst +++ b/docs/alpha/staking.rst @@ -103,7 +103,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 -``DELEGATE_PARAMETERS_ACTIVATION_DELAY`` (currently 5) cycles later. +``DELEGATE_PARAMETERS_ACTIVATION_DELAY`` (currently 30) cycles later. :: diff --git a/docs/alpha/voting.rst b/docs/alpha/voting.rst index 2fcd53ed60774f54db9e2e3dc4b5b71bc44f714b..bfb7d583a57d45a6a9579b75451edcac9c9c995c 100644 --- a/docs/alpha/voting.rst +++ b/docs/alpha/voting.rst @@ -16,7 +16,7 @@ Periods ------- The amendment process consists of five *periods*. Each period lasts -for ``CYCLES_PER_VOTING_PERIOD`` = 14 cycles (that is, around 14 +for ``CYCLES_PER_VOTING_PERIOD`` = 84 cycles (that is, around 14 days). The periods (listed below) typically succeed one to another for a total duration of approximately 2 months and a half, after which the whole amendment process starts again. diff --git a/docs/protocols/alpha.rst b/docs/protocols/alpha.rst index ff806f329b7bfb382dabc3f68773cf0b53f73fee..5da70a609501984682ef430330efc6cce1f2d463 100644 --- a/docs/protocols/alpha.rst +++ b/docs/protocols/alpha.rst @@ -44,7 +44,33 @@ Errors Protocol parameters ------------------- - +- Lowered the number of blocks per cycle (``blocks_per_cycle``) from + 10800 (~1 day) to 1800 (~4 hours) on mainnet (with 8-second minimal + block time). (MR :gl:`!17583`) + + - On ghostnet where minimal block time is 4s, lowered + ``blocks_per_cycle`` from 10800 (~12 hours) to 3600 (~4 + hours). (MR :gl:`!17583`) + +- In order for the duration of voting periods to stay about the same, + updated the number of cycles per voting period + (``cycles_per_voting_period``) on mainnet from 14 cycles (that is, + ~14 days with old cycle duration) to 84 cycles (~14 days with new + cycle duration). (MR :gl:`!17583`) + +- In order to keep the same duration in days for the activation of + delegate parameters, updated the number of cycles after which + submitted delegate parameters take effect + (``delegate_parameters_activation_delay``) on mainnet from 5 cycles + (that is, ~5 days with old cycle duration) to 30 cycles (~5 days + with new cycle duration). (MR :gl:`!17583`) + +- Reduced blocks per commitment (``blocks_per_commitment``) to 14 to + keep the number of nonces per cycle to 128. (:gl:`!17583`) + +- Reduced the nonce revelation period (``nonce_revelation_threshold``) + from 300 blocks to 150 blocks. Reduced accordingly the VDF + difficulty (``vdf_difficulty``) as well. (:gl:`!17583`) Bug Fixes --------- diff --git a/src/proto_alpha/lib_parameters/default_parameters.ml b/src/proto_alpha/lib_parameters/default_parameters.ml index fc4a205dd8ca3fe8213ba3808a2457ef3fdc1420..c99076c0440eea9348a8219c8c3edb4d7ac13ef0 100644 --- a/src/proto_alpha/lib_parameters/default_parameters.ml +++ b/src/proto_alpha/lib_parameters/default_parameters.ml @@ -251,8 +251,11 @@ let constants_mainnet : Constants.Parametric.t = also be longer than the delay for unstake requests to become finalizable, to make possible for delegators to finish unstaking before the new parameters take effect if they are - unhappy with the change. *) - delegate_parameters_activation_delay = 5; + unhappy with the change. + + Current value is 5 days (30 cycles of 4 hours). + Last updated in protocol T. *) + delegate_parameters_activation_delay = 30; (* At the end of a cycle, a delegate gets deactivated if the chain has witnessed no consensus activity (baking, attesting) from it during the past [tolerated_inactivity_period] cycles, including @@ -275,30 +278,30 @@ let constants_mainnet : Constants.Parametric.t = blocks. Multiply it by [minimal_block_delay] to get the minimal duration of a cycle in seconds. - [blocks_per_cycle = 10800l] has been chosen so that cycles last - one day (24h) (plus drift from non-zero rounds) on mainnet - where [minimal_block_delay] is 8s, and half a day (12h) on - ghostnet where [minimal_block_delay] is 4s. + [blocks_per_cycle = 1800l] has been chosen so that cycles last + 4 hours (plus drift from non-zero rounds) on mainnet + where [minimal_block_delay] is 8s. - Last updated in protocol R. *) - blocks_per_cycle = 10800l; + Last updated in protocol T. *) + blocks_per_cycle = 1800l; (* Each [blocks_per_commitment] blocks, the block producer has to commit on a nonce. Currently we target 128 nonces per cycle in order to ensure the nonces are produced by sufficiently many different bakers. (blocks_per_commitment = blocks_per_cycle / 128) Don't forget to update cycles-eras when updating this parameter. - Last updated in protocol S. + Last updated in protocol T. *) - blocks_per_commitment = 84l; + blocks_per_commitment = 14l; (* Duration in levels of the nonce revelation phase (which precedes the VDF phase). - Last updated in protocol S. *) - nonce_revelation_threshold = 300l; + Last updated in protocol T. *) + nonce_revelation_threshold = 150l; (* [cycles_per_voting_period] is the duration of any voting period. + It is currently 14 days (84 cycles of 4 hours). - Last updated in protocol R. *) - cycles_per_voting_period = 14l; + Last updated in protocol T. *) + cycles_per_voting_period = 84l; hard_gas_limit_per_operation = Gas.Arith.(integral_of_int_exn 1_040_000); hard_gas_limit_per_block = Gas.Arith.(integral_of_int_exn 1_386_666); (* When reducing blocks time, consider adapting this constant so @@ -307,14 +310,14 @@ let constants_mainnet : Constants.Parametric.t = minimal_stake = Tez.(mul_exn one 6_000); minimal_frozen_stake = Tez.(mul_exn one 600); (* VDF's difficulty must be a multiple of `nonce_revelation_threshold` times - the block time. At the moment it is equal to 2400M = 2400 * 5 * 0.2M with - - 2400 ~= 300 * 8 that is nonce_revelation_threshold * block time + the block time. At the moment it is equal to 1200M = 1200 * 5 * 0.2M with + - 1200 ~= 150 * 8 that is nonce_revelation_threshold * block time - 0.2M ~= number of modular squaring per second on benchmark machine with 2.8GHz CPU - 5: security factor (strictly higher than the ratio between highest CPU clock rate and benchmark machine that is 9.12/2.8 ~= 3. - Last updated in protocol S. *) - vdf_difficulty = 2_400_000_000L; + Last updated in protocol T. *) + vdf_difficulty = 1_200_000_000L; origination_size = 257; issuance_weights = { diff --git a/src/proto_alpha/lib_protocol/raw_context.ml b/src/proto_alpha/lib_protocol/raw_context.ml index 919dcfc69a37a1555effca7fe1e9c4ab14f6a396..ec2b289a4d2da0f5c22dce50f0eaf16d35a70a18 100644 --- a/src/proto_alpha/lib_protocol/raw_context.ml +++ b/src/proto_alpha/lib_protocol/raw_context.ml @@ -986,6 +986,80 @@ let get_previous_protocol_constants ctxt = (* Please add here any code that should be removed at the next automatic protocol snapshot *) +let update_cycle_eras ctxt level ~prev_blocks_per_cycle ~new_blocks_per_cycle + ~new_blocks_per_commitment ~prev_blocks_per_commitment = + let open Lwt_result_syntax in + let* cycle_eras = get_cycle_eras ctxt in + let*? new_cycle_eras = + Level_repr.update_cycle_eras + cycle_eras + ~level + ~prev_blocks_per_cycle + ~new_blocks_per_cycle + ~prev_blocks_per_commitment + ~new_blocks_per_commitment + in + set_cycle_eras ctxt new_cycle_eras + +type delays = { + blocks_per_cycle : int32; + delegate_parameters_activation_delay : int; + cycles_per_voting_period : int32; + blocks_per_commitment : int32; + nonce_revelation_threshold : int32; + vdf_difficulty : int64; +} + +let new_constants_four_hours_cycles ~preserve_duration_in_days + ~previous_minimal_block_delay ~minimal_block_delay + ~(previous_delays : delays) : delays = + let previous_minimal_block_delay_sec = + Period_repr.to_seconds previous_minimal_block_delay + in + let minimal_block_delay_sec = Period_repr.to_seconds minimal_block_delay in + let blocks_per_cycle = + Int64.(to_int32 (div (mul 4L 3600L) minimal_block_delay_sec)) + in + let blocks_per_commitment = Int32.(div blocks_per_cycle 128l) in + let nonce_revelation_threshold = Int32.(div (div blocks_per_cycle 2l) 6l) in + (* keeping half of the cycle for VDF result revelation and as margin to finish VDF computation *) + (* Then 1/6th to reveal nonces, 5/6th to compute VDF *) + let vdf_difficulty = + Int64.( + mul + (mul + (mul minimal_block_delay_sec 5L) + (of_int32 nonce_revelation_threshold)) + 200_000L) + in + let preserve_duration cst = + if not preserve_duration_in_days then cst + else + Int64.( + to_int32 + @@ div + (mul + (mul (of_int32 cst) previous_minimal_block_delay_sec) + (of_int32 previous_delays.blocks_per_cycle)) + (mul minimal_block_delay_sec (of_int32 blocks_per_cycle))) + in + let delegate_parameters_activation_delay = + Int32.to_int + @@ preserve_duration + (Int32.of_int previous_delays.delegate_parameters_activation_delay) + in + let cycles_per_voting_period = + preserve_duration previous_delays.cycles_per_voting_period + in + { + blocks_per_cycle; + delegate_parameters_activation_delay; + cycles_per_voting_period; + blocks_per_commitment; + nonce_revelation_threshold; + vdf_difficulty; + } + (* End of code to remove at next automatic protocol snapshot *) (* You should ensure that if the type `Constants_parametric_repr.t` is @@ -1499,59 +1573,110 @@ let prepare_first_block ~level ~timestamp chain_id ctxt = dal_rewards_weight; } in - let constants = - let ({ - consensus_rights_delay; - blocks_preservation_cycles; - delegate_parameters_activation_delay; - tolerated_inactivity_period; - blocks_per_cycle; - blocks_per_commitment; - nonce_revelation_threshold; - cycles_per_voting_period; - hard_gas_limit_per_operation; - hard_gas_limit_per_block; - proof_of_work_threshold; - minimal_stake; - minimal_frozen_stake; - vdf_difficulty; - origination_size; - max_operations_time_to_live; - issuance_weights = _; - cost_per_byte; - hard_storage_limit_per_operation; - quorum_min; - quorum_max; - min_proposal_quorum; - liquidity_baking_subsidy; - liquidity_baking_toggle_ema_threshold; - minimal_block_delay; - delay_increment_per_round; - consensus_committee_size; - consensus_threshold_size; - minimal_participation_ratio; - limit_of_delegation_over_baking; - percentage_of_frozen_deposits_slashed_per_double_baking; - max_slashing_per_block; - max_slashing_threshold; - (* The `testnet_dictator` should absolutely be None on mainnet *) - testnet_dictator; - initial_seed; - cache_script_size; - cache_stake_distribution_cycles; - cache_sampler_state_cycles; - dal = _; - sc_rollup = _; - zk_rollup = _; - adaptive_issuance = _; - direct_ticket_spending_enable; - aggregate_attestation = _; - allow_tz4_delegate_enable = _; - all_bakers_attest_activation_level; - } - : Previous.t) = - c + let ({ + consensus_rights_delay; + blocks_preservation_cycles; + delegate_parameters_activation_delay; + tolerated_inactivity_period; + blocks_per_cycle; + blocks_per_commitment; + nonce_revelation_threshold; + cycles_per_voting_period; + hard_gas_limit_per_operation; + hard_gas_limit_per_block; + proof_of_work_threshold; + minimal_stake; + minimal_frozen_stake; + vdf_difficulty; + origination_size; + max_operations_time_to_live; + issuance_weights = _; + cost_per_byte; + hard_storage_limit_per_operation; + quorum_min; + quorum_max; + min_proposal_quorum; + liquidity_baking_subsidy; + liquidity_baking_toggle_ema_threshold; + minimal_block_delay; + delay_increment_per_round; + consensus_committee_size; + consensus_threshold_size; + minimal_participation_ratio; + limit_of_delegation_over_baking; + percentage_of_frozen_deposits_slashed_per_double_baking; + max_slashing_per_block; + max_slashing_threshold; + (* The `testnet_dictator` should absolutely be None on mainnet *) + testnet_dictator; + initial_seed; + cache_script_size; + cache_stake_distribution_cycles; + cache_sampler_state_cycles; + dal = _; + sc_rollup = _; + zk_rollup = _; + adaptive_issuance = _; + direct_ticket_spending_enable; + aggregate_attestation = _; + allow_tz4_delegate_enable = _; + all_bakers_attest_activation_level; + } + : Previous.t) = + c + in + let is_new_constants = + (* This check is used to trigger the constant changes at + migration on this protocol for mainnet and ghostnet with + blocks_per_cycle = 10800l *) + Compare.Int32.(c.blocks_per_cycle = 10800l) + in + let { + blocks_per_cycle; + delegate_parameters_activation_delay; + cycles_per_voting_period; + blocks_per_commitment; + nonce_revelation_threshold; + vdf_difficulty; + } = + let previous_delays = + { + blocks_per_cycle; + blocks_per_commitment; + delegate_parameters_activation_delay; + cycles_per_voting_period; + nonce_revelation_threshold; + vdf_difficulty; + } in + if is_new_constants then + (* we keep the same duration in days for the + [cycles_per_voting_period] and + [delegate_parameters_activation_delay] protocol + constants on mainnet *) + let preserve_duration_in_days = + Compare.Int64.(Period_repr.to_seconds c.minimal_block_delay = 8L) + in + (* [minimal_block_delay] is the same for proto S and T *) + new_constants_four_hours_cycles + ~preserve_duration_in_days + ~previous_minimal_block_delay:c.minimal_block_delay + ~minimal_block_delay:c.minimal_block_delay + ~previous_delays + else previous_delays + in + let* ctxt = + if is_new_constants then + update_cycle_eras + ctxt + level + ~prev_blocks_per_cycle:c.blocks_per_cycle + ~new_blocks_per_cycle:blocks_per_cycle + ~prev_blocks_per_commitment:c.blocks_per_commitment + ~new_blocks_per_commitment:blocks_per_commitment + else return ctxt + in + let constants = { Constants_parametric_repr.consensus_rights_delay; blocks_preservation_cycles; @@ -1603,7 +1728,6 @@ let prepare_first_block ~level ~timestamp chain_id ctxt = } in let*! ctxt = add_constants ctxt constants in - return (ctxt, Some c) (* End of alpha predecessor stitching. Comment used for automatic snapshot *) in diff --git a/src/proto_alpha/lib_protocol/test/integration/test_constants.ml b/src/proto_alpha/lib_protocol/test/integration/test_constants.ml index 663692810648eeec8d5fa186dba3acedbde82ac5..d959160a10b84bc6d058dd7b9f32acf419571218 100644 --- a/src/proto_alpha/lib_protocol/test/integration/test_constants.ml +++ b/src/proto_alpha/lib_protocol/test/integration/test_constants.ml @@ -134,23 +134,31 @@ let cycles_to_period let*?@ res = Alpha_context.Period.mult c one_cycle_period in return res +type duration = Days of int32 | Hours of int32 + let check_protocol_time_correlation - ~(constants : Protocol.Alpha_context.Constants.Parametric.t) ~cycles ~days = + ~(constants : Protocol.Alpha_context.Constants.Parametric.t) ~cycles + ~duration = let open Lwt_result_wrap_syntax in let open Protocol in - let days_to_period x = - let*?@ res = Protocol.Alpha_context.Period.(mult x one_day) in + let duration_to_period x = + let x, period = + match x with + | Days x -> (x, Protocol.Alpha_context.Period.one_day) + | Hours x -> (x, Protocol.Alpha_context.Period.one_hour) + in + let*?@ res = Protocol.Alpha_context.Period.mult x period in return res in + let* duration = duration_to_period duration in let* constant = cycles_to_period ~constants cycles in - let* days = days_to_period days in Assert.equal ~loc:__LOC__ (fun x y -> Alpha_context.Period.compare x y = 0) - "constant in cycles is not equal to given days" + "constant in cycles is not equal to given period" Alpha_context.Period.pp constant - days + duration let () = register_test @@ -163,9 +171,9 @@ let () = constants.delay_increment_per_round >= Period.one_second) let () = - register_test ~title:"one cycle is 1 day" @@ fun () -> + register_test ~title:"one cycle is 4 hours" @@ fun () -> let constants = Default_parameters.constants_mainnet in - check_protocol_time_correlation ~constants ~cycles:1l ~days:1l + check_protocol_time_correlation ~constants ~cycles:1l ~duration:(Hours 4l) let () = register_test ~title:"voting period is 14 days" @@ fun () -> @@ -173,7 +181,7 @@ let () = check_protocol_time_correlation ~constants ~cycles:constants.cycles_per_voting_period - ~days:14l + ~duration:(Days 14l) let () = register_test ~title:"delegate parameters activation delay is 5 days" @@ -182,15 +190,15 @@ let () = check_protocol_time_correlation ~constants ~cycles:(Int32.of_int constants.delegate_parameters_activation_delay) - ~days:5l + ~duration:(Days 5l) let () = - register_test ~title:"tolerated inactivity period is 2 days" @@ fun () -> + register_test ~title:"tolerated inactivity period is 8 hours" @@ fun () -> let constants = Default_parameters.constants_mainnet in check_protocol_time_correlation ~constants ~cycles:(Int32.of_int constants.tolerated_inactivity_period) - ~days:2l + ~duration:(Hours 8l) let () = register_test ~title:"Nonce commitment per cycle is above 128" @@ fun () -> @@ -229,7 +237,7 @@ let () = ~title:"Nonce revelation period is short enough for VDF to fit in a cycle " @@ fun () -> let constants = Default_parameters.constants_mainnet in - Assert.lt + Assert.leq ~loc:__LOC__ Int32.compare "nonce_revelation_threshold is too short wrt blocks_per_cycle" @@ -249,7 +257,7 @@ let () = let constants = Default_parameters.constants_mainnet in let open Lwt_result_syntax in let* cycle_period = cycles_to_period ~constants 1l in - Assert.lt + Assert.leq ~loc:__LOC__ Int64.compare "nonce_revelation_threshold is too short wrt blocks_per_cycle"