From 45d175c11c39bf97c58fdc950e42702c67ff6be7 Mon Sep 17 00:00:00 2001 From: Julien Tesson Date: Wed, 27 Mar 2024 09:54:57 +0100 Subject: [PATCH 1/5] proto/test/helpers/context: expose grace period --- src/proto_alpha/lib_protocol/test/helpers/context.ml | 2 ++ src/proto_alpha/lib_protocol/test/helpers/context.mli | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/proto_alpha/lib_protocol/test/helpers/context.ml b/src/proto_alpha/lib_protocol/test/helpers/context.ml index 42d8b87fa7a2..b8d17f56dc66 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/context.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/context.ml @@ -503,6 +503,8 @@ module Delegate = struct type stake = {frozen : Tez.t; weighted_delegated : Tez.t} + let grace_period ctxt pkh = Delegate_services.grace_period rpc_ctxt ctxt pkh + let info ctxt pkh = Plugin.RPC.Delegates.info rpc_ctxt ctxt pkh let full_balance ctxt pkh = Delegate_services.full_balance rpc_ctxt ctxt pkh diff --git a/src/proto_alpha/lib_protocol/test/helpers/context.mli b/src/proto_alpha/lib_protocol/test/helpers/context.mli index 17e4813cc4ed..542ae960b458 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/context.mli +++ b/src/proto_alpha/lib_protocol/test/helpers/context.mli @@ -297,6 +297,8 @@ module Delegate : sig val deactivated : t -> public_key_hash -> bool tzresult Lwt.t + val grace_period : t -> public_key_hash -> Cycle.t tzresult Lwt.t + val voting_info : t -> public_key_hash -> Vote.delegate_info tzresult Lwt.t val consensus_key : -- GitLab From 3baaf3cc0b43b1d978c5c85367a2e73fa105ae9e Mon Sep 17 00:00:00 2001 From: Julien Tesson Date: Wed, 27 Mar 2024 09:56:36 +0100 Subject: [PATCH 2/5] proto/test/helpers/scenario: add a grace period to fresh bakers --- src/proto_alpha/lib_protocol/test/helpers/scenario_begin.ml | 2 ++ src/proto_alpha/lib_protocol/test/helpers/scenario_op.ml | 4 +--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/proto_alpha/lib_protocol/test/helpers/scenario_begin.ml b/src/proto_alpha/lib_protocol/test/helpers/scenario_begin.ml index 6ea7a016fc18..68fb0a3c7195 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/scenario_begin.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/scenario_begin.ml @@ -150,6 +150,8 @@ let begin_test ?(burn_rewards = false) ?(force_attest_all = false) ~liquid ~frozen_deposits ~frozen_rights + ~last_active_cycle: + Cycle.(add root constants.consensus_rights_delay) () in let account_map = String.Map.add name account account_map in diff --git a/src/proto_alpha/lib_protocol/test/helpers/scenario_op.ml b/src/proto_alpha/lib_protocol/test/helpers/scenario_op.ml index d12946b258bc..f0566d957cb4 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/scenario_op.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/scenario_op.ml @@ -162,9 +162,7 @@ let set_delegate src_name delegate_name_opt : (t, t) scenarios = let pred_level = block.header.shell.level in let level = Int32.(succ pred_level) in let activity_cycle = - Block.current_cycle_of_level - ~blocks_per_cycle:state.constants.blocks_per_cycle - ~current_level:level + Cycle.add current_cycle state.State.constants.consensus_rights_delay in (* update delegate activation status *) let state = -- GitLab From b4d539b44897b1df214140b65c5b2ebf6606437b Mon Sep 17 00:00:00 2001 From: Julien Tesson Date: Wed, 27 Mar 2024 10:09:54 +0100 Subject: [PATCH 3/5] proto/test/state_ai_flags: grace period is consensus_rights_delay+1 --- src/proto_alpha/lib_protocol/test/helpers/state_ai_flags.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/proto_alpha/lib_protocol/test/helpers/state_ai_flags.ml b/src/proto_alpha/lib_protocol/test/helpers/state_ai_flags.ml index 40fce015234a..42d9493f74ac 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/state_ai_flags.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/state_ai_flags.ml @@ -113,7 +113,7 @@ module Autostake = struct let open Lwt_result_syntax in (* TODO: use Protocol.Constants_storage.tolerated_inactivity_period *) let tolerated_inactivity_period = - (2 * state.constants.consensus_rights_delay) + 1 + state.constants.consensus_rights_delay + 1 in if Some name <> delegate then ( Log.debug -- GitLab From 616c16f612f55b0a75d4e81189a1c6ede3006682 Mon Sep 17 00:00:00 2001 From: Julien Tesson Date: Wed, 27 Mar 2024 10:13:07 +0100 Subject: [PATCH 4/5] proto/test/test-deactivation: check grace period --- .../integration/test_scenario_deactivation.ml | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/proto_alpha/lib_protocol/test/integration/test_scenario_deactivation.ml b/src/proto_alpha/lib_protocol/test/integration/test_scenario_deactivation.ml index 104f744fab7a..3fd7918e971c 100644 --- a/src/proto_alpha/lib_protocol/test/integration/test_scenario_deactivation.ml +++ b/src/proto_alpha/lib_protocol/test/integration/test_scenario_deactivation.ml @@ -31,6 +31,24 @@ let check_is_not_active ~loc src_name = let* b = Context.Delegate.deactivated (B block) src.pkh in Assert.is_true ~loc b +let check_grace_period ~loc src_name = + let open Lwt_result_syntax in + exec_unit @@ fun (block, state) -> + let src = State.find_account src_name state in + let grace = + Cycle.add + src.last_active_cycle + (state.State.constants.consensus_rights_delay + 1) + in + let* rpc_grace = Context.Delegate.grace_period (B block) src.pkh in + Assert.equal + ( = ) + "Grace period is not correct: expected vs RPC" + ~loc + Cycle.pp + grace + rpc_grace + (** Test that a delegate gets deactivated after a set period of time if it is not baking. Test that with autostaking, the frozen funds are completely unstaked, which get finalizable (but not finalized) after a set period of time. @@ -40,6 +58,7 @@ let test_simple_scenario_with_autostaking = --> set S.Adaptive_issuance.autostaking_enable true --> activate_ai `No --> begin_test ["delegate"; "baker"] + --> check_grace_period ~loc:__LOC__ "baker" --> set_baker "baker" --> wait_n_cycles_f (fun (_, state) -> (2 * state.State.constants.consensus_rights_delay) + 1) @@ -48,12 +67,17 @@ let test_simple_scenario_with_autostaking = --> next_cycle --> check_is_not_active ~loc:__LOC__ "delegate" --> check_balance_field "delegate" `Staked Tez.zero + --> check_grace_period ~loc:__LOC__ "baker" + --> next_block + --> check_grace_period ~loc:__LOC__ "baker" --> check_balance_field "delegate" `Unstaked_frozen_total (Tez.of_mutez 200_000_000_000L) --> wait_n_cycles_f Test_scenario_stake.unstake_wait --> check_balance_field "delegate" `Unstaked_frozen_total Tez.zero + --> check_grace_period ~loc:__LOC__ "delegate" + --> check_grace_period ~loc:__LOC__ "baker" --> check_balance_field "delegate" `Unstaked_finalizable -- GitLab From 575f0b0cc35be4a1d8756669ef099cad6cd058d1 Mon Sep 17 00:00:00 2001 From: Diane Gallois-Wong Date: Fri, 5 Jul 2024 17:08:09 +0200 Subject: [PATCH 5/5] Proto/test: add link to follow-up issue in comments --- src/proto_alpha/lib_protocol/test/helpers/scenario_op.ml | 2 ++ src/proto_alpha/lib_protocol/test/helpers/state_ai_flags.ml | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/proto_alpha/lib_protocol/test/helpers/scenario_op.ml b/src/proto_alpha/lib_protocol/test/helpers/scenario_op.ml index f0566d957cb4..2754cef1579d 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/scenario_op.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/scenario_op.ml @@ -162,6 +162,8 @@ let set_delegate src_name delegate_name_opt : (t, t) scenarios = let pred_level = block.header.shell.level in let level = Int32.(succ pred_level) in let activity_cycle = + (* TODO: https://gitlab.com/tezos/tezos/-/issues/7362 + Use delegate_parameters_activation_delay - Protocol.Constants_storage.tolerated_inactivity_period *) Cycle.add current_cycle state.State.constants.consensus_rights_delay in (* update delegate activation status *) diff --git a/src/proto_alpha/lib_protocol/test/helpers/state_ai_flags.ml b/src/proto_alpha/lib_protocol/test/helpers/state_ai_flags.ml index 42d9493f74ac..6631c2e79458 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/state_ai_flags.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/state_ai_flags.ml @@ -111,7 +111,8 @@ module Autostake = struct } : account_state) state = let open Lwt_result_syntax in - (* TODO: use Protocol.Constants_storage.tolerated_inactivity_period *) + (* TODO: https://gitlab.com/tezos/tezos/-/issues/7362 + Use Protocol.Constants_storage.tolerated_inactivity_period *) let tolerated_inactivity_period = state.constants.consensus_rights_delay + 1 in -- GitLab