Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Further incremental improvements to path finding memory usage #4111

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 23 additions & 14 deletions src/ripple/app/paths/AccountCurrencies.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,23 @@ accountSourceCurrencies(
if (includeXRP)
currencies.insert(xrpCurrency());

for (auto const& rspEntry : lrCache->getRippleLines(account))
if (auto const lines =
lrCache->getRippleLines(account, LineDirection::outgoing))
{
auto& saBalance = rspEntry.getBalance();

// Filter out non
if (saBalance > beast::zero
// Have IOUs to send.
|| (rspEntry.getLimitPeer()
// Peer extends credit.
&& ((-saBalance) < rspEntry.getLimitPeer()))) // Credit left.
for (auto const& rspEntry : *lines)
{
currencies.insert(saBalance.getCurrency());
auto& saBalance = rspEntry.getBalance();

// Filter out non
if (saBalance > beast::zero
// Have IOUs to send.
||
(rspEntry.getLimitPeer()
// Peer extends credit.
&& ((-saBalance) < rspEntry.getLimitPeer()))) // Credit left.
{
currencies.insert(saBalance.getCurrency());
}
}
}

Expand All @@ -64,12 +69,16 @@ accountDestCurrencies(
currencies.insert(xrpCurrency());
// Even if account doesn't exist

for (auto const& rspEntry : lrCache->getRippleLines(account))
if (auto const lines =
lrCache->getRippleLines(account, LineDirection::outgoing))
{
auto& saBalance = rspEntry.getBalance();
for (auto const& rspEntry : *lines)
{
auto& saBalance = rspEntry.getBalance();

if (saBalance < rspEntry.getLimit()) // Can take more
currencies.insert(saBalance.getCurrency());
if (saBalance < rspEntry.getLimit()) // Can take more
currencies.insert(saBalance.getCurrency());
}
}

currencies.erase(badCurrency());
Expand Down
2 changes: 2 additions & 0 deletions src/ripple/app/paths/PathRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,8 @@ PathRequest::doUpdate(
jvStatus = newStatus;
}

JLOG(m_journal.debug())
<< iIdentifier << " update finished " << (fast ? "fast" : "normal");
return newStatus;
}

Expand Down
248 changes: 132 additions & 116 deletions src/ripple/app/paths/Pathfinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,7 @@ int
Pathfinder::getPathsOut(
Currency const& currency,
AccountID const& account,
LineDirection direction,
bool isDstCurrency,
AccountID const& dstAccount,
std::function<bool(void)> const& continueCallback)
Expand Down Expand Up @@ -735,33 +736,37 @@ Pathfinder::getPathsOut(
{
count = app_.getOrderBookDB().getBookSize(issue);

for (auto const& rspEntry : mRLCache->getRippleLines(account))
if (auto const lines = mRLCache->getRippleLines(account, direction))
{
if (currency != rspEntry.getLimit().getCurrency())
for (auto const& rspEntry : *lines)
{
}
else if (
rspEntry.getBalance() <= beast::zero &&
(!rspEntry.getLimitPeer() ||
-rspEntry.getBalance() >= rspEntry.getLimitPeer() ||
(bAuthRequired && !rspEntry.getAuth())))
{
}
else if (isDstCurrency && dstAccount == rspEntry.getAccountIDPeer())
{
count += 10000; // count a path to the destination extra
}
else if (rspEntry.getNoRipplePeer())
{
// This probably isn't a useful path out
}
else if (rspEntry.getFreezePeer())
{
// Not a useful path out
}
else
{
++count;
if (currency != rspEntry.getLimit().getCurrency())
{
}
else if (
rspEntry.getBalance() <= beast::zero &&
(!rspEntry.getLimitPeer() ||
-rspEntry.getBalance() >= rspEntry.getLimitPeer() ||
(bAuthRequired && !rspEntry.getAuth())))
{
}
else if (
isDstCurrency && dstAccount == rspEntry.getAccountIDPeer())
{
count += 10000; // count a path to the destination extra
}
else if (rspEntry.getNoRipplePeer())
{
// This probably isn't a useful path out
}
else if (rspEntry.getFreezePeer())
{
// Not a useful path out
}
else
{
++count;
}
}
}
}
Expand Down Expand Up @@ -976,117 +981,128 @@ Pathfinder::addLink(
bool const bIsNoRippleOut(isNoRippleOut(currentPath));
bool const bDestOnly(addFlags & afAC_LAST);

auto& rippleLines(mRLCache->getRippleLines(uEndAccount));

AccountCandidates candidates;
candidates.reserve(rippleLines.size());

for (auto const& rs : rippleLines)
if (auto const lines = mRLCache->getRippleLines(
uEndAccount,
bIsNoRippleOut ? LineDirection::incoming
: LineDirection::outgoing))
{
if (continueCallback && !continueCallback())
return;
auto const& acct = rs.getAccountIDPeer();
auto& rippleLines = *lines;

if (hasEffectiveDestination && (acct == mDstAccount))
{
// We skipped the gateway
continue;
}

bool bToDestination = acct == mEffectiveDst;
AccountCandidates candidates;
candidates.reserve(rippleLines.size());

if (bDestOnly && !bToDestination)
for (auto const& rs : rippleLines)
{
continue;
}
if (continueCallback && !continueCallback())
return;
auto const& acct = rs.getAccountIDPeer();
LineDirection const direction = rs.getDirectionPeer();

if ((uEndCurrency == rs.getLimit().getCurrency()) &&
!currentPath.hasSeen(acct, uEndCurrency, acct))
{
// path is for correct currency and has not been seen
if (rs.getBalance() <= beast::zero &&
(!rs.getLimitPeer() ||
-rs.getBalance() >= rs.getLimitPeer() ||
(bRequireAuth && !rs.getAuth())))
if (hasEffectiveDestination && (acct == mDstAccount))
{
// path has no credit
// We skipped the gateway
continue;
}
else if (bIsNoRippleOut && rs.getNoRipple())

bool bToDestination = acct == mEffectiveDst;

if (bDestOnly && !bToDestination)
{
// Can't leave on this path
continue;
}
else if (bToDestination)

if ((uEndCurrency == rs.getLimit().getCurrency()) &&
!currentPath.hasSeen(acct, uEndCurrency, acct))
{
// destination is always worth trying
if (uEndCurrency == mDstAmount.getCurrency())
// path is for correct currency and has not been
// seen
if (rs.getBalance() <= beast::zero &&
(!rs.getLimitPeer() ||
-rs.getBalance() >= rs.getLimitPeer() ||
(bRequireAuth && !rs.getAuth())))
{
// path has no credit
}
else if (bIsNoRippleOut && rs.getNoRipple())
{
// Can't leave on this path
}
else if (bToDestination)
{
// this is a complete path
if (!currentPath.empty())
// destination is always worth trying
if (uEndCurrency == mDstAmount.getCurrency())
{
JLOG(j_.trace())
<< "complete path found ae: "
<< currentPath.getJson(
JsonOptions::none);
addUniquePath(mCompletePaths, currentPath);
// this is a complete path
if (!currentPath.empty())
{
JLOG(j_.trace())
<< "complete path found ae: "
<< currentPath.getJson(
JsonOptions::none);
addUniquePath(
mCompletePaths, currentPath);
}
}
else if (!bDestOnly)
{
// this is a high-priority candidate
candidates.push_back(
{AccountCandidate::highPriority, acct});
}
}
else if (!bDestOnly)
else if (acct == mSrcAccount)
{
// this is a high-priority candidate
candidates.push_back(
{AccountCandidate::highPriority, acct});
// going back to the source is bad
}
else
{
// save this candidate
int out = getPathsOut(
uEndCurrency,
acct,
direction,
bIsEndCurrency,
mEffectiveDst,
continueCallback);
if (out)
candidates.push_back({out, acct});
}
}
else if (acct == mSrcAccount)
{
// going back to the source is bad
}
else
{
// save this candidate
int out = getPathsOut(
uEndCurrency,
acct,
bIsEndCurrency,
mEffectiveDst,
continueCallback);
if (out)
candidates.push_back({out, acct});
}
}
}

if (!candidates.empty())
{
std::sort(
candidates.begin(),
candidates.end(),
std::bind(
compareAccountCandidate,
mLedger->seq(),
std::placeholders::_1,
std::placeholders::_2));

int count = candidates.size();
// allow more paths from source
if ((count > 10) && (uEndAccount != mSrcAccount))
count = 10;
else if (count > 50)
count = 50;

auto it = candidates.begin();
while (count-- != 0)
if (!candidates.empty())
{
if (continueCallback && !continueCallback())
return;
// Add accounts to incompletePaths
STPathElement pathElement(
STPathElement::typeAccount,
it->account,
uEndCurrency,
it->account);
incompletePaths.assembleAdd(currentPath, pathElement);
++it;
std::sort(
candidates.begin(),
candidates.end(),
std::bind(
compareAccountCandidate,
mLedger->seq(),
std::placeholders::_1,
std::placeholders::_2));

int count = candidates.size();
// allow more paths from source
if ((count > 10) && (uEndAccount != mSrcAccount))
count = 10;
else if (count > 50)
count = 50;

auto it = candidates.begin();
while (count-- != 0)
{
if (continueCallback && !continueCallback())
return;
// Add accounts to incompletePaths
STPathElement pathElement(
STPathElement::typeAccount,
it->account,
uEndCurrency,
it->account);
incompletePaths.assembleAdd(
currentPath, pathElement);
++it;
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/ripple/app/paths/Pathfinder.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ class Pathfinder : public CountedObject<Pathfinder>
getPathsOut(
Currency const& currency,
AccountID const& account,
LineDirection direction,
bool isDestCurrency,
AccountID const& dest,
std::function<bool(void)> const& continueCallback);
Expand Down
Loading