Sponsored Content
Skip to content

fix: Include management-fee delta in doOverpayment assertion - #7039

Merged
bthomee merged 23 commits into
developfrom
tapanito/lending-overpayment
May 26, 2026
Merged

fix: Include management-fee delta in doOverpayment assertion#7039
bthomee merged 23 commits into
developfrom
tapanito/lending-overpayment

Conversation

@Tapanito

@Tapanito Tapanito commented Apr 28, 2026

Copy link
Copy Markdown
Contributor

Two related issues on the loan overpayment path triggered assertion failures.

  1. computeOverpaymentComponents requires its input amount to be representable at the loan's scale (isRounded(asset, overpayment, loanScale)). The residual passed in by loanMakePayment was the raw amount - totalPaid (capped at totalValueOutstanding), which could carry more precision than loanScale allows when the borrower pays an amount with extra fractional digits. Round the residual down to loanScale before calling computeOverpaymentComponents.

  2. The "interest paid agrees" assertion in doOverpayment was missing the management-fee component released during re-amortization. When a borrower overpays and the loan is re-amortized, the management fee outstanding decreases, but the original assertion formula did not account for this delta. Add mfeeReleased (oldMfee - newMfee) to the assertion, and introduce named intermediate variables with a comment explaining the loan-state identity behind the derivation.

Add a regression test (testBugOverpayUnroundedAmount) that exercises the overpayment path with a non-zero management fee rate and an unrounded payment amount.

High Level Overview of Change

Context of Change

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)

@xrplf-ai-reviewer xrplf-ai-reviewer Bot 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.

No issues.

Review by Claude Opus 4.6 · Prompt: V15

@codecov

codecov Bot commented Apr 28, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.73684% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 82.4%. Comparing base (a911f90) to head (d52e983).

Files with missing lines Patch % Lines
src/libxrpl/ledger/helpers/LendingHelpers.cpp 94.7% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##           develop   #7039     +/-   ##
=========================================
- Coverage     82.4%   82.4%   -0.0%     
=========================================
  Files         1011    1011             
  Lines        76330   76338      +8     
  Branches      7318    7308     -10     
=========================================
  Hits         62874   62874             
- Misses       13456   13464      +8     
Files with missing lines Coverage Δ
src/libxrpl/ledger/helpers/LendingHelpers.cpp 90.6% <94.7%> (+0.1%) ⬆️

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

@Tapanito
Tapanito force-pushed the tapanito/lending-overpayment branch from f68fdab to 04c9f27 Compare April 28, 2026 12:14

@xrplf-ai-reviewer xrplf-ai-reviewer Bot 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.

Went through the changes

Missing definition for testBugOverpayInterestPaidAgrees() will cause a compilation error — see inline.


Review by ReviewBot 🤖

Review by Claude Opus 4.6 · Prompt: V15

Comment thread src/test/app/Loan_test.cpp Outdated
@Tapanito
Tapanito force-pushed the tapanito/lending-overpayment branch from 04c9f27 to 45b4e5b Compare April 28, 2026 12:22

@xrplf-ai-reviewer xrplf-ai-reviewer Bot 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.

Compile error flagged inline — testBugOverpayInterestPaidAgrees() is called in run() but has no definition in this PR.

Review by Claude Opus 4.6 · Prompt: V15

Comment thread src/test/app/Loan_test.cpp Outdated
@Tapanito
Tapanito force-pushed the tapanito/lending-overpayment branch from 45b4e5b to d61ffa6 Compare April 28, 2026 12:28

@xrplf-ai-reviewer xrplf-ai-reviewer Bot 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.

New regression test is never called — wrong function name in run(). See inline.

Review by Claude Opus 4.6 · Prompt: V15

Comment thread src/test/app/Loan_test.cpp Outdated
Two related issues on the loan overpayment path triggered spurious
assertion failures.

