From 69e854e2dcb842b96dd4771511a578537e909387 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Thir=C3=A9?= Date: Mon, 17 Feb 2025 16:21:00 +0100 Subject: [PATCH 1/2] DAL/Node: add a metric to attest the slot ratio for the baker --- src/bin_dal_node/dal_metrics.ml | 17 +++++++++++++++++ src/bin_dal_node/dal_metrics.mli | 4 ++++ 2 files changed, 21 insertions(+) diff --git a/src/bin_dal_node/dal_metrics.ml b/src/bin_dal_node/dal_metrics.ml index e159fd5c1730..efd64463771e 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 9bd87b54a06b..04f8f1a39cae 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 -- GitLab From b3ff138c69f5a59fb24b44e7e03ed9ad12994f0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Thir=C3=A9?= Date: Tue, 25 Feb 2025 13:39:24 +0100 Subject: [PATCH 2/2] DAL/Node: Implement a metric to monitor baker performance --- src/bin_dal_node/daemon.ml | 31 +++++++++++++++++-- src/lib_dal_node/dal_plugin.ml | 2 ++ src/lib_dal_node/dal_plugin.mli | 3 ++ .../lib_dal/dal_plugin_registration.ml | 2 ++ .../lib_dal/dal_plugin_registration.ml | 3 ++ .../lib_dal/dal_plugin_registration.ml | 3 ++ 6 files changed, 41 insertions(+), 3 deletions(-) diff --git a/src/bin_dal_node/daemon.ml b/src/bin_dal_node/daemon.ml index bfcb7a9353a1..ec717bed392b 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/lib_dal_node/dal_plugin.ml b/src/lib_dal_node/dal_plugin.ml index 8ac9bf4b6f76..44580c004c51 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 dd32ab5c6a89..7b6ac6fb0433 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 0e477ee588ee..fe4f1140b19c 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 6c6a735d7967..119813a1b893 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 6c6a735d7967..119813a1b893 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 -- GitLab