diff --git a/src/proto_alpha/lib_plugin/delegate_services.ml b/src/proto_alpha/lib_plugin/delegate_services.ml index d9da5b3dfdb6d01099b0ba05cfbced24a8bfede9..3e2c9b40ee06be8a717a4a8f9ccffc441c508439 100644 --- a/src/proto_alpha/lib_plugin/delegate_services.ml +++ b/src/proto_alpha/lib_plugin/delegate_services.ml @@ -150,27 +150,27 @@ let dal_participation_info_encoding = { expected_assigned_shards_per_slot; delegate_attested_dal_slots; - total_dal_attested_slots; + delegate_attestable_dal_slots; expected_dal_rewards; sufficient_dal_participation; denounced; } -> ( expected_assigned_shards_per_slot, delegate_attested_dal_slots, - total_dal_attested_slots, + delegate_attestable_dal_slots, expected_dal_rewards, sufficient_dal_participation, denounced )) (fun ( expected_assigned_shards_per_slot, delegate_attested_dal_slots, - total_dal_attested_slots, + delegate_attestable_dal_slots, expected_dal_rewards, sufficient_dal_participation, denounced ) -> { expected_assigned_shards_per_slot; delegate_attested_dal_slots; - total_dal_attested_slots; + delegate_attestable_dal_slots; expected_dal_rewards; sufficient_dal_participation; denounced; @@ -178,7 +178,7 @@ let dal_participation_info_encoding = (obj6 (req "expected_assigned_shards_per_slot" int31) (req "delegate_attested_dal_slots" int31) - (req "total_dal_attested_slots" int31) + (req "delegate_attestable_dal_slots" int31) (req "expected_dal_rewards" Tez.encoding) (req "sufficient_dal_participation" bool) (req "denounced" bool)) @@ -895,18 +895,18 @@ module S = struct shards assigned to the delegate in the cycle per DAL slot. The field \ 'delegate_attested_dal_slots' represents the number of attested DAL \ slots which are also attested by the delegate, while \ - 'total_dal_attested_slots' provides the total number of DAL slots \ - attested during the cycle, regardless of the delegate's \ - participation. The 'expected_dal_rewards' field specifies the \ - expected amount of rewards for the delegate based on DAL \ - participation, provided the delegate meets the required participation \ - Whether this threshold is currently met is determined by the \ + 'delegate_attestable_dal_slots' provides the total number of DAL \ + slots attested during the cycle for which the delegate had shards \ + assigned. The 'expected_dal_rewards' field specifies the expected \ + amount of rewards for the delegate based on DAL participation, \ + provided the delegate meets the required participation. Whether this \ + threshold is currently met is determined by the \ 'sufficient_dal_participation' flag, which is true if currently the \ delegate has sufficiently participated in attesting DAL slots \ declared to be attested by the protocol. Note that this flag may \ evolve during the cycle. Also note, in particular, that if no DAL no \ DAL slots have been globally attested during the cycle (i.e., when \ - 'total_dal_attested_slots' is zero), the flag is true. The \ + 'delegate_attestable_dal_slots' is zero), the flag is true. The \ 'denounced' field specifies whether the delegate was denounced for \ not detecting traps during the current cycle." ~query:RPC_query.empty diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index ef222fda1c3a5c7ea239b142ab5463a459df871f..b2af438052e49e761c5c15529a725c8eea3da0f6 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -2343,7 +2343,8 @@ module Delegate : sig val record_dal_participation : context -> delegate:Signature.Public_key_hash.t -> - number_of_attested_slots:int -> + number_of_slots_attested_by_delegate:int -> + number_of_protocol_attested_slots:int -> context tzresult Lwt.t val current_frozen_deposits : @@ -2535,7 +2536,7 @@ module Delegate : sig type dal_participation_info = { expected_assigned_shards_per_slot : int; delegate_attested_dal_slots : int; - total_dal_attested_slots : int; + delegate_attestable_dal_slots : int; expected_dal_rewards : Tez.t; sufficient_dal_participation : bool; denounced : bool; diff --git a/src/proto_alpha/lib_protocol/apply.ml b/src/proto_alpha/lib_protocol/apply.ml index c105c62c6679c5af3441eba2d15f440b3194d624..dea20068c272737b8d37f8dd5e39982b9916e4cc 100644 --- a/src/proto_alpha/lib_protocol/apply.ml +++ b/src/proto_alpha/lib_protocol/apply.ml @@ -2839,7 +2839,7 @@ let record_attesting_participation ctxt dal_attestation = | Some validators -> Slot.Map.fold_es (fun initial_slot - ((consensus_pk : Consensus_key.pk), power, _dal_power) + ((consensus_pk : Consensus_key.pk), power, dal_power) ctxt -> let participation = if Slot.Set.mem initial_slot (Consensus.attestations_seen ctxt) then @@ -2853,10 +2853,11 @@ let record_attesting_participation ctxt dal_attestation = ~participation ~attesting_power:power in - Dal_apply.record_dal_participation + Dal_apply.record_participation ctxt consensus_pk.delegate initial_slot + ~dal_power dal_attestation) validators ctxt diff --git a/src/proto_alpha/lib_protocol/dal_apply.ml b/src/proto_alpha/lib_protocol/dal_apply.ml index 6fc372cbbba5b68b0f8ab77ffec49fe2209efd01..4de63c5aeca30110bce27915d8e88a75e748cf5b 100644 --- a/src/proto_alpha/lib_protocol/dal_apply.ml +++ b/src/proto_alpha/lib_protocol/dal_apply.ml @@ -99,22 +99,36 @@ let apply_publish_commitment ctxt operation ~source = let* ctxt = Dal.Slot.register_slot_header ctxt slot_header ~source in return (ctxt, slot_header) -let record_dal_participation ctxt delegate tb_slot dal_attestation = +let record_participation ctxt delegate tb_slot ~dal_power dal_attestation = let open Lwt_result_syntax in let*? () = Dal.assert_feature_enabled ctxt in Dal.only_if_incentives_enabled ctxt ~default:(fun ctxt -> return ctxt) (fun ctxt -> - let number_of_attested_slots = - match Slot.Map.find_opt tb_slot (Dal.Attestation.attestations ctxt) with - | None -> 0 - | Some delegate_attestation -> - Dal.Attestation.( - intersection dal_attestation delegate_attestation - |> number_of_attested_slots) - in - Delegate.record_dal_participation ctxt ~delegate ~number_of_attested_slots) + if Compare.Int.(dal_power = 0) then + (* the delegate is not in the DAL committee, there is no need to update + the participation *) + return ctxt + else + let number_of_slots_attested_by_delegate = + match + Slot.Map.find_opt tb_slot (Dal.Attestation.attestations ctxt) + with + | None -> 0 + | Some delegate_attestation -> + Dal.Attestation.( + intersection dal_attestation delegate_attestation + |> number_of_attested_slots) + in + let number_of_protocol_attested_slots = + Dal.Attestation.number_of_attested_slots dal_attestation + in + Delegate.record_dal_participation + ctxt + ~delegate + ~number_of_slots_attested_by_delegate + ~number_of_protocol_attested_slots) let finalisation ctxt = let open Lwt_result_syntax in diff --git a/src/proto_alpha/lib_protocol/dal_apply.mli b/src/proto_alpha/lib_protocol/dal_apply.mli index df823e2be0c2357026ace186c46fa8fba60bd8ae..950e75f872bfa5d73e3ca5c0afe59204c8647219 100644 --- a/src/proto_alpha/lib_protocol/dal_apply.mli +++ b/src/proto_alpha/lib_protocol/dal_apply.mli @@ -68,13 +68,15 @@ val apply_publish_commitment : source:Contract.t -> (t * Dal.Slot.Header.t) tzresult -(** [record_dal_participation ctxt delegate tb_slot dal_attestation] records the - number of protocol-attested slots (given in [dal_attestation] attested by - [delegate] (with the initial TB slot [tb_slot]) in the current block. *) -val record_dal_participation : +(** [record_dal_participation ctxt delegate tb_slot ~dal_power dal_attestation] + records the number of protocol-attested slots (given in [dal_attestation] + attested by [delegate] (with the initial TB slot [tb_slot] and [dal_power] + assigned shards per slot) in the current block. *) +val record_participation : t -> Signature.Public_key_hash.t -> Slot.t -> + dal_power:int -> Dal.Attestation.t -> t tzresult Lwt.t diff --git a/src/proto_alpha/lib_protocol/dal_slot_storage.ml b/src/proto_alpha/lib_protocol/dal_slot_storage.ml index 98082dd1954ad2308e1780ebb37c56714f1bf06a..b605f03eb781c6760dc56a7aa202e1212ba2b65f 100644 --- a/src/proto_alpha/lib_protocol/dal_slot_storage.ml +++ b/src/proto_alpha/lib_protocol/dal_slot_storage.ml @@ -95,22 +95,6 @@ let update_skip_list ctxt ~slot_headers_statuses ~published_level in return ctxt -let update_number_of_attested_slots ctxt num_attested_slots = - let open Lwt_result_syntax in - Raw_context.Dal.only_if_incentives_enabled ctxt ~default:return (fun ctxt -> - if Compare.Int.(num_attested_slots = 0) then return ctxt - else - let* res = Storage.Dal.Total_attested_slots.find ctxt in - match res with - | None -> - Storage.Dal.Total_attested_slots.init - ctxt - (Int32.of_int num_attested_slots) - | Some v -> - Storage.Dal.Total_attested_slots.update - ctxt - Int32.(add v (of_int num_attested_slots))) - (* TODO https://gitlab.com/tezos/tezos/-/issues/7647 Consider if it is better to store commitments only for attestation lag levels, by: @@ -151,12 +135,6 @@ let finalize_pending_slot_headers ctxt ~number_of_slots = in compute_slot_headers_statuses ~is_slot_attested published_slots in - let num_attested_slots = - Dal_attestation_repr.number_of_attested_slots attestation - in - let* ctxt = - update_number_of_attested_slots ctxt num_attested_slots - in return (ctxt, attestation, slot_headers_statuses) in let* ctxt = diff --git a/src/proto_alpha/lib_protocol/delegate_cycles.ml b/src/proto_alpha/lib_protocol/delegate_cycles.ml index 278f9a0a2987839dd8e116021b1072d491ffd045..db2bd663de99ed45012378a3b6178bbd1e92b669 100644 --- a/src/proto_alpha/lib_protocol/delegate_cycles.ml +++ b/src/proto_alpha/lib_protocol/delegate_cycles.ml @@ -53,13 +53,13 @@ let delegate_has_revealed_nonces delegate unrevelead_nonces_set = not (Signature.Public_key_hash.Set.mem delegate unrevelead_nonces_set) let distribute_dal_attesting_rewards ctxt delegate - ~dal_attesting_reward_per_shard ~total_dal_attested_slots - ~total_active_stake_weight ~active_stake_weight active_stake = + ~dal_attesting_reward_per_shard ~total_active_stake_weight + ~active_stake_weight active_stake = let open Lwt_result_syntax in let*! denounced_in_cycle = Dal_already_denounced_storage.is_denounced ctxt delegate in - let* ctxt, dal_attested_slots_by_delegate = + let* ctxt, dal_participation = Delegate_missed_attestations_storage .get_and_reset_delegate_dal_participation ctxt @@ -68,8 +68,7 @@ let distribute_dal_attesting_rewards ctxt delegate let sufficient_dal_participation = Delegate_missed_attestations_storage.is_dal_participation_sufficient ctxt - ~dal_attested_slots_by_delegate - ~total_dal_attested_slots + dal_participation in let expected_dal_shards = Delegate_missed_attestations_storage @@ -102,23 +101,22 @@ let distribute_dal_attesting_rewards ctxt delegate dal_rewards let maybe_distribute_dal_attesting_rewards ctxt delegate - ~dal_attesting_reward_per_shard ~total_dal_attested_slots - ~total_active_stake_weight ~active_stake_weight active_stake = + ~dal_attesting_reward_per_shard ~total_active_stake_weight + ~active_stake_weight active_stake = let open Lwt_result_syntax in Raw_context.Dal.only_if_incentives_enabled ctxt ~default:(fun ctxt -> return (ctxt, [])) (fun ctxt -> - let dal_attesting_reward_per_shard, total_dal_attested_slots = - match (dal_attesting_reward_per_shard, total_dal_attested_slots) with - | Some v1, Some v2 -> (v1, v2) - | _ -> (* unreachable *) (Tez_repr.zero, 0l) + let dal_attesting_reward_per_shard = + match dal_attesting_reward_per_shard with + | Some v -> v + | _ -> (* unreachable *) Tez_repr.zero in distribute_dal_attesting_rewards ctxt delegate ~dal_attesting_reward_per_shard - ~total_dal_attested_slots ~total_active_stake_weight ~active_stake_weight active_stake) @@ -142,17 +140,15 @@ let distribute_attesting_rewards ctxt last_cycle unrevealed_nonces = let total_active_stake_weight = Stake_repr.staking_weight total_active_stake in - let* dal_attesting_reward_per_shard, total_dal_attested_slots = + let* dal_attesting_reward_per_shard = Raw_context.Dal.only_if_incentives_enabled ctxt - ~default:(fun _ctxt -> return (None, None)) + ~default:(fun _ctxt -> return None) (fun ctxt -> let*? dal_attesting_reward_per_shard = Delegate_rewards.dal_attesting_reward_per_shard ctxt in - let+ total_opt = Storage.Dal.Total_attested_slots.find ctxt in - let total = match total_opt with None -> Some 0l | v -> v in - (Some dal_attesting_reward_per_shard, total)) + return @@ Some dal_attesting_reward_per_shard) in let* delegates = Stake_storage.get_selected_distribution ctxt last_cycle in List.fold_left_es @@ -198,7 +194,6 @@ let distribute_attesting_rewards ctxt last_cycle unrevealed_nonces = ctxt delegate ~dal_attesting_reward_per_shard - ~total_dal_attested_slots ~total_active_stake_weight ~active_stake_weight active_stake @@ -217,9 +212,6 @@ let cycle_end ctxt last_cycle = let* ctxt, attesting_balance_updates = distribute_attesting_rewards ctxt last_cycle unrevealed_nonces in - let*! ctxt = - Delegate_missed_attestations_storage.remove_total_dal_attested_slots ctxt - in (* Applying slashing related to expiring denunciations *) let* ctxt, slashing_balance_updates = Delegate_slashed_deposits_storage.apply_and_clear_denunciations ctxt diff --git a/src/proto_alpha/lib_protocol/delegate_missed_attestations_storage.ml b/src/proto_alpha/lib_protocol/delegate_missed_attestations_storage.ml index e09671b8fda2ce71fda1e6cbde932a5e7079e4c6..0f340da4a607987151c8522846e61b74ab2c8f9c 100644 --- a/src/proto_alpha/lib_protocol/delegate_missed_attestations_storage.ml +++ b/src/proto_alpha/lib_protocol/delegate_missed_attestations_storage.ml @@ -57,9 +57,6 @@ let expected_dal_shards_per_slot_for_given_active_stake ctxt (Z.of_int number_of_shards_per_cycle)) (Z.of_int64 total_active_stake_weight)) -let remove_total_dal_attested_slots ctxt = - Storage.Dal.Total_attested_slots.remove ctxt - type level_participation = Participated | Didn't_participate (* Note that the participation for the last block of a cycle is @@ -122,33 +119,49 @@ let record_attesting_participation ctxt ~delegate ~participation contract {remaining_slots; missed_levels = 1})) -let record_dal_participation ctxt ~delegate ~number_of_attested_slots = +let record_dal_participation ctxt ~delegate + ~number_of_slots_attested_by_delegate ~number_of_protocol_attested_slots = let open Lwt_result_syntax in - if Compare.Int.(number_of_attested_slots = 0) then return ctxt + if Compare.Int.(number_of_protocol_attested_slots = 0) then + (* then the number of slots attested by the delegate is also 0 *) + return ctxt else let contract = Contract_repr.Implicit delegate in - let* result = Storage.Contract.Attested_dal_slots.find ctxt contract in + let* result = Storage.Contract.Dal_participation.find ctxt contract in match result with - | Some already_attested_slots -> - Storage.Contract.Attested_dal_slots.update - ctxt - contract - Int32.(add already_attested_slots (of_int number_of_attested_slots)) + | Some past_participation -> + let participation = + Storage. + { + attested_slots = + past_participation.attested_slots + + number_of_slots_attested_by_delegate; + attestable_slots = + past_participation.attestable_slots + + number_of_protocol_attested_slots; + } + in + Storage.Contract.Dal_participation.update ctxt contract participation | None -> - Storage.Contract.Attested_dal_slots.init + Storage.Contract.Dal_participation.init ctxt contract - (Int32.of_int number_of_attested_slots) + { + attested_slots = number_of_slots_attested_by_delegate; + attestable_slots = number_of_protocol_attested_slots; + } -let is_dal_participation_sufficient ctxt ~dal_attested_slots_by_delegate - ~total_dal_attested_slots = +let is_dal_participation_sufficient ctxt participation = let open Q in let minimal_dal_participation_ratio = (Raw_context.constants ctxt).dal.minimal_participation_ratio in - geq - (of_int32 dal_attested_slots_by_delegate) - (mul (of_int32 total_dal_attested_slots) minimal_dal_participation_ratio) + Compare.Int.(participation.Storage.attestable_slots = 0) + || leq + minimal_dal_participation_ratio + (div + (of_int participation.attested_slots) + (of_int participation.attestable_slots)) let record_baking_activity_and_pay_rewards_and_fees ctxt ~payload_producer ~block_producer ~baking_reward ~reward_bonus = @@ -201,15 +214,15 @@ let check_and_reset_delegate_participation ctxt delegate = let get_and_maybe_reset_delegate_dal_participation ~reset ctxt delegate = let open Lwt_result_syntax in let contract = Contract_repr.Implicit delegate in - let* result = Storage.Contract.Attested_dal_slots.find ctxt contract in + let* result = Storage.Contract.Dal_participation.find ctxt contract in match result with - | None -> return (ctxt, 0l) - | Some num_slots -> + | None -> return (ctxt, Storage.{attested_slots = 0; attestable_slots = 0}) + | Some participation -> let*! ctxt = - if reset then Storage.Contract.Attested_dal_slots.remove ctxt contract + if reset then Storage.Contract.Dal_participation.remove ctxt contract else Lwt.return ctxt in - return (ctxt, num_slots) + return (ctxt, participation) let get_and_reset_delegate_dal_participation = get_and_maybe_reset_delegate_dal_participation ~reset:true @@ -314,7 +327,7 @@ module For_RPC = struct type dal_participation_info = { expected_assigned_shards_per_slot : int; delegate_attested_dal_slots : int; - total_dal_attested_slots : int; + delegate_attestable_dal_slots : int; expected_dal_rewards : Tez_repr.t; sufficient_dal_participation : bool; denounced : bool; @@ -339,7 +352,7 @@ module For_RPC = struct { expected_assigned_shards_per_slot = 0; delegate_attested_dal_slots = 0; - total_dal_attested_slots = 0; + delegate_attestable_dal_slots = 0; expected_dal_rewards = Tez_repr.zero; sufficient_dal_participation = false; denounced = false; @@ -358,18 +371,9 @@ module For_RPC = struct ~total_active_stake_weight ~active_stake_weight in - let* dal_attested_slots_by_delegate = - get_delegate_dal_participation ctxt delegate - in - let* total_dal_attested_slots = - let+ total_opt = Storage.Dal.Total_attested_slots.find ctxt in - Option.value ~default:0l total_opt - in + let* participation = get_delegate_dal_participation ctxt delegate in let sufficient_dal_participation = - is_dal_participation_sufficient - ctxt - ~dal_attested_slots_by_delegate - ~total_dal_attested_slots + is_dal_participation_sufficient ctxt participation in let*! denounced = Dal_already_denounced_storage.is_denounced ctxt delegate @@ -387,9 +391,8 @@ module For_RPC = struct return { expected_assigned_shards_per_slot; - delegate_attested_dal_slots = - Int32.to_int dal_attested_slots_by_delegate; - total_dal_attested_slots = Int32.to_int total_dal_attested_slots; + delegate_attested_dal_slots = participation.Storage.attested_slots; + delegate_attestable_dal_slots = participation.attestable_slots; expected_dal_rewards; sufficient_dal_participation; denounced; diff --git a/src/proto_alpha/lib_protocol/delegate_missed_attestations_storage.mli b/src/proto_alpha/lib_protocol/delegate_missed_attestations_storage.mli index 5638be1cbad8421d9c62e81109f6853805a6f600..ef8366b62c109f9646b626e7e233f23627c15d51 100644 --- a/src/proto_alpha/lib_protocol/delegate_missed_attestations_storage.mli +++ b/src/proto_alpha/lib_protocol/delegate_missed_attestations_storage.mli @@ -48,9 +48,6 @@ val expected_dal_shards_per_slot_for_given_active_stake : active_stake_weight:int64 -> int -(** Removes the [Storage.Dal.Total_attested_slots] value from the context. *) -val remove_total_dal_attested_slots : Raw_context.t -> Raw_context.t Lwt.t - type level_participation = Participated | Didn't_participate (** Update the participation of a delegate as a validator in the current cycle @@ -63,26 +60,27 @@ val record_attesting_participation : Raw_context.t tzresult Lwt.t (** Update the participation of a delegate as a DAL attester in the current - cycle with its participation (ie the number of DAL slots it attested) at the - current level. *) + cycle with its participation (ie the number of DAL slots it attested and the + number of DAL slots it could have attested) at the current level, based on + the number of slots it attested, and the number of protocol-attested + slot. Note that this function must be called only when attester has assigned + shards, so we know the delegate could have attested DAL slots. *) val record_dal_participation : Raw_context.t -> delegate:Signature.Public_key_hash.t -> - number_of_attested_slots:int -> + number_of_slots_attested_by_delegate:int -> + number_of_protocol_attested_slots:int -> Raw_context.t tzresult Lwt.t (** Returns [true] iff the protocol considers that the delegate attested sufficiently many slots during a cycle, given the total number of attested - slots for that cycle and the number of those slots also attested by the - delegate. + slots for that cycle that the delegate could have attested and the number of + those slots actually attested by the delegate. The decision depends on the [minimal_participation_ratio] protocol parameter. *) val is_dal_participation_sufficient : - Raw_context.t -> - dal_attested_slots_by_delegate:int32 -> - total_dal_attested_slots:int32 -> - bool + Raw_context.t -> Storage.dal_delegate_participation -> bool (** Sets the payload and block producer as active. Pays the baking reward and the fees to the payload producer and the reward bonus to @@ -103,12 +101,12 @@ val check_and_reset_delegate_participation : Signature.Public_key_hash.t -> (Raw_context.t * bool) tzresult Lwt.t -(** Retrieve the number of DAL slots a delegate DAL-attested during the last - cycle, and then reset the participation for preparing the next cycle. *) +(** Retrieve the DAL participation of a delegate during the last cycle, and then + reset the participation for preparing the next cycle. *) val get_and_reset_delegate_dal_participation : Raw_context.t -> Signature.Public_key_hash.t -> - (Raw_context.t * int32) tzresult Lwt.t + (Raw_context.t * Storage.dal_delegate_participation) tzresult Lwt.t module For_RPC : sig (** Participation information. We denote by: @@ -154,10 +152,9 @@ module For_RPC : sig delegate_attested_dal_slots : int; (** The number of attested slots during the current cycle that are attested by the delegate. (dynamic) *) - total_dal_attested_slots : int; + delegate_attestable_dal_slots : int; (** The total number of attested slots during the current cycle - (regardless whether this delegate attested them or - not). (dynamic) *) + for which the delegates had assigned shards. (dynamic) *) expected_dal_rewards : Tez_repr.t; (** The expected amount of DAL rewards for the delegate, assuming a sufficient DAL participation (see [sufficient_dal_participation] diff --git a/src/proto_alpha/lib_protocol/storage.ml b/src/proto_alpha/lib_protocol/storage.ml index 063ff0497dc486348684db774d0d38e728ae4a6d..c88f8dd04805e96d206bbb68a02d9e240164b4b8 100644 --- a/src/proto_alpha/lib_protocol/storage.ml +++ b/src/proto_alpha/lib_protocol/storage.ml @@ -161,6 +161,21 @@ module Missed_attestations_info = struct (obj2 (req "remaining_slots" int31) (req "missed_levels" int31)) end +type dal_delegate_participation = {attested_slots : int; attestable_slots : int} + +module Dal_delegate_participation = struct + type t = dal_delegate_participation + + let encoding = + let open Data_encoding in + conv + (fun {attested_slots; attestable_slots} -> + (attested_slots, attestable_slots)) + (fun (attested_slots, attestable_slots) -> + {attested_slots; attestable_slots}) + (obj2 (req "attested_slots" int31) (req "attestable_slots" int31)) +end + (* TODO #6918: move closer to its only use left after P *) module Slashed_deposits_history = struct type slashed_percentage = Percentage.t @@ -296,13 +311,13 @@ module Contract = struct end) (Missed_attestations_info) - module Attested_dal_slots = + module Dal_participation = Indexed_context.Make_map (Registered) (struct - let name = ["attested_dal_slots"] + let name = ["dal_delegate_participation"] end) - (Encoding.Int32) + (Dal_delegate_participation) module Manager = Indexed_context.Make_map @@ -2254,13 +2269,6 @@ module Dal = struct end) end - module Total_attested_slots = - Make_single_data_storage (Registered) (Raw_context) - (struct - let name = ["total_attested_slots"] - end) - (Encoding.Int32) - module Denounced_delegates = Make_indexed_data_storage (Make_subcontext (Registered) (Raw_context) diff --git a/src/proto_alpha/lib_protocol/storage.mli b/src/proto_alpha/lib_protocol/storage.mli index d7d3dad0b54220fad7d727d258ef36e38df7f2a9..aa8226cd3c67aa2f4825959287718e048bd75600 100644 --- a/src/proto_alpha/lib_protocol/storage.mli +++ b/src/proto_alpha/lib_protocol/storage.mli @@ -54,6 +54,15 @@ module Consecutive_round_zero : type missed_attestations_info = {remaining_slots : int; missed_levels : int} +type dal_delegate_participation = { + (* the number of slots attested by the delegate *) + attested_slots : int; + (* the number of protocol-attested slots that could have been attested by the + baker (that is, the baker had at least one assigned shard for the relevant + levels *) + attestable_slots : int; +} + module Slashed_deposits_history : sig type slashed_percentage = Percentage.t @@ -152,12 +161,11 @@ module Contract : sig and type value = missed_attestations_info and type t := Raw_context.t - (** The number of protocol-attested DAL slots attested by a delegate during a - cycle. *) - module Attested_dal_slots : + (** The DAL participation of a delegate during a cycle. *) + module Dal_participation : Indexed_data_storage with type key = Contract_repr.t - and type value = Int32.t + and type value = dal_delegate_participation and type t := Raw_context.t (** The manager of a contract *) @@ -1076,10 +1084,6 @@ module Dal : sig (Dal_slot_repr.History.Pointer_hash.t * Dal_slot_repr.History.t) list end - (** The number of protocol-attested DAL slots for the current cycle. *) - module Total_attested_slots : - Single_data_storage with type t := Raw_context.t and type value = Int32.t - (** Set of delegates denounced in the current cycle. It is used to not distribute rewards for such delegates. *) module Denounced_delegates : diff --git a/src/proto_alpha/lib_protocol/test/integration/consensus/test_participation.ml b/src/proto_alpha/lib_protocol/test/integration/consensus/test_participation.ml index e78c9008c569b24bcafa0a6218986933e37caf17..2e340877301da1ca79b7f8269e1fbf055dd59e6e 100644 --- a/src/proto_alpha/lib_protocol/test/integration/consensus/test_participation.ml +++ b/src/proto_alpha/lib_protocol/test/integration/consensus/test_participation.ml @@ -161,8 +161,8 @@ let check_no_dal_participation 0 in let* () = - (* No slot is attested globally. *) - Assert.equal_int ~loc:__LOC__ dal_info.total_dal_attested_slots 0 + (* No slot is attested globally, so no slot is attestable. *) + Assert.equal_int ~loc:__LOC__ dal_info.delegate_attestable_dal_slots 0 in let* () = (* No attested slot is also attested by this delegate. *) diff --git a/tezt/tests/dal.ml b/tezt/tests/dal.ml index 50621b3c0869ebcc39a088ed6b9bed74abe5cd33..1e7a74f2c36c802af90447db4e23d74f85fc7965 100644 --- a/tezt/tests/dal.ml +++ b/tezt/tests/dal.ml @@ -8243,9 +8243,7 @@ let test_attesters_receive_dal_rewards protocol dal_parameters _cryptobox node let rest_delegates = List.tl all_delegates in let* first_level = Node.get_level node in - let middle_of_cycle_level = - first_level + blocks_per_cycle + (blocks_per_cycle / 4) - in + let middle_of_cycle_level = first_level + blocks_per_cycle in let last_level = first_level + (2 * blocks_per_cycle) in Log.info "Bake from first_level = %d to last_level = %d"