From 519a0194a9fb7147d138a0304bb809700574761b Mon Sep 17 00:00:00 2001 From: Albin Coquereau Date: Fri, 12 Jul 2024 11:01:28 +0200 Subject: [PATCH] alpha: introduce stitching from alpha --- src/proto_alpha/lib_protocol/init_storage.ml | 13 + src/proto_alpha/lib_protocol/raw_context.ml | 286 ++++++++++++++++++- src/proto_alpha/lib_protocol/raw_context.mli | 2 +- 3 files changed, 299 insertions(+), 2 deletions(-) diff --git a/src/proto_alpha/lib_protocol/init_storage.ml b/src/proto_alpha/lib_protocol/init_storage.ml index 6bb14abe9637..abc55eaac64c 100644 --- a/src/proto_alpha/lib_protocol/init_storage.ml +++ b/src/proto_alpha/lib_protocol/init_storage.ml @@ -195,6 +195,19 @@ 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) + | Alpha -> + (* TODO (#2704): possibly handle attestations for migration block (in bakers); + if that is done, do not set Storage.Tenderbake.First_level_of_protocol. + /!\ this storage is also use to add the smart rollup + inbox migration message. see `sc_rollup_inbox_storage`. *) + let* ctxt = + Storage.Tenderbake.First_level_of_protocol.update ctxt level + in + (* Migration of refutation games needs to be kept for each protocol. *) + let* ctxt = + Sc_rollup_refutation_storage.migrate_clean_refutation_games ctxt + in + return (ctxt, []) | ParisC_020 (* Please update [next_protocol] and [previous_protocol] in [tezt/lib_tezos/protocol.ml] when you update this value. *) -> diff --git a/src/proto_alpha/lib_protocol/raw_context.ml b/src/proto_alpha/lib_protocol/raw_context.ml index 0ff7eb24dd68..1f163fa64e77 100644 --- a/src/proto_alpha/lib_protocol/raw_context.ml +++ b/src/proto_alpha/lib_protocol/raw_context.ml @@ -881,7 +881,7 @@ let prepare ~level ~predecessor_timestamp ~timestamp ~adaptive_issuance_enable }; } -type previous_protocol = Genesis of Parameters_repr.t | ParisC_020 +type previous_protocol = Genesis of Parameters_repr.t | Alpha | ParisC_020 let check_and_update_protocol_version ctxt = let open Lwt_result_syntax in @@ -897,6 +897,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 = "alpha_current") then return (Alpha, ctxt) else if Compare.String.(s = "paris_020") then return (ParisC_020, ctxt) else Lwt.return @@ storage_error (Incompatible_protocol_version s) in @@ -1016,6 +1017,289 @@ 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, None) + | Alpha -> + let module Previous = Constants_parametric_repr in + let* c = get_constants ctxt in + let dal = + let ({ + feature_enable; + incentives_enable; + number_of_slots; + attestation_lag; + attestation_threshold; + cryptobox_parameters; + } + : Previous.dal) = + c.dal + in + { + Constants_parametric_repr.feature_enable; + incentives_enable; + number_of_slots; + attestation_lag; + attestation_threshold; + cryptobox_parameters; + } + in + let reveal_activation_level = + let ({ + raw_data; + metadata; + dal_page; + dal_parameters; + dal_attested_slots_validity_lag; + } + : Previous.sc_rollup_reveal_activation_level) = + c.sc_rollup.reveal_activation_level + in + let raw_data = + Constants_parametric_repr.{blake2B = raw_data.blake2B} + in + { + Constants_parametric_repr.raw_data; + metadata; + dal_page; + dal_parameters; + dal_attested_slots_validity_lag; + } + in + let sc_rollup = + let ({ + arith_pvm_enable; + origination_size; + challenge_window_in_blocks; + stake_amount; + commitment_period_in_blocks; + max_lookahead_in_blocks; + max_active_outbox_levels; + max_outbox_messages_per_level; + number_of_sections_in_dissection; + timeout_period_in_blocks; + max_number_of_stored_cemented_commitments; + max_number_of_parallel_games; + reveal_activation_level = _; + private_enable; + riscv_pvm_enable; + } + : Previous.sc_rollup) = + c.sc_rollup + in + Constants_parametric_repr. + { + arith_pvm_enable; + origination_size; + challenge_window_in_blocks; + stake_amount; + commitment_period_in_blocks; + max_lookahead_in_blocks; + max_active_outbox_levels; + max_outbox_messages_per_level; + number_of_sections_in_dissection; + timeout_period_in_blocks; + max_number_of_stored_cemented_commitments; + max_number_of_parallel_games; + reveal_activation_level; + private_enable; + riscv_pvm_enable; + } + in + let zk_rollup = + let ({ + enable; + origination_size; + min_pending_to_process; + max_ticket_payload_size; + } + : Previous.zk_rollup) = + c.zk_rollup + in + Constants_parametric_repr. + { + enable; + origination_size; + min_pending_to_process; + max_ticket_payload_size; + } + in + let adaptive_rewards_params = + let ({ + issuance_ratio_final_min; + issuance_ratio_final_max; + issuance_ratio_initial_min; + issuance_ratio_initial_max; + initial_period; + transition_period; + max_bonus; + growth_rate; + center_dz; + radius_dz; + } + : Previous.adaptive_rewards_params) = + c.adaptive_issuance.adaptive_rewards_params + in + Constants_parametric_repr. + { + issuance_ratio_final_min; + issuance_ratio_final_max; + issuance_ratio_initial_min; + issuance_ratio_initial_max; + initial_period; + transition_period; + max_bonus; + growth_rate; + center_dz; + radius_dz; + } + in + let adaptive_issuance = + let ({ + global_limit_of_staking_over_baking; + edge_of_staking_over_delegation; + launch_ema_threshold; + adaptive_rewards_params = _; + activation_vote_enable; + autostaking_enable; + force_activation; + ns_enable; + } + : Previous.adaptive_issuance) = + c.adaptive_issuance + in + Constants_parametric_repr. + { + global_limit_of_staking_over_baking; + edge_of_staking_over_delegation; + launch_ema_threshold; + adaptive_rewards_params; + activation_vote_enable; + autostaking_enable; + force_activation; + ns_enable; + } + in + let issuance_weights = + let ({ + base_total_issued_per_minute; + baking_reward_fixed_portion_weight; + baking_reward_bonus_weight; + attesting_reward_weight; + seed_nonce_revelation_tip_weight; + vdf_revelation_tip_weight; + } + : Previous.issuance_weights) = + c.issuance_weights + in + { + Constants_parametric_repr.base_total_issued_per_minute; + baking_reward_fixed_portion_weight; + baking_reward_bonus_weight; + attesting_reward_weight; + seed_nonce_revelation_tip_weight; + vdf_revelation_tip_weight; + } + in + let constants = + let ({ + consensus_rights_delay; + blocks_preservation_cycles; + delegate_parameters_activation_delay; + blocks_per_cycle; + blocks_per_commitment; + nonce_revelation_threshold; + cycles_per_voting_period; + hard_gas_limit_per_operation; + hard_gas_limit_per_block; + proof_of_work_threshold; + minimal_stake; + minimal_frozen_stake; + vdf_difficulty; + origination_size; + max_operations_time_to_live; + issuance_weights = _; + cost_per_byte; + hard_storage_limit_per_operation; + quorum_min; + quorum_max; + min_proposal_quorum; + liquidity_baking_subsidy; + liquidity_baking_toggle_ema_threshold; + minimal_block_delay; + delay_increment_per_round; + consensus_committee_size; + consensus_threshold; + minimal_participation_ratio; + limit_of_delegation_over_baking; + percentage_of_frozen_deposits_slashed_per_double_baking; + percentage_of_frozen_deposits_slashed_per_double_attestation; + max_slashing_per_block; + max_slashing_threshold; + (* The `testnet_dictator` should absolutely be None on mainnet *) + testnet_dictator; + initial_seed; + cache_script_size; + cache_stake_distribution_cycles; + cache_sampler_state_cycles; + dal = _; + sc_rollup = _; + zk_rollup = _; + adaptive_issuance = _; + direct_ticket_spending_enable; + } + : Previous.t) = + c + in + { + Constants_parametric_repr.consensus_rights_delay; + blocks_preservation_cycles; + delegate_parameters_activation_delay; + blocks_per_cycle; + blocks_per_commitment; + nonce_revelation_threshold; + cycles_per_voting_period; + hard_gas_limit_per_operation; + hard_gas_limit_per_block; + proof_of_work_threshold; + minimal_stake; + minimal_frozen_stake; + vdf_difficulty; + origination_size; + max_operations_time_to_live; + issuance_weights; + cost_per_byte; + hard_storage_limit_per_operation; + quorum_min; + quorum_max; + min_proposal_quorum; + liquidity_baking_subsidy; + liquidity_baking_toggle_ema_threshold; + minimal_block_delay; + delay_increment_per_round; + consensus_committee_size; + consensus_threshold; + minimal_participation_ratio; + limit_of_delegation_over_baking; + percentage_of_frozen_deposits_slashed_per_double_baking; + percentage_of_frozen_deposits_slashed_per_double_attestation; + max_slashing_per_block; + max_slashing_threshold; + (* The `testnet_dictator` should absolutely be None on mainnet *) + testnet_dictator; + initial_seed; + cache_script_size; + cache_stake_distribution_cycles; + cache_sampler_state_cycles; + dal; + sc_rollup; + zk_rollup; + adaptive_issuance; + direct_ticket_spending_enable; + } + in + let*! ctxt = add_constants ctxt constants in + (* This line is only here to please the typechecker, + it should be removed in beta when stabilising *) + let*! c = get_previous_protocol_constants ctxt in + return (ctxt, Some c) | ParisC_020 -> let*! c = get_previous_protocol_constants ctxt in diff --git a/src/proto_alpha/lib_protocol/raw_context.mli b/src/proto_alpha/lib_protocol/raw_context.mli index e1215c20854f..c3ccfeb337e3 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 | ParisC_020 +type previous_protocol = Genesis of Parameters_repr.t | Alpha | ParisC_020 val prepare_first_block : level:int32 -> -- GitLab