-
Notifications
You must be signed in to change notification settings - Fork 116
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
Improve QuoteToBaseQuantums
#1554
Conversation
WalkthroughThe Changes
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.
Actionable comments posted: 0
Review Details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- protocol/lib/quantums_test.go (1 hunks)
Additional Context Used
Path-based Instructions (1)
protocol/lib/quantums_test.go (1)
Pattern
**/**
: Do not include a walkthrough. For all comments on line changes that are longer than 15 lines, add a prefix to the comment of what lines you are commenting on (for example: "The changes from lines 100 to 200...". Add your comment to be on the last 15 lines of the chunk rather than adding your comment to the entire chunk.
Additional comments not posted (1)
protocol/lib/quantums_test.go (1)
255-283
: The new benchmark functionBenchmarkQuoteToBaseQuantums
is well-implemented and covers a variety of scenarios to ensure robustness. Good use ofrequire.Equal
to validate the results.
protocol/lib/quantums.go
Outdated
@@ -63,7 +63,7 @@ func BaseToQuoteQuantums( | |||
// quoteQuantums / priceValue / | |||
// 10^(priceExponent + baseCurrencyAtomicResolution - quoteCurrencyAtomicResolution) | |||
// | |||
// The result is rounded down. | |||
// The result is rounded down. It is okay to do the divisions separately, as the result is the same. |
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.
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.
Actionable comments posted: 0
Review Details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- protocol/lib/quantums.go (2 hunks)
Additional Context Used
Path-based Instructions (1)
protocol/lib/quantums.go (1)
Pattern
**/**
: Do not include a walkthrough. For all comments on line changes that are longer than 15 lines, add a prefix to the comment of what lines you are commenting on (for example: "The changes from lines 100 to 200...". Add your comment to be on the last 15 lines of the chunk rather than adding your comment to the entire chunk.
Additional comments not posted (3)
protocol/lib/quantums.go (3)
Line range hint
66-94
: Review ofQuoteToBaseQuantums
function changes.The changes in the function
QuoteToBaseQuantums
align with the PR's objective to optimize performance by avoidingbig.Rat
. The logic for handling positive and negative exponents (lines 81-85) and the separate division bypriceValue
(line 88) are correctly implemented. Ensure that the new logic is covered by the new benchmark and existing unit tests to prevent regressions.
Line range hint
94-126
: Review ofmultiplyByPrice
function.The function
multiplyByPrice
appears to be correctly implemented with proper handling of big rational operations and exponent adjustments. It is crucial to ensure that changes inQuoteToBaseQuantums
do not affect the logic inmultiplyByPrice
, especially since it is used by other functions likeFundingRateToIndex
.
Line range hint
1-64
: Ensure consistency in handling exponents across functions.The function
BaseToQuoteQuantums
uses similar exponent handling logic. Verify that the changes inQuoteToBaseQuantums
do not introduce inconsistencies in how exponents are managed across these functions. Consider aligning the handling of exponents and big integer operations in both functions to maintain uniformity and prevent logical errors.Verification successful
The search results indicate that both
BaseToQuoteQuantums
andQuoteToBaseQuantums
handle exponents in a similar manner. Specifically, both functions calculate the exponent aspriceExponent + baseCurrencyAtomicResolution - QuoteCurrencyAtomicResolution
and use similar logic for handling positive and negative exponents.
BaseToQuoteQuantums
:
- Calculates the exponent.
- Checks if the exponent is zero.
- Uses
bigPow10Helper
for exponentiation.- Multiplies or divides based on the sign of the exponent.
QuoteToBaseQuantums
:
- Calculates the exponent.
- Uses
BigPow10
for exponentiation.- Divides based on the sign of the exponent.
Given the consistency in handling exponents and big integer operations, there are no discrepancies between the two functions.
Scripts Executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify consistency in exponent handling between `BaseToQuoteQuantums` and `QuoteToBaseQuantums`. # Test: Search for exponent handling logic in both functions. Expect: Similar logic and handling. rg --type go $'exponent' protocol/lib/quantums.goLength of output: 693
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.
Actionable comments posted: 0
Review Details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- protocol/lib/quantums.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
- protocol/lib/quantums.go
Changelist
big.Rat
big.Rat
anywhereTest Plan
Summary by CodeRabbit
Performance Improvements
QuoteToBaseQuantums
function for better efficiency.New Features
QuoteToBaseQuantums
to ensure performance under various scenarios.