diff --git a/src/lib_store/unix/test/alpha_utils.ml b/src/lib_store/unix/test/alpha_utils.ml index d7e6e1144350574ffe571921806d92d4dcb3cda8..65b172ec1be5ea18efe33cf9d809af3fea62cbd3 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; diff --git a/src/proto_alpha/lib_client/mockup.ml b/src/proto_alpha/lib_client/mockup.ml index 3fc9ac56e84c76a6d847281a708993eaebc1ff29..ea1959ba9f5a4a422b966c73ef444304b84a823d 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 149606e70901e57da5fdac204b7d5000c53ba97a..291c5bb23c7a43acb1d55ca68397a17dd78e4da4 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 28250f7dc17c68e9075594fa275b3a27f477ea17..fc68cac09f6b891229d7add29b1f88dbbb7c84be 100644 --- a/src/proto_alpha/lib_delegate/baking_commands.ml +++ b/src/proto_alpha/lib_delegate/baking_commands.ml @@ -147,14 +147,14 @@ 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.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\"." @@ -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) = @@ -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 @@ -527,8 +527,8 @@ 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. *) - Per_block_vote_file.load_toggle_votes_config + 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 ~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 32f594ab24457b09e1a6a90bd96bb83fafe2b995..9721f494226589ee67b84c6e3ab7ba42c68b0b73 100644 --- a/src/proto_alpha/lib_delegate/baking_configuration.ml +++ b/src/proto_alpha/lib_delegate/baking_configuration.ml @@ -76,10 +76,11 @@ 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 +89,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 +118,10 @@ 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 +139,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 +171,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 +239,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 +297,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 +309,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 +319,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 +330,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 +346,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 7cc6b38ec5506fbad02a3a5e762b2e4b07e19b1c..00404aa3ea4a30efc6041c55de7812c8d988ea81 100644 --- a/src/proto_alpha/lib_delegate/baking_configuration.mli +++ b/src/proto_alpha/lib_delegate/baking_configuration.mli @@ -51,10 +51,11 @@ 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 +64,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 +82,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 +102,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 +123,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 393dec0eb44aefb8409a63aadf62edc4552c80cf..b9722b6dd3d94206c40b8d2dd8a5b614b82c5377 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,8 @@ 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 +1021,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 +1039,8 @@ 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 d36d94a1d1db3811e6a3c04adbb5881732d0fe6b..81cdb4699a313b310adb4e67fbd60a9903e1fd47 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 04dbadbcc42465468cf100fd9dbee677ef6acd95..f0c2638ee6cf396c73cce85d4c3de47330981b92 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 6b7d49f79b54d3ec05ae54cfb0af917ac1214e4a..ce530fee53971367f70a01ab46c408362e6f8204 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 f1d2a8187a4e0cb526f8f0950582f273e59c8d92..5473692de0157230313272f729a7ca07aedbaa64 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,11 @@ 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 +178,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 +196,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 +207,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 +216,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 +240,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 dd83692f4d1cab81e5fbfd066e4906c35c6b8bc1..51d9cbf6125248cdbc273d3400837ece93fc1de4 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,21 @@ 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 -> +(** 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 -> 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 0fe62d4c5fef666d0e172be1ac7850907178b039..3b4acac0c286b88ef2c48998431ecfc21cef96fa 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,9 +929,9 @@ let genesis_protocol_data (baker_sk : Signature.secret_key) ~payload_round:Alpha_context.Round.zero [] in - let toggle_votes = + let per_block_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 = @@ -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 19689e99c38d75e2f3560affcd05c49f8165d053..745a3ad0e78eb90b200b26ded1468aad334906ab 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; - adaptive_inflation_toggle_ema = - Toggle_votes.Adaptive_inflation_launch_EMA.zero; + Per_block_votes.Liquidity_baking_toggle_EMA.zero; + adaptive_inflation_vote_ema = + 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 2a14aee0769c17272d374a70b99251321bbc62f3..68b4df280749b574dc20f40b45943e56317ee370 100644 --- a/src/proto_alpha/lib_protocol/TEZOS_PROTOCOL +++ b/src/proto_alpha/lib_protocol/TEZOS_PROTOCOL @@ -91,8 +91,8 @@ "Bond_id_repr", "Vote_repr", - "Toggle_EMA", - "Toggle_votes_repr", + "Votes_EMA_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 0badec280cea456e71fc6b0d55fc032891e91624..83927fd08e47634f9cb31d66d1d3bde5f977998a 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 - ~toggle_vote:vote + Per_block_votes_repr.compute_new_adaptive_inflation_ema + ~per_block_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 51f7b50f6706f8be0a1289b78855974b0f013a08..3944c6e01d5bc5bdc4c4ef8fa90897c68aced915 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.per_block_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 b717217919900acf3467c1af89a1caf8ba456402..5779d0061c0e0fa451a9172bd9f1f3e5cba3a058 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 = Toggle_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 acbfba6d960a342b9b25457406fa89b25c2a4b33..311987624be9c2b234d93904ac4d3841c55bbd3c 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; + 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 @@ -4731,35 +4731,35 @@ module Toggle_EMA : sig end end -(** This module re-exports definitions from {!Toggle_votes_repr}. *) -module Toggle_votes : sig - type toggle_vote = Toggle_votes_repr.toggle_vote = - | Toggle_vote_on - | Toggle_vote_off - | Toggle_vote_pass +(** This module re-exports definitions from {!Per_block_votes_repr}. *) +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 toggle_votes = Toggle_votes_repr.toggle_votes = { - liquidity_baking_vote : toggle_vote; - adaptive_inflation_vote : toggle_vote; + 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 9a90871d9a3bef76cf68268f26eb0353a8895d2e..167e17afb475cedc2c5f5bedc133874939deea61 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_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; @@ -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* ctxt, adaptive_inflation_launch_cycle, adaptive_inflation_vote_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 @@ -2551,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 @@ -2584,13 +2584,15 @@ 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* ctxt, adaptive_inflation_launch_cycle, adaptive_inflation_vote_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 @@ -2617,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 @@ -2629,12 +2631,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* 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 let* ctxt = @@ -2655,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 @@ -2664,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) = @@ -2755,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; @@ -2806,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; @@ -2848,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 @@ -2880,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; @@ -2904,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 be1581c7bc550d2ff3a47868c71399126e1c5e6c..7275d1a46bf44345f87f1e20968a7632ed9f25b3 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_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 d016357c64c0f2067da961dfb8b436f5fd3511ca..e9298c5001cb661b455d42084ba330648c83c91a 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_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; @@ -2620,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; @@ -2633,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, @@ -2648,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, @@ -2665,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; @@ -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) + "adaptive_inflation_vote_ema" + 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 e921635b6298c16ee3bdb0da0f8c034634c185cf..8a4e17940b5a8682abcff91914a633304d73a66b 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_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/block_header_repr.ml b/src/proto_alpha/lib_protocol/block_header_repr.ml index 2ea1b609df0fbad2753a6f4f3e8bbcf9f7b74dee..e4665a93153f5fb4c2c911cf94e6d83248e81a74 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; + 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) @@ -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 @@ -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" Toggle_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 9960bff5a90704efbecdf854254adc15716ca5be..f3600db1e1595084355bb6cbf5d24920e3a8fed4 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; + 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 59f4e7ea2540e23dfaf61c8d025ed22b9f8f763c..adfab8c731d9db4ea451c9888da6cedadcdb1f50 100644 --- a/src/proto_alpha/lib_protocol/dune +++ b/src/proto_alpha/lib_protocol/dune @@ -114,8 +114,8 @@ Zk_rollup_circuit_public_inputs_repr Bond_id_repr Vote_repr - Toggle_EMA - Toggle_votes_repr + Votes_EMA_repr + Per_block_votes_repr Block_header_repr Destination_repr Script_int @@ -382,8 +382,8 @@ 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 - toggle_votes_repr.ml toggle_votes_repr.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 script_int.ml script_int.mli @@ -652,8 +652,8 @@ 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 - toggle_votes_repr.ml toggle_votes_repr.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 script_int.ml script_int.mli @@ -906,8 +906,8 @@ 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 - toggle_votes_repr.ml toggle_votes_repr.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 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 1650758e8eaa382c48175539b24d4e39ad7c2b6e..5b296fb94974d9a61483f4c39d10ce5e4bf9c04c 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 @@ -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 97db7278af4c0ab055f6aeccf4ae93ae6e68630f..19641d5886460b3d948d9fe866827075391f2531 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,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 -> + 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 * 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/main.ml b/src/proto_alpha/lib_protocol/main.ml index 13d97f60ede5616cf8b88d03f053a36cb485df39..741d14c1518c862fc848ba4087d7c3964c965b36 100644 --- a/src/proto_alpha/lib_protocol/main.ml +++ b/src/proto_alpha/lib_protocol/main.ml @@ -415,11 +415,12 @@ 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/toggle_votes_repr.ml b/src/proto_alpha/lib_protocol/per_block_votes_repr.ml similarity index 65% rename from src/proto_alpha/lib_protocol/toggle_votes_repr.ml rename to src/proto_alpha/lib_protocol/per_block_votes_repr.ml index e0f17d3b174a219e7a8320fa3c2db86d6d37e82d..803cab6c022ce1586dea97f9d8c161e8f4a11177 100644 --- a/src/proto_alpha/lib_protocol/toggle_votes_repr.ml +++ b/src/proto_alpha/lib_protocol/per_block_votes_repr.ml @@ -24,16 +24,19 @@ (* *) (*****************************************************************************) -(** 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 +44,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 +81,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 +114,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/toggle_votes_repr.mli b/src/proto_alpha/lib_protocol/per_block_votes_repr.mli similarity index 65% rename from src/proto_alpha/lib_protocol/toggle_votes_repr.mli rename to src/proto_alpha/lib_protocol/per_block_votes_repr.mli index adef7e167b5368887acf35240b1d77a7612f5c7b..ee751fe61f7876a7a5a9fa3e401fab25d0a549ab 100644 --- a/src/proto_alpha/lib_protocol/toggle_votes_repr.mli +++ b/src/proto_alpha/lib_protocol/per_block_votes_repr.mli @@ -24,57 +24,60 @@ (* *) (*****************************************************************************) -(** 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 3edae223a5c05ad32c911de9c30c35d824a34491..5371c72da9fb7d79da336eb92d52776c3b1ac06f 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,16 +305,16 @@ 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 - ~payload_round shell_header = + ?(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 shell_header { 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; diff --git a/src/proto_alpha/lib_protocol/test/helpers/block.mli b/src/proto_alpha/lib_protocol/test/helpers/block.mli index a434badcc9f884b3ed57bf38665d122f9f6f5aeb..36e8d40a941206de68cddb2b572115963e1e11ea 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:Toggle_votes_repr.toggle_vote -> - ?adaptive_inflation_vote:Toggle_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:Toggle_votes_repr.toggle_vote -> - ?adaptive_inflation_vote:Toggle_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:Toggle_votes_repr.toggle_vote -> - ?adaptive_inflation_vote:Toggle_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 eb88a16eac472fdc6c7e50d6292c9afbd1e185b1..6c2ab15baeca7fe3e52d9189a84681cb7baa163e 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,8 +114,9 @@ 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 - metadata.adaptive_inflation_toggle_ema + Protocol.Alpha_context.Per_block_votes.Adaptive_inflation_launch_EMA + .to_int32 + metadata.adaptive_inflation_vote_ema in Assert.lt_int32 ~loc threshold ema in @@ -164,7 +165,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 +189,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 +198,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 +208,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 +218,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,12 +228,12 @@ 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 + metadata.adaptive_inflation_vote_ema in let launch_cycle = metadata.adaptive_inflation_launch_cycle in let cond = Compare.Int32.(ema < threshold) in @@ -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: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 61bdf96ffc017f593c196db77ed5255dee39eb7e..62b90e67ffc13ee833ecb305bddddffe40017efd 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,15 @@ 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 +153,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 +166,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 +190,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 +209,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 +248,12 @@ 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 +264,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,48 +456,48 @@ let tests = `Quick (liquidity_baking_subsidies 64); Tztest.tztest - "liquidity baking toggle vote with 100% of bakers voting Toggle_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 Toggle_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 Toggle_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 Toggle_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 Toggle_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 Toggle_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 Toggle_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 Toggle_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 Toggle_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 @@ -506,7 +512,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 87ebb81c48651a42fb0d0337354cdb19c76264b9..cc7373b9a98684f19b25dffdc18e608c9594bea8 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,25 @@ *) open Protocol -module Toggle_EMA = Toggle_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 = - Toggle_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 -> - Toggle_votes_repr.compute_new_adaptive_inflation_ema ~toggle_vote ema) + (fun ema per_block_vote -> + 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 +102,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 +111,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 +125,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 +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 ~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 +146,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 +159,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,18 +170,20 @@ 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 (* 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__ (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,35 +191,35 @@ 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%. *) 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__ 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 (* 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__ (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 +227,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 +241,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 4caf766f8fb18e9d50b9e2afa9f0a63f0b58b374..7d4ca3a6719cc3b11aca20fd888389699217203d 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 = Toggle_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 = - Toggle_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 -> - Toggle_votes_repr.compute_new_liquidity_baking_ema ~toggle_vote ema) + (fun ema per_block_vote -> + 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,9 @@ 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 +143,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 +156,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,18 +167,20 @@ 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 (* 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__ (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,24 +188,24 @@ 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). *) 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__ 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 +220,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