From a12194c68bb9ca8a82366d23d9cf445f5ac2fe2a Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Tue, 10 Oct 2023 17:27:49 +0200 Subject: [PATCH 1/2] Revert "Proto: Migrate from Oxford" This reverts commit c4cb4a44765a6a238b9775d4edc717f1c343093e. --- .../constants_parametric_previous_repr.ml | 411 +++++++----------- .../constants_parametric_previous_repr.mli | 109 ++--- src/proto_alpha/lib_protocol/init_storage.ml | 153 ++++++- src/proto_alpha/lib_protocol/raw_context.ml | 92 ++-- src/proto_alpha/lib_protocol/raw_context.mli | 2 +- src/proto_alpha/lib_protocol/storage.ml | 7 + src/proto_alpha/lib_protocol/storage.mli | 10 + tezt/lib_tezos/protocol.ml | 6 +- 8 files changed, 414 insertions(+), 376 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 42bf8352e3e4..910fdbcde1a9 100644 --- a/src/proto_alpha/lib_protocol/constants_parametric_previous_repr.ml +++ b/src/proto_alpha/lib_protocol/constants_parametric_previous_repr.ml @@ -83,32 +83,24 @@ 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 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; +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; } -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; @@ -123,40 +115,12 @@ 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 = { @@ -170,15 +134,18 @@ 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; - issuance_weights : issuance_weights; + baking_reward_fixed_portion : Tez_repr.t; + baking_reward_bonus_per_slot : Tez_repr.t; + endorsing_reward_per_slot : Tez_repr.t; 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; @@ -187,9 +154,9 @@ type t = { consensus_committee_size : int; consensus_threshold : int; max_slashing_period : int; - limit_of_delegation_over_baking : int; - percentage_of_frozen_deposits_slashed_per_double_baking : int; - percentage_of_frozen_deposits_slashed_per_double_attestation : int; + frozen_deposits_percentage : int; + double_baking_punishment : Tez_repr.t; + ratio_of_frozen_deposits_slashed_per_double_attestation : Ratio_repr.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 @@ -197,12 +164,82 @@ 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 @@ -219,8 +256,7 @@ 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.reveal_activation_level ) )) + c.max_number_of_parallel_games ) )) (fun ( ( sc_rollup_enable, sc_rollup_arith_pvm_enable, sc_rollup_origination_size, @@ -233,8 +269,7 @@ 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_reveal_activation_level ) ) -> + sc_rollup_max_number_of_parallel_games ) ) -> { enable = sc_rollup_enable; arith_pvm_enable = sc_rollup_arith_pvm_enable; @@ -251,7 +286,6 @@ 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 @@ -264,189 +298,29 @@ 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)) - (obj5 + (obj4 (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_reveal_activation_level" - sc_rollup_reveal_activation_level_encoding))) + (req "smart_rollup_max_number_of_parallel_games" int31))) let zk_rollup_encoding = let open Data_encoding in conv - (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 ({enable; origination_size; min_pending_to_process} : zk_rollup) -> + (enable, origination_size, min_pending_to_process)) (fun ( zk_rollup_enable, zk_rollup_origination_size, - zk_rollup_min_pending_to_process, - zk_rollup_max_ticket_payload_size ) -> + zk_rollup_min_pending_to_process ) -> { 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; }) - (obj4 + (obj3 (req "zk_rollup_enable" bool) (req "zk_rollup_origination_size" 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)) + (req "zk_rollup_min_pending_to_process" int31)) let encoding = let open Data_encoding in @@ -462,15 +336,18 @@ let encoding = c.hard_gas_limit_per_block, c.proof_of_work_threshold, c.minimal_stake ), - ( ( c.minimal_frozen_stake, - c.vdf_difficulty, + ( ( c.vdf_difficulty, + c.seed_nonce_revelation_tip, c.origination_size, - c.issuance_weights, + c.baking_reward_fixed_portion, + c.baking_reward_bonus_per_slot, + c.endorsing_reward_per_slot, 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, @@ -479,16 +356,15 @@ let encoding = c.consensus_threshold ), ( ( c.minimal_participation_ratio, c.max_slashing_period, - 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.frozen_deposits_percentage, + c.double_baking_punishment, + c.ratio_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.dal, ((c.sc_rollup, c.zk_rollup), c.adaptive_issuance)) ) ) - ) ) )) + (c.tx_rollup, (c.dal, (c.sc_rollup, c.zk_rollup))) ) ) ) ) )) (fun ( ( preserved_cycles, blocks_per_cycle, blocks_per_commitment, @@ -499,15 +375,18 @@ let encoding = hard_gas_limit_per_block, proof_of_work_threshold, minimal_stake ), - ( ( minimal_frozen_stake, - vdf_difficulty, + ( ( vdf_difficulty, + seed_nonce_revelation_tip, origination_size, - issuance_weights, + baking_reward_fixed_portion, + baking_reward_bonus_per_slot, + endorsing_reward_per_slot, 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, @@ -516,15 +395,15 @@ let encoding = consensus_threshold ), ( ( minimal_participation_ratio, max_slashing_period, - limit_of_delegation_over_baking, - percentage_of_frozen_deposits_slashed_per_double_baking, - percentage_of_frozen_deposits_slashed_per_double_attestation, + frozen_deposits_percentage, + double_baking_punishment, + ratio_of_frozen_deposits_slashed_per_double_attestation, testnet_dictator, initial_seed ), ( ( cache_script_size, cache_stake_distribution_cycles, cache_sampler_state_cycles ), - (dal, ((sc_rollup, zk_rollup), adaptive_issuance)) ) ) ) ) ) -> + (tx_rollup, (dal, (sc_rollup, zk_rollup))) ) ) ) ) ) -> { preserved_cycles; blocks_per_cycle; @@ -536,15 +415,18 @@ let encoding = hard_gas_limit_per_block; proof_of_work_threshold; minimal_stake; - minimal_frozen_stake; vdf_difficulty; + seed_nonce_revelation_tip; origination_size; - issuance_weights; + baking_reward_fixed_portion; + baking_reward_bonus_per_slot; + endorsing_reward_per_slot; 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; @@ -553,18 +435,18 @@ let encoding = max_slashing_period; consensus_committee_size; consensus_threshold; - limit_of_delegation_over_baking; - percentage_of_frozen_deposits_slashed_per_double_baking; - percentage_of_frozen_deposits_slashed_per_double_attestation; + frozen_deposits_percentage; + double_baking_punishment; + ratio_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 @@ -583,18 +465,21 @@ let encoding = (req "proof_of_work_threshold" int64) (req "minimal_stake" Tez_repr.encoding)) (merge_objs - (obj7 - (req "minimal_frozen_stake" Tez_repr.encoding) + (obj9 (req "vdf_difficulty" int64) + (req "seed_nonce_revelation_tip" Tez_repr.encoding) (req "origination_size" int31) - (req "issuance_weights" issuance_weights_encoding) + (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 "cost_per_byte" Tez_repr.encoding) (req "hard_storage_limit_per_operation" z) (req "quorum_min" int32)) (merge_objs - (obj8 + (obj9 (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) @@ -605,13 +490,11 @@ let encoding = (obj7 (req "minimal_participation_ratio" Ratio_repr.encoding) (req "max_slashing_period" int31) - (req "limit_of_delegation_over_baking" uint8) - (req - "percentage_of_frozen_deposits_slashed_per_double_baking" - uint8) + (req "frozen_deposits_percentage" int31) + (req "double_baking_punishment" Tez_repr.encoding) (req - "percentage_of_frozen_deposits_slashed_per_double_attestation" - uint8) + "ratio_of_frozen_deposits_slashed_per_double_endorsement" + Ratio_repr.encoding) (opt "testnet_dictator" Signature.Public_key_hash.encoding) (opt "initial_seed" State_hash.encoding)) (merge_objs @@ -620,7 +503,7 @@ let encoding = (req "cache_stake_distribution_cycles" int8) (req "cache_sampler_state_cycles" int8)) (merge_objs - (obj1 (req "dal_parametric" dal_encoding)) + tx_rollup_encoding (merge_objs - (merge_objs sc_rollup_encoding zk_rollup_encoding) - adaptive_issuance_encoding))))))) + (obj1 (req "dal_parametric" dal_encoding)) + (merge_objs sc_rollup_encoding zk_rollup_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 2a5881d9663a..294790c41a07 100644 --- a/src/proto_alpha/lib_protocol/constants_parametric_previous_repr.mli +++ b/src/proto_alpha/lib_protocol/constants_parametric_previous_repr.mli @@ -36,13 +36,53 @@ type dal = { val dal_encoding : dal Data_encoding.t -type sc_rollup_reveal_hashing_schemes = {blake2B : Raw_level_repr.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. -(** 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; + 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; } type sc_rollup = { @@ -84,8 +124,6 @@ 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 = { @@ -98,44 +136,6 @@ 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,16 +149,19 @@ 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; - issuance_weights : issuance_weights; + baking_reward_fixed_portion : Tez_repr.t; + baking_reward_bonus_per_slot : Tez_repr.t; + endorsing_reward_per_slot : Tez_repr.t; 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; @@ -170,10 +173,10 @@ type t = { (* in slots *) max_slashing_period : int; (* in cycles *) - 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; + 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; testnet_dictator : Signature.Public_key_hash.t option; initial_seed : State_hash.t option; cache_script_size : int; @@ -182,10 +185,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 27d7e71e2432..15ac9316f1a1 100644 --- a/src/proto_alpha/lib_protocol/init_storage.ml +++ b/src/proto_alpha/lib_protocol/init_storage.ml @@ -109,6 +109,137 @@ 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 + (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 @@ -189,7 +320,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) - | Oxford_018 + | Nairobi_017 (* 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); @@ -200,6 +331,26 @@ 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 + let* ctxt = + Storage.Tenderbake.Forbidden_delegates.init + ctxt + Signature.Public_key_hash.Set.empty + 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 = + 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. *) let* ctxt = Sc_rollup_refutation_storage.migrate_clean_refutation_games ctxt diff --git a/src/proto_alpha/lib_protocol/raw_context.ml b/src/proto_alpha/lib_protocol/raw_context.ml index 9568de2cac61..c11f60699332 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 | Oxford_018 +type previous_protocol = Genesis of Parameters_repr.t | Nairobi_017 let check_and_update_protocol_version ctxt = let open Lwt_result_syntax in @@ -907,7 +907,8 @@ 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 = "oxford_018") then return (Oxford_018, ctxt) + else if Compare.String.(s = "nairobi_017") then + return (Nairobi_017, ctxt) else Lwt.return @@ storage_error (Incompatible_protocol_version s) in let*! ctxt = @@ -946,7 +947,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 = @@ -965,11 +966,8 @@ 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 - | Oxford_018 -> + | Nairobi_017 -> let*! c = get_previous_protocol_constants ctxt in - let max_bonus = - Issuance_bonus_repr.max_bonus_parameter_of_Q_exn Q.(5 // 100) - in let cryptobox_parameters = { @@ -1006,12 +1004,10 @@ let prepare_first_block ~level ~timestamp _chain_id ctxt = let reveal_activation_level : Constants_parametric_repr.sc_rollup_reveal_activation_level = { - raw_data = - {blake2B = c.sc_rollup.reveal_activation_level.raw_data.blake2B}; - metadata = c.sc_rollup.reveal_activation_level.metadata; + raw_data = {blake2B = Raw_level_repr.root}; + metadata = Raw_level_repr.root; dal_page = - (if c.dal.feature_enable then - c.sc_rollup.reveal_activation_level.dal_page + (if c.dal.feature_enable then Raw_level_repr.root else if dal.feature_enable then (* First level of the protocol with dal activated. *) Raw_level_repr.of_int32_exn (Int32.succ level) @@ -1060,68 +1056,57 @@ 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.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; + max_ticket_payload_size = c.tx_rollup.max_ticket_payload_size; } in let adaptive_rewards_params = Constants_parametric_repr. { - 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; - (* 0.01% per 1% per day *) + 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 = c.adaptive_issuance.adaptive_rewards_params.center_dz; - radius_dz = c.adaptive_issuance.adaptive_rewards_params.radius_dz; + center_dz = Q.(50 // 100); + radius_dz = Q.(2 // 100); } in let adaptive_issuance = Constants_parametric_repr. { - 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; + 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); adaptive_rewards_params; activation_vote_enable = false; } 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_baking = Int_percentage.p7 in let percentage_of_frozen_deposits_slashed_per_double_attestation = Int_percentage.of_ratio_bounded - { - numerator = - c.percentage_of_frozen_deposits_slashed_per_double_attestation; - denominator = 100; - } + 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)) in let constants = Constants_parametric_repr. @@ -1136,7 +1121,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 = c.minimal_frozen_stake; + minimal_frozen_stake; vdf_difficulty = c.vdf_difficulty; origination_size = c.origination_size; max_operations_time_to_live = c.max_operations_time_to_live; @@ -1154,8 +1139,7 @@ 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 = - c.limit_of_delegation_over_baking; + limit_of_delegation_over_baking; percentage_of_frozen_deposits_slashed_per_double_baking; percentage_of_frozen_deposits_slashed_per_double_attestation; (* The `testnet_dictator` should absolutely be None on mainnet *) diff --git a/src/proto_alpha/lib_protocol/raw_context.mli b/src/proto_alpha/lib_protocol/raw_context.mli index b6f5c69d3747..e144bf316515 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 | Oxford_018 +type previous_protocol = Genesis of Parameters_repr.t | Nairobi_017 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 3f35369f00a6..758b9a89a0e5 100644 --- a/src/proto_alpha/lib_protocol/storage.ml +++ b/src/proto_alpha/lib_protocol/storage.ml @@ -123,6 +123,13 @@ 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 5003856e37c0..ac7ea89219c3 100644 --- a/src/proto_alpha/lib_protocol/storage.mli +++ b/src/proto_alpha/lib_protocol/storage.mli @@ -827,6 +827,16 @@ 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 b3c85003f55f..216758ccb2ac 100644 --- a/tezt/lib_tezos/protocol.ml +++ b/tezt/lib_tezos/protocol.ml @@ -261,12 +261,12 @@ let write_parameter_file : Lwt.return output_file let next_protocol = function - | Nairobi -> Some Oxford - | Oxford -> Some Alpha + | Nairobi -> Some Alpha + | Oxford -> None | Alpha -> None let previous_protocol = function - | Alpha -> Some Oxford + | Alpha -> Some Nairobi | Oxford -> Some Nairobi | Nairobi -> None -- GitLab From 11f76d4dd7ab320d38005bc7614d11229d7264a6 Mon Sep 17 00:00:00 2001 From: Albin Coquereau Date: Tue, 24 Oct 2023 12:18:37 +0200 Subject: [PATCH 2/2] fixup! Revert "Proto: Migrate from Oxford" --- tezt/tests/protocol_migration.ml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tezt/tests/protocol_migration.ml b/tezt/tests/protocol_migration.ml index f5b4d7d77b19..b2d47e0c2cd7 100644 --- a/tezt/tests/protocol_migration.ml +++ b/tezt/tests/protocol_migration.ml @@ -924,7 +924,10 @@ let test_forked_migration_bakers ~migrate_from ~migrate_to = let expected_count = if level_from = post_migration_level then 0 else n_delegates in - check_attestations ~protocol:migrate_from ~expected_count consensus_ops ; + let protocol = + if level_from > migration_level then migrate_to else migrate_from + in + check_attestations ~protocol ~expected_count consensus_ops ; check_blocks ~level_from:(level_from + 1) ~level_to) in check_blocks ~level_from ~level_to -- GitLab