Skip to content

fix: optimize queue lookup with mapping-based O(1) duplicate detection (#45)#118

Merged
RonTuretzky merged 5 commits into
mainfrom
RonTuretzky/90-queue-mapping-fix
May 5, 2026
Merged

fix: optimize queue lookup with mapping-based O(1) duplicate detection (#45)#118
RonTuretzky merged 5 commits into
mainfrom
RonTuretzky/90-queue-mapping-fix

Conversation

@RonTuretzky
Copy link
Copy Markdown
Contributor

Summary

  • Replace O(n) linear search with O(1) mapping-based duplicate detection for both addition and removal queues
  • Add MAX_QUEUE_SIZE = 100 constant to bound gas consumption of clearAdditionQueue/clearRemovalQueue
  • Add MaxQueueSizeReached error to IRecipientRegistry
  • Both queue mappings use EIP-7201 namespaced storage (inside existing struct)

Closes #45
Supersedes #90 (addresses all review feedback from that PR)

Test plan

  • Re-queue after removal works correctly
  • Re-queue after clearing addition queue works correctly
  • Double-queue reverts with RecipientAlreadyQueued
  • Addition and removal queues are independent
  • MAX_QUEUE_SIZE enforced on both queues
  • All 103 existing tests pass

Stack: PR 1 of 10 (0.0.1)

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 / isQueuedForRemovalMapping to enable O(1) duplicate detection and isQueuedFor* lookups.
  • Enforce MAX_QUEUE_SIZE = 100 for both addition and removal queues, reverting with a new MaxQueueSizeReached error.
  • 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.

Comment thread src/abstract/AbstractRecipientRegistry.sol
Comment thread src/abstract/AbstractRecipientRegistry.sol
Comment thread src/abstract/AbstractRecipientRegistry.sol
Comment thread src/interfaces/IRecipientRegistry.sol Outdated
- Fix NatSpec grammar: 'reached' → 'has reached'
- Add MAX_QUEUE_SIZE boundary tests for both addition and removal queues
@RonTuretzky RonTuretzky merged commit 77806a3 into main May 5, 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.

Optimize Recipient Queue Lookup in BaseRecipeIntRegistry for Large Queues (addition and removal)

3 participants