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 1cdbd9b2d5ac0d048bff588a53975e1361686766..6d8678201e3360606d60e3617a389ba2248b0feb 100644 --- a/src/proto_alpha/lib_protocol/constants_parametric_previous_repr.ml +++ b/src/proto_alpha/lib_protocol/constants_parametric_previous_repr.ml @@ -25,16 +25,99 @@ (* *) (*****************************************************************************) +type dal = { + feature_enable : bool; + number_of_slots : int; + number_of_shards : int; + endorsement_lag : int; + availability_threshold : int; +} + +let dal_encoding = + let open Data_encoding in + conv + (fun { + feature_enable; + number_of_slots; + number_of_shards; + endorsement_lag; + availability_threshold; + } -> + ( feature_enable, + number_of_slots, + number_of_shards, + endorsement_lag, + availability_threshold )) + (fun ( feature_enable, + number_of_slots, + number_of_shards, + endorsement_lag, + availability_threshold ) -> + { + feature_enable; + number_of_slots; + number_of_shards; + endorsement_lag; + availability_threshold; + }) + (obj5 + (req "feature_enable" Data_encoding.bool) + (req "number_of_slots" Data_encoding.int16) + (req "number_of_shards" Data_encoding.int16) + (req "endorsement_lag" Data_encoding.int16) + (req "availability_threshold" Data_encoding.int16)) + +(* The encoded representation of this type is stored in the context as + bytes. Changing the encoding, or the value of these constants from + the previous protocol may break the context migration, or (even + worse) yield an incorrect context after migration. + + If you change this encoding compared to `Constants_parametric_previous_repr.t`, + 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 = { + enable : bool; + origination_size : int; + challenge_window_in_blocks : int; + max_available_messages : int; + stake_amount : Tez_repr.t; + commitment_period_in_blocks : int; + max_lookahead_in_blocks : int32; + max_active_outbox_levels : int32; + max_outbox_messages_per_level : int; +} + type t = { preserved_cycles : int; blocks_per_cycle : int32; blocks_per_commitment : int32; + nonce_revelation_threshold : int32; blocks_per_stake_snapshot : int32; cycles_per_voting_period : int32; hard_gas_limit_per_operation : Gas_limit_repr.Arith.integral; hard_gas_limit_per_block : Gas_limit_repr.Arith.integral; proof_of_work_threshold : int64; tokens_per_roll : Tez_repr.t; + vdf_difficulty : int64; seed_nonce_revelation_tip : Tez_repr.t; origination_size : int; baking_reward_fixed_portion : Tez_repr.t; @@ -58,31 +141,132 @@ type t = { frozen_deposits_percentage : int; double_baking_punishment : Tez_repr.t; ratio_of_frozen_deposits_slashed_per_double_endorsement : 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 + [cache_layout_size] value. *) cache_script_size : int; cache_stake_distribution_cycles : int; cache_sampler_state_cycles : int; - tx_rollup_enable : bool; - tx_rollup_origination_size : int; - tx_rollup_hard_size_limit_per_inbox : int; - tx_rollup_hard_size_limit_per_message : int; - tx_rollup_commitment_bond : Tez_repr.t; - tx_rollup_finality_period : int; - tx_rollup_withdraw_period : int; - tx_rollup_max_inboxes_count : int; - tx_rollup_max_messages_per_inbox : int; - tx_rollup_max_commitments_count : int; - tx_rollup_cost_per_byte_ema_factor : int; - tx_rollup_max_ticket_payload_size : int; - tx_rollup_max_withdrawals_per_batch : int; - tx_rollup_rejection_max_proof_size : int; - tx_rollup_sunset_level : int32; - sc_rollup_enable : bool; - sc_rollup_origination_size : int; - sc_rollup_challenge_window_in_blocks : int; - sc_rollup_max_available_messages : int; + tx_rollup : tx_rollup; + dal : dal; + sc_rollup : sc_rollup; } +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.origination_size, + c.challenge_window_in_blocks, + c.max_available_messages, + c.stake_amount, + c.commitment_period_in_blocks, + c.max_lookahead_in_blocks, + c.max_active_outbox_levels, + c.max_outbox_messages_per_level )) + (fun ( sc_rollup_enable, + sc_rollup_origination_size, + sc_rollup_challenge_window_in_blocks, + sc_rollup_max_available_messages, + sc_rollup_stake_amount, + sc_rollup_commitment_period_in_blocks, + sc_rollup_max_lookahead_in_blocks, + sc_rollup_max_active_outbox_levels, + sc_rollup_max_outbox_messages_per_level ) -> + { + enable = sc_rollup_enable; + origination_size = sc_rollup_origination_size; + challenge_window_in_blocks = sc_rollup_challenge_window_in_blocks; + max_available_messages = sc_rollup_max_available_messages; + stake_amount = sc_rollup_stake_amount; + commitment_period_in_blocks = sc_rollup_commitment_period_in_blocks; + max_lookahead_in_blocks = sc_rollup_max_lookahead_in_blocks; + max_active_outbox_levels = sc_rollup_max_active_outbox_levels; + max_outbox_messages_per_level = sc_rollup_max_outbox_messages_per_level; + }) + (obj9 + (req "sc_rollup_enable" bool) + (req "sc_rollup_origination_size" int31) + (req "sc_rollup_challenge_window_in_blocks" int31) + (req "sc_rollup_max_available_messages" int31) + (req "sc_rollup_stake_amount" Tez_repr.encoding) + (req "sc_rollup_commitment_period_in_blocks" int31) + (req "sc_rollup_max_lookahead_in_blocks" int32) + (req "sc_rollup_max_active_outbox_levels" int32) + (req "sc_rollup_max_outbox_messages_per_level" int31)) + let encoding = let open Data_encoding in conv @@ -90,13 +274,15 @@ let encoding = ( ( c.preserved_cycles, c.blocks_per_cycle, c.blocks_per_commitment, + c.nonce_revelation_threshold, c.blocks_per_stake_snapshot, c.cycles_per_voting_period, c.hard_gas_limit_per_operation, c.hard_gas_limit_per_block, c.proof_of_work_threshold, c.tokens_per_roll ), - ( ( c.seed_nonce_revelation_tip, + ( ( c.vdf_difficulty, + c.seed_nonce_revelation_tip, c.origination_size, c.baking_reward_fixed_portion, c.baking_reward_bonus_per_slot, @@ -119,39 +305,24 @@ let encoding = c.frozen_deposits_percentage, c.double_baking_punishment, c.ratio_of_frozen_deposits_slashed_per_double_endorsement, + c.testnet_dictator, c.initial_seed ), ( ( c.cache_script_size, c.cache_stake_distribution_cycles, c.cache_sampler_state_cycles ), - ( ( ( c.tx_rollup_enable, - c.tx_rollup_origination_size, - c.tx_rollup_hard_size_limit_per_inbox, - c.tx_rollup_hard_size_limit_per_message, - c.tx_rollup_max_withdrawals_per_batch, - c.tx_rollup_commitment_bond, - c.tx_rollup_finality_period, - c.tx_rollup_withdraw_period, - c.tx_rollup_max_inboxes_count, - c.tx_rollup_max_messages_per_inbox ), - ( c.tx_rollup_max_commitments_count, - c.tx_rollup_cost_per_byte_ema_factor, - c.tx_rollup_max_ticket_payload_size, - c.tx_rollup_rejection_max_proof_size, - c.tx_rollup_sunset_level ) ), - ( c.sc_rollup_enable, - c.sc_rollup_origination_size, - c.sc_rollup_challenge_window_in_blocks, - c.sc_rollup_max_available_messages ) ) ) ) ) ) )) + (c.tx_rollup, (c.dal, c.sc_rollup)) ) ) ) ) )) (fun ( ( preserved_cycles, blocks_per_cycle, blocks_per_commitment, + nonce_revelation_threshold, blocks_per_stake_snapshot, cycles_per_voting_period, hard_gas_limit_per_operation, hard_gas_limit_per_block, proof_of_work_threshold, tokens_per_roll ), - ( ( seed_nonce_revelation_tip, + ( ( vdf_difficulty, + seed_nonce_revelation_tip, origination_size, baking_reward_fixed_portion, baking_reward_bonus_per_slot, @@ -174,39 +345,24 @@ let encoding = frozen_deposits_percentage, double_baking_punishment, ratio_of_frozen_deposits_slashed_per_double_endorsement, + testnet_dictator, initial_seed ), ( ( cache_script_size, cache_stake_distribution_cycles, cache_sampler_state_cycles ), - ( ( ( 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 ) ), - ( sc_rollup_enable, - sc_rollup_origination_size, - sc_rollup_challenge_window_in_blocks, - sc_rollup_max_available_messages ) ) ) ) ) ) ) -> + (tx_rollup, (dal, sc_rollup)) ) ) ) ) ) -> { preserved_cycles; blocks_per_cycle; blocks_per_commitment; + nonce_revelation_threshold; blocks_per_stake_snapshot; cycles_per_voting_period; hard_gas_limit_per_operation; hard_gas_limit_per_block; proof_of_work_threshold; tokens_per_roll; + vdf_difficulty; seed_nonce_revelation_tip; origination_size; baking_reward_fixed_portion; @@ -230,35 +386,21 @@ let encoding = frozen_deposits_percentage; double_baking_punishment; ratio_of_frozen_deposits_slashed_per_double_endorsement; + testnet_dictator; initial_seed; cache_script_size; cache_stake_distribution_cycles; cache_sampler_state_cycles; - 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; - sc_rollup_enable; - sc_rollup_origination_size; - sc_rollup_challenge_window_in_blocks; - sc_rollup_max_available_messages; + tx_rollup; + dal; + sc_rollup; }) (merge_objs - (obj9 + (obj10 (req "preserved_cycles" uint8) (req "blocks_per_cycle" int32) (req "blocks_per_commitment" int32) + (req "nonce_revelation_threshold" int32) (req "blocks_per_stake_snapshot" int32) (req "cycles_per_voting_period" int32) (req @@ -270,7 +412,8 @@ let encoding = (req "proof_of_work_threshold" int64) (req "tokens_per_roll" Tez_repr.encoding)) (merge_objs - (obj8 + (obj9 + (req "vdf_difficulty" int64) (req "seed_nonce_revelation_tip" Tez_repr.encoding) (req "origination_size" int31) (req "baking_reward_fixed_portion" Tez_repr.encoding) @@ -292,7 +435,7 @@ let encoding = (req "consensus_committee_size" int31) (req "consensus_threshold" int31)) (merge_objs - (obj6 + (obj7 (req "minimal_participation_ratio" Ratio_repr.encoding) (req "max_slashing_period" int31) (req "frozen_deposits_percentage" int31) @@ -300,6 +443,7 @@ let encoding = (req "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 (obj3 @@ -307,26 +451,7 @@ let encoding = (req "cache_stake_distribution_cycles" int8) (req "cache_sampler_state_cycles" int8)) (merge_objs + tx_rollup_encoding (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))) - (obj4 - (req "sc_rollup_enable" bool) - (req "sc_rollup_origination_size" int31) - (req "sc_rollup_challenge_window_in_blocks" int31) - (req "sc_rollup_max_available_messages" int31)))))))) + (obj1 (req "dal_parametric" dal_encoding)) + sc_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 aa70452999d5aa5bd61bf71278277d61dc7a60c0..41a652bc63cbde746bccb75b0d0a30b603c5d082 100644 --- a/src/proto_alpha/lib_protocol/constants_parametric_previous_repr.mli +++ b/src/proto_alpha/lib_protocol/constants_parametric_previous_repr.mli @@ -25,16 +25,95 @@ (* *) (*****************************************************************************) +type dal = { + feature_enable : bool; + number_of_slots : int; + number_of_shards : int; + endorsement_lag : int; + availability_threshold : int; +} + +val dal_encoding : dal Data_encoding.t + +type tx_rollup = { + enable : bool; + origination_size : int; + (* the maximum amount of bytes messages can allocate in an inbox *) + hard_size_limit_per_inbox : int; + (* the maximum amount of bytes one batch can allocate in an inbox *) + hard_size_limit_per_message : int; + (* the amount of tez to bond a tx rollup commitment *) + commitment_bond : Tez_repr.t; + (* the number of blocks before a tx rollup block is final *) + finality_period : int; + (* the maximum number of levels that can be left unfinalized + before we stop accepting new inboxes for a tx rollup *) + (* the minimum number of blocks to wait before removing a finalised + commitment from the context. *) + withdraw_period : int; + max_inboxes_count : int; + (* the maximum number of messages in an inbox. This bounds the + size of a commitment. *) + max_messages_per_inbox : int; + (* the maximum number of finalized commitments, to ensure that + remove_commitment is ever called *) + max_commitments_count : int; + (* The number of blocks used to compute the ema factor determining + the cost per byte for new messages in the inbox. *) + cost_per_byte_ema_factor : int; + (* Tickets are transmitted in batches in the + [Tx_rollup_dispatch_tickets] operation. + + The semantics is that this operation is used to + concretize the withdraw orders emitted by the layer-2, + one layer-1 operation per messages of an + inbox. Therefore, it is of significant importance that + a valid batch does not produce a list of withdraw + orders which could not fit in a layer-1 operation. + + 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 = { + enable : bool; + origination_size : int; + challenge_window_in_blocks : int; + max_available_messages : int; + stake_amount : Tez_repr.t; + (* The period with which commitments are made. *) + commitment_period_in_blocks : int; + (* The maximum depth of a staker's position - chosen alongside + [commitment_period_in_blocks] to prevent the cost + of a staker's commitments' storage being greater than their deposit. *) + max_lookahead_in_blocks : int32; + (* Maximum number of active outbox levels allowed. An outbox level is active + if it has an associated record of applied messages. *) + max_active_outbox_levels : int32; + max_outbox_messages_per_level : int; +} + type t = { preserved_cycles : int; blocks_per_cycle : int32; blocks_per_commitment : int32; + nonce_revelation_threshold : int32; blocks_per_stake_snapshot : int32; cycles_per_voting_period : int32; hard_gas_limit_per_operation : Gas_limit_repr.Arith.integral; hard_gas_limit_per_block : Gas_limit_repr.Arith.integral; proof_of_work_threshold : int64; tokens_per_roll : Tez_repr.t; + vdf_difficulty : int64; seed_nonce_revelation_tip : Tez_repr.t; origination_size : int; baking_reward_fixed_portion : Tez_repr.t; @@ -43,6 +122,7 @@ type 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; @@ -53,34 +133,26 @@ type t = { delay_increment_per_round : Period_repr.t; minimal_participation_ratio : Ratio_repr.t; consensus_committee_size : int; + (* 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_endorsement : Ratio_repr.t; + testnet_dictator : Signature.Public_key_hash.t option; initial_seed : State_hash.t option; cache_script_size : int; + (* in bytes *) cache_stake_distribution_cycles : int; + (* in cycles *) cache_sampler_state_cycles : int; - tx_rollup_enable : bool; - tx_rollup_origination_size : int; - tx_rollup_hard_size_limit_per_inbox : int; - tx_rollup_hard_size_limit_per_message : int; - tx_rollup_commitment_bond : Tez_repr.t; - tx_rollup_finality_period : int; - tx_rollup_withdraw_period : int; - tx_rollup_max_inboxes_count : int; - tx_rollup_max_messages_per_inbox : int; - tx_rollup_max_commitments_count : int; - tx_rollup_cost_per_byte_ema_factor : int; - tx_rollup_max_ticket_payload_size : int; - tx_rollup_max_withdrawals_per_batch : int; - tx_rollup_rejection_max_proof_size : int; - tx_rollup_sunset_level : int32; - sc_rollup_enable : bool; - sc_rollup_origination_size : int; - sc_rollup_challenge_window_in_blocks : int; - sc_rollup_max_available_messages : int; + (* in cycles *) + tx_rollup : tx_rollup; + dal : dal; + sc_rollup : sc_rollup; } 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 66987eab849aa2fe1acbe985cafb8e7054a2da7b..8dd1785dae194fcd3ba21dd0cf934deed220c353 100644 --- a/src/proto_alpha/lib_protocol/init_storage.ml +++ b/src/proto_alpha/lib_protocol/init_storage.ml @@ -25,6 +25,9 @@ (* *) (*****************************************************************************) +(* + To add invoices, you can use a helper function like this one: + (** Invoice a contract at a given address with a given amount. Returns the updated context and a balance update receipt (singleton list). The address must be a valid base58 hash, otherwise this is no-op and returns an empty @@ -46,6 +49,7 @@ let invoice_contract ctxt ~address ~amount_mutez = >|= function | Ok res -> res | Error _ -> (ctxt, [])) +*) (* To patch code of legacy contracts you can add a helper function here and call @@ -54,26 +58,6 @@ let invoice_contract ctxt ~address ~amount_mutez = See !3730 for an example. *) -module Patch_dictator_for_ghostnet = struct - let ghostnet_id = - let id = Chain_id.of_b58check_exn "NetXnHfVqm9iesp" in - if Chain_id.equal id Constants_repr.mainnet_id then assert false else id - - let oxhead_testnet_baker = - Signature.Public_key_hash.of_b58check_exn - "tz1Xf8zdT3DbAX9cHw3c3CXh79rc4nK4gCe8" - - let patch_constant chain_id ctxt = - if Chain_id.equal chain_id ghostnet_id then - Raw_context.patch_constants ctxt (fun c -> - { - c with - testnet_dictator = Some oxhead_testnet_baker; - cycles_per_voting_period = 1l; - }) - else Lwt.return ctxt -end - let patch_script (address, hash, patched_code) ctxt = Contract_repr.of_b58check address >>?= fun contract -> Storage.Contract.Code.find ctxt contract >>=? fun (ctxt, code_opt) -> @@ -118,7 +102,7 @@ let patch_script (address, hash, patched_code) ctxt = address ; return ctxt -let prepare_first_block chain_id ctxt ~typecheck ~level ~timestamp = +let prepare_first_block _chain_id ctxt ~typecheck ~level ~timestamp = Raw_context.prepare_first_block ~level ~timestamp ctxt >>=? fun (previous_protocol, ctxt) -> let parametric = Raw_context.constants ctxt in @@ -178,20 +162,14 @@ let prepare_first_block chain_id ctxt ~typecheck ~level ~timestamp = ( ctxt, commitments_balance_updates @ bootstrap_balance_updates @ deposits_balance_updates ) - | Jakarta_013 + | Kathmandu_014 (* Please update [next_protocol] and [previous_protocol] in [tezt/lib_tezos/protocol.ml] when you update this value. *) -> (* TODO (#2704): possibly handle endorsements for migration block (in bakers); if that is done, do not set Storage.Tenderbake.First_level_of_protocol. *) Raw_level_repr.of_int32 level >>?= fun level -> Storage.Tenderbake.First_level_of_protocol.update ctxt level - >>=? fun ctxt -> - Patch_dictator_for_ghostnet.patch_constant chain_id ctxt >>= fun ctxt -> - invoice_contract - ctxt - ~address:"tz1X81bCXPtMiHu1d4UZF4GPhMPkvkp56ssb" - ~amount_mutez:3_000_000_000L - >>= fun (ctxt, balance_updates) -> return (ctxt, balance_updates)) + >>=? fun ctxt -> return (ctxt, [])) >>=? fun (ctxt, balance_updates) -> List.fold_right_es patch_script Legacy_script_patches.addresses_to_patch ctxt >>=? fun ctxt -> diff --git a/src/proto_alpha/lib_protocol/raw_context.ml b/src/proto_alpha/lib_protocol/raw_context.ml index a34b0145576cbea7c545515a79ace8e55dadbc1c..cacaabe67a059f77f539fcb8b0b1ac0f07ef803d 100644 --- a/src/proto_alpha/lib_protocol/raw_context.ml +++ b/src/proto_alpha/lib_protocol/raw_context.ml @@ -827,7 +827,7 @@ let prepare ~level ~predecessor_timestamp ~timestamp ctxt = }; } -type previous_protocol = Genesis of Parameters_repr.t | Jakarta_013 +type previous_protocol = Genesis of Parameters_repr.t | Kathmandu_014 let check_and_update_protocol_version ctxt = (Context.find ctxt version_key >>= function @@ -839,7 +839,8 @@ let check_and_update_protocol_version ctxt = failwith "Internal error: previously initialized context." else if Compare.String.(s = "genesis") then get_proto_param ctxt >|=? fun (param, ctxt) -> (Genesis param, ctxt) - else if Compare.String.(s = "jakarta_013") then return (Jakarta_013, ctxt) + else if Compare.String.(s = "kathmandu_014") then + return (Kathmandu_014, ctxt) else Lwt.return @@ storage_error (Incompatible_protocol_version s)) >>=? fun (previous_proto, ctxt) -> Context.add ctxt version_key (Bytes.of_string version_value) >|= fun ctxt -> @@ -890,8 +891,29 @@ let prepare_first_block ~level ~timestamp ctxt = Level_repr.create_cycle_eras [cycle_era] >>?= fun cycle_eras -> set_cycle_eras ctxt cycle_eras >>=? fun ctxt -> add_constants ctxt param.constants >|= ok - | Jakarta_013 -> + | Kathmandu_014 -> get_previous_protocol_constants ctxt >>= fun c -> + let tx_rollup = + Constants_parametric_repr. + { + enable = c.tx_rollup.enable; + origination_size = c.tx_rollup.origination_size; + hard_size_limit_per_inbox = c.tx_rollup.hard_size_limit_per_inbox; + hard_size_limit_per_message = + c.tx_rollup.hard_size_limit_per_message; + max_withdrawals_per_batch = c.tx_rollup.max_withdrawals_per_batch; + max_ticket_payload_size = c.tx_rollup.max_ticket_payload_size; + commitment_bond = c.tx_rollup.commitment_bond; + finality_period = c.tx_rollup.finality_period; + withdraw_period = c.tx_rollup.withdraw_period; + max_inboxes_count = c.tx_rollup.max_inboxes_count; + max_messages_per_inbox = c.tx_rollup.max_messages_per_inbox; + max_commitments_count = c.tx_rollup.max_commitments_count; + cost_per_byte_ema_factor = c.tx_rollup.cost_per_byte_ema_factor; + rejection_max_proof_size = c.tx_rollup.rejection_max_proof_size; + sunset_level = c.tx_rollup.sunset_level; + } + in let dal = Constants_parametric_repr. { @@ -902,24 +924,52 @@ let prepare_first_block ~level ~timestamp ctxt = availability_threshold = 50; } in + let sc_rollup = + Constants_parametric_repr. + { + enable = false; + origination_size = c.sc_rollup.origination_size; + challenge_window_in_blocks = 20_160; + (* The following value is chosen to limit the maximal + length of an inbox refutation proof. *) + (* TODO: https://gitlab.com/tezos/tezos/-/issues/2373 + check this is reasonable. *) + max_number_of_messages_per_commitment_period = 32_765; + (* TODO: https://gitlab.com/tezos/tezos/-/issues/2756 + The following constants need to be refined. *) + stake_amount = Tez_repr.of_mutez_exn 10_000_000_000L; + commitment_period_in_blocks = 30; + max_lookahead_in_blocks = 30_000l; + (* Number of active levels kept for executing outbox messages. + WARNING: Changing this value impacts the storage charge for + applying messages from the outbox. It also requires migration for + remapping existing active outbox levels to new indices. *) + max_active_outbox_levels = 20_160l; + (* Maximum number of outbox messages per level. + WARNING: changing this value impacts the storage cost charged + for applying messages from the outbox. *) + max_outbox_messages_per_level = 100; + (* The default number of required sections in a dissection *) + number_of_sections_in_dissection = 32; + (* TODO: https://gitlab.com/tezos/tezos/-/issues/2902 + This constant needs to be refined. *) + timeout_period_in_blocks = 20_160; + } + in let constants = Constants_parametric_repr. { preserved_cycles = c.preserved_cycles; blocks_per_cycle = c.blocks_per_cycle; blocks_per_commitment = c.blocks_per_commitment; - nonce_revelation_threshold = - (if Compare.Int32.(256l < c.blocks_per_cycle) then 256l - else (* not on mainnet *) Int32.div c.blocks_per_cycle 2l); + nonce_revelation_threshold = c.nonce_revelation_threshold; blocks_per_stake_snapshot = c.blocks_per_stake_snapshot; cycles_per_voting_period = c.cycles_per_voting_period; hard_gas_limit_per_operation = c.hard_gas_limit_per_operation; hard_gas_limit_per_block = c.hard_gas_limit_per_block; proof_of_work_threshold = c.proof_of_work_threshold; tokens_per_roll = c.tokens_per_roll; - vdf_difficulty = - (if Compare.Int32.(256l < c.blocks_per_cycle) then 8_000_000_000L - else (* not on mainnet *) 50_000L); + vdf_difficulty = c.vdf_difficulty; seed_nonce_revelation_tip = c.seed_nonce_revelation_tip; origination_size = c.origination_size; max_operations_time_to_live = c.max_operations_time_to_live; @@ -947,63 +997,14 @@ let prepare_first_block ~level ~timestamp ctxt = ratio_of_frozen_deposits_slashed_per_double_endorsement = c.ratio_of_frozen_deposits_slashed_per_double_endorsement; (* The `testnet_dictator` should absolutely be None on mainnet *) - testnet_dictator = None; + testnet_dictator = c.testnet_dictator; initial_seed = c.initial_seed; cache_script_size = c.cache_script_size; cache_stake_distribution_cycles = c.cache_stake_distribution_cycles; cache_sampler_state_cycles = c.cache_sampler_state_cycles; - tx_rollup = - { - enable = c.tx_rollup_enable; - origination_size = c.tx_rollup_origination_size; - hard_size_limit_per_inbox = - c.tx_rollup_hard_size_limit_per_inbox; - hard_size_limit_per_message = - c.tx_rollup_hard_size_limit_per_message; - max_withdrawals_per_batch = - c.tx_rollup_max_withdrawals_per_batch; - max_ticket_payload_size = c.tx_rollup_max_ticket_payload_size; - commitment_bond = c.tx_rollup_commitment_bond; - finality_period = c.tx_rollup_finality_period; - withdraw_period = c.tx_rollup_withdraw_period; - max_inboxes_count = c.tx_rollup_max_inboxes_count; - max_messages_per_inbox = c.tx_rollup_max_messages_per_inbox; - max_commitments_count = c.tx_rollup_max_commitments_count; - cost_per_byte_ema_factor = c.tx_rollup_cost_per_byte_ema_factor; - rejection_max_proof_size = c.tx_rollup_rejection_max_proof_size; - sunset_level = c.tx_rollup_sunset_level; - }; + tx_rollup; dal; - sc_rollup = - { - enable = false; - origination_size = c.sc_rollup_origination_size; - challenge_window_in_blocks = 20_160; - (* The following value is chosen to limit the maximal - length of an inbox refutation proof. *) - (* TODO: https://gitlab.com/tezos/tezos/-/issues/2373 - check this is reasonable. *) - max_number_of_messages_per_commitment_period = 32_765; - (* TODO: https://gitlab.com/tezos/tezos/-/issues/2756 - The following constants need to be refined. *) - stake_amount = Tez_repr.of_mutez_exn 10_000_000_000L; - commitment_period_in_blocks = 30; - max_lookahead_in_blocks = 30_000l; - (* Number of active levels kept for executing outbox messages. - WARNING: Changing this value impacts the storage charge for - applying messages from the outbox. It also requires migration for - remapping existing active outbox levels to new indices. *) - max_active_outbox_levels = 20_160l; - (* Maximum number of outbox messages per level. - WARNING: changing this value impacts the storage cost charged - for applying messages from the outbox. *) - max_outbox_messages_per_level = 100; - (* The default number of required sections in a dissection *) - number_of_sections_in_dissection = 32; - (* TODO: https://gitlab.com/tezos/tezos/-/issues/2902 - This constant needs to be refined. *) - timeout_period_in_blocks = 20_160; - }; + sc_rollup; } in add_constants ctxt constants >>= fun ctxt -> return ctxt) diff --git a/src/proto_alpha/lib_protocol/raw_context.mli b/src/proto_alpha/lib_protocol/raw_context.mli index eef60d8c3117c1c550ed074203bf4586e57f8273..0f612ebe7a7d8ef850aa22393c2d0217230d5337 100644 --- a/src/proto_alpha/lib_protocol/raw_context.mli +++ b/src/proto_alpha/lib_protocol/raw_context.mli @@ -83,7 +83,7 @@ val prepare : Context.t -> t tzresult Lwt.t -type previous_protocol = Genesis of Parameters_repr.t | Jakarta_013 +type previous_protocol = Genesis of Parameters_repr.t | Kathmandu_014 val prepare_first_block : level:int32 -> diff --git a/tests_python/tests_alpha/protocol.py b/tests_python/tests_alpha/protocol.py index 92fce27d49e983f6be65239f583ae75d75889163..d4e6e74c8306ea2ae271e6aa6aa34a4b81661289 100644 --- a/tests_python/tests_alpha/protocol.py +++ b/tests_python/tests_alpha/protocol.py @@ -14,9 +14,9 @@ TENDERBAKE_PARAMETERS['consensus_committee_size'] = 67 FOLDER = constants.ALPHA_FOLDER -PREV_HASH = constants.JAKARTA -PREV_DAEMON = constants.JAKARTA_DAEMON -PREV_PARAMETERS = constants.JAKARTA_PARAMETERS +PREV_HASH = constants.KATHMANDU +PREV_DAEMON = constants.KATHMANDU_DAEMON +PREV_PARAMETERS = constants.KATHMANDU_PARAMETERS def activate( diff --git a/tezt/lib_tezos/protocol.ml b/tezt/lib_tezos/protocol.ml index 2c6882af90ce058642cf858e4e9feb5d2c3af41c..3ee82d00f5fb80893ac79a3547251f7dac5b6a25 100644 --- a/tezt/lib_tezos/protocol.ml +++ b/tezt/lib_tezos/protocol.ml @@ -129,11 +129,11 @@ let write_parameter_file : let next_protocol = function | Jakarta -> Some Kathmandu - | Kathmandu -> None (* To update once the migration starts from Kathmandu. *) + | Kathmandu -> Some Alpha | Alpha -> None let previous_protocol = function - | Alpha -> Some Jakarta (* To update once the migration starts from K. *) + | Alpha -> Some Kathmandu | Kathmandu -> Some Jakarta | Jakarta -> None diff --git a/tezt/tests/ghostnet_dictator_migration.ml b/tezt/tests/ghostnet_dictator_migration.ml index 843cccd4baeae3b16faa3b115b732cc55153add5..d04206de3944f2b0bacc64cec7ecbe4fbd972799 100644 --- a/tezt/tests/ghostnet_dictator_migration.ml +++ b/tezt/tests/ghostnet_dictator_migration.ml @@ -74,13 +74,16 @@ let init chain_id ~from_protocol ~to_protocol = in let* node = Node.init ?patch_config [Synchronisation_threshold 0] in let* client = Client.init ~endpoint:(Node node) () in + let parameters = + [(["blocks_per_cycle"], Some "4"); (["cycles_per_voting_period"], Some "2")] + in + let parameters = + if Protocol.number from_protocol >= 014 then + parameters @ [(["nonce_revelation_threshold"], Some "2")] + else parameters + in let* parameter_file = - Protocol.write_parameter_file - ~base:(Right (from_protocol, None)) - [ - (["blocks_per_cycle"], Some "4"); - (["cycles_per_voting_period"], Some "2"); - ] + Protocol.write_parameter_file ~base:(Right (from_protocol, None)) parameters in let* () = Client.activate_protocol @@ -112,7 +115,7 @@ let register_migration_test chain_id = in let expected_dictator, expected_remaining = match chain_id with - | Chain_id_ghostnet when to_protocol = Alpha -> + | Chain_id_ghostnet when to_protocol = Kathmandu -> (Some "tz1Xf8zdT3DbAX9cHw3c3CXh79rc4nK4gCe8", 1) | _ -> (None, 5) in diff --git a/tezt/tests/main.ml b/tezt/tests/main.ml index 3e1182582ce0ba6209595d4365d3111a221e4f70..ef201e320469967950293f1b7e884b3d291833ce 100644 --- a/tezt/tests/main.ml +++ b/tezt/tests/main.ml @@ -136,12 +136,12 @@ let register_K_plus_tests () = protocol. *) let protocols = Protocol.[Kathmandu; Alpha] in Events.register ~protocols:[Alpha] ; - Ghostnet_dictator_migration.register ~protocols:[Alpha] ; + Ghostnet_dictator_migration.register ~protocols ; Increase_paid_storage.register ~protocols ; Operation_validation.register ~protocols ; Sc_rollup.register ~protocols:[Alpha] ; Test_contract_bls12_381.register ~protocols:[Alpha] ; - Testnet_dictator.register ~protocols:[Alpha] ; + Testnet_dictator.register ~protocols ; Vdf_test.register ~protocols let () = diff --git a/tezt/tests/testnet_dictator.ml b/tezt/tests/testnet_dictator.ml index b81a1dffd0b581f74f34b8471c34c3f399355b20..95ca146e64c661a91e60d0b3fbe8ae5c55ef15cf 100644 --- a/tezt/tests/testnet_dictator.ml +++ b/tezt/tests/testnet_dictator.ml @@ -174,11 +174,11 @@ let register_test chain_id period = "Checking that %s migration occurred..." (if chain_id = Chain_id_mainnet then "no" else "a forced") ; let expected_protocol = - if chain_id = Chain_id_mainnet then Protocol.hash Alpha + if chain_id = Chain_id_mainnet then Protocol.hash protocol else Protocol.demo_counter_hash in let* () = - Voting.check_protocols client (Protocol.hash Alpha, expected_protocol) + Voting.check_protocols client (Protocol.hash protocol, expected_protocol) in return ()) in @@ -188,8 +188,8 @@ let register_test chain_id period = Log.info "- submitting proposals %s for %s" proto_hash key.Account.alias ; Client.submit_proposals ~key:key.alias ~proto_hash client in - let* () = submit_proposal ~key:Constant.bootstrap2 (Protocol.hash Alpha) in - let* () = submit_proposal ~key:Constant.bootstrap3 (Protocol.hash Alpha) in + let* () = submit_proposal ~key:Constant.bootstrap2 (Protocol.hash protocol) in + let* () = submit_proposal ~key:Constant.bootstrap3 (Protocol.hash protocol) in let* () = bake_until_next_period node client in let* () = Voting.check_current_period @@ -208,7 +208,7 @@ let register_test chain_id period = Log.info "- submitting ballot for %s" key.Account.alias ; Client.submit_ballot ~key:key.alias - ~proto_hash:(Protocol.hash Alpha) + ~proto_hash:(Protocol.hash protocol) ballot client in