From 78b6a336968ad950f4ac413e500ba01ea8a2bc4d Mon Sep 17 00:00:00 2001 From: Guillaume Genestier Date: Wed, 23 Apr 2025 16:39:54 +0200 Subject: [PATCH 1/3] Tezt-cloud/DAL: Use as much as possible in DAL monitoring --- tezt/tests/cloud/dal.ml | 46 +++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/tezt/tests/cloud/dal.ml b/tezt/tests/cloud/dal.ml index 5fe49da4048a..22009e38d524 100644 --- a/tezt/tests/cloud/dal.ml +++ b/tezt/tests/cloud/dal.ml @@ -1120,6 +1120,12 @@ let get_metrics t infos_per_level metrics = } module Monitoring_app = struct + let pp_delegate fmt delegate_pkh = + match Hashtbl.find_opt aliases delegate_pkh with + | None -> Format.fprintf fmt "`%s`" delegate_pkh + | Some alias -> + Format.fprintf fmt "`%s` : `%s`" (String.sub delegate_pkh 0 7) alias + (** [network_to_image_url network] return an image for each monitored network. *) let network_to_image_url : Network.t -> string = function | `Rionet -> @@ -1374,16 +1380,8 @@ module Monitoring_app = struct let pp_stake fmt stake_ratio = Format.fprintf fmt "`%.2f%%` stake" (stake_ratio *. 100.) - let display_delegate (`address address, `alias alias, _, stake_ratio) = - match alias with - | None -> Format.asprintf "`%s` (%a)" address pp_stake stake_ratio - | Some alias -> - Format.asprintf - "`%s` : `%s` (%a)" - (String.sub address 0 7) - alias - pp_stake - stake_ratio + let display_delegate (`address address, _, _, stake_ratio) = + Format.asprintf "%a (%a)" pp_delegate address pp_stake stake_ratio let view_bakers bakers = List.map @@ -1648,9 +1646,11 @@ module Monitoring_app = struct let content = List.map (fun (`delegate delegate, `change change) -> - Format.sprintf - "▪ `%s` has missed ~%d tez DAL attestation rewards" - (String.sub delegate 0 7) + Format.asprintf + ":black_small_square: %a has missed ~%d tez DAL attestation \ + rewards" + pp_delegate + delegate (change / 100_000)) lost_dal_rewards in @@ -1726,10 +1726,11 @@ module Monitoring_app = struct `slot_index slot_index, `delegate delegate, `op_hash hash ) -> - Format.sprintf - "▪ `%s` for attesting slot index `%d` at level `%d`. \ - " - (String.sub delegate 0 7) + Format.asprintf + ":black_small_square: %a for attesting slot index `%d` at \ + level `%d`. " + pp_delegate + delegate slot_index attestation_level (Network.to_string network) @@ -1841,19 +1842,20 @@ module Monitoring_app = struct let {slack_channel_id; slack_bot_token} = monitor_app_configuration in let data = let header = - Format.sprintf + Format.asprintf (match transition with | Restarted_attesting -> "*[dal-attester-is-back]* On network `%s` at level `%d`, \ - delegate `%s` who was under the reward threshold is again \ - above threshold. New attestation rate is %.2f%%." + delegate %a who was under the reward threshold is again above \ + threshold. New attestation rate is %.2f%%." | Stopped_attesting -> "*[dal-attester-dropped]* On network `%s` at level `%d`, \ - delegate `%s` DAL attestation rate dropped under the reward \ + delegate %a DAL attestation rate dropped under the reward \ threshold. New attestation rate is %.2f%%.") (Network.to_string network) level - (String.sub pkh 0 8) + pp_delegate + pkh attestation_percentage in Format_app.section [header] () -- GitLab From 43fee0c5e95c93e17dca4327a8e522b39a982246 Mon Sep 17 00:00:00 2001 From: Guillaume Genestier Date: Wed, 23 Apr 2025 16:40:50 +0200 Subject: [PATCH 2/3] Tezt-cloud/DAL: Since alias is computed by pp_delegate, it is not required to have it in fetch_bakers_info --- tezt/tests/cloud/dal.ml | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/tezt/tests/cloud/dal.ml b/tezt/tests/cloud/dal.ml index 22009e38d524..7825896bc445 100644 --- a/tezt/tests/cloud/dal.ml +++ b/tezt/tests/cloud/dal.ml @@ -1380,12 +1380,12 @@ module Monitoring_app = struct let pp_stake fmt stake_ratio = Format.fprintf fmt "`%.2f%%` stake" (stake_ratio *. 100.) - let display_delegate (`address address, _, _, stake_ratio) = + let display_delegate (`address address, _, stake_ratio) = Format.asprintf "%a (%a)" pp_delegate address pp_stake stake_ratio let view_bakers bakers = List.map - (fun ((_, _, (value, mentions_dal), _) as baker) -> + (fun ((_, (value, mentions_dal), _) as baker) -> Format.sprintf ":black_small_square: %s - %s (%s)" (Option.fold @@ -1463,13 +1463,12 @@ module Monitoring_app = struct let baking_ratio = float_of_int baking_power /. float_of_int total_baking_power in - let alias = Hashtbl.find_opt aliases delegate in - Lwt.return_some (`address delegate, `alias alias, info, baking_ratio)) + Lwt.return_some (`address delegate, info, baking_ratio)) bakers in let rec classify_bakers mute_bakers dal_on dal_off = function | [] -> (mute_bakers, dal_on, dal_off) - | ((_, _, (_, dal_endorsement), _) as baker) :: tl -> ( + | ((_, (_, dal_endorsement), _) as baker) :: tl -> ( match dal_endorsement with | None -> classify_bakers (baker :: mute_bakers) dal_on dal_off tl | Some 0. -> @@ -1480,15 +1479,15 @@ module Monitoring_app = struct let ( >> ) cmp1 cmp2 x y = match cmp1 x y with 0 -> cmp2 x y | cmp -> cmp in - let stake_descending (_, _, (_, _), x_stake) (_, _, (_, _), y_stake) = + let stake_descending (_, (_, _), x_stake) (_, (_, _), y_stake) = Float.compare y_stake x_stake in - let attestation_rate_ascending (_, _, (x_attestation, _), _) - (_, _, (y_attestation, _), _) = + let attestation_rate_ascending (_, (x_attestation, _), _) + (_, (y_attestation, _), _) = Option.compare Float.compare x_attestation y_attestation in - let dal_mention_perf_ascending (_, _, (_, x_dal_mention), _) - (_, _, (_, y_dal_mention), _) = + let dal_mention_perf_ascending (_, (_, x_dal_mention), _) + (_, (_, y_dal_mention), _) = Option.compare Float.compare x_dal_mention y_dal_mention in let mute_bakers = List.sort stake_descending mute_bakers in @@ -1515,7 +1514,7 @@ module Monitoring_app = struct let agglomerate_infos bakers = let nb, stake = List.fold_left - (fun (nb, stake_acc) (_, _, _, stake_ratio) -> + (fun (nb, stake_acc) (_, _, stake_ratio) -> (nb + 1, stake_acc +. stake_ratio)) (0, 0.) bakers -- GitLab From dd4b6215a4adf3b690f305ded5bfa4f3399f0a57 Mon Sep 17 00:00:00 2001 From: Guillaume Genestier Date: Mon, 28 Apr 2025 18:22:30 +0200 Subject: [PATCH 3/3] Tezt-cloud/DAL: Factor 10 in missed rewards --- tezt/tests/cloud/dal.ml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tezt/tests/cloud/dal.ml b/tezt/tests/cloud/dal.ml index 7825896bc445..5009999aa357 100644 --- a/tezt/tests/cloud/dal.ml +++ b/tezt/tests/cloud/dal.ml @@ -1646,11 +1646,11 @@ module Monitoring_app = struct List.map (fun (`delegate delegate, `change change) -> Format.asprintf - ":black_small_square: %a has missed ~%d tez DAL attestation \ + ":black_small_square: %a has missed ~%.1f tez DAL attestation \ rewards" pp_delegate delegate - (change / 100_000)) + (float_of_int change /. 1_000_000.)) lost_dal_rewards in Format_app.section (header :: content) () -- GitLab