Skip to content

Conversation

@ximinez
Copy link
Collaborator

@ximinez ximinez commented Nov 12, 2025

Supersedes #6000.

  • Update the conversion points between Number and {XRP,MPT,IOU,ST}Amount & STNumber.

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)

@ximinez ximinez force-pushed the ximinez/lending-number-simple branch from 5cd623f to 4abb6d9 Compare November 13, 2025 05:52
@ximinez ximinez added the DraftRunCI Normally CI does not run on draft PRs. This opts in. label Nov 13, 2025
- Field will be absent in RPC results instead of returning 0.
…number-simple

* upstream/develop:
  chore: Clean up incorrect comments (6031)
  refactor: Retire MultiSignReserve and ExpandedSignerList amendments (5981)
@ximinez ximinez force-pushed the ximinez/lending-number-simple branch from b1079c5 to 9310991 Compare November 14, 2025 23:51
- Nothing really needed to be changed in the tests, but I added a couple
  of test cases for the min and max int64.
@ximinez ximinez force-pushed the ximinez/lending-number-simple branch from b17225c to c9ad49f Compare November 15, 2025 00:41
- Added test cases min int64.
- Updated numberFromJson range checking to use the larger range
  available from Number.
- Default Number outside of transaction processing to be "large" so RPC
  will work.
@ximinez ximinez mentioned this pull request Nov 16, 2025
13 tasks
@ximinez ximinez force-pushed the ximinez/lending-number-simple branch from 470c9c3 to 248d267 Compare November 16, 2025 18:10
{
// LCOV_EXCL_START
[[maybe_unused]]
auto const available = *assetsAvailableProxy;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why are available and total needed? They are not used.

sleBroker->at(sfCoverAvailable) -= clawAmount;
view().update(sleBroker);

associateAsset(*sleBroker, vaultAsset);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I keep on thinking if there is a way to make this association table driven. There is already a new field property defined sMD_NeedsAsset. What if instead adding this property in sfields, it's added in ledger_entries. Then we just need a way to point it to the associated asset, which requires accessing up to two linked objects right now. What if we add an integral flag to each related ledger entry (Vault, LoanBroker, Loan) to indicate if an asset is integral? Then in STObject::applyTemplate(), which iterates over all fields , for any STNumber field with sMD_NeedsAsset, we can set the integral flag. Does it make sense to explore this approach?

@ximinez ximinez force-pushed the ximinez/lending-number-simple branch from 451b474 to 565e62f Compare December 19, 2025 00:40
…nto ximinez/lending-number-simple

* XRPLF/ximinez/lending-XLS-66-ongoing:
  Fix Overpayment ValueChange calculation in Lending Protocol (6114)
  Ensure vault asset cap is not exceeded (6124)
  Disallow pseudo accounts to be Destination for LoanBrokerCoverWithdraw (6106)
  Check permissions in LoanSet and LoanPay (6108)
  Fix some minor bugs in Lending Protocol (6101)
  Fix LoanBrokerSet debtMaximum limits (6116)
- Prompted by review feedback from @gregtatcam.
- Should be pretty thorough.
- Tweaked how the MantissaRange class is instantiated, and added
  a couple more static_asserts.
@ximinez ximinez force-pushed the ximinez/lending-number-simple branch from 8c64508 to 16ab78d Compare January 6, 2026 01:17
Copy link
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.

Looks good to me. Thanks for adding extensive comments to the Number and MantissaRange classes.

Please add some documentation to STTakesAsset.h explaining why it's needed and how to use it. I'll approve once those are in!

* Make `maxRep` public.
* Document why template normalize takes min/max params.
* Add a check to normalizeToRange to ensure there are no signed/unsigned
  conversion issues.
* static_assert that maxRep is >= maxMPTokenAmount and INITIAL_XRP at
  their definition points. If something ever changes so that it's not,
  we'll know immediately.
@ximinez
Copy link
Collaborator Author

ximinez commented Jan 7, 2026

Want to make sure I understood this correctly: with largeRange, we can support full precision up to 2^63 - 1, so integer types (MPT or XRP) don’t lose precision even for large values. We’re still bounded by the signed int64 limit, but this works for existing integers since none of them exceed int64.

That is correct.

However, if we ever want to go beyond the 63-bit range (e.g., increasing MPT’s MaximumAmount to max(uint64) in the future), this implementation is not sufficient.

That is correct, however my current understanding is that there is no need or plan to extend the current limit.

Such a change would require an amendment, so a second expansion of Number would need to be included in that amendment work.

The updated class documentation now explicitly mentions that the limits for Number were chosen partially because of maxMPTokenAmount.

I've added a couple of static_asserts to ensure this invariant remains true in c88dd55

- Remove redundant "else" because of early return.
- Add a concept "Integral64" to use in the template parameter for
  normalizeToRange.
- Add documentation to STTakesAsset, associateAsset, and add explanation
  for how `STNumber` uses it.
- Assert that `numberToJson` is always outside of a Transaction context.
- Remove copy of `InitialFibSeqPct` and the assert in
  `Number::operator*=` that prompted me to add it.
- Add amendment gating to `STAmount::operator=`
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.

5 participants