diff --git a/CHANGES.rst b/CHANGES.rst index 342f2788dd0b0fd3a2f9e1d942eba3fcac25fef9..8ad628ec1e1f27799678758e7c12fe33f1958d30 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -42,6 +42,9 @@ Baker data directory when searching an existing file. The previous semantics, which looks for this file in the current working directory, takes predecence. +- Bakers are now required to set their votes for the adoption of the + adaptive inflation feature. They may use the per block votes file, + or CLI option ``--adaptive-inflation-toggle-vote``. Accuser ------- diff --git a/docs/protocols/alpha.rst b/docs/protocols/alpha.rst index 7ca1ec26b0c951ac9a74bb830082cfebc4f13823..5ac8f5ae28a5baa76a53fa4ce3995caf999f486c 100644 --- a/docs/protocols/alpha.rst +++ b/docs/protocols/alpha.rst @@ -15,6 +15,14 @@ Environment Version This protocol requires a different protocol environment version than Nairobi. It requires protocol environment V10, compared to V9 for Nairobi. +Adaptive Inflation +------------------ + +- This protocol asks the bakers to set their votes for the + adoption of the adaptive inflation feature. They may use the per + block votes file, or CLI option + ``--adaptive-inflation-toggle-vote``. + Smart Rollups ------------- diff --git a/src/lib_store/unix/test/alpha_utils.ml b/src/lib_store/unix/test/alpha_utils.ml index a7b0e4e958d29be4c5596932cd51b1f665d9e9fd..487f0b6ec32ece5bc84abaea294d957c248dc3c2 100644 --- a/src/lib_store/unix/test/alpha_utils.ml +++ b/src/lib_store/unix/test/alpha_utils.ml @@ -262,7 +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 = Liquidity_baking.LB_pass) + ?(liquidity_baking_toggle_vote = Toggle_votes.Toggle_vote_pass) + ?(adaptive_inflation_toggle_vote = Toggle_votes.Toggle_vote_pass) ~seed_nonce_hash () = Block_header. { @@ -270,7 +271,11 @@ module Forge = struct payload_round; proof_of_work_nonce; seed_nonce_hash; - liquidity_baking_toggle_vote; + toggle_votes = + { + liquidity_baking_vote = liquidity_baking_toggle_vote; + adaptive_inflation_vote = adaptive_inflation_toggle_vote; + }; } let make_shell ~level ~predecessor ~timestamp ~fitness ~operations_hash diff --git a/src/proto_alpha/lib_client/mockup.ml b/src/proto_alpha/lib_client/mockup.ml index 8ba8d4ccfd2f152dd397c2acc6007811b5b8ad3e..d1bf4ff2889eb8e2e65d3b6149347cf9a5257842 100644 --- a/src/proto_alpha/lib_client/mockup.ml +++ b/src/proto_alpha/lib_client/mockup.ml @@ -518,7 +518,11 @@ let mem_init : seed_nonce_hash = None; proof_of_work_nonce; (* following Baking_configuration.toggle_votes in lib_delegate *) - liquidity_baking_toggle_vote = Liquidity_baking.LB_pass; + toggle_votes = + { + liquidity_baking_vote = Toggle_votes.Toggle_vote_pass; + adaptive_inflation_vote = Toggle_votes.Toggle_vote_pass; + }; } in let unsigned_bytes = diff --git a/src/proto_alpha/lib_delegate/baking_actions.ml b/src/proto_alpha/lib_delegate/baking_actions.ml index 2ffc5a82216a7413d05f38b37859a17217fcf466..35978f251198ff4c45b9f502e724e0c0dd3a0c3d 100644 --- a/src/proto_alpha/lib_delegate/baking_actions.ml +++ b/src/proto_alpha/lib_delegate/baking_actions.ml @@ -284,17 +284,25 @@ let inject_block ~state_recorder state block_to_bake ~updated_state = state.global_state.config.user_activated_upgrades in (* Set liquidity_baking_toggle_vote for this block *) - let {Baking_configuration.vote_file; liquidity_baking_vote} = - state.global_state.config.liquidity_baking + let { + Baking_configuration.vote_file; + liquidity_baking_vote; + adaptive_inflation_vote; + } = + state.global_state.config.toggle_votes in (* Prioritize reading from the [vote_file] if it exists. *) - (match vote_file with - | Some per_block_vote_file -> - Liquidity_baking_vote.read_liquidity_baking_toggle_vote_no_fail - ~default_liquidity_baking_vote:liquidity_baking_vote - ~per_block_vote_file - | None -> Lwt.return liquidity_baking_vote) - >>= fun liquidity_baking_toggle_vote -> + (let default = + Protocol.Alpha_context.Toggle_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 + ~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 *) let updated_state = { @@ -305,16 +313,19 @@ let inject_block ~state_recorder state block_to_bake ~updated_state = config = { updated_state.global_state.config with - liquidity_baking = + toggle_votes = { - updated_state.global_state.config.liquidity_baking with - liquidity_baking_vote = liquidity_baking_toggle_vote; + updated_state.global_state.config.toggle_votes with + liquidity_baking_vote; + adaptive_inflation_vote; }; }; }; } in - Events.(emit vote_for_liquidity_baking_toggle) liquidity_baking_toggle_vote + Events.(emit vote_for_liquidity_baking_toggle) liquidity_baking_vote + >>= fun () -> + Events.(emit vote_for_adaptive_inflation_toggle) adaptive_inflation_vote >>= fun () -> let chain = `Hash state.global_state.chain_id in let pred_block = `Hash (predecessor.hash, 0) in @@ -338,7 +349,8 @@ let inject_block ~state_recorder state block_to_bake ~updated_state = ~round ~seed_nonce_hash ~payload_round - ~liquidity_baking_toggle_vote + ~liquidity_baking_toggle_vote:liquidity_baking_vote + ~adaptive_inflation_toggle_vote:adaptive_inflation_vote ~user_activated_upgrades ~force_apply state.global_state.config.fees diff --git a/src/proto_alpha/lib_delegate/baking_commands.ml b/src/proto_alpha/lib_delegate/baking_commands.ml index f7afe1494d71e42ef1c420c01af9e119fd189e43..9e7a44cc3a3700853f1fcf00f461954f1779480a 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 liquidity_baking_toggle_vote_parameter = +let toggle_vote_parameter = Tezos_clic.parameter ~autocomplete:(fun _ctxt -> return ["on"; "off"; "pass"]) - (let open Protocol.Alpha_context.Liquidity_baking in + (let open Protocol.Alpha_context.Toggle_votes in fun _ctxt -> function - | "on" -> return LB_on - | "off" -> return LB_off - | "pass" -> return LB_pass + | "on" -> return Toggle_vote_on + | "off" -> return Toggle_vote_off + | "pass" -> return Toggle_vote_pass | s -> failwith "unexpected vote: %s, expected either \"on\", \"off\", or \"pass\"." @@ -169,7 +169,18 @@ let liquidity_baking_toggle_vote_arg = abstain. Note that this \"option\" is mandatory!" ~long:"liquidity-baking-toggle-vote" ~placeholder:"vote" - liquidity_baking_toggle_vote_parameter + toggle_vote_parameter + +let adaptive_inflation_toggle_vote_arg = + Tezos_clic.arg + ~doc: + "Vote to adopt or not the adaptive inflation feature. The possible \ + values for this option are: \"off\" to request not activating it, \ + \"on\" to request activating it, and \"pass\" to abstain. If you do not \ + vote, default value is \"pass\"." + ~long:"adaptive-inflation-toggle-vote" + ~placeholder:"vote" + toggle_vote_parameter let get_delegates (cctxt : Protocol_client_context.full) (pkhs : Signature.public_key_hash list) = @@ -304,7 +315,11 @@ let delegate_commands () : Protocol_client_context.full Tezos_clic.command list payload_round = Round.zero; seed_nonce_hash = None; proof_of_work_nonce; - liquidity_baking_toggle_vote = LB_pass; + toggle_votes = + { + liquidity_baking_vote = Toggle_vote_pass; + adaptive_inflation_vote = Toggle_vote_pass; + }; }) in let _then = Time.System.now () in @@ -451,17 +466,17 @@ let per_block_vote_file_arg = let* file_exists = protect ~on_error:(fun _ -> - tzfail (Liquidity_baking_vote.Block_vote_file_not_found file)) + tzfail (Per_block_vote_file.Block_vote_file_not_found file)) (fun () -> let*! b = Lwt_unix.file_exists file in return b) in if file_exists then return file - else tzfail (Liquidity_baking_vote.Block_vote_file_not_found file))) + else tzfail (Per_block_vote_file.Block_vote_file_not_found file))) let lookup_default_vote_file_path (cctxt : Protocol_client_context.full) = let open Lwt_syntax in - let default_filename = Liquidity_baking_vote.default_vote_json_filename in + let default_filename = Per_block_vote_file.default_vote_json_filename in let file_exists path = Lwt.catch (fun () -> Lwt_unix.file_exists path) (fun _ -> return_false) in @@ -478,7 +493,7 @@ let lookup_default_vote_file_path (cctxt : Protocol_client_context.full) = type baking_mode = Local of {local_data_dir_path : string} | Remote let baker_args = - Tezos_clic.args10 + Tezos_clic.args11 pidfile_arg minimal_fees_arg minimal_nanotez_per_gas_unit_arg @@ -486,6 +501,7 @@ let baker_args = force_apply_switch_arg keep_alive_arg liquidity_baking_toggle_vote_arg + adaptive_inflation_toggle_vote_arg per_block_vote_file_arg operations_arg endpoint_arg @@ -497,24 +513,26 @@ let run_baker minimal_nanotez_per_byte, force_apply, keep_alive, - liquidity_baking_toggle_vote, + liquidity_baking_vote, + adaptive_inflation_vote, per_block_vote_file, extra_operations, dal_node_endpoint ) baking_mode sources cctxt = may_lock_pidfile pidfile @@ fun () -> (if per_block_vote_file = None then - (* If the liquidity baking file was not explicitly given, we + (* If the votes file was not explicitly given, we look into default locations. *) lookup_default_vote_file_path cctxt else Lwt.return per_block_vote_file) >>= 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 vote. *) - Liquidity_baking_vote.load_liquidity_baking_config - ~per_block_vote_file_arg:per_block_vote_file - ~toggle_vote_arg:liquidity_baking_toggle_vote - >>=? fun liquidity_baking -> + the toggle votes. *) + Per_block_vote_file.load_toggle_votes_config + ~default_liquidity_baking_vote:liquidity_baking_vote + ~default_adaptive_inflation_vote:adaptive_inflation_vote + ~per_block_vote_file + >>=? fun votes -> get_delegates cctxt sources >>=? fun delegates -> let context_path = match baking_mode with @@ -527,7 +545,7 @@ let run_baker ~minimal_fees ~minimal_nanotez_per_gas_unit ~minimal_nanotez_per_byte - ~liquidity_baking + ~votes ?extra_operations ?dal_node_endpoint ~force_apply diff --git a/src/proto_alpha/lib_delegate/baking_configuration.ml b/src/proto_alpha/lib_delegate/baking_configuration.ml index 96cf501641432d7e1f6b62c871ed53182c28b230..94d0ef11ce0c807461c8ad29578f3e1d1fa0f776 100644 --- a/src/proto_alpha/lib_delegate/baking_configuration.ml +++ b/src/proto_alpha/lib_delegate/baking_configuration.ml @@ -76,10 +76,10 @@ type nonce_config = Deterministic | Random type state_recorder_config = Filesystem | Disabled -type liquidity_baking_config = { +type toggle_votes_config = { vote_file : string option; - liquidity_baking_vote : - Protocol.Alpha_context.Liquidity_baking.liquidity_baking_toggle_vote; + liquidity_baking_vote : Protocol.Alpha_context.Toggle_votes.toggle_vote; + adaptive_inflation_vote : Protocol.Alpha_context.Toggle_votes.toggle_vote; } type t = { @@ -88,7 +88,7 @@ type t = { validation : validation_config; retries_on_failure : int; user_activated_upgrades : (int32 * Protocol_hash.t) list; - liquidity_baking : liquidity_baking_config; + toggle_votes : toggle_votes_config; force_apply : bool; force : bool; state_recorder : state_recorder_config; @@ -114,10 +114,12 @@ let default_retries_on_failure_config = 5 let default_user_activated_upgrades = [] -let default_liquidity_baking_config = +let default_votes_config = { vote_file = None; - liquidity_baking_vote = Protocol.Alpha_context.Liquidity_baking.LB_pass; + liquidity_baking_vote = Protocol.Alpha_context.Toggle_votes.Toggle_vote_pass; + adaptive_inflation_vote = + Protocol.Alpha_context.Toggle_votes.Toggle_vote_pass; } let default_force = false @@ -135,7 +137,7 @@ let default_config = validation = default_validation_config; retries_on_failure = default_retries_on_failure_config; user_activated_upgrades = default_user_activated_upgrades; - liquidity_baking = default_liquidity_baking_config; + toggle_votes = default_votes_config; force_apply = default_force_apply; force = default_force; state_recorder = default_state_recorder_config; @@ -150,10 +152,9 @@ let make ?(minimal_fees = default_fees_config.minimal_fees) ?(nonce = default_nonce_config) ?context_path ?(retries_on_failure = default_retries_on_failure_config) ?(user_activated_upgrades = default_user_activated_upgrades) - ?(liquidity_baking = default_liquidity_baking_config) - ?(force_apply = default_force_apply) ?(force = default_force) - ?(state_recorder = default_state_recorder_config) ?extra_operations - ?dal_node_endpoint () = + ?(votes = default_votes_config) ?(force_apply = default_force_apply) + ?(force = default_force) ?(state_recorder = default_state_recorder_config) + ?extra_operations ?dal_node_endpoint () = let fees = {minimal_fees; minimal_nanotez_per_gas_unit; minimal_nanotez_per_byte} in @@ -168,7 +169,7 @@ let make ?(minimal_fees = default_fees_config.minimal_fees) nonce; retries_on_failure; user_activated_upgrades; - liquidity_baking; + toggle_votes = votes; force_apply; force; state_recorder; @@ -235,23 +236,28 @@ let user_activate_upgrades_config_encoding = let open Data_encoding in list (tup2 int32 Protocol_hash.encoding) -let liquidity_baking_config_encoding = +let liquidity_baking_toggle_vote_config_encoding = + Protocol.Alpha_context.Toggle_votes.liquidity_baking_vote_encoding + +let adaptive_inflation_toggle_vote_config_encoding = + Protocol.Alpha_context.Toggle_votes.adaptive_inflation_vote_encoding + +let toggle_votes_config_encoding = let open Data_encoding in - def (String.concat "." [Protocol.name; "liquidity_baking_config"]) + def (String.concat "." [Protocol.name; "toggle_votes_config"]) @@ conv - (fun {vote_file; liquidity_baking_vote} -> - (vote_file, liquidity_baking_vote)) - (fun (vote_file, liquidity_baking_vote) -> - {vote_file; liquidity_baking_vote}) - (obj2 + (fun {vote_file; liquidity_baking_vote; adaptive_inflation_vote} -> + (vote_file, liquidity_baking_vote, adaptive_inflation_vote)) + (fun (vote_file, liquidity_baking_vote, adaptive_inflation_vote) -> + {vote_file; liquidity_baking_vote; adaptive_inflation_vote}) + (obj3 (opt "per_block_vote_file" string) (req "liquidity_baking_vote" - Protocol.Alpha_context.Liquidity_baking - .liquidity_baking_toggle_vote_encoding)) - -let liquidity_baking_toggle_vote_config_encoding = - Protocol.Alpha_context.Liquidity_baking.liquidity_baking_toggle_vote_encoding + liquidity_baking_toggle_vote_config_encoding) + (req + "adaptive_inflation_vote" + adaptive_inflation_toggle_vote_config_encoding)) let force_config_encoding = Data_encoding.bool @@ -289,7 +295,7 @@ let encoding : t Data_encoding.t = nonce; retries_on_failure; user_activated_upgrades; - liquidity_baking; + toggle_votes; force_apply; force; state_recorder; @@ -301,7 +307,7 @@ let encoding : t Data_encoding.t = nonce, retries_on_failure, user_activated_upgrades, - liquidity_baking, + toggle_votes, force_apply, force, state_recorder ), @@ -311,7 +317,7 @@ let encoding : t Data_encoding.t = nonce, retries_on_failure, user_activated_upgrades, - liquidity_baking, + toggle_votes, force_apply, force, state_recorder ), @@ -322,7 +328,7 @@ let encoding : t Data_encoding.t = nonce; retries_on_failure; user_activated_upgrades; - liquidity_baking; + toggle_votes; force_apply; force; state_recorder; @@ -338,7 +344,7 @@ let encoding : t Data_encoding.t = (req "user_activated_upgrades" user_activate_upgrades_config_encoding) - (req "liquidity_baking" liquidity_baking_config_encoding) + (req "votes" toggle_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 57a6dfbfb335ac151336161e7fcec7f21c37bcdd..22ed5ec035084ba4dc0913b10a5dc249e8ed3614 100644 --- a/src/proto_alpha/lib_delegate/baking_configuration.mli +++ b/src/proto_alpha/lib_delegate/baking_configuration.mli @@ -51,10 +51,10 @@ type nonce_config = Deterministic | Random type state_recorder_config = Filesystem | Disabled -type liquidity_baking_config = { +type toggle_votes_config = { vote_file : string option; - liquidity_baking_vote : - Protocol.Alpha_context.Liquidity_baking.liquidity_baking_toggle_vote; + liquidity_baking_vote : Protocol.Alpha_context.Toggle_votes.toggle_vote; + adaptive_inflation_vote : Protocol.Alpha_context.Toggle_votes.toggle_vote; } type t = { @@ -63,7 +63,7 @@ type t = { validation : validation_config; retries_on_failure : int; user_activated_upgrades : (int32 * Protocol_hash.t) list; - liquidity_baking : liquidity_baking_config; + toggle_votes : toggle_votes_config; force_apply : bool; force : bool; state_recorder : state_recorder_config; @@ -81,7 +81,7 @@ val default_retries_on_failure_config : int val default_user_activated_upgrades : (int32 * Protocol_hash.t) list -val default_liquidity_baking_config : liquidity_baking_config +val default_votes_config : toggle_votes_config val default_force_apply : bool @@ -101,7 +101,7 @@ val make : ?context_path:string -> ?retries_on_failure:int -> ?user_activated_upgrades:(int32 * Protocol_hash.t) list -> - ?liquidity_baking:liquidity_baking_config -> + ?votes:toggle_votes_config -> ?force_apply:bool -> ?force:bool -> ?state_recorder:state_recorder_config -> @@ -122,8 +122,12 @@ val user_activate_upgrades_config_encoding : (int32 * Protocol_hash.t) list Data_encoding.t val liquidity_baking_toggle_vote_config_encoding : - Protocol.Alpha_context.Liquidity_baking.liquidity_baking_toggle_vote - Data_encoding.t + Protocol.Alpha_context.Toggle_votes.toggle_vote Data_encoding.t + +val adaptive_inflation_toggle_vote_config_encoding : + Protocol.Alpha_context.Toggle_votes.toggle_vote Data_encoding.t + +val toggle_votes_config_encoding : toggle_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 82b9a38834ca2ebd3ce5792765b94e05e33ee8bb..75f30e8e2122b3e2eb384f9dd5dc15ac5076aaff 100644 --- a/src/proto_alpha/lib_delegate/baking_events.ml +++ b/src/proto_alpha/lib_delegate/baking_events.ml @@ -796,8 +796,16 @@ module Actions = struct ~level:Notice ~msg:"Voting {value} for liquidity baking toggle vote" ( "value", - Protocol.Alpha_context.Liquidity_baking - .liquidity_baking_toggle_vote_encoding ) + Protocol.Alpha_context.Toggle_votes.liquidity_baking_vote_encoding ) + + let vote_for_adaptive_inflation_toggle = + declare_1 + ~section + ~name:"vote_for_adaptive_inflation_toggle" + ~level:Notice + ~msg:"Voting {value} for adaptive inflation toggle vote" + ( "value", + Protocol.Alpha_context.Toggle_votes.adaptive_inflation_vote_encoding ) let no_dal_node = declare_0 @@ -993,15 +1001,15 @@ module Nonces = struct () end -module Liquidity_baking = struct +module Per_block_votes = struct include Internal_event.Simple - let reading_per_block = + let reading_per_block_votes = declare_1 ~section - ~name:"reading_per_block" + ~name:"reading_per_block_votes" ~level:Notice - ~msg:"reading liquidity baking vote file: {path}" + ~msg:"reading votes file: {path}" ("path", Data_encoding.string) let liquidity_baking_toggle_vote = @@ -1011,8 +1019,7 @@ module Liquidity_baking = struct ~level:Notice ~msg:"liquidity baking toggle vote = {value}" ( "value", - Protocol.Alpha_context.Liquidity_baking - .liquidity_baking_toggle_vote_encoding ) + Protocol.Alpha_context.Toggle_votes.liquidity_baking_vote_encoding ) let per_block_vote_file_fail = declare_1 @@ -1022,6 +1029,15 @@ module Liquidity_baking = struct ~msg:"Error reading the block vote file: {errors}" ~pp1:pp_print_top_error_of_trace ("errors", Error_monad.(TzTrace.encoding error_encoding)) + + let adaptive_inflation_toggle_vote = + declare_1 + ~section + ~name:"adaptive_inflation_toggle_vote" + ~level:Notice + ~msg:"adaptive inflation toggle vote = {value}" + ( "value", + Protocol.Alpha_context.Toggle_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 21b6f69116d75a9d887d2901bd68460970c1c9a5..3ef8e3b493393bf5d3db661dbe545f496ec0a93d 100644 --- a/src/proto_alpha/lib_delegate/block_forge.ml +++ b/src/proto_alpha/lib_delegate/block_forge.ml @@ -41,12 +41,13 @@ type simulation_kind = type simulation_mode = Local of Context.index | Node (* [forge_faked_protocol_data ?payload_hash ~payload_round ~seed_nonce_hash - ~liquidity_baking_toggle_vote] forges a fake [block_header_data] with + ~liquidity_baking_toggle_vote ~adaptive_inflation_toggle_vote] forges a fake [block_header_data] with [payload_hash] ([zero] by default), [payload_round], [seed_nonce_hash], [liquidity_baking_toggle_vote] and with an empty [proof_of_work_nonce] and a dummy [signature]. *) let forge_faked_protocol_data ?(payload_hash = Block_payload_hash.zero) - ~payload_round ~seed_nonce_hash ~liquidity_baking_toggle_vote () = + ~payload_round ~seed_nonce_hash ~liquidity_baking_toggle_vote + ~adaptive_inflation_toggle_vote () = Block_header. { contents = @@ -55,7 +56,11 @@ 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; - liquidity_baking_toggle_vote; + toggle_votes = + { + liquidity_baking_vote = liquidity_baking_toggle_vote; + adaptive_inflation_vote = adaptive_inflation_toggle_vote; + }; }; signature = Signature.zero; } @@ -377,8 +382,9 @@ let apply_with_context ~chain_id ~faked_protocol_data ~user_activated_upgrades let forge (cctxt : #Protocol_client_context.full) ~chain_id ~(pred_info : Baking_state.block_info) ~pred_resulting_context_hash ~pred_live_blocks ~timestamp ~round ~liquidity_baking_toggle_vote - ~user_activated_upgrades fees_config ~force_apply ~seed_nonce_hash - ~payload_round simulation_mode simulation_kind constants = + ~adaptive_inflation_toggle_vote ~user_activated_upgrades fees_config + ~force_apply ~seed_nonce_hash ~payload_round simulation_mode simulation_kind + constants = let open Lwt_result_syntax in let hard_gas_limit_per_block = constants.Constants.Parametric.hard_gas_limit_per_block @@ -404,6 +410,7 @@ let forge (cctxt : #Protocol_client_context.full) ~chain_id ~payload_round ~seed_nonce_hash ~liquidity_baking_toggle_vote + ~adaptive_inflation_toggle_vote () in filter_via_node @@ -423,6 +430,7 @@ let forge (cctxt : #Protocol_client_context.full) ~chain_id ~payload_round ~seed_nonce_hash ~liquidity_baking_toggle_vote + ~adaptive_inflation_toggle_vote () in apply_via_node @@ -439,6 +447,7 @@ let forge (cctxt : #Protocol_client_context.full) ~chain_id ~payload_round ~seed_nonce_hash ~liquidity_baking_toggle_vote + ~adaptive_inflation_toggle_vote () in filter_with_context @@ -463,6 +472,7 @@ let forge (cctxt : #Protocol_client_context.full) ~chain_id ~payload_round ~seed_nonce_hash ~liquidity_baking_toggle_vote + ~adaptive_inflation_toggle_vote () in apply_with_context @@ -489,7 +499,11 @@ let forge (cctxt : #Protocol_client_context.full) ~chain_id payload_round; seed_nonce_hash; proof_of_work_nonce; - liquidity_baking_toggle_vote; + toggle_votes = + { + liquidity_baking_vote = liquidity_baking_toggle_vote; + adaptive_inflation_vote = adaptive_inflation_toggle_vote; + }; }) in let unsigned_block_header = diff --git a/src/proto_alpha/lib_delegate/block_forge.mli b/src/proto_alpha/lib_delegate/block_forge.mli index 7afc2ce9791f20e0309badd6ccc15a1c7e344e83..ab8dd25c154b42f12a9953f1407e1337d3f60e98 100644 --- a/src/proto_alpha/lib_delegate/block_forge.mli +++ b/src/proto_alpha/lib_delegate/block_forge.mli @@ -48,7 +48,8 @@ val forge : pred_live_blocks:Block_hash.Set.t -> timestamp:Time.Protocol.t -> round:Round.t -> - liquidity_baking_toggle_vote:Liquidity_baking.liquidity_baking_toggle_vote -> + liquidity_baking_toggle_vote:Toggle_votes.toggle_vote -> + adaptive_inflation_toggle_vote:Toggle_votes.toggle_vote -> user_activated_upgrades:User_activated.upgrades -> Baking_configuration.fees_config -> force_apply:bool -> diff --git a/src/proto_alpha/lib_delegate/client_daemon.ml b/src/proto_alpha/lib_delegate/client_daemon.ml index 3748f0dd300574bac854ec4241a2ed694c7c2529..1ec3357eabaa45fe3c84d351a3d9c757a98d4f67 100644 --- a/src/proto_alpha/lib_delegate/client_daemon.ml +++ b/src/proto_alpha/lib_delegate/client_daemon.ml @@ -72,7 +72,7 @@ let await_protocol_start (cctxt : #Protocol_client_context.full) ~chain = module Baker = struct let run (cctxt : Protocol_client_context.full) ?minimal_fees - ?minimal_nanotez_per_gas_unit ?minimal_nanotez_per_byte ?liquidity_baking + ?minimal_nanotez_per_gas_unit ?minimal_nanotez_per_byte ?votes ?extra_operations ?dal_node_endpoint ?force_apply ?context_path ~chain ~keep_alive delegates = let process () = @@ -83,7 +83,7 @@ module Baker = struct ?minimal_fees ?minimal_nanotez_per_gas_unit ?minimal_nanotez_per_byte - ?liquidity_baking + ?votes ?extra_operations ?dal_node_endpoint ?force_apply diff --git a/src/proto_alpha/lib_delegate/client_daemon.mli b/src/proto_alpha/lib_delegate/client_daemon.mli index 1f3dedf9c305fde73e4516e7aa0352894f6d7a52..6b7d49f79b54d3ec05ae54cfb0af917ac1214e4a 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 -> - ?liquidity_baking:Baking_configuration.liquidity_baking_config -> + ?votes:Baking_configuration.toggle_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/liquidity_baking_vote.ml b/src/proto_alpha/lib_delegate/per_block_vote_file.ml similarity index 53% rename from src/proto_alpha/lib_delegate/liquidity_baking_vote.ml rename to src/proto_alpha/lib_delegate/per_block_vote_file.ml index a7afef165a95c38b4db9f9d977afb7a8406d80fc..53923bec30fd06ff2b028a42721e89f11557d54d 100644 --- a/src/proto_alpha/lib_delegate/liquidity_baking_vote.ml +++ b/src/proto_alpha/lib_delegate/per_block_vote_file.ml @@ -1,7 +1,7 @@ (*****************************************************************************) (* *) (* Open Source License *) -(* Copyright (c) 2021 Nomadic Labs *) +(* Copyright (c) 2023 Nomadic Labs *) (* *) (* Permission is hereby granted, free of charge, to any person obtaining a *) (* copy of this software and associated documentation files (the "Software"),*) @@ -24,19 +24,33 @@ (*****************************************************************************) open Protocol_client_context -module Events = Baking_events.Liquidity_baking +module Events = Baking_events.Per_block_votes let default_vote_json_filename = "per_block_votes.json" +type per_block_votes = { + liquidity_baking_toggle_vote : + Protocol.Alpha_context.Toggle_votes.toggle_vote; + adaptive_inflation_toggle_vote_opt : + Protocol.Alpha_context.Toggle_votes.toggle_vote option; +} + let vote_file_content_encoding = let open Data_encoding in - def - (String.concat "." [Protocol.name; "vote_file_content"]) - (obj1 - (req - "liquidity_baking_toggle_vote" - Protocol.Alpha_context.Liquidity_baking - .liquidity_baking_toggle_vote_encoding)) + def (String.concat "." [Protocol.name; "vote_file_content"]) + @@ conv + (fun {liquidity_baking_toggle_vote; adaptive_inflation_toggle_vote_opt} -> + (liquidity_baking_toggle_vote, adaptive_inflation_toggle_vote_opt)) + (fun (liquidity_baking_toggle_vote, adaptive_inflation_toggle_vote_opt) -> + {liquidity_baking_toggle_vote; adaptive_inflation_toggle_vote_opt}) + (obj2 + (req + "liquidity_baking_toggle_vote" + Protocol.Alpha_context.Toggle_votes.liquidity_baking_vote_encoding) + (opt + "adaptive_inflation_toggle_vote" + Protocol.Alpha_context.Toggle_votes + .adaptive_inflation_vote_encoding)) type error += Block_vote_file_not_found of string @@ -51,7 +65,7 @@ type error += Missing_vote_on_startup let () = register_error_kind `Permanent - ~id:"liquidity_baking_vote.block_vote_file_not_found" + ~id:"per_block_vote_file.block_vote_file_not_found" ~title: "The provided block vote file path does not point to an existing file." ~description: @@ -69,7 +83,7 @@ let () = (fun file_path -> Block_vote_file_not_found file_path) ; register_error_kind `Permanent - ~id:"liquidity_baking_vote.block_vote_file_invalid" + ~id:"per_block_vote_file.block_vote_file_invalid" ~title: "The provided block vote file path does not point to a valid JSON file." ~description: @@ -86,7 +100,7 @@ let () = (fun file_path -> Block_vote_file_invalid file_path) ; register_error_kind `Permanent - ~id:"liquidity_baking_vote.block_vote_file_wrong_content" + ~id:"per_block_vote_file.block_vote_file_wrong_content" ~title:"The content of the provided block vote file is unexpected." ~description: "The block vote file is valid JSON but its content is not the expected \ @@ -95,10 +109,14 @@ let () = Format.fprintf ppf "@[The provided block vote file \"%s\" is a valid JSON file but its \ - content is unexpected. Expecting a JSON file containing either \ - '{\"liquidity_baking_toggle_vote\": \"on\"}', or \ - '{\"liquidity_baking_toggle_vote\": \"off\"}', or \ - '{\"liquidity_baking_toggle_vote\": \"pass\"}'.@]" + content is unexpected. Expecting a JSON file containing \ + '{\"liquidity_baking_toggle_vote\": value1, \ + \"adaptive_inflation_toggle_vote\": value2}' or \ + '{\"adaptive_inflation_toggle_vote\": value1, \ + \"liquidity_baking_toggle_vote\": value2}', where value1 is one of \ + \"on\", \"off\", or \"pass\" and value2 is one of \"on\", \"off\", or \ + \"pass\", or '{\"liquidity_baking_toggle_vote\": value}' where value \ + is one of \"on\", \"off\", or \"pass\".@]" file_path) Data_encoding.(obj1 (req "file_path" string)) (function @@ -107,7 +125,7 @@ let () = register_error_kind `Permanent ~id: - "liquidity_baking_vote.block_vote_file_missing_liquidity_baking_toggle_vote" + "per_block_vote_file.block_vote_file_missing_liquidity_baking_toggle_vote" ~title: "In the provided block vote file, no entry for liquidity baking toggle \ vote was found" @@ -118,10 +136,14 @@ let () = Format.fprintf ppf "@[In the provided block vote file \"%s\", the \ - \"liquidity_baking_toggle_vote\" boolean field is missing. Expecting \ - a JSON file containing either '{\"liquidity_baking_toggle_vote\": \ - \"on\"}', or '{\"liquidity_baking_toggle_vote\": \"off\"}', or \ - '{\"liquidity_baking_toggle_vote\": \"pass\"}'.@]" + \"liquidity_baking_toggle_vote\" field is missing. Expecting a JSON \ + file containing '{\"liquidity_baking_toggle_vote\": value1, \ + \"adaptive_inflation_toggle_vote\": value2}' or \ + '{\"adaptive_inflation_toggle_vote\": value1, \ + \"liquidity_baking_toggle_vote\": value2}', where value1 is one of \ + \"on\", \"off\", or \"pass\" and value2 is one of \"on\", \"off\", or \ + \"pass\", or '{\"liquidity_baking_toggle_vote\": value}' where value \ + is one of \"on\", \"off\", or \"pass\".@]" file_path) Data_encoding.(obj1 (req "file_path" string)) (function @@ -132,18 +154,18 @@ let () = Block_vote_file_missing_liquidity_baking_toggle_vote file_path) ; register_error_kind `Permanent - ~id:"liquidity_baking_vote.missing_vote_on_startup" + ~id:"per_block_vote_file.missing_vote_on_startup" ~title:"Missing vote on startup" ~description: - "No CLI flag, file path, or vote file in default location provided on \ + "No CLI flag, file path, or votes file in default location provided on \ startup" ~pp:(fun fmt () -> Format.fprintf fmt "Missing liquidity baking toggle vote, please use either the \ - --liquidity-baking-toggle-vote or --votefile option or a vote file in \ - the default location: per_block_votes.json in the current working \ - directory or in the baker directory.") + --liquidity-baking-toggle-vote option, or the --votefile option or a \ + votes file in the default location: per_block_votes.json in the \ + current working directory or in the baker directory.") Data_encoding.empty (function Missing_vote_on_startup -> Some () | _ -> None) (fun () -> Missing_vote_on_startup) @@ -155,55 +177,107 @@ let check_file_exists file = in if file_exists then return_unit else tzfail (Block_vote_file_not_found file) -let read_liquidity_baking_toggle_vote ~per_block_vote_file : 'a tzresult Lwt.t = +let read_toggle_votes ~per_block_vote_file : 'a tzresult Lwt.t = let open Lwt_result_syntax in - let*! () = Events.(emit reading_per_block) per_block_vote_file in + let*! () = Events.(emit reading_per_block_votes) per_block_vote_file in let* () = check_file_exists per_block_vote_file in let* votes_json = trace (Block_vote_file_invalid per_block_vote_file) (Lwt_utils_unix.Json.read_file per_block_vote_file) in - let* liquidity_baking_toggle_vote = + let* votes = trace (Block_vote_file_wrong_content per_block_vote_file) (protect (fun () -> return (Data_encoding.Json.destruct vote_file_content_encoding votes_json))) in - return liquidity_baking_toggle_vote + return votes -let read_liquidity_baking_toggle_vote_no_fail ~default_liquidity_baking_vote - ~per_block_vote_file = - read_liquidity_baking_toggle_vote ~per_block_vote_file >>= function - | Ok vote -> Lwt.return vote +let read_toggle_votes_no_fail ~default ~per_block_vote_file = + read_toggle_votes ~per_block_vote_file >>= function | Error errs -> Events.(emit per_block_vote_file_fail) errs >>= fun () -> - Lwt.return default_liquidity_baking_vote + Lwt.return default + | Ok + { + liquidity_baking_toggle_vote; + adaptive_inflation_toggle_vote_opt = Some adaptive_inflation_toggle_vote; + } -> + Lwt.return + Protocol.Alpha_context.Toggle_votes. + { + liquidity_baking_vote = liquidity_baking_toggle_vote; + adaptive_inflation_vote = adaptive_inflation_toggle_vote; + } + | Ok {liquidity_baking_toggle_vote; adaptive_inflation_toggle_vote_opt = None} + -> + Lwt.return + {default with liquidity_baking_vote = liquidity_baking_toggle_vote} -let load_liquidity_baking_config ~per_block_vote_file_arg - ~(toggle_vote_arg : - Protocol.Alpha_context.Liquidity_baking.liquidity_baking_toggle_vote - option) : Baking_configuration.liquidity_baking_config tzresult Lwt.t = +let load_toggle_votes_config ~default_liquidity_baking_vote + ~default_adaptive_inflation_vote ~per_block_vote_file : + Baking_configuration.toggle_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. *) let* config = - match (per_block_vote_file_arg, toggle_vote_arg) with - | None, None -> tzfail Missing_vote_on_startup - | None, Some vote -> + match + ( per_block_vote_file, + default_liquidity_baking_vote, + default_adaptive_inflation_vote ) + with + | None, None, _ -> tzfail Missing_vote_on_startup + | None, Some liquidity_baking_vote, None -> + return + { + Baking_configuration.vote_file = None; + liquidity_baking_vote; + adaptive_inflation_vote = + Protocol.Alpha_context.Toggle_votes.Toggle_vote_pass; + } + | None, Some liquidity_baking_vote, Some adaptive_inflation_vote -> return - {Baking_configuration.vote_file = None; liquidity_baking_vote = vote} - | Some per_block_vote_file, _ -> ( - let*! (res : _ tzresult) = - read_liquidity_baking_toggle_vote ~per_block_vote_file - in + { + Baking_configuration.vote_file = None; + liquidity_baking_vote; + adaptive_inflation_vote; + } + | Some per_block_vote_file, _, _ -> ( + let*! (res : _ tzresult) = read_toggle_votes ~per_block_vote_file in match res with - | Ok vote -> + | Ok + { + liquidity_baking_toggle_vote = liquidity_baking_vote; + adaptive_inflation_toggle_vote_opt = None; + } -> ( + match default_adaptive_inflation_vote with + | Some adaptive_inflation_vote -> + return + { + Baking_configuration.vote_file = Some per_block_vote_file; + liquidity_baking_vote; + adaptive_inflation_vote; + } + | None -> + return + { + Baking_configuration.vote_file = Some per_block_vote_file; + liquidity_baking_vote; + adaptive_inflation_vote = + Protocol.Alpha_context.Toggle_votes.Toggle_vote_pass; + }) + | Ok + { + liquidity_baking_toggle_vote = liquidity_baking_vote; + adaptive_inflation_toggle_vote_opt = Some adaptive_inflation_vote; + } -> return { Baking_configuration.vote_file = Some per_block_vote_file; - liquidity_baking_vote = vote; + liquidity_baking_vote; + adaptive_inflation_vote; } | Error errs -> Events.(emit per_block_vote_file_fail) errs >>= fun () -> @@ -212,4 +286,7 @@ let load_liquidity_baking_config ~per_block_vote_file_arg let*! () = Events.(emit liquidity_baking_toggle_vote) config.liquidity_baking_vote in + let*! () = + Events.(emit adaptive_inflation_toggle_vote) config.adaptive_inflation_vote + in return config diff --git a/src/proto_alpha/lib_delegate/liquidity_baking_vote.mli b/src/proto_alpha/lib_delegate/per_block_vote_file.mli similarity index 67% rename from src/proto_alpha/lib_delegate/liquidity_baking_vote.mli rename to src/proto_alpha/lib_delegate/per_block_vote_file.mli index e74b38031771ee63727514ea8dcc853ab5c1a5ad..e2832aa08a316bf504e8451c85057552b454c6c3 100644 --- a/src/proto_alpha/lib_delegate/liquidity_baking_vote.mli +++ b/src/proto_alpha/lib_delegate/per_block_vote_file.mli @@ -23,12 +23,24 @@ (* *) (*****************************************************************************) -(** This module is used to load the baker's liquidity baking vote +(** This module is used to load the baker's per block votes configurations. When a file is given as configuration, its content is expected to be a valid JSON matching the following examples: - {v {"liquidity_baking_toggle_vote": "on"} v} - {v {"liquidity_baking_toggle_vote": "off"} v} - {v {"liquidity_baking_toggle_vote": "pass"} v} + - {v {"adaptive_inflation_toggle_vote": "on"} v} + - {v {"adaptive_inflation_toggle_vote": "off"} v} + - {v {"adaptive_inflation_toggle_vote": "pass"} v} + - {v {"liquidity_baking_toggle_vote": "on","adaptive_inflation_toggle_vote": "on"} v} + - {v {"liquidity_baking_toggle_vote": "on","adaptive_inflation_toggle_vote": "off"} v} + - {v {"liquidity_baking_toggle_vote": "on","adaptive_inflation_toggle_vote": "pass"} v} + - {v {"liquidity_baking_toggle_vote": "off","adaptive_inflation_toggle_vote": "on"} v} + - {v {"liquidity_baking_toggle_vote": "off","adaptive_inflation_toggle_vote": "off"} v} + - {v {"liquidity_baking_toggle_vote": "off","adaptive_inflation_toggle_vote": "pass"} v} + - {v {"liquidity_baking_toggle_vote": "pass","adaptive_inflation_toggle_vote": "on"} v} + - {v {"liquidity_baking_toggle_vote": "pass","adaptive_inflation_toggle_vote": "off"} v} + - {v {"liquidity_baking_toggle_vote": "pass","adaptive_inflation_toggle_vote": "pass"} v} Moreover, in order to handle dynamic voting (i.e. change the baker's vote without having to restart it), each time a block is @@ -52,20 +64,21 @@ type error += Missing_vote_on_startup starts. *) val default_vote_json_filename : string -(** Reads the content of [per_block_vote_file] and returns a vote. If +(** Reads the content of [per_block_vote_file] and returns the votes. If any error occurs (e.g. Non-existing file, unparsable content, - etc.), [default_liquidity_baking_vote] will be returned. *) -val read_liquidity_baking_toggle_vote_no_fail : - default_liquidity_baking_vote:Liquidity_baking.liquidity_baking_toggle_vote -> + etc.), given default values will be used to fill the gaps. *) +val read_toggle_votes_no_fail : + default:Toggle_votes.toggle_votes -> per_block_vote_file:string -> - Liquidity_baking.liquidity_baking_toggle_vote Lwt.t + Toggle_votes.toggle_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_liquidity_baking_config : - per_block_vote_file_arg:string option -> - toggle_vote_arg:Liquidity_baking.liquidity_baking_toggle_vote option -> - Baking_configuration.liquidity_baking_config tzresult Lwt.t +val load_toggle_votes_config : + default_liquidity_baking_vote:Toggle_votes.toggle_vote option -> + default_adaptive_inflation_vote:Toggle_votes.toggle_vote option -> + per_block_vote_file:string option -> + Baking_configuration.toggle_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 bced9bf820c3ab9755bcf82578904e94569eb1c9..d116e513d0f635413fadd24d2f4e82ef35f16a61 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 @@ -928,6 +928,16 @@ let genesis_protocol_data (baker_sk : Signature.secret_key) ~payload_round:Alpha_context.Round.zero [] in + let toggle_votes = + { + Protocol.Toggle_votes_repr.liquidity_baking_vote = + Baking_configuration.default_votes_config + .Baking_configuration.liquidity_baking_vote; + adaptive_inflation_vote = + Baking_configuration.default_votes_config + .Baking_configuration.adaptive_inflation_vote; + } + in let contents = Protocol.Alpha_context.Block_header. { @@ -935,9 +945,7 @@ let genesis_protocol_data (baker_sk : Signature.secret_key) payload_round = Alpha_context.Round.zero; proof_of_work_nonce; seed_nonce_hash = None; - liquidity_baking_toggle_vote = - Baking_configuration.default_liquidity_baking_config - .liquidity_baking_vote; + toggle_votes; } in let unsigned_header = diff --git a/src/proto_alpha/lib_plugin/RPC.ml b/src/proto_alpha/lib_plugin/RPC.ml index 4869459ded9fbed2d612b81a007269db8763a155..a0b761a705a0c14f3efe70e4ee6b3e777c351512 100644 --- a/src/proto_alpha/lib_plugin/RPC.ml +++ b/src/proto_alpha/lib_plugin/RPC.ml @@ -969,7 +969,8 @@ module Scripts = struct mode = application_mode; op_count = 0; migration_balance_updates = []; - liquidity_baking_toggle_ema = Liquidity_baking.Toggle_EMA.zero; + liquidity_baking_toggle_ema = Toggle_EMA.zero; + adaptive_inflation_toggle_ema = Toggle_EMA.zero; implicit_operations_results = []; } in @@ -2667,11 +2668,14 @@ module Forge = struct Hex Alpha_context.Constants.proof_of_work_nonce_size) empty_proof_of_work_nonce) - Liquidity_baking.( + Toggle_votes.( dft - "liquidity_baking_toggle_vote" - liquidity_baking_toggle_vote_encoding - LB_pass)) + "toggle_votes" + toggle_votes_encoding + { + liquidity_baking_vote = Toggle_vote_pass; + adaptive_inflation_vote = Toggle_vote_pass; + })) ~output:(obj1 (req "protocol_data" (bytes Hex))) RPC_path.(path / "protocol_data") end @@ -2694,7 +2698,7 @@ module Forge = struct payload_round, seed_nonce_hash, proof_of_work_nonce, - liquidity_baking_toggle_vote ) + toggle_votes ) -> return (Data_encoding.Binary.to_bytes_exn @@ -2704,7 +2708,7 @@ module Forge = struct payload_round; seed_nonce_hash; proof_of_work_nonce; - liquidity_baking_toggle_vote; + toggle_votes; })) module Manager = struct @@ -2841,7 +2845,7 @@ module Forge = struct let protocol_data ctxt block ?(payload_hash = Block_payload_hash.zero) ?(payload_round = Round.zero) ?seed_nonce_hash ?(proof_of_work_nonce = empty_proof_of_work_nonce) - ~liquidity_baking_toggle_vote () = + ~liquidity_baking_toggle_vote ~adaptive_inflation_toggle_vote () = RPC_context.make_call0 S.protocol_data ctxt @@ -2851,7 +2855,10 @@ module Forge = struct payload_round, seed_nonce_hash, proof_of_work_nonce, - liquidity_baking_toggle_vote ) + { + liquidity_baking_vote = liquidity_baking_toggle_vote; + adaptive_inflation_vote = adaptive_inflation_toggle_vote; + } ) end module Parse = struct diff --git a/src/proto_alpha/lib_protocol/TEZOS_PROTOCOL b/src/proto_alpha/lib_protocol/TEZOS_PROTOCOL index 68c78822f3cb4dbadf204ccb496d930914be933b..ca742908aa9f6a6d4e92fc04a2f0af0c6ef24052 100644 --- a/src/proto_alpha/lib_protocol/TEZOS_PROTOCOL +++ b/src/proto_alpha/lib_protocol/TEZOS_PROTOCOL @@ -106,7 +106,8 @@ "Bond_id_repr", "Vote_repr", - "Liquidity_baking_repr", + "Toggle_EMA", + "Toggle_votes_repr", "Block_header_repr", "Destination_repr", "Script_int", diff --git a/src/proto_alpha/lib_protocol/alpha_context.ml b/src/proto_alpha/lib_protocol/alpha_context.ml index 70c8061a3a780c2695276ca6496fd34fe1970bba..f3431547bde816bde5a1252b3c0122939cbb57a5 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.ml +++ b/src/proto_alpha/lib_protocol/alpha_context.ml @@ -649,9 +649,10 @@ 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 Liquidity_baking = struct - include Liquidity_baking_repr include Liquidity_baking_storage end diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index ce0980048d0ec498c313130b9fc02af9a14212c7..b26022f5e6f229c5b3edf2b501e855198266c712 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -4349,8 +4349,7 @@ module Block_header : sig payload_round : Round.t; seed_nonce_hash : Nonce_hash.t option; proof_of_work_nonce : bytes; - liquidity_baking_toggle_vote : - Liquidity_baking_repr.liquidity_baking_toggle_vote; + toggle_votes : Toggle_votes_repr.toggle_votes; } type protocol_data = {contents : contents; signature : signature} @@ -5206,33 +5205,45 @@ module Parameters : sig val encoding : t Data_encoding.t end -(** This module re-exports definitions from {!Liquidity_baking_repr} and - {!Liquidity_baking_storage}. *) -module Liquidity_baking : sig - type liquidity_baking_toggle_vote = - Liquidity_baking_repr.liquidity_baking_toggle_vote = - | LB_on - | LB_off - | LB_pass +(** This module re-exports definitions from {!Toggle_EMA} *) +module Toggle_EMA : sig + type t - val liquidity_baking_toggle_vote_encoding : - liquidity_baking_toggle_vote Data_encoding.encoding + val zero : t - val get_cpmm_address : context -> Contract_hash.t tzresult Lwt.t + val to_int32 : t -> Int32.t - module Toggle_EMA : sig - type t + val encoding : t Data_encoding.t +end - val zero : t +(** 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 + + type toggle_votes = Toggle_votes_repr.toggle_votes = { + liquidity_baking_vote : toggle_vote; + adaptive_inflation_vote : toggle_vote; + } - val to_int32 : t -> Int32.t + val liquidity_baking_vote_encoding : toggle_vote Data_encoding.encoding - val encoding : t Data_encoding.t - end + val adaptive_inflation_vote_encoding : toggle_vote Data_encoding.encoding + + val toggle_votes_encoding : toggle_votes Data_encoding.encoding + + val compute_new_ema : toggle_vote:toggle_vote -> Toggle_EMA.t -> Toggle_EMA.t +end + +(** This module re-exports definitions from {!Liquidity_baking_storage}. *) +module Liquidity_baking : sig + val get_cpmm_address : context -> Contract_hash.t tzresult Lwt.t val on_subsidy_allowed : context -> - toggle_vote:liquidity_baking_toggle_vote -> + toggle_vote:Toggle_votes.toggle_vote -> (context -> Contract_hash.t -> (context * 'a list) tzresult Lwt.t) -> (context * 'a list * Toggle_EMA.t) tzresult Lwt.t end diff --git a/src/proto_alpha/lib_protocol/apply.ml b/src/proto_alpha/lib_protocol/apply.ml index 4a9a8dbaa46409c6e2f84d8bbe3a1031b7f742ec..8421f59d3746fe749dc198325f92c0566bf96fec 100644 --- a/src/proto_alpha/lib_protocol/apply.ml +++ b/src/proto_alpha/lib_protocol/apply.ml @@ -1731,7 +1731,8 @@ type application_state = { mode : mode; op_count : int; migration_balance_updates : Receipt.balance_updates; - liquidity_baking_toggle_ema : Liquidity_baking.Toggle_EMA.t; + liquidity_baking_toggle_ema : Toggle_EMA.t; + adaptive_inflation_toggle_ema : Toggle_EMA.t; implicit_operations_results : Apply_results.packed_successful_manager_operation_result list; } @@ -2309,8 +2310,8 @@ let begin_application ctxt chain_id ~migration_balance_updates ~round:block_header.protocol_data.contents.payload_round in let toggle_vote = - block_header.Block_header.protocol_data.contents - .liquidity_baking_toggle_vote + block_header.Block_header.protocol_data.contents.toggle_votes + .liquidity_baking_vote in let* ctxt, liquidity_baking_operations_results, liquidity_baking_toggle_ema = apply_liquidity_baking_subsidy ctxt ~toggle_vote @@ -2339,6 +2340,7 @@ let begin_application ctxt chain_id ~migration_balance_updates op_count = 0; migration_balance_updates; liquidity_baking_toggle_ema; + adaptive_inflation_toggle_ema = Toggle_EMA.zero; implicit_operations_results = Apply_results.pack_migration_operation_results migration_operation_results @@ -2370,7 +2372,7 @@ 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.liquidity_baking_toggle_vote in + let toggle_vote = block_data_contents.toggle_votes.liquidity_baking_vote in let* ctxt, liquidity_baking_operations_results, liquidity_baking_toggle_ema = apply_liquidity_baking_subsidy ctxt ~toggle_vote in @@ -2397,6 +2399,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 = Toggle_EMA.zero; implicit_operations_results = Apply_results.pack_migration_operation_results migration_operation_results @@ -2407,7 +2410,7 @@ 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 = Liquidity_baking.LB_pass in + let toggle_vote = Toggle_votes.Toggle_vote_pass in let* ctxt, liquidity_baking_operations_results, liquidity_baking_toggle_ema = apply_liquidity_baking_subsidy ctxt ~toggle_vote in @@ -2429,6 +2432,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 = Toggle_EMA.zero; implicit_operations_results = Apply_results.pack_migration_operation_results migration_operation_results @@ -2436,9 +2440,9 @@ let begin_partial_construction ctxt chain_id ~migration_balance_updates } let finalize_application ctxt block_data_contents ~round ~predecessor_hash - ~liquidity_baking_toggle_ema ~implicit_operations_results - ~migration_balance_updates ~(block_producer : Consensus_key.t) - ~(payload_producer : Consensus_key.t) = + ~liquidity_baking_toggle_ema ~adaptive_inflation_toggle_ema + ~implicit_operations_results ~migration_balance_updates + ~(block_producer : Consensus_key.t) ~(payload_producer : Consensus_key.t) = let open Lwt_result_syntax in let level = Level.current ctxt in let endorsing_power = Consensus.current_endorsement_power ctxt in @@ -2524,6 +2528,7 @@ let finalize_application ctxt block_data_contents ~round ~predecessor_hash deactivated; balance_updates; liquidity_baking_toggle_ema; + adaptive_inflation_toggle_ema; implicit_operations_results; dal_attestation; } @@ -2573,6 +2578,7 @@ let finalize_block (application_state : application_state) shell_header_opt = let { ctxt; liquidity_baking_toggle_ema; + adaptive_inflation_toggle_ema; implicit_operations_results; migration_balance_updates; op_count; @@ -2613,6 +2619,7 @@ let finalize_block (application_state : application_state) shell_header_opt = ~round ~predecessor_hash ~liquidity_baking_toggle_ema + ~adaptive_inflation_toggle_ema ~implicit_operations_results ~migration_balance_updates ~block_producer @@ -2643,6 +2650,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; implicit_operations_results; dal_attestation = None; } ) @@ -2665,6 +2673,7 @@ let finalize_block (application_state : application_state) shell_header_opt = ~round ~predecessor_hash:shell.predecessor ~liquidity_baking_toggle_ema + ~adaptive_inflation_toggle_ema ~implicit_operations_results ~migration_balance_updates ~block_producer diff --git a/src/proto_alpha/lib_protocol/apply.mli b/src/proto_alpha/lib_protocol/apply.mli index b20cfdb108eb8a168d05c90014e20ca15696e757..9f1d0de95119c4107f48315153bb15fb375e15a8 100644 --- a/src/proto_alpha/lib_protocol/apply.mli +++ b/src/proto_alpha/lib_protocol/apply.mli @@ -68,7 +68,8 @@ type application_state = { mode : mode; op_count : int; migration_balance_updates : Receipt.balance_updates; - liquidity_baking_toggle_ema : Liquidity_baking.Toggle_EMA.t; + liquidity_baking_toggle_ema : Toggle_EMA.t; + adaptive_inflation_toggle_ema : Toggle_EMA.t; 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 9778fad1feb8d04f9199f1677cfaca609ae0f065..fa860722de71bfc6fa5a178136a68206dba51b14 100644 --- a/src/proto_alpha/lib_protocol/apply_results.ml +++ b/src/proto_alpha/lib_protocol/apply_results.ml @@ -2494,7 +2494,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 : Liquidity_baking.Toggle_EMA.t; + liquidity_baking_toggle_ema : Toggle_EMA.t; + adaptive_inflation_toggle_ema : Toggle_EMA.t; implicit_operations_results : packed_successful_manager_operation_result list; dal_attestation : Dal.Attestation.t option; } @@ -2514,6 +2515,7 @@ let block_metadata_encoding = deactivated; balance_updates; liquidity_baking_toggle_ema; + adaptive_inflation_toggle_ema; implicit_operations_results; dal_attestation; } -> @@ -2525,6 +2527,7 @@ let block_metadata_encoding = deactivated, balance_updates, liquidity_baking_toggle_ema, + adaptive_inflation_toggle_ema, implicit_operations_results ), (proposer_active_key, baker_active_key, consumed_gas, dal_attestation) )) @@ -2536,6 +2539,7 @@ let block_metadata_encoding = deactivated, balance_updates, liquidity_baking_toggle_ema, + adaptive_inflation_toggle_ema, implicit_operations_results ), ( proposer_active_key, baker_active_key, @@ -2551,11 +2555,12 @@ let block_metadata_encoding = deactivated; balance_updates; liquidity_baking_toggle_ema; + adaptive_inflation_toggle_ema; implicit_operations_results; dal_attestation; }) (merge_objs - (obj9 + (obj10 (req "proposer" Signature.Public_key_hash.encoding) (req "baker" Signature.Public_key_hash.encoding) (req "level_info" Level.encoding) @@ -2563,9 +2568,8 @@ let block_metadata_encoding = (req "nonce_hash" (option Nonce_hash.encoding)) (req "deactivated" (list Signature.Public_key_hash.encoding)) (dft "balance_updates" Receipt.balance_updates_encoding []) - (req - "liquidity_baking_toggle_ema" - Liquidity_baking.Toggle_EMA.encoding) + (req "liquidity_baking_toggle_ema" Toggle_EMA.encoding) + (req "adaptive_inflation_toggle_ema" Toggle_EMA.encoding) (req "implicit_operations_results" (list successful_manager_operation_result_encoding))) diff --git a/src/proto_alpha/lib_protocol/apply_results.mli b/src/proto_alpha/lib_protocol/apply_results.mli index 6011179e6dd9236af91bcc7fbe9e7d13de8e3ae2..673c4b801e16caf6b398b8e0ce93f6338cfea35c 100644 --- a/src/proto_alpha/lib_protocol/apply_results.mli +++ b/src/proto_alpha/lib_protocol/apply_results.mli @@ -317,7 +317,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 : Liquidity_baking.Toggle_EMA.t; + liquidity_baking_toggle_ema : Toggle_EMA.t; + adaptive_inflation_toggle_ema : Toggle_EMA.t; 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 c9a1752eacc1d36863823d6d8917a8e38c52d95c..4f37fefa23277dbd055aa4517925b630a8bbf2f7 100644 --- a/src/proto_alpha/lib_protocol/block_header_repr.ml +++ b/src/proto_alpha/lib_protocol/block_header_repr.ml @@ -30,8 +30,7 @@ type contents = { payload_round : Round_repr.t; seed_nonce_hash : Nonce_hash.t option; proof_of_work_nonce : bytes; - liquidity_baking_toggle_vote : - Liquidity_baking_repr.liquidity_baking_toggle_vote; + toggle_votes : Toggle_votes_repr.toggle_votes; } type protocol_data = {contents : contents; signature : Signature.t} @@ -70,42 +69,84 @@ let of_watermark = function let contents_encoding = let open Data_encoding in - def "block_header.alpha.unsigned_contents" - @@ conv - (fun { - payload_hash; - payload_round; - seed_nonce_hash; - proof_of_work_nonce; - liquidity_baking_toggle_vote; - } -> - ( payload_hash, - payload_round, - proof_of_work_nonce, - seed_nonce_hash, - liquidity_baking_toggle_vote )) - (fun ( payload_hash, - payload_round, - proof_of_work_nonce, - seed_nonce_hash, - liquidity_baking_toggle_vote ) -> - { - payload_hash; - payload_round; - seed_nonce_hash; - proof_of_work_nonce; - liquidity_baking_toggle_vote; - }) - (obj5 - (req "payload_hash" Block_payload_hash.encoding) - (req "payload_round" Round_repr.encoding) - (req - "proof_of_work_nonce" - (Fixed.bytes Hex Constants_repr.proof_of_work_nonce_size)) - (opt "seed_nonce_hash" Nonce_hash.encoding) - (req - "liquidity_baking_toggle_vote" - Liquidity_baking_repr.liquidity_baking_toggle_vote_encoding)) + let json = + conv + (fun { + payload_hash; + payload_round; + seed_nonce_hash; + proof_of_work_nonce; + toggle_votes = {liquidity_baking_vote; adaptive_inflation_vote}; + } -> + ( payload_hash, + payload_round, + proof_of_work_nonce, + seed_nonce_hash, + liquidity_baking_vote, + adaptive_inflation_vote )) + (fun ( payload_hash, + payload_round, + proof_of_work_nonce, + seed_nonce_hash, + liquidity_baking_vote, + adaptive_inflation_vote ) -> + { + payload_hash; + payload_round; + seed_nonce_hash; + proof_of_work_nonce; + toggle_votes = {liquidity_baking_vote; adaptive_inflation_vote}; + }) + (obj6 + (req "payload_hash" Block_payload_hash.encoding) + (req "payload_round" Round_repr.encoding) + (req + "proof_of_work_nonce" + (Fixed.bytes Hex Constants_repr.proof_of_work_nonce_size)) + (opt "seed_nonce_hash" Nonce_hash.encoding) + (req + "liquidity_baking_toggle_vote" + Toggle_votes_repr.liquidity_baking_vote_encoding) + (req + "adaptive_inflation_toggle_vote" + Toggle_votes_repr.adaptive_inflation_vote_encoding)) + in + let binary = + conv + (fun { + payload_hash; + payload_round; + seed_nonce_hash; + proof_of_work_nonce; + toggle_votes; + } -> + ( payload_hash, + payload_round, + proof_of_work_nonce, + seed_nonce_hash, + toggle_votes )) + (fun ( payload_hash, + payload_round, + proof_of_work_nonce, + seed_nonce_hash, + toggle_votes ) -> + { + payload_hash; + payload_round; + seed_nonce_hash; + proof_of_work_nonce; + toggle_votes; + }) + (obj5 + (req "payload_hash" Block_payload_hash.encoding) + (req "payload_round" Round_repr.encoding) + (req + "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)) + in + def "block_header.alpha.unsigned_contents" @@ splitted ~binary ~json let protocol_data_encoding = let open Data_encoding in @@ -164,7 +205,11 @@ 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; - liquidity_baking_toggle_vote = LB_pass; + toggle_votes = + { + liquidity_baking_vote = Toggle_vote_pass; + adaptive_inflation_vote = Toggle_vote_pass; + }; } in Data_encoding.Binary.length diff --git a/src/proto_alpha/lib_protocol/block_header_repr.mli b/src/proto_alpha/lib_protocol/block_header_repr.mli index 4ee5715933396bb2efdc357edd1dbefe4942f676..9960bff5a90704efbecdf854254adc15716ca5be 100644 --- a/src/proto_alpha/lib_protocol/block_header_repr.mli +++ b/src/proto_alpha/lib_protocol/block_header_repr.mli @@ -30,8 +30,7 @@ type contents = { payload_round : Round_repr.t; seed_nonce_hash : Nonce_hash.t option; proof_of_work_nonce : bytes; - liquidity_baking_toggle_vote : - Liquidity_baking_repr.liquidity_baking_toggle_vote; + toggle_votes : Toggle_votes_repr.toggle_votes; } type protocol_data = {contents : contents; signature : Signature.t} diff --git a/src/proto_alpha/lib_protocol/dune b/src/proto_alpha/lib_protocol/dune index f67e2eb7ffb6e5dbd30711c25f25c4c228c2f9fd..4e4f8a0336e9bfce47b5e03b32d00a8222276994 100644 --- a/src/proto_alpha/lib_protocol/dune +++ b/src/proto_alpha/lib_protocol/dune @@ -129,7 +129,8 @@ Zk_rollup_circuit_public_inputs_repr Bond_id_repr Vote_repr - Liquidity_baking_repr + Toggle_EMA + Toggle_votes_repr Block_header_repr Destination_repr Script_int @@ -409,7 +410,8 @@ zk_rollup_circuit_public_inputs_repr.mli bond_id_repr.ml bond_id_repr.mli vote_repr.ml vote_repr.mli - liquidity_baking_repr.ml liquidity_baking_repr.mli + toggle_EMA.ml toggle_EMA.mli + toggle_votes_repr.ml toggle_votes_repr.mli block_header_repr.ml block_header_repr.mli destination_repr.ml destination_repr.mli script_int.ml script_int.mli @@ -691,7 +693,8 @@ zk_rollup_circuit_public_inputs_repr.mli bond_id_repr.ml bond_id_repr.mli vote_repr.ml vote_repr.mli - liquidity_baking_repr.ml liquidity_baking_repr.mli + toggle_EMA.ml toggle_EMA.mli + toggle_votes_repr.ml toggle_votes_repr.mli block_header_repr.ml block_header_repr.mli destination_repr.ml destination_repr.mli script_int.ml script_int.mli @@ -957,7 +960,8 @@ zk_rollup_circuit_public_inputs_repr.mli bond_id_repr.ml bond_id_repr.mli vote_repr.ml vote_repr.mli - liquidity_baking_repr.ml liquidity_baking_repr.mli + toggle_EMA.ml toggle_EMA.mli + toggle_votes_repr.ml toggle_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_repr.ml b/src/proto_alpha/lib_protocol/liquidity_baking_repr.ml deleted file mode 100644 index 09ea87b0e4c465046f214ebca9d410f50cd1f6c0..0000000000000000000000000000000000000000 --- a/src/proto_alpha/lib_protocol/liquidity_baking_repr.ml +++ /dev/null @@ -1,122 +0,0 @@ -(*****************************************************************************) -(* *) -(* Open Source License *) -(* Copyright (c) 2021 Tocqueville Group, Inc. *) -(* Copyright (c) 2022 Nomadic Labs *) -(* *) -(* Permission is hereby granted, free of charge, to any person obtaining a *) -(* copy of this software and associated documentation files (the "Software"),*) -(* to deal in the Software without restriction, including without limitation *) -(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *) -(* and/or sell copies of the Software, and to permit persons to whom the *) -(* Software is furnished to do so, subject to the following conditions: *) -(* *) -(* The above copyright notice and this permission notice shall be included *) -(* in all copies or substantial portions of the Software. *) -(* *) -(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*) -(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *) -(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *) -(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*) -(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *) -(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *) -(* DEALINGS IN THE SOFTWARE. *) -(* *) -(*****************************************************************************) - -(** Options available for the Liquidity Baking per-block vote *) - -type liquidity_baking_toggle_vote = LB_on | LB_off | LB_pass - -let liquidity_baking_toggle_vote_encoding = - let of_int8 = function - | 0 -> Ok LB_on - | 1 -> Ok LB_off - | 2 -> Ok LB_pass - | _ -> Error "liquidity_baking_toggle_vote_of_int8" - in - let to_int8 = function LB_on -> 0 | LB_off -> 1 | LB_pass -> 2 in - let open Data_encoding in - (* union *) - def "liquidity_baking_toggle_vote" - @@ splitted - ~binary:(conv_with_guard to_int8 of_int8 int8) - ~json:(string_enum [("on", LB_on); ("off", LB_off); ("pass", LB_pass)]) - -module Toggle_EMA : sig - (* The exponential moving average is represented as an Int32 between 0l and 2_000_000_000l *) - - type t - - val zero : t - - val of_int32 : Int32.t -> t tzresult Lwt.t - - val to_int32 : t -> Int32.t - - val update_ema_off : t -> t - - val update_ema_on : t -> t - - val ( < ) : t -> Int32.t -> bool - - val encoding : t Data_encoding.t -end = struct - type t = Int32.t (* Invariant 0 <= ema <= 2_000_000_000l *) - - (* This error is not registered because we don't expect it to be - raised. *) - type error += Liquidity_baking_toggle_ema_out_of_bound of Int32.t - - let check_bounds x = Compare.Int32.(0l <= x && x <= 2_000_000_000l) - - let of_int32 x = - if check_bounds x then return x - else tzfail @@ Liquidity_baking_toggle_ema_out_of_bound x - - let zero = Int32.zero - - (* The conv_with_guard combinator of Data_encoding expects a (_, string) result. *) - let of_int32_for_encoding x = - if check_bounds x then Ok x else Error "out of bounds" - - let to_int32 ema = ema - - (* We perform the computations in Z to avoid overflows. *) - - let z_1999 = Z.of_int 1999 - - let z_2000 = Z.of_int 2000 - - let attenuate z = Z.(div (mul z_1999 z) z_2000) - - let z_1_000_000_000 = Z.of_int 1_000_000_000 - - (* Outside of this module, the EMA is always between 0 and 2,000,000,000. - This [recenter] wrappers, puts it in between -1,000,000,000 and 1,000,000,000. - The goal of this recentering around zero is to make [update_ema_off] and - [update_ema_on] behave symmetrically with respect to rounding. *) - let recenter f ema = Z.(add z_1_000_000_000 (f (sub ema z_1_000_000_000))) - - let z_500_000 = Z.of_int 500_000 - - let update_ema_off ema = - let ema = Z.of_int32 ema in - recenter (fun ema -> Z.add (attenuate ema) z_500_000) ema |> Z.to_int32 - - let update_ema_on ema = - let ema = Z.of_int32 ema in - recenter (fun ema -> Z.sub (attenuate ema) z_500_000) ema |> Z.to_int32 - - let ( < ) = Compare.Int32.( < ) - - let encoding = - Data_encoding.(conv_with_guard to_int32 of_int32_for_encoding int32) -end - -(* Invariant: 0 <= ema <= 2_000_000 *) -let compute_new_ema ~toggle_vote ema = - match toggle_vote with - | LB_pass -> ema - | LB_off -> Toggle_EMA.update_ema_off ema - | LB_on -> Toggle_EMA.update_ema_on ema diff --git a/src/proto_alpha/lib_protocol/liquidity_baking_storage.ml b/src/proto_alpha/lib_protocol/liquidity_baking_storage.ml index 56c6f3746ad753b9df1894c879f0ea63f01ee94b..7dd169ceb5c7188002ffa020a74305d3a02b70b5 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 Liquidity_baking_repr +open Toggle_votes_repr let get_cpmm_address = Storage.Liquidity_baking.Cpmm_address.get diff --git a/src/proto_alpha/lib_protocol/liquidity_baking_storage.mli b/src/proto_alpha/lib_protocol/liquidity_baking_storage.mli index f1d0d5886292e437be01f2aa2c4bec75dfb22b6f..9d83c3cc96893e7b6351fc23043216e8708acfb9 100644 --- a/src/proto_alpha/lib_protocol/liquidity_baking_storage.mli +++ b/src/proto_alpha/lib_protocol/liquidity_baking_storage.mli @@ -24,7 +24,7 @@ (* *) (*****************************************************************************) -(** Get the address of the Constant-Product Market Maker receiving the +(** Get the address of the Constant-Product Market Maker receiving the Liquidity Baking subsidy *) val get_cpmm_address : Raw_context.t -> Contract_hash.t tzresult Lwt.t @@ -38,6 +38,6 @@ 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:Liquidity_baking_repr.liquidity_baking_toggle_vote -> + toggle_vote:Toggle_votes_repr.toggle_vote -> (Raw_context.t -> Contract_hash.t -> (Raw_context.t * 'a list) tzresult Lwt.t) -> - (Raw_context.t * 'a list * Liquidity_baking_repr.Toggle_EMA.t) tzresult Lwt.t + (Raw_context.t * 'a list * 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 2f346600822988ed41073878e012bac8c18f1450..27e49b47dddcd623d7b4c54de63daf49c39d47a3 100644 --- a/src/proto_alpha/lib_protocol/main.ml +++ b/src/proto_alpha/lib_protocol/main.ml @@ -405,7 +405,12 @@ let init chain_id ctxt block_header = ({ payload_hash = Block_payload_hash.zero; payload_round = Alpha_context.Round.zero; - liquidity_baking_toggle_vote = Alpha_context.Liquidity_baking.LB_pass; + toggle_votes = + { + liquidity_baking_vote = Alpha_context.Toggle_votes.Toggle_vote_pass; + adaptive_inflation_vote = + Alpha_context.Toggle_votes.Toggle_vote_pass; + }; seed_nonce_hash = None; proof_of_work_nonce = Bytes.make Constants_repr.proof_of_work_nonce_size '0'; diff --git a/src/proto_alpha/lib_protocol/test/helpers/block.ml b/src/proto_alpha/lib_protocol/test/helpers/block.ml index f40cf8a13aab5584b9a7ca68ec7fc45fafed9255..13e045bfda7c9f4201e1a5d503fc403b1e6f9e55 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/block.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/block.ml @@ -168,7 +168,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 = Liquidity_baking.LB_pass) + ?(liquidity_baking_toggle_vote = Toggle_votes.Toggle_vote_pass) + ?(adaptive_inflation_toggle_vote = Toggle_votes.Toggle_vote_pass) ~seed_nonce_hash shell = naive_pow_miner ~proof_of_work_threshold @@ -179,7 +180,11 @@ module Forge = struct payload_round; proof_of_work_nonce = default_proof_of_work_nonce; seed_nonce_hash; - liquidity_baking_toggle_vote; + toggle_votes = + { + liquidity_baking_vote = liquidity_baking_toggle_vote; + adaptive_inflation_vote = adaptive_inflation_toggle_vote; + }; } let make_shell ~level ~predecessor ~timestamp ~fitness ~operations_hash = @@ -239,7 +244,7 @@ module Forge = struct let forge_header ?(locked_round = None) ?(payload_round = None) ?(policy = By_round 0) ?timestamp ?(operations = []) - ?liquidity_baking_toggle_vote pred = + ?liquidity_baking_toggle_vote ?adaptive_inflation_toggle_vote pred = let pred_fitness = match Fitness.from_raw pred.header.shell.fitness with | Ok pred_fitness -> pred_fitness @@ -288,6 +293,7 @@ module Forge = struct make_contents ~seed_nonce_hash ?liquidity_baking_toggle_vote + ?adaptive_inflation_toggle_vote ~payload_hash ~payload_round shell @@ -298,15 +304,20 @@ 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 = Liquidity_baking.LB_pass) ~payload_hash - ~payload_round shell_header = + ?(liquidity_baking_toggle_vote = Toggle_votes.Toggle_vote_pass) + ?(adaptive_inflation_toggle_vote = Toggle_votes.Toggle_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; - liquidity_baking_toggle_vote; + toggle_votes = + { + liquidity_baking_vote = liquidity_baking_toggle_vote; + adaptive_inflation_vote = adaptive_inflation_toggle_vote; + }; payload_hash; payload_round; } @@ -800,7 +811,7 @@ let apply header ?(operations = []) ?(allow_manager_failures = false) pred = let bake_with_metadata ?locked_round ?policy ?timestamp ?operation ?operations ?payload_round ?check_size ~baking_mode ?(allow_manager_failures = false) - ?liquidity_baking_toggle_vote pred = + ?liquidity_baking_toggle_vote ?adaptive_inflation_toggle_vote pred = let operations = match (operation, operations) with | Some op, Some ops -> Some (op :: ops) @@ -815,6 +826,7 @@ let bake_with_metadata ?locked_round ?policy ?timestamp ?operation ?operations ?policy ?operations ?liquidity_baking_toggle_vote + ?adaptive_inflation_toggle_vote pred >>=? fun header -> Forge.sign_header header >>=? fun header -> @@ -829,7 +841,8 @@ let bake_with_metadata ?locked_round ?policy ?timestamp ?operation ?operations let bake ?(baking_mode = Application) ?(allow_manager_failures = false) ?payload_round ?locked_round ?policy ?timestamp ?operation ?operations - ?liquidity_baking_toggle_vote ?check_size pred = + ?liquidity_baking_toggle_vote ?adaptive_inflation_toggle_vote ?check_size + pred = bake_with_metadata ?payload_round ~baking_mode @@ -840,6 +853,7 @@ let bake ?(baking_mode = Application) ?(allow_manager_failures = false) ?operation ?operations ?liquidity_baking_toggle_vote + ?adaptive_inflation_toggle_vote ?check_size pred >>=? fun (t, (_metadata : block_header_metadata)) -> return t @@ -849,40 +863,60 @@ let bake ?(baking_mode = Application) ?(allow_manager_failures = false) (* This function is duplicated from Context to avoid a cyclic dependency *) let get_constants b = Alpha_services.Constants.all rpc_ctxt b -let bake_n ?(baking_mode = Application) ?policy ?liquidity_baking_toggle_vote n - b = +let bake_n ?(baking_mode = Application) ?policy ?liquidity_baking_toggle_vote + ?adaptive_inflation_toggle_vote n b = List.fold_left_es - (fun b _ -> bake ~baking_mode ?policy ?liquidity_baking_toggle_vote b) + (fun b _ -> + bake + ~baking_mode + ?policy + ?liquidity_baking_toggle_vote + ?adaptive_inflation_toggle_vote + b) b (1 -- n) let rec bake_while ?(baking_mode = Application) ?policy - ?liquidity_baking_toggle_vote predicate b = + ?liquidity_baking_toggle_vote ?adaptive_inflation_toggle_vote predicate b = let open Lwt_result_syntax in - let* new_block = bake ~baking_mode ?policy ?liquidity_baking_toggle_vote b in + let* new_block = + bake + ~baking_mode + ?policy + ?liquidity_baking_toggle_vote + ?adaptive_inflation_toggle_vote + b + in if predicate new_block then (bake_while [@ocaml.tailcall]) ~baking_mode ?policy ?liquidity_baking_toggle_vote + ?adaptive_inflation_toggle_vote predicate new_block else return b let bake_until_level ?(baking_mode = Application) ?policy - ?liquidity_baking_toggle_vote level b = + ?liquidity_baking_toggle_vote ?adaptive_inflation_toggle_vote level b = bake_while ~baking_mode ?policy ?liquidity_baking_toggle_vote + ?adaptive_inflation_toggle_vote (fun b -> b.header.shell.level <= Raw_level.to_int32 level) b let bake_n_with_all_balance_updates ?(baking_mode = Application) ?policy - ?liquidity_baking_toggle_vote n b = + ?liquidity_baking_toggle_vote ?adaptive_inflation_toggle_vote n b = List.fold_left_es (fun (b, balance_updates_rev) _ -> - bake_with_metadata ~baking_mode ?policy ?liquidity_baking_toggle_vote b + bake_with_metadata + ~baking_mode + ?policy + ?liquidity_baking_toggle_vote + ?adaptive_inflation_toggle_vote + b >>=? fun (b, metadata) -> let balance_updates_rev = List.rev_append metadata.balance_updates balance_updates_rev @@ -961,11 +995,16 @@ let bake_n_with_origination_results ?(baking_mode = Application) ?policy n b = >|=? fun (b, origination_results_rev) -> (b, List.rev origination_results_rev) let bake_n_with_liquidity_baking_toggle_ema ?(baking_mode = Application) ?policy - ?liquidity_baking_toggle_vote n b = - let initial_ema = Liquidity_baking.Toggle_EMA.zero in + ?liquidity_baking_toggle_vote ?adaptive_inflation_toggle_vote n b = + let initial_ema = Toggle_EMA.zero in List.fold_left_es (fun (b, _toggle_ema) _ -> - bake_with_metadata ~baking_mode ?policy ?liquidity_baking_toggle_vote b + bake_with_metadata + ~baking_mode + ?policy + ?liquidity_baking_toggle_vote + ?adaptive_inflation_toggle_vote + b >|=? fun (b, metadata) -> (b, metadata.liquidity_baking_toggle_ema)) (b, initial_ema) (1 -- n) diff --git a/src/proto_alpha/lib_protocol/test/helpers/block.mli b/src/proto_alpha/lib_protocol/test/helpers/block.mli index cde54f39b43560dd8215b9c8afa3e1fa605be48e..5c49bc36c6491d6cbcf92e0b836b27884f6822c4 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/block.mli +++ b/src/proto_alpha/lib_protocol/test/helpers/block.mli @@ -72,7 +72,8 @@ module Forge : sig val contents : ?proof_of_work_threshold:Int64.t -> ?seed_nonce_hash:Nonce_hash.t -> - ?liquidity_baking_toggle_vote:Liquidity_baking.liquidity_baking_toggle_vote -> + ?liquidity_baking_toggle_vote:Toggle_votes.toggle_vote -> + ?adaptive_inflation_toggle_vote:Toggle_votes.toggle_vote -> payload_hash:Block_payload_hash.t -> payload_round:Round.t -> Block_header.shell_header -> @@ -90,7 +91,8 @@ module Forge : sig ?policy:baker_policy -> ?timestamp:Timestamp.time -> ?operations:Operation.packed list -> - ?liquidity_baking_toggle_vote:Liquidity_baking.liquidity_baking_toggle_vote -> + ?liquidity_baking_toggle_vote:Toggle_votes.toggle_vote -> + ?adaptive_inflation_toggle_vote:Toggle_votes.toggle_vote -> t -> header tzresult Lwt.t @@ -208,7 +210,8 @@ val bake : ?timestamp:Timestamp.time -> ?operation:Operation.packed -> ?operations:Operation.packed list -> - ?liquidity_baking_toggle_vote:Liquidity_baking.liquidity_baking_toggle_vote -> + ?liquidity_baking_toggle_vote:Toggle_votes.toggle_vote -> + ?adaptive_inflation_toggle_vote:Toggle_votes.toggle_vote -> ?check_size:bool -> t -> t tzresult Lwt.t @@ -217,7 +220,8 @@ val bake : val bake_n : ?baking_mode:baking_mode -> ?policy:baker_policy -> - ?liquidity_baking_toggle_vote:Liquidity_baking.liquidity_baking_toggle_vote -> + ?liquidity_baking_toggle_vote:Toggle_votes.toggle_vote -> + ?adaptive_inflation_toggle_vote:Toggle_votes.toggle_vote -> int -> t -> block tzresult Lwt.t @@ -226,7 +230,8 @@ val bake_n : val bake_until_level : ?baking_mode:baking_mode -> ?policy:baker_policy -> - ?liquidity_baking_toggle_vote:Liquidity_baking.liquidity_baking_toggle_vote -> + ?liquidity_baking_toggle_vote:Toggle_votes.toggle_vote -> + ?adaptive_inflation_toggle_vote:Toggle_votes.toggle_vote -> Raw_level.t -> t -> block tzresult Lwt.t @@ -236,7 +241,8 @@ val bake_until_level : val bake_n_with_all_balance_updates : ?baking_mode:baking_mode -> ?policy:baker_policy -> - ?liquidity_baking_toggle_vote:Liquidity_baking.liquidity_baking_toggle_vote -> + ?liquidity_baking_toggle_vote:Toggle_votes.toggle_vote -> + ?adaptive_inflation_toggle_vote:Toggle_votes.toggle_vote -> int -> t -> (block * Alpha_context.Receipt.balance_updates) tzresult Lwt.t @@ -259,10 +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:Liquidity_baking.liquidity_baking_toggle_vote -> + ?liquidity_baking_toggle_vote:Toggle_votes.toggle_vote -> + ?adaptive_inflation_toggle_vote:Toggle_votes.toggle_vote -> int -> t -> - (block * Alpha_context.Liquidity_baking.Toggle_EMA.t) tzresult Lwt.t + (block * Alpha_context.Toggle_EMA.t) tzresult Lwt.t val current_cycle : t -> Cycle.t tzresult Lwt.t diff --git a/src/proto_alpha/lib_protocol/test/helpers/operation_generator.ml b/src/proto_alpha/lib_protocol/test/helpers/operation_generator.ml index 95e977fc9ee2aed4cafa86bdce718f82f0514827..c838e1a9f6916b0f418ce9bdb15e31f78eea891b 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/operation_generator.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/operation_generator.ml @@ -223,13 +223,13 @@ let random_contract_hash = let block_headers = let bh1 = - {json|{ "level": 2, "proto": 1, "predecessor": "BLbcVY1kYiKQy2MJJfoHJMN2xRk5QPG1PEKWMDSyW2JMxBsMmiL", "timestamp": "2022-08-08T11:16:30Z", "validation_pass": 4, "operations_hash": "LLoa7bxRTKaQN2bLYoitYB6bU2DvLnBAqrVjZcvJ364cTcX2PZYKU", "fitness": [ "02", "00000002", "", "ffffffff", "00000001" ], "context": "CoUvpF8XBUfz3w9CJumt4ZKGZkrcdcfs1Qdrrd1ZeFij64E1QCud", "payload_hash": "vh2TyrWeZ2dydEy9ZjmvrjQvyCs5sdHZPypcZrXDUSM1tNuPermf", "payload_round": 1, "proof_of_work_nonce": "62de1e0d00000000", "liquidity_baking_toggle_vote": "pass", "signature": "sigaXGo4DWsZwo1SvbKCp2hLgE5jcwd61Ufkc3iMt3sXy3NBj9jticuJKJnRhyH2ZPJQMwEuDqQTgZgoK5xRH6HeF7YxLb4u" }|json} + {json|{ "level": 2, "proto": 1, "predecessor": "BLbcVY1kYiKQy2MJJfoHJMN2xRk5QPG1PEKWMDSyW2JMxBsMmiL", "timestamp": "2022-08-08T11:16:30Z", "validation_pass": 4, "operations_hash": "LLoa7bxRTKaQN2bLYoitYB6bU2DvLnBAqrVjZcvJ364cTcX2PZYKU", "fitness": [ "02", "00000002", "", "ffffffff", "00000001" ], "context": "CoUvpF8XBUfz3w9CJumt4ZKGZkrcdcfs1Qdrrd1ZeFij64E1QCud", "payload_hash": "vh2TyrWeZ2dydEy9ZjmvrjQvyCs5sdHZPypcZrXDUSM1tNuPermf", "payload_round": 1, "proof_of_work_nonce": "62de1e0d00000000", "liquidity_baking_toggle_vote": "pass", "adaptive_inflation_toggle_vote": "pass", "signature": "sigaXGo4DWsZwo1SvbKCp2hLgE5jcwd61Ufkc3iMt3sXy3NBj9jticuJKJnRhyH2ZPJQMwEuDqQTgZgoK5xRH6HeF7YxLb4u" }|json} in let bh2 = - {json|{ "level": 3, "proto": 1, "predecessor": "BLAUNUbzKHgA4DYQEXCbxY73wdE2roGAzvJJbFp8dQe62Ekpada", "timestamp": "2022-08-08T11:16:32Z", "validation_pass": 4, "operations_hash": "LLoaWjBX8Cm8DVpoLNtm7FPNnxUdL6Dakq122pVfNHYaf2rE9GQXi", "fitness": [ "02", "00000003", "", "fffffffe", "00000000" ], "context": "CoUtWowJUqXwMm4pbR1jjyFfVRHqRHGs6bYVDaaByvbmULoAND2x", "payload_hash": "vh1p1VzeYjZLEW6WDqdTwVy354KEmGCDgPmagEKcLN4NT4X58mNk", "payload_round": 0, "proof_of_work_nonce": "62de1e0d00000000", "liquidity_baking_toggle_vote": "pass", "signature": "sigVqWWE7BPuxHqPWiVRmzQ1eMZZAPAxGJ94ytY2sjV8Y1Z4QH1F2bPGZS1ZeWDbqmcppPPFobRpi7wNasQ17Mm9CFGKag2t" }|json} + {json|{ "level": 3, "proto": 1, "predecessor": "BLAUNUbzKHgA4DYQEXCbxY73wdE2roGAzvJJbFp8dQe62Ekpada", "timestamp": "2022-08-08T11:16:32Z", "validation_pass": 4, "operations_hash": "LLoaWjBX8Cm8DVpoLNtm7FPNnxUdL6Dakq122pVfNHYaf2rE9GQXi", "fitness": [ "02", "00000003", "", "fffffffe", "00000000" ], "context": "CoUtWowJUqXwMm4pbR1jjyFfVRHqRHGs6bYVDaaByvbmULoAND2x", "payload_hash": "vh1p1VzeYjZLEW6WDqdTwVy354KEmGCDgPmagEKcLN4NT4X58mNk", "payload_round": 0, "proof_of_work_nonce": "62de1e0d00000000", "liquidity_baking_toggle_vote": "pass", "adaptive_inflation_toggle_vote": "pass", "signature": "sigVqWWE7BPuxHqPWiVRmzQ1eMZZAPAxGJ94ytY2sjV8Y1Z4QH1F2bPGZS1ZeWDbqmcppPPFobRpi7wNasQ17Mm9CFGKag2t" }|json} in let bh3 = - {json|{ "level": 4, "proto": 1, "predecessor": "BLuurCvGmNPTzXSnGCpcFPy5h8A49PwH2LnfAWBnp5R1qv5czwe", "timestamp": "2022-08-08T11:16:33Z", "validation_pass": 4, "operations_hash": "LLoaf8AANzyNxhk715zykDrwG5Bpqw6FsZLWWNp2Dcm3ewFrcc3Wc", "fitness": [ "02", "00000004", "", "ffffffff", "00000000" ], "context": "CoVzxEBMDhxpGVxrguik6r5qVogJBFyhuvwm2KZBcsmvqhekPiwL", "payload_hash": "vh2gWcSUUhJBwvjx4vS7JN5ioMVWpHCSK6W2MKNPr5dn6NUdfFDQ", "payload_round": 0, "proof_of_work_nonce": "62de1e0d00000000", "seed_nonce_hash": "nceV3VjdHp1yk6uqcQicQBxLJY1AfWvLSabQpqnpiqkC1q2tS35EN", "liquidity_baking_toggle_vote": "pass", "signature": "sigijumaDLSQwjh2AKK7af1VcEDsZsRwbweL8hF176puhHy3ySVocNCbrwPqJLiQP8EbqY5YL6z6b1vDaw12h8MQU2Rh4SW1" }|json} + {json|{ "level": 4, "proto": 1, "predecessor": "BLuurCvGmNPTzXSnGCpcFPy5h8A49PwH2LnfAWBnp5R1qv5czwe", "timestamp": "2022-08-08T11:16:33Z", "validation_pass": 4, "operations_hash": "LLoaf8AANzyNxhk715zykDrwG5Bpqw6FsZLWWNp2Dcm3ewFrcc3Wc", "fitness": [ "02", "00000004", "", "ffffffff", "00000000" ], "context": "CoVzxEBMDhxpGVxrguik6r5qVogJBFyhuvwm2KZBcsmvqhekPiwL", "payload_hash": "vh2gWcSUUhJBwvjx4vS7JN5ioMVWpHCSK6W2MKNPr5dn6NUdfFDQ", "payload_round": 0, "proof_of_work_nonce": "62de1e0d00000000", "seed_nonce_hash": "nceV3VjdHp1yk6uqcQicQBxLJY1AfWvLSabQpqnpiqkC1q2tS35EN", "liquidity_baking_toggle_vote": "pass", "adaptive_inflation_toggle_vote": "pass", "signature": "sigijumaDLSQwjh2AKK7af1VcEDsZsRwbweL8hF176puhHy3ySVocNCbrwPqJLiQP8EbqY5YL6z6b1vDaw12h8MQU2Rh4SW1" }|json} in List.map (fun s -> 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 c779a10d5adaaca874ae28cc3593c4c3815917d2..9a63b0b546d329fe7b2374cb93acbdefeb028258 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 [LB_on], [LB_off], and [LB_pass] followed by [bake_after_toggle] blocks with it set to [LB_pass]. *) -(* Expected level is roughly 2*(log(1-1/(2*p)) / log(0.999)) where [p] is the proportion [LB_off / (LB_on + LB_off)]. *) + 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)]. *) 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,18 +136,21 @@ 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:LB_on n_vote_on blk + Block.bake_n ~liquidity_baking_toggle_vote:Toggle_vote_on n_vote_on blk >>=? fun blk -> - Block.bake_n ~liquidity_baking_toggle_vote:LB_off n_vote_off blk + Block.bake_n ~liquidity_baking_toggle_vote:Toggle_vote_off n_vote_off blk >>=? fun blk -> - Block.bake_n ~liquidity_baking_toggle_vote:LB_pass n_vote_pass blk + Block.bake_n + ~liquidity_baking_toggle_vote:Toggle_vote_pass + n_vote_pass + blk >>=? fun blk -> bake_stopping blk (i + n_vote_on + n_vote_off + n_vote_pass) else return blk in bake_stopping blk 0 >>=? fun blk -> Context.Contract.balance (B blk) liquidity_baking >>=? fun balance -> - Block.bake_n ~liquidity_baking_toggle_vote:LB_pass bake_after blk + Block.bake_n ~liquidity_baking_toggle_vote:Toggle_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) @@ -160,19 +163,19 @@ let liquidity_baking_toggle ~n_vote_on ~n_vote_off ~n_vote_pass expected_level expected_final_balance >>=? fun () -> return_unit -(* 100% of blocks have liquidity_baking_toggle_vote = LB_off *) +(* 100% of blocks have liquidity_baking_toggle_vote = Toggle_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 = LB_off *) +(* 80% of blocks have liquidity_baking_toggle_vote = Toggle_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 = LB_off *) +(* 60% of blocks have liquidity_baking_toggle_vote = Toggle_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 = LB_off. +(* 50% of blocks have liquidity_baking_toggle_vote = Toggle_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 () = @@ -184,9 +187,10 @@ 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:LB_on blk >>=? fun blk -> - Block.bake ~liquidity_baking_toggle_vote:LB_off blk >>=? fun blk -> - bake_stopping blk (i + 2) + Block.bake ~liquidity_baking_toggle_vote:Toggle_vote_on blk + >>=? fun blk -> + Block.bake ~liquidity_baking_toggle_vote:Toggle_vote_off blk + >>=? fun blk -> bake_stopping blk (i + 2) else return blk in bake_stopping blk 0 >>=? fun blk -> @@ -202,24 +206,28 @@ let liquidity_baking_toggle_50 () = expected_final_balance >>=? fun () -> return_unit -(* Test that the subsidy can restart if LB_on votes regain majority. - Bake n_votes with LB_off, check that the subsidy is paused, bake - n_votes with LB_on, check that the subsidy flows. +(* 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. *) 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:LB_off n_votes blk >>=? fun blk -> + Block.bake_n ~liquidity_baking_toggle_vote:Toggle_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:LB_pass n blk >>=? fun blk -> + Block.bake_n ~liquidity_baking_toggle_vote:Toggle_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:LB_on n_votes blk >>=? fun blk -> + Block.bake_n ~liquidity_baking_toggle_vote:Toggle_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:LB_pass n blk >>=? fun blk -> + Block.bake_n ~liquidity_baking_toggle_vote:Toggle_vote_pass n blk + >>=? fun blk -> Context.get_liquidity_baking_subsidy (B blk) >>=? fun liquidity_baking_subsidy -> liquidity_baking_subsidy *? Int64.of_int n >>?= fun expected_balance -> @@ -237,9 +245,9 @@ let liquidity_baking_toggle_ema n_vote_on n_vote_off level bake_after Context.init1 ~consensus_threshold:0 () >>=? fun (blk, _contract) -> let rec bake_escaping blk i = if i < level then - Block.bake_n ~liquidity_baking_toggle_vote:LB_on n_vote_on blk + Block.bake_n ~liquidity_baking_toggle_vote:Toggle_vote_on n_vote_on blk >>=? fun blk -> - Block.bake_n ~liquidity_baking_toggle_vote:LB_off n_vote_off blk + Block.bake_n ~liquidity_baking_toggle_vote:Toggle_vote_off n_vote_off blk >>=? fun blk -> bake_escaping blk (i + n_vote_on + n_vote_off) else return blk in @@ -249,8 +257,7 @@ let liquidity_baking_toggle_ema n_vote_on n_vote_off level bake_after >>=? fun (_blk, toggle_ema) -> Assert.leq_int ~loc:__LOC__ - (toggle_ema |> Alpha_context.Liquidity_baking.Toggle_EMA.to_int32 - |> Int32.to_int) + (toggle_ema |> Alpha_context.Toggle_EMA.to_int32 |> Int32.to_int) expected_toggle_ema >>=? fun () -> return_unit @@ -441,48 +448,48 @@ let tests = `Quick (liquidity_baking_subsidies 64); Tztest.tztest - "liquidity baking toggle vote with 100% of bakers voting LB_off baking \ - one block longer" + "liquidity baking toggle vote with 100% of bakers voting Toggle_vote_off \ + baking one block longer" `Quick (liquidity_baking_toggle_100 1); Tztest.tztest - "liquidity baking toggle vote with 100% of bakers voting LB_off baking \ - two blocks longer" + "liquidity baking toggle vote with 100% of bakers voting Toggle_vote_off \ + baking two blocks longer" `Quick (liquidity_baking_toggle_100 2); Tztest.tztest - "liquidity baking toggle vote with 100% of bakers voting LB_off baking \ - 100 blocks longer" + "liquidity baking toggle vote with 100% of bakers voting Toggle_vote_off \ + baking 100 blocks longer" `Quick (liquidity_baking_toggle_100 100); Tztest.tztest - "liquidity baking toggle vote with 80% of bakers voting LB_off baking \ - one block longer" + "liquidity baking toggle vote with 80% of bakers voting Toggle_vote_off \ + baking one block longer" `Quick (liquidity_baking_toggle_80 1); Tztest.tztest - "liquidity baking toggle vote with 80% of bakers voting LB_off baking \ - two blocks longer" + "liquidity baking toggle vote with 80% of bakers voting Toggle_vote_off \ + baking two blocks longer" `Quick (liquidity_baking_toggle_80 2); Tztest.tztest - "liquidity baking toggle vote with 80% of bakers voting LB_off baking \ - 100 blocks longer" + "liquidity baking toggle vote with 80% of bakers voting Toggle_vote_off \ + baking 100 blocks longer" `Quick (liquidity_baking_toggle_80 100); Tztest.tztest - "liquidity baking toggle vote with 60% of bakers voting LB_off baking \ - one block longer" + "liquidity baking toggle vote with 60% of bakers voting Toggle_vote_off \ + baking one block longer" `Quick (liquidity_baking_toggle_60 1); Tztest.tztest - "liquidity baking toggle vote with 60% of bakers voting LB_off baking \ - two blocks longer" + "liquidity baking toggle vote with 60% of bakers voting Toggle_vote_off \ + baking two blocks longer" `Quick (liquidity_baking_toggle_60 2); Tztest.tztest - "liquidity baking toggle vote with 60% of bakers voting LB_off baking \ - 100 blocks longer" + "liquidity baking toggle vote with 60% of bakers voting Toggle_vote_off \ + baking 100 blocks longer" `Quick (liquidity_baking_toggle_60 100); Tztest.tztest @@ -497,7 +504,7 @@ let tests = (liquidity_baking_restart 2000 1); Tztest.tztest "liquidity baking toggle ema in block metadata is zero with no bakers \ - voting LB_off." + voting Toggle_vote_off." `Quick liquidity_baking_toggle_ema_zero; Tztest.tztest 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 78d3b0d73851e786d0f84c78667f140d59673ce1..11bd5db88e18de3f6c2b9800d78bfbd97c0264de 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 @@ -33,19 +33,17 @@ open Protocol -let ema_of_int32 ema = - Liquidity_baking_repr.Toggle_EMA.of_int32 ema >|= Environment.wrap_tzresult +let ema_of_int32 ema = Toggle_EMA.of_int32 ema >|= Environment.wrap_tzresult -let ema_to_int32 = Liquidity_baking_repr.Toggle_EMA.to_int32 +let ema_to_int32 = Toggle_EMA.to_int32 let compute_new_ema ~toggle_vote ema = - Liquidity_baking_repr.compute_new_ema ~toggle_vote ema |> ema_to_int32 + Toggle_votes_repr.compute_new_ema ~toggle_vote ema |> ema_to_int32 (* Folds compute_new_ema on a list of votes *) let compute_new_ema_n toggle_votes initial_ema = List.fold_left - (fun ema toggle_vote -> - Liquidity_baking_repr.compute_new_ema ~toggle_vote ema) + (fun ema toggle_vote -> Toggle_votes_repr.compute_new_ema ~toggle_vote ema) initial_ema toggle_votes |> ema_to_int32 @@ -98,7 +96,7 @@ let test_ema_pass () = ema_of_int32 old_ema >>=? fun ema -> Assert.equal_int32 ~loc:__LOC__ - (compute_new_ema ~toggle_vote:LB_pass ema) + (compute_new_ema ~toggle_vote:Toggle_vote_pass ema) old_ema) ema_range @@ -107,7 +105,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:LB_off ema in + let new_ema = compute_new_ema ~toggle_vote:Toggle_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 @@ -121,7 +119,7 @@ let test_ema_increases_off () = Assert.lt_int32 ~loc:__LOC__ old_ema - (compute_new_ema ~toggle_vote:LB_off ema)) + (compute_new_ema ~toggle_vote:Toggle_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 *) @@ -131,7 +129,7 @@ let test_ema_increases_off_bound () = ema_of_int32 old_ema >>=? fun ema -> Assert.leq_int32 ~loc:__LOC__ - (Int32.sub (compute_new_ema ~toggle_vote:LB_off ema) old_ema) + (Int32.sub (compute_new_ema ~toggle_vote:Toggle_vote_off ema) old_ema) 1_000_000l) ema_range @@ -140,7 +138,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:LB_on ema in + let new_ema = compute_new_ema ~toggle_vote:Toggle_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 @@ -153,7 +151,7 @@ let test_ema_decreases_on () = ema_of_int32 old_ema >>=? fun ema -> Assert.lt_int32 ~loc:__LOC__ - (compute_new_ema ~toggle_vote:LB_on ema) + (compute_new_ema ~toggle_vote:Toggle_vote_on ema) old_ema) (List.filter (fun ema -> Compare.Int32.(ema > 1000l)) ema_range) @@ -164,36 +162,44 @@ 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:LB_on ema) old_ema) + (Int32.sub (compute_new_ema ~toggle_vote:Toggle_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 Liquidity_baking_repr in + let open Toggle_votes_repr in ema_of_int32 0l >>=? fun initial_ema -> Assert.leq_int32 ~loc:__LOC__ - (compute_new_ema_n (Stdlib.List.init 1385 (fun _ -> LB_off)) initial_ema) + (compute_new_ema_n + (Stdlib.List.init 1385 (fun _ -> Toggle_vote_off)) + initial_ema) 1_000_000_000l >>=? fun () -> Assert.leq_int32 ~loc:__LOC__ 1_000_000_000l - (compute_new_ema_n (Stdlib.List.init 1386 (fun _ -> LB_off)) initial_ema) + (compute_new_ema_n + (Stdlib.List.init 1386 (fun _ -> Toggle_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 Liquidity_baking_repr in + let open Toggle_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 _ -> LB_on)) initial_ema) + (compute_new_ema_n + (Stdlib.List.init 1385 (fun _ -> Toggle_vote_on)) + initial_ema) >>=? fun () -> Assert.leq_int32 ~loc:__LOC__ - (compute_new_ema_n (Stdlib.List.init 1386 (fun _ -> LB_on)) initial_ema) + (compute_new_ema_n + (Stdlib.List.init 1386 (fun _ -> Toggle_vote_on)) + initial_ema) 1_000_000_000l (* Test that the EMA update function is symmetric: @@ -207,8 +213,10 @@ 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:LB_on ema in - let new_opposite_ema = compute_new_ema ~toggle_vote:LB_off opposite_ema in + let new_ema = compute_new_ema ~toggle_vote:Toggle_vote_on ema in + let new_opposite_ema = + compute_new_ema ~toggle_vote:Toggle_vote_off opposite_ema + in Assert.equal_int32 ~loc:__LOC__ Int32.(add new_ema new_opposite_ema) diff --git a/src/proto_alpha/lib_protocol/toggle_EMA.ml b/src/proto_alpha/lib_protocol/toggle_EMA.ml new file mode 100644 index 0000000000000000000000000000000000000000..4b4c469a41e2ecfec2f4dbb8b2c03007873cfd7d --- /dev/null +++ b/src/proto_alpha/lib_protocol/toggle_EMA.ml @@ -0,0 +1,80 @@ +(*****************************************************************************) +(* *) +(* Open Source License *) +(* Copyright (c) 2021 Tocqueville Group, Inc. *) +(* Copyright (c) 2023 Nomadic Labs *) +(* *) +(* Permission is hereby granted, free of charge, to any person obtaining a *) +(* copy of this software and associated documentation files (the "Software"),*) +(* to deal in the Software without restriction, including without limitation *) +(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *) +(* and/or sell copies of the Software, and to permit persons to whom the *) +(* Software is furnished to do so, subject to the following conditions: *) +(* *) +(* The above copyright notice and this permission notice shall be included *) +(* in all copies or substantial portions of the Software. *) +(* *) +(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*) +(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *) +(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *) +(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*) +(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *) +(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *) +(* DEALINGS IN THE SOFTWARE. *) +(* *) +(*****************************************************************************) + +(** Exponential moving average of toggle votes. Represented as an int32 between + 0 and 2,000,000. It is an exponential moving average of the "off" votes + over a window of the most recent 2000 blocks that did not vote "pass". *) + +(* The exponential moving average is represented as an Int32 between 0l and 2_000_000_000l *) +type t = Int32.t (* Invariant 0 <= ema <= 2_000_000_000l *) + +(* This error is not registered because we don't expect it to be + raised. *) +type error += Toggle_ema_out_of_bound of Int32.t + +let check_bounds x = Compare.Int32.(0l <= x && x <= 2_000_000_000l) + +let of_int32 (x : Int32.t) : t tzresult Lwt.t = + if check_bounds x then return x else tzfail @@ Toggle_ema_out_of_bound x + +let zero : t = Int32.zero + +(* The conv_with_guard combinator of Data_encoding expects a (_, string) result. *) +let of_int32_for_encoding x = + if check_bounds x then Ok x else Error "out of bounds" + +let to_int32 (ema : t) : Int32.t = ema + +(* We perform the computations in Z to avoid overflows. *) + +let z_1999 : Z.t = Z.of_int 1999 + +let z_2000 : Z.t = Z.of_int 2000 + +let attenuate z = Z.(div (mul z_1999 z) z_2000) + +let z_1_000_000_000 = Z.of_int 1_000_000_000 + +(* Outside of this module, the EMA is always between 0 and 2,000,000,000. + This [recenter] wrappers, puts it in between -1,000,000,000 and 1,000,000,000. + The goal of this recentering around zero is to make [update_ema_off] and + [update_ema_on] behave symmetrically with respect to rounding. *) +let recenter f ema = Z.(add z_1_000_000_000 (f (sub ema z_1_000_000_000))) + +let z_500_000 = Z.of_int 500_000 + +let update_ema_off (ema : t) : t = + let ema = Z.of_int32 ema in + recenter (fun ema -> Z.add (attenuate ema) z_500_000) ema |> Z.to_int32 + +let update_ema_on (ema : t) : t = + let ema = Z.of_int32 ema in + recenter (fun ema -> Z.sub (attenuate ema) z_500_000) ema |> Z.to_int32 + +let ( < ) : t -> Int32.t -> bool = Compare.Int32.( < ) + +let encoding : t Data_encoding.t = + Data_encoding.(conv_with_guard to_int32 of_int32_for_encoding int32) diff --git a/src/proto_alpha/lib_protocol/toggle_EMA.mli b/src/proto_alpha/lib_protocol/toggle_EMA.mli new file mode 100644 index 0000000000000000000000000000000000000000..2867c35bcb9c42bc5c0b1761335e07c858202a53 --- /dev/null +++ b/src/proto_alpha/lib_protocol/toggle_EMA.mli @@ -0,0 +1,45 @@ +(*****************************************************************************) +(* *) +(* Open Source License *) +(* Copyright (c) 2021 Tocqueville Group, Inc. *) +(* Copyright (c) 2023 Nomadic Labs *) +(* *) +(* Permission is hereby granted, free of charge, to any person obtaining a *) +(* copy of this software and associated documentation files (the "Software"),*) +(* to deal in the Software without restriction, including without limitation *) +(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *) +(* and/or sell copies of the Software, and to permit persons to whom the *) +(* Software is furnished to do so, subject to the following conditions: *) +(* *) +(* The above copyright notice and this permission notice shall be included *) +(* in all copies or substantial portions of the Software. *) +(* *) +(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*) +(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *) +(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *) +(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*) +(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *) +(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *) +(* DEALINGS IN THE SOFTWARE. *) +(* *) +(*****************************************************************************) + +(** Exponential moving average of toggle votes. Represented as an int32 between + 0 and 2,000,000. It is an exponential moving average of the "off" votes + over a window of the most recent 2000 blocks that did not vote "pass". *) + +type t + +val of_int32 : Int32.t -> t tzresult Lwt.t + +val zero : t + +val to_int32 : t -> Int32.t + +val encoding : t Data_encoding.t + +val ( < ) : t -> Int32.t -> bool + +val update_ema_off : t -> t + +val update_ema_on : t -> t diff --git a/src/proto_alpha/lib_protocol/toggle_votes_repr.ml b/src/proto_alpha/lib_protocol/toggle_votes_repr.ml new file mode 100644 index 0000000000000000000000000000000000000000..7425ed029b22d7ff159858ad47a6dadffa694242 --- /dev/null +++ b/src/proto_alpha/lib_protocol/toggle_votes_repr.ml @@ -0,0 +1,95 @@ +(*****************************************************************************) +(* *) +(* Open Source License *) +(* Copyright (c) 2021 Tocqueville Group, Inc. *) +(* Copyright (c) 2022-2023 Nomadic Labs *) +(* *) +(* Permission is hereby granted, free of charge, to any person obtaining a *) +(* copy of this software and associated documentation files (the "Software"),*) +(* to deal in the Software without restriction, including without limitation *) +(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *) +(* and/or sell copies of the Software, and to permit persons to whom the *) +(* Software is furnished to do so, subject to the following conditions: *) +(* *) +(* The above copyright notice and this permission notice shall be included *) +(* in all copies or substantial portions of the Software. *) +(* *) +(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*) +(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *) +(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *) +(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*) +(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *) +(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *) +(* DEALINGS IN THE SOFTWARE. *) +(* *) +(*****************************************************************************) + +(** Options available for toggle per-block votes *) + +type toggle_vote = Toggle_vote_on | Toggle_vote_off | Toggle_vote_pass + +type toggle_votes = { + liquidity_baking_vote : toggle_vote; + adaptive_inflation_vote : toggle_vote; +} + +let toggle_vote_compact_encoding = + let open Data_encoding in + let open Compact in + union + ~union_tag_bits:2 + ~cases_tag_bits:0 + [ + case + ~title:"toggle_data_vote_on" + (payload (constant "on")) + (function Toggle_vote_on -> Some () | _ -> None) + (fun () -> Toggle_vote_on); + case + ~title:"toggle_data_vote_off" + (payload (constant "off")) + (function Toggle_vote_off -> Some () | _ -> None) + (fun () -> Toggle_vote_off); + case + ~title:"toggle_data_vote_pass" + (payload (constant "pass")) + (function Toggle_vote_pass -> Some () | _ -> None) + (fun () -> Toggle_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) + +let adaptive_inflation_vote_encoding = + let open Data_encoding in + def + "adaptive_inflation_vote" + (Compact.make ~tag_size:`Uint8 toggle_vote_compact_encoding) + +let toggle_votes_compact_encoding = + let open Data_encoding in + let open Compact in + conv + (fun {liquidity_baking_vote; adaptive_inflation_vote} -> + (liquidity_baking_vote, adaptive_inflation_vote)) + (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)) + +let toggle_votes_encoding = + let open Data_encoding in + def + "toggle_votes" + (Compact.make ~tag_size:`Uint8 toggle_votes_compact_encoding) + +(* Invariant: 0 <= ema <= 2_000_000 *) +let compute_new_ema ~toggle_vote ema = + match toggle_vote with + | Toggle_vote_pass -> ema + | Toggle_vote_off -> Toggle_EMA.update_ema_off ema + | Toggle_vote_on -> Toggle_EMA.update_ema_on ema diff --git a/src/proto_alpha/lib_protocol/liquidity_baking_repr.mli b/src/proto_alpha/lib_protocol/toggle_votes_repr.mli similarity index 67% rename from src/proto_alpha/lib_protocol/liquidity_baking_repr.mli rename to src/proto_alpha/lib_protocol/toggle_votes_repr.mli index a41f80d5835b3211fbad71bd7e4dee7f7fb3fd2c..25aed7e9b4d0f0c82982c3f2b50f70b794bbcb28 100644 --- a/src/proto_alpha/lib_protocol/liquidity_baking_repr.mli +++ b/src/proto_alpha/lib_protocol/toggle_votes_repr.mli @@ -2,7 +2,7 @@ (* *) (* Open Source License *) (* Copyright (c) 2021 Tocqueville Group, Inc. *) -(* Copyright (c) 2022 Nomadic Labs *) +(* Copyright (c) 2022-2023 Nomadic Labs *) (* *) (* Permission is hereby granted, free of charge, to any person obtaining a *) (* copy of this software and associated documentation files (the "Software"),*) @@ -24,41 +24,30 @@ (* *) (*****************************************************************************) -(** Options available for the Liquidity Baking per-block vote *) +(** Options available for toggle per-block votes *) -type liquidity_baking_toggle_vote = LB_on | LB_off | LB_pass +type toggle_vote = Toggle_vote_on | Toggle_vote_off | Toggle_vote_pass -val liquidity_baking_toggle_vote_encoding : - liquidity_baking_toggle_vote Data_encoding.encoding +type toggle_votes = { + liquidity_baking_vote : toggle_vote; + adaptive_inflation_vote : toggle_vote; +} -(** Exponential moving average of toggle votes. Represented as an int32 between - 0 and 2,000,000. It is an exponential moving average of the [LB_off] votes - over a window of the most recent 2000 blocks that did not vote [LB_pass]. *) +val liquidity_baking_vote_encoding : toggle_vote Data_encoding.encoding -module Toggle_EMA : sig - type t +val adaptive_inflation_vote_encoding : toggle_vote Data_encoding.encoding - val of_int32 : Int32.t -> t tzresult Lwt.t - - val zero : t - - val to_int32 : t -> Int32.t - - val encoding : t Data_encoding.t - - val ( < ) : t -> Int32.t -> bool -end +val toggle_votes_encoding : toggle_votes Data_encoding.encoding (** [compute_new_ema ~toggle_vote old_ema] returns the value [new_ema] of the exponential moving average [old_ema] updated by the vote [toggle_vote]. It is updated as follows: - - if [toggle_vote] is [LB_pass] then [new_ema] = [old_ema], - - if [toggle_vote] is [LB_off], then [new_ema] = (1999 * ema[n] // 2000) + 1,000,000, - - if [toggle_vote] is [LB_on], then [new_ema] = (1999 * ema[n] // 2000). + - 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). 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_ema : - toggle_vote:liquidity_baking_toggle_vote -> Toggle_EMA.t -> Toggle_EMA.t +val compute_new_ema : toggle_vote:toggle_vote -> Toggle_EMA.t -> Toggle_EMA.t diff --git a/tezt/tests/encoding_samples/alpha/block_header.unsigned/block_header.unsigned.sample.json b/tezt/tests/encoding_samples/alpha/block_header.unsigned/block_header.unsigned.sample.json index 51a6450fc42a00147fcb4db9f8eced1cbc146b96..ca17d9d49df9b24b35a350ddaf7e623ea3cd5dee 100644 --- a/tezt/tests/encoding_samples/alpha/block_header.unsigned/block_header.unsigned.sample.json +++ b/tezt/tests/encoding_samples/alpha/block_header.unsigned/block_header.unsigned.sample.json @@ -13,6 +13,7 @@ "proof_of_work_nonce": "101895ca00000000", "seed_nonce_hash": "nceUFoeQDgkJCmzdMWh19ZjBYqQD3N9fe6bXQ1ZsUKKvMn7iun5Z3", "liquidity_baking_toggle_vote": "off", + "adaptive_inflation_toggle_vote": "on", "payload_hash": "vh1g87ZG6scSYxKhspAUzprQVuLAyoa5qMBKcUfjgnQGnFb3dJcG", "payload_round":0 } diff --git a/tezt/tests/encoding_samples/alpha/block_header/block_header.sample.json b/tezt/tests/encoding_samples/alpha/block_header/block_header.sample.json index af21dd2f4598e41da643e95453fa8929fbc7ca71..14968fcf78226abc467416e482e72376ada57dcb 100644 --- a/tezt/tests/encoding_samples/alpha/block_header/block_header.sample.json +++ b/tezt/tests/encoding_samples/alpha/block_header/block_header.sample.json @@ -13,6 +13,7 @@ "proof_of_work_nonce": "101895ca00000000", "seed_nonce_hash": "nceUFoeQDgkJCmzdMWh19ZjBYqQD3N9fe6bXQ1ZsUKKvMn7iun5Z3", "liquidity_baking_toggle_vote": "off", + "adaptive_inflation_toggle_vote": "on", "signature": "sigbQ5ZNvkjvGssJgoAnUAfY4Wvvg3QZqawBYB1j1VDBNTMBAALnCzRHWzer34bnfmzgHg3EvwdzQKdxgSghB897cono6gbQ", "payload_hash": "vh1g87ZG6scSYxKhspAUzprQVuLAyoa5qMBKcUfjgnQGnFb3dJcG", "payload_round":0 diff --git a/tezt/tests/encoding_samples/alpha/operation.unsigned/operation.unsigned-double-baking-evidence.sample.json b/tezt/tests/encoding_samples/alpha/operation.unsigned/operation.unsigned-double-baking-evidence.sample.json index 8eed2982138e38bc3d8ad2eb98def9c62803d097..f6e45f38b173af6fa788783d1b19f8658c214dd1 100644 --- a/tezt/tests/encoding_samples/alpha/operation.unsigned/operation.unsigned-double-baking-evidence.sample.json +++ b/tezt/tests/encoding_samples/alpha/operation.unsigned/operation.unsigned-double-baking-evidence.sample.json @@ -17,6 +17,7 @@ "context": "CoVDyf9y9gHfAkPWofBJffo4X4bWjmehH2LeVonDcCKKzyQYwqdk", "proof_of_work_nonce": "101895ca00000000", "liquidity_baking_toggle_vote": "off", + "adaptive_inflation_toggle_vote": "on", "signature": "sigbQ5ZNvkjvGssJgoAnUAfY4Wvvg3QZqawBYB1j1VDBNTMBAALnCzRHWzer34bnfmzgHg3EvwdzQKdxgSghB897cono6gbQ", "payload_hash": "vh1g87ZG6scSYxKhspAUzprQVuLAyoa5qMBKcUfjgnQGnFb3dJcG", "payload_round":0 @@ -35,6 +36,7 @@ "context": "CoVDyf9y9gHfAkPWofBJffo4X4bWjmehH2LeVonDcCKKzyQYwqdk", "proof_of_work_nonce": "101895ca00000000", "liquidity_baking_toggle_vote": "off", + "adaptive_inflation_toggle_vote": "on", "signature": "sigbQ5ZNvkjvGssJgoAnUAfY4Wvvg3QZqawBYB1j1VDBNTMBAALnCzRHWzer34bnfmzgHg3EvwdzQKdxgSghB897cono6gbQ", "payload_hash": "vh1g87ZG6scSYxKhspAUzprQVuLAyoa5qMBKcUfjgnQGnFb3dJcG", "payload_round":0 diff --git a/tezt/tests/encoding_samples/alpha/operation/operation-double-baking-evidence.sample.json b/tezt/tests/encoding_samples/alpha/operation/operation-double-baking-evidence.sample.json index 1c8f236c2deefaf67b93da9f487d2d136404e325..ed0a64bbd207c96016b9a29f09716dc67b2b9144 100644 --- a/tezt/tests/encoding_samples/alpha/operation/operation-double-baking-evidence.sample.json +++ b/tezt/tests/encoding_samples/alpha/operation/operation-double-baking-evidence.sample.json @@ -13,6 +13,7 @@ "context": "CoVDyf9y9gHfAkPWofBJffo4X4bWjmehH2LeVonDcCKKzyQYwqdk", "proof_of_work_nonce": "101895ca00000000", "liquidity_baking_toggle_vote": "off", + "adaptive_inflation_toggle_vote": "on", "signature": "sigbQ5ZNvkjvGssJgoAnUAfY4Wvvg3QZqawBYB1j1VDBNTMBAALnCzRHWzer34bnfmzgHg3EvwdzQKdxgSghB897cono6gbQ", "payload_hash": "vh1g87ZG6scSYxKhspAUzprQVuLAyoa5qMBKcUfjgnQGnFb3dJcG", "payload_round":0 @@ -28,6 +29,7 @@ "context": "CoVDyf9y9gHfAkPWofBJffo4X4bWjmehH2LeVonDcCKKzyQYwqdk", "proof_of_work_nonce": "101895ca00000000", "liquidity_baking_toggle_vote": "off", + "adaptive_inflation_toggle_vote": "on", "signature": "sigbQ5ZNvkjvGssJgoAnUAfY4Wvvg3QZqawBYB1j1VDBNTMBAALnCzRHWzer34bnfmzgHg3EvwdzQKdxgSghB897cono6gbQ", "payload_hash": "vh1g87ZG6scSYxKhspAUzprQVuLAyoa5qMBKcUfjgnQGnFb3dJcG", "payload_round":0 diff --git a/tezt/tests/encoding_samples/alpha/operation_with_attestation.unsigned/operation.unsigned-double-baking-evidence.sample.json b/tezt/tests/encoding_samples/alpha/operation_with_attestation.unsigned/operation.unsigned-double-baking-evidence.sample.json index 8eed2982138e38bc3d8ad2eb98def9c62803d097..f6e45f38b173af6fa788783d1b19f8658c214dd1 100644 --- a/tezt/tests/encoding_samples/alpha/operation_with_attestation.unsigned/operation.unsigned-double-baking-evidence.sample.json +++ b/tezt/tests/encoding_samples/alpha/operation_with_attestation.unsigned/operation.unsigned-double-baking-evidence.sample.json @@ -17,6 +17,7 @@ "context": "CoVDyf9y9gHfAkPWofBJffo4X4bWjmehH2LeVonDcCKKzyQYwqdk", "proof_of_work_nonce": "101895ca00000000", "liquidity_baking_toggle_vote": "off", + "adaptive_inflation_toggle_vote": "on", "signature": "sigbQ5ZNvkjvGssJgoAnUAfY4Wvvg3QZqawBYB1j1VDBNTMBAALnCzRHWzer34bnfmzgHg3EvwdzQKdxgSghB897cono6gbQ", "payload_hash": "vh1g87ZG6scSYxKhspAUzprQVuLAyoa5qMBKcUfjgnQGnFb3dJcG", "payload_round":0 @@ -35,6 +36,7 @@ "context": "CoVDyf9y9gHfAkPWofBJffo4X4bWjmehH2LeVonDcCKKzyQYwqdk", "proof_of_work_nonce": "101895ca00000000", "liquidity_baking_toggle_vote": "off", + "adaptive_inflation_toggle_vote": "on", "signature": "sigbQ5ZNvkjvGssJgoAnUAfY4Wvvg3QZqawBYB1j1VDBNTMBAALnCzRHWzer34bnfmzgHg3EvwdzQKdxgSghB897cono6gbQ", "payload_hash": "vh1g87ZG6scSYxKhspAUzprQVuLAyoa5qMBKcUfjgnQGnFb3dJcG", "payload_round":0 diff --git a/tezt/tests/encoding_samples/alpha/operation_with_attestation/operation-double-baking-evidence.sample.json b/tezt/tests/encoding_samples/alpha/operation_with_attestation/operation-double-baking-evidence.sample.json index 1c8f236c2deefaf67b93da9f487d2d136404e325..ed0a64bbd207c96016b9a29f09716dc67b2b9144 100644 --- a/tezt/tests/encoding_samples/alpha/operation_with_attestation/operation-double-baking-evidence.sample.json +++ b/tezt/tests/encoding_samples/alpha/operation_with_attestation/operation-double-baking-evidence.sample.json @@ -13,6 +13,7 @@ "context": "CoVDyf9y9gHfAkPWofBJffo4X4bWjmehH2LeVonDcCKKzyQYwqdk", "proof_of_work_nonce": "101895ca00000000", "liquidity_baking_toggle_vote": "off", + "adaptive_inflation_toggle_vote": "on", "signature": "sigbQ5ZNvkjvGssJgoAnUAfY4Wvvg3QZqawBYB1j1VDBNTMBAALnCzRHWzer34bnfmzgHg3EvwdzQKdxgSghB897cono6gbQ", "payload_hash": "vh1g87ZG6scSYxKhspAUzprQVuLAyoa5qMBKcUfjgnQGnFb3dJcG", "payload_round":0 @@ -28,6 +29,7 @@ "context": "CoVDyf9y9gHfAkPWofBJffo4X4bWjmehH2LeVonDcCKKzyQYwqdk", "proof_of_work_nonce": "101895ca00000000", "liquidity_baking_toggle_vote": "off", + "adaptive_inflation_toggle_vote": "on", "signature": "sigbQ5ZNvkjvGssJgoAnUAfY4Wvvg3QZqawBYB1j1VDBNTMBAALnCzRHWzer34bnfmzgHg3EvwdzQKdxgSghB897cono6gbQ", "payload_hash": "vh1g87ZG6scSYxKhspAUzprQVuLAyoa5qMBKcUfjgnQGnFb3dJcG", "payload_round":0 diff --git a/tezt/tests/expected/encoding.ml/Alpha- protocol encoding regression test- block_header.out b/tezt/tests/expected/encoding.ml/Alpha- protocol encoding regression test- block_header.out index 91c5dd6fcd5326d3cb98f6e916e742442c217ebb..734d744c5f5f4670c5e194378316abb457c5dcd5 100644 --- a/tezt/tests/expected/encoding.ml/Alpha- protocol encoding regression test- block_header.out +++ b/tezt/tests/expected/encoding.ml/Alpha- protocol encoding regression test- block_header.out @@ -14,6 +14,7 @@ "proof_of_work_nonce": "101895ca00000000", "seed_nonce_hash": "nceUFoeQDgkJCmzdMWh19ZjBYqQD3N9fe6bXQ1ZsUKKvMn7iun5Z3", "liquidity_baking_toggle_vote": "off", + "adaptive_inflation_toggle_vote": "on", "signature": "sigbQ5ZNvkjvGssJgoAnUAfY4Wvvg3QZqawBYB1j1VDBNTMBAALnCzRHWzer34bnfmzgHg3EvwdzQKdxgSghB897cono6gbQ", "payload_hash": "vh1g87ZG6scSYxKhspAUzprQVuLAyoa5qMBKcUfjgnQGnFb3dJcG", "payload_round": 0 @@ -31,5 +32,6 @@ "payload_round": 0, "proof_of_work_nonce": "101895ca00000000", "seed_nonce_hash": "nceUFoeQDgkJCmzdMWh19ZjBYqQD3N9fe6bXQ1ZsUKKvMn7iun5Z3", "liquidity_baking_toggle_vote": "off", + "adaptive_inflation_toggle_vote": "on", "signature": "sigbQ5ZNvkjvGssJgoAnUAfY4Wvvg3QZqawBYB1j1VDBNTMBAALnCzRHWzer34bnfmzgHg3EvwdzQKdxgSghB897cono6gbQ" } diff --git a/tezt/tests/expected/encoding.ml/Alpha- protocol encoding regression test- block_header.unsigned.out b/tezt/tests/expected/encoding.ml/Alpha- protocol encoding regression test- block_header.unsigned.out index 94a6b2aaf3cb5f396ef9e0341c1bce1db83da633..74cf3437e0c8c4cd39689a9ef4c8a0a7e5efb971 100644 --- a/tezt/tests/expected/encoding.ml/Alpha- protocol encoding regression test- block_header.unsigned.out +++ b/tezt/tests/expected/encoding.ml/Alpha- protocol encoding regression test- block_header.unsigned.out @@ -14,6 +14,7 @@ "proof_of_work_nonce": "101895ca00000000", "seed_nonce_hash": "nceUFoeQDgkJCmzdMWh19ZjBYqQD3N9fe6bXQ1ZsUKKvMn7iun5Z3", "liquidity_baking_toggle_vote": "off", + "adaptive_inflation_toggle_vote": "on", "payload_hash": "vh1g87ZG6scSYxKhspAUzprQVuLAyoa5qMBKcUfjgnQGnFb3dJcG", "payload_round": 0 }' @@ -29,4 +30,5 @@ "payload_hash": "vh1g87ZG6scSYxKhspAUzprQVuLAyoa5qMBKcUfjgnQGnFb3dJcG", "payload_round": 0, "proof_of_work_nonce": "101895ca00000000", "seed_nonce_hash": "nceUFoeQDgkJCmzdMWh19ZjBYqQD3N9fe6bXQ1ZsUKKvMn7iun5Z3", - "liquidity_baking_toggle_vote": "off" } + "liquidity_baking_toggle_vote": "off", + "adaptive_inflation_toggle_vote": "on" } diff --git a/tezt/tests/expected/encoding.ml/Alpha- protocol encoding regression test- operation.out b/tezt/tests/expected/encoding.ml/Alpha- protocol encoding regression test- operation.out index fe55ffd3f87c493b24802086cca7d85538db7a6e..1562092c5058e2935e1c2c2c5e0e5b04093fa041 100644 --- a/tezt/tests/expected/encoding.ml/Alpha- protocol encoding regression test- operation.out +++ b/tezt/tests/expected/encoding.ml/Alpha- protocol encoding regression test- operation.out @@ -119,6 +119,7 @@ "context": "CoVDyf9y9gHfAkPWofBJffo4X4bWjmehH2LeVonDcCKKzyQYwqdk", "proof_of_work_nonce": "101895ca00000000", "liquidity_baking_toggle_vote": "off", + "adaptive_inflation_toggle_vote": "on", "signature": "sigbQ5ZNvkjvGssJgoAnUAfY4Wvvg3QZqawBYB1j1VDBNTMBAALnCzRHWzer34bnfmzgHg3EvwdzQKdxgSghB897cono6gbQ", "payload_hash": "vh1g87ZG6scSYxKhspAUzprQVuLAyoa5qMBKcUfjgnQGnFb3dJcG", "payload_round": 0 @@ -137,6 +138,7 @@ "context": "CoVDyf9y9gHfAkPWofBJffo4X4bWjmehH2LeVonDcCKKzyQYwqdk", "proof_of_work_nonce": "101895ca00000000", "liquidity_baking_toggle_vote": "off", + "adaptive_inflation_toggle_vote": "on", "signature": "sigbQ5ZNvkjvGssJgoAnUAfY4Wvvg3QZqawBYB1j1VDBNTMBAALnCzRHWzer34bnfmzgHg3EvwdzQKdxgSghB897cono6gbQ", "payload_hash": "vh1g87ZG6scSYxKhspAUzprQVuLAyoa5qMBKcUfjgnQGnFb3dJcG", "payload_round": 0 @@ -164,6 +166,7 @@ "vh1g87ZG6scSYxKhspAUzprQVuLAyoa5qMBKcUfjgnQGnFb3dJcG", "payload_round": 0, "proof_of_work_nonce": "101895ca00000000", "liquidity_baking_toggle_vote": "off", + "adaptive_inflation_toggle_vote": "on", "signature": "sigbQ5ZNvkjvGssJgoAnUAfY4Wvvg3QZqawBYB1j1VDBNTMBAALnCzRHWzer34bnfmzgHg3EvwdzQKdxgSghB897cono6gbQ" }, "bh2": @@ -179,6 +182,7 @@ "vh1g87ZG6scSYxKhspAUzprQVuLAyoa5qMBKcUfjgnQGnFb3dJcG", "payload_round": 0, "proof_of_work_nonce": "101895ca00000000", "liquidity_baking_toggle_vote": "off", + "adaptive_inflation_toggle_vote": "on", "signature": "sigbQ5ZNvkjvGssJgoAnUAfY4Wvvg3QZqawBYB1j1VDBNTMBAALnCzRHWzer34bnfmzgHg3EvwdzQKdxgSghB897cono6gbQ" } } ], "signature": diff --git a/tezt/tests/expected/encoding.ml/Alpha- protocol encoding regression test- operation.unsigned.out b/tezt/tests/expected/encoding.ml/Alpha- protocol encoding regression test- operation.unsigned.out index b86292d4e7915723ea4ec14e358b5fbeeb78073c..59fc122be6e383ecc6f9a08c64dda2b11a209325 100644 --- a/tezt/tests/expected/encoding.ml/Alpha- protocol encoding regression test- operation.unsigned.out +++ b/tezt/tests/expected/encoding.ml/Alpha- protocol encoding regression test- operation.unsigned.out @@ -107,6 +107,7 @@ "context": "CoVDyf9y9gHfAkPWofBJffo4X4bWjmehH2LeVonDcCKKzyQYwqdk", "proof_of_work_nonce": "101895ca00000000", "liquidity_baking_toggle_vote": "off", + "adaptive_inflation_toggle_vote": "on", "signature": "sigbQ5ZNvkjvGssJgoAnUAfY4Wvvg3QZqawBYB1j1VDBNTMBAALnCzRHWzer34bnfmzgHg3EvwdzQKdxgSghB897cono6gbQ", "payload_hash": "vh1g87ZG6scSYxKhspAUzprQVuLAyoa5qMBKcUfjgnQGnFb3dJcG", "payload_round": 0 @@ -125,6 +126,7 @@ "context": "CoVDyf9y9gHfAkPWofBJffo4X4bWjmehH2LeVonDcCKKzyQYwqdk", "proof_of_work_nonce": "101895ca00000000", "liquidity_baking_toggle_vote": "off", + "adaptive_inflation_toggle_vote": "on", "signature": "sigbQ5ZNvkjvGssJgoAnUAfY4Wvvg3QZqawBYB1j1VDBNTMBAALnCzRHWzer34bnfmzgHg3EvwdzQKdxgSghB897cono6gbQ", "payload_hash": "vh1g87ZG6scSYxKhspAUzprQVuLAyoa5qMBKcUfjgnQGnFb3dJcG", "payload_round": 0 @@ -151,6 +153,7 @@ "vh1g87ZG6scSYxKhspAUzprQVuLAyoa5qMBKcUfjgnQGnFb3dJcG", "payload_round": 0, "proof_of_work_nonce": "101895ca00000000", "liquidity_baking_toggle_vote": "off", + "adaptive_inflation_toggle_vote": "on", "signature": "sigbQ5ZNvkjvGssJgoAnUAfY4Wvvg3QZqawBYB1j1VDBNTMBAALnCzRHWzer34bnfmzgHg3EvwdzQKdxgSghB897cono6gbQ" }, "bh2": @@ -166,6 +169,7 @@ "vh1g87ZG6scSYxKhspAUzprQVuLAyoa5qMBKcUfjgnQGnFb3dJcG", "payload_round": 0, "proof_of_work_nonce": "101895ca00000000", "liquidity_baking_toggle_vote": "off", + "adaptive_inflation_toggle_vote": "on", "signature": "sigbQ5ZNvkjvGssJgoAnUAfY4Wvvg3QZqawBYB1j1VDBNTMBAALnCzRHWzer34bnfmzgHg3EvwdzQKdxgSghB897cono6gbQ" } } ] } diff --git a/tezt/tests/expected/encoding.ml/Alpha- protocol encoding regression test- operation_with_attestation.out b/tezt/tests/expected/encoding.ml/Alpha- protocol encoding regression test- operation_with_attestation.out index cf0e30ff4387b572d6250a6fa1a225a384e696d1..7aa18621100198e819e76fa0ea085bfdb5f66e9a 100644 --- a/tezt/tests/expected/encoding.ml/Alpha- protocol encoding regression test- operation_with_attestation.out +++ b/tezt/tests/expected/encoding.ml/Alpha- protocol encoding regression test- operation_with_attestation.out @@ -167,6 +167,7 @@ "context": "CoVDyf9y9gHfAkPWofBJffo4X4bWjmehH2LeVonDcCKKzyQYwqdk", "proof_of_work_nonce": "101895ca00000000", "liquidity_baking_toggle_vote": "off", + "adaptive_inflation_toggle_vote": "on", "signature": "sigbQ5ZNvkjvGssJgoAnUAfY4Wvvg3QZqawBYB1j1VDBNTMBAALnCzRHWzer34bnfmzgHg3EvwdzQKdxgSghB897cono6gbQ", "payload_hash": "vh1g87ZG6scSYxKhspAUzprQVuLAyoa5qMBKcUfjgnQGnFb3dJcG", "payload_round": 0 @@ -185,6 +186,7 @@ "context": "CoVDyf9y9gHfAkPWofBJffo4X4bWjmehH2LeVonDcCKKzyQYwqdk", "proof_of_work_nonce": "101895ca00000000", "liquidity_baking_toggle_vote": "off", + "adaptive_inflation_toggle_vote": "on", "signature": "sigbQ5ZNvkjvGssJgoAnUAfY4Wvvg3QZqawBYB1j1VDBNTMBAALnCzRHWzer34bnfmzgHg3EvwdzQKdxgSghB897cono6gbQ", "payload_hash": "vh1g87ZG6scSYxKhspAUzprQVuLAyoa5qMBKcUfjgnQGnFb3dJcG", "payload_round": 0 @@ -212,6 +214,7 @@ "vh1g87ZG6scSYxKhspAUzprQVuLAyoa5qMBKcUfjgnQGnFb3dJcG", "payload_round": 0, "proof_of_work_nonce": "101895ca00000000", "liquidity_baking_toggle_vote": "off", + "adaptive_inflation_toggle_vote": "on", "signature": "sigbQ5ZNvkjvGssJgoAnUAfY4Wvvg3QZqawBYB1j1VDBNTMBAALnCzRHWzer34bnfmzgHg3EvwdzQKdxgSghB897cono6gbQ" }, "bh2": @@ -227,6 +230,7 @@ "vh1g87ZG6scSYxKhspAUzprQVuLAyoa5qMBKcUfjgnQGnFb3dJcG", "payload_round": 0, "proof_of_work_nonce": "101895ca00000000", "liquidity_baking_toggle_vote": "off", + "adaptive_inflation_toggle_vote": "on", "signature": "sigbQ5ZNvkjvGssJgoAnUAfY4Wvvg3QZqawBYB1j1VDBNTMBAALnCzRHWzer34bnfmzgHg3EvwdzQKdxgSghB897cono6gbQ" } } ], "signature": diff --git a/tezt/tests/expected/encoding.ml/Alpha- protocol encoding regression test- operation_with_attestation.unsigned.out b/tezt/tests/expected/encoding.ml/Alpha- protocol encoding regression test- operation_with_attestation.unsigned.out index b1ec74e5075d3547110efcfe6d8e2e2547ae4447..9bfabc76ac45e70b7c07a18900cb77b13f207725 100644 --- a/tezt/tests/expected/encoding.ml/Alpha- protocol encoding regression test- operation_with_attestation.unsigned.out +++ b/tezt/tests/expected/encoding.ml/Alpha- protocol encoding regression test- operation_with_attestation.unsigned.out @@ -181,6 +181,7 @@ "context": "CoVDyf9y9gHfAkPWofBJffo4X4bWjmehH2LeVonDcCKKzyQYwqdk", "proof_of_work_nonce": "101895ca00000000", "liquidity_baking_toggle_vote": "off", + "adaptive_inflation_toggle_vote": "on", "signature": "sigbQ5ZNvkjvGssJgoAnUAfY4Wvvg3QZqawBYB1j1VDBNTMBAALnCzRHWzer34bnfmzgHg3EvwdzQKdxgSghB897cono6gbQ", "payload_hash": "vh1g87ZG6scSYxKhspAUzprQVuLAyoa5qMBKcUfjgnQGnFb3dJcG", "payload_round": 0 @@ -199,6 +200,7 @@ "context": "CoVDyf9y9gHfAkPWofBJffo4X4bWjmehH2LeVonDcCKKzyQYwqdk", "proof_of_work_nonce": "101895ca00000000", "liquidity_baking_toggle_vote": "off", + "adaptive_inflation_toggle_vote": "on", "signature": "sigbQ5ZNvkjvGssJgoAnUAfY4Wvvg3QZqawBYB1j1VDBNTMBAALnCzRHWzer34bnfmzgHg3EvwdzQKdxgSghB897cono6gbQ", "payload_hash": "vh1g87ZG6scSYxKhspAUzprQVuLAyoa5qMBKcUfjgnQGnFb3dJcG", "payload_round": 0 @@ -225,6 +227,7 @@ "vh1g87ZG6scSYxKhspAUzprQVuLAyoa5qMBKcUfjgnQGnFb3dJcG", "payload_round": 0, "proof_of_work_nonce": "101895ca00000000", "liquidity_baking_toggle_vote": "off", + "adaptive_inflation_toggle_vote": "on", "signature": "sigbQ5ZNvkjvGssJgoAnUAfY4Wvvg3QZqawBYB1j1VDBNTMBAALnCzRHWzer34bnfmzgHg3EvwdzQKdxgSghB897cono6gbQ" }, "bh2": @@ -240,6 +243,7 @@ "vh1g87ZG6scSYxKhspAUzprQVuLAyoa5qMBKcUfjgnQGnFb3dJcG", "payload_round": 0, "proof_of_work_nonce": "101895ca00000000", "liquidity_baking_toggle_vote": "off", + "adaptive_inflation_toggle_vote": "on", "signature": "sigbQ5ZNvkjvGssJgoAnUAfY4Wvvg3QZqawBYB1j1VDBNTMBAALnCzRHWzer34bnfmzgHg3EvwdzQKdxgSghB897cono6gbQ" } } ] } diff --git a/tezt/tests/liquidity_baking_per_block_votes.ml b/tezt/tests/liquidity_baking_per_block_votes.ml index e83b26112a4ef7fcbed7ec66bc0f93337c5a4fb9..8342b811dd08726e8020e05ba2d221532271b8c8 100644 --- a/tezt/tests/liquidity_baking_per_block_votes.ml +++ b/tezt/tests/liquidity_baking_per_block_votes.ml @@ -240,7 +240,7 @@ let test_all_per_block_votes = let p_error = baker_wait_for_per_block_vote_file_error ~expected_id: - (error_prefix ^ "liquidity_baking_vote.block_vote_file_not_found") + (error_prefix ^ "per_block_vote_file.block_vote_file_not_found") ~expected_file_path:default_votefile baker in diff --git a/tezt/tests/sc_rollup.ml b/tezt/tests/sc_rollup.ml index 146cef6ecef5d20737cf6b954b6efe98d316b3aa..ae91b17dc01f4ef57cad4a0f24922dee4d47e184 100644 --- a/tezt/tests/sc_rollup.ml +++ b/tezt/tests/sc_rollup.ml @@ -1464,19 +1464,20 @@ let test_rollup_node_simple_migration ~kind ~migrate_from ~migrate_to = let* () = Sc_rollup_node.run rollup_node sc_rollup [] in let* () = send_messages commitment_period tezos_client in let* _ = Sc_rollup_node.wait_sync rollup_node ~timeout:10. in - let* () = Sc_rollup_node.terminate rollup_node in - unit + return rollup_node in let scenario_after ~sc_rollup rollup_node rollup_client tezos_node - tezos_client () = + tezos_client previous_rollup_node = let migration_level = Node.get_level tezos_node in + let* _ = Sc_rollup_node.wait_sync previous_rollup_node ~timeout:10. in + let* () = Sc_rollup_node.terminate previous_rollup_node in + let* () = send_messages 1 tezos_client in let* () = Sc_rollup_node.run rollup_node sc_rollup [] in let*! _l2_block = Sc_rollup_client.rpc_get rollup_client ["global"; "block"; string_of_int (migration_level - 1)] in - let* () = send_messages 1 tezos_client in let* _ = Sc_rollup_node.wait_sync rollup_node ~timeout:10. in let*! _l2_block = Sc_rollup_client.rpc_get rollup_client ["global"; "block"; "head"]