From 791b088ff310978a60c9fa296d1e42c3b7cedee3 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Tue, 5 Mar 2013 15:02:21 -0800 Subject: [PATCH 1/2] Make sure paths are correectly serializable. --- src/cpp/ripple/Pathfinder.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/cpp/ripple/Pathfinder.cpp b/src/cpp/ripple/Pathfinder.cpp index ef14477a57..f9113952b7 100644 --- a/src/cpp/ripple/Pathfinder.cpp +++ b/src/cpp/ripple/Pathfinder.cpp @@ -410,7 +410,7 @@ bool Pathfinder::findPaths(const unsigned int iMaxSteps, const unsigned int iMax BOOST_FOREACH(AccountItem::ref item, rippleLines.getItems()) { RippleState* rspEntry = (RippleState*) item.get(); - const uint160 uPeerID = rspEntry->getAccountIDPeer(); + const uint160& uPeerID = rspEntry->getAccountIDPeer(); if (spPath.hasSeen(uPeerID, speEnd.mCurrencyID, uPeerID)) { @@ -467,7 +467,8 @@ bool Pathfinder::findPaths(const unsigned int iMaxSteps, const unsigned int iMax { // A book we haven't seen before. Add it. STPath spNew(spPath); - STPathElement speBook(ACCOUNT_XRP, book->getCurrencyOut(), book->getIssuerOut()); + STPathElement speBook(ACCOUNT_XRP, book->getCurrencyOut(), book->getIssuerOut(), + book->getCurrencyIn() != book->getCurrencyOut()); spNew.mPath.push_back(speBook); // Add the order book. From 3f6cb7815829e16449833e58cd116969e15e4471 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Tue, 5 Mar 2013 15:17:37 -0800 Subject: [PATCH 2/2] Fix a bug where we negate the balance during pathfinding. --- src/cpp/ripple/Pathfinder.cpp | 4 ++-- src/cpp/ripple/RippleCalc.cpp | 2 +- src/cpp/ripple/SerializedTypes.h | 12 ++++++------ 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/cpp/ripple/Pathfinder.cpp b/src/cpp/ripple/Pathfinder.cpp index f9113952b7..366bf18ad5 100644 --- a/src/cpp/ripple/Pathfinder.cpp +++ b/src/cpp/ripple/Pathfinder.cpp @@ -424,7 +424,7 @@ bool Pathfinder::findPaths(const unsigned int iMaxSteps, const unsigned int iMax } else if (!rspEntry->getBalance().isPositive() // No IOUs to send. && (!rspEntry->getLimitPeer() // Peer does not extend credit. - || *rspEntry->getBalance().negate() >= rspEntry->getLimitPeer() // No credit left. + || -rspEntry->getBalance() >= rspEntry->getLimitPeer() // No credit left. || (bRequireAuth && !rspEntry->getAuth()))) // Not authorized to hold credit. { // Path has no credit left. Ignore it. @@ -700,7 +700,7 @@ boost::unordered_set usAccountSourceCurrencies(const RippleAddress& raA // Filter out non if (saBalance.isPositive() // Have IOUs to send. || (rspEntry->getLimitPeer() // Peer extends credit. - && *saBalance.negate() < rspEntry->getLimitPeer())) // Credit left. + && -saBalance < rspEntry->getLimitPeer())) // Credit left. { // Path has no credit left. Ignore it. usCurrencies.insert(saBalance.getCurrency()); diff --git a/src/cpp/ripple/RippleCalc.cpp b/src/cpp/ripple/RippleCalc.cpp index 3ec5f8b578..fcbea270ac 100644 --- a/src/cpp/ripple/RippleCalc.cpp +++ b/src/cpp/ripple/RippleCalc.cpp @@ -233,7 +233,7 @@ TER PathState::pushNode( STAmount saOwed = lesEntries.rippleOwed(pnCur.uAccountID, pnBck.uAccountID, pnCur.uCurrencyID); - if (!saOwed.isPositive() && *saOwed.negate() >= lesEntries.rippleLimit(pnCur.uAccountID, pnBck.uAccountID, pnCur.uCurrencyID)) + if (!saOwed.isPositive() && -saOwed >= lesEntries.rippleLimit(pnCur.uAccountID, pnBck.uAccountID, pnCur.uCurrencyID)) { terResult = tecPATH_DRY; } diff --git a/src/cpp/ripple/SerializedTypes.h b/src/cpp/ripple/SerializedTypes.h index 9a75bfde20..b618c952d7 100644 --- a/src/cpp/ripple/SerializedTypes.h +++ b/src/cpp/ripple/SerializedTypes.h @@ -364,14 +364,14 @@ public: bool isGEZero() const { return !mIsNegative; } operator bool() const { return !isZero(); } - STAmount* negate() { if (!isZero()) mIsNegative = !mIsNegative; return this; } - STAmount* zero() { mOffset = mIsNative ? 0 : -100; mValue = 0; mIsNegative = false; return this; } + void negate() { if (!isZero()) mIsNegative = !mIsNegative; } + void zero() { mOffset = mIsNative ? 0 : -100; mValue = 0; mIsNegative = false; } // Zero while copying currency and issuer. - STAmount* zero(const STAmount& saTmpl) - { mCurrency = saTmpl.mCurrency; mIssuer = saTmpl.mIssuer; mIsNative = saTmpl.mIsNative; return zero(); } - STAmount* zero(const uint160& uCurrencyID, const uint160& uIssuerID) - { mCurrency = uCurrencyID; mIssuer = uIssuerID; mIsNative = !uCurrencyID; return zero(); } + void zero(const STAmount& saTmpl) + { mCurrency = saTmpl.mCurrency; mIssuer = saTmpl.mIssuer; mIsNative = saTmpl.mIsNative; zero(); } + void zero(const uint160& uCurrencyID, const uint160& uIssuerID) + { mCurrency = uCurrencyID; mIssuer = uIssuerID; mIsNative = !uCurrencyID; zero(); } int compare(const STAmount&) const;