refactor: replace queue mappings with sorted-array invariant#116
Open
RonTuretzky wants to merge 2 commits into
Conversation
… duplicate detection Remove isQueuedForAdditionMapping and isQueuedForRemovalMapping from storage. Instead, require queue entries to be submitted in ascending address order — duplicate and ordering checks become a single comparison against the last element. This eliminates the O(n) loop in clearAdditionQueue/clearRemovalQueue (now just `delete array`) and removes two storage mappings entirely. View functions (isQueuedForAddition/isQueuedForRemoval) use binary search on the sorted array. Adds test coverage for re-queue after removal, re-queue after clear, duplicate/out-of-order reverts, and cross-queue independence.
Merge remote branch and resolve conflicts: - Keep MAX_QUEUE_SIZE (100) from remote as additional safety bound - Keep sorted-array invariant for duplicate detection (no mappings) - Update RecipientRegistry tests to expect QueueNotSorted instead of RecipientAlreadyQueued for duplicate queue entries
RonTuretzky
added a commit
that referenced
this pull request
Apr 15, 2026
Replace O(1) mapping-based duplicate detection with sorted-array invariant + binary search for O(log n) lookup. Require ascending address order for queue submissions. Simplify clear operations back to simple delete. Add QueueNotSorted error. Add 6 new tests for sorted order enforcement and re-queue scenarios.
RonTuretzky
added a commit
that referenced
this pull request
Apr 16, 2026
Replace O(1) mapping-based duplicate detection with sorted-array invariant + binary search for O(log n) lookup. Require ascending address order for queue submissions. Simplify clear operations back to simple delete. Add QueueNotSorted error. Add 6 new tests for sorted order enforcement and re-queue scenarios.
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
Addresses the review feedback on #90:
isQueuedForAdditionMappingandisQueuedForRemovalMappingfrom storage entirely. Instead, queues enforce ascending address order — duplicate detection is a single<=comparison against the last element, O(1).clearAdditionQueue/clearRemovalQueueare O(1) again — justdelete array, no loop needed to clear mapping entries. This resolves the gas-unbounded concern.isQueuedForAddition/isQueuedForRemovalview functions use binary search on the sorted array.QueueNotSortederror to the interface for when callers submit addresses out of order.Tradeoff: callers must submit addresses in ascending order. For admin/governance-gated calls this is trivially enforced off-chain.
Test plan
AdminRecipientRegistryTesttests pass (6 new)VotingRecipientRegistryTesttests passRecipientRegistryTesttests pass