Omit default paths from pathfinder results.

This commit is contained in:
Arthur Britto
2012-12-11 14:03:32 -08:00
parent 42e3453073
commit a1915bd899
2 changed files with 32 additions and 11 deletions

View File

@@ -77,7 +77,6 @@ PathOption::PathOption(PathOption::pointer other)
// Return true, if path is a default path with an element. // Return true, if path is a default path with an element.
// A path is a default path if it is implied via src, dst, send, and sendmax. // A path is a default path if it is implied via src, dst, send, and sendmax.
// XXX Could be determined via STAmount
bool Pathfinder::bDefaultPath(const STPath& spPath) bool Pathfinder::bDefaultPath(const STPath& spPath)
{ {
if (2 == spPath.mPath.size()) { if (2 == spPath.mPath.size()) {
@@ -87,6 +86,15 @@ bool Pathfinder::bDefaultPath(const STPath& spPath)
return true; return true;
} }
if (!mPsDefault)
{
// No default path.
// There might not be a direct credit line or there may be no implied nodes
// in send and sendmax.
return false; // Didn't generate a default path. So can't match.
}
PathState::pointer pspCurrent = boost::make_shared<PathState>(mDstAmount, mSrcAmount, mLedger); PathState::pointer pspCurrent = boost::make_shared<PathState>(mDstAmount, mSrcAmount, mLedger);
if (pspCurrent) if (pspCurrent)
@@ -98,6 +106,8 @@ bool Pathfinder::bDefaultPath(const STPath& spPath)
bDefault = pspCurrent->vpnNodes == mPsDefault->vpnNodes; bDefault = pspCurrent->vpnNodes == mPsDefault->vpnNodes;
cLog(lsDEBUG) << "findPaths: expanded path: " << pspCurrent->getJson();
// Path is a default (implied). Don't need to add it to return set. // Path is a default (implied). Don't need to add it to return set.
cLog(lsDEBUG) << "findPaths: default path: indirect: " << spPath.getJson(0); cLog(lsDEBUG) << "findPaths: default path: indirect: " << spPath.getJson(0);
@@ -119,13 +129,23 @@ Pathfinder::Pathfinder(const RippleAddress& uSrcAccountID, const RippleAddress&
// Construct the default path for later comparison. // Construct the default path for later comparison.
mPsDefault = boost::make_shared<PathState>(mDstAmount, mSrcAmount, mLedger); PathState::pointer psDefault = boost::make_shared<PathState>(mDstAmount, mSrcAmount, mLedger);
if (mPsDefault) if (psDefault)
{ {
LedgerEntrySet lesActive(mLedger); LedgerEntrySet lesActive(mLedger);
mPsDefault->setExpanded(lesActive, STPath(), mDstAccountID, mSrcAccountID); psDefault->setExpanded(lesActive, STPath(), mDstAccountID, mSrcAccountID);
if (tesSUCCESS == psDefault->terStatus)
{
cLog(lsDEBUG) << "Pathfinder: reference path: " << psDefault->getJson();
mPsDefault = psDefault;
}
else
{
cLog(lsDEBUG) << "Pathfinder: reference path: NONE: " << transToken(psDefault->terStatus);
}
} }
} }
@@ -150,13 +170,7 @@ bool Pathfinder::findPaths(int maxSearchSteps, int maxPay, STPathSet& retPathSet
% RippleAddress::createHumanAccountID(mSrcIssuerID) % RippleAddress::createHumanAccountID(mSrcIssuerID)
); );
if (!mPsDefault) if (mLedger)
{
cLog(lsDEBUG) << boost::str(boost::format("findPaths: failed to generate default path."));
return false;
}
else if (mLedger)
{ {
std::queue<STPath> pqueue; std::queue<STPath> pqueue;
STPathElement ele(mSrcAccountID, STPathElement ele(mSrcAccountID,

View File

@@ -62,6 +62,7 @@ bool PathState::lessPriority(PathState& lhs, PathState& rhs)
// - A node names it's output. // - A node names it's output.
// - A ripple nodes output issuer must be the node's account or the next node's account. // - A ripple nodes output issuer must be the node's account or the next node's account.
// - Offers can only go directly to another offer if the currency and issuer are an exact match. // - Offers can only go directly to another offer if the currency and issuer are an exact match.
// - Real issuers must be specified for non-XRP.
TER PathState::pushImply( TER PathState::pushImply(
const uint160& uAccountID, // --> Delivering to this account. const uint160& uAccountID, // --> Delivering to this account.
const uint160& uCurrencyID, // --> Delivering this currency. const uint160& uCurrencyID, // --> Delivering this currency.
@@ -186,6 +187,8 @@ TER PathState::pushNode(
else else
{ {
// Add required intermediate nodes to deliver to current account. // Add required intermediate nodes to deliver to current account.
cLog(lsDEBUG) << "pushNode: imply for account.";
terResult = pushImply( terResult = pushImply(
pnCur.uAccountID, // Current account. pnCur.uAccountID, // Current account.
pnCur.uCurrencyID, // Wanted currency. pnCur.uCurrencyID, // Wanted currency.
@@ -262,6 +265,7 @@ TER PathState::pushNode(
else if (!!pnPrv.uAccountID) else if (!!pnPrv.uAccountID)
{ {
// Previous is an account. // Previous is an account.
cLog(lsDEBUG) << "pushNode: imply for offer.";
// Insert intermediary issuer account if needed. // Insert intermediary issuer account if needed.
terResult = pushImply( terResult = pushImply(
@@ -364,7 +368,10 @@ cLog(lsDEBUG) << boost::str(boost::format("PathState: sender implied: account=%s
BOOST_FOREACH(const STPathElement& speElement, spSourcePath) BOOST_FOREACH(const STPathElement& speElement, spSourcePath)
{ {
if (tesSUCCESS == terStatus) if (tesSUCCESS == terStatus)
{
cLog(lsDEBUG) << boost::str(boost::format("PathState: element in path:"));
terStatus = pushNode(speElement.getNodeType(), speElement.getAccountID(), speElement.getCurrency(), speElement.getIssuerID()); terStatus = pushNode(speElement.getNodeType(), speElement.getAccountID(), speElement.getCurrency(), speElement.getIssuerID());
}
} }
const PaymentNode& pnPrv = vpnNodes.back(); const PaymentNode& pnPrv = vpnNodes.back();