From d077a7c100d8766fd6fd2e413986a7e716f51654 Mon Sep 17 00:00:00 2001 From: Diane Gallois-Wong Date: Thu, 18 Jan 2024 10:29:31 +0100 Subject: [PATCH 1/3] Alpha: introduce Misbehaviour_repr hidden behind Alpha_context --- src/proto_alpha/lib_protocol/TEZOS_PROTOCOL | 2 +- src/proto_alpha/lib_protocol/alpha_context.ml | 1 + src/proto_alpha/lib_protocol/alpha_context.mli | 5 +++++ .../lib_protocol/delegate_slashed_deposits_storage.ml | 6 +++--- .../lib_protocol/delegate_slashed_deposits_storage.mli | 2 +- src/proto_alpha/lib_protocol/denunciations_repr.ml | 4 ++-- src/proto_alpha/lib_protocol/denunciations_repr.mli | 4 ++-- src/proto_alpha/lib_protocol/dune | 8 ++++---- .../{misbehaviour.ml => misbehaviour_repr.ml} | 0 .../{misbehaviour.mli => misbehaviour_repr.mli} | 0 .../test/integration/consensus/test_double_attestation.ml | 3 +-- .../test/integration/test_adaptive_issuance_roundtrip.ml | 2 +- 12 files changed, 21 insertions(+), 16 deletions(-) rename src/proto_alpha/lib_protocol/{misbehaviour.ml => misbehaviour_repr.ml} (100%) rename src/proto_alpha/lib_protocol/{misbehaviour.mli => misbehaviour_repr.mli} (100%) diff --git a/src/proto_alpha/lib_protocol/TEZOS_PROTOCOL b/src/proto_alpha/lib_protocol/TEZOS_PROTOCOL index 11216be38d1c..d185d74b414b 100644 --- a/src/proto_alpha/lib_protocol/TEZOS_PROTOCOL +++ b/src/proto_alpha/lib_protocol/TEZOS_PROTOCOL @@ -18,7 +18,6 @@ "Bitset", "Bounded_history_repr", "Context_binary_proof", - "Misbehaviour", "Ratio_repr", "Int_percentage", @@ -129,6 +128,7 @@ "Carbonated_map_costs", "Carbonated_map", "Staking_parameters_repr", + "Misbehaviour_repr", "Denunciations_repr", "Raw_context_intf", diff --git a/src/proto_alpha/lib_protocol/alpha_context.ml b/src/proto_alpha/lib_protocol/alpha_context.ml index a99e6f2dc553..a3fe1e08a3f5 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.ml +++ b/src/proto_alpha/lib_protocol/alpha_context.ml @@ -519,6 +519,7 @@ module Receipt = struct end module Consensus_key = Delegate_consensus_key +module Misbehaviour = Misbehaviour_repr module Delegate = struct include Delegate_storage diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index 982aef8efe7c..7cb933696307 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -2190,6 +2190,11 @@ module Consensus_key : sig val pkh : pk -> t end +(** This module re-exports definitions from {!Misbehaviour_repr}. *) +module Misbehaviour : sig + type t = Double_baking | Double_attesting +end + (** This module re-exports definitions from {!Delegate_storage}, {!Delegate_consensus_key}, {!Delegate_missed_attestations_storage}, {!Delegate_slashed_deposits_storage}, {!Delegate_cycles}, 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 28af64f69944..baf01b902eb4 100644 --- a/src/proto_alpha/lib_protocol/delegate_slashed_deposits_storage.ml +++ b/src/proto_alpha/lib_protocol/delegate_slashed_deposits_storage.ml @@ -57,9 +57,9 @@ type punishing_amounts = { The double signing event corresponds to a field in {!Storage.slashed_level}. *) -let punish_double_signing ctxt ~operation_hash (misbehaviour : Misbehaviour.t) - delegate (level : Level_repr.t) ~rewarded : - (Raw_context.t * bool) tzresult Lwt.t = +let punish_double_signing ctxt ~operation_hash + (misbehaviour : Misbehaviour_repr.t) delegate (level : Level_repr.t) + ~rewarded : (Raw_context.t * bool) tzresult Lwt.t = let open Lwt_result_syntax in let* slashed_opt = Storage.Slashed_deposits.find (ctxt, level.cycle) (level.level, delegate) diff --git a/src/proto_alpha/lib_protocol/delegate_slashed_deposits_storage.mli b/src/proto_alpha/lib_protocol/delegate_slashed_deposits_storage.mli index 16b4fc7658d9..a5903d0dda97 100644 --- a/src/proto_alpha/lib_protocol/delegate_slashed_deposits_storage.mli +++ b/src/proto_alpha/lib_protocol/delegate_slashed_deposits_storage.mli @@ -69,7 +69,7 @@ type punishing_amounts = { val punish_double_signing : Raw_context.t -> operation_hash:Operation_hash.t -> - Misbehaviour.t -> + Misbehaviour_repr.t -> Signature.Public_key_hash.t -> Level_repr.t -> rewarded:Signature.public_key_hash -> diff --git a/src/proto_alpha/lib_protocol/denunciations_repr.ml b/src/proto_alpha/lib_protocol/denunciations_repr.ml index ac6648dfaaae..c0a3b9d09bc6 100644 --- a/src/proto_alpha/lib_protocol/denunciations_repr.ml +++ b/src/proto_alpha/lib_protocol/denunciations_repr.ml @@ -20,7 +20,7 @@ let misbehaviour_cycle_encoding = type item = { operation_hash : Operation_hash.t; rewarded : Signature.public_key_hash; - misbehaviour : Misbehaviour.t; + misbehaviour : Misbehaviour_repr.t; misbehaviour_cycle : misbehaviour_cycle; } @@ -34,7 +34,7 @@ let item_encoding = (obj4 (req "operation_hash" Operation_hash.encoding) (req "rewarded" Signature.Public_key_hash.encoding) - (req "misbehaviour" Misbehaviour.encoding) + (req "misbehaviour" Misbehaviour_repr.encoding) (req "misbehaviour_cycle" misbehaviour_cycle_encoding)) type t = item list diff --git a/src/proto_alpha/lib_protocol/denunciations_repr.mli b/src/proto_alpha/lib_protocol/denunciations_repr.mli index b3ecb1c1a601..7f4b36895734 100644 --- a/src/proto_alpha/lib_protocol/denunciations_repr.mli +++ b/src/proto_alpha/lib_protocol/denunciations_repr.mli @@ -13,7 +13,7 @@ type misbehaviour_cycle = Current | Previous type item = { operation_hash : Operation_hash.t; rewarded : Signature.public_key_hash; - misbehaviour : Misbehaviour.t; + misbehaviour : Misbehaviour_repr.t; misbehaviour_cycle : misbehaviour_cycle; } @@ -26,7 +26,7 @@ val encoding : t Data_encoding.t val add : Operation_hash.t -> Signature.public_key_hash -> - Misbehaviour.t -> + Misbehaviour_repr.t -> misbehaviour_cycle -> t -> t diff --git a/src/proto_alpha/lib_protocol/dune b/src/proto_alpha/lib_protocol/dune index 5c1c4e88d14b..b670cb37c8d5 100644 --- a/src/proto_alpha/lib_protocol/dune +++ b/src/proto_alpha/lib_protocol/dune @@ -48,7 +48,6 @@ Bitset Bounded_history_repr Context_binary_proof - Misbehaviour Ratio_repr Int_percentage Michelson_v1_primitives @@ -151,6 +150,7 @@ Carbonated_map_costs Carbonated_map Staking_parameters_repr + Misbehaviour_repr Denunciations_repr Raw_context_intf Raw_context @@ -341,7 +341,6 @@ bitset.ml bitset.mli bounded_history_repr.ml bounded_history_repr.mli context_binary_proof.ml context_binary_proof.mli - misbehaviour.ml misbehaviour.mli ratio_repr.ml ratio_repr.mli int_percentage.ml int_percentage.mli michelson_v1_primitives.ml michelson_v1_primitives.mli @@ -447,6 +446,7 @@ carbonated_map_costs.ml carbonated_map_costs.mli carbonated_map.ml carbonated_map.mli staking_parameters_repr.ml staking_parameters_repr.mli + misbehaviour_repr.ml misbehaviour_repr.mli denunciations_repr.ml denunciations_repr.mli raw_context_intf.ml raw_context.ml raw_context.mli @@ -639,7 +639,6 @@ bitset.ml bitset.mli bounded_history_repr.ml bounded_history_repr.mli context_binary_proof.ml context_binary_proof.mli - misbehaviour.ml misbehaviour.mli ratio_repr.ml ratio_repr.mli int_percentage.ml int_percentage.mli michelson_v1_primitives.ml michelson_v1_primitives.mli @@ -745,6 +744,7 @@ carbonated_map_costs.ml carbonated_map_costs.mli carbonated_map.ml carbonated_map.mli staking_parameters_repr.ml staking_parameters_repr.mli + misbehaviour_repr.ml misbehaviour_repr.mli denunciations_repr.ml denunciations_repr.mli raw_context_intf.ml raw_context.ml raw_context.mli @@ -921,7 +921,6 @@ bitset.ml bitset.mli bounded_history_repr.ml bounded_history_repr.mli context_binary_proof.ml context_binary_proof.mli - misbehaviour.ml misbehaviour.mli ratio_repr.ml ratio_repr.mli int_percentage.ml int_percentage.mli michelson_v1_primitives.ml michelson_v1_primitives.mli @@ -1027,6 +1026,7 @@ carbonated_map_costs.ml carbonated_map_costs.mli carbonated_map.ml carbonated_map.mli staking_parameters_repr.ml staking_parameters_repr.mli + misbehaviour_repr.ml misbehaviour_repr.mli denunciations_repr.ml denunciations_repr.mli raw_context_intf.ml raw_context.ml raw_context.mli diff --git a/src/proto_alpha/lib_protocol/misbehaviour.ml b/src/proto_alpha/lib_protocol/misbehaviour_repr.ml similarity index 100% rename from src/proto_alpha/lib_protocol/misbehaviour.ml rename to src/proto_alpha/lib_protocol/misbehaviour_repr.ml diff --git a/src/proto_alpha/lib_protocol/misbehaviour.mli b/src/proto_alpha/lib_protocol/misbehaviour_repr.mli similarity index 100% rename from src/proto_alpha/lib_protocol/misbehaviour.mli rename to src/proto_alpha/lib_protocol/misbehaviour_repr.mli 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 110f98d24122..61dec06df36d 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 @@ -58,8 +58,7 @@ let check_denunciations ~(cycle : Denunciations_repr.misbehaviour_cycle) b let* denunciations = Context.get_denunciations (B b) in match denunciations with | [(d, item)] when Signature.Public_key_hash.equal d delegate -> - assert ( - item.Denunciations_repr.misbehaviour = Misbehaviour.Double_attesting) ; + assert (item.Denunciations_repr.misbehaviour = Double_attesting) ; assert (item.Denunciations_repr.misbehaviour_cycle = cycle) ; return_unit | _ -> assert false diff --git a/src/proto_alpha/lib_protocol/test/integration/test_adaptive_issuance_roundtrip.ml b/src/proto_alpha/lib_protocol/test/integration/test_adaptive_issuance_roundtrip.ml index d3a487e4319a..6184c98d31f4 100644 --- a/src/proto_alpha/lib_protocol/test/integration/test_adaptive_issuance_roundtrip.ml +++ b/src/proto_alpha/lib_protocol/test/integration/test_adaptive_issuance_roundtrip.ml @@ -1515,7 +1515,7 @@ let cycle_from_level blocks_per_cycle level = current_cycle let pct_from_kind (block : Block.t) = function - | Protocol.Misbehaviour.Double_baking -> + | Protocol.Misbehaviour_repr.Double_baking -> (block.constants.percentage_of_frozen_deposits_slashed_per_double_baking :> int) | Double_attesting -> -- GitLab From e5780250fb5defa54377cda692f260d5603233a4 Mon Sep 17 00:00:00 2001 From: Diane Gallois-Wong Date: Thu, 18 Jan 2024 17:55:29 +0100 Subject: [PATCH 2/3] Alpha: add and update a few comments on denunciation handling --- .../delegate_slashed_deposits_storage.ml | 7 ------ .../delegate_slashed_deposits_storage.mli | 25 +++++++++++++------ .../lib_protocol/denunciations_repr.mli | 9 +++++++ 3 files changed, 27 insertions(+), 14 deletions(-) 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 baf01b902eb4..bc8676c3f781 100644 --- a/src/proto_alpha/lib_protocol/delegate_slashed_deposits_storage.ml +++ b/src/proto_alpha/lib_protocol/delegate_slashed_deposits_storage.ml @@ -50,13 +50,6 @@ type punishing_amounts = { unstaked : (Cycle_repr.t * reward_and_burn) list; } -(** [punish_double_signing ctxt misbehaviour delegate level] record - in the context that the given [delegate] has now been slashed for the - double signing event [misbehaviour] for the given [level] and return the amounts of the - frozen deposits to burn and to reward the denuncer. - - The double signing event corresponds to a field in {!Storage.slashed_level}. -*) let punish_double_signing ctxt ~operation_hash (misbehaviour : Misbehaviour_repr.t) delegate (level : Level_repr.t) ~rewarded : (Raw_context.t * bool) tzresult Lwt.t = diff --git a/src/proto_alpha/lib_protocol/delegate_slashed_deposits_storage.mli b/src/proto_alpha/lib_protocol/delegate_slashed_deposits_storage.mli index a5903d0dda97..75fd1689edba 100644 --- a/src/proto_alpha/lib_protocol/delegate_slashed_deposits_storage.mli +++ b/src/proto_alpha/lib_protocol/delegate_slashed_deposits_storage.mli @@ -58,14 +58,25 @@ type punishing_amounts = { unstaked : (Cycle_repr.t * reward_and_burn) list; } -(** Record in the context that the given delegate has now been slashed - for double signing for the given misbehaviour for the given level and return the amounts to - burn and to reward. If the delegate has no remaining frozen - deposits, this will also forbid it to bake or attest until a new - deposit is frozen. +(** Record in the context that the given delegate is now marked for + slashing for the given misbehaviour. If the past and pending + slashings for the delegate since the previous cycle exceed a fixed + threshold, then this function also records in the context that the + delegate is now forbidden from taking part in the consensus + process. - Fails with [Unrequired_denunciation] if the given delegate has - already been slashed for the same misbehaviour for the given level. *) + Return the updated context and a boolean indicating whether the + delegate is actually forbidden from baking/attesting. + + [operation_hash] corresponds to the denunciation that prompted + this punishment. The level argument is the level of the duplicate + blocks, or the level that the duplicate (pre)attestations point + to, **not** the level of the block that contains the denunciation. + + This function asserts that the delegate has not already been + denounced for the same misbehaviour at the same level. Indeed, if + this were the case, then the current denunciation operation should + have been rejected by {!Validate}. *) val punish_double_signing : Raw_context.t -> operation_hash:Operation_hash.t -> diff --git a/src/proto_alpha/lib_protocol/denunciations_repr.mli b/src/proto_alpha/lib_protocol/denunciations_repr.mli index 7f4b36895734..75ca75a11a81 100644 --- a/src/proto_alpha/lib_protocol/denunciations_repr.mli +++ b/src/proto_alpha/lib_protocol/denunciations_repr.mli @@ -10,6 +10,13 @@ denunciation or the preceding one. *) type misbehaviour_cycle = Current | Previous +(** Internal representation of a pending denunciation, meaning that a + denunciation operation has been observed in an applied block, but + the corresponding slashing has not happened yet. + + Note: the public key hash of the culprit doesn't appear in this + type because it is used as key to store the list of a culprit's + items (see type [t] below) in the context. *) type item = { operation_hash : Operation_hash.t; rewarded : Signature.public_key_hash; @@ -17,12 +24,14 @@ type item = { misbehaviour_cycle : misbehaviour_cycle; } +(** List of all pending denunciations about the same culprit. *) type t = item list val item_encoding : item Data_encoding.t val encoding : t Data_encoding.t +(** Append a new pending denunciation to the end of the given list. *) val add : Operation_hash.t -> Signature.public_key_hash -> -- GitLab From 601f39ce86aa8c2b9d8b3622af2d6d53f9ad653d Mon Sep 17 00:00:00 2001 From: Diane Gallois-Wong Date: Thu, 18 Jan 2024 14:15:50 +0100 Subject: [PATCH 3/3] Alpha: add level, round, and slot to misbehaviour_repr --- .../lib_protocol/alpha_context.mli | 4 ++- src/proto_alpha/lib_protocol/apply.ml | 20 +++++++++++-- .../delegate_slashed_deposits_storage.ml | 4 +-- .../lib_protocol/misbehaviour_repr.ml | 22 +++++++++++++-- .../lib_protocol/misbehaviour_repr.mli | 28 ++++++++++++++++++- .../test/helpers/adaptive_issuance_helpers.ml | 2 +- .../consensus/test_double_attestation.ml | 2 +- .../test_adaptive_issuance_roundtrip.ml | 21 ++++++++++---- .../lib_protocol/unstake_requests_storage.ml | 2 +- 9 files changed, 88 insertions(+), 17 deletions(-) diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index 7cb933696307..d3dc9f7ef7fb 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -2192,7 +2192,9 @@ end (** This module re-exports definitions from {!Misbehaviour_repr}. *) module Misbehaviour : sig - type t = Double_baking | Double_attesting + type kind = Double_baking | Double_attesting + + type t = {kind : kind; level : Raw_level.t; round : Round.t; slot : Slot.t} end (** This module re-exports definitions from {!Delegate_storage}, diff --git a/src/proto_alpha/lib_protocol/apply.ml b/src/proto_alpha/lib_protocol/apply.ml index b24c9eee5639..5c3902103c2e 100644 --- a/src/proto_alpha/lib_protocol/apply.ml +++ b/src/proto_alpha/lib_protocol/apply.ml @@ -2392,12 +2392,20 @@ let punish_double_attestation_or_preattestation (type kind) ctxt ~operation_hash let* ctxt, consensus_pk1 = Stake_distribution.slot_owner ctxt level e1.slot in + let misbehaviour = + { + Misbehaviour.kind = Double_attesting; + level = e1.level; + round = e1.round; + slot = e1.slot; + } + in punish_delegate ctxt ~operation_hash consensus_pk1.delegate level - Double_attesting + misbehaviour mk_result ~payload_producer @@ -2411,12 +2419,20 @@ let punish_double_baking ctxt ~operation_hash (bh1 : Block_header.t) let committee_size = Constants.consensus_committee_size ctxt in let*? slot1 = Round.to_slot round1 ~committee_size in let* ctxt, consensus_pk1 = Stake_distribution.slot_owner ctxt level slot1 in + let misbehaviour = + { + Misbehaviour.kind = Double_baking; + level = raw_level; + round = round1; + slot = slot1; + } + in punish_delegate ctxt ~operation_hash consensus_pk1.delegate level - Double_baking + misbehaviour ~payload_producer (fun forbidden_delegate balance_updates -> Double_baking_evidence_result {forbidden_delegate; balance_updates}) 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 bc8676c3f781..6c042a7c1aef 100644 --- a/src/proto_alpha/lib_protocol/delegate_slashed_deposits_storage.ml +++ b/src/proto_alpha/lib_protocol/delegate_slashed_deposits_storage.ml @@ -62,7 +62,7 @@ let punish_double_signing ctxt ~operation_hash in let already_slashed, updated_slashed, slashing_percentage = let Storage.{for_double_baking; for_double_attesting} = slashed in - match misbehaviour with + match misbehaviour.kind with | Double_baking -> ( for_double_baking, {slashed with for_double_baking = true}, @@ -195,7 +195,7 @@ let apply_and_clear_current_cycle_denunciations ctxt = Denunciations_repr. {operation_hash; rewarded; misbehaviour; misbehaviour_cycle} -> let slashing_percentage = - match misbehaviour with + match misbehaviour.kind with | Double_baking -> Constants_storage .percentage_of_frozen_deposits_slashed_per_double_baking diff --git a/src/proto_alpha/lib_protocol/misbehaviour_repr.ml b/src/proto_alpha/lib_protocol/misbehaviour_repr.ml index e138007b6f6a..dcae67d85697 100644 --- a/src/proto_alpha/lib_protocol/misbehaviour_repr.ml +++ b/src/proto_alpha/lib_protocol/misbehaviour_repr.ml @@ -5,9 +5,9 @@ (* *) (*****************************************************************************) -type t = Double_baking | Double_attesting +type kind = Double_baking | Double_attesting -let encoding = +let kind_encoding = let open Data_encoding in union ~tag_size:`Uint8 @@ -25,3 +25,21 @@ let encoding = (function Double_attesting -> Some () | _ -> None) (fun () -> Double_attesting); ] + +type t = { + kind : kind; + level : Raw_level_repr.t; + round : Round_repr.t; + slot : Slot_repr.t; +} + +let encoding = + let open Data_encoding in + conv + (fun {kind; level; round; slot} -> (kind, level, round, slot)) + (fun (kind, level, round, slot) -> {kind; level; round; slot}) + (obj4 + (req "kind" kind_encoding) + (req "level" Raw_level_repr.encoding) + (req "round" Round_repr.encoding) + (req "slot" Slot_repr.encoding)) diff --git a/src/proto_alpha/lib_protocol/misbehaviour_repr.mli b/src/proto_alpha/lib_protocol/misbehaviour_repr.mli index 0436bddba5dc..93e89fe300d5 100644 --- a/src/proto_alpha/lib_protocol/misbehaviour_repr.mli +++ b/src/proto_alpha/lib_protocol/misbehaviour_repr.mli @@ -5,6 +5,32 @@ (* *) (*****************************************************************************) -type t = Double_baking | Double_attesting +(** Which double signing event has occurred. *) +type kind = + | Double_baking + | Double_attesting + (** Includes both double preattestion and double attestion. *) + +(** Internal representation of a double signing event used in + {!Denunciations_repr.item}. + + For a double baking event, [level] and [round] are those of the + duplicate blocks, and [slot] is [Round_repr.to_slot round]. + + For a double (pre)attestation event, [level], [round], and [slot] + are those indicated in the {!Operation_repr.consensus_content} of + the consensus operation that appears first in the denunciation + operation. Note that both duplicate operations always have the + same [level] and [round] anyway, but might have different [slot]s. + + Note: the culprit pkh doesn't appear as a field here because it is + typically used as a key when storing denunciation items in the + context. *) +type t = { + kind : kind; + level : Raw_level_repr.t; + round : Round_repr.t; + slot : Slot_repr.t; +} val encoding : t Data_encoding.t diff --git a/src/proto_alpha/lib_protocol/test/helpers/adaptive_issuance_helpers.ml b/src/proto_alpha/lib_protocol/test/helpers/adaptive_issuance_helpers.ml index c4c97f770f24..96db7e3a82cf 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/adaptive_issuance_helpers.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/adaptive_issuance_helpers.ml @@ -1040,7 +1040,7 @@ let apply_slashing |> Option.value_f ~default:(fun _ -> assert false) in let slashed_pct = - match misbehaviour with + match misbehaviour.kind with | Double_baking -> constants .Protocol.Alpha_context.Constants.Parametric 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 61dec06df36d..c21cc1c48454 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 @@ -58,7 +58,7 @@ let check_denunciations ~(cycle : Denunciations_repr.misbehaviour_cycle) b let* denunciations = Context.get_denunciations (B b) in match denunciations with | [(d, item)] when Signature.Public_key_hash.equal d delegate -> - assert (item.Denunciations_repr.misbehaviour = Double_attesting) ; + assert (item.Denunciations_repr.misbehaviour.kind = Double_attesting) ; assert (item.Denunciations_repr.misbehaviour_cycle = cycle) ; return_unit | _ -> assert false diff --git a/src/proto_alpha/lib_protocol/test/integration/test_adaptive_issuance_roundtrip.ml b/src/proto_alpha/lib_protocol/test/integration/test_adaptive_issuance_roundtrip.ml index 6184c98d31f4..0915afe1c77e 100644 --- a/src/proto_alpha/lib_protocol/test/integration/test_adaptive_issuance_roundtrip.ml +++ b/src/proto_alpha/lib_protocol/test/integration/test_adaptive_issuance_roundtrip.ml @@ -1331,7 +1331,7 @@ let check_pending_slashings (block, state) : unit tzresult Lwt.t = (pkh_2, {rewarded = r2; misbehaviour = m2; misbehaviour_cycle = mc2; _}) = Signature.Public_key_hash.equal pkh_1 pkh_2 && Signature.Public_key_hash.equal r1 r2 - && Stdlib.(m1 = m2) + && Stdlib.(m1.kind = m2.kind) && Stdlib.(mc1 = mc2) in let compare_denunciations @@ -1344,7 +1344,7 @@ let check_pending_slashings (block, state) : unit tzresult Lwt.t = if c2 <> 0 then c2 else let c3 = - match (m1, m2) with + match (m1.kind, m2.kind) with | Double_baking, Double_attesting -> -1 | x, y when x = y -> 0 | _ -> 1 @@ -1370,7 +1370,7 @@ let check_pending_slashings (block, state) : unit tzresult Lwt.t = pkh Signature.Public_key_hash.pp rewarded - (match misbehaviour with + (match misbehaviour.kind with | Double_baking -> "double baking" | Double_attesting -> "double attesting") (match misbehaviour_cycle with @@ -1528,7 +1528,7 @@ let get_pending_slashed_pct_for_delegate (block, state) delegate = | [] -> 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 in + 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 @@ -1569,12 +1569,21 @@ let update_state_denunciation (block, state) else if Cycle.(succ ds_cycle = inclusion_cycle) then Previous else assert false in - let misbehaviour = + let kind = match kind with - | Double_baking -> Protocol.Misbehaviour.Double_baking + | Double_baking -> Protocol.Misbehaviour_repr.Double_baking | Double_attesting -> Double_attesting | Double_preattesting -> Double_attesting in + let misbehaviour = + { + Protocol.Misbehaviour_repr.kind; + (* Fields level, round, and slot are unused for now. *) + level = Protocol.Raw_level_repr.of_int32_exn level; + round = Protocol.Round_repr.zero; + slot = Protocol.Slot_repr.zero; + } + in (* for simplicity's sake (lol), the block producer and the payload producer are the same We also assume that the current state baking policy will be used for the next block *) let* rewarded, _, _, _ = diff --git a/src/proto_alpha/lib_protocol/unstake_requests_storage.ml b/src/proto_alpha/lib_protocol/unstake_requests_storage.ml index 044c2d643fde..80ba7b60eb80 100644 --- a/src/proto_alpha/lib_protocol/unstake_requests_storage.ml +++ b/src/proto_alpha/lib_protocol/unstake_requests_storage.ml @@ -190,7 +190,7 @@ module For_RPC = struct else List.fold_left (fun acc Denunciations_repr.{misbehaviour; misbehaviour_cycle; _} -> - match (misbehaviour_cycle, misbehaviour) with + match (misbehaviour_cycle, misbehaviour.kind) with | Current, _ -> acc | Previous, Double_baking -> Int_percentage.add_bounded -- GitLab