From 0f6f1c36793f2c17245d1da161e5df06a7f33460 Mon Sep 17 00:00:00 2001 From: Diane Gallois-Wong Date: Fri, 29 Nov 2024 15:48:11 +0100 Subject: [PATCH 01/13] Proto/test: remove dead code on slashing percentage This is dead code since 7ad425345a74c02b8ab13bc09e113958d892de49 --- .../lib_protocol/test/helpers/scenario_op.ml | 24 ------------------- 1 file changed, 24 deletions(-) diff --git a/src/proto_alpha/lib_protocol/test/helpers/scenario_op.ml b/src/proto_alpha/lib_protocol/test/helpers/scenario_op.ml index 82480ed04efc..26295574d735 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/scenario_op.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/scenario_op.ml @@ -442,30 +442,6 @@ let cycle_from_level blocks_per_cycle level = let current_cycle = Cycle.add Cycle.root (Int32.to_int current_cycle) in current_cycle -let pct_from_kind (block : Block.t) = function - | Protocol.Misbehaviour_repr.Double_baking -> - Protocol.Percentage.to_q - block.constants.percentage_of_frozen_deposits_slashed_per_double_baking - |> Q.(mul (100 // 1)) - |> Q.to_int - | Double_attesting | Double_preattesting -> - Protocol.Percentage.to_q - block.constants - .percentage_of_frozen_deposits_slashed_per_double_attestation - |> Q.(mul (100 // 1)) - |> Q.to_int - -let get_pending_slashed_pct_for_delegate (block, state) delegate = - let rec aux r = function - | [] -> r - | (culprit, {Protocol.Denunciations_repr.misbehaviour; _}) :: t -> - if Signature.Public_key_hash.equal delegate culprit then - let new_r = r + pct_from_kind block misbehaviour.kind in - if new_r >= 100 then 100 else aux new_r t - else aux r t - in - aux 0 state.State.pending_slashes - let update_state_denunciation (block, state) {State.culprit; denounced; evidence = _; misbehaviour} = let open Lwt_result_syntax in -- GitLab From 8af2858ef60512ccd46b702467f076c78bb7bed3 Mon Sep 17 00:00:00 2001 From: Diane Gallois-Wong Date: Thu, 14 Nov 2024 12:27:09 +0100 Subject: [PATCH 02/13] Proto/test: remove test on ns_enable=false --- .../test/unit/test_slashing_percentage.ml | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/src/proto_alpha/lib_protocol/test/unit/test_slashing_percentage.ml b/src/proto_alpha/lib_protocol/test/unit/test_slashing_percentage.ml index e3ded8d6879d..78fec51e9b24 100644 --- a/src/proto_alpha/lib_protocol/test/unit/test_slashing_percentage.ml +++ b/src/proto_alpha/lib_protocol/test/unit/test_slashing_percentage.ml @@ -74,22 +74,6 @@ let get_pct ~ns_enable ~max_slashing_threshold ~max_slashing_per_block int_list map pkh_list -(** Test the double attesting slash is always 50% with ns_enable = false *) -let test_ns_enable_disable () = - let open Lwt_result_syntax in - let f x = - get_pct - ~ns_enable:false - ~max_slashing_threshold:100 - ~max_slashing_per_block:Percentage.p100 - [x] - in - let* () = assert_equal_int ~loc:__LOC__ 50 (f 0) in - let* () = assert_equal_int ~loc:__LOC__ 50 (f 1) in - let* () = assert_equal_int ~loc:__LOC__ 50 (f 100) in - let* () = assert_equal_int ~loc:__LOC__ 50 (f 10000) in - return_unit - (** We set ns_enable = true for the following tests *) let get_pct = get_pct ~ns_enable:true @@ -182,7 +166,6 @@ let test_mainnet_values () = let tests = Tztest. [ - tztest "Test ns_enable = false" `Quick test_ns_enable_disable; tztest "Test only sum of rights counts" `Quick test_list_and_sum; tztest "Test max_slashing_per_block" `Quick test_max_slashing_per_block; tztest "Test max_slashing_threshold" `Quick test_max_slashing_threshold; -- GitLab From 0d604b3bc90583cf2c9546f8ddcba4665bdd64bc Mon Sep 17 00:00:00 2001 From: Diane Gallois-Wong Date: Mon, 28 Oct 2024 11:02:15 +0100 Subject: [PATCH 03/13] Proto/test: remove ns_enable boilerplate --- .../test/helpers/constants_helpers.ml | 7 -- .../test/helpers/scenario_begin.ml | 7 +- .../test/helpers/state_ai_flags.ml | 90 ++++++++----------- .../test/helpers/state_ai_flags.mli | 7 -- .../integration/test_scenario_slashing.ml | 14 +-- .../test_scenario_slashing_stakers.ml | 2 - .../test/unit/test_slashing_percentage.ml | 13 +-- 7 files changed, 44 insertions(+), 96 deletions(-) diff --git a/src/proto_alpha/lib_protocol/test/helpers/constants_helpers.ml b/src/proto_alpha/lib_protocol/test/helpers/constants_helpers.ml index 0bcf3c37e8fa..afc90d9a9e60 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/constants_helpers.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/constants_helpers.ml @@ -93,10 +93,6 @@ module Set = struct percentage_of_frozen_deposits_slashed_per_double_baking (c : t) = {c with percentage_of_frozen_deposits_slashed_per_double_baking} - let percentage_of_frozen_deposits_slashed_per_double_attestation - percentage_of_frozen_deposits_slashed_per_double_attestation (c : t) = - {c with percentage_of_frozen_deposits_slashed_per_double_attestation} - let max_slashing_per_block max_slashing_per_block (c : t) = {c with max_slashing_per_block} @@ -140,9 +136,6 @@ module Set = struct let force_activation force_activation (c : t) = adaptive_issuance {c.adaptive_issuance with force_activation} c - let ns_enable ns_enable (c : t) = - adaptive_issuance {c.adaptive_issuance with ns_enable} c - let launch_ema_threshold launch_ema_threshold (c : t) = adaptive_issuance {c.adaptive_issuance with launch_ema_threshold} c diff --git a/src/proto_alpha/lib_protocol/test/helpers/scenario_begin.ml b/src/proto_alpha/lib_protocol/test/helpers/scenario_begin.ml index acf485e4256c..fa6d63420284 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/scenario_begin.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/scenario_begin.ml @@ -116,18 +116,13 @@ let init_constants ?(default = Test) ?(reward_per_block = 0L) (Protocol.Issuance_bonus_repr.max_bonus_parameter_of_Q_exn Q.zero) else Empty) --> set S.Adaptive_issuance.force_activation true - --> set S.Adaptive_issuance.ns_enable true (** Initialize the test, given some initial parameters *) let begin_test ?(burn_rewards = false) ?(force_attest_all = false) delegates_name_list : (constants, t) scenarios = exec (fun (constants : constants) -> let open Lwt_result_syntax in - let constants = - constants - |> S.Adaptive_issuance.force_activation true - |> S.Adaptive_issuance.ns_enable true - in + let constants = constants |> S.Adaptive_issuance.force_activation true in let bootstrap = "__bootstrap__" in let delegates_name_list = bootstrap :: delegates_name_list in (* Override threshold value if activate *) diff --git a/src/proto_alpha/lib_protocol/test/helpers/state_ai_flags.ml b/src/proto_alpha/lib_protocol/test/helpers/state_ai_flags.ml index 7aaa0b02903d..fcb6b2960f39 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/state_ai_flags.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/state_ai_flags.ml @@ -71,66 +71,52 @@ module AI = struct end module Delayed_slashing = struct - let enabled (state : State.t) = state.constants.adaptive_issuance.ns_enable - (* Returns a pair, fst is the delayed slashes, snd is the slashes to apply now *) let partition_slashes state current_cycle = - if not (enabled state) then ([], state.pending_slashes) - else - List.partition - (fun (_, Protocol.Denunciations_repr.{misbehaviour; _}) -> - let cycle = - Block.current_cycle_of_level - ~blocks_per_cycle: - state.constants - .Protocol.Alpha_context.Constants.Parametric.blocks_per_cycle - ~current_level: - (Protocol.Raw_level_repr.to_int32 misbehaviour.level) - in - Protocol.Alpha_context.Cycle.(cycle = current_cycle)) - state.pending_slashes + List.partition + (fun (_, Protocol.Denunciations_repr.{misbehaviour; _}) -> + let cycle = + Block.current_cycle_of_level + ~blocks_per_cycle: + state.constants + .Protocol.Alpha_context.Constants.Parametric.blocks_per_cycle + ~current_level:(Protocol.Raw_level_repr.to_int32 misbehaviour.level) + in + Protocol.Alpha_context.Cycle.(cycle = current_cycle)) + state.pending_slashes end module NS = struct - let enabled (block : Block.t) (state : State.t) = - AI.enabled block state && state.constants.adaptive_issuance.ns_enable - let get_double_attestation_slashing_percentage all_denunciations_to_apply - block_before_slash state (misbehaviour : Protocol.Misbehaviour_repr.t) = + block_before_slash _state (misbehaviour : Protocol.Misbehaviour_repr.t) = let open Lwt_result_wrap_syntax in (* We need to get the block before the slash, because after the slash, the context gets rid of the required Seed to recompute the rights for the misbehaving delegates. *) - if not (enabled block_before_slash state) then - return - state.constants - .percentage_of_frozen_deposits_slashed_per_double_attestation - else - let* alpha_ctxt = Context.(get_alpha_ctxt (B block_before_slash)) in - let raw_ctxt = - Protocol.Alpha_context.Internal_for_tests.to_raw alpha_ctxt - in - let level = - Protocol.Level_repr.level_from_raw - ~cycle_eras:(Protocol.Raw_context.cycle_eras raw_ctxt) - misbehaviour.level - in - let delegates = - List.filter - (fun (_, (den : Protocol.Denunciations_repr.item)) -> - Compare.Int.( - Protocol.Misbehaviour_repr.compare misbehaviour den.misbehaviour - = 0)) - all_denunciations_to_apply - |> List.map fst - |> List.sort_uniq Signature.Public_key_hash.compare - in - let*@ _, pct = - Protocol.Slash_percentage.get - raw_ctxt - ~kind:misbehaviour.kind - ~level - delegates - in - return pct + let* alpha_ctxt = Context.(get_alpha_ctxt (B block_before_slash)) in + let raw_ctxt = + Protocol.Alpha_context.Internal_for_tests.to_raw alpha_ctxt + in + let level = + Protocol.Level_repr.level_from_raw + ~cycle_eras:(Protocol.Raw_context.cycle_eras raw_ctxt) + misbehaviour.level + in + let delegates = + List.filter + (fun (_, (den : Protocol.Denunciations_repr.item)) -> + Compare.Int.( + Protocol.Misbehaviour_repr.compare misbehaviour den.misbehaviour = 0)) + all_denunciations_to_apply + |> List.map fst + |> List.sort_uniq Signature.Public_key_hash.compare + in + let*@ _, pct = + Protocol.Slash_percentage.get + raw_ctxt + ~kind:misbehaviour.kind + ~level + delegates + in + return pct end diff --git a/src/proto_alpha/lib_protocol/test/helpers/state_ai_flags.mli b/src/proto_alpha/lib_protocol/test/helpers/state_ai_flags.mli index 30a82b160475..e7a9091bf879 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/state_ai_flags.mli +++ b/src/proto_alpha/lib_protocol/test/helpers/state_ai_flags.mli @@ -35,9 +35,6 @@ module Delayed_slashing : sig (** This module takes care of choosing the denunciations that need to be applied at the end of a cycle. It depends on the flag [ns_enable]. *) - (** [Delayed_slashing] is enabled iff [ns_enable = true]. *) - val enabled : State.t -> bool - (** [partition_slashes s cycle] returns a pair [(l1,l2)] of lists of slashes, partitioned from the [state.pending_slashes]. [l2] is the list of slashes to apply at the end of the given [cycle], and [l1] is the rest (which should @@ -53,10 +50,6 @@ end module NS : sig (** This module takes care of the new adaptive slashing mechanism.*) - (** It is enabled iff the flag [ns_enable] is set to true, and AI is - also enabled. *) - val enabled : Block.t -> State.t -> bool - (** Whatever the value of the flag is, this function returns the slashing value for a given double attestation *) val get_double_attestation_slashing_percentage : diff --git a/src/proto_alpha/lib_protocol/test/integration/test_scenario_slashing.ml b/src/proto_alpha/lib_protocol/test/integration/test_scenario_slashing.ml index a4dd7f767f3f..bea9b82b1064 100644 --- a/src/proto_alpha/lib_protocol/test/integration/test_scenario_slashing.ml +++ b/src/proto_alpha/lib_protocol/test/integration/test_scenario_slashing.ml @@ -103,7 +103,6 @@ let test_multiple_misbehaviors = in init_constants ~blocks_per_cycle:24l ~reward_per_block:0L () --> (Tag "No AI" --> activate_ai `No |+ Tag "Yes AI" --> activate_ai `Force) - --> branch_flag S.Adaptive_issuance.ns_enable --> begin_test ["delegate"; "bootstrap1"; "bootstrap2"; "bootstrap3"] --> next_cycle --> (* various make misbehaviors spread over 1 or two cycles *) @@ -195,7 +194,6 @@ let test_delegate_forbidden = let crd (_, state) = state.State.constants.consensus_rights_delay in init_constants ~blocks_per_cycle:32l () --> activate_ai `No - --> branch_flag S.Adaptive_issuance.ns_enable --> begin_test ["delegate"; "bootstrap1"; "bootstrap2"] --> set_baker "bootstrap1" --> (Tag "Is not forbidden until first denunciation" @@ -251,7 +249,6 @@ let test_delegate_forbidden = let test_slash_unstake = init_constants () --> activate_ai `No - --> branch_flag S.Adaptive_issuance.ns_enable --> begin_test ["delegate"; "bootstrap1"; "bootstrap2"] --> set_baker "bootstrap1" --> next_cycle --> unstake "delegate" Half --> next_cycle --> double_bake "delegate" --> make_denunciations () @@ -263,7 +260,6 @@ let test_slash_monotonous_stake = let scenario ~offending_op ~op ~early_d = init_constants ~blocks_per_cycle:16l () --> activate_ai `No - --> branch_flag S.Adaptive_issuance.ns_enable --> begin_test ["delegate"; "bootstrap1"] --> next_cycle --> loop @@ -320,7 +316,6 @@ let test_slash_monotonous_stake = let test_slash_timing = init_constants ~blocks_per_cycle:8l () --> activate_ai `No - --> branch_flag S.Adaptive_issuance.ns_enable --> begin_test ~force_attest_all:true ["delegate"; "bootstrap1"] --> next_cycle --> (Tag "stake" --> stake "delegate" Half @@ -345,7 +340,6 @@ let test_no_shortcut_for_cheaters = Default_parameters.constants_test.consensus_rights_delay in init_constants () --> activate_ai `Force - --> set S.Adaptive_issuance.ns_enable true --> begin_test ["delegate"; "bootstrap1"] --> stake "delegate" (Amount (Tez.of_mutez 1_800_000_000_000L)) --> next_cycle --> double_bake "delegate" --> make_denunciations () @@ -406,7 +400,6 @@ let test_slash_correct_amount_after_stake_from_unstake = () in init_constants () --> activate_ai `Force - --> set S.Adaptive_issuance.ns_enable true --> begin_test ["delegate"; "bootstrap1"] --> next_cycle --> unstake "delegate" (Amount tez_to_unstake) @@ -473,16 +466,14 @@ let test_mini_slash = |+ Tag "95% slash" --> next_cycle --> double_attest "delegate" --> loop 9 (double_bake "delegate") --> make_denunciations ()) - (* Wait two cycles because of ns_enable *) - --> next_cycle - --> next_cycle + (* Wait two cycles for the slashing to be applied *) + --> wait_n_cycles 2 --> check_balance_field "delegate" `Unstaked_frozen_total Tez.zero --> wait_n_cycles_f (fun (_, state) -> state.constants.consensus_rights_delay + 1) let test_slash_rounding = init_constants () --> activate_ai `Force - --> branch_flag S.Adaptive_issuance.ns_enable --> begin_test ["delegate"; "baker"] --> set_baker "baker" --> unstake "delegate" (Amount (Tez.of_mutez 2L)) @@ -501,7 +492,6 @@ let test_mega_slash = S.max_slashing_per_block (Protocol.Percentage.of_q_bounded ~round:`Down Q.(99 // 100)) --> set S.max_slashing_threshold 0 - --> set S.Adaptive_issuance.ns_enable true --> activate_ai `Force --> set S.blocks_per_cycle 8l --> let delegates = ["delegate"; "baker"; "faucet"; "big_spender"] in diff --git a/src/proto_alpha/lib_protocol/test/integration/test_scenario_slashing_stakers.ml b/src/proto_alpha/lib_protocol/test/integration/test_scenario_slashing_stakers.ml index 5fe1fea4601b..9e1ee2c472bd 100644 --- a/src/proto_alpha/lib_protocol/test/integration/test_scenario_slashing_stakers.ml +++ b/src/proto_alpha/lib_protocol/test/integration/test_scenario_slashing_stakers.ml @@ -39,7 +39,6 @@ let never_slashed_delegate2 = "bootstrap3" - potentialy three stakers (2 delegating to first_slashed_delegate and 1 to never_slashed_delegate1 respectively) - AI enabled - - ns_enable enabled/disabled - alternative parameters for first_slashed_delegate and never_slashed_delegate1 *) @@ -78,7 +77,6 @@ let init_with_stakers () = |+ Empty in init_constants () --> activate_ai `Force - --> set S.Adaptive_issuance.ns_enable true --> begin_test ~force_attest_all:true [ diff --git a/src/proto_alpha/lib_protocol/test/unit/test_slashing_percentage.ml b/src/proto_alpha/lib_protocol/test/unit/test_slashing_percentage.ml index 78fec51e9b24..5a9c622dd68a 100644 --- a/src/proto_alpha/lib_protocol/test/unit/test_slashing_percentage.ml +++ b/src/proto_alpha/lib_protocol/test/unit/test_slashing_percentage.ml @@ -35,12 +35,11 @@ let assert_not_equal_int ~loc n (pct : Percentage.t tzresult Lwt.t) = let pct_q = Percentage.to_q pct in Assert.not_equal ~loc Q.equal "Values are equal" Q.pp_print Q.(n // 100) pct_q -let raw_context ~max_slashing_threshold ~max_slashing_per_block ~ns_enable () = +let raw_context ~max_slashing_threshold ~max_slashing_per_block () = let open Constants_helpers in let constants = Default_parameters.constants_test |> Set.Adaptive_issuance.force_activation true - |> Set.Adaptive_issuance.ns_enable ns_enable |> Set.max_slashing_threshold max_slashing_threshold |> Set.max_slashing_per_block max_slashing_per_block in @@ -61,12 +60,9 @@ let make_fake_culprits_with_rights_from_int_list il = in return (map, pkh_list) -let get_pct ~ns_enable ~max_slashing_threshold ~max_slashing_per_block int_list - = +let get_pct ~max_slashing_threshold ~max_slashing_per_block int_list = let open Lwt_result_syntax in - let* ctxt = - raw_context ~max_slashing_threshold ~max_slashing_per_block ~ns_enable () - in + let* ctxt = raw_context ~max_slashing_threshold ~max_slashing_per_block () in let*? map, pkh_list = make_fake_culprits_with_rights_from_int_list int_list in return @@ Protocol.Slash_percentage.Internal_for_tests.for_double_attestation @@ -74,9 +70,6 @@ let get_pct ~ns_enable ~max_slashing_threshold ~max_slashing_per_block int_list map pkh_list -(** We set ns_enable = true for the following tests *) -let get_pct = get_pct ~ns_enable:true - (** Tests that the slashing amount for several delegates is the same as long as the sum of their rights is the same *) let test_list_and_sum () = -- GitLab From 425659e008d6d0deefeba6f2304a746ea98ce018 Mon Sep 17 00:00:00 2001 From: Diane Gallois-Wong Date: Thu, 28 Nov 2024 12:13:12 +0100 Subject: [PATCH 04/13] Proto/test: move slashing percentage helper out of feature flag file and use it for all misbehaviour kinds --- .../test/helpers/slashing_helpers.ml | 45 ++++++++++++++----- .../test/helpers/slashing_helpers.mli | 24 ++++++++++ .../test/helpers/state_ai_flags.ml | 35 --------------- .../test/helpers/state_ai_flags.mli | 13 ------ 4 files changed, 57 insertions(+), 60 deletions(-) diff --git a/src/proto_alpha/lib_protocol/test/helpers/slashing_helpers.ml b/src/proto_alpha/lib_protocol/test/helpers/slashing_helpers.ml index bbc4dbe437bc..fe5cde5e606d 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/slashing_helpers.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/slashing_helpers.ml @@ -108,6 +108,35 @@ module Full_denunciation = struct pp list1 list2 + + let slashing_percentage ~block_before_slash + (misbehaviour : Protocol.Misbehaviour_repr.t) all_denunciations_to_apply = + let open Lwt_result_wrap_syntax in + let* alpha_ctxt = Context.(get_alpha_ctxt (B block_before_slash)) in + let raw_ctxt = + Protocol.Alpha_context.Internal_for_tests.to_raw alpha_ctxt + in + let level = + Protocol.Level_repr.level_from_raw + ~cycle_eras:(Protocol.Raw_context.cycle_eras raw_ctxt) + misbehaviour.level + in + let delegates = + List.filter + (fun (_, (den : Protocol.Denunciations_repr.item)) -> + Misbehaviour_repr.equal misbehaviour den.misbehaviour) + all_denunciations_to_apply + |> List.map fst + |> List.sort_uniq Signature.Public_key_hash.compare + in + let*@ _, pct = + Protocol.Slash_percentage.get + raw_ctxt + ~kind:misbehaviour.kind + ~level + delegates + in + return pct end let apply_slashing_account all_denunciations_to_apply @@ -147,18 +176,10 @@ let apply_slashing_account all_denunciations_to_apply Misbehaviour_repr.pp misbehaviour ; let* slashed_pct = - match misbehaviour.kind with - | Double_baking -> - return - constants - .Protocol.Alpha_context.Constants.Parametric - .percentage_of_frozen_deposits_slashed_per_double_baking - | Double_attesting | Double_preattesting -> - State_ai_flags.NS.get_double_attestation_slashing_percentage - all_denunciations_to_apply - block_before_slash - state - misbehaviour + Full_denunciation.slashing_percentage + ~block_before_slash + misbehaviour + all_denunciations_to_apply in let slash_culprit ({frozen_deposits; unstaked_frozen; frozen_rights; parameters; _} as acc) diff --git a/src/proto_alpha/lib_protocol/test/helpers/slashing_helpers.mli b/src/proto_alpha/lib_protocol/test/helpers/slashing_helpers.mli index 2a9a2c368ce7..ef5fbc50d6fb 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/slashing_helpers.mli +++ b/src/proto_alpha/lib_protocol/test/helpers/slashing_helpers.mli @@ -48,6 +48,30 @@ module Full_denunciation : sig same multiplicity in both lists. *) val check_same_lists_any_order : loc:string -> t list -> t list -> unit tzresult Lwt.t + + (** [slashing_percentage all_denunciations_to_apply + ~block_before_slash misbehaviour] returns the slashing percentage + to apply for [misbehaviour] considering the denunciations in + [all_denunciations_to_apply]. + + Preconditions: + + - [all_denunciations_to_apply] contains at least all the + denunciations for [misbehaviour] known to the chain (it may + additionally contain denunciations for other misbehaviours: this + function will ignore them). + + - [block_before_slash] is any block from cycle + [misbehaviour_cycle - consensus_rights_delay] up to the last + block **before** the slashing gets applied. Indeed, the block + that applies the slashing also moves on to the next cycle and + discards the seed for the misbehaviour level rights from the + context. *) + val slashing_percentage : + block_before_slash:Block.t -> + Protocol.Misbehaviour_repr.t -> + t list -> + Protocol.Percentage.t tzresult Lwt.t end (** Applies all slashes at cycle end in the state *) diff --git a/src/proto_alpha/lib_protocol/test/helpers/state_ai_flags.ml b/src/proto_alpha/lib_protocol/test/helpers/state_ai_flags.ml index fcb6b2960f39..2e23e73dc03d 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/state_ai_flags.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/state_ai_flags.ml @@ -85,38 +85,3 @@ module Delayed_slashing = struct Protocol.Alpha_context.Cycle.(cycle = current_cycle)) state.pending_slashes end - -module NS = struct - let get_double_attestation_slashing_percentage all_denunciations_to_apply - block_before_slash _state (misbehaviour : Protocol.Misbehaviour_repr.t) = - let open Lwt_result_wrap_syntax in - (* We need to get the block before the slash, because after the slash, - the context gets rid of the required Seed to recompute the rights - for the misbehaving delegates. *) - let* alpha_ctxt = Context.(get_alpha_ctxt (B block_before_slash)) in - let raw_ctxt = - Protocol.Alpha_context.Internal_for_tests.to_raw alpha_ctxt - in - let level = - Protocol.Level_repr.level_from_raw - ~cycle_eras:(Protocol.Raw_context.cycle_eras raw_ctxt) - misbehaviour.level - in - let delegates = - List.filter - (fun (_, (den : Protocol.Denunciations_repr.item)) -> - Compare.Int.( - Protocol.Misbehaviour_repr.compare misbehaviour den.misbehaviour = 0)) - all_denunciations_to_apply - |> List.map fst - |> List.sort_uniq Signature.Public_key_hash.compare - in - let*@ _, pct = - Protocol.Slash_percentage.get - raw_ctxt - ~kind:misbehaviour.kind - ~level - delegates - in - return pct -end diff --git a/src/proto_alpha/lib_protocol/test/helpers/state_ai_flags.mli b/src/proto_alpha/lib_protocol/test/helpers/state_ai_flags.mli index e7a9091bf879..eb9c8fd4ba5a 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/state_ai_flags.mli +++ b/src/proto_alpha/lib_protocol/test/helpers/state_ai_flags.mli @@ -46,16 +46,3 @@ module Delayed_slashing : sig (Signature.Public_key_hash.t * Protocol.Denunciations_repr.item) list * (Signature.Public_key_hash.t * Protocol.Denunciations_repr.item) list end - -module NS : sig - (** This module takes care of the new adaptive slashing mechanism.*) - - (** Whatever the value of the flag is, this function returns the - slashing value for a given double attestation *) - val get_double_attestation_slashing_percentage : - (Signature.public_key_hash * Protocol.Denunciations_repr.item) list -> - Block.t -> - State.t -> - Protocol.Misbehaviour_repr.t -> - Protocol.Percentage.t tzresult Lwt.t -end -- GitLab From f4471e217c26c302ab75e47c1375225804186523 Mon Sep 17 00:00:00 2001 From: Julien Tesson Date: Mon, 7 Oct 2024 21:02:49 +0200 Subject: [PATCH 05/13] proto: remove adaptive slashing feature-flag --- .../lib_parameters/default_parameters.ml | 1 - .../lib_protocol/alpha_context.mli | 1 - .../lib_protocol/constants_parametric_repr.ml | 14 ++----- .../constants_parametric_repr.mli | 2 - .../lib_protocol/constants_storage.ml | 2 - .../lib_protocol/constants_storage.mli | 2 - .../delegate_slashed_deposits_storage.ml | 23 +++++------ src/proto_alpha/lib_protocol/raw_context.ml | 5 +-- .../lib_protocol/slash_percentage.ml | 41 ++++++++----------- 9 files changed, 31 insertions(+), 60 deletions(-) diff --git a/src/proto_alpha/lib_parameters/default_parameters.ml b/src/proto_alpha/lib_parameters/default_parameters.ml index 7ee3109164c6..17b7fd78adee 100644 --- a/src/proto_alpha/lib_parameters/default_parameters.ml +++ b/src/proto_alpha/lib_parameters/default_parameters.ml @@ -325,7 +325,6 @@ let constants_mainnet : Constants.Parametric.t = }; activation_vote_enable = true; force_activation = false; - ns_enable = true; }; (* TODO: https://gitlab.com/tezos/tezos/-/issues/6668 Enable once at least the following is done: diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index 132a0a4c0293..480e25b4116f 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -893,7 +893,6 @@ module Constants : sig adaptive_rewards_params : adaptive_rewards_params; activation_vote_enable : bool; force_activation : bool; - ns_enable : bool; } type issuance_weights = { diff --git a/src/proto_alpha/lib_protocol/constants_parametric_repr.ml b/src/proto_alpha/lib_protocol/constants_parametric_repr.ml index ad3bbd5d59ea..890fa708ad94 100644 --- a/src/proto_alpha/lib_protocol/constants_parametric_repr.ml +++ b/src/proto_alpha/lib_protocol/constants_parametric_repr.ml @@ -233,7 +233,6 @@ type adaptive_issuance = { adaptive_rewards_params : adaptive_rewards_params; activation_vote_enable : bool; force_activation : bool; - ns_enable : bool; } type issuance_weights = { @@ -484,22 +483,19 @@ let adaptive_issuance_encoding = adaptive_rewards_params; activation_vote_enable; force_activation; - ns_enable; } -> ( global_limit_of_staking_over_baking, edge_of_staking_over_delegation, launch_ema_threshold, adaptive_rewards_params, activation_vote_enable, - force_activation, - ns_enable )) + force_activation )) (fun ( global_limit_of_staking_over_baking, edge_of_staking_over_delegation, launch_ema_threshold, adaptive_rewards_params, activation_vote_enable, - force_activation, - ns_enable ) -> + force_activation ) -> { global_limit_of_staking_over_baking; edge_of_staking_over_delegation; @@ -507,16 +503,14 @@ let adaptive_issuance_encoding = adaptive_rewards_params; activation_vote_enable; force_activation; - ns_enable; }) - (obj7 + (obj6 (req "global_limit_of_staking_over_baking" uint8) (req "edge_of_staking_over_delegation" uint8) (req "adaptive_issuance_launch_ema_threshold" int32) (req "adaptive_rewards_params" adaptive_rewards_params_encoding) (req "adaptive_issuance_activation_vote_enable" bool) - (req "adaptive_issuance_force_activation" bool) - (req "ns_enable" bool)) + (req "adaptive_issuance_force_activation" bool)) let issuance_weights_encoding = let open Data_encoding in diff --git a/src/proto_alpha/lib_protocol/constants_parametric_repr.mli b/src/proto_alpha/lib_protocol/constants_parametric_repr.mli index 8bb3998f9531..b55f01f77e2f 100644 --- a/src/proto_alpha/lib_protocol/constants_parametric_repr.mli +++ b/src/proto_alpha/lib_protocol/constants_parametric_repr.mli @@ -152,8 +152,6 @@ type adaptive_issuance = { (* For testing purposes. If set to true, the adaptive issuance feature is enabled without waiting to reach the launch_ema_threshold.*) bool; - ns_enable : (* If set to true, enables the NS feature *) - bool; } type issuance_weights = { diff --git a/src/proto_alpha/lib_protocol/constants_storage.ml b/src/proto_alpha/lib_protocol/constants_storage.ml index bf7d3f996811..38709f0181af 100644 --- a/src/proto_alpha/lib_protocol/constants_storage.ml +++ b/src/proto_alpha/lib_protocol/constants_storage.ml @@ -295,8 +295,6 @@ let adaptive_issuance_activation_vote_enable c = let adaptive_issuance_force_activation c = (adaptive_issuance c).force_activation -let adaptive_issuance_ns_enable c = (adaptive_issuance c).ns_enable - let direct_ticket_spending_enable c = (Raw_context.constants c).direct_ticket_spending_enable diff --git a/src/proto_alpha/lib_protocol/constants_storage.mli b/src/proto_alpha/lib_protocol/constants_storage.mli index b49339fc1662..6386892cfcfa 100644 --- a/src/proto_alpha/lib_protocol/constants_storage.mli +++ b/src/proto_alpha/lib_protocol/constants_storage.mli @@ -158,8 +158,6 @@ val adaptive_issuance_rewards_params : val adaptive_issuance_force_activation : Raw_context.t -> bool -val adaptive_issuance_ns_enable : Raw_context.t -> bool - val direct_ticket_spending_enable : Raw_context.t -> bool val allow_tz4_delegate_enable : Raw_context.t -> bool diff --git a/src/proto_alpha/lib_protocol/delegate_slashed_deposits_storage.ml b/src/proto_alpha/lib_protocol/delegate_slashed_deposits_storage.ml index dd447b8f1adf..9d6deb9d05e7 100644 --- a/src/proto_alpha/lib_protocol/delegate_slashed_deposits_storage.ml +++ b/src/proto_alpha/lib_protocol/delegate_slashed_deposits_storage.ml @@ -167,19 +167,16 @@ let get_applicable_and_remaining_denunciations ctxt current_cycle = the time between the misbehaviour and the slashing is at most [max_slashing_period = 2] cycles. *) let denunciations_to_apply, denunciations_to_delay = - if not (Constants_storage.adaptive_issuance_ns_enable ctxt) then - (denunciations, []) - else - List.partition - (fun denunciation -> - let level = denunciation.Denunciations_repr.misbehaviour.level in - let misb_cycle = - Level_repr.cycle_from_raw - ~cycle_eras:(Raw_context.cycle_eras ctxt) - level - in - Cycle_repr.(misb_cycle < current_cycle)) - denunciations + List.partition + (fun denunciation -> + let level = denunciation.Denunciations_repr.misbehaviour.level in + let misb_cycle = + Level_repr.cycle_from_raw + ~cycle_eras:(Raw_context.cycle_eras ctxt) + level + in + Cycle_repr.(misb_cycle < current_cycle)) + denunciations in let new_block_map = update_block_denunciations_map_with diff --git a/src/proto_alpha/lib_protocol/raw_context.ml b/src/proto_alpha/lib_protocol/raw_context.ml index 2a5ec0027844..579c05201dda 100644 --- a/src/proto_alpha/lib_protocol/raw_context.ml +++ b/src/proto_alpha/lib_protocol/raw_context.ml @@ -1149,7 +1149,6 @@ let prepare_first_block ~level ~timestamp chain_id ctxt = adaptive_rewards_params = _; activation_vote_enable; force_activation; - ns_enable; } : Previous.adaptive_issuance) = c.adaptive_issuance @@ -1162,7 +1161,6 @@ let prepare_first_block ~level ~timestamp chain_id ctxt = adaptive_rewards_params; activation_vote_enable; force_activation; - ns_enable; } in let issuance_weights = @@ -1445,7 +1443,7 @@ let prepare_first_block ~level ~timestamp chain_id ctxt = activation_vote_enable; autostaking_enable = _; force_activation; - ns_enable; + ns_enable = _; } : Previous.adaptive_issuance) = c.adaptive_issuance @@ -1458,7 +1456,6 @@ let prepare_first_block ~level ~timestamp chain_id ctxt = adaptive_rewards_params; activation_vote_enable; force_activation; - ns_enable; } in let issuance_weights = diff --git a/src/proto_alpha/lib_protocol/slash_percentage.ml b/src/proto_alpha/lib_protocol/slash_percentage.ml index 83e31903dab7..722dfd4e298b 100644 --- a/src/proto_alpha/lib_protocol/slash_percentage.ml +++ b/src/proto_alpha/lib_protocol/slash_percentage.ml @@ -9,32 +9,23 @@ let for_double_baking ctxt = Constants_storage.percentage_of_frozen_deposits_slashed_per_double_baking ctxt let for_double_attestation ctxt rights denounced = - if - not - (Constants_storage.adaptive_issuance_ns_enable ctxt - && Constants_storage.adaptive_issuance_enable ctxt) - then - Constants_storage - .percentage_of_frozen_deposits_slashed_per_double_attestation - ctxt + let total_rights_denounced = + List.fold_left + (fun total delegate -> + Option.value + (Signature.Public_key_hash.Map.find delegate rights) + ~default:0 + |> ( + ) total) + 0 + denounced + in + let threshold_max = (Raw_context.constants ctxt).max_slashing_threshold in + let max_slashing = (Raw_context.constants ctxt).max_slashing_per_block in + if Compare.Int.(total_rights_denounced >= threshold_max) then max_slashing else - let total_rights_denounced = - List.fold_left - (fun total delegate -> - Option.value - (Signature.Public_key_hash.Map.find delegate rights) - ~default:0 - |> ( + ) total) - 0 - denounced - in - let threshold_max = (Raw_context.constants ctxt).max_slashing_threshold in - let max_slashing = (Raw_context.constants ctxt).max_slashing_per_block in - if Compare.Int.(total_rights_denounced >= threshold_max) then max_slashing - else - let num_z = Z.(pow (of_int total_rights_denounced) 2) in - let den_z = Z.(pow (of_int threshold_max) 2) in - Percentage.mul_q_bounded ~round:`Up max_slashing Q.(num_z /// den_z) + let num_z = Z.(pow (of_int total_rights_denounced) 2) in + let den_z = Z.(pow (of_int threshold_max) 2) in + Percentage.mul_q_bounded ~round:`Up max_slashing Q.(num_z /// den_z) let get ctxt ~(kind : Misbehaviour_repr.kind) ~(level : Level_repr.t) (denounced : Signature.public_key_hash list) = -- GitLab From 3c8274640e3ab5b6b7df186f1beb830f15c85c75 Mon Sep 17 00:00:00 2001 From: Julien Tesson Date: Mon, 7 Oct 2024 20:56:04 +0200 Subject: [PATCH 06/13] proto: remove unused percentage_of_frozen_deposits_slashed_per_double_attestation --- src/proto_alpha/lib_parameters/default_parameters.ml | 2 -- src/proto_alpha/lib_protocol/alpha_context.mli | 5 ----- .../lib_protocol/constants_parametric_repr.ml | 9 +-------- .../lib_protocol/constants_parametric_repr.mli | 1 - src/proto_alpha/lib_protocol/constants_storage.ml | 4 ---- src/proto_alpha/lib_protocol/constants_storage.mli | 3 --- src/proto_alpha/lib_protocol/raw_context.ml | 6 ++---- 7 files changed, 3 insertions(+), 27 deletions(-) diff --git a/src/proto_alpha/lib_parameters/default_parameters.ml b/src/proto_alpha/lib_parameters/default_parameters.ml index 17b7fd78adee..369848b78fd0 100644 --- a/src/proto_alpha/lib_parameters/default_parameters.ml +++ b/src/proto_alpha/lib_parameters/default_parameters.ml @@ -275,8 +275,6 @@ let constants_mainnet : Constants.Parametric.t = limit_of_delegation_over_baking = 9; percentage_of_frozen_deposits_slashed_per_double_baking = Protocol.Percentage.p5; - percentage_of_frozen_deposits_slashed_per_double_attestation = - Protocol.Percentage.p50; max_slashing_per_block = Protocol.Percentage.p100; max_slashing_threshold; (* The `testnet_dictator` should absolutely be None on mainnet *) diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index 480e25b4116f..df2f28456d6a 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -937,8 +937,6 @@ module Constants : sig consensus_threshold : int; limit_of_delegation_over_baking : int; percentage_of_frozen_deposits_slashed_per_double_baking : Percentage.t; - percentage_of_frozen_deposits_slashed_per_double_attestation : - Percentage.t; max_slashing_per_block : Percentage.t; max_slashing_threshold : int; testnet_dictator : public_key_hash option; @@ -1046,9 +1044,6 @@ module Constants : sig val percentage_of_frozen_deposits_slashed_per_double_baking : context -> Percentage.t - val percentage_of_frozen_deposits_slashed_per_double_attestation : - context -> Percentage.t - val testnet_dictator : context -> public_key_hash option val dal_enable : context -> bool diff --git a/src/proto_alpha/lib_protocol/constants_parametric_repr.ml b/src/proto_alpha/lib_protocol/constants_parametric_repr.ml index 890fa708ad94..e105ec83b31a 100644 --- a/src/proto_alpha/lib_protocol/constants_parametric_repr.ml +++ b/src/proto_alpha/lib_protocol/constants_parametric_repr.ml @@ -277,7 +277,6 @@ type t = { consensus_threshold : int; limit_of_delegation_over_baking : int; percentage_of_frozen_deposits_slashed_per_double_baking : Percentage.t; - percentage_of_frozen_deposits_slashed_per_double_attestation : Percentage.t; max_slashing_per_block : Percentage.t; max_slashing_threshold : int; testnet_dictator : Signature.Public_key_hash.t option; @@ -592,7 +591,6 @@ let encoding = ( ( c.minimal_participation_ratio, c.limit_of_delegation_over_baking, c.percentage_of_frozen_deposits_slashed_per_double_baking, - c.percentage_of_frozen_deposits_slashed_per_double_attestation, c.max_slashing_per_block, c.max_slashing_threshold, c.testnet_dictator, @@ -638,7 +636,6 @@ let encoding = ( ( minimal_participation_ratio, limit_of_delegation_over_baking, percentage_of_frozen_deposits_slashed_per_double_baking, - percentage_of_frozen_deposits_slashed_per_double_attestation, max_slashing_per_block, max_slashing_threshold, testnet_dictator, @@ -685,7 +682,6 @@ let encoding = consensus_threshold; limit_of_delegation_over_baking; percentage_of_frozen_deposits_slashed_per_double_baking; - percentage_of_frozen_deposits_slashed_per_double_attestation; max_slashing_per_block; max_slashing_threshold; testnet_dictator; @@ -743,15 +739,12 @@ let encoding = (req "consensus_committee_size" int31) (req "consensus_threshold" int31)) (merge_objs - (obj8 + (obj7 (req "minimal_participation_ratio" Ratio_repr.encoding) (req "limit_of_delegation_over_baking" uint8) (req "percentage_of_frozen_deposits_slashed_per_double_baking" Percentage.encoding) - (req - "percentage_of_frozen_deposits_slashed_per_double_attestation" - Percentage.encoding) (req "max_slashing_per_block" Percentage.encoding) (req "max_slashing_threshold" int31) (opt "testnet_dictator" Signature.Public_key_hash.encoding) diff --git a/src/proto_alpha/lib_protocol/constants_parametric_repr.mli b/src/proto_alpha/lib_protocol/constants_parametric_repr.mli index b55f01f77e2f..60a1a50fbd15 100644 --- a/src/proto_alpha/lib_protocol/constants_parametric_repr.mli +++ b/src/proto_alpha/lib_protocol/constants_parametric_repr.mli @@ -212,7 +212,6 @@ type t = { limit_of_delegation_over_baking : int; (* upper bound on the (delegated tz / own frozen tz) ratio *) percentage_of_frozen_deposits_slashed_per_double_baking : Percentage.t; - percentage_of_frozen_deposits_slashed_per_double_attestation : Percentage.t; max_slashing_per_block : Percentage.t; max_slashing_threshold : int; testnet_dictator : Signature.Public_key_hash.t option; diff --git a/src/proto_alpha/lib_protocol/constants_storage.ml b/src/proto_alpha/lib_protocol/constants_storage.ml index 38709f0181af..d765b1c2f2f5 100644 --- a/src/proto_alpha/lib_protocol/constants_storage.ml +++ b/src/proto_alpha/lib_protocol/constants_storage.ml @@ -177,10 +177,6 @@ let percentage_of_frozen_deposits_slashed_per_double_baking c = let constants = Raw_context.constants c in constants.percentage_of_frozen_deposits_slashed_per_double_baking -let percentage_of_frozen_deposits_slashed_per_double_attestation c = - let constants = Raw_context.constants c in - constants.percentage_of_frozen_deposits_slashed_per_double_attestation - let testnet_dictator c = let constants = Raw_context.constants c in constants.testnet_dictator diff --git a/src/proto_alpha/lib_protocol/constants_storage.mli b/src/proto_alpha/lib_protocol/constants_storage.mli index 6386892cfcfa..2de3bbe76632 100644 --- a/src/proto_alpha/lib_protocol/constants_storage.mli +++ b/src/proto_alpha/lib_protocol/constants_storage.mli @@ -89,9 +89,6 @@ val limit_of_delegation_over_baking : Raw_context.t -> int val percentage_of_frozen_deposits_slashed_per_double_baking : Raw_context.t -> Percentage.t -val percentage_of_frozen_deposits_slashed_per_double_attestation : - Raw_context.t -> Percentage.t - val testnet_dictator : Raw_context.t -> Signature.Public_key_hash.t option val minimal_block_delay : Raw_context.t -> Period_repr.t diff --git a/src/proto_alpha/lib_protocol/raw_context.ml b/src/proto_alpha/lib_protocol/raw_context.ml index 579c05201dda..f42782d048f8 100644 --- a/src/proto_alpha/lib_protocol/raw_context.ml +++ b/src/proto_alpha/lib_protocol/raw_context.ml @@ -1219,7 +1219,6 @@ let prepare_first_block ~level ~timestamp chain_id ctxt = minimal_participation_ratio; limit_of_delegation_over_baking; percentage_of_frozen_deposits_slashed_per_double_baking; - percentage_of_frozen_deposits_slashed_per_double_attestation; max_slashing_per_block; max_slashing_threshold; (* The `testnet_dictator` should absolutely be None on mainnet *) @@ -1272,7 +1271,6 @@ let prepare_first_block ~level ~timestamp chain_id ctxt = minimal_participation_ratio; limit_of_delegation_over_baking; percentage_of_frozen_deposits_slashed_per_double_baking; - percentage_of_frozen_deposits_slashed_per_double_attestation; max_slashing_per_block; max_slashing_threshold; (* The `testnet_dictator` should absolutely be None on mainnet *) @@ -1512,7 +1510,8 @@ let prepare_first_block ~level ~timestamp chain_id ctxt = minimal_participation_ratio; limit_of_delegation_over_baking; percentage_of_frozen_deposits_slashed_per_double_baking; - percentage_of_frozen_deposits_slashed_per_double_attestation; + percentage_of_frozen_deposits_slashed_per_double_attestation = + _; max_slashing_per_block; max_slashing_threshold; (* The `testnet_dictator` should absolutely be None on mainnet *) @@ -1562,7 +1561,6 @@ let prepare_first_block ~level ~timestamp chain_id ctxt = minimal_participation_ratio; limit_of_delegation_over_baking; percentage_of_frozen_deposits_slashed_per_double_baking; - percentage_of_frozen_deposits_slashed_per_double_attestation; max_slashing_per_block; max_slashing_threshold; (* The `testnet_dictator` should absolutely be None on mainnet *) -- GitLab From b56884b52feb66988f2fcfe8541c6bb81f24023c Mon Sep 17 00:00:00 2001 From: Diane Gallois-Wong Date: Fri, 15 Nov 2024 15:28:37 +0100 Subject: [PATCH 07/13] Kaitai: update files The changes have been generated with: cd client-libs/kaitai-struct-files dune exec -- ../bin_codec_kaitai/codec.exe dump kaitai specs in ./files --- client-libs/kaitai-struct-files/files/alpha__constants.ksy | 5 ----- .../files/alpha__constants__parametric.ksy | 5 ----- client-libs/kaitai-struct-files/files/alpha__parameters.ksy | 5 ----- 3 files changed, 15 deletions(-) diff --git a/client-libs/kaitai-struct-files/files/alpha__constants.ksy b/client-libs/kaitai-struct-files/files/alpha__constants.ksy index e91dff4cc6c1..57b37cddac91 100644 --- a/client-libs/kaitai-struct-files/files/alpha__constants.ksy +++ b/client-libs/kaitai-struct-files/files/alpha__constants.ksy @@ -292,8 +292,6 @@ seq: type: u1 - id: percentage_of_frozen_deposits_slashed_per_double_baking type: u2be -- id: percentage_of_frozen_deposits_slashed_per_double_attestation - type: u2be - id: max_slashing_per_block type: u2be - id: max_slashing_threshold @@ -375,9 +373,6 @@ seq: - id: adaptive_issuance_force_activation type: u1 enum: bool -- id: ns_enable - type: u1 - enum: bool - id: direct_ticket_spending_enable type: u1 enum: bool diff --git a/client-libs/kaitai-struct-files/files/alpha__constants__parametric.ksy b/client-libs/kaitai-struct-files/files/alpha__constants__parametric.ksy index 1b4e8371f950..af2c8cac106f 100644 --- a/client-libs/kaitai-struct-files/files/alpha__constants__parametric.ksy +++ b/client-libs/kaitai-struct-files/files/alpha__constants__parametric.ksy @@ -264,8 +264,6 @@ seq: type: u1 - id: percentage_of_frozen_deposits_slashed_per_double_baking type: u2be -- id: percentage_of_frozen_deposits_slashed_per_double_attestation - type: u2be - id: max_slashing_per_block type: u2be - id: max_slashing_threshold @@ -347,9 +345,6 @@ seq: - id: adaptive_issuance_force_activation type: u1 enum: bool -- id: ns_enable - type: u1 - enum: bool - id: direct_ticket_spending_enable type: u1 enum: bool diff --git a/client-libs/kaitai-struct-files/files/alpha__parameters.ksy b/client-libs/kaitai-struct-files/files/alpha__parameters.ksy index 469be38cb185..5b4ef02703a7 100644 --- a/client-libs/kaitai-struct-files/files/alpha__parameters.ksy +++ b/client-libs/kaitai-struct-files/files/alpha__parameters.ksy @@ -542,8 +542,6 @@ seq: type: u1 - id: percentage_of_frozen_deposits_slashed_per_double_baking type: u2be -- id: percentage_of_frozen_deposits_slashed_per_double_attestation - type: u2be - id: max_slashing_per_block type: u2be - id: max_slashing_threshold @@ -625,9 +623,6 @@ seq: - id: adaptive_issuance_force_activation type: u1 enum: bool -- id: ns_enable - type: u1 - enum: bool - id: direct_ticket_spending_enable type: u1 enum: bool -- GitLab From 167fa8ca2ce3f3ad7c10728cc842b8c886f6d302 Mon Sep 17 00:00:00 2001 From: Diane Gallois-Wong Date: Fri, 15 Nov 2024 11:03:44 +0100 Subject: [PATCH 08/13] Proto/test/consensus: fix expected reward --- .../consensus/test_double_attestation.ml | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/proto_alpha/lib_protocol/test/integration/consensus/test_double_attestation.ml b/src/proto_alpha/lib_protocol/test/integration/consensus/test_double_attestation.ml index 777e15f42d3a..49f8a41ff4ff 100644 --- a/src/proto_alpha/lib_protocol/test/integration/consensus/test_double_attestation.ml +++ b/src/proto_alpha/lib_protocol/test/integration/consensus/test_double_attestation.ml @@ -192,12 +192,35 @@ let test_valid_double_attestation_evidence () = (Int64.of_int constants.adaptive_issuance.global_limit_of_staking_over_baking) in - let evidence_reward = Tez_helpers.(frozen_deposits_after /! divider) in + let evidence_reward = + Tez_helpers.((frozen_deposits_before -! frozen_deposits_after) /! divider) + in let expected_reward = Tez_helpers.(baking_reward +! evidence_reward) in let* full_balance_with_rewards = Context.Delegate.full_balance (B blk_eoc) baker in let real_reward = Tez_helpers.(full_balance_with_rewards -! full_balance) in + Log.info + "@[frozen_deposits_before = %a@,\ + frozen_deposits_after = %a@,\ + baking_reward = %a@,\ + divider = %Ld@,\ + evidence_reward = %a@,\ + expected_reward = %a@,\ + real_reward = %a@]" + Tez.pp + frozen_deposits_before + Tez.pp + frozen_deposits_after + Tez.pp + baking_reward + divider + Tez.pp + evidence_reward + Tez.pp + expected_reward + Tez.pp + real_reward ; Assert.equal_tez ~loc:__LOC__ expected_reward real_reward (** Check that a double (pre)attestation evidence with equivalent -- GitLab From f0cdbe6ca689ebed87b109a8f155b1b2aeb601ba Mon Sep 17 00:00:00 2001 From: Diane Gallois-Wong Date: Fri, 29 Nov 2024 15:40:24 +0100 Subject: [PATCH 09/13] Proto/test/consensus: give explicit delegate argument to Op.raw_attestation and Op.raw_preattestation In tests with two misbehaviours, this is needed to guarantee that the culprit of the second double signing it the expected one. At other places, it avoids having to rely on the fact that the default delegate used is always the output of Context.get_attester --- .../consensus/test_double_attestation.ml | 24 +++++++++---------- .../consensus/test_double_preattestation.ml | 4 ++-- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/proto_alpha/lib_protocol/test/integration/consensus/test_double_attestation.ml b/src/proto_alpha/lib_protocol/test/integration/consensus/test_double_attestation.ml index 49f8a41ff4ff..46fa3d2511c0 100644 --- a/src/proto_alpha/lib_protocol/test/integration/consensus/test_double_attestation.ml +++ b/src/proto_alpha/lib_protocol/test/integration/consensus/test_double_attestation.ml @@ -118,8 +118,8 @@ let test_valid_double_attestation_evidence () = let* blk_a = Block.bake blk_1 in let* blk_b = Block.bake blk_2 in let* delegate, _ = Context.get_attester (B blk_a) in - let* attestation_a = Op.raw_attestation blk_a in - let* attestation_b = Op.raw_attestation blk_b in + let* attestation_a = Op.raw_attestation ~delegate blk_a in + let* attestation_b = Op.raw_attestation ~delegate blk_b in let operation = double_attestation (B genesis) attestation_a attestation_b in let* bakers = Context.get_bakers (B blk_a) in let baker = Context.get_first_different_baker delegate bakers in @@ -292,8 +292,8 @@ let test_two_double_attestation_evidences_leadsto_no_bake () = let* blk_a = Block.bake blk_1 in let* blk_b = Block.bake blk_2 in let* delegate, _ = Context.get_attester (B blk_a) in - let* attestation_a = Op.raw_attestation blk_a in - let* attestation_b = Op.raw_attestation blk_b in + let* attestation_a = Op.raw_attestation ~delegate blk_a in + let* attestation_b = Op.raw_attestation ~delegate blk_b in let operation = double_attestation (B genesis) attestation_a attestation_b in let* bakers = Context.get_bakers (B blk_a) in let baker = Context.get_first_different_baker delegate bakers in @@ -306,8 +306,8 @@ let test_two_double_attestation_evidences_leadsto_no_bake () = let* blk_30, blk_40 = block_fork ~excluding:[delegate] blk_with_evidence1 in let* blk_3 = Block.bake ~policy:(Excluding [delegate]) blk_30 in let* blk_4 = Block.bake ~policy:(Excluding [delegate]) blk_40 in - let* attestation_3 = Op.raw_attestation blk_3 in - let* attestation_4 = Op.raw_attestation blk_4 in + let* attestation_3 = Op.raw_attestation ~delegate blk_3 in + let* attestation_4 = Op.raw_attestation ~delegate blk_4 in let operation = double_attestation (B blk_with_evidence1) attestation_3 attestation_4 in @@ -391,8 +391,8 @@ let test_two_double_attestation_evidences_staggered () = let* blk_a = Block.bake blk_1 in let* blk_b = Block.bake blk_2 in let* delegate, _ = Context.get_attester (B blk_a) in - let* attestation_a = Op.raw_attestation blk_a in - let* attestation_b = Op.raw_attestation blk_b in + let* attestation_a = Op.raw_attestation ~delegate blk_a in + let* attestation_b = Op.raw_attestation ~delegate blk_b in let operation = double_attestation (B genesis) attestation_a attestation_b in let* bakers = Context.get_bakers (B blk_a) in let baker = Context.get_first_different_baker delegate bakers in @@ -466,8 +466,8 @@ let test_two_double_attestation_evidences_consecutive_cycles () = let* blk_a = Block.bake blk_1 in let* blk_b = Block.bake blk_2 in let* delegate, _ = Context.get_attester (B blk_a) in - let* attestation_a = Op.raw_attestation blk_a in - let* attestation_b = Op.raw_attestation blk_b in + let* attestation_a = Op.raw_attestation ~delegate blk_a in + let* attestation_b = Op.raw_attestation ~delegate blk_b in let operation = double_attestation (B genesis) attestation_a attestation_b in let* bakers = Context.get_bakers (B blk_a) in let baker = Context.get_first_different_baker delegate bakers in @@ -861,8 +861,8 @@ let test_two_double_attestation_evidences_leads_to_duplicate_denunciation () = let* blk_a = Block.bake blk_1 in let* blk_b = Block.bake blk_2 in let* delegate, _ = Context.get_attester (B blk_a) in - let* attestation_a = Op.raw_attestation blk_a in - let* attestation_b = Op.raw_attestation blk_b in + let* attestation_a = Op.raw_attestation ~delegate blk_a in + let* attestation_b = Op.raw_attestation ~delegate blk_b in let operation = double_attestation (B genesis) attestation_a attestation_b in let operation2 = double_attestation (B genesis) attestation_b attestation_a in let* bakers = Context.get_bakers (B blk_a) in diff --git a/src/proto_alpha/lib_protocol/test/integration/consensus/test_double_preattestation.ml b/src/proto_alpha/lib_protocol/test/integration/consensus/test_double_preattestation.ml index 3b2071821beb..b417de031df7 100644 --- a/src/proto_alpha/lib_protocol/test/integration/consensus/test_double_preattestation.ml +++ b/src/proto_alpha/lib_protocol/test/integration/consensus/test_double_preattestation.ml @@ -365,8 +365,8 @@ end = struct let* blk_a = Block.bake blk_1 in let* blk_b = Block.bake blk_2 in let* delegate, _ = Context.get_attester (B blk_a) in - let* preattestation_a = Op.raw_preattestation blk_a in - let* preattestation_b = Op.raw_preattestation blk_b in + let* preattestation_a = Op.raw_preattestation ~delegate blk_a in + let* preattestation_b = Op.raw_preattestation ~delegate blk_b in let operation = double_preattestation (B genesis) preattestation_a preattestation_b in -- GitLab From b5321c08f758df0a8688dc475b4d4faff249c57d Mon Sep 17 00:00:00 2001 From: Diane Gallois-Wong Date: Thu, 14 Nov 2024 14:42:56 +0100 Subject: [PATCH 10/13] Proto/test/consensus: update with new slashing --- .../test/helpers/slashing_helpers.ml | 36 ++++---- .../test/helpers/slashing_helpers.mli | 43 +++++---- .../consensus/test_double_attestation.ml | 87 +++++++++++-------- .../consensus/test_double_baking.ml | 16 +++- .../consensus/test_double_preattestation.ml | 21 +++-- 5 files changed, 120 insertions(+), 83 deletions(-) diff --git a/src/proto_alpha/lib_protocol/test/helpers/slashing_helpers.ml b/src/proto_alpha/lib_protocol/test/helpers/slashing_helpers.ml index fe5cde5e606d..9334eb6699a2 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/slashing_helpers.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/slashing_helpers.ml @@ -5,6 +5,21 @@ (* *) (*****************************************************************************) +let slashing_percentage ~block_before_slash + {Protocol.Misbehaviour_repr.level; round = _; kind} ~all_culprits = + let open Lwt_result_wrap_syntax in + let* ctxt = Block.get_alpha_ctxt block_before_slash in + let raw_ctxt = Protocol.Alpha_context.Internal_for_tests.to_raw ctxt in + let level = + Protocol.Level_repr.level_from_raw + ~cycle_eras:(Protocol.Raw_context.cycle_eras raw_ctxt) + level + in + let*@ _, slashing_pct = + Protocol.Slash_percentage.get raw_ctxt ~kind ~level all_culprits + in + return slashing_pct + module Misbehaviour_repr = struct open Protocol.Misbehaviour_repr @@ -111,17 +126,7 @@ module Full_denunciation = struct let slashing_percentage ~block_before_slash (misbehaviour : Protocol.Misbehaviour_repr.t) all_denunciations_to_apply = - let open Lwt_result_wrap_syntax in - let* alpha_ctxt = Context.(get_alpha_ctxt (B block_before_slash)) in - let raw_ctxt = - Protocol.Alpha_context.Internal_for_tests.to_raw alpha_ctxt - in - let level = - Protocol.Level_repr.level_from_raw - ~cycle_eras:(Protocol.Raw_context.cycle_eras raw_ctxt) - misbehaviour.level - in - let delegates = + let all_culprits = List.filter (fun (_, (den : Protocol.Denunciations_repr.item)) -> Misbehaviour_repr.equal misbehaviour den.misbehaviour) @@ -129,14 +134,7 @@ module Full_denunciation = struct |> List.map fst |> List.sort_uniq Signature.Public_key_hash.compare in - let*@ _, pct = - Protocol.Slash_percentage.get - raw_ctxt - ~kind:misbehaviour.kind - ~level - delegates - in - return pct + slashing_percentage ~block_before_slash misbehaviour ~all_culprits end let apply_slashing_account all_denunciations_to_apply diff --git a/src/proto_alpha/lib_protocol/test/helpers/slashing_helpers.mli b/src/proto_alpha/lib_protocol/test/helpers/slashing_helpers.mli index ef5fbc50d6fb..d1fddd0468af 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/slashing_helpers.mli +++ b/src/proto_alpha/lib_protocol/test/helpers/slashing_helpers.mli @@ -7,6 +7,25 @@ (** Helpers related to denunciations and slashing. *) +(** Returns the slashing percentage to apply for the given + misbehaviour. + + Preconditions: + + - [all_culprits] is the list of all delegates that have been + denounced for the given misbehaviour. + + - [block_before_slash] is any block from cycle + [misbehaviour_cycle - consensus_rights_delay] up to the last block + **before** the slashing gets applied. Indeed, the block that + applies the slashing also moves on to the next cycle and discards + the seed for the misbehaviour level rights from the context. *) +val slashing_percentage : + block_before_slash:Block.t -> + Protocol.Misbehaviour_repr.t -> + all_culprits:Signature.public_key_hash list -> + Protocol.Percentage.t tzresult Lwt.t + (** Helpers related to {!Protocol.Misbehaviour_repr}. *) module Misbehaviour_repr : sig val pp : Format.formatter -> Protocol.Misbehaviour_repr.t -> unit @@ -49,24 +68,16 @@ module Full_denunciation : sig val check_same_lists_any_order : loc:string -> t list -> t list -> unit tzresult Lwt.t - (** [slashing_percentage all_denunciations_to_apply - ~block_before_slash misbehaviour] returns the slashing percentage - to apply for [misbehaviour] considering the denunciations in - [all_denunciations_to_apply]. - - Preconditions: + (** Same as {!slashing_percentage} (top-level function), but takes + directly a list of full denunciations as an argument. - - [all_denunciations_to_apply] contains at least all the - denunciations for [misbehaviour] known to the chain (it may - additionally contain denunciations for other misbehaviours: this - function will ignore them). + The list of full denunciation must contain at least all the + denunciations for [misbehaviour] known to the chain. Note that it + may additionally contain denunciations for other misbehaviours, + which will be ignored. - - [block_before_slash] is any block from cycle - [misbehaviour_cycle - consensus_rights_delay] up to the last - block **before** the slashing gets applied. Indeed, the block - that applies the slashing also moves on to the next cycle and - discards the seed for the misbehaviour level rights from the - context. *) + See {!slashing_percentage} for the precondition on + [block_before_slash]. *) val slashing_percentage : block_before_slash:Block.t -> Protocol.Misbehaviour_repr.t -> diff --git a/src/proto_alpha/lib_protocol/test/integration/consensus/test_double_attestation.ml b/src/proto_alpha/lib_protocol/test/integration/consensus/test_double_attestation.ml index 46fa3d2511c0..41013b9227db 100644 --- a/src/proto_alpha/lib_protocol/test/integration/consensus/test_double_attestation.ml +++ b/src/proto_alpha/lib_protocol/test/integration/consensus/test_double_attestation.ml @@ -164,10 +164,14 @@ let test_valid_double_attestation_evidence () = let frozen_deposits_after = Tez_helpers.(frozen_deposits_after -! autostaked) in - let one_minus_p = - Percentage.neg - constants.percentage_of_frozen_deposits_slashed_per_double_attestation - in + let* slashing_pct = + Slashing_helpers.slashing_percentage + (Slashing_helpers.Misbehaviour_repr.from_duplicate_operation + attestation_a) + ~block_before_slash:blk_a + ~all_culprits:[delegate] + in + let one_minus_p = Percentage.neg slashing_pct in let {Q.num; den} = Percentage.to_q one_minus_p in let expected_frozen_deposits_after = Tez_helpers.(frozen_deposits_before *! Z.to_int64 num /! Z.to_int64 den) @@ -278,7 +282,7 @@ let test_different_slots () = (** Say a delegate double-attests twice and say the 2 evidences are timely included. Then the delegate can no longer bake. *) let test_two_double_attestation_evidences_leadsto_no_bake () = - let open Lwt_result_syntax in + let open Lwt_result_wrap_syntax in let issuance_weights = { Default_parameters.constants_test.issuance_weights with @@ -352,34 +356,43 @@ let test_two_double_attestation_evidences_leadsto_no_bake () = | _ -> false) in (* Check that all frozen deposits have been slashed at the end of the cycle. *) - let* b, metadata, _ = - Block.bake_until_n_cycle_end_with_metadata + let* b = + Block.bake_until_n_cycle_end ~policy:(By_account baker) - 2 + Constants_repr.max_slashing_period blk_with_evidence2 in - let metadata = Option.value_f ~default:(fun () -> assert false) metadata in - let autostaked = Block.autostaked delegate metadata in + let* slashing_pct1 = + Slashing_helpers.slashing_percentage + (Slashing_helpers.Misbehaviour_repr.from_duplicate_operation + attestation_a) + ~block_before_slash:blk_a + ~all_culprits:[delegate] + in + let* slashing_pct2 = + Slashing_helpers.slashing_percentage + (Slashing_helpers.Misbehaviour_repr.from_duplicate_operation + attestation_3) + ~block_before_slash:blk_3 + ~all_culprits:[delegate] + in + let one_minus_p = + Percentage.(neg (add_bounded slashing_pct1 slashing_pct2)) + in + let {Q.num; den} = Percentage.to_q one_minus_p in + let expected_frozen_deposits_after = + Tez_helpers.(frozen_deposits_before *! Z.to_int64 num /! Z.to_int64 den) + in let* frozen_deposits_after = Context.Delegate.current_frozen_deposits (B b) delegate in - let frozen_deposits_after = - Tez_helpers.(frozen_deposits_after -! autostaked) + let* () = + Assert.equal_tez + ~loc:__LOC__ + expected_frozen_deposits_after + frozen_deposits_after in - let* base_reward = Context.get_baking_reward_fixed_portion (B genesis) in - let* to_liquid = - Adaptive_issuance_helpers.portion_of_rewards_to_liquid_for_cycle - (B b) - (Block.current_cycle b) - delegate - base_reward - in - (* [delegate] baked one block. The block rewards for that block should be all - that's left *) - Assert.equal_tez - ~loc:__LOC__ - Tez_helpers.(base_reward -! to_liquid) - frozen_deposits_after + return_unit (** Say a delegate double-attests twice in a cycle, and say the 2 evidences are included in different (valid) cycles. @@ -694,7 +707,10 @@ let test_freeze_more_with_low_balance = in let* attestation_b = Op.raw_attestation ~delegate:account1 ~slot blk_b in let denunciation = double_attestation (B b2) attestation_a attestation_b in - Block.bake ~policy:(Excluding [account1]) b2 ~operations:[denunciation] + let* b = + Block.bake ~policy:(Excluding [account1]) b2 ~operations:[denunciation] + in + return (b, attestation_a) in let check_unique_attester b account2 = let* attesters_list = Context.get_attesters (B b) in @@ -715,9 +731,6 @@ let test_freeze_more_with_low_balance = consensus_threshold = 0; origination_size = 0; consensus_rights_delay = 5; - percentage_of_frozen_deposits_slashed_per_double_attestation = - (* enforce that percentage is 50% in the test's params. *) - Percentage.p50; } in let* genesis, (c1, c2) = Context.init_with_constants2 constants in @@ -746,7 +759,7 @@ let test_freeze_more_with_low_balance = let* () = Assert.equal_tez ~loc:__LOC__ info1.frozen_deposits info2.frozen_deposits in - let* b3 = double_attest_and_punish b2 account1 in + let* b3, duplicate_op = double_attest_and_punish b2 account1 in (* Denunciation has happened but slashing hasn't yet. We check that frozen deposits haven't changed and still correspond to the full balance and itself hasn't changed. *) @@ -777,10 +790,14 @@ let test_freeze_more_with_low_balance = in (* We also check that compared to deposits at block [b2], [account1] lost 50% of its deposits. *) - let one_minus_slash_percentage = - Percentage.neg - constants.percentage_of_frozen_deposits_slashed_per_double_attestation + let* slashing_pct = + Slashing_helpers.slashing_percentage + (Slashing_helpers.Misbehaviour_repr.from_duplicate_operation + duplicate_op) + ~block_before_slash:b3 + ~all_culprits:[account1] in + let one_minus_slash_percentage = Percentage.neg slashing_pct in let {Q.num; den} = Percentage.to_q one_minus_slash_percentage in let expected_frozen_deposits_after = Tez_helpers.(info2.frozen_deposits *! Z.to_int64 num /! Z.to_int64 den) @@ -791,7 +808,7 @@ let test_freeze_more_with_low_balance = expected_frozen_deposits_after info4.current_frozen_deposits in - let* c2 = double_attest_and_punish c1 account1 in + let* c2, _ = double_attest_and_punish c1 account1 in (* Second denunciation has happened but slashing not yet, again. Current frozen deposits reflect the slashing of 50% of the original deposits. *) diff --git a/src/proto_alpha/lib_protocol/test/integration/consensus/test_double_baking.ml b/src/proto_alpha/lib_protocol/test/integration/consensus/test_double_baking.ml index c94ba9562ad6..f227147dd345 100644 --- a/src/proto_alpha/lib_protocol/test/integration/consensus/test_double_baking.ml +++ b/src/proto_alpha/lib_protocol/test/integration/consensus/test_double_baking.ml @@ -201,8 +201,12 @@ let test_valid_double_baking_followed_by_double_attesting () = Context.Delegate.current_frozen_deposits (B blk_eoc) baker1 in let* csts = Context.get_constants (B genesis) in - let p_de = - csts.parametric.percentage_of_frozen_deposits_slashed_per_double_attestation + let* p_de = + Slashing_helpers.slashing_percentage + (Slashing_helpers.Misbehaviour_repr.from_duplicate_operation + attestation_a) + ~block_before_slash:blk_final + ~all_culprits:[delegate] in let p_db = csts.parametric.percentage_of_frozen_deposits_slashed_per_double_baking @@ -282,8 +286,12 @@ let test_valid_double_attesting_followed_by_double_baking () = Context.Delegate.current_frozen_deposits (B blk_eoc) baker1 in let* csts = Context.get_constants (B genesis) in - let p_de = - csts.parametric.percentage_of_frozen_deposits_slashed_per_double_attestation + let* p_de = + Slashing_helpers.slashing_percentage + (Slashing_helpers.Misbehaviour_repr.from_duplicate_operation + attestation_a) + ~block_before_slash:blk_with_db_evidence + ~all_culprits:[delegate] in let p_db = csts.parametric.percentage_of_frozen_deposits_slashed_per_double_baking diff --git a/src/proto_alpha/lib_protocol/test/integration/consensus/test_double_preattestation.ml b/src/proto_alpha/lib_protocol/test/integration/consensus/test_double_preattestation.ml index b417de031df7..eb407ddb4705 100644 --- a/src/proto_alpha/lib_protocol/test/integration/consensus/test_double_preattestation.ml +++ b/src/proto_alpha/lib_protocol/test/integration/consensus/test_double_preattestation.ml @@ -127,15 +127,11 @@ end = struct let unexpected_success loc _ _ _ _ _ = Alcotest.fail (loc ^ ": Test should not succeed") - let expected_success _loc baker pred bbad d1 d2 = + let expected_success _loc baker pred bbad d1 d2 ~duplicate_op = let open Lwt_result_syntax in (* same preattesters in case denunciation succeeds*) let* () = Assert.equal_pkh ~loc:__LOC__ d1 d2 in let* constants = Context.get_constants (B pred) in - let p = - constants.parametric - .percentage_of_frozen_deposits_slashed_per_double_attestation - in (* let's bake the block on top of pred without denunciating d1 *) let* bgood = bake ~policy:(By_account baker) pred in (* Slashing hasn't happened yet. *) @@ -154,6 +150,13 @@ end = struct (* the diff of the two balances in normal and in denunciation cases *) let diff_end_bal = Tez_helpers.(bal_good -! bal_bad) in (* amount lost due to denunciation *) + let* p = + Slashing_helpers.slashing_percentage + (Slashing_helpers.Misbehaviour_repr.from_duplicate_operation + duplicate_op) + ~block_before_slash:pred + ~all_culprits:[d1] + in let Q.{num; den} = Percentage.to_q p in let lost_deposit = Tez_helpers.(frozen_deposit *! Z.to_int64 num /! Z.to_int64 den) @@ -210,9 +213,7 @@ end = struct (** Helper function for denunciations inclusion *) let generic_double_preattestation_denunciation ~nb_blocks_before_double - ~nb_blocks_before_denunciation - ?(test_expected_ok = - fun _loc _baker _pred _bbad _d1 _d2 -> Lwt_result_syntax.return_unit) + ~nb_blocks_before_denunciation ~test_expected_ok ?(test_expected_ko = fun _loc _res -> Lwt_result_syntax.return_unit) ?(pick_attesters = let open Lwt_result_syntax in @@ -249,7 +250,9 @@ end = struct let*! head_opt = bake ~policy:(By_account baker) blk ~operations:[op] in match head_opt with | Ok new_head -> - let* () = test_expected_ok loc baker blk new_head d1 d2 in + let* () = + test_expected_ok loc baker blk new_head d1 d2 ~duplicate_op:op1 + in let op : Operation.packed = Op.double_preattestation (B new_head) op2 op1 in -- GitLab From 3366aaa0b28c7cf592042f69b70136d9041d24f5 Mon Sep 17 00:00:00 2001 From: Diane Gallois-Wong Date: Fri, 15 Nov 2024 17:31:53 +0100 Subject: [PATCH 11/13] Tezt: reset regressions --- ...lpha- (mode client) RPC regression tests- misc_protocol.out | 3 +-- ...Alpha- (mode light) RPC regression tests- misc_protocol.out | 3 +-- ...Alpha- (mode proxy) RPC regression tests- misc_protocol.out | 3 +-- .../expected/weeklynet.ml/Alpha- weeklynet regression test.out | 3 +-- 4 files changed, 4 insertions(+), 8 deletions(-) diff --git a/tezt/tests/expected/RPC_test.ml/Alpha- (mode client) RPC regression tests- misc_protocol.out b/tezt/tests/expected/RPC_test.ml/Alpha- (mode client) RPC regression tests- misc_protocol.out index 8a22eae11331..4b8e30747e46 100644 --- a/tezt/tests/expected/RPC_test.ml/Alpha- (mode client) RPC regression tests- misc_protocol.out +++ b/tezt/tests/expected/RPC_test.ml/Alpha- (mode client) RPC regression tests- misc_protocol.out @@ -34,7 +34,6 @@ "minimal_participation_ratio": { "numerator": 2, "denominator": 3 }, "limit_of_delegation_over_baking": 19, "percentage_of_frozen_deposits_slashed_per_double_baking": 500, - "percentage_of_frozen_deposits_slashed_per_double_attestation": 5000, "max_slashing_per_block": 10000, "max_slashing_threshold": 101, "cache_script_size": 100000000, "cache_stake_distribution_cycles": 5, "cache_sampler_state_cycles": 5, @@ -80,7 +79,7 @@ "center_dz": { "numerator": "1", "denominator": "2" }, "radius_dz": { "numerator": "1", "denominator": "50" } }, "adaptive_issuance_activation_vote_enable": true, - "adaptive_issuance_force_activation": false, "ns_enable": true, + "adaptive_issuance_force_activation": false, "direct_ticket_spending_enable": false, "aggregate_attestation": false, "allow_tz4_delegate_enable": true, "all_bakers_attest_enable": false } diff --git a/tezt/tests/expected/RPC_test.ml/Alpha- (mode light) RPC regression tests- misc_protocol.out b/tezt/tests/expected/RPC_test.ml/Alpha- (mode light) RPC regression tests- misc_protocol.out index e56cd5fbbe64..604258e8de4d 100644 --- a/tezt/tests/expected/RPC_test.ml/Alpha- (mode light) RPC regression tests- misc_protocol.out +++ b/tezt/tests/expected/RPC_test.ml/Alpha- (mode light) RPC regression tests- misc_protocol.out @@ -34,7 +34,6 @@ "minimal_participation_ratio": { "numerator": 2, "denominator": 3 }, "limit_of_delegation_over_baking": 19, "percentage_of_frozen_deposits_slashed_per_double_baking": 500, - "percentage_of_frozen_deposits_slashed_per_double_attestation": 5000, "max_slashing_per_block": 10000, "max_slashing_threshold": 101, "cache_script_size": 100000000, "cache_stake_distribution_cycles": 5, "cache_sampler_state_cycles": 5, @@ -80,7 +79,7 @@ "center_dz": { "numerator": "1", "denominator": "2" }, "radius_dz": { "numerator": "1", "denominator": "50" } }, "adaptive_issuance_activation_vote_enable": true, - "adaptive_issuance_force_activation": false, "ns_enable": true, + "adaptive_issuance_force_activation": false, "direct_ticket_spending_enable": false, "aggregate_attestation": false, "allow_tz4_delegate_enable": true, "all_bakers_attest_enable": false } diff --git a/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy) RPC regression tests- misc_protocol.out b/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy) RPC regression tests- misc_protocol.out index 3070b3387917..3254159df6e9 100644 --- a/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy) RPC regression tests- misc_protocol.out +++ b/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy) RPC regression tests- misc_protocol.out @@ -34,7 +34,6 @@ "minimal_participation_ratio": { "numerator": 2, "denominator": 3 }, "limit_of_delegation_over_baking": 19, "percentage_of_frozen_deposits_slashed_per_double_baking": 500, - "percentage_of_frozen_deposits_slashed_per_double_attestation": 5000, "max_slashing_per_block": 10000, "max_slashing_threshold": 101, "cache_script_size": 100000000, "cache_stake_distribution_cycles": 5, "cache_sampler_state_cycles": 5, @@ -80,7 +79,7 @@ "center_dz": { "numerator": "1", "denominator": "2" }, "radius_dz": { "numerator": "1", "denominator": "50" } }, "adaptive_issuance_activation_vote_enable": true, - "adaptive_issuance_force_activation": false, "ns_enable": true, + "adaptive_issuance_force_activation": false, "direct_ticket_spending_enable": false, "aggregate_attestation": false, "allow_tz4_delegate_enable": true, "all_bakers_attest_enable": false } diff --git a/tezt/tests/expected/weeklynet.ml/Alpha- weeklynet regression test.out b/tezt/tests/expected/weeklynet.ml/Alpha- weeklynet regression test.out index a85d0a278773..a4289984e283 100644 --- a/tezt/tests/expected/weeklynet.ml/Alpha- weeklynet regression test.out +++ b/tezt/tests/expected/weeklynet.ml/Alpha- weeklynet regression test.out @@ -24,7 +24,6 @@ "minimal_participation_ratio": { "numerator": 2, "denominator": 3 }, "limit_of_delegation_over_baking": 9, "percentage_of_frozen_deposits_slashed_per_double_baking": 700, - "percentage_of_frozen_deposits_slashed_per_double_attestation": 5000, "max_slashing_per_block": 10000, "max_slashing_threshold": 2334, "cache_script_size": 100000000, "cache_stake_distribution_cycles": 5, "cache_sampler_state_cycles": 5, @@ -70,6 +69,6 @@ "center_dz": { "numerator": "1", "denominator": "2" }, "radius_dz": { "numerator": "1", "denominator": "50" } }, "adaptive_issuance_activation_vote_enable": true, - "adaptive_issuance_force_activation": false, "ns_enable": true, + "adaptive_issuance_force_activation": false, "direct_ticket_spending_enable": false, "aggregate_attestation": false, "allow_tz4_delegate_enable": false, "all_bakers_attest_enable": false } -- GitLab From 40067e7f9b7f4703b56d37c51315eb1d4275c3fe Mon Sep 17 00:00:00 2001 From: Diane Gallois-Wong Date: Thu, 5 Dec 2024 11:46:36 +0100 Subject: [PATCH 12/13] Tezt/weeklynet: update config --- tezt/tests/weeklynet_configs/alpha.json | 2 -- 1 file changed, 2 deletions(-) diff --git a/tezt/tests/weeklynet_configs/alpha.json b/tezt/tests/weeklynet_configs/alpha.json index 8094b09b7a73..84264f34cf49 100644 --- a/tezt/tests/weeklynet_configs/alpha.json +++ b/tezt/tests/weeklynet_configs/alpha.json @@ -63,7 +63,6 @@ }, "limit_of_delegation_over_baking": 9, "percentage_of_frozen_deposits_slashed_per_double_baking": 700, - "percentage_of_frozen_deposits_slashed_per_double_attestation": 5000, "max_slashing_per_block": 10000, "max_slashing_threshold": 2334, "cache_script_size": 100000000, @@ -153,7 +152,6 @@ }, "adaptive_issuance_activation_vote_enable": true, "adaptive_issuance_force_activation": false, - "ns_enable": true, "direct_ticket_spending_enable": false, "aggregate_attestation": false, "allow_tz4_delegate_enable": false, -- GitLab From 2d4afce72b5928f9703ed1d4e4cdc1a60bf0a3d3 Mon Sep 17 00:00:00 2001 From: Diane Gallois-Wong Date: Thu, 5 Dec 2024 11:50:55 +0100 Subject: [PATCH 13/13] Doc: update changelog --- docs/protocols/alpha.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/protocols/alpha.rst b/docs/protocols/alpha.rst index 4e42a4e2bcd9..0a5dc83b8f46 100644 --- a/docs/protocols/alpha.rst +++ b/docs/protocols/alpha.rst @@ -87,4 +87,5 @@ Internal -------- - Removed obsolete feature flags and code related to adaptive issuance - and autostaking. (MR :gl:`!15215`) + activation, auto-staking, and old slashing. (MRs :gl:`!15215`, + :gl:`!15223`) -- GitLab