From f405a492a4524376294d92fe849c65173ad1fc02 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Sun, 7 Apr 2013 20:15:01 -0700 Subject: [PATCH] Avoid redundant exploration. --- src/cpp/ripple/Pathfinder.cpp | 45 +++++++++-------------------------- src/cpp/ripple/Pathfinder.h | 2 ++ 2 files changed, 13 insertions(+), 34 deletions(-) diff --git a/src/cpp/ripple/Pathfinder.cpp b/src/cpp/ripple/Pathfinder.cpp index 0a3a1b0400..f7193772cf 100644 --- a/src/cpp/ripple/Pathfinder.cpp +++ b/src/cpp/ripple/Pathfinder.cpp @@ -46,37 +46,6 @@ Test USD to EUR // length of path // width of path // correct currency at the end -#if 0 -bool sortPathOptions(PathOption::pointer first, PathOption::pointer second) -{ - if (first->mTotalCostmTotalCost) return(true); - if (first->mTotalCost>second->mTotalCost) return(false); - - if (first->mCorrectCurrency && !second->mCorrectCurrency) return(true); - if (!first->mCorrectCurrency && second->mCorrectCurrency) return(false); - - if (first->mPath.size()mPath.size()) return(true); - if (first->mPath.size()>second->mPath.size()) return(false); - - if (first->mMinWidthmMinWidth) return true; - - return false; -} - -PathOption::PathOption(uint160& srcAccount,uint160& srcCurrencyID,const uint160& dstCurrencyID) -{ - mCurrentAccount=srcAccount; - mCurrencyID=srcCurrencyID; - mCorrectCurrency=(srcCurrencyID==dstCurrencyID); - mQuality=0; - mMinWidth=STAmount(dstCurrencyID,99999,80); // this will get lowered when we convert back to the correct currency -} - -PathOption::PathOption(PathOption::pointer other) -{ - // TODO: -} -#endif // quality, length, liquidity, index typedef boost::tuple path_LQ_t; @@ -395,7 +364,8 @@ bool Pathfinder::findPaths(const unsigned int iMaxSteps, const unsigned int iMax { // New end is an order book with the currency and issuer. - if (!spPath.hasSeen(ACCOUNT_XRP, book->getCurrencyOut(), book->getIssuerOut())) + if (!spPath.hasSeen(ACCOUNT_XRP, book->getCurrencyOut(), book->getIssuerOut()) && + !matchesOrigin(book->getCurrencyOut(), book->getIssuerOut())) { // Not a order book already in path. STPath spNew(spPath); @@ -456,7 +426,7 @@ bool Pathfinder::findPaths(const unsigned int iMaxSteps, const unsigned int iMax // wrong currency nothing(); } - else if (spPath.hasSeen(uPeerID, speEnd.mCurrencyID, uPeerID)) + else if (spPath.hasSeen(uPeerID, speEnd.mCurrencyID, uPeerID) && (uPeerID != mSrcAccountID)) { // Peer is in path already. Ignore it to avoid a loop. cLog(lsTRACE) << @@ -513,7 +483,8 @@ bool Pathfinder::findPaths(const unsigned int iMaxSteps, const unsigned int iMax BOOST_FOREACH(OrderBook::ref book, books) { - if (!spPath.hasSeen(ACCOUNT_XRP, book->getCurrencyOut(), book->getIssuerOut())) + if (!spPath.hasSeen(ACCOUNT_XRP, book->getCurrencyOut(), book->getIssuerOut()) && + !matchesOrigin(book->getCurrencyOut(), book->getIssuerOut())) { // A book we haven't seen before. Add it. STPath spNew(spPath); @@ -812,4 +783,10 @@ boost::unordered_set usAccountSourceCurrencies(const RippleAddress& raA return usCurrencies; } + +bool Pathfinder::matchesOrigin(const uint160& currency, const uint160& issuer) +{ + return (currency == mSrcCurrencyID) && (issuer == mSrcIssuerID); +} + // vim:ts=4 diff --git a/src/cpp/ripple/Pathfinder.h b/src/cpp/ripple/Pathfinder.h index 135bc3e2fe..87f3c95516 100644 --- a/src/cpp/ripple/Pathfinder.h +++ b/src/cpp/ripple/Pathfinder.h @@ -57,6 +57,8 @@ class Pathfinder // void addPathOption(PathOption::pointer pathOption); + bool matchesOrigin(const uint160& currency, const uint160& issuer); + public: Pathfinder(Ledger::ref ledger, const RippleAddress& srcAccountID, const RippleAddress& dstAccountID,