From 821fc8abe9de4d19e3c9cacacd5ccbfb493a3090 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Tue, 9 Apr 2013 14:09:23 -0700 Subject: [PATCH] Widen the ripple paths we explore close to the beginning but narrow them in the middle. --- rippled-example.cfg | 4 +- src/cpp/ripple/Config.h | 2 +- src/cpp/ripple/Pathfinder.cpp | 111 ++-------------------------------- 3 files changed, 8 insertions(+), 109 deletions(-) diff --git a/rippled-example.cfg b/rippled-example.cfg index fa5690e56..4e8c1e7b3 100644 --- a/rippled-example.cfg +++ b/rippled-example.cfg @@ -249,9 +249,9 @@ # # [path_search_size] # When searching for paths, the maximum number of nodes allowed. This can take -# exponentially more resource as the size is increasded. +# exponentially more resources as the size is increasded. # -# The default is: 5 +# The default is: 6 # # [rpc_startup] # Specify a list of RPC commands to run at startup. diff --git a/src/cpp/ripple/Config.h b/src/cpp/ripple/Config.h index 2f31731e6..58158ca0d 100644 --- a/src/cpp/ripple/Config.h +++ b/src/cpp/ripple/Config.h @@ -51,7 +51,7 @@ const int SYSTEM_WEBSOCKET_PUBLIC_PORT = 6563; // XXX Going away. #define DEFAULT_PEER_CONNECT_LOW_WATER 4 // Grows exponentially worse. -#define DEFAULT_PATH_SEARCH_SIZE 5 +#define DEFAULT_PATH_SEARCH_SIZE 6 enum SizedItemName { diff --git a/src/cpp/ripple/Pathfinder.cpp b/src/cpp/ripple/Pathfinder.cpp index c9c9f168f..0ddae12c5 100644 --- a/src/cpp/ripple/Pathfinder.cpp +++ b/src/cpp/ripple/Pathfinder.cpp @@ -483,16 +483,14 @@ bool Pathfinder::findPaths(const unsigned int iMaxSteps, const unsigned int iMax if (!candidates.empty()) { - bFound = true; - std::sort(candidates.begin(), candidates.end(), BIND_TYPE(candCmp, mLedger->getLedgerSeq(), P_1, P_2)); - int count = candidates.size(); - if (count > 30) - count /= 3; - else if (count > 10) - count /= 2; + int count = candidates.size(); + if ((count > 10) && (speEnd.mAccountID != mSrcAccountID)) // try more paths from source + count = 10; + else if (count > 50) + count = 50; std::vector< std::pair >::iterator it = candidates.begin(); while (count-- != 0) @@ -701,105 +699,6 @@ bool Pathfinder::findPaths(const unsigned int iMaxSteps, const unsigned int iMax return bFound; } -#if 0 -bool Pathfinder::checkComplete(STPathSet& retPathSet) -{ - if (mCompletePaths.size()) - { // TODO: look through these and pick the most promising - int count=0; - BOOST_FOREACH(PathOption::ref pathOption,mCompletePaths) - { - retPathSet.addPath(pathOption->mPath); - count++; - if(count>2) return(true); - } - return(true); - } - return(false); -} - - -// get all the options from this accountID -// if source is XRP -// every offer that wants XRP -// else -// every ripple line that starts with the source currency -// every offer that we can take that wants the source currency - -void Pathfinder::addOptions(PathOption::pointer tail) -{ - if (!tail->mCurrencyID) - { // source XRP - std::vector xrpBooks; - theApp->getOrderBookDB().getBooksByTakerPays(ISSUER_XRP, CURRENCY_XRP, xrpBooks); - BOOST_FOREACH(OrderBook::ref book, xrpBooks) - { - PathOption::pointer pathOption(new PathOption(tail)); - - STPathElement ele(uint160(), book->getCurrencyOut(), book->getIssuerOut()); - pathOption->mPath.addElement(ele); - - pathOption->mCurrentAccount=book->getIssuerOut(); - pathOption->mCurrencyID=book->getCurrencyOut(); - addPathOption(pathOption); - } - } - else - { // ripple - RippleLines rippleLines(tail->mCurrentAccount); - BOOST_FOREACH(RippleState::ref line,rippleLines.getLines()) - { - // TODO: make sure we can move in the correct direction - STAmount balance=line->getBalance(); - if(balance.getCurrency()==tail->mCurrencyID) - { // we have a ripple line from the tail to somewhere else - PathOption::pointer pathOption(new PathOption(tail)); - - STPathElement ele(line->getAccountIDPeer().getAccountID(), uint160(), uint160()); - pathOption->mPath.addElement(ele); - - - pathOption->mCurrentAccount=line->getAccountIDPeer().getAccountID(); - addPathOption(pathOption); - } - } - - // Every offer that can take this currency in - std::vector books; - theApp->getOrderBookDB().getBooksByTakerPays(tail->mCurrentAccount, tail->mCurrencyID, books); - BOOST_FOREACH(OrderBook::ref book, books) - { - PathOption::pointer pathOption(new PathOption(tail)); - - STPathElement ele(uint160(), book->getCurrencyOut(), book->getIssuerOut()); - pathOption->mPath.addElement(ele); - - pathOption->mCurrentAccount=book->getIssuerOut(); - pathOption->mCurrencyID=book->getCurrencyOut(); - addPathOption(pathOption); - } - } -} - -void Pathfinder::addPathOption(PathOption::pointer pathOption) -{ - if(pathOption->mCurrencyID==mDstAmount.getCurrency()) - { - pathOption->mCorrectCurrency=true; - - if(pathOption->mCurrentAccount==mDstAccountID) - { // this path is complete - mCompletePaths.push_back(pathOption); - }else mBuildingPaths.push_back(pathOption); - } - else - { - pathOption->mCorrectCurrency=false; - mBuildingPaths.push_back(pathOption); - } -} -#endif - boost::unordered_set usAccountSourceCurrencies(const RippleAddress& raAccountID, Ledger::ref lrLedger, bool includeXRP) {