Skip to content

test: Fix LoanBatch broker cover rates and schedule overflow - #7967

Open
Tapanito wants to merge 1 commit into
developfrom
tapanito/fix-loanbatch-cover-rate
Open

test: Fix LoanBatch broker cover rates and schedule overflow#7967
Tapanito wants to merge 1 commit into
developfrom
tapanito/fix-loanbatch-cover-rate

Conversation

@Tapanito

@Tapanito Tapanito commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

High Level Overview of Change

Fixes the manual LoanBatch test suite, which failed in every iteration (20 failures with the default 5 iterations). Both bugs have been present since the lending protocol merged, unnoticed because the suite is manual and not run in CI.

Context of Change

LoanBatch_test::testRandomLoan had two problems:

  1. Inconsistent broker cover rates. The broker parameters set CoverRateMinimum to zero while leaving CoverRateLiquidation at the 25% test default. LoanBrokerSet::preflight requires the two rates to be both zero or both non-zero, so broker creation failed with temINVALID and every subsequent step cascaded (tecNO_ENTRY on cover deposit, missing-object expectation failures). The fix sets CoverRateLiquidation to zero explicitly, matching LoanArbitrary_test.

  2. Payment schedule overflowing the protocol time horizon. The random distributions (payment total up to 10,000, interval up to 30 days) can produce a schedule whose final grace period overflows the 32-bit ripple-epoch timestamp, which LoanSet::preclaim correctly rejects with tecKILLED. The default seed hits this in iteration 5 (4,940 payments at ~21.7-day intervals, about 293 years). The fix clamps the payment total so the schedule stays within 2e9 seconds (~63 years), while still exercising thousand-payment schedules.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • Tests (you added tests for code that already exists, or your new feature included in this PR)

Test Plan

./xrpld -u LoanBatch: 5 iterations, 446,565 checks, 0 failures (previously 20 failures).

The LoanBatch manual suite failed in every iteration because
testRandomLoan set CoverRateMinimum to zero while leaving
CoverRateLiquidation at the 25% default, which LoanBrokerSet preflight
rejects with temINVALID (the rates must be both zero or both non-zero).

It also randomly generated payment schedules whose final grace period
overflows the 32-bit ripple-epoch time horizon, which LoanSet preclaim
rejects with tecKILLED. Clamp the payment total so the schedule fits.
@Tapanito Tapanito added the Trivial Simple change with minimal effect, or already tested. Only needs one approval. label Aug 6, 2026
@Tapanito
Tapanito requested a review from ximinez August 6, 2026 17:01

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

The MR correctly fixes the broker cover-rate mismatch and adds a clamp to keep the payment schedule within the 32-bit ripple-epoch horizon. The only concern is the new clamp's division by payInterval, which will crash with a division-by-zero (SIGFPE) if the interval distribution can ever produce 0.

@codecov

codecov Bot commented Aug 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@Tapanito
Tapanito requested review from gregtatcam and removed request for ximinez August 7, 2026 07:43
@Tapanito Tapanito added this to the 3.4.0 milestone Aug 7, 2026

@gregtatcam gregtatcam 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

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

Labels

Trivial Simple change with minimal effect, or already tested. Only needs one approval.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants