diff --git a/src/proto_alpha/lib_parameters/default_parameters.ml b/src/proto_alpha/lib_parameters/default_parameters.ml index 545470e06e4044b433f634ef91ef9b9b53061a79..80b8a541f77fefd45b44110c862b89edc3e1742f 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/adaptive_inflation_storage.ml b/src/proto_alpha/lib_protocol/adaptive_inflation_storage.ml index 0b6940d510ab383178f39fb55bed9a6241918df0..6f0b3231ab06459de9711bdb974eaf382a9a5900 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 diff --git a/src/proto_alpha/lib_protocol/adaptive_inflation_storage.mli b/src/proto_alpha/lib_protocol/adaptive_inflation_storage.mli index 2551ad0c88bee7ff769d39932c541b0e48c0ac1d..cd57bf18aaeb91b373ab7ee22752d971fc6a8899 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. diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index 1bb9a3f539ff9b8447ef3fcd49adc0f76f650884..4ec828986a1bac6118345ec3d0a068a9c6790ff9 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 27e76de5c5e8fb26400d87c9b9ede1b49a5f2d58..f9e9dd33bf36bda40eb1b712c0d2c564112be407 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 620a025d7520103546850e83f22aa416d792f39a..04c8b5b47d2f28dd85926d486c1a468d70b20d31 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 39b7c4439d4a383c4134dec39a1879b6f484184b..87df7d47928eff0471480bfb1d0293080e3dabbd 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 0c5204a09ee383eca842d13b26279c1fba191cf9..e74570d6468916c4dd5f41243451b61909c396fb 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 84ba6d37a825167bf62a9b9d8b764a74188a3d43..a6672ffe1ac60dec7b7fa5a59100eabeca2e440b 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 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 b1f8e8278ba3c97a9d6c2a93b5b886988d8f1e49..f871f256776ce35d7ec367112dc7d0567c2532cc 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 bfe7e0088d6f338955fffc50ba3f758bee99e201..e78ae19711bc121241ac7d6dbf819fd3fc752d26 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 8ea4205178e9d442ea2b68f1192bbdcd60176440..0fc0ccbd2b9d48437e41bbc1c1e3dd139608f0df 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 52f185b881774b218729e98adb310e333d3aa794..ce9a02becea58f53aeab369d2d1cca5dcfb63d45 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 52f185b881774b218729e98adb310e333d3aa794..ce9a02becea58f53aeab369d2d1cca5dcfb63d45 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]",