Skip to content

fixAMMClawbackRounding: adjust last holder's LPToken balance#5513

Merged
bthomee merged 10 commits intoXRPLF:developfrom
yinyiqian1:fix_ammclawback
Jul 11, 2025
Merged

fixAMMClawbackRounding: adjust last holder's LPToken balance#5513
bthomee merged 10 commits intoXRPLF:developfrom
yinyiqian1:fix_ammclawback

Conversation

@yinyiqian1
Copy link
Copy Markdown
Collaborator

@yinyiqian1 yinyiqian1 commented Jun 25, 2025

Overview of fixAMMClawbackRounding: Due to rounding, the LPTokenBalance of the last LP might not match the LP's trustline balance, this was fixed for AMMWithdraw in fixAMMv1_1 by adjusting the LPTokenBalance to be the same as trustline balance.
Since AMMClawback is also performing a withdrawal, we need to adjust LPTokenBalance as well in AMMClawback.

This PR includes:

  1. refactored verifyAndAdjustLPTokenBalance function to AMMUtils. AMMWithdraw and AMMClawback both call this function to adjust LPTokenBalance.
  2. Added unit test testLastHolderLPTokenBalance to test the scenario.
  3. Modify the existing unit tests for fixAMMClawbackRounding. Added some minor changes, for example, variable aliceXrpBalance is updated after each transaction to make checking xrp balance easier.

High Level Overview of Change

Context of Change

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Refactor (non-breaking change that only restructures code)
  • Performance (increase or change in throughput and/or latency)
  • Tests (you added tests for code that already exists, or your new feature included in this PR)
  • Documentation update
  • Chore (no impact to binary, e.g. .gitignore, formatting, dropping support for older tooling)
  • Release

API Impact

  • Public API: New feature (new methods and/or new fields)
  • Public API: Breaking change (in general, breaking changes should only impact the next api_version)
  • libxrpl change (any change that may affect libxrpl or dependents of libxrpl)
  • Peer protocol change (must be backward compatible or bump the peer protocol version)

@yinyiqian1 yinyiqian1 force-pushed the fix_ammclawback branch 2 times, most recently from d83e7c9 to 8058476 Compare June 26, 2025 16:01
@yinyiqian1 yinyiqian1 changed the title fix last holder's LPToken balance for AMMClawback fixAMMClawback: adjust last holder's LPToken balance Jun 26, 2025
@yinyiqian1 yinyiqian1 marked this pull request as ready for review June 26, 2025 16:15
@yinyiqian1 yinyiqian1 requested review from a team, gregtatcam and shawnxie999 June 26, 2025 16:15
@codecov
Copy link
Copy Markdown

codecov bot commented Jun 26, 2025

Codecov Report

Attention: Patch coverage is 93.33333% with 2 lines in your changes missing coverage. Please review.

Project coverage is 79.0%. Comparing base (258ba71) to head (51aa456).
Report is 1 commits behind head on develop.

Files with missing lines Patch % Lines
src/xrpld/app/misc/detail/AMMUtils.cpp 83.3% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##           develop   #5513     +/-   ##
=========================================
- Coverage     79.1%   79.0%   -0.0%     
=========================================
  Files          816     816             
  Lines        71632   71652     +20     
  Branches      8237    8263     +26     
=========================================
- Hits         56648   56639      -9     
- Misses       14984   15013     +29     
Files with missing lines Coverage Δ
src/xrpld/app/tx/detail/AMMClawback.cpp 100.0% <100.0%> (ø)
src/xrpld/app/tx/detail/AMMWithdraw.cpp 95.5% <100.0%> (+0.2%) ⬆️
src/xrpld/app/misc/detail/AMMUtils.cpp 96.5% <83.3%> (-0.8%) ⬇️

... and 7 files with indirect coverage changes

Impacted file tree graph

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Collaborator

@gregtatcam gregtatcam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AMMClawback logs a bunch of errors like

ERR:OpenLedger AMM 31 invariant failed: 8A5A159FDA51F5E9841D2C80FD488DD47014FFE4F5948235D7B5AE7B957D248D true 565.685424949238/USD/r9QxhA9RghPZBbUchA9HkrmLKaWvkLXU29 70710678/XRP 199999.9998321968 200000 0.0000000008390160007039478

This is normal but it makes parsing unit-tests output difficult. These errors can be inhibited like this

Env env(*this, features, std::make_unique<CaptureLogs>(&logs));

You can search CaptureLogs for examples.

@yinyiqian1 yinyiqian1 changed the title fixAMMClawback: adjust last holder's LPToken balance fixAMMClawbackRounding: adjust last holder's LPToken balance Jul 3, 2025
Copy link
Copy Markdown
Collaborator

@shawnxie999 shawnxie999 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Copy Markdown
Collaborator

