Skip to content

fix: clear stale guardian votes when guardians are removed - #345

Merged
icentedward76-sketch merged 2 commits into
SoroWill:mainfrom
timilehin01010-byte:fix/issue-334-reset-guardian-votes-reset-guardian-cancel
Aug 31, 2026
Merged

fix: clear stale guardian votes when guardians are removed#345
icentedward76-sketch merged 2 commits into
SoroWill:mainfrom
timilehin01010-byte:fix/issue-334-reset-guardian-votes-reset-guardian-cancel

Conversation

@timilehin01010-byte

Copy link
Copy Markdown
Contributor

Overview

This PR fixes a stale-vote cleanup gap in the will contract. Previously, reset_guardian_votes and reset_guardian_cancel_votes only iterated over will.guardians, so a guardian who voted and was later removed from the list could leave a GuardianVote/GuardianCancelVote entry in storage indefinitely. If that same address was later re-added as a guardian, the old vote record could still be found by has_guardian_voted, causing the guardian to be treated as having already voted in a new, unrelated cycle.

This PR ensures guardian-list-changing entry points explicitly clean up vote/cancel-vote entries for guardians being removed, and adds a regression test for the remove/re-add scenario.

Related Issue

Closes #bounty

Changes

🧹 Stale Guardian Vote Cleanup

  • [MODIFY] contracts/will/src/storage.rs

    • In update_guardians, compute the set of guardian addresses being removed and explicitly clear their GuardianVote and GuardianCancelVote storage entries before updating the guardian list.
    • In update_will_settings, apply the same explicit cleanup for any guardian that is removed when the new guardian list is set.
    • Keep existing reset_guardian_votes/reset_guardian_cancel_votes behavior for the current guardian list unchanged.
  • [ADD] contracts/will/src/regression_test.rs

    • Adds a regression test that:
      • Creates a will with a guardian.
      • Lets that guardian vote.
      • Removes the guardian from the guardian list.
      • Re-adds the same guardian.
      • Asserts has_guardian_voted returns false in the new cycle, proving the stale vote was cleared.

Verification Results

cargo test --workspace
✅ all tests passed

cargo clippy --all-targets -- -D warnings
✅ no warnings

Regression test:
✅ stale guardian vote cleared on removal
✅ re-added guardian is not treated as having already voted
Acceptance Criteria Status
Removing a guardian clears GuardianVote/GuardianCancelVote entries for that guardian update_guardians/update_will_settings now remove stale vote entries for removed guardians
Re-added guardian is not treated as having already voted in a new cycle ✅ Regression test asserts has_guardian_voted == false after remove/re-add
cargo test --workspace passes ✅ All tests pass
cargo clippy --all-targets -- -D warnings passes ✅ No clippy warnings

Closes #334

@drips-wave

drips-wave Bot commented Aug 31, 2026

Copy link
Copy Markdown

@timilehin01010-byte Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@icentedward76-sketch
icentedward76-sketch merged commit c1913ab into SoroWill:main Aug 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

reset_guardian_votes/reset_guardian_cancel_votes only clear votes for guardians in the *current* guardian list

2 participants