From 521d528d6a99555a63994caa85f8b5cdd783d622 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Fri, 3 May 2013 14:51:49 -0700 Subject: [PATCH] Bug fixes. --- src/cpp/ripple/PFRequest.cpp | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/src/cpp/ripple/PFRequest.cpp b/src/cpp/ripple/PFRequest.cpp index 59f2c3668..cc1b827ee 100644 --- a/src/cpp/ripple/PFRequest.cpp +++ b/src/cpp/ripple/PFRequest.cpp @@ -8,6 +8,8 @@ #include "RippleCalc.h" #include "LedgerFormats.h" +SETUP_LOG(); + boost::recursive_mutex PFRequest::sLock; std::set PFRequest::sRequests; @@ -98,6 +100,10 @@ Json::Value PFRequest::doCreate(Ledger::ref lrLedger, const Json::Value& value) if (mValid) { + cLog(lsINFO) << "Request created: " << raSrcAccount.humanAccountID() << + " -> " << raDstAccount.humanAccountID(); + cLog(lsINFO) << "Deliver: " << saDstAmount.getFullText(); + boost::recursive_mutex::scoped_lock sl(sLock); sRequests.insert(shared_from_this()); } @@ -125,7 +131,7 @@ int PFRequest::parseJson(const Json::Value& jvParams, bool complete) if (jvParams.isMember("destination_account")) { - if (!raDstAccount.setAccountID(jvParams["source_account"].asString())) + if (!raDstAccount.setAccountID(jvParams["destination_account"].asString())) { jvStatus = rpcError(rpcDST_ACT_MALFORMED); return PFR_PJ_INVALID; @@ -141,7 +147,8 @@ int PFRequest::parseJson(const Json::Value& jvParams, bool complete) { if (!saDstAmount.bSetJson(jvParams["destination_amount"]) || (saDstAmount.getCurrency().isZero() && saDstAmount.getIssuer().isNonZero()) || - (saDstAmount.getCurrency() == CURRENCY_BAD)) + (saDstAmount.getCurrency() == CURRENCY_BAD) || + !saDstAmount.isPositive()) { jvStatus = rpcError(rpcDST_AMT_MALFORMED); return PFR_PJ_INVALID; @@ -216,7 +223,12 @@ bool PFRequest::doUpdate(RLCache::ref cache, bool fast) BOOST_FOREACH(const uint160& c, usCurrencies) { if (!sameAccount || (c != saDstAmount.getCurrency())) - sourceCurrencies.insert(std::make_pair(c, ACCOUNT_XRP)); + { + if (c.isZero()) + sourceCurrencies.insert(std::make_pair(c, ACCOUNT_XRP)); + else + sourceCurrencies.insert(std::make_pair(c, raSrcAccount.getAccountID())); + } } } @@ -227,10 +239,15 @@ bool PFRequest::doUpdate(RLCache::ref cache, bool fast) BOOST_FOREACH(const currIssuer_t& currIssuer, sourceCurrencies) { + { + STAmount test(currIssuer.first, currIssuer.second, 1); + cLog(lsDEBUG) << "Trying to find paths: " << test.getFullText(); + } bool valid; STPathSet spsPaths; Pathfinder pf(cache, raSrcAccount, raDstAccount, currIssuer.first, currIssuer.second, saDstAmount, valid); + tLog(!valid, lsINFO) << "PF request not valid"; if (valid && pf.findPaths(theConfig.PATH_SEARCH_SIZE - (fast ? 0 : 1), 3, spsPaths)) { LedgerEntrySet lesSandbox(cache->getLedger(), tapNONE); @@ -240,6 +257,8 @@ bool PFRequest::doUpdate(RLCache::ref cache, bool fast) STAmount saMaxAmount(currIssuer.first, currIssuer.second.isNonZero() ? currIssuer.second : (currIssuer.first.isZero() ? ACCOUNT_XRP : raSrcAccount.getAccountID()), 1); + saMaxAmount.negate(); + cLog(lsDEBUG) << "Paths found, calling rippleCalc"; TER terResult = RippleCalc::rippleCalc(lesSandbox, saMaxAmountAct, saDstAmountAct, vpsExpanded, saMaxAmount, saDstAmount, raDstAccount.getAccountID(), raSrcAccount.getAccountID(), spsPaths, false, false, false, true); @@ -250,6 +269,14 @@ bool PFRequest::doUpdate(RLCache::ref cache, bool fast) jvEntry["paths_computed"] = spsPaths.getJson(0); jvArray.append(jvEntry); } + else + { + cLog(lsINFO) << "rippleCalc returns " << transHuman(terResult); + } + } + else + { + cLog(lsINFO) << "No paths found"; } } jvStatus["alternatives"] = jvArray;