From c9ddee83c2653bbebf7bcb02082f06a0912e1fdb Mon Sep 17 00:00:00 2001 From: Alphonse Noni Mousse <39067955+a-noni-mousse@users.noreply.github.com> Date: Thu, 19 Feb 2026 15:14:12 +0900 Subject: [PATCH] refactor: improve checking of path lengths (#4519) Improve the checking of the path lengths during Payments. Previously, the code that did the check of the payment path lengths was sometimes executed, but without any effect. This changes it to only check when it matters, and to not make unnecessary copies of the path vectors. Signed-off-by: Manoj Doshi --- src/ripple/app/tx/impl/Payment.cpp | 31 +++++++++--------------------- 1 file changed, 9 insertions(+), 22 deletions(-) diff --git a/src/ripple/app/tx/impl/Payment.cpp b/src/ripple/app/tx/impl/Payment.cpp index ce0b00014..4859a327d 100644 --- a/src/ripple/app/tx/impl/Payment.cpp +++ b/src/ripple/app/tx/impl/Payment.cpp @@ -270,27 +270,17 @@ Payment::preclaim(PreclaimContext const& ctx) return tecDST_TAG_NEEDED; } - if (paths || sendMax || !saDstAmount.native()) + // Payment with at least one intermediate step and uses transitive balances. + if ((paths || sendMax || !saDstAmount.native()) && ctx.view.open()) { - // Ripple payment with at least one intermediate step and uses - // transitive balances. + STPathSet const& paths = ctx.tx.getFieldPathSet(sfPaths); - // Copy paths into an editable class. - STPathSet const spsPaths = ctx.tx.getFieldPathSet(sfPaths); - - auto pathTooBig = spsPaths.size() > MaxPathSize; - - if (!pathTooBig) - for (auto const& path : spsPaths) - if (path.size() > MaxPathLength) - { - pathTooBig = true; - break; - } - - if (ctx.view.open() && pathTooBig) + if (paths.size() > MaxPathSize || + std::any_of(paths.begin(), paths.end(), [](STPath const& path) { + return path.size() > MaxPathLength; + })) { - return telBAD_PATH_COUNT; // Too many paths for proposed ledger. + return telBAD_PATH_COUNT; } } @@ -398,9 +388,6 @@ Payment::doApply() } } - // Copy paths into an editable class. - STPathSet spsPaths = ctx_.tx.getFieldPathSet(sfPaths); - path::RippleCalc::Input rcInput; rcInput.partialPaymentAllowed = partialPaymentAllowed; rcInput.defaultPathsAllowed = defaultPathsAllowed; @@ -418,7 +405,7 @@ Payment::doApply() saDstAmount, uDstAccountID, account_, - spsPaths, + ctx_.tx.getFieldPathSet(sfPaths), ctx_.app.logs(), &rcInput); // VFALCO NOTE We might not need to apply, depending