From 25e10ce9cbc225fbad39f78bc4abc567db601d78 Mon Sep 17 00:00:00 2001 From: MJK Date: Tue, 9 Oct 2012 17:02:01 -0700 Subject: [PATCH 1/2] bug fix for Pathfinder. Drop zero-length paths; prevent them from getting added and avoid pathbuilding errors later --- src/Pathfinder.cpp | 27 ++++++++++++++++++++++++++- src/SerializedTypes.h | 3 +++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/Pathfinder.cpp b/src/Pathfinder.cpp index 9290f921ae..6585730936 100644 --- a/src/Pathfinder.cpp +++ b/src/Pathfinder.cpp @@ -104,6 +104,9 @@ bool Pathfinder::findPaths(int maxSearchSteps, int maxPay, STPathSet& retPathSet if (ele.mAccountID == mDstAccountID) { path.mPath.erase(path.mPath.begin()); path.mPath.erase(path.mPath.begin() + path.mPath.size()-1); + if (path.mPath.size() == 0) { + continue; + } retPathSet.addPath(path); return true; } @@ -118,7 +121,11 @@ bool Pathfinder::findPaths(int maxSearchSteps, int maxPay, STPathSet& retPathSet STPath new_path(path); STPathElement new_ele(uint160(), book->getCurrencyOut(), book->getIssuerOut()); new_path.mPath.push_back(new_ele); + new_path.mCurrencyID = book->getCurrencyOut(); + new_path.mCurrencyID = book->getCurrencyOut(); + pqueue.push(new_path); + } } @@ -136,8 +143,26 @@ bool Pathfinder::findPaths(int maxSearchSteps, int maxPay, STPathSet& retPathSet new_path.mPath.push_back(new_ele); pqueue.push(new_path); } + } // BOOST_FOREACHE + + // every offer that wants the source currency + std::vector books; + mOrderBook.getBooks(path.mCurrentAccount, path.mCurrencyID, books); + + BOOST_FOREACH(OrderBook::pointer book,books) + { + STPath new_path(path); + STPathElement new_ele(uint160(), book->getCurrencyOut(), book->getIssuerOut()); + + new_path.mPath.push_back(new_ele); + new_path.mCurrentAccount=book->getIssuerOut(); + new_path.mCurrencyID=book->getCurrencyOut(); + + pqueue.push(new_path); + } - } + + } // else // enumerate all adjacent nodes, construct a new path and push it into the queue } // While } // if there is a ledger diff --git a/src/SerializedTypes.h b/src/SerializedTypes.h index 9b502409f5..90438442a8 100644 --- a/src/SerializedTypes.h +++ b/src/SerializedTypes.h @@ -595,6 +595,9 @@ public: // std::string getText() const; Json::Value getJson(int) const; + uint160 mCurrencyID; + uint160 mCurrentAccount; // what account is at the end of the path + std::vector::iterator begin() { return mPath.begin(); } std::vector::iterator end() { return mPath.end(); } std::vector::const_iterator begin() const { return mPath.begin(); } From 6d87af5e933b96b1f35393c9fa04fa1bb24c926b Mon Sep 17 00:00:00 2001 From: MJK Date: Tue, 9 Oct 2012 17:19:12 -0700 Subject: [PATCH 2/2] fix typo in code in previous Pathfinder fix --- src/Pathfinder.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Pathfinder.cpp b/src/Pathfinder.cpp index 6585730936..23e596aab4 100644 --- a/src/Pathfinder.cpp +++ b/src/Pathfinder.cpp @@ -122,7 +122,7 @@ bool Pathfinder::findPaths(int maxSearchSteps, int maxPay, STPathSet& retPathSet STPathElement new_ele(uint160(), book->getCurrencyOut(), book->getIssuerOut()); new_path.mPath.push_back(new_ele); new_path.mCurrencyID = book->getCurrencyOut(); - new_path.mCurrencyID = book->getCurrencyOut(); + new_path.mCurrentAccount = book->getCurrencyOut(); pqueue.push(new_path);