diff --git a/src/lib_store/test/alpha_utils.ml b/src/lib_store/test/alpha_utils.ml index 4f0f31ad4367ffb9cfdcecdfa72af1c7fe195309..ed69fbe23945de49fd44ecee95e9b75fd793dcb4 100644 --- a/src/lib_store/test/alpha_utils.ml +++ b/src/lib_store/test/alpha_utils.ml @@ -357,7 +357,7 @@ let protocol_param_key = ["protocol_parameters"] let check_constants_consistency constants = let open Lwt_result_syntax in - let open Constants_repr in + let open Constants_parametric_repr in let {blocks_per_cycle; blocks_per_commitment; blocks_per_stake_snapshot; _} = constants in diff --git a/src/lib_store/test/test_snapshots.ml b/src/lib_store/test/test_snapshots.ml index 7a0d9d3574fbdff73433fd20f9ebf024848aaabd..1f9661d1e7e43887ee5cae4bcf5a0a252567bff8 100644 --- a/src/lib_store/test/test_snapshots.ml +++ b/src/lib_store/test/test_snapshots.ml @@ -379,7 +379,8 @@ let test store_path ~test_descr ?exported_block_level let make_tests speed genesis_parameters = let open Tezos_protocol_alpha.Protocol.Alpha_context in let { - Parameters.constants = {Constants.blocks_per_cycle; preserved_cycles; _}; + Parameters.constants = + {Constants.Parametric.blocks_per_cycle; preserved_cycles; _}; _; } = genesis_parameters diff --git a/src/proto_alpha/lib_client/mockup.ml b/src/proto_alpha/lib_client/mockup.ml index d46f4b6817f56b7a10ea7120aa69a6bb59536a3e..d50bccad0a5ae1da8e83e2e21f773fad64cd5e34 100644 --- a/src/proto_alpha/lib_client/mockup.ml +++ b/src/proto_alpha/lib_client/mockup.ml @@ -61,14 +61,13 @@ module Protocol_constants_overrides = struct max_operations_time_to_live : int option; minimal_block_delay : Period.t option; delay_increment_per_round : Period.t option; - minimal_participation_ratio : Constants.ratio option; + minimal_participation_ratio : Ratio.t option; consensus_committee_size : int option; consensus_threshold : int option; max_slashing_period : int option; frozen_deposits_percentage : int option; double_baking_punishment : Tez.t option; - ratio_of_frozen_deposits_slashed_per_double_endorsement : - Constants.ratio option; + ratio_of_frozen_deposits_slashed_per_double_endorsement : Ratio.t option; cache_script_size : int option; cache_stake_distribution_cycles : int option; cache_sampler_state_cycles : int option; @@ -326,15 +325,13 @@ module Protocol_constants_overrides = struct (opt "consensus_threshold" int31)) (merge_objs (obj8 - (opt - "minimal_participation_ratio" - Constants.ratio_encoding) + (opt "minimal_participation_ratio" Ratio.encoding) (opt "max_slashing_period" int31) (opt "frozen_deposits_percentage" int31) (opt "double_baking_punishment" Tez.encoding) (opt "ratio_of_frozen_deposits_slashed_per_double_endorsement" - Constants.ratio_encoding) + Ratio.encoding) (opt "chain_id" Chain_id.encoding) (opt "initial_timestamp" Time.Protocol.encoding) (opt "initial_seed" (option State_hash.encoding))) @@ -565,7 +562,7 @@ module Protocol_constants_overrides = struct | Some value -> Format.fprintf ppf "@[%s: %a@]" name pp value let apply_overrides (cctxt : Tezos_client_base.Client_context.printer) (o : t) - (c : Constants.parametric) : Constants.parametric tzresult Lwt.t = + (c : Constants.Parametric.t) : Constants.Parametric.t tzresult Lwt.t = let open Format in let pp_print_int32 ppf i = fprintf ppf "%li" i in let pp_print_int64 ppf i = fprintf ppf "%Li" i in @@ -719,7 +716,7 @@ module Protocol_constants_overrides = struct { name = "minimal_participation_ratio"; override_value = o.minimal_participation_ratio; - pp = Constants.pp_ratio; + pp = Ratio.pp; }; O { @@ -756,7 +753,7 @@ module Protocol_constants_overrides = struct name = "ratio_of_frozen_deposits_slashed_per_double_endorsement"; override_value = o.ratio_of_frozen_deposits_slashed_per_double_endorsement; - pp = Constants.pp_ratio; + pp = Ratio.pp; }; O { @@ -1050,7 +1047,7 @@ module Protocol_constants_overrides = struct ~default:c.sc_rollup_max_lookahead_in_blocks o.sc_rollup_max_lookahead_in_blocks; } - : Constants.parametric) + : Constants.Parametric.t) end module Parsed_account = struct @@ -1163,7 +1160,7 @@ module Protocol_parameters = struct initial_timestamp : Time.Protocol.t; bootstrap_accounts : Parameters.bootstrap_account list; bootstrap_contracts : Parameters.bootstrap_contract list; - constants : Constants.parametric; + constants : Constants.Parametric.t; } let encoding : t Data_encoding.t = @@ -1183,7 +1180,7 @@ module Protocol_parameters = struct (req "initial_timestamp" Time.Protocol.encoding) (req "bootstrap_accounts" (list Bootstrap_account.encoding)) (req "bootstrap_contracts" (list Bootstrap_contract.encoding)) - (req "constants" Constants.parametric_encoding)) + (req "constants" Constants.Parametric.encoding)) let default_value : t = let parameters = diff --git a/src/proto_alpha/lib_client/protocol_client_context.ml b/src/proto_alpha/lib_client/protocol_client_context.ml index 886d256b9c0b4369ea34a4d68bff7f789224b580..0f340c607999387e414df0030d4019931c560337 100644 --- a/src/proto_alpha/lib_client/protocol_client_context.ml +++ b/src/proto_alpha/lib_client/protocol_client_context.ml @@ -223,7 +223,7 @@ let () = @@ def "constants" ["parametric"] - Protocol.Alpha_context.Constants.parametric_encoding ; + Protocol.Alpha_context.Constants.Parametric.encoding ; register @@ def "nonce" [] Protocol.Alpha_context.Nonce.encoding ; register @@ def "block_header" [] Protocol.Alpha_context.Block_header.encoding ; register diff --git a/src/proto_alpha/lib_delegate/block_forge.ml b/src/proto_alpha/lib_delegate/block_forge.ml index 4bc63292ac7a49232892668c4cd8d5fcb29aa8ca..fe58614ba2f689344c6ae7e89d5f7f0754c5d588 100644 --- a/src/proto_alpha/lib_delegate/block_forge.ml +++ b/src/proto_alpha/lib_delegate/block_forge.ml @@ -120,7 +120,9 @@ let forge (cctxt : #Protocol_client_context.full) ~chain_id ~pred_info fees_config ~seed_nonce_hash ~payload_round simulation_mode simulation_kind constants = let predecessor_block = (pred_info : Baking_state.block_info) in - let hard_gas_limit_per_block = constants.Constants.hard_gas_limit_per_block in + let hard_gas_limit_per_block = + constants.Constants.Parametric.hard_gas_limit_per_block + in let chain = `Hash chain_id in let check_protocol_changed ~(validation_result : Environment_context.validation_result) = diff --git a/src/proto_alpha/lib_delegate/block_forge.mli b/src/proto_alpha/lib_delegate/block_forge.mli index 6074c544908a0af8c76eb72a99f49a98485dd7ca..b111e27b417c4a67c69c1b2160ee019ae9620e34 100644 --- a/src/proto_alpha/lib_delegate/block_forge.mli +++ b/src/proto_alpha/lib_delegate/block_forge.mli @@ -60,5 +60,5 @@ val forge : payload_round:Round.t -> Baking_state.validation_mode -> simulation_kind -> - Constants.parametric -> + Constants.Parametric.t -> unsigned_block tzresult Lwt.t diff --git a/src/proto_alpha/lib_parameters/default_parameters.ml b/src/proto_alpha/lib_parameters/default_parameters.ml index 6a3d8ff6a500104da29f4bc2c508ed71e3051bfa..7a76ab74e1762ef11e9b3414b76ae07e53825119 100644 --- a/src/proto_alpha/lib_parameters/default_parameters.ml +++ b/src/proto_alpha/lib_parameters/default_parameters.ml @@ -44,7 +44,7 @@ let constants_mainnet = ~blocks_per_minute:{numerator = 60; denominator = block_time} in { - Constants.preserved_cycles = 5; + Constants.Parametric.preserved_cycles = 5; blocks_per_cycle = 8192l; blocks_per_commitment = 64l; blocks_per_stake_snapshot = 512l; @@ -180,7 +180,7 @@ let constants_sandbox = in { constants_mainnet with - Constants.preserved_cycles = 2; + Constants.Parametric.preserved_cycles = 2; blocks_per_cycle = 8l; blocks_per_commitment = 4l; blocks_per_stake_snapshot = 4l; @@ -213,7 +213,7 @@ let constants_test = in { constants_mainnet with - Constants.preserved_cycles = 3; + Constants.Parametric.preserved_cycles = 3; blocks_per_cycle = 12l; blocks_per_commitment = 4l; blocks_per_stake_snapshot = 4l; diff --git a/src/proto_alpha/lib_parameters/default_parameters.mli b/src/proto_alpha/lib_parameters/default_parameters.mli index 3551ac5d3117dad8145a2ff25c698a54829aa27f..def1fe37347b3f30ebc18adc3882cf9ec2a23652 100644 --- a/src/proto_alpha/lib_parameters/default_parameters.mli +++ b/src/proto_alpha/lib_parameters/default_parameters.mli @@ -26,11 +26,11 @@ open Protocol.Alpha_context -val constants_mainnet : Constants.parametric +val constants_mainnet : Constants.Parametric.t -val constants_sandbox : Constants.parametric +val constants_sandbox : Constants.Parametric.t -val constants_test : Constants.parametric +val constants_test : Constants.Parametric.t val test_commitments : Commitment.t list lazy_t @@ -42,7 +42,7 @@ val parameters_of_constants : ?bootstrap_accounts:Parameters.bootstrap_account list -> ?bootstrap_contracts:Parameters.bootstrap_contract list -> ?commitments:Commitment.t list -> - Constants.parametric -> + Constants.Parametric.t -> Parameters.t val json_of_parameters : Parameters.t -> Data_encoding.json diff --git a/src/proto_alpha/lib_protocol/TEZOS_PROTOCOL b/src/proto_alpha/lib_protocol/TEZOS_PROTOCOL index de2fcb055bad03e1f0c51cdd2a2d9aa72d18877b..79fdc8de4b9d7e84a2b1266bc8869be6f76a20a3 100644 --- a/src/proto_alpha/lib_protocol/TEZOS_PROTOCOL +++ b/src/proto_alpha/lib_protocol/TEZOS_PROTOCOL @@ -21,11 +21,14 @@ "Tez_repr", "Period_repr", "Time_repr", + "Ratio_repr", "Round_repr", "Block_payload_repr", "Fixed_point_repr", "Saturation_repr", "Gas_limit_repr", + "Constants_parametric_repr", + "Constants_parametric_previous_repr", "Constants_repr", "Raw_level_repr", "Fitness_repr", diff --git a/src/proto_alpha/lib_protocol/alpha_context.ml b/src/proto_alpha/lib_protocol/alpha_context.ml index 94e9f94924029a1b9c1caeeafc718003b843e1fb..520c0f00d71c68cab6c8486e9aed071831a05974 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.ml +++ b/src/proto_alpha/lib_protocol/alpha_context.ml @@ -90,6 +90,7 @@ module First_level_of_protocol = struct let get = Storage.Tenderbake.First_level_of_protocol.get end +module Ratio = Ratio_repr module Raw_level = Raw_level_repr module Cycle = Cycle_repr @@ -125,6 +126,7 @@ type signature = Signature.t module Constants = struct include Constants_repr include Constants_storage + module Parametric = Constants_parametric_repr let round_durations ctxt = Raw_context.round_durations ctxt diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index ba08e9598d5d8bf78c50ee9cf7fbdfba5dc07fba..20c78d441b24cb105ffc53f8026fcd88a9fb7a59 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -200,6 +200,14 @@ module Timestamp : sig val predecessor : context -> time end +module Ratio : sig + type t = {numerator : int; denominator : int} + + val encoding : t Data_encoding.t + + val pp : Format.formatter -> t -> unit +end + module Raw_level : sig include BASIC_DATA @@ -711,74 +719,72 @@ module Constants : sig val michelson_maximum_type_size : int - type ratio = {numerator : int; denominator : int} - - val ratio_encoding : ratio Data_encoding.t - - val pp_ratio : Format.formatter -> ratio -> unit - (** Constants parameterized by context *) - type parametric = { - preserved_cycles : int; - blocks_per_cycle : int32; - blocks_per_commitment : int32; - blocks_per_stake_snapshot : int32; - cycles_per_voting_period : int32; - hard_gas_limit_per_operation : Gas.Arith.integral; - hard_gas_limit_per_block : Gas.Arith.integral; - proof_of_work_threshold : int64; - tokens_per_roll : Tez.t; - seed_nonce_revelation_tip : Tez.t; - origination_size : int; - baking_reward_fixed_portion : Tez.t; - baking_reward_bonus_per_slot : Tez.t; - endorsing_reward_per_slot : Tez.t; - cost_per_byte : Tez.t; - hard_storage_limit_per_operation : Z.t; - quorum_min : int32; - quorum_max : int32; - min_proposal_quorum : int32; - liquidity_baking_subsidy : Tez.t; - liquidity_baking_sunset_level : int32; - liquidity_baking_toggle_ema_threshold : int32; - max_operations_time_to_live : int; - minimal_block_delay : Period.t; - delay_increment_per_round : Period.t; - minimal_participation_ratio : ratio; - consensus_committee_size : int; - consensus_threshold : int; - max_slashing_period : int; - frozen_deposits_percentage : int; - double_baking_punishment : Tez.t; - ratio_of_frozen_deposits_slashed_per_double_endorsement : ratio; - initial_seed : State_hash.t option; - 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.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; - sc_rollup_stake_amount_in_mutez : int; - sc_rollup_commitment_frequency_in_blocks : int; - sc_rollup_commitment_storage_size_in_bytes : int; - sc_rollup_max_lookahead_in_blocks : int32; - } + module Parametric : sig + type t = { + preserved_cycles : int; + blocks_per_cycle : int32; + blocks_per_commitment : int32; + blocks_per_stake_snapshot : int32; + cycles_per_voting_period : int32; + hard_gas_limit_per_operation : Gas.Arith.integral; + hard_gas_limit_per_block : Gas.Arith.integral; + proof_of_work_threshold : int64; + tokens_per_roll : Tez.t; + seed_nonce_revelation_tip : Tez.t; + origination_size : int; + baking_reward_fixed_portion : Tez.t; + baking_reward_bonus_per_slot : Tez.t; + endorsing_reward_per_slot : Tez.t; + cost_per_byte : Tez.t; + hard_storage_limit_per_operation : Z.t; + quorum_min : int32; + quorum_max : int32; + min_proposal_quorum : int32; + liquidity_baking_subsidy : Tez.t; + liquidity_baking_sunset_level : int32; + liquidity_baking_toggle_ema_threshold : int32; + max_operations_time_to_live : int; + minimal_block_delay : Period.t; + delay_increment_per_round : Period.t; + minimal_participation_ratio : Ratio.t; + consensus_committee_size : int; + consensus_threshold : int; + max_slashing_period : int; + frozen_deposits_percentage : int; + double_baking_punishment : Tez.t; + ratio_of_frozen_deposits_slashed_per_double_endorsement : Ratio.t; + initial_seed : State_hash.t option; + 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.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; + sc_rollup_stake_amount_in_mutez : int; + sc_rollup_commitment_frequency_in_blocks : int; + sc_rollup_commitment_storage_size_in_bytes : int; + sc_rollup_max_lookahead_in_blocks : int32; + } + + val encoding : t Data_encoding.t + end module Generated : sig type t = { @@ -788,12 +794,11 @@ module Constants : sig endorsing_reward_per_slot : Tez.t; } - val generate : consensus_committee_size:int -> blocks_per_minute:ratio -> t + val generate : + consensus_committee_size:int -> blocks_per_minute:Ratio.t -> t end - val parametric_encoding : parametric Data_encoding.t - - val parametric : context -> parametric + val parametric : context -> Parametric.t val preserved_cycles : context -> int @@ -849,7 +854,7 @@ module Constants : sig val consensus_threshold : context -> int - val minimal_participation_ratio : context -> ratio + val minimal_participation_ratio : context -> Ratio.t val max_slashing_period : context -> int @@ -857,7 +862,8 @@ module Constants : sig val double_baking_punishment : context -> Tez.t - val ratio_of_frozen_deposits_slashed_per_double_endorsement : context -> ratio + val ratio_of_frozen_deposits_slashed_per_double_endorsement : + context -> Ratio.t val tx_rollup_enable : context -> bool @@ -892,7 +898,7 @@ module Constants : sig val sc_rollup_max_available_messages : context -> int (** All constants: fixed and parametric *) - type t = private {fixed : fixed; parametric : parametric} + type t = private {fixed : fixed; parametric : Parametric.t} val all : context -> t @@ -3356,7 +3362,7 @@ module Parameters : sig bootstrap_accounts : bootstrap_account list; bootstrap_contracts : bootstrap_contract list; commitments : Commitment.t list; - constants : Constants.parametric; + constants : Constants.Parametric.t; security_deposit_ramp_up_cycles : int option; no_reward_cycles : int option; } diff --git a/src/proto_alpha/lib_protocol/apply.ml b/src/proto_alpha/lib_protocol/apply.ml index ba6b66f451d782bc8912f3a5038fc444b12427b7..2de1d7edc84d4ba39bbd8022762fc61198a96b6a 100644 --- a/src/proto_alpha/lib_protocol/apply.ml +++ b/src/proto_alpha/lib_protocol/apply.ml @@ -1903,7 +1903,7 @@ let precheck_manager_contents (type kind) ctxt (op : kind Kind.manager contents) >|? fun (_ty, ctxt) -> ctxt ) | Tx_rollup_dispatch_tickets {tickets_info; message_result_path; _} -> assert_tx_rollup_feature_enabled ctxt >>=? fun () -> - let Constants. + let Constants.Parametric. { tx_rollup_max_messages_per_inbox; tx_rollup_max_withdrawals_per_batch; @@ -1942,7 +1942,7 @@ let precheck_manager_contents (type kind) ctxt (op : kind Kind.manager contents) | Tx_rollup_rejection {message_path; message_result_path; previous_message_result_path; _} -> assert_tx_rollup_feature_enabled ctxt >>=? fun () -> - let Constants.{tx_rollup_max_messages_per_inbox; _} = + let Constants.Parametric.{tx_rollup_max_messages_per_inbox; _} = Constants.parametric ctxt in Tx_rollup_errors.check_path_depth diff --git a/src/proto_alpha/lib_protocol/constants_parametric_previous_repr.ml b/src/proto_alpha/lib_protocol/constants_parametric_previous_repr.ml new file mode 100644 index 0000000000000000000000000000000000000000..177d569927214dedc8ef38e4f3e3fc532f8dea57 --- /dev/null +++ b/src/proto_alpha/lib_protocol/constants_parametric_previous_repr.ml @@ -0,0 +1,236 @@ +(*****************************************************************************) +(* *) +(* Open Source License *) +(* Copyright (c) 2018 Dynamic Ledger Solutions, Inc. *) +(* Copyright (c) 2020-2021 Nomadic Labs *) +(* Copyright (c) 2021-2022 Trili Tech, *) +(* *) +(* 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. *) +(* *) +(*****************************************************************************) + +type delegate_selection = + | Random + | Round_robin_over of Signature.Public_key.t list list + +let delegate_selection_encoding = + let open Data_encoding in + union + [ + case + (Tag 0) + ~title:"Random_delegate_selection" + (constant "random") + (function Random -> Some () | _ -> None) + (fun () -> Random); + case + (Tag 1) + ~title:"Round_robin_over_delegates" + (list (list Signature.Public_key.encoding)) + (function Round_robin_over l -> Some l | _ -> None) + (fun l -> Round_robin_over l); + ] + +type t = { + preserved_cycles : int; + blocks_per_cycle : int32; + blocks_per_commitment : int32; + blocks_per_stake_snapshot : int32; + blocks_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; + 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; + 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_sunset_level : int32; + liquidity_baking_escape_ema_threshold : int32; + max_operations_time_to_live : int; + minimal_block_delay : Period_repr.t; + delay_increment_per_round : Period_repr.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_endorsement : Ratio_repr.t; + delegate_selection : delegate_selection; +} + +let encoding = + let open Data_encoding in + conv + (fun c -> + ( ( c.preserved_cycles, + c.blocks_per_cycle, + c.blocks_per_commitment, + c.blocks_per_stake_snapshot, + c.blocks_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.origination_size, + 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_sunset_level, + c.liquidity_baking_escape_ema_threshold, + c.max_operations_time_to_live, + c.minimal_block_delay, + c.delay_increment_per_round, + 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_endorsement, + c.delegate_selection ) ) ) )) + (fun ( ( preserved_cycles, + blocks_per_cycle, + blocks_per_commitment, + blocks_per_stake_snapshot, + blocks_per_voting_period, + hard_gas_limit_per_operation, + hard_gas_limit_per_block, + proof_of_work_threshold, + tokens_per_roll ), + ( ( seed_nonce_revelation_tip, + origination_size, + 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_sunset_level, + liquidity_baking_escape_ema_threshold, + max_operations_time_to_live, + minimal_block_delay, + delay_increment_per_round, + consensus_committee_size, + consensus_threshold ), + ( minimal_participation_ratio, + max_slashing_period, + frozen_deposits_percentage, + double_baking_punishment, + ratio_of_frozen_deposits_slashed_per_double_endorsement, + delegate_selection ) ) ) ) -> + { + preserved_cycles; + blocks_per_cycle; + blocks_per_commitment; + blocks_per_stake_snapshot; + blocks_per_voting_period; + hard_gas_limit_per_operation; + hard_gas_limit_per_block; + proof_of_work_threshold; + tokens_per_roll; + seed_nonce_revelation_tip; + origination_size; + 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_sunset_level; + liquidity_baking_escape_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_endorsement; + delegate_selection; + }) + (merge_objs + (obj9 + (req "preserved_cycles" uint8) + (req "blocks_per_cycle" int32) + (req "blocks_per_commitment" int32) + (req "blocks_per_stake_snapshot" int32) + (req "blocks_per_voting_period" int32) + (req + "hard_gas_limit_per_operation" + Gas_limit_repr.Arith.z_integral_encoding) + (req + "hard_gas_limit_per_block" + Gas_limit_repr.Arith.z_integral_encoding) + (req "proof_of_work_threshold" int64) + (req "tokens_per_roll" Tez_repr.encoding)) + (merge_objs + (obj8 + (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 "cost_per_byte" Tez_repr.encoding) + (req "hard_storage_limit_per_operation" z) + (req "quorum_min" int32)) + (merge_objs + (obj10 + (req "quorum_max" int32) + (req "min_proposal_quorum" int32) + (req "liquidity_baking_subsidy" Tez_repr.encoding) + (req "liquidity_baking_sunset_level" int32) + (req "liquidity_baking_escape_ema_threshold" int32) + (req "max_operations_time_to_live" int16) + (req "minimal_block_delay" Period_repr.encoding) + (req "delay_increment_per_round" Period_repr.encoding) + (req "consensus_committee_size" int31) + (req "consensus_threshold" int31)) + (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 + "ratio_of_frozen_deposits_slashed_per_double_endorsement" + Ratio_repr.encoding) + (dft "delegate_selection" delegate_selection_encoding Random))))) diff --git a/src/proto_alpha/lib_protocol/constants_parametric_previous_repr.mli b/src/proto_alpha/lib_protocol/constants_parametric_previous_repr.mli new file mode 100644 index 0000000000000000000000000000000000000000..bdd14528b364c21cf08e99a5026f865349a4c684 --- /dev/null +++ b/src/proto_alpha/lib_protocol/constants_parametric_previous_repr.mli @@ -0,0 +1,68 @@ +(*****************************************************************************) +(* *) +(* Open Source License *) +(* Copyright (c) 2018 Dynamic Ledger Solutions, Inc. *) +(* Copyright (c) 2020-2021 Nomadic Labs *) +(* Copyright (c) 2021-2022 Trili Tech, *) +(* *) +(* 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. *) +(* *) +(*****************************************************************************) + +type delegate_selection = + | Random + | Round_robin_over of Signature.Public_key.t list list + +type t = { + preserved_cycles : int; + blocks_per_cycle : int32; + blocks_per_commitment : int32; + blocks_per_stake_snapshot : int32; + blocks_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; + 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; + 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_sunset_level : int32; + liquidity_baking_escape_ema_threshold : int32; + max_operations_time_to_live : int; + minimal_block_delay : Period_repr.t; + delay_increment_per_round : Period_repr.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_endorsement : Ratio_repr.t; + delegate_selection : delegate_selection; +} + +val encoding : t Data_encoding.encoding diff --git a/src/proto_alpha/lib_protocol/constants_parametric_repr.ml b/src/proto_alpha/lib_protocol/constants_parametric_repr.ml new file mode 100644 index 0000000000000000000000000000000000000000..b06fad40921523a680ec6f62b399e93b28b1cb6f --- /dev/null +++ b/src/proto_alpha/lib_protocol/constants_parametric_repr.ml @@ -0,0 +1,364 @@ +(*****************************************************************************) +(* *) +(* Open Source License *) +(* Copyright (c) 2018 Dynamic Ledger Solutions, Inc. *) +(* Copyright (c) 2020-2021 Nomadic Labs *) +(* Copyright (c) 2021-2022 Trili Tech, *) +(* *) +(* 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. *) +(* *) +(*****************************************************************************) + +(* 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 t = { + preserved_cycles : int; + blocks_per_cycle : int32; + blocks_per_commitment : 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; + 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; + 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_sunset_level : int32; + liquidity_baking_toggle_ema_threshold : int32; + max_operations_time_to_live : int; + minimal_block_delay : Period_repr.t; + delay_increment_per_round : Period_repr.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_endorsement : Ratio_repr.t; + 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; + sc_rollup_stake_amount_in_mutez : int; + sc_rollup_commitment_frequency_in_blocks : int; + sc_rollup_commitment_storage_size_in_bytes : int; + sc_rollup_max_lookahead_in_blocks : int32; +} + +let encoding = + let open Data_encoding in + conv + (fun c -> + ( ( c.preserved_cycles, + c.blocks_per_cycle, + c.blocks_per_commitment, + 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.origination_size, + 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_sunset_level, + c.liquidity_baking_toggle_ema_threshold, + c.max_operations_time_to_live, + c.minimal_block_delay, + c.delay_increment_per_round, + 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_endorsement, + 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.sc_rollup_stake_amount_in_mutez, + c.sc_rollup_commitment_frequency_in_blocks, + c.sc_rollup_commitment_storage_size_in_bytes, + c.sc_rollup_max_lookahead_in_blocks ) ) ) ) ) ) )) + (fun ( ( preserved_cycles, + blocks_per_cycle, + blocks_per_commitment, + 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, + origination_size, + 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_sunset_level, + liquidity_baking_toggle_ema_threshold, + max_operations_time_to_live, + minimal_block_delay, + delay_increment_per_round, + consensus_committee_size, + consensus_threshold ), + ( ( minimal_participation_ratio, + max_slashing_period, + frozen_deposits_percentage, + double_baking_punishment, + ratio_of_frozen_deposits_slashed_per_double_endorsement, + 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, + sc_rollup_stake_amount_in_mutez, + sc_rollup_commitment_frequency_in_blocks, + sc_rollup_commitment_storage_size_in_bytes, + sc_rollup_max_lookahead_in_blocks ) ) ) ) ) ) ) -> + { + preserved_cycles; + blocks_per_cycle; + blocks_per_commitment; + 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; + origination_size; + 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_sunset_level; + 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_endorsement; + 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; + sc_rollup_stake_amount_in_mutez; + sc_rollup_commitment_frequency_in_blocks; + sc_rollup_commitment_storage_size_in_bytes; + sc_rollup_max_lookahead_in_blocks; + }) + (merge_objs + (obj9 + (req "preserved_cycles" uint8) + (req "blocks_per_cycle" int32) + (req "blocks_per_commitment" int32) + (req "blocks_per_stake_snapshot" int32) + (req "cycles_per_voting_period" int32) + (req + "hard_gas_limit_per_operation" + Gas_limit_repr.Arith.z_integral_encoding) + (req + "hard_gas_limit_per_block" + Gas_limit_repr.Arith.z_integral_encoding) + (req "proof_of_work_threshold" int64) + (req "tokens_per_roll" Tez_repr.encoding)) + (merge_objs + (obj8 + (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 "cost_per_byte" Tez_repr.encoding) + (req "hard_storage_limit_per_operation" z) + (req "quorum_min" int32)) + (merge_objs + (obj10 + (req "quorum_max" int32) + (req "min_proposal_quorum" int32) + (req "liquidity_baking_subsidy" Tez_repr.encoding) + (req "liquidity_baking_sunset_level" int32) + (req "liquidity_baking_toggle_ema_threshold" int32) + (req "max_operations_time_to_live" int16) + (req "minimal_block_delay" Period_repr.encoding) + (req "delay_increment_per_round" Period_repr.encoding) + (req "consensus_committee_size" int31) + (req "consensus_threshold" int31)) + (merge_objs + (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 + "ratio_of_frozen_deposits_slashed_per_double_endorsement" + Ratio_repr.encoding) + (opt "initial_seed" State_hash.encoding)) + (merge_objs + (obj3 + (req "cache_script_size" int31) + (req "cache_stake_distribution_cycles" int8) + (req "cache_sampler_state_cycles" int8)) + (merge_objs + (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))) + (obj8 + (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_in_mutez" int31) + (req "sc_rollup_commitment_frequency_in_blocks" int31) + (req + "sc_rollup_commitment_storage_size_in_bytes" + int31) + (req "sc_rollup_max_lookahead_in_blocks" int32)))))))) diff --git a/src/proto_alpha/lib_protocol/constants_parametric_repr.mli b/src/proto_alpha/lib_protocol/constants_parametric_repr.mli new file mode 100644 index 0000000000000000000000000000000000000000..11a3374952252f38164b1be0cb6e837bd8b3fb4a --- /dev/null +++ b/src/proto_alpha/lib_protocol/constants_parametric_repr.mli @@ -0,0 +1,134 @@ +(*****************************************************************************) +(* *) +(* Open Source License *) +(* Copyright (c) 2018 Dynamic Ledger Solutions, Inc. *) +(* Copyright (c) 2020-2021 Nomadic Labs *) +(* Copyright (c) 2021-2022 Trili Tech, *) +(* *) +(* 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. *) +(* *) +(*****************************************************************************) + +type t = { + preserved_cycles : int; + blocks_per_cycle : int32; + blocks_per_commitment : 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; + 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; + 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_sunset_level : int32; + liquidity_baking_toggle_ema_threshold : int32; + max_operations_time_to_live : int; + minimal_block_delay : Period_repr.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; + initial_seed : State_hash.t option; + cache_script_size : int; + (* in bytes *) + cache_stake_distribution_cycles : int; + (* in cycles *) + cache_sampler_state_cycles : int; + (* in cycles *) + tx_rollup_enable : bool; + tx_rollup_origination_size : int; + (* the maximum amount of bytes messages can allocate in an inbox *) + tx_rollup_hard_size_limit_per_inbox : int; + (* the maximum amount of bytes one batch can allocate in an inbox *) + tx_rollup_hard_size_limit_per_message : int; + (* the amount of tez to bond a tx rollup commitment *) + tx_rollup_commitment_bond : Tez_repr.t; + (* the number of blocks before a tx rollup block is final *) + tx_rollup_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. *) + tx_rollup_withdraw_period : int; + tx_rollup_max_inboxes_count : int; + (* the maximum number of messages in an inbox. This bounds the + size of a commitment. *) + tx_rollup_max_messages_per_inbox : int; + (* the maximum number of finalized commitments, to ensure that + remove_commitment is ever called *) + tx_rollup_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. *) + tx_rollup_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. *) + tx_rollup_max_ticket_payload_size : int; + tx_rollup_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. *) + 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; + sc_rollup_stake_amount_in_mutez : int; + (* The frequency with which commitments are made. *) + sc_rollup_commitment_frequency_in_blocks : int; + (* The storage size requirement (in bytes) of a commitment *) + sc_rollup_commitment_storage_size_in_bytes : int; + (* The maximum depth of a staker's position - chosen alongside + [sc_rollup_commitment_frequency_in_blocks] to prevent the cost + of a staker's commitments' storage being greater than their deposit. *) + sc_rollup_max_lookahead_in_blocks : int32; +} + +val encoding : t Data_encoding.encoding diff --git a/src/proto_alpha/lib_protocol/constants_repr.ml b/src/proto_alpha/lib_protocol/constants_repr.ml index 2c50f5ab494f385e1c912278169b9b0b095b82f5..05d0eecc038cd3bdc4a88a36f137a23970db936e 100644 --- a/src/proto_alpha/lib_protocol/constants_repr.ml +++ b/src/proto_alpha/lib_protocol/constants_repr.ml @@ -61,20 +61,6 @@ let cache_layout_size = 3 type fixed = unit -type ratio = {numerator : int; denominator : int} - -let ratio_encoding = - let open Data_encoding in - conv_with_guard - (fun r -> (r.numerator, r.denominator)) - (fun (numerator, denominator) -> - if Compare.Int.(denominator > 0) then ok {numerator; denominator} - else Error "The denominator must be greater than 0.") - (obj2 (req "numerator" uint16) (req "denominator" uint16)) - -let pp_ratio fmt {numerator; denominator} = - Format.fprintf fmt "%d/%d" numerator denominator - let fixed_encoding = let open Data_encoding in conv @@ -113,344 +99,7 @@ let fixed_encoding = let fixed = () -(* 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, you should ensure that there is a - proper migration of the constants during context migration. *) -type parametric = { - preserved_cycles : int; - blocks_per_cycle : int32; - blocks_per_commitment : 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; - 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; - 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_sunset_level : int32; - liquidity_baking_toggle_ema_threshold : int32; - max_operations_time_to_live : int; - minimal_block_delay : Period_repr.t; - delay_increment_per_round : Period_repr.t; - minimal_participation_ratio : ratio; - 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_endorsement : ratio; - 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; - sc_rollup_stake_amount_in_mutez : int; - sc_rollup_commitment_frequency_in_blocks : int; - sc_rollup_commitment_storage_size_in_bytes : int; - sc_rollup_max_lookahead_in_blocks : int32; -} - -let parametric_encoding = - let open Data_encoding in - conv - (fun c -> - ( ( c.preserved_cycles, - c.blocks_per_cycle, - c.blocks_per_commitment, - 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.origination_size, - 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_sunset_level, - c.liquidity_baking_toggle_ema_threshold, - c.max_operations_time_to_live, - c.minimal_block_delay, - c.delay_increment_per_round, - 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_endorsement, - 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.sc_rollup_stake_amount_in_mutez, - c.sc_rollup_commitment_frequency_in_blocks, - c.sc_rollup_commitment_storage_size_in_bytes, - c.sc_rollup_max_lookahead_in_blocks ) ) ) ) ) ) )) - (fun ( ( preserved_cycles, - blocks_per_cycle, - blocks_per_commitment, - 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, - origination_size, - 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_sunset_level, - liquidity_baking_toggle_ema_threshold, - max_operations_time_to_live, - minimal_block_delay, - delay_increment_per_round, - consensus_committee_size, - consensus_threshold ), - ( ( minimal_participation_ratio, - max_slashing_period, - frozen_deposits_percentage, - double_baking_punishment, - ratio_of_frozen_deposits_slashed_per_double_endorsement, - 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, - sc_rollup_stake_amount_in_mutez, - sc_rollup_commitment_frequency_in_blocks, - sc_rollup_commitment_storage_size_in_bytes, - sc_rollup_max_lookahead_in_blocks ) ) ) ) ) ) ) -> - { - preserved_cycles; - blocks_per_cycle; - blocks_per_commitment; - 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; - origination_size; - 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_sunset_level; - 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_endorsement; - 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; - sc_rollup_stake_amount_in_mutez; - sc_rollup_commitment_frequency_in_blocks; - sc_rollup_commitment_storage_size_in_bytes; - sc_rollup_max_lookahead_in_blocks; - }) - (merge_objs - (obj9 - (req "preserved_cycles" uint8) - (req "blocks_per_cycle" int32) - (req "blocks_per_commitment" int32) - (req "blocks_per_stake_snapshot" int32) - (req "cycles_per_voting_period" int32) - (req - "hard_gas_limit_per_operation" - Gas_limit_repr.Arith.z_integral_encoding) - (req - "hard_gas_limit_per_block" - Gas_limit_repr.Arith.z_integral_encoding) - (req "proof_of_work_threshold" int64) - (req "tokens_per_roll" Tez_repr.encoding)) - (merge_objs - (obj8 - (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 "cost_per_byte" Tez_repr.encoding) - (req "hard_storage_limit_per_operation" z) - (req "quorum_min" int32)) - (merge_objs - (obj10 - (req "quorum_max" int32) - (req "min_proposal_quorum" int32) - (req "liquidity_baking_subsidy" Tez_repr.encoding) - (req "liquidity_baking_sunset_level" int32) - (req "liquidity_baking_toggle_ema_threshold" int32) - (req "max_operations_time_to_live" int16) - (req "minimal_block_delay" Period_repr.encoding) - (req "delay_increment_per_round" Period_repr.encoding) - (req "consensus_committee_size" int31) - (req "consensus_threshold" int31)) - (merge_objs - (obj6 - (req "minimal_participation_ratio" ratio_encoding) - (req "max_slashing_period" int31) - (req "frozen_deposits_percentage" int31) - (req "double_baking_punishment" Tez_repr.encoding) - (req - "ratio_of_frozen_deposits_slashed_per_double_endorsement" - ratio_encoding) - (opt "initial_seed" State_hash.encoding)) - (merge_objs - (obj3 - (req "cache_script_size" int31) - (req "cache_stake_distribution_cycles" int8) - (req "cache_sampler_state_cycles" int8)) - (merge_objs - (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))) - (obj8 - (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_in_mutez" int31) - (req "sc_rollup_commitment_frequency_in_blocks" int31) - (req - "sc_rollup_commitment_storage_size_in_bytes" - int31) - (req "sc_rollup_max_lookahead_in_blocks" int32)))))))) - -type t = {fixed : fixed; parametric : parametric} +type t = {fixed : fixed; parametric : Constants_parametric_repr.t} let all_of_parametric parametric = {fixed; parametric} @@ -459,7 +108,7 @@ let encoding = conv (fun {fixed; parametric} -> (fixed, parametric)) (fun (fixed, parametric) -> {fixed; parametric}) - (merge_objs fixed_encoding parametric_encoding) + (merge_objs fixed_encoding Constants_parametric_repr.encoding) type error += Invalid_protocol_constants of string (* `Permanent *) @@ -476,6 +125,7 @@ let () = (fun reason -> Invalid_protocol_constants reason) let check_constants constants = + let open Constants_parametric_repr in error_unless Period_repr.(constants.minimal_block_delay > zero) (Invalid_protocol_constants @@ -500,7 +150,9 @@ let check_constants constants = than or equal to the consensus commitee size.") >>? fun () -> error_unless - (let {numerator; denominator} = constants.minimal_participation_ratio in + (let Ratio_repr.{numerator; denominator} = + constants.minimal_participation_ratio + in Compare.Int.(numerator >= 0 && denominator > 0)) (Invalid_protocol_constants "The minimal participation ratio must be a non-negative valid ratio.") @@ -532,7 +184,7 @@ let check_constants constants = "The double baking punishment must be non-negative.") >>? fun () -> error_unless - (let {numerator; denominator} = + (let Ratio_repr.{numerator; denominator} = constants.ratio_of_frozen_deposits_slashed_per_double_endorsement in Compare.Int.(numerator >= 0 && denominator > 0)) @@ -566,10 +218,11 @@ module Generated = struct be 80 tez. *) let rewards_per_minute = Tez_repr.(mul_exn one 80) in let rewards_per_block = - Tez_repr.( - div_exn - (mul_exn rewards_per_minute blocks_per_minute.denominator) - blocks_per_minute.numerator) + Ratio_repr.( + Tez_repr.( + div_exn + (mul_exn rewards_per_minute blocks_per_minute.denominator) + blocks_per_minute.numerator)) in let rewards_half = Tez_repr.(div_exn rewards_per_block 2) in let rewards_quarter = Tez_repr.(div_exn rewards_per_block 4) in @@ -589,221 +242,10 @@ module Generated = struct } end -module Proto_previous = struct - type delegate_selection = - | Random - | Round_robin_over of Signature.Public_key.t list list - - let delegate_selection_encoding = - let open Data_encoding in - union - [ - case - (Tag 0) - ~title:"Random_delegate_selection" - (constant "random") - (function Random -> Some () | _ -> None) - (fun () -> Random); - case - (Tag 1) - ~title:"Round_robin_over_delegates" - (list (list Signature.Public_key.encoding)) - (function Round_robin_over l -> Some l | _ -> None) - (fun l -> Round_robin_over l); - ] - - type parametric = { - preserved_cycles : int; - blocks_per_cycle : int32; - blocks_per_commitment : int32; - blocks_per_stake_snapshot : int32; - blocks_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; - 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; - 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_sunset_level : int32; - liquidity_baking_toggle_ema_threshold : int32; - max_operations_time_to_live : int; - minimal_block_delay : Period_repr.t; - delay_increment_per_round : Period_repr.t; - minimal_participation_ratio : ratio; - 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_endorsement : ratio; - delegate_selection : delegate_selection; - } - - let parametric_encoding = - let open Data_encoding in - conv - (fun c -> - ( ( c.preserved_cycles, - c.blocks_per_cycle, - c.blocks_per_commitment, - c.blocks_per_stake_snapshot, - c.blocks_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.origination_size, - 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_sunset_level, - c.liquidity_baking_toggle_ema_threshold, - c.max_operations_time_to_live, - c.minimal_block_delay, - c.delay_increment_per_round, - 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_endorsement, - c.delegate_selection ) ) ) )) - (fun ( ( preserved_cycles, - blocks_per_cycle, - blocks_per_commitment, - blocks_per_stake_snapshot, - blocks_per_voting_period, - hard_gas_limit_per_operation, - hard_gas_limit_per_block, - proof_of_work_threshold, - tokens_per_roll ), - ( ( seed_nonce_revelation_tip, - origination_size, - 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_sunset_level, - liquidity_baking_toggle_ema_threshold, - max_operations_time_to_live, - minimal_block_delay, - delay_increment_per_round, - consensus_committee_size, - consensus_threshold ), - ( minimal_participation_ratio, - max_slashing_period, - frozen_deposits_percentage, - double_baking_punishment, - ratio_of_frozen_deposits_slashed_per_double_endorsement, - delegate_selection ) ) ) ) -> - { - preserved_cycles; - blocks_per_cycle; - blocks_per_commitment; - blocks_per_stake_snapshot; - blocks_per_voting_period; - hard_gas_limit_per_operation; - hard_gas_limit_per_block; - proof_of_work_threshold; - tokens_per_roll; - seed_nonce_revelation_tip; - origination_size; - 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_sunset_level; - 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_endorsement; - delegate_selection; - }) - (merge_objs - (obj9 - (req "preserved_cycles" uint8) - (req "blocks_per_cycle" int32) - (req "blocks_per_commitment" int32) - (req "blocks_per_stake_snapshot" int32) - (req "blocks_per_voting_period" int32) - (req - "hard_gas_limit_per_operation" - Gas_limit_repr.Arith.z_integral_encoding) - (req - "hard_gas_limit_per_block" - Gas_limit_repr.Arith.z_integral_encoding) - (req "proof_of_work_threshold" int64) - (req "tokens_per_roll" Tez_repr.encoding)) - (merge_objs - (obj8 - (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 "cost_per_byte" Tez_repr.encoding) - (req "hard_storage_limit_per_operation" z) - (req "quorum_min" int32)) - (merge_objs - (obj10 - (req "quorum_max" int32) - (req "min_proposal_quorum" int32) - (req "liquidity_baking_subsidy" Tez_repr.encoding) - (req "liquidity_baking_sunset_level" int32) - (req "liquidity_baking_toggle_ema_threshold" int32) - (req "max_operations_time_to_live" int16) - (req "minimal_block_delay" Period_repr.encoding) - (req "delay_increment_per_round" Period_repr.encoding) - (req "consensus_committee_size" int31) - (req "consensus_threshold" int31)) - (obj6 - (req "minimal_participation_ratio" ratio_encoding) - (req "max_slashing_period" int31) - (req "frozen_deposits_percentage" int31) - (req "double_baking_punishment" Tez_repr.encoding) - (req - "ratio_of_frozen_deposits_slashed_per_double_endorsement" - ratio_encoding) - (dft "delegate_selection" delegate_selection_encoding Random))))) -end - let cache_layout p = - [ - p.cache_script_size; - p.cache_stake_distribution_cycles; - p.cache_sampler_state_cycles; - ] + Constants_parametric_repr. + [ + p.cache_script_size; + p.cache_stake_distribution_cycles; + p.cache_sampler_state_cycles; + ] diff --git a/src/proto_alpha/lib_protocol/constants_repr.mli b/src/proto_alpha/lib_protocol/constants_repr.mli index 17fa05f0fd43bcf7174dfed332c297770befd491..60c4bf1139d34bb1f6814d17c0b517118179b036 100644 --- a/src/proto_alpha/lib_protocol/constants_repr.mli +++ b/src/proto_alpha/lib_protocol/constants_repr.mli @@ -76,130 +76,16 @@ type fixed val fixed_encoding : fixed Data_encoding.encoding -type ratio = {numerator : int; denominator : int} +type t = private {fixed : fixed; parametric : Constants_parametric_repr.t} -val ratio_encoding : ratio Data_encoding.t - -val pp_ratio : Format.formatter -> ratio -> unit - -type parametric = { - preserved_cycles : int; - blocks_per_cycle : int32; - blocks_per_commitment : 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; - 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; - 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_sunset_level : int32; - liquidity_baking_toggle_ema_threshold : int32; - max_operations_time_to_live : int; - minimal_block_delay : Period_repr.t; - delay_increment_per_round : Period_repr.t; - minimal_participation_ratio : ratio; - 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; - initial_seed : State_hash.t option; - cache_script_size : int; - (* in bytes *) - cache_stake_distribution_cycles : int; - (* in cycles *) - cache_sampler_state_cycles : int; - (* in cycles *) - tx_rollup_enable : bool; - tx_rollup_origination_size : int; - (* the maximum amount of bytes messages can allocate in an inbox *) - tx_rollup_hard_size_limit_per_inbox : int; - (* the maximum amount of bytes one batch can allocate in an inbox *) - tx_rollup_hard_size_limit_per_message : int; - (* the amount of tez to bond a tx rollup commitment *) - tx_rollup_commitment_bond : Tez_repr.t; - (* the number of blocks before a tx rollup block is final *) - tx_rollup_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. *) - tx_rollup_withdraw_period : int; - tx_rollup_max_inboxes_count : int; - (* the maximum number of messages in an inbox. This bounds the - size of a commitment. *) - tx_rollup_max_messages_per_inbox : int; - (* the maximum number of finalized commitments, to ensure that - remove_commitment is ever called *) - tx_rollup_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. *) - tx_rollup_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. *) - tx_rollup_max_ticket_payload_size : int; - tx_rollup_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. *) - 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; - sc_rollup_stake_amount_in_mutez : int; - (* The frequency with which commitments are made. *) - sc_rollup_commitment_frequency_in_blocks : int; - (* The storage size requirement (in bytes) of a commitment *) - sc_rollup_commitment_storage_size_in_bytes : int; - (* The maximum depth of a staker's position - chosen alongside - [sc_rollup_commitment_frequency_in_blocks] to prevent the cost - of a staker's commitments' storage being greater than their deposit. *) - sc_rollup_max_lookahead_in_blocks : int32; -} - -val parametric_encoding : parametric Data_encoding.encoding - -type t = private {fixed : fixed; parametric : parametric} - -val all_of_parametric : parametric -> t +val all_of_parametric : Constants_parametric_repr.t -> t val encoding : t Data_encoding.encoding type error += (* `Permanent *) Invalid_protocol_constants of string (** performs some consistency checks on the protocol parameters *) -val check_constants : parametric -> unit tzresult +val check_constants : Constants_parametric_repr.t -> unit tzresult module Generated : sig type t = { @@ -211,51 +97,8 @@ module Generated : sig (* This function is meant to be used just in lib_parameters and in the migration code to be sure that the parameters are consistent. *) - val generate : consensus_committee_size:int -> blocks_per_minute:ratio -> t -end - -module Proto_previous : sig - type delegate_selection = - | Random - | Round_robin_over of Signature.Public_key.t list list - - type parametric = { - preserved_cycles : int; - blocks_per_cycle : int32; - blocks_per_commitment : int32; - blocks_per_stake_snapshot : int32; - blocks_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; - 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; - 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_sunset_level : int32; - liquidity_baking_toggle_ema_threshold : int32; - max_operations_time_to_live : int; - minimal_block_delay : Period_repr.t; - delay_increment_per_round : Period_repr.t; - minimal_participation_ratio : ratio; - 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_endorsement : ratio; - delegate_selection : delegate_selection; - } - - val parametric_encoding : parametric Data_encoding.encoding + val generate : + consensus_committee_size:int -> blocks_per_minute:Ratio_repr.t -> t end (** For each subcache, a size limit needs to be declared once. However, @@ -269,4 +112,4 @@ end val cache_layout_size : int (** The [cache_layout] depends on parametric constants. *) -val cache_layout : parametric -> int list +val cache_layout : Constants_parametric_repr.t -> int list diff --git a/src/proto_alpha/lib_protocol/constants_storage.mli b/src/proto_alpha/lib_protocol/constants_storage.mli index 242f918277cbc4c508899191a98cb3ce826bd565..d5896d65c2ab118580f542354d570e83eb169347 100644 --- a/src/proto_alpha/lib_protocol/constants_storage.mli +++ b/src/proto_alpha/lib_protocol/constants_storage.mli @@ -74,13 +74,13 @@ val liquidity_baking_sunset_level : Raw_context.t -> int32 val liquidity_baking_toggle_ema_threshold : Raw_context.t -> int32 -val parametric : Raw_context.t -> Constants_repr.parametric +val parametric : Raw_context.t -> Constants_parametric_repr.t val consensus_committee_size : Raw_context.t -> int val consensus_threshold : Raw_context.t -> int -val minimal_participation_ratio : Raw_context.t -> Constants_repr.ratio +val minimal_participation_ratio : Raw_context.t -> Ratio_repr.t val max_slashing_period : Raw_context.t -> int @@ -119,7 +119,7 @@ val tx_rollup_rejection_max_proof_size : Raw_context.t -> int val tx_rollup_sunset_level : Raw_context.t -> int32 val ratio_of_frozen_deposits_slashed_per_double_endorsement : - Raw_context.t -> Constants_repr.ratio + Raw_context.t -> Ratio_repr.t val minimal_block_delay : Raw_context.t -> Period_repr.t diff --git a/src/proto_alpha/lib_protocol/delegate_storage.ml b/src/proto_alpha/lib_protocol/delegate_storage.ml index fcfbe0ab3a203b3b6d5fe44ed8a4e9d3dbdcb305..58e78810f5d5a1550e3c0925e8124238bd65a2f1 100644 --- a/src/proto_alpha/lib_protocol/delegate_storage.ml +++ b/src/proto_alpha/lib_protocol/delegate_storage.ml @@ -815,7 +815,7 @@ let already_slashed_for_double_baking ctxt delegate (level : Level_repr.t) = let punish_double_endorsing ctxt delegate (level : Level_repr.t) = let delegate_contract = Contract_repr.implicit_contract delegate in Frozen_deposits_storage.get ctxt delegate_contract >>=? fun frozen_deposits -> - let slashing_ratio : Constants_repr.ratio = + let slashing_ratio : Ratio_repr.t = Constants_storage.ratio_of_frozen_deposits_slashed_per_double_endorsement ctxt in @@ -921,7 +921,7 @@ let record_endorsing_participation ctxt ~delegate ~participation ~total_active_stake ~active_stake >>?= fun expected_slots -> - let Constants_repr.{numerator; denominator} = + let Ratio_repr.{numerator; denominator} = Constants_storage.minimal_participation_ratio ctxt in let minimal_activity = expected_slots * numerator / denominator in @@ -999,7 +999,7 @@ let delegate_participation_info ctxt delegate = ~total_active_stake ~active_stake >>?= fun expected_cycle_activity -> - let Constants_repr.{numerator; denominator} = + let Ratio_repr.{numerator; denominator} = Constants_storage.minimal_participation_ratio ctxt in let endorsing_reward_per_slot = diff --git a/src/proto_alpha/lib_protocol/dune.inc b/src/proto_alpha/lib_protocol/dune.inc index cd2d02f738092ea2c0ce706c3df42531dcd8e9e8..bf948fdebf1014cec76bd0bfb363c359109dbd7f 100644 --- a/src/proto_alpha/lib_protocol/dune.inc +++ b/src/proto_alpha/lib_protocol/dune.inc @@ -46,11 +46,14 @@ module CamlinternalFormatBasics = struct include CamlinternalFormatBasics end tez_repr.mli tez_repr.ml period_repr.mli period_repr.ml time_repr.mli time_repr.ml + ratio_repr.mli ratio_repr.ml round_repr.mli round_repr.ml block_payload_repr.mli block_payload_repr.ml fixed_point_repr.mli fixed_point_repr.ml saturation_repr.mli saturation_repr.ml gas_limit_repr.mli gas_limit_repr.ml + constants_parametric_repr.mli constants_parametric_repr.ml + constants_parametric_previous_repr.mli constants_parametric_previous_repr.ml constants_repr.mli constants_repr.ml raw_level_repr.mli raw_level_repr.ml fitness_repr.mli fitness_repr.ml @@ -233,11 +236,14 @@ module CamlinternalFormatBasics = struct include CamlinternalFormatBasics end tez_repr.mli tez_repr.ml period_repr.mli period_repr.ml time_repr.mli time_repr.ml + ratio_repr.mli ratio_repr.ml round_repr.mli round_repr.ml block_payload_repr.mli block_payload_repr.ml fixed_point_repr.mli fixed_point_repr.ml saturation_repr.mli saturation_repr.ml gas_limit_repr.mli gas_limit_repr.ml + constants_parametric_repr.mli constants_parametric_repr.ml + constants_parametric_previous_repr.mli constants_parametric_previous_repr.ml constants_repr.mli constants_repr.ml raw_level_repr.mli raw_level_repr.ml fitness_repr.mli fitness_repr.ml @@ -420,11 +426,14 @@ module CamlinternalFormatBasics = struct include CamlinternalFormatBasics end tez_repr.mli tez_repr.ml period_repr.mli period_repr.ml time_repr.mli time_repr.ml + ratio_repr.mli ratio_repr.ml round_repr.mli round_repr.ml block_payload_repr.mli block_payload_repr.ml fixed_point_repr.mli fixed_point_repr.ml saturation_repr.mli saturation_repr.ml gas_limit_repr.mli gas_limit_repr.ml + constants_parametric_repr.mli constants_parametric_repr.ml + constants_parametric_previous_repr.mli constants_parametric_previous_repr.ml constants_repr.mli constants_repr.ml raw_level_repr.mli raw_level_repr.ml fitness_repr.mli fitness_repr.ml @@ -629,11 +638,14 @@ include Tezos_raw_protocol_alpha.Main Tez_repr Period_repr Time_repr + Ratio_repr Round_repr Block_payload_repr Fixed_point_repr Saturation_repr Gas_limit_repr + Constants_parametric_repr + Constants_parametric_previous_repr Constants_repr Raw_level_repr Fitness_repr @@ -857,11 +869,14 @@ include Tezos_raw_protocol_alpha.Main tez_repr.mli tez_repr.ml period_repr.mli period_repr.ml time_repr.mli time_repr.ml + ratio_repr.mli ratio_repr.ml round_repr.mli round_repr.ml block_payload_repr.mli block_payload_repr.ml fixed_point_repr.mli fixed_point_repr.ml saturation_repr.mli saturation_repr.ml gas_limit_repr.mli gas_limit_repr.ml + constants_parametric_repr.mli constants_parametric_repr.ml + constants_parametric_previous_repr.mli constants_parametric_previous_repr.ml constants_repr.mli constants_repr.ml raw_level_repr.mli raw_level_repr.ml fitness_repr.mli fitness_repr.ml diff --git a/src/proto_alpha/lib_protocol/parameters_repr.ml b/src/proto_alpha/lib_protocol/parameters_repr.ml index 5f21e6c3d453a821f41c65b96273adaefef17f31..5fc7d3bd9fb35b82da22627ce0f7b22030e1927f 100644 --- a/src/proto_alpha/lib_protocol/parameters_repr.ml +++ b/src/proto_alpha/lib_protocol/parameters_repr.ml @@ -40,7 +40,7 @@ type t = { bootstrap_accounts : bootstrap_account list; bootstrap_contracts : bootstrap_contract list; commitments : Commitment_repr.t list; - constants : Constants_repr.parametric; + constants : Constants_parametric_repr.t; security_deposit_ramp_up_cycles : int option; no_reward_cycles : int option; } @@ -127,6 +127,6 @@ let encoding = (dft "commitments" (list Commitment_repr.encoding) []) (opt "security_deposit_ramp_up_cycles" int31) (opt "no_reward_cycles" int31)) - Constants_repr.parametric_encoding) + Constants_parametric_repr.encoding) let check_params params = Constants_repr.check_constants params.constants diff --git a/src/proto_alpha/lib_protocol/parameters_repr.mli b/src/proto_alpha/lib_protocol/parameters_repr.mli index 0b9e3af8ed3dcef52234d61788732071db847b9a..d31bab91a86cd9482a298c069fd7733a0ddfae8f 100644 --- a/src/proto_alpha/lib_protocol/parameters_repr.mli +++ b/src/proto_alpha/lib_protocol/parameters_repr.mli @@ -47,7 +47,7 @@ type t = { bootstrap_accounts : bootstrap_account list; bootstrap_contracts : bootstrap_contract list; commitments : Commitment_repr.t list; - constants : Constants_repr.parametric; + constants : Constants_parametric_repr.t; security_deposit_ramp_up_cycles : int option; no_reward_cycles : int option; } diff --git a/src/proto_alpha/lib_protocol/ratio_repr.ml b/src/proto_alpha/lib_protocol/ratio_repr.ml new file mode 100644 index 0000000000000000000000000000000000000000..463ab0667f228de93630986d303f25b36fbceea4 --- /dev/null +++ b/src/proto_alpha/lib_protocol/ratio_repr.ml @@ -0,0 +1,38 @@ +(*****************************************************************************) +(* *) +(* Open Source License *) +(* Copyright (c) 2021 Nomadic Labs *) +(* *) +(* 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. *) +(* *) +(*****************************************************************************) + +type t = {numerator : int; denominator : int} + +let encoding = + let open Data_encoding in + conv_with_guard + (fun r -> (r.numerator, r.denominator)) + (fun (numerator, denominator) -> + if Compare.Int.(denominator > 0) then ok {numerator; denominator} + else Error "The denominator must be greater than 0.") + (obj2 (req "numerator" uint16) (req "denominator" uint16)) + +let pp fmt {numerator; denominator} = + Format.fprintf fmt "%d/%d" numerator denominator diff --git a/src/proto_alpha/lib_protocol/ratio_repr.mli b/src/proto_alpha/lib_protocol/ratio_repr.mli new file mode 100644 index 0000000000000000000000000000000000000000..237f04972695f111cbde3519be40460349efaf14 --- /dev/null +++ b/src/proto_alpha/lib_protocol/ratio_repr.mli @@ -0,0 +1,30 @@ +(*****************************************************************************) +(* *) +(* Open Source License *) +(* Copyright (c) 2021 Nomadic Labs *) +(* *) +(* 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. *) +(* *) +(*****************************************************************************) + +type t = {numerator : int; denominator : int} + +val encoding : t Data_encoding.t + +val pp : Format.formatter -> t -> unit diff --git a/src/proto_alpha/lib_protocol/raw_context.ml b/src/proto_alpha/lib_protocol/raw_context.ml index 1d76c99145b0b6680f38a4226a91b9e7d52038c4..455e3716316f796c2183be7bf3b7dc45a153317b 100644 --- a/src/proto_alpha/lib_protocol/raw_context.ml +++ b/src/proto_alpha/lib_protocol/raw_context.ml @@ -223,7 +223,7 @@ end type back = { context : Context.t; - constants : Constants_repr.parametric; + constants : Constants_parametric_repr.t; round_durations : Round_repr.Durations.t; cycle_eras : Level_repr.cycle_eras; level : Level_repr.t; @@ -740,7 +740,7 @@ let get_proto_param ctxt = let add_constants ctxt constants = let bytes = Data_encoding.Binary.to_bytes_exn - Constants_repr.parametric_encoding + Constants_parametric_repr.encoding constants in Context.add ctxt constants_key bytes @@ -751,7 +751,7 @@ let get_constants ctxt = | Some bytes -> ( match Data_encoding.Binary.of_bytes_opt - Constants_repr.parametric_encoding + Constants_parametric_repr.encoding bytes with | None -> failwith "Internal error: cannot parse constants in context." @@ -772,7 +772,7 @@ let check_inited ctxt = else storage_error (Incompatible_protocol_version s) let check_cycle_eras (cycle_eras : Level_repr.cycle_eras) - (constants : Constants_repr.parametric) = + (constants : Constants_parametric_repr.t) = let current_era = Level_repr.current_era cycle_eras in assert ( Compare.Int32.(current_era.blocks_per_cycle = constants.blocks_per_cycle)) ; @@ -809,7 +809,7 @@ let prepare ~level ~predecessor_timestamp ~timestamp ctxt = internal_nonces_used = Int_set.empty; remaining_block_gas = Gas_limit_repr.Arith.fp - constants.Constants_repr.hard_gas_limit_per_block; + constants.Constants_parametric_repr.hard_gas_limit_per_block; unlimited_operation_gas = true; consensus = Raw_consensus.empty; non_consensus_operations_rev = []; @@ -847,7 +847,7 @@ let[@warning "-32"] get_previous_protocol_constants ctxt = | Some bytes -> ( match Data_encoding.Binary.of_bytes_opt - Constants_repr.Proto_previous.parametric_encoding + Constants_parametric_previous_repr.encoding bytes with | None -> @@ -856,8 +856,8 @@ let[@warning "-32"] get_previous_protocol_constants ctxt = context." | Some constants -> Lwt.return constants) -(* You should ensure that if the type `Constant_repr.parametric` is - different from the previous protocol or the value of these +(* You should ensure that if the type `Constants_parametric_repr.t` is + different from `Constants_parametric_previous_repr.t` or the value of these constants is modified, is changed from the previous protocol, then you `propagate` these constants to the new protocol by writing them onto the context via the function `add_constants` or @@ -891,7 +891,7 @@ let prepare_first_block ~level ~timestamp ctxt = in let tx_rollup_finality_period = 40_000 in let constants = - Constants_repr. + Constants_parametric_repr. { preserved_cycles = c.preserved_cycles; blocks_per_cycle = c.blocks_per_cycle; diff --git a/src/proto_alpha/lib_protocol/raw_context.mli b/src/proto_alpha/lib_protocol/raw_context.mli index 0d0be17ae4cd42b2860e8ed0b3375aa65f0c66fb..d01092a3adf7af0dad020c86427536630682a173 100644 --- a/src/proto_alpha/lib_protocol/raw_context.mli +++ b/src/proto_alpha/lib_protocol/raw_context.mli @@ -103,10 +103,10 @@ val predecessor_timestamp : t -> Time.t val current_timestamp : t -> Time.t -val constants : t -> Constants_repr.parametric +val constants : t -> Constants_parametric_repr.t val patch_constants : - t -> (Constants_repr.parametric -> Constants_repr.parametric) -> t Lwt.t + t -> (Constants_parametric_repr.t -> Constants_parametric_repr.t) -> t Lwt.t val round_durations : t -> Round_repr.Durations.t diff --git a/src/proto_alpha/lib_protocol/test/helpers/block.ml b/src/proto_alpha/lib_protocol/test/helpers/block.ml index bfef99e48c7f10c9564b48661ca43c862da6e2ed..a0dacf2fbce433d265ee5b37c079add13bee5d04 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/block.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/block.ml @@ -257,7 +257,7 @@ end let protocol_param_key = ["protocol_parameters"] let check_constants_consistency constants = - let open Constants in + let open Constants.Parametric in let {blocks_per_cycle; blocks_per_commitment; blocks_per_stake_snapshot; _} = constants in diff --git a/src/proto_alpha/lib_protocol/test/helpers/block.mli b/src/proto_alpha/lib_protocol/test/helpers/block.mli index 265609ad96d8365b9c87a5c99023e852f1636b5e..ad43ff797e2626181e98babb8b976fa1ceb76c57 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/block.mli +++ b/src/proto_alpha/lib_protocol/test/helpers/block.mli @@ -101,7 +101,7 @@ module Forge : sig val sign_header : header -> Block_header.block_header tzresult Lwt.t end -val check_constants_consistency : Constants.parametric -> unit tzresult Lwt.t +val check_constants_consistency : Constants.Parametric.t -> unit tzresult Lwt.t (** [genesis accounts] : generates an initial block with the given constants [] and initializes [accounts] with their @@ -263,7 +263,7 @@ val prepare_initial_context_params : ?tx_rollup_origination_size:int -> ?sc_rollup_enable:bool -> (Account.t * Tez.t) list -> - ( Constants.parametric * Block_header.shell_header * Block_hash.t, + ( Constants.Parametric.t * Block_header.shell_header * Block_hash.t, tztrace ) result Lwt.t diff --git a/src/proto_alpha/lib_protocol/test/helpers/context.mli b/src/proto_alpha/lib_protocol/test/helpers/context.mli index 6f4b244732f6dba4f9e2af6516c8fba60d57216c..6e267f7243cf737c1b922334e56860af681cb9df 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/context.mli +++ b/src/proto_alpha/lib_protocol/test/helpers/context.mli @@ -75,7 +75,7 @@ val get_constants : t -> Constants.t tzresult Lwt.t (** The default constants used in the test framework. To be used with [init_with_constants]. *) -val default_test_constants : Constants.parametric +val default_test_constants : Constants.Parametric.t val get_baking_reward_fixed_portion : t -> Tez.t tzresult Lwt.t @@ -255,19 +255,19 @@ val init3 : val init_with_constants_gen : (Alpha_context.Contract.t, 'contracts) tup -> - Constants.parametric -> + Constants.Parametric.t -> (Block.t * 'contracts) tzresult Lwt.t val init_with_constants_n : - Constants.parametric -> + Constants.Parametric.t -> int -> (Block.t * Alpha_context.Contract.t list) tzresult Lwt.t val init_with_constants1 : - Constants.parametric -> (Block.t * Alpha_context.Contract.t) tzresult Lwt.t + Constants.Parametric.t -> (Block.t * Alpha_context.Contract.t) tzresult Lwt.t val init_with_constants2 : - Constants.parametric -> + Constants.Parametric.t -> (Block.t * (Alpha_context.Contract.t * Alpha_context.Contract.t)) tzresult Lwt.t diff --git a/src/proto_alpha/lib_protocol/test/integration/consensus/test_participation.ml b/src/proto_alpha/lib_protocol/test/integration/consensus/test_participation.ml index dd930553708e080575901d42ab6e124a973db04e..919ef95c96b0cb7ded82f41448d7536236947a1c 100644 --- a/src/proto_alpha/lib_protocol/test/integration/consensus/test_participation.ml +++ b/src/proto_alpha/lib_protocol/test/integration/consensus/test_participation.ml @@ -130,7 +130,7 @@ let test_participation_rpc () = let del2 = Context.Contract.pkh account2 in Context.get_constants (B b0) >>=? fun csts -> let blocks_per_cycle = Int32.to_int csts.parametric.blocks_per_cycle in - let Constants.{numerator; denominator} = + let Ratio.{numerator; denominator} = csts.parametric.minimal_participation_ratio in let expected_cycle_activity = diff --git a/src/proto_alpha/lib_protocol/test/integration/consensus/test_seed.ml b/src/proto_alpha/lib_protocol/test/integration/consensus/test_seed.ml index 85cf20c0e645c681ec4f1b90e98efd1e22abc7c3..504bdec22b5f60366b5b327d5451dfd5d6dba40d 100644 --- a/src/proto_alpha/lib_protocol/test/integration/consensus/test_seed.ml +++ b/src/proto_alpha/lib_protocol/test/integration/consensus/test_seed.ml @@ -185,7 +185,7 @@ let test_unrevealed () = baking_reward_fixed_portion = Tez.zero; seed_nonce_revelation_tip = Tez.zero; consensus_threshold = 0; - minimal_participation_ratio = Constants.{numerator = 0; denominator = 1}; + minimal_participation_ratio = Ratio.{numerator = 0; denominator = 1}; } in Context.init_with_constants2 constants >>=? fun (b, (_account1, account2)) -> diff --git a/src/proto_alpha/lib_tx_rollup/daemon.ml b/src/proto_alpha/lib_tx_rollup/daemon.ml index 4806d496c8bbaa5873b901b3d0343724288ad0be..5f81de987ec43cd67b6cc5f004e2d524fc0735ee 100644 --- a/src/proto_alpha/lib_tx_rollup/daemon.ml +++ b/src/proto_alpha/lib_tx_rollup/daemon.ml @@ -356,7 +356,7 @@ let queue_gc_operations state = let time_until_next_block state (header : Tezos_base.Block_header.t) = let open Result_syntax in - let Constants.{minimal_block_delay; delay_increment_per_round; _} = + let Constants.Parametric.{minimal_block_delay; delay_increment_per_round; _} = state.State.constants.parametric in let next_level_timestamp =