Some pathfinding fixes.

This commit is contained in:
Arthur Britto
2012-12-07 17:47:29 -08:00
parent bfce6b4ec1
commit e03ed39fca
3 changed files with 54 additions and 35 deletions

View File

@@ -761,10 +761,8 @@ Json::Value RPCHandler::doRipplePathFind(Json::Value jvRequest)
return rpcError(rpcINVALID_PARAMS); return rpcError(rpcINVALID_PARAMS);
} }
STPathSet spsComputed; STPathSet spsComputed;
std::vector<PathState::pointer> vpsExpanded; Pathfinder pf(raSrc, raDst, uSrcCurrencyID, uSrcIssuerID, saDstAmount);
Pathfinder pf(raSrc, raDst, uSrcCurrencyID, uSrcIssuerID, saDstAmount);
if (!pf.findPaths(5, 1, spsComputed)) if (!pf.findPaths(5, 1, spsComputed))
{ {
@@ -772,37 +770,40 @@ Json::Value RPCHandler::doRipplePathFind(Json::Value jvRequest)
} }
else else
{ {
STAmount saMaxAmountAct; std::vector<PathState::pointer> vpsExpanded;
STAmount saDstAmountAct; STAmount saMaxAmountAct;
STAmount saMaxAmount( STAmount saDstAmountAct;
uSrcCurrencyID, STAmount saMaxAmount(
!!uSrcIssuerID uSrcCurrencyID,
? uSrcIssuerID !!uSrcIssuerID
: !!uSrcCurrencyID ? uSrcIssuerID
? raSrc.getAccountID() : !!uSrcCurrencyID
: ACCOUNT_XRP, ? raSrc.getAccountID()
1); : ACCOUNT_XRP,
1);
saMaxAmount.negate(); saMaxAmount.negate();
cLog(lsDEBUG) << "ripple_path_find: PATHS: " << spsComputed.size();
TER terResult = TER terResult =
RippleCalc::rippleCalc( RippleCalc::rippleCalc(
lesSnapshot, lesSnapshot,
saMaxAmountAct, saMaxAmountAct, // <--
saDstAmountAct, saDstAmountAct, // <--
vpsExpanded, vpsExpanded, // <--
saMaxAmount, // --> Amount to send is unlimited to get an estimate. saMaxAmount, // --> Amount to send is unlimited to get an estimate.
saDstAmount, // --> Amount to deliver. saDstAmount, // --> Amount to deliver.
raDst.getAccountID(), // --> Account to deliver to. raDst.getAccountID(), // --> Account to deliver to.
raSrc.getAccountID(), // --> Account sending from. raSrc.getAccountID(), // --> Account sending from.
spsComputed, // --> Path set. spsComputed, // --> Path set.
false, // --> Don't allow partial payment. This is for normal fill or kill payments. false, // --> Don't allow partial payment. This is for normal fill or kill payments.
// Must achive delivery goal. // Must achieve delivery goal.
false, // --> Don't limit quality. Average quality is wanted for normal payments. false, // --> Don't limit quality. Average quality is wanted for normal payments.
false, // --> Allow direct ripple. false, // --> Allow direct ripple to be added to path set. to path set.
true); // --> Stand alone mode, no point in deleting unfundeds. true); // --> Stand alone mode, no point in deleting unfundeds.
// cLog(lsDEBUG) << "ripple_path_find: PATHS IN: " << spsComputed.size() << " : " << spsComputed.getJson(0);
// cLog(lsDEBUG) << "ripple_path_find: PATHS EXP: " << vpsExpanded.size();
cLog(lsDEBUG) cLog(lsDEBUG)
<< boost::str(boost::format("ripple_path_find: saMaxAmount=%s saDstAmount=%s saMaxAmountAct=%s saDstAmountAct=%s") << boost::str(boost::format("ripple_path_find: saMaxAmount=%s saDstAmount=%s saMaxAmountAct=%s saDstAmountAct=%s")
% saMaxAmount % saMaxAmount
@@ -816,7 +817,9 @@ Json::Value RPCHandler::doRipplePathFind(Json::Value jvRequest)
STPathSet spsCanonical; STPathSet spsCanonical;
RippleCalc::setCanonical(spsCanonical, vpsExpanded); // Reuse the expanded as it would need to be calcuated anyway to produce the canonical.
// (At least unless we make a direct canonical.)
RippleCalc::setCanonical(spsCanonical, vpsExpanded, false);
jvEntry["source_amount"] = saMaxAmountAct.getJson(0); jvEntry["source_amount"] = saMaxAmountAct.getJson(0);
// jvEntry["paths_expanded"] = vpsExpanded.getJson(0); // jvEntry["paths_expanded"] = vpsExpanded.getJson(0);
@@ -840,6 +843,7 @@ Json::Value RPCHandler::doRipplePathFind(Json::Value jvRequest)
} }
} }
// Each alternative differs by source currency.
jvResult["alternatives"] = jvArray; jvResult["alternatives"] = jvArray;
} }

View File

@@ -580,24 +580,39 @@ void PathState::setCanonical(
% getJson()); % getJson());
} }
void RippleCalc::setCanonical(STPathSet& spsDst, const std::vector<PathState::pointer>& vpsExpanded) void RippleCalc::setCanonical(STPathSet& spsDst, const std::vector<PathState::pointer>& vpsExpanded, bool bKeepDefault)
{ {
// cLog(lsDEBUG) << boost::str(boost::format("SET: setCanonical> %d") % vpsExpanded.size());
BOOST_FOREACH(PathState::ref pspExpanded, vpsExpanded) BOOST_FOREACH(PathState::ref pspExpanded, vpsExpanded)
{ {
PathState psCanonical(*pspExpanded, false); // Obvious defaults have 2 nodes when expanded.
if (bKeepDefault || 2 != pspExpanded->vpnNodes.size())
psCanonical.setCanonical(*pspExpanded);
STPath spCanonical;
BOOST_FOREACH(const PaymentNode& pnElem, psCanonical.vpnNodes)
{ {
STPathElement speElem(pnElem.uFlags, pnElem.uAccountID, pnElem.uCurrencyID, pnElem.uIssuerID); PathState psCanonical(*pspExpanded, false);
spCanonical.addElement(speElem);
}
spsDst.addPath(spCanonical); // cLog(lsDEBUG) << boost::str(boost::format("SET: setCanonical: %d %d %s") % bKeepDirect % pspExpanded->vpnNodes.size() % pspExpanded->getJson());
psCanonical.setCanonical(*pspExpanded);
// Non-obvious defaults have 0 nodes when canonicalized.
if (bKeepDefault || psCanonical.vpnNodes.size())
{
STPath spCanonical;
BOOST_FOREACH(const PaymentNode& pnElem, psCanonical.vpnNodes)
{
STPathElement speElem(pnElem.uFlags, pnElem.uAccountID, pnElem.uCurrencyID, pnElem.uIssuerID);
spCanonical.addElement(speElem);
}
spsDst.addPath(spCanonical);
}
}
} }
// cLog(lsDEBUG) << boost::str(boost::format("SET: setCanonical< %d") % spsDst.size());
} }
Json::Value PathState::getJson() const Json::Value PathState::getJson() const

View File

@@ -210,7 +210,7 @@ public:
const bool bStandAlone const bool bStandAlone
); );
static void setCanonical(STPathSet& spsDst, const std::vector<PathState::pointer>& vpsExpanded); static void setCanonical(STPathSet& spsDst, const std::vector<PathState::pointer>& vpsExpanded, bool bKeepDefault);
}; };
#endif #endif