Don't count forced issuer nodes after exchanges because we didn't have to find them.

Drop the default maximum path length to four because exchanges to non-XRP aren't overcounted.
This commit is contained in:
JoelKatz
2013-04-12 16:11:51 -07:00
parent 2e39dfc15a
commit 0359ab5d46
2 changed files with 16 additions and 6 deletions

View File

@@ -251,7 +251,7 @@
# When searching for paths, the maximum number of nodes allowed. This can take
# exponentially more resources as the size is increased.
#
# The default is: 5
# The default is: 4
#
# [rpc_startup]
# Specify a list of RPC commands to run at startup.

View File

@@ -118,7 +118,7 @@ bool Pathfinder::bDefaultPath(const STPath& spPath)
}
typedef std::pair<int, uint160> candidate_t;
bool candCmp(uint32 seq, const candidate_t& first, const candidate_t& second)
static bool candCmp(uint32 seq, const candidate_t& first, const candidate_t& second)
{
if (first.first < second.first)
return false;
@@ -127,6 +127,17 @@ bool candCmp(uint32 seq, const candidate_t& first, const candidate_t& second)
return (first.first ^ seq) < (second.first ^ seq);
}
static int getEffectiveLength(const STPath& spPath)
{ // don't count exchanges to non-XRP currencies twice (only count the forced issuer account node)
int length = 0;
for (std::vector<STPathElement>::const_iterator it = spPath.begin(); it != spPath.end(); ++it)
{
if (it->isAccount() || it->getCurrency().isZero())
++length;
}
return length;
}
Pathfinder::Pathfinder(Ledger::ref ledger,
const RippleAddress& uSrcAccountID, const RippleAddress& uDstAccountID,
const uint160& uSrcCurrencyID, const uint160& uSrcIssuerID, const STAmount& saDstAmount, bool& bValid)
@@ -360,7 +371,8 @@ bool Pathfinder::findPaths(const unsigned int iMaxSteps, const unsigned int iMax
% STAmount::createHumanCurrency(speEnd.mCurrencyID)
% RippleAddress::createHumanAccountID(speEnd.mIssuerID));
if (spPath.mPath.size() >= iMaxSteps)
int length = getEffectiveLength(spPath.mPath);
if (length >= iMaxSteps)
{
// Path is at maximum size. Don't want to add more.
@@ -369,12 +381,10 @@ bool Pathfinder::findPaths(const unsigned int iMaxSteps, const unsigned int iMax
continue;
}
bool isLast = (spPath.mPath.size() == (iMaxSteps - 1));
bool isLast = (length == (iMaxSteps - 1));
if (!speEnd.mCurrencyID)
{
// XXX Might restrict the number of times bridging through XRP.
// Cursor is for XRP, continue with qualifying books: XRP -> non-XRP
std::vector<OrderBook::pointer> xrpBooks;
theApp->getOrderBookDB().getBooksByTakerPays(ACCOUNT_XRP, CURRENCY_XRP, xrpBooks);