From b0bcb9db6cef01c4398287280de4406b50e9cb18 Mon Sep 17 00:00:00 2001 From: Philippe Wang Date: Tue, 27 Jun 2023 10:43:31 -0700 Subject: [PATCH 1/6] Proto: rename Toggle_votes_repr to Per_block_votes_repr --- .../test/mockup_simulator/mockup_simulator.ml | 2 +- src/proto_alpha/lib_protocol/TEZOS_PROTOCOL | 2 +- .../lib_protocol/adaptive_inflation_storage.ml | 8 ++++---- .../lib_protocol/adaptive_inflation_storage.mli | 4 ++-- src/proto_alpha/lib_protocol/alpha_context.ml | 2 +- src/proto_alpha/lib_protocol/alpha_context.mli | 8 ++++---- src/proto_alpha/lib_protocol/block_header_repr.ml | 8 ++++---- src/proto_alpha/lib_protocol/block_header_repr.mli | 2 +- src/proto_alpha/lib_protocol/dune | 8 ++++---- .../lib_protocol/liquidity_baking_storage.ml | 2 +- .../lib_protocol/liquidity_baking_storage.mli | 4 ++-- ...{toggle_votes_repr.ml => per_block_votes_repr.ml} | 0 ...oggle_votes_repr.mli => per_block_votes_repr.mli} | 0 src/proto_alpha/lib_protocol/test/helpers/block.mli | 12 ++++++------ .../test/unit/test_adaptive_inflation_ema.ml | 12 ++++++------ .../test/unit/test_liquidity_baking_repr.ml | 10 +++++----- 16 files changed, 42 insertions(+), 42 deletions(-) rename src/proto_alpha/lib_protocol/{toggle_votes_repr.ml => per_block_votes_repr.ml} (100%) rename src/proto_alpha/lib_protocol/{toggle_votes_repr.mli => per_block_votes_repr.mli} (100%) diff --git a/src/proto_alpha/lib_delegate/test/mockup_simulator/mockup_simulator.ml b/src/proto_alpha/lib_delegate/test/mockup_simulator/mockup_simulator.ml index 0fe62d4c5fef..b80d30e8090e 100644 --- a/src/proto_alpha/lib_delegate/test/mockup_simulator/mockup_simulator.ml +++ b/src/proto_alpha/lib_delegate/test/mockup_simulator/mockup_simulator.ml @@ -931,7 +931,7 @@ let genesis_protocol_data (baker_sk : Signature.secret_key) in let toggle_votes = { - Protocol.Toggle_votes_repr.liquidity_baking_vote = + Protocol.Per_block_votes_repr.liquidity_baking_vote = Baking_configuration.default_votes_config .Baking_configuration.liquidity_baking_vote; adaptive_inflation_vote = diff --git a/src/proto_alpha/lib_protocol/TEZOS_PROTOCOL b/src/proto_alpha/lib_protocol/TEZOS_PROTOCOL index 2a14aee0769c..00918789fa8a 100644 --- a/src/proto_alpha/lib_protocol/TEZOS_PROTOCOL +++ b/src/proto_alpha/lib_protocol/TEZOS_PROTOCOL @@ -92,7 +92,7 @@ "Bond_id_repr", "Vote_repr", "Toggle_EMA", - "Toggle_votes_repr", + "Per_block_votes_repr", "Block_header_repr", "Destination_repr", "Script_int", diff --git a/src/proto_alpha/lib_protocol/adaptive_inflation_storage.ml b/src/proto_alpha/lib_protocol/adaptive_inflation_storage.ml index 0badec280cea..eabf304cc3c3 100644 --- a/src/proto_alpha/lib_protocol/adaptive_inflation_storage.ml +++ b/src/proto_alpha/lib_protocol/adaptive_inflation_storage.ml @@ -287,21 +287,21 @@ let set_adaptive_inflation_enable ctxt = let update_ema ctxt ~vote = Storage.Adaptive_inflation.Launch_ema.get ctxt >>=? fun old_ema -> - Toggle_votes_repr.Adaptive_inflation_launch_EMA.of_int32 old_ema + Per_block_votes_repr.Adaptive_inflation_launch_EMA.of_int32 old_ema >>=? fun old_ema -> let new_ema = - Toggle_votes_repr.compute_new_adaptive_inflation_ema + Per_block_votes_repr.compute_new_adaptive_inflation_ema ~toggle_vote:vote old_ema in Storage.Adaptive_inflation.Launch_ema.update ctxt - (Toggle_votes_repr.Adaptive_inflation_launch_EMA.to_int32 new_ema) + (Per_block_votes_repr.Adaptive_inflation_launch_EMA.to_int32 new_ema) >>=? fun ctxt -> launch_cycle ctxt >>=? fun launch_cycle -> let open Constants_storage in (if - Toggle_votes_repr.Adaptive_inflation_launch_EMA.( + Per_block_votes_repr.Adaptive_inflation_launch_EMA.( new_ema < adaptive_inflation_launch_ema_threshold ctxt) then return (ctxt, launch_cycle) else diff --git a/src/proto_alpha/lib_protocol/adaptive_inflation_storage.mli b/src/proto_alpha/lib_protocol/adaptive_inflation_storage.mli index 51f7b50f6706..00dccdb23192 100644 --- a/src/proto_alpha/lib_protocol/adaptive_inflation_storage.mli +++ b/src/proto_alpha/lib_protocol/adaptive_inflation_storage.mli @@ -54,10 +54,10 @@ val init : Raw_context.t -> Raw_context.t tzresult Lwt.t (** [update_ema ctxt ~vote] returns the new context with the new EMA *) val update_ema : Raw_context.t -> - vote:Toggle_votes_repr.toggle_vote -> + vote:Per_block_votes_repr.toggle_vote -> (Raw_context.t * Cycle_repr.t option - * Toggle_votes_repr.Adaptive_inflation_launch_EMA.t) + * Per_block_votes_repr.Adaptive_inflation_launch_EMA.t) tzresult Lwt.t diff --git a/src/proto_alpha/lib_protocol/alpha_context.ml b/src/proto_alpha/lib_protocol/alpha_context.ml index b71721791990..e6ffe8f6d44d 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.ml +++ b/src/proto_alpha/lib_protocol/alpha_context.ml @@ -613,7 +613,7 @@ let description = Raw_context.description module Parameters = Parameters_repr module Toggle_EMA = Toggle_EMA -module Toggle_votes = Toggle_votes_repr +module Toggle_votes = Per_block_votes_repr module Liquidity_baking = struct include Liquidity_baking_storage diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index acbfba6d960a..2f6ead6bc8d3 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -3848,7 +3848,7 @@ module Block_header : sig payload_round : Round.t; seed_nonce_hash : Nonce_hash.t option; proof_of_work_nonce : bytes; - toggle_votes : Toggle_votes_repr.toggle_votes; + toggle_votes : Per_block_votes_repr.toggle_votes; } type protocol_data = {contents : contents; signature : signature} @@ -4731,14 +4731,14 @@ module Toggle_EMA : sig end end -(** This module re-exports definitions from {!Toggle_votes_repr}. *) +(** This module re-exports definitions from {!Per_block_votes_repr}. *) module Toggle_votes : sig - type toggle_vote = Toggle_votes_repr.toggle_vote = + type toggle_vote = Per_block_votes_repr.toggle_vote = | Toggle_vote_on | Toggle_vote_off | Toggle_vote_pass - type toggle_votes = Toggle_votes_repr.toggle_votes = { + type toggle_votes = Per_block_votes_repr.toggle_votes = { liquidity_baking_vote : toggle_vote; adaptive_inflation_vote : toggle_vote; } diff --git a/src/proto_alpha/lib_protocol/block_header_repr.ml b/src/proto_alpha/lib_protocol/block_header_repr.ml index 2ea1b609df0f..a4e9b7ef65f1 100644 --- a/src/proto_alpha/lib_protocol/block_header_repr.ml +++ b/src/proto_alpha/lib_protocol/block_header_repr.ml @@ -30,7 +30,7 @@ type contents = { payload_round : Round_repr.t; seed_nonce_hash : Nonce_hash.t option; proof_of_work_nonce : bytes; - toggle_votes : Toggle_votes_repr.toggle_votes; + toggle_votes : Per_block_votes_repr.toggle_votes; } type protocol_data = {contents : contents; signature : Signature.t} @@ -106,10 +106,10 @@ let contents_encoding = (opt "seed_nonce_hash" Nonce_hash.encoding) (req "liquidity_baking_toggle_vote" - Toggle_votes_repr.liquidity_baking_vote_encoding) + Per_block_votes_repr.liquidity_baking_vote_encoding) (req "adaptive_inflation_vote" - Toggle_votes_repr.adaptive_inflation_vote_encoding)) + Per_block_votes_repr.adaptive_inflation_vote_encoding)) in let binary = conv @@ -144,7 +144,7 @@ let contents_encoding = "proof_of_work_nonce" (Fixed.bytes Hex Constants_repr.proof_of_work_nonce_size)) (opt "seed_nonce_hash" Nonce_hash.encoding) - (req "toggle_votes" Toggle_votes_repr.toggle_votes_encoding)) + (req "toggle_votes" Per_block_votes_repr.toggle_votes_encoding)) in def "block_header.alpha.unsigned_contents" @@ splitted ~binary ~json diff --git a/src/proto_alpha/lib_protocol/block_header_repr.mli b/src/proto_alpha/lib_protocol/block_header_repr.mli index 9960bff5a907..740d3352153e 100644 --- a/src/proto_alpha/lib_protocol/block_header_repr.mli +++ b/src/proto_alpha/lib_protocol/block_header_repr.mli @@ -30,7 +30,7 @@ type contents = { payload_round : Round_repr.t; seed_nonce_hash : Nonce_hash.t option; proof_of_work_nonce : bytes; - toggle_votes : Toggle_votes_repr.toggle_votes; + toggle_votes : Per_block_votes_repr.toggle_votes; } type protocol_data = {contents : contents; signature : Signature.t} diff --git a/src/proto_alpha/lib_protocol/dune b/src/proto_alpha/lib_protocol/dune index 59f4e7ea2540..88e24ffdb7d4 100644 --- a/src/proto_alpha/lib_protocol/dune +++ b/src/proto_alpha/lib_protocol/dune @@ -115,7 +115,7 @@ Bond_id_repr Vote_repr Toggle_EMA - Toggle_votes_repr + Per_block_votes_repr Block_header_repr Destination_repr Script_int @@ -383,7 +383,7 @@ bond_id_repr.ml bond_id_repr.mli vote_repr.ml vote_repr.mli toggle_EMA.ml toggle_EMA.mli - toggle_votes_repr.ml toggle_votes_repr.mli + per_block_votes_repr.ml per_block_votes_repr.mli block_header_repr.ml block_header_repr.mli destination_repr.ml destination_repr.mli script_int.ml script_int.mli @@ -653,7 +653,7 @@ bond_id_repr.ml bond_id_repr.mli vote_repr.ml vote_repr.mli toggle_EMA.ml toggle_EMA.mli - toggle_votes_repr.ml toggle_votes_repr.mli + per_block_votes_repr.ml per_block_votes_repr.mli block_header_repr.ml block_header_repr.mli destination_repr.ml destination_repr.mli script_int.ml script_int.mli @@ -907,7 +907,7 @@ bond_id_repr.ml bond_id_repr.mli vote_repr.ml vote_repr.mli toggle_EMA.ml toggle_EMA.mli - toggle_votes_repr.ml toggle_votes_repr.mli + per_block_votes_repr.ml per_block_votes_repr.mli block_header_repr.ml block_header_repr.mli destination_repr.ml destination_repr.mli script_int.ml script_int.mli diff --git a/src/proto_alpha/lib_protocol/liquidity_baking_storage.ml b/src/proto_alpha/lib_protocol/liquidity_baking_storage.ml index 1650758e8eaa..cb2d85fc5e31 100644 --- a/src/proto_alpha/lib_protocol/liquidity_baking_storage.ml +++ b/src/proto_alpha/lib_protocol/liquidity_baking_storage.ml @@ -24,7 +24,7 @@ (* *) (*****************************************************************************) -open Toggle_votes_repr +open Per_block_votes_repr let get_cpmm_address = Storage.Liquidity_baking.Cpmm_address.get diff --git a/src/proto_alpha/lib_protocol/liquidity_baking_storage.mli b/src/proto_alpha/lib_protocol/liquidity_baking_storage.mli index 97db7278af4c..23a2df6a591d 100644 --- a/src/proto_alpha/lib_protocol/liquidity_baking_storage.mli +++ b/src/proto_alpha/lib_protocol/liquidity_baking_storage.mli @@ -38,8 +38,8 @@ val get_cpmm_address : Raw_context.t -> Contract_hash.t tzresult Lwt.t see [apply_liquidity_baking_subsidy] in [apply.ml]. *) val on_subsidy_allowed : Raw_context.t -> - toggle_vote:Toggle_votes_repr.toggle_vote -> + toggle_vote:Per_block_votes_repr.toggle_vote -> (Raw_context.t -> Contract_hash.t -> (Raw_context.t * 'a list) tzresult Lwt.t) -> - (Raw_context.t * 'a list * Toggle_votes_repr.Liquidity_baking_toggle_EMA.t) + (Raw_context.t * 'a list * Per_block_votes_repr.Liquidity_baking_toggle_EMA.t) tzresult Lwt.t diff --git a/src/proto_alpha/lib_protocol/toggle_votes_repr.ml b/src/proto_alpha/lib_protocol/per_block_votes_repr.ml similarity index 100% rename from src/proto_alpha/lib_protocol/toggle_votes_repr.ml rename to src/proto_alpha/lib_protocol/per_block_votes_repr.ml diff --git a/src/proto_alpha/lib_protocol/toggle_votes_repr.mli b/src/proto_alpha/lib_protocol/per_block_votes_repr.mli similarity index 100% rename from src/proto_alpha/lib_protocol/toggle_votes_repr.mli rename to src/proto_alpha/lib_protocol/per_block_votes_repr.mli diff --git a/src/proto_alpha/lib_protocol/test/helpers/block.mli b/src/proto_alpha/lib_protocol/test/helpers/block.mli index a434badcc9f8..2837688f27cc 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/block.mli +++ b/src/proto_alpha/lib_protocol/test/helpers/block.mli @@ -282,8 +282,8 @@ val bake_n_with_metadata : ?check_size:bool -> ?baking_mode:baking_mode -> ?allow_manager_failures:bool -> - ?liquidity_baking_toggle_vote:Toggle_votes_repr.toggle_vote -> - ?adaptive_inflation_vote:Toggle_votes_repr.toggle_vote -> + ?liquidity_baking_toggle_vote:Per_block_votes_repr.toggle_vote -> + ?adaptive_inflation_vote:Per_block_votes_repr.toggle_vote -> int -> block -> (block * block_header_metadata, Error_monad.tztrace) result Lwt.t @@ -298,8 +298,8 @@ val bake_n_with_metadata : val bake_while : ?baking_mode:baking_mode -> ?policy:baker_policy -> - ?liquidity_baking_toggle_vote:Toggle_votes_repr.toggle_vote -> - ?adaptive_inflation_vote:Toggle_votes_repr.toggle_vote -> + ?liquidity_baking_toggle_vote:Per_block_votes_repr.toggle_vote -> + ?adaptive_inflation_vote:Per_block_votes_repr.toggle_vote -> ?invariant:(block -> unit tzresult Lwt.t) -> (block -> bool) -> block -> @@ -310,8 +310,8 @@ val bake_while : val bake_while_with_metadata : ?baking_mode:baking_mode -> ?policy:baker_policy -> - ?liquidity_baking_toggle_vote:Toggle_votes_repr.toggle_vote -> - ?adaptive_inflation_vote:Toggle_votes_repr.toggle_vote -> + ?liquidity_baking_toggle_vote:Per_block_votes_repr.toggle_vote -> + ?adaptive_inflation_vote:Per_block_votes_repr.toggle_vote -> ?invariant:(block -> unit tzresult Lwt.t) -> (block -> block_header_metadata -> bool) -> block -> diff --git a/src/proto_alpha/lib_protocol/test/unit/test_adaptive_inflation_ema.ml b/src/proto_alpha/lib_protocol/test/unit/test_adaptive_inflation_ema.ml index 87ebb81c4865..35b3208fb121 100644 --- a/src/proto_alpha/lib_protocol/test/unit/test_adaptive_inflation_ema.ml +++ b/src/proto_alpha/lib_protocol/test/unit/test_adaptive_inflation_ema.ml @@ -33,21 +33,21 @@ *) open Protocol -module Toggle_EMA = Toggle_votes_repr.Adaptive_inflation_launch_EMA +module Toggle_EMA = Per_block_votes_repr.Adaptive_inflation_launch_EMA let ema_of_int32 ema = Toggle_EMA.of_int32 ema >|= Environment.wrap_tzresult let ema_to_int32 = Toggle_EMA.to_int32 let compute_new_ema ~toggle_vote ema = - Toggle_votes_repr.compute_new_adaptive_inflation_ema ~toggle_vote ema + Per_block_votes_repr.compute_new_adaptive_inflation_ema ~toggle_vote ema |> ema_to_int32 (* Folds compute_new_ema on a list of votes *) let compute_new_ema_n toggle_votes initial_ema = List.fold_left (fun ema toggle_vote -> - Toggle_votes_repr.compute_new_adaptive_inflation_ema ~toggle_vote ema) + Per_block_votes_repr.compute_new_adaptive_inflation_ema ~toggle_vote ema) initial_ema toggle_votes |> ema_to_int32 @@ -172,7 +172,7 @@ let test_ema_decreases_off_bound () = (* Test that 80642 On votes are needed to move from 0% to 50%. *) let test_ema_many_on () = - let open Toggle_votes_repr in + let open Per_block_votes_repr in ema_of_int32 0l >>=? fun initial_ema -> Assert.leq_int32 ~loc:__LOC__ @@ -190,7 +190,7 @@ let test_ema_many_on () = (* Test that 80642 Off votes are needed to move from 100% to 50%. *) let test_ema_many_off () = - let open Toggle_votes_repr in + let open Per_block_votes_repr in ema_of_int32 2_000_000_000l >>=? fun initial_ema -> Assert.leq_int32 ~loc:__LOC__ @@ -208,7 +208,7 @@ let test_ema_many_off () = (* Test that 187259 On votes are needed to move from 0% to 80%. *) let test_ema_many_many_on () = - let open Toggle_votes_repr in + let open Per_block_votes_repr in ema_of_int32 0l >>=? fun initial_ema -> Assert.leq_int32 ~loc:__LOC__ diff --git a/src/proto_alpha/lib_protocol/test/unit/test_liquidity_baking_repr.ml b/src/proto_alpha/lib_protocol/test/unit/test_liquidity_baking_repr.ml index 4caf766f8fb1..06f7e471658d 100644 --- a/src/proto_alpha/lib_protocol/test/unit/test_liquidity_baking_repr.ml +++ b/src/proto_alpha/lib_protocol/test/unit/test_liquidity_baking_repr.ml @@ -32,21 +32,21 @@ *) open Protocol -module Toggle_EMA = Toggle_votes_repr.Liquidity_baking_toggle_EMA +module Toggle_EMA = Per_block_votes_repr.Liquidity_baking_toggle_EMA let ema_of_int32 ema = Toggle_EMA.of_int32 ema >|= Environment.wrap_tzresult let ema_to_int32 = Toggle_EMA.to_int32 let compute_new_ema ~toggle_vote ema = - Toggle_votes_repr.compute_new_liquidity_baking_ema ~toggle_vote ema + Per_block_votes_repr.compute_new_liquidity_baking_ema ~toggle_vote ema |> ema_to_int32 (* Folds compute_new_ema on a list of votes *) let compute_new_ema_n toggle_votes initial_ema = List.fold_left (fun ema toggle_vote -> - Toggle_votes_repr.compute_new_liquidity_baking_ema ~toggle_vote ema) + Per_block_votes_repr.compute_new_liquidity_baking_ema ~toggle_vote ema) initial_ema toggle_votes |> ema_to_int32 @@ -171,7 +171,7 @@ let test_ema_decreases_on_bound () = (* Test that 1385 Off votes are needed to reach the threshold from 0. *) let test_ema_many_off () = - let open Toggle_votes_repr in + let open Per_block_votes_repr in ema_of_int32 0l >>=? fun initial_ema -> Assert.leq_int32 ~loc:__LOC__ @@ -189,7 +189,7 @@ let test_ema_many_off () = (* Test that 1385 On votes are needed to reach the threshold from the max value of the EMA (2,000,000,000). *) let test_ema_many_on () = - let open Toggle_votes_repr in + let open Per_block_votes_repr in ema_of_int32 2_000_000_000l >>=? fun initial_ema -> Assert.leq_int32 ~loc:__LOC__ -- GitLab From a6785ce29bb43c44b3617eb6b8d07d261775ce36 Mon Sep 17 00:00:00 2001 From: Philippe Wang Date: Tue, 27 Jun 2023 10:52:29 -0700 Subject: [PATCH 2/6] Proto: rename Toggle_EMA to Votes_EMA --- src/proto_alpha/lib_client/mockup.ml | 8 +-- .../lib_delegate/baking_actions.ml | 12 ++-- .../lib_delegate/baking_commands.ml | 16 ++--- .../lib_delegate/baking_configuration.ml | 34 ++++----- .../lib_delegate/baking_configuration.mli | 18 ++--- src/proto_alpha/lib_delegate/baking_events.ml | 8 +-- src/proto_alpha/lib_delegate/block_forge.ml | 4 +- src/proto_alpha/lib_delegate/block_forge.mli | 4 +- .../lib_delegate/client_daemon.mli | 2 +- .../lib_delegate/per_block_vote_file.ml | 26 +++---- .../lib_delegate/per_block_vote_file.mli | 14 ++-- .../test/mockup_simulator/mockup_simulator.ml | 4 +- src/proto_alpha/lib_plugin/RPC.ml | 18 ++--- src/proto_alpha/lib_protocol/TEZOS_PROTOCOL | 2 +- .../adaptive_inflation_storage.ml | 2 +- .../adaptive_inflation_storage.mli | 2 +- src/proto_alpha/lib_protocol/alpha_context.ml | 4 +- .../lib_protocol/alpha_context.mli | 46 ++++++------ src/proto_alpha/lib_protocol/apply.ml | 28 ++++---- src/proto_alpha/lib_protocol/apply.mli | 4 +- src/proto_alpha/lib_protocol/apply_results.ml | 8 +-- .../lib_protocol/apply_results.mli | 4 +- .../lib_protocol/block_header_repr.ml | 22 +++--- .../lib_protocol/block_header_repr.mli | 2 +- src/proto_alpha/lib_protocol/dune | 8 +-- .../lib_protocol/liquidity_baking_storage.ml | 8 +-- .../lib_protocol/liquidity_baking_storage.mli | 4 +- src/proto_alpha/lib_protocol/main.ml | 6 +- .../lib_protocol/per_block_votes_repr.ml | 72 +++++++++---------- .../lib_protocol/per_block_votes_repr.mli | 44 ++++++------ .../lib_protocol/test/helpers/block.ml | 13 ++-- .../lib_protocol/test/helpers/block.mli | 42 +++++------ .../test_adaptive_inflation_launch.ml | 18 ++--- .../test/integration/test_liquidity_baking.ml | 64 ++++++++--------- .../test/unit/test_adaptive_inflation_ema.ml | 46 ++++++------ .../test/unit/test_liquidity_baking_repr.ml | 42 +++++------ .../{toggle_EMA.ml => votes_EMA_repr.ml} | 0 .../{toggle_EMA.mli => votes_EMA_repr.mli} | 0 38 files changed, 330 insertions(+), 329 deletions(-) rename src/proto_alpha/lib_protocol/{toggle_EMA.ml => votes_EMA_repr.ml} (100%) rename src/proto_alpha/lib_protocol/{toggle_EMA.mli => votes_EMA_repr.mli} (100%) diff --git a/src/proto_alpha/lib_client/mockup.ml b/src/proto_alpha/lib_client/mockup.ml index 3fc9ac56e84c..ea1959ba9f5a 100644 --- a/src/proto_alpha/lib_client/mockup.ml +++ b/src/proto_alpha/lib_client/mockup.ml @@ -518,11 +518,11 @@ let mem_init : payload_hash; seed_nonce_hash = None; proof_of_work_nonce; - (* following Baking_configuration.toggle_votes in lib_delegate *) - toggle_votes = + (* following Baking_configuration.per_block_votes in lib_delegate *) + per_block_votes = { - liquidity_baking_vote = Toggle_votes.Toggle_vote_pass; - adaptive_inflation_vote = Toggle_votes.Toggle_vote_pass; + liquidity_baking_vote = Per_block_votes.Per_block_vote_pass; + adaptive_inflation_vote = Per_block_votes.Per_block_vote_pass; }; } in diff --git a/src/proto_alpha/lib_delegate/baking_actions.ml b/src/proto_alpha/lib_delegate/baking_actions.ml index 149606e70901..291c5bb23c7a 100644 --- a/src/proto_alpha/lib_delegate/baking_actions.ml +++ b/src/proto_alpha/lib_delegate/baking_actions.ml @@ -289,21 +289,21 @@ let inject_block ~state_recorder state block_to_bake ~updated_state = liquidity_baking_vote; adaptive_inflation_vote; } = - state.global_state.config.toggle_votes + state.global_state.config.per_block_votes in (* Prioritize reading from the [vote_file] if it exists. *) (let default = - Protocol.Alpha_context.Toggle_votes. + Protocol.Alpha_context.Per_block_votes. {liquidity_baking_vote; adaptive_inflation_vote} in match vote_file with | Some per_block_vote_file -> - Per_block_vote_file.read_toggle_votes_no_fail + Per_block_vote_file.read_per_block_votes_no_fail ~default ~per_block_vote_file | None -> Lwt.return default) >>= fun {liquidity_baking_vote; adaptive_inflation_vote} -> - (* Cache last toggle vote to use in case of vote file errors *) + (* Cache last per-block votes to use in case of vote file errors *) let updated_state = { updated_state with @@ -313,9 +313,9 @@ let inject_block ~state_recorder state block_to_bake ~updated_state = config = { updated_state.global_state.config with - toggle_votes = + per_block_votes = { - updated_state.global_state.config.toggle_votes with + updated_state.global_state.config.per_block_votes with liquidity_baking_vote; adaptive_inflation_vote; }; diff --git a/src/proto_alpha/lib_delegate/baking_commands.ml b/src/proto_alpha/lib_delegate/baking_commands.ml index 28250f7dc17c..2311ceaff64c 100644 --- a/src/proto_alpha/lib_delegate/baking_commands.ml +++ b/src/proto_alpha/lib_delegate/baking_commands.ml @@ -150,11 +150,11 @@ let keep_alive_arg = let toggle_vote_parameter = Tezos_clic.parameter ~autocomplete:(fun _ctxt -> return ["on"; "off"; "pass"]) - (let open Protocol.Alpha_context.Toggle_votes in + (let open Protocol.Alpha_context.Per_block_votes in fun _ctxt -> function - | "on" -> return Toggle_vote_on - | "off" -> return Toggle_vote_off - | "pass" -> return Toggle_vote_pass + | "on" -> return Per_block_vote_on + | "off" -> return Per_block_vote_off + | "pass" -> return Per_block_vote_pass | s -> failwith "unexpected vote: %s, expected either \"on\", \"off\", or \"pass\"." @@ -315,10 +315,10 @@ let delegate_commands () : Protocol_client_context.full Tezos_clic.command list payload_round = Round.zero; seed_nonce_hash = None; proof_of_work_nonce; - toggle_votes = + per_block_votes = { - liquidity_baking_vote = Toggle_vote_pass; - adaptive_inflation_vote = Toggle_vote_pass; + liquidity_baking_vote = Per_block_vote_pass; + adaptive_inflation_vote = Per_block_vote_pass; }; }) in @@ -528,7 +528,7 @@ let run_baker (* We don't let the user run the baker without providing some option (CLI, file path, or file in default location) for the toggle votes. *) - Per_block_vote_file.load_toggle_votes_config + Per_block_vote_file.load_per_block_votes_config ~default_liquidity_baking_vote:liquidity_baking_vote ~default_adaptive_inflation_vote:adaptive_inflation_vote ~per_block_vote_file diff --git a/src/proto_alpha/lib_delegate/baking_configuration.ml b/src/proto_alpha/lib_delegate/baking_configuration.ml index 32f594ab2445..0e2e4fe44953 100644 --- a/src/proto_alpha/lib_delegate/baking_configuration.ml +++ b/src/proto_alpha/lib_delegate/baking_configuration.ml @@ -76,10 +76,10 @@ type nonce_config = Deterministic | Random type state_recorder_config = Filesystem | Disabled -type toggle_votes_config = { +type per_block_votes_config = { vote_file : string option; - liquidity_baking_vote : Protocol.Alpha_context.Toggle_votes.toggle_vote; - adaptive_inflation_vote : Protocol.Alpha_context.Toggle_votes.toggle_vote; + liquidity_baking_vote : Protocol.Alpha_context.Per_block_votes.per_block_vote; + adaptive_inflation_vote : Protocol.Alpha_context.Per_block_votes.per_block_vote; } type t = { @@ -88,7 +88,7 @@ type t = { validation : validation_config; retries_on_failure : int; user_activated_upgrades : (int32 * Protocol_hash.t) list; - toggle_votes : toggle_votes_config; + per_block_votes : per_block_votes_config; force_apply : bool; force : bool; state_recorder : state_recorder_config; @@ -117,9 +117,9 @@ let default_user_activated_upgrades = [] let default_votes_config = { vote_file = None; - liquidity_baking_vote = Protocol.Alpha_context.Toggle_votes.Toggle_vote_pass; + liquidity_baking_vote = Protocol.Alpha_context.Per_block_votes.Per_block_vote_pass; adaptive_inflation_vote = - Protocol.Alpha_context.Toggle_votes.Toggle_vote_pass; + Protocol.Alpha_context.Per_block_votes.Per_block_vote_pass; } let default_force = false @@ -137,7 +137,7 @@ let default_config = validation = default_validation_config; retries_on_failure = default_retries_on_failure_config; user_activated_upgrades = default_user_activated_upgrades; - toggle_votes = default_votes_config; + per_block_votes = default_votes_config; force_apply = default_force_apply; force = default_force; state_recorder = default_state_recorder_config; @@ -169,7 +169,7 @@ let make ?(minimal_fees = default_fees_config.minimal_fees) nonce; retries_on_failure; user_activated_upgrades; - toggle_votes = votes; + per_block_votes = votes; force_apply; force; state_recorder; @@ -237,14 +237,14 @@ let user_activate_upgrades_config_encoding = list (tup2 int32 Protocol_hash.encoding) let liquidity_baking_toggle_vote_config_encoding = - Protocol.Alpha_context.Toggle_votes.liquidity_baking_vote_encoding + Protocol.Alpha_context.Per_block_votes.liquidity_baking_vote_encoding let adaptive_inflation_vote_config_encoding = - Protocol.Alpha_context.Toggle_votes.adaptive_inflation_vote_encoding + Protocol.Alpha_context.Per_block_votes.adaptive_inflation_vote_encoding -let toggle_votes_config_encoding = +let per_block_votes_config_encoding = let open Data_encoding in - def (String.concat "." [Protocol.name; "toggle_votes_config"]) + def (String.concat "." [Protocol.name; "per_block_votes_config"]) @@ conv (fun {vote_file; liquidity_baking_vote; adaptive_inflation_vote} -> (vote_file, liquidity_baking_vote, adaptive_inflation_vote)) @@ -295,7 +295,7 @@ let encoding : t Data_encoding.t = nonce; retries_on_failure; user_activated_upgrades; - toggle_votes; + per_block_votes; force_apply; force; state_recorder; @@ -307,7 +307,7 @@ let encoding : t Data_encoding.t = nonce, retries_on_failure, user_activated_upgrades, - toggle_votes, + per_block_votes, force_apply, force, state_recorder ), @@ -317,7 +317,7 @@ let encoding : t Data_encoding.t = nonce, retries_on_failure, user_activated_upgrades, - toggle_votes, + per_block_votes, force_apply, force, state_recorder ), @@ -328,7 +328,7 @@ let encoding : t Data_encoding.t = nonce; retries_on_failure; user_activated_upgrades; - toggle_votes; + per_block_votes; force_apply; force; state_recorder; @@ -344,7 +344,7 @@ let encoding : t Data_encoding.t = (req "user_activated_upgrades" user_activate_upgrades_config_encoding) - (req "votes" toggle_votes_config_encoding) + (req "votes" per_block_votes_config_encoding) (req "force_apply" force_apply_config_encoding) (req "force" force_config_encoding) (req "state_recorder" state_recorder_config_encoding)) diff --git a/src/proto_alpha/lib_delegate/baking_configuration.mli b/src/proto_alpha/lib_delegate/baking_configuration.mli index 7cc6b38ec550..945f4e18cbb5 100644 --- a/src/proto_alpha/lib_delegate/baking_configuration.mli +++ b/src/proto_alpha/lib_delegate/baking_configuration.mli @@ -51,10 +51,10 @@ type nonce_config = Deterministic | Random type state_recorder_config = Filesystem | Disabled -type toggle_votes_config = { +type per_block_votes_config = { vote_file : string option; - liquidity_baking_vote : Protocol.Alpha_context.Toggle_votes.toggle_vote; - adaptive_inflation_vote : Protocol.Alpha_context.Toggle_votes.toggle_vote; + liquidity_baking_vote : Protocol.Alpha_context.Per_block_votes.per_block_vote; + adaptive_inflation_vote : Protocol.Alpha_context.Per_block_votes.per_block_vote; } type t = { @@ -63,7 +63,7 @@ type t = { validation : validation_config; retries_on_failure : int; user_activated_upgrades : (int32 * Protocol_hash.t) list; - toggle_votes : toggle_votes_config; + per_block_votes : per_block_votes_config; force_apply : bool; force : bool; state_recorder : state_recorder_config; @@ -81,7 +81,7 @@ val default_retries_on_failure_config : int val default_user_activated_upgrades : (int32 * Protocol_hash.t) list -val default_votes_config : toggle_votes_config +val default_votes_config : per_block_votes_config val default_force_apply : bool @@ -101,7 +101,7 @@ val make : ?context_path:string -> ?retries_on_failure:int -> ?user_activated_upgrades:(int32 * Protocol_hash.t) list -> - ?votes:toggle_votes_config -> + ?votes:per_block_votes_config -> ?force_apply:bool -> ?force:bool -> ?state_recorder:state_recorder_config -> @@ -122,12 +122,12 @@ val user_activate_upgrades_config_encoding : (int32 * Protocol_hash.t) list Data_encoding.t val liquidity_baking_toggle_vote_config_encoding : - Protocol.Alpha_context.Toggle_votes.toggle_vote Data_encoding.t + Protocol.Alpha_context.Per_block_votes.per_block_vote Data_encoding.t val adaptive_inflation_vote_config_encoding : - Protocol.Alpha_context.Toggle_votes.toggle_vote Data_encoding.t + Protocol.Alpha_context.Per_block_votes.per_block_vote Data_encoding.t -val toggle_votes_config_encoding : toggle_votes_config Data_encoding.t +val per_block_votes_config_encoding : per_block_votes_config Data_encoding.t val encoding : t Data_encoding.t diff --git a/src/proto_alpha/lib_delegate/baking_events.ml b/src/proto_alpha/lib_delegate/baking_events.ml index 393dec0eb44a..ba6083186a00 100644 --- a/src/proto_alpha/lib_delegate/baking_events.ml +++ b/src/proto_alpha/lib_delegate/baking_events.ml @@ -797,7 +797,7 @@ module Actions = struct ~level:Notice ~msg:"Voting {value} for liquidity baking toggle vote" ( "value", - Protocol.Alpha_context.Toggle_votes.liquidity_baking_vote_encoding ) + Protocol.Alpha_context.Per_block_votes.liquidity_baking_vote_encoding ) let vote_for_adaptive_inflation = declare_1 @@ -806,7 +806,7 @@ module Actions = struct ~level:Notice ~msg:"Voting {value} for adaptive inflation vote" ( "value", - Protocol.Alpha_context.Toggle_votes.adaptive_inflation_vote_encoding ) + Protocol.Alpha_context.Per_block_votes.adaptive_inflation_vote_encoding ) let no_dal_node = declare_0 @@ -1020,7 +1020,7 @@ module Per_block_votes = struct ~level:Notice ~msg:"liquidity baking toggle vote = {value}" ( "value", - Protocol.Alpha_context.Toggle_votes.liquidity_baking_vote_encoding ) + Protocol.Alpha_context.Per_block_votes.liquidity_baking_vote_encoding ) let per_block_vote_file_fail = declare_1 @@ -1038,7 +1038,7 @@ module Per_block_votes = struct ~level:Notice ~msg:"adaptive inflation vote = {value}" ( "value", - Protocol.Alpha_context.Toggle_votes.adaptive_inflation_vote_encoding ) + Protocol.Alpha_context.Per_block_votes.adaptive_inflation_vote_encoding ) end module Selection = struct diff --git a/src/proto_alpha/lib_delegate/block_forge.ml b/src/proto_alpha/lib_delegate/block_forge.ml index d36d94a1d1db..81cdb4699a31 100644 --- a/src/proto_alpha/lib_delegate/block_forge.ml +++ b/src/proto_alpha/lib_delegate/block_forge.ml @@ -56,7 +56,7 @@ let forge_faked_protocol_data ?(payload_hash = Block_payload_hash.zero) payload_round; seed_nonce_hash; proof_of_work_nonce = Baking_pow.empty_proof_of_work_nonce; - toggle_votes = + per_block_votes = { liquidity_baking_vote = liquidity_baking_toggle_vote; adaptive_inflation_vote; @@ -498,7 +498,7 @@ let forge (cctxt : #Protocol_client_context.full) ~chain_id payload_round; seed_nonce_hash; proof_of_work_nonce; - toggle_votes = + per_block_votes = { liquidity_baking_vote = liquidity_baking_toggle_vote; adaptive_inflation_vote; diff --git a/src/proto_alpha/lib_delegate/block_forge.mli b/src/proto_alpha/lib_delegate/block_forge.mli index 04dbadbcc424..f0c2638ee6cf 100644 --- a/src/proto_alpha/lib_delegate/block_forge.mli +++ b/src/proto_alpha/lib_delegate/block_forge.mli @@ -48,8 +48,8 @@ val forge : pred_live_blocks:Block_hash.Set.t -> timestamp:Time.Protocol.t -> round:Round.t -> - liquidity_baking_toggle_vote:Toggle_votes.toggle_vote -> - adaptive_inflation_vote:Toggle_votes.toggle_vote -> + liquidity_baking_toggle_vote:Per_block_votes.per_block_vote -> + adaptive_inflation_vote:Per_block_votes.per_block_vote -> user_activated_upgrades:User_activated.upgrades -> Baking_configuration.fees_config -> force_apply:bool -> diff --git a/src/proto_alpha/lib_delegate/client_daemon.mli b/src/proto_alpha/lib_delegate/client_daemon.mli index 6b7d49f79b54..ce530fee5397 100644 --- a/src/proto_alpha/lib_delegate/client_daemon.mli +++ b/src/proto_alpha/lib_delegate/client_daemon.mli @@ -32,7 +32,7 @@ module Baker : sig ?minimal_fees:Protocol.Alpha_context.Tez.t -> ?minimal_nanotez_per_gas_unit:Q.t -> ?minimal_nanotez_per_byte:Q.t -> - ?votes:Baking_configuration.toggle_votes_config -> + ?votes:Baking_configuration.per_block_votes_config -> ?extra_operations:Baking_configuration.Operations_source.t -> ?dal_node_endpoint:Uri.t -> ?force_apply:bool -> diff --git a/src/proto_alpha/lib_delegate/per_block_vote_file.ml b/src/proto_alpha/lib_delegate/per_block_vote_file.ml index f1d2a8187a4e..c736ce1ffd03 100644 --- a/src/proto_alpha/lib_delegate/per_block_vote_file.ml +++ b/src/proto_alpha/lib_delegate/per_block_vote_file.ml @@ -30,9 +30,9 @@ let default_vote_json_filename = "per_block_votes.json" type per_block_votes = { liquidity_baking_toggle_vote : - Protocol.Alpha_context.Toggle_votes.toggle_vote; + Protocol.Alpha_context.Per_block_votes.per_block_vote; adaptive_inflation_vote_opt : - Protocol.Alpha_context.Toggle_votes.toggle_vote option; + Protocol.Alpha_context.Per_block_votes.per_block_vote option; } let vote_file_content_encoding = @@ -46,10 +46,10 @@ let vote_file_content_encoding = (obj2 (req "liquidity_baking_toggle_vote" - Protocol.Alpha_context.Toggle_votes.liquidity_baking_vote_encoding) + Protocol.Alpha_context.Per_block_votes.liquidity_baking_vote_encoding) (opt "adaptive_inflation_vote" - Protocol.Alpha_context.Toggle_votes + Protocol.Alpha_context.Per_block_votes .adaptive_inflation_vote_encoding)) type error += Block_vote_file_not_found of string @@ -177,7 +177,7 @@ let check_file_exists file = in if file_exists then return_unit else tzfail (Block_vote_file_not_found file) -let read_toggle_votes ~per_block_vote_file : 'a tzresult Lwt.t = +let read_per_block_votes ~per_block_vote_file : 'a tzresult Lwt.t = let open Lwt_result_syntax in let*! () = Events.(emit reading_per_block_votes) per_block_vote_file in let* () = check_file_exists per_block_vote_file in @@ -195,8 +195,8 @@ let read_toggle_votes ~per_block_vote_file : 'a tzresult Lwt.t = in return votes -let read_toggle_votes_no_fail ~default ~per_block_vote_file = - read_toggle_votes ~per_block_vote_file >>= function +let read_per_block_votes_no_fail ~default ~per_block_vote_file = + read_per_block_votes ~per_block_vote_file >>= function | Error errs -> Events.(emit per_block_vote_file_fail) errs >>= fun () -> Lwt.return default @@ -206,7 +206,7 @@ let read_toggle_votes_no_fail ~default ~per_block_vote_file = adaptive_inflation_vote_opt = Some adaptive_inflation_vote; } -> Lwt.return - Protocol.Alpha_context.Toggle_votes. + Protocol.Alpha_context.Per_block_votes. { liquidity_baking_vote = liquidity_baking_toggle_vote; adaptive_inflation_vote; @@ -215,17 +215,17 @@ let read_toggle_votes_no_fail ~default ~per_block_vote_file = Lwt.return {default with liquidity_baking_vote = liquidity_baking_toggle_vote} -let load_toggle_votes_config ~default_liquidity_baking_vote +let load_per_block_votes_config ~default_liquidity_baking_vote ~default_adaptive_inflation_vote ~per_block_vote_file : - Baking_configuration.toggle_votes_config tzresult Lwt.t = + Baking_configuration.per_block_votes_config tzresult Lwt.t = let open Lwt_result_syntax in (* If a vote file is given, it takes priority. Otherwise, we expect - a toggle vote argument to be passed. *) + per-block vote arguments to be passed. *) let default_adaptive_inflation_vote = (* Unlike the vote for liquidity baking, the vote for adaptive inflation is not mandatory. *) match default_adaptive_inflation_vote with - | None -> Protocol.Alpha_context.Toggle_votes.Toggle_vote_pass + | None -> Protocol.Alpha_context.Per_block_votes.Per_block_vote_pass | Some default_adaptive_inflation_vote -> default_adaptive_inflation_vote in let* config = @@ -239,7 +239,7 @@ let load_toggle_votes_config ~default_liquidity_baking_vote adaptive_inflation_vote = default_adaptive_inflation_vote; } | Some per_block_vote_file, _ -> ( - let*! (res : _ tzresult) = read_toggle_votes ~per_block_vote_file in + let*! (res : _ tzresult) = read_per_block_votes ~per_block_vote_file in match res with | Ok { diff --git a/src/proto_alpha/lib_delegate/per_block_vote_file.mli b/src/proto_alpha/lib_delegate/per_block_vote_file.mli index dd83692f4d1c..70fe4b619cbe 100644 --- a/src/proto_alpha/lib_delegate/per_block_vote_file.mli +++ b/src/proto_alpha/lib_delegate/per_block_vote_file.mli @@ -67,18 +67,18 @@ val default_vote_json_filename : string (** Reads the content of [per_block_vote_file] and returns the votes. If any error occurs (e.g. Non-existing file, unparsable content, etc.), given default values will be used to fill the gaps. *) -val read_toggle_votes_no_fail : - default:Toggle_votes.toggle_votes -> +val read_per_block_votes_no_fail : + default:Per_block_votes.per_block_votes -> per_block_vote_file:string -> - Toggle_votes.toggle_votes Lwt.t + Per_block_votes.per_block_votes Lwt.t (** Load a liquidity baking configuration given two possible arguments. If neither are provided, it fails. Otherwise, it tries, in priority, to read the [per_block_vote_file_arg] file if it is given and loads a config using its content. Otherwise, the [toggle_vote_arg] is used. *) -val load_toggle_votes_config : - default_liquidity_baking_vote:Toggle_votes.toggle_vote option -> - default_adaptive_inflation_vote:Toggle_votes.toggle_vote option -> +val load_per_block_votes_config : + default_liquidity_baking_vote:Per_block_votes.per_block_vote option -> + default_adaptive_inflation_vote:Per_block_votes.per_block_vote option -> per_block_vote_file:string option -> - Baking_configuration.toggle_votes_config tzresult Lwt.t + Baking_configuration.per_block_votes_config tzresult Lwt.t diff --git a/src/proto_alpha/lib_delegate/test/mockup_simulator/mockup_simulator.ml b/src/proto_alpha/lib_delegate/test/mockup_simulator/mockup_simulator.ml index b80d30e8090e..3b4acac0c286 100644 --- a/src/proto_alpha/lib_delegate/test/mockup_simulator/mockup_simulator.ml +++ b/src/proto_alpha/lib_delegate/test/mockup_simulator/mockup_simulator.ml @@ -929,7 +929,7 @@ let genesis_protocol_data (baker_sk : Signature.secret_key) ~payload_round:Alpha_context.Round.zero [] in - let toggle_votes = + let per_block_votes = { Protocol.Per_block_votes_repr.liquidity_baking_vote = Baking_configuration.default_votes_config @@ -946,7 +946,7 @@ let genesis_protocol_data (baker_sk : Signature.secret_key) payload_round = Alpha_context.Round.zero; proof_of_work_nonce; seed_nonce_hash = None; - toggle_votes; + per_block_votes; } in let unsigned_header = diff --git a/src/proto_alpha/lib_plugin/RPC.ml b/src/proto_alpha/lib_plugin/RPC.ml index 19689e99c38d..086265bab38e 100644 --- a/src/proto_alpha/lib_plugin/RPC.ml +++ b/src/proto_alpha/lib_plugin/RPC.ml @@ -1034,9 +1034,9 @@ module Scripts = struct op_count = 0; migration_balance_updates = []; liquidity_baking_toggle_ema = - Toggle_votes.Liquidity_baking_toggle_EMA.zero; + Per_block_votes.Liquidity_baking_toggle_EMA.zero; adaptive_inflation_toggle_ema = - Toggle_votes.Adaptive_inflation_launch_EMA.zero; + Per_block_votes.Adaptive_inflation_launch_EMA.zero; adaptive_inflation_launch_cycle = None; implicit_operations_results = []; } @@ -2756,13 +2756,13 @@ module Forge = struct Hex Alpha_context.Constants.proof_of_work_nonce_size) empty_proof_of_work_nonce) - Toggle_votes.( + Per_block_votes.( dft - "toggle_votes" - toggle_votes_encoding + "per_block_votes" + per_block_votes_encoding { - liquidity_baking_vote = Toggle_vote_pass; - adaptive_inflation_vote = Toggle_vote_pass; + liquidity_baking_vote = Per_block_vote_pass; + adaptive_inflation_vote = Per_block_vote_pass; })) ~output:(obj1 (req "protocol_data" (bytes Hex))) RPC_path.(path / "protocol_data") @@ -2786,7 +2786,7 @@ module Forge = struct payload_round, seed_nonce_hash, proof_of_work_nonce, - toggle_votes ) + per_block_votes ) -> return (Data_encoding.Binary.to_bytes_exn @@ -2796,7 +2796,7 @@ module Forge = struct payload_round; seed_nonce_hash; proof_of_work_nonce; - toggle_votes; + per_block_votes; })) module Manager = struct diff --git a/src/proto_alpha/lib_protocol/TEZOS_PROTOCOL b/src/proto_alpha/lib_protocol/TEZOS_PROTOCOL index 00918789fa8a..68b4df280749 100644 --- a/src/proto_alpha/lib_protocol/TEZOS_PROTOCOL +++ b/src/proto_alpha/lib_protocol/TEZOS_PROTOCOL @@ -91,7 +91,7 @@ "Bond_id_repr", "Vote_repr", - "Toggle_EMA", + "Votes_EMA_repr", "Per_block_votes_repr", "Block_header_repr", "Destination_repr", diff --git a/src/proto_alpha/lib_protocol/adaptive_inflation_storage.ml b/src/proto_alpha/lib_protocol/adaptive_inflation_storage.ml index eabf304cc3c3..83927fd08e47 100644 --- a/src/proto_alpha/lib_protocol/adaptive_inflation_storage.ml +++ b/src/proto_alpha/lib_protocol/adaptive_inflation_storage.ml @@ -291,7 +291,7 @@ let update_ema ctxt ~vote = >>=? fun old_ema -> let new_ema = Per_block_votes_repr.compute_new_adaptive_inflation_ema - ~toggle_vote:vote + ~per_block_vote:vote old_ema in Storage.Adaptive_inflation.Launch_ema.update diff --git a/src/proto_alpha/lib_protocol/adaptive_inflation_storage.mli b/src/proto_alpha/lib_protocol/adaptive_inflation_storage.mli index 00dccdb23192..3944c6e01d5b 100644 --- a/src/proto_alpha/lib_protocol/adaptive_inflation_storage.mli +++ b/src/proto_alpha/lib_protocol/adaptive_inflation_storage.mli @@ -54,7 +54,7 @@ val init : Raw_context.t -> Raw_context.t tzresult Lwt.t (** [update_ema ctxt ~vote] returns the new context with the new EMA *) val update_ema : Raw_context.t -> - vote:Per_block_votes_repr.toggle_vote -> + vote:Per_block_votes_repr.per_block_vote -> (Raw_context.t * Cycle_repr.t option * Per_block_votes_repr.Adaptive_inflation_launch_EMA.t) diff --git a/src/proto_alpha/lib_protocol/alpha_context.ml b/src/proto_alpha/lib_protocol/alpha_context.ml index e6ffe8f6d44d..5779d0061c0e 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.ml +++ b/src/proto_alpha/lib_protocol/alpha_context.ml @@ -612,8 +612,8 @@ let internal_nonce_already_recorded = let description = Raw_context.description module Parameters = Parameters_repr -module Toggle_EMA = Toggle_EMA -module Toggle_votes = Per_block_votes_repr +module Votes_EMA = Votes_EMA_repr +module Per_block_votes = Per_block_votes_repr module Liquidity_baking = struct include Liquidity_baking_storage diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index 2f6ead6bc8d3..311987624be9 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -3848,7 +3848,7 @@ module Block_header : sig payload_round : Round.t; seed_nonce_hash : Nonce_hash.t option; proof_of_work_nonce : bytes; - toggle_votes : Per_block_votes_repr.toggle_votes; + per_block_votes : Per_block_votes_repr.per_block_votes; } type protocol_data = {contents : contents; signature : signature} @@ -4710,8 +4710,8 @@ module Parameters : sig val encoding : t Data_encoding.t end -(** This module re-exports definitions from {!Toggle_EMA} *) -module Toggle_EMA : sig +(** This module re-exports definitions from {!Votes_EMA_repr} *) +module Votes_EMA : sig module type T = sig type t @@ -4732,34 +4732,34 @@ module Toggle_EMA : sig end (** This module re-exports definitions from {!Per_block_votes_repr}. *) -module Toggle_votes : sig - type toggle_vote = Per_block_votes_repr.toggle_vote = - | Toggle_vote_on - | Toggle_vote_off - | Toggle_vote_pass - - type toggle_votes = Per_block_votes_repr.toggle_votes = { - liquidity_baking_vote : toggle_vote; - adaptive_inflation_vote : toggle_vote; +module Per_block_votes : sig + type per_block_vote = Per_block_votes_repr.per_block_vote = + | Per_block_vote_on + | Per_block_vote_off + | Per_block_vote_pass + + type per_block_votes = Per_block_votes_repr.per_block_votes = { + liquidity_baking_vote : per_block_vote; + adaptive_inflation_vote : per_block_vote; } - val liquidity_baking_vote_encoding : toggle_vote Data_encoding.encoding + val liquidity_baking_vote_encoding : per_block_vote Data_encoding.encoding - val adaptive_inflation_vote_encoding : toggle_vote Data_encoding.encoding + val adaptive_inflation_vote_encoding : per_block_vote Data_encoding.encoding - val toggle_votes_encoding : toggle_votes Data_encoding.encoding + val per_block_votes_encoding : per_block_votes Data_encoding.encoding - module Liquidity_baking_toggle_EMA : Toggle_EMA.T + module Liquidity_baking_toggle_EMA : Votes_EMA.T - module Adaptive_inflation_launch_EMA : Toggle_EMA.T + module Adaptive_inflation_launch_EMA : Votes_EMA.T val compute_new_liquidity_baking_ema : - toggle_vote:toggle_vote -> + per_block_vote:per_block_vote -> Liquidity_baking_toggle_EMA.t -> Liquidity_baking_toggle_EMA.t val compute_new_adaptive_inflation_ema : - toggle_vote:toggle_vote -> + per_block_vote:per_block_vote -> Adaptive_inflation_launch_EMA.t -> Adaptive_inflation_launch_EMA.t end @@ -4770,9 +4770,9 @@ module Liquidity_baking : sig val on_subsidy_allowed : context -> - toggle_vote:Toggle_votes.toggle_vote -> + per_block_vote:Per_block_votes.per_block_vote -> (context -> Contract_hash.t -> (context * 'a list) tzresult Lwt.t) -> - (context * 'a list * Toggle_votes.Liquidity_baking_toggle_EMA.t) tzresult + (context * 'a list * Per_block_votes.Liquidity_baking_toggle_EMA.t) tzresult Lwt.t end @@ -4780,8 +4780,8 @@ end module Adaptive_inflation : sig val update_ema : context -> - vote:Toggle_votes.toggle_vote -> - (context * Cycle.t option * Toggle_votes.Adaptive_inflation_launch_EMA.t) + vote:Per_block_votes.per_block_vote -> + (context * Cycle.t option * Per_block_votes.Adaptive_inflation_launch_EMA.t) tzresult Lwt.t diff --git a/src/proto_alpha/lib_protocol/apply.ml b/src/proto_alpha/lib_protocol/apply.ml index 9a90871d9a3b..b004f6fc6fd0 100644 --- a/src/proto_alpha/lib_protocol/apply.ml +++ b/src/proto_alpha/lib_protocol/apply.ml @@ -1946,8 +1946,8 @@ type application_state = { mode : mode; op_count : int; migration_balance_updates : Receipt.balance_updates; - liquidity_baking_toggle_ema : Toggle_votes.Liquidity_baking_toggle_EMA.t; - adaptive_inflation_toggle_ema : Toggle_votes.Adaptive_inflation_launch_EMA.t; + liquidity_baking_toggle_ema : Per_block_votes.Liquidity_baking_toggle_EMA.t; + adaptive_inflation_toggle_ema : Per_block_votes.Adaptive_inflation_launch_EMA.t; adaptive_inflation_launch_cycle : Cycle.t option; implicit_operations_results : Apply_results.packed_successful_manager_operation_result list; @@ -2305,10 +2305,10 @@ let may_start_new_cycle ctxt = Bootstrap.cycle_end ctxt last_cycle >|=? fun ctxt -> (ctxt, balance_updates, deactivated) -let apply_liquidity_baking_subsidy ctxt ~toggle_vote = +let apply_liquidity_baking_subsidy ctxt ~per_block_vote = Liquidity_baking.on_subsidy_allowed ctxt - ~toggle_vote + ~per_block_vote (fun ctxt liquidity_baking_cpmm_contract_hash -> let liquidity_baking_cpmm_contract = Contract.Originated liquidity_baking_cpmm_contract_hash @@ -2513,16 +2513,16 @@ let begin_application ctxt chain_id ~migration_balance_updates current_level ~round:block_header.protocol_data.contents.payload_round in - let toggle_vote = - block_header.Block_header.protocol_data.contents.toggle_votes + let per_block_vote = + block_header.Block_header.protocol_data.contents.per_block_votes .liquidity_baking_vote in let* ctxt, liquidity_baking_operations_results, liquidity_baking_toggle_ema = - apply_liquidity_baking_subsidy ctxt ~toggle_vote + apply_liquidity_baking_subsidy ctxt ~per_block_vote in let* ctxt, adaptive_inflation_launch_cycle, adaptive_inflation_toggle_ema = let adaptive_inflation_vote = - block_header.Block_header.protocol_data.contents.toggle_votes + block_header.Block_header.protocol_data.contents.per_block_votes .adaptive_inflation_vote in Adaptive_inflation.update_ema ctxt ~vote:adaptive_inflation_vote @@ -2584,13 +2584,13 @@ let begin_full_construction ctxt chain_id ~migration_balance_updates current_level ~round:block_data_contents.payload_round in - let toggle_vote = block_data_contents.toggle_votes.liquidity_baking_vote in + let per_block_vote = block_data_contents.per_block_votes.liquidity_baking_vote in let* ctxt, liquidity_baking_operations_results, liquidity_baking_toggle_ema = - apply_liquidity_baking_subsidy ctxt ~toggle_vote + apply_liquidity_baking_subsidy ctxt ~per_block_vote in let* ctxt, adaptive_inflation_launch_cycle, adaptive_inflation_toggle_ema = let adaptive_inflation_vote = - block_data_contents.toggle_votes.adaptive_inflation_vote + block_data_contents.per_block_votes.adaptive_inflation_vote in Adaptive_inflation.update_ema ctxt ~vote:adaptive_inflation_vote in @@ -2629,12 +2629,12 @@ let begin_partial_construction ctxt chain_id ~migration_balance_updates ~migration_operation_results ~predecessor_hash ~(predecessor_fitness : Fitness.raw) : application_state tzresult Lwt.t = let open Lwt_result_syntax in - let toggle_vote = Toggle_votes.Toggle_vote_pass in + let per_block_vote = Per_block_votes.Per_block_vote_pass in let* ctxt, liquidity_baking_operations_results, liquidity_baking_toggle_ema = - apply_liquidity_baking_subsidy ctxt ~toggle_vote + apply_liquidity_baking_subsidy ctxt ~per_block_vote in let* ctxt, adaptive_inflation_launch_cycle, adaptive_inflation_toggle_ema = - let adaptive_inflation_vote = Toggle_votes.Toggle_vote_pass in + let adaptive_inflation_vote = Per_block_votes.Per_block_vote_pass in Adaptive_inflation.update_ema ctxt ~vote:adaptive_inflation_vote in let* ctxt = diff --git a/src/proto_alpha/lib_protocol/apply.mli b/src/proto_alpha/lib_protocol/apply.mli index be1581c7bc55..24ddc9c8b16e 100644 --- a/src/proto_alpha/lib_protocol/apply.mli +++ b/src/proto_alpha/lib_protocol/apply.mli @@ -68,8 +68,8 @@ type application_state = { mode : mode; op_count : int; migration_balance_updates : Receipt.balance_updates; - liquidity_baking_toggle_ema : Toggle_votes.Liquidity_baking_toggle_EMA.t; - adaptive_inflation_toggle_ema : Toggle_votes.Adaptive_inflation_launch_EMA.t; + liquidity_baking_toggle_ema : Per_block_votes.Liquidity_baking_toggle_EMA.t; + adaptive_inflation_toggle_ema : Per_block_votes.Adaptive_inflation_launch_EMA.t; adaptive_inflation_launch_cycle : Cycle.t option; implicit_operations_results : Apply_results.packed_successful_manager_operation_result list; diff --git a/src/proto_alpha/lib_protocol/apply_results.ml b/src/proto_alpha/lib_protocol/apply_results.ml index d016357c64c0..7a4e86d3b08e 100644 --- a/src/proto_alpha/lib_protocol/apply_results.ml +++ b/src/proto_alpha/lib_protocol/apply_results.ml @@ -2598,8 +2598,8 @@ type block_metadata = { consumed_gas : Gas.Arith.fp; deactivated : Signature.Public_key_hash.t list; balance_updates : Receipt.balance_updates; - liquidity_baking_toggle_ema : Toggle_votes.Liquidity_baking_toggle_EMA.t; - adaptive_inflation_toggle_ema : Toggle_votes.Adaptive_inflation_launch_EMA.t; + liquidity_baking_toggle_ema : Per_block_votes.Liquidity_baking_toggle_EMA.t; + adaptive_inflation_toggle_ema : Per_block_votes.Adaptive_inflation_launch_EMA.t; adaptive_inflation_launch_cycle : Cycle.t option; implicit_operations_results : packed_successful_manager_operation_result list; dal_attestation : Dal.Attestation.t option; @@ -2681,10 +2681,10 @@ let block_metadata_encoding = (dft "balance_updates" Receipt.balance_updates_encoding []) (req "liquidity_baking_toggle_ema" - Toggle_votes.Liquidity_baking_toggle_EMA.encoding) + Per_block_votes.Liquidity_baking_toggle_EMA.encoding) (req "adaptive_inflation_toggle_ema" - Toggle_votes.Adaptive_inflation_launch_EMA.encoding) + Per_block_votes.Adaptive_inflation_launch_EMA.encoding) (opt "adaptive_inflation_activation_cycle" Cycle.encoding)) (obj5 (req diff --git a/src/proto_alpha/lib_protocol/apply_results.mli b/src/proto_alpha/lib_protocol/apply_results.mli index e921635b6298..fa9500b610b5 100644 --- a/src/proto_alpha/lib_protocol/apply_results.mli +++ b/src/proto_alpha/lib_protocol/apply_results.mli @@ -339,8 +339,8 @@ type block_metadata = { consumed_gas : Gas.Arith.fp; deactivated : Signature.Public_key_hash.t list; balance_updates : Receipt.balance_updates; - liquidity_baking_toggle_ema : Toggle_votes.Liquidity_baking_toggle_EMA.t; - adaptive_inflation_toggle_ema : Toggle_votes.Adaptive_inflation_launch_EMA.t; + liquidity_baking_toggle_ema : Per_block_votes.Liquidity_baking_toggle_EMA.t; + adaptive_inflation_toggle_ema : Per_block_votes.Adaptive_inflation_launch_EMA.t; adaptive_inflation_launch_cycle : Cycle.t option; implicit_operations_results : packed_successful_manager_operation_result list; dal_attestation : Dal.Attestation.t option; diff --git a/src/proto_alpha/lib_protocol/block_header_repr.ml b/src/proto_alpha/lib_protocol/block_header_repr.ml index a4e9b7ef65f1..e4665a93153f 100644 --- a/src/proto_alpha/lib_protocol/block_header_repr.ml +++ b/src/proto_alpha/lib_protocol/block_header_repr.ml @@ -30,7 +30,7 @@ type contents = { payload_round : Round_repr.t; seed_nonce_hash : Nonce_hash.t option; proof_of_work_nonce : bytes; - toggle_votes : Per_block_votes_repr.toggle_votes; + per_block_votes : Per_block_votes_repr.per_block_votes; } type protocol_data = {contents : contents; signature : Signature.t} @@ -76,7 +76,7 @@ let contents_encoding = payload_round; seed_nonce_hash; proof_of_work_nonce; - toggle_votes = {liquidity_baking_vote; adaptive_inflation_vote}; + per_block_votes = {liquidity_baking_vote; adaptive_inflation_vote}; } -> ( payload_hash, payload_round, @@ -95,7 +95,7 @@ let contents_encoding = payload_round; seed_nonce_hash; proof_of_work_nonce; - toggle_votes = {liquidity_baking_vote; adaptive_inflation_vote}; + per_block_votes = {liquidity_baking_vote; adaptive_inflation_vote}; }) (obj6 (req "payload_hash" Block_payload_hash.encoding) @@ -118,24 +118,24 @@ let contents_encoding = payload_round; seed_nonce_hash; proof_of_work_nonce; - toggle_votes; + per_block_votes; } -> ( payload_hash, payload_round, proof_of_work_nonce, seed_nonce_hash, - toggle_votes )) + per_block_votes )) (fun ( payload_hash, payload_round, proof_of_work_nonce, seed_nonce_hash, - toggle_votes ) -> + per_block_votes ) -> { payload_hash; payload_round; seed_nonce_hash; proof_of_work_nonce; - toggle_votes; + per_block_votes; }) (obj5 (req "payload_hash" Block_payload_hash.encoding) @@ -144,7 +144,7 @@ let contents_encoding = "proof_of_work_nonce" (Fixed.bytes Hex Constants_repr.proof_of_work_nonce_size)) (opt "seed_nonce_hash" Nonce_hash.encoding) - (req "toggle_votes" Per_block_votes_repr.toggle_votes_encoding)) + (req "per_block_votes" Per_block_votes_repr.per_block_votes_encoding)) in def "block_header.alpha.unsigned_contents" @@ splitted ~binary ~json @@ -205,10 +205,10 @@ let max_header_length = proof_of_work_nonce = Bytes.make Constants_repr.proof_of_work_nonce_size '0'; seed_nonce_hash = Some Nonce_hash.zero; - toggle_votes = + per_block_votes = { - liquidity_baking_vote = Toggle_vote_pass; - adaptive_inflation_vote = Toggle_vote_pass; + liquidity_baking_vote = Per_block_vote_pass; + adaptive_inflation_vote = Per_block_vote_pass; }; } in diff --git a/src/proto_alpha/lib_protocol/block_header_repr.mli b/src/proto_alpha/lib_protocol/block_header_repr.mli index 740d3352153e..f3600db1e159 100644 --- a/src/proto_alpha/lib_protocol/block_header_repr.mli +++ b/src/proto_alpha/lib_protocol/block_header_repr.mli @@ -30,7 +30,7 @@ type contents = { payload_round : Round_repr.t; seed_nonce_hash : Nonce_hash.t option; proof_of_work_nonce : bytes; - toggle_votes : Per_block_votes_repr.toggle_votes; + per_block_votes : Per_block_votes_repr.per_block_votes; } type protocol_data = {contents : contents; signature : Signature.t} diff --git a/src/proto_alpha/lib_protocol/dune b/src/proto_alpha/lib_protocol/dune index 88e24ffdb7d4..adfab8c731d9 100644 --- a/src/proto_alpha/lib_protocol/dune +++ b/src/proto_alpha/lib_protocol/dune @@ -114,7 +114,7 @@ Zk_rollup_circuit_public_inputs_repr Bond_id_repr Vote_repr - Toggle_EMA + Votes_EMA_repr Per_block_votes_repr Block_header_repr Destination_repr @@ -382,7 +382,7 @@ zk_rollup_circuit_public_inputs_repr.mli bond_id_repr.ml bond_id_repr.mli vote_repr.ml vote_repr.mli - toggle_EMA.ml toggle_EMA.mli + votes_EMA_repr.ml votes_EMA_repr.mli per_block_votes_repr.ml per_block_votes_repr.mli block_header_repr.ml block_header_repr.mli destination_repr.ml destination_repr.mli @@ -652,7 +652,7 @@ zk_rollup_circuit_public_inputs_repr.mli bond_id_repr.ml bond_id_repr.mli vote_repr.ml vote_repr.mli - toggle_EMA.ml toggle_EMA.mli + votes_EMA_repr.ml votes_EMA_repr.mli per_block_votes_repr.ml per_block_votes_repr.mli block_header_repr.ml block_header_repr.mli destination_repr.ml destination_repr.mli @@ -906,7 +906,7 @@ zk_rollup_circuit_public_inputs_repr.mli bond_id_repr.ml bond_id_repr.mli vote_repr.ml vote_repr.mli - toggle_EMA.ml toggle_EMA.mli + votes_EMA_repr.ml votes_EMA_repr.mli per_block_votes_repr.ml per_block_votes_repr.mli block_header_repr.ml block_header_repr.mli destination_repr.ml destination_repr.mli diff --git a/src/proto_alpha/lib_protocol/liquidity_baking_storage.ml b/src/proto_alpha/lib_protocol/liquidity_baking_storage.ml index cb2d85fc5e31..5b296fb94974 100644 --- a/src/proto_alpha/lib_protocol/liquidity_baking_storage.ml +++ b/src/proto_alpha/lib_protocol/liquidity_baking_storage.ml @@ -41,9 +41,9 @@ let on_cpmm_exists ctxt f = return (ctxt, []) | true -> f ctxt cpmm_contract -let update_toggle_ema ctxt ~toggle_vote = +let update_toggle_ema ctxt ~per_block_vote = get_toggle_ema ctxt >>=? fun old_ema -> - let new_ema = compute_new_liquidity_baking_ema ~toggle_vote old_ema in + let new_ema = compute_new_liquidity_baking_ema ~per_block_vote old_ema in Storage.Liquidity_baking.Toggle_ema.update ctxt (Liquidity_baking_toggle_EMA.to_int32 new_ema) @@ -53,8 +53,8 @@ let check_ema_below_threshold ctxt ema = Liquidity_baking_toggle_EMA.( ema < Constants_storage.liquidity_baking_toggle_ema_threshold ctxt) -let on_subsidy_allowed ctxt ~toggle_vote f = - update_toggle_ema ctxt ~toggle_vote >>=? fun (ctxt, toggle_ema) -> +let on_subsidy_allowed ctxt ~per_block_vote f = + update_toggle_ema ctxt ~per_block_vote >>=? fun (ctxt, toggle_ema) -> if check_ema_below_threshold ctxt toggle_ema then on_cpmm_exists ctxt f >|=? fun (ctxt, operation_results) -> (ctxt, operation_results, toggle_ema) diff --git a/src/proto_alpha/lib_protocol/liquidity_baking_storage.mli b/src/proto_alpha/lib_protocol/liquidity_baking_storage.mli index 23a2df6a591d..19641d588646 100644 --- a/src/proto_alpha/lib_protocol/liquidity_baking_storage.mli +++ b/src/proto_alpha/lib_protocol/liquidity_baking_storage.mli @@ -28,7 +28,7 @@ Liquidity Baking subsidy *) val get_cpmm_address : Raw_context.t -> Contract_hash.t tzresult Lwt.t -(** [on_subsidy_allowed ctxt ~toggle_vote f] updates the toggle EMA according to +(** [on_subsidy_allowed ctxt ~per_block_vote f] updates the toggle EMA according to [toggle_vote]. Then the callback function [f] is called if the following conditions are met: - the updated EMA is below the threshold, @@ -38,7 +38,7 @@ val get_cpmm_address : Raw_context.t -> Contract_hash.t tzresult Lwt.t see [apply_liquidity_baking_subsidy] in [apply.ml]. *) val on_subsidy_allowed : Raw_context.t -> - toggle_vote:Per_block_votes_repr.toggle_vote -> + per_block_vote:Per_block_votes_repr.per_block_vote -> (Raw_context.t -> Contract_hash.t -> (Raw_context.t * 'a list) tzresult Lwt.t) -> (Raw_context.t * 'a list * Per_block_votes_repr.Liquidity_baking_toggle_EMA.t) tzresult diff --git a/src/proto_alpha/lib_protocol/main.ml b/src/proto_alpha/lib_protocol/main.ml index 13d97f60ede5..8faa05f764d3 100644 --- a/src/proto_alpha/lib_protocol/main.ml +++ b/src/proto_alpha/lib_protocol/main.ml @@ -415,11 +415,11 @@ let init chain_id ctxt block_header = ({ payload_hash = Block_payload_hash.zero; payload_round = Alpha_context.Round.zero; - toggle_votes = + per_block_votes = { - liquidity_baking_vote = Alpha_context.Toggle_votes.Toggle_vote_pass; + liquidity_baking_vote = Alpha_context.Per_block_votes.Per_block_vote_pass; adaptive_inflation_vote = - Alpha_context.Toggle_votes.Toggle_vote_pass; + Alpha_context.Per_block_votes.Per_block_vote_pass; }; seed_nonce_hash = None; proof_of_work_nonce = diff --git a/src/proto_alpha/lib_protocol/per_block_votes_repr.ml b/src/proto_alpha/lib_protocol/per_block_votes_repr.ml index e0f17d3b174a..821ad0ed02be 100644 --- a/src/proto_alpha/lib_protocol/per_block_votes_repr.ml +++ b/src/proto_alpha/lib_protocol/per_block_votes_repr.ml @@ -24,16 +24,16 @@ (* *) (*****************************************************************************) -(** Options available for toggle per-block votes *) +(** Options available for per-block votes *) -type toggle_vote = Toggle_vote_on | Toggle_vote_off | Toggle_vote_pass +type per_block_vote = Per_block_vote_on | Per_block_vote_off | Per_block_vote_pass -type toggle_votes = { - liquidity_baking_vote : toggle_vote; - adaptive_inflation_vote : toggle_vote; +type per_block_votes = { + liquidity_baking_vote : per_block_vote; + adaptive_inflation_vote : per_block_vote; } -let toggle_vote_compact_encoding = +let per_block_vote_compact_encoding = let open Data_encoding in let open Compact in union @@ -41,35 +41,35 @@ let toggle_vote_compact_encoding = ~cases_tag_bits:0 [ case - ~title:"toggle_data_vote_on" + ~title:"per_block_vote_on" (payload (constant "on")) - (function Toggle_vote_on -> Some () | _ -> None) - (fun () -> Toggle_vote_on); + (function Per_block_vote_on -> Some () | _ -> None) + (fun () -> Per_block_vote_on); case - ~title:"toggle_data_vote_off" + ~title:"per_block_vote_off" (payload (constant "off")) - (function Toggle_vote_off -> Some () | _ -> None) - (fun () -> Toggle_vote_off); + (function Per_block_vote_off -> Some () | _ -> None) + (fun () -> Per_block_vote_off); case - ~title:"toggle_data_vote_pass" + ~title:"per_block_vote_pass" (payload (constant "pass")) - (function Toggle_vote_pass -> Some () | _ -> None) - (fun () -> Toggle_vote_pass); + (function Per_block_vote_pass -> Some () | _ -> None) + (fun () -> Per_block_vote_pass); ] let liquidity_baking_vote_encoding = let open Data_encoding in def "liquidity_baking_vote" - (Compact.make ~tag_size:`Uint8 toggle_vote_compact_encoding) + (Compact.make ~tag_size:`Uint8 per_block_vote_compact_encoding) let adaptive_inflation_vote_encoding = let open Data_encoding in def "adaptive_inflation_vote" - (Compact.make ~tag_size:`Uint8 toggle_vote_compact_encoding) + (Compact.make ~tag_size:`Uint8 per_block_vote_compact_encoding) -let toggle_votes_compact_encoding = +let per_block_votes_compact_encoding = let open Data_encoding in let open Compact in conv @@ -78,22 +78,22 @@ let toggle_votes_compact_encoding = (fun (liquidity_baking_vote, adaptive_inflation_vote) -> {liquidity_baking_vote; adaptive_inflation_vote}) (obj2 - (req "liquidity_baking_vote" toggle_vote_compact_encoding) - (req "adaptive_inflation_vote" toggle_vote_compact_encoding)) + (req "liquidity_baking_vote" per_block_vote_compact_encoding) + (req "adaptive_inflation_vote" per_block_vote_compact_encoding)) -let toggle_votes_encoding = +let per_block_votes_encoding = let open Data_encoding in def - "toggle_votes" - (Compact.make ~tag_size:`Uint8 toggle_votes_compact_encoding) + "per_block_votes" + (Compact.make ~tag_size:`Uint8 per_block_votes_compact_encoding) -module Liquidity_baking_toggle_EMA = Toggle_EMA.Make (struct +module Liquidity_baking_toggle_EMA = Votes_EMA_repr.Make (struct let baker_contribution = Z.of_int 500_000 let ema_max = 2_000_000_000l end) -module Adaptive_inflation_launch_EMA = Toggle_EMA.Make (struct +module Adaptive_inflation_launch_EMA = Votes_EMA_repr.Make (struct (* The baker_contribution parameter of the adaptive inflation activation vote was chosen so that 2 weeks are needed to move the EMA from 0% to 50% when all bakers vote On. @@ -111,14 +111,14 @@ module Adaptive_inflation_launch_EMA = Toggle_EMA.Make (struct let ema_max = 2_000_000_000l end) -let compute_new_liquidity_baking_ema ~toggle_vote ema = - match toggle_vote with - | Toggle_vote_pass -> ema - | Toggle_vote_off -> Liquidity_baking_toggle_EMA.update_ema_up ema - | Toggle_vote_on -> Liquidity_baking_toggle_EMA.update_ema_down ema - -let compute_new_adaptive_inflation_ema ~toggle_vote ema = - match toggle_vote with - | Toggle_vote_pass -> ema - | Toggle_vote_off -> Adaptive_inflation_launch_EMA.update_ema_down ema - | Toggle_vote_on -> Adaptive_inflation_launch_EMA.update_ema_up ema +let compute_new_liquidity_baking_ema ~per_block_vote ema = + match per_block_vote with + | Per_block_vote_pass -> ema + | Per_block_vote_off -> Liquidity_baking_toggle_EMA.update_ema_up ema + | Per_block_vote_on -> Liquidity_baking_toggle_EMA.update_ema_down ema + +let compute_new_adaptive_inflation_ema ~per_block_vote ema = + match per_block_vote with + | Per_block_vote_pass -> ema + | Per_block_vote_off -> Adaptive_inflation_launch_EMA.update_ema_down ema + | Per_block_vote_on -> Adaptive_inflation_launch_EMA.update_ema_up ema diff --git a/src/proto_alpha/lib_protocol/per_block_votes_repr.mli b/src/proto_alpha/lib_protocol/per_block_votes_repr.mli index adef7e167b53..63bfca962213 100644 --- a/src/proto_alpha/lib_protocol/per_block_votes_repr.mli +++ b/src/proto_alpha/lib_protocol/per_block_votes_repr.mli @@ -24,57 +24,57 @@ (* *) (*****************************************************************************) -(** Options available for toggle per-block votes *) +(** Options available for per-block votes *) -type toggle_vote = Toggle_vote_on | Toggle_vote_off | Toggle_vote_pass +type per_block_vote = Per_block_vote_on | Per_block_vote_off | Per_block_vote_pass -type toggle_votes = { - liquidity_baking_vote : toggle_vote; - adaptive_inflation_vote : toggle_vote; +type per_block_votes = { + liquidity_baking_vote : per_block_vote; + adaptive_inflation_vote : per_block_vote; } -val liquidity_baking_vote_encoding : toggle_vote Data_encoding.encoding +val liquidity_baking_vote_encoding : per_block_vote Data_encoding.encoding -val adaptive_inflation_vote_encoding : toggle_vote Data_encoding.encoding +val adaptive_inflation_vote_encoding : per_block_vote Data_encoding.encoding -val toggle_votes_encoding : toggle_votes Data_encoding.encoding +val per_block_votes_encoding : per_block_votes Data_encoding.encoding -module Liquidity_baking_toggle_EMA : Toggle_EMA.T +module Liquidity_baking_toggle_EMA : Votes_EMA_repr.T -module Adaptive_inflation_launch_EMA : Toggle_EMA.T +module Adaptive_inflation_launch_EMA : Votes_EMA_repr.T -(** [compute_new_liquidity_baking_ema ~toggle_vote old_ema] returns the value +(** [compute_new_liquidity_baking_ema ~per_block_vote old_ema] returns the value [new_ema] of the exponential moving average [old_ema] updated by the vote - [toggle_vote] interpreted as a vote to deactivate the liquidity baking + [per_block_vote] interpreted as a vote to deactivate the liquidity baking feature (Off increases the EMA). The EMA is updated as follows: - - if [toggle_vote] is [Toggle_vote_pass] then [new_ema] = [old_ema], - - if [toggle_vote] is [Toggle_vote_off], then [new_ema] = (1999 * ema[n] // 2000) + 1,000,000, - - if [toggle_vote] is [Toggle_vote_on], then [new_ema] = (1999 * ema[n] // 2000). + - if [per_block_vote] is [Per_block_vote_pass] then [new_ema] = [old_ema], + - if [per_block_vote] is [Per_block_vote_off], then [new_ema] = (1999 * ema[n] // 2000) + 1,000,000, + - if [per_block_vote] is [Per_block_vote_on], then [new_ema] = (1999 * ema[n] // 2000). The multiplication is performed in [Z.t] to avoid overflows, division is rounded toward 1,000,000,000 (the middle of the interval). *) val compute_new_liquidity_baking_ema : - toggle_vote:toggle_vote -> + per_block_vote:per_block_vote -> Liquidity_baking_toggle_EMA.t -> Liquidity_baking_toggle_EMA.t -(** [compute_new_adaptive_inflation_ema ~toggle_vote old_ema] returns the value +(** [compute_new_adaptive_inflation_ema ~per_block_vote old_ema] returns the value [new_ema] of the exponential moving average [old_ema] updated by the vote - [toggle_vote] interpreted as a vote to activate the adaptive inflation + [per_block_vote] interpreted as a vote to activate the adaptive inflation feature (Off decreases the EMA). The EMA is updated as follows: - - if [toggle_vote] is [Toggle_vote_pass] then [new_ema] = [old_ema], - - if [toggle_vote] is [Toggle_vote_off], then [new_ema] = (1999 * ema[n] // 2000), - - if [toggle_vote] is [Toggle_vote_on], then [new_ema] = (1999 * ema[n] // 2000) + 1,000,000. + - if [per_block_vote] is [Per_block_vote_pass] then [new_ema] = [old_ema], + - if [per_block_vote] is [Per_block_vote_off], then [new_ema] = (1999 * ema[n] // 2000), + - if [per_block_vote] is [Per_block_vote_on], then [new_ema] = (1999 * ema[n] // 2000) + 1,000,000. The multiplication is performed in [Z.t] to avoid overflows, division is rounded toward 1,000,000,000 (the middle of the interval). *) val compute_new_adaptive_inflation_ema : - toggle_vote:toggle_vote -> + per_block_vote:per_block_vote -> Adaptive_inflation_launch_EMA.t -> Adaptive_inflation_launch_EMA.t diff --git a/src/proto_alpha/lib_protocol/test/helpers/block.ml b/src/proto_alpha/lib_protocol/test/helpers/block.ml index 3edae223a5c0..a2727376bda8 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/block.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/block.ml @@ -169,8 +169,8 @@ module Forge = struct ?(proof_of_work_threshold = Tezos_protocol_alpha_parameters.Default_parameters.constants_test .proof_of_work_threshold) ~payload_hash ~payload_round - ?(liquidity_baking_toggle_vote = Toggle_votes.Toggle_vote_pass) - ?(adaptive_inflation_vote = Toggle_votes.Toggle_vote_pass) + ?(liquidity_baking_toggle_vote = Per_block_votes.Per_block_vote_pass) + ?(adaptive_inflation_vote = Per_block_votes.Per_block_vote_pass) ~seed_nonce_hash shell = naive_pow_miner ~proof_of_work_threshold @@ -181,7 +181,7 @@ module Forge = struct payload_round; proof_of_work_nonce = default_proof_of_work_nonce; seed_nonce_hash; - toggle_votes = + per_block_votes = { liquidity_baking_vote = liquidity_baking_toggle_vote; adaptive_inflation_vote; @@ -305,8 +305,8 @@ module Forge = struct ?(proof_of_work_threshold = Tezos_protocol_alpha_parameters.Default_parameters.constants_test .proof_of_work_threshold) ?seed_nonce_hash - ?(liquidity_baking_toggle_vote = Toggle_votes.Toggle_vote_pass) - ?(adaptive_inflation_vote = Toggle_votes.Toggle_vote_pass) ~payload_hash + ?(liquidity_baking_toggle_vote = Per_block_votes.Per_block_vote_pass) + ?(adaptive_inflation_vote = Per_block_votes.Per_block_vote_pass) ~payload_hash ~payload_round shell_header = naive_pow_miner ~proof_of_work_threshold @@ -314,7 +314,7 @@ module Forge = struct { Block_header.proof_of_work_nonce = default_proof_of_work_nonce; seed_nonce_hash; - toggle_votes = + per_block_votes = { liquidity_baking_vote = liquidity_baking_toggle_vote; adaptive_inflation_vote; @@ -1032,6 +1032,7 @@ let bake_n_with_liquidity_baking_toggle_ema ?baking_mode ?policy in (b, metadata.liquidity_baking_toggle_ema) + let current_cycle b = let blocks_per_cycle = b.constants.blocks_per_cycle in let current_level = b.header.shell.level in diff --git a/src/proto_alpha/lib_protocol/test/helpers/block.mli b/src/proto_alpha/lib_protocol/test/helpers/block.mli index 2837688f27cc..36e8d40a9412 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/block.mli +++ b/src/proto_alpha/lib_protocol/test/helpers/block.mli @@ -73,8 +73,8 @@ module Forge : sig val contents : ?proof_of_work_threshold:Int64.t -> ?seed_nonce_hash:Nonce_hash.t -> - ?liquidity_baking_toggle_vote:Toggle_votes.toggle_vote -> - ?adaptive_inflation_vote:Toggle_votes.toggle_vote -> + ?liquidity_baking_toggle_vote:Per_block_votes.per_block_vote -> + ?adaptive_inflation_vote:Per_block_votes.per_block_vote -> payload_hash:Block_payload_hash.t -> payload_round:Round.t -> Block_header.shell_header -> @@ -92,8 +92,8 @@ module Forge : sig ?policy:baker_policy -> ?timestamp:Timestamp.time -> ?operations:Operation.packed list -> - ?liquidity_baking_toggle_vote:Toggle_votes.toggle_vote -> - ?adaptive_inflation_vote:Toggle_votes.toggle_vote -> + ?liquidity_baking_toggle_vote:Per_block_votes.per_block_vote -> + ?adaptive_inflation_vote:Per_block_votes.per_block_vote -> t -> header tzresult Lwt.t @@ -210,8 +210,8 @@ val bake : ?timestamp:Timestamp.time -> ?operation:Operation.packed -> ?operations:Operation.packed list -> - ?liquidity_baking_toggle_vote:Toggle_votes.toggle_vote -> - ?adaptive_inflation_vote:Toggle_votes.toggle_vote -> + ?liquidity_baking_toggle_vote:Per_block_votes.per_block_vote -> + ?adaptive_inflation_vote:Per_block_votes.per_block_vote -> ?check_size:bool -> t -> t tzresult Lwt.t @@ -220,8 +220,8 @@ val bake : val bake_n : ?baking_mode:baking_mode -> ?policy:baker_policy -> - ?liquidity_baking_toggle_vote:Toggle_votes.toggle_vote -> - ?adaptive_inflation_vote:Toggle_votes.toggle_vote -> + ?liquidity_baking_toggle_vote:Per_block_votes.per_block_vote -> + ?adaptive_inflation_vote:Per_block_votes.per_block_vote -> int -> t -> block tzresult Lwt.t @@ -230,8 +230,8 @@ val bake_n : val bake_until_level : ?baking_mode:baking_mode -> ?policy:baker_policy -> - ?liquidity_baking_toggle_vote:Toggle_votes.toggle_vote -> - ?adaptive_inflation_vote:Toggle_votes.toggle_vote -> + ?liquidity_baking_toggle_vote:Per_block_votes.per_block_vote -> + ?adaptive_inflation_vote:Per_block_votes.per_block_vote -> Raw_level.t -> t -> block tzresult Lwt.t @@ -241,8 +241,8 @@ val bake_until_level : val bake_n_with_all_balance_updates : ?baking_mode:baking_mode -> ?policy:baker_policy -> - ?liquidity_baking_toggle_vote:Toggle_votes.toggle_vote -> - ?adaptive_inflation_vote:Toggle_votes.toggle_vote -> + ?liquidity_baking_toggle_vote:Per_block_votes.per_block_vote -> + ?adaptive_inflation_vote:Per_block_votes.per_block_vote -> int -> t -> (block * Alpha_context.Receipt.balance_updates) tzresult Lwt.t @@ -265,11 +265,11 @@ val bake_n_with_origination_results : val bake_n_with_liquidity_baking_toggle_ema : ?baking_mode:baking_mode -> ?policy:baker_policy -> - ?liquidity_baking_toggle_vote:Toggle_votes.toggle_vote -> - ?adaptive_inflation_vote:Toggle_votes.toggle_vote -> + ?liquidity_baking_toggle_vote:Per_block_votes.per_block_vote -> + ?adaptive_inflation_vote:Per_block_votes.per_block_vote -> int -> t -> - (block * Alpha_context.Toggle_votes.Liquidity_baking_toggle_EMA.t) tzresult + (block * Alpha_context.Per_block_votes.Liquidity_baking_toggle_EMA.t) tzresult Lwt.t (** Variant of [bake_n] that returns the block metadata of the last @@ -282,8 +282,8 @@ val bake_n_with_metadata : ?check_size:bool -> ?baking_mode:baking_mode -> ?allow_manager_failures:bool -> - ?liquidity_baking_toggle_vote:Per_block_votes_repr.toggle_vote -> - ?adaptive_inflation_vote:Per_block_votes_repr.toggle_vote -> + ?liquidity_baking_toggle_vote:Per_block_votes_repr.per_block_vote -> + ?adaptive_inflation_vote:Per_block_votes_repr.per_block_vote -> int -> block -> (block * block_header_metadata, Error_monad.tztrace) result Lwt.t @@ -298,8 +298,8 @@ val bake_n_with_metadata : val bake_while : ?baking_mode:baking_mode -> ?policy:baker_policy -> - ?liquidity_baking_toggle_vote:Per_block_votes_repr.toggle_vote -> - ?adaptive_inflation_vote:Per_block_votes_repr.toggle_vote -> + ?liquidity_baking_toggle_vote:Per_block_votes_repr.per_block_vote -> + ?adaptive_inflation_vote:Per_block_votes_repr.per_block_vote -> ?invariant:(block -> unit tzresult Lwt.t) -> (block -> bool) -> block -> @@ -310,8 +310,8 @@ val bake_while : val bake_while_with_metadata : ?baking_mode:baking_mode -> ?policy:baker_policy -> - ?liquidity_baking_toggle_vote:Per_block_votes_repr.toggle_vote -> - ?adaptive_inflation_vote:Per_block_votes_repr.toggle_vote -> + ?liquidity_baking_toggle_vote:Per_block_votes_repr.per_block_vote -> + ?adaptive_inflation_vote:Per_block_votes_repr.per_block_vote -> ?invariant:(block -> unit tzresult Lwt.t) -> (block -> block_header_metadata -> bool) -> block -> diff --git a/src/proto_alpha/lib_protocol/test/integration/test_adaptive_inflation_launch.ml b/src/proto_alpha/lib_protocol/test/integration/test_adaptive_inflation_launch.ml index eb88a16eac47..3da101f05744 100644 --- a/src/proto_alpha/lib_protocol/test/integration/test_adaptive_inflation_launch.ml +++ b/src/proto_alpha/lib_protocol/test/integration/test_adaptive_inflation_launch.ml @@ -114,7 +114,7 @@ let test_launch threshold expected_vote_duration () = let assert_ema_above_threshold ~loc (metadata : Protocol.Main.block_header_metadata) = let ema = - Protocol.Alpha_context.Toggle_votes.Adaptive_inflation_launch_EMA.to_int32 + Protocol.Alpha_context.Per_block_votes.Adaptive_inflation_launch_EMA.to_int32 metadata.adaptive_inflation_toggle_ema in Assert.lt_int32 ~loc threshold ema @@ -164,7 +164,7 @@ let test_launch threshold expected_vote_duration () = ~staking_over_baking_limit:1_000_000 ~baking_over_staking_edge_billionth:1_000_000_000 in - Block.bake ~operation ~adaptive_inflation_vote:Toggle_vote_on block + Block.bake ~operation ~adaptive_inflation_vote:Per_block_vote_on block in (* Initialization of a delegator account which will attempt to @@ -188,7 +188,7 @@ let test_launch threshold expected_vote_duration () = wannabe_costaker (Protocol.Alpha_context.Tez.of_mutez_exn 2_000_000_000_000L) in - Block.bake ~operation ~adaptive_inflation_vote:Toggle_vote_on block + Block.bake ~operation ~adaptive_inflation_vote:Per_block_vote_on block in let* block = let* operation = @@ -197,7 +197,7 @@ let test_launch threshold expected_vote_duration () = (B block) wannabe_costaker_account.pk in - Block.bake ~operation ~adaptive_inflation_vote:Toggle_vote_on block + Block.bake ~operation ~adaptive_inflation_vote:Per_block_vote_on block in let* block = let* operation = @@ -207,7 +207,7 @@ let test_launch threshold expected_vote_duration () = wannabe_costaker (Some delegate_pkh) in - Block.bake ~operation ~adaptive_inflation_vote:Toggle_vote_on block + Block.bake ~operation ~adaptive_inflation_vote:Per_block_vote_on block in (* Self-staking most of the remaining balance. *) let* block = @@ -217,7 +217,7 @@ let test_launch threshold expected_vote_duration () = delegate (Protocol.Alpha_context.Tez.of_mutez_exn 1_800_000_000_000L) in - Block.bake ~operation ~adaptive_inflation_vote:Toggle_vote_on block + Block.bake ~operation ~adaptive_inflation_vote:Per_block_vote_on block in (* We are now ready to activate the feature through by baking many @@ -227,10 +227,10 @@ let test_launch threshold expected_vote_duration () = let* block = Block.bake_while_with_metadata - ~adaptive_inflation_vote:Toggle_vote_on + ~adaptive_inflation_vote:Per_block_vote_on (fun _block metadata -> let ema = - Protocol.Alpha_context.Toggle_votes.Adaptive_inflation_launch_EMA + Protocol.Alpha_context.Per_block_votes.Adaptive_inflation_launch_EMA .to_int32 metadata.adaptive_inflation_toggle_ema in @@ -249,7 +249,7 @@ let test_launch threshold expected_vote_duration () = let* () = assert_is_not_yet_set_to_launch ~loc:__LOC__ block in (* We bake one more block to end the vote and set the feature to launch. *) let* block, metadata = - Block.bake_n_with_metadata ~adaptive_inflation_vote:Toggle_vote_on 1 block + Block.bake_n_with_metadata ~adaptive_inflation_vote:Per_block_vote_on 1 block in let* () = assert_ema_above_threshold ~loc:__LOC__ metadata in let* () = assert_level ~loc:__LOC__ block expected_vote_duration in diff --git a/src/proto_alpha/lib_protocol/test/integration/test_liquidity_baking.ml b/src/proto_alpha/lib_protocol/test/integration/test_liquidity_baking.ml index 61bdf96ffc01..1feb6fd98e91 100644 --- a/src/proto_alpha/lib_protocol/test/integration/test_liquidity_baking.ml +++ b/src/proto_alpha/lib_protocol/test/integration/test_liquidity_baking.ml @@ -124,8 +124,8 @@ let liquidity_baking_subsidies n () = >>=? fun () -> return_unit (* Test that subsidy shuts off at correct level alternating baking - blocks with liquidity_baking_toggle_vote set to [Toggle_vote_on], [Toggle_vote_off], and [Toggle_vote_pass] followed by [bake_after_toggle] blocks with it set to [Toggle_vote_pass]. *) -(* Expected level is roughly 2*(log(1-1/(2*p)) / log(0.999)) where [p] is the proportion [Toggle_vote_off / (Toggle_vote_on + Toggle_vote_off)]. *) + blocks with liquidity_baking_toggle_vote set to [Per_block_vote_on], [Per_block_vote_off], and [Per_block_vote_pass] followed by [bake_after_toggle] blocks with it set to [Per_block_vote_pass]. *) +(* Expected level is roughly 2*(log(1-1/(2*p)) / log(0.999)) where [p] is the proportion [Per_block_vote_off / (Per_block_vote_on + Per_block_vote_off)]. *) let liquidity_baking_toggle ~n_vote_on ~n_vote_off ~n_vote_pass expected_level bake_after () = Context.init1 ~consensus_threshold:0 () >>=? fun (blk, _contract) -> @@ -136,12 +136,12 @@ let liquidity_baking_toggle ~n_vote_on ~n_vote_off ~n_vote_pass expected_level >>=? fun liquidity_baking_subsidy -> let rec bake_stopping blk i = if i < expected_level then - Block.bake_n ~liquidity_baking_toggle_vote:Toggle_vote_on n_vote_on blk + Block.bake_n ~liquidity_baking_toggle_vote:Per_block_vote_on n_vote_on blk >>=? fun blk -> - Block.bake_n ~liquidity_baking_toggle_vote:Toggle_vote_off n_vote_off blk + Block.bake_n ~liquidity_baking_toggle_vote:Per_block_vote_off n_vote_off blk >>=? fun blk -> Block.bake_n - ~liquidity_baking_toggle_vote:Toggle_vote_pass + ~liquidity_baking_toggle_vote:Per_block_vote_pass n_vote_pass blk >>=? fun blk -> @@ -150,7 +150,7 @@ let liquidity_baking_toggle ~n_vote_on ~n_vote_off ~n_vote_pass expected_level in bake_stopping blk 0 >>=? fun blk -> Context.Contract.balance (B blk) liquidity_baking >>=? fun balance -> - Block.bake_n ~liquidity_baking_toggle_vote:Toggle_vote_pass bake_after blk + Block.bake_n ~liquidity_baking_toggle_vote:Per_block_vote_pass bake_after blk >>=? fun blk -> Assert.balance_is ~loc:__LOC__ (B blk) liquidity_baking balance >>=? fun () -> liquidity_baking_subsidy *? Int64.of_int (expected_level - 1) @@ -163,19 +163,19 @@ let liquidity_baking_toggle ~n_vote_on ~n_vote_off ~n_vote_pass expected_level expected_final_balance >>=? fun () -> return_unit -(* 100% of blocks have liquidity_baking_toggle_vote = Toggle_vote_off *) +(* 100% of blocks have liquidity_baking_toggle_vote = Per_block_vote_off *) let liquidity_baking_toggle_100 n () = liquidity_baking_toggle ~n_vote_on:0 ~n_vote_off:1 ~n_vote_pass:0 1386 n () -(* 80% of blocks have liquidity_baking_toggle_vote = Toggle_vote_off *) +(* 80% of blocks have liquidity_baking_toggle_vote = Per_block_vote_off *) let liquidity_baking_toggle_80 n () = liquidity_baking_toggle ~n_vote_on:1 ~n_vote_off:4 ~n_vote_pass:0 1963 n () -(* 60% of blocks have liquidity_baking_toggle_vote = Toggle_vote_off *) +(* 60% of blocks have liquidity_baking_toggle_vote = Per_block_vote_off *) let liquidity_baking_toggle_60 n () = liquidity_baking_toggle ~n_vote_on:2 ~n_vote_off:3 ~n_vote_pass:0 3583 n () -(* 50% of blocks have liquidity_baking_toggle_vote = Toggle_vote_off. +(* 50% of blocks have liquidity_baking_toggle_vote = Per_block_vote_off. Subsidy should not be stopped. Bakes until 100 blocks after the test sunset level of 4096 used in previous protocols. *) let liquidity_baking_toggle_50 () = @@ -187,9 +187,9 @@ let liquidity_baking_toggle_50 () = >>=? fun liquidity_baking_subsidy -> let rec bake_stopping blk i = if i < 4196 then - Block.bake ~liquidity_baking_toggle_vote:Toggle_vote_on blk + Block.bake ~liquidity_baking_toggle_vote:Per_block_vote_on blk >>=? fun blk -> - Block.bake ~liquidity_baking_toggle_vote:Toggle_vote_off blk + Block.bake ~liquidity_baking_toggle_vote:Per_block_vote_off blk >>=? fun blk -> bake_stopping blk (i + 2) else return blk in @@ -206,27 +206,27 @@ let liquidity_baking_toggle_50 () = expected_final_balance >>=? fun () -> return_unit -(* Test that the subsidy can restart if Toggle_vote_on votes regain majority. - Bake n_votes with Toggle_vote_off, check that the subsidy is paused, bake - n_votes with Toggle_vote_on, check that the subsidy flows. +(* Test that the subsidy can restart if Per_block_vote_on votes regain majority. + Bake n_votes with Per_block_vote_off, check that the subsidy is paused, bake + n_votes with Per_block_vote_on, check that the subsidy flows. *) let liquidity_baking_restart n_votes n () = Context.init1 ~consensus_threshold:0 () >>=? fun (blk, _contract) -> Context.get_liquidity_baking_cpmm_address (B blk) >>=? fun liquidity_baking -> let liquidity_baking = Alpha_context.Contract.Originated liquidity_baking in - Block.bake_n ~liquidity_baking_toggle_vote:Toggle_vote_off n_votes blk + Block.bake_n ~liquidity_baking_toggle_vote:Per_block_vote_off n_votes blk >>=? fun blk -> Context.Contract.balance (B blk) liquidity_baking >>=? fun balance_when_paused -> - Block.bake_n ~liquidity_baking_toggle_vote:Toggle_vote_pass n blk + Block.bake_n ~liquidity_baking_toggle_vote:Per_block_vote_pass n blk >>=? fun blk -> Assert.balance_is ~loc:__LOC__ (B blk) liquidity_baking balance_when_paused >>=? fun () -> - Block.bake_n ~liquidity_baking_toggle_vote:Toggle_vote_on n_votes blk + Block.bake_n ~liquidity_baking_toggle_vote:Per_block_vote_on n_votes blk >>=? fun blk -> Context.Contract.balance (B blk) liquidity_baking >>=? fun balance_when_restarted -> - Block.bake_n ~liquidity_baking_toggle_vote:Toggle_vote_pass n blk + Block.bake_n ~liquidity_baking_toggle_vote:Per_block_vote_pass n blk >>=? fun blk -> Context.get_liquidity_baking_subsidy (B blk) >>=? fun liquidity_baking_subsidy -> @@ -245,9 +245,9 @@ let liquidity_baking_toggle_ema n_vote_on n_vote_off level bake_after Context.init1 ~consensus_threshold:0 () >>=? fun (blk, _contract) -> let rec bake_escaping blk i = if i < level then - Block.bake_n ~liquidity_baking_toggle_vote:Toggle_vote_on n_vote_on blk + Block.bake_n ~liquidity_baking_toggle_vote:Per_block_vote_on n_vote_on blk >>=? fun blk -> - Block.bake_n ~liquidity_baking_toggle_vote:Toggle_vote_off n_vote_off blk + Block.bake_n ~liquidity_baking_toggle_vote:Per_block_vote_off n_vote_off blk >>=? fun blk -> bake_escaping blk (i + n_vote_on + n_vote_off) else return blk in @@ -258,7 +258,7 @@ let liquidity_baking_toggle_ema n_vote_on n_vote_off level bake_after Assert.leq_int ~loc:__LOC__ (toggle_ema - |> Alpha_context.Toggle_votes.Liquidity_baking_toggle_EMA.to_int32 + |> Alpha_context.Per_block_votes.Liquidity_baking_toggle_EMA.to_int32 |> Int32.to_int) expected_toggle_ema >>=? fun () -> return_unit @@ -450,47 +450,47 @@ let tests = `Quick (liquidity_baking_subsidies 64); Tztest.tztest - "liquidity baking toggle vote with 100% of bakers voting Toggle_vote_off \ + "liquidity baking toggle vote with 100% of bakers voting Per_block_vote_off \ baking one block longer" `Quick (liquidity_baking_toggle_100 1); Tztest.tztest - "liquidity baking toggle vote with 100% of bakers voting Toggle_vote_off \ + "liquidity baking toggle vote with 100% of bakers voting Per_block_vote_off \ baking two blocks longer" `Quick (liquidity_baking_toggle_100 2); Tztest.tztest - "liquidity baking toggle vote with 100% of bakers voting Toggle_vote_off \ + "liquidity baking toggle vote with 100% of bakers voting Per_block_vote_off \ baking 100 blocks longer" `Quick (liquidity_baking_toggle_100 100); Tztest.tztest - "liquidity baking toggle vote with 80% of bakers voting Toggle_vote_off \ + "liquidity baking toggle vote with 80% of bakers voting Per_block_vote_off \ baking one block longer" `Quick (liquidity_baking_toggle_80 1); Tztest.tztest - "liquidity baking toggle vote with 80% of bakers voting Toggle_vote_off \ + "liquidity baking toggle vote with 80% of bakers voting Per_block_vote_off \ baking two blocks longer" `Quick (liquidity_baking_toggle_80 2); Tztest.tztest - "liquidity baking toggle vote with 80% of bakers voting Toggle_vote_off \ + "liquidity baking toggle vote with 80% of bakers voting Per_block_vote_off \ baking 100 blocks longer" `Quick (liquidity_baking_toggle_80 100); Tztest.tztest - "liquidity baking toggle vote with 60% of bakers voting Toggle_vote_off \ + "liquidity baking toggle vote with 60% of bakers voting Per_block_vote_off \ baking one block longer" `Quick (liquidity_baking_toggle_60 1); Tztest.tztest - "liquidity baking toggle vote with 60% of bakers voting Toggle_vote_off \ + "liquidity baking toggle vote with 60% of bakers voting Per_block_vote_off \ baking two blocks longer" `Quick (liquidity_baking_toggle_60 2); Tztest.tztest - "liquidity baking toggle vote with 60% of bakers voting Toggle_vote_off \ + "liquidity baking toggle vote with 60% of bakers voting Per_block_vote_off \ baking 100 blocks longer" `Quick (liquidity_baking_toggle_60 100); @@ -506,7 +506,7 @@ let tests = (liquidity_baking_restart 2000 1); Tztest.tztest "liquidity baking toggle ema in block metadata is zero with no bakers \ - voting Toggle_vote_off." + voting Per_block_vote_off." `Quick liquidity_baking_toggle_ema_zero; Tztest.tztest diff --git a/src/proto_alpha/lib_protocol/test/unit/test_adaptive_inflation_ema.ml b/src/proto_alpha/lib_protocol/test/unit/test_adaptive_inflation_ema.ml index 35b3208fb121..99d102069758 100644 --- a/src/proto_alpha/lib_protocol/test/unit/test_adaptive_inflation_ema.ml +++ b/src/proto_alpha/lib_protocol/test/unit/test_adaptive_inflation_ema.ml @@ -33,23 +33,23 @@ *) open Protocol -module Toggle_EMA = Per_block_votes_repr.Adaptive_inflation_launch_EMA +module Votes_EMA = Per_block_votes_repr.Adaptive_inflation_launch_EMA -let ema_of_int32 ema = Toggle_EMA.of_int32 ema >|= Environment.wrap_tzresult +let ema_of_int32 ema = Votes_EMA.of_int32 ema >|= Environment.wrap_tzresult -let ema_to_int32 = Toggle_EMA.to_int32 +let ema_to_int32 = Votes_EMA.to_int32 -let compute_new_ema ~toggle_vote ema = - Per_block_votes_repr.compute_new_adaptive_inflation_ema ~toggle_vote ema +let compute_new_ema ~per_block_vote ema = + Per_block_votes_repr.compute_new_adaptive_inflation_ema ~per_block_vote ema |> ema_to_int32 (* Folds compute_new_ema on a list of votes *) -let compute_new_ema_n toggle_votes initial_ema = +let compute_new_ema_n per_block_votes initial_ema = List.fold_left (fun ema toggle_vote -> - Per_block_votes_repr.compute_new_adaptive_inflation_ema ~toggle_vote ema) + Per_block_votes_repr.compute_new_adaptive_inflation_ema ~per_block_vote ema) initial_ema - toggle_votes + per_block_votes |> ema_to_int32 let ema_range = @@ -100,7 +100,7 @@ let test_ema_pass () = ema_of_int32 old_ema >>=? fun ema -> Assert.equal_int32 ~loc:__LOC__ - (compute_new_ema ~toggle_vote:Toggle_vote_pass ema) + (compute_new_ema ~per_block_vote:Per_block_vote_pass ema) old_ema) ema_range @@ -109,7 +109,7 @@ let test_ema_in_bound_on () = List.iter_es (fun old_ema -> ema_of_int32 old_ema >>=? fun ema -> - let new_ema = compute_new_ema ~toggle_vote:Toggle_vote_on ema in + let new_ema = compute_new_ema ~per_block_vote:Per_block_vote_on ema in Assert.leq_int32 ~loc:__LOC__ 0l new_ema >>=? fun () -> Assert.leq_int32 ~loc:__LOC__ new_ema 2_000_000_000l) ema_range @@ -123,7 +123,7 @@ let test_ema_increases_on () = Assert.lt_int32 ~loc:__LOC__ old_ema - (compute_new_ema ~toggle_vote:Toggle_vote_on ema)) + (compute_new_ema ~per_block_vote:Per_block_vote_on ema)) (List.filter (fun ema -> Compare.Int32.(ema < 1_999_000_000l)) ema_range) (* Test that the increase in EMA caused by an On vote is bounded by 1,000,000 *) @@ -133,7 +133,7 @@ let test_ema_increases_on_bound () = ema_of_int32 old_ema >>=? fun ema -> Assert.leq_int32 ~loc:__LOC__ - (Int32.sub (compute_new_ema ~toggle_vote:Toggle_vote_on ema) old_ema) + (Int32.sub (compute_new_ema ~per_block_vote:Per_block_vote_on ema) old_ema) 1_000_000l) ema_range @@ -142,7 +142,7 @@ let test_ema_in_bound_off () = List.iter_es (fun old_ema -> ema_of_int32 old_ema >>=? fun ema -> - let new_ema = compute_new_ema ~toggle_vote:Toggle_vote_off ema in + let new_ema = compute_new_ema ~per_block_vote:Per_block_vote_off ema in Assert.leq_int32 ~loc:__LOC__ 0l new_ema >>=? fun () -> Assert.leq_int32 ~loc:__LOC__ new_ema 2_000_000_000l) ema_range @@ -155,7 +155,7 @@ let test_ema_decreases_off () = ema_of_int32 old_ema >>=? fun ema -> Assert.lt_int32 ~loc:__LOC__ - (compute_new_ema ~toggle_vote:Toggle_vote_off ema) + (compute_new_ema ~per_block_vote:Per_block_vote_off ema) old_ema) (List.filter (fun ema -> Compare.Int32.(ema > 1_000_000l)) ema_range) @@ -166,7 +166,7 @@ let test_ema_decreases_off_bound () = ema_of_int32 old_ema >>=? fun ema -> Assert.leq_int32 ~loc:__LOC__ - (Int32.sub (compute_new_ema ~toggle_vote:Toggle_vote_off ema) old_ema) + (Int32.sub (compute_new_ema ~per_block_vote:Per_block_vote_off ema) old_ema) 1_000_000l) ema_range @@ -177,7 +177,7 @@ let test_ema_many_on () = Assert.leq_int32 ~loc:__LOC__ (compute_new_ema_n - (Stdlib.List.init 80321 (fun _ -> Toggle_vote_on)) + (Stdlib.List.init 80321 (fun _ -> Per_block_vote_on)) initial_ema) 1_000_000_000l >>=? fun () -> @@ -185,7 +185,7 @@ let test_ema_many_on () = ~loc:__LOC__ 1_000_000_000l (compute_new_ema_n - (Stdlib.List.init 80642 (fun _ -> Toggle_vote_on)) + (Stdlib.List.init 80642 (fun _ -> Per_block_vote_on)) initial_ema) (* Test that 80642 Off votes are needed to move from 100% to 50%. *) @@ -196,13 +196,13 @@ let test_ema_many_off () = ~loc:__LOC__ 1_000_000_000l (compute_new_ema_n - (Stdlib.List.init 80321 (fun _ -> Toggle_vote_off)) + (Stdlib.List.init 80321 (fun _ -> Per_block_vote_off)) initial_ema) >>=? fun () -> Assert.leq_int32 ~loc:__LOC__ (compute_new_ema_n - (Stdlib.List.init 80642 (fun _ -> Toggle_vote_off)) + (Stdlib.List.init 80642 (fun _ -> Per_block_vote_off)) initial_ema) 1_000_000_000l @@ -213,7 +213,7 @@ let test_ema_many_many_on () = Assert.leq_int32 ~loc:__LOC__ (compute_new_ema_n - (Stdlib.List.init 187258 (fun _ -> Toggle_vote_on)) + (Stdlib.List.init 187258 (fun _ -> Per_block_vote_on)) initial_ema) 1_600_000_000l >>=? fun () -> @@ -221,7 +221,7 @@ let test_ema_many_many_on () = ~loc:__LOC__ 1_600_000_000l (compute_new_ema_n - (Stdlib.List.init 187259 (fun _ -> Toggle_vote_on)) + (Stdlib.List.init 187259 (fun _ -> Per_block_vote_on)) initial_ema) (* Test that the EMA update function is symmetric: @@ -235,9 +235,9 @@ let test_ema_symmetry () = let opposite_ema = Int32.(sub 2_000_000_000l ema) in ema_of_int32 ema >>=? fun ema -> ema_of_int32 opposite_ema >>=? fun opposite_ema -> - let new_ema = compute_new_ema ~toggle_vote:Toggle_vote_off ema in + let new_ema = compute_new_ema ~per_block_vote:Per_block_vote_off ema in let new_opposite_ema = - compute_new_ema ~toggle_vote:Toggle_vote_on opposite_ema + compute_new_ema ~per_block_vote:Per_block_vote_on opposite_ema in Assert.equal_int32 ~loc:__LOC__ diff --git a/src/proto_alpha/lib_protocol/test/unit/test_liquidity_baking_repr.ml b/src/proto_alpha/lib_protocol/test/unit/test_liquidity_baking_repr.ml index 06f7e471658d..bf895ab8547b 100644 --- a/src/proto_alpha/lib_protocol/test/unit/test_liquidity_baking_repr.ml +++ b/src/proto_alpha/lib_protocol/test/unit/test_liquidity_baking_repr.ml @@ -32,23 +32,23 @@ *) open Protocol -module Toggle_EMA = Per_block_votes_repr.Liquidity_baking_toggle_EMA +module Votes_EMA = Per_block_votes_repr.Liquidity_baking_toggle_EMA -let ema_of_int32 ema = Toggle_EMA.of_int32 ema >|= Environment.wrap_tzresult +let ema_of_int32 ema = Votes_EMA.of_int32 ema >|= Environment.wrap_tzresult -let ema_to_int32 = Toggle_EMA.to_int32 +let ema_to_int32 = Votes_EMA.to_int32 -let compute_new_ema ~toggle_vote ema = - Per_block_votes_repr.compute_new_liquidity_baking_ema ~toggle_vote ema +let compute_new_ema ~per_block_vote ema = + Per_block_votes_repr.compute_new_liquidity_baking_ema ~per_block_vote ema |> ema_to_int32 (* Folds compute_new_ema on a list of votes *) -let compute_new_ema_n toggle_votes initial_ema = +let compute_new_ema_n per_block_votes initial_ema = List.fold_left (fun ema toggle_vote -> - Per_block_votes_repr.compute_new_liquidity_baking_ema ~toggle_vote ema) + Per_block_votes_repr.compute_new_liquidity_baking_ema ~per_block_vote ema) initial_ema - toggle_votes + per_block_votes |> ema_to_int32 let ema_range = @@ -99,7 +99,7 @@ let test_ema_pass () = ema_of_int32 old_ema >>=? fun ema -> Assert.equal_int32 ~loc:__LOC__ - (compute_new_ema ~toggle_vote:Toggle_vote_pass ema) + (compute_new_ema ~per_block_vote:Per_block_vote_pass ema) old_ema) ema_range @@ -108,7 +108,7 @@ let test_ema_in_bound_off () = List.iter_es (fun old_ema -> ema_of_int32 old_ema >>=? fun ema -> - let new_ema = compute_new_ema ~toggle_vote:Toggle_vote_off ema in + let new_ema = compute_new_ema ~per_block_vote:Per_block_vote_off ema in Assert.leq_int32 ~loc:__LOC__ 0l new_ema >>=? fun () -> Assert.leq_int32 ~loc:__LOC__ new_ema 2_000_000_000l) ema_range @@ -122,7 +122,7 @@ let test_ema_increases_off () = Assert.lt_int32 ~loc:__LOC__ old_ema - (compute_new_ema ~toggle_vote:Toggle_vote_off ema)) + (compute_new_ema ~per_block_vote:Per_block_vote_off ema)) (List.filter (fun ema -> Compare.Int32.(ema < 1_999_999_000l)) ema_range) (* Test that the increase in EMA caused by an Off vote is bounded by 1,000,000 *) @@ -132,7 +132,7 @@ let test_ema_increases_off_bound () = ema_of_int32 old_ema >>=? fun ema -> Assert.leq_int32 ~loc:__LOC__ - (Int32.sub (compute_new_ema ~toggle_vote:Toggle_vote_off ema) old_ema) + (Int32.sub (compute_new_ema ~per_block_vote:Per_block_vote_off ema) old_ema) 1_000_000l) ema_range @@ -141,7 +141,7 @@ let test_ema_in_bound_on () = List.iter_es (fun old_ema -> ema_of_int32 old_ema >>=? fun ema -> - let new_ema = compute_new_ema ~toggle_vote:Toggle_vote_on ema in + let new_ema = compute_new_ema ~per_block_vote:Per_block_vote_on ema in Assert.leq_int32 ~loc:__LOC__ 0l new_ema >>=? fun () -> Assert.leq_int32 ~loc:__LOC__ new_ema 2_000_000_000l) ema_range @@ -154,7 +154,7 @@ let test_ema_decreases_on () = ema_of_int32 old_ema >>=? fun ema -> Assert.lt_int32 ~loc:__LOC__ - (compute_new_ema ~toggle_vote:Toggle_vote_on ema) + (compute_new_ema ~per_block_vote:Per_block_vote_on ema) old_ema) (List.filter (fun ema -> Compare.Int32.(ema > 1000l)) ema_range) @@ -165,7 +165,7 @@ let test_ema_decreases_on_bound () = ema_of_int32 old_ema >>=? fun ema -> Assert.leq_int32 ~loc:__LOC__ - (Int32.sub (compute_new_ema ~toggle_vote:Toggle_vote_on ema) old_ema) + (Int32.sub (compute_new_ema ~per_block_vote:Per_block_vote_on ema) old_ema) 1_000_000l) ema_range @@ -176,7 +176,7 @@ let test_ema_many_off () = Assert.leq_int32 ~loc:__LOC__ (compute_new_ema_n - (Stdlib.List.init 1385 (fun _ -> Toggle_vote_off)) + (Stdlib.List.init 1385 (fun _ -> Per_block_vote_off)) initial_ema) 1_000_000_000l >>=? fun () -> @@ -184,7 +184,7 @@ let test_ema_many_off () = ~loc:__LOC__ 1_000_000_000l (compute_new_ema_n - (Stdlib.List.init 1386 (fun _ -> Toggle_vote_off)) + (Stdlib.List.init 1386 (fun _ -> Per_block_vote_off)) initial_ema) (* Test that 1385 On votes are needed to reach the threshold from the max value of the EMA (2,000,000,000). *) @@ -195,13 +195,13 @@ let test_ema_many_on () = ~loc:__LOC__ 1_000_000_000l (compute_new_ema_n - (Stdlib.List.init 1385 (fun _ -> Toggle_vote_on)) + (Stdlib.List.init 1385 (fun _ -> Per_block_vote_on)) initial_ema) >>=? fun () -> Assert.leq_int32 ~loc:__LOC__ (compute_new_ema_n - (Stdlib.List.init 1386 (fun _ -> Toggle_vote_on)) + (Stdlib.List.init 1386 (fun _ -> Per_block_vote_on)) initial_ema) 1_000_000_000l @@ -216,9 +216,9 @@ let test_ema_symmetry () = let opposite_ema = Int32.(sub 2_000_000_000l ema) in ema_of_int32 ema >>=? fun ema -> ema_of_int32 opposite_ema >>=? fun opposite_ema -> - let new_ema = compute_new_ema ~toggle_vote:Toggle_vote_on ema in + let new_ema = compute_new_ema ~per_block_vote:Per_block_vote_on ema in let new_opposite_ema = - compute_new_ema ~toggle_vote:Toggle_vote_off opposite_ema + compute_new_ema ~per_block_vote:Per_block_vote_off opposite_ema in Assert.equal_int32 ~loc:__LOC__ diff --git a/src/proto_alpha/lib_protocol/toggle_EMA.ml b/src/proto_alpha/lib_protocol/votes_EMA_repr.ml similarity index 100% rename from src/proto_alpha/lib_protocol/toggle_EMA.ml rename to src/proto_alpha/lib_protocol/votes_EMA_repr.ml diff --git a/src/proto_alpha/lib_protocol/toggle_EMA.mli b/src/proto_alpha/lib_protocol/votes_EMA_repr.mli similarity index 100% rename from src/proto_alpha/lib_protocol/toggle_EMA.mli rename to src/proto_alpha/lib_protocol/votes_EMA_repr.mli -- GitLab From be3f550eb9518e92f2da613fdf6afc449401b4d3 Mon Sep 17 00:00:00 2001 From: Philippe Wang Date: Tue, 27 Jun 2023 11:41:06 -0700 Subject: [PATCH 3/6] Protocol: continued: rename toggle vote to per-block vote --- .../lib_delegate/baking_commands.ml | 8 ++-- .../lib_delegate/baking_configuration.ml | 6 ++- .../lib_delegate/baking_configuration.mli | 3 +- src/proto_alpha/lib_delegate/baking_events.ml | 6 ++- .../lib_delegate/per_block_vote_file.ml | 3 +- src/proto_alpha/lib_protocol/apply.ml | 7 ++- src/proto_alpha/lib_protocol/apply.mli | 3 +- src/proto_alpha/lib_protocol/apply_results.ml | 3 +- .../lib_protocol/apply_results.mli | 3 +- src/proto_alpha/lib_protocol/main.ml | 3 +- .../lib_protocol/per_block_votes_repr.ml | 5 +- .../lib_protocol/per_block_votes_repr.mli | 5 +- .../lib_protocol/test/helpers/block.ml | 5 +- .../test_adaptive_inflation_launch.ml | 8 +++- .../test/integration/test_liquidity_baking.ml | 46 +++++++++++-------- .../test/unit/test_adaptive_inflation_ema.ml | 14 ++++-- .../test/unit/test_liquidity_baking_repr.ml | 10 ++-- 17 files changed, 88 insertions(+), 50 deletions(-) diff --git a/src/proto_alpha/lib_delegate/baking_commands.ml b/src/proto_alpha/lib_delegate/baking_commands.ml index 2311ceaff64c..fc68cac09f6b 100644 --- a/src/proto_alpha/lib_delegate/baking_commands.ml +++ b/src/proto_alpha/lib_delegate/baking_commands.ml @@ -147,7 +147,7 @@ let keep_alive_arg = ~long:"keep-alive" () -let toggle_vote_parameter = +let per_block_vote_parameter = Tezos_clic.parameter ~autocomplete:(fun _ctxt -> return ["on"; "off"; "pass"]) (let open Protocol.Alpha_context.Per_block_votes in @@ -169,7 +169,7 @@ let liquidity_baking_toggle_vote_arg = abstain. Note that this \"option\" is mandatory!" ~long:"liquidity-baking-toggle-vote" ~placeholder:"vote" - toggle_vote_parameter + per_block_vote_parameter let adaptive_inflation_vote_arg = Tezos_clic.arg @@ -180,7 +180,7 @@ let adaptive_inflation_vote_arg = vote, default value is \"pass\"." ~long:"adaptive-inflation-vote" ~placeholder:"vote" - toggle_vote_parameter + per_block_vote_parameter let get_delegates (cctxt : Protocol_client_context.full) (pkhs : Signature.public_key_hash list) = @@ -527,7 +527,7 @@ let run_baker >>= fun per_block_vote_file -> (* We don't let the user run the baker without providing some option (CLI, file path, or file in default location) for - the toggle votes. *) + the per-block votes. *) Per_block_vote_file.load_per_block_votes_config ~default_liquidity_baking_vote:liquidity_baking_vote ~default_adaptive_inflation_vote:adaptive_inflation_vote diff --git a/src/proto_alpha/lib_delegate/baking_configuration.ml b/src/proto_alpha/lib_delegate/baking_configuration.ml index 0e2e4fe44953..9721f4942265 100644 --- a/src/proto_alpha/lib_delegate/baking_configuration.ml +++ b/src/proto_alpha/lib_delegate/baking_configuration.ml @@ -79,7 +79,8 @@ type state_recorder_config = Filesystem | Disabled type per_block_votes_config = { vote_file : string option; liquidity_baking_vote : Protocol.Alpha_context.Per_block_votes.per_block_vote; - adaptive_inflation_vote : Protocol.Alpha_context.Per_block_votes.per_block_vote; + adaptive_inflation_vote : + Protocol.Alpha_context.Per_block_votes.per_block_vote; } type t = { @@ -117,7 +118,8 @@ let default_user_activated_upgrades = [] let default_votes_config = { vote_file = None; - liquidity_baking_vote = Protocol.Alpha_context.Per_block_votes.Per_block_vote_pass; + liquidity_baking_vote = + Protocol.Alpha_context.Per_block_votes.Per_block_vote_pass; adaptive_inflation_vote = Protocol.Alpha_context.Per_block_votes.Per_block_vote_pass; } diff --git a/src/proto_alpha/lib_delegate/baking_configuration.mli b/src/proto_alpha/lib_delegate/baking_configuration.mli index 945f4e18cbb5..00404aa3ea4a 100644 --- a/src/proto_alpha/lib_delegate/baking_configuration.mli +++ b/src/proto_alpha/lib_delegate/baking_configuration.mli @@ -54,7 +54,8 @@ type state_recorder_config = Filesystem | Disabled type per_block_votes_config = { vote_file : string option; liquidity_baking_vote : Protocol.Alpha_context.Per_block_votes.per_block_vote; - adaptive_inflation_vote : Protocol.Alpha_context.Per_block_votes.per_block_vote; + adaptive_inflation_vote : + Protocol.Alpha_context.Per_block_votes.per_block_vote; } type t = { diff --git a/src/proto_alpha/lib_delegate/baking_events.ml b/src/proto_alpha/lib_delegate/baking_events.ml index ba6083186a00..b9722b6dd3d9 100644 --- a/src/proto_alpha/lib_delegate/baking_events.ml +++ b/src/proto_alpha/lib_delegate/baking_events.ml @@ -806,7 +806,8 @@ module Actions = struct ~level:Notice ~msg:"Voting {value} for adaptive inflation vote" ( "value", - Protocol.Alpha_context.Per_block_votes.adaptive_inflation_vote_encoding ) + Protocol.Alpha_context.Per_block_votes.adaptive_inflation_vote_encoding + ) let no_dal_node = declare_0 @@ -1038,7 +1039,8 @@ module Per_block_votes = struct ~level:Notice ~msg:"adaptive inflation vote = {value}" ( "value", - Protocol.Alpha_context.Per_block_votes.adaptive_inflation_vote_encoding ) + Protocol.Alpha_context.Per_block_votes.adaptive_inflation_vote_encoding + ) end module Selection = struct diff --git a/src/proto_alpha/lib_delegate/per_block_vote_file.ml b/src/proto_alpha/lib_delegate/per_block_vote_file.ml index c736ce1ffd03..5473692de015 100644 --- a/src/proto_alpha/lib_delegate/per_block_vote_file.ml +++ b/src/proto_alpha/lib_delegate/per_block_vote_file.ml @@ -46,7 +46,8 @@ let vote_file_content_encoding = (obj2 (req "liquidity_baking_toggle_vote" - Protocol.Alpha_context.Per_block_votes.liquidity_baking_vote_encoding) + Protocol.Alpha_context.Per_block_votes + .liquidity_baking_vote_encoding) (opt "adaptive_inflation_vote" Protocol.Alpha_context.Per_block_votes diff --git a/src/proto_alpha/lib_protocol/apply.ml b/src/proto_alpha/lib_protocol/apply.ml index b004f6fc6fd0..54fa34224eeb 100644 --- a/src/proto_alpha/lib_protocol/apply.ml +++ b/src/proto_alpha/lib_protocol/apply.ml @@ -1947,7 +1947,8 @@ type application_state = { op_count : int; migration_balance_updates : Receipt.balance_updates; liquidity_baking_toggle_ema : Per_block_votes.Liquidity_baking_toggle_EMA.t; - adaptive_inflation_toggle_ema : Per_block_votes.Adaptive_inflation_launch_EMA.t; + adaptive_inflation_toggle_ema : + Per_block_votes.Adaptive_inflation_launch_EMA.t; adaptive_inflation_launch_cycle : Cycle.t option; implicit_operations_results : Apply_results.packed_successful_manager_operation_result list; @@ -2584,7 +2585,9 @@ let begin_full_construction ctxt chain_id ~migration_balance_updates current_level ~round:block_data_contents.payload_round in - let per_block_vote = block_data_contents.per_block_votes.liquidity_baking_vote in + let per_block_vote = + block_data_contents.per_block_votes.liquidity_baking_vote + in let* ctxt, liquidity_baking_operations_results, liquidity_baking_toggle_ema = apply_liquidity_baking_subsidy ctxt ~per_block_vote in diff --git a/src/proto_alpha/lib_protocol/apply.mli b/src/proto_alpha/lib_protocol/apply.mli index 24ddc9c8b16e..46fa86210012 100644 --- a/src/proto_alpha/lib_protocol/apply.mli +++ b/src/proto_alpha/lib_protocol/apply.mli @@ -69,7 +69,8 @@ type application_state = { op_count : int; migration_balance_updates : Receipt.balance_updates; liquidity_baking_toggle_ema : Per_block_votes.Liquidity_baking_toggle_EMA.t; - adaptive_inflation_toggle_ema : Per_block_votes.Adaptive_inflation_launch_EMA.t; + adaptive_inflation_toggle_ema : + Per_block_votes.Adaptive_inflation_launch_EMA.t; adaptive_inflation_launch_cycle : Cycle.t option; implicit_operations_results : Apply_results.packed_successful_manager_operation_result list; diff --git a/src/proto_alpha/lib_protocol/apply_results.ml b/src/proto_alpha/lib_protocol/apply_results.ml index 7a4e86d3b08e..e1f33bd45146 100644 --- a/src/proto_alpha/lib_protocol/apply_results.ml +++ b/src/proto_alpha/lib_protocol/apply_results.ml @@ -2599,7 +2599,8 @@ type block_metadata = { deactivated : Signature.Public_key_hash.t list; balance_updates : Receipt.balance_updates; liquidity_baking_toggle_ema : Per_block_votes.Liquidity_baking_toggle_EMA.t; - adaptive_inflation_toggle_ema : Per_block_votes.Adaptive_inflation_launch_EMA.t; + adaptive_inflation_toggle_ema : + Per_block_votes.Adaptive_inflation_launch_EMA.t; adaptive_inflation_launch_cycle : Cycle.t option; implicit_operations_results : packed_successful_manager_operation_result list; dal_attestation : Dal.Attestation.t option; diff --git a/src/proto_alpha/lib_protocol/apply_results.mli b/src/proto_alpha/lib_protocol/apply_results.mli index fa9500b610b5..a93d346458bc 100644 --- a/src/proto_alpha/lib_protocol/apply_results.mli +++ b/src/proto_alpha/lib_protocol/apply_results.mli @@ -340,7 +340,8 @@ type block_metadata = { deactivated : Signature.Public_key_hash.t list; balance_updates : Receipt.balance_updates; liquidity_baking_toggle_ema : Per_block_votes.Liquidity_baking_toggle_EMA.t; - adaptive_inflation_toggle_ema : Per_block_votes.Adaptive_inflation_launch_EMA.t; + adaptive_inflation_toggle_ema : + Per_block_votes.Adaptive_inflation_launch_EMA.t; adaptive_inflation_launch_cycle : Cycle.t option; implicit_operations_results : packed_successful_manager_operation_result list; dal_attestation : Dal.Attestation.t option; diff --git a/src/proto_alpha/lib_protocol/main.ml b/src/proto_alpha/lib_protocol/main.ml index 8faa05f764d3..741d14c1518c 100644 --- a/src/proto_alpha/lib_protocol/main.ml +++ b/src/proto_alpha/lib_protocol/main.ml @@ -417,7 +417,8 @@ let init chain_id ctxt block_header = payload_round = Alpha_context.Round.zero; per_block_votes = { - liquidity_baking_vote = Alpha_context.Per_block_votes.Per_block_vote_pass; + liquidity_baking_vote = + Alpha_context.Per_block_votes.Per_block_vote_pass; adaptive_inflation_vote = Alpha_context.Per_block_votes.Per_block_vote_pass; }; diff --git a/src/proto_alpha/lib_protocol/per_block_votes_repr.ml b/src/proto_alpha/lib_protocol/per_block_votes_repr.ml index 821ad0ed02be..803cab6c022c 100644 --- a/src/proto_alpha/lib_protocol/per_block_votes_repr.ml +++ b/src/proto_alpha/lib_protocol/per_block_votes_repr.ml @@ -26,7 +26,10 @@ (** Options available for per-block votes *) -type per_block_vote = Per_block_vote_on | Per_block_vote_off | Per_block_vote_pass +type per_block_vote = + | Per_block_vote_on + | Per_block_vote_off + | Per_block_vote_pass type per_block_votes = { liquidity_baking_vote : per_block_vote; diff --git a/src/proto_alpha/lib_protocol/per_block_votes_repr.mli b/src/proto_alpha/lib_protocol/per_block_votes_repr.mli index 63bfca962213..ee751fe61f78 100644 --- a/src/proto_alpha/lib_protocol/per_block_votes_repr.mli +++ b/src/proto_alpha/lib_protocol/per_block_votes_repr.mli @@ -26,7 +26,10 @@ (** Options available for per-block votes *) -type per_block_vote = Per_block_vote_on | Per_block_vote_off | Per_block_vote_pass +type per_block_vote = + | Per_block_vote_on + | Per_block_vote_off + | Per_block_vote_pass type per_block_votes = { liquidity_baking_vote : per_block_vote; diff --git a/src/proto_alpha/lib_protocol/test/helpers/block.ml b/src/proto_alpha/lib_protocol/test/helpers/block.ml index a2727376bda8..5371c72da9fb 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/block.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/block.ml @@ -306,8 +306,8 @@ module Forge = struct Tezos_protocol_alpha_parameters.Default_parameters.constants_test .proof_of_work_threshold) ?seed_nonce_hash ?(liquidity_baking_toggle_vote = Per_block_votes.Per_block_vote_pass) - ?(adaptive_inflation_vote = Per_block_votes.Per_block_vote_pass) ~payload_hash - ~payload_round shell_header = + ?(adaptive_inflation_vote = Per_block_votes.Per_block_vote_pass) + ~payload_hash ~payload_round shell_header = naive_pow_miner ~proof_of_work_threshold shell_header @@ -1032,7 +1032,6 @@ let bake_n_with_liquidity_baking_toggle_ema ?baking_mode ?policy in (b, metadata.liquidity_baking_toggle_ema) - let current_cycle b = let blocks_per_cycle = b.constants.blocks_per_cycle in let current_level = b.header.shell.level in diff --git a/src/proto_alpha/lib_protocol/test/integration/test_adaptive_inflation_launch.ml b/src/proto_alpha/lib_protocol/test/integration/test_adaptive_inflation_launch.ml index 3da101f05744..27dfe4d18e95 100644 --- a/src/proto_alpha/lib_protocol/test/integration/test_adaptive_inflation_launch.ml +++ b/src/proto_alpha/lib_protocol/test/integration/test_adaptive_inflation_launch.ml @@ -114,7 +114,8 @@ let test_launch threshold expected_vote_duration () = let assert_ema_above_threshold ~loc (metadata : Protocol.Main.block_header_metadata) = let ema = - Protocol.Alpha_context.Per_block_votes.Adaptive_inflation_launch_EMA.to_int32 + Protocol.Alpha_context.Per_block_votes.Adaptive_inflation_launch_EMA + .to_int32 metadata.adaptive_inflation_toggle_ema in Assert.lt_int32 ~loc threshold ema @@ -249,7 +250,10 @@ let test_launch threshold expected_vote_duration () = let* () = assert_is_not_yet_set_to_launch ~loc:__LOC__ block in (* We bake one more block to end the vote and set the feature to launch. *) let* block, metadata = - Block.bake_n_with_metadata ~adaptive_inflation_vote:Per_block_vote_on 1 block + Block.bake_n_with_metadata + ~adaptive_inflation_vote:Per_block_vote_on + 1 + block in let* () = assert_ema_above_threshold ~loc:__LOC__ metadata in let* () = assert_level ~loc:__LOC__ block expected_vote_duration in diff --git a/src/proto_alpha/lib_protocol/test/integration/test_liquidity_baking.ml b/src/proto_alpha/lib_protocol/test/integration/test_liquidity_baking.ml index 1feb6fd98e91..62b90e67ffc1 100644 --- a/src/proto_alpha/lib_protocol/test/integration/test_liquidity_baking.ml +++ b/src/proto_alpha/lib_protocol/test/integration/test_liquidity_baking.ml @@ -138,7 +138,10 @@ let liquidity_baking_toggle ~n_vote_on ~n_vote_off ~n_vote_pass expected_level if i < expected_level then Block.bake_n ~liquidity_baking_toggle_vote:Per_block_vote_on n_vote_on blk >>=? fun blk -> - Block.bake_n ~liquidity_baking_toggle_vote:Per_block_vote_off n_vote_off blk + Block.bake_n + ~liquidity_baking_toggle_vote:Per_block_vote_off + n_vote_off + blk >>=? fun blk -> Block.bake_n ~liquidity_baking_toggle_vote:Per_block_vote_pass @@ -247,7 +250,10 @@ let liquidity_baking_toggle_ema n_vote_on n_vote_off level bake_after if i < level then Block.bake_n ~liquidity_baking_toggle_vote:Per_block_vote_on n_vote_on blk >>=? fun blk -> - Block.bake_n ~liquidity_baking_toggle_vote:Per_block_vote_off n_vote_off blk + Block.bake_n + ~liquidity_baking_toggle_vote:Per_block_vote_off + n_vote_off + blk >>=? fun blk -> bake_escaping blk (i + n_vote_on + n_vote_off) else return blk in @@ -450,48 +456,48 @@ let tests = `Quick (liquidity_baking_subsidies 64); Tztest.tztest - "liquidity baking toggle vote with 100% of bakers voting Per_block_vote_off \ - baking one block longer" + "liquidity baking toggle vote with 100% of bakers voting \ + Per_block_vote_off baking one block longer" `Quick (liquidity_baking_toggle_100 1); Tztest.tztest - "liquidity baking toggle vote with 100% of bakers voting Per_block_vote_off \ - baking two blocks longer" + "liquidity baking toggle vote with 100% of bakers voting \ + Per_block_vote_off baking two blocks longer" `Quick (liquidity_baking_toggle_100 2); Tztest.tztest - "liquidity baking toggle vote with 100% of bakers voting Per_block_vote_off \ - baking 100 blocks longer" + "liquidity baking toggle vote with 100% of bakers voting \ + Per_block_vote_off baking 100 blocks longer" `Quick (liquidity_baking_toggle_100 100); Tztest.tztest - "liquidity baking toggle vote with 80% of bakers voting Per_block_vote_off \ - baking one block longer" + "liquidity baking toggle vote with 80% of bakers voting \ + Per_block_vote_off baking one block longer" `Quick (liquidity_baking_toggle_80 1); Tztest.tztest - "liquidity baking toggle vote with 80% of bakers voting Per_block_vote_off \ - baking two blocks longer" + "liquidity baking toggle vote with 80% of bakers voting \ + Per_block_vote_off baking two blocks longer" `Quick (liquidity_baking_toggle_80 2); Tztest.tztest - "liquidity baking toggle vote with 80% of bakers voting Per_block_vote_off \ - baking 100 blocks longer" + "liquidity baking toggle vote with 80% of bakers voting \ + Per_block_vote_off baking 100 blocks longer" `Quick (liquidity_baking_toggle_80 100); Tztest.tztest - "liquidity baking toggle vote with 60% of bakers voting Per_block_vote_off \ - baking one block longer" + "liquidity baking toggle vote with 60% of bakers voting \ + Per_block_vote_off baking one block longer" `Quick (liquidity_baking_toggle_60 1); Tztest.tztest - "liquidity baking toggle vote with 60% of bakers voting Per_block_vote_off \ - baking two blocks longer" + "liquidity baking toggle vote with 60% of bakers voting \ + Per_block_vote_off baking two blocks longer" `Quick (liquidity_baking_toggle_60 2); Tztest.tztest - "liquidity baking toggle vote with 60% of bakers voting Per_block_vote_off \ - baking 100 blocks longer" + "liquidity baking toggle vote with 60% of bakers voting \ + Per_block_vote_off baking 100 blocks longer" `Quick (liquidity_baking_toggle_60 100); Tztest.tztest diff --git a/src/proto_alpha/lib_protocol/test/unit/test_adaptive_inflation_ema.ml b/src/proto_alpha/lib_protocol/test/unit/test_adaptive_inflation_ema.ml index 99d102069758..cc7373b9a986 100644 --- a/src/proto_alpha/lib_protocol/test/unit/test_adaptive_inflation_ema.ml +++ b/src/proto_alpha/lib_protocol/test/unit/test_adaptive_inflation_ema.ml @@ -46,8 +46,10 @@ let compute_new_ema ~per_block_vote ema = (* Folds compute_new_ema on a list of votes *) let compute_new_ema_n per_block_votes initial_ema = List.fold_left - (fun ema toggle_vote -> - Per_block_votes_repr.compute_new_adaptive_inflation_ema ~per_block_vote ema) + (fun ema per_block_vote -> + Per_block_votes_repr.compute_new_adaptive_inflation_ema + ~per_block_vote + ema) initial_ema per_block_votes |> ema_to_int32 @@ -133,7 +135,9 @@ let test_ema_increases_on_bound () = ema_of_int32 old_ema >>=? fun ema -> Assert.leq_int32 ~loc:__LOC__ - (Int32.sub (compute_new_ema ~per_block_vote:Per_block_vote_on ema) old_ema) + (Int32.sub + (compute_new_ema ~per_block_vote:Per_block_vote_on ema) + old_ema) 1_000_000l) ema_range @@ -166,7 +170,9 @@ let test_ema_decreases_off_bound () = ema_of_int32 old_ema >>=? fun ema -> Assert.leq_int32 ~loc:__LOC__ - (Int32.sub (compute_new_ema ~per_block_vote:Per_block_vote_off ema) old_ema) + (Int32.sub + (compute_new_ema ~per_block_vote:Per_block_vote_off ema) + old_ema) 1_000_000l) ema_range diff --git a/src/proto_alpha/lib_protocol/test/unit/test_liquidity_baking_repr.ml b/src/proto_alpha/lib_protocol/test/unit/test_liquidity_baking_repr.ml index bf895ab8547b..7d4ca3a6719c 100644 --- a/src/proto_alpha/lib_protocol/test/unit/test_liquidity_baking_repr.ml +++ b/src/proto_alpha/lib_protocol/test/unit/test_liquidity_baking_repr.ml @@ -45,7 +45,7 @@ let compute_new_ema ~per_block_vote ema = (* Folds compute_new_ema on a list of votes *) let compute_new_ema_n per_block_votes initial_ema = List.fold_left - (fun ema toggle_vote -> + (fun ema per_block_vote -> Per_block_votes_repr.compute_new_liquidity_baking_ema ~per_block_vote ema) initial_ema per_block_votes @@ -132,7 +132,9 @@ let test_ema_increases_off_bound () = ema_of_int32 old_ema >>=? fun ema -> Assert.leq_int32 ~loc:__LOC__ - (Int32.sub (compute_new_ema ~per_block_vote:Per_block_vote_off ema) old_ema) + (Int32.sub + (compute_new_ema ~per_block_vote:Per_block_vote_off ema) + old_ema) 1_000_000l) ema_range @@ -165,7 +167,9 @@ let test_ema_decreases_on_bound () = ema_of_int32 old_ema >>=? fun ema -> Assert.leq_int32 ~loc:__LOC__ - (Int32.sub (compute_new_ema ~per_block_vote:Per_block_vote_on ema) old_ema) + (Int32.sub + (compute_new_ema ~per_block_vote:Per_block_vote_on ema) + old_ema) 1_000_000l) ema_range -- GitLab From 44f566712c71b24411549129eff454e0d62ce4ee Mon Sep 17 00:00:00 2001 From: Philippe Wang Date: Tue, 27 Jun 2023 14:05:40 -0700 Subject: [PATCH 4/6] Protocol/Tests: rename toggle vote to per-block vote --- src/lib_store/unix/test/alpha_utils.ml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib_store/unix/test/alpha_utils.ml b/src/lib_store/unix/test/alpha_utils.ml index d7e6e1144350..65b172ec1be5 100644 --- a/src/lib_store/unix/test/alpha_utils.ml +++ b/src/lib_store/unix/test/alpha_utils.ml @@ -262,8 +262,8 @@ module Forge = struct let make_contents ~payload_hash ~payload_round ?(proof_of_work_nonce = default_proof_of_work_nonce) - ?(liquidity_baking_toggle_vote = Toggle_votes.Toggle_vote_pass) - ?(adaptive_inflation_vote = Toggle_votes.Toggle_vote_pass) + ?(liquidity_baking_toggle_vote = Per_block_votes.Per_block_vote_pass) + ?(adaptive_inflation_vote = Per_block_votes.Per_block_vote_pass) ~seed_nonce_hash () = Block_header. { @@ -271,7 +271,7 @@ module Forge = struct payload_round; proof_of_work_nonce; seed_nonce_hash; - toggle_votes = + per_block_votes = { liquidity_baking_vote = liquidity_baking_toggle_vote; adaptive_inflation_vote; -- GitLab From a744100e43dd97003d2ccb87f2a835a3aaa2df07 Mon Sep 17 00:00:00 2001 From: Philippe Wang Date: Wed, 28 Jun 2023 08:38:34 -0700 Subject: [PATCH 5/6] Protocol/AI: mv adaptive_inflation_{toggle,vote}_ema --- src/proto_alpha/lib_plugin/RPC.ml | 2 +- src/proto_alpha/lib_protocol/apply.ml | 27 +++++++++---------- src/proto_alpha/lib_protocol/apply.mli | 3 +-- src/proto_alpha/lib_protocol/apply_results.ml | 13 +++++---- .../lib_protocol/apply_results.mli | 3 +-- .../test_adaptive_inflation_launch.ml | 4 +-- 6 files changed, 24 insertions(+), 28 deletions(-) diff --git a/src/proto_alpha/lib_plugin/RPC.ml b/src/proto_alpha/lib_plugin/RPC.ml index 086265bab38e..745a3ad0e78e 100644 --- a/src/proto_alpha/lib_plugin/RPC.ml +++ b/src/proto_alpha/lib_plugin/RPC.ml @@ -1035,7 +1035,7 @@ module Scripts = struct migration_balance_updates = []; liquidity_baking_toggle_ema = Per_block_votes.Liquidity_baking_toggle_EMA.zero; - adaptive_inflation_toggle_ema = + adaptive_inflation_vote_ema = Per_block_votes.Adaptive_inflation_launch_EMA.zero; adaptive_inflation_launch_cycle = None; implicit_operations_results = []; diff --git a/src/proto_alpha/lib_protocol/apply.ml b/src/proto_alpha/lib_protocol/apply.ml index 54fa34224eeb..167e17afb475 100644 --- a/src/proto_alpha/lib_protocol/apply.ml +++ b/src/proto_alpha/lib_protocol/apply.ml @@ -1947,8 +1947,7 @@ type application_state = { op_count : int; migration_balance_updates : Receipt.balance_updates; liquidity_baking_toggle_ema : Per_block_votes.Liquidity_baking_toggle_EMA.t; - adaptive_inflation_toggle_ema : - Per_block_votes.Adaptive_inflation_launch_EMA.t; + adaptive_inflation_vote_ema : Per_block_votes.Adaptive_inflation_launch_EMA.t; adaptive_inflation_launch_cycle : Cycle.t option; implicit_operations_results : Apply_results.packed_successful_manager_operation_result list; @@ -2521,7 +2520,7 @@ let begin_application ctxt chain_id ~migration_balance_updates let* ctxt, liquidity_baking_operations_results, liquidity_baking_toggle_ema = apply_liquidity_baking_subsidy ctxt ~per_block_vote in - let* ctxt, adaptive_inflation_launch_cycle, adaptive_inflation_toggle_ema = + let* ctxt, adaptive_inflation_launch_cycle, adaptive_inflation_vote_ema = let adaptive_inflation_vote = block_header.Block_header.protocol_data.contents.per_block_votes .adaptive_inflation_vote @@ -2552,7 +2551,7 @@ let begin_application ctxt chain_id ~migration_balance_updates op_count = 0; migration_balance_updates; liquidity_baking_toggle_ema; - adaptive_inflation_toggle_ema; + adaptive_inflation_vote_ema; adaptive_inflation_launch_cycle; implicit_operations_results = Apply_results.pack_migration_operation_results @@ -2591,7 +2590,7 @@ let begin_full_construction ctxt chain_id ~migration_balance_updates let* ctxt, liquidity_baking_operations_results, liquidity_baking_toggle_ema = apply_liquidity_baking_subsidy ctxt ~per_block_vote in - let* ctxt, adaptive_inflation_launch_cycle, adaptive_inflation_toggle_ema = + let* ctxt, adaptive_inflation_launch_cycle, adaptive_inflation_vote_ema = let adaptive_inflation_vote = block_data_contents.per_block_votes.adaptive_inflation_vote in @@ -2620,7 +2619,7 @@ let begin_full_construction ctxt chain_id ~migration_balance_updates op_count = 0; migration_balance_updates; liquidity_baking_toggle_ema; - adaptive_inflation_toggle_ema; + adaptive_inflation_vote_ema; adaptive_inflation_launch_cycle; implicit_operations_results = Apply_results.pack_migration_operation_results @@ -2636,7 +2635,7 @@ let begin_partial_construction ctxt chain_id ~migration_balance_updates let* ctxt, liquidity_baking_operations_results, liquidity_baking_toggle_ema = apply_liquidity_baking_subsidy ctxt ~per_block_vote in - let* ctxt, adaptive_inflation_launch_cycle, adaptive_inflation_toggle_ema = + let* ctxt, adaptive_inflation_launch_cycle, adaptive_inflation_vote_ema = let adaptive_inflation_vote = Per_block_votes.Per_block_vote_pass in Adaptive_inflation.update_ema ctxt ~vote:adaptive_inflation_vote in @@ -2658,7 +2657,7 @@ let begin_partial_construction ctxt chain_id ~migration_balance_updates op_count = 0; migration_balance_updates; liquidity_baking_toggle_ema; - adaptive_inflation_toggle_ema; + adaptive_inflation_vote_ema; adaptive_inflation_launch_cycle; implicit_operations_results = Apply_results.pack_migration_operation_results @@ -2667,7 +2666,7 @@ let begin_partial_construction ctxt chain_id ~migration_balance_updates } let finalize_application ctxt block_data_contents ~round ~predecessor_hash - ~liquidity_baking_toggle_ema ~adaptive_inflation_toggle_ema + ~liquidity_baking_toggle_ema ~adaptive_inflation_vote_ema ~adaptive_inflation_launch_cycle ~implicit_operations_results ~migration_balance_updates ~(block_producer : Consensus_key.t) ~(payload_producer : Consensus_key.t) = @@ -2758,7 +2757,7 @@ let finalize_application ctxt block_data_contents ~round ~predecessor_hash deactivated; balance_updates; liquidity_baking_toggle_ema; - adaptive_inflation_toggle_ema; + adaptive_inflation_vote_ema; adaptive_inflation_launch_cycle; implicit_operations_results; dal_attestation; @@ -2809,7 +2808,7 @@ let finalize_block (application_state : application_state) shell_header_opt = let { ctxt; liquidity_baking_toggle_ema; - adaptive_inflation_toggle_ema; + adaptive_inflation_vote_ema; adaptive_inflation_launch_cycle; implicit_operations_results; migration_balance_updates; @@ -2851,7 +2850,7 @@ let finalize_block (application_state : application_state) shell_header_opt = ~round ~predecessor_hash ~liquidity_baking_toggle_ema - ~adaptive_inflation_toggle_ema + ~adaptive_inflation_vote_ema ~adaptive_inflation_launch_cycle ~implicit_operations_results ~migration_balance_updates @@ -2883,7 +2882,7 @@ let finalize_block (application_state : application_state) shell_header_opt = deactivated = []; balance_updates = migration_balance_updates; liquidity_baking_toggle_ema; - adaptive_inflation_toggle_ema; + adaptive_inflation_vote_ema; adaptive_inflation_launch_cycle; implicit_operations_results; dal_attestation = None; @@ -2907,7 +2906,7 @@ let finalize_block (application_state : application_state) shell_header_opt = ~round ~predecessor_hash:shell.predecessor ~liquidity_baking_toggle_ema - ~adaptive_inflation_toggle_ema + ~adaptive_inflation_vote_ema ~adaptive_inflation_launch_cycle ~implicit_operations_results ~migration_balance_updates diff --git a/src/proto_alpha/lib_protocol/apply.mli b/src/proto_alpha/lib_protocol/apply.mli index 46fa86210012..7275d1a46bf4 100644 --- a/src/proto_alpha/lib_protocol/apply.mli +++ b/src/proto_alpha/lib_protocol/apply.mli @@ -69,8 +69,7 @@ type application_state = { op_count : int; migration_balance_updates : Receipt.balance_updates; liquidity_baking_toggle_ema : Per_block_votes.Liquidity_baking_toggle_EMA.t; - adaptive_inflation_toggle_ema : - Per_block_votes.Adaptive_inflation_launch_EMA.t; + adaptive_inflation_vote_ema : Per_block_votes.Adaptive_inflation_launch_EMA.t; adaptive_inflation_launch_cycle : Cycle.t option; implicit_operations_results : Apply_results.packed_successful_manager_operation_result list; diff --git a/src/proto_alpha/lib_protocol/apply_results.ml b/src/proto_alpha/lib_protocol/apply_results.ml index e1f33bd45146..e9298c5001cb 100644 --- a/src/proto_alpha/lib_protocol/apply_results.ml +++ b/src/proto_alpha/lib_protocol/apply_results.ml @@ -2599,8 +2599,7 @@ type block_metadata = { deactivated : Signature.Public_key_hash.t list; balance_updates : Receipt.balance_updates; liquidity_baking_toggle_ema : Per_block_votes.Liquidity_baking_toggle_EMA.t; - adaptive_inflation_toggle_ema : - Per_block_votes.Adaptive_inflation_launch_EMA.t; + adaptive_inflation_vote_ema : Per_block_votes.Adaptive_inflation_launch_EMA.t; adaptive_inflation_launch_cycle : Cycle.t option; implicit_operations_results : packed_successful_manager_operation_result list; dal_attestation : Dal.Attestation.t option; @@ -2621,7 +2620,7 @@ let block_metadata_encoding = deactivated; balance_updates; liquidity_baking_toggle_ema; - adaptive_inflation_toggle_ema; + adaptive_inflation_vote_ema; adaptive_inflation_launch_cycle; implicit_operations_results; dal_attestation; @@ -2634,7 +2633,7 @@ let block_metadata_encoding = deactivated, balance_updates, liquidity_baking_toggle_ema, - adaptive_inflation_toggle_ema, + adaptive_inflation_vote_ema, adaptive_inflation_launch_cycle ), ( implicit_operations_results, proposer_active_key, @@ -2649,7 +2648,7 @@ let block_metadata_encoding = deactivated, balance_updates, liquidity_baking_toggle_ema, - adaptive_inflation_toggle_ema, + adaptive_inflation_vote_ema, adaptive_inflation_launch_cycle ), ( implicit_operations_results, proposer_active_key, @@ -2666,7 +2665,7 @@ let block_metadata_encoding = deactivated; balance_updates; liquidity_baking_toggle_ema; - adaptive_inflation_toggle_ema; + adaptive_inflation_vote_ema; adaptive_inflation_launch_cycle; implicit_operations_results; dal_attestation; @@ -2684,7 +2683,7 @@ let block_metadata_encoding = "liquidity_baking_toggle_ema" Per_block_votes.Liquidity_baking_toggle_EMA.encoding) (req - "adaptive_inflation_toggle_ema" + "adaptive_inflation_vote_ema" Per_block_votes.Adaptive_inflation_launch_EMA.encoding) (opt "adaptive_inflation_activation_cycle" Cycle.encoding)) (obj5 diff --git a/src/proto_alpha/lib_protocol/apply_results.mli b/src/proto_alpha/lib_protocol/apply_results.mli index a93d346458bc..8a4e17940b5a 100644 --- a/src/proto_alpha/lib_protocol/apply_results.mli +++ b/src/proto_alpha/lib_protocol/apply_results.mli @@ -340,8 +340,7 @@ type block_metadata = { deactivated : Signature.Public_key_hash.t list; balance_updates : Receipt.balance_updates; liquidity_baking_toggle_ema : Per_block_votes.Liquidity_baking_toggle_EMA.t; - adaptive_inflation_toggle_ema : - Per_block_votes.Adaptive_inflation_launch_EMA.t; + adaptive_inflation_vote_ema : Per_block_votes.Adaptive_inflation_launch_EMA.t; adaptive_inflation_launch_cycle : Cycle.t option; implicit_operations_results : packed_successful_manager_operation_result list; dal_attestation : Dal.Attestation.t option; diff --git a/src/proto_alpha/lib_protocol/test/integration/test_adaptive_inflation_launch.ml b/src/proto_alpha/lib_protocol/test/integration/test_adaptive_inflation_launch.ml index 27dfe4d18e95..6c2ab15baeca 100644 --- a/src/proto_alpha/lib_protocol/test/integration/test_adaptive_inflation_launch.ml +++ b/src/proto_alpha/lib_protocol/test/integration/test_adaptive_inflation_launch.ml @@ -116,7 +116,7 @@ let test_launch threshold expected_vote_duration () = let ema = Protocol.Alpha_context.Per_block_votes.Adaptive_inflation_launch_EMA .to_int32 - metadata.adaptive_inflation_toggle_ema + metadata.adaptive_inflation_vote_ema in Assert.lt_int32 ~loc threshold ema in @@ -233,7 +233,7 @@ let test_launch threshold expected_vote_duration () = let ema = Protocol.Alpha_context.Per_block_votes.Adaptive_inflation_launch_EMA .to_int32 - metadata.adaptive_inflation_toggle_ema + metadata.adaptive_inflation_vote_ema in let launch_cycle = metadata.adaptive_inflation_launch_cycle in let cond = Compare.Int32.(ema < threshold) in -- GitLab From 1c003e586b772ebed1ac05f8350c5e356530871a Mon Sep 17 00:00:00 2001 From: Philippe Wang Date: Wed, 28 Jun 2023 08:54:06 -0700 Subject: [PATCH 6/6] Protocol/AI: fix/update doc for Per_block_vote_file.load_per_block_votes_config --- .../lib_delegate/per_block_vote_file.mli | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/proto_alpha/lib_delegate/per_block_vote_file.mli b/src/proto_alpha/lib_delegate/per_block_vote_file.mli index 70fe4b619cbe..51d9cbf61252 100644 --- a/src/proto_alpha/lib_delegate/per_block_vote_file.mli +++ b/src/proto_alpha/lib_delegate/per_block_vote_file.mli @@ -72,11 +72,14 @@ val read_per_block_votes_no_fail : per_block_vote_file:string -> Per_block_votes.per_block_votes Lwt.t -(** Load a liquidity baking configuration given two possible - arguments. If neither are provided, it fails. Otherwise, it tries, - in priority, to read the [per_block_vote_file_arg] file if it is - given and loads a config using its content. Otherwise, the - [toggle_vote_arg] is used. *) +(** Load a configuration of per-block votes. Liquidity baking toggle + vote is mandatory, it has to come from either the per-block vote + file [per_block_vote_file] or from + [default_liquidity_baking_vote]. If a vote cannot be determined + from those values, this function fails. Adaptive inflation feature + vote is optional. Priority is given to the values in the + [per_block_vote_file] file for all votes at the time of the block + (the file is freshly read each time). *) val load_per_block_votes_config : default_liquidity_baking_vote:Per_block_votes.per_block_vote option -> default_adaptive_inflation_vote:Per_block_votes.per_block_vote option -> -- GitLab