From cddd133bd92e621b525cea79a9701889d9b6afbb Mon Sep 17 00:00:00 2001 From: Philippe Wang Date: Mon, 15 May 2023 10:31:01 -0700 Subject: [PATCH 1/9] adaptive inflation: renamings for adding toggle vote - rename liquidity_baking_repr.ml{,i} to toggle_votes_repr.ml{,i} - rename liquidity_baking_vote.ml{,i} to per_block_vote_file.ml{,i} --- src/proto_alpha/lib_delegate/baking_actions.ml | 2 +- src/proto_alpha/lib_delegate/baking_commands.ml | 8 ++++---- ...ity_baking_vote.ml => per_block_vote_file.ml} | 0 ...y_baking_vote.mli => per_block_vote_file.mli} | 0 src/proto_alpha/lib_protocol/TEZOS_PROTOCOL | 2 +- src/proto_alpha/lib_protocol/alpha_context.ml | 2 +- src/proto_alpha/lib_protocol/alpha_context.mli | 6 +++--- .../lib_protocol/block_header_repr.ml | 4 ++-- .../lib_protocol/block_header_repr.mli | 2 +- src/proto_alpha/lib_protocol/dune | 8 ++++---- .../lib_protocol/liquidity_baking_storage.ml | 2 +- .../lib_protocol/liquidity_baking_storage.mli | 4 ++-- .../test/unit/test_liquidity_baking_repr.ml | 16 ++++++++-------- ...idity_baking_repr.ml => toggle_votes_repr.ml} | 0 ...ity_baking_repr.mli => toggle_votes_repr.mli} | 0 15 files changed, 28 insertions(+), 28 deletions(-) rename src/proto_alpha/lib_delegate/{liquidity_baking_vote.ml => per_block_vote_file.ml} (100%) rename src/proto_alpha/lib_delegate/{liquidity_baking_vote.mli => per_block_vote_file.mli} (100%) rename src/proto_alpha/lib_protocol/{liquidity_baking_repr.ml => toggle_votes_repr.ml} (100%) rename src/proto_alpha/lib_protocol/{liquidity_baking_repr.mli => toggle_votes_repr.mli} (100%) diff --git a/src/proto_alpha/lib_delegate/baking_actions.ml b/src/proto_alpha/lib_delegate/baking_actions.ml index 2ffc5a82216a..0bac567075e2 100644 --- a/src/proto_alpha/lib_delegate/baking_actions.ml +++ b/src/proto_alpha/lib_delegate/baking_actions.ml @@ -290,7 +290,7 @@ let inject_block ~state_recorder state block_to_bake ~updated_state = (* 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 + Per_block_vote_file.read_liquidity_baking_toggle_vote_no_fail ~default_liquidity_baking_vote:liquidity_baking_vote ~per_block_vote_file | None -> Lwt.return liquidity_baking_vote) diff --git a/src/proto_alpha/lib_delegate/baking_commands.ml b/src/proto_alpha/lib_delegate/baking_commands.ml index f7afe1494d71..26c21c7676d9 100644 --- a/src/proto_alpha/lib_delegate/baking_commands.ml +++ b/src/proto_alpha/lib_delegate/baking_commands.ml @@ -451,17 +451,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 @@ -511,7 +511,7 @@ let run_baker (* We don't let the user run the baker without providing some option (CLI, file path, or file in default location) for the toggle vote. *) - Liquidity_baking_vote.load_liquidity_baking_config + Per_block_vote_file.load_liquidity_baking_config ~per_block_vote_file_arg:per_block_vote_file ~toggle_vote_arg:liquidity_baking_toggle_vote >>=? fun liquidity_baking -> 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 100% rename from src/proto_alpha/lib_delegate/liquidity_baking_vote.ml rename to src/proto_alpha/lib_delegate/per_block_vote_file.ml 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 100% rename from src/proto_alpha/lib_delegate/liquidity_baking_vote.mli rename to src/proto_alpha/lib_delegate/per_block_vote_file.mli diff --git a/src/proto_alpha/lib_protocol/TEZOS_PROTOCOL b/src/proto_alpha/lib_protocol/TEZOS_PROTOCOL index 68c78822f3cb..a5603653a3d3 100644 --- a/src/proto_alpha/lib_protocol/TEZOS_PROTOCOL +++ b/src/proto_alpha/lib_protocol/TEZOS_PROTOCOL @@ -106,7 +106,7 @@ "Bond_id_repr", "Vote_repr", - "Liquidity_baking_repr", + "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 70c8061a3a78..24a9a4095603 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.ml +++ b/src/proto_alpha/lib_protocol/alpha_context.ml @@ -651,7 +651,7 @@ let description = Raw_context.description module Parameters = Parameters_repr module Liquidity_baking = struct - include Liquidity_baking_repr + include Toggle_votes_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 ce0980048d0e..82d9c9509d45 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -4350,7 +4350,7 @@ module Block_header : sig 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_repr.liquidity_baking_toggle_vote; } type protocol_data = {contents : contents; signature : signature} @@ -5206,11 +5206,11 @@ module Parameters : sig val encoding : t Data_encoding.t end -(** This module re-exports definitions from {!Liquidity_baking_repr} and +(** This module re-exports definitions from {!Toggle_votes_repr} and {!Liquidity_baking_storage}. *) module Liquidity_baking : sig type liquidity_baking_toggle_vote = - Liquidity_baking_repr.liquidity_baking_toggle_vote = + Toggle_votes_repr.liquidity_baking_toggle_vote = | LB_on | LB_off | LB_pass diff --git a/src/proto_alpha/lib_protocol/block_header_repr.ml b/src/proto_alpha/lib_protocol/block_header_repr.ml index c9a1752eacc1..18787dd42da7 100644 --- a/src/proto_alpha/lib_protocol/block_header_repr.ml +++ b/src/proto_alpha/lib_protocol/block_header_repr.ml @@ -31,7 +31,7 @@ type contents = { 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_repr.liquidity_baking_toggle_vote; } type protocol_data = {contents : contents; signature : Signature.t} @@ -105,7 +105,7 @@ let contents_encoding = (opt "seed_nonce_hash" Nonce_hash.encoding) (req "liquidity_baking_toggle_vote" - Liquidity_baking_repr.liquidity_baking_toggle_vote_encoding)) + Toggle_votes_repr.liquidity_baking_toggle_vote_encoding)) let protocol_data_encoding = let open Data_encoding in diff --git a/src/proto_alpha/lib_protocol/block_header_repr.mli b/src/proto_alpha/lib_protocol/block_header_repr.mli index 4ee571593339..b78e2f5c1cfa 100644 --- a/src/proto_alpha/lib_protocol/block_header_repr.mli +++ b/src/proto_alpha/lib_protocol/block_header_repr.mli @@ -31,7 +31,7 @@ type contents = { 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_repr.liquidity_baking_toggle_vote; } 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 f67e2eb7ffb6..87664395e498 100644 --- a/src/proto_alpha/lib_protocol/dune +++ b/src/proto_alpha/lib_protocol/dune @@ -129,7 +129,7 @@ Zk_rollup_circuit_public_inputs_repr Bond_id_repr Vote_repr - Liquidity_baking_repr + Toggle_votes_repr Block_header_repr Destination_repr Script_int @@ -409,7 +409,7 @@ 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_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 +691,7 @@ 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_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 +957,7 @@ 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_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_storage.ml b/src/proto_alpha/lib_protocol/liquidity_baking_storage.ml index 56c6f3746ad7..7dd169ceb5c7 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 f1d0d5886292..0e711a4d2093 100644 --- a/src/proto_alpha/lib_protocol/liquidity_baking_storage.mli +++ b/src/proto_alpha/lib_protocol/liquidity_baking_storage.mli @@ -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.liquidity_baking_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_votes_repr.Toggle_EMA.t) tzresult Lwt.t 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 78d3b0d73851..8f3cf3ed61b6 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 @@ -25,27 +25,27 @@ (** Testing ------- - Component: Protocol Liquidity_baking_repr module + Component: Protocol Toggle_votes_repr module Invocation: dune exec src/proto_alpha/lib_protocol/test/unit/main.exe \ -- --file test_liquidity_baking_repr.ml - Subject: Tests for the Liquidity_baking_repr module + Subject: Tests for the Toggle_votes_repr module *) open Protocol let ema_of_int32 ema = - Liquidity_baking_repr.Toggle_EMA.of_int32 ema >|= Environment.wrap_tzresult + Toggle_votes_repr.Toggle_EMA.of_int32 ema >|= Environment.wrap_tzresult -let ema_to_int32 = Liquidity_baking_repr.Toggle_EMA.to_int32 +let ema_to_int32 = Toggle_votes_repr.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) + Toggle_votes_repr.compute_new_ema ~toggle_vote ema) initial_ema toggle_votes |> ema_to_int32 @@ -170,7 +170,7 @@ let test_ema_decreases_on_bound () = (* Test that 1385 Off votes are needed to reach the threshold from 0. *) let test_ema_many_off () = - let open Liquidity_baking_repr in + let open Toggle_votes_repr in ema_of_int32 0l >>=? fun initial_ema -> Assert.leq_int32 ~loc:__LOC__ @@ -184,7 +184,7 @@ let test_ema_many_off () = (* Test that 1385 On votes are needed to reach the threshold from the max value of the EMA (2,000,000,000). *) let test_ema_many_on () = - let open 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__ diff --git a/src/proto_alpha/lib_protocol/liquidity_baking_repr.ml b/src/proto_alpha/lib_protocol/toggle_votes_repr.ml similarity index 100% rename from src/proto_alpha/lib_protocol/liquidity_baking_repr.ml rename to src/proto_alpha/lib_protocol/toggle_votes_repr.ml diff --git a/src/proto_alpha/lib_protocol/liquidity_baking_repr.mli b/src/proto_alpha/lib_protocol/toggle_votes_repr.mli similarity index 100% rename from src/proto_alpha/lib_protocol/liquidity_baking_repr.mli rename to src/proto_alpha/lib_protocol/toggle_votes_repr.mli -- GitLab From c5727c135191d0fd80c1b60810baae12320dfe22 Mon Sep 17 00:00:00 2001 From: Philippe Wang Date: Mon, 15 May 2023 10:51:50 -0700 Subject: [PATCH 2/9] adaptive inflation: add toggle vote --- src/proto_alpha/lib_client/mockup.ml | 6 +- .../lib_delegate/baking_actions.ml | 40 ++-- .../lib_delegate/baking_commands.ml | 50 +++-- .../lib_delegate/baking_configuration.ml | 64 +++--- .../lib_delegate/baking_configuration.mli | 20 +- src/proto_alpha/lib_delegate/baking_events.ml | 32 ++- src/proto_alpha/lib_delegate/block_forge.ml | 26 ++- src/proto_alpha/lib_delegate/block_forge.mli | 3 +- src/proto_alpha/lib_delegate/client_daemon.ml | 4 +- .../lib_delegate/client_daemon.mli | 2 +- .../lib_delegate/per_block_vote_file.ml | 187 ++++++++++++------ .../lib_delegate/per_block_vote_file.mli | 35 ++-- src/proto_alpha/lib_plugin/RPC.ml | 25 ++- src/proto_alpha/lib_protocol/TEZOS_PROTOCOL | 1 + src/proto_alpha/lib_protocol/alpha_context.ml | 3 +- .../lib_protocol/alpha_context.mli | 51 +++-- src/proto_alpha/lib_protocol/apply.ml | 25 ++- src/proto_alpha/lib_protocol/apply.mli | 3 +- src/proto_alpha/lib_protocol/apply_results.ml | 9 +- .../lib_protocol/apply_results.mli | 3 +- .../lib_protocol/block_header_repr.ml | 122 ++++++++---- .../lib_protocol/block_header_repr.mli | 3 +- src/proto_alpha/lib_protocol/dune | 4 + .../lib_protocol/liquidity_baking_storage.mli | 6 +- src/proto_alpha/lib_protocol/main.ml | 7 +- .../lib_protocol/test/helpers/block.ml | 77 ++++++-- .../lib_protocol/test/helpers/block.mli | 23 ++- src/proto_alpha/lib_protocol/toggle_EMA.ml | 80 ++++++++ src/proto_alpha/lib_protocol/toggle_EMA.mli | 45 +++++ .../lib_protocol/toggle_votes_repr.ml | 152 ++++++-------- .../lib_protocol/toggle_votes_repr.mli | 39 ++-- 31 files changed, 764 insertions(+), 383 deletions(-) create mode 100644 src/proto_alpha/lib_protocol/toggle_EMA.ml create mode 100644 src/proto_alpha/lib_protocol/toggle_EMA.mli diff --git a/src/proto_alpha/lib_client/mockup.ml b/src/proto_alpha/lib_client/mockup.ml index 8ba8d4ccfd2f..d1bf4ff2889e 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 0bac567075e2..35978f251198 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 -> - Per_block_vote_file.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 26c21c7676d9..c0257de33bb0 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. Note that \ + this \"option\" is mandatory!" + ~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 @@ -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. *) - Per_block_vote_file.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 96cf50164143..94d0ef11ce0c 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 57a6dfbfb335..22ed5ec03508 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 82b9a38834ca..e564f0b31b4c 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 liquidity baking 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 21b6f69116d7..3ef8e3b49339 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 7afc2ce9791f..ab8dd25c154b 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 3748f0dd3005..1ec3357eabaa 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 1f3dedf9c305..6b7d49f79b54 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/per_block_vote_file.ml b/src/proto_alpha/lib_delegate/per_block_vote_file.ml index a7afef165a95..70fecd7313d9 100644 --- a/src/proto_alpha/lib_delegate/per_block_vote_file.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 @@ -44,14 +58,14 @@ type error += Block_vote_file_invalid of string type error += Block_vote_file_wrong_content of string -type error += Block_vote_file_missing_liquidity_baking_toggle_vote of string +type error += Block_vote_file_missing_toggle_votes of string 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,13 @@ 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\".@]" file_path) Data_encoding.(obj1 (req "file_path" string)) (function @@ -106,44 +123,45 @@ let () = (fun file_path -> Block_vote_file_wrong_content file_path) ; register_error_kind `Permanent - ~id: - "liquidity_baking_vote.block_vote_file_missing_liquidity_baking_toggle_vote" + ~id:"per_block_vote_file.block_vote_file_missing_toggle_votes" ~title: "In the provided block vote file, no entry for liquidity baking toggle \ vote was found" ~description: "In the provided block vote file, no entry for liquidity baking toggle \ - vote was found." + vote weres found." ~pp:(fun ppf file_path -> 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 - | Block_vote_file_missing_liquidity_baking_toggle_vote file_path -> - Some file_path + | Block_vote_file_missing_toggle_votes file_path -> Some file_path | _ -> None) - (fun file_path -> - Block_vote_file_missing_liquidity_baking_toggle_vote file_path) ; + (fun file_path -> Block_vote_file_missing_toggle_votes file_path) ; register_error_kind `Permanent - ~id:"liquidity_baking_vote.missing_vote_on_startup" - ~title:"Missing vote on startup" + ~id:"per_block_vote_file.missing_votes_on_startup" + ~title:"Missing votes 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 \ + vote file in the default location: per_block_votes.json in the \ + current working directory.") Data_encoding.empty (function Missing_vote_on_startup -> Some () | _ -> None) (fun () -> Missing_vote_on_startup) @@ -155,55 +173,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 +282,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/per_block_vote_file.mli b/src/proto_alpha/lib_delegate/per_block_vote_file.mli index e74b38031771..81d12888ebfe 100644 --- a/src/proto_alpha/lib_delegate/per_block_vote_file.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 @@ -44,7 +56,7 @@ type error += Block_vote_file_invalid of string type error += Block_vote_file_wrong_content of string -type error += Block_vote_file_missing_liquidity_baking_toggle_vote of string +type error += Block_vote_file_missing_toggle_votes of string type error += Missing_vote_on_startup @@ -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_plugin/RPC.ml b/src/proto_alpha/lib_plugin/RPC.ml index 4869459ded9f..a0b761a705a0 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 a5603653a3d3..ca742908aa9f 100644 --- a/src/proto_alpha/lib_protocol/TEZOS_PROTOCOL +++ b/src/proto_alpha/lib_protocol/TEZOS_PROTOCOL @@ -106,6 +106,7 @@ "Bond_id_repr", "Vote_repr", + "Toggle_EMA", "Toggle_votes_repr", "Block_header_repr", "Destination_repr", diff --git a/src/proto_alpha/lib_protocol/alpha_context.ml b/src/proto_alpha/lib_protocol/alpha_context.ml index 24a9a4095603..f3431547bde8 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 Toggle_votes_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 82d9c9509d45..b26022f5e6f2 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 : - Toggle_votes_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 {!Toggle_votes_repr} and - {!Liquidity_baking_storage}. *) -module Liquidity_baking : sig - type liquidity_baking_toggle_vote = - Toggle_votes_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 4a9a8dbaa464..8421f59d3746 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 b20cfdb108eb..9f1d0de95119 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 9778fad1feb8..80312f989cfa 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; } -> @@ -2551,6 +2553,7 @@ let block_metadata_encoding = deactivated; balance_updates; liquidity_baking_toggle_ema; + adaptive_inflation_toggle_ema = Toggle_EMA.zero; implicit_operations_results; dal_attestation; }) @@ -2563,9 +2566,7 @@ 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 "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 6011179e6dd9..673c4b801e16 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 18787dd42da7..058e3eb3241e 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 : - Toggle_votes_repr.liquidity_baking_toggle_vote; + toggle_votes : Toggle_votes_repr.toggle_votes; } type protocol_data = {contents : contents; signature : Signature.t} @@ -70,42 +69,83 @@ 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" - Toggle_votes_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_vote" + Toggle_votes_repr.adaptive_inflation_vote_encoding)) + and 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 +204,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 b78e2f5c1cfa..9960bff5a907 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 : - Toggle_votes_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 87664395e498..4e4f8a0336e9 100644 --- a/src/proto_alpha/lib_protocol/dune +++ b/src/proto_alpha/lib_protocol/dune @@ -129,6 +129,7 @@ Zk_rollup_circuit_public_inputs_repr Bond_id_repr Vote_repr + Toggle_EMA Toggle_votes_repr Block_header_repr Destination_repr @@ -409,6 +410,7 @@ zk_rollup_circuit_public_inputs_repr.mli bond_id_repr.ml bond_id_repr.mli vote_repr.ml vote_repr.mli + toggle_EMA.ml toggle_EMA.mli toggle_votes_repr.ml toggle_votes_repr.mli block_header_repr.ml block_header_repr.mli destination_repr.ml destination_repr.mli @@ -691,6 +693,7 @@ zk_rollup_circuit_public_inputs_repr.mli bond_id_repr.ml bond_id_repr.mli vote_repr.ml vote_repr.mli + toggle_EMA.ml toggle_EMA.mli toggle_votes_repr.ml toggle_votes_repr.mli block_header_repr.ml block_header_repr.mli destination_repr.ml destination_repr.mli @@ -957,6 +960,7 @@ zk_rollup_circuit_public_inputs_repr.mli bond_id_repr.ml bond_id_repr.mli vote_repr.ml vote_repr.mli + toggle_EMA.ml toggle_EMA.mli toggle_votes_repr.ml toggle_votes_repr.mli block_header_repr.ml block_header_repr.mli destination_repr.ml destination_repr.mli diff --git a/src/proto_alpha/lib_protocol/liquidity_baking_storage.mli b/src/proto_alpha/lib_protocol/liquidity_baking_storage.mli index 0e711a4d2093..9d83c3cc9689 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:Toggle_votes_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 * Toggle_votes_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 2f3466008229..27e49b47dddc 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 f40cf8a13aab..13e045bfda7c 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 cde54f39b435..5c49bc36c649 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/toggle_EMA.ml b/src/proto_alpha/lib_protocol/toggle_EMA.ml new file mode 100644 index 000000000000..4b4c469a41e2 --- /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 000000000000..2867c35bcb9c --- /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 index 09ea87b0e4c4..f396b030d8fc 100644 --- a/src/proto_alpha/lib_protocol/toggle_votes_repr.ml +++ b/src/proto_alpha/lib_protocol/toggle_votes_repr.ml @@ -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,99 +24,75 @@ (* *) (*****************************************************************************) -(** 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 -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" +type toggle_votes = { + liquidity_baking_vote : toggle_vote; + adaptive_inflation_vote : toggle_vote; +} - let to_int32 ema = ema +let toggle_vote_of_int2 = function + | 0 -> Ok Toggle_vote_on + | 1 -> Ok Toggle_vote_off + | 2 -> Ok Toggle_vote_pass + | _ -> Error "toggle_vote_of_int2" - (* We perform the computations in Z to avoid overflows. *) +let toggle_vote_to_int2 = function + | Toggle_vote_on -> 0 + | Toggle_vote_off -> 1 + | Toggle_vote_pass -> 2 - 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 +let toggle_vote_encoding name = + let open Data_encoding in + (* union *) + def name + @@ splitted + ~binary:(conv_with_guard toggle_vote_to_int2 toggle_vote_of_int2 int8) + ~json: + (string_enum + [ + ("on", Toggle_vote_on); + ("off", Toggle_vote_off); + ("pass", Toggle_vote_pass); + ]) + +let liquidity_baking_vote_encoding = + toggle_vote_encoding "liquidity_baking_vote" + +let adaptive_inflation_vote_encoding = + toggle_vote_encoding "adaptive_inflation_vote" + +let toggle_votes_encoding = + let of_int8 i = + match (toggle_vote_of_int2 (i land 0b11), toggle_vote_of_int2 (i / 4)) with + | Ok liquidity_baking_vote, Ok adaptive_inflation_vote -> + Ok {liquidity_baking_vote; adaptive_inflation_vote} + | _ -> Error "toggle_votes_of_int8" + in + let to_int8 {liquidity_baking_vote; adaptive_inflation_vote} = + toggle_vote_to_int2 liquidity_baking_vote + + (toggle_vote_to_int2 adaptive_inflation_vote * 4) + in + let open Data_encoding in + let json = + 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" liquidity_baking_vote_encoding) + (req "adaptive_inflation_vote" adaptive_inflation_vote_encoding)) + in + (* union *) + def "toggle_votes" + @@ splitted ~binary:(conv_with_guard to_int8 of_int8 int8) ~json (* 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 + | 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/toggle_votes_repr.mli b/src/proto_alpha/lib_protocol/toggle_votes_repr.mli index a41f80d5835b..25aed7e9b4d0 100644 --- a/src/proto_alpha/lib_protocol/toggle_votes_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 -- GitLab From 342dc0f15e5fa8dd926b45132f176e34869e904d Mon Sep 17 00:00:00 2001 From: Philippe Wang Date: Mon, 15 May 2023 10:55:34 -0700 Subject: [PATCH 3/9] adaptive inflation: update tests --- src/lib_store/unix/test/alpha_utils.ml | 9 +- .../test/mockup_simulator/mockup_simulator.ml | 14 ++- .../test/helpers/operation_generator.ml | 6 +- .../test/integration/test_liquidity_baking.ml | 93 ++++++++++--------- .../test/unit/test_liquidity_baking_repr.ml | 48 ++++++---- .../block_header.unsigned.sample.json | 1 + .../block_header/block_header.sample.json | 1 + ...nsigned-double-baking-evidence.sample.json | 2 + ...eration-double-baking-evidence.sample.json | 2 + ...nsigned-double-baking-evidence.sample.json | 2 + ...eration-double-baking-evidence.sample.json | 2 + ...encoding regression test- block_header.out | 2 + ...regression test- block_header.unsigned.out | 4 +- ...ol encoding regression test- operation.out | 4 + ...ng regression test- operation.unsigned.out | 4 + ...ssion test- operation_with_attestation.out | 4 + ...t- operation_with_attestation.unsigned.out | 4 + .../tests/liquidity_baking_per_block_votes.ml | 2 +- 18 files changed, 131 insertions(+), 73 deletions(-) diff --git a/src/lib_store/unix/test/alpha_utils.ml b/src/lib_store/unix/test/alpha_utils.ml index a7b0e4e958d2..487f0b6ec32e 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_delegate/test/mockup_simulator/mockup_simulator.ml b/src/proto_alpha/lib_delegate/test/mockup_simulator/mockup_simulator.ml index bced9bf820c3..d116e513d0f6 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_protocol/test/helpers/operation_generator.ml b/src/proto_alpha/lib_protocol/test/helpers/operation_generator.ml index 95e977fc9ee2..c838e1a9f691 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 c779a10d5ada..9a63b0b546d3 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 8f3cf3ed61b6..11bd5db88e18 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 @@ -25,18 +25,17 @@ (** Testing ------- - Component: Protocol Toggle_votes_repr module + Component: Protocol Liquidity_baking_repr module Invocation: dune exec src/proto_alpha/lib_protocol/test/unit/main.exe \ -- --file test_liquidity_baking_repr.ml - Subject: Tests for the Toggle_votes_repr module + Subject: Tests for the Liquidity_baking_repr module *) open Protocol -let ema_of_int32 ema = - Toggle_votes_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 = Toggle_votes_repr.Toggle_EMA.to_int32 +let ema_to_int32 = Toggle_EMA.to_int32 let compute_new_ema ~toggle_vote ema = Toggle_votes_repr.compute_new_ema ~toggle_vote ema |> ema_to_int32 @@ -44,8 +43,7 @@ let compute_new_ema ~toggle_vote ema = (* Folds compute_new_ema on a list of votes *) let compute_new_ema_n toggle_votes initial_ema = List.fold_left - (fun ema toggle_vote -> - Toggle_votes_repr.compute_new_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,7 +162,7 @@ let test_ema_decreases_on_bound () = ema_of_int32 old_ema >>=? fun ema -> Assert.leq_int32 ~loc:__LOC__ - (Int32.sub (compute_new_ema ~toggle_vote:LB_on ema) old_ema) + (Int32.sub (compute_new_ema ~toggle_vote:Toggle_vote_on ema) old_ema) 1_000_000l) ema_range @@ -174,13 +172,17 @@ let test_ema_many_off () = 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 () = @@ -189,11 +191,15 @@ let test_ema_many_on () = 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/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 51a6450fc42a..ca17d9d49df9 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 af21dd2f4598..14968fcf7822 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 8eed2982138e..f6e45f38b173 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 1c8f236c2dee..ed0a64bbd207 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 8eed2982138e..f6e45f38b173 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 1c8f236c2dee..ed0a64bbd207 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 91c5dd6fcd53..734d744c5f5f 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 94a6b2aaf3cb..74cf3437e0c8 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 fe55ffd3f87c..1562092c5058 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 b86292d4e791..59fc122be6e3 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 cf0e30ff4387..7aa186211001 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 b1ec74e5075d..9bfabc76ac45 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 e83b26112a4e..8342b811dd08 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 -- GitLab From ff1159fe17395185da4024857ce11b5d12209830 Mon Sep 17 00:00:00 2001 From: Philippe Wang Date: Mon, 15 May 2023 10:56:06 -0700 Subject: [PATCH 4/9] adaptive inflation: update docs --- CHANGES.rst | 3 +++ docs/protocols/alpha.rst | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index 342f2788dd0b..8ad628ec1e1f 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 7ca1ec26b0c9..5ac8f5ae28a5 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 ------------- -- GitLab From 3a477674e2b6f7edbb52c447aac5462d10467a37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Proust?= Date: Tue, 16 May 2023 17:54:36 +0200 Subject: [PATCH 5/9] Protocol: use compact encoding for toggle votes --- .../lib_protocol/block_header_repr.ml | 111 ++++++------------ .../lib_protocol/toggle_votes_repr.ml | 93 +++++++-------- 2 files changed, 79 insertions(+), 125 deletions(-) diff --git a/src/proto_alpha/lib_protocol/block_header_repr.ml b/src/proto_alpha/lib_protocol/block_header_repr.ml index 058e3eb3241e..052887258c55 100644 --- a/src/proto_alpha/lib_protocol/block_header_repr.ml +++ b/src/proto_alpha/lib_protocol/block_header_repr.ml @@ -69,83 +69,40 @@ let of_watermark = function let contents_encoding = let open Data_encoding in - 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_vote" - Toggle_votes_repr.adaptive_inflation_vote_encoding)) - and 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 + def "block_header.alpha.unsigned_contents" + @@ 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)) let protocol_data_encoding = let open Data_encoding in diff --git a/src/proto_alpha/lib_protocol/toggle_votes_repr.ml b/src/proto_alpha/lib_protocol/toggle_votes_repr.ml index f396b030d8fc..7425ed029b22 100644 --- a/src/proto_alpha/lib_protocol/toggle_votes_repr.ml +++ b/src/proto_alpha/lib_protocol/toggle_votes_repr.ml @@ -33,62 +33,59 @@ type toggle_votes = { adaptive_inflation_vote : toggle_vote; } -let toggle_vote_of_int2 = function - | 0 -> Ok Toggle_vote_on - | 1 -> Ok Toggle_vote_off - | 2 -> Ok Toggle_vote_pass - | _ -> Error "toggle_vote_of_int2" - -let toggle_vote_to_int2 = function - | Toggle_vote_on -> 0 - | Toggle_vote_off -> 1 - | Toggle_vote_pass -> 2 - -let toggle_vote_encoding name = +let toggle_vote_compact_encoding = let open Data_encoding in - (* union *) - def name - @@ splitted - ~binary:(conv_with_guard toggle_vote_to_int2 toggle_vote_of_int2 int8) - ~json: - (string_enum - [ - ("on", Toggle_vote_on); - ("off", Toggle_vote_off); - ("pass", Toggle_vote_pass); - ]) + 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 = - toggle_vote_encoding "liquidity_baking_vote" + let open Data_encoding in + def + "liquidity_baking_vote" + (Compact.make ~tag_size:`Uint8 toggle_vote_compact_encoding) let adaptive_inflation_vote_encoding = - toggle_vote_encoding "adaptive_inflation_vote" + 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 of_int8 i = - match (toggle_vote_of_int2 (i land 0b11), toggle_vote_of_int2 (i / 4)) with - | Ok liquidity_baking_vote, Ok adaptive_inflation_vote -> - Ok {liquidity_baking_vote; adaptive_inflation_vote} - | _ -> Error "toggle_votes_of_int8" - in - let to_int8 {liquidity_baking_vote; adaptive_inflation_vote} = - toggle_vote_to_int2 liquidity_baking_vote - + (toggle_vote_to_int2 adaptive_inflation_vote * 4) - in let open Data_encoding in - let json = - 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" liquidity_baking_vote_encoding) - (req "adaptive_inflation_vote" adaptive_inflation_vote_encoding)) - in - (* union *) - def "toggle_votes" - @@ splitted ~binary:(conv_with_guard to_int8 of_int8 int8) ~json + 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 = -- GitLab From a65197787ddd2cceef13dabbe8a8263ab35dc4ae Mon Sep 17 00:00:00 2001 From: Philippe Wang Date: Tue, 16 May 2023 12:47:36 -0700 Subject: [PATCH 6/9] Protocol: better encoding compatibility for json block headers re. toggle votes --- .../lib_protocol/block_header_repr.ml | 112 ++++++++++++------ 1 file changed, 78 insertions(+), 34 deletions(-) diff --git a/src/proto_alpha/lib_protocol/block_header_repr.ml b/src/proto_alpha/lib_protocol/block_header_repr.ml index 052887258c55..4f37fefa2327 100644 --- a/src/proto_alpha/lib_protocol/block_header_repr.ml +++ b/src/proto_alpha/lib_protocol/block_header_repr.ml @@ -69,40 +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; - 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)) + 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 -- GitLab From 7a67554298a5b956af28da94c113108e651b6d44 Mon Sep 17 00:00:00 2001 From: Philippe Wang Date: Wed, 24 May 2023 07:47:20 -0700 Subject: [PATCH 7/9] Adaptive inflation: fix typos --- .../lib_delegate/baking_commands.ml | 4 ++-- src/proto_alpha/lib_delegate/baking_events.ml | 2 +- .../lib_delegate/per_block_vote_file.ml | 24 +++++++++++-------- .../lib_delegate/per_block_vote_file.mli | 2 +- 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/proto_alpha/lib_delegate/baking_commands.ml b/src/proto_alpha/lib_delegate/baking_commands.ml index c0257de33bb0..9e7a44cc3a37 100644 --- a/src/proto_alpha/lib_delegate/baking_commands.ml +++ b/src/proto_alpha/lib_delegate/baking_commands.ml @@ -176,8 +176,8 @@ let adaptive_inflation_toggle_vote_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. Note that \ - this \"option\" is mandatory!" + \"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 diff --git a/src/proto_alpha/lib_delegate/baking_events.ml b/src/proto_alpha/lib_delegate/baking_events.ml index e564f0b31b4c..75f30e8e2122 100644 --- a/src/proto_alpha/lib_delegate/baking_events.ml +++ b/src/proto_alpha/lib_delegate/baking_events.ml @@ -803,7 +803,7 @@ module Actions = struct ~section ~name:"vote_for_adaptive_inflation_toggle" ~level:Notice - ~msg:"Voting {value} for liquidity baking toggle vote" + ~msg:"Voting {value} for adaptive inflation toggle vote" ( "value", Protocol.Alpha_context.Toggle_votes.adaptive_inflation_vote_encoding ) diff --git a/src/proto_alpha/lib_delegate/per_block_vote_file.ml b/src/proto_alpha/lib_delegate/per_block_vote_file.ml index 70fecd7313d9..53923bec30fd 100644 --- a/src/proto_alpha/lib_delegate/per_block_vote_file.ml +++ b/src/proto_alpha/lib_delegate/per_block_vote_file.ml @@ -58,7 +58,7 @@ type error += Block_vote_file_invalid of string type error += Block_vote_file_wrong_content of string -type error += Block_vote_file_missing_toggle_votes of string +type error += Block_vote_file_missing_liquidity_baking_toggle_vote of string type error += Missing_vote_on_startup @@ -115,7 +115,8 @@ let () = '{\"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\".@]" + \"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 @@ -123,13 +124,14 @@ let () = (fun file_path -> Block_vote_file_wrong_content file_path) ; register_error_kind `Permanent - ~id:"per_block_vote_file.block_vote_file_missing_toggle_votes" + ~id: + "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" ~description: "In the provided block vote file, no entry for liquidity baking toggle \ - vote weres found." + vote was found." ~pp:(fun ppf file_path -> Format.fprintf ppf @@ -145,13 +147,15 @@ let () = file_path) Data_encoding.(obj1 (req "file_path" string)) (function - | Block_vote_file_missing_toggle_votes file_path -> Some file_path + | Block_vote_file_missing_liquidity_baking_toggle_vote file_path -> + Some file_path | _ -> None) - (fun file_path -> Block_vote_file_missing_toggle_votes file_path) ; + (fun file_path -> + Block_vote_file_missing_liquidity_baking_toggle_vote file_path) ; register_error_kind `Permanent - ~id:"per_block_vote_file.missing_votes_on_startup" - ~title:"Missing votes on startup" + ~id:"per_block_vote_file.missing_vote_on_startup" + ~title:"Missing vote on startup" ~description: "No CLI flag, file path, or votes file in default location provided on \ startup" @@ -160,8 +164,8 @@ let () = fmt "Missing liquidity baking toggle vote, please use either the \ --liquidity-baking-toggle-vote option, or the --votefile option or a \ - vote file in the default location: per_block_votes.json in the \ - current working directory.") + 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) diff --git a/src/proto_alpha/lib_delegate/per_block_vote_file.mli b/src/proto_alpha/lib_delegate/per_block_vote_file.mli index 81d12888ebfe..e2832aa08a31 100644 --- a/src/proto_alpha/lib_delegate/per_block_vote_file.mli +++ b/src/proto_alpha/lib_delegate/per_block_vote_file.mli @@ -56,7 +56,7 @@ type error += Block_vote_file_invalid of string type error += Block_vote_file_wrong_content of string -type error += Block_vote_file_missing_toggle_votes of string +type error += Block_vote_file_missing_liquidity_baking_toggle_vote of string type error += Missing_vote_on_startup -- GitLab From f2b5de7486873407fcb1b2f2f37fbcaeb16bc4d2 Mon Sep 17 00:00:00 2001 From: Philippe Wang Date: Tue, 23 May 2023 10:52:44 -0700 Subject: [PATCH 8/9] Revert "Adaptive inflation: remove adaptive inflation toggle EMA from block metadata" This reverts commit 296a6db95a7b3b4e0dfdf71c332103200c290a5a. --- src/proto_alpha/lib_protocol/apply_results.ml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/proto_alpha/lib_protocol/apply_results.ml b/src/proto_alpha/lib_protocol/apply_results.ml index 80312f989cfa..fa860722de71 100644 --- a/src/proto_alpha/lib_protocol/apply_results.ml +++ b/src/proto_alpha/lib_protocol/apply_results.ml @@ -2515,7 +2515,7 @@ let block_metadata_encoding = deactivated; balance_updates; liquidity_baking_toggle_ema; - adaptive_inflation_toggle_ema = _; + adaptive_inflation_toggle_ema; implicit_operations_results; dal_attestation; } -> @@ -2527,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) )) @@ -2538,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, @@ -2553,12 +2555,12 @@ let block_metadata_encoding = deactivated; balance_updates; liquidity_baking_toggle_ema; - adaptive_inflation_toggle_ema = Toggle_EMA.zero; + 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) @@ -2567,6 +2569,7 @@ let block_metadata_encoding = (req "deactivated" (list Signature.Public_key_hash.encoding)) (dft "balance_updates" Receipt.balance_updates_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))) -- GitLab From 1d7b45b6a5a94a1b1e6c7565d95c3d60615ae417 Mon Sep 17 00:00:00 2001 From: Alain Mebsout Date: Thu, 25 May 2023 11:21:31 +0200 Subject: [PATCH 9/9] Test/tezt: fix rollup node migration test Make sure the rollup node for the previous protocol has processed the migration block. --- tezt/tests/sc_rollup.ml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tezt/tests/sc_rollup.ml b/tezt/tests/sc_rollup.ml index 146cef6ecef5..ae91b17dc01f 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"] -- GitLab