From 78de3d564beec7d400378d5f1c8962f0ab031887 Mon Sep 17 00:00:00 2001 From: Philippe Wang Date: Sun, 4 Jun 2023 21:56:17 -0700 Subject: [PATCH 1/2] Proto/AI: add storage init for EMA and feature flag --- .../lib_protocol/adaptive_inflation_storage.ml | 4 ++++ .../lib_protocol/adaptive_inflation_storage.mli | 16 ++++++++++++++++ src/proto_alpha/lib_protocol/init_storage.ml | 4 +++- src/proto_alpha/lib_protocol/storage.ml | 16 ++++++++++++++++ src/proto_alpha/lib_protocol/storage.mli | 14 ++++++++++++++ 5 files changed, 53 insertions(+), 1 deletion(-) diff --git a/src/proto_alpha/lib_protocol/adaptive_inflation_storage.ml b/src/proto_alpha/lib_protocol/adaptive_inflation_storage.ml index 13c913255d0b..a72ad9b43ddc 100644 --- a/src/proto_alpha/lib_protocol/adaptive_inflation_storage.ml +++ b/src/proto_alpha/lib_protocol/adaptive_inflation_storage.ml @@ -200,3 +200,7 @@ let update_stored_rewards_at_cycle_end ctxt ~new_cycle = let load_reward_coeff ctxt = load_reward_coeff ctxt ~cycle:(Raw_context.current_level ctxt).cycle + +let init_ema ctxt = Storage.Adaptive_inflation.Launch_ema.init ctxt 0L + +let activate ctxt ~cycle = Storage.Adaptive_inflation.Activation.init ctxt cycle diff --git a/src/proto_alpha/lib_protocol/adaptive_inflation_storage.mli b/src/proto_alpha/lib_protocol/adaptive_inflation_storage.mli index 0af8728cdfb4..898da8efcd34 100644 --- a/src/proto_alpha/lib_protocol/adaptive_inflation_storage.mli +++ b/src/proto_alpha/lib_protocol/adaptive_inflation_storage.mli @@ -38,3 +38,19 @@ val load_reward_coeff : Raw_context.t -> Raw_context.t tzresult Lwt.t access. *) val update_stored_rewards_at_cycle_end : Raw_context.t -> new_cycle:Cycle_repr.t -> Raw_context.t tzresult Lwt.t + +(** [init_ema ctxt] adds into the context an adaptive inflation vote EMA at 0 *) +val init_ema : Raw_context.t -> Raw_context.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. + + 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 diff --git a/src/proto_alpha/lib_protocol/init_storage.ml b/src/proto_alpha/lib_protocol/init_storage.ml index f9ce84c704c8..fbbee67e3ac0 100644 --- a/src/proto_alpha/lib_protocol/init_storage.ml +++ b/src/proto_alpha/lib_protocol/init_storage.ml @@ -249,6 +249,7 @@ let prepare_first_block _chain_id ctxt ~typecheck_smart_contract Storage.Pending_migration.Operation_results.init ctxt operation_results >>=? fun ctxt -> Sc_rollup_inbox_storage.init_inbox ~predecessor ctxt >>=? fun ctxt -> + Adaptive_inflation_storage.init_ema ctxt >>=? fun ctxt -> return ( ctxt, commitments_balance_updates @ bootstrap_balance_updates @@ -271,7 +272,8 @@ let prepare_first_block _chain_id ctxt ~typecheck_smart_contract initialize_total_supply_for_o ctxt >>= fun ctxt -> Remove_zero_amount_ticket_migration_for_o.remove_zero_ticket_entries ctxt >>= fun ctxt -> - migrate_liquidity_baking_ema ctxt >>=? fun ctxt -> return (ctxt, [])) + migrate_liquidity_baking_ema ctxt >>=? fun ctxt -> + Adaptive_inflation_storage.init_ema ctxt >>=? fun ctxt -> return (ctxt, [])) >>=? fun (ctxt, balance_updates) -> List.fold_left_es patch_script ctxt Legacy_script_patches.addresses_to_patch >>=? fun ctxt -> diff --git a/src/proto_alpha/lib_protocol/storage.ml b/src/proto_alpha/lib_protocol/storage.ml index 0e927688dba1..b83708463c71 100644 --- a/src/proto_alpha/lib_protocol/storage.ml +++ b/src/proto_alpha/lib_protocol/storage.ml @@ -1616,6 +1616,22 @@ module Liquidity_baking = struct end) end +module Adaptive_inflation = struct + module Launch_ema = + Make_single_data_storage (Registered) (Raw_context) + (struct + let name = ["adaptive_inflation_ema"] + end) + (Encoding.Int64) + + module Activation = + Make_single_data_storage (Registered) (Raw_context) + (struct + let name = ["adaptive_inflation_launch_cycle"] + end) + (Cycle_repr) +end + module Ticket_balance = struct module Name = struct let name = ["ticket_balance"] diff --git a/src/proto_alpha/lib_protocol/storage.mli b/src/proto_alpha/lib_protocol/storage.mli index d050121895fd..3e909bce87bb 100644 --- a/src/proto_alpha/lib_protocol/storage.mli +++ b/src/proto_alpha/lib_protocol/storage.mli @@ -702,6 +702,20 @@ module Liquidity_baking : sig and type value = Contract_hash.t end +module Adaptive_inflation : sig + (** Exponential moving average (ema) of votes set in the block header + protocol_data.contents. Once the feature is activated, it can no + longer be deactivated without a protocol amendment. **) + module Launch_ema : + Single_data_storage with type t := Raw_context.t and type value = Int64.t + + (** Cycle [c] at which adaptive inflation gets activated. **) + module Activation : + Single_data_storage + with type t := Raw_context.t + and type value = Cycle_repr.t +end + (** A map of [Script_repr.expr] values, indexed by their hash ([Script_expr_hash.t]). Values from this map can be incorporated by any contract via the primitive [Michelson_v1_primitives.H_constant]. *) -- GitLab From f9dfc5cb127c4234e99de8f366fac38739217214 Mon Sep 17 00:00:00 2001 From: Philippe Wang Date: Tue, 6 Jun 2023 14:03:51 -0700 Subject: [PATCH 2/2] Proto/tests: regenerate regression test --- .../expected/tickets.ml/Alpha- Send tickets in bigmap.out | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tezt/tests/expected/tickets.ml/Alpha- Send tickets in bigmap.out b/tezt/tests/expected/tickets.ml/Alpha- Send tickets in bigmap.out index 711a76eb0787..910ea285d6a4 100644 --- a/tezt/tests/expected/tickets.ml/Alpha- Send tickets in bigmap.out +++ b/tezt/tests/expected/tickets.ml/Alpha- Send tickets in bigmap.out @@ -137,7 +137,7 @@ Contract memorized as send_tickets_in_big_map. ./octez-client --mode mockup --wait none transfer 0 from bootstrap2 to '[CONTRACT_HASH]' --burn-cap 30 --storage-limit 1000000 --arg '"[CONTRACT_HASH]"' Node is bootstrapped. -Estimated gas: 98836.189 units (will add 100 for safety) +Estimated gas: 98836.657 units (will add 100 for safety) Estimated storage: 10767 bytes added (will add 20 for safety) Operation successfully injected in the node. Operation hash is '[OPERATION_HASH]' @@ -266,7 +266,7 @@ This sequence of operations was run: Set temp(1)[40] to (Pair 0x01b15c53925dc62a43681d4bdc4f24b31eeb31a49200 (Pair "BLUE" 1)) Storage size: 320 bytes Paid storage size diff: 67 bytes - Consumed gas: 49911.044 + Consumed gas: 49911.161 Balance updates: [PUBLIC_KEY_HASH] ... -ꜩ0.01675 storage fees ........................... +ꜩ0.01675 @@ -283,7 +283,7 @@ This sequence of operations was run: Copy temp(1) to map(5) Storage size: 10783 bytes Paid storage size diff: 10700 bytes - Consumed gas: 48926.177 + Consumed gas: 48926.528 Balance updates: [PUBLIC_KEY_HASH] ... -ꜩ2.675 storage fees ........................... +ꜩ2.675 -- GitLab