From c4096664434dc124c9ddb8467d7d02ec83475a6a Mon Sep 17 00:00:00 2001 From: Eugen Zalinescu Date: Tue, 29 Oct 2024 17:09:16 +0100 Subject: [PATCH 1/7] Alpha: provide a q_encoding helper function --- .../lib_protocol/constants_parametric_repr.ml | 61 ++++++++----------- 1 file changed, 25 insertions(+), 36 deletions(-) diff --git a/src/proto_alpha/lib_protocol/constants_parametric_repr.ml b/src/proto_alpha/lib_protocol/constants_parametric_repr.ml index 7ead82db13c1..e3b9b6b59db4 100644 --- a/src/proto_alpha/lib_protocol/constants_parametric_repr.ml +++ b/src/proto_alpha/lib_protocol/constants_parametric_repr.ml @@ -25,6 +25,23 @@ (* *) (*****************************************************************************) +let q_encoding cond error_msg = + Data_encoding.( + conv_with_guard + (fun Q.{num; den} -> (num, den)) + (fun (num, den) -> + if Compare.Z.(den > Z.zero) && cond num den then Ok (Q.make num den) + else Error error_msg) + (obj2 (req "numerator" z) (req "denominator" z))) + +let positive_q_encoding = q_encoding (fun num _den -> Compare.Z.(num > Z.zero)) + +let non_negative_q_encoding = + q_encoding (fun num _den -> Compare.Z.(num >= Z.zero)) + +let between_zero_and_one_q_encoding = + q_encoding (fun num den -> Compare.Z.(num >= Z.zero && num <= den)) + type dal = { feature_enable : bool; incentives_enable : bool; @@ -355,48 +372,20 @@ let zk_rollup_encoding = (req "zk_rollup_max_ticket_payload_size" int31)) let extremum_encoding = - Data_encoding.( - conv_with_guard - (fun Q.{num; den} -> (num, den)) - (fun (num, den) -> - if Compare.Z.(num > Z.zero && den > Z.zero) then Ok (Q.make num den) - else - Error - "Invalid Reward Extremum Parameter: only positive values allowed") - (obj2 (req "numerator" z) (req "denominator" z))) + positive_q_encoding + "Invalid Reward Extremum Parameter: only positive values allowed" let center_encoding = - Data_encoding.( - conv_with_guard - (fun Q.{num; den} -> (num, den)) - (fun (num, den) -> - if Compare.Z.(num >= Z.zero && den > Z.zero && num <= den) then - Ok (Q.make num den) - else - Error - "Invalid Reward Parameter: dead zone center can only be between 0 \ - and 1") - (obj2 (req "numerator" z) (req "denominator" z))) + between_zero_and_one_q_encoding + "Invalid Reward Parameter: dead zone center can only be between 0 and 1" let radius_encoding = - Data_encoding.( - conv_with_guard - (fun Q.{num; den} -> (num, den)) - (fun (num, den) -> - if Compare.Z.(num >= Z.zero && den > Z.zero) then Ok (Q.make num den) - else - Error - "Invalid Reward Parameter: dead zone radius must be non-negative") - (obj2 (req "numerator" z) (req "denominator" z))) + non_negative_q_encoding + "Invalid Reward Parameter: dead zone radius must be non-negative" let growth_rate_encoding = - Data_encoding.( - conv_with_guard - (fun Q.{num; den} -> (num, den)) - (fun (num, den) -> - if Compare.Z.(num >= Z.zero && den > Z.zero) then Ok (Q.make num den) - else Error "Invalid Reward Parameter: growth rate must be non-negative") - (obj2 (req "numerator" z) (req "denominator" z))) + non_negative_q_encoding + "Invalid Reward Parameter: growth rate must be non-negative" let adaptive_rewards_params_encoding = let open Data_encoding in -- GitLab From 295d7796b5458e7acaec812823e204481cb14430 Mon Sep 17 00:00:00 2001 From: Eugen Zalinescu Date: Thu, 31 Oct 2024 12:06:01 +0100 Subject: [PATCH 2/7] Alpha: refactor Constants.generate --- .../lib_protocol/constants_repr.ml | 43 +++++++++++-------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/src/proto_alpha/lib_protocol/constants_repr.ml b/src/proto_alpha/lib_protocol/constants_repr.ml index ac692c1d79ff..2c863f218aa7 100644 --- a/src/proto_alpha/lib_protocol/constants_repr.ml +++ b/src/proto_alpha/lib_protocol/constants_repr.ml @@ -376,7 +376,7 @@ module Generated = struct let generate ~consensus_committee_size = (* The weights are expressed in [(256 * 80)]th of the total - reward, because it is the smallest proportion used so far*) + reward, because it is the smallest proportion used so far *) (* let f = consensus_committee_size / 3 in *) let max_slashing_threshold = (consensus_committee_size / 3) + 1 in let consensus_threshold = (consensus_committee_size * 2 / 3) + 1 in @@ -385,6 +385,25 @@ module Generated = struct let _reward_parts_whole = 20480 (* = 256 * 80 *) in let reward_parts_half = 10240 (* = reward_parts_whole / 2 *) in let reward_parts_quarter = 5120 (* = reward_parts_whole / 4 *) in + let baking_reward_fixed_portion_weight = + (* 1/4 or 1/2 *) + if Compare.Int.(bonus_committee_size <= 0) then + (* a fortiori, consensus_committee_size < 4 *) + reward_parts_half + else reward_parts_quarter + in + let baking_reward_bonus_weight = + (* 1/4 or 0 *) + if Compare.Int.(bonus_committee_size <= 0) then 0 + else reward_parts_quarter + in + let attesting_reward_weight = + (* 1/2 *) + reward_parts_half + in + (* All block (baking + attesting) rewards sum to 1 ( *256*80 ) *) + let seed_nonce_revelation_tip_weight = (* 1/20480 *) 1 in + let vdf_revelation_tip_weight = (* 1/20480 *) 1 in { max_slashing_threshold; consensus_threshold; @@ -392,23 +411,11 @@ module Generated = struct { base_total_issued_per_minute; (* 80.007812 tez/minute *) - baking_reward_fixed_portion_weight = - (* 1/4 or 1/2 *) - (if Compare.Int.(bonus_committee_size <= 0) then - (* a fortiori, consensus_committee_size < 4 *) - reward_parts_half - else reward_parts_quarter); - baking_reward_bonus_weight = - (* 1/4 or 0 *) - (if Compare.Int.(bonus_committee_size <= 0) then 0 - else reward_parts_quarter); - attesting_reward_weight = reward_parts_half; - (* 1/2 *) - (* All block (baking + attesting)rewards sum to 1 ( *256*80 ) *) - seed_nonce_revelation_tip_weight = 1; - (* 1/20480 *) - vdf_revelation_tip_weight = 1; - (* 1/20480 *) + baking_reward_fixed_portion_weight; + baking_reward_bonus_weight; + attesting_reward_weight; + seed_nonce_revelation_tip_weight; + vdf_revelation_tip_weight; }; } end -- GitLab From 331f10fd5adcce323a714747859666c96a836c2c Mon Sep 17 00:00:00 2001 From: Eugen Zalinescu Date: Wed, 25 Sep 2024 17:49:09 +0200 Subject: [PATCH 3/7] Alpha/DAL: add minimal_participation_ratio parameter --- .../lib_dal/dal_plugin_registration.ml | 1 + .../lib_parameters/default_parameters.ml | 12 +++++++++++ .../lib_protocol/alpha_context.mli | 1 + .../lib_protocol/constants_parametric_repr.ml | 20 +++++++++++++++---- .../constants_parametric_repr.mli | 3 +++ src/proto_alpha/lib_protocol/raw_context.ml | 3 +++ 6 files changed, 36 insertions(+), 4 deletions(-) diff --git a/src/proto_alpha/lib_dal/dal_plugin_registration.ml b/src/proto_alpha/lib_dal/dal_plugin_registration.ml index 3ad475ebfd5e..88d405564946 100644 --- a/src/proto_alpha/lib_dal/dal_plugin_registration.ml +++ b/src/proto_alpha/lib_dal/dal_plugin_registration.ml @@ -48,6 +48,7 @@ module Plugin = struct number_of_slots; attestation_lag; attestation_threshold; + minimal_participation_ratio = _; cryptobox_parameters; } = parametric.dal diff --git a/src/proto_alpha/lib_parameters/default_parameters.ml b/src/proto_alpha/lib_parameters/default_parameters.ml index 6689c08be0ef..1b14cbc65e45 100644 --- a/src/proto_alpha/lib_parameters/default_parameters.ml +++ b/src/proto_alpha/lib_parameters/default_parameters.ml @@ -145,6 +145,18 @@ let default_dal = attestation_lag = 8; attestation_threshold = 66; cryptobox_parameters = default_cryptobox_parameters; + minimal_participation_ratio = Q.(64 // 100); + (* Note that other values may make tests in tezt/tests/mockup.ml + fail. Indeed, some tests modify the constants' values a bit and then + perform some checks on the modified values. In case of [Q.t] values, + the numerator and the denominator are increased by 1. For instance, + when minimal_attestation_ratio is 60%, we have that the new value is + 2/3 = 4/6 = (3+1)/(5+1). However, the test fails because it does not + realize that 2/3 = 4/6... + That is why a value x of [minimal_participation_ratio] was chosen such + that we have x = a/b with a and b smallest such that they are relatively + prime, and (a+1, b+1) are relatively prime as well. The value x = 63% + works as well. *) } let constants_mainnet : Constants.Parametric.t = diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index de30bace905e..04341f9befb2 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -829,6 +829,7 @@ module Constants : sig attestation_lag : int; attestation_threshold : int; cryptobox_parameters : Dal.parameters; + minimal_participation_ratio : Q.t; } val dal_encoding : dal Data_encoding.t diff --git a/src/proto_alpha/lib_protocol/constants_parametric_repr.ml b/src/proto_alpha/lib_protocol/constants_parametric_repr.ml index e3b9b6b59db4..c849c31de82f 100644 --- a/src/proto_alpha/lib_protocol/constants_parametric_repr.ml +++ b/src/proto_alpha/lib_protocol/constants_parametric_repr.ml @@ -49,8 +49,13 @@ type dal = { attestation_lag : int; attestation_threshold : int; cryptobox_parameters : Dal.parameters; + minimal_participation_ratio : Q.t; } +let minimal_participation_ratio_encoding = + between_zero_and_one_q_encoding + "dal.minimal_participation_ratio must be a value between zero and one" + let dal_encoding = let open Data_encoding in conv @@ -61,18 +66,21 @@ let dal_encoding = attestation_lag; attestation_threshold; cryptobox_parameters; + minimal_participation_ratio; } -> ( ( feature_enable, incentives_enable, number_of_slots, attestation_lag, - attestation_threshold ), + attestation_threshold, + minimal_participation_ratio ), cryptobox_parameters )) (fun ( ( feature_enable, incentives_enable, number_of_slots, attestation_lag, - attestation_threshold ), + attestation_threshold, + minimal_participation_ratio ), cryptobox_parameters ) -> { feature_enable; @@ -81,14 +89,18 @@ let dal_encoding = attestation_lag; attestation_threshold; cryptobox_parameters; + minimal_participation_ratio; }) (merge_objs - (obj5 + (obj6 (req "feature_enable" bool) (req "incentives_enable" bool) (req "number_of_slots" uint16) (req "attestation_lag" uint8) - (req "attestation_threshold" uint8)) + (req "attestation_threshold" uint8) + (req + "minimal_participation_ratio" + minimal_participation_ratio_encoding)) Dal.parameters_encoding) (* The encoded representation of this type is stored in the context as diff --git a/src/proto_alpha/lib_protocol/constants_parametric_repr.mli b/src/proto_alpha/lib_protocol/constants_parametric_repr.mli index f771c958365f..38549ccefe13 100644 --- a/src/proto_alpha/lib_protocol/constants_parametric_repr.mli +++ b/src/proto_alpha/lib_protocol/constants_parametric_repr.mli @@ -33,6 +33,9 @@ type dal = { attestation_lag : int; attestation_threshold : int; cryptobox_parameters : Dal.parameters; + minimal_participation_ratio : Q.t; + (* the ratio of the protocol-attested slots that need to be attested by an + attester in order to receive rewards *) } val dal_encoding : dal Data_encoding.t diff --git a/src/proto_alpha/lib_protocol/raw_context.ml b/src/proto_alpha/lib_protocol/raw_context.ml index d70c90e86e78..af6cb425ed12 100644 --- a/src/proto_alpha/lib_protocol/raw_context.ml +++ b/src/proto_alpha/lib_protocol/raw_context.ml @@ -1003,6 +1003,7 @@ let prepare_first_block ~level ~timestamp chain_id ctxt = attestation_lag; attestation_threshold; cryptobox_parameters; + minimal_participation_ratio; } : Previous.dal) = c.dal @@ -1014,6 +1015,7 @@ let prepare_first_block ~level ~timestamp chain_id ctxt = attestation_lag; attestation_threshold; cryptobox_parameters; + minimal_participation_ratio; } in let reveal_activation_level = @@ -1303,6 +1305,7 @@ let prepare_first_block ~level ~timestamp chain_id ctxt = attestation_lag; attestation_threshold; cryptobox_parameters; + minimal_participation_ratio = Q.(64 // 100); } in let reveal_activation_level = -- GitLab From 898fb0edac34f0da413aed25f6806bb402e43582 Mon Sep 17 00:00:00 2001 From: Eugen Zalinescu Date: Wed, 30 Oct 2024 16:14:32 +0100 Subject: [PATCH 4/7] Alpha/DAL: add rewards_ratio DAL parameter --- .../lib_dal/dal_plugin_registration.ml | 1 + .../lib_parameters/default_parameters.ml | 1 + .../lib_protocol/alpha_context.mli | 1 + .../lib_protocol/constants_parametric_repr.ml | 22 +++++++++++++++---- .../constants_parametric_repr.mli | 1 + .../lib_protocol/constants_repr.ml | 14 ++++++++++++ src/proto_alpha/lib_protocol/raw_context.ml | 3 +++ 7 files changed, 39 insertions(+), 4 deletions(-) diff --git a/src/proto_alpha/lib_dal/dal_plugin_registration.ml b/src/proto_alpha/lib_dal/dal_plugin_registration.ml index 88d405564946..6dccd347025d 100644 --- a/src/proto_alpha/lib_dal/dal_plugin_registration.ml +++ b/src/proto_alpha/lib_dal/dal_plugin_registration.ml @@ -49,6 +49,7 @@ module Plugin = struct attestation_lag; attestation_threshold; minimal_participation_ratio = _; + rewards_ratio = _; cryptobox_parameters; } = parametric.dal diff --git a/src/proto_alpha/lib_parameters/default_parameters.ml b/src/proto_alpha/lib_parameters/default_parameters.ml index 1b14cbc65e45..bd6443cd01a9 100644 --- a/src/proto_alpha/lib_parameters/default_parameters.ml +++ b/src/proto_alpha/lib_parameters/default_parameters.ml @@ -157,6 +157,7 @@ let default_dal = that we have x = a/b with a and b smallest such that they are relatively prime, and (a+1, b+1) are relatively prime as well. The value x = 63% works as well. *) + rewards_ratio = Q.zero; } let constants_mainnet : Constants.Parametric.t = diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index 04341f9befb2..b459d1632ec8 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -830,6 +830,7 @@ module Constants : sig attestation_threshold : int; cryptobox_parameters : Dal.parameters; minimal_participation_ratio : Q.t; + rewards_ratio : Q.t; } val dal_encoding : dal Data_encoding.t diff --git a/src/proto_alpha/lib_protocol/constants_parametric_repr.ml b/src/proto_alpha/lib_protocol/constants_parametric_repr.ml index c849c31de82f..1d341c86bdcf 100644 --- a/src/proto_alpha/lib_protocol/constants_parametric_repr.ml +++ b/src/proto_alpha/lib_protocol/constants_parametric_repr.ml @@ -42,6 +42,9 @@ let non_negative_q_encoding = let between_zero_and_one_q_encoding = q_encoding (fun num den -> Compare.Z.(num >= Z.zero && num <= den)) +let between_zero_and_excluding_one_q_encoding = + q_encoding (fun num den -> Compare.Z.(num >= Z.zero && num < den)) + type dal = { feature_enable : bool; incentives_enable : bool; @@ -50,12 +53,18 @@ type dal = { attestation_threshold : int; cryptobox_parameters : Dal.parameters; minimal_participation_ratio : Q.t; + rewards_ratio : Q.t; } let minimal_participation_ratio_encoding = between_zero_and_one_q_encoding "dal.minimal_participation_ratio must be a value between zero and one" +let rewards_ratio_encoding = + between_zero_and_excluding_one_q_encoding + "dal.rewards_ratio must be a value between zero (inclusive) and one \ + (exclusive)" + let dal_encoding = let open Data_encoding in conv @@ -67,20 +76,23 @@ let dal_encoding = attestation_threshold; cryptobox_parameters; minimal_participation_ratio; + rewards_ratio; } -> ( ( feature_enable, incentives_enable, number_of_slots, attestation_lag, attestation_threshold, - minimal_participation_ratio ), + minimal_participation_ratio, + rewards_ratio ), cryptobox_parameters )) (fun ( ( feature_enable, incentives_enable, number_of_slots, attestation_lag, attestation_threshold, - minimal_participation_ratio ), + minimal_participation_ratio, + rewards_ratio ), cryptobox_parameters ) -> { feature_enable; @@ -90,9 +102,10 @@ let dal_encoding = attestation_threshold; cryptobox_parameters; minimal_participation_ratio; + rewards_ratio; }) (merge_objs - (obj6 + (obj7 (req "feature_enable" bool) (req "incentives_enable" bool) (req "number_of_slots" uint16) @@ -100,7 +113,8 @@ let dal_encoding = (req "attestation_threshold" uint8) (req "minimal_participation_ratio" - minimal_participation_ratio_encoding)) + minimal_participation_ratio_encoding) + (req "rewards_ratio" rewards_ratio_encoding)) Dal.parameters_encoding) (* The encoded representation of this type is stored in the context as diff --git a/src/proto_alpha/lib_protocol/constants_parametric_repr.mli b/src/proto_alpha/lib_protocol/constants_parametric_repr.mli index 38549ccefe13..01de35193f3c 100644 --- a/src/proto_alpha/lib_protocol/constants_parametric_repr.mli +++ b/src/proto_alpha/lib_protocol/constants_parametric_repr.mli @@ -36,6 +36,7 @@ type dal = { minimal_participation_ratio : Q.t; (* the ratio of the protocol-attested slots that need to be attested by an attester in order to receive rewards *) + rewards_ratio : Q.t; (* the ratio of DAL rewards versus total rewards *) } val dal_encoding : dal Data_encoding.t diff --git a/src/proto_alpha/lib_protocol/constants_repr.ml b/src/proto_alpha/lib_protocol/constants_repr.ml index 2c863f218aa7..db9b9e04c428 100644 --- a/src/proto_alpha/lib_protocol/constants_repr.ml +++ b/src/proto_alpha/lib_protocol/constants_repr.ml @@ -332,6 +332,20 @@ let check_constants constants = (Invalid_protocol_constants "The DAL committee must be a subset of the Tenderbake committee.") in + let* () = + error_when + (Q.(constants.dal.rewards_ratio > zero) + && not constants.dal.incentives_enable) + (Invalid_protocol_constants + "When DAL incentives are not enabled, the DAL rewards_ratio should be \ + zero.") + in + let* () = + error_unless + Q.(constants.dal.rewards_ratio < one) + (Invalid_protocol_constants + "The DAL rewards_ratio should be strictly less than one.") + in let* () = error_unless Compare.Int.( diff --git a/src/proto_alpha/lib_protocol/raw_context.ml b/src/proto_alpha/lib_protocol/raw_context.ml index af6cb425ed12..c3180beba902 100644 --- a/src/proto_alpha/lib_protocol/raw_context.ml +++ b/src/proto_alpha/lib_protocol/raw_context.ml @@ -1004,6 +1004,7 @@ let prepare_first_block ~level ~timestamp chain_id ctxt = attestation_threshold; cryptobox_parameters; minimal_participation_ratio; + rewards_ratio; } : Previous.dal) = c.dal @@ -1016,6 +1017,7 @@ let prepare_first_block ~level ~timestamp chain_id ctxt = attestation_threshold; cryptobox_parameters; minimal_participation_ratio; + rewards_ratio; } in let reveal_activation_level = @@ -1306,6 +1308,7 @@ let prepare_first_block ~level ~timestamp chain_id ctxt = attestation_threshold; cryptobox_parameters; minimal_participation_ratio = Q.(64 // 100); + rewards_ratio = Q.zero; } in let reveal_activation_level = -- GitLab From f75577d7783ce17033efc60f9f22e8e8377dd731 Mon Sep 17 00:00:00 2001 From: Eugen Zalinescu Date: Wed, 25 Sep 2024 16:41:45 +0200 Subject: [PATCH 5/7] Alpha/DAL: add dal_rewards_weight parameter --- .../lib_parameters/default_parameters.ml | 15 ++++++++++++--- src/proto_alpha/lib_protocol/alpha_context.mli | 3 ++- .../lib_protocol/constants_parametric_repr.ml | 14 ++++++++++---- .../lib_protocol/constants_parametric_repr.mli | 1 + src/proto_alpha/lib_protocol/constants_repr.ml | 18 ++++++++++++++++-- .../lib_protocol/constants_repr.mli | 2 +- .../lib_protocol/delegate_rewards.ml | 2 ++ src/proto_alpha/lib_protocol/raw_context.ml | 3 +++ .../test/helpers/scenario_begin.ml | 1 + .../test/integration/consensus/test_seed.ml | 1 + .../test/integration/operations/test_voting.ml | 1 + 11 files changed, 50 insertions(+), 11 deletions(-) diff --git a/src/proto_alpha/lib_parameters/default_parameters.ml b/src/proto_alpha/lib_parameters/default_parameters.ml index bd6443cd01a9..cfe318dded28 100644 --- a/src/proto_alpha/lib_parameters/default_parameters.ml +++ b/src/proto_alpha/lib_parameters/default_parameters.ml @@ -174,10 +174,13 @@ let constants_mainnet : Constants.Parametric.t = attesting_reward_weight; seed_nonce_revelation_tip_weight; vdf_revelation_tip_weight; + dal_rewards_weight; }; max_slashing_threshold; } = - Constants.Generated.generate ~consensus_committee_size + Constants.Generated.generate + ~consensus_committee_size + ~dal_rewards_ratio:default_dal.rewards_ratio in let dal_activation_level = if default_dal.feature_enable then Raw_level.succ Raw_level.root @@ -243,6 +246,8 @@ let constants_mainnet : Constants.Parametric.t = (* 1/20480 of block rewards *) vdf_revelation_tip_weight; (* 1/20480 of block rewards *) + dal_rewards_weight; + (* 0 for now *) }; hard_storage_limit_per_operation = Z.of_int 60_000; cost_per_byte = Tez.of_mutez_exn 250L; @@ -339,7 +344,9 @@ let constants_sandbox = let block_time = 1 in let Constants.Generated. {max_slashing_threshold; consensus_threshold = _; issuance_weights} = - Constants.Generated.generate ~consensus_committee_size + Constants.Generated.generate + ~consensus_committee_size + ~dal_rewards_ratio:default_dal.rewards_ratio in { constants_mainnet with @@ -374,7 +381,9 @@ let constants_test = let consensus_committee_size = 67 in let Constants.Generated. {max_slashing_threshold = _; consensus_threshold; issuance_weights} = - Constants.Generated.generate ~consensus_committee_size + Constants.Generated.generate + ~consensus_committee_size + ~dal_rewards_ratio:default_dal.rewards_ratio in { constants_mainnet with diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index b459d1632ec8..60ccef1fbe7c 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -900,6 +900,7 @@ module Constants : sig attesting_reward_weight : int; seed_nonce_revelation_tip_weight : int; vdf_revelation_tip_weight : int; + dal_rewards_weight : int; } type t = { @@ -969,7 +970,7 @@ module Constants : sig max_slashing_threshold : int; } - val generate : consensus_committee_size:int -> t + val generate : consensus_committee_size:int -> dal_rewards_ratio:Q.t -> t end val parametric : context -> Parametric.t diff --git a/src/proto_alpha/lib_protocol/constants_parametric_repr.ml b/src/proto_alpha/lib_protocol/constants_parametric_repr.ml index 1d341c86bdcf..32dad28bbc27 100644 --- a/src/proto_alpha/lib_protocol/constants_parametric_repr.ml +++ b/src/proto_alpha/lib_protocol/constants_parametric_repr.ml @@ -243,6 +243,7 @@ type issuance_weights = { attesting_reward_weight : int; seed_nonce_revelation_tip_weight : int; vdf_revelation_tip_weight : int; + dal_rewards_weight : int; } type t = { @@ -526,6 +527,7 @@ let issuance_weights_encoding = attesting_reward_weight; seed_nonce_revelation_tip_weight; vdf_revelation_tip_weight; + dal_rewards_weight; } : issuance_weights) -> ( base_total_issued_per_minute, @@ -533,13 +535,15 @@ let issuance_weights_encoding = baking_reward_bonus_weight, attesting_reward_weight, seed_nonce_revelation_tip_weight, - vdf_revelation_tip_weight )) + vdf_revelation_tip_weight, + dal_rewards_weight )) (fun ( base_total_issued_per_minute, baking_reward_fixed_portion_weight, baking_reward_bonus_weight, attesting_reward_weight, seed_nonce_revelation_tip_weight, - vdf_revelation_tip_weight ) -> + vdf_revelation_tip_weight, + dal_rewards_weight ) -> { base_total_issued_per_minute; baking_reward_fixed_portion_weight; @@ -547,14 +551,16 @@ let issuance_weights_encoding = attesting_reward_weight; seed_nonce_revelation_tip_weight; vdf_revelation_tip_weight; + dal_rewards_weight; }) - (obj6 + (obj7 (req "base_total_issued_per_minute" Tez_repr.encoding) (req "baking_reward_fixed_portion_weight" int31) (req "baking_reward_bonus_weight" int31) (req "attesting_reward_weight" int31) (req "seed_nonce_revelation_tip_weight" int31) - (req "vdf_revelation_tip_weight" int31)) + (req "vdf_revelation_tip_weight" int31) + (req "dal_rewards_weight" int31)) let encoding = let open Data_encoding in diff --git a/src/proto_alpha/lib_protocol/constants_parametric_repr.mli b/src/proto_alpha/lib_protocol/constants_parametric_repr.mli index 01de35193f3c..956f07659ca7 100644 --- a/src/proto_alpha/lib_protocol/constants_parametric_repr.mli +++ b/src/proto_alpha/lib_protocol/constants_parametric_repr.mli @@ -169,6 +169,7 @@ type issuance_weights = { attesting_reward_weight : int; seed_nonce_revelation_tip_weight : int; vdf_revelation_tip_weight : int; + dal_rewards_weight : int; } type t = { diff --git a/src/proto_alpha/lib_protocol/constants_repr.ml b/src/proto_alpha/lib_protocol/constants_repr.ml index db9b9e04c428..6107f0e2f57a 100644 --- a/src/proto_alpha/lib_protocol/constants_repr.ml +++ b/src/proto_alpha/lib_protocol/constants_repr.ml @@ -388,7 +388,7 @@ module Generated = struct max_slashing_threshold : int; } - let generate ~consensus_committee_size = + let generate ~consensus_committee_size ~dal_rewards_ratio = (* The weights are expressed in [(256 * 80)]th of the total reward, because it is the smallest proportion used so far *) (* let f = consensus_committee_size / 3 in *) @@ -396,7 +396,7 @@ module Generated = struct let consensus_threshold = (consensus_committee_size * 2 / 3) + 1 in let bonus_committee_size = consensus_committee_size - consensus_threshold in let base_total_issued_per_minute = Tez_repr.of_mutez_exn 80_007_812L in - let _reward_parts_whole = 20480 (* = 256 * 80 *) in + let reward_parts_whole = 20480 (* = 256 * 80 *) in let reward_parts_half = 10240 (* = reward_parts_whole / 2 *) in let reward_parts_quarter = 5120 (* = reward_parts_whole / 4 *) in let baking_reward_fixed_portion_weight = @@ -418,6 +418,19 @@ module Generated = struct (* All block (baking + attesting) rewards sum to 1 ( *256*80 ) *) let seed_nonce_revelation_tip_weight = (* 1/20480 *) 1 in let vdf_revelation_tip_weight = (* 1/20480 *) 1 in + let sum_non_dal_weights = + reward_parts_whole + seed_nonce_revelation_tip_weight + + vdf_revelation_tip_weight + in + (* Compute the weight of DAL rewards such that these represent + [dal_rewards_ratio] of the total rewards. *) + let dal_rewards_weight = + let open Q in + div + (mul (of_int sum_non_dal_weights) dal_rewards_ratio) + (sub one dal_rewards_ratio) + |> to_int + in { max_slashing_threshold; consensus_threshold; @@ -428,6 +441,7 @@ module Generated = struct baking_reward_fixed_portion_weight; baking_reward_bonus_weight; attesting_reward_weight; + dal_rewards_weight; seed_nonce_revelation_tip_weight; vdf_revelation_tip_weight; }; diff --git a/src/proto_alpha/lib_protocol/constants_repr.mli b/src/proto_alpha/lib_protocol/constants_repr.mli index 29e20a85e38f..a764bda26577 100644 --- a/src/proto_alpha/lib_protocol/constants_repr.mli +++ b/src/proto_alpha/lib_protocol/constants_repr.mli @@ -125,7 +125,7 @@ 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 -> t + val generate : consensus_committee_size:int -> dal_rewards_ratio:Q.t -> t end (** For each subcache, a size limit needs to be declared once. However, diff --git a/src/proto_alpha/lib_protocol/delegate_rewards.ml b/src/proto_alpha/lib_protocol/delegate_rewards.ml index 3d108c7e34df..67b19ee0e28a 100644 --- a/src/proto_alpha/lib_protocol/delegate_rewards.ml +++ b/src/proto_alpha/lib_protocol/delegate_rewards.ml @@ -32,6 +32,7 @@ let sum_weights attesting_reward_weight; seed_nonce_revelation_tip_weight; vdf_revelation_tip_weight; + dal_rewards_weight; } : Constants_parametric_repr.issuance_weights) = let r = baking_reward_fixed_portion_weight in @@ -39,6 +40,7 @@ let sum_weights let r = attesting_reward_weight + r in let r = seed_nonce_revelation_tip_weight + r in let r = vdf_revelation_tip_weight + r in + let r = dal_rewards_weight + r in assert (Compare.Int.(r > 0)) ; r diff --git a/src/proto_alpha/lib_protocol/raw_context.ml b/src/proto_alpha/lib_protocol/raw_context.ml index c3180beba902..3230d55952c9 100644 --- a/src/proto_alpha/lib_protocol/raw_context.ml +++ b/src/proto_alpha/lib_protocol/raw_context.ml @@ -1162,6 +1162,7 @@ let prepare_first_block ~level ~timestamp chain_id ctxt = attesting_reward_weight; seed_nonce_revelation_tip_weight; vdf_revelation_tip_weight; + dal_rewards_weight; } : Previous.issuance_weights) = c.issuance_weights @@ -1173,6 +1174,7 @@ let prepare_first_block ~level ~timestamp chain_id ctxt = attesting_reward_weight; seed_nonce_revelation_tip_weight; vdf_revelation_tip_weight; + dal_rewards_weight; } in let constants = @@ -1465,6 +1467,7 @@ let prepare_first_block ~level ~timestamp chain_id ctxt = attesting_reward_weight; seed_nonce_revelation_tip_weight; vdf_revelation_tip_weight; + dal_rewards_weight = 0; } in let constants = diff --git a/src/proto_alpha/lib_protocol/test/helpers/scenario_begin.ml b/src/proto_alpha/lib_protocol/test/helpers/scenario_begin.ml index fc832fb20219..99dadb0caf0c 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/scenario_begin.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/scenario_begin.ml @@ -104,6 +104,7 @@ let init_constants ?(default = Test) ?(reward_per_block = 0L) attesting_reward_weight = 0; seed_nonce_revelation_tip_weight = 0; vdf_revelation_tip_weight = 0; + dal_rewards_weight = 0; } --> set S.liquidity_baking_subsidy Tez.zero --> set S.minimal_block_delay Protocol.Alpha_context.Period.one_minute 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 9344f0dd2e59..80b9145f9a05 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 @@ -312,6 +312,7 @@ let test_unrevealed () = baking_reward_fixed_portion_weight = 0; seed_nonce_revelation_tip_weight = 0; vdf_revelation_tip_weight = 0; + dal_rewards_weight = 0; }; consensus_threshold = 0; minimal_participation_ratio = Ratio.{numerator = 0; denominator = 1}; diff --git a/src/proto_alpha/lib_protocol/test/integration/operations/test_voting.ml b/src/proto_alpha/lib_protocol/test/integration/operations/test_voting.ml index df31d2f3cb8c..a23fe5ffb8a4 100644 --- a/src/proto_alpha/lib_protocol/test/integration/operations/test_voting.ml +++ b/src/proto_alpha/lib_protocol/test/integration/operations/test_voting.ml @@ -279,6 +279,7 @@ let context_init_tup tup ?(blocks_per_cycle = 4l) = baking_reward_fixed_portion_weight = 1; seed_nonce_revelation_tip_weight = 1; vdf_revelation_tip_weight = 1; + dal_rewards_weight = 1; } ~nonce_revelation_threshold:2l -- GitLab From 511df0c97f581b379b8e389d648aba1af17bd65e Mon Sep 17 00:00:00 2001 From: Eugen Zalinescu Date: Wed, 30 Oct 2024 17:30:24 +0100 Subject: [PATCH 6/7] Tests/DAL: update regression outputs --- ...ient) RPC regression tests- misc_protocol.out | 16 ++++++++++------ ...ight) RPC regression tests- misc_protocol.out | 16 ++++++++++------ ...roxy) RPC regression tests- misc_protocol.out | 16 ++++++++++------ .../Alpha- weeklynet regression test.out | 16 ++++++++++------ 4 files changed, 40 insertions(+), 24 deletions(-) diff --git a/tezt/tests/expected/RPC_test.ml/Alpha- (mode client) RPC regression tests- misc_protocol.out b/tezt/tests/expected/RPC_test.ml/Alpha- (mode client) RPC regression tests- misc_protocol.out index 970ed0caadd9..da0e279e9c93 100644 --- a/tezt/tests/expected/RPC_test.ml/Alpha- (mode client) RPC regression tests- misc_protocol.out +++ b/tezt/tests/expected/RPC_test.ml/Alpha- (mode client) RPC regression tests- misc_protocol.out @@ -22,9 +22,10 @@ { "base_total_issued_per_minute": "80007812", "baking_reward_fixed_portion_weight": 5120, "baking_reward_bonus_weight": 5120, "attesting_reward_weight": 10240, - "seed_nonce_revelation_tip_weight": 1, "vdf_revelation_tip_weight": 1 }, - "cost_per_byte": "250", "hard_storage_limit_per_operation": "60000", - "quorum_min": 2000, "quorum_max": 7000, "min_proposal_quorum": 500, + "seed_nonce_revelation_tip_weight": 1, "vdf_revelation_tip_weight": 1, + "dal_rewards_weight": 0 }, "cost_per_byte": "250", + "hard_storage_limit_per_operation": "60000", "quorum_min": 2000, + "quorum_max": 7000, "min_proposal_quorum": 500, "liquidity_baking_subsidy": "5000000", "liquidity_baking_toggle_ema_threshold": 1000000000, "max_operations_time_to_live": 8, "minimal_block_delay": "1", @@ -40,9 +41,12 @@ "dal_parametric": { "feature_enable": true, "incentives_enable": false, "number_of_slots": 16, "attestation_lag": 8, - "attestation_threshold": 66, "redundancy_factor": 8, "page_size": 3967, - "slot_size": 126944, "number_of_shards": 256 }, - "smart_rollup_arith_pvm_enable": false, + "attestation_threshold": 66, + "minimal_participation_ratio": + { "numerator": "16", "denominator": "25" }, + "rewards_ratio": { "numerator": "0", "denominator": "1" }, + "redundancy_factor": 8, "page_size": 3967, "slot_size": 126944, + "number_of_shards": 256 }, "smart_rollup_arith_pvm_enable": false, "smart_rollup_origination_size": 6314, "smart_rollup_challenge_window_in_blocks": 151200, "smart_rollup_stake_amount": "10000000000", diff --git a/tezt/tests/expected/RPC_test.ml/Alpha- (mode light) RPC regression tests- misc_protocol.out b/tezt/tests/expected/RPC_test.ml/Alpha- (mode light) RPC regression tests- misc_protocol.out index 7f261bd69435..abb88f3b5829 100644 --- a/tezt/tests/expected/RPC_test.ml/Alpha- (mode light) RPC regression tests- misc_protocol.out +++ b/tezt/tests/expected/RPC_test.ml/Alpha- (mode light) RPC regression tests- misc_protocol.out @@ -22,9 +22,10 @@ { "base_total_issued_per_minute": "80007812", "baking_reward_fixed_portion_weight": 5120, "baking_reward_bonus_weight": 5120, "attesting_reward_weight": 10240, - "seed_nonce_revelation_tip_weight": 1, "vdf_revelation_tip_weight": 1 }, - "cost_per_byte": "250", "hard_storage_limit_per_operation": "60000", - "quorum_min": 2000, "quorum_max": 7000, "min_proposal_quorum": 500, + "seed_nonce_revelation_tip_weight": 1, "vdf_revelation_tip_weight": 1, + "dal_rewards_weight": 0 }, "cost_per_byte": "250", + "hard_storage_limit_per_operation": "60000", "quorum_min": 2000, + "quorum_max": 7000, "min_proposal_quorum": 500, "liquidity_baking_subsidy": "5000000", "liquidity_baking_toggle_ema_threshold": 1000000000, "max_operations_time_to_live": 8, "minimal_block_delay": "1", @@ -40,9 +41,12 @@ "dal_parametric": { "feature_enable": true, "incentives_enable": false, "number_of_slots": 16, "attestation_lag": 8, - "attestation_threshold": 66, "redundancy_factor": 8, "page_size": 3967, - "slot_size": 126944, "number_of_shards": 256 }, - "smart_rollup_arith_pvm_enable": false, + "attestation_threshold": 66, + "minimal_participation_ratio": + { "numerator": "16", "denominator": "25" }, + "rewards_ratio": { "numerator": "0", "denominator": "1" }, + "redundancy_factor": 8, "page_size": 3967, "slot_size": 126944, + "number_of_shards": 256 }, "smart_rollup_arith_pvm_enable": false, "smart_rollup_origination_size": 6314, "smart_rollup_challenge_window_in_blocks": 151200, "smart_rollup_stake_amount": "10000000000", diff --git a/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy) RPC regression tests- misc_protocol.out b/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy) RPC regression tests- misc_protocol.out index 9885c93051ce..240d581287d7 100644 --- a/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy) RPC regression tests- misc_protocol.out +++ b/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy) RPC regression tests- misc_protocol.out @@ -22,9 +22,10 @@ { "base_total_issued_per_minute": "80007812", "baking_reward_fixed_portion_weight": 5120, "baking_reward_bonus_weight": 5120, "attesting_reward_weight": 10240, - "seed_nonce_revelation_tip_weight": 1, "vdf_revelation_tip_weight": 1 }, - "cost_per_byte": "250", "hard_storage_limit_per_operation": "60000", - "quorum_min": 2000, "quorum_max": 7000, "min_proposal_quorum": 500, + "seed_nonce_revelation_tip_weight": 1, "vdf_revelation_tip_weight": 1, + "dal_rewards_weight": 0 }, "cost_per_byte": "250", + "hard_storage_limit_per_operation": "60000", "quorum_min": 2000, + "quorum_max": 7000, "min_proposal_quorum": 500, "liquidity_baking_subsidy": "5000000", "liquidity_baking_toggle_ema_threshold": 1000000000, "max_operations_time_to_live": 8, "minimal_block_delay": "1", @@ -40,9 +41,12 @@ "dal_parametric": { "feature_enable": true, "incentives_enable": false, "number_of_slots": 16, "attestation_lag": 8, - "attestation_threshold": 66, "redundancy_factor": 8, "page_size": 3967, - "slot_size": 126944, "number_of_shards": 256 }, - "smart_rollup_arith_pvm_enable": false, + "attestation_threshold": 66, + "minimal_participation_ratio": + { "numerator": "16", "denominator": "25" }, + "rewards_ratio": { "numerator": "0", "denominator": "1" }, + "redundancy_factor": 8, "page_size": 3967, "slot_size": 126944, + "number_of_shards": 256 }, "smart_rollup_arith_pvm_enable": false, "smart_rollup_origination_size": 6314, "smart_rollup_challenge_window_in_blocks": 151200, "smart_rollup_stake_amount": "10000000000", diff --git a/tezt/tests/expected/protocol_migration.ml/Alpha- weeklynet regression test.out b/tezt/tests/expected/protocol_migration.ml/Alpha- weeklynet regression test.out index f982931035a9..acd11f96902b 100644 --- a/tezt/tests/expected/protocol_migration.ml/Alpha- weeklynet regression test.out +++ b/tezt/tests/expected/protocol_migration.ml/Alpha- weeklynet regression test.out @@ -12,9 +12,10 @@ { "base_total_issued_per_minute": "85007812", "baking_reward_fixed_portion_weight": 5120, "baking_reward_bonus_weight": 5120, "attesting_reward_weight": 10240, - "seed_nonce_revelation_tip_weight": 1, "vdf_revelation_tip_weight": 1 }, - "cost_per_byte": "250", "hard_storage_limit_per_operation": "60000", - "quorum_min": 2000, "quorum_max": 7000, "min_proposal_quorum": 500, + "seed_nonce_revelation_tip_weight": 1, "vdf_revelation_tip_weight": 1, + "dal_rewards_weight": 0 }, "cost_per_byte": "250", + "hard_storage_limit_per_operation": "60000", "quorum_min": 2000, + "quorum_max": 7000, "min_proposal_quorum": 500, "liquidity_baking_subsidy": "5000000", "liquidity_baking_toggle_ema_threshold": 100000, "max_operations_time_to_live": 188, "minimal_block_delay": "4", @@ -30,9 +31,12 @@ "dal_parametric": { "feature_enable": true, "incentives_enable": false, "number_of_slots": 32, "attestation_lag": 8, - "attestation_threshold": 66, "redundancy_factor": 8, "page_size": 3967, - "slot_size": 126944, "number_of_shards": 512 }, - "smart_rollup_arith_pvm_enable": true, + "attestation_threshold": 66, + "minimal_participation_ratio": + { "numerator": "16", "denominator": "25" }, + "rewards_ratio": { "numerator": "0", "denominator": "1" }, + "redundancy_factor": 8, "page_size": 3967, "slot_size": 126944, + "number_of_shards": 512 }, "smart_rollup_arith_pvm_enable": true, "smart_rollup_origination_size": 6314, "smart_rollup_challenge_window_in_blocks": 62, "smart_rollup_stake_amount": "32000000", -- GitLab From 3f4747b2bcc7d53a2d1da8c6ab17bba296ae620b Mon Sep 17 00:00:00 2001 From: Eugen Zalinescu Date: Wed, 30 Oct 2024 17:37:29 +0100 Subject: [PATCH 7/7] Kaitai: update struct files --- .../files/alpha__constants.ksy | 18 ++++++++++++++++++ .../files/alpha__constants__parametric.ksy | 18 ++++++++++++++++++ .../files/alpha__parameters.ksy | 18 ++++++++++++++++++ 3 files changed, 54 insertions(+) diff --git a/client-libs/kaitai-struct-files/files/alpha__constants.ksy b/client-libs/kaitai-struct-files/files/alpha__constants.ksy index 0806e89e8117..51950c14d577 100644 --- a/client-libs/kaitai-struct-files/files/alpha__constants.ksy +++ b/client-libs/kaitai-struct-files/files/alpha__constants.ksy @@ -49,6 +49,10 @@ types: type: u1 - id: attestation_threshold type: u1 + - id: minimal_participation_ratio + type: minimal_participation_ratio_0 + - id: rewards_ratio + type: rewards_ratio - id: redundancy_factor type: u1 - id: page_size @@ -108,12 +112,20 @@ types: type: int31 - id: vdf_revelation_tip_weight type: int31 + - id: dal_rewards_weight + type: int31 minimal_participation_ratio: seq: - id: numerator type: u2be - id: denominator type: u2be + minimal_participation_ratio_0: + seq: + - id: numerator + type: z + - id: denominator + type: z n: seq: - id: n @@ -149,6 +161,12 @@ types: type: z - id: denominator type: z + rewards_ratio: + seq: + - id: numerator + type: z + - id: denominator + type: z smart_rollup_reveal_activation_level: seq: - id: raw_data diff --git a/client-libs/kaitai-struct-files/files/alpha__constants__parametric.ksy b/client-libs/kaitai-struct-files/files/alpha__constants__parametric.ksy index f174aa9d43c1..16dc5cf7c15f 100644 --- a/client-libs/kaitai-struct-files/files/alpha__constants__parametric.ksy +++ b/client-libs/kaitai-struct-files/files/alpha__constants__parametric.ksy @@ -49,6 +49,10 @@ types: type: u1 - id: attestation_threshold type: u1 + - id: minimal_participation_ratio + type: minimal_participation_ratio_0 + - id: rewards_ratio + type: rewards_ratio - id: redundancy_factor type: u1 - id: page_size @@ -108,12 +112,20 @@ types: type: int31 - id: vdf_revelation_tip_weight type: int31 + - id: dal_rewards_weight + type: int31 minimal_participation_ratio: seq: - id: numerator type: u2be - id: denominator type: u2be + minimal_participation_ratio_0: + seq: + - id: numerator + type: z + - id: denominator + type: z n: seq: - id: n @@ -149,6 +161,12 @@ types: type: z - id: denominator type: z + rewards_ratio: + seq: + - id: numerator + type: z + - id: denominator + type: z smart_rollup_reveal_activation_level: seq: - id: raw_data diff --git a/client-libs/kaitai-struct-files/files/alpha__parameters.ksy b/client-libs/kaitai-struct-files/files/alpha__parameters.ksy index 7ede8f687102..6e3a8cd76b02 100644 --- a/client-libs/kaitai-struct-files/files/alpha__parameters.ksy +++ b/client-libs/kaitai-struct-files/files/alpha__parameters.ksy @@ -183,6 +183,10 @@ types: type: u1 - id: attestation_threshold type: u1 + - id: minimal_participation_ratio + type: minimal_participation_ratio_0 + - id: rewards_ratio + type: rewards_ratio - id: redundancy_factor type: u1 - id: page_size @@ -242,12 +246,20 @@ types: type: int31 - id: vdf_revelation_tip_weight type: int31 + - id: dal_rewards_weight + type: int31 minimal_participation_ratio: seq: - id: numerator type: u2be - id: denominator type: u2be + minimal_participation_ratio_0: + seq: + - id: numerator + type: z + - id: denominator + type: z n: seq: - id: n @@ -373,6 +385,12 @@ types: type: z - id: denominator type: z + rewards_ratio: + seq: + - id: numerator + type: z + - id: denominator + type: z smart_rollup_reveal_activation_level: seq: - id: raw_data -- GitLab