From d7362321421b3f1ac3cf934556774ceecf0a9f93 Mon Sep 17 00:00:00 2001 From: Nik Bougalis Date: Sat, 20 Feb 2016 16:20:16 -0800 Subject: [PATCH] Pathfinding cleanup: * Remove unused code * Do not use `pointer` and `ref` type aliases * Misc. cleanups --- Builds/VisualStudio2015/RippleD.vcxproj | 6 - .../VisualStudio2015/RippleD.vcxproj.filters | 6 - src/ripple/app/paths/AccountCurrencies.cpp | 4 +- src/ripple/app/paths/AccountCurrencies.h | 4 +- src/ripple/app/paths/FindPaths.cpp | 155 ------------------ src/ripple/app/paths/FindPaths.h | 101 ------------ src/ripple/app/paths/PathRequest.cpp | 18 +- src/ripple/app/paths/PathRequest.h | 11 +- src/ripple/app/paths/PathRequests.cpp | 9 +- src/ripple/app/paths/PathRequests.h | 4 +- src/ripple/app/paths/Pathfinder.cpp | 2 +- src/ripple/app/paths/Pathfinder.h | 4 +- src/ripple/app/paths/RippleLineCache.cpp | 8 +- src/ripple/app/paths/RippleLineCache.h | 15 +- src/ripple/ledger/ApplyViewImpl.h | 2 +- src/ripple/ledger/OpenView.h | 2 +- src/ripple/ledger/PaymentSandbox.h | 2 +- src/ripple/rpc/RipplePathFind.h | 2 +- src/ripple/rpc/handlers/RipplePathFind.cpp | 8 +- 19 files changed, 50 insertions(+), 313 deletions(-) delete mode 100644 src/ripple/app/paths/FindPaths.cpp delete mode 100644 src/ripple/app/paths/FindPaths.h diff --git a/Builds/VisualStudio2015/RippleD.vcxproj b/Builds/VisualStudio2015/RippleD.vcxproj index 7f0e19eab..9698689f8 100644 --- a/Builds/VisualStudio2015/RippleD.vcxproj +++ b/Builds/VisualStudio2015/RippleD.vcxproj @@ -1436,12 +1436,6 @@ - - True - True - - - True True diff --git a/Builds/VisualStudio2015/RippleD.vcxproj.filters b/Builds/VisualStudio2015/RippleD.vcxproj.filters index e7047369e..725339382 100644 --- a/Builds/VisualStudio2015/RippleD.vcxproj.filters +++ b/Builds/VisualStudio2015/RippleD.vcxproj.filters @@ -2028,12 +2028,6 @@ ripple\app\paths\cursor - - ripple\app\paths - - - ripple\app\paths - ripple\app\paths diff --git a/src/ripple/app/paths/AccountCurrencies.cpp b/src/ripple/app/paths/AccountCurrencies.cpp index 6f4d612d3..9aa2d77d5 100644 --- a/src/ripple/app/paths/AccountCurrencies.cpp +++ b/src/ripple/app/paths/AccountCurrencies.cpp @@ -24,7 +24,7 @@ namespace ripple { hash_set accountSourceCurrencies ( AccountID const& account, - RippleLineCache::ref lrCache, + std::shared_ptr const& lrCache, bool includeXRP) { hash_set currencies; @@ -62,7 +62,7 @@ hash_set accountSourceCurrencies ( hash_set accountDestCurrencies ( AccountID const& account, - RippleLineCache::ref lrCache, + std::shared_ptr const& lrCache, bool includeXRP) { hash_set currencies; diff --git a/src/ripple/app/paths/AccountCurrencies.h b/src/ripple/app/paths/AccountCurrencies.h index 8f415f3ec..2895ff8e4 100644 --- a/src/ripple/app/paths/AccountCurrencies.h +++ b/src/ripple/app/paths/AccountCurrencies.h @@ -28,13 +28,13 @@ namespace ripple { hash_set accountDestCurrencies( AccountID const& account, - RippleLineCache::ref cache, + std::shared_ptr const& cache, bool includeXRP); hash_set accountSourceCurrencies( AccountID const& account, - RippleLineCache::ref lrLedger, + std::shared_ptr const& lrLedger, bool includeXRP); } // ripple diff --git a/src/ripple/app/paths/FindPaths.cpp b/src/ripple/app/paths/FindPaths.cpp deleted file mode 100644 index fbb6051de..000000000 --- a/src/ripple/app/paths/FindPaths.cpp +++ /dev/null @@ -1,155 +0,0 @@ -//------------------------------------------------------------------------------ -/* - This file is part of rippled: https://github.com/ripple/rippled - Copyright (c) 2012, 2013 Ripple Labs Inc. - - Permission to use, copy, modify, and/or distribute this software for any - purpose with or without fee is hereby granted, provided that the above - copyright notice and this permission notice appear in all copies. - - THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -*/ -//============================================================================== - -#include -#include -#include - -namespace ripple { - -class FindPaths::Impl { -public: - Impl ( - RippleLineCache::ref cache, - AccountID const& srcAccount, - AccountID const& dstAccount, - STAmount const& dstAmount, - boost::optional const& srcAmount, - int searchLevel, - unsigned int maxPaths) - : cache_ (cache), - srcAccount_ (srcAccount), - dstAccount_ (dstAccount), - dstAmount_ (dstAmount), - srcAmount_ (srcAmount), - searchLevel_ (searchLevel), - maxPaths_ (maxPaths) - { - } - - boost::optional - findPathsForIssue ( - Issue const& issue, - STPathSet const& paths, - STPath& fullLiquidityPath, - Application& app) - { - if (auto& pathfinder = getPathFinder (issue.currency, app)) - { - return pathfinder->getBestPaths (maxPaths_, - fullLiquidityPath, paths, issue.account); - } - assert (false); - return boost::none; - } - -private: - hash_map> currencyMap_; - - RippleLineCache::ref cache_; - AccountID const srcAccount_; - AccountID const dstAccount_; - STAmount const dstAmount_; - boost::optional const srcAmount_; - int const searchLevel_; - unsigned int const maxPaths_; - - std::unique_ptr const& - getPathFinder (Currency const& currency, Application& app) - { - auto i = currencyMap_.find (currency); - if (i != currencyMap_.end ()) - return i->second; - auto pathfinder = std::make_unique ( - cache_, srcAccount_, dstAccount_, currency, - boost::none, dstAmount_, srcAmount_, app); - if (pathfinder->findPaths (searchLevel_)) - pathfinder->computePathRanks (maxPaths_); - else - pathfinder.reset (); // It's a bad request - clear it. - return currencyMap_[currency] = std::move (pathfinder); - - // TODO(tom): why doesn't this faster way compile? - // return currencyMap_.insert (i, std::move (pathfinder)).second; - } -}; - -FindPaths::FindPaths ( - RippleLineCache::ref cache, - AccountID const& srcAccount, - AccountID const& dstAccount, - STAmount const& dstAmount, - boost::optional const& srcAmount, - int level, - unsigned int maxPaths) - : impl_ (std::make_unique ( - cache, srcAccount, dstAccount, - dstAmount, srcAmount, level, maxPaths)) -{ -} - -FindPaths::~FindPaths() = default; - -boost::optional -FindPaths::findPathsForIssue ( - Issue const& issue, - STPathSet const& paths, - STPath& fullLiquidityPath, - Application& app) -{ - return impl_->findPathsForIssue (issue, paths, fullLiquidityPath, app); -} - -boost::optional -findPathsForOneIssuer ( - RippleLineCache::ref cache, - AccountID const& srcAccount, - AccountID const& dstAccount, - Issue const& srcIssue, - STAmount const& dstAmount, - int searchLevel, - unsigned int const maxPaths, - STPathSet const& paths, - STPath& fullLiquidityPath, - Application& app) -{ - Pathfinder pf ( - cache, - srcAccount, - dstAccount, - srcIssue.currency, - srcIssue.account, - dstAmount, - boost::none, - app); - - if (! pf.findPaths(searchLevel)) - return boost::none; - - pf.computePathRanks (maxPaths); - return pf.getBestPaths(maxPaths, fullLiquidityPath, - paths, srcIssue.account); -} - -void initializePathfinding () -{ - Pathfinder::initPathTable (); -} - -} // ripple diff --git a/src/ripple/app/paths/FindPaths.h b/src/ripple/app/paths/FindPaths.h deleted file mode 100644 index 2f09f76cf..000000000 --- a/src/ripple/app/paths/FindPaths.h +++ /dev/null @@ -1,101 +0,0 @@ -//------------------------------------------------------------------------------ -/* - This file is part of rippled: https://github.com/ripple/rippled - Copyright (c) 2012, 2013 Ripple Labs Inc. - - Permission to use, copy, modify, and/or distribute this software for any - purpose with or without fee is hereby granted, provided that the above - copyright notice and this permission notice appear in all copies. - - THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -*/ -//============================================================================== - -#ifndef RIPPLE_APP_PATHS_FINDPATHS_H_INCLUDED -#define RIPPLE_APP_PATHS_FINDPATHS_H_INCLUDED - -#include - -namespace ripple { - -class FindPaths -{ -public: - FindPaths ( - RippleLineCache::ref cache, - AccountID const& srcAccount, - AccountID const& dstAccount, - STAmount const& dstAmount, - boost::optional const& srcAmount, - /** searchLevel is the maximum search level allowed in an output path. - */ - int searchLevel, - /** maxPaths is the maximum number of paths that can be returned in - pathsOut. */ - unsigned int const maxPaths); - ~FindPaths(); - - /** The return value will have any additional paths found. Only - non-default paths without source or destination will be added. */ - boost::optional - findPathsForIssue ( - Issue const& issue, - - /** Contains any paths you want to ensure are - included if still good. */ - STPathSet const& paths, - - /** On input, fullLiquidityPath must be an empty STPath. - - On output, if fullLiquidityPath is non-empty, it contains one extra - path that can move the entire liquidity requested. */ - STPath& fullLiquidityPath, - - Application& app); - -private: - class Impl; - std::unique_ptr impl_; -}; - -/** The return value will have any additional paths found. Only - non-default paths without source or destination will be added. */ -boost::optional -findPathsForOneIssuer ( - RippleLineCache::ref cache, - AccountID const& srcAccount, - AccountID const& dstAccount, - Issue const& srcIssue, - STAmount const& dstAmount, - - /** searchLevel is the maximum search level allowed in an output path. */ - int searchLevel, - - /** maxPaths is the maximum number of paths that can be returned in - pathsOut. */ - unsigned int const maxPaths, - - /** Contains any paths you want to ensure are included if - still good. - */ - STPathSet const& paths, - - /** On input, fullLiquidityPath must be an empty STPath. - - On output, if fullLiquidityPath is non-empty, it contains one extra path - that can move the entire liquidity requested. */ - STPath& fullLiquidityPath, - - Application& app); - -void initializePathfinding (); - -} // ripple - -#endif diff --git a/src/ripple/app/paths/PathRequest.cpp b/src/ripple/app/paths/PathRequest.cpp index d1fbc2353..29654982f 100644 --- a/src/ripple/app/paths/PathRequest.cpp +++ b/src/ripple/app/paths/PathRequest.cpp @@ -159,7 +159,7 @@ void PathRequest::updateComplete () } } -bool PathRequest::isValid (RippleLineCache::ref crCache) +bool PathRequest::isValid (std::shared_ptr const& crCache) { if (! raSrcAccount || ! raDstAccount) return false; @@ -171,16 +171,16 @@ bool PathRequest::isValid (RippleLineCache::ref crCache) return false; } - if (! crCache->getLedger()->exists( - keylet::account(*raSrcAccount))) + auto const& lrLedger = crCache->getLedger(); + + if (! lrLedger->exists(keylet::account(*raSrcAccount))) { // Source account does not exist. jvStatus = rpcError (rpcSRC_ACT_NOT_FOUND); return false; } - auto const& lrLedger = crCache->getLedger(); - auto const sleDest = crCache->getLedger()->read( + auto const sleDest = lrLedger->read( keylet::account(*raDstAccount)); Json::Value& jvDestCur = @@ -234,7 +234,7 @@ bool PathRequest::isValid (RippleLineCache::ref crCache) */ std::pair PathRequest::doCreate ( - RippleLineCache::ref& cache, + std::shared_ptr const& cache, Json::Value const& value) { bool valid = false; @@ -435,7 +435,7 @@ Json::Value PathRequest::doStatus (Json::Value const&) } std::unique_ptr const& -PathRequest::getPathFinder(RippleLineCache::ref cache, +PathRequest::getPathFinder(std::shared_ptr const& cache, hash_map>& currency_map, Currency const& currency, STAmount const& dst_amount, int const level) @@ -454,7 +454,7 @@ PathRequest::getPathFinder(RippleLineCache::ref cache, } bool -PathRequest::findPaths (RippleLineCache::ref cache, int const level, +PathRequest::findPaths (std::shared_ptr const& cache, int const level, Json::Value& jvArray) { auto sourceCurrencies = sciSourceCurrencies; @@ -588,7 +588,7 @@ PathRequest::findPaths (RippleLineCache::ref cache, int const level, return true; } -Json::Value PathRequest::doUpdate (RippleLineCache::ref cache, bool fast) +Json::Value PathRequest::doUpdate (std::shared_ptr const& cache, bool fast) { using namespace std::chrono; m_journal.debug << iIdentifier << " update " << (fast ? "fast" : "normal"); diff --git a/src/ripple/app/paths/PathRequest.h b/src/ripple/app/paths/PathRequest.h index 3b4203ba7..be1e58581 100644 --- a/src/ripple/app/paths/PathRequest.h +++ b/src/ripple/app/paths/PathRequest.h @@ -81,25 +81,26 @@ public: Json::Value getStatus (); std::pair doCreate ( - const RippleLineCache::pointer&, + std::shared_ptr const&, Json::Value const&); Json::Value doClose (Json::Value const&); Json::Value doStatus (Json::Value const&); // update jvStatus - Json::Value doUpdate (const std::shared_ptr&, bool fast); + Json::Value doUpdate ( + std::shared_ptr const&, bool fast); InfoSub::pointer getSubscriber (); bool hasCompletion (); private: using ScopedLockType = std::lock_guard ; - bool isValid (RippleLineCache::ref crCache); + bool isValid (std::shared_ptr const& crCache); void setValid (); std::unique_ptr const& - getPathFinder(RippleLineCache::ref, + getPathFinder(std::shared_ptr const&, hash_map>&, Currency const&, STAmount const&, int const); @@ -107,7 +108,7 @@ private: Returns false if the source currencies are inavlid. */ bool - findPaths (RippleLineCache::ref, int const, Json::Value&); + findPaths (std::shared_ptr const&, int const, Json::Value&); int parseJson (Json::Value const&); diff --git a/src/ripple/app/paths/PathRequests.cpp b/src/ripple/app/paths/PathRequests.cpp index efb3c66c6..635ef4c2d 100644 --- a/src/ripple/app/paths/PathRequests.cpp +++ b/src/ripple/app/paths/PathRequests.cpp @@ -32,10 +32,11 @@ namespace ripple { /** Get the current RippleLineCache, updating it if necessary. Get the correct ledger to use. */ -RippleLineCache::pointer PathRequests::getLineCache ( - std::shared_ptr const& ledger, bool authoritative) +std::shared_ptr +PathRequests::getLineCache ( + std::shared_ptr const& ledger, + bool authoritative) { - ScopedLockType sl (mLock); std::uint32_t lineSeq = mLineCache ? mLineCache->getLedger()->seq() : 0; @@ -59,7 +60,7 @@ void PathRequests::updateAll (std::shared_ptr const& inLedger, jtPATH_FIND, "PathRequest::updateAll"); std::vector requests; - RippleLineCache::pointer cache; + std::shared_ptr cache; // Get the ledger and cache we should be using { diff --git a/src/ripple/app/paths/PathRequests.h b/src/ripple/app/paths/PathRequests.h index 57c91bdd2..f84392e1c 100644 --- a/src/ripple/app/paths/PathRequests.h +++ b/src/ripple/app/paths/PathRequests.h @@ -46,7 +46,7 @@ public: void updateAll (std::shared_ptr const& ledger, Job::CancelCallback shouldCancel); - RippleLineCache::pointer getLineCache ( + std::shared_ptr getLineCache ( std::shared_ptr const& ledger, bool authoritative); Json::Value makePathRequest ( @@ -83,7 +83,7 @@ private: std::vector requests_; // Use a RippleLineCache - RippleLineCache::pointer mLineCache; + std::shared_ptr mLineCache; std::atomic mLastIdentifier; diff --git a/src/ripple/app/paths/Pathfinder.cpp b/src/ripple/app/paths/Pathfinder.cpp index e1169128a..e248fb9e5 100644 --- a/src/ripple/app/paths/Pathfinder.cpp +++ b/src/ripple/app/paths/Pathfinder.cpp @@ -142,7 +142,7 @@ std::string pathTypeToString (Pathfinder::PathType const& type) } // namespace Pathfinder::Pathfinder ( - RippleLineCache::ref cache, + std::shared_ptr const& cache, AccountID const& uSrcAccount, AccountID const& uDstAccount, Currency const& uSrcCurrency, diff --git a/src/ripple/app/paths/Pathfinder.h b/src/ripple/app/paths/Pathfinder.h index 469dc2796..fb8b47858 100644 --- a/src/ripple/app/paths/Pathfinder.h +++ b/src/ripple/app/paths/Pathfinder.h @@ -39,7 +39,7 @@ class Pathfinder public: /** Construct a pathfinder without an issuer.*/ Pathfinder ( - RippleLineCache::ref cache, + std::shared_ptr const& cache, AccountID const& srcAccount, AccountID const& dstAccount, Currency const& uSrcCurrency, @@ -182,7 +182,7 @@ private: std::shared_ptr mLedger; LoadEvent::pointer m_loadEvent; - RippleLineCache::pointer mRLCache; + std::shared_ptr mRLCache; STPathElement mSource; STPathSet mCompletePaths; diff --git a/src/ripple/app/paths/RippleLineCache.cpp b/src/ripple/app/paths/RippleLineCache.cpp index 6ddacbcb3..95e413d87 100644 --- a/src/ripple/app/paths/RippleLineCache.cpp +++ b/src/ripple/app/paths/RippleLineCache.cpp @@ -32,17 +32,19 @@ RippleLineCache::RippleLineCache( mLedger = std::make_shared(&*ledger, ledger); } -RippleLineCache::RippleStateVector const& +std::vector const& RippleLineCache::getRippleLines (AccountID const& accountID) { AccountKey key (accountID, hasher_ (accountID)); std::lock_guard sl (mLock); - auto it = mRLMap.emplace (key, RippleStateVector ()); + auto it = lines_.emplace (key, + std::vector()); if (it.second) - it.first->second = ripple::getRippleStateItems (accountID, *mLedger); + it.first->second = getRippleStateItems ( + accountID, *mLedger); return it.first->second; } diff --git a/src/ripple/app/paths/RippleLineCache.h b/src/ripple/app/paths/RippleLineCache.h index 0c2beece8..854fe83db 100644 --- a/src/ripple/app/paths/RippleLineCache.h +++ b/src/ripple/app/paths/RippleLineCache.h @@ -34,14 +34,12 @@ namespace ripple { class RippleLineCache { public: - using RippleStateVector = std::vector ; - using pointer = std::shared_ptr ; - using ref = pointer const&; - - explicit RippleLineCache (std::shared_ptr const& l); + explicit + RippleLineCache ( + std::shared_ptr const& l); std::shared_ptr const& - getLedger () // VFALCO TODO const? + getLedger () const { return mLedger; } @@ -91,7 +89,10 @@ private: }; }; - hash_map mRLMap; + hash_map < + AccountKey, + std::vector , + AccountKey::Hash> lines_; }; } // ripple diff --git a/src/ripple/ledger/ApplyViewImpl.h b/src/ripple/ledger/ApplyViewImpl.h index bd3554d69..3c5531c6f 100644 --- a/src/ripple/ledger/ApplyViewImpl.h +++ b/src/ripple/ledger/ApplyViewImpl.h @@ -34,7 +34,7 @@ namespace ripple { @note Presented as ApplyView to clients. */ -class ApplyViewImpl +class ApplyViewImpl final : public detail::ApplyViewBase { public: diff --git a/src/ripple/ledger/OpenView.h b/src/ripple/ledger/OpenView.h index ce9f4fc3a..dd0e3759b 100644 --- a/src/ripple/ledger/OpenView.h +++ b/src/ripple/ledger/OpenView.h @@ -45,7 +45,7 @@ extern open_ledger_t const open_ledger; @note Presented as ReadView to clients. */ -class OpenView +class OpenView final : public ReadView , public TxsRawView { diff --git a/src/ripple/ledger/PaymentSandbox.h b/src/ripple/ledger/PaymentSandbox.h index cdf989d17..6753d6410 100644 --- a/src/ripple/ledger/PaymentSandbox.h +++ b/src/ripple/ledger/PaymentSandbox.h @@ -87,7 +87,7 @@ private: @note Presented as ApplyView to clients */ -class PaymentSandbox +class PaymentSandbox final : public detail::ApplyViewBase { public: diff --git a/src/ripple/rpc/RipplePathFind.h b/src/ripple/rpc/RipplePathFind.h index f1677ce92..4e23843d5 100644 --- a/src/ripple/rpc/RipplePathFind.h +++ b/src/ripple/rpc/RipplePathFind.h @@ -26,7 +26,7 @@ namespace ripple { std::pair -ripplePathFind (RippleLineCache::pointer const& cache, +ripplePathFind (std::shared_ptr const& cache, AccountID const& raSrc, AccountID const& raDst, STAmount const& saDstAmount, Json::Value const& jvSrcCurrencies, diff --git a/src/ripple/rpc/handlers/RipplePathFind.cpp b/src/ripple/rpc/handlers/RipplePathFind.cpp index db1885b7d..14db256c6 100644 --- a/src/ripple/rpc/handlers/RipplePathFind.cpp +++ b/src/ripple/rpc/handlers/RipplePathFind.cpp @@ -52,7 +52,7 @@ static unsigned int const max_paths = 4; static Json::Value buildSrcCurrencies(AccountID const& account, - RippleLineCache::pointer const& cache) + std::shared_ptr const& cache) { auto currencies = accountSourceCurrencies(account, cache, true); auto jvSrcCurrencies = Json::Value(Json::arrayValue); @@ -163,7 +163,7 @@ Json::Value doRipplePathFind (RPC::Context& context) } else { - RippleLineCache::pointer cache; + std::shared_ptr cache; if (lpLedger) { @@ -265,7 +265,7 @@ Json::Value doRipplePathFind (RPC::Context& context) } std::unique_ptr const& -getPathFinder(RippleLineCache::ref cache, AccountID const& raSrc, +getPathFinder(std::shared_ptr const& cache, AccountID const& raSrc, AccountID const& raDst, boost::optional saSendMax, hash_map>& currency_map, Currency const& currency, STAmount const& dst_amount, @@ -284,7 +284,7 @@ getPathFinder(RippleLineCache::ref cache, AccountID const& raSrc, } std::pair -ripplePathFind (RippleLineCache::pointer const& cache, +ripplePathFind (std::shared_ptr const& cache, AccountID const& raSrc, AccountID const& raDst, STAmount const& saDstAmount, Json::Value const& jvSrcCurrencies, boost::optional const& contextPaths,