From 892e9dfaa41b2bcbcb8aeed1cb8e87fec2b9fb77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Cauderlier?= Date: Thu, 8 Jun 2023 16:52:25 +0200 Subject: [PATCH 1/2] Proto/Adaptive Inflation: expose launch cycle at the RPC level This commit adds a RPC to get the cycle at which Adaptive Inflation is set to activate. --- .../lib_protocol/adaptive_inflation_services.ml | 17 ++++++++++++++++- .../adaptive_inflation_services.mli | 3 +++ .../lib_protocol/adaptive_inflation_storage.ml | 2 ++ .../lib_protocol/adaptive_inflation_storage.mli | 14 ++++++++------ src/proto_alpha/lib_protocol/alpha_context.mli | 2 ++ 5 files changed, 31 insertions(+), 7 deletions(-) diff --git a/src/proto_alpha/lib_protocol/adaptive_inflation_services.ml b/src/proto_alpha/lib_protocol/adaptive_inflation_services.ml index 9ea2d75c5261..ae51999b4504 100644 --- a/src/proto_alpha/lib_protocol/adaptive_inflation_services.ml +++ b/src/proto_alpha/lib_protocol/adaptive_inflation_services.ml @@ -76,6 +76,16 @@ module S = struct ~query:RPC_query.empty ~output:Tez.encoding RPC_path.(path / "rewards_per_minute") + + let launch_cycle = + RPC_service.get_service + ~description: + "Returns the cycle at which the launch of the Adaptive Inflation \ + feature is set to happen. A result of None means that the feature is \ + not yet set to launch." + ~query:RPC_query.empty + ~output:(Data_encoding.option Cycle.encoding) + RPC_path.(context_path / "adaptive_inflation_launch_cycle") end let q_to_float_string q = @@ -127,7 +137,9 @@ let register () = current_yearly_rate_value ~formatter:(fun x -> x) ctxt) ; register0 ~chunked:false S.current_rewards_per_minute (fun ctxt () () -> let* f = current_rewards_per_minute ctxt in - return (Tez.of_mutez_exn (Q.to_int64 f))) + return (Tez.of_mutez_exn (Q.to_int64 f))) ; + register0 ~chunked:false S.launch_cycle (fun ctxt () () -> + Adaptive_inflation.launch_cycle ctxt) let total_supply ctxt block = RPC_context.make_call0 S.total_supply ctxt block () () @@ -143,3 +155,6 @@ let current_yearly_rate_exact ctxt block = let current_rewards_per_minute ctxt block = RPC_context.make_call0 S.current_rewards_per_minute ctxt block () () + +let launch_cycle ctxt block = + RPC_context.make_call0 S.launch_cycle ctxt block () () diff --git a/src/proto_alpha/lib_protocol/adaptive_inflation_services.mli b/src/proto_alpha/lib_protocol/adaptive_inflation_services.mli index 651aa92f8c31..bf9af6235016 100644 --- a/src/proto_alpha/lib_protocol/adaptive_inflation_services.mli +++ b/src/proto_alpha/lib_protocol/adaptive_inflation_services.mli @@ -39,4 +39,7 @@ val current_yearly_rate_exact : val current_rewards_per_minute : 'a #RPC_context.simple -> 'a -> Tez.t shell_tzresult Lwt.t +val launch_cycle : + 'a #RPC_context.simple -> 'a -> Cycle.t option shell_tzresult Lwt.t + val register : unit -> unit diff --git a/src/proto_alpha/lib_protocol/adaptive_inflation_storage.ml b/src/proto_alpha/lib_protocol/adaptive_inflation_storage.ml index ab2c1823fe61..0b6940d510ab 100644 --- a/src/proto_alpha/lib_protocol/adaptive_inflation_storage.ml +++ b/src/proto_alpha/lib_protocol/adaptive_inflation_storage.ml @@ -219,6 +219,8 @@ let update_ema ctxt ~vote = 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 6054df5c9482..2551ad0c88be 100644 --- a/src/proto_alpha/lib_protocol/adaptive_inflation_storage.mli +++ b/src/proto_alpha/lib_protocol/adaptive_inflation_storage.mli @@ -53,15 +53,17 @@ val update_ema : 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. - - In practice, it means that you may call - [Storage.Adaptive_inflation.Activation.find ctxt] to get the value - of the cycle at which the feature is activated, and if that call - returns [None], then it means the feature has not been - voted to be activated (yet). *) +*) 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. + + If this function returns [None], then it means the feature has not been + voted to be activated (yet). *) +val launch_cycle : Raw_context.t -> Cycle_repr.t option tzresult Lwt.t + module For_RPC : sig (** [get_reward_coeff ctxt cycle] reads the reward coeff for the given cycle from the storage. diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index 7e3390098e29..e6034415b832 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -4789,6 +4789,8 @@ module Adaptive_inflation : sig context -> vote:Toggle_votes.toggle_vote -> (context * Toggle_votes.Adaptive_inflation_launch_EMA.t) tzresult Lwt.t + + val launch_cycle : context -> Cycle.t option tzresult Lwt.t end (** This module re-exports definitions from {!Ticket_storage}. *) -- GitLab From f68deebcdf97e8b3a1125244cb78d3f8103f0c41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Cauderlier?= Date: Thu, 8 Jun 2023 21:35:22 +0200 Subject: [PATCH 2/2] Proto test helpers/AI: helper fun for new launch_cycle RPC --- src/proto_alpha/lib_protocol/test/helpers/context.ml | 3 +++ src/proto_alpha/lib_protocol/test/helpers/context.mli | 2 ++ 2 files changed, 5 insertions(+) diff --git a/src/proto_alpha/lib_protocol/test/helpers/context.ml b/src/proto_alpha/lib_protocol/test/helpers/context.ml index 888f979b8dcf..07d05906175a 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/context.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/context.ml @@ -241,6 +241,9 @@ let get_liquidity_baking_subsidy ctxt = let get_liquidity_baking_cpmm_address ctxt = Alpha_services.Liquidity_baking.get_cpmm_address rpc_ctxt ctxt +let get_adaptive_inflation_launch_cycle ctxt = + Adaptive_inflation_services.launch_cycle rpc_ctxt ctxt + let get_seed_nonce_revelation_tip ctxt = get_constants ctxt >>=? fun {Constants.parametric = csts; _} -> return diff --git a/src/proto_alpha/lib_protocol/test/helpers/context.mli b/src/proto_alpha/lib_protocol/test/helpers/context.mli index 5a787671ed65..bc011b463bb9 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/context.mli +++ b/src/proto_alpha/lib_protocol/test/helpers/context.mli @@ -108,6 +108,8 @@ val get_liquidity_baking_subsidy : t -> Tez.t tzresult Lwt.t val get_liquidity_baking_cpmm_address : t -> Contract_hash.t tzresult Lwt.t +val get_adaptive_inflation_launch_cycle : t -> Cycle.t option tzresult Lwt.t + val get_seed_nonce_revelation_tip : t -> Tez.t tzresult Lwt.t val get_vdf_revelation_tip : t -> Tez.t tzresult Lwt.t -- GitLab