Skip to content

Number scale helper function#6384

Merged
ximinez merged 11 commits into
tapanito/lending-vault-invariantfrom
ximinez/number-scale2
Feb 24, 2026
Merged

Number scale helper function#6384
ximinez merged 11 commits into
tapanito/lending-vault-invariantfrom
ximinez/number-scale2

Conversation

@ximinez

@ximinez ximinez commented Feb 18, 2026

Copy link
Copy Markdown
Collaborator

High Level Overview of Change

After looking again at #6246 changes, I realized there could be a simpler function call.

Questions:

  1. Is this worth merging?
  2. If it is worth merging, is numberScale a good name?
  3. Also if it's worth merging, would it be worth getting rid of Number::scale entirely and inlining it into numberScale?

Context of Change

Type of Change

  • Refactor (non-breaking change that only restructures code)

@ximinez ximinez changed the title attempt to fix rounding issues Number scale helper function Feb 18, 2026
@ximinez ximinez changed the base branch from tapanito/lending-fix-amendment to tapanito/lending-vault-invariant February 18, 2026 19:58
@ximinez ximinez added the DraftRunCI Normally CI does not run on draft PRs. This opts in. label Feb 18, 2026
@ximinez ximinez marked this pull request as ready for review February 18, 2026 19:59
@ximinez ximinez marked this pull request as draft February 18, 2026 19:59
@codecov

codecov Bot commented Feb 18, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 66.66667% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.8%. Comparing base (253c04b) to head (651d4ee).
⚠️ Report is 1 commits behind head on tapanito/lending-vault-invariant.

Files with missing lines Patch % Lines
src/libxrpl/tx/InvariantCheck.cpp 50.0% 6 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@                       Coverage Diff                        @@
##           tapanito/lending-vault-invariant   #6384   +/-   ##
================================================================
  Coverage                              79.8%   79.8%           
================================================================
  Files                                   846     846           
  Lines                                 67825   67825           
  Branches                               7556    7557    +1     
================================================================
  Hits                                  54130   54130           
  Misses                                13695   13695           
Files with missing lines Coverage Δ
include/xrpl/basics/Number.h 98.7% <ø> (-<0.1%) ⬇️
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/InvariantCheck.cpp 93.0% <50.0%> (ø)

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

@ximinez ximinez marked this pull request as ready for review February 19, 2026 19:55
@ximinez ximinez requested a review from Tapanito February 19, 2026 19:55
@ximinez ximinez added the Trivial Simple change with minimal effect, or already tested. Only needs one approval. label Feb 19, 2026
… into ximinez/number-scale2

* XRPLF/tapanito/lending-vault-invariant:
  adds missing includes
  refactor: Modularize app/tx (6228)
  refactor: Decouple app/tx from `Application` and `Config` (6227)
- Rename `numberScale` to `scale`.
- Remove the `AssetType` template parameter - just use class Asset.

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

Refactors “Number scale” computation by replacing the recently added Number::scale member template with a simpler free helper function, and updates vault/lending call sites to use it.

Changes:

  • Add scale(Number const&, Asset const&) helper in STAmount.h.
  • Remove Number::scale (and its supporting concept) from Number.h.
  • Update invariant checks and lending/vault-related code/tests to call the new helper (plus minor formatting-only changes).

Reviewed changes

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

Show a summary per file
File Description
src/test/app/Vault_test.cpp Formatting-only adjustment to lambda parameter layout.
src/test/app/Invariants_test.cpp Switches vault min-scale test helper to scale(number, asset).
src/libxrpl/tx/transactors/Lending/LoanBrokerCoverWithdraw.cpp Uses new scale(...) helper when rounding minimum cover.
src/libxrpl/tx/InvariantCheck.cpp Uses new scale(...) helper for vault delta scale computations.
include/xrpl/tx/transactors/Lending/LendingHelpers.h Uses new scale(...) helper to compute stored assets-total scale.
include/xrpl/protocol/STAmount.h Adds the new scale(Number, Asset) helper and minor formatting of operators.
include/xrpl/basics/Number.h Removes Number::scale member template and related concept.
Comments suppressed due to low confidence (2)

include/xrpl/protocol/STAmount.h:726

  • The new doc comment for scale(Number, Asset) has very long lines and a slightly awkward sentence (“different rules and mantissa ranges for determining the exponent than Number”). Please wrap to match the surrounding style and tweak the wording for clarity/grammar.
/** Get the scale of a Number for a given asset.
 *
 * "scale" is similar to "exponent", but from the perspective of STAmount, which has different rules and mantissa ranges
 * for determining the exponent than Number.

src/libxrpl/tx/InvariantCheck.cpp:3012

  • The std::max(scale(...), scale(...)) initializer is now formatted on a single long line, while the adjacent availableDelta uses a wrapped style. Consider wrapping this call too for consistency/readability (and to avoid line-length issues).
                        afterVault.assetsTotal - beforeVault.assetsTotal,
                        std::max(
                            scale(afterVault.assetsTotal, vaultAsset), scale(beforeVault.assetsTotal, vaultAsset))};
                    DeltaInfo availableDelta{

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

Comment thread include/xrpl/basics/Number.h
});

#if LOANTODO
#if LOAN_TODO

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Out of scope for this PR, but do we still need these blocks? Can we clean them up?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Out of scope for this PR, but do we still need these blocks? Can we clean them up?

That #if block is wrapped around test cases that I started or copy/pasted, but wasn't able to fully integrate and get working - not Loan problems, but just problems with the way the test was written or the scenario was set up. I think it would be worthwhile to come back to them eventually. I could stick them in a branch, but they're likely to be even more forgotten than they are now.

I only renamed the label because cspell complained about it, and I want a green build.

…number-scale2

* commit '25cca465538a56cce501477f9e5e2c1c7ea2d84c':
  chore: Set clang-format width to 100 in config file (6387)
  chore: Set cmake-format width to 100 (6386)
  ci: Add clang tidy workflow to ci (6369)
* commit '2c1fad1023':
  chore: Apply clang-format width 100 (6387)
… into ximinez/number-scale2

* XRPLF/tapanito/lending-vault-invariant:
  chore: Add nix development environment (6314)
  ci: [DEPENDABOT] bump actions/upload-artifact from 4.6.2 to 6.0.0 (6396)
  ci: [DEPENDABOT] bump actions/checkout from 4.3.0 to 6.0.2 (6397)
  ci: [DEPENDABOT] bump actions/setup-python from 5.6.0 to 6.2.0 (6395)
  ci: [DEPENDABOT] bump tj-actions/changed-files from 46.0.5 to 47.0.4 (6394)
  ci: [DEPENDABOT] bump codecov/codecov-action from 5.4.3 to 5.5.2 (6398)
  ci: Build docs in PRs and in private repos (6400)
  ci: Add dependabot config (6379)
  Fix tautological assertion (6393)
@ximinez ximinez added Ready to merge *PR author* thinks it's ready to merge. Has passed code review. Perf sign-off may still be required. and removed DraftRunCI Normally CI does not run on draft PRs. This opts in. labels Feb 24, 2026
@ximinez ximinez merged commit 11864ff into tapanito/lending-vault-invariant Feb 24, 2026
29 of 30 checks passed
@ximinez ximinez deleted the ximinez/number-scale2 branch February 24, 2026 23:40
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. 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.

3 participants