Sponsored Content
Skip to content

Add rounding to Vault invariants - #6217

Merged
Tapanito merged 27 commits into
tapanito/lending-fix-amendmentfrom
tapanito/lending-vault-invariant
Mar 5, 2026
Merged

Add rounding to Vault invariants#6217
Tapanito merged 27 commits into
tapanito/lending-fix-amendmentfrom
tapanito/lending-vault-invariant

Conversation

@Tapanito

@Tapanito Tapanito commented Jan 14, 2026

Copy link
Copy Markdown
Contributor

This PR relaxes Vault Deposit, Withdraw and Clawback invariants for IOUs to allow minimal discrepancy between various balance changes.

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)

@Tapanito
Tapanito requested a review from ximinez January 14, 2026 19:59
@codecov

codecov Bot commented Jan 14, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.89051% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.8%. Comparing base (ed4330a) to head (d54a1f7).
⚠️ Report is 1 commits behind head on tapanito/lending-fix-amendment.

Files with missing lines Patch % Lines
src/libxrpl/tx/invariants/VaultInvariant.cpp 94.7% 7 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@                      Coverage Diff                       @@
##           tapanito/lending-fix-amendment   #6217   +/-   ##
==============================================================
  Coverage                            79.8%   79.8%           
==============================================================
  Files                                 858     858           
  Lines                               67768   67847   +79     
  Branches                             7570    7554   -16     
==============================================================
+ Hits                                54064   54152   +88     
+ Misses                              13704   13695    -9     
Files with missing lines Coverage Δ
include/xrpl/protocol/STAmount.h 95.7% <100.0%> (+0.1%) ⬆️
...clude/xrpl/tx/transactors/Lending/LendingHelpers.h 95.2% <100.0%> (ø)
...tx/transactors/Lending/LoanBrokerCoverWithdraw.cpp 96.3% <100.0%> (ø)
src/libxrpl/tx/invariants/VaultInvariant.cpp 97.4% <94.7%> (-0.8%) ⬇️

... and 10 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.

@Tapanito Tapanito changed the title Relax Vault Invariant to account for rounding errors Add rounding to VaultWithdraw invariants Jan 15, 2026
@Tapanito Tapanito changed the title Add rounding to VaultWithdraw invariants Add rounding to Vault invariants Jan 20, 2026
@Tapanito
Tapanito force-pushed the tapanito/lending-vault-invariant branch from a7e80dd to 6b5618e Compare January 20, 2026 12:40
@Tapanito
Tapanito force-pushed the tapanito/lending-vault-invariant branch from 6b5618e to 9235ec4 Compare January 20, 2026 16:06
ximinez added a commit that referenced this pull request Jan 21, 2026
- Requires a template for STAmount and Asset.
- Update tests and computeMinScale from #6217 to use scale.
- Convert a few other places to use "scale" correctly.

@ximinez ximinez left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I created #6246 to make the some of the changes I requested below. Pretty much everything except the changes to the actual ValidVault invariant checks.

Comment thread src/xrpld/app/tx/detail/InvariantCheck.cpp Outdated
Comment thread src/xrpld/app/tx/detail/InvariantCheck.cpp Outdated
Comment thread src/xrpld/app/tx/detail/InvariantCheck.cpp Outdated
Comment thread src/xrpld/app/tx/detail/InvariantCheck.cpp Outdated
Comment thread src/xrpld/app/tx/detail/InvariantCheck.cpp Outdated
Comment thread src/xrpld/app/tx/detail/InvariantCheck.cpp Outdated
Comment thread src/test/app/Invariants_test.cpp Outdated
Comment thread src/test/app/Invariants_test.cpp
@Tapanito
Tapanito force-pushed the tapanito/lending-vault-invariant branch from 6f9b206 to c6821ab Compare January 21, 2026 10:42
@Tapanito

Copy link
Copy Markdown
Contributor Author

@ximinez apologies for the forced push, I haven't seen your review!

@kennyzlei
kennyzlei requested a review from gregtatcam January 21, 2026 17:07
@Tapanito

Copy link
Copy Markdown
Contributor Author

@ximinez as we discussed, I rewrote the Invariant to check relative distance between values within some tolerance. For IOU the tolerance is 1 * 10^-13, for MPT/XRP the tolerance is zero.

The IOU tolerance is the smallest tolerance that would cause the unit test to pass. If the tolerance was -14, the unit-test would fail.

@Tapanito
Tapanito requested a review from ximinez January 21, 2026 18:03
Comment thread src/xrpld/app/tx/detail/InvariantCheck.cpp Outdated
@Tapanito
Tapanito changed the base branch from develop to tapanito/lending-fix-amendment February 10, 2026 12:34
@Tapanito
Tapanito requested a review from a1q123456 February 11, 2026 17:02
@Tapanito Tapanito removed the Blocked label Feb 11, 2026
@Tapanito
Tapanito merged commit 4067e50 into tapanito/lending-fix-amendment Mar 5, 2026
3 checks passed
@Tapanito
Tapanito deleted the tapanito/lending-vault-invariant branch March 5, 2026 09:38
Tapanito added a commit that referenced this pull request Mar 24, 2026
Co-authored-by: Ed Hennis <ed@ripple.com>
@ximinez
ximinez restored the tapanito/lending-vault-invariant branch April 8, 2026 20:52
@ximinez
ximinez deleted the tapanito/lending-vault-invariant branch April 8, 2026 20:53
@ximinez ximinez added this to the 3.1.3 milestone Apr 15, 2026
kuznetsss pushed a commit to kuznetsss/rippled that referenced this pull request Apr 21, 2026
Co-authored-by: Vito Tumas <5780819+Tapanito@users.noreply.github.com>
Co-authored-by: Ed Hennis <ed@ripple.com>
marek-foss-neti pushed a commit to marek-foss-neti/rippled that referenced this pull request May 5, 2026
Co-authored-by: Vito Tumas <5780819+Tapanito@users.noreply.github.com>
Co-authored-by: Ed Hennis <ed@ripple.com>
beartec-jpg pushed a commit to beartec-jpg/FalconLedger that referenced this pull request Jun 1, 2026
Co-authored-by: Vito Tumas <5780819+Tapanito@users.noreply.github.com>
Co-authored-by: Ed Hennis <ed@ripple.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants