diff --git a/src/test/app/HashRouter_test.cpp b/src/test/app/HashRouter_test.cpp index 527ae7b55a..b46adc7b0c 100644 --- a/src/test/app/HashRouter_test.cpp +++ b/src/test/app/HashRouter_test.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include diff --git a/src/xrpld/app/main/Application.cpp b/src/xrpld/app/main/Application.cpp index f542279114..07e768cf41 100644 --- a/src/xrpld/app/main/Application.cpp +++ b/src/xrpld/app/main/Application.cpp @@ -14,6 +14,8 @@ #include #include #include +#include +#include #include #include #include @@ -21,7 +23,6 @@ #include #include #include -#include #include #include #include @@ -360,7 +361,8 @@ public: {config_->PATH_SEARCH_MAX, config_->standalone()}) , m_pathRequests(std::make_unique( - *this, + setup_PathRequest(*config_), + *serviceRegistry_, logs_->journal("PathRequest"), m_collectorManager->collector())) diff --git a/src/xrpld/app/misc/detail/setup_HashRouter.cpp b/src/xrpld/app/main/detail/setup_HashRouter.cpp similarity index 96% rename from src/xrpld/app/misc/detail/setup_HashRouter.cpp rename to src/xrpld/app/main/detail/setup_HashRouter.cpp index 42bcd7dce1..06af78f746 100644 --- a/src/xrpld/app/misc/detail/setup_HashRouter.cpp +++ b/src/xrpld/app/main/detail/setup_HashRouter.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include diff --git a/src/xrpld/app/main/detail/setup_PathRequest.cpp b/src/xrpld/app/main/detail/setup_PathRequest.cpp new file mode 100644 index 0000000000..0956973c50 --- /dev/null +++ b/src/xrpld/app/main/detail/setup_PathRequest.cpp @@ -0,0 +1,16 @@ +#include +#include + +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 diff --git a/src/xrpld/app/misc/setup_HashRouter.h b/src/xrpld/app/main/setup_HashRouter.h similarity index 100% rename from src/xrpld/app/misc/setup_HashRouter.h rename to src/xrpld/app/main/setup_HashRouter.h diff --git a/src/xrpld/app/main/setup_PathRequest.h b/src/xrpld/app/main/setup_PathRequest.h new file mode 100644 index 0000000000..e11602e565 --- /dev/null +++ b/src/xrpld/app/main/setup_PathRequest.h @@ -0,0 +1,17 @@ +#ifndef XRPLD_APP_PATHS_SETUP_PATHREQUEST_H_INCLUDED +#define XRPLD_APP_PATHS_SETUP_PATHREQUEST_H_INCLUDED + +#include + +namespace xrpl { + +// Forward declaration +class Config; + +/** Create PathRequest setup from configuration */ +PathRequest::Setup +setup_PathRequest(Config const& config); + +} // namespace xrpl + +#endif diff --git a/src/xrpld/app/paths/PathRequest.cpp b/src/xrpld/app/paths/PathRequest.cpp index 41bae4b178..0c61d1076b 100644 --- a/src/xrpld/app/paths/PathRequest.cpp +++ b/src/xrpld/app/paths/PathRequest.cpp @@ -1,12 +1,9 @@ -#include #include -#include #include #include #include #include #include -#include #include #include @@ -21,12 +18,14 @@ namespace xrpl { PathRequest::PathRequest( - Application& app, + Setup const& setup, + ServiceRegistry& registry, std::shared_ptr 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 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; } diff --git a/src/xrpld/app/paths/PathRequest.h b/src/xrpld/app/paths/PathRequest.h index 83cd0c0d79..c2ebc7d8a1 100644 --- a/src/xrpld/app/paths/PathRequest.h +++ b/src/xrpld/app/paths/PathRequest.h @@ -1,11 +1,11 @@ #ifndef XRPL_APP_PATHS_PATHREQUEST_H_INCLUDED #define XRPL_APP_PATHS_PATHREQUEST_H_INCLUDED -#include #include #include #include +#include #include #include #include @@ -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 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 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; diff --git a/src/xrpld/app/paths/PathRequests.cpp b/src/xrpld/app/paths/PathRequests.cpp index cfe6080eac..b6e2c71388 100644 --- a/src/xrpld/app/paths/PathRequests.cpp +++ b/src/xrpld/app/paths/PathRequests.cpp @@ -1,5 +1,4 @@ #include -#include #include #include @@ -41,7 +40,7 @@ PathRequests::getLineCache( // weak_ptr, and will immediately discard it if there are no other // references. lineCache_ = lineCache = std::make_shared( - ledger, app_.journal("RippleLineCache")); + ledger, registry_.journal("RippleLineCache")); } return lineCache; } @@ -49,8 +48,8 @@ PathRequests::getLineCache( void PathRequests::updateAll(std::shared_ptr const& inLedger) { - auto event = - app_.getJobQueue().makeLoadEvent(jtPATH_FIND, "PathRequest::updateAll"); + auto event = registry_.getJobQueue().makeLoadEvent( + jtPATH_FIND, "PathRequest::updateAll"); std::vector requests; std::shared_ptr cache; @@ -62,7 +61,7 @@ PathRequests::updateAll(std::shared_ptr 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 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 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 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 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( - 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( - 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( - inLedger, app_.journal("RippleLineCache")); + inLedger, registry_.journal("RippleLineCache")); auto req = std::make_shared( - app_, [] {}, consumer, ++mLastIdentifier, *this, mJournal); + setup_, registry_, [] {}, consumer, ++mLastIdentifier, *this, mJournal); auto [valid, jvRes] = req->doCreate(cache, request); if (valid) diff --git a/src/xrpld/app/paths/PathRequests.h b/src/xrpld/app/paths/PathRequests.h index 5c97bafa8a..153291ee4c 100644 --- a/src/xrpld/app/paths/PathRequests.h +++ b/src/xrpld/app/paths/PathRequests.h @@ -1,10 +1,11 @@ #ifndef XRPL_APP_PATHS_PATHREQUESTS_H_INCLUDED #define XRPL_APP_PATHS_PATHREQUESTS_H_INCLUDED -#include #include #include +#include + #include #include #include @@ -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; diff --git a/src/xrpld/app/paths/RippleLineCache.h b/src/xrpld/app/paths/RippleLineCache.h index c2763ca2b4..4e02db3d51 100644 --- a/src/xrpld/app/paths/RippleLineCache.h +++ b/src/xrpld/app/paths/RippleLineCache.h @@ -1,7 +1,6 @@ #ifndef XRPL_APP_PATHS_RIPPLELINECACHE_H_INCLUDED #define XRPL_APP_PATHS_RIPPLELINECACHE_H_INCLUDED -#include #include #include