fix: optimize queue lookup with mapping-based O(1) duplicate detection (#45)#118
Merged
Conversation
This was referenced Apr 15, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR optimizes recipient addition/removal queue duplicate detection by switching from linear scans to mapping-backed O(1) membership checks, and introduces a queue-size cap intended to keep queue-clearing gas bounded.
Changes:
- Add
isQueuedForAdditionMapping/isQueuedForRemovalMappingto enable O(1) duplicate detection andisQueuedFor*lookups. - Enforce
MAX_QUEUE_SIZE = 100for both addition and removal queues, reverting with a newMaxQueueSizeReachederror. - Expand registry tests around re-queuing behavior and tighten revert expectations for duplicate queueing.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
src/abstract/AbstractRecipientRegistry.sol |
Adds queue membership mappings, enforces max queue size, and updates clearing logic to reset mapping state. |
src/interfaces/IRecipientRegistry.sol |
Introduces MaxQueueSizeReached error for queue cap enforcement. |
test/RecipientRegistry.t.sol |
Adds re-queueing and queue-independence tests; updates duplicate-queue revert assertions to check RecipientAlreadyQueued. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Fix NatSpec grammar: 'reached' → 'has reached' - Add MAX_QUEUE_SIZE boundary tests for both addition and removal queues
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
MAX_QUEUE_SIZE = 100constant to bound gas consumption ofclearAdditionQueue/clearRemovalQueueMaxQueueSizeReachederror toIRecipientRegistryCloses #45
Supersedes #90 (addresses all review feedback from that PR)
Test plan
RecipientAlreadyQueuedMAX_QUEUE_SIZEenforced on both queuesStack: PR 1 of 10 (0.0.1)