diff --git a/src/lib_store/test/alpha_utils.ml b/src/lib_store/test/alpha_utils.ml index 6369a58503c47fcefd89166aa203b2f64466de91..2688620ea2fd99d4d358cac16320d8aeaab1caad 100644 --- a/src/lib_store/test/alpha_utils.ml +++ b/src/lib_store/test/alpha_utils.ml @@ -253,15 +253,14 @@ 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) - ~seed_nonce_hash () = + ?(per_block_vote = Per_block_vote.default) ~seed_nonce_hash () = Block_header. { payload_hash; payload_round; proof_of_work_nonce; seed_nonce_hash; - liquidity_baking_toggle_vote; + per_block_vote; } let make_shell ~level ~predecessor ~timestamp ~fitness ~operations_hash diff --git a/src/proto_alpha/lib_client/mockup.ml b/src/proto_alpha/lib_client/mockup.ml index 61f6f776485495a0b1880390339038fe6dd172d5..46c150fff470b7322a9cc8b43a80f5394eed00ee 100644 --- a/src/proto_alpha/lib_client/mockup.ml +++ b/src/proto_alpha/lib_client/mockup.ml @@ -87,7 +87,6 @@ module Protocol_constants_overrides = struct min_proposal_quorum : int32 option; liquidity_baking_subsidy : Tez.t option; liquidity_baking_sunset_level : int32 option; - liquidity_baking_toggle_ema_threshold : int32 option; max_operations_time_to_live : int option; minimal_block_delay : Period.t option; delay_increment_per_round : Period.t option; @@ -251,7 +250,6 @@ module Protocol_constants_overrides = struct c.min_proposal_quorum, c.liquidity_baking_subsidy, c.liquidity_baking_sunset_level, - c.liquidity_baking_toggle_ema_threshold, c.max_operations_time_to_live, c.minimal_block_delay, c.delay_increment_per_round, @@ -290,7 +288,6 @@ module Protocol_constants_overrides = struct min_proposal_quorum, liquidity_baking_subsidy, liquidity_baking_sunset_level, - liquidity_baking_toggle_ema_threshold, max_operations_time_to_live, minimal_block_delay, delay_increment_per_round, @@ -330,7 +327,6 @@ module Protocol_constants_overrides = struct min_proposal_quorum; liquidity_baking_subsidy; liquidity_baking_sunset_level; - liquidity_baking_toggle_ema_threshold; max_operations_time_to_live; minimal_block_delay; delay_increment_per_round; @@ -373,12 +369,11 @@ module Protocol_constants_overrides = struct (opt "hard_storage_limit_per_operation" z) (opt "quorum_min" int32)) (merge_objs - (obj10 + (obj9 (opt "quorum_max" int32) (opt "min_proposal_quorum" int32) (opt "liquidity_baking_subsidy" Tez.encoding) (opt "liquidity_baking_sunset_level" int32) - (opt "liquidity_baking_toggle_ema_threshold" int32) (opt "max_operations_time_to_live" int16) (opt "minimal_block_delay" Period.encoding) (opt "delay_increment_per_round" Period.encoding) @@ -450,8 +445,6 @@ module Protocol_constants_overrides = struct liquidity_baking_subsidy = Some parametric.liquidity_baking_subsidy; liquidity_baking_sunset_level = Some parametric.liquidity_baking_sunset_level; - liquidity_baking_toggle_ema_threshold = - Some parametric.liquidity_baking_toggle_ema_threshold; max_operations_time_to_live = Some parametric.max_operations_time_to_live; minimal_block_delay = Some parametric.minimal_block_delay; @@ -545,7 +538,6 @@ module Protocol_constants_overrides = struct min_proposal_quorum = None; liquidity_baking_subsidy = None; liquidity_baking_sunset_level = None; - liquidity_baking_toggle_ema_threshold = None; max_operations_time_to_live = None; minimal_block_delay = None; delay_increment_per_round = None; @@ -744,12 +736,6 @@ module Protocol_constants_overrides = struct override_value = o.liquidity_baking_sunset_level; pp = pp_print_int32; }; - O - { - name = "liquidity_baking_toggle_ema_threshold"; - override_value = o.liquidity_baking_toggle_ema_threshold; - pp = pp_print_int32; - }; O { name = "minimal_block_delay"; @@ -970,10 +956,6 @@ module Protocol_constants_overrides = struct Option.value ~default:c.liquidity_baking_sunset_level o.liquidity_baking_sunset_level; - liquidity_baking_toggle_ema_threshold = - Option.value - ~default:c.liquidity_baking_toggle_ema_threshold - o.liquidity_baking_toggle_ema_threshold; max_operations_time_to_live = Option.value ~default:c.max_operations_time_to_live @@ -1529,8 +1511,7 @@ let mem_init : payload_hash; seed_nonce_hash = None; proof_of_work_nonce; - (* following Baking_configuration.toggle_votes in lib_delegate *) - liquidity_baking_toggle_vote = Liquidity_baking.LB_pass; + per_block_vote = Per_block_vote.default; } 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 81dfefc9f74b02bff03fdde1ef009eb296c2e954..902ba615f9a3c1a31ca38d6abd01295edf880f82 100644 --- a/src/proto_alpha/lib_delegate/baking_actions.ml +++ b/src/proto_alpha/lib_delegate/baking_actions.ml @@ -267,17 +267,10 @@ let inject_block ~state_recorder state block_to_bake ~updated_state = let user_activated_upgrades = state.global_state.config.user_activated_upgrades in - (* Set liquidity_baking_toggle_vote for this block *) - let default = state.global_state.config.liquidity_baking_toggle_vote in - (match state.global_state.config.per_block_vote_file with - | None -> Lwt.return default - | Some per_block_vote_file -> - Liquidity_baking_vote_file.read_liquidity_baking_toggle_vote_no_fail - ~default - ~per_block_vote_file) - >>= fun liquidity_baking_toggle_vote -> - Events.(emit vote_for_liquidity_baking_toggle) liquidity_baking_toggle_vote - >>= fun () -> + Per_block_vote_file.may_read_with_default + state.global_state.config.per_block_vote + state.global_state.config.per_block_vote_file + >>= fun per_block_vote -> Block_forge.forge cctxt ~chain_id @@ -285,7 +278,7 @@ let inject_block ~state_recorder state block_to_bake ~updated_state = ~timestamp ~seed_nonce_hash ~payload_round - ~liquidity_baking_toggle_vote + ~per_block_vote ~user_activated_upgrades state.global_state.config.fees simulation_mode diff --git a/src/proto_alpha/lib_delegate/baking_commands.ml b/src/proto_alpha/lib_delegate/baking_commands.ml index 78d6ec9e61a1bfcea816b01223c67e5e329f29b6..610576b19d0fd96c14a3b4ef6ba2144567608f98 100644 --- a/src/proto_alpha/lib_delegate/baking_commands.ml +++ b/src/proto_alpha/lib_delegate/baking_commands.ml @@ -141,27 +141,66 @@ let keep_alive_arg = ~long:"keep-alive" () -let liquidity_baking_toggle_vote_parameter = +let toggle_vote_parameter = Clic.parameter ~autocomplete:(fun _ctxt -> return ["on"; "off"; "pass"]) - (let open Protocol.Alpha_context.Liquidity_baking in + (let open Protocol.Alpha_context.Toggle_vote in fun _ctxt -> function - | "on" -> return LB_on - | "off" -> return LB_off - | "pass" -> return LB_pass + | "on" -> return On + | "off" -> return Off + | "pass" -> return Pass | s -> failwith "unexpected vote: %s, expected either \"on\", \"off\", or \"pass\"." s) -let liquidity_baking_toggle_vote_arg = +let per_block_vote_arg ?(mandatory = false) () = + let open Protocol.Alpha_context in + let open Toggle_vote.Name in + let to_name = function Liquidity_baking -> "liquidity baking" in + let to_option_name = function + | Liquidity_baking -> "liquidity-baking-toggle-vote" + in + let to_option_doc = function + | Liquidity_baking -> + "Vote to continue (option \"on\") or end (option \"off\") the \ + liquidity baking subsidy. Or choose to pass (option \"pass\")." + in + let rec generate arg = function + | [] -> arg + | name :: names -> + generate + (Clic.map_arg + ~f:(fun _ctx (vote, ballot) -> + match vote with + | Some vote -> + return (Per_block_vote.set_toggle_vote name ballot vote) + | None -> + if mandatory then + failwith + "Missing %s vote, please use the --%s option" + (to_name name) + (to_option_name name) + else return ballot) + (Clic.aggregate + (Clic.args2 + (Clic.arg + ~doc:(to_option_doc name) + ~long:(to_option_name name) + ~placeholder:"vote" + toggle_vote_parameter) + arg))) + names + in + generate (Clic.constant Per_block_vote.default) Toggle_vote.Name.all + +let per_block_vote_file_arg = Clic.arg - ~doc: - "Vote to continue (option \"on\") or end (option \"off\") the liquidity \ - baking subsidy. Or choose to pass (option \"pass\")." - ~long:"liquidity-baking-toggle-vote" - ~placeholder:"vote" - liquidity_baking_toggle_vote_parameter + ~doc:"read per block votes as json file" + ~short:'V' + ~long:"votefile" + ~placeholder:"filename" + (Clic.parameter (fun _ s -> return s)) let get_delegates (cctxt : Protocol_client_context.full) (pkhs : Signature.public_key_hash list) = @@ -213,7 +252,7 @@ let delegate_commands () : Protocol_client_context.full Clic.command list = command ~group ~desc:"Forge and inject block using the delegates' rights." - (args8 + (args10 minimal_fees_arg minimal_nanotez_per_gas_unit_arg minimal_nanotez_per_byte_arg @@ -221,7 +260,9 @@ let delegate_commands () : Protocol_client_context.full Clic.command list = force_switch operations_arg context_path_arg - do_not_monitor_node_mempool_arg) + do_not_monitor_node_mempool_arg + (per_block_vote_arg ()) + per_block_vote_file_arg) (prefixes ["bake"; "for"] @@ sources_param) (fun ( minimal_fees, minimal_nanotez_per_gas_unit, @@ -230,7 +271,9 @@ let delegate_commands () : Protocol_client_context.full Clic.command list = force, extra_operations, context_path, - do_not_monitor_node_mempool ) + do_not_monitor_node_mempool, + per_block_vote, + per_block_vote_file ) pkhs cctxt -> get_delegates cctxt pkhs >>=? fun delegates -> @@ -242,6 +285,8 @@ let delegate_commands () : Protocol_client_context.full Clic.command list = ~minimal_fees ~force ~monitor_node_mempool:(not do_not_monitor_node_mempool) + ~per_block_vote + ?per_block_vote_file ?extra_operations ?context_path delegates); @@ -301,14 +346,6 @@ let directory_parameter = failwith "Directory doesn't exist: '%s'" p else return p) -let per_block_vote_file_arg = - Clic.arg - ~doc:"read per block votes as json file" - ~short:'V' - ~long:"votefile" - ~placeholder:"filename" - (Clic.parameter (fun _ s -> return s)) - let baker_commands () : Protocol_client_context.full Clic.command list = let open Clic in let group = @@ -327,7 +364,7 @@ let baker_commands () : Protocol_client_context.full Clic.command list = minimal_nanotez_per_gas_unit_arg minimal_nanotez_per_byte_arg keep_alive_arg - liquidity_baking_toggle_vote_arg + (per_block_vote_arg ~mandatory:true ()) per_block_vote_file_arg operations_arg) (prefixes ["run"; "with"; "local"; "node"] @@ -341,19 +378,12 @@ let baker_commands () : Protocol_client_context.full Clic.command list = minimal_nanotez_per_gas_unit, minimal_nanotez_per_byte, keep_alive, - liquidity_baking_toggle_vote, + per_block_vote, per_block_vote_file, extra_operations ) node_data_path sources cctxt -> - (match liquidity_baking_toggle_vote with - | None -> - failwith - "Missing liquidity baking toggle vote, please use the \ - --liquidity-baking-toggle-vote option" - | Some vote -> return vote) - >>=? fun liquidity_baking_toggle_vote -> may_lock_pidfile pidfile @@ fun () -> get_delegates cctxt sources >>=? fun delegates -> let context_path = Filename.Infix.(node_data_path // "context") in @@ -362,7 +392,7 @@ let baker_commands () : Protocol_client_context.full Clic.command list = ~minimal_fees ~minimal_nanotez_per_gas_unit ~minimal_nanotez_per_byte - ~liquidity_baking_toggle_vote + ~per_block_vote ?per_block_vote_file ?extra_operations ~chain:cctxt#chain diff --git a/src/proto_alpha/lib_delegate/baking_configuration.ml b/src/proto_alpha/lib_delegate/baking_configuration.ml index d7b24e86ddc72ca562d14b86a2fe74a515742dca..028ad82f01506d850bc1d89e8f4de5fd28e72e34 100644 --- a/src/proto_alpha/lib_delegate/baking_configuration.ml +++ b/src/proto_alpha/lib_delegate/baking_configuration.ml @@ -82,8 +82,7 @@ type t = { validation : validation_config; retries_on_failure : int; user_activated_upgrades : (int32 * Protocol_hash.t) list; - liquidity_baking_toggle_vote : - Protocol.Alpha_context.Liquidity_baking.liquidity_baking_toggle_vote; + per_block_vote : Protocol.Alpha_context.Per_block_vote.t; per_block_vote_file : string option; force : bool; state_recorder : state_recorder_config; @@ -108,8 +107,7 @@ let default_retries_on_failure_config = 5 let default_user_activated_upgrades = [] -let default_liquidity_baking_toggle_vote = - Protocol.Alpha_context.Liquidity_baking.LB_pass +let default_per_block_vote = Protocol.Alpha_context.Per_block_vote.default let default_force = false @@ -126,7 +124,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_toggle_vote = default_liquidity_baking_toggle_vote; + per_block_vote = default_per_block_vote; force = default_force; state_recorder = default_state_recorder_config; extra_operations = default_extra_operations; @@ -140,9 +138,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_toggle_vote = default_liquidity_baking_toggle_vote) - ?per_block_vote_file ?(force = default_force) - ?(state_recorder = default_state_recorder_config) ?extra_operations () = + ?(per_block_vote = default_per_block_vote) ?per_block_vote_file + ?(force = default_force) ?(state_recorder = default_state_recorder_config) + ?extra_operations () = let fees = {minimal_fees; minimal_nanotez_per_gas_unit; minimal_nanotez_per_byte} in @@ -157,7 +155,7 @@ let make ?(minimal_fees = default_fees_config.minimal_fees) nonce; retries_on_failure; user_activated_upgrades; - liquidity_baking_toggle_vote; + per_block_vote; per_block_vote_file; force; state_recorder; @@ -223,8 +221,8 @@ let user_activate_upgrades_config_encoding = let open Data_encoding in list (tup2 int32 Protocol_hash.encoding) -let liquidity_baking_toggle_vote_config_encoding = - Protocol.Alpha_context.Liquidity_baking.liquidity_baking_toggle_vote_encoding +let per_block_vote_config_encoding = + Protocol.Alpha_context.Per_block_vote.dft_encoding let force_config_encoding = Data_encoding.bool @@ -260,57 +258,58 @@ let encoding : t Data_encoding.t = nonce; retries_on_failure; user_activated_upgrades; - liquidity_baking_toggle_vote; + per_block_vote; per_block_vote_file; force; state_recorder; extra_operations; } -> - ( fees, - validation, - nonce, - retries_on_failure, - user_activated_upgrades, - liquidity_baking_toggle_vote, - per_block_vote_file, - force, - state_recorder, - extra_operations )) - (fun ( fees, - validation, - nonce, - retries_on_failure, - user_activated_upgrades, - liquidity_baking_toggle_vote, - per_block_vote_file, - force, - state_recorder, - extra_operations ) -> + ( ( fees, + validation, + nonce, + retries_on_failure, + user_activated_upgrades, + per_block_vote_file, + force, + state_recorder, + extra_operations ), + per_block_vote )) + (fun ( ( fees, + validation, + nonce, + retries_on_failure, + user_activated_upgrades, + per_block_vote_file, + force, + state_recorder, + extra_operations ), + per_block_vote ) -> { fees; validation; nonce; retries_on_failure; user_activated_upgrades; - liquidity_baking_toggle_vote; + per_block_vote; per_block_vote_file; force; state_recorder; extra_operations; }) - (obj10 - (req "fees" fees_config_encoding) - (req "validation" validation_config_encoding) - (req "nonce" nonce_config_encoding) - (req "retries_on_failure" retries_on_failure_config_encoding) - (req "user_activated_upgrades" user_activate_upgrades_config_encoding) - (req - "liquidity_baking_toggle_vote" - liquidity_baking_toggle_vote_config_encoding) - (opt "per_block_vote_file" Data_encoding.string) - (req "force" force_config_encoding) - (req "state_recorder" state_recorder_config_encoding) - (opt "extra_operations" Operations_source.encoding)) + (merge_objs + (obj9 + (req "fees" fees_config_encoding) + (req "validation" validation_config_encoding) + (req "nonce" nonce_config_encoding) + (req "retries_on_failure" retries_on_failure_config_encoding) + (req + "user_activated_upgrades" + user_activate_upgrades_config_encoding) + (opt "per_block_vote_file" Data_encoding.string) + (req "force" force_config_encoding) + (req "state_recorder" state_recorder_config_encoding) + (opt "extra_operations" Operations_source.encoding)) + per_block_vote_config_encoding) let pp fmt t = let json = Data_encoding.Json.construct encoding t in diff --git a/src/proto_alpha/lib_delegate/baking_configuration.mli b/src/proto_alpha/lib_delegate/baking_configuration.mli index bb90f6f5cf4a9cc180d12585699632d11da8db28..62f9368abb8b249b54acf22403b241576e33b68e 100644 --- a/src/proto_alpha/lib_delegate/baking_configuration.mli +++ b/src/proto_alpha/lib_delegate/baking_configuration.mli @@ -22,6 +22,9 @@ (* DEALINGS IN THE SOFTWARE. *) (* *) (*****************************************************************************) + +open Protocol.Alpha_context + (** {1 Operations_source abstraction} *) module Operations_source : sig type t = @@ -37,7 +40,7 @@ module Operations_source : sig end type fees_config = { - minimal_fees : Protocol.Alpha_context.Tez.t; + minimal_fees : Tez.t; minimal_nanotez_per_gas_unit : Q.t; minimal_nanotez_per_byte : Q.t; } @@ -57,8 +60,7 @@ type t = { validation : validation_config; retries_on_failure : int; user_activated_upgrades : (int32 * Protocol_hash.t) list; - liquidity_baking_toggle_vote : - Protocol.Alpha_context.Liquidity_baking.liquidity_baking_toggle_vote; + per_block_vote : Per_block_vote.t; per_block_vote_file : string option; force : bool; state_recorder : state_recorder_config; @@ -75,8 +77,7 @@ val default_retries_on_failure_config : int val default_user_activated_upgrades : (int32 * Protocol_hash.t) list -val default_liquidity_baking_toggle_vote : - Protocol.Alpha_context.Liquidity_baking.liquidity_baking_toggle_vote +val default_per_block_vote : Per_block_vote.t val default_force : bool @@ -89,15 +90,14 @@ val default_per_block_vote_file : string option val default_config : t val make : - ?minimal_fees:Protocol.Alpha_context.Tez.t -> + ?minimal_fees:Tez.t -> ?minimal_nanotez_per_gas_unit:Q.t -> ?minimal_nanotez_per_byte:Q.t -> ?nonce:nonce_config -> ?context_path:string -> ?retries_on_failure:int -> ?user_activated_upgrades:(int32 * Protocol_hash.t) list -> - ?liquidity_baking_toggle_vote: - Protocol.Alpha_context.Liquidity_baking.liquidity_baking_toggle_vote -> + ?per_block_vote:Per_block_vote.t -> ?per_block_vote_file:string -> ?force:bool -> ?state_recorder:state_recorder_config -> @@ -116,9 +116,7 @@ val retries_on_failure_config_encoding : int Data_encoding.t 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 +val per_block_vote_config_encoding : Per_block_vote.t 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 d0e2f9a35f2eb7e10fe323969f710a69fea90a74..15bccd0083b5ce4b728db182fdbec7c19b82136c 100644 --- a/src/proto_alpha/lib_delegate/baking_events.ml +++ b/src/proto_alpha/lib_delegate/baking_events.ml @@ -655,16 +655,6 @@ module Actions = struct ~level:Error ~msg:"cannot fetch operations: {errs}" ("errs", Error_monad.(TzTrace.encoding error_encoding)) - - let vote_for_liquidity_baking_toggle = - declare_1 - ~section - ~name:"vote_for_liquidity_baking_toggle" - ~level:Notice - ~msg:"Voting {value} for liquidity baking toggle vote" - ( "value", - Protocol.Alpha_context.Liquidity_baking - .liquidity_baking_toggle_vote_encoding ) end module Nonces = struct @@ -792,7 +782,7 @@ module Nonces = struct () end -module Liquidity_baking = struct +module Block_vote = struct include Internal_event.Simple let reading_per_block = @@ -811,24 +801,6 @@ module Liquidity_baking = struct ~msg:"per block vote file {event}" ("event", Data_encoding.string) - let reading_liquidity_baking = - declare_0 - ~section - ~name:"reading_liquidity_baking" - ~level:Notice - ~msg:"reading liquidity baking toggle vote" - () - - let liquidity_baking_toggle_vote = - declare_1 - ~section - ~name:"liquidity_baking_toggle_vote" - ~level:Notice - ~msg:"liquidity baking toggle vote = {value}" - ( "value", - Protocol.Alpha_context.Liquidity_baking - .liquidity_baking_toggle_vote_encoding ) - let per_block_vote_file_fail = declare_1 ~section @@ -838,6 +810,29 @@ module Liquidity_baking = struct ~pp1:pp_print_top_error_of_trace ("errors", Error_monad.(TzTrace.encoding error_encoding)) + let using_default_vote = + declare_2 + ~section + ~name:"per_block_vote_default" + ~level:Notice + ~msg:"Voting {vote} for {name} toggle vote" + ("vote", Toggle_vote.encoding) + ("name", Toggle_vote.Name.encoding) + + let using_file_vote = + declare_3 + ~section + ~name:"per_block_vote_file" + ~level:Notice + ~msg:"Voting {vote} for {name} toggle vote (file vote over {default})" + ("vote", Toggle_vote.encoding) + ("default", Toggle_vote.encoding) + ("name", Toggle_vote.Name.encoding) +end + +module Liquidity_baking = struct + include Internal_event.Simple + let liquidity_baking_off = declare_0 ~section diff --git a/src/proto_alpha/lib_delegate/baking_lib.ml b/src/proto_alpha/lib_delegate/baking_lib.ml index 7ef044310a5fcdecef62b38675193170a21d0c21..d2f6eb6c42e25879b4db6015b415f337c2550736 100644 --- a/src/proto_alpha/lib_delegate/baking_lib.ml +++ b/src/proto_alpha/lib_delegate/baking_lib.ml @@ -503,7 +503,8 @@ let baking_minimal_timestamp state = let bake (cctxt : Protocol_client_context.full) ?minimal_fees ?minimal_nanotez_per_gas_unit ?minimal_nanotez_per_byte ?force ?(minimal_timestamp = false) ?extra_operations - ?(monitor_node_mempool = true) ?context_path delegates = + ?(monitor_node_mempool = true) ?per_block_vote ?per_block_vote_file + ?context_path delegates = let open Lwt_result_syntax in let config = Baking_configuration.make @@ -513,6 +514,8 @@ let bake (cctxt : Protocol_client_context.full) ?minimal_fees ?context_path ?force ?extra_operations + ?per_block_vote + ?per_block_vote_file () in let* block_stream, current_proposal = get_current_proposal cctxt in diff --git a/src/proto_alpha/lib_delegate/baking_lib.mli b/src/proto_alpha/lib_delegate/baking_lib.mli index 547822f25d1a878ea38f1216f02d18923b8e31f7..75c960ea2ebd17f57e4f9a5262e8832bac8fb38a 100644 --- a/src/proto_alpha/lib_delegate/baking_lib.mli +++ b/src/proto_alpha/lib_delegate/baking_lib.mli @@ -36,6 +36,8 @@ val bake : ?minimal_timestamp:bool -> ?extra_operations:Baking_configuration.Operations_source.t -> ?monitor_node_mempool:bool -> + ?per_block_vote:Per_block_vote.t -> + ?per_block_vote_file:string -> ?context_path:string -> Baking_state.delegate list -> unit tzresult Lwt.t diff --git a/src/proto_alpha/lib_delegate/block_forge.ml b/src/proto_alpha/lib_delegate/block_forge.ml index 8efc10394526b8dc3f969c616d90c8a14978e375..6c20edc911d1d81680ff339f09e04ab6573dd89f 100644 --- a/src/proto_alpha/lib_delegate/block_forge.ml +++ b/src/proto_alpha/lib_delegate/block_forge.ml @@ -41,7 +41,7 @@ type simulation_kind = type simulation_mode = Local of Context.index | Node 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 ~per_block_vote () = Block_header. { contents = @@ -50,7 +50,7 @@ let forge_faked_protocol_data ?(payload_hash = Block_payload_hash.zero) payload_round; seed_nonce_hash; proof_of_work_nonce = Baking_pow.empty_proof_of_work_nonce; - liquidity_baking_toggle_vote; + per_block_vote; }; signature = Signature.zero; } @@ -116,9 +116,8 @@ let retain_live_operations_only ~live_blocks operation_pool = operation_pool let forge (cctxt : #Protocol_client_context.full) ~chain_id ~pred_info - ~timestamp ~liquidity_baking_toggle_vote ~user_activated_upgrades - fees_config ~seed_nonce_hash ~payload_round simulation_mode simulation_kind - constants = + ~timestamp ~per_block_vote ~user_activated_upgrades fees_config + ~seed_nonce_hash ~payload_round simulation_mode simulation_kind constants = let predecessor_block = (pred_info : Baking_state.block_info) in let hard_gas_limit_per_block = constants.Constants.Parametric.hard_gas_limit_per_block @@ -149,7 +148,7 @@ let forge (cctxt : #Protocol_client_context.full) ~chain_id ~pred_info forge_faked_protocol_data ~payload_round ~seed_nonce_hash - ~liquidity_baking_toggle_vote + ~per_block_vote () in Node_rpc.preapply_block @@ -182,7 +181,7 @@ let forge (cctxt : #Protocol_client_context.full) ~chain_id ~pred_info forge_faked_protocol_data ~payload_round ~seed_nonce_hash - ~liquidity_baking_toggle_vote + ~per_block_vote () in Baking_simulator.begin_construction @@ -256,7 +255,7 @@ let forge (cctxt : #Protocol_client_context.full) ~chain_id ~pred_info let faked_protocol_data = forge_faked_protocol_data ~seed_nonce_hash - ~liquidity_baking_toggle_vote + ~per_block_vote ~payload_hash ~payload_round () @@ -276,7 +275,7 @@ let forge (cctxt : #Protocol_client_context.full) ~chain_id ~pred_info let faked_protocol_data = forge_faked_protocol_data ~seed_nonce_hash - ~liquidity_baking_toggle_vote + ~per_block_vote ~payload_hash ~payload_round () @@ -378,7 +377,7 @@ let forge (cctxt : #Protocol_client_context.full) ~chain_id ~pred_info payload_round; seed_nonce_hash; proof_of_work_nonce; - liquidity_baking_toggle_vote; + per_block_vote; }) >>=? fun contents -> 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 b111e27b417c4a67c69c1b2160ee019ae9620e34..22912cf008637e4d843c4c1ca8acd6744c984d5d 100644 --- a/src/proto_alpha/lib_delegate/block_forge.mli +++ b/src/proto_alpha/lib_delegate/block_forge.mli @@ -44,7 +44,7 @@ val forge_faked_protocol_data : ?payload_hash:Block_payload_hash.t -> payload_round:Round.t -> seed_nonce_hash:Nonce_hash.t option -> - liquidity_baking_toggle_vote:Liquidity_baking.liquidity_baking_toggle_vote -> + per_block_vote:Per_block_vote.t -> unit -> block_header_data @@ -53,7 +53,7 @@ val forge : chain_id:Chain_id.t -> pred_info:Baking_state.block_info -> timestamp:Time.Protocol.t -> - liquidity_baking_toggle_vote:Liquidity_baking.liquidity_baking_toggle_vote -> + per_block_vote:Per_block_vote.t -> user_activated_upgrades:User_activated.upgrades -> Baking_configuration.fees_config -> seed_nonce_hash:Nonce_hash.t option -> diff --git a/src/proto_alpha/lib_delegate/client_daemon.ml b/src/proto_alpha/lib_delegate/client_daemon.ml index cb5d92e4b6bc8f7b9922039a3fdcd4e5884320e1..89a8e4189d83bf9b2bd6c030a53815e99454b006 100644 --- a/src/proto_alpha/lib_delegate/client_daemon.ml +++ b/src/proto_alpha/lib_delegate/client_daemon.ml @@ -68,9 +68,9 @@ let rec retry_on_disconnection (cctxt : #Protocol_client_context.full) f = module Baker = struct let run (cctxt : Protocol_client_context.full) ?minimal_fees - ?minimal_nanotez_per_gas_unit ?minimal_nanotez_per_byte - ~liquidity_baking_toggle_vote ?per_block_vote_file ?extra_operations - ~chain ~context_path ~keep_alive delegates = + ?minimal_nanotez_per_gas_unit ?minimal_nanotez_per_byte ~per_block_vote + ?per_block_vote_file ?extra_operations ~chain ~context_path ~keep_alive + delegates = let process () = Config_services.user_activated_upgrades cctxt >>=? fun user_activated_upgrades -> @@ -79,7 +79,7 @@ module Baker = struct ?minimal_fees ?minimal_nanotez_per_gas_unit ?minimal_nanotez_per_byte - ~liquidity_baking_toggle_vote + ~per_block_vote ?per_block_vote_file ?extra_operations ~context_path diff --git a/src/proto_alpha/lib_delegate/client_daemon.mli b/src/proto_alpha/lib_delegate/client_daemon.mli index 0e6f799861058fffabcd8e5f5cdca36a0ad0e9e9..628a9919e96d86b0f65e9d84b58a6e68d94059be 100644 --- a/src/proto_alpha/lib_delegate/client_daemon.mli +++ b/src/proto_alpha/lib_delegate/client_daemon.mli @@ -32,8 +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_toggle_vote: - Protocol.Alpha_context.Liquidity_baking.liquidity_baking_toggle_vote -> + per_block_vote:Protocol.Alpha_context.Per_block_vote.t -> ?per_block_vote_file:string -> ?extra_operations:Baking_configuration.Operations_source.t -> chain:Shell_services.chain -> diff --git a/src/proto_alpha/lib_delegate/liquidity_baking_vote_file.ml b/src/proto_alpha/lib_delegate/liquidity_baking_vote_file.ml deleted file mode 100644 index da49a169c1b0d273580c47b399b4757d76534f9e..0000000000000000000000000000000000000000 --- a/src/proto_alpha/lib_delegate/liquidity_baking_vote_file.ml +++ /dev/null @@ -1,171 +0,0 @@ -(*****************************************************************************) -(* *) -(* Open Source License *) -(* Copyright (c) 2021 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. *) -(* *) -(*****************************************************************************) - -open Protocol_client_context -module Events = Baking_events.Liquidity_baking - -type per_block_votes = { - liquidity_baking_toggle_vote : - Protocol.Alpha_context.Liquidity_baking.liquidity_baking_toggle_vote option; -} - -let per_block_votes_encoding = - let open Data_encoding in - def "per_block_votes.alpha" - @@ conv - (fun {liquidity_baking_toggle_vote} -> liquidity_baking_toggle_vote) - (fun liquidity_baking_toggle_vote -> {liquidity_baking_toggle_vote}) - (obj1 - (opt - "liquidity_baking_toggle_vote" - Protocol.Alpha_context.Liquidity_baking - .liquidity_baking_toggle_vote_encoding)) - -type error += Block_vote_file_not_found of string - -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 - -let () = - register_error_kind - `Permanent - ~id:"Client_baking_forge.block_vote_file_not_found" - ~title: - "The provided block vote file path does not point to an existing file." - ~description: - "A block vote file path was provided on the command line but the path \ - does not point to an existing file." - ~pp:(fun ppf file_path -> - Format.fprintf - ppf - "@[The provided block vote file path \"%s\" does not point to an \ - existing file.@]" - file_path) - Data_encoding.(obj1 (req "file_path" string)) - (function - | Block_vote_file_not_found file_path -> Some file_path | _ -> None) - (fun file_path -> Block_vote_file_not_found file_path) ; - register_error_kind - `Permanent - ~id:"Client_baking_forge.block_vote_file_invalid" - ~title: - "The provided block vote file path does not point to a valid JSON file." - ~description: - "A block vote file path was provided on the command line but the path \ - does not point to a valid JSON file." - ~pp:(fun ppf file_path -> - Format.fprintf - ppf - "@[The provided block vote file path \"%s\" does not point to a valid \ - JSON file. The file exists but its content is not valid JSON.@]" - file_path) - Data_encoding.(obj1 (req "file_path" string)) - (function Block_vote_file_invalid file_path -> Some file_path | _ -> None) - (fun file_path -> Block_vote_file_invalid file_path) ; - register_error_kind - `Permanent - ~id:"Client_baking_forge.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 \ - one." - ~pp:(fun ppf file_path -> - 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\"}'.@]" - file_path) - Data_encoding.(obj1 (req "file_path" string)) - (function - | Block_vote_file_wrong_content file_path -> Some file_path | _ -> None) - (fun file_path -> Block_vote_file_wrong_content file_path) ; - register_error_kind - `Permanent - ~id: - "Client_baking_forge.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 was 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\"}'.@]" - file_path) - Data_encoding.(obj1 (req "file_path" string)) - (function - | Block_vote_file_missing_liquidity_baking_toggle_vote file_path -> - Some file_path - | _ -> None) - (fun file_path -> - Block_vote_file_missing_liquidity_baking_toggle_vote file_path) - -let traced_option_to_result ~error = - Option.fold ~some:ok ~none:(Result_syntax.tzfail error) - -let check_file_exists file = - if Sys.file_exists file then Result.return_unit - else error (Block_vote_file_not_found file) - -let read_liquidity_baking_toggle_vote ~per_block_vote_file = - Events.(emit reading_per_block) per_block_vote_file >>= fun () -> - check_file_exists per_block_vote_file >>?= fun () -> - trace (Block_vote_file_invalid per_block_vote_file) - @@ Lwt_utils_unix.Json.read_file per_block_vote_file - >>=? fun votes_json -> - Events.(emit per_block_vote_file_notice) "found" >>= fun () -> - trace (Block_vote_file_wrong_content per_block_vote_file) - @@ Error_monad.protect (fun () -> - return - @@ Data_encoding.Json.destruct per_block_votes_encoding votes_json) - >>=? fun votes -> - Events.(emit per_block_vote_file_notice) "JSON decoded" >>= fun () -> - traced_option_to_result - ~error: - (Block_vote_file_missing_liquidity_baking_toggle_vote per_block_vote_file) - votes.liquidity_baking_toggle_vote - >>?= fun liquidity_baking_toggle_vote -> - Events.(emit reading_liquidity_baking) () >>= fun () -> - Events.(emit liquidity_baking_toggle_vote) liquidity_baking_toggle_vote - >>= fun () -> return liquidity_baking_toggle_vote - -let read_liquidity_baking_toggle_vote_no_fail ~default ~per_block_vote_file = - read_liquidity_baking_toggle_vote ~per_block_vote_file >>= function - | Ok vote -> Lwt.return vote - | Error errs -> - Events.(emit per_block_vote_file_fail) errs >>= fun () -> - Lwt.return default diff --git a/src/proto_alpha/lib_delegate/per_block_vote_file.ml b/src/proto_alpha/lib_delegate/per_block_vote_file.ml new file mode 100644 index 0000000000000000000000000000000000000000..61460084b7255fd09ddd36da980e11b01c89dd12 --- /dev/null +++ b/src/proto_alpha/lib_delegate/per_block_vote_file.ml @@ -0,0 +1,160 @@ +(*****************************************************************************) +(* *) +(* Open Source License *) +(* Copyright (c) 2021 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. *) +(* *) +(*****************************************************************************) + +open Protocol.Alpha_context +module Events = Baking_events.Block_vote + +type error += + | Not_found of string + | Malformed_json of string + | Unexpected_content of string + +let () = + register_error_kind + `Permanent + ~id:"toggle_vote_file.not_found" + ~title: + "The provided block toggle vote file path does not point to an existing \ + file." + ~description: + "A toggle vote file path was provided on the command line but the path \ + does not point to an existing file." + ~pp:(fun ppf file_path -> + Format.fprintf + ppf + "The provided block vote file path \"%s\" does not point to an \ + existing file." + file_path) + Data_encoding.(obj1 (req "file_path" string)) + (function Not_found file_path -> Some file_path | _ -> None) + (fun file_path -> Not_found file_path) ; + register_error_kind + `Permanent + ~id:"toggle_vote_file.malformed_json" + ~title: + "The provided block vote file path does not point to a valid JSON file." + ~description: + "A block vote file path was provided on the command line but the path \ + does not point to a valid JSON file." + ~pp:(fun ppf file_path -> + Format.fprintf + ppf + "The provided block vote file path \"%s\" does not point to a valid \ + JSON file. The file exists but its content is not valid JSON." + file_path) + Data_encoding.(obj1 (req "file_path" string)) + (function Malformed_json file_path -> Some file_path | _ -> None) + (fun file_path -> Malformed_json file_path) ; + register_error_kind + `Permanent + ~id:"toggle_vote_file.unexpected_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 \ + one." + ~pp:(fun ppf file_path -> + 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\"}'.@]" + file_path) + Data_encoding.(obj1 (req "file_path" string)) + (function Unexpected_content file_path -> Some file_path | _ -> None) + (fun file_path -> Unexpected_content file_path) + +type t = {liquidity_baking : Toggle_vote.t option} + +let encoding = + let open Data_encoding in + conv + (fun {liquidity_baking} -> liquidity_baking) + (fun liquidity_baking -> {liquidity_baking}) + (obj1 (opt "liquidity_baking_toggle_vote" Toggle_vote.encoding)) + +let check_file_exists file = + if Sys.file_exists file then Result.return_unit else error (Not_found file) + +let read file = + let open Lwt_result_syntax in + let*! () = Events.(emit reading_per_block) file in + let*? () = check_file_exists file in + let* votes_json = + trace (Malformed_json file) @@ Lwt_utils_unix.Json.read_file file + in + let*! () = Events.(emit per_block_vote_file_notice) "found" in + let* votes = + trace (Unexpected_content file) + @@ Error_monad.protect (fun () -> + return @@ Data_encoding.Json.destruct encoding votes_json) + in + let*! () = Events.(emit per_block_vote_file_notice) "JSON decoded" in + return votes + +let merge_vote default file name = + let open Lwt_result_syntax in + match file with + | Some v -> + let*! () = Events.(emit using_file_vote (v, default, name)) in + Lwt.return v + | None -> + let*! () = Events.(emit using_default_vote (default, name)) in + Lwt.return default + +let merge (default : Per_block_vote.t) (vote : t) = + let open Lwt_result_syntax in + let*! liquidity_baking = + merge_vote default.liquidity_baking vote.liquidity_baking Liquidity_baking + in + Lwt.return {Per_block_vote.liquidity_baking} + +let emit_default_vote default = + List.iter_s + (fun name -> + Events.( + emit + using_default_vote + (Per_block_vote.get_toggle_vote name default, name))) + Toggle_vote.Name.all + +let read_with_default default file = + let open Lwt_result_syntax in + let*! content = read file in + match content with + | Ok vote -> merge default vote + | Error errs -> + let*! () = Events.(emit per_block_vote_file_fail) errs in + let*! () = emit_default_vote default in + Lwt.return default + +let may_read_with_default default file = + let open Lwt_result_syntax in + match file with + | None -> + let*! () = emit_default_vote default in + Lwt.return default + | Some file -> read_with_default default file diff --git a/src/proto_alpha/lib_delegate/per_block_vote_file.mli b/src/proto_alpha/lib_delegate/per_block_vote_file.mli new file mode 100644 index 0000000000000000000000000000000000000000..2c381d5cac4a48923d09231c296f0d86a4942887 --- /dev/null +++ b/src/proto_alpha/lib_delegate/per_block_vote_file.mli @@ -0,0 +1,40 @@ +(*****************************************************************************) +(* *) +(* Open Source License *) +(* Copyright (c) 2021 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. *) +(* *) +(*****************************************************************************) + +open Protocol.Alpha_context + +val read_with_default : Per_block_vote.t -> string -> Per_block_vote.t Lwt.t + +val may_read_with_default : + Per_block_vote.t -> string option -> Per_block_vote.t Lwt.t + +type error += + | Not_found of string + | Malformed_json of string + | Unexpected_content of string + +type t = {liquidity_baking : Toggle_vote.t option} + +val read : string -> t tzresult Lwt.t diff --git a/src/proto_alpha/lib_delegate/test/mockup_simulator/mockup_simulator.ml b/src/proto_alpha/lib_delegate/test/mockup_simulator/mockup_simulator.ml index 5194f4dd2cea398ab182799710190069b2c3b4a4..281e714865e88dae0531c8e3a931f9df89e5a20b 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 @@ -823,8 +823,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_toggle_vote; + per_block_vote = Baking_configuration.default_per_block_vote; } in let unsigned_header = diff --git a/src/proto_alpha/lib_parameters/default_parameters.ml b/src/proto_alpha/lib_parameters/default_parameters.ml index 36ce5101dabd3ef1655cf1e7811862c4c16bd3ff..9981d06f738e2afcd807557a408296677d16f5cb 100644 --- a/src/proto_alpha/lib_parameters/default_parameters.ml +++ b/src/proto_alpha/lib_parameters/default_parameters.ml @@ -99,9 +99,6 @@ let constants_mainnet = (* level after protocol activation when liquidity baking shuts off: about 6 months after first activation on mainnet *) liquidity_baking_sunset_level = 3_063_809l; - (* 1/2 window size of 2000 blocks with precision of 1_000_000 - for integer computation *) - liquidity_baking_toggle_ema_threshold = 1_000_000_000l; (* The rationale behind the value of this constant is that an operation should be considered alive for about one hour: diff --git a/src/proto_alpha/lib_plugin/RPC.ml b/src/proto_alpha/lib_plugin/RPC.ml index 03c8f89a1e060228cb8c52c898d4498805b033cf..ab9146a193a250cdf901babfd8cfc87f75772122 100644 --- a/src/proto_alpha/lib_plugin/RPC.ml +++ b/src/proto_alpha/lib_plugin/RPC.ml @@ -1972,19 +1972,17 @@ module Forge = struct ~description:"Forge the protocol-specific part of a block header" ~query:RPC_query.empty ~input: - (obj5 - (req "payload_hash" Block_payload_hash.encoding) - (req "payload_round" Round.encoding) - (opt "nonce_hash" Nonce_hash.encoding) - (dft - "proof_of_work_nonce" - (Fixed.bytes Alpha_context.Constants.proof_of_work_nonce_size) - empty_proof_of_work_nonce) - Liquidity_baking.( - dft - "liquidity_baking_toggle_vote" - liquidity_baking_toggle_vote_encoding - LB_pass)) + (merge_objs + (obj4 + (req "payload_hash" Block_payload_hash.encoding) + (req "payload_round" Round.encoding) + (opt "nonce_hash" Nonce_hash.encoding) + (dft + "proof_of_work_nonce" + (Fixed.bytes + Alpha_context.Constants.proof_of_work_nonce_size) + empty_proof_of_work_nonce)) + Per_block_vote.dft_encoding) ~output:(obj1 (req "protocol_data" bytes)) RPC_path.(path / "protocol_data") @@ -2096,11 +2094,8 @@ module Forge = struct S.protocol_data (fun () - ( payload_hash, - payload_round, - seed_nonce_hash, - proof_of_work_nonce, - liquidity_baking_toggle_vote ) + ( (payload_hash, payload_round, seed_nonce_hash, proof_of_work_nonce), + per_block_vote ) -> return (Data_encoding.Binary.to_bytes_exn @@ -2110,7 +2105,7 @@ module Forge = struct payload_round; seed_nonce_hash; proof_of_work_nonce; - liquidity_baking_toggle_vote; + per_block_vote; })) ; Registration.register0_noctxt ~chunked:true @@ -2283,18 +2278,14 @@ 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 () = + ?(proof_of_work_nonce = empty_proof_of_work_nonce) ~per_block_vote () = RPC_context.make_call0 S.protocol_data ctxt block () - ( payload_hash, - payload_round, - seed_nonce_hash, - proof_of_work_nonce, - liquidity_baking_toggle_vote ) + ( (payload_hash, payload_round, seed_nonce_hash, proof_of_work_nonce), + per_block_vote ) end module Parse = struct diff --git a/src/proto_alpha/lib_protocol/TEZOS_PROTOCOL b/src/proto_alpha/lib_protocol/TEZOS_PROTOCOL index f0e49e3602fb101e51963b777b2cf84ea6cb257d..5b7b61c7c420012e2b2954d1381e59d7448b6483 100644 --- a/src/proto_alpha/lib_protocol/TEZOS_PROTOCOL +++ b/src/proto_alpha/lib_protocol/TEZOS_PROTOCOL @@ -28,6 +28,10 @@ "Fixed_point_repr", "Saturation_repr", "Gas_limit_repr", + "Toggle_vote_name_repr", + "Toggle_vote_repr", + "Toggle_vote_ema_repr", + "Per_block_vote_repr", "Constants_parametric_repr", "Constants_parametric_previous_repr", "Constants_repr", @@ -81,7 +85,6 @@ "Bond_id_repr", "Vote_repr", - "Liquidity_baking_repr", "Block_header_repr", "Destination_repr", "Operation_repr", @@ -127,6 +130,7 @@ "Bootstrap_storage", "Vote_storage", + "Per_block_vote_storage", "Fees_storage", "Ticket_storage", "Liquidity_baking_storage", diff --git a/src/proto_alpha/lib_protocol/alpha_context.ml b/src/proto_alpha/lib_protocol/alpha_context.ml index f1e852c2f6ee467715a1ba344823b7a02742db10..de5e69f13078ac478714cc6c0de0f9603c3661b9 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.ml +++ b/src/proto_alpha/lib_protocol/alpha_context.ml @@ -123,6 +123,17 @@ module Vote = struct include Vote_storage end +module Toggle_vote = struct + module Name = Toggle_vote_name_repr + module Ema = Toggle_vote_ema_repr + include Toggle_vote_repr +end + +module Per_block_vote = struct + include Per_block_vote_repr + include Per_block_vote_storage +end + module Block_payload = struct include Block_payload_repr end @@ -554,7 +565,6 @@ let description = Raw_context.description module Parameters = Parameters_repr module Liquidity_baking = struct - include Liquidity_baking_repr include Liquidity_baking_storage end diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index e246db86a4fd878c70ea338282fe0b20878d3c5d..573564905646b84696ba82f7e3dd5af7c9e41099 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -713,6 +713,64 @@ module Script : sig val strip_annotations : node -> node end +module Toggle_vote : sig + module Name : sig + type t = Liquidity_baking + + val pp : Format.formatter -> t -> unit + + val encoding : t Data_encoding.t + + val all : t list + end + + module Ema : sig + include BASIC_DATA + + val pp : Format.formatter -> t -> unit + + val encoding : t Data_encoding.t + + val min_value : t + + val max_value : t + + module Internal_for_tests : sig + val to_int32 : t -> Int32.t + end + end + + type t = On | Off | Pass + + val pp : Format.formatter -> t -> unit + + val encoding : t Data_encoding.t +end + +module Per_block_vote : sig + type t = {liquidity_baking : Toggle_vote.t} + + val encoding : t Data_encoding.t + + val dft_encoding : t Data_encoding.t + + val default : t + + val get_toggle_vote : Toggle_vote.Name.t -> t -> Toggle_vote.t + + val set_toggle_vote : Toggle_vote.Name.t -> t -> Toggle_vote.t -> t + + module State : sig + type t = {liquidity_baking : Toggle_vote.Ema.t} + + val encoding : t Data_encoding.t + + val initial : t + end + + val update : context -> t -> (context * State.t) tzresult Lwt.t +end + module Constants : sig (** Fixed constants *) type fixed @@ -795,7 +853,6 @@ module Constants : sig min_proposal_quorum : int32; liquidity_baking_subsidy : Tez.t; liquidity_baking_sunset_level : int32; - liquidity_baking_toggle_ema_threshold : int32; max_operations_time_to_live : int; minimal_block_delay : Period.t; delay_increment_per_round : Period.t; @@ -878,8 +935,6 @@ module Constants : sig val liquidity_baking_sunset_level : context -> int32 - val liquidity_baking_toggle_ema_threshold : context -> int32 - val minimal_block_delay : context -> Period.t val delay_increment_per_round : context -> Period.t @@ -3136,8 +3191,7 @@ module Block_header : sig payload_round : Round.t; seed_nonce_hash : Nonce_hash.t option; proof_of_work_nonce : bytes; - liquidity_baking_toggle_vote : - Liquidity_baking_repr.liquidity_baking_toggle_vote; + per_block_vote : Per_block_vote.t; } type protocol_data = {contents : contents; signature : Signature.t} @@ -3937,32 +3991,13 @@ module Parameters : sig end module Liquidity_baking : sig - type liquidity_baking_toggle_vote = - Liquidity_baking_repr.liquidity_baking_toggle_vote = - | LB_on - | LB_off - | LB_pass - - val liquidity_baking_toggle_vote_encoding : - liquidity_baking_toggle_vote Data_encoding.encoding - val get_cpmm_address : context -> Contract_hash.t tzresult Lwt.t - module Toggle_EMA : sig - type t - - val zero : t - - val to_int32 : t -> Int32.t - - val encoding : t Data_encoding.t - end - val on_subsidy_allowed : context -> - toggle_vote:liquidity_baking_toggle_vote -> + Per_block_vote.State.t -> (context -> Contract_hash.t -> (context * 'a list) tzresult Lwt.t) -> - (context * 'a list * Toggle_EMA.t) tzresult Lwt.t + (context * 'a list) tzresult Lwt.t end (** This module re-exports functions from [Ticket_storage]. See diff --git a/src/proto_alpha/lib_protocol/apply.ml b/src/proto_alpha/lib_protocol/apply.ml index bd65117ab13d5d829d225beaf367428ad353e71c..2ace8fd9716f2081e7538d4672d5f110c0a3e9a2 100644 --- a/src/proto_alpha/lib_protocol/apply.ml +++ b/src/proto_alpha/lib_protocol/apply.ml @@ -3242,10 +3242,10 @@ let init_allowed_consensus_operations ctxt ~endorsement_level ~allowed_endorsements ~allowed_preendorsements) -let apply_liquidity_baking_subsidy ctxt ~toggle_vote = +let apply_liquidity_baking_subsidy ctxt per_block_vote_state = Liquidity_baking.on_subsidy_allowed ctxt - ~toggle_vote + per_block_vote_state (fun ctxt liquidity_baking_cpmm_contract_hash -> let liquidity_baking_cpmm_contract = Contract.Originated liquidity_baking_cpmm_contract_hash @@ -3405,7 +3405,7 @@ type 'a full_construction = { block_producer : Signature.public_key_hash; round : Round.t; implicit_operations_results : packed_successful_manager_operation_result list; - liquidity_baking_toggle_ema : Liquidity_baking.Toggle_EMA.t; + per_block_vote_state : Per_block_vote.State.t; } let begin_full_construction ctxt ~predecessor_timestamp ~predecessor_level @@ -3437,11 +3437,10 @@ let begin_full_construction ctxt ~predecessor_timestamp ~predecessor_level ~endorsement_level:predecessor_level ~preendorsement_level:current_level >>=? fun ctxt -> - let toggle_vote = protocol_data.liquidity_baking_toggle_vote in - apply_liquidity_baking_subsidy ctxt ~toggle_vote - >|=? fun ( ctxt, - liquidity_baking_operations_results, - liquidity_baking_toggle_ema ) -> + Per_block_vote.update ctxt protocol_data.per_block_vote + >>=? fun (ctxt, per_block_vote_state) -> + apply_liquidity_baking_subsidy ctxt per_block_vote_state + >|=? fun (ctxt, liquidity_baking_operations_results) -> { ctxt; protocol_data; @@ -3449,10 +3448,10 @@ let begin_full_construction ctxt ~predecessor_timestamp ~predecessor_level block_producer; round; implicit_operations_results = liquidity_baking_operations_results; - liquidity_baking_toggle_ema; + per_block_vote_state; } -let begin_partial_construction ctxt ~predecessor_level ~toggle_vote = +let begin_partial_construction ctxt ~predecessor_level ~per_block_vote = (* In the mempool, only consensus operations for [predecessor_level] (that is, head's level) are allowed, contrary to block validation where endorsements are for the previous level and @@ -3461,7 +3460,12 @@ let begin_partial_construction ctxt ~predecessor_level ~toggle_vote = ctxt ~endorsement_level:predecessor_level ~preendorsement_level:predecessor_level - >>=? fun ctxt -> apply_liquidity_baking_subsidy ctxt ~toggle_vote + >>=? fun ctxt -> + Per_block_vote.update ctxt per_block_vote + >>=? fun (ctxt, per_block_vote_state) -> + apply_liquidity_baking_subsidy ctxt per_block_vote_state + >|=? fun (ctxt, liquidity_baking_operations_results) -> + (ctxt, liquidity_baking_operations_results, per_block_vote_state) let begin_application ctxt chain_id (block_header : Block_header.t) fitness ~predecessor_timestamp ~predecessor_level ~predecessor_round = @@ -3497,19 +3501,18 @@ let begin_application ctxt chain_id (block_header : Block_header.t) fitness ~endorsement_level:predecessor_level ~preendorsement_level:current_level >>=? fun ctxt -> - let toggle_vote = - block_header.Block_header.protocol_data.contents - .liquidity_baking_toggle_vote + let per_block_vote = + block_header.Block_header.protocol_data.contents.per_block_vote in - apply_liquidity_baking_subsidy ctxt ~toggle_vote - >|=? fun ( ctxt, - liquidity_baking_operations_results, - liquidity_baking_toggle_ema ) -> + Per_block_vote.update ctxt per_block_vote + >>=? fun (ctxt, per_block_vote_state) -> + apply_liquidity_baking_subsidy ctxt per_block_vote_state + >|=? fun (ctxt, liquidity_baking_operations_results) -> ( ctxt, payload_producer_pk, block_producer, liquidity_baking_operations_results, - liquidity_baking_toggle_ema ) + per_block_vote_state ) type finalize_application_mode = | Finalize_full_construction of { @@ -3609,7 +3612,7 @@ let record_endorsing_participation ctxt = ctxt let finalize_application ctxt (mode : finalize_application_mode) protocol_data - ~payload_producer ~block_producer liquidity_baking_toggle_ema + ~payload_producer ~block_producer per_block_vote_state implicit_operations_results ~round ~predecessor ~migration_balance_updates = (* Then we finalize the consensus. *) let level = Level.current ctxt in @@ -3689,7 +3692,7 @@ let finalize_application ctxt (mode : finalize_application_mode) protocol_data consumed_gas; deactivated; balance_updates; - liquidity_baking_toggle_ema; + per_block_vote = per_block_vote_state; implicit_operations_results; dal_slot_availability; } diff --git a/src/proto_alpha/lib_protocol/apply.mli b/src/proto_alpha/lib_protocol/apply.mli index f2b8258f2cdb84ed1a22c3bee315143be6e38236..71e8dc13761145f2e96a3b02b3c167250a40f992 100644 --- a/src/proto_alpha/lib_protocol/apply.mli +++ b/src/proto_alpha/lib_protocol/apply.mli @@ -50,10 +50,8 @@ type error += val begin_partial_construction : context -> predecessor_level:Level.t -> - toggle_vote:Liquidity_baking_repr.liquidity_baking_toggle_vote -> - (t - * packed_successful_manager_operation_result list - * Liquidity_baking.Toggle_EMA.t) + per_block_vote:Per_block_vote.t -> + (t * packed_successful_manager_operation_result list * Per_block_vote.State.t) tzresult Lwt.t @@ -64,7 +62,7 @@ type 'a full_construction = { block_producer : Signature.public_key_hash; round : Round.t; implicit_operations_results : packed_successful_manager_operation_result list; - liquidity_baking_toggle_ema : Liquidity_baking.Toggle_EMA.t; + per_block_vote_state : Per_block_vote.State.t; } val begin_full_construction : @@ -88,7 +86,7 @@ val begin_application : * Signature.public_key * Signature.public_key_hash * packed_successful_manager_operation_result list - * Liquidity_baking.Toggle_EMA.t) + * Per_block_vote.State.t) tzresult Lwt.t @@ -138,7 +136,7 @@ val finalize_application : Block_header.contents -> payload_producer:public_key_hash -> block_producer:public_key_hash -> - Liquidity_baking.Toggle_EMA.t -> + Per_block_vote.State.t -> packed_successful_manager_operation_result list -> round:Round.t -> predecessor:Block_hash.t -> diff --git a/src/proto_alpha/lib_protocol/apply_results.ml b/src/proto_alpha/lib_protocol/apply_results.ml index c1fe3cf605746a8b406a79b73da0692295e222c2..39029a1aece60db7841f641ccb8510c8c8ed0bf8 100644 --- a/src/proto_alpha/lib_protocol/apply_results.ml +++ b/src/proto_alpha/lib_protocol/apply_results.ml @@ -3064,7 +3064,7 @@ 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; + per_block_vote : Per_block_vote.State.t; implicit_operations_results : packed_successful_manager_operation_result list; dal_slot_availability : Dal.Endorsement.t option; } @@ -3082,7 +3082,7 @@ let block_metadata_encoding = consumed_gas; deactivated; balance_updates; - liquidity_baking_toggle_ema; + per_block_vote; implicit_operations_results; dal_slot_availability; } -> @@ -3092,22 +3092,22 @@ let block_metadata_encoding = voting_period_info, nonce_hash, consumed_gas, + consumed_gas, deactivated, balance_updates, - liquidity_baking_toggle_ema, implicit_operations_results ), - (consumed_gas, dal_slot_availability) )) + (per_block_vote, dal_slot_availability) )) (fun ( ( proposer, baker, level_info, voting_period_info, nonce_hash, consumed_gas, + _consumed_millgas, deactivated, balance_updates, - liquidity_baking_toggle_ema, implicit_operations_results ), - (_consumed_millgas, dal_slot_availability) ) -> + (per_block_vote, dal_slot_availability) ) -> { proposer; baker; @@ -3117,7 +3117,7 @@ let block_metadata_encoding = consumed_gas; deactivated; balance_updates; - liquidity_baking_toggle_ema; + per_block_vote; implicit_operations_results; dal_slot_availability; }) @@ -3129,22 +3129,21 @@ let block_metadata_encoding = (req "voting_period_info" Voting_period.info_encoding) (req "nonce_hash" (option Nonce_hash.encoding)) (req "consumed_gas" Gas.Arith.n_fp_encoding) + (req "consumed_milligas" Gas.Arith.n_fp_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 "implicit_operations_results" (list successful_manager_operation_result_encoding))) - (obj2 - (req "consumed_milligas" Gas.Arith.n_fp_encoding) - (* DAL/FIXME https://gitlab.com/tezos/tezos/-/issues/3119 - - This varopt is here while the DAL is behind a feature - flag. This should be replaced by a required field once - the feature flag will be activated. *) - (varopt "dal_slot_availability" Dal.Endorsement.encoding))) + (merge_objs + Per_block_vote.State.encoding + (obj1 + (* DAL/FIXME https://gitlab.com/tezos/tezos/-/issues/3119 + + This varopt is here while the DAL is behind a feature + flag. This should be replaced by a required field once + the feature flag will be activated. *) + (varopt "dal_slot_availability" Dal.Endorsement.encoding)))) type 'kind prechecked_contents = { contents : 'kind contents; diff --git a/src/proto_alpha/lib_protocol/apply_results.mli b/src/proto_alpha/lib_protocol/apply_results.mli index 009fbdbbc34073f9fc620b6a72707cb64122cf69..11259aa0499f1f9a23d3564065321d5f9ff97cd8 100644 --- a/src/proto_alpha/lib_protocol/apply_results.mli +++ b/src/proto_alpha/lib_protocol/apply_results.mli @@ -419,7 +419,7 @@ 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; + per_block_vote : Per_block_vote.State.t; implicit_operations_results : packed_successful_manager_operation_result list; dal_slot_availability : Dal.Endorsement.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 39b6375d1afd6d37dbd518941fda908708ac2318..5e35aa2f3ff7e11acf3f9bc8324829e36ab2facf 100644 --- a/src/proto_alpha/lib_protocol/block_header_repr.ml +++ b/src/proto_alpha/lib_protocol/block_header_repr.ml @@ -30,8 +30,7 @@ type contents = { payload_round : Round_repr.t; seed_nonce_hash : Nonce_hash.t option; proof_of_work_nonce : bytes; - liquidity_baking_toggle_vote : - Liquidity_baking_repr.liquidity_baking_toggle_vote; + per_block_vote : Per_block_vote_repr.t; } type protocol_data = {contents : contents; signature : Signature.t} @@ -77,35 +76,28 @@ let contents_encoding = payload_round; seed_nonce_hash; proof_of_work_nonce; - liquidity_baking_toggle_vote; + per_block_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, proof_of_work_nonce, seed_nonce_hash), + per_block_vote )) + (fun ( (payload_hash, payload_round, proof_of_work_nonce, seed_nonce_hash), + per_block_vote ) -> { payload_hash; payload_round; seed_nonce_hash; proof_of_work_nonce; - liquidity_baking_toggle_vote; + per_block_vote; }) - (obj5 - (req "payload_hash" Block_payload_hash.encoding) - (req "payload_round" Round_repr.encoding) - (req - "proof_of_work_nonce" - (Fixed.bytes Constants_repr.proof_of_work_nonce_size)) - (opt "seed_nonce_hash" Nonce_hash.encoding) - (req - "liquidity_baking_toggle_vote" - Liquidity_baking_repr.liquidity_baking_toggle_vote_encoding)) + (merge_objs + (obj4 + (req "payload_hash" Block_payload_hash.encoding) + (req "payload_round" Round_repr.encoding) + (req + "proof_of_work_nonce" + (Fixed.bytes Constants_repr.proof_of_work_nonce_size)) + (opt "seed_nonce_hash" Nonce_hash.encoding)) + Per_block_vote_repr.encoding) let protocol_data_encoding = let open Data_encoding in @@ -164,7 +156,7 @@ 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; + per_block_vote = Per_block_vote_repr.default; } 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 a84761403288d586650ab75e0805a6237a2b1aed..bcfb81a241f255b4180ba2fe1e9d8da975029eca 100644 --- a/src/proto_alpha/lib_protocol/block_header_repr.mli +++ b/src/proto_alpha/lib_protocol/block_header_repr.mli @@ -30,8 +30,7 @@ type contents = { payload_round : Round_repr.t; seed_nonce_hash : Nonce_hash.t option; proof_of_work_nonce : bytes; - liquidity_baking_toggle_vote : - Liquidity_baking_repr.liquidity_baking_toggle_vote; + per_block_vote : Per_block_vote_repr.t; } type protocol_data = {contents : contents; signature : Signature.t} diff --git a/src/proto_alpha/lib_protocol/constants_parametric_previous_repr.ml b/src/proto_alpha/lib_protocol/constants_parametric_previous_repr.ml index 1cdbd9b2d5ac0d048bff588a53975e1361686766..fd1ce6f31e337795b612afb50a7b3a0600ab1370 100644 --- a/src/proto_alpha/lib_protocol/constants_parametric_previous_repr.ml +++ b/src/proto_alpha/lib_protocol/constants_parametric_previous_repr.ml @@ -47,7 +47,7 @@ type t = { min_proposal_quorum : int32; liquidity_baking_subsidy : Tez_repr.t; liquidity_baking_sunset_level : int32; - liquidity_baking_toggle_ema_threshold : int32; + liquidity_baking_toggle_ema_threshold : Toggle_vote_ema_repr.t; max_operations_time_to_live : int; minimal_block_delay : Period_repr.t; delay_increment_per_round : Period_repr.t; @@ -285,7 +285,9 @@ let encoding = (req "min_proposal_quorum" int32) (req "liquidity_baking_subsidy" Tez_repr.encoding) (req "liquidity_baking_sunset_level" int32) - (req "liquidity_baking_toggle_ema_threshold" int32) + (req + "liquidity_baking_toggle_ema_threshold" + Toggle_vote_ema_repr.encoding) (req "max_operations_time_to_live" int16) (req "minimal_block_delay" Period_repr.encoding) (req "delay_increment_per_round" Period_repr.encoding) diff --git a/src/proto_alpha/lib_protocol/constants_parametric_previous_repr.mli b/src/proto_alpha/lib_protocol/constants_parametric_previous_repr.mli index aa70452999d5aa5bd61bf71278277d61dc7a60c0..9849527eece760d120aa42a12dd09d8812cb1f56 100644 --- a/src/proto_alpha/lib_protocol/constants_parametric_previous_repr.mli +++ b/src/proto_alpha/lib_protocol/constants_parametric_previous_repr.mli @@ -47,7 +47,7 @@ type t = { min_proposal_quorum : int32; liquidity_baking_subsidy : Tez_repr.t; liquidity_baking_sunset_level : int32; - liquidity_baking_toggle_ema_threshold : int32; + liquidity_baking_toggle_ema_threshold : Toggle_vote_ema_repr.t; max_operations_time_to_live : int; minimal_block_delay : Period_repr.t; delay_increment_per_round : Period_repr.t; diff --git a/src/proto_alpha/lib_protocol/constants_parametric_repr.ml b/src/proto_alpha/lib_protocol/constants_parametric_repr.ml index 2ca203edaa06f4c55869de711b564e34049b60b8..d989eaba870e1a180f91e740704dae1f02c6e368 100644 --- a/src/proto_alpha/lib_protocol/constants_parametric_repr.ml +++ b/src/proto_alpha/lib_protocol/constants_parametric_repr.ml @@ -128,7 +128,6 @@ type t = { min_proposal_quorum : int32; liquidity_baking_subsidy : Tez_repr.t; liquidity_baking_sunset_level : int32; - liquidity_baking_toggle_ema_threshold : int32; max_operations_time_to_live : int; minimal_block_delay : Period_repr.t; delay_increment_per_round : Period_repr.t; @@ -289,7 +288,6 @@ let encoding = c.min_proposal_quorum, c.liquidity_baking_subsidy, c.liquidity_baking_sunset_level, - c.liquidity_baking_toggle_ema_threshold, c.max_operations_time_to_live, c.minimal_block_delay, c.delay_increment_per_round, @@ -326,7 +324,6 @@ let encoding = min_proposal_quorum, liquidity_baking_subsidy, liquidity_baking_sunset_level, - liquidity_baking_toggle_ema_threshold, max_operations_time_to_live, minimal_block_delay, delay_increment_per_round, @@ -364,7 +361,6 @@ let encoding = min_proposal_quorum; liquidity_baking_subsidy; liquidity_baking_sunset_level; - liquidity_baking_toggle_ema_threshold; max_operations_time_to_live; minimal_block_delay; delay_increment_per_round; @@ -409,12 +405,11 @@ let encoding = (req "hard_storage_limit_per_operation" z) (req "quorum_min" int32)) (merge_objs - (obj10 + (obj9 (req "quorum_max" int32) (req "min_proposal_quorum" int32) (req "liquidity_baking_subsidy" Tez_repr.encoding) (req "liquidity_baking_sunset_level" int32) - (req "liquidity_baking_toggle_ema_threshold" int32) (req "max_operations_time_to_live" int16) (req "minimal_block_delay" Period_repr.encoding) (req "delay_increment_per_round" Period_repr.encoding) diff --git a/src/proto_alpha/lib_protocol/constants_parametric_repr.mli b/src/proto_alpha/lib_protocol/constants_parametric_repr.mli index d5d38f6985068df3d9e9c85d3473a37a90259ba4..e48d7b43b1b21451890eb40c3badefdf897d8e3a 100644 --- a/src/proto_alpha/lib_protocol/constants_parametric_repr.mli +++ b/src/proto_alpha/lib_protocol/constants_parametric_repr.mli @@ -125,7 +125,6 @@ type t = { min_proposal_quorum : int32; liquidity_baking_subsidy : Tez_repr.t; liquidity_baking_sunset_level : int32; - liquidity_baking_toggle_ema_threshold : int32; max_operations_time_to_live : int; minimal_block_delay : Period_repr.t; delay_increment_per_round : Period_repr.t; diff --git a/src/proto_alpha/lib_protocol/constants_storage.ml b/src/proto_alpha/lib_protocol/constants_storage.ml index 85d75f3fc71b2f01254b3f13540082a78ed4e1db..b1008c131c26c3462be73066e352fa363ec24532 100644 --- a/src/proto_alpha/lib_protocol/constants_storage.ml +++ b/src/proto_alpha/lib_protocol/constants_storage.ml @@ -108,10 +108,6 @@ let liquidity_baking_sunset_level c = let constants = Raw_context.constants c in constants.liquidity_baking_sunset_level -let liquidity_baking_toggle_ema_threshold c = - let constants = Raw_context.constants c in - constants.liquidity_baking_toggle_ema_threshold - let parametric c = Raw_context.constants c let tx_rollup c = (Raw_context.constants c).tx_rollup diff --git a/src/proto_alpha/lib_protocol/constants_storage.mli b/src/proto_alpha/lib_protocol/constants_storage.mli index a278ae0d67ea196a693a2e3ca0da04f30b045bb3..8caceb6cde90777502551485cdfaf8dae233c38b 100644 --- a/src/proto_alpha/lib_protocol/constants_storage.mli +++ b/src/proto_alpha/lib_protocol/constants_storage.mli @@ -72,8 +72,6 @@ val liquidity_baking_subsidy : Raw_context.t -> Tez_repr.t val liquidity_baking_sunset_level : Raw_context.t -> int32 -val liquidity_baking_toggle_ema_threshold : Raw_context.t -> int32 - val parametric : Raw_context.t -> Constants_parametric_repr.t val tx_rollup : Raw_context.t -> Constants_parametric_repr.tx_rollup diff --git a/src/proto_alpha/lib_protocol/dune b/src/proto_alpha/lib_protocol/dune index ee039990e78f18abe924c856cc02409ae5a2ca34..fafc30106a1bfb8defa495bf849aa4b27ddf4fc9 100644 --- a/src/proto_alpha/lib_protocol/dune +++ b/src/proto_alpha/lib_protocol/dune @@ -59,6 +59,10 @@ Fixed_point_repr Saturation_repr Gas_limit_repr + Toggle_vote_name_repr + Toggle_vote_repr + Toggle_vote_ema_repr + Per_block_vote_repr Constants_parametric_repr Constants_parametric_previous_repr Constants_repr @@ -110,7 +114,6 @@ Dal_endorsement_repr Bond_id_repr Vote_repr - Liquidity_baking_repr Block_header_repr Destination_repr Operation_repr @@ -151,6 +154,7 @@ Delegate_storage Bootstrap_storage Vote_storage + Per_block_vote_storage Fees_storage Ticket_storage Liquidity_baking_storage @@ -279,6 +283,10 @@ fixed_point_repr.ml fixed_point_repr.mli saturation_repr.ml saturation_repr.mli gas_limit_repr.ml gas_limit_repr.mli + toggle_vote_name_repr.ml toggle_vote_name_repr.mli + toggle_vote_repr.ml toggle_vote_repr.mli + toggle_vote_ema_repr.ml toggle_vote_ema_repr.mli + per_block_vote_repr.ml per_block_vote_repr.mli constants_parametric_repr.ml constants_parametric_repr.mli constants_parametric_previous_repr.ml constants_parametric_previous_repr.mli @@ -332,7 +340,6 @@ dal_endorsement_repr.ml dal_endorsement_repr.mli bond_id_repr.ml bond_id_repr.mli vote_repr.ml vote_repr.mli - liquidity_baking_repr.ml liquidity_baking_repr.mli block_header_repr.ml block_header_repr.mli destination_repr.ml destination_repr.mli operation_repr.ml operation_repr.mli @@ -373,6 +380,7 @@ delegate_storage.ml delegate_storage.mli bootstrap_storage.ml bootstrap_storage.mli vote_storage.ml vote_storage.mli + per_block_vote_storage.ml per_block_vote_storage.mli fees_storage.ml fees_storage.mli ticket_storage.ml ticket_storage.mli liquidity_baking_storage.ml liquidity_baking_storage.mli @@ -487,6 +495,10 @@ fixed_point_repr.ml fixed_point_repr.mli saturation_repr.ml saturation_repr.mli gas_limit_repr.ml gas_limit_repr.mli + toggle_vote_name_repr.ml toggle_vote_name_repr.mli + toggle_vote_repr.ml toggle_vote_repr.mli + toggle_vote_ema_repr.ml toggle_vote_ema_repr.mli + per_block_vote_repr.ml per_block_vote_repr.mli constants_parametric_repr.ml constants_parametric_repr.mli constants_parametric_previous_repr.ml constants_parametric_previous_repr.mli @@ -540,7 +552,6 @@ dal_endorsement_repr.ml dal_endorsement_repr.mli bond_id_repr.ml bond_id_repr.mli vote_repr.ml vote_repr.mli - liquidity_baking_repr.ml liquidity_baking_repr.mli block_header_repr.ml block_header_repr.mli destination_repr.ml destination_repr.mli operation_repr.ml operation_repr.mli @@ -581,6 +592,7 @@ delegate_storage.ml delegate_storage.mli bootstrap_storage.ml bootstrap_storage.mli vote_storage.ml vote_storage.mli + per_block_vote_storage.ml per_block_vote_storage.mli fees_storage.ml fees_storage.mli ticket_storage.ml ticket_storage.mli liquidity_baking_storage.ml liquidity_baking_storage.mli @@ -715,6 +727,10 @@ fixed_point_repr.ml fixed_point_repr.mli saturation_repr.ml saturation_repr.mli gas_limit_repr.ml gas_limit_repr.mli + toggle_vote_name_repr.ml toggle_vote_name_repr.mli + toggle_vote_repr.ml toggle_vote_repr.mli + toggle_vote_ema_repr.ml toggle_vote_ema_repr.mli + per_block_vote_repr.ml per_block_vote_repr.mli constants_parametric_repr.ml constants_parametric_repr.mli constants_parametric_previous_repr.ml constants_parametric_previous_repr.mli @@ -768,7 +784,6 @@ dal_endorsement_repr.ml dal_endorsement_repr.mli bond_id_repr.ml bond_id_repr.mli vote_repr.ml vote_repr.mli - liquidity_baking_repr.ml liquidity_baking_repr.mli block_header_repr.ml block_header_repr.mli destination_repr.ml destination_repr.mli operation_repr.ml operation_repr.mli @@ -809,6 +824,7 @@ delegate_storage.ml delegate_storage.mli bootstrap_storage.ml bootstrap_storage.mli vote_storage.ml vote_storage.mli + per_block_vote_storage.ml per_block_vote_storage.mli fees_storage.ml fees_storage.mli ticket_storage.ml ticket_storage.mli liquidity_baking_storage.ml liquidity_baking_storage.mli @@ -939,6 +955,10 @@ fixed_point_repr.ml fixed_point_repr.mli saturation_repr.ml saturation_repr.mli gas_limit_repr.ml gas_limit_repr.mli + toggle_vote_name_repr.ml toggle_vote_name_repr.mli + toggle_vote_repr.ml toggle_vote_repr.mli + toggle_vote_ema_repr.ml toggle_vote_ema_repr.mli + per_block_vote_repr.ml per_block_vote_repr.mli constants_parametric_repr.ml constants_parametric_repr.mli constants_parametric_previous_repr.ml constants_parametric_previous_repr.mli @@ -992,7 +1012,6 @@ dal_endorsement_repr.ml dal_endorsement_repr.mli bond_id_repr.ml bond_id_repr.mli vote_repr.ml vote_repr.mli - liquidity_baking_repr.ml liquidity_baking_repr.mli block_header_repr.ml block_header_repr.mli destination_repr.ml destination_repr.mli operation_repr.ml operation_repr.mli @@ -1033,6 +1052,7 @@ delegate_storage.ml delegate_storage.mli bootstrap_storage.ml bootstrap_storage.mli vote_storage.ml vote_storage.mli + per_block_vote_storage.ml per_block_vote_storage.mli fees_storage.ml fees_storage.mli ticket_storage.ml ticket_storage.mli liquidity_baking_storage.ml liquidity_baking_storage.mli diff --git a/src/proto_alpha/lib_protocol/init_storage.ml b/src/proto_alpha/lib_protocol/init_storage.ml index 258702c6e1f02a990bd7d7de728d54bae8edf4d5..91d075a188289d7ee1404cae0387f327595ae598 100644 --- a/src/proto_alpha/lib_protocol/init_storage.ml +++ b/src/proto_alpha/lib_protocol/init_storage.ml @@ -114,6 +114,7 @@ let prepare_first_block _chain_id ctxt ~typecheck ~level ~timestamp = >>=? fun (ctxt, operation_results) -> Storage.Pending_migration.Operation_results.init ctxt operation_results >>=? fun ctxt -> + Per_block_vote_storage.init ctxt >>= fun ctxt -> return ( ctxt, commitments_balance_updates @ bootstrap_balance_updates @@ -123,7 +124,9 @@ let prepare_first_block _chain_id ctxt ~typecheck ~level ~timestamp = if that is done, do not set Storage.Tenderbake.First_level_of_protocol. *) Raw_level_repr.of_int32 level >>?= fun level -> Storage.Tenderbake.First_level_of_protocol.update ctxt level - >>=? fun ctxt -> return (ctxt, [])) + >>=? fun ctxt -> + Per_block_vote_storage.Migration_from_Jakarta.update ctxt >>=? fun ctxt -> + return (ctxt, [])) >>=? fun (ctxt, balance_updates) -> Receipt_repr.group_balance_updates balance_updates >>?= fun balance_updates -> Storage.Pending_migration.Balance_updates.add ctxt balance_updates diff --git a/src/proto_alpha/lib_protocol/liquidity_baking_migration.ml b/src/proto_alpha/lib_protocol/liquidity_baking_migration.ml index 4f4d13dfa38ebc7b1bbda76bac8c88d888a15afc..f3d77311b4a861ad8c6463382012d7ac4deaefaa 100644 --- a/src/proto_alpha/lib_protocol/liquidity_baking_migration.ml +++ b/src/proto_alpha/lib_protocol/liquidity_baking_migration.ml @@ -198,7 +198,6 @@ let init ctxt ~typecheck = (* We use a custom origination nonce because it is unset when stitching from 009 *) let nonce = Operation_hash.hash_string ["Drip, drip, drip."] in let ctxt = Raw_context.init_origination_nonce ctxt nonce in - Storage.Liquidity_baking.Toggle_ema.init ctxt 0l >>=? fun ctxt -> let current_level = Raw_level_repr.to_int32 (Level_storage.current ctxt).level in diff --git a/src/proto_alpha/lib_protocol/liquidity_baking_repr.ml b/src/proto_alpha/lib_protocol/liquidity_baking_repr.ml deleted file mode 100644 index 7a15716270ccd99ea70f69321802196fbc47a4fa..0000000000000000000000000000000000000000 --- a/src/proto_alpha/lib_protocol/liquidity_baking_repr.ml +++ /dev/null @@ -1,122 +0,0 @@ -(*****************************************************************************) -(* *) -(* Open Source License *) -(* Copyright (c) 2021 Tocqueville Group, Inc. *) -(* Copyright (c) 2022 Nomadic Labs *) -(* *) -(* Permission is hereby granted, free of charge, to any person obtaining a *) -(* copy of this software and associated documentation files (the "Software"),*) -(* to deal in the Software without restriction, including without limitation *) -(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *) -(* and/or sell copies of the Software, and to permit persons to whom the *) -(* Software is furnished to do so, subject to the following conditions: *) -(* *) -(* The above copyright notice and this permission notice shall be included *) -(* in all copies or substantial portions of the Software. *) -(* *) -(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*) -(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *) -(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *) -(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*) -(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *) -(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *) -(* DEALINGS IN THE SOFTWARE. *) -(* *) -(*****************************************************************************) - -(** Options available for the Liquidity Baking per-block vote *) - -type liquidity_baking_toggle_vote = LB_on | LB_off | LB_pass - -let liquidity_baking_toggle_vote_encoding = - let of_int8 = function - | 0 -> Ok LB_on - | 1 -> Ok LB_off - | 2 -> Ok LB_pass - | _ -> Error "liquidity_baking_toggle_vote_of_int8" - in - let to_int8 = function LB_on -> 0 | LB_off -> 1 | LB_pass -> 2 in - let open Data_encoding in - (* union *) - def "liquidity_baking_toggle_vote" - @@ splitted - ~binary:(conv_with_guard to_int8 of_int8 int8) - ~json:(string_enum [("on", LB_on); ("off", LB_off); ("pass", LB_pass)]) - -module Toggle_EMA : sig - (* The exponential moving average is represented as an Int32 between 0l and 2_000_000_000l *) - - type t - - val zero : t - - val of_int32 : Int32.t -> t tzresult Lwt.t - - val to_int32 : t -> Int32.t - - val update_ema_off : t -> t - - val update_ema_on : t -> t - - val ( < ) : t -> Int32.t -> bool - - val encoding : t Data_encoding.t -end = struct - type t = Int32.t (* Invariant 0 <= ema <= 2_000_000_000l *) - - (* This error is not registered because we don't expect it to be - raised. *) - type error += Liquidity_baking_toggle_ema_out_of_bound of Int32.t - - let check_bounds x = Compare.Int32.(0l <= x && x <= 2_000_000_000l) - - let of_int32 x = - if check_bounds x then return x - else fail @@ Liquidity_baking_toggle_ema_out_of_bound x - - let zero = Int32.zero - - (* The conv_with_guard combinator of Data_encoding expects a (_, string) result. *) - let of_int32_for_encoding x = - if check_bounds x then Ok x else Error "out of bounds" - - let to_int32 ema = ema - - (* We perform the computations in Z to avoid overflows. *) - - let z_1999 = Z.of_int 1999 - - let z_2000 = Z.of_int 2000 - - let attenuate z = Z.(div (mul z_1999 z) z_2000) - - let z_1_000_000_000 = Z.of_int 1_000_000_000 - - (* Outside of this module, the EMA is always between 0 and 2,000,000,000. - This [recenter] wrappers, puts it in between -1,000,000,000 and 1,000,000,000. - The goal of this recentering around zero is to make [update_ema_off] and - [update_ema_on] behave symmetrically with respect to rounding. *) - let recenter f ema = Z.(add z_1_000_000_000 (f (sub ema z_1_000_000_000))) - - let z_500_000 = Z.of_int 500_000 - - let update_ema_off ema = - let ema = Z.of_int32 ema in - recenter (fun ema -> Z.add (attenuate ema) z_500_000) ema |> Z.to_int32 - - let update_ema_on ema = - let ema = Z.of_int32 ema in - recenter (fun ema -> Z.sub (attenuate ema) z_500_000) ema |> Z.to_int32 - - let ( < ) = Compare.Int32.( < ) - - let encoding = - Data_encoding.(conv_with_guard to_int32 of_int32_for_encoding int32) -end - -(* Invariant: 0 <= ema <= 2_000_000 *) -let compute_new_ema ~toggle_vote ema = - match toggle_vote with - | LB_pass -> ema - | LB_off -> Toggle_EMA.update_ema_off ema - | LB_on -> Toggle_EMA.update_ema_on ema diff --git a/src/proto_alpha/lib_protocol/liquidity_baking_storage.ml b/src/proto_alpha/lib_protocol/liquidity_baking_storage.ml index 0202241484b9650957134154000c3d8f6a4524e8..c7d52cffc6c3750bcf85c8e127b01d967ef8bca3 100644 --- a/src/proto_alpha/lib_protocol/liquidity_baking_storage.ml +++ b/src/proto_alpha/lib_protocol/liquidity_baking_storage.ml @@ -24,14 +24,8 @@ (* *) (*****************************************************************************) -open Liquidity_baking_repr - let get_cpmm_address = Storage.Liquidity_baking.Cpmm_address.get -let get_toggle_ema ctxt = - Storage.Liquidity_baking.Toggle_ema.get ctxt >>=? fun ema -> - Toggle_EMA.of_int32 ema - let on_cpmm_exists ctxt f = get_cpmm_address ctxt >>=? fun cpmm_contract -> Contract_storage.exists ctxt (Contract_repr.Originated cpmm_contract) @@ -46,19 +40,12 @@ let check_below_sunset ctxt = let level = Raw_level_repr.to_int32 (Level_storage.current ctxt).level in Compare.Int32.(level < sunset_level) -let update_toggle_ema ctxt ~toggle_vote = - get_toggle_ema ctxt >>=? fun old_ema -> - let new_ema = compute_new_ema ~toggle_vote old_ema in - Storage.Liquidity_baking.Toggle_ema.update ctxt (Toggle_EMA.to_int32 new_ema) - >|=? fun ctxt -> (ctxt, new_ema) - -let check_ema_below_threshold ctxt ema = - Toggle_EMA.( - ema < Constants_storage.liquidity_baking_toggle_ema_threshold ctxt) - -let on_subsidy_allowed ctxt ~toggle_vote f = - update_toggle_ema ctxt ~toggle_vote >>=? fun (ctxt, toggle_ema) -> - if check_ema_below_threshold ctxt toggle_ema && check_below_sunset ctxt then +let on_subsidy_allowed ctxt state f = + let open Per_block_vote_repr.State in + if + Toggle_vote_ema_repr.below_threshold state.liquidity_baking + && check_below_sunset ctxt + then on_cpmm_exists ctxt f >|=? fun (ctxt, operation_results) -> - (ctxt, operation_results, toggle_ema) - else return (ctxt, [], toggle_ema) + (ctxt, operation_results) + else return (ctxt, []) diff --git a/src/proto_alpha/lib_protocol/liquidity_baking_storage.mli b/src/proto_alpha/lib_protocol/liquidity_baking_storage.mli index 4db50c0a25365f6276ea7bc0e8b826773f1729db..80e10d3bd78bb7f0255220907e8804ed74a107a3 100644 --- a/src/proto_alpha/lib_protocol/liquidity_baking_storage.mli +++ b/src/proto_alpha/lib_protocol/liquidity_baking_storage.mli @@ -24,14 +24,13 @@ (* *) (*****************************************************************************) -(** 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 -(** [on_subsidy_allowed ctxt ~toggle_vote f] updates the toggle EMA according to - [toggle_vote]. Then the callback function [f] is called if the following +(** [on_subsidy_allowed ctxt emas f]. The callback function [f] is called if the following conditions are met: - - the updated EMA is below the threshold, + - the liquidity baking toggle vote EMA is below the threshold, - the current level is below the sunset level, - the CPMM contract exists. @@ -39,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 -> + Per_block_vote_repr.State.t -> (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) tzresult Lwt.t diff --git a/src/proto_alpha/lib_protocol/main.ml b/src/proto_alpha/lib_protocol/main.ml index 022ebeb62a766567f09a136f444309da9796365d..77640a33ead94521029f346d4703a2c3944404a3 100644 --- a/src/proto_alpha/lib_protocol/main.ml +++ b/src/proto_alpha/lib_protocol/main.ml @@ -132,7 +132,7 @@ type validation_state = { ctxt : Alpha_context.t; op_count : int; migration_balance_updates : Alpha_context.Receipt.balance_updates; - liquidity_baking_toggle_ema : Alpha_context.Liquidity_baking.Toggle_EMA.t; + per_block_vote_state : Alpha_context.Per_block_vote.State.t; implicit_operations_results : Apply_results.packed_successful_manager_operation_result list; } @@ -165,7 +165,7 @@ let begin_partial_application ~chain_id ~ancestor_context:ctxt payload_producer_pk, block_producer, liquidity_baking_operations_results, - liquidity_baking_toggle_ema ) -> + per_block_vote_state ) -> let mode = Partial_application { @@ -184,7 +184,7 @@ let begin_partial_application ~chain_id ~ancestor_context:ctxt ctxt; op_count = 0; migration_balance_updates; - liquidity_baking_toggle_ema; + per_block_vote_state; implicit_operations_results = Apply_results.pack_migration_operation_results migration_operation_results @@ -221,7 +221,7 @@ let begin_application ~chain_id ~predecessor_context:ctxt ~predecessor_timestamp payload_producer, block_producer, liquidity_baking_operations_results, - liquidity_baking_toggle_ema ) -> + per_block_vote_state ) -> let mode = Application { @@ -240,7 +240,7 @@ let begin_application ~chain_id ~predecessor_context:ctxt ~predecessor_timestamp ctxt; op_count = 0; migration_balance_updates; - liquidity_baking_toggle_ema; + per_block_vote_state; implicit_operations_results = Apply_results.pack_migration_operation_results migration_operation_results @@ -262,11 +262,10 @@ let begin_construction ~chain_id ~predecessor_context:ctxt | None -> Alpha_context.Fitness.round_from_raw predecessor_fitness >>?= fun predecessor_round -> - let toggle_vote = Alpha_context.Liquidity_baking.LB_pass in - Apply.begin_partial_construction ctxt ~predecessor_level ~toggle_vote - >>=? fun ( ctxt, - liquidity_baking_operations_results, - liquidity_baking_toggle_ema ) -> + let per_block_vote = Alpha_context.Per_block_vote.default in + Apply.begin_partial_construction ctxt ~predecessor_level ~per_block_vote + >>=? fun (ctxt, liquidity_baking_operations_results, per_block_vote_state) + -> let mode = Partial_construction { @@ -277,10 +276,7 @@ let begin_construction ~chain_id ~predecessor_context:ctxt } in return - ( mode, - ctxt, - liquidity_baking_operations_results, - liquidity_baking_toggle_ema ) + (mode, ctxt, liquidity_baking_operations_results, per_block_vote_state) | Some proto_header -> Alpha_context.Fitness.round_from_raw predecessor_fitness >>?= fun predecessor_round -> @@ -306,7 +302,7 @@ let begin_construction ~chain_id ~predecessor_context:ctxt payload_producer; block_producer; round; - liquidity_baking_toggle_ema; + per_block_vote_state; implicit_operations_results = liquidity_baking_operations_results; } -> @@ -324,21 +320,18 @@ let begin_construction ~chain_id ~predecessor_context:ctxt } in return - ( mode, - ctxt, - liquidity_baking_operations_results, - liquidity_baking_toggle_ema )) + (mode, ctxt, liquidity_baking_operations_results, per_block_vote_state)) >|=? fun ( mode, ctxt, liquidity_baking_operations_results, - liquidity_baking_toggle_ema ) -> + per_block_vote_state ) -> { mode; chain_id; ctxt; op_count = 0; migration_balance_updates; - liquidity_baking_toggle_ema; + per_block_vote_state; implicit_operations_results = Apply_results.pack_migration_operation_results migration_operation_results @ liquidity_baking_operations_results; @@ -498,7 +491,7 @@ let cache_nonce_from_block_header shell contents = Block_hash.to_bytes (hash x) let finalize_block_application ctxt round ~cache_nonce finalize_application_mode - protocol_data payload_producer block_producer liquidity_baking_toggle_ema + protocol_data payload_producer block_producer per_block_vote_state implicit_operations_results predecessor migration_balance_updates op_count = Apply.finalize_application ctxt @@ -506,7 +499,7 @@ let finalize_block_application ctxt round ~cache_nonce finalize_application_mode protocol_data ~payload_producer ~block_producer - liquidity_baking_toggle_ema + per_block_vote_state implicit_operations_results ~round ~predecessor @@ -558,7 +551,7 @@ let finalize_block ctxt; op_count; migration_balance_updates; - liquidity_baking_toggle_ema; + per_block_vote_state; implicit_operations_results; _; } shell_header = @@ -581,7 +574,7 @@ let finalize_block consumed_gas = Alpha_context.Gas.Arith.zero; deactivated = []; balance_updates = migration_balance_updates; - liquidity_baking_toggle_ema; + per_block_vote = per_block_vote_state; implicit_operations_results; dal_slot_availability = None; } ) @@ -621,7 +614,7 @@ let finalize_block consumed_gas = Alpha_context.Gas.Arith.zero; deactivated = []; balance_updates = migration_balance_updates; - liquidity_baking_toggle_ema; + per_block_vote = per_block_vote_state; implicit_operations_results; dal_slot_availability = None; } ) @@ -643,7 +636,7 @@ let finalize_block protocol_data payload_producer block_producer - liquidity_baking_toggle_ema + per_block_vote_state implicit_operations_results shell.predecessor migration_balance_updates @@ -675,7 +668,7 @@ let finalize_block protocol_data_contents payload_producer block_producer - liquidity_baking_toggle_ema + per_block_vote_state implicit_operations_results predecessor migration_balance_updates @@ -786,7 +779,7 @@ 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; + per_block_vote = Alpha_context.Per_block_vote.default; 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/main.mli b/src/proto_alpha/lib_protocol/main.mli index a6e20a489ec40d0612844ce7698175cbad37b9d2..955546735f112ac8faa48d6d1164d58890697720 100644 --- a/src/proto_alpha/lib_protocol/main.mli +++ b/src/proto_alpha/lib_protocol/main.mli @@ -104,7 +104,7 @@ type validation_state = { ctxt : Alpha_context.t; op_count : int; migration_balance_updates : Alpha_context.Receipt.balance_updates; - liquidity_baking_toggle_ema : Alpha_context.Liquidity_baking.Toggle_EMA.t; + per_block_vote_state : Alpha_context.Per_block_vote.State.t; implicit_operations_results : Apply_results.packed_successful_manager_operation_result list; } diff --git a/src/proto_alpha/lib_protocol/per_block_vote_repr.ml b/src/proto_alpha/lib_protocol/per_block_vote_repr.ml new file mode 100644 index 0000000000000000000000000000000000000000..5a34d878880727006ff2e9ad636b8b0375fc72fe --- /dev/null +++ b/src/proto_alpha/lib_protocol/per_block_vote_repr.ml @@ -0,0 +1,73 @@ +(*****************************************************************************) +(* *) +(* Open Source License *) +(* Copyright (c) 2022 G.B. Fefe *) +(* *) +(* 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. *) +(* *) +(*****************************************************************************) + +open Toggle_vote_repr +open Toggle_vote_name_repr + +type t = {liquidity_baking : Toggle_vote_repr.t} + +let encoding = + (* Warning: when adding a second vote, please use compact encodings. *) + let open Data_encoding in + conv + (fun {liquidity_baking} -> liquidity_baking) + (fun liquidity_baking -> {liquidity_baking}) + (obj1 (req "liquidity_baking_toggle_vote" Toggle_vote_repr.encoding)) + +let dft_encoding = + let open Data_encoding in + conv + (fun {liquidity_baking} -> liquidity_baking) + (fun liquidity_baking -> {liquidity_baking}) + (obj1 (dft "liquidity_baking_toggle_vote" Toggle_vote_repr.encoding Pass)) + +let default = {liquidity_baking = Pass} + +let get_toggle_vote = function + | Liquidity_baking -> fun ballot -> ballot.liquidity_baking + +let set_toggle_vote name = + match name with + | Liquidity_baking -> + fun {liquidity_baking = _} vote -> {liquidity_baking = vote} + +module State = struct + type t = {liquidity_baking : Toggle_vote_ema_repr.t} + + let encoding = + let open Data_encoding in + conv + (fun {liquidity_baking} -> liquidity_baking) + (fun liquidity_baking -> {liquidity_baking}) + (obj1 (req "liquidity_baking_toggle_ema" Toggle_vote_ema_repr.encoding)) + + let initial = {liquidity_baking = Toggle_vote_ema_repr.initial} +end + +let update ballot (state : State.t) : State.t = + { + liquidity_baking = + Toggle_vote_ema_repr.update ballot.liquidity_baking state.liquidity_baking; + } diff --git a/src/proto_alpha/lib_protocol/per_block_vote_repr.mli b/src/proto_alpha/lib_protocol/per_block_vote_repr.mli new file mode 100644 index 0000000000000000000000000000000000000000..dd90869189144fbcf016124cb8ad1bb4f352d8bc --- /dev/null +++ b/src/proto_alpha/lib_protocol/per_block_vote_repr.mli @@ -0,0 +1,58 @@ +(*****************************************************************************) +(* *) +(* Open Source License *) +(* Copyright (c) 2022 G.B. Fefe *) +(* *) +(* 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. *) +(* *) +(*****************************************************************************) + +(** A per-block ballot. *) +type t = {liquidity_baking : Toggle_vote_repr.t} + +(** Encoding for a per-block ballot where all toggle-vote fields are required. *) +val encoding : t Data_encoding.t + +(** Encoding for a per-block ballot where all toggle-vote fields have + [Pass] as default value . *) +val dft_encoding : t Data_encoding.t + +(** A default per block ballot where all toggle-votes are [Pass]. *) +val default : t + +(** Extracts a given toggle vote from a ballot. *) +val get_toggle_vote : Toggle_vote_name_repr.t -> t -> Toggle_vote_repr.t + +(** Update a given toggle vote from a ballot. *) +val set_toggle_vote : Toggle_vote_name_repr.t -> t -> Toggle_vote_repr.t -> t + +module State : sig + (** The current state for all pending per-block votes. *) + type t = {liquidity_baking : Toggle_vote_ema_repr.t} + + (** Encoding for current state of all pending per-block votes. *) + val encoding : t Data_encoding.t + + (** Initial statis for all pending per-block votes. *) + val initial : t +end + +(** Given a ballot and the old EMAs, compute the new EMAs. + See [Toggle_vote_ema_repr] for the computation details. *) +val update : t -> State.t -> State.t diff --git a/src/proto_alpha/lib_protocol/per_block_vote_storage.ml b/src/proto_alpha/lib_protocol/per_block_vote_storage.ml new file mode 100644 index 0000000000000000000000000000000000000000..2187373e95c3026633eee4b130c82c5da41d5b56 --- /dev/null +++ b/src/proto_alpha/lib_protocol/per_block_vote_storage.ml @@ -0,0 +1,70 @@ +(*****************************************************************************) +(* *) +(* Open Source License *) +(* Copyright (c) 2022 Nomadic Labs *) +(* Copyright (c) 2022 G.B. Fefe *) +(* *) +(* 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. *) +(* *) +(*****************************************************************************) + +open Per_block_vote_repr + +let get_ema ctxt vote = + let open Lwt_tzresult_syntax in + let* ema = Storage.Toggle_vote_ema.find ctxt vote in + match ema with + | None -> return Toggle_vote_ema_repr.initial + | Some ema -> return ema + +let set_ema = Storage.Toggle_vote_ema.add + +let get ctxt = + let open Lwt_tzresult_syntax in + let* liquidity_baking = get_ema ctxt Liquidity_baking in + return {State.liquidity_baking} + +let set ctxt state = + let open Lwt_result_syntax in + let {State.liquidity_baking} = state in + let*! ctxt = set_ema ctxt Liquidity_baking liquidity_baking in + Lwt.return ctxt + +let update ctxt ballots = + let open Lwt_tzresult_syntax in + let* emas = get ctxt in + let emas = Per_block_vote_repr.update ballots emas in + let*! ctxt = set ctxt emas in + return (ctxt, emas) + +let init ctxt = set ctxt State.initial + +module Migration_from_Jakarta = struct + let update ctxt = + let open Lwt_tzresult_syntax in + let*! ctxt = init ctxt in + let* lb_ema = + Storage.Liquidity_baking.Migration_from_Jakarta.Toggle_ema.get ctxt + in + let*! ctxt = + Storage.Liquidity_baking.Migration_from_Jakarta.Toggle_ema.remove ctxt + in + let*! ctxt = set_ema ctxt Liquidity_baking lb_ema in + return ctxt +end diff --git a/src/proto_alpha/lib_protocol/per_block_vote_storage.mli b/src/proto_alpha/lib_protocol/per_block_vote_storage.mli new file mode 100644 index 0000000000000000000000000000000000000000..e12b3f09473b7402d5085b0d9012ab93d59c05a9 --- /dev/null +++ b/src/proto_alpha/lib_protocol/per_block_vote_storage.mli @@ -0,0 +1,39 @@ +(*****************************************************************************) +(* *) +(* Open Source License *) +(* Copyright (c) 2022 Nomadic Labs *) +(* Copyright (c) 2022 G.B. Fefe *) +(* *) +(* 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. *) +(* *) +(*****************************************************************************) + +(** Updates in the context the current EMA value of each pending + toggle votes, and return the new values. *) +val update : + Raw_context.t -> + Per_block_vote_repr.t -> + (Raw_context.t * Per_block_vote_repr.State.t) tzresult Lwt.t + +(** Initializes the context with the initial EMA value for all toggle votes. *) +val init : Raw_context.t -> Raw_context.t Lwt.t + +module Migration_from_Jakarta : sig + val update : Raw_context.t -> Raw_context.t tzresult Lwt.t +end diff --git a/src/proto_alpha/lib_protocol/raw_context.ml b/src/proto_alpha/lib_protocol/raw_context.ml index f14d37096401f7938221f23a4d9fcd6eca786fbd..4a7bc8e9b5541f7b54a76a055069d68f653302cf 100644 --- a/src/proto_alpha/lib_protocol/raw_context.ml +++ b/src/proto_alpha/lib_protocol/raw_context.ml @@ -946,8 +946,6 @@ let prepare_first_block ~level ~timestamp ctxt = min_proposal_quorum = c.min_proposal_quorum; liquidity_baking_subsidy = c.liquidity_baking_subsidy; liquidity_baking_sunset_level = c.liquidity_baking_sunset_level; - liquidity_baking_toggle_ema_threshold = - c.liquidity_baking_toggle_ema_threshold; minimal_block_delay = c.minimal_block_delay; delay_increment_per_round = c.delay_increment_per_round; consensus_committee_size = c.consensus_committee_size; diff --git a/src/proto_alpha/lib_protocol/storage.ml b/src/proto_alpha/lib_protocol/storage.ml index f5f916ec2278e8c48213a5fd88676dfe9996293e..9f3e5ad75667f9bde4f8ae7e8903a8082b47b09f 100644 --- a/src/proto_alpha/lib_protocol/storage.ml +++ b/src/proto_alpha/lib_protocol/storage.ml @@ -1352,14 +1352,25 @@ module Pending_migration = struct return (ctxt, balance_updates, operation_results) end +module Toggle_vote_ema = + Make_indexed_data_storage + (Make_subcontext (Registered) (Raw_context) + (struct + let name = ["toggle_vote_emas"] + end)) + (Make_index (Toggle_vote_name_repr)) + (Toggle_vote_ema_repr) + module Liquidity_baking = struct - module Toggle_ema = - Make_single_data_storage (Registered) (Raw_context) - (struct - (* The old "escape" name is kept here to avoid migrating this. *) - let name = ["liquidity_baking_escape_ema"] - end) - (Encoding.Int32) + module Migration_from_Jakarta = struct + module Toggle_ema = + Make_single_data_storage (Ghost) (Raw_context) + (struct + (* The old "escape" name is kept here to avoid migrating this. *) + let name = ["liquidity_baking_escape_ema"] + end) + (Toggle_vote_ema_repr) + end module Cpmm_address = Make_single_data_storage (Registered) (Raw_context) diff --git a/src/proto_alpha/lib_protocol/storage.mli b/src/proto_alpha/lib_protocol/storage.mli index e6aa79faa30a4e6cd6930a5147047c545cf5c9f9..12f62c27c052c2097e2b83eb8a7e66e39407acf1 100644 --- a/src/proto_alpha/lib_protocol/storage.mli +++ b/src/proto_alpha/lib_protocol/storage.mli @@ -537,12 +537,20 @@ module Pending_migration : sig Lwt.t end +(** Exponential moving average (ema) of flags set in protocol_data.contents. **) +module Toggle_vote_ema : + Indexed_data_storage + with type t := Raw_context.t + and type key = Toggle_vote_name_repr.t + and type value = Toggle_vote_ema_repr.t + module Liquidity_baking : sig - (** Exponential moving average (ema) of flags set in protocol_data.contents. - The liquidity baking subsidy is not sent to the CPMM if this EMA is above - the threshold set in constants. **) - module Toggle_ema : - Single_data_storage with type t := Raw_context.t and type value = Int32.t + module Migration_from_Jakarta : sig + module Toggle_ema : + Single_data_storage + with type t := Raw_context.t + and type value = Toggle_vote_ema_repr.t + end (** Constant product market maker contract that receives liquidity baking subsidy. **) module Cpmm_address : diff --git a/src/proto_alpha/lib_protocol/test/helpers/block.ml b/src/proto_alpha/lib_protocol/test/helpers/block.ml index 8d941c7d07a97c3c5976741cc564c26d84a64977..c18bc074a5d5a269db571772ddcc55e23f497686 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/block.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/block.ml @@ -120,8 +120,7 @@ module Forge = struct Bytes.create Constants.proof_of_work_nonce_size let make_contents ?(proof_of_work_nonce = default_proof_of_work_nonce) - ~payload_hash ~payload_round - ?(liquidity_baking_toggle_vote = Liquidity_baking.LB_pass) + ~payload_hash ~payload_round ?(per_block_vote = Per_block_vote.default) ~seed_nonce_hash () = Block_header. { @@ -129,7 +128,7 @@ module Forge = struct payload_round; proof_of_work_nonce; seed_nonce_hash; - liquidity_baking_toggle_vote; + per_block_vote; } let make_shell ~level ~predecessor ~timestamp ~fitness ~operations_hash = @@ -179,8 +178,8 @@ module Forge = struct Array.to_list t let forge_header ?(locked_round = None) ?(payload_round = None) - ?(policy = By_round 0) ?timestamp ?(operations = []) - ?liquidity_baking_toggle_vote pred = + ?(policy = By_round 0) ?timestamp ?(operations = []) ?per_block_vote pred + = let pred_fitness = match Fitness.from_raw pred.header.shell.fitness with | Ok pred_fitness -> pred_fitness @@ -229,7 +228,7 @@ module Forge = struct let contents = make_contents ~seed_nonce_hash - ?liquidity_baking_toggle_vote + ?per_block_vote ~payload_hash ~payload_round () @@ -238,13 +237,12 @@ module Forge = struct (* compatibility only, needed by incremental *) let contents ?(proof_of_work_nonce = default_proof_of_work_nonce) - ?seed_nonce_hash - ?(liquidity_baking_toggle_vote = Liquidity_baking.LB_pass) ~payload_hash + ?seed_nonce_hash ?(per_block_vote = Per_block_vote.default) ~payload_hash ~payload_round () = { Block_header.proof_of_work_nonce; seed_nonce_hash; - liquidity_baking_toggle_vote; + per_block_vote; payload_hash; payload_round; } @@ -695,7 +693,7 @@ let apply header ?(operations = []) pred = >>=? fun (t, _metadata) -> return t let bake_with_metadata ?locked_round ?policy ?timestamp ?operation ?operations - ?payload_round ?check_size ~baking_mode ?liquidity_baking_toggle_vote pred = + ?payload_round ?check_size ~baking_mode ?per_block_vote pred = let operations = match (operation, operations) with | Some op, Some ops -> Some (op :: ops) @@ -709,15 +707,14 @@ let bake_with_metadata ?locked_round ?policy ?timestamp ?operation ?operations ?timestamp ?policy ?operations - ?liquidity_baking_toggle_vote + ?per_block_vote pred >>=? fun header -> Forge.sign_header header >>=? fun header -> apply_with_metadata ?policy ?check_size ~baking_mode header ?operations pred let bake ?(baking_mode = Application) ?payload_round ?locked_round ?policy - ?timestamp ?operation ?operations ?liquidity_baking_toggle_vote ?check_size - pred = + ?timestamp ?operation ?operations ?per_block_vote ?check_size pred = bake_with_metadata ?payload_round ~baking_mode @@ -726,7 +723,7 @@ let bake ?(baking_mode = Application) ?payload_round ?locked_round ?policy ?timestamp ?operation ?operations - ?liquidity_baking_toggle_vote + ?per_block_vote ?check_size pred >>=? fun (t, (_metadata : block_header_metadata)) -> return t @@ -736,18 +733,17 @@ let bake ?(baking_mode = Application) ?payload_round ?locked_round ?policy (* 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 ?per_block_vote n b = List.fold_left_es - (fun b _ -> bake ~baking_mode ?policy ?liquidity_baking_toggle_vote b) + (fun b _ -> bake ~baking_mode ?policy ?per_block_vote b) b (1 -- n) let bake_n_with_all_balance_updates ?(baking_mode = Application) ?policy - ?liquidity_baking_toggle_vote n b = + ?per_block_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 ?per_block_vote b >>=? fun (b, metadata) -> let balance_updates_rev = List.rev_append metadata.balance_updates balance_updates_rev @@ -832,14 +828,14 @@ let bake_n_with_origination_results ?(baking_mode = Application) ?policy n b = (1 -- n) >|=? 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 +let bake_n_with_toggle_ema ?(baking_mode = Application) ?policy ?per_block_vote + n b = + let initial_state = Per_block_vote.State.initial in List.fold_left_es (fun (b, _toggle_ema) _ -> - bake_with_metadata ~baking_mode ?policy ?liquidity_baking_toggle_vote b - >|=? fun (b, metadata) -> (b, metadata.liquidity_baking_toggle_ema)) - (b, initial_ema) + bake_with_metadata ~baking_mode ?policy ?per_block_vote b + >|=? fun (b, metadata) -> (b, metadata.per_block_vote)) + (b, initial_state) (1 -- n) let bake_until_cycle_end ?policy b = diff --git a/src/proto_alpha/lib_protocol/test/helpers/block.mli b/src/proto_alpha/lib_protocol/test/helpers/block.mli index 74ea23ec0fa25eaec5160c686c557445eafa8a2b..3443f51574f4d9f0e9fbffdd6e46f4a198a63831 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/block.mli +++ b/src/proto_alpha/lib_protocol/test/helpers/block.mli @@ -68,7 +68,7 @@ module Forge : sig val contents : ?proof_of_work_nonce:Bytes.t -> ?seed_nonce_hash:Nonce_hash.t -> - ?liquidity_baking_toggle_vote:Liquidity_baking.liquidity_baking_toggle_vote -> + ?per_block_vote:Per_block_vote.t -> payload_hash:Block_payload_hash.t -> payload_round:Round.t -> unit -> @@ -86,7 +86,7 @@ module Forge : sig ?policy:baker_policy -> ?timestamp:Timestamp.time -> ?operations:Operation.packed list -> - ?liquidity_baking_toggle_vote:Liquidity_baking.liquidity_baking_toggle_vote -> + ?per_block_vote:Per_block_vote.t -> t -> header tzresult Lwt.t @@ -191,7 +191,7 @@ val bake : ?timestamp:Timestamp.time -> ?operation:Operation.packed -> ?operations:Operation.packed list -> - ?liquidity_baking_toggle_vote:Liquidity_baking.liquidity_baking_toggle_vote -> + ?per_block_vote:Per_block_vote.t -> ?check_size:bool -> t -> t tzresult Lwt.t @@ -200,7 +200,7 @@ val bake : val bake_n : ?baking_mode:baking_mode -> ?policy:baker_policy -> - ?liquidity_baking_toggle_vote:Liquidity_baking.liquidity_baking_toggle_vote -> + ?per_block_vote:Per_block_vote.t -> int -> t -> block tzresult Lwt.t @@ -210,7 +210,7 @@ val bake_n : val bake_n_with_all_balance_updates : ?baking_mode:baking_mode -> ?policy:baker_policy -> - ?liquidity_baking_toggle_vote:Liquidity_baking.liquidity_baking_toggle_vote -> + ?per_block_vote:Per_block_vote.t -> int -> t -> (block * Alpha_context.Receipt.balance_updates) tzresult Lwt.t @@ -230,13 +230,13 @@ val bake_n_with_origination_results : Lwt.t (** Version of bake_n that returns the liquidity baking toggle EMA after [n] blocks. **) -val bake_n_with_liquidity_baking_toggle_ema : +val bake_n_with_toggle_ema : ?baking_mode:baking_mode -> ?policy:baker_policy -> - ?liquidity_baking_toggle_vote:Liquidity_baking.liquidity_baking_toggle_vote -> + ?per_block_vote:Per_block_vote.t -> int -> t -> - (block * Alpha_context.Liquidity_baking.Toggle_EMA.t) tzresult Lwt.t + (block * Alpha_context.Per_block_vote.State.t) tzresult Lwt.t val current_cycle : t -> Cycle.t tzresult Lwt.t 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 78c42d5fce1b8dc2f4017213e64ce34f8edbd1bf..95f4512b43ea14cfc603361710f7ebcd6e5c7739 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 @@ -147,6 +147,12 @@ let liquidity_baking_sunset_level n () = expected_credit >>=? fun () -> return_unit +let lb_pass = {Alpha_context.Per_block_vote.liquidity_baking = Pass} + +let lb_off = {Alpha_context.Per_block_vote.liquidity_baking = Off} + +let lb_on = {Alpha_context.Per_block_vote.liquidity_baking = On} + (* 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)]. *) @@ -160,19 +166,15 @@ let liquidity_baking_toggle ~n_vote_on ~n_vote_off ~n_vote_pass expected_level >>=? fun liquidity_baking_subsidy -> let rec bake_stopping blk i = if i < expected_level then - Block.bake_n ~liquidity_baking_toggle_vote:LB_on n_vote_on blk - >>=? fun blk -> - Block.bake_n ~liquidity_baking_toggle_vote:LB_off n_vote_off blk - >>=? fun blk -> - Block.bake_n ~liquidity_baking_toggle_vote:LB_pass n_vote_pass blk - >>=? fun blk -> + Block.bake_n ~per_block_vote:lb_on n_vote_on blk >>=? fun blk -> + Block.bake_n ~per_block_vote:lb_off n_vote_off blk >>=? fun blk -> + Block.bake_n ~per_block_vote:lb_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 - >>=? fun blk -> + Block.bake_n ~per_block_vote:lb_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) >>?= fun expected_final_balance -> @@ -184,19 +186,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 = 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 = 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 = 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 = Off. Subsidy should not be stopped. *) let liquidity_baking_toggle_50 n () = Context.init1 ~consensus_threshold:0 () >>=? fun (blk, _contract) -> @@ -207,8 +209,8 @@ let liquidity_baking_toggle_50 n () = Context.Contract.balance (B blk) liquidity_baking >>=? fun old_balance -> let rec bake_50_percent_escaping blk i = if i < Int32.to_int sunset + n then - Block.bake ~liquidity_baking_toggle_vote:LB_on blk >>=? fun blk -> - Block.bake ~liquidity_baking_toggle_vote:LB_off blk >>=? fun blk -> + Block.bake ~per_block_vote:lb_on blk >>=? fun blk -> + Block.bake ~per_block_vote:lb_off blk >>=? fun blk -> bake_50_percent_escaping blk (i + 2) else return blk in @@ -225,24 +227,24 @@ let liquidity_baking_toggle_50 n () = expected_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 On votes regain majority. + Bake n_votes with Off, check that the subsidy is paused, bake + n_votes with 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 ~per_block_vote:lb_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 ~per_block_vote:lb_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 ~per_block_vote:lb_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 ~per_block_vote:lb_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 -> @@ -260,20 +262,19 @@ 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 - >>=? fun blk -> - Block.bake_n ~liquidity_baking_toggle_vote:LB_off n_vote_off blk - >>=? fun blk -> bake_escaping blk (i + n_vote_on + n_vote_off) + Block.bake_n ~per_block_vote:lb_on n_vote_on blk >>=? fun blk -> + Block.bake_n ~per_block_vote:lb_off n_vote_off blk >>=? fun blk -> + bake_escaping blk (i + n_vote_on + n_vote_off) else return blk in bake_escaping blk 0 >>=? fun blk -> (* We only need to return the toggle EMA at the end. *) - Block.bake_n_with_liquidity_baking_toggle_ema bake_after blk - >>=? fun (_blk, toggle_ema) -> + Block.bake_n_with_toggle_ema bake_after blk >>=? fun (_blk, toggle_ema) -> Assert.leq_int ~loc:__LOC__ - (toggle_ema |> Alpha_context.Liquidity_baking.Toggle_EMA.to_int32 - |> Int32.to_int) + (toggle_ema.liquidity_baking + |> Alpha_context.Toggle_vote.Ema.Internal_for_tests.to_int32 |> Int32.to_int + ) expected_toggle_ema >>=? fun () -> return_unit @@ -481,48 +482,48 @@ let tests = `Quick (liquidity_baking_sunset_level 100); Tztest.tztest - "test liquidity baking toggle vote with 100% of bakers voting LB_off \ - baking one block longer" + "test liquidity baking toggle vote with 100% of bakers voting Off baking \ + one block longer" `Quick (liquidity_baking_toggle_100 1); Tztest.tztest - "test liquidity baking toggle vote with 100% of bakers voting LB_off \ - baking two blocks longer" + "test liquidity baking toggle vote with 100% of bakers voting Off baking \ + two blocks longer" `Quick (liquidity_baking_toggle_100 2); Tztest.tztest - "test liquidity baking toggle vote with 100% of bakers voting LB_off \ - baking 100 blocks longer" + "test liquidity baking toggle vote with 100% of bakers voting Off baking \ + 100 blocks longer" `Quick (liquidity_baking_toggle_100 100); Tztest.tztest - "test liquidity baking toggle vote with 80% of bakers voting LB_off \ - baking one block longer" + "test liquidity baking toggle vote with 80% of bakers voting Off baking \ + one block longer" `Quick (liquidity_baking_toggle_80 1); Tztest.tztest - "test liquidity baking toggle vote with 80% of bakers voting LB_off \ - baking two blocks longer" + "test liquidity baking toggle vote with 80% of bakers voting Off baking \ + two blocks longer" `Quick (liquidity_baking_toggle_80 2); Tztest.tztest - "test liquidity baking toggle vote with 80% of bakers voting LB_off \ - baking 100 blocks longer" + "test liquidity baking toggle vote with 80% of bakers voting Off baking \ + 100 blocks longer" `Quick (liquidity_baking_toggle_80 100); Tztest.tztest - "test liquidity baking toggle vote with 60% of bakers voting LB_off \ - baking one block longer" + "test liquidity baking toggle vote with 60% of bakers voting Off baking \ + one block longer" `Quick (liquidity_baking_toggle_60 1); Tztest.tztest - "test liquidity baking toggle vote with 60% of bakers voting LB_off \ - baking two blocks longer" + "test liquidity baking toggle vote with 60% of bakers voting Off baking \ + two blocks longer" `Quick (liquidity_baking_toggle_60 2); Tztest.tztest - "test liquidity baking toggle vote with 60% of bakers voting LB_off \ - baking 100 blocks longer" + "test liquidity baking toggle vote with 60% of bakers voting Off baking \ + 100 blocks longer" `Quick (liquidity_baking_toggle_60 100); Tztest.tztest @@ -547,7 +548,7 @@ let tests = (liquidity_baking_restart 2000 1); Tztest.tztest "test liquidity baking toggle ema in block metadata is zero with no \ - bakers voting LB_off." + bakers voting Off." `Quick liquidity_baking_toggle_ema_zero; Tztest.tztest diff --git a/src/proto_alpha/lib_protocol/test/unit/main.ml b/src/proto_alpha/lib_protocol/test/unit/main.ml index b99d723fcd8cca9fdcd10fc23d9e773e45d2650f..efc93a50edbe2ee28228c7a6b2cc35c9efb876bb 100644 --- a/src/proto_alpha/lib_protocol/test/unit/main.ml +++ b/src/proto_alpha/lib_protocol/test/unit/main.ml @@ -72,7 +72,7 @@ let () = Unit_test.spec "sc rollup game" Test_sc_rollup_game.tests; Unit_test.spec "tx rollup l2" Test_tx_rollup_l2.tests; Unit_test.spec "tx rollup l2 apply" Test_tx_rollup_l2_apply.tests; - Unit_test.spec "liquidity baking" Test_liquidity_baking_repr.tests; + Unit_test.spec "toggle vote ema" Test_toggle_vote_ema_repr.tests; Unit_test.spec "sc rollup arith" Test_sc_rollup_arith.tests; Unit_test.spec "merkle list" Test_merkle_list.tests; Unit_test.spec "sc rollup inbox" Test_sc_rollup_inbox.tests; diff --git a/src/proto_alpha/lib_protocol/test/unit/test_liquidity_baking_repr.ml b/src/proto_alpha/lib_protocol/test/unit/test_toggle_vote_ema_repr.ml similarity index 56% rename from src/proto_alpha/lib_protocol/test/unit/test_liquidity_baking_repr.ml rename to src/proto_alpha/lib_protocol/test/unit/test_toggle_vote_ema_repr.ml index ac40fa0600e82fdf3ab3901f92072ae4deb7f80b..2babb2ced9936ab209b1f3e21d16af830eed628c 100644 --- a/src/proto_alpha/lib_protocol/test/unit/test_liquidity_baking_repr.ml +++ b/src/proto_alpha/lib_protocol/test/unit/test_toggle_vote_ema_repr.ml @@ -25,176 +25,153 @@ (** Testing ------- - Component: Protocol Liquidity_baking_repr module + Component: Protocol Toggle_vote_ema_repr module Invocation: dune exec src/proto_alpha/lib_protocol/test/unit/main.exe \ - -- test "^\[Unit\] liquidity baking$" - Subject: Tests for the Liquidity_baking_repr module + -- test "^\[Unit\] toggle vote ema" + Subject: Tests for the Toggle_vote_ema_repr module *) open Protocol +open Toggle_vote_repr -let ema_of_int32 ema = - Liquidity_baking_repr.Toggle_EMA.of_int32 ema >|= Environment.wrap_tzresult +module Ema = struct + include Toggle_vote_ema_repr + include Internal_for_tests +end -let ema_to_int32 = Liquidity_baking_repr.Toggle_EMA.to_int32 - -let compute_new_ema ~toggle_vote ema = - Liquidity_baking_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 = +(* Folds [update] on a list of votes *) +let update_n toggle_votes initial_ema = List.fold_left - (fun ema toggle_vote -> - Liquidity_baking_repr.compute_new_ema ~toggle_vote ema) + (fun ema toggle_vote -> Ema.update toggle_vote ema) initial_ema toggle_votes - |> ema_to_int32 let ema_range = - [ - 0l; - 1l; - 10l; - 100l; - 1000l; - 10_000l; - 100_000l; - 1_000_000l; - 10_000_000l; - 100_000_000l; - 200_000_000l; - 300_000_000l; - 400_000_000l; - 500_000_000l; - 600_000_000l; - 760_000_000l; - 800_000_000l; - 900_000_000l; - 1_000_000_000l; - 1_100_000_000l; - 1_200_000_000l; - 1_300_000_000l; - 1_400_000_000l; - 1_500_000_000l; - 1_600_000_000l; - 1_700_000_000l; - 1_800_000_000l; - 1_900_000_000l; - 1_990_000_000l; - 1_999_000_000l; - 1_999_900_000l; - 1_999_990_000l; - 1_999_999_000l; - 1_999_999_900l; - 1_999_999_990l; - 1_999_999_999l; - 2_000_000_000l; - ] + List.map + Ema.Internal_for_tests.of_int32_exn + [ + 0l; + 1l; + 10l; + 100l; + 1000l; + 10_000l; + 100_000l; + 1_000_000l; + 10_000_000l; + 100_000_000l; + 200_000_000l; + 300_000_000l; + 400_000_000l; + 500_000_000l; + 600_000_000l; + 760_000_000l; + 800_000_000l; + 900_000_000l; + 1_000_000_000l; + 1_100_000_000l; + 1_200_000_000l; + 1_300_000_000l; + 1_400_000_000l; + 1_500_000_000l; + 1_600_000_000l; + 1_700_000_000l; + 1_800_000_000l; + 1_900_000_000l; + 1_990_000_000l; + 1_999_000_000l; + 1_999_900_000l; + 1_999_990_000l; + 1_999_999_000l; + 1_999_999_900l; + 1_999_999_990l; + 1_999_999_999l; + 2_000_000_000l; + ] + +module Assert = struct + include Assert + + let equal_ema ~__LOC__ ?(msg = "") a b = + equal ~loc:__LOC__ Ema.equal (msg ^ "EMA aren't equal") Ema.pp a b + + let leq_ema ~__LOC__ ?(msg = "") a b = + leq ~loc:__LOC__ Ema.compare (msg ^ "EMA comparison") Ema.pp a b + + let lt_ema ~__LOC__ ?(msg = "") a b = + lt ~loc:__LOC__ Ema.compare (msg ^ "EMA comparison") Ema.pp a b + + let in_range_ema ~__LOC__ ?(msg = "") a = + leq ~loc:__LOC__ Ema.compare (msg ^ "EMA comparison") Ema.pp Ema.min_value a + >>=? fun () -> + leq ~loc:__LOC__ Ema.compare (msg ^ "EMA comparison") Ema.pp a Ema.max_value +end (* Test that new_ema = old_ema when voting Pass. *) let test_ema_pass () = List.iter_es - (fun old_ema -> - ema_of_int32 old_ema >>=? fun ema -> - Assert.equal_int32 - ~loc:__LOC__ - (compute_new_ema ~toggle_vote:LB_pass ema) - old_ema) + (fun ema -> Assert.equal_ema ~__LOC__ (Ema.update Pass ema) ema) ema_range (* Test that new_ema is still between 0 and 2,000,000,000 after an Off vote. *) 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 - Assert.leq_int32 ~loc:__LOC__ 0l new_ema >>=? fun () -> - Assert.leq_int32 ~loc:__LOC__ new_ema 2_000_000_000l) + (fun ema -> Assert.in_range_ema ~__LOC__ (Ema.update Off ema)) ema_range (* Test that new_ema > old_ema when voting Off, except if old_ema is already very close to the upper bound. *) let test_ema_increases_off () = List.iter_es - (fun old_ema -> - ema_of_int32 old_ema >>=? fun ema -> - Assert.lt_int32 - ~loc:__LOC__ - old_ema - (compute_new_ema ~toggle_vote:LB_off ema)) - (List.filter (fun ema -> Compare.Int32.(ema < 1_999_999_000l)) ema_range) + (fun ema -> Assert.lt_ema ~__LOC__ ema (Ema.update Off ema)) + (List.filter (fun ema -> Ema.(ema < of_int32_exn 1_999_999_000l)) ema_range) (* Test that the increase in EMA caused by an Off vote is bounded by 1,000,000 *) let test_ema_increases_off_bound () = List.iter_es - (fun old_ema -> - ema_of_int32 old_ema >>=? fun ema -> + (fun ema -> Assert.leq_int32 ~loc:__LOC__ - (Int32.sub (compute_new_ema ~toggle_vote:LB_off ema) old_ema) + (Int32.sub (Ema.to_int32 (Ema.update Off ema)) (Ema.to_int32 ema)) 1_000_000l) ema_range (* Test that new_ema is still between 0 and 2,000,000,000 after an Off vote. *) 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 - Assert.leq_int32 ~loc:__LOC__ 0l new_ema >>=? fun () -> - Assert.leq_int32 ~loc:__LOC__ new_ema 2_000_000_000l) + (fun ema -> Assert.in_range_ema ~__LOC__ (Ema.update On ema)) ema_range (* Test that new_ema < old_ema when voting On, except if old_ema is already very close to the lower bound. *) let test_ema_decreases_on () = List.iter_es - (fun old_ema -> - ema_of_int32 old_ema >>=? fun ema -> - Assert.lt_int32 - ~loc:__LOC__ - (compute_new_ema ~toggle_vote:LB_on ema) - old_ema) - (List.filter (fun ema -> Compare.Int32.(ema > 1000l)) ema_range) + (fun ema -> Assert.lt_ema ~__LOC__ (Ema.update On ema) ema) + (List.filter (fun ema -> Ema.(of_int32_exn 1000l < ema)) ema_range) (* Test that the decrease in EMA caused by an On vote is bounded by 1,000,000 *) let test_ema_decreases_on_bound () = List.iter_es - (fun old_ema -> - ema_of_int32 old_ema >>=? fun ema -> + (fun ema -> Assert.leq_int32 ~loc:__LOC__ - (Int32.sub (compute_new_ema ~toggle_vote:LB_on ema) old_ema) + (Int32.sub (Ema.to_int32 ema) (Ema.to_int32 (Ema.update On ema))) 1_000_000l) ema_range (* Test that 1385 Off votes are needed to reach the threshold from 0. *) let test_ema_many_off () = - let open Liquidity_baking_repr in - 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) - 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) + let ema = update_n (Stdlib.List.init 1385 (fun _ -> Off)) Ema.initial in + Assert.leq_ema ~__LOC__ ema Ema.threshold >>=? fun () -> + let ema = Ema.update Off ema in + Assert.leq_ema ~__LOC__ Ema.threshold ema >>=? fun () -> return_unit (* 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 - ema_of_int32 2_000_000_000l >>=? fun initial_ema -> - Assert.leq_int32 - ~loc:__LOC__ - 1_000_000_000l - (compute_new_ema_n (Stdlib.List.init 1385 (fun _ -> LB_on)) initial_ema) - >>=? fun () -> - Assert.leq_int32 - ~loc:__LOC__ - (compute_new_ema_n (Stdlib.List.init 1386 (fun _ -> LB_on)) initial_ema) - 1_000_000_000l + let ema = update_n (Stdlib.List.init 1385 (fun _ -> On)) Ema.max_value in + Assert.leq_ema ~__LOC__ Ema.threshold ema >>=? fun () -> + let ema = Ema.update On ema in + Assert.leq_ema ~__LOC__ ema Ema.threshold >>=? fun () -> return_unit (* Test that the EMA update function is symmetric: from two dual values of the EMA (that is, two values x and y such that @@ -204,15 +181,16 @@ let test_ema_many_on () = let test_ema_symmetry () = List.iter_es (fun ema -> - 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 opposite_ema = + Ema.of_int32_exn + Int32.(sub (Ema.to_int32 Ema.max_value) (Ema.to_int32 ema)) + in Assert.equal_int32 ~loc:__LOC__ - Int32.(add new_ema new_opposite_ema) - 2_000_000_000l) + (Int32.add + (Ema.to_int32 (Ema.update On ema)) + (Ema.to_int32 (Ema.update Off opposite_ema))) + (Ema.to_int32 Ema.max_value)) ema_range let tests = diff --git a/src/proto_alpha/lib_protocol/toggle_vote_ema_repr.ml b/src/proto_alpha/lib_protocol/toggle_vote_ema_repr.ml new file mode 100644 index 0000000000000000000000000000000000000000..1e86ba468c50502bf29bee4f880ca787a7d2fa08 --- /dev/null +++ b/src/proto_alpha/lib_protocol/toggle_vote_ema_repr.ml @@ -0,0 +1,87 @@ +(*****************************************************************************) +(* *) +(* Open Source License *) +(* Copyright (c) 2022 Nomadic Labs *) +(* Copyright (c) 2022 G.B. Fefe *) +(* *) +(* 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. *) +(* *) +(*****************************************************************************) + +include Compare.Int32 (* Invariant 0 <= ema <= 2_000_000_000l *) + +let pp ppf = Format.fprintf ppf "%ld" + +let min_value = 0l + +let max_value = 2_000_000_000l + +let check_bounds x = min_value <= x && x <= max_value + +let of_int32_exn x = if check_bounds x then x else assert false + +let of_int32_err x = + if check_bounds x then Ok x + else Error "Toggle_vote.EMA.of_int32: out of bounds" + +let to_int32 ema = ema + +(* We perform the computations in Z to avoid overflows. *) + +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 (of_int32 ema) z_1_000_000_000)) |> to_int32) + +let encoding = Data_encoding.(conv_with_guard to_int32 of_int32_err int32) + +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_500_000 = Z.of_int 500_000 + +let update_ema_off = recenter (fun ema -> Z.add (attenuate ema) z_500_000) + +let update_ema_on = recenter (fun ema -> Z.sub (attenuate ema) z_500_000) + +let initial = of_int32_exn 0l + +let threshold = of_int32_exn 1_000_000_000l + +let update vote ema = + let open Toggle_vote_repr in + match vote with + | Pass -> ema + | Off -> update_ema_off ema + | On -> update_ema_on ema + +let below_threshold ema = ema < threshold + +module Internal_for_tests = struct + let of_int32_exn = of_int32_exn + + let to_int32 = to_int32 +end diff --git a/src/proto_alpha/lib_protocol/liquidity_baking_repr.mli b/src/proto_alpha/lib_protocol/toggle_vote_ema_repr.mli similarity index 58% rename from src/proto_alpha/lib_protocol/liquidity_baking_repr.mli rename to src/proto_alpha/lib_protocol/toggle_vote_ema_repr.mli index a41f80d5835b3211fbad71bd7e4dee7f7fb3fd2c..e66aa7a52b3c1a4b8b8fd7a1f520e02e28fd6ea7 100644 --- a/src/proto_alpha/lib_protocol/liquidity_baking_repr.mli +++ b/src/proto_alpha/lib_protocol/toggle_vote_ema_repr.mli @@ -1,8 +1,8 @@ (*****************************************************************************) (* *) (* Open Source License *) -(* Copyright (c) 2021 Tocqueville Group, Inc. *) (* Copyright (c) 2022 Nomadic Labs *) +(* Copyright (c) 2022 G.B. Fefe *) (* *) (* 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,36 @@ (* *) (*****************************************************************************) -(** Options available for the Liquidity Baking per-block vote *) +(** Exponential moving average of toggle votes. Represented as int32 + between 0 and 2,000,000,000. *) +type t -type liquidity_baking_toggle_vote = LB_on | LB_off | LB_pass +val pp : Format.formatter -> t -> unit -val liquidity_baking_toggle_vote_encoding : - liquidity_baking_toggle_vote Data_encoding.encoding +val encoding : t Data_encoding.t -(** 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]. *) +include Compare.S with type t := t -module Toggle_EMA : sig - type t +(** Lowest bound for [t]. Currently 0. *) +val min_value : t - val of_int32 : Int32.t -> t tzresult Lwt.t +(** Upper bound for [t]. Currently 2,000,000,000. *) +val max_value : t - val zero : t +(** Initial value for the EMA. Currently 0. *) +val initial : t - val to_int32 : t -> Int32.t - - val encoding : t Data_encoding.t +(** Threshold value for the EMA. Currently 1,000,000,000. *) +val threshold : t - val ( < ) : t -> Int32.t -> bool -end +(** Compute the next EMA for a given vote. *) +val update : Toggle_vote_repr.t -> t -> t -(** [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]. +(** Test if the provided EMA is below the threshold. *) +val below_threshold : t -> bool - 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). +module Internal_for_tests : sig + val of_int32_exn : Int32.t -> t - 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 to_int32 : t -> Int32.t +end diff --git a/src/proto_alpha/lib_protocol/toggle_vote_name_repr.ml b/src/proto_alpha/lib_protocol/toggle_vote_name_repr.ml new file mode 100644 index 0000000000000000000000000000000000000000..0a63f3a97a7cea70e9df75e6b717ddf8ad331295 --- /dev/null +++ b/src/proto_alpha/lib_protocol/toggle_vote_name_repr.ml @@ -0,0 +1,64 @@ +(*****************************************************************************) +(* *) +(* Open Source License *) +(* Copyright (c) 2022 G.B. Fefe *) +(* *) +(* 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. *) +(* *) +(*****************************************************************************) + +type t = Liquidity_baking + +let to_string = function Liquidity_baking -> "liquidity_baking" + +let of_string_opt = function + | "liquidity_baking" -> Some Liquidity_baking + | _ -> None + +let of_string_err name = + match of_string_opt name with + | Some vote -> Ok vote + | None -> Error "invalid name of toggle vote" + +let pp ppf v = Format.pp_print_string ppf (to_string v) + +let all = [Liquidity_baking] + +let encoding = + let open Data_encoding in + def "toggle_vote_name" + @@ conv + (fun Liquidity_baking -> ()) + (fun () -> Liquidity_baking) + (constant "liquidity_baking") + +let path_length = 1 + +let to_path v l = to_string v :: l + +let of_path = function [] | _ :: _ :: _ -> None | [c] -> of_string_opt c + +let rpc_arg = + RPC_arg.make + ~name:"toggle_vote" + ~destruct:of_string_err + ~construct:to_string + () + +let compare a b = match (a, b) with Liquidity_baking, Liquidity_baking -> 0 diff --git a/src/proto_alpha/lib_protocol/toggle_vote_name_repr.mli b/src/proto_alpha/lib_protocol/toggle_vote_name_repr.mli new file mode 100644 index 0000000000000000000000000000000000000000..ef3bad1c89f36ceefb751a1e67b49efc30090968 --- /dev/null +++ b/src/proto_alpha/lib_protocol/toggle_vote_name_repr.mli @@ -0,0 +1,34 @@ +(*****************************************************************************) +(* *) +(* Open Source License *) +(* Copyright (c) 2022 G.B. Fefe *) +(* *) +(* 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. *) +(* *) +(*****************************************************************************) + +(** The per-block toggle votes. *) +type t = Liquidity_baking + +val pp : Format.formatter -> t -> unit + +include Storage_description.INDEX with type t := t + +(** The list of all per-block toggle votes. *) +val all : t list diff --git a/src/proto_alpha/lib_protocol/toggle_vote_repr.ml b/src/proto_alpha/lib_protocol/toggle_vote_repr.ml new file mode 100644 index 0000000000000000000000000000000000000000..9d45900e804469b5807d5d9dd2d26626a520f12c --- /dev/null +++ b/src/proto_alpha/lib_protocol/toggle_vote_repr.ml @@ -0,0 +1,35 @@ +(*****************************************************************************) +(* *) +(* Open Source License *) +(* Copyright (c) 2022 Nomadic Labs *) +(* Copyright (c) 2022 G.B. Fefe *) +(* *) +(* 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. *) +(* *) +(*****************************************************************************) + +type t = On | Off | Pass + +let encoding = + let open Data_encoding in + def "toggle_vote" @@ string_enum [("on", On); ("off", Off); ("pass", Pass)] + +let to_string = function Pass -> "pass" | Off -> "off" | On -> "on" + +let pp ppf v = Format.pp_print_string ppf (to_string v) diff --git a/src/proto_alpha/lib_protocol/toggle_vote_repr.mli b/src/proto_alpha/lib_protocol/toggle_vote_repr.mli new file mode 100644 index 0000000000000000000000000000000000000000..0f9d0c92f0d34a9238f186d77259930cb3077387 --- /dev/null +++ b/src/proto_alpha/lib_protocol/toggle_vote_repr.mli @@ -0,0 +1,32 @@ +(*****************************************************************************) +(* *) +(* Open Source License *) +(* Copyright (c) 2022 Nomadic Labs *) +(* Copyright (c) 2022 G.B. Fefe *) +(* *) +(* Permission is hereby granted, free of charge, to any person obtaining a *) +(* copy of this software and associated documentation files (the "Software"),*) +(* to deal in the Software without restriction, including without limitation *) +(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *) +(* and/or sell copies of the Software, and to permit persons to whom the *) +(* Software is furnished to do so, subject to the following conditions: *) +(* *) +(* The above copyright notice and this permission notice shall be included *) +(* in all copies or substantial portions of the Software. *) +(* *) +(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*) +(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *) +(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *) +(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*) +(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *) +(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *) +(* DEALINGS IN THE SOFTWARE. *) +(* *) +(*****************************************************************************) + +(** Options available for toggle votes *) +type t = On | Off | Pass + +val pp : Format.formatter -> t -> unit + +val encoding : t Data_encoding.t diff --git a/tests_python/examples/example.py b/tests_python/examples/example.py index 82f3dc8cc9d92cdce65fa2576cdfa688978db695..883aa9c71ede616f66892ce8156ce00780c0c1d5 100644 --- a/tests_python/examples/example.py +++ b/tests_python/examples/example.py @@ -18,7 +18,7 @@ def scenario(): 0, ['bootstrap5'], proto=constants.ALPHA_DAEMON, - run_params=['--liquidity-baking-toggle-vote', 'pass'], + run_params=constants.TOGGLE_VOTE_BAKER_PARAMS, ) # Wait for second node to update its protocol to alpha, if not # it may not know yet the `wait_for_inclusion` operation which is diff --git a/tests_python/examples/test_example.py b/tests_python/examples/test_example.py index 7331a0666187167d6aa3511a2540ef71b68c98eb..93713d2595b318429bf3bb1ea1be3eec32c9f6ed 100644 --- a/tests_python/examples/test_example.py +++ b/tests_python/examples/test_example.py @@ -16,7 +16,7 @@ def sandbox() -> Iterator[Sandbox]: 0, [], proto=constants.ALPHA_DAEMON, - run_params=['--liquidity-baking-toggle-vote', 'pass'], + run_params=constants.TOGGLE_VOTE_BAKER_PARAMS, ) yield sandbox assert sandbox.are_daemons_alive() diff --git a/tests_python/scripts/run_node_baker.py b/tests_python/scripts/run_node_baker.py index b3cd6a702861ac00d4f1c6c469ec51cf5f2df61e..88f18cc579834ffdba928d4cbf85f4212fa2feb7 100755 --- a/tests_python/scripts/run_node_baker.py +++ b/tests_python/scripts/run_node_baker.py @@ -29,7 +29,7 @@ def scenario(contract, storage, round_duration, proto): 1, accounts, proto=proto_daemon, - run_params=['--liquidity-baking-toggle-vote', 'pass'], + run_params=constants.TOGGLE_VOTE_BAKER_PARAMS, ) client = sandbox.client(1) if contract: diff --git a/tests_python/scripts/run_testnet.py b/tests_python/scripts/run_testnet.py index 190ce4c9cbd7beacc2f10d00b35e5b42d401f451..03931a963a8dd26b5964c565265f5997c89b2fad 100755 --- a/tests_python/scripts/run_testnet.py +++ b/tests_python/scripts/run_testnet.py @@ -448,7 +448,7 @@ def scenario(round_duration, num_nodes, log_dir): accounts(i, num_nodes), proto=constants.ALPHA_DAEMON, log_levels=constants.TENDERBAKE_BAKER_LOG_LEVELS, - run_params=['--liquidity-baking-toggle-vote', 'pass'], + run_params=constants.TOGGLE_VOTE_BAKER_PARAMS, ) while 1: diff --git a/tests_python/tests_alpha/test_baker_endorser.py b/tests_python/tests_alpha/test_baker_endorser.py index 0a49d475ad5e001f46a531dc918c3b590c07d992..c30fb21a323449af719379033d8bf7f3098c5773 100644 --- a/tests_python/tests_alpha/test_baker_endorser.py +++ b/tests_python/tests_alpha/test_baker_endorser.py @@ -48,7 +48,7 @@ class TestAllDaemonsWithOperations: i, [f'bootstrap{5 - i}'], protocol.DAEMON, - run_params=['--liquidity-baking-toggle-vote', 'pass'], + run_params=constants.TOGGLE_VOTE_BAKER_PARAMS, ) def test_wait_for_protocol(self, sandbox: Sandbox): diff --git a/tests_python/tests_alpha/test_baker_operations_cli_options.py b/tests_python/tests_alpha/test_baker_operations_cli_options.py index 907e32f544e6938a85d735b36478517519934485..82cd56aa762871f4256905249a013c4b72b12473 100644 --- a/tests_python/tests_alpha/test_baker_operations_cli_options.py +++ b/tests_python/tests_alpha/test_baker_operations_cli_options.py @@ -339,9 +339,8 @@ class TestBakerExternalOperations: run_params=[ '--operations-pool', session['operations_file'], - '--liquidity-baking-toggle-vote', - 'pass', - ], + ] + + constants.TOGGLE_VOTE_BAKER_PARAMS, ) @pytest.mark.timeout(30) diff --git a/tests_python/tests_alpha/test_bootstrap.py b/tests_python/tests_alpha/test_bootstrap.py index 87b50aea9318677e4363ac88af10656ecfe0a2e7..724289dc4497dc7147f728d32b77a1081dbb243d 100644 --- a/tests_python/tests_alpha/test_bootstrap.py +++ b/tests_python/tests_alpha/test_bootstrap.py @@ -1,6 +1,7 @@ import time import pytest +from tools import constants from launchers.sandbox import Sandbox from . import protocol @@ -24,7 +25,7 @@ def add_fully_delegated_baker(sandbox: Sandbox, node: int, protocol: str): node, [], proto=protocol, - run_params=['--liquidity-baking-toggle-vote', 'pass'], + run_params=constants.TOGGLE_VOTE_BAKER_PARAMS, ) @@ -39,7 +40,7 @@ class TestThresholdZero: 0, ['bootstrap5'], proto=protocol.DAEMON, - run_params=['--liquidity-baking-toggle-vote', 'pass'], + run_params=constants.TOGGLE_VOTE_BAKER_PARAMS, ) def test_bootstrap(self, sandbox: Sandbox): @@ -60,7 +61,7 @@ class TestThresholdOne: 0, ['bootstrap5'], proto=protocol.DAEMON, - run_params=['--liquidity-baking-toggle-vote', 'pass'], + run_params=constants.TOGGLE_VOTE_BAKER_PARAMS, ) def test_bootstrap(self, sandbox: Sandbox): @@ -86,7 +87,7 @@ class TestThresholdTwo: 0, ['bootstrap5'], proto=protocol.DAEMON, - run_params=['--liquidity-baking-toggle-vote', 'pass'], + run_params=constants.TOGGLE_VOTE_BAKER_PARAMS, ) def test_add_nodes(self, sandbox: Sandbox): diff --git a/tests_python/tests_alpha/test_many_bakers.py b/tests_python/tests_alpha/test_many_bakers.py index b08bc4e2ecdb47c15238d3cf29767be72a10bf3a..a01a59d57edef2bd70668d878faf571ef3e9e9c5 100644 --- a/tests_python/tests_alpha/test_many_bakers.py +++ b/tests_python/tests_alpha/test_many_bakers.py @@ -25,7 +25,7 @@ class TestManyBakers: i, [f'bootstrap{i + 1}'], proto=protocol.DAEMON, - run_params=['--liquidity-baking-toggle-vote', 'pass'], + run_params=constants.TOGGLE_VOTE_BAKER_PARAMS, ) def test_wait(self): diff --git a/tests_python/tests_alpha/test_many_nodes.py b/tests_python/tests_alpha/test_many_nodes.py index e6a9eed2f7b149a8f9b46fef5ca5a5ad1bd826f8..6b371487db5d1da5f64fb8e43723b0490890ad32 100644 --- a/tests_python/tests_alpha/test_many_nodes.py +++ b/tests_python/tests_alpha/test_many_nodes.py @@ -34,7 +34,7 @@ class TestManyNodesBootstrap: i, [f'bootstrap{i + 1}'], proto=protocol.DAEMON, - run_params=['--liquidity-baking-toggle-vote', 'pass'], + run_params=constants.TOGGLE_VOTE_BAKER_PARAMS, ) def test_add_nodes(self, sandbox: Sandbox): diff --git a/tests_python/tests_alpha/test_mockup.py b/tests_python/tests_alpha/test_mockup.py index 1a39706f7306b7223f50a94588d1a021941e10b7..d56251cb865a102222e83f5290625d50d7fff92d 100644 --- a/tests_python/tests_alpha/test_mockup.py +++ b/tests_python/tests_alpha/test_mockup.py @@ -642,7 +642,6 @@ def _test_create_mockup_init_show_roundtrip( "blocks_per_commitment": 5, "blocks_per_cycle": 9, "preserved_cycles": 3, - "liquidity_baking_toggle_ema_threshold": 1000000000, "liquidity_baking_subsidy": "2500000", "liquidity_baking_sunset_level": 1024, "max_operations_time_to_live": 120, diff --git a/tests_python/tests_alpha/test_nonce_seed_revelation.py b/tests_python/tests_alpha/test_nonce_seed_revelation.py index 44ac88f405cc65890c4898337f545c4d6cbbd5c6..da9f820eff4466fb3708f8a4cba0575e902e6c0a 100644 --- a/tests_python/tests_alpha/test_nonce_seed_revelation.py +++ b/tests_python/tests_alpha/test_nonce_seed_revelation.py @@ -55,7 +55,7 @@ class TestNonceSeedRevelation: [f"bootstrap{i + 1}"], proto=protocol.DAEMON, log_levels=constants.TENDERBAKE_BAKER_LOG_LEVELS, - run_params=['--liquidity-baking-toggle-vote', 'pass'], + run_params=constants.TOGGLE_VOTE_BAKER_PARAMS, ) @pytest.mark.timeout(2 * TEST_DURATION) diff --git a/tests_python/tests_alpha/test_per_block_votes.py b/tests_python/tests_alpha/test_per_block_votes.py index 97493c6023a153fad71ed755f6e4a191dbf78819..51a12a439ee113ff6606046fa2632069128ff6ab 100644 --- a/tests_python/tests_alpha/test_per_block_votes.py +++ b/tests_python/tests_alpha/test_per_block_votes.py @@ -45,15 +45,15 @@ def check_baker_logs(sandbox: Sandbox, pattern: str) -> bool: def get_what_the_baker_votes_from_its_logs(sandbox: Sandbox) -> str: if not check_baker_logs( - sandbox, 'Voting on for liquidity baking toggle vote' + sandbox, 'Voting on for liquidity_baking toggle vote' ): return 'on' if not check_baker_logs( - sandbox, 'Voting off for liquidity baking toggle vote' + sandbox, 'Voting off for liquidity_baking toggle vote' ): return 'off' if not check_baker_logs( - sandbox, 'Voting pass for liquidity baking toggle vote' + sandbox, 'Voting pass for liquidity_baking toggle vote' ): return 'pass' return 'error' @@ -136,7 +136,7 @@ class TestAllPerBlockVotes: 0, ['bootstrap1'], proto=protocol.DAEMON, - run_params=['--liquidity-baking-toggle-vote', 'pass'], + run_params=constants.TOGGLE_VOTE_BAKER_PARAMS, ) def test_wait_for_protocol(self, sandbox: Sandbox): diff --git a/tests_python/tests_alpha/test_tenderbake.py b/tests_python/tests_alpha/test_tenderbake.py index 4f6d414d53452086c6275feab7b9ab6bac89cc0f..33988d38f00ffa8a58c26f6378d9f329a355adc6 100644 --- a/tests_python/tests_alpha/test_tenderbake.py +++ b/tests_python/tests_alpha/test_tenderbake.py @@ -41,7 +41,7 @@ class TestProtoTenderbake: [f'bootstrap{i + 1}'], proto=protocol.DAEMON, log_levels=constants.TENDERBAKE_BAKER_LOG_LEVELS, - run_params=['--liquidity-baking-toggle-vote', 'pass'], + run_params=constants.TOGGLE_VOTE_BAKER_PARAMS, ) def test_wait(self): diff --git a/tests_python/tests_alpha/test_tenderbake_bakers_restart.py b/tests_python/tests_alpha/test_tenderbake_bakers_restart.py index 37c5b8a455904013c917222e802feacbd83c0652..a295436856006f598cef35d82079329bf4de1cd4 100644 --- a/tests_python/tests_alpha/test_tenderbake_bakers_restart.py +++ b/tests_python/tests_alpha/test_tenderbake_bakers_restart.py @@ -48,7 +48,7 @@ class TestProtoTenderbake: [f'bootstrap{i + 1}'], proto=protocol.DAEMON, log_levels=constants.TENDERBAKE_BAKER_LOG_LEVELS, - run_params=['--liquidity-baking-toggle-vote', 'pass'], + run_params=constants.TOGGLE_VOTE_BAKER_PARAMS, ) def test_restart(self, sandbox): @@ -69,7 +69,7 @@ class TestProtoTenderbake: [f'bootstrap{dead_baker + 1}'], proto=protocol.DAEMON, log_levels=constants.TENDERBAKE_BAKER_LOG_LEVELS, - run_params=['--liquidity-baking-toggle-vote', 'pass'], + run_params=constants.TOGGLE_VOTE_BAKER_PARAMS, ) # the CYCLE_DUR is long enough for bakers to take a decision time.sleep(CYCLE_DUR) diff --git a/tests_python/tests_alpha/test_tenderbake_incremental_start.py b/tests_python/tests_alpha/test_tenderbake_incremental_start.py index df8d5db846e01c7cc7b537b4b5eeaffc8a922d84..41c81c265faf4e90a6e52de62630b18e8b12b681 100644 --- a/tests_python/tests_alpha/test_tenderbake_incremental_start.py +++ b/tests_python/tests_alpha/test_tenderbake_incremental_start.py @@ -38,7 +38,7 @@ class TestProtoTenderbakeIncrementalStart: [account], proto=protocol.DAEMON, log_levels=constants.TENDERBAKE_BAKER_LOG_LEVELS, - run_params=['--liquidity-baking-toggle-vote', 'pass'], + run_params=constants.TOGGLE_VOTE_BAKER_PARAMS, ) def test_activate(self, sandbox): @@ -64,7 +64,7 @@ class TestProtoTenderbakeIncrementalStart: [account], proto=protocol.DAEMON, log_levels=constants.TENDERBAKE_BAKER_LOG_LEVELS, - run_params=['--liquidity-baking-toggle-vote', 'pass'], + run_params=constants.TOGGLE_VOTE_BAKER_PARAMS, ) time.sleep(MINIMAL_BLOCK_DELAY) diff --git a/tests_python/tests_alpha/test_tenderbake_long_dynamic_bake.py b/tests_python/tests_alpha/test_tenderbake_long_dynamic_bake.py index b64008511772459460c00470b48457504ea442b5..25454068165a8e28b8558737a5f140c42d0b0406 100644 --- a/tests_python/tests_alpha/test_tenderbake_long_dynamic_bake.py +++ b/tests_python/tests_alpha/test_tenderbake_long_dynamic_bake.py @@ -77,7 +77,7 @@ def add_bakers(sandbox: Sandbox, nodes: Iterable[int]) -> None: [account], proto=protocol.DAEMON, log_levels=constants.TENDERBAKE_BAKER_LOG_LEVELS, - run_params=['--liquidity-baking-toggle-vote', 'pass'], + run_params=constants.TOGGLE_VOTE_BAKER_PARAMS, ) @@ -155,7 +155,7 @@ class TestAllDaemonsWithOperations: [f'bootstrap{dead_baker+1}'], proto=protocol.DAEMON, log_levels=constants.TENDERBAKE_BAKER_LOG_LEVELS, - run_params=['--liquidity-baking-toggle-vote', 'pass'], + run_params=constants.TOGGLE_VOTE_BAKER_PARAMS, ) # set the next baker to die dead_baker = baker diff --git a/tests_python/tests_alpha/test_voting_full.py b/tests_python/tests_alpha/test_voting_full.py index 9203fb194174b86c4ccd2a602e8cb59dd418877f..801f6f9df26c87b011f3971bc4e8b554e9e97ac6 100644 --- a/tests_python/tests_alpha/test_voting_full.py +++ b/tests_python/tests_alpha/test_voting_full.py @@ -110,7 +110,7 @@ class TestVotingFull: # """Add a baker per node""" # sandbox.add_baker( # 1, [f"bootstrap{i}" for i in range(1, 6)], proto=PROTO_B_DAEMON, - # run_params=['--liquidity-baking-toggle-vote', 'pass'], + # run_params=constants.TOGGLE_VOTE_BAKER_PARAMS, # ) def test_client_knows_proto_b(self, sandbox: Sandbox): @@ -181,12 +181,12 @@ class TestVotingFull: # we let a PROTO_A baker bake the last blocks of PROTO_A # sandbox.add_baker( # 0, [f"bootstrap{i}" for i in range(1, 6)], proto=PROTO_A_DAEMON, - # run_params=['--liquidity-baking-toggle-vote', 'pass'], + # run_params=constants.TOGGLE_VOTE_BAKER_PARAMS, # ) # for i in range(1,NUM_NODES): # sandbox.add_baker( # i, [f"bootstrap{i}"], proto=PROTO_B_DAEMON, - # run_params=['--liquidity-baking-toggle-vote', 'pass'], + # run_params=constants.TOGGLE_VOTE_BAKER_PARAMS, # ) clients = sandbox.all_clients() client = clients[0] diff --git a/tests_python/tools/constants.py b/tests_python/tools/constants.py index 0c53cc8ca5b35d79c87e4b075eb7135ff7b7ef1d..902056a70734b98291b5a302cc248e8de5d7d4ce 100644 --- a/tests_python/tools/constants.py +++ b/tests_python/tools/constants.py @@ -264,3 +264,5 @@ TENDERBAKE_NODE_LOG_LEVELS = { "validator.block": "debug", "validator.chain": "debug", } + +TOGGLE_VOTE_BAKER_PARAMS = ['--liquidity-baking-toggle-vote', 'pass'] diff --git a/tezt/tests/expected/RPC_test.ml/Alpha- (mode client) RPC regression tests- others.out b/tezt/tests/expected/RPC_test.ml/Alpha- (mode client) RPC regression tests- others.out index 2dcff75290479f62f622f4fd9437a6a0838ff0ea..5a306f5b36e8e19b44e937ea85b2e35a6c574501 100644 --- a/tezt/tests/expected/RPC_test.ml/Alpha- (mode client) RPC regression tests- others.out +++ b/tezt/tests/expected/RPC_test.ml/Alpha- (mode client) RPC regression tests- others.out @@ -18,11 +18,9 @@ "hard_storage_limit_per_operation": "60000", "quorum_min": 2000, "quorum_max": 7000, "min_proposal_quorum": 500, "liquidity_baking_subsidy": "2500000", - "liquidity_baking_sunset_level": 128, - "liquidity_baking_toggle_ema_threshold": 1000000000, - "max_operations_time_to_live": 120, "minimal_block_delay": "1", - "delay_increment_per_round": "1", "consensus_committee_size": 256, - "consensus_threshold": 0, + "liquidity_baking_sunset_level": 128, "max_operations_time_to_live": 120, + "minimal_block_delay": "1", "delay_increment_per_round": "1", + "consensus_committee_size": 256, "consensus_threshold": 0, "minimal_participation_ratio": { "numerator": 2, "denominator": 3 }, "max_slashing_period": 2, "frozen_deposits_percentage": 5, "double_baking_punishment": "640000000", diff --git a/tezt/tests/expected/RPC_test.ml/Alpha- (mode light) RPC regression tests- others.out b/tezt/tests/expected/RPC_test.ml/Alpha- (mode light) RPC regression tests- others.out index 56f90a3571b6112cd64b0f0a5aba352e96aac49d..9b1ba4659970319593f8e336431bf4551a4cd306 100644 --- a/tezt/tests/expected/RPC_test.ml/Alpha- (mode light) RPC regression tests- others.out +++ b/tezt/tests/expected/RPC_test.ml/Alpha- (mode light) RPC regression tests- others.out @@ -18,11 +18,9 @@ "hard_storage_limit_per_operation": "60000", "quorum_min": 2000, "quorum_max": 7000, "min_proposal_quorum": 500, "liquidity_baking_subsidy": "2500000", - "liquidity_baking_sunset_level": 128, - "liquidity_baking_toggle_ema_threshold": 1000000000, - "max_operations_time_to_live": 120, "minimal_block_delay": "1", - "delay_increment_per_round": "1", "consensus_committee_size": 256, - "consensus_threshold": 0, + "liquidity_baking_sunset_level": 128, "max_operations_time_to_live": 120, + "minimal_block_delay": "1", "delay_increment_per_round": "1", + "consensus_committee_size": 256, "consensus_threshold": 0, "minimal_participation_ratio": { "numerator": 2, "denominator": 3 }, "max_slashing_period": 2, "frozen_deposits_percentage": 5, "double_baking_punishment": "640000000", diff --git a/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy) RPC regression tests- others.out b/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy) RPC regression tests- others.out index 4be9e6a5203f21573513008c932ddc3e28b16d6f..85a52c8c43e2eef77b78a9ecb9f5a2b7ecd8bf8a 100644 --- a/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy) RPC regression tests- others.out +++ b/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy) RPC regression tests- others.out @@ -18,11 +18,9 @@ "hard_storage_limit_per_operation": "60000", "quorum_min": 2000, "quorum_max": 7000, "min_proposal_quorum": 500, "liquidity_baking_subsidy": "2500000", - "liquidity_baking_sunset_level": 128, - "liquidity_baking_toggle_ema_threshold": 1000000000, - "max_operations_time_to_live": 120, "minimal_block_delay": "1", - "delay_increment_per_round": "1", "consensus_committee_size": 256, - "consensus_threshold": 0, + "liquidity_baking_sunset_level": 128, "max_operations_time_to_live": 120, + "minimal_block_delay": "1", "delay_increment_per_round": "1", + "consensus_committee_size": 256, "consensus_threshold": 0, "minimal_participation_ratio": { "numerator": 2, "denominator": 3 }, "max_slashing_period": 2, "frozen_deposits_percentage": 5, "double_baking_punishment": "640000000", diff --git a/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy_server_data_dir) RPC regression tests- others.out b/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy_server_data_dir) RPC regression tests- others.out index e977b651c85034dcfae7848df0d8275290438f9a..06259540635c3ab8d84614c34850236c189f966a 100644 --- a/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy_server_data_dir) RPC regression tests- others.out +++ b/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy_server_data_dir) RPC regression tests- others.out @@ -18,11 +18,9 @@ "hard_storage_limit_per_operation": "60000", "quorum_min": 2000, "quorum_max": 7000, "min_proposal_quorum": 500, "liquidity_baking_subsidy": "2500000", - "liquidity_baking_sunset_level": 128, - "liquidity_baking_toggle_ema_threshold": 1000000000, - "max_operations_time_to_live": 120, "minimal_block_delay": "1", - "delay_increment_per_round": "1", "consensus_committee_size": 256, - "consensus_threshold": 0, + "liquidity_baking_sunset_level": 128, "max_operations_time_to_live": 120, + "minimal_block_delay": "1", "delay_increment_per_round": "1", + "consensus_committee_size": 256, "consensus_threshold": 0, "minimal_participation_ratio": { "numerator": 2, "denominator": 3 }, "max_slashing_period": 2, "frozen_deposits_percentage": 5, "double_baking_punishment": "640000000", diff --git a/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy_server_rpc) RPC regression tests- others.out b/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy_server_rpc) RPC regression tests- others.out index e977b651c85034dcfae7848df0d8275290438f9a..06259540635c3ab8d84614c34850236c189f966a 100644 --- a/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy_server_rpc) RPC regression tests- others.out +++ b/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy_server_rpc) RPC regression tests- others.out @@ -18,11 +18,9 @@ "hard_storage_limit_per_operation": "60000", "quorum_min": 2000, "quorum_max": 7000, "min_proposal_quorum": 500, "liquidity_baking_subsidy": "2500000", - "liquidity_baking_sunset_level": 128, - "liquidity_baking_toggle_ema_threshold": 1000000000, - "max_operations_time_to_live": 120, "minimal_block_delay": "1", - "delay_increment_per_round": "1", "consensus_committee_size": 256, - "consensus_threshold": 0, + "liquidity_baking_sunset_level": 128, "max_operations_time_to_live": 120, + "minimal_block_delay": "1", "delay_increment_per_round": "1", + "consensus_committee_size": 256, "consensus_threshold": 0, "minimal_participation_ratio": { "numerator": 2, "denominator": 3 }, "max_slashing_period": 2, "frozen_deposits_percentage": 5, "double_baking_punishment": "640000000", diff --git a/tezt/tests/expected/sc_rollup.ml/Alpha- observing the correct handling of commitments in the rollup node (no_comm.out b/tezt/tests/expected/sc_rollup.ml/Alpha- observing the correct handling of commitments in the rollup node (no_comm.out index 726b690845e6a58dcc39d5998ca55446f7cb5708..4da9e37fe8efcfa1eaafcc5e75e93413c32b25de 100644 --- a/tezt/tests/expected/sc_rollup.ml/Alpha- observing the correct handling of commitments in the rollup node (no_comm.out +++ b/tezt/tests/expected/sc_rollup.ml/Alpha- observing the correct handling of commitments in the rollup node (no_comm.out @@ -70,11 +70,9 @@ This sequence of operations was run: "hard_storage_limit_per_operation": "60000", "quorum_min": 2000, "quorum_max": 7000, "min_proposal_quorum": 500, "liquidity_baking_subsidy": "2500000", - "liquidity_baking_sunset_level": 128, - "liquidity_baking_toggle_ema_threshold": 1000000000, - "max_operations_time_to_live": 120, "minimal_block_delay": "1", - "delay_increment_per_round": "1", "consensus_committee_size": 256, - "consensus_threshold": 0, + "liquidity_baking_sunset_level": 128, "max_operations_time_to_live": 120, + "minimal_block_delay": "1", "delay_increment_per_round": "1", + "consensus_committee_size": 256, "consensus_threshold": 0, "minimal_participation_ratio": { "numerator": 2, "denominator": 3 }, "max_slashing_period": 2, "frozen_deposits_percentage": 5, "double_baking_punishment": "640000000", @@ -170,11 +168,9 @@ This sequence of operations was run: "hard_storage_limit_per_operation": "60000", "quorum_min": 2000, "quorum_max": 7000, "min_proposal_quorum": 500, "liquidity_baking_subsidy": "2500000", - "liquidity_baking_sunset_level": 128, - "liquidity_baking_toggle_ema_threshold": 1000000000, - "max_operations_time_to_live": 120, "minimal_block_delay": "1", - "delay_increment_per_round": "1", "consensus_committee_size": 256, - "consensus_threshold": 0, + "liquidity_baking_sunset_level": 128, "max_operations_time_to_live": 120, + "minimal_block_delay": "1", "delay_increment_per_round": "1", + "consensus_committee_size": 256, "consensus_threshold": 0, "minimal_participation_ratio": { "numerator": 2, "denominator": 3 }, "max_slashing_period": 2, "frozen_deposits_percentage": 5, "double_baking_punishment": "640000000",