From a92c7e0bac8653049e48535afb1402b4eb49d6a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Cauderlier?= Date: Thu, 8 Jun 2023 23:51:48 +0200 Subject: [PATCH 1/4] Proto/AI: add a constant for the threshold of the activation vote --- .../lib_parameters/default_parameters.ml | 1 + src/proto_alpha/lib_protocol/alpha_context.mli | 1 + .../lib_protocol/constants_parametric_repr.ml | 14 ++++++++++---- .../lib_protocol/constants_parametric_repr.mli | 1 + src/proto_alpha/lib_protocol/constants_storage.ml | 3 +++ src/proto_alpha/lib_protocol/constants_storage.mli | 2 ++ src/proto_alpha/lib_protocol/raw_context.ml | 2 ++ 7 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/proto_alpha/lib_parameters/default_parameters.ml b/src/proto_alpha/lib_parameters/default_parameters.ml index 545470e06e40..80b8a541f77f 100644 --- a/src/proto_alpha/lib_parameters/default_parameters.ml +++ b/src/proto_alpha/lib_parameters/default_parameters.ml @@ -293,6 +293,7 @@ let constants_mainnet = staking_over_baking_limit = 5; max_costaking_baker_count = 5; staking_over_delegation_edge = 2; + launch_ema_threshold = 1_600_000_000L; }; } diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index 1bb9a3f539ff..4ec828986a1b 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -847,6 +847,7 @@ module Constants : sig staking_over_baking_limit : int; max_costaking_baker_count : int; staking_over_delegation_edge : int; + launch_ema_threshold : int64; } type reward_weights = { diff --git a/src/proto_alpha/lib_protocol/constants_parametric_repr.ml b/src/proto_alpha/lib_protocol/constants_parametric_repr.ml index 27e76de5c5e8..f9e9dd33bf36 100644 --- a/src/proto_alpha/lib_protocol/constants_parametric_repr.ml +++ b/src/proto_alpha/lib_protocol/constants_parametric_repr.ml @@ -128,6 +128,7 @@ type adaptive_inflation = { staking_over_baking_limit : int; max_costaking_baker_count : int; staking_over_delegation_edge : int; + launch_ema_threshold : int64; } type reward_weights = { @@ -344,26 +345,31 @@ let adaptive_inflation_encoding = staking_over_baking_limit; max_costaking_baker_count; staking_over_delegation_edge; + launch_ema_threshold; } -> ( enable, staking_over_baking_limit, max_costaking_baker_count, - staking_over_delegation_edge )) + staking_over_delegation_edge, + launch_ema_threshold )) (fun ( adaptive_inflation_enable, staking_over_baking_limit, max_costaking_baker_count, - staking_over_delegation_edge ) -> + staking_over_delegation_edge, + launch_ema_threshold ) -> { enable = adaptive_inflation_enable; staking_over_baking_limit; max_costaking_baker_count; staking_over_delegation_edge; + launch_ema_threshold; }) - (obj4 + (obj5 (req "adaptive_inflation_enable" bool) (req "staking_over_baking_limit" uint8) (req "max_costaking_baker_count" uint16) - (req "staking_over_delegation_edge" uint8)) + (req "staking_over_delegation_edge" uint8) + (req "adaptive_inflation_launch_ema_threshold" int64)) let reward_weights_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 620a025d7520..04c8b5b47d2f 100644 --- a/src/proto_alpha/lib_protocol/constants_parametric_repr.mli +++ b/src/proto_alpha/lib_protocol/constants_parametric_repr.mli @@ -146,6 +146,7 @@ type adaptive_inflation = { max_costaking_baker_count : (* Maximal number of bakers an account can costake to. *) int; staking_over_delegation_edge : (* Weight of staking over delegation. *) int; + launch_ema_threshold : (* Threshold of the activation vote *) int64; } type reward_weights = { diff --git a/src/proto_alpha/lib_protocol/constants_storage.ml b/src/proto_alpha/lib_protocol/constants_storage.ml index 39b7c4439d4a..87df7d47928e 100644 --- a/src/proto_alpha/lib_protocol/constants_storage.ml +++ b/src/proto_alpha/lib_protocol/constants_storage.ml @@ -288,4 +288,7 @@ let adaptive_inflation_staking_over_baking_limit c = let adaptive_inflation_staking_over_delegation_edge c = (adaptive_inflation c).staking_over_delegation_edge +let adaptive_inflation_launch_ema_threshold c = + (adaptive_inflation c).launch_ema_threshold + let freeze_rewards = adaptive_inflation_enable diff --git a/src/proto_alpha/lib_protocol/constants_storage.mli b/src/proto_alpha/lib_protocol/constants_storage.mli index 0c5204a09ee3..e74570d64689 100644 --- a/src/proto_alpha/lib_protocol/constants_storage.mli +++ b/src/proto_alpha/lib_protocol/constants_storage.mli @@ -168,4 +168,6 @@ val adaptive_inflation_staking_over_baking_limit : Raw_context.t -> int val adaptive_inflation_staking_over_delegation_edge : Raw_context.t -> int +val adaptive_inflation_launch_ema_threshold : Raw_context.t -> int64 + val freeze_rewards : Raw_context.t -> bool diff --git a/src/proto_alpha/lib_protocol/raw_context.ml b/src/proto_alpha/lib_protocol/raw_context.ml index 84ba6d37a825..a6672ffe1ac6 100644 --- a/src/proto_alpha/lib_protocol/raw_context.ml +++ b/src/proto_alpha/lib_protocol/raw_context.ml @@ -999,6 +999,8 @@ let prepare_first_block ~level ~timestamp ctxt = staking_over_baking_limit = 5; max_costaking_baker_count = 5; staking_over_delegation_edge = 2; + launch_ema_threshold = + (* 80% of the max ema (which is 2 billion) *) 1_600_000_000L; } in -- GitLab From a5febf337af7a4a306364a6d982d43ea9d05661b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Cauderlier?= Date: Thu, 8 Jun 2023 23:53:02 +0200 Subject: [PATCH 2/4] Proto/AI/activation vote: threshold check --- .../adaptive_inflation_storage.ml | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/proto_alpha/lib_protocol/adaptive_inflation_storage.ml b/src/proto_alpha/lib_protocol/adaptive_inflation_storage.ml index 0b6940d510ab..6f0b3231ab06 100644 --- a/src/proto_alpha/lib_protocol/adaptive_inflation_storage.ml +++ b/src/proto_alpha/lib_protocol/adaptive_inflation_storage.ml @@ -203,6 +203,10 @@ let load_reward_coeff ctxt = let init_ema ctxt = Storage.Adaptive_inflation.Launch_ema.init ctxt 0L +let activate ctxt ~cycle = Storage.Adaptive_inflation.Activation.init ctxt cycle + +let launch_cycle ctxt = Storage.Adaptive_inflation.Activation.find ctxt + let update_ema ctxt ~vote = Storage.Adaptive_inflation.Launch_ema.get ctxt >>=? fun old_ema -> Toggle_votes_repr.Adaptive_inflation_launch_EMA.of_int64 old_ema @@ -215,12 +219,24 @@ let update_ema ctxt ~vote = Storage.Adaptive_inflation.Launch_ema.update ctxt (Toggle_votes_repr.Adaptive_inflation_launch_EMA.to_int64 new_ema) + >>=? fun ctxt -> + let open Constants_storage in + (if + Toggle_votes_repr.Adaptive_inflation_launch_EMA.( + new_ema < adaptive_inflation_launch_ema_threshold ctxt) + then return ctxt + else + launch_cycle ctxt >>=? function + | Some _ -> + (* the feature is already set to launch, do nothing to avoid postponing it. *) + return ctxt + | None -> + (* set the feature to activate in a few cycles *) + let current_cycle = (Level_storage.current ctxt).cycle in + let delay = 1 + preserved_cycles ctxt + max_slashing_period ctxt in + activate ctxt ~cycle:(Cycle_repr.add current_cycle delay)) >|=? fun ctxt -> (ctxt, new_ema) -let activate ctxt ~cycle = Storage.Adaptive_inflation.Activation.init ctxt cycle - -let launch_cycle ctxt = Storage.Adaptive_inflation.Activation.find ctxt - module For_RPC = struct let get_reward_coeff = get_reward_coeff end -- GitLab From ce767389db69510e97f16c8eace56385012bf1f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Cauderlier?= Date: Thu, 8 Jun 2023 23:57:10 +0200 Subject: [PATCH 3/4] Proto/AI: do not export the activate function The Adaptive_inflation module is now responsible for activating the feature so we do not need to expose the activation function. --- .../lib_protocol/adaptive_inflation_storage.mli | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/proto_alpha/lib_protocol/adaptive_inflation_storage.mli b/src/proto_alpha/lib_protocol/adaptive_inflation_storage.mli index 2551ad0c88be..cd57bf18aaeb 100644 --- a/src/proto_alpha/lib_protocol/adaptive_inflation_storage.mli +++ b/src/proto_alpha/lib_protocol/adaptive_inflation_storage.mli @@ -49,14 +49,6 @@ val update_ema : (Raw_context.t * Toggle_votes_repr.Adaptive_inflation_launch_EMA.t) tzresult Lwt.t -(** [activate ctxt ~cycle] adds into the context the cycle at which - the adaptive inflation feature gets activated. If this function is - never called, then the context does not contain the cycle for the - feature activation, which implies the feature is inactive. -*) -val activate : - Raw_context.t -> cycle:Cycle_repr.t -> Raw_context.t tzresult Lwt.t - (** [launch_cycle ctxt] reads from the context the cycle at which the adaptive inflation feature is set to activate. -- GitLab From cefc39eee97ecdc2944a6d527c56452e48b65751 Mon Sep 17 00:00:00 2001 From: Philippe Wang Date: Fri, 9 Jun 2023 12:01:02 -0700 Subject: [PATCH 4/4] Proto: update outputs for regression tests --- ...lpha- (mode client) RPC regression tests- misc_protocol.out | 3 ++- ...Alpha- (mode light) RPC regression tests- misc_protocol.out | 3 ++- ...Alpha- (mode proxy) RPC regression tests- misc_protocol.out | 3 ++- ...xy_server_data_dir) RPC regression tests- misc_protocol.out | 3 ++- ...e proxy_server_rpc) RPC regression tests- misc_protocol.out | 3 ++- 5 files changed, 10 insertions(+), 5 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 b1f8e8278ba3..f871f256776c 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 @@ -66,7 +66,8 @@ "smart_rollup_max_number_of_parallel_games": 32, "zk_rollup_enable": false, "zk_rollup_origination_size": 4000, "zk_rollup_min_pending_to_process": 10, "adaptive_inflation_enable": false, "staking_over_baking_limit": 5, - "max_costaking_baker_count": 5, "staking_over_delegation_edge": 2 } + "max_costaking_baker_count": 5, "staking_over_delegation_edge": 2, + "adaptive_inflation_launch_ema_threshold": "1600000000" } ./octez-client rpc get /chains/main/blocks/head/helpers/baking_rights [ { "level": 2, "delegate": "[PUBLIC_KEY_HASH]", 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 bfe7e0088d6f..e78ae19711bc 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 @@ -66,7 +66,8 @@ "smart_rollup_max_number_of_parallel_games": 32, "zk_rollup_enable": false, "zk_rollup_origination_size": 4000, "zk_rollup_min_pending_to_process": 10, "adaptive_inflation_enable": false, "staking_over_baking_limit": 5, - "max_costaking_baker_count": 5, "staking_over_delegation_edge": 2 } + "max_costaking_baker_count": 5, "staking_over_delegation_edge": 2, + "adaptive_inflation_launch_ema_threshold": "1600000000" } ./octez-client --mode light rpc get /chains/main/blocks/head/helpers/baking_rights [ { "level": 2, "delegate": "[PUBLIC_KEY_HASH]", 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 8ea4205178e9..0fc0ccbd2b9d 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 @@ -66,7 +66,8 @@ "smart_rollup_max_number_of_parallel_games": 32, "zk_rollup_enable": false, "zk_rollup_origination_size": 4000, "zk_rollup_min_pending_to_process": 10, "adaptive_inflation_enable": false, "staking_over_baking_limit": 5, - "max_costaking_baker_count": 5, "staking_over_delegation_edge": 2 } + "max_costaking_baker_count": 5, "staking_over_delegation_edge": 2, + "adaptive_inflation_launch_ema_threshold": "1600000000" } ./octez-client --mode proxy rpc get /chains/main/blocks/head/helpers/baking_rights [ { "level": 2, "delegate": "[PUBLIC_KEY_HASH]", diff --git a/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy_server_data_dir) RPC regression tests- misc_protocol.out b/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy_server_data_dir) RPC regression tests- misc_protocol.out index 52f185b88177..ce9a02becea5 100644 --- a/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy_server_data_dir) RPC regression tests- misc_protocol.out +++ b/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy_server_data_dir) RPC regression tests- misc_protocol.out @@ -66,7 +66,8 @@ "smart_rollup_max_number_of_parallel_games": 32, "zk_rollup_enable": false, "zk_rollup_origination_size": 4000, "zk_rollup_min_pending_to_process": 10, "adaptive_inflation_enable": false, "staking_over_baking_limit": 5, - "max_costaking_baker_count": 5, "staking_over_delegation_edge": 2 } + "max_costaking_baker_count": 5, "staking_over_delegation_edge": 2, + "adaptive_inflation_launch_ema_threshold": "1600000000" } ./octez-client rpc get /chains/main/blocks/head/helpers/baking_rights [ { "level": 3, "delegate": "[PUBLIC_KEY_HASH]", diff --git a/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy_server_rpc) RPC regression tests- misc_protocol.out b/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy_server_rpc) RPC regression tests- misc_protocol.out index 52f185b88177..ce9a02becea5 100644 --- a/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy_server_rpc) RPC regression tests- misc_protocol.out +++ b/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy_server_rpc) RPC regression tests- misc_protocol.out @@ -66,7 +66,8 @@ "smart_rollup_max_number_of_parallel_games": 32, "zk_rollup_enable": false, "zk_rollup_origination_size": 4000, "zk_rollup_min_pending_to_process": 10, "adaptive_inflation_enable": false, "staking_over_baking_limit": 5, - "max_costaking_baker_count": 5, "staking_over_delegation_edge": 2 } + "max_costaking_baker_count": 5, "staking_over_delegation_edge": 2, + "adaptive_inflation_launch_ema_threshold": "1600000000" } ./octez-client rpc get /chains/main/blocks/head/helpers/baking_rights [ { "level": 3, "delegate": "[PUBLIC_KEY_HASH]", -- GitLab