1. computeOverpaymentComponents requires its input amount to be
   representable at the loan's scale (`isRounded(asset, overpayment,
   loanScale)`). The residual passed in by loanMakePayment was the
   raw `amount - totalPaid` (capped at totalValueOutstanding), which
   could carry more precision than loanScale allows when the borrower
   pays an amount with extra fractional digits. Round the residual
   down to loanScale before calling computeOverpaymentComponents.

2. The "interest paid agrees" assertion in doOverpayment was missing
   the management-fee component released during re-amortization. When
   a borrower overpays and the loan is re-amortized, the management
   fee outstanding decreases, but the original assertion formula did
   not account for this delta. Add `mfeeReleased` (oldMfee - newMfee)
   to the assertion, and introduce named intermediate variables with
   a comment explaining the loan-state identity behind the derivation.

Add a regression test (testBugOverpayUnroundedAmount) that exercises
the overpayment path with a non-zero management fee rate and an
unrounded payment amount.
@Tapanito
Tapanito force-pushed the tapanito/lending-overpayment branch from d61ffa6 to 00af7ba Compare April 28, 2026 12:36

@xrplf-ai-reviewer xrplf-ai-reviewer Bot 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.

No issues.

Review by Claude Opus 4.6 · Prompt: V15

@kennyzlei
kennyzlei requested review from a1q123456 and ximinez April 28, 2026 22:51
Wrap the roundToAsset call on the overpayment residual in
loanMakePayment with a view.rules().enabled(fixCleanup3_2_0) check so
pre-amendment behavior is preserved. Update the testBugOverpayUnrounded
Amount comment to note that the pre-amendment path can't be exercised
as a regression test because the assertion fires in Debug builds and
aborts the test process.

@xrplf-ai-reviewer xrplf-ai-reviewer Bot 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.

No issues.

Review by Claude Opus 4.6 · Prompt: V15

@bthomee
bthomee requested review from Copilot and godexsoft and removed request for ximinez April 29, 2026 19:01

Copilot AI 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.

Pull request overview

Fixes assertion failures in the loan overpayment path by ensuring overpayment residuals respect loanScale precision and by correcting the doOverpayment value/interest identity to include management-fee release during re-amortization. Adds a regression test that reproduces the unrounded residual scenario with a non-zero management fee rate.

Changes:

  • Round overpayment residual down to loanScale (behind fixCleanup3_2_0) before calling computeOverpaymentComponents.
  • Update doOverpayment’s “interest paid agrees” assertion to include managementFeeOutstanding delta released during re-amortization, with clearer intermediate terms.
  • Add a regression test covering overpayment with an unrounded payment amount + non-zero management fee rate.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/libxrpl/ledger/helpers/LendingHelpers.cpp Fixes overpayment residual precision handling and corrects the overpayment value-change assertion to account for management-fee delta.
src/test/app/Loan_test.cpp Adds a regression test that exercises the overpayment path with extra fractional precision and management fees enabled.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Tapanito Tapanito added this to the 3.2.0 milestone Apr 30, 2026
@github-actions

github-actions Bot commented May 3, 2026

Copy link
Copy Markdown

This PR has conflicts, please resolve them in order for the PR to be reviewed.

@godexsoft

Copy link
Copy Markdown
Contributor

We recently merged a refactor to develop that enables clang-tidy's readability-identifier-naming. Your branch now has heavy conflicts that are largely mechanical. Below is a workflow that aligns your branch's naming with develop before merging, which should minimize the merge conflicts.

One-time setup

If you don't already have clang-tidy working in your env, on macOS:

brew install llvm@21
# Follow brew's hint to put $(brew --prefix llvm@21)/bin on PATH so run-clang-tidy is found.

Workflow on your branch (before merging develop)

1. Grab the new .clang-tidy from develop without pulling anything else. Sync your fork on GitHub first, then:

git remote -v   # should show 'upstream' among others; if not:
# git remote set-url upstream git@github.com:XRPLF/rippled.git
git fetch upstream
git checkout upstream/develop -- .clang-tidy

2. Reconfigure conan/cmake so compile_commands.json is fresh.

3. Apply renames for the files modified in your PR:

git diff --name-only $(git merge-base HEAD upstream/develop) HEAD \
  | grep -E '\.(cpp|h|hpp|ipp)$' \
  | xargs run-clang-tidy -p build -fix -allow-no-checks
# or -p .build, or whatever your build dir is called

4. Build + test, then commit as a single dedicated commit:

cmake --build build -j8
git commit -am "refactor: Align identifier naming with develop"

5. Now merge develop:

git merge upstream/develop

Extra

Run clang-tidy once more after the merge to catch any stragglers introduced from develop's side:

run-clang-tidy -p build -fix -allow-no-checks src tests
# or -p .build, or whatever your build dir is called

@github-actions

github-actions Bot commented May 4, 2026

Copy link
Copy Markdown

All conflicts have been resolved. Assigned reviewers can now start or resume their review.

@xrplf-ai-reviewer xrplf-ai-reviewer Bot 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.

New regression test and three previously-active tests are commented out — see inline.

Review by Claude Opus 4.6 · Prompt: V15

Comment thread src/test/app/Loan_test.cpp Outdated

@xrplf-ai-reviewer xrplf-ai-reviewer Bot 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.

Went through the changes

The new regression test testBugOverpayUnroundedAmount is dead code — it's commented out in run() and never executed. See inline.


Review by ReviewBot 🤖

Review by Claude Opus 4.6 · Prompt: V15

Comment thread src/test/app/Loan_test.cpp Outdated
@Tapanito
Tapanito force-pushed the tapanito/lending-overpayment branch from d30bc90 to f94bda2 Compare May 22, 2026 10:38

@xrplf-ai-reviewer xrplf-ai-reviewer Bot 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.

No issues.

Review by Claude Opus 4.6 · Prompt: V15

Copilot AI 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.

Pull request overview

Copilot reviewed 2 out of 3 changed files in this pull request and generated 1 comment.

Comment thread src/test/app/Loan_test.cpp Outdated

@xrplf-ai-reviewer xrplf-ai-reviewer Bot 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.

No issues.

Review by Claude Opus 4.6 · Prompt: V15

Comment thread .gitignore Outdated

Copilot AI 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.

Pull request overview

Copilot reviewed 2 out of 3 changed files in this pull request and generated 1 comment.

Comment thread src/test/app/Loan_test.cpp Outdated

@xrplf-ai-reviewer xrplf-ai-reviewer Bot 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.

No issues.

Review by Claude Opus 4.6 · Prompt: V15

@xrplf-ai-reviewer xrplf-ai-reviewer Bot 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.

No issues.

Review by Claude Opus 4.6 · Prompt: V15

@a1q123456 a1q123456 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.

LGTM

@Tapanito Tapanito 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 May 26, 2026
Comment thread src/libxrpl/ledger/helpers/LendingHelpers.cpp Outdated

@xrplf-ai-reviewer xrplf-ai-reviewer Bot 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.

No issues.

Review by Claude Opus 4.6 · Prompt: V15

@bthomee
bthomee enabled auto-merge May 26, 2026 13:41
@bthomee
bthomee added this pull request to the merge queue May 26, 2026
Merged via the queue into develop with commit 22a21b1 May 26, 2026
3 checks passed
@bthomee
bthomee deleted the tapanito/lending-overpayment branch May 26, 2026 14:38
Kassaking7 pushed a commit to Kassaking7/rippled that referenced this pull request Jun 2, 2026
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.

5 participants