-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
AMM Unit tests: rounding down of equal asset deposit LPToken calculation #4982
Conversation
include reference from XLS-30d. Validate the expected deposit sums against XLS-30d spec
src/test/app/AMM_test.cpp
Outdated
// testClawback(); | ||
// testAMMID(); | ||
// testSelection(); | ||
// testFixDefaultInnerObj(); |
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.
Why comment out all of the tests?
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.
my bad, fixed it
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## develop #4982 +/- ##
=======================================
Coverage 70.9% 70.9%
=======================================
Files 796 796
Lines 66727 66727
Branches 10981 10976 -5
=======================================
+ Hits 47333 47338 +5
+ Misses 19394 19389 -5 |
This looks good to me. But I was hoping it would hit these lines: https://app.codecov.io/gh/XRPLF/rippled/pull/4982/blob/src/ripple/app/misc/impl/AMMHelpers.cpp#L171. And I don't have a good explanation as to why it didn't. Nevertheless, this looks like a good addition to me. |
@HowardHinnant I have updated the numbers so that the execution hits the necessary lines. I expected |
BEAST_EXPECT(expectLedgerEntryRoot(env, carol, XRP(30'000) - | ||
depositXRP - txfee(env, 1))); | ||
}); | ||
|
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.
Maybe my brain isn't working today, but I'm not following how this tests rounding down. Where would the calculation differ if we rounded to nearest, say? Can you add some clarifying comments to help me follow this test?
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 values computed by AMMHelpers.cpp:adjustLPTokens
would be different, if we used the nearest rounding mode. I have tagged that line above ^
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.
I'm still not sure how the test is showing this difference. I think what I'm looking for is a comment in the test that explains how the test proves that the rounding is working as we intended. The test may be doing that, but I'm not sure how. I think I need a comment to explain how the test works.
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.
Fwiw, I checked the test coverage of AMMHelpers.cpp before and after this PR and this PR improves the coverage in this file, specifically in adjustAmountsByLPTokens
.
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 howard.
@seelabs I have added a test case and asserts on line 1155 to show the rounding down behavior
// digits, it is possible that lpTokensActual is rounded down. This is to | ||
// ensure that we don't create/burn more LPTokens (depending on | ||
// whether it's AMMDeposit or AMMWithdraw transaction) than what the trader | ||
// asked for. |
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.
@seelabs This is one of the points in the codebase where LPTokens are rounded down. Check the function above adjustLPTokens
.
Consequently, lpTokensActual
< lpTokens
by a very small margin.
BEAST_EXPECT(ammAlice.expectBalances( | ||
XRP(10'000) + depositXRP, | ||
USD(10'000) + depositUSD, | ||
IOUAmount{1, 7} + newLPTokens)); |
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.
I don't understand how lines 1156 and 1177 can be true at the same. I'm guessing it's due to the loss of precision in the last few digits.
newLPTokens
== deltaLPTokens
(numerically)
initLPTokens
+ newLPTokens
= finalLPTokens
, but finalLPToken - initLPToken < deltaLPTokens
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.
👍 nice job on this!
Hello, the commit message could be: |
…#4982) * Specifically, test using tfLPToken flag
High Level Overview of Change
This PR exercises a specific portion of the AMMHelpers.cpp file. It triggers a downward rounding of LPTokens in
adjustLPTokens
function in theAMMHelpers.cpp
file.Context of Change
Type of Change
.gitignore
, formatting, dropping support for older tooling)API Impact
libxrpl
change (any change that may affectlibxrpl
or dependents oflibxrpl
)No impact on performance. No change to APIs