From 992711175d414cbea066eda1cfc597c94c2d13d2 Mon Sep 17 00:00:00 2001 From: Julien Tesson Date: Tue, 12 Dec 2023 15:56:09 +0100 Subject: [PATCH 1/7] proto: stitch from Oxford - previous param constants are from Oxford --- .../constants_parametric_previous_repr.ml | 464 ++++++++++++------ .../constants_parametric_previous_repr.mli | 128 ++--- src/proto_alpha/lib_protocol/init_storage.ml | 2 +- src/proto_alpha/lib_protocol/raw_context.ml | 132 ++--- src/proto_alpha/lib_protocol/raw_context.mli | 2 +- 5 files changed, 441 insertions(+), 287 deletions(-) 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 910fdbcde1a9..0536a4c71540 100644 --- a/src/proto_alpha/lib_protocol/constants_parametric_previous_repr.ml +++ b/src/proto_alpha/lib_protocol/constants_parametric_previous_repr.ml @@ -83,26 +83,36 @@ 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; + dal_parameters : 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, t.dal_parameters)) + (fun (raw_data, metadata, dal_page, dal_parameters) -> + {raw_data; metadata; dal_page; dal_parameters}) + (obj4 + (req "raw_data" sc_rollup_reveal_hashing_schemes_encoding) + (req "metadata" Raw_level_repr.encoding) + (req "dal_page" Raw_level_repr.encoding) + (req "dal_parameters" Raw_level_repr.encoding)) + type sc_rollup = { - enable : bool; arith_pvm_enable : bool; origination_size : int; challenge_window_in_blocks : int; @@ -115,12 +125,44 @@ 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; + private_enable : bool; + riscv_pvm_enable : bool; } 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 : Issuance_bonus_repr.max_bonus; + growth_rate : Q.t; + 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; + activation_vote_enable : bool; + autostaking_enable : bool; +} + +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 +176,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; @@ -153,10 +192,10 @@ type t = { minimal_participation_ratio : Ratio_repr.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.t; + percentage_of_frozen_deposits_slashed_per_double_attestation : + Int_percentage.t; 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,88 +203,17 @@ 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 (fun (c : sc_rollup) -> - ( ( c.enable, - c.arith_pvm_enable, + ( ( c.arith_pvm_enable, c.origination_size, c.challenge_window_in_blocks, c.stake_amount, @@ -256,9 +224,11 @@ 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 ) )) - (fun ( ( sc_rollup_enable, - sc_rollup_arith_pvm_enable, + c.max_number_of_parallel_games, + c.reveal_activation_level, + c.private_enable, + c.riscv_pvm_enable ) )) + (fun ( ( sc_rollup_arith_pvm_enable, sc_rollup_origination_size, sc_rollup_challenge_window_in_blocks, sc_rollup_stake_amount, @@ -269,9 +239,11 @@ 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, + sc_rollup_private_enable, + sc_rollup_riscv_pvm_enable ) ) -> { - enable = sc_rollup_enable; arith_pvm_enable = sc_rollup_arith_pvm_enable; origination_size = sc_rollup_origination_size; challenge_window_in_blocks = sc_rollup_challenge_window_in_blocks; @@ -286,10 +258,12 @@ 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; + private_enable = sc_rollup_private_enable; + riscv_pvm_enable = sc_rollup_riscv_pvm_enable; }) (merge_objs - (obj9 - (req "smart_rollup_enable" bool) + (obj8 (req "smart_rollup_arith_pvm_enable" bool) (req "smart_rollup_origination_size" int31) (req "smart_rollup_challenge_window_in_blocks" int31) @@ -298,29 +272,210 @@ 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 + (obj7 (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) + (req "smart_rollup_private_enable" bool) + (req "smart_rollup_riscv_pvm_enable" bool))) 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 growth_rate_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: growth rate 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" Issuance_bonus_repr.max_bonus_encoding) + (req "growth_rate" growth_rate_encoding) + (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; + activation_vote_enable; + autostaking_enable; + } -> + ( global_limit_of_staking_over_baking, + edge_of_staking_over_delegation, + launch_ema_threshold, + adaptive_rewards_params, + activation_vote_enable, + autostaking_enable )) + (fun ( global_limit_of_staking_over_baking, + edge_of_staking_over_delegation, + launch_ema_threshold, + adaptive_rewards_params, + activation_vote_enable, + autostaking_enable ) -> + { + global_limit_of_staking_over_baking; + edge_of_staking_over_delegation; + launch_ema_threshold; + adaptive_rewards_params; + activation_vote_enable; + autostaking_enable; + }) + (obj6 + (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) + (req "adaptive_issuance_activation_vote_enable" bool) + (req "autostaking_enable" bool)) + +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 +491,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, @@ -355,16 +507,16 @@ let encoding = c.consensus_committee_size, 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 +527,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, @@ -394,16 +543,15 @@ let encoding = consensus_committee_size, 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,38 +563,34 @@ 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; delay_increment_per_round; minimal_participation_ratio; - 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 +609,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) @@ -487,14 +628,15 @@ let encoding = (req "consensus_committee_size" int31) (req "consensus_threshold" int31)) (merge_objs - (obj7 + (obj6 (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" + Int_percentage.encoding) (req - "ratio_of_frozen_deposits_slashed_per_double_endorsement" - Ratio_repr.encoding) + "percentage_of_frozen_deposits_slashed_per_double_attestation" + Int_percentage.encoding) (opt "testnet_dictator" Signature.Public_key_hash.encoding) (opt "initial_seed" State_hash.encoding)) (merge_objs @@ -503,7 +645,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 294790c41a07..ac561e744ed2 100644 --- a/src/proto_alpha/lib_protocol/constants_parametric_previous_repr.mli +++ b/src/proto_alpha/lib_protocol/constants_parametric_previous_repr.mli @@ -36,57 +36,17 @@ 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. +type sc_rollup_reveal_hashing_schemes = {blake2B : Raw_level_repr.t} - 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. - - 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; + dal_parameters : Raw_level_repr.t; } type sc_rollup = { - enable : bool; arith_pvm_enable : bool; origination_size : int; challenge_window_in_blocks : int; @@ -124,6 +84,13 @@ 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; + (* Activates an updatable whitelist of stakers. Only keys in the whitelist are + allowed to stake and publish a commitment. *) + private_enable : bool; + (* Activates the RISC-V pvm. *) + riscv_pvm_enable : bool; } type zk_rollup = { @@ -136,6 +103,53 @@ 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 *) Issuance_bonus_repr.max_bonus; + growth_rate : (* Bonus value's growth rate *) Q.t; + 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; + activation_vote_enable : + (* If set to true, reaching the launch_ema_threshold in the adaptive + issuance activation vote triggers the activation of the adaptive + inflation feature; otherwise the activation vote has no effect. *) + bool; + autostaking_enable : + (* If set to true, a stake/unstake/finalize operation will be triggered for + all delegate at end of cycle. *) + bool; +} + +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 +163,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; @@ -171,12 +182,11 @@ type t = { (* in slots *) consensus_threshold : int; (* 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.t; + percentage_of_frozen_deposits_slashed_per_double_attestation : + Int_percentage.t; testnet_dictator : Signature.Public_key_hash.t option; initial_seed : State_hash.t option; cache_script_size : int; @@ -185,10 +195,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 4d21ac9cd4ea..0fd15b61fcda 100644 --- a/src/proto_alpha/lib_protocol/init_storage.ml +++ b/src/proto_alpha/lib_protocol/init_storage.ml @@ -323,7 +323,7 @@ let prepare_first_block chain_id ctxt ~typecheck_smart_contract let* ctxt = Sc_rollup_inbox_storage.init_inbox ~predecessor ctxt in let* ctxt = Adaptive_issuance_storage.init ctxt in 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); diff --git a/src/proto_alpha/lib_protocol/raw_context.ml b/src/proto_alpha/lib_protocol/raw_context.ml index c0bd545f1766..f9d0c0824f67 100644 --- a/src/proto_alpha/lib_protocol/raw_context.ml +++ b/src/proto_alpha/lib_protocol/raw_context.ml @@ -891,7 +891,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 = let open Lwt_result_syntax in @@ -907,8 +907,7 @@ let check_and_update_protocol_version ctxt = else if Compare.String.(s = "genesis") then let+ param, ctxt = get_proto_param ctxt in (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) in let*! ctxt = @@ -947,7 +946,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 = let open Lwt_result_syntax in let* previous_proto, ctxt = check_and_update_protocol_version ctxt in let* ctxt = @@ -966,25 +965,18 @@ let prepare_first_block ~level ~timestamp chain_id ctxt = let* ctxt = set_cycle_eras ctxt cycle_eras in let*! result = add_constants ctxt param.constants in return result - | Nairobi_017 -> + | Oxford_018 -> let*! c = get_previous_protocol_constants ctxt in - let cryptobox_parameters = - { - Dal.page_size = c.dal.cryptobox_parameters.page_size; - number_of_shards = c.dal.cryptobox_parameters.number_of_shards; - slot_size = c.dal.cryptobox_parameters.slot_size; - redundancy_factor = c.dal.cryptobox_parameters.redundancy_factor; - } - in + let cryptobox_parameters = c.dal.cryptobox_parameters in let dal = Constants_parametric_repr. { feature_enable = c.dal.feature_enable; number_of_slots = c.dal.number_of_slots; - attestation_lag = 4; + attestation_lag = c.dal.attestation_lag; attestation_threshold = c.dal.attestation_threshold; - blocks_per_epoch = 1l; + blocks_per_epoch = c.dal.blocks_per_epoch; cryptobox_parameters; } in @@ -1014,14 +1006,21 @@ let prepare_first_block ~level ~timestamp chain_id ctxt = tezt/tests/mockup.ml). *) Raw_level_repr.of_int32_exn Int32.(pred max_int) in - (* When stitching from Oxford and after, [Raw_level_repr.root] - should be replaced by the previous value, that is - [c.reveal_activation_level.*]. *) let reveal_activation_level : Constants_parametric_repr.sc_rollup_reveal_activation_level = + let ({ + raw_data = {blake2B}; + metadata; + dal_page = _; + dal_parameters = _; + } + : Constants_parametric_previous_repr + .sc_rollup_reveal_activation_level) = + c.sc_rollup.reveal_activation_level + in { - raw_data = {blake2B = Raw_level_repr.root}; - metadata = Raw_level_repr.root; + raw_data = {blake2B}; + metadata; dal_page = dal_activation_level; dal_parameters = dal_activation_level; } @@ -1048,8 +1047,8 @@ let prepare_first_block ~level ~timestamp chain_id ctxt = max_number_of_parallel_games = c.sc_rollup.max_number_of_parallel_games; reveal_activation_level; - private_enable = true; - riscv_pvm_enable = false; + private_enable = c.sc_rollup.private_enable; + riscv_pvm_enable = c.sc_rollup.riscv_pvm_enable; } in let zk_rollup = @@ -1058,62 +1057,62 @@ 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 adaptive_rewards_params = Constants_parametric_repr. { - issuance_ratio_min = Q.(5 // 10_000) (* 0.05% *); - issuance_ratio_max = Q.(5 // 100); - max_bonus = - Issuance_bonus_repr.max_bonus_parameter_of_Q_exn Q.(5 // 100); - growth_rate = Q.(1 // 100); - center_dz = Q.(50 // 100); - radius_dz = Q.(2 // 100); + 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 = + 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; - activation_vote_enable = false; - autostaking_enable = true; + activation_vote_enable = + c.adaptive_issuance.activation_vote_enable; + autostaking_enable = c.adaptive_issuance.autostaking_enable; } in - let issuance_weights = - let c_gen = - Constants_repr.Generated.generate - ~consensus_committee_size:c.consensus_committee_size + let issuance_weights : Constants_parametric_repr.issuance_weights = + let ({ + 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; + } + : Constants_parametric_previous_repr.issuance_weights) = + c.issuance_weights in - c_gen.issuance_weights - in - - let percentage_of_frozen_deposits_slashed_per_double_baking = - Int_percentage.p5 - in - let percentage_of_frozen_deposits_slashed_per_double_attestation = - Int_percentage.of_ratio_bounded - c.ratio_of_frozen_deposits_slashed_per_double_attestation - in - let limit_of_delegation_over_baking = - (100 / c.frozen_deposits_percentage) - 1 - in - let minimal_frozen_stake = - Tez_repr.( - div_exn c.minimal_stake (limit_of_delegation_over_baking + 1)) + { + 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; + } in - let direct_ticket_spending_enable = false in - let constants = Constants_parametric_repr. { @@ -1129,7 +1128,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; @@ -1147,9 +1146,12 @@ let prepare_first_block ~level ~timestamp chain_id ctxt = consensus_committee_size = c.consensus_committee_size; consensus_threshold = c.consensus_threshold; minimal_participation_ratio = c.minimal_participation_ratio; - 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 db8d25268ad0..12f7c303fcef 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 -> -- GitLab From 9f80b68552f91df7497f46d96584deaa2cb6db45 Mon Sep 17 00:00:00 2001 From: Julien Tesson Date: Tue, 12 Dec 2023 16:57:49 +0100 Subject: [PATCH 2/7] proto: stitch from Oxford - forbiddden delegates init only for Genesis --- .../lib_protocol/forbidden_delegates_storage.ml | 2 +- .../lib_protocol/forbidden_delegates_storage.mli | 2 +- src/proto_alpha/lib_protocol/init_storage.ml | 8 +------- 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/src/proto_alpha/lib_protocol/forbidden_delegates_storage.ml b/src/proto_alpha/lib_protocol/forbidden_delegates_storage.ml index 224a826d17ad..4d8bfa9dad98 100644 --- a/src/proto_alpha/lib_protocol/forbidden_delegates_storage.ml +++ b/src/proto_alpha/lib_protocol/forbidden_delegates_storage.ml @@ -117,7 +117,7 @@ let update_at_cycle_end ctxt ~new_cycle = let*! ctxt = set_forbidden_delegates ctxt forbidden_delegates in return ctxt -let init_for_genesis_and_oxford ctxt = +let init_for_genesis ctxt = Storage.Tenderbake.Forbidden_delegates.init ctxt Signature.Public_key_hash.Set.empty diff --git a/src/proto_alpha/lib_protocol/forbidden_delegates_storage.mli b/src/proto_alpha/lib_protocol/forbidden_delegates_storage.mli index 6bebc0c8e874..e1ada9054b23 100644 --- a/src/proto_alpha/lib_protocol/forbidden_delegates_storage.mli +++ b/src/proto_alpha/lib_protocol/forbidden_delegates_storage.mli @@ -37,4 +37,4 @@ val load : Raw_context.t -> Raw_context.t tzresult Lwt.t val update_at_cycle_end : Raw_context.t -> new_cycle:Cycle_repr.t -> Raw_context.t tzresult Lwt.t -val init_for_genesis_and_oxford : Raw_context.t -> Raw_context.t tzresult Lwt.t +val init_for_genesis : Raw_context.t -> Raw_context.t tzresult Lwt.t diff --git a/src/proto_alpha/lib_protocol/init_storage.ml b/src/proto_alpha/lib_protocol/init_storage.ml index 0fd15b61fcda..a67a6790c75a 100644 --- a/src/proto_alpha/lib_protocol/init_storage.ml +++ b/src/proto_alpha/lib_protocol/init_storage.ml @@ -268,9 +268,7 @@ let prepare_first_block chain_id ctxt ~typecheck_smart_contract let* ctxt = Storage.Tenderbake.First_level_of_protocol.init ctxt level in - let* ctxt = - Forbidden_delegates_storage.init_for_genesis_and_oxford ctxt - in + let* ctxt = Forbidden_delegates_storage.init_for_genesis ctxt in let*! ctxt = Storage.Contract.Total_supply.add ctxt Tez_repr.zero in let* ctxt = Storage.Block_round.init ctxt Round_repr.zero in let init_commitment (ctxt, balance_updates) @@ -339,10 +337,6 @@ let prepare_first_block chain_id ctxt ~typecheck_smart_contract let*! ctxt = Storage.Tenderbake.Attestation_branch.add_or_remove ctxt opt in - let* ctxt = - (* In P, remove this call and rename the function. *) - Forbidden_delegates_storage.init_for_genesis_and_oxford ctxt - in let* ctxt = migrate_staking_balance_for_o ctxt in let* ctxt = clear_staking_balance_snapshots_for_o ctxt in let* ctxt = migrate_stake_distribution_for_o ctxt in -- GitLab From 51d5861b51405cb7f7ce99c4f46172a5117e6ada Mon Sep 17 00:00:00 2001 From: Julien Tesson Date: Tue, 12 Dec 2023 17:05:16 +0100 Subject: [PATCH 3/7] proto: stitch from Oxford - rm remove_zero_amount_ticket_migration_for_o --- src/proto_alpha/lib_protocol/TEZOS_PROTOCOL | 1 - src/proto_alpha/lib_protocol/dune | 4 - src/proto_alpha/lib_protocol/init_storage.ml | 4 - ...move_zero_amount_ticket_migration_for_o.ml | 181 ------------------ 4 files changed, 190 deletions(-) delete mode 100644 src/proto_alpha/lib_protocol/remove_zero_amount_ticket_migration_for_o.ml diff --git a/src/proto_alpha/lib_protocol/TEZOS_PROTOCOL b/src/proto_alpha/lib_protocol/TEZOS_PROTOCOL index 200febecd949..9077f84ff78a 100644 --- a/src/proto_alpha/lib_protocol/TEZOS_PROTOCOL +++ b/src/proto_alpha/lib_protocol/TEZOS_PROTOCOL @@ -195,7 +195,6 @@ "Sc_rollup_errors", "Sc_rollup_inbox_storage", - "Remove_zero_amount_ticket_migration_for_o", "Legacy_script_patches", "Sapling_validator", diff --git a/src/proto_alpha/lib_protocol/dune b/src/proto_alpha/lib_protocol/dune index 72d265c08483..5c1c4e88d14b 100644 --- a/src/proto_alpha/lib_protocol/dune +++ b/src/proto_alpha/lib_protocol/dune @@ -208,7 +208,6 @@ Liquidity_baking_migration Sc_rollup_errors Sc_rollup_inbox_storage - Remove_zero_amount_ticket_migration_for_o Legacy_script_patches Sapling_validator Global_constants_storage @@ -506,7 +505,6 @@ liquidity_baking_migration.ml liquidity_baking_migration.mli sc_rollup_errors.ml sc_rollup_inbox_storage.ml sc_rollup_inbox_storage.mli - remove_zero_amount_ticket_migration_for_o.ml legacy_script_patches.ml sapling_validator.ml global_constants_storage.ml global_constants_storage.mli @@ -805,7 +803,6 @@ liquidity_baking_migration.ml liquidity_baking_migration.mli sc_rollup_errors.ml sc_rollup_inbox_storage.ml sc_rollup_inbox_storage.mli - remove_zero_amount_ticket_migration_for_o.ml legacy_script_patches.ml sapling_validator.ml global_constants_storage.ml global_constants_storage.mli @@ -1088,7 +1085,6 @@ liquidity_baking_migration.ml liquidity_baking_migration.mli sc_rollup_errors.ml sc_rollup_inbox_storage.ml sc_rollup_inbox_storage.mli - remove_zero_amount_ticket_migration_for_o.ml legacy_script_patches.ml sapling_validator.ml global_constants_storage.ml global_constants_storage.mli diff --git a/src/proto_alpha/lib_protocol/init_storage.ml b/src/proto_alpha/lib_protocol/init_storage.ml index a67a6790c75a..202d2150d2f9 100644 --- a/src/proto_alpha/lib_protocol/init_storage.ml +++ b/src/proto_alpha/lib_protocol/init_storage.ml @@ -341,10 +341,6 @@ let prepare_first_block chain_id ctxt ~typecheck_smart_contract let* ctxt = clear_staking_balance_snapshots_for_o ctxt in let* ctxt = migrate_stake_distribution_for_o ctxt in let*! ctxt = initialize_total_supply_for_o chain_id ctxt in - let*! ctxt = - Remove_zero_amount_ticket_migration_for_o.remove_zero_ticket_entries - ctxt - in let* ctxt = Adaptive_issuance_storage.init ctxt in let*! ctxt = migrate_pending_consensus_keys_for_o ctxt in (* Migration of refutation games needs to be kept for each protocol. *) diff --git a/src/proto_alpha/lib_protocol/remove_zero_amount_ticket_migration_for_o.ml b/src/proto_alpha/lib_protocol/remove_zero_amount_ticket_migration_for_o.ml deleted file mode 100644 index 299053260caf..000000000000 --- a/src/proto_alpha/lib_protocol/remove_zero_amount_ticket_migration_for_o.ml +++ /dev/null @@ -1,181 +0,0 @@ -(*****************************************************************************) -(* *) -(* Open Source License *) -(* Copyright (c) 2023 Marigold *) -(* *) -(* Permission is hereby granted, free of charge, to any person obtaining a *) -(* copy of this software and associated documentation files (the "Software"),*) -(* to deal in the Software without restriction, including without limitation *) -(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *) -(* and/or sell copies of the Software, and to permit persons to whom the *) -(* Software is furnished to do so, subject to the following conditions: *) -(* *) -(* The above copyright notice and this permission notice shall be included *) -(* in all copies or substantial portions of the Software. *) -(* *) -(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*) -(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *) -(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *) -(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*) -(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *) -(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *) -(* DEALINGS IN THE SOFTWARE. *) -(* *) -(*****************************************************************************) - -(* Remove zero tickets from big map with id 5696. This big map is found in the - storage of [KT1CnygLoKfJA66499U9ZQkL6ykUfzgruGfM]. The id can be looked up in - https://tzkt.io/KT1CnygLoKfJA66499U9ZQkL6ykUfzgruGfM/storage/ - - This procedure removes all keys with zero-amount tickets from the big-map. - We have compiled a list of hashes corresponding to keys of values with - zero-amount tickets. We also verify removal by pattern matching on the values - to make sure they contain zero-amount ticket values. -*) - -type error += - | Invalid_big_map_key of string - | Not_zero_ticket of Script_expr_hash.t - | Invalid_big_map_value of Script_expr_hash.t - -let () = - register_error_kind - `Permanent - ~id:"migration.invalid_big_map_key" - ~title:"Invalid big map key as a script expression hash" - ~description: - "As part of the protocol migration, a big map key was expected to be \ - parsed successfully into a script expression hash" - ~pp:(fun ppf key -> - Format.fprintf ppf "Unable to parse %s as a script expression hash" key) - Data_encoding.(obj1 (req "key" (string Plain))) - (function Invalid_big_map_key key -> Some key | _ -> None) - (fun key -> Invalid_big_map_key key) ; - register_error_kind - `Permanent - ~id:"migration.not_zero_ticket_key" - ~title:"A big map key is not mapping to any zero ticket" - ~description:"the value mapped to a big map key has an unexpected shape" - ~pp:(fun ppf key -> - Format.fprintf - ppf - "%a does not map to a zero ticket, key not found" - Script_expr_hash.pp - key) - Data_encoding.(obj1 (req "key" Script_expr_hash.encoding)) - (function Not_zero_ticket key -> Some key | _ -> None) - (fun key -> Not_zero_ticket key) ; - register_error_kind - `Permanent - ~id:"migration.zero_ticket_wrong_value" - ~title:"A big map key is mapped to an unexpected value" - ~description: - "As part of the protocol migration, a big map key was expected to be \ - mapping into a value which is of unexpected shape" - ~pp:(fun ppf key -> - Format.fprintf - ppf - "%a does not map to a zero ticket, unexpected shape" - Script_expr_hash.pp - key) - Data_encoding.(obj1 (req "key" Script_expr_hash.encoding)) - (function Invalid_big_map_value key -> Some key | _ -> None) - (fun key -> Invalid_big_map_value key) - -let remove_zero_ticket_entries ctxt = - let open Lwt_result_syntax in - let*? contract_to_clean = - Contract_repr.of_b58check "KT1CnygLoKfJA66499U9ZQkL6ykUfzgruGfM" - in - let big_map_to_clean = - Lazy_storage_kind.Big_map.Id.parse_z @@ Z.of_int 5696 - in - let*? keys_to_evict = - List.map_e - (fun key -> - match Script_expr_hash.of_b58check_opt key with - | Some key -> ok key - | None -> error (Invalid_big_map_key key)) - [ - "exprtXBtxJxCDEDETueKAFLL7r7vZtNEo1MHajpHba1djtGKqJzWd3"; - "exprtbuRhaGDS942BgZ1qFdD7HAKeBjPEqzRxgLQyWQ6HWxcaiLC2c"; - "exprtePxSLgrhJmTPZEePyFBmESLhaBUN1WodvLYy9xYhEYE6dKPLe"; - "exprtx9GaYz5Fy5ytiuYgSfJqeYqkxGgobust8U6dpCLaeZUMiitmg"; - "expru28t4XoyB61WuRQnExk3Kq8ssGv1ejgdo9XHxpTXoQjXTGw1Dg"; - "expru2fZALknjB4vJjmQBPkrs3dJZ5ytuzfmE9A7ScUk5opJiZQyiJ"; - "expru2riAFKURjHJ1vNpvsZGGw6z4wtTvbstXVuwQPj1MaTqKPeQ6z"; - "expruHoZDr8ioVhaAs495crYTprAYyC87CruEJ6HaS7diYV6qLARqQ"; - "expruMie2gfy5smMd81NtcvvWm4jD7ThUebw9hpF3N3apKVtxkVG9M"; - "expruc3QW7cdxrGurDJQa6k9QqMZjGkRDJahy2XNtBt9WQzC1yavJK"; - "exprud86wYL7inFCVHkF1Jcz8uMXVY7dnbzxVupyyknZjtDVmwoQTJ"; - "exprufYzeBTGn9733Ga8xEEmU4SsrSyDrzEip8V8hTBAG253T5zZQx"; - "exprum9tuHNvisMa3c372AFmCa27rmkbCGrhzMSprrxgJjzXhrKAag"; - "expruokt7oQ6dDHRvL4sURKUzfwJirR8FPHvpXwjgUD4KHhPWhDGbv"; - "expruom5ds2hVgjdTB877Fx3ZuWT5WUnw1H6kUZavVHcJFbCkcgo3x"; - "exprv2DPd1pV3GVSN2CgW7PPrAQUTuZAdeJphwToQrTNrxiJcWzvtX"; - "exprv65Czv5TnKyEWgBHjDztkCkc1FAVEPxZ3V3ocgvGjfXwjPLo8M"; - "exprv6S2KAvqAC18jDLYjaj1w9oc4ESdDGJkUZ63EpkqSTAz88cSYB"; - "exprvNg3VDBnhtTHvc75krAEYzz6vUMr3iU5jtLdxs83FbgTbZ9nFT"; - "exprvS7wNDHYKYZ19nj3ZUo7AAVMCDpTK3NNERFhqe5SJGCBL4pwFA"; - ] - in - let* initial_big_map_size = - Storage.Big_map.Total_bytes.get ctxt big_map_to_clean - in - let* initial_storage_size = - Storage.Contract.Used_storage_space.get ctxt contract_to_clean - in - let scan_and_remove (ctxt, storage_freed) key = - let* ctxt, v = Storage.Big_map.Contents.get (ctxt, big_map_to_clean) key in - let open Micheline in - let open Michelson_v1_primitives in - match root v with - | Prim - ( _, - D_Pair, - [ - _timestamp; - Prim - ( _, - D_Pair, - [_data; Prim (_, D_Pair, [_ticketer; Int (_, amount)], _)], - _ ); - ], - _ ) -> - if Z.(equal amount zero) then - let* ctxt, size_sub, is_evicted = - Storage.Big_map.Contents.remove (ctxt, big_map_to_clean) key - in - if is_evicted then - return (ctxt, Z.(add storage_freed (Z.of_int size_sub))) - else tzfail @@ Invalid_big_map_value key - else tzfail @@ Invalid_big_map_value key - | _ -> tzfail @@ Invalid_big_map_value key - in - let* ctxt, storage_freed = - List.fold_left_es scan_and_remove (ctxt, Z.zero) keys_to_evict - in - let new_big_map_size = Z.sub initial_big_map_size storage_freed in - let* ctxt = - Storage.Big_map.Total_bytes.update ctxt big_map_to_clean new_big_map_size - in - let new_storage_size = Z.sub initial_storage_size storage_freed in - Storage.Contract.Used_storage_space.update - ctxt - contract_to_clean - new_storage_size - -let remove_zero_ticket_entries orig_ctxt = - let open Lwt_syntax in - let* res = remove_zero_ticket_entries orig_ctxt in - match res with - | Error e -> - Logging.( - log - Warning - "Trying to remove zero tickets from Mainnet context failed with \ - error (ignore this message on testnets): %a" - Error_monad.pp_trace - e) ; - return orig_ctxt - | Ok ctxt -> return ctxt -- GitLab From af8fb28b99cbbd2d16c3850497665f7a430012a1 Mon Sep 17 00:00:00 2001 From: Julien Tesson Date: Tue, 12 Dec 2023 17:12:11 +0100 Subject: [PATCH 4/7] proto/init_storage: stitch from Oxford - remove migrations for O This removes AI and consensus keys migration code for O --- src/proto_alpha/lib_protocol/init_storage.ml | 142 ------------------- 1 file changed, 142 deletions(-) diff --git a/src/proto_alpha/lib_protocol/init_storage.ml b/src/proto_alpha/lib_protocol/init_storage.ml index 202d2150d2f9..dae4232fb8da 100644 --- a/src/proto_alpha/lib_protocol/init_storage.ml +++ b/src/proto_alpha/lib_protocol/init_storage.ml @@ -109,142 +109,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* frozen_deposits_opt = - Storage.Contract.Frozen_deposits_up_to_Nairobi.find ctxt delegate_contract - in - let own_frozen = - match frozen_deposits_opt with - | Some {current_amount; initial_amount = _} -> current_amount - | None -> Tez_repr.zero - 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 - (Full_staking_balance_repr.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 ~weighted_delegated:delegated - | None -> - Stake_repr.make ~frozen:old_stake ~weighted_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 = let open Lwt_result_syntax in @@ -337,12 +201,6 @@ let prepare_first_block chain_id ctxt ~typecheck_smart_contract let*! ctxt = Storage.Tenderbake.Attestation_branch.add_or_remove ctxt opt in - let* ctxt = migrate_staking_balance_for_o ctxt in - let* ctxt = clear_staking_balance_snapshots_for_o ctxt in - let* ctxt = migrate_stake_distribution_for_o ctxt in - let*! ctxt = initialize_total_supply_for_o chain_id ctxt in - let* ctxt = Adaptive_issuance_storage.init ctxt in - let*! ctxt = migrate_pending_consensus_keys_for_o ctxt in (* Migration of refutation games needs to be kept for each protocol. *) let* ctxt = Sc_rollup_refutation_storage.migrate_clean_refutation_games ctxt -- GitLab From 8ef0dd8860606e04565fdbe9915b2241b83a2cc0 Mon Sep 17 00:00:00 2001 From: Julien Tesson Date: Wed, 13 Dec 2023 10:25:46 +0100 Subject: [PATCH 5/7] proto/storage: stitch from Oxford - removing Endorsement_branch --- src/proto_alpha/lib_protocol/init_storage.ml | 5 ----- src/proto_alpha/lib_protocol/storage.ml | 7 ------- src/proto_alpha/lib_protocol/storage.mli | 10 ---------- 3 files changed, 22 deletions(-) diff --git a/src/proto_alpha/lib_protocol/init_storage.ml b/src/proto_alpha/lib_protocol/init_storage.ml index dae4232fb8da..e5958cf63513 100644 --- a/src/proto_alpha/lib_protocol/init_storage.ml +++ b/src/proto_alpha/lib_protocol/init_storage.ml @@ -196,11 +196,6 @@ let prepare_first_block chain_id ctxt ~typecheck_smart_contract let* ctxt = Storage.Tenderbake.First_level_of_protocol.update ctxt level in - let* opt = Storage.Tenderbake.Endorsement_branch.find ctxt in - let*! ctxt = Storage.Tenderbake.Endorsement_branch.remove ctxt in - let*! ctxt = - Storage.Tenderbake.Attestation_branch.add_or_remove ctxt opt - in (* Migration of refutation games needs to be kept for each protocol. *) let* ctxt = Sc_rollup_refutation_storage.migrate_clean_refutation_games ctxt diff --git a/src/proto_alpha/lib_protocol/storage.ml b/src/proto_alpha/lib_protocol/storage.ml index 4fb55ad496ec..0c9b54d0e464 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 e9f09cb9ef88..372dda037a37 100644 --- a/src/proto_alpha/lib_protocol/storage.mli +++ b/src/proto_alpha/lib_protocol/storage.mli @@ -830,16 +830,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 : -- GitLab From f238f0cbe85f92714cf42c6c270d71a8d355e49f Mon Sep 17 00:00:00 2001 From: Julien Tesson Date: Wed, 13 Dec 2023 10:36:19 +0100 Subject: [PATCH 6/7] tezt/tezos: stitch from Oxford - Alpha comes after Oxford --- tezt/lib_tezos/protocol.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tezt/lib_tezos/protocol.ml b/tezt/lib_tezos/protocol.ml index 4872cb57c237..23634d8fdef3 100644 --- a/tezt/lib_tezos/protocol.ml +++ b/tezt/lib_tezos/protocol.ml @@ -278,7 +278,7 @@ let write_parameter_file : Lwt.return output_file let previous_protocol = function - | Alpha -> Some Nairobi + | Alpha -> Some Oxford | Oxford -> Some Nairobi | Nairobi -> None -- GitLab From cd03fd7a61045e5d1c22a3fcaffe582d6fabaa86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Thir=C3=A9?= Date: Thu, 14 Dec 2023 16:44:17 +0000 Subject: [PATCH 7/7] proto/raw_context: comments on dal constants --- src/proto_alpha/lib_protocol/raw_context.ml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/proto_alpha/lib_protocol/raw_context.ml b/src/proto_alpha/lib_protocol/raw_context.ml index f9d0c0824f67..d3ef6ce0fd5e 100644 --- a/src/proto_alpha/lib_protocol/raw_context.ml +++ b/src/proto_alpha/lib_protocol/raw_context.ml @@ -968,6 +968,9 @@ let prepare_first_block ~level ~timestamp _chain_id ctxt = | Oxford_018 -> let*! c = get_previous_protocol_constants ctxt in + (* When modifying the line below, be careful that the values are + compatible with the encodings exported by the environment did not + change. *) let cryptobox_parameters = c.dal.cryptobox_parameters in let dal = Constants_parametric_repr. @@ -991,9 +994,12 @@ let prepare_first_block ~level ~timestamp _chain_id ctxt = else ok () in let dal_activation_level = - if c.dal.feature_enable then Raw_level_repr.root + if c.dal.feature_enable then + (* if dal was enable in previous protocol, do as if it were always + activated *) + Raw_level_repr.root else if dal.feature_enable then - (* First level of the protocol with dal activated. *) + (* dal activates at first level of the new protocol. *) Raw_level_repr.of_int32_exn (Int32.succ level) else (* Deactivate the reveal if the dal is not enabled. -- GitLab