@gregtatcam gregtatcam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@kennyzlei kennyzlei added the Ready to merge *PR author* thinks it's ready to merge. Has passed code review. Perf sign-off may still be required. label Jul 11, 2025
@bthomee bthomee enabled auto-merge (squash) July 11, 2025 19:30
@bthomee bthomee merged commit 8aa94ea into XRPLF:develop Jul 11, 2025
2 checks passed
ximinez added a commit that referenced this pull request Jul 11, 2025
* XRPLF/develop:
  fixAMMClawbackRounding: adjust last holder's LPToken balance (#5513)
  chore: Add gcc-12 workaround (#5554)
  Add MPT related txns into issuer's account history  (#5530)
  chore: Remove unused headers (#5526)
ximinez added a commit that referenced this pull request Jul 21, 2025
…refactoring-1

* upstream/develop: (56 commits)
  Remove `include(default)` from libxrpl profile (#5587)
  refactor: Change boost::shared_mutex to std::shared_mutex (#5576)
  Fix macos runner (#5585)
  Remove the type filter from "ledger" RPC command (#4934)
  refactor: Update date, libarchive, nudb, openssl, sqlite3, xxhash packages (#5567)
  test: Run unit tests regardless of 'Supported' amendment status (#5537)
  Retire Flow Cross amendment (#5562)
  chore: Update CI to use Conan 2 (#5556)
  fixAMMClawbackRounding: adjust last holder's LPToken balance (#5513)
  chore: Add gcc-12 workaround (#5554)
  Add MPT related txns into issuer's account history  (#5530)
  chore: Remove unused headers (#5526)
  fix: add allowTrustLineLocking flag for account_info (#5525)
  Downgrade required CMake version for Antithesis SDK (#5548)
  fix: Link with boost libraries explicitly (#5546)
  chore: Fix compilation error with clang-20 and cleanup (#5543)
  test: Remove circular jtx.h dependencies (#5544)
  Decouple CredentialHelpers from xrpld/app/tx (#5487)
  fix: crash when trace-logging in tests (#5529)
  test: switch some unit tests to doctest (#5383)
  ...
ximinez added a commit that referenced this pull request Jul 22, 2025
…actoring-2

* ximinez/lending-refactoring-1: (57 commits)
  Fix formatting
  Remove `include(default)` from libxrpl profile (#5587)
  refactor: Change boost::shared_mutex to std::shared_mutex (#5576)
  Fix macos runner (#5585)
  Remove the type filter from "ledger" RPC command (#4934)
  refactor: Update date, libarchive, nudb, openssl, sqlite3, xxhash packages (#5567)
  test: Run unit tests regardless of 'Supported' amendment status (#5537)
  Retire Flow Cross amendment (#5562)
  chore: Update CI to use Conan 2 (#5556)
  fixAMMClawbackRounding: adjust last holder's LPToken balance (#5513)
  chore: Add gcc-12 workaround (#5554)
  Add MPT related txns into issuer's account history  (#5530)
  chore: Remove unused headers (#5526)
  fix: add allowTrustLineLocking flag for account_info (#5525)
  Downgrade required CMake version for Antithesis SDK (#5548)
  fix: Link with boost libraries explicitly (#5546)
  chore: Fix compilation error with clang-20 and cleanup (#5543)
  test: Remove circular jtx.h dependencies (#5544)
  Decouple CredentialHelpers from xrpld/app/tx (#5487)
  fix: crash when trace-logging in tests (#5529)
  ...
ximinez added a commit that referenced this pull request Jul 22, 2025
…actoring-3

* ximinez/lending-refactoring-2: (57 commits)
  Fix formatting
  Remove `include(default)` from libxrpl profile (#5587)
  refactor: Change boost::shared_mutex to std::shared_mutex (#5576)
  Fix macos runner (#5585)
  Remove the type filter from "ledger" RPC command (#4934)
  refactor: Update date, libarchive, nudb, openssl, sqlite3, xxhash packages (#5567)
  test: Run unit tests regardless of 'Supported' amendment status (#5537)
  Retire Flow Cross amendment (#5562)
  chore: Update CI to use Conan 2 (#5556)
  fixAMMClawbackRounding: adjust last holder's LPToken balance (#5513)
  chore: Add gcc-12 workaround (#5554)
  Add MPT related txns into issuer's account history  (#5530)
  chore: Remove unused headers (#5526)
  fix: add allowTrustLineLocking flag for account_info (#5525)
  Downgrade required CMake version for Antithesis SDK (#5548)
  fix: Link with boost libraries explicitly (#5546)
  chore: Fix compilation error with clang-20 and cleanup (#5543)
  test: Remove circular jtx.h dependencies (#5544)
  Decouple CredentialHelpers from xrpld/app/tx (#5487)
  fix: crash when trace-logging in tests (#5529)
  ...
ximinez added a commit that referenced this pull request Jul 22, 2025
…actoring-4

* ximinez/lending-refactoring-3: (61 commits)
  fixup! Rename Transactor preflight functions
  Rename Transactor preflight functions
  fixup! Make preflight1 and preflight2 private static Transactor functions
  Make preflight1 and preflight2 private static Transactor functions
  Fix formatting
  Remove `include(default)` from libxrpl profile (#5587)
  refactor: Change boost::shared_mutex to std::shared_mutex (#5576)
  Fix macos runner (#5585)
  Remove the type filter from "ledger" RPC command (#4934)
  refactor: Update date, libarchive, nudb, openssl, sqlite3, xxhash packages (#5567)
  test: Run unit tests regardless of 'Supported' amendment status (#5537)
  Retire Flow Cross amendment (#5562)
  chore: Update CI to use Conan 2 (#5556)
  fixAMMClawbackRounding: adjust last holder's LPToken balance (#5513)
  chore: Add gcc-12 workaround (#5554)
  Add MPT related txns into issuer's account history  (#5530)
  chore: Remove unused headers (#5526)
  fix: add allowTrustLineLocking flag for account_info (#5525)
  Downgrade required CMake version for Antithesis SDK (#5548)
  fix: Link with boost libraries explicitly (#5546)
  ...
ximinez added a commit that referenced this pull request Jul 22, 2025
…actoring-4

* ximinez/lending-refactoring-3: (61 commits)
  fixup! Rename Transactor preflight functions
  Rename Transactor preflight functions
  fixup! Make preflight1 and preflight2 private static Transactor functions
  Make preflight1 and preflight2 private static Transactor functions
  Fix formatting
  Remove `include(default)` from libxrpl profile (#5587)
  refactor: Change boost::shared_mutex to std::shared_mutex (#5576)
  Fix macos runner (#5585)
  Remove the type filter from "ledger" RPC command (#4934)
  refactor: Update date, libarchive, nudb, openssl, sqlite3, xxhash packages (#5567)
  test: Run unit tests regardless of 'Supported' amendment status (#5537)
  Retire Flow Cross amendment (#5562)
  chore: Update CI to use Conan 2 (#5556)
  fixAMMClawbackRounding: adjust last holder's LPToken balance (#5513)
  chore: Add gcc-12 workaround (#5554)
  Add MPT related txns into issuer's account history  (#5530)
  chore: Remove unused headers (#5526)
  fix: add allowTrustLineLocking flag for account_info (#5525)
  Downgrade required CMake version for Antithesis SDK (#5548)
  fix: Link with boost libraries explicitly (#5546)
  ...

Co-authored-by: Bronek Kozicki <brok@incorrekt.com>
mvadari added a commit that referenced this pull request Jul 23, 2025
Co-authored-by: Jingchen <a1q123456@users.noreply.github.com>
Co-authored-by: Bronek Kozicki <brok@incorrekt.com>
Co-authored-by: Ayaz Salikhov <mathbunnyru@users.noreply.github.com>
Co-authored-by: Denis Angell <dangell@transia.co>
Co-authored-by: Vlad <129996061+vvysokikh1@users.noreply.github.com>
Co-authored-by: Shawn Xie <35279399+shawnxie999@users.noreply.github.com>
Co-authored-by: yinyiqian1 <yqian@ripple.com>
Co-authored-by: Michael Legleux <legleux@users.noreply.github.com>
Co-authored-by: Bart <bthomee@users.noreply.github.com>
Co-authored-by: Chenna Keshava B S <21219765+ckeshava@users.noreply.github.com>
Co-authored-by: Vito Tumas <5780819+Tapanito@users.noreply.github.com>
Co-authored-by: Luc des Trois Maisons <3maisons@gmail.com>
Co-authored-by: Valentin Balaschenko <13349202+vlntb@users.noreply.github.com>
fix: crash when trace-logging in tests (#5529)
Fix compilation error with clang-20 and cleanup (#5543)
fix: Link with boost libraries explicitly (#5546)
fix: add allowTrustLineLocking flag for account_info (#5525)
fixAMMClawbackRounding: adjust last holder's LPToken balance (#5513)
Fix macos runner (#5585)
Fix clang-format CI job (#5598)
resolved actions/runner#2058.
@yinyiqian1 yinyiqian1 deleted the fix_ammclawback branch July 25, 2025 14:36
@legleux legleux mentioned this pull request Aug 27, 2025
@Bronek
Copy link
Copy Markdown
Collaborator

Bronek commented Sep 1, 2025

@yinyiqian1 would you like to create a new PR to switch Supported::no to yes for this amendment, before the 3.0.0 release ?

@yinyiqian1
Copy link
Copy Markdown
Collaborator Author

@yinyiqian1 would you like to create a new PR to switch Supported::no to yes for this amendment, before the 3.0.0 release ?

Sure. Just created: #5750

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ready to merge *PR author* thinks it's ready to merge. Has passed code review. Perf sign-off may still be required.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants