Skip to content

Commit

Permalink
Replace account[Source,Dest]Currencies() with account[Source,Dest]Ass…
Browse files Browse the repository at this point in the history
…ets()
  • Loading branch information
gregtatcam committed Jan 18, 2025
1 parent a105295 commit b5ee270
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 55 deletions.
2 changes: 1 addition & 1 deletion src/test/app/Path_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

#include <test/jtx.h>
#include <test/jtx/envconfig.h>
#include <xrpld/app/paths/AccountCurrencies.h>
#include <xrpld/app/paths/AccountAssets.h>
#include <xrpld/core/JobQueue.h>
#include <xrpld/rpc/Context.h>
#include <xrpld/rpc/RPCHandler.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@
*/
//==============================================================================

#include <xrpld/app/paths/AccountCurrencies.h>
#include <xrpld/app/paths/AccountAssets.h>

namespace ripple {

hash_set<Currency>
accountSourceCurrencies(
hash_set<PathAsset>
accountSourceAssets(
AccountID const& account,
std::shared_ptr<AssetCache> const& lrCache,
bool includeXRP)
{
hash_set<Currency> currencies;
hash_set<PathAsset> assets;

// YYY Only bother if they are above reserve
if (includeXRP)
currencies.insert(xrpCurrency());
assets.insert(xrpCurrency());

if (auto const lines =
lrCache->getRippleLines(account, LineDirection::outgoing))
Expand All @@ -48,25 +48,35 @@ accountSourceCurrencies(
// Peer extends credit.
&& ((-saBalance) < rspEntry.getLimitPeer()))) // Credit left.
{
currencies.insert(saBalance.getCurrency());
assets.insert(saBalance.getCurrency());
}
}
}

currencies.erase(badCurrency());
return currencies;
assets.erase(badCurrency());

if (auto const mpts = lrCache->getMPTs(account))
{
for (auto const& rspEntry : *mpts)
{
if (!rspEntry.isZeroBalance() && !rspEntry.isMaxedOut())
assets.insert(rspEntry.getMptID());
}
}

return assets;
}

hash_set<Currency>
accountDestCurrencies(
hash_set<PathAsset>
accountDestAssets(
AccountID const& account,
std::shared_ptr<AssetCache> const& lrCache,
bool includeXRP)
{
hash_set<Currency> currencies;
hash_set<PathAsset> assets;

if (includeXRP)
currencies.insert(xrpCurrency());
assets.insert(xrpCurrency());
// Even if account doesn't exist

if (auto const lines =
Expand All @@ -77,12 +87,22 @@ accountDestCurrencies(
auto& saBalance = rspEntry.getBalance();

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

assets.erase(badCurrency());

if (auto const mpts = lrCache->getMPTs(account))
{
for (auto const& rspEntry : *mpts)
{
if (rspEntry.isZeroBalance() && !rspEntry.isMaxedOut())
assets.insert(rspEntry.getMptID());
}
}

currencies.erase(badCurrency());
return currencies;
return assets;
}

} // namespace ripple
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@

namespace ripple {

hash_set<Currency>
accountDestCurrencies(
hash_set<PathAsset>
accountDestAssets(
AccountID const& account,
std::shared_ptr<AssetCache> const& cache,
bool includeXRP);

hash_set<Currency>
accountSourceCurrencies(
hash_set<PathAsset>
accountSourceAssets(
AccountID const& account,
std::shared_ptr<AssetCache> const& lrLedger,
bool includeXRP);
Expand Down
63 changes: 28 additions & 35 deletions src/xrpld/app/paths/PathRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include <xrpld/app/main/Application.h>
#include <xrpld/app/misc/LoadFeeTrack.h>
#include <xrpld/app/misc/NetworkOPs.h>
#include <xrpld/app/paths/AccountCurrencies.h>
#include <xrpld/app/paths/AccountAssets.h>
#include <xrpld/app/paths/PathRequest.h>
#include <xrpld/app/paths/PathRequests.h>
#include <xrpld/app/paths/RippleCalc.h>
Expand Down Expand Up @@ -218,17 +218,11 @@ PathRequest::isValid(std::shared_ptr<AssetCache> const& crCache)
{
bool const disallowXRP(sleDest->getFlags() & lsfDisallowXRP);

auto usDestCurrID =
accountDestCurrencies(*raDstAccount, crCache, !disallowXRP);
auto const destAssets =
accountDestAssets(*raDstAccount, crCache, !disallowXRP);

for (auto const& currency : usDestCurrID)
jvDestCur.append(to_string(currency));

if (auto mpts = crCache->getMPTs(*raDstAccount))
{
for (auto const& mpt : *mpts)
jvDestCur.append(to_string(mpt.getMptID()));
}
for (auto const& asset : destAssets)
jvDestCur.append(to_string(asset));

jvStatus[jss::destination_tag] =
(sleDest->getFlags() & lsfRequireDestTag);
Expand Down Expand Up @@ -545,26 +539,30 @@ PathRequest::findPaths(
}
if (sourceAssets.empty())
{
auto currencies = accountSourceCurrencies(*raSrcAccount, cache, true);
auto assets = accountSourceAssets(*raSrcAccount, cache, true);
bool const sameAccount = *raSrcAccount == *raDstAccount;
for (auto const& c : currencies)
for (auto const& asset : assets)
{
if (!sameAccount ||
(saDstAmount.holds<Issue>() &&
c != saDstAmount.get<Issue>().currency))
if (!std::visit(
[&]<typename TAsset>(TAsset const& a) {
if (!sameAccount || a != saDstAmount.asset())
{
if (sourceAssets.size() >=
RPC::Tuning::max_auto_src_cur)
return false;
if constexpr (std::is_same_v<TAsset, Currency>)
sourceAssets.insert(Issue{
a,
a.isZero() ? xrpAccount() : *raSrcAccount});
else
sourceAssets.insert(MPTIssue{a});
}
return true;
},
asset.value()))
{
if (sourceAssets.size() >= RPC::Tuning::max_auto_src_cur)
return false;
sourceAssets.insert(
Issue{c, c.isZero() ? xrpAccount() : *raSrcAccount});
}
}
if (auto mpts = cache->getMPTs(*raSrcAccount))
{
if (sourceAssets.size() >= RPC::Tuning::max_auto_src_cur)
return false;
for (auto const& mpt : *mpts)
sourceAssets.insert(MPTIssue{mpt});
}
}
}

Expand Down Expand Up @@ -731,14 +729,9 @@ PathRequest::doUpdate(
// Old ripple_path_find API gives destination_currencies
auto& destAssets =
(newStatus[jss::destination_currencies] = Json::arrayValue);
auto usAssets = accountDestCurrencies(*raDstAccount, cache, true);
for (auto const& c : usAssets)
destAssets.append(to_string(c));
if (auto mpts = cache->getMPTs(*raDstAccount))
{
for (auto const& mpt : *mpts)
destAssets.append(to_string(mpt.getMptID()));
}
auto const assets = accountDestAssets(*raDstAccount, cache, true);
for (auto const& asset : assets)
destAssets.append(to_string(asset));
}

newStatus[jss::source_account] = toBase58(*raSrcAccount);
Expand Down

0 comments on commit b5ee270

Please sign in to comment.