diff --git a/src/bin_dal_node/daemon.ml b/src/bin_dal_node/daemon.ml index bfcb7a9353a10e3cc104f4744a3e27a6b1e1590f..ec717bed392bdcb3ce8872d3eaedc94eec825eed 100644 --- a/src/bin_dal_node/daemon.ml +++ b/src/bin_dal_node/daemon.ml @@ -494,9 +494,18 @@ module Handler = struct parameters.cryptobox_parameters.number_of_shards / parameters.cryptobox_parameters.redundancy_factor in - let should_be_attested index = - let num_attested_shards = attested_shards_per_slot.(index) in - num_attested_shards >= threshold + let are_slots_protocol_attested = + Array.map + (fun num_attested_shards -> num_attested_shards >= threshold) + attested_shards_per_slot + in + let should_be_attested index = are_slots_protocol_attested.(index) in + let number_of_attested_slots = + Array.fold_left + (fun counter is_attested -> + if is_attested then counter + 1 else counter) + 0 + are_slots_protocol_attested in let contains_traps = let store = Node_context.get_store node_ctxt in @@ -523,6 +532,7 @@ module Handler = struct in match attestation_opt with | None -> + Dal_metrics.attested_slots_for_baker_per_level_ratio ~delegate 0. ; Event.emit_warn_no_attestation ~attester:delegate ~attested_level:block_level @@ -530,6 +540,9 @@ module Handler = struct -> ( match dal_attestation_opt with | None -> + Dal_metrics.attested_slots_for_baker_per_level_ratio + ~delegate + 0. ; Event.emit_warn_attester_not_dal_attesting ~attester:delegate ~attested_level:block_level @@ -557,6 +570,18 @@ module Handler = struct ([], [], []) (parameters.number_of_slots - 1 --- 0) in + let baker_attested_slot = + List.length attested + List.length not_attested_with_traps + in + let ratio = + try + float_of_int baker_attested_slot + /. float_of_int number_of_attested_slots + with _ -> 1. + in + Dal_metrics.attested_slots_for_baker_per_level_ratio + ~delegate + ratio ; let*! () = if attested <> [] then Event.emit_attester_attested diff --git a/src/bin_dal_node/dal_metrics.ml b/src/bin_dal_node/dal_metrics.ml index e159fd5c173040da420d4051bb683d6a93eefbaf..efd64463771e16e4c8c0ce374a370965f378d37a 100644 --- a/src/bin_dal_node/dal_metrics.ml +++ b/src/bin_dal_node/dal_metrics.ml @@ -93,6 +93,17 @@ module Node_metrics = struct ~subsystem name + let attested_slots_for_baker_per_level_ratio = + let name = "attested_slot_for_baker_per_level_ratio" in + Prometheus.Gauge.v_label + ~label_name:"attester" + ~help: + "Ratio between the number of slots attested by the baker over the \ + total number of attestable slots per level." + ~namespace + ~subsystem + name + let new_layer1_head = let name = "new_layer1_head" in Prometheus.Gauge.v @@ -518,6 +529,12 @@ let slot_attested ~set i = let v = float_of_int @@ if set then 1 else 0 in Prometheus.Gauge.set (Node_metrics.slots_attested (string_of_int i)) v +let attested_slots_for_baker_per_level_ratio ~delegate ratio = + let attester = Format.asprintf "%a@." Signature.Public_key_hash.pp delegate in + Prometheus.Gauge.set + (Node_metrics.attested_slots_for_baker_per_level_ratio attester) + ratio + let new_layer1_head ~head_level = Int32.to_float head_level |> Prometheus.Gauge.set Node_metrics.new_layer1_head diff --git a/src/bin_dal_node/dal_metrics.mli b/src/bin_dal_node/dal_metrics.mli index 9bd87b54a06bbe8b4df5030f69671447689eb9eb..04f8f1a39caef5e87caf8066c4522edd461c788d 100644 --- a/src/bin_dal_node/dal_metrics.mli +++ b/src/bin_dal_node/dal_metrics.mli @@ -33,6 +33,10 @@ val slot_waiting_for_attestation : set:bool -> int -> unit value is set to 1 if [set] is true, and -1 otherwise. *) val slot_attested : set:bool -> int -> unit +(** Update the "attestation" ratio for the baker *) +val attested_slots_for_baker_per_level_ratio : + delegate:Signature.Public_key_hash.t -> float -> unit + (** Update the seen layer1 heads with the given value. *) val new_layer1_head : head_level:int32 -> unit diff --git a/src/lib_dal_node/dal_plugin.ml b/src/lib_dal_node/dal_plugin.ml index 8ac9bf4b6f7668c885af3f20926b425bfb7a4e25..44580c004c51e18e12c9d831c8d28a3ef249fd9b 100644 --- a/src/lib_dal_node/dal_plugin.ml +++ b/src/lib_dal_node/dal_plugin.ml @@ -76,6 +76,8 @@ module type T = sig val is_attested : dal_attestation -> slot_index -> bool + val number_of_attested_slots : dal_attestation -> int + val get_round : Fitness.t -> int32 tzresult val block_shell_header : block_info -> Block_header.shell_header diff --git a/src/lib_dal_node/dal_plugin.mli b/src/lib_dal_node/dal_plugin.mli index dd32ab5c6a8932cceca421a83d8d5b18c9f38c8b..7b6ac6fb0433eaf008489fd09321d4561a425528 100644 --- a/src/lib_dal_node/dal_plugin.mli +++ b/src/lib_dal_node/dal_plugin.mli @@ -105,6 +105,9 @@ module type T = sig is one of the [dal_attestation] and [false] otherwise. *) val is_attested : dal_attestation -> slot_index -> bool + (** [number_of_attested_slots] returns the number of slots attested in the [dal_attestation]. *) + val number_of_attested_slots : dal_attestation -> int + (** [get_round fitness] returns the block round contained in [fitness]. *) val get_round : Fitness.t -> int32 tzresult diff --git a/src/proto_021_PsQuebec/lib_dal/dal_plugin_registration.ml b/src/proto_021_PsQuebec/lib_dal/dal_plugin_registration.ml index 0e477ee588eeae075cba68e323ff3d7a2e86ebdf..fe4f1140b19c1c54d3c63f6f96979e65b28bd71f 100644 --- a/src/proto_021_PsQuebec/lib_dal/dal_plugin_registration.ml +++ b/src/proto_021_PsQuebec/lib_dal/dal_plugin_registration.ml @@ -209,6 +209,8 @@ module Plugin = struct let is_attested attestation slot_index = match Bitset.mem attestation slot_index with Ok b -> b | Error _ -> false + let number_of_attested_slots attestation = Bitset.hamming_weight attestation + let is_delegate ctxt ~pkh = let open Lwt_result_syntax in let*? pkh = Signature.Of_V_latest.get_public_key_hash pkh in diff --git a/src/proto_022_PsRiotum/lib_dal/dal_plugin_registration.ml b/src/proto_022_PsRiotum/lib_dal/dal_plugin_registration.ml index 6c6a735d7967430e2118db74b573f969c9121709..119813a1b89360d1afa4c2d31c076517b860b395 100644 --- a/src/proto_022_PsRiotum/lib_dal/dal_plugin_registration.ml +++ b/src/proto_022_PsRiotum/lib_dal/dal_plugin_registration.ml @@ -250,6 +250,9 @@ module Plugin = struct | Ok b -> b | Error _ -> false + let number_of_attested_slots attestation = + Environment.Bitset.cardinal attestation + let is_delegate ctxt ~pkh = let open Lwt_result_syntax in let*? pkh = Signature.Of_V_latest.get_public_key_hash pkh in diff --git a/src/proto_alpha/lib_dal/dal_plugin_registration.ml b/src/proto_alpha/lib_dal/dal_plugin_registration.ml index 6c6a735d7967430e2118db74b573f969c9121709..119813a1b89360d1afa4c2d31c076517b860b395 100644 --- a/src/proto_alpha/lib_dal/dal_plugin_registration.ml +++ b/src/proto_alpha/lib_dal/dal_plugin_registration.ml @@ -250,6 +250,9 @@ module Plugin = struct | Ok b -> b | Error _ -> false + let number_of_attested_slots attestation = + Environment.Bitset.cardinal attestation + let is_delegate ctxt ~pkh = let open Lwt_result_syntax in let*? pkh = Signature.Of_V_latest.get_public_key_hash pkh in