diff --git a/src/proto_alpha/lib_protocol/constants_parametric_previous_repr.ml b/src/proto_alpha/lib_protocol/constants_parametric_previous_repr.ml index 910fdbcde1a9f50c9d2f898ead2723ca269ce40c..42bf8352e3e43b5542fca71d8506da7bd56f62e8 100644 --- a/src/proto_alpha/lib_protocol/constants_parametric_previous_repr.ml +++ b/src/proto_alpha/lib_protocol/constants_parametric_previous_repr.ml @@ -83,24 +83,32 @@ let dal_encoding = you should ensure that there is a proper migration of the constants during context migration. See: `Raw_context.prepare_first_block` *) -type tx_rollup = { - enable : bool; - origination_size : int; - hard_size_limit_per_inbox : int; - hard_size_limit_per_message : int; - commitment_bond : Tez_repr.t; - finality_period : int; - withdraw_period : int; - max_inboxes_count : int; - max_messages_per_inbox : int; - max_commitments_count : int; - cost_per_byte_ema_factor : int; - max_ticket_payload_size : int; - max_withdrawals_per_batch : int; - rejection_max_proof_size : int; - sunset_level : int32; +type sc_rollup_reveal_hashing_schemes = {blake2B : Raw_level_repr.t} + +type sc_rollup_reveal_activation_level = { + raw_data : sc_rollup_reveal_hashing_schemes; + metadata : Raw_level_repr.t; + dal_page : Raw_level_repr.t; } +let sc_rollup_reveal_hashing_schemes_encoding = + let open Data_encoding in + conv + (fun t -> t.blake2B) + (fun blake2B -> {blake2B}) + (obj1 (req "Blake2B" Raw_level_repr.encoding)) + +let sc_rollup_reveal_activation_level_encoding : + sc_rollup_reveal_activation_level Data_encoding.t = + let open Data_encoding in + conv + (fun t -> (t.raw_data, t.metadata, t.dal_page)) + (fun (raw_data, metadata, dal_page) -> {raw_data; metadata; dal_page}) + (obj3 + (req "raw_data" sc_rollup_reveal_hashing_schemes_encoding) + (req "metadata" Raw_level_repr.encoding) + (req "dal_page" Raw_level_repr.encoding)) + type sc_rollup = { enable : bool; arith_pvm_enable : bool; @@ -115,12 +123,40 @@ type sc_rollup = { timeout_period_in_blocks : int; max_number_of_stored_cemented_commitments : int; max_number_of_parallel_games : int; + reveal_activation_level : sc_rollup_reveal_activation_level; } type zk_rollup = { enable : bool; origination_size : int; min_pending_to_process : int; + max_ticket_payload_size : int; +} + +type adaptive_rewards_params = { + issuance_ratio_min : Q.t; + issuance_ratio_max : Q.t; + max_bonus : int64; + growth_rate : int64; + center_dz : Q.t; + radius_dz : Q.t; +} + +type adaptive_issuance = { + global_limit_of_staking_over_baking : int; + edge_of_staking_over_delegation : int; + launch_ema_threshold : int32; + adaptive_rewards_params : adaptive_rewards_params; +} + +type issuance_weights = { + base_total_issued_per_minute : Tez_repr.t; + baking_reward_fixed_portion_weight : int; + baking_reward_bonus_weight : int; + attesting_reward_weight : int; + liquidity_baking_subsidy_weight : int; + seed_nonce_revelation_tip_weight : int; + vdf_revelation_tip_weight : int; } type t = { @@ -134,18 +170,15 @@ type t = { hard_gas_limit_per_block : Gas_limit_repr.Arith.integral; proof_of_work_threshold : int64; minimal_stake : Tez_repr.t; + minimal_frozen_stake : Tez_repr.t; vdf_difficulty : int64; - seed_nonce_revelation_tip : Tez_repr.t; origination_size : int; - baking_reward_fixed_portion : Tez_repr.t; - baking_reward_bonus_per_slot : Tez_repr.t; - endorsing_reward_per_slot : Tez_repr.t; + issuance_weights : issuance_weights; cost_per_byte : Tez_repr.t; hard_storage_limit_per_operation : Z.t; quorum_min : int32; quorum_max : int32; min_proposal_quorum : int32; - liquidity_baking_subsidy : Tez_repr.t; liquidity_baking_toggle_ema_threshold : int32; max_operations_time_to_live : int; minimal_block_delay : Period_repr.t; @@ -154,9 +187,9 @@ type t = { consensus_committee_size : int; consensus_threshold : int; max_slashing_period : int; - frozen_deposits_percentage : int; - double_baking_punishment : Tez_repr.t; - ratio_of_frozen_deposits_slashed_per_double_attestation : Ratio_repr.t; + limit_of_delegation_over_baking : int; + percentage_of_frozen_deposits_slashed_per_double_baking : int; + percentage_of_frozen_deposits_slashed_per_double_attestation : int; testnet_dictator : Signature.Public_key_hash.t option; initial_seed : State_hash.t option; (* If a new cache is added, please also modify the @@ -164,82 +197,12 @@ type t = { cache_script_size : int; cache_stake_distribution_cycles : int; cache_sampler_state_cycles : int; - tx_rollup : tx_rollup; dal : dal; sc_rollup : sc_rollup; zk_rollup : zk_rollup; + adaptive_issuance : adaptive_issuance; } -let tx_rollup_encoding = - let open Data_encoding in - conv - (fun (c : tx_rollup) -> - ( ( c.enable, - c.origination_size, - c.hard_size_limit_per_inbox, - c.hard_size_limit_per_message, - c.max_withdrawals_per_batch, - c.commitment_bond, - c.finality_period, - c.withdraw_period, - c.max_inboxes_count, - c.max_messages_per_inbox ), - ( c.max_commitments_count, - c.cost_per_byte_ema_factor, - c.max_ticket_payload_size, - c.rejection_max_proof_size, - c.sunset_level ) )) - (fun ( ( tx_rollup_enable, - tx_rollup_origination_size, - tx_rollup_hard_size_limit_per_inbox, - tx_rollup_hard_size_limit_per_message, - tx_rollup_max_withdrawals_per_batch, - tx_rollup_commitment_bond, - tx_rollup_finality_period, - tx_rollup_withdraw_period, - tx_rollup_max_inboxes_count, - tx_rollup_max_messages_per_inbox ), - ( tx_rollup_max_commitments_count, - tx_rollup_cost_per_byte_ema_factor, - tx_rollup_max_ticket_payload_size, - tx_rollup_rejection_max_proof_size, - tx_rollup_sunset_level ) ) -> - { - enable = tx_rollup_enable; - origination_size = tx_rollup_origination_size; - hard_size_limit_per_inbox = tx_rollup_hard_size_limit_per_inbox; - hard_size_limit_per_message = tx_rollup_hard_size_limit_per_message; - max_withdrawals_per_batch = tx_rollup_max_withdrawals_per_batch; - commitment_bond = tx_rollup_commitment_bond; - finality_period = tx_rollup_finality_period; - withdraw_period = tx_rollup_withdraw_period; - max_inboxes_count = tx_rollup_max_inboxes_count; - max_messages_per_inbox = tx_rollup_max_messages_per_inbox; - max_commitments_count = tx_rollup_max_commitments_count; - cost_per_byte_ema_factor = tx_rollup_cost_per_byte_ema_factor; - max_ticket_payload_size = tx_rollup_max_ticket_payload_size; - rejection_max_proof_size = tx_rollup_rejection_max_proof_size; - sunset_level = tx_rollup_sunset_level; - }) - (merge_objs - (obj10 - (req "tx_rollup_enable" bool) - (req "tx_rollup_origination_size" int31) - (req "tx_rollup_hard_size_limit_per_inbox" int31) - (req "tx_rollup_hard_size_limit_per_message" int31) - (req "tx_rollup_max_withdrawals_per_batch" int31) - (req "tx_rollup_commitment_bond" Tez_repr.encoding) - (req "tx_rollup_finality_period" int31) - (req "tx_rollup_withdraw_period" int31) - (req "tx_rollup_max_inboxes_count" int31) - (req "tx_rollup_max_messages_per_inbox" int31)) - (obj5 - (req "tx_rollup_max_commitments_count" int31) - (req "tx_rollup_cost_per_byte_ema_factor" int31) - (req "tx_rollup_max_ticket_payload_size" int31) - (req "tx_rollup_rejection_max_proof_size" int31) - (req "tx_rollup_sunset_level" int32))) - let sc_rollup_encoding = let open Data_encoding in conv @@ -256,7 +219,8 @@ let sc_rollup_encoding = ( c.number_of_sections_in_dissection, c.timeout_period_in_blocks, c.max_number_of_stored_cemented_commitments, - c.max_number_of_parallel_games ) )) + c.max_number_of_parallel_games, + c.reveal_activation_level ) )) (fun ( ( sc_rollup_enable, sc_rollup_arith_pvm_enable, sc_rollup_origination_size, @@ -269,7 +233,8 @@ let sc_rollup_encoding = ( sc_rollup_number_of_sections_in_dissection, sc_rollup_timeout_period_in_blocks, sc_rollup_max_number_of_cemented_commitments, - sc_rollup_max_number_of_parallel_games ) ) -> + sc_rollup_max_number_of_parallel_games, + sc_rollup_reveal_activation_level ) ) -> { enable = sc_rollup_enable; arith_pvm_enable = sc_rollup_arith_pvm_enable; @@ -286,6 +251,7 @@ let sc_rollup_encoding = max_number_of_stored_cemented_commitments = sc_rollup_max_number_of_cemented_commitments; max_number_of_parallel_games = sc_rollup_max_number_of_parallel_games; + reveal_activation_level = sc_rollup_reveal_activation_level; }) (merge_objs (obj9 @@ -298,29 +264,189 @@ let sc_rollup_encoding = (req "smart_rollup_max_lookahead_in_blocks" int32) (req "smart_rollup_max_active_outbox_levels" int32) (req "smart_rollup_max_outbox_messages_per_level" int31)) - (obj4 + (obj5 (req "smart_rollup_number_of_sections_in_dissection" uint8) (req "smart_rollup_timeout_period_in_blocks" int31) (req "smart_rollup_max_number_of_cemented_commitments" int31) - (req "smart_rollup_max_number_of_parallel_games" int31))) + (req "smart_rollup_max_number_of_parallel_games" int31) + (req + "smart_rollup_reveal_activation_level" + sc_rollup_reveal_activation_level_encoding))) let zk_rollup_encoding = let open Data_encoding in conv - (fun ({enable; origination_size; min_pending_to_process} : zk_rollup) -> - (enable, origination_size, min_pending_to_process)) + (fun ({ + enable; + origination_size; + min_pending_to_process; + max_ticket_payload_size; + } : + zk_rollup) -> + (enable, origination_size, min_pending_to_process, max_ticket_payload_size)) (fun ( zk_rollup_enable, zk_rollup_origination_size, - zk_rollup_min_pending_to_process ) -> + zk_rollup_min_pending_to_process, + zk_rollup_max_ticket_payload_size ) -> { enable = zk_rollup_enable; origination_size = zk_rollup_origination_size; min_pending_to_process = zk_rollup_min_pending_to_process; + max_ticket_payload_size = zk_rollup_max_ticket_payload_size; }) - (obj3 + (obj4 (req "zk_rollup_enable" bool) (req "zk_rollup_origination_size" int31) - (req "zk_rollup_min_pending_to_process" int31)) + (req "zk_rollup_min_pending_to_process" int31) + (req "zk_rollup_max_ticket_payload_size" int31)) + +let extremum_encoding = + Data_encoding.( + conv_with_guard + (fun Q.{num; den} -> (num, den)) + (fun (num, den) -> + if Compare.Z.(num > Z.zero && den > Z.zero) then Ok (Q.make num den) + else + Error + "Invalid Reward Extremum Parameter: only positive values allowed") + (obj2 (req "numerator" z) (req "denominator" z))) + +let center_encoding = + Data_encoding.( + conv_with_guard + (fun Q.{num; den} -> (num, den)) + (fun (num, den) -> + if Compare.Z.(num >= Z.zero && den > Z.zero && num <= den) then + Ok (Q.make num den) + else + Error + "Invalid Reward Parameter: dead zone center can only be between 0 \ + and 1") + (obj2 (req "numerator" z) (req "denominator" z))) + +let radius_encoding = + Data_encoding.( + conv_with_guard + (fun Q.{num; den} -> (num, den)) + (fun (num, den) -> + if Compare.Z.(num >= Z.zero && den > Z.zero) then Ok (Q.make num den) + else + Error + "Invalid Reward Parameter: dead zone radius must be non-negative") + (obj2 (req "numerator" z) (req "denominator" z))) + +let adaptive_rewards_params_encoding = + let open Data_encoding in + conv + (fun { + issuance_ratio_min; + issuance_ratio_max; + max_bonus; + growth_rate; + center_dz; + radius_dz; + } -> + ( issuance_ratio_min, + issuance_ratio_max, + max_bonus, + growth_rate, + center_dz, + radius_dz )) + (fun ( issuance_ratio_min, + issuance_ratio_max, + max_bonus, + growth_rate, + center_dz, + radius_dz ) -> + { + issuance_ratio_min; + issuance_ratio_max; + max_bonus; + growth_rate; + center_dz; + radius_dz; + }) + (obj6 + (req "issuance_ratio_min" extremum_encoding) + (req "issuance_ratio_max" extremum_encoding) + (req "max_bonus" int64) + (req "growth_rate" int64) + (req "center_dz" center_encoding) + (req "radius_dz" radius_encoding)) + +let adaptive_issuance_encoding = + let open Data_encoding in + conv + (fun { + global_limit_of_staking_over_baking; + edge_of_staking_over_delegation; + launch_ema_threshold; + adaptive_rewards_params; + } -> + ( global_limit_of_staking_over_baking, + edge_of_staking_over_delegation, + launch_ema_threshold, + adaptive_rewards_params )) + (fun ( global_limit_of_staking_over_baking, + edge_of_staking_over_delegation, + launch_ema_threshold, + adaptive_rewards_params ) -> + { + global_limit_of_staking_over_baking; + edge_of_staking_over_delegation; + launch_ema_threshold; + adaptive_rewards_params; + }) + (obj4 + (req "global_limit_of_staking_over_baking" uint8) + (req "edge_of_staking_over_delegation" uint8) + (req "adaptive_issuance_launch_ema_threshold" int32) + (req "adaptive_rewards_params" adaptive_rewards_params_encoding)) + +let issuance_weights_encoding = + let open Data_encoding in + conv + (fun ({ + base_total_issued_per_minute; + baking_reward_fixed_portion_weight; + baking_reward_bonus_weight; + attesting_reward_weight; + liquidity_baking_subsidy_weight; + seed_nonce_revelation_tip_weight; + vdf_revelation_tip_weight; + } : + issuance_weights) -> + ( base_total_issued_per_minute, + baking_reward_fixed_portion_weight, + baking_reward_bonus_weight, + attesting_reward_weight, + liquidity_baking_subsidy_weight, + seed_nonce_revelation_tip_weight, + vdf_revelation_tip_weight )) + (fun ( base_total_issued_per_minute, + baking_reward_fixed_portion_weight, + baking_reward_bonus_weight, + attesting_reward_weight, + liquidity_baking_subsidy_weight, + seed_nonce_revelation_tip_weight, + vdf_revelation_tip_weight ) -> + { + base_total_issued_per_minute; + baking_reward_fixed_portion_weight; + baking_reward_bonus_weight; + attesting_reward_weight; + liquidity_baking_subsidy_weight; + seed_nonce_revelation_tip_weight; + vdf_revelation_tip_weight; + }) + (obj7 + (req "base_total_issued_per_minute" Tez_repr.encoding) + (req "baking_reward_fixed_portion_weight" int31) + (req "baking_reward_bonus_weight" int31) + (req "attesting_reward_weight" int31) + (req "liquidity_baking_subsidy_weight" int31) + (req "seed_nonce_revelation_tip_weight" int31) + (req "vdf_revelation_tip_weight" int31)) let encoding = let open Data_encoding in @@ -336,18 +462,15 @@ let encoding = c.hard_gas_limit_per_block, c.proof_of_work_threshold, c.minimal_stake ), - ( ( c.vdf_difficulty, - c.seed_nonce_revelation_tip, + ( ( c.minimal_frozen_stake, + c.vdf_difficulty, c.origination_size, - c.baking_reward_fixed_portion, - c.baking_reward_bonus_per_slot, - c.endorsing_reward_per_slot, + c.issuance_weights, c.cost_per_byte, c.hard_storage_limit_per_operation, c.quorum_min ), ( ( c.quorum_max, c.min_proposal_quorum, - c.liquidity_baking_subsidy, c.liquidity_baking_toggle_ema_threshold, c.max_operations_time_to_live, c.minimal_block_delay, @@ -356,15 +479,16 @@ let encoding = c.consensus_threshold ), ( ( c.minimal_participation_ratio, c.max_slashing_period, - c.frozen_deposits_percentage, - c.double_baking_punishment, - c.ratio_of_frozen_deposits_slashed_per_double_attestation, + c.limit_of_delegation_over_baking, + c.percentage_of_frozen_deposits_slashed_per_double_baking, + c.percentage_of_frozen_deposits_slashed_per_double_attestation, c.testnet_dictator, c.initial_seed ), ( ( c.cache_script_size, c.cache_stake_distribution_cycles, c.cache_sampler_state_cycles ), - (c.tx_rollup, (c.dal, (c.sc_rollup, c.zk_rollup))) ) ) ) ) )) + (c.dal, ((c.sc_rollup, c.zk_rollup), c.adaptive_issuance)) ) ) + ) ) )) (fun ( ( preserved_cycles, blocks_per_cycle, blocks_per_commitment, @@ -375,18 +499,15 @@ let encoding = hard_gas_limit_per_block, proof_of_work_threshold, minimal_stake ), - ( ( vdf_difficulty, - seed_nonce_revelation_tip, + ( ( minimal_frozen_stake, + vdf_difficulty, origination_size, - baking_reward_fixed_portion, - baking_reward_bonus_per_slot, - endorsing_reward_per_slot, + 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, max_operations_time_to_live, minimal_block_delay, @@ -395,15 +516,15 @@ let encoding = consensus_threshold ), ( ( minimal_participation_ratio, max_slashing_period, - frozen_deposits_percentage, - double_baking_punishment, - ratio_of_frozen_deposits_slashed_per_double_attestation, + limit_of_delegation_over_baking, + percentage_of_frozen_deposits_slashed_per_double_baking, + percentage_of_frozen_deposits_slashed_per_double_attestation, testnet_dictator, initial_seed ), ( ( cache_script_size, cache_stake_distribution_cycles, cache_sampler_state_cycles ), - (tx_rollup, (dal, (sc_rollup, zk_rollup))) ) ) ) ) ) -> + (dal, ((sc_rollup, zk_rollup), adaptive_issuance)) ) ) ) ) ) -> { preserved_cycles; blocks_per_cycle; @@ -415,18 +536,15 @@ let encoding = hard_gas_limit_per_block; proof_of_work_threshold; minimal_stake; + minimal_frozen_stake; vdf_difficulty; - seed_nonce_revelation_tip; origination_size; - baking_reward_fixed_portion; - baking_reward_bonus_per_slot; - endorsing_reward_per_slot; + 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; max_operations_time_to_live; minimal_block_delay; @@ -435,18 +553,18 @@ let encoding = max_slashing_period; consensus_committee_size; consensus_threshold; - frozen_deposits_percentage; - double_baking_punishment; - ratio_of_frozen_deposits_slashed_per_double_attestation; + limit_of_delegation_over_baking; + percentage_of_frozen_deposits_slashed_per_double_baking; + percentage_of_frozen_deposits_slashed_per_double_attestation; testnet_dictator; initial_seed; cache_script_size; cache_stake_distribution_cycles; cache_sampler_state_cycles; - tx_rollup; dal; sc_rollup; zk_rollup; + adaptive_issuance; }) (merge_objs (obj10 @@ -465,21 +583,18 @@ let encoding = (req "proof_of_work_threshold" int64) (req "minimal_stake" Tez_repr.encoding)) (merge_objs - (obj9 + (obj7 + (req "minimal_frozen_stake" Tez_repr.encoding) (req "vdf_difficulty" int64) - (req "seed_nonce_revelation_tip" Tez_repr.encoding) (req "origination_size" int31) - (req "baking_reward_fixed_portion" Tez_repr.encoding) - (req "baking_reward_bonus_per_slot" Tez_repr.encoding) - (req "endorsing_reward_per_slot" Tez_repr.encoding) + (req "issuance_weights" issuance_weights_encoding) (req "cost_per_byte" Tez_repr.encoding) (req "hard_storage_limit_per_operation" z) (req "quorum_min" int32)) (merge_objs - (obj9 + (obj8 (req "quorum_max" int32) (req "min_proposal_quorum" int32) - (req "liquidity_baking_subsidy" Tez_repr.encoding) (req "liquidity_baking_toggle_ema_threshold" int32) (req "max_operations_time_to_live" int16) (req "minimal_block_delay" Period_repr.encoding) @@ -490,11 +605,13 @@ let encoding = (obj7 (req "minimal_participation_ratio" Ratio_repr.encoding) (req "max_slashing_period" int31) - (req "frozen_deposits_percentage" int31) - (req "double_baking_punishment" Tez_repr.encoding) + (req "limit_of_delegation_over_baking" uint8) + (req + "percentage_of_frozen_deposits_slashed_per_double_baking" + uint8) (req - "ratio_of_frozen_deposits_slashed_per_double_endorsement" - Ratio_repr.encoding) + "percentage_of_frozen_deposits_slashed_per_double_attestation" + uint8) (opt "testnet_dictator" Signature.Public_key_hash.encoding) (opt "initial_seed" State_hash.encoding)) (merge_objs @@ -503,7 +620,7 @@ let encoding = (req "cache_stake_distribution_cycles" int8) (req "cache_sampler_state_cycles" int8)) (merge_objs - tx_rollup_encoding + (obj1 (req "dal_parametric" dal_encoding)) (merge_objs - (obj1 (req "dal_parametric" dal_encoding)) - (merge_objs sc_rollup_encoding zk_rollup_encoding)))))))) + (merge_objs sc_rollup_encoding zk_rollup_encoding) + adaptive_issuance_encoding))))))) diff --git a/src/proto_alpha/lib_protocol/constants_parametric_previous_repr.mli b/src/proto_alpha/lib_protocol/constants_parametric_previous_repr.mli index 294790c41a079e428af872628d11cb61825aba62..2a5881d9663a938b51586a9e11b4bc299740911f 100644 --- a/src/proto_alpha/lib_protocol/constants_parametric_previous_repr.mli +++ b/src/proto_alpha/lib_protocol/constants_parametric_previous_repr.mli @@ -36,53 +36,13 @@ type dal = { val dal_encoding : dal Data_encoding.t -type tx_rollup = { - enable : bool; - origination_size : int; - (* the maximum amount of bytes messages can allocate in an inbox *) - hard_size_limit_per_inbox : int; - (* the maximum amount of bytes one batch can allocate in an inbox *) - hard_size_limit_per_message : int; - (* the amount of tez to bond a tx rollup commitment *) - commitment_bond : Tez_repr.t; - (* the number of blocks before a tx rollup block is final *) - finality_period : int; - (* the maximum number of levels that can be left unfinalized - before we stop accepting new inboxes for a tx rollup *) - (* the minimum number of blocks to wait before removing a finalised - commitment from the context. *) - withdraw_period : int; - max_inboxes_count : int; - (* the maximum number of messages in an inbox. This bounds the - size of a commitment. *) - max_messages_per_inbox : int; - (* the maximum number of finalized commitments, to ensure that - remove_commitment is ever called *) - max_commitments_count : int; - (* The number of blocks used to compute the ema factor determining - the cost per byte for new messages in the inbox. *) - cost_per_byte_ema_factor : int; - (* Tickets are transmitted in batches in the - [Tx_rollup_dispatch_tickets] operation. - - The semantics is that this operation is used to - concretize the withdraw orders emitted by the layer-2, - one layer-1 operation per messages of an - inbox. Therefore, it is of significant importance that - a valid batch does not produce a list of withdraw - orders which could not fit in a layer-1 operation. +type sc_rollup_reveal_hashing_schemes = {blake2B : Raw_level_repr.t} - With these values, at least 2048 bytes remain available - to store the rest of the operands of - [Tx_rollup_dispatch_tickets] (in practice, even more, - because we overapproximate the size of tickets). So we - are safe. *) - max_ticket_payload_size : int; - max_withdrawals_per_batch : int; - (* The maximum size, in bytes, of a Merkle proof. Operations which would - require proofs larger than this should be no-ops. *) - rejection_max_proof_size : int; - sunset_level : int32; +(** Associates reveal kinds to their activation level. *) +type sc_rollup_reveal_activation_level = { + raw_data : sc_rollup_reveal_hashing_schemes; + metadata : Raw_level_repr.t; + dal_page : Raw_level_repr.t; } type sc_rollup = { @@ -124,6 +84,8 @@ type sc_rollup = { max_number_of_stored_cemented_commitments : int; (* The maximum number of parallel games played by a given staker. *) max_number_of_parallel_games : int; + (* Activation's block level of reveal kinds. *) + reveal_activation_level : sc_rollup_reveal_activation_level; } type zk_rollup = { @@ -136,6 +98,44 @@ type zk_rollup = { That is, every update must process at least [min(length pending_list, min_pending_to_process)] pending operations. *) min_pending_to_process : int; + max_ticket_payload_size : int; +} + +type adaptive_rewards_params = { + issuance_ratio_min : (* Maximum yearly issuance rate *) Q.t; + issuance_ratio_max : (* Minimum yearly issuance rate *) Q.t; + max_bonus : (* Maximum issuance bonus value *) int64; + growth_rate : (* Bonus value's groth rate *) int64; + center_dz : (* Center for bonus *) Q.t; + radius_dz : + (* Minimum distance from center required for non-zero growth *) Q.t; +} + +type adaptive_issuance = { + global_limit_of_staking_over_baking + (* Global maximum stake tokens taken into account per baking token. Each baker can set their own lower limit. *) : + int; + edge_of_staking_over_delegation : + (* Weight of staking over delegation. *) int; + launch_ema_threshold : (* Threshold of the activation vote *) int32; + adaptive_rewards_params : + (* Parameters for the reward mechanism *) adaptive_rewards_params; +} + +type issuance_weights = { + (* [base_total_issued_per_minute] is the total amount of rewards expected to + be distributed every minute *) + base_total_issued_per_minute : Tez_repr.t; + (* The following fields represent the "weights" of the respective reward kinds. + The actual reward values are computed proportionally from the other weights + as a portion of the [base_total_issued_per_minute]. See the module + {!Delegate_rewards} for more details *) + baking_reward_fixed_portion_weight : int; + baking_reward_bonus_weight : int; + attesting_reward_weight : int; + liquidity_baking_subsidy_weight : int; + seed_nonce_revelation_tip_weight : int; + vdf_revelation_tip_weight : int; } type t = { @@ -149,19 +149,16 @@ type t = { hard_gas_limit_per_block : Gas_limit_repr.Arith.integral; proof_of_work_threshold : int64; minimal_stake : Tez_repr.t; + minimal_frozen_stake : Tez_repr.t; vdf_difficulty : int64; - seed_nonce_revelation_tip : Tez_repr.t; origination_size : int; - baking_reward_fixed_portion : Tez_repr.t; - baking_reward_bonus_per_slot : Tez_repr.t; - endorsing_reward_per_slot : Tez_repr.t; + issuance_weights : issuance_weights; cost_per_byte : Tez_repr.t; hard_storage_limit_per_operation : Z.t; quorum_min : int32; (* in centile of a percentage *) quorum_max : int32; min_proposal_quorum : int32; - liquidity_baking_subsidy : Tez_repr.t; liquidity_baking_toggle_ema_threshold : int32; max_operations_time_to_live : int; minimal_block_delay : Period_repr.t; @@ -173,10 +170,10 @@ type t = { (* in slots *) max_slashing_period : int; (* in cycles *) - frozen_deposits_percentage : int; - (* that is, (100 * delegated tz / own tz) *) - double_baking_punishment : Tez_repr.t; - ratio_of_frozen_deposits_slashed_per_double_attestation : Ratio_repr.t; + limit_of_delegation_over_baking : int; + (* upper bound on the (delegated tz / own frozen tz) ratio *) + percentage_of_frozen_deposits_slashed_per_double_baking : int; + percentage_of_frozen_deposits_slashed_per_double_attestation : int; testnet_dictator : Signature.Public_key_hash.t option; initial_seed : State_hash.t option; cache_script_size : int; @@ -185,10 +182,10 @@ type t = { (* in cycles *) cache_sampler_state_cycles : int; (* in cycles *) - tx_rollup : tx_rollup; dal : dal; sc_rollup : sc_rollup; zk_rollup : zk_rollup; + adaptive_issuance : adaptive_issuance; } val encoding : t Data_encoding.encoding diff --git a/src/proto_alpha/lib_protocol/init_storage.ml b/src/proto_alpha/lib_protocol/init_storage.ml index 22f3316fb066d0a5f62da36edb52d876897af20b..5bf24654482761a804a1bebfaef2a2b23ff4793a 100644 --- a/src/proto_alpha/lib_protocol/init_storage.ml +++ b/src/proto_alpha/lib_protocol/init_storage.ml @@ -103,135 +103,6 @@ let patch_script ctxt (address, hash, patched_code) = address ; return ctxt -(** Converts {Storage.Stake.Staking_balance} from {Tez_repr} to - {Stake_repr.Full}. Remove me in P. *) -let migrate_staking_balance_for_o ctxt = - let open Lwt_result_syntax in - let convert ctxt delegate staking_balance = - let delegate_contract = Contract_repr.Implicit delegate in - let* {current_amount = own_frozen; initial_amount = _} = - Frozen_deposits_storage.get ctxt delegate_contract - in - let delegated = - Tez_repr.sub_opt staking_balance own_frozen - |> Option.value ~default:Tez_repr.zero - in - let staked_frozen = Tez_repr.zero in - return (Stake_repr.Full.make ~own_frozen ~staked_frozen ~delegated) - in - Storage.Stake.Staking_balance_up_to_Nairobi.fold - ctxt - ~order:`Undefined - ~init:(ok ctxt) - ~f:(fun delegate staking_balance ctxt -> - let*? ctxt in - let* stake = convert ctxt delegate staking_balance in - Storage.Stake.Staking_balance.update ctxt delegate stake) - -(** Clear staking balance snapshots to avoid storing legacy values. - This should do nothing if the migration happens at a cycle - boundary, which is usually the case. -*) -let clear_staking_balance_snapshots_for_o ctxt = - let open Lwt_result_syntax in - let*! ctxt = - Storage.Stake.Staking_balance_up_to_Nairobi.Snapshot.clear ctxt - in - Storage.Stake.Last_snapshot.update ctxt 0 - -(** Converts {Storage.Stake.Total_active_stake} and - {Storage.Stake.Selected_distribution_for_cycle} from {Tez_repr} to - {Stake_repr}. - Remove me in P. *) -let migrate_stake_distribution_for_o ctxt = - let open Lwt_result_syntax in - let convert = - let limit_of_delegation_over_baking = - Constants_storage.limit_of_delegation_over_baking ctxt - in - fun old_stake -> - let frozen = - Tez_repr.div_exn old_stake (limit_of_delegation_over_baking + 1) - in - match Tez_repr.sub_opt old_stake frozen with - | Some delegated -> Stake_repr.make ~frozen ~delegated - | None -> Stake_repr.make ~frozen:old_stake ~delegated:Tez_repr.zero - in - let* ctxt = - Storage.Stake.Total_active_stake_up_to_Nairobi.fold - ctxt - ~order:`Undefined - ~init:(ok ctxt) - ~f:(fun cycle stake ctxt -> - let*? ctxt in - let stake = convert stake in - Storage.Stake.Total_active_stake.update ctxt cycle stake) - in - Storage.Stake.Selected_distribution_for_cycle_up_to_Nairobi.fold - ctxt - ~order:`Undefined - ~init:(ok ctxt) - ~f:(fun cycle distr ctxt -> - let*? ctxt in - let distr = List.map (fun (pkh, stake) -> (pkh, convert stake)) distr in - Storage.Stake.Selected_distribution_for_cycle.update ctxt cycle distr) - -(** Initializes the total supply when migrating from N to O - Uses an estimation of the total supply at the activation of O. - This value can be refined at the beginning of P to have a - perfectly accurate ammount on mainnet. - - Remove me in P. *) -let initialize_total_supply_for_o chain_id ctxt = - let open Lwt_syntax in - if Chain_id.equal Constants_repr.mainnet_id chain_id then - (* We only estimate the total supply in mainnet *) - (* around 967_000_000 tz (current estimated supply) - + 43_000_000 tz (yearly issuance) * 70 (days from activation) / 365 *) - Storage.Contract.Total_supply.add - ctxt - (Tez_repr.of_mutez_exn 975_000_000_000_000L) - else - (* If not on mainnet, iterate over all accounts and get an accurate total supply *) - let* total_supply = - Storage.Contract.fold - ctxt - ~order:`Undefined - ~f:(fun contract acc -> - let* full_balance = - Contract_storage.For_RPC.get_full_balance ctxt contract - in - match full_balance with - | Ok full_balance -> - return @@ Result.value ~default:acc Tez_repr.(acc +? full_balance) - | _ -> return acc) - ~init:Tez_repr.zero - in - Storage.Contract.Total_supply.add ctxt total_supply - -let migrate_pending_consensus_keys_for_o ctxt = - let open Lwt_result_syntax in - Storage.Delegates.fold - ctxt - ~order:`Undefined - ~init:ctxt - ~f:(fun delegate ctxt -> - let delegate = Contract_repr.Implicit delegate in - let*! pending_cks = - Storage.Contract.Pending_consensus_keys_up_to_Nairobi.bindings - (ctxt, delegate) - in - List.fold_left_s - (fun ctxt (cycle, pk) -> - let*! ctxt = - Storage.Pending_consensus_keys.add (ctxt, cycle) delegate pk - in - Storage.Contract.Pending_consensus_keys_up_to_Nairobi.remove - (ctxt, delegate) - cycle) - ctxt - pending_cks) - let prepare_first_block chain_id ctxt ~typecheck_smart_contract ~typecheck_smart_rollup ~level ~timestamp ~predecessor = Raw_context.prepare_first_block ~level ~timestamp chain_id ctxt @@ -293,7 +164,7 @@ let prepare_first_block chain_id ctxt ~typecheck_smart_contract Sc_rollup_inbox_storage.init_inbox ~predecessor ctxt >>=? fun ctxt -> Adaptive_issuance_storage.init ctxt >>=? fun ctxt -> return (ctxt, commitments_balance_updates @ bootstrap_balance_updates) - | Nairobi_017 + | Oxford_018 (* Please update [next_protocol] and [previous_protocol] in [tezt/lib_tezos/protocol.ml] when you update this value. *) -> (* TODO (#2704): possibly handle attestations for migration block (in bakers); @@ -303,22 +174,6 @@ let prepare_first_block chain_id ctxt ~typecheck_smart_contract Raw_level_repr.of_int32 level >>?= fun level -> Storage.Tenderbake.First_level_of_protocol.update ctxt level >>=? fun ctxt -> - Storage.Tenderbake.Endorsement_branch.find ctxt >>=? fun opt -> - Storage.Tenderbake.Endorsement_branch.remove ctxt >>= fun ctxt -> - Storage.Tenderbake.Attestation_branch.add_or_remove ctxt opt - >>= fun ctxt -> - Storage.Tenderbake.Forbidden_delegates.init - ctxt - Signature.Public_key_hash.Set.empty - >>=? fun ctxt -> - migrate_staking_balance_for_o ctxt >>=? fun ctxt -> - clear_staking_balance_snapshots_for_o ctxt >>=? fun ctxt -> - migrate_stake_distribution_for_o ctxt >>=? fun ctxt -> - initialize_total_supply_for_o chain_id ctxt >>= fun ctxt -> - Remove_zero_amount_ticket_migration_for_o.remove_zero_ticket_entries ctxt - >>= fun ctxt -> - Adaptive_issuance_storage.init ctxt >>=? fun ctxt -> - migrate_pending_consensus_keys_for_o ctxt >>= fun ctxt -> (* Migration of refutation games needs to be kept for each protocol. *) Sc_rollup_refutation_storage.migrate_clean_refutation_games ctxt >>=? fun ctxt -> return (ctxt, [])) diff --git a/src/proto_alpha/lib_protocol/raw_context.ml b/src/proto_alpha/lib_protocol/raw_context.ml index 951c7466fc6efa51501e099bc92230b741d53db7..0fba6d0d6df1e8e77f4b70332c7a7776d47638da 100644 --- a/src/proto_alpha/lib_protocol/raw_context.ml +++ b/src/proto_alpha/lib_protocol/raw_context.ml @@ -861,7 +861,7 @@ let prepare ~level ~predecessor_timestamp ~timestamp ~adaptive_issuance_enable }; } -type previous_protocol = Genesis of Parameters_repr.t | Nairobi_017 +type previous_protocol = Genesis of Parameters_repr.t | Oxford_018 let check_and_update_protocol_version ctxt = (Context.find ctxt version_key >>= function @@ -873,7 +873,7 @@ let check_and_update_protocol_version ctxt = failwith "Internal error: previously initialized context." else if Compare.String.(s = "genesis") then get_proto_param ctxt >|=? fun (param, ctxt) -> (Genesis param, ctxt) - else if Compare.String.(s = "nairobi_017") then return (Nairobi_017, ctxt) + else if Compare.String.(s = "oxford_018") then return (Oxford_018, ctxt) else Lwt.return @@ storage_error (Incompatible_protocol_version s)) >>=? fun (previous_proto, ctxt) -> Context.add ctxt version_key (Bytes.of_string Constants_repr.version_value) @@ -908,7 +908,7 @@ let[@warning "-32"] get_previous_protocol_constants ctxt = encoding directly in a way which is compatible with the previous protocol. However, by doing so, you do not change the value of these constants inside the context. *) -let prepare_first_block ~level ~timestamp chain_id ctxt = +let prepare_first_block ~level ~timestamp _chain_id ctxt = check_and_update_protocol_version ctxt >>=? fun (previous_proto, ctxt) -> (match previous_proto with | Genesis param -> @@ -924,7 +924,7 @@ let prepare_first_block ~level ~timestamp chain_id ctxt = Level_repr.create_cycle_eras [cycle_era] >>?= fun cycle_eras -> set_cycle_eras ctxt cycle_eras >>=? fun ctxt -> add_constants ctxt param.constants >|= ok - | Nairobi_017 -> + | Oxford_018 -> get_previous_protocol_constants ctxt >>= fun c -> let cryptobox_parameters = { @@ -951,10 +951,12 @@ let prepare_first_block ~level ~timestamp chain_id ctxt = let reveal_activation_level : Constants_parametric_repr.sc_rollup_reveal_activation_level = { - raw_data = {blake2B = Raw_level_repr.root}; - metadata = Raw_level_repr.root; + raw_data = + {blake2B = c.sc_rollup.reveal_activation_level.raw_data.blake2B}; + metadata = c.sc_rollup.reveal_activation_level.metadata; dal_page = - (if c.dal.feature_enable then Raw_level_repr.root + (if c.dal.feature_enable then + c.sc_rollup.reveal_activation_level.dal_page else if dal.feature_enable then (* First level of the protocol with dal activated. *) Raw_level_repr.of_int32_exn (Int32.succ level) @@ -1001,71 +1003,56 @@ let prepare_first_block ~level ~timestamp chain_id ctxt = enable = c.zk_rollup.enable; origination_size = c.zk_rollup.origination_size; min_pending_to_process = c.zk_rollup.min_pending_to_process; - max_ticket_payload_size = c.tx_rollup.max_ticket_payload_size; + max_ticket_payload_size = c.zk_rollup.max_ticket_payload_size; + } + in + + let issuance_weights = + Constants_parametric_repr. + { + base_total_issued_per_minute = + c.issuance_weights.base_total_issued_per_minute; + baking_reward_fixed_portion_weight = + c.issuance_weights.baking_reward_fixed_portion_weight; + baking_reward_bonus_weight = + c.issuance_weights.baking_reward_bonus_weight; + attesting_reward_weight = c.issuance_weights.attesting_reward_weight; + liquidity_baking_subsidy_weight = + c.issuance_weights.liquidity_baking_subsidy_weight; + seed_nonce_revelation_tip_weight = + c.issuance_weights.seed_nonce_revelation_tip_weight; + vdf_revelation_tip_weight = + c.issuance_weights.vdf_revelation_tip_weight; } in let adaptive_rewards_params = Constants_parametric_repr. { - issuance_ratio_min = Q.(5 // 10000) (* 0.05% *); - issuance_ratio_max = Q.(1 // 20) (* 5% *); - max_bonus = 50_000_000_000_000L (* 5% *); + issuance_ratio_min = + c.adaptive_issuance.adaptive_rewards_params.issuance_ratio_min; + issuance_ratio_max = + c.adaptive_issuance.adaptive_rewards_params.issuance_ratio_max; + max_bonus = c.adaptive_issuance.adaptive_rewards_params.max_bonus; growth_rate = - 115_740_740L - (* 0.01 * [bonus_unit] / second_per_day - For each % and each day, grows the bonus by 0.01% *); - center_dz = Q.(1 // 2) (* 50% *); - radius_dz = Q.(1 // 50) (* 2% *); + c.adaptive_issuance.adaptive_rewards_params.growth_rate; + center_dz = c.adaptive_issuance.adaptive_rewards_params.center_dz; + radius_dz = c.adaptive_issuance.adaptive_rewards_params.radius_dz; } in let adaptive_issuance = Constants_parametric_repr. { - global_limit_of_staking_over_baking = 5; - edge_of_staking_over_delegation = 2; - launch_ema_threshold = - (if Chain_id.equal Constants_repr.mainnet_id chain_id then - (* 80% of the max ema (which is 2 billion) *) 1_600_000_000l - else (* 5% for testnets *) 100_000_000l); + global_limit_of_staking_over_baking = + c.adaptive_issuance.global_limit_of_staking_over_baking; + edge_of_staking_over_delegation = + c.adaptive_issuance.edge_of_staking_over_delegation; + launch_ema_threshold = c.adaptive_issuance.launch_ema_threshold; adaptive_rewards_params; } in - let issuance_weights = - let c_gen = - Constants_repr.Generated.generate - ~consensus_committee_size:c.consensus_committee_size - in - c_gen.issuance_weights - in - - let percentage_of_frozen_deposits_slashed_per_double_attestation = - 100 - * c.ratio_of_frozen_deposits_slashed_per_double_attestation.numerator - / c.ratio_of_frozen_deposits_slashed_per_double_attestation.denominator - in - let percentage_of_frozen_deposits_slashed_per_double_baking = - let double_baking_punishment_times_100 = - Int64.mul 100L (Tez_repr.to_mutez c.double_baking_punishment) - in - let percentage_rounded_down = - Int64.div - double_baking_punishment_times_100 - (Tez_repr.to_mutez c.minimal_stake) - in - Int64.to_int percentage_rounded_down - in - let limit_of_delegation_over_baking = - (100 / c.frozen_deposits_percentage) - 1 - in - let minimal_frozen_stake = - Tez_repr.( - div_exn - (mul_exn c.minimal_stake (limit_of_delegation_over_baking + 1)) - 100) - in let constants = Constants_parametric_repr. { @@ -1079,7 +1066,7 @@ let prepare_first_block ~level ~timestamp chain_id ctxt = hard_gas_limit_per_block = c.hard_gas_limit_per_block; proof_of_work_threshold = c.proof_of_work_threshold; minimal_stake = c.minimal_stake; - minimal_frozen_stake; + minimal_frozen_stake = c.minimal_frozen_stake; vdf_difficulty = c.vdf_difficulty; origination_size = c.origination_size; max_operations_time_to_live = c.max_operations_time_to_live; @@ -1098,9 +1085,11 @@ let prepare_first_block ~level ~timestamp chain_id ctxt = consensus_threshold = c.consensus_threshold; minimal_participation_ratio = c.minimal_participation_ratio; max_slashing_period = c.max_slashing_period; - limit_of_delegation_over_baking; - percentage_of_frozen_deposits_slashed_per_double_baking; - percentage_of_frozen_deposits_slashed_per_double_attestation; + limit_of_delegation_over_baking = c.limit_of_delegation_over_baking; + percentage_of_frozen_deposits_slashed_per_double_baking = + c.percentage_of_frozen_deposits_slashed_per_double_baking; + percentage_of_frozen_deposits_slashed_per_double_attestation = + c.percentage_of_frozen_deposits_slashed_per_double_attestation; (* The `testnet_dictator` should absolutely be None on mainnet *) testnet_dictator = c.testnet_dictator; initial_seed = c.initial_seed; diff --git a/src/proto_alpha/lib_protocol/raw_context.mli b/src/proto_alpha/lib_protocol/raw_context.mli index dd75cc663159100dcf56c9ca3ca8b7620b05067d..5cf9ec8bd5160f6a89c9c438e3aaa6c5b017a338 100644 --- a/src/proto_alpha/lib_protocol/raw_context.mli +++ b/src/proto_alpha/lib_protocol/raw_context.mli @@ -93,7 +93,7 @@ val prepare : Context.t -> t tzresult Lwt.t -type previous_protocol = Genesis of Parameters_repr.t | Nairobi_017 +type previous_protocol = Genesis of Parameters_repr.t | Oxford_018 val prepare_first_block : level:int32 -> diff --git a/src/proto_alpha/lib_protocol/storage.ml b/src/proto_alpha/lib_protocol/storage.ml index 75ffb79ed3b2be75dec5364ce3af3f3fdb5b46ac..ab9508eb8de05f3c0dcd31053f8d4b2d486f9a46 100644 --- a/src/proto_alpha/lib_protocol/storage.ml +++ b/src/proto_alpha/lib_protocol/storage.ml @@ -123,13 +123,6 @@ module Tenderbake = struct (req "predecessor_payload" Block_payload_hash.encoding)) end - module Endorsement_branch = - Make_single_data_storage (Registered) (Raw_context) - (struct - let name = ["endorsement_branch"] - end) - (Branch) - module Attestation_branch = Make_single_data_storage (Registered) (Raw_context) (struct diff --git a/src/proto_alpha/lib_protocol/storage.mli b/src/proto_alpha/lib_protocol/storage.mli index d036a2f281168b1765aeac66767da489245c7575..36f0faa6f4ee08d97d6bcb1ddb88b79e12129901 100644 --- a/src/proto_alpha/lib_protocol/storage.mli +++ b/src/proto_alpha/lib_protocol/storage.mli @@ -815,16 +815,6 @@ module Tenderbake : sig with type value = Block_hash.t * Block_payload_hash.t and type t := Raw_context.t - (** Similar to [Attestation_branch] but only used for the stitching from - Nairobi. - - TODO: https://gitlab.com/tezos/tezos/-/issues/6082 - This should be removed once in the next protocol. *) - module Endorsement_branch : - Single_data_storage - with type value = Block_hash.t * Block_payload_hash.t - and type t := Raw_context.t - (** [Forbidden_delegates] stores the set of delegates that are not allowed to bake or attest blocks. *) module Forbidden_delegates : diff --git a/tezt/lib_tezos/protocol.ml b/tezt/lib_tezos/protocol.ml index a35040ce0d1e50b98c3949eab40bbfc38984f730..5742796255a30d94e107f41dba3ebdd5157110c0 100644 --- a/tezt/lib_tezos/protocol.ml +++ b/tezt/lib_tezos/protocol.ml @@ -243,12 +243,12 @@ let write_parameter_file : Lwt.return overriden_parameters let next_protocol = function - | Nairobi -> Some Alpha - | Oxford -> None + | Nairobi -> Some Oxford + | Oxford -> Some Alpha | Alpha -> None let previous_protocol = function - | Alpha -> Some Nairobi + | Alpha -> Some Oxford | Oxford -> Some Nairobi | Nairobi -> None diff --git a/tezt/tests/protocol_migration.ml b/tezt/tests/protocol_migration.ml index 72bc5b83315aa12d8fcdbbc4c20b0309f6ff316b..4374c091c56581f186eb8c0f60424d7748c1cd98 100644 --- a/tezt/tests/protocol_migration.ml +++ b/tezt/tests/protocol_migration.ml @@ -352,6 +352,7 @@ let check_attestations_in_block ~protocol ~level ~expected_count client = let* consensus_operations = RPC.Client.call client @@ RPC.get_chain_block_operations_validation_pass + ~version:"1" ~block:(string_of_int level) ~validation_pass:0 (* consensus operations pass *) () @@ -727,7 +728,10 @@ let wait_for_qc_at_level level baker = if !level_seen then Some () else None) let get_block_at_level level client = - RPC.(Client.call client (get_chain_block ~block:(string_of_int level) ())) + RPC.( + Client.call + client + (get_chain_block ~version:"1" ~block:(string_of_int level) ())) let test_forked_migration_bakers ~migrate_from ~migrate_to = Test.register