diff --git a/client-libs/kaitai-struct-files/files/alpha__constants.ksy b/client-libs/kaitai-struct-files/files/alpha__constants.ksy index e91dff4cc6c1ac3dd19aec2c0d4d03bcff2321d1..57b37cddac9161485126b2342f3a872319705a8d 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 1b4e8371f95011b7692b9f222f2775043ca8ad18..af2c8cac106f99468c5eb2381b1bb8ab7a4bf00c 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 469be38cb185745ec3eb845eb6d977cea80bb5b5..5b4ef02703a7974b9c0dace50fc9dbf5b8278c39 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 diff --git a/docs/protocols/alpha.rst b/docs/protocols/alpha.rst index 4e42a4e2bcd901385a7c1faceadb078f7821fb10..0a5dc83b8f466c2ffcc3d85bb728af96703a9452 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`) diff --git a/src/proto_alpha/lib_parameters/default_parameters.ml b/src/proto_alpha/lib_parameters/default_parameters.ml index 7ee3109164c6c383fa692ecf01997959cbbf9e37..369848b78fd08d2421c44f9821bd23c760bb2978 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 *) @@ -325,7 +323,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 132a0a4c0293fedd319248d1ba93a25cca1229c3..df2f28456d6a336d27e1707bad1e2b96f0296090 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 = { @@ -938,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; @@ -1047,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 ad3bbd5d59ea53740ed32aee1b8687ca1a085eb4..e105ec83b31ac813962eda0550505206a8e873f0 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 = { @@ -278,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; @@ -484,22 +482,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 +502,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 @@ -598,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, @@ -644,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, @@ -691,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; @@ -749,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 8bb3998f95314995675fdf7794f5a5cad2b508c5..60a1a50fbd15bffd9bb1f3dac29c7b411533baae 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 = { @@ -214,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 bf7d3f99681185e76a8a0a080b8cadc04f38e839..d765b1c2f2f58d14097600043144b357ed23eb78 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 @@ -295,8 +291,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 b49339fc1662892b7e9361fc7b69df877c1f4052..2de3bbe766325148c10a1e8371c42cc8b81304c3 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 @@ -158,8 +155,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 dd447b8f1adfd4f148720a8aec8576245bbeda91..9d6deb9d05e73116b4bea52aba0ce9a4165941f4 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 2a5ec00278444722ee4ec27ad337b57085b55259..f42782d048f8b4635aae5f318e4a3e48730f4da7 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 = @@ -1221,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 *) @@ -1274,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 *) @@ -1445,7 +1441,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 +1454,6 @@ let prepare_first_block ~level ~timestamp chain_id ctxt = adaptive_rewards_params; activation_vote_enable; force_activation; - ns_enable; } in let issuance_weights = @@ -1515,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 *) @@ -1565,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 *) diff --git a/src/proto_alpha/lib_protocol/slash_percentage.ml b/src/proto_alpha/lib_protocol/slash_percentage.ml index 83e31903dab769c23f16b23666c9bbb71696ea87..722dfd4e298b0b5da81a243d8023b1e198ff4a22 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) = 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 0bcf3c37e8fa8d6e40178ca9040b7997f2e9978d..afc90d9a9e600e822d8efd16fae120848d4d2019 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 acf485e4256cc82dd71f859977773923a414029f..fa6d6342028496d3a41f076a98e9582542e38e7e 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/scenario_op.ml b/src/proto_alpha/lib_protocol/test/helpers/scenario_op.ml index 82480ed04efc53a4cffda5df62822f8c7e949932..26295574d735c0eb677a990668b45f1db3af390c 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 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 bbc4dbe437bc2578a986fb440f3e1e76e7534227..9334eb6699a2ce711388d94afb8434873f150f9a 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 @@ -108,6 +123,18 @@ module Full_denunciation = struct pp list1 list2 + + let slashing_percentage ~block_before_slash + (misbehaviour : Protocol.Misbehaviour_repr.t) all_denunciations_to_apply = + let all_culprits = + 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 + slashing_percentage ~block_before_slash misbehaviour ~all_culprits end let apply_slashing_account all_denunciations_to_apply @@ -147,18 +174,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 2a9a2c368ce757be184d0f91e55513533aa4590c..d1fddd0468af43c59d31f8997923713c3119ed4c 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 @@ -48,6 +67,22 @@ 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 + + (** Same as {!slashing_percentage} (top-level function), but takes + directly a list of full denunciations as an argument. + + 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. + + See {!slashing_percentage} for the precondition on + [block_before_slash]. *) + 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 7aaa0b02903d75e5264b5330b82b24ce67542403..2e23e73dc03dfb1349e56298047e7154631ed4d4 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,17 @@ 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 -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) = - 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 + 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 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 30a82b160475395771ec80500fa259f0ca41f846..eb9c8fd4ba5a60a7be4b7e49a8dc5ef977ad04c4 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 @@ -49,20 +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.*) - - (** 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 : - (Signature.public_key_hash * Protocol.Denunciations_repr.item) list -> - Block.t -> - State.t -> - Protocol.Misbehaviour_repr.t -> - Protocol.Percentage.t tzresult Lwt.t -end 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 777e15f42d3a04f9b830a23c1a4a1575c270bbfa..41013b9227db683b3022de0dbcd93e87f9741b7d 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 @@ -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 + 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) @@ -192,12 +196,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 @@ -255,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 @@ -269,8 +296,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 @@ -283,8 +310,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 @@ -329,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. @@ -368,8 +404,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 @@ -443,8 +479,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 @@ -671,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 @@ -692,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 @@ -723,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. *) @@ -754,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) @@ -768,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. *) @@ -838,8 +878,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_baking.ml b/src/proto_alpha/lib_protocol/test/integration/consensus/test_double_baking.ml index c94ba9562ad609e94e04014d56f0eadc4f685ab5..f227147dd345c4b3165eb1559efbed5d5691d5dd 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 3b2071821bebf2a87e5b0fdd0df6614d7fa34aa5..eb407ddb470522aade6e021db687a6b279547dad 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 @@ -365,8 +368,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 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 a4dd7f767f3f929a4e1b988927ba21109c192614..bea9b82b10644d13f9b282908e7bcbb92e7eabe2 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 5fe1fea4601b20c7ed8acaeb00d800bbf51b106b..9e1ee2c472bd7574a633f6388e274e2589a6c553 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 e3ded8d6879d43823b71b04624d6c54ee65373c6..5a9c622dd68af95b157c2383740655e69d57153f 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,25 +70,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 - (** 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 () = @@ -182,7 +159,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; 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 8a22eae11331b509cd59e3c73678e8e1867e4958..4b8e30747e46809d614b22f8efa479679c222c6d 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 e56cd5fbbe64d2df6e469414b10ffc40084dfde4..604258e8de4d93aa35058ee0abef4fe9695ddf1a 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 3070b3387917be5d30f004490a4fe0c44bd53161..3254159df6e9212ecf822bbdd81c6372a3d94ab7 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 a85d0a2787730776412650a44e4c1be0cc354937..a4289984e2836bcaf76390515a05f709269c96c1 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 } diff --git a/tezt/tests/weeklynet_configs/alpha.json b/tezt/tests/weeklynet_configs/alpha.json index 8094b09b7a732b8d1ff3df2a3b7b358990b12ea3..84264f34cf49b99385e88b4ca31dc061c9cb25f2 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,