fix: deregister guardian from AllGuardians and slot index in resign_g… - #311
Open
Joycejay17 wants to merge 1 commit into
Open
fix: deregister guardian from AllGuardians and slot index in resign_g…#311Joycejay17 wants to merge 1 commit into
Joycejay17 wants to merge 1 commit into
Conversation
…uardian (Vero-protocol#303) - Extract deregister_guardian helper from remove_guardian - Update resign_guardian to call deregister_guardian for proper cleanup - Add regression test that resigned guardian can be re-added - Keep token-refund/timelock logic after deregistration Closes Vero-protocol#303
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #303 -
resign_guardiannow properly deregisters guardians from all membership structures (AllGuardians and the dense slot index), preventing permanent lockout of resigned guardians and eliminating storage leaks.Problem
Previously,
resign_guardianonly cleared the guardian membership flag (DataKey::Guardian) but did not remove the address from:DataKey::AllGuardianssetGuardianIndexAt/GuardianIndexOf/GuardianIndexCount)This caused:
add_guardianchecksall_guardians.contains(guardian)get_snapshot_meta().guardian_countremained inflated, andget_guardians_pagestill included resigned guardiansresign_guardianandremove_guardianleft the contract in different states for the same addressSolution
deregister_guardianhelper fromremove_guardianthat handles complete membership cleanupresign_guardianto callderegister_guardianinstead of the bareremove(&g_key)NotGuardianearly return checkChanges
deregister_guardianhelper function (pub(crate)), refactoredremove_guardianto use itresign_guardianto callguardian::deregister_guardiantest_resigned_guardian_can_be_readdedTest plan
guardian_countdecreases by 1 after resignationget_guardians_pagetest_resign_guardian_refunds_tokensstill passescargo test --libcargo test --test resign_guardian_deregisterVerification
After resignation:
is_guardian(g)returnsfalseget_snapshot_meta().guardian_countdecreases by 1get_guardians_page(0, 50)no longer includes the resigned addressadd_guardian(admin, g)succeeds and the guardian is properly re-registeredresign_guardianandremove_guardiannow leave byte-identical guardian-index state for the same address