From fc435fa75f8ef81a213b270ac941c40474a6ede5 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Fri, 29 Mar 2013 20:19:47 -0700 Subject: [PATCH] Correctly account for liquidity in the implied default path. --- src/cpp/ripple/Pathfinder.cpp | 55 +++++++++++++++++++++++++++++------ 1 file changed, 46 insertions(+), 9 deletions(-) diff --git a/src/cpp/ripple/Pathfinder.cpp b/src/cpp/ripple/Pathfinder.cpp index d3c1be196..9628bb213 100644 --- a/src/cpp/ripple/Pathfinder.cpp +++ b/src/cpp/ripple/Pathfinder.cpp @@ -609,11 +609,46 @@ bool Pathfinder::findPaths(const unsigned int iMaxSteps, const unsigned int iMax { std::sort(vMap.begin(), vMap.end(), bQualityCmp); // Lower is better and should be first. -// if (bFound) -// { // must subtract liquidity in default path from remaining amount WRITEME -// } - STAmount remaining = mDstAmount; + if (bFound) + { // must subtract liquidity in default path from remaining amount + try + { + STAmount saMaxAmountAct, saDstAmountAct; + std::vector vpsExpanded; + LedgerEntrySet lesSandbox(lesActive.duplicate()); + + TER result = RippleCalc::rippleCalc( + lesSandbox, + saMaxAmountAct, + saDstAmountAct, + vpsExpanded, + mSrcAmount, + mDstAmount, + mDstAccountID, + mSrcAccountID, + STPathSet(), + true, // allow partial payment + false, + false, // don't suppress default paths, that's the point + true); + + if (tesSUCCESS == result) + { + cLog(lsDEBUG) << "Default path contributes: " << saDstAmountAct; + remaining -= saDstAmountAct; + } + else + { + cLog(lsDEBUG) << "Default path fails: " << transToken(result); + } + } + catch (...) + { + cLog(lsDEBUG) << "Default path causes exception"; + } + } + for (int i = 0, iPathsLeft = iMaxPaths; (iPathsLeft > 0) && (i < vMap.size()); ++i) { path_LQ_t& lqt = vMap[i]; @@ -627,11 +662,13 @@ bool Pathfinder::findPaths(const unsigned int iMaxSteps, const unsigned int iMax cLog(lsDEBUG) << "Skipping a non-filling path: " << vspResults[lqt.get<3>()].getJson(0); } -// if (remaining.isPositive()) -// { -// bFound = false; -// cLog(lsWARNING) << "Paths could not send " << remaining << " of " << mDstAmount; -// | + if (remaining.isPositive()) + { + bFound = false; + cLog(lsINFO) << "Paths could not send " << remaining << " of " << mDstAmount; + } + else + bFound = true; cLog(lsDEBUG) << boost::str(boost::format("findPaths: RESULTS: %s") % spsDst.getJson(0)); }