diff --git a/docs/protocols/alpha.rst b/docs/protocols/alpha.rst index 92c4550dbfaebde2b8636f6153ac79727f668835..6706d13533204cfc68371cd10ccc12185464a571 100644 --- a/docs/protocols/alpha.rst +++ b/docs/protocols/alpha.rst @@ -36,6 +36,15 @@ Gas improvements Breaking Changes ---------------- +- Protocol parameter ``ratio_of_frozen_deposits_slashed_per_double_endorsement`` is + converted from the ratio ``1/5`` into the percentage ``50%`` and renamed to + ``percentage_of_frozen_deposits_slashed_per_double_endorsement``. (MR :gl:`!8753`) + +- Protocol parameter ``double_baking_punishment`` is converted from a fixed + value of ``640tz`` into the percentage ``11%`` and renamed to + ``percentage_of_frozen_deposits_slashed_per_double_baking``. (MR :gl:`!8753`) + + RPC Changes ----------- diff --git a/src/proto_alpha/lib_parameters/default_parameters.ml b/src/proto_alpha/lib_parameters/default_parameters.ml index 85ce8ea4152c425cc9b08e50bb01020a97b85699..9694edbbe003a7b586cf5b0533ee00384645819a 100644 --- a/src/proto_alpha/lib_parameters/default_parameters.ml +++ b/src/proto_alpha/lib_parameters/default_parameters.ml @@ -180,9 +180,8 @@ let constants_mainnet = minimal_participation_ratio = {numerator = 2; denominator = 3}; max_slashing_period = 2; frozen_deposits_percentage = 10; - double_baking_punishment = Tez.(mul_exn one 640); - ratio_of_frozen_deposits_slashed_per_double_endorsement = - {numerator = 1; denominator = 2}; + percentage_of_frozen_deposits_slashed_per_double_baking = 11; + percentage_of_frozen_deposits_slashed_per_double_endorsement = 50; (* The `testnet_dictator` should absolutely be None on mainnet *) testnet_dictator = None; initial_seed = None; diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index 62f800366a9a8ec7931033b59edc59c12ad3a2fc..ddbb4ac646924385727a1d68b7364b4780b49ac6 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -884,8 +884,8 @@ module Constants : sig consensus_threshold : int; max_slashing_period : int; frozen_deposits_percentage : int; - double_baking_punishment : Tez.t; - ratio_of_frozen_deposits_slashed_per_double_endorsement : Ratio.t; + percentage_of_frozen_deposits_slashed_per_double_baking : int; + percentage_of_frozen_deposits_slashed_per_double_endorsement : int; testnet_dictator : public_key_hash option; initial_seed : State_hash.t option; cache_script_size : int; @@ -971,10 +971,10 @@ module Constants : sig val frozen_deposits_percentage : context -> int - val double_baking_punishment : context -> Tez.t + val percentage_of_frozen_deposits_slashed_per_double_baking : context -> int - val ratio_of_frozen_deposits_slashed_per_double_endorsement : - context -> Ratio.t + val percentage_of_frozen_deposits_slashed_per_double_endorsement : + context -> int val testnet_dictator : context -> public_key_hash option diff --git a/src/proto_alpha/lib_protocol/constants_parametric_repr.ml b/src/proto_alpha/lib_protocol/constants_parametric_repr.ml index 6ef035b0b4ada3562ed85073902588842f715488..46de36c9137f67612afeb4dbfa61137a85937d7c 100644 --- a/src/proto_alpha/lib_protocol/constants_parametric_repr.ml +++ b/src/proto_alpha/lib_protocol/constants_parametric_repr.ml @@ -167,8 +167,8 @@ type t = { consensus_threshold : int; max_slashing_period : int; frozen_deposits_percentage : int; - double_baking_punishment : Tez_repr.t; - ratio_of_frozen_deposits_slashed_per_double_endorsement : Ratio_repr.t; + percentage_of_frozen_deposits_slashed_per_double_baking : int; + percentage_of_frozen_deposits_slashed_per_double_endorsement : int; testnet_dictator : Signature.Public_key_hash.t option; initial_seed : State_hash.t option; (* If a new cache is added, please also modify the @@ -429,8 +429,8 @@ let encoding = ( ( c.minimal_participation_ratio, c.max_slashing_period, c.frozen_deposits_percentage, - c.double_baking_punishment, - c.ratio_of_frozen_deposits_slashed_per_double_endorsement, + c.percentage_of_frozen_deposits_slashed_per_double_baking, + c.percentage_of_frozen_deposits_slashed_per_double_endorsement, c.testnet_dictator, c.initial_seed ), ( ( c.cache_script_size, @@ -466,8 +466,8 @@ let encoding = ( ( minimal_participation_ratio, max_slashing_period, frozen_deposits_percentage, - double_baking_punishment, - ratio_of_frozen_deposits_slashed_per_double_endorsement, + percentage_of_frozen_deposits_slashed_per_double_baking, + percentage_of_frozen_deposits_slashed_per_double_endorsement, testnet_dictator, initial_seed ), ( ( cache_script_size, @@ -504,8 +504,8 @@ let encoding = consensus_committee_size; consensus_threshold; frozen_deposits_percentage; - double_baking_punishment; - ratio_of_frozen_deposits_slashed_per_double_endorsement; + percentage_of_frozen_deposits_slashed_per_double_baking; + percentage_of_frozen_deposits_slashed_per_double_endorsement; testnet_dictator; initial_seed; cache_script_size; @@ -556,10 +556,12 @@ let encoding = (req "minimal_participation_ratio" Ratio_repr.encoding) (req "max_slashing_period" int31) (req "frozen_deposits_percentage" int31) - (req "double_baking_punishment" Tez_repr.encoding) (req - "ratio_of_frozen_deposits_slashed_per_double_endorsement" - Ratio_repr.encoding) + "percentage_of_frozen_deposits_slashed_per_double_baking" + uint8) + (req + "percentage_of_frozen_deposits_slashed_per_double_endorsement" + uint8) (opt "testnet_dictator" Signature.Public_key_hash.encoding) (opt "initial_seed" State_hash.encoding)) (merge_objs diff --git a/src/proto_alpha/lib_protocol/constants_parametric_repr.mli b/src/proto_alpha/lib_protocol/constants_parametric_repr.mli index b6b57acbacdb1044513105dfe5c1b12afb3f4ad2..e21bc9a37a179932cb7e8cdb2e02bb4ef272f82b 100644 --- a/src/proto_alpha/lib_protocol/constants_parametric_repr.mli +++ b/src/proto_alpha/lib_protocol/constants_parametric_repr.mli @@ -196,8 +196,8 @@ type t = { (* in cycles *) frozen_deposits_percentage : int; (* that is, (100 * delegated tz / own tz) *) - double_baking_punishment : Tez_repr.t; - ratio_of_frozen_deposits_slashed_per_double_endorsement : Ratio_repr.t; + percentage_of_frozen_deposits_slashed_per_double_baking : int; + percentage_of_frozen_deposits_slashed_per_double_endorsement : int; testnet_dictator : Signature.Public_key_hash.t option; initial_seed : State_hash.t option; cache_script_size : int; diff --git a/src/proto_alpha/lib_protocol/constants_repr.ml b/src/proto_alpha/lib_protocol/constants_repr.ml index b4faea3ebb6813a62f373c90eac181dff0dd8f84..16a1b80597a9d16f4eeaf41e10d0cf7d7eacf5dd 100644 --- a/src/proto_alpha/lib_protocol/constants_repr.ml +++ b/src/proto_alpha/lib_protocol/constants_repr.ml @@ -229,18 +229,23 @@ let check_constants constants = or equal than 100.") >>? fun () -> error_unless - Tez_repr.(constants.double_baking_punishment >= zero) + Compare.Int.( + constants.percentage_of_frozen_deposits_slashed_per_double_baking >= 0 + && constants.percentage_of_frozen_deposits_slashed_per_double_baking + <= 100) (Invalid_protocol_constants - "The double baking punishment must be non-negative.") + "The percentage of frozen deposits slashed per double baking must be \ + between 0 and 100 included.") >>? fun () -> error_unless - (let Ratio_repr.{numerator; denominator} = - constants.ratio_of_frozen_deposits_slashed_per_double_endorsement - in - Compare.Int.(numerator >= 0 && denominator > 0)) + Compare.Int.( + constants.percentage_of_frozen_deposits_slashed_per_double_endorsement + >= 0 + && constants.percentage_of_frozen_deposits_slashed_per_double_endorsement + <= 100) (Invalid_protocol_constants - "The ratio of frozen deposits ratio slashed per double endorsement must \ - be a non-negative valid ratio.") + "The percentage of frozen deposits slashed per double endorsement must \ + be between 0 and 100 included.") >>? fun () -> error_unless (let snapshot_frequence = diff --git a/src/proto_alpha/lib_protocol/constants_storage.ml b/src/proto_alpha/lib_protocol/constants_storage.ml index dacae7e11584edf107f7613a6e45338af355deec..abcf569dd7fc51c227a921fc3d648faeb691fcfc 100644 --- a/src/proto_alpha/lib_protocol/constants_storage.ml +++ b/src/proto_alpha/lib_protocol/constants_storage.ml @@ -134,9 +134,9 @@ let frozen_deposits_percentage c = let constants = Raw_context.constants c in constants.frozen_deposits_percentage -let double_baking_punishment c = +let percentage_of_frozen_deposits_slashed_per_double_baking c = let constants = Raw_context.constants c in - constants.double_baking_punishment + constants.percentage_of_frozen_deposits_slashed_per_double_baking let tx_rollup_enable c = let tx_rollup = Raw_context.tx_rollup c in @@ -198,9 +198,9 @@ let tx_rollup_rejection_max_proof_size c = let tx_rollup = Raw_context.tx_rollup c in tx_rollup.rejection_max_proof_size -let ratio_of_frozen_deposits_slashed_per_double_endorsement c = +let percentage_of_frozen_deposits_slashed_per_double_endorsement c = let constants = Raw_context.constants c in - constants.ratio_of_frozen_deposits_slashed_per_double_endorsement + constants.percentage_of_frozen_deposits_slashed_per_double_endorsement let testnet_dictator c = let constants = Raw_context.constants c in diff --git a/src/proto_alpha/lib_protocol/constants_storage.mli b/src/proto_alpha/lib_protocol/constants_storage.mli index b899229650468056d4730fac3a4fc3c77d22e222..688f68a517a58a7cfd239ee13f191e254ce6a86f 100644 --- a/src/proto_alpha/lib_protocol/constants_storage.mli +++ b/src/proto_alpha/lib_protocol/constants_storage.mli @@ -84,7 +84,8 @@ val max_slashing_period : Raw_context.t -> int val frozen_deposits_percentage : Raw_context.t -> int -val double_baking_punishment : Raw_context.t -> Tez_repr.t +val percentage_of_frozen_deposits_slashed_per_double_baking : + Raw_context.t -> int val tx_rollup_enable : Raw_context.t -> bool @@ -116,8 +117,8 @@ val tx_rollup_rejection_max_proof_size : Raw_context.t -> int val tx_rollup_sunset_level : Raw_context.t -> int32 -val ratio_of_frozen_deposits_slashed_per_double_endorsement : - Raw_context.t -> Ratio_repr.t +val percentage_of_frozen_deposits_slashed_per_double_endorsement : + Raw_context.t -> int val testnet_dictator : Raw_context.t -> Signature.Public_key_hash.t option 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 7b0406f2d0ac4b176ca94e9bffbdad0367fc0080..28ad5832b23c109c5d5706485c10c3baa2d25e28 100644 --- a/src/proto_alpha/lib_protocol/delegate_slashed_deposits_storage.ml +++ b/src/proto_alpha/lib_protocol/delegate_slashed_deposits_storage.ml @@ -39,78 +39,62 @@ let already_slashed_for_double_baking ctxt delegate (level : Level_repr.t) = type punishing_amounts = {reward : Tez_repr.t; amount_to_burn : Tez_repr.t} -let finish_punish ctxt delegate (level : Level_repr.t) updated_slashed - punishing_amount = - let open Lwt_result_syntax in - let reward, amount_to_burn = Tez_repr.div2_sub punishing_amount in - let*! ctxt = - Storage.Slashed_deposits.add - (ctxt, level.cycle) - (level.level, delegate) - updated_slashed - in - return (ctxt, {reward; amount_to_burn}) +(** [punish_double_signing ~get ~set ~get_percentage ctxt delegate level] record + in the context that the given [delegate] has now been slashed for the + double signing event for the given [level] and return the amounts of the + frozen deposits to burn and to reward the denuncer. -let punish_double_endorsing ctxt delegate (level : Level_repr.t) = + The double signing event corresponds to a field in {!Storage.slashed_level}, + retrieved with [get] and set to true with [set]. + + The part to burn is retrieved with [get_percentage]. +*) +let punish_double_signing ~get ~set ~get_percentage ctxt delegate + (level : Level_repr.t) = let open Lwt_result_syntax in - let* slashed = + let* slashed_opt = Storage.Slashed_deposits.find (ctxt, level.cycle) (level.level, delegate) in - let updated_slashed = - match slashed with - | None -> {Storage.for_double_endorsing = true; for_double_baking = false} - | Some slashed -> - assert (Compare.Bool.(slashed.for_double_endorsing = false)) ; - {slashed with for_double_endorsing = true} + let slashed = + Option.value slashed_opt ~default:Storage.default_slashed_level in + assert (Compare.Bool.(get slashed = false)) ; + let updated_slashed = set slashed in let delegate_contract = Contract_repr.Implicit delegate in let* frozen_deposits = Frozen_deposits_storage.get ctxt delegate_contract in - let slashing_ratio : Ratio_repr.t = - Constants_storage.ratio_of_frozen_deposits_slashed_per_double_endorsement - ctxt - in + let slashing_percentage = get_percentage ctxt in let punish_value = Tez_repr.( - div_exn - (mul_exn frozen_deposits.initial_amount slashing_ratio.numerator) - slashing_ratio.denominator) + div_exn (mul_exn frozen_deposits.initial_amount slashing_percentage) 100) in let punishing_amount = Tez_repr.(min frozen_deposits.current_amount punish_value) in - finish_punish - ctxt - delegate - (level : Level_repr.t) - updated_slashed - punishing_amount - -let punish_double_baking ctxt delegate (level : Level_repr.t) = - let open Lwt_result_syntax in - let* slashed = - Storage.Slashed_deposits.find (ctxt, level.cycle) (level.level, delegate) - in - let updated_slashed = - match slashed with - | None -> {Storage.for_double_baking = true; for_double_endorsing = false} - | Some slashed -> - assert (Compare.Bool.(slashed.for_double_baking = false)) ; - {slashed with for_double_baking = true} + let reward, amount_to_burn = Tez_repr.div2_sub punishing_amount in + let*! ctxt = + Storage.Slashed_deposits.add + (ctxt, level.cycle) + (level.level, delegate) + updated_slashed in - let delegate_contract = Contract_repr.Implicit delegate in - let* frozen_deposits = Frozen_deposits_storage.get ctxt delegate_contract in - let slashing_for_one_block = - Constants_storage.double_baking_punishment ctxt + return (ctxt, {reward; amount_to_burn}) + +let punish_double_endorsing = + let get Storage.{for_double_endorsing; _} = for_double_endorsing in + let set slashed = Storage.{slashed with for_double_endorsing = true} in + let get_percentage = + Constants_storage + .percentage_of_frozen_deposits_slashed_per_double_endorsement in - let punishing_amount = - Tez_repr.(min frozen_deposits.current_amount slashing_for_one_block) + punish_double_signing ~get ~set ~get_percentage + +let punish_double_baking = + let get Storage.{for_double_baking; _} = for_double_baking in + let set slashed = Storage.{slashed with for_double_baking = true} in + let get_percentage = + Constants_storage.percentage_of_frozen_deposits_slashed_per_double_baking in - finish_punish - ctxt - delegate - (level : Level_repr.t) - updated_slashed - punishing_amount + punish_double_signing ~get ~set ~get_percentage let clear_outdated_slashed_deposits ctxt ~new_cycle = let max_slashable_period = Constants_storage.max_slashing_period ctxt in diff --git a/src/proto_alpha/lib_protocol/raw_context.ml b/src/proto_alpha/lib_protocol/raw_context.ml index 1e83a1d7a2e81f890dd266448929f099306ff4a9..765dbae7a0c385f84c7b43e3469ce04dd6dcd028 100644 --- a/src/proto_alpha/lib_protocol/raw_context.ml +++ b/src/proto_alpha/lib_protocol/raw_context.ml @@ -990,6 +990,22 @@ let prepare_first_block ~level ~timestamp ctxt = c_gen.reward_weights in + let percentage_of_frozen_deposits_slashed_per_double_endorsement = + 100 + * c.ratio_of_frozen_deposits_slashed_per_double_endorsement.numerator + / c.ratio_of_frozen_deposits_slashed_per_double_endorsement.denominator + in + let percentage_of_frozen_deposits_slashed_per_double_baking = + let double_baking_punishment_times_100 = + Int64.mul 100L (Tez_repr.to_mutez c.double_baking_punishment) + in + let percentage_rounded_down = + Int64.div + double_baking_punishment_times_100 + (Tez_repr.to_mutez c.minimal_stake) + in + 1 + Int64.to_int percentage_rounded_down + in let constants = Constants_parametric_repr. { @@ -1022,9 +1038,8 @@ let prepare_first_block ~level ~timestamp ctxt = minimal_participation_ratio = c.minimal_participation_ratio; max_slashing_period = c.max_slashing_period; frozen_deposits_percentage = c.frozen_deposits_percentage; - double_baking_punishment = c.double_baking_punishment; - ratio_of_frozen_deposits_slashed_per_double_endorsement = - c.ratio_of_frozen_deposits_slashed_per_double_endorsement; + percentage_of_frozen_deposits_slashed_per_double_baking; + percentage_of_frozen_deposits_slashed_per_double_endorsement; (* The `testnet_dictator` should absolutely be None on mainnet *) testnet_dictator = c.testnet_dictator; initial_seed = c.initial_seed; diff --git a/src/proto_alpha/lib_protocol/storage.ml b/src/proto_alpha/lib_protocol/storage.ml index 2a2850b7f2ce336d827709472e943900b780649d..7124f5ba6cd78c2c7271a47c4a381e2fd09ee10a 100644 --- a/src/proto_alpha/lib_protocol/storage.ml +++ b/src/proto_alpha/lib_protocol/storage.ml @@ -967,6 +967,9 @@ module Consensus_keys = type slashed_level = {for_double_endorsing : bool; for_double_baking : bool} +let default_slashed_level = + {for_double_endorsing = false; for_double_baking = false} + module Slashed_level = struct type t = slashed_level diff --git a/src/proto_alpha/lib_protocol/storage.mli b/src/proto_alpha/lib_protocol/storage.mli index b1280cff1f984ab5abe2a312d8823a8257597271..9e0b6257cf9f966373b3649ce01c798d11299e1e 100644 --- a/src/proto_alpha/lib_protocol/storage.mli +++ b/src/proto_alpha/lib_protocol/storage.mli @@ -385,6 +385,9 @@ module Consensus_keys : type slashed_level = {for_double_endorsing : bool; for_double_baking : bool} +(** [slashed_level] with all fields being [false]. *) +val default_slashed_level : slashed_level + (** Set used to avoid slashing multiple times the same event *) module Slashed_deposits : Indexed_data_storage 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 c9047155bb616e409e4591cf41495f9d98f15427..85a208162934cb0dd754c24ca4f8336675b9aea1 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 @@ -68,8 +68,10 @@ let double_baking ctxt ?(correct_order = true) bh1 bh2 = exposed by a double baking evidence operation. *) let test_valid_double_baking_evidence () = Context.init2 ~consensus_threshold:0 () >>=? fun (genesis, contracts) -> - Context.get_constants (B genesis) - >>=? fun Constants.{parametric = {double_baking_punishment; _}; _} -> + Context.get_constants (B genesis) >>=? fun c -> + let p = + c.parametric.percentage_of_frozen_deposits_slashed_per_double_baking + in Context.get_first_different_bakers (B genesis) >>=? fun (baker1, baker2) -> block_fork ~policy:(By_account baker1) contracts genesis >>=? fun (blk_a, blk_b) -> @@ -80,10 +82,13 @@ let test_valid_double_baking_evidence () = >>=? fun frozen_deposits_before -> Context.Delegate.current_frozen_deposits (B blk_final) baker1 >>=? fun frozen_deposits_after -> - let slashed_amount = - Test_tez.(frozen_deposits_before -! frozen_deposits_after) + let expected_frozen_deposits_after = + Test_tez.(frozen_deposits_before *! Int64.of_int (100 - p) /! 100L) in - Assert.equal_tez ~loc:__LOC__ slashed_amount double_baking_punishment + Assert.equal_tez + ~loc:__LOC__ + frozen_deposits_after + expected_frozen_deposits_after >>=? fun () -> (* Check that the initial frozen deposits has not changed *) Context.Delegate.initial_frozen_deposits (B blk_final) baker1 @@ -129,23 +134,21 @@ let test_valid_double_baking_followed_by_double_endorsing () = Context.Delegate.current_frozen_deposits (B blk_final) baker1 >>=? fun frozen_deposits_after -> Context.get_constants (B genesis) >>=? fun csts -> - let r = - csts.parametric.ratio_of_frozen_deposits_slashed_per_double_endorsement + let p_de = + csts.parametric.percentage_of_frozen_deposits_slashed_per_double_endorsement in - let expected_frozen_deposits_after_de = - Test_tez.( - frozen_deposits_before - *! Int64.of_int (r.denominator - r.numerator) - /! Int64.of_int r.denominator) + let p_db = + csts.parametric.percentage_of_frozen_deposits_slashed_per_double_baking in - (* the deposit after double baking and double endorsing equals the - expected deposit after double endorsing minus the double baking - punishment *) + let p = p_de + p_db (* assuming the sum doesn't exceed 100% *) in + let expected_frozen_deposits_after = + Test_tez.(frozen_deposits_before *! Int64.of_int (100 - p) /! 100L) + in + (* Both slashings are computed on the initial amount of frozen deposits so + the percentages are additive, not multiplicative. *) Assert.equal_tez ~loc:__LOC__ - Test_tez.( - expected_frozen_deposits_after_de - -! csts.parametric.double_baking_punishment) + expected_frozen_deposits_after frozen_deposits_after (* auxiliary function used in [test_valid_double_endorsing_followed_by_double_baking] *) @@ -180,23 +183,21 @@ let test_valid_double_endorsing_followed_by_double_baking () = Context.Delegate.current_frozen_deposits (B blk_with_db_evidence) baker1 >>=? fun frozen_deposits_after -> Context.get_constants (B genesis) >>=? fun csts -> - let r = - csts.parametric.ratio_of_frozen_deposits_slashed_per_double_endorsement + let p_de = + csts.parametric.percentage_of_frozen_deposits_slashed_per_double_endorsement + in + let p_db = + csts.parametric.percentage_of_frozen_deposits_slashed_per_double_baking in - let expected_frozen_deposits_after_de = - Test_tez.( - frozen_deposits_before - *! Int64.of_int (r.denominator - r.numerator) - /! Int64.of_int r.denominator) + let p = p_de + p_db (* assuming the sum doesn't exceed 100% *) in + let expected_frozen_deposits_after = + Test_tez.(frozen_deposits_before *! Int64.of_int (100 - p) /! 100L) in - (* the deposit after double baking and double endorsing equals the - expected deposit after double endorsing minus the double baking - punishment *) + (* Both slashings are computed on the initial amount of frozen deposits so + the percentages are additive, not multiplicative. *) Assert.equal_tez ~loc:__LOC__ - Test_tez.( - expected_frozen_deposits_after_de - -! csts.parametric.double_baking_punishment) + expected_frozen_deposits_after frozen_deposits_after (** Test that the payload producer of the block containing a double @@ -204,8 +205,10 @@ let test_valid_double_endorsing_followed_by_double_baking () = the reward. *) let test_payload_producer_gets_evidence_rewards () = Context.init_n ~consensus_threshold:0 10 () >>=? fun (genesis, contracts) -> - Context.get_constants (B genesis) - >>=? fun Constants.{parametric = {double_baking_punishment; _}; _} -> + Context.get_constants (B genesis) >>=? fun c -> + let p = + c.parametric.percentage_of_frozen_deposits_slashed_per_double_baking + in Context.get_baking_reward_fixed_portion (B genesis) >>=? fun baking_reward_fixed_portion -> Context.get_first_different_bakers (B genesis) >>=? fun (baker1, baker2) -> @@ -239,11 +242,17 @@ let test_payload_producer_gets_evidence_rewards () = >>=? fun frozen_deposits_before -> Context.Delegate.current_frozen_deposits (B b') baker1 >>=? fun frozen_deposits_after -> + let expected_frozen_deposits_after = + Test_tez.(frozen_deposits_before *! Int64.of_int (100 - p) /! 100L) + in + Assert.equal_tez + ~loc:__LOC__ + frozen_deposits_after + expected_frozen_deposits_after + >>=? fun () -> let slashed_amount = Test_tez.(frozen_deposits_before -! frozen_deposits_after) in - Assert.equal_tez ~loc:__LOC__ slashed_amount double_baking_punishment - >>=? fun () -> (* [baker2] included the double baking evidence in [b_with_evidence] and so it receives the reward for the evidence included in [b'] (besides the reward for proposing the payload). *) @@ -263,7 +272,7 @@ let test_payload_producer_gets_evidence_rewards () = Assert.equal_tez ~loc:__LOC__ full_balance_at_b' - Test_tez.(full_balance_at_b1 -! double_baking_punishment) + Test_tez.(full_balance_at_b1 -! slashed_amount) (****************************************************************) (* The following test scenarios are supposed to raise errors. *) diff --git a/src/proto_alpha/lib_protocol/test/integration/consensus/test_double_endorsement.ml b/src/proto_alpha/lib_protocol/test/integration/consensus/test_double_endorsement.ml index 06378385be48b124c512444792f1468916e05878..7222d4fb9ce06259fa5b8c874d51e4d45b09b561 100644 --- a/src/proto_alpha/lib_protocol/test/integration/consensus/test_double_endorsement.ml +++ b/src/proto_alpha/lib_protocol/test/integration/consensus/test_double_endorsement.ml @@ -99,14 +99,11 @@ let test_valid_double_endorsement_evidence () = Context.Delegate.current_frozen_deposits (B blk_final) delegate >>=? fun frozen_deposits_after -> Context.get_constants (B genesis) >>=? fun csts -> - let r = - csts.parametric.ratio_of_frozen_deposits_slashed_per_double_endorsement + let p = + csts.parametric.percentage_of_frozen_deposits_slashed_per_double_endorsement in let expected_frozen_deposits_after = - Test_tez.( - frozen_deposits_before - *! Int64.of_int (r.denominator - r.numerator) - /! Int64.of_int r.denominator) + Test_tez.(frozen_deposits_before *! Int64.of_int (100 - p) /! 100L) in Assert.equal_tez ~loc:__LOC__ @@ -392,9 +389,9 @@ let test_freeze_more_with_low_balance = consensus_threshold = 0; origination_size = 0; preserved_cycles = 5; - ratio_of_frozen_deposits_slashed_per_double_endorsement = - (* enforce that ratio is 50% is the test's params. *) - {numerator = 1; denominator = 2}; + percentage_of_frozen_deposits_slashed_per_double_endorsement = + (* enforce that percentage is 50% in the test's params. *) + 50; } in Context.init_with_constants2 constants >>=? fun (genesis, (c1, c2)) -> @@ -430,14 +427,12 @@ let test_freeze_more_with_low_balance = >>=? fun () -> (* We also check that compared to deposits at block [b2], [account1] lost 50% of its deposits. *) - let slash_ratio = - constants.ratio_of_frozen_deposits_slashed_per_double_endorsement + let slash_percentage = + constants.percentage_of_frozen_deposits_slashed_per_double_endorsement in let expected_frozen_deposits_after = Test_tez.( - info2.frozen_deposits - *! Int64.of_int (slash_ratio.denominator - slash_ratio.numerator) - /! Int64.of_int slash_ratio.denominator) + info2.frozen_deposits *! Int64.of_int (100 - slash_percentage) /! 100L) in Assert.equal_tez ~loc:__LOC__ diff --git a/src/proto_alpha/lib_protocol/test/integration/consensus/test_double_preendorsement.ml b/src/proto_alpha/lib_protocol/test/integration/consensus/test_double_preendorsement.ml index eeeff16940ceb4237981b20826d6ba5c65bf2b5e..f6a264121cd4386a04c37749dc376cf99aca1967 100644 --- a/src/proto_alpha/lib_protocol/test/integration/consensus/test_double_preendorsement.ml +++ b/src/proto_alpha/lib_protocol/test/integration/consensus/test_double_preendorsement.ml @@ -126,7 +126,8 @@ end = struct { parametric = { - ratio_of_frozen_deposits_slashed_per_double_endorsement = r; + percentage_of_frozen_deposits_slashed_per_double_endorsement = + p; _; }; _; @@ -141,10 +142,7 @@ end = struct (* the diff of the two balances in normal and in denunciation cases *) let diff_end_bal = Test_tez.(bal_good -! bal_bad) in (* amount lost due to denunciation *) - let lost_deposit = - Test_tez.( - frozen_deposit *! Int64.of_int r.numerator /! Int64.of_int r.denominator) - in + let lost_deposit = Test_tez.(frozen_deposit *! Int64.of_int p /! 100L) in (* have of the lost deposts will be earned by the baker *) let denun_reward = Test_tez.(lost_deposit /! 2L) in (* if the baker is the endorser, he'll only loose half of the deposits *) 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 7b6d69a7516e87bdd0c05ad6e2f9758cfaec4cf9..0d6678583369d8eff1a77bede87b82e2105a68b6 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 @@ -30,11 +30,11 @@ "consensus_threshold": 0, "minimal_participation_ratio": { "numerator": 2, "denominator": 3 }, "max_slashing_period": 2, "frozen_deposits_percentage": 5, - "double_baking_punishment": "640000000", - "ratio_of_frozen_deposits_slashed_per_double_endorsement": - { "numerator": 1, "denominator": 2 }, "cache_script_size": 100000000, - "cache_stake_distribution_cycles": 8, "cache_sampler_state_cycles": 8, - "tx_rollup_enable": false, "tx_rollup_origination_size": 4000, + "percentage_of_frozen_deposits_slashed_per_double_baking": 11, + "percentage_of_frozen_deposits_slashed_per_double_endorsement": 50, + "cache_script_size": 100000000, "cache_stake_distribution_cycles": 8, + "cache_sampler_state_cycles": 8, "tx_rollup_enable": false, + "tx_rollup_origination_size": 4000, "tx_rollup_hard_size_limit_per_inbox": 500000, "tx_rollup_hard_size_limit_per_message": 5000, "tx_rollup_max_withdrawals_per_batch": 15, 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 5b3401c117aac576432a3e79f4de062ba8de2122..d1bd2a48e3285fe70e17c260068b90342cdf2acb 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 @@ -30,11 +30,11 @@ "consensus_threshold": 0, "minimal_participation_ratio": { "numerator": 2, "denominator": 3 }, "max_slashing_period": 2, "frozen_deposits_percentage": 5, - "double_baking_punishment": "640000000", - "ratio_of_frozen_deposits_slashed_per_double_endorsement": - { "numerator": 1, "denominator": 2 }, "cache_script_size": 100000000, - "cache_stake_distribution_cycles": 8, "cache_sampler_state_cycles": 8, - "tx_rollup_enable": false, "tx_rollup_origination_size": 4000, + "percentage_of_frozen_deposits_slashed_per_double_baking": 11, + "percentage_of_frozen_deposits_slashed_per_double_endorsement": 50, + "cache_script_size": 100000000, "cache_stake_distribution_cycles": 8, + "cache_sampler_state_cycles": 8, "tx_rollup_enable": false, + "tx_rollup_origination_size": 4000, "tx_rollup_hard_size_limit_per_inbox": 500000, "tx_rollup_hard_size_limit_per_message": 5000, "tx_rollup_max_withdrawals_per_batch": 15, 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 501dbf5926795b8f9f3aa6be2ef1487ad7c66888..cd53813985757ce6aad8b43fd39e89042bc7ce7c 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 @@ -30,11 +30,11 @@ "consensus_threshold": 0, "minimal_participation_ratio": { "numerator": 2, "denominator": 3 }, "max_slashing_period": 2, "frozen_deposits_percentage": 5, - "double_baking_punishment": "640000000", - "ratio_of_frozen_deposits_slashed_per_double_endorsement": - { "numerator": 1, "denominator": 2 }, "cache_script_size": 100000000, - "cache_stake_distribution_cycles": 8, "cache_sampler_state_cycles": 8, - "tx_rollup_enable": false, "tx_rollup_origination_size": 4000, + "percentage_of_frozen_deposits_slashed_per_double_baking": 11, + "percentage_of_frozen_deposits_slashed_per_double_endorsement": 50, + "cache_script_size": 100000000, "cache_stake_distribution_cycles": 8, + "cache_sampler_state_cycles": 8, "tx_rollup_enable": false, + "tx_rollup_origination_size": 4000, "tx_rollup_hard_size_limit_per_inbox": 500000, "tx_rollup_hard_size_limit_per_message": 5000, "tx_rollup_max_withdrawals_per_batch": 15, diff --git a/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy_server_data_dir) RPC regression tests- misc_protocol.out b/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy_server_data_dir) RPC regression tests- misc_protocol.out index 895898a83eafdb4e8c49b876b8634a4d647284d5..eb775a863701e1fea67f328372b7a9a07dc24250 100644 --- a/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy_server_data_dir) RPC regression tests- misc_protocol.out +++ b/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy_server_data_dir) RPC regression tests- misc_protocol.out @@ -30,11 +30,11 @@ "consensus_threshold": 0, "minimal_participation_ratio": { "numerator": 2, "denominator": 3 }, "max_slashing_period": 2, "frozen_deposits_percentage": 5, - "double_baking_punishment": "640000000", - "ratio_of_frozen_deposits_slashed_per_double_endorsement": - { "numerator": 1, "denominator": 2 }, "cache_script_size": 100000000, - "cache_stake_distribution_cycles": 8, "cache_sampler_state_cycles": 8, - "tx_rollup_enable": false, "tx_rollup_origination_size": 4000, + "percentage_of_frozen_deposits_slashed_per_double_baking": 11, + "percentage_of_frozen_deposits_slashed_per_double_endorsement": 50, + "cache_script_size": 100000000, "cache_stake_distribution_cycles": 8, + "cache_sampler_state_cycles": 8, "tx_rollup_enable": false, + "tx_rollup_origination_size": 4000, "tx_rollup_hard_size_limit_per_inbox": 500000, "tx_rollup_hard_size_limit_per_message": 5000, "tx_rollup_max_withdrawals_per_batch": 15, diff --git a/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy_server_rpc) RPC regression tests- misc_protocol.out b/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy_server_rpc) RPC regression tests- misc_protocol.out index 895898a83eafdb4e8c49b876b8634a4d647284d5..eb775a863701e1fea67f328372b7a9a07dc24250 100644 --- a/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy_server_rpc) RPC regression tests- misc_protocol.out +++ b/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy_server_rpc) RPC regression tests- misc_protocol.out @@ -30,11 +30,11 @@ "consensus_threshold": 0, "minimal_participation_ratio": { "numerator": 2, "denominator": 3 }, "max_slashing_period": 2, "frozen_deposits_percentage": 5, - "double_baking_punishment": "640000000", - "ratio_of_frozen_deposits_slashed_per_double_endorsement": - { "numerator": 1, "denominator": 2 }, "cache_script_size": 100000000, - "cache_stake_distribution_cycles": 8, "cache_sampler_state_cycles": 8, - "tx_rollup_enable": false, "tx_rollup_origination_size": 4000, + "percentage_of_frozen_deposits_slashed_per_double_baking": 11, + "percentage_of_frozen_deposits_slashed_per_double_endorsement": 50, + "cache_script_size": 100000000, "cache_stake_distribution_cycles": 8, + "cache_sampler_state_cycles": 8, "tx_rollup_enable": false, + "tx_rollup_origination_size": 4000, "tx_rollup_hard_size_limit_per_inbox": 500000, "tx_rollup_hard_size_limit_per_message": 5000, "tx_rollup_max_withdrawals_per_batch": 15,