From 305e35d3236dd407c7f19723355e6e348c69ef9a Mon Sep 17 00:00:00 2001 From: Diane Gallois-Wong Date: Thu, 18 Sep 2025 12:16:22 +0200 Subject: [PATCH] Proto/deactivation: more precise comparison --- .../lib_protocol/delegate_activation_storage.ml | 14 ++++++++------ .../lib_protocol/test/helpers/scenario_activity.ml | 10 ++++++---- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/proto_alpha/lib_protocol/delegate_activation_storage.ml b/src/proto_alpha/lib_protocol/delegate_activation_storage.ml index 1b81194cd6bd..ff1a89403753 100644 --- a/src/proto_alpha/lib_protocol/delegate_activation_storage.ml +++ b/src/proto_alpha/lib_protocol/delegate_activation_storage.ml @@ -73,15 +73,17 @@ let tolerated_inactivity_period ctxt delegate = ctxt current_cycle in - let compare_stake_ratio_with_threshold = + (* If [(delegate_baking_power / total_baking_power) > (tolerance_threshold / 1000)] + use low tolerance, otherwise use high tolerance. *) + let compare_power_ratio_with_threshold = Int64.( compare - (div - (mul 1000L (Stake_repr.staking_weight delegate_stake)) - (Stake_repr.staking_weight total_stake)) - (of_int tolerance_threshold)) + (mul 1000L (Stake_repr.staking_weight delegate_stake)) + (mul + (of_int tolerance_threshold) + (Stake_repr.staking_weight total_stake))) in - if Compare.Int.(compare_stake_ratio_with_threshold > 0) then + if Compare.Int.(compare_power_ratio_with_threshold > 0) then (ctxt, tolerance_low) else (ctxt, tolerance_high) diff --git a/src/proto_alpha/lib_protocol/test/helpers/scenario_activity.ml b/src/proto_alpha/lib_protocol/test/helpers/scenario_activity.ml index 40c03278292a..89622d13ca20 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/scenario_activity.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/scenario_activity.ml @@ -8,6 +8,8 @@ open State_account open State +(** Mimics + {!Protocol.Delegate_activation_storage.tolerated_inactivity_period}. *) let tolerated_inactivity_period ~block ~state account = let open Lwt_result_syntax in let tolerance_threshold = @@ -24,13 +26,13 @@ let tolerated_inactivity_period ~block ~state account = match delegate_stake with | None -> tolerance_low | Some delegate_stake -> - let compare_stake_ratio_with_threshold = + let compare_power_ratio_with_threshold = Int64.( compare - (div (mul 1000L delegate_stake) total_stake) - (of_int tolerance_threshold)) + (mul 1000L delegate_stake) + (mul (of_int tolerance_threshold) total_stake)) in - if Compare.Int.(compare_stake_ratio_with_threshold > 0) then + if Compare.Int.(compare_power_ratio_with_threshold > 0) then tolerance_low else tolerance_high -- GitLab