Refactor: extract pending-admin cleanup to shared helper - #77
Open
onyekachi66 wants to merge 1 commit into
Open
Conversation
Factored the 'clear any pending admin proposal for the outgoing admin' logic into a new internal helper set_admin_and_clear_pending to ensure structural enforcement of this invariant. Both existing admin-rotation paths (accept_admin and execute_recovery) now route through this helper. Also added an explicit regression test to assert that PendingAdmin(old_admin) is successfully removed after a normal accept_admin flow.
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.
Closes #44
Root cause
The invariant that every admin-rotation path must remove
PendingAdmin(old_admin)was implicit and enforced only by each function (accept_adminandexecute_recovery) remembering to execute the cleanup independently. BecausePendingAdminis keyed by the admin's address rather than being a singleton, this design is structurally fragile: if a third admin-rotation mechanism is ever added, it would be easy to forget this cleanup, leading to orphaned pending-admin entries accumulating under stale addresses.What changed and why
Factored the 'clear any pending admin proposal for the outgoing admin' logic into a new internal helper
set_admin_and_clear_pendingto ensure structural enforcement of this invariant. Both existing admin-rotation paths (accept_adminandexecute_recovery) now route through this helper, centralizing the invariant so future rotation paths cannot forget to clean it up. I chose a shared helper over individual function checks because it enforces the cleanup at the structural level anytime the admin role is transferred.Definition of done — addressed item by item
test_pending_admin_entry_removed_after_normal_acceptwhich explicitly tests this.set_admin_and_clear_pendinginternal helper and routed bothaccept_adminandexecute_recoveryto use it.Evidence this actually runs
Tests
Added
test_pending_admin_entry_removed_after_normal_accept. It asserts that after a normalaccept_adminflow, a fresh proposal targeting the old admin address finds no leftover pending entry and returns theNoPendingAdminerror.Regression check
The adjacent behavior is the guardian recovery path, which also clears the pending admin entry. I verified this via the existing
test_recovery_clears_any_in_flight_normal_admin_transfertest, which explicitly ensures that the recovery path also leaves no stalePendingAdminentries behind.Checklist
console.log/TODO/debug code