diff --git a/src/proto_alpha/lib_protocol/delegate_cycles.ml b/src/proto_alpha/lib_protocol/delegate_cycles.ml index ed32b9476f5587894f53e601692a2bda4d5a6087..72145484038ab5258d693b467541c92fe113ddd8 100644 --- a/src/proto_alpha/lib_protocol/delegate_cycles.ml +++ b/src/proto_alpha/lib_protocol/delegate_cycles.ml @@ -190,15 +190,12 @@ let cycle_end ctxt last_cycle = let* ctxt, attesting_balance_updates = distribute_attesting_rewards ctxt last_cycle unrevealed_nonces in - let* ctxt, slashings, slashing_balance_updates = + let* ctxt, slashing_balance_updates = Delegate_slashed_deposits_storage.apply_and_clear_denunciations ctxt in let new_cycle = Cycle_repr.add last_cycle 1 in let* ctxt = - Delegate_sampler.select_new_distribution_at_cycle_end - ctxt - ~slashings - ~new_cycle + Delegate_sampler.select_new_distribution_at_cycle_end ctxt ~new_cycle in let*! ctxt = Delegate_consensus_key.activate ctxt ~new_cycle in let*! ctxt = @@ -234,9 +231,6 @@ let init_first_cycles ctxt = let* ctxt = Stake_storage.snapshot ctxt in (* NB: we need to take several snapshots because select_distribution_for_cycle deletes the snapshots *) - Delegate_sampler.select_distribution_for_cycle - ctxt - ~slashings:Signature.Public_key_hash.Map.empty - cycle) + Delegate_sampler.select_distribution_for_cycle ctxt cycle) ctxt Misc.(0 --> preserved) diff --git a/src/proto_alpha/lib_protocol/delegate_sampler.ml b/src/proto_alpha/lib_protocol/delegate_sampler.ml index 9ea36b58ec1cb608b20cd62011c063ea4da371b8..5608b1e5ce88b7b2ccd59fd888843f5450e2ba6b 100644 --- a/src/proto_alpha/lib_protocol/delegate_sampler.ml +++ b/src/proto_alpha/lib_protocol/delegate_sampler.ml @@ -166,7 +166,7 @@ let get_delegate_stake_from_staking_balance ctxt delegate staking_balance = Lwt.return (Stake_context.apply_limits ctxt staking_parameters staking_balance) -let get_stakes_for_selected_index ctxt ~slashings:_ _index = +let get_stakes ctxt = let open Lwt_result_syntax in let minimal_frozen_stake = Constants_storage.minimal_frozen_stake ctxt in let minimal_stake = Constants_storage.minimal_stake ctxt in @@ -211,16 +211,10 @@ let compute_snapshot_index ctxt cycle ~max_snapshot_index = let* seed = Seed_storage.for_cycle ctxt cycle in compute_snapshot_index_for_seed ~max_snapshot_index seed -let select_distribution_for_cycle ctxt ~slashings cycle = +let select_distribution_for_cycle ctxt cycle = let open Lwt_result_syntax in - let* max_snapshot_index = Stake_storage.max_snapshot_index ctxt in let* seed = Seed_storage.raw_for_cycle ctxt cycle in - let* selected_index = - compute_snapshot_index_for_seed ~max_snapshot_index seed - in - let* stakes, total_stake = - get_stakes_for_selected_index ctxt ~slashings selected_index - in + let* stakes, total_stake = get_stakes ctxt in let* ctxt = Stake_storage.set_selected_distribution_for_cycle ctxt @@ -243,10 +237,10 @@ let select_distribution_for_cycle ctxt ~slashings cycle = (* pre-allocate the sampler *) Lwt.return (Raw_context.init_sampler_for_cycle ctxt cycle seed state) -let select_new_distribution_at_cycle_end ctxt ~slashings ~new_cycle = +let select_new_distribution_at_cycle_end ctxt ~new_cycle = let preserved = Constants_storage.preserved_cycles ctxt in let for_cycle = Cycle_repr.add new_cycle preserved in - select_distribution_for_cycle ctxt ~slashings for_cycle + select_distribution_for_cycle ctxt for_cycle let clear_outdated_sampling_data ctxt ~new_cycle = let open Lwt_result_syntax in diff --git a/src/proto_alpha/lib_protocol/delegate_sampler.mli b/src/proto_alpha/lib_protocol/delegate_sampler.mli index 18cac67c0f6abafff024f747360fa610555c3a95..d3477865821d008260c5a5f66c8711d9677e263e 100644 --- a/src/proto_alpha/lib_protocol/delegate_sampler.mli +++ b/src/proto_alpha/lib_protocol/delegate_sampler.mli @@ -26,9 +26,8 @@ (*****************************************************************************) (** This module draws random values for a cycle based on the {!Seed_repr.seed} - associated that cycle. These random values are: - - delegates associated with slots - - snapshot indexes. + associated that cycle. These random values are only delegates associated with + slots. The selection of delegates is done by {i sampling} from a particular distribution of the stake among the active delegates. @@ -70,19 +69,13 @@ val compute_snapshot_index : Raw_context.t -> Cycle_repr.t -> max_snapshot_index:int -> int tzresult Lwt.t val select_new_distribution_at_cycle_end : - Raw_context.t -> - slashings:Int_percentage.t Signature.Public_key_hash.Map.t -> - new_cycle:Cycle_repr.t -> - Raw_context.t tzresult Lwt.t + Raw_context.t -> new_cycle:Cycle_repr.t -> Raw_context.t tzresult Lwt.t val clear_outdated_sampling_data : Raw_context.t -> new_cycle:Cycle_repr.t -> Raw_context.t tzresult Lwt.t val select_distribution_for_cycle : - Raw_context.t -> - slashings:Int_percentage.t Signature.Public_key_hash.Map.t -> - Cycle_repr.t -> - Raw_context.t tzresult Lwt.t + Raw_context.t -> Cycle_repr.t -> Raw_context.t tzresult Lwt.t module For_RPC : sig (** The baking power for a given delegate computed from its current 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 db950bd8ac4beb56244a4f165ad9e8193cccac9e..85b2ea98f7326826381ce63b41215610a7526673 100644 --- a/src/proto_alpha/lib_protocol/delegate_slashed_deposits_storage.ml +++ b/src/proto_alpha/lib_protocol/delegate_slashed_deposits_storage.ml @@ -171,13 +171,13 @@ let apply_and_clear_denunciations ctxt = let+ amount_to_burn = Tez_repr.(punishing_amount -? reward) in {reward; amount_to_burn} in - let* ctxt, slashings, balance_updates, remaining_denunciations = + let* ctxt, balance_updates, remaining_denunciations = Storage.Pending_denunciations.fold ctxt ~order:`Undefined - ~init:(Ok (ctxt, Signature.Public_key_hash.Map.empty, [], [])) + ~init:(Ok (ctxt, [], [])) ~f:(fun delegate denunciations acc -> - let*? ctxt, slashings, balance_updates, remaining_denunciations = acc in + let*? ctxt, balance_updates, remaining_denunciations = acc in (* Since the [max_slashing_period] is 2, and we want to apply denunciations at the end of this period, we "delay" the current cycle's misbehaviour's denunciations, while we apply the older denunciations. @@ -202,9 +202,9 @@ let apply_and_clear_denunciations ctxt = Cycle_repr.(misb_cycle < current_cycle)) denunciations in - let+ ctxt, percentage, balance_updates = + let+ ctxt, balance_updates = List.fold_left_es - (fun (ctxt, percentage, balance_updates) + (fun (ctxt, balance_updates) Denunciations_repr.{operation_hash; rewarded; misbehaviour} -> let slashing_percentage = match misbehaviour.kind with @@ -322,21 +322,13 @@ let apply_and_clear_denunciations ctxt = to_reward (`Contract (Contract_repr.Implicit rewarded)) in - let percentage = - Int_percentage.add_bounded percentage slashing_percentage - in ( ctxt, - percentage, punish_balance_updates @ reward_balance_updates @ balance_updates )) - (ctxt, Int_percentage.p0, balance_updates) + (ctxt, balance_updates) denunciations_to_apply in - let slashings = - Signature.Public_key_hash.Map.add delegate percentage slashings - in ( ctxt, - slashings, balance_updates, (delegate, denunciations_to_delay) :: remaining_denunciations )) in @@ -354,4 +346,4 @@ let apply_and_clear_denunciations ctxt = ctxt remaining_denunciations in - return (ctxt, slashings, balance_updates) + return (ctxt, balance_updates) 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 617368f9aa46f3d4532605d2756802b72d259278..2252a9584021293272835222a028d5735c46f4e3 100644 --- a/src/proto_alpha/lib_protocol/delegate_slashed_deposits_storage.mli +++ b/src/proto_alpha/lib_protocol/delegate_slashed_deposits_storage.mli @@ -90,9 +90,4 @@ val clear_outdated_slashed_deposits : Raw_context.t -> new_cycle:Cycle_repr.t -> Raw_context.t Lwt.t val apply_and_clear_denunciations : - Raw_context.t -> - (Raw_context.t - * Int_percentage.t Signature.Public_key_hash.Map.t - * Receipt_repr.balance_updates) - tzresult - Lwt.t + Raw_context.t -> (Raw_context.t * Receipt_repr.balance_updates) tzresult Lwt.t