-
Notifications
You must be signed in to change notification settings - Fork 202
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
reduced CalcTWAP to only one snapshots range #1801
base: main
Are you sure you want to change the base?
Conversation
WalkthroughThe update in the Changes
Assessment against linked issues
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
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.
Review Status
Actionable comments generated: 1
Configuration used: CodeRabbit UI
Files selected for processing (1)
- x/perp/v2/keeper/twap.go (2 hunks)
Additional comments: 3
x/perp/v2/keeper/twap.go (3)
- 59-59: Introducing a
count
variable to track the number of snapshots processed is a good practice for clarity and can be useful for debugging or further logic enhancements. This addition aligns with the goal of simplifying the function's logic.- 62-62: Incrementing the
count
variable for each snapshot processed is straightforward and effective. However, ensure that this logic correctly accounts for all relevant snapshots, especially in edge cases where snapshots might be skipped due to identical timestamps.- 98-99: The updated circuit-breaker condition to handle cases with only a single snapshot or when
cumulativePeriodMs
equals zero is a logical improvement. It simplifies handling edge cases, ensuring that the function can gracefully handle scenarios with minimal data. However, verify that this change does not inadvertently affect the accuracy of TWAP calculations in edge cases.
break | ||
} | ||
} | ||
snapshots = iter.Values() |
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.
The direct assignment of values from the iterator to snapshots
simplifies the logic for collecting snapshot data. This change should improve readability and potentially performance by eliminating explicit iteration. However, ensure that the iter.Values()
method efficiently handles large datasets without significant memory overhead.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1801 +/- ##
==========================================
+ Coverage 73.07% 74.15% +1.07%
==========================================
Files 196 196
Lines 15564 12687 -2877
==========================================
- Hits 11374 9408 -1966
+ Misses 3526 2615 -911
Partials 664 664
|
Purpose / Abstract
Summary by CodeRabbit