XRPLF / rippled

Decentralized cryptocurrency blockchain daemon implementing the XRP Ledger protocol in C++
https://xrpl.org
ISC License
4.48k stars 1.45k forks source link

AMM Unit test: Create AMM Pools with tiny pool balances #4981

Closed ckeshava closed 2 months ago

ckeshava commented 2 months ago

High Level Overview of Change

This PR introduces new unit tests to test small AMM Pool creation and tiny Payment transactions against AMMs. AMM pool sizes are in order of 1e-6 and payment transactions are in order of 1e-7. Please let me know if I should test smaller ranges.

The behavior of the code matches our understanding for both XRP/IOU and IOU/IOU AMM pools. Many thanks to @gregtatcam for helping with these tests.

Context of Change

Type of Change

API Impact

No impact on performance. No changes to Public APIs either.

ckeshava commented 2 months ago

@seelabs can you please review this PR? I'm not able to add reviewers through the Github UI

codecov-commenter commented 2 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 76.97%. Comparing base (c88166e) to head (1e2cb43).

:exclamation: Current head 1e2cb43 differs from pull request most recent head 8b6382b. Consider uploading reports for the commit 8b6382b to get more accurate results

Additional details and impacted files ```diff @@ Coverage Diff @@ ## develop #4981 +/- ## =========================================== - Coverage 76.97% 76.97% -0.01% =========================================== Files 1129 1129 Lines 131914 131940 +26 Branches 39629 39693 +64 =========================================== + Hits 101539 101556 +17 - Misses 24459 24497 +38 + Partials 5916 5887 -29 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

seelabs commented 2 months ago

I think I'd separate these tests out as a separate test case - I'm not sure they belong in "basic" tests. Maybe call it "extreme values test" or somesuch. I'd also tests every combination of the following amounts. The amounts should be used for both AMM pool balances and for transaction amounts (deposit/withdrawal/payments)

  1. max allowed IOU
  2. 10^-9 IOU
  3. min allowed IOU
  4. 1 drop
  5. 2 drops
  6. 1 XRP
  7. 10^7 XRP
  8. 1 IOU
  9. 10^7 IOU

I'd expect that you'd want to create these combinations programmatically.

ckeshava commented 2 months ago

@seelabs what would be the appropriate values for minimum and maximum allowed IOUs? STAmount represents numbers with a mantissa and an exponent. I believe these numbers can have 16 significant digits. So the max and min values would be 1e16 and 1e-16 ?

ckeshava commented 2 months ago

FYI: When using IOUs with AMMDeposit, Payment and AMMWithdraw transactions, it is not feasible to use less than 1e-3 values. The individual transactions have differing limits, but this is the common denominator. 1e-3 appears to be the minimum value of IOUs