From 0a4dd087004371471b95a2cbb2116651f5159f37 Mon Sep 17 00:00:00 2001 From: Vito <5780819+Tapanito@users.noreply.github.com> Date: Mon, 10 Aug 2026 16:34:29 +0200 Subject: [PATCH] chore: Address inline review comments on Vault helpers - Restore the doc comment on STAmount::isRounded that was lost when it moved out of LendingHelpers.cpp. - Collapse LoanManage::defaultLoan's Vault-update block into a direct return of addVaultAssets, since there is no follow-up work after it. - Mark removeVaultAssets's amount==0 early-return with LCOV_EXCL_LINE: it is a defensive short-circuit for a branch that is only reachable in a vanishingly rare edge case (final withdrawal from a vault whose sfAssetsAvailable has already been written down to zero) and is not reached by any current transactor-level test. --- include/xrpl/protocol/STAmount.h | 4 ++++ src/libxrpl/ledger/helpers/VaultHelpers.cpp | 2 +- .../tx/transactors/lending/LoanManage.cpp | 18 +++++++----------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/include/xrpl/protocol/STAmount.h b/include/xrpl/protocol/STAmount.h index c17b74f113..8217c21a32 100644 --- a/include/xrpl/protocol/STAmount.h +++ b/include/xrpl/protocol/STAmount.h @@ -772,6 +772,10 @@ roundToAsset( return roundToScale(ret, scale); } +/* Checks if a value is already rounded to the specified scale. + * Returns true if rounding down and rounding up produce the same result, + * indicating no further precision exists beyond the scale. + */ [[nodiscard]] inline bool isRounded(Asset const& asset, Number const& value, std::int32_t scale) { diff --git a/src/libxrpl/ledger/helpers/VaultHelpers.cpp b/src/libxrpl/ledger/helpers/VaultHelpers.cpp index 769e50149b..09cdb2edea 100644 --- a/src/libxrpl/ledger/helpers/VaultHelpers.cpp +++ b/src/libxrpl/ledger/helpers/VaultHelpers.cpp @@ -307,7 +307,7 @@ removeVaultAssets( applyRemoveVaultAssets(ctx.view, vault, amount, finalRemoval); if (amount == beast::kZero) - return tesSUCCESS; + return tesSUCCESS; // LCOV_EXCL_LINE return doWithdraw(ctx, senderAcct, dstAcct, vault->at(sfAccount), priorBalance, amount, j); } diff --git a/src/libxrpl/tx/transactors/lending/LoanManage.cpp b/src/libxrpl/tx/transactors/lending/LoanManage.cpp index 76a3060b25..b3e02c5a5e 100644 --- a/src/libxrpl/tx/transactors/lending/LoanManage.cpp +++ b/src/libxrpl/tx/transactors/lending/LoanManage.cpp @@ -271,17 +271,13 @@ LoanManage::defaultLoan( // Update the Vault's assets, and return funds from the LoanBroker // pseudo-account to the Vault pseudo-account: - if (auto const ter = addVaultAssets( - view, - vaultSle, - brokerSle->at(sfAccount), - STAmount{vaultAsset, defaultCovered}, - STAmount{vaultAsset, vaultTotalDelta}, - j); - !isTesSuccess(ter)) - return ter; - - return tesSUCCESS; + return addVaultAssets( + view, + vaultSle, + brokerSle->at(sfAccount), + STAmount{vaultAsset, defaultCovered}, + STAmount{vaultAsset, vaultTotalDelta}, + j); } TER