-
Couldn't load subscription status.
- Fork 12.3k
Add try DoubleEndedQueue functions
#6020
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: 293a992 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
WalkthroughThis pull request introduces non-reverting try-prefixed variants to the DoubleEndedQueue contract. Internal functions (tryPushBack, tryPopBack, tryPushFront, tryPopFront, tryFront, tryBack, tryAt) replace direct reverts with false or zero returns on failure. Public methods (pushBack, pushFront, popBack, popFront, front, back, at) now delegate to these try variants and panic with specific error codes when operations fail. The public API signatures remain unchanged. Complementary test coverage validates try function behavior in empty and non-empty queue states, including event emissions and boundary conditions. A changeset documents the minor version bump for the OpenZeppelin Solidity dependency. Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (3)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (9)
🔇 Additional comments (14)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @davidperk, thanks for the PR.
I personally like the idea so I'm approving, but we'll need another review from someone else in the team to merge.
A couple of comments:
- Maybe it makes sense to keep the original functions implemented as they currently are. The new versions depending on the
try*ones might be a couple gas units more expensive to push thesuccessandvalueinto the stack and then reusing it. Not a big deal imo - Technically, users can check whether the function they're using will revert beforehand by checking
_beginand_end. We don't recommend accessing these values directly so maybe checkingempty(),front()andback()would do the job. I still think this PR is better.
I gas-profiled some of the original function implementations vs. the PR versions via
I think it makes sense to keep the original function implementations at the expense of DRY, so I've just restored them in f9b63dc.
Yes, technically, users can manually check |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for taking the time to prepare the benchmarks.
LGTM
Adds the following
DoubleEndedQueuefunctions that return aboolflag instead of reverting:tryPushBacktryPopBacktryPushFronttryPopFronttryFronttryBacktryAtThese functions eliminate a redundant SLOAD for calling contracts that currently need to check a condition (e.g., whether the deque is full or empty, or whether the index is out of bounds) before invoking a function in order to not revert, all of which themselves check the same condition and revert if the condition fails.
For example, a calling contract currently needs to check
emptybefore invokingfrontin order to not revert if the deque is empty. Butfrontalready invokesemptyitself. Now, a calling contract can optimistically invoketryFrontwithout having to checkemptyfirst and gracefully handle the error if the deque is empty.npx changeset add)