From a1915bd89986e34a0ecf1fbb05b6437531e3c3e2 Mon Sep 17 00:00:00 2001 From: Arthur Britto Date: Tue, 11 Dec 2012 14:03:32 -0800 Subject: [PATCH] Omit default paths from pathfinder results. --- src/cpp/ripple/Pathfinder.cpp | 36 ++++++++++++++++++++++++----------- src/cpp/ripple/RippleCalc.cpp | 7 +++++++ 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/src/cpp/ripple/Pathfinder.cpp b/src/cpp/ripple/Pathfinder.cpp index 7dcc5ef1b6..c8f0b66ba0 100644 --- a/src/cpp/ripple/Pathfinder.cpp +++ b/src/cpp/ripple/Pathfinder.cpp @@ -77,7 +77,6 @@ PathOption::PathOption(PathOption::pointer other) // Return true, if path is a default path with an element. // A path is a default path if it is implied via src, dst, send, and sendmax. -// XXX Could be determined via STAmount bool Pathfinder::bDefaultPath(const STPath& spPath) { if (2 == spPath.mPath.size()) { @@ -87,6 +86,15 @@ bool Pathfinder::bDefaultPath(const STPath& spPath) return true; } + if (!mPsDefault) + { + // No default path. + // There might not be a direct credit line or there may be no implied nodes + // in send and sendmax. + + return false; // Didn't generate a default path. So can't match. + } + PathState::pointer pspCurrent = boost::make_shared(mDstAmount, mSrcAmount, mLedger); if (pspCurrent) @@ -98,6 +106,8 @@ bool Pathfinder::bDefaultPath(const STPath& spPath) bDefault = pspCurrent->vpnNodes == mPsDefault->vpnNodes; + cLog(lsDEBUG) << "findPaths: expanded path: " << pspCurrent->getJson(); + // Path is a default (implied). Don't need to add it to return set. cLog(lsDEBUG) << "findPaths: default path: indirect: " << spPath.getJson(0); @@ -119,13 +129,23 @@ Pathfinder::Pathfinder(const RippleAddress& uSrcAccountID, const RippleAddress& // Construct the default path for later comparison. - mPsDefault = boost::make_shared(mDstAmount, mSrcAmount, mLedger); + PathState::pointer psDefault = boost::make_shared(mDstAmount, mSrcAmount, mLedger); - if (mPsDefault) + if (psDefault) { LedgerEntrySet lesActive(mLedger); - mPsDefault->setExpanded(lesActive, STPath(), mDstAccountID, mSrcAccountID); + psDefault->setExpanded(lesActive, STPath(), mDstAccountID, mSrcAccountID); + + if (tesSUCCESS == psDefault->terStatus) + { + cLog(lsDEBUG) << "Pathfinder: reference path: " << psDefault->getJson(); + mPsDefault = psDefault; + } + else + { + cLog(lsDEBUG) << "Pathfinder: reference path: NONE: " << transToken(psDefault->terStatus); + } } } @@ -150,13 +170,7 @@ bool Pathfinder::findPaths(int maxSearchSteps, int maxPay, STPathSet& retPathSet % RippleAddress::createHumanAccountID(mSrcIssuerID) ); - if (!mPsDefault) - { - cLog(lsDEBUG) << boost::str(boost::format("findPaths: failed to generate default path.")); - - return false; - } - else if (mLedger) + if (mLedger) { std::queue pqueue; STPathElement ele(mSrcAccountID, diff --git a/src/cpp/ripple/RippleCalc.cpp b/src/cpp/ripple/RippleCalc.cpp index 8919a848e1..5440eb34e5 100644 --- a/src/cpp/ripple/RippleCalc.cpp +++ b/src/cpp/ripple/RippleCalc.cpp @@ -62,6 +62,7 @@ bool PathState::lessPriority(PathState& lhs, PathState& rhs) // - A node names it's output. // - A ripple nodes output issuer must be the node's account or the next node's account. // - Offers can only go directly to another offer if the currency and issuer are an exact match. +// - Real issuers must be specified for non-XRP. TER PathState::pushImply( const uint160& uAccountID, // --> Delivering to this account. const uint160& uCurrencyID, // --> Delivering this currency. @@ -186,6 +187,8 @@ TER PathState::pushNode( else { // Add required intermediate nodes to deliver to current account. + cLog(lsDEBUG) << "pushNode: imply for account."; + terResult = pushImply( pnCur.uAccountID, // Current account. pnCur.uCurrencyID, // Wanted currency. @@ -262,6 +265,7 @@ TER PathState::pushNode( else if (!!pnPrv.uAccountID) { // Previous is an account. + cLog(lsDEBUG) << "pushNode: imply for offer."; // Insert intermediary issuer account if needed. terResult = pushImply( @@ -364,7 +368,10 @@ cLog(lsDEBUG) << boost::str(boost::format("PathState: sender implied: account=%s BOOST_FOREACH(const STPathElement& speElement, spSourcePath) { if (tesSUCCESS == terStatus) + { +cLog(lsDEBUG) << boost::str(boost::format("PathState: element in path:")); terStatus = pushNode(speElement.getNodeType(), speElement.getAccountID(), speElement.getCurrency(), speElement.getIssuerID()); + } } const PaymentNode& pnPrv = vpnNodes.back();