From 0a3e1af04c804af94568a0a85d6afce7a39a24e9 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Tue, 28 Oct 2014 11:34:27 -0700 Subject: [PATCH] When pathfinding, don't output a redundant account node --- src/ripple/app/paths/Pathfinder.cpp | 37 +++++++++++++++++++---------- src/ripple/protocol/STPathSet.h | 10 ++++++++ 2 files changed, 34 insertions(+), 13 deletions(-) diff --git a/src/ripple/app/paths/Pathfinder.cpp b/src/ripple/app/paths/Pathfinder.cpp index a912c44a3c..55495a10e8 100644 --- a/src/ripple/app/paths/Pathfinder.cpp +++ b/src/ripple/app/paths/Pathfinder.cpp @@ -1086,20 +1086,31 @@ void Pathfinder::addLink ( book->getIssuerOut (), book->getCurrencyOut (), book->getIssuerOut ())) - { // Don't want the book if we've already seen the issuer - // add the order book itself - newPath.emplace_back ( - STPathElement::typeCurrency | - STPathElement::typeIssuer, - xrpAccount (), - book->getCurrencyOut (), - book->getIssuerOut ()); - - if (book->getIssuerOut () == mDstAccount && - book->getCurrencyOut () == mDstAmount.getCurrency()) + { + // Don't want the book if we've already seen the issuer + // book -> account -> book + if ((newPath.size() >= 2) && + (newPath.back().isAccount ()) && + (newPath[newPath.size() - 2].isOffer ())) { - // with the destination account, this path is - // complete + // replace the redundant account with the order book + newPath[newPath.size() - 1] = STPathElement ( + STPathElement::typeCurrency | STPathElement::typeIssuer, + xrpAccount(), book->getCurrencyOut(), + book->getIssuerOut()); + } + else + { + // add the order book + newPath.emplace_back( + STPathElement::typeCurrency | STPathElement::typeIssuer, + xrpAccount(), book->getCurrencyOut(), + book->getIssuerOut()); + } + + if (book->getIssuerOut() == mDstAccount && + book->getCurrencyOut() == mDstAmount.getCurrency()) + { // with the destination account, this path is complete WriteLog (lsTRACE, Pathfinder) << "complete path found ba: " << currentPath.getJson(0); diff --git a/src/ripple/protocol/STPathSet.h b/src/ripple/protocol/STPathSet.h index 931eeef187..f5acfe1eca 100644 --- a/src/ripple/protocol/STPathSet.h +++ b/src/ripple/protocol/STPathSet.h @@ -195,6 +195,16 @@ public: return mPath.front (); } + STPathElement& operator[](int i) + { + return mPath[i]; + } + + const STPathElement& operator[](int i) const + { + return mPath[i]; + } + private: std::vector mPath; };