mirror of
https://github.com/XRPLF/rippled.git
synced 2026-06-05 17:56:49 +00:00
Make PahRequest and PathRequests interfaces
Signed-off-by: JCW <a1q123456@users.noreply.github.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
#include <xrpld/app/misc/setup_HashRouter.h>
|
||||
#include <xrpld/app/main/setup_HashRouter.h>
|
||||
#include <xrpld/core/Config.h>
|
||||
|
||||
#include <xrpl/basics/chrono.h>
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
#include <xrpld/app/main/LoadManager.h>
|
||||
#include <xrpld/app/main/NodeIdentity.h>
|
||||
#include <xrpld/app/main/NodeStoreScheduler.h>
|
||||
#include <xrpld/app/main/setup_HashRouter.h>
|
||||
#include <xrpld/app/main/setup_PathRequest.h>
|
||||
#include <xrpld/app/misc/AmendmentTable.h>
|
||||
#include <xrpld/app/misc/LoadFeeTrack.h>
|
||||
#include <xrpld/app/misc/NetworkOPs.h>
|
||||
@@ -21,7 +23,6 @@
|
||||
#include <xrpld/app/misc/TxQ.h>
|
||||
#include <xrpld/app/misc/ValidatorKeys.h>
|
||||
#include <xrpld/app/misc/ValidatorSite.h>
|
||||
#include <xrpld/app/misc/setup_HashRouter.h>
|
||||
#include <xrpld/app/paths/PathRequests.h>
|
||||
#include <xrpld/app/rdb/backend/SQLiteDatabase.h>
|
||||
#include <xrpld/app/rpc/LedgerToJson.h>
|
||||
@@ -360,7 +361,8 @@ public:
|
||||
{config_->PATH_SEARCH_MAX, config_->standalone()})
|
||||
|
||||
, m_pathRequests(std::make_unique<PathRequests>(
|
||||
*this,
|
||||
setup_PathRequest(*config_),
|
||||
*serviceRegistry_,
|
||||
logs_->journal("PathRequest"),
|
||||
m_collectorManager->collector()))
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include <xrpld/app/misc/setup_HashRouter.h>
|
||||
#include <xrpld/app/main/setup_HashRouter.h>
|
||||
#include <xrpld/core/Config.h>
|
||||
|
||||
#include <xrpl/basics/BasicConfig.h>
|
||||
16
src/xrpld/app/main/detail/setup_PathRequest.cpp
Normal file
16
src/xrpld/app/main/detail/setup_PathRequest.cpp
Normal file
@@ -0,0 +1,16 @@
|
||||
#include <xrpld/app/main/setup_PathRequest.h>
|
||||
#include <xrpld/core/Config.h>
|
||||
|
||||
namespace xrpl {
|
||||
|
||||
PathRequest::Setup
|
||||
setup_PathRequest(Config const& config)
|
||||
{
|
||||
PathRequest::Setup setup;
|
||||
setup.pathSearch = config.PATH_SEARCH;
|
||||
setup.pathSearchFast = config.PATH_SEARCH_FAST;
|
||||
setup.pathSearchMax = config.PATH_SEARCH_MAX;
|
||||
return setup;
|
||||
}
|
||||
|
||||
} // namespace xrpl
|
||||
17
src/xrpld/app/main/setup_PathRequest.h
Normal file
17
src/xrpld/app/main/setup_PathRequest.h
Normal file
@@ -0,0 +1,17 @@
|
||||
#ifndef XRPLD_APP_PATHS_SETUP_PATHREQUEST_H_INCLUDED
|
||||
#define XRPLD_APP_PATHS_SETUP_PATHREQUEST_H_INCLUDED
|
||||
|
||||
#include <xrpld/app/paths/PathRequest.h>
|
||||
|
||||
namespace xrpl {
|
||||
|
||||
// Forward declaration
|
||||
class Config;
|
||||
|
||||
/** Create PathRequest setup from configuration */
|
||||
PathRequest::Setup
|
||||
setup_PathRequest(Config const& config);
|
||||
|
||||
} // namespace xrpl
|
||||
|
||||
#endif
|
||||
@@ -1,12 +1,9 @@
|
||||
#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/PathRequest.h>
|
||||
#include <xrpld/app/paths/PathRequests.h>
|
||||
#include <xrpld/app/paths/RippleCalc.h>
|
||||
#include <xrpld/app/paths/detail/PathfinderUtils.h>
|
||||
#include <xrpld/core/Config.h>
|
||||
#include <xrpld/rpc/detail/Tuning.h>
|
||||
|
||||
#include <xrpl/basics/Log.h>
|
||||
@@ -21,12 +18,14 @@
|
||||
namespace xrpl {
|
||||
|
||||
PathRequest::PathRequest(
|
||||
Application& app,
|
||||
Setup const& setup,
|
||||
ServiceRegistry& registry,
|
||||
std::shared_ptr<InfoSub> const& subscriber,
|
||||
int id,
|
||||
PathRequests& owner,
|
||||
beast::Journal journal)
|
||||
: app_(app)
|
||||
: setup_(setup)
|
||||
, registry_(registry)
|
||||
, m_journal(journal)
|
||||
, mOwner(owner)
|
||||
, wpSubscriber(subscriber)
|
||||
@@ -43,13 +42,15 @@ PathRequest::PathRequest(
|
||||
}
|
||||
|
||||
PathRequest::PathRequest(
|
||||
Application& app,
|
||||
Setup const& setup,
|
||||
ServiceRegistry& registry,
|
||||
std::function<void(void)> const& completion,
|
||||
Resource::Consumer& consumer,
|
||||
int id,
|
||||
PathRequests& owner,
|
||||
beast::Journal journal)
|
||||
: app_(app)
|
||||
: setup_(setup)
|
||||
, registry_(registry)
|
||||
, m_journal(journal)
|
||||
, mOwner(owner)
|
||||
, fCompletion(completion)
|
||||
@@ -479,7 +480,7 @@ PathRequest::getPathFinder(
|
||||
dst_amount,
|
||||
saSendMax,
|
||||
domain,
|
||||
app_);
|
||||
registry_);
|
||||
if (pathfinder->findPaths(level, continueCallback))
|
||||
pathfinder->computePathRanks(max_paths_, continueCallback);
|
||||
else
|
||||
@@ -577,7 +578,7 @@ PathRequest::findPaths(
|
||||
*raSrcAccount, // --> Account sending from.
|
||||
ps, // --> Path set.
|
||||
domain, // --> Domain.
|
||||
app_.logs(),
|
||||
registry_.logs(),
|
||||
&rcInput);
|
||||
|
||||
if (!convert_all_ && !fullLiquidityPath.empty() &&
|
||||
@@ -598,7 +599,7 @@ PathRequest::findPaths(
|
||||
*raSrcAccount, // --> Account sending from.
|
||||
ps, // --> Path set.
|
||||
domain, // --> Domain.
|
||||
app_.logs());
|
||||
registry_.logs());
|
||||
|
||||
if (rc.result() != tesSUCCESS)
|
||||
{
|
||||
@@ -687,36 +688,36 @@ PathRequest::doUpdate(
|
||||
if (jvId)
|
||||
newStatus[jss::id] = jvId;
|
||||
|
||||
bool loaded = app_.getFeeTrack().isLoadedLocal();
|
||||
bool loaded = registry_.getFeeTrack().isLoadedLocal();
|
||||
|
||||
if (iLevel == 0)
|
||||
{
|
||||
// first pass
|
||||
if (loaded || fast)
|
||||
iLevel = app_.config().PATH_SEARCH_FAST;
|
||||
iLevel = setup_.pathSearchFast;
|
||||
else
|
||||
iLevel = app_.config().PATH_SEARCH;
|
||||
iLevel = setup_.pathSearch;
|
||||
}
|
||||
else if ((iLevel == app_.config().PATH_SEARCH_FAST) && !fast)
|
||||
else if ((iLevel == setup_.pathSearchFast) && !fast)
|
||||
{
|
||||
// leaving fast pathfinding
|
||||
iLevel = app_.config().PATH_SEARCH;
|
||||
if (loaded && (iLevel > app_.config().PATH_SEARCH_FAST))
|
||||
iLevel = setup_.pathSearch;
|
||||
if (loaded && (iLevel > setup_.pathSearchFast))
|
||||
--iLevel;
|
||||
}
|
||||
else if (bLastSuccess)
|
||||
{
|
||||
// decrement, if possible
|
||||
if (iLevel > app_.config().PATH_SEARCH ||
|
||||
(loaded && (iLevel > app_.config().PATH_SEARCH_FAST)))
|
||||
if (iLevel > setup_.pathSearch ||
|
||||
(loaded && (iLevel > setup_.pathSearchFast)))
|
||||
--iLevel;
|
||||
}
|
||||
else
|
||||
{
|
||||
// adjust as needed
|
||||
if (!loaded && (iLevel < app_.config().PATH_SEARCH_MAX))
|
||||
if (!loaded && (iLevel < setup_.pathSearchMax))
|
||||
++iLevel;
|
||||
if (loaded && (iLevel > app_.config().PATH_SEARCH_FAST))
|
||||
if (loaded && (iLevel > setup_.pathSearchFast))
|
||||
--iLevel;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
#ifndef XRPL_APP_PATHS_PATHREQUEST_H_INCLUDED
|
||||
#define XRPL_APP_PATHS_PATHREQUEST_H_INCLUDED
|
||||
|
||||
#include <xrpld/app/ledger/Ledger.h>
|
||||
#include <xrpld/app/paths/Pathfinder.h>
|
||||
#include <xrpld/app/paths/RippleLineCache.h>
|
||||
|
||||
#include <xrpl/basics/base_uint.h>
|
||||
#include <xrpl/core/ServiceRegistry.h>
|
||||
#include <xrpl/json/json_value.h>
|
||||
#include <xrpl/protocol/UintTypes.h>
|
||||
#include <xrpl/server/InfoSub.h>
|
||||
@@ -37,11 +37,33 @@ public:
|
||||
using ref = pointer const&;
|
||||
using wref = wptr const&;
|
||||
|
||||
/** Configuration for path search aggressiveness.
|
||||
*
|
||||
* These values control the search depth and resource consumption
|
||||
* of pathfinding operations. Higher values result in exponentially
|
||||
* higher resource usage.
|
||||
*/
|
||||
struct Setup
|
||||
{
|
||||
/** Default constructor with standard values */
|
||||
explicit Setup() = default;
|
||||
|
||||
/** Default search aggressiveness */
|
||||
int pathSearch = 2;
|
||||
|
||||
/** Fast search aggressiveness (used when loaded or fast mode) */
|
||||
int pathSearchFast = 2;
|
||||
|
||||
/** Maximum search aggressiveness */
|
||||
int pathSearchMax = 3;
|
||||
};
|
||||
|
||||
public:
|
||||
// path_find semantics
|
||||
// Subscriber is updated
|
||||
PathRequest(
|
||||
Application& app,
|
||||
Setup const& setup,
|
||||
ServiceRegistry& registry,
|
||||
std::shared_ptr<InfoSub> const& subscriber,
|
||||
int id,
|
||||
PathRequests&,
|
||||
@@ -50,7 +72,8 @@ public:
|
||||
// ripple_path_find semantics
|
||||
// Completion function is called after path update is complete
|
||||
PathRequest(
|
||||
Application& app,
|
||||
Setup const& setup,
|
||||
ServiceRegistry& registry,
|
||||
std::function<void(void)> const& completion,
|
||||
Resource::Consumer& consumer,
|
||||
int id,
|
||||
@@ -115,7 +138,8 @@ private:
|
||||
int
|
||||
parseJson(Json::Value const&);
|
||||
|
||||
Application& app_;
|
||||
Setup const setup_;
|
||||
ServiceRegistry& registry_;
|
||||
beast::Journal m_journal;
|
||||
|
||||
std::recursive_mutex mLock;
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#include <xrpld/app/ledger/LedgerMaster.h>
|
||||
#include <xrpld/app/main/Application.h>
|
||||
#include <xrpld/app/paths/PathRequests.h>
|
||||
|
||||
#include <xrpl/basics/Log.h>
|
||||
@@ -41,7 +40,7 @@ PathRequests::getLineCache(
|
||||
// weak_ptr, and will immediately discard it if there are no other
|
||||
// references.
|
||||
lineCache_ = lineCache = std::make_shared<RippleLineCache>(
|
||||
ledger, app_.journal("RippleLineCache"));
|
||||
ledger, registry_.journal("RippleLineCache"));
|
||||
}
|
||||
return lineCache;
|
||||
}
|
||||
@@ -49,8 +48,8 @@ PathRequests::getLineCache(
|
||||
void
|
||||
PathRequests::updateAll(std::shared_ptr<ReadView const> const& inLedger)
|
||||
{
|
||||
auto event =
|
||||
app_.getJobQueue().makeLoadEvent(jtPATH_FIND, "PathRequest::updateAll");
|
||||
auto event = registry_.getJobQueue().makeLoadEvent(
|
||||
jtPATH_FIND, "PathRequest::updateAll");
|
||||
|
||||
std::vector<PathRequest::wptr> requests;
|
||||
std::shared_ptr<RippleLineCache> cache;
|
||||
@@ -62,7 +61,7 @@ PathRequests::updateAll(std::shared_ptr<ReadView const> const& inLedger)
|
||||
cache = getLineCache(inLedger, true);
|
||||
}
|
||||
|
||||
bool newRequests = app_.getLedgerMaster().isNewPathRequest();
|
||||
bool newRequests = registry_.getLedgerMaster().isNewPathRequest();
|
||||
bool mustBreak = false;
|
||||
|
||||
JLOG(mJournal.trace()) << "updateAll seq=" << cache->getLedger()->seq()
|
||||
@@ -86,7 +85,7 @@ PathRequests::updateAll(std::shared_ptr<ReadView const> const& inLedger)
|
||||
JLOG(mJournal.trace()) << "updateAll looping";
|
||||
for (auto const& wr : requests)
|
||||
{
|
||||
if (app_.getJobQueue().isStopping())
|
||||
if (registry_.getJobQueue().isStopping())
|
||||
break;
|
||||
|
||||
auto request = wr.lock();
|
||||
@@ -159,7 +158,7 @@ PathRequests::updateAll(std::shared_ptr<ReadView const> const& inLedger)
|
||||
}
|
||||
|
||||
mustBreak =
|
||||
!newRequests && app_.getLedgerMaster().isNewPathRequest();
|
||||
!newRequests && registry_.getLedgerMaster().isNewPathRequest();
|
||||
|
||||
// We weren't handling new requests and then
|
||||
// there was a new request
|
||||
@@ -173,11 +172,11 @@ PathRequests::updateAll(std::shared_ptr<ReadView const> const& inLedger)
|
||||
}
|
||||
else if (newRequests)
|
||||
{ // we only did new requests, so we always need a last pass
|
||||
newRequests = app_.getLedgerMaster().isNewPathRequest();
|
||||
newRequests = registry_.getLedgerMaster().isNewPathRequest();
|
||||
}
|
||||
else
|
||||
{ // if there are no new requests, we are done
|
||||
newRequests = app_.getLedgerMaster().isNewPathRequest();
|
||||
newRequests = registry_.getLedgerMaster().isNewPathRequest();
|
||||
if (!newRequests)
|
||||
break;
|
||||
}
|
||||
@@ -195,7 +194,7 @@ PathRequests::updateAll(std::shared_ptr<ReadView const> const& inLedger)
|
||||
lastCache = cache;
|
||||
cache = getLineCache(cache->getLedger(), false);
|
||||
}
|
||||
} while (!app_.getJobQueue().isStopping());
|
||||
} while (!registry_.getJobQueue().isStopping());
|
||||
|
||||
JLOG(mJournal.debug()) << "updateAll complete: " << processed
|
||||
<< " processed and " << removed << " removed";
|
||||
@@ -234,7 +233,7 @@ PathRequests::makePathRequest(
|
||||
Json::Value const& requestJson)
|
||||
{
|
||||
auto req = std::make_shared<PathRequest>(
|
||||
app_, subscriber, ++mLastIdentifier, *this, mJournal);
|
||||
setup_, registry_, subscriber, ++mLastIdentifier, *this, mJournal);
|
||||
|
||||
auto [valid, jvRes] =
|
||||
req->doCreate(getLineCache(inLedger, false), requestJson);
|
||||
@@ -243,7 +242,7 @@ PathRequests::makePathRequest(
|
||||
{
|
||||
subscriber->setRequest(req);
|
||||
insertPathRequest(req);
|
||||
app_.getLedgerMaster().newPathRequest();
|
||||
registry_.getLedgerMaster().newPathRequest();
|
||||
}
|
||||
return std::move(jvRes);
|
||||
}
|
||||
@@ -260,7 +259,13 @@ PathRequests::makeLegacyPathRequest(
|
||||
// This assignment must take place before the
|
||||
// completion function is called
|
||||
req = std::make_shared<PathRequest>(
|
||||
app_, completion, consumer, ++mLastIdentifier, *this, mJournal);
|
||||
setup_,
|
||||
registry_,
|
||||
completion,
|
||||
consumer,
|
||||
++mLastIdentifier,
|
||||
*this,
|
||||
mJournal);
|
||||
|
||||
auto [valid, jvRes] = req->doCreate(getLineCache(inLedger, false), request);
|
||||
|
||||
@@ -271,7 +276,7 @@ PathRequests::makeLegacyPathRequest(
|
||||
else
|
||||
{
|
||||
insertPathRequest(req);
|
||||
if (!app_.getLedgerMaster().newPathRequest())
|
||||
if (!registry_.getLedgerMaster().newPathRequest())
|
||||
{
|
||||
// The newPathRequest failed. Tell the caller.
|
||||
jvRes = rpcError(rpcTOO_BUSY);
|
||||
@@ -289,10 +294,10 @@ PathRequests::doLegacyPathRequest(
|
||||
Json::Value const& request)
|
||||
{
|
||||
auto cache = std::make_shared<RippleLineCache>(
|
||||
inLedger, app_.journal("RippleLineCache"));
|
||||
inLedger, registry_.journal("RippleLineCache"));
|
||||
|
||||
auto req = std::make_shared<PathRequest>(
|
||||
app_, [] {}, consumer, ++mLastIdentifier, *this, mJournal);
|
||||
setup_, registry_, [] {}, consumer, ++mLastIdentifier, *this, mJournal);
|
||||
|
||||
auto [valid, jvRes] = req->doCreate(cache, request);
|
||||
if (valid)
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
#ifndef XRPL_APP_PATHS_PATHREQUESTS_H_INCLUDED
|
||||
#define XRPL_APP_PATHS_PATHREQUESTS_H_INCLUDED
|
||||
|
||||
#include <xrpld/app/main/Application.h>
|
||||
#include <xrpld/app/paths/PathRequest.h>
|
||||
#include <xrpld/app/paths/RippleLineCache.h>
|
||||
|
||||
#include <xrpl/core/ServiceRegistry.h>
|
||||
|
||||
#include <atomic>
|
||||
#include <mutex>
|
||||
#include <vector>
|
||||
@@ -16,10 +17,14 @@ class PathRequests
|
||||
public:
|
||||
/** A collection of all PathRequest instances. */
|
||||
PathRequests(
|
||||
Application& app,
|
||||
PathRequest::Setup const& setup,
|
||||
ServiceRegistry& registry,
|
||||
beast::Journal journal,
|
||||
beast::insight::Collector::ptr const& collector)
|
||||
: app_(app), mJournal(journal), mLastIdentifier(0)
|
||||
: setup_(setup)
|
||||
, registry_(registry)
|
||||
, mJournal(journal)
|
||||
, mLastIdentifier(0)
|
||||
{
|
||||
mFast = collector->make_event("pathfind_fast");
|
||||
mFull = collector->make_event("pathfind_full");
|
||||
@@ -83,7 +88,8 @@ private:
|
||||
void
|
||||
insertPathRequest(PathRequest::pointer const&);
|
||||
|
||||
Application& app_;
|
||||
PathRequest::Setup const setup_;
|
||||
ServiceRegistry& registry_;
|
||||
beast::Journal mJournal;
|
||||
|
||||
beast::insight::Event mFast;
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#ifndef XRPL_APP_PATHS_RIPPLELINECACHE_H_INCLUDED
|
||||
#define XRPL_APP_PATHS_RIPPLELINECACHE_H_INCLUDED
|
||||
|
||||
#include <xrpld/app/ledger/Ledger.h>
|
||||
#include <xrpld/app/paths/TrustLine.h>
|
||||
|
||||
#include <xrpl/basics/CountedObject.h>
|
||||
|
||||
Reference in New Issue
Block a user