mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Use continuation in legacy pathfinding:
Handle legacy (ripple_path_find) requests that don't specify a ledger the same way regular path_find requests are. This provides a performance improvement for these requests and reduces the problem of server busy errors. Conflicts: src/ripple/app/paths/PathRequest.cpp
This commit is contained in:
@@ -58,6 +58,27 @@ PathRequest::PathRequest (
|
||||
ptCreated = boost::posix_time::microsec_clock::universal_time ();
|
||||
}
|
||||
|
||||
PathRequest::PathRequest (
|
||||
std::function <void(void)> const& completion,
|
||||
int id,
|
||||
PathRequests& owner,
|
||||
beast::Journal journal)
|
||||
: m_journal (journal)
|
||||
, mOwner (owner)
|
||||
, fCompletion (completion)
|
||||
, jvStatus (Json::objectValue)
|
||||
, bValid (false)
|
||||
, mLastIndex (0)
|
||||
, mInProgress (false)
|
||||
, iLastLevel (0)
|
||||
, bLastSuccess (false)
|
||||
, iIdentifier (id)
|
||||
{
|
||||
if (m_journal.debug)
|
||||
m_journal.debug << iIdentifier << " created";
|
||||
ptCreated = boost::posix_time::microsec_clock::universal_time ();
|
||||
}
|
||||
|
||||
static std::string const get_milli_diff (
|
||||
boost::posix_time::ptime const& after,
|
||||
boost::posix_time::ptime
|
||||
@@ -132,12 +153,23 @@ bool PathRequest::needsUpdate (bool newOnly, LedgerIndex index)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PathRequest::hasCompletion ()
|
||||
{
|
||||
return bool (fCompletion);
|
||||
}
|
||||
|
||||
void PathRequest::updateComplete ()
|
||||
{
|
||||
ScopedLockType sl (mIndexLock);
|
||||
|
||||
assert (mInProgress);
|
||||
mInProgress = false;
|
||||
|
||||
if (fCompletion)
|
||||
{
|
||||
fCompletion();
|
||||
fCompletion = std::function<void (void)>();
|
||||
}
|
||||
}
|
||||
|
||||
bool PathRequest::isValid (RippleLineCache::ref crCache)
|
||||
@@ -407,6 +439,15 @@ Json::Value PathRequest::doUpdate (RippleLineCache::ref cache, bool fast)
|
||||
}
|
||||
}
|
||||
|
||||
if (hasCompletion ())
|
||||
{
|
||||
// Old ripple_path_find API gives destination_currencies
|
||||
auto& destCurrencies = (jvStatus[jss::destination_currencies] = Json::arrayValue);
|
||||
auto usCurrencies = accountDestCurrencies (*raDstAccount, cache, true);
|
||||
for (auto const& c : usCurrencies)
|
||||
destCurrencies.append (to_string (c));
|
||||
}
|
||||
|
||||
jvStatus[jss::source_account] = getApp().accountIDCache().toBase58(*raSrcAccount);
|
||||
jvStatus[jss::destination_account] = getApp().accountIDCache().toBase58(*raDstAccount);
|
||||
jvStatus[jss::destination_amount] = saDstAmount.getJson (0);
|
||||
@@ -535,6 +576,13 @@ Json::Value PathRequest::doUpdate (RippleLineCache::ref cache, bool fast)
|
||||
|
||||
jvEntry[jss::source_amount] = rc.actualAmountIn.getJson (0);
|
||||
jvEntry[jss::paths_computed] = spsPaths.getJson (0);
|
||||
|
||||
if (hasCompletion ())
|
||||
{
|
||||
// Old ripple_path_find API requires this
|
||||
jvEntry[jss::paths_canonical] = Json::arrayValue;
|
||||
}
|
||||
|
||||
found = true;
|
||||
jvArray.append (jvEntry);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user