Bug fixes.

This commit is contained in:
JoelKatz
2013-05-03 14:51:49 -07:00
parent e7529d0221
commit 521d528d6a

View File

@@ -8,6 +8,8 @@
#include "RippleCalc.h" #include "RippleCalc.h"
#include "LedgerFormats.h" #include "LedgerFormats.h"
SETUP_LOG();
boost::recursive_mutex PFRequest::sLock; boost::recursive_mutex PFRequest::sLock;
std::set<PFRequest::wptr> PFRequest::sRequests; std::set<PFRequest::wptr> PFRequest::sRequests;
@@ -98,6 +100,10 @@ Json::Value PFRequest::doCreate(Ledger::ref lrLedger, const Json::Value& value)
if (mValid) if (mValid)
{ {
cLog(lsINFO) << "Request created: " << raSrcAccount.humanAccountID() <<
" -> " << raDstAccount.humanAccountID();
cLog(lsINFO) << "Deliver: " << saDstAmount.getFullText();
boost::recursive_mutex::scoped_lock sl(sLock); boost::recursive_mutex::scoped_lock sl(sLock);
sRequests.insert(shared_from_this()); sRequests.insert(shared_from_this());
} }
@@ -125,7 +131,7 @@ int PFRequest::parseJson(const Json::Value& jvParams, bool complete)
if (jvParams.isMember("destination_account")) if (jvParams.isMember("destination_account"))
{ {
if (!raDstAccount.setAccountID(jvParams["source_account"].asString())) if (!raDstAccount.setAccountID(jvParams["destination_account"].asString()))
{ {
jvStatus = rpcError(rpcDST_ACT_MALFORMED); jvStatus = rpcError(rpcDST_ACT_MALFORMED);
return PFR_PJ_INVALID; return PFR_PJ_INVALID;
@@ -141,7 +147,8 @@ int PFRequest::parseJson(const Json::Value& jvParams, bool complete)
{ {
if (!saDstAmount.bSetJson(jvParams["destination_amount"]) || if (!saDstAmount.bSetJson(jvParams["destination_amount"]) ||
(saDstAmount.getCurrency().isZero() && saDstAmount.getIssuer().isNonZero()) || (saDstAmount.getCurrency().isZero() && saDstAmount.getIssuer().isNonZero()) ||
(saDstAmount.getCurrency() == CURRENCY_BAD)) (saDstAmount.getCurrency() == CURRENCY_BAD) ||
!saDstAmount.isPositive())
{ {
jvStatus = rpcError(rpcDST_AMT_MALFORMED); jvStatus = rpcError(rpcDST_AMT_MALFORMED);
return PFR_PJ_INVALID; return PFR_PJ_INVALID;
@@ -216,7 +223,12 @@ bool PFRequest::doUpdate(RLCache::ref cache, bool fast)
BOOST_FOREACH(const uint160& c, usCurrencies) BOOST_FOREACH(const uint160& c, usCurrencies)
{ {
if (!sameAccount || (c != saDstAmount.getCurrency())) if (!sameAccount || (c != saDstAmount.getCurrency()))
{
if (c.isZero())
sourceCurrencies.insert(std::make_pair(c, ACCOUNT_XRP)); 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) BOOST_FOREACH(const currIssuer_t& currIssuer, sourceCurrencies)
{ {
{
STAmount test(currIssuer.first, currIssuer.second, 1);
cLog(lsDEBUG) << "Trying to find paths: " << test.getFullText();
}
bool valid; bool valid;
STPathSet spsPaths; STPathSet spsPaths;
Pathfinder pf(cache, raSrcAccount, raDstAccount, Pathfinder pf(cache, raSrcAccount, raDstAccount,
currIssuer.first, currIssuer.second, saDstAmount, valid); 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)) if (valid && pf.findPaths(theConfig.PATH_SEARCH_SIZE - (fast ? 0 : 1), 3, spsPaths))
{ {
LedgerEntrySet lesSandbox(cache->getLedger(), tapNONE); LedgerEntrySet lesSandbox(cache->getLedger(), tapNONE);
@@ -240,6 +257,8 @@ bool PFRequest::doUpdate(RLCache::ref cache, bool fast)
STAmount saMaxAmount(currIssuer.first, STAmount saMaxAmount(currIssuer.first,
currIssuer.second.isNonZero() ? currIssuer.second : currIssuer.second.isNonZero() ? currIssuer.second :
(currIssuer.first.isZero() ? ACCOUNT_XRP : raSrcAccount.getAccountID()), 1); (currIssuer.first.isZero() ? ACCOUNT_XRP : raSrcAccount.getAccountID()), 1);
saMaxAmount.negate();
cLog(lsDEBUG) << "Paths found, calling rippleCalc";
TER terResult = RippleCalc::rippleCalc(lesSandbox, saMaxAmountAct, saDstAmountAct, TER terResult = RippleCalc::rippleCalc(lesSandbox, saMaxAmountAct, saDstAmountAct,
vpsExpanded, saMaxAmount, saDstAmount, raDstAccount.getAccountID(), raSrcAccount.getAccountID(), vpsExpanded, saMaxAmount, saDstAmount, raDstAccount.getAccountID(), raSrcAccount.getAccountID(),
spsPaths, false, false, false, true); spsPaths, false, false, false, true);
@@ -250,6 +269,14 @@ bool PFRequest::doUpdate(RLCache::ref cache, bool fast)
jvEntry["paths_computed"] = spsPaths.getJson(0); jvEntry["paths_computed"] = spsPaths.getJson(0);
jvArray.append(jvEntry); jvArray.append(jvEntry);
} }
else
{
cLog(lsINFO) << "rippleCalc returns " << transHuman(terResult);
}
}
else
{
cLog(lsINFO) << "No paths found";
} }
} }
jvStatus["alternatives"] = jvArray; jvStatus["alternatives"] = jvArray;