diff --git a/src/ripple/app/ledger/tests/common_ledger.cpp b/src/ripple/app/ledger/tests/common_ledger.cpp index 4613f6517f..90619c2a4f 100644 --- a/src/ripple/app/ledger/tests/common_ledger.cpp +++ b/src/ripple/app/ledger/tests/common_ledger.cpp @@ -494,7 +494,7 @@ Json::Value findPath(Ledger::pointer ledger, TestAccount const& src, auto result = ripplePathFind(cache, calcAccountID(src.pk), calcAccountID(dest.pk), saDstAmount, - ledger, jvSrcCurrencies, contextPaths, level); + jvSrcCurrencies, contextPaths, level); if(!result.first) throw std::runtime_error( "ripplePathFind find failed"); diff --git a/src/ripple/app/paths/PathRequest.cpp b/src/ripple/app/paths/PathRequest.cpp index dd987b8e15..9d3c53fdad 100644 --- a/src/ripple/app/paths/PathRequest.cpp +++ b/src/ripple/app/paths/PathRequest.cpp @@ -177,7 +177,7 @@ bool PathRequest::isValid (RippleLineCache::ref crCache) ScopedLockType sl (mLock); bValid = raSrcAccount && raDstAccount && saDstAmount > zero; - Ledger::pointer lrLedger = crCache->getLedger (); + auto const& lrLedger = crCache->getLedger (); if (bValid) { @@ -192,9 +192,8 @@ bool PathRequest::isValid (RippleLineCache::ref crCache) if (bValid) { - auto const sleDest = cachedRead(*crCache->getLedger(), - keylet::account(*raDstAccount).key, - getApp().getSLECache(), ltACCOUNT_ROOT); + auto const sleDest = crCache->getLedger()->read( + keylet::account(*raDstAccount)); Json::Value& jvDestCur = (jvStatus[jss::destination_currencies] = Json::arrayValue); @@ -210,7 +209,7 @@ bool PathRequest::isValid (RippleLineCache::ref crCache) bValid = false; jvStatus = rpcError (rpcACT_NOT_FOUND); } - else if (saDstAmount < STAmount (lrLedger->getReserve (0))) + else if (saDstAmount < STAmount (lrLedger->fees().accountReserve (0))) { // payment must meet reserve bValid = false; @@ -236,14 +235,13 @@ bool PathRequest::isValid (RippleLineCache::ref crCache) if (bValid) { - jvStatus[jss::ledger_hash] = to_string (lrLedger->getHash ()); - jvStatus[jss::ledger_index] = lrLedger->getLedgerSeq (); + jvStatus[jss::ledger_hash] = to_string (lrLedger->info().hash); + jvStatus[jss::ledger_index] = lrLedger->seq(); } return bValid; } Json::Value PathRequest::doCreate ( - Ledger::ref lrLedger, RippleLineCache::ref& cache, Json::Value const& value, bool& valid) diff --git a/src/ripple/app/paths/PathRequest.h b/src/ripple/app/paths/PathRequest.h index 057341be88..6342d37983 100644 --- a/src/ripple/app/paths/PathRequest.h +++ b/src/ripple/app/paths/PathRequest.h @@ -77,7 +77,6 @@ public: Json::Value getStatus (); Json::Value doCreate ( - const std::shared_ptr&, const RippleLineCache::pointer&, Json::Value const&, bool&); diff --git a/src/ripple/app/paths/PathRequests.cpp b/src/ripple/app/paths/PathRequests.cpp index 0812f5840b..303077a2e1 100644 --- a/src/ripple/app/paths/PathRequests.cpp +++ b/src/ripple/app/paths/PathRequests.cpp @@ -30,29 +30,26 @@ namespace ripple { /** Get the current RippleLineCache, updating it if necessary. Get the correct ledger to use. */ -RippleLineCache::pointer PathRequests::getLineCache (Ledger::pointer& ledger, bool authoritative) +RippleLineCache::pointer PathRequests::getLineCache ( + std::shared_ptr const& ledger, bool authoritative) { + ScopedLockType sl (mLock); - std::uint32_t lineSeq = mLineCache ? mLineCache->getLedger()->getLedgerSeq() : 0; - std::uint32_t lgrSeq = ledger->getLedgerSeq(); + std::uint32_t lineSeq = mLineCache ? mLineCache->getLedger()->seq() : 0; + std::uint32_t lgrSeq = ledger->seq(); if ( (lineSeq == 0) || // no ledger (authoritative && (lgrSeq > lineSeq)) || // newer authoritative ledger (authoritative && ((lgrSeq + 8) < lineSeq)) || // we jumped way back for some reason (lgrSeq > (lineSeq + 8))) // we jumped way forward for some reason { - ledger = std::make_shared(*ledger, false); // Take a snapshot of the ledger mLineCache = std::make_shared (ledger); } - else - { - ledger = mLineCache->getLedger(); - } return mLineCache; } -void PathRequests::updateAll (Ledger::ref inLedger, +void PathRequests::updateAll (std::shared_ptr const& inLedger, Job::CancelCallback shouldCancel) { std::vector requests; @@ -60,18 +57,17 @@ void PathRequests::updateAll (Ledger::ref inLedger, LoadEvent::autoptr event (getApp().getJobQueue().getLoadEventAP(jtPATH_FIND, "PathRequest::updateAll")); // Get the ledger and cache we should be using - Ledger::pointer ledger = inLedger; RippleLineCache::pointer cache; { ScopedLockType sl (mLock); requests = mRequests; - cache = getLineCache (ledger, true); + cache = getLineCache (inLedger, true); } bool newRequests = getApp().getLedgerMaster().isNewPathRequest(); bool mustBreak = false; - mJournal.trace << "updateAll seq=" << ledger->getLedgerSeq() << ", " << + mJournal.trace << "updateAll seq=" << cache->getLedger()->seq() << ", " << requests.size() << " requests"; int processed = 0, removed = 0; @@ -87,7 +83,7 @@ void PathRequests::updateAll (Ledger::ref inLedger, if (pRequest) { - if (!pRequest->needsUpdate (newRequests, ledger->getLedgerSeq ())) + if (!pRequest->needsUpdate (newRequests, cache->getLedger()->seq())) remove = false; else { @@ -165,7 +161,7 @@ void PathRequests::updateAll (Ledger::ref inLedger, break; requests = mRequests; - cache = getLineCache (ledger, false); + cache = getLineCache (cache->getLedger(), false); } } @@ -196,22 +192,21 @@ void PathRequests::insertPathRequest (PathRequest::pointer const& req) // Make a new-style path_find request Json::Value PathRequests::makePathRequest( std::shared_ptr const& subscriber, - const std::shared_ptr& inLedger, + std::shared_ptr const& inLedger, Json::Value const& requestJson) { PathRequest::pointer req = std::make_shared ( subscriber, ++mLastIdentifier, *this, mJournal); - Ledger::pointer ledger = inLedger; RippleLineCache::pointer cache; { ScopedLockType sl (mLock); - cache = getLineCache (ledger, false); + cache = getLineCache (inLedger, false); } bool valid = false; - Json::Value result = req->doCreate (ledger, cache, requestJson, valid); + Json::Value result = req->doCreate (cache, requestJson, valid); if (valid) { @@ -226,7 +221,7 @@ Json::Value PathRequests::makePathRequest( Json::Value PathRequests::makeLegacyPathRequest( PathRequest::pointer& req, std::function completion, - const std::shared_ptr& inLedger, + std::shared_ptr const& inLedger, Json::Value const& request) { // This assignment must take place before the @@ -234,16 +229,15 @@ Json::Value PathRequests::makeLegacyPathRequest( req = std::make_shared ( completion, ++mLastIdentifier, *this, mJournal); - auto ledger = inLedger; RippleLineCache::pointer cache; { ScopedLockType sl (mLock); - cache = getLineCache (ledger, false); + cache = getLineCache (inLedger, false); } bool valid = false; - Json::Value result = req->doCreate (ledger, cache, request, valid); + Json::Value result = req->doCreate (cache, request, valid); if (!valid) { diff --git a/src/ripple/app/paths/PathRequests.h b/src/ripple/app/paths/PathRequests.h index 5633ae5129..f1734d232b 100644 --- a/src/ripple/app/paths/PathRequests.h +++ b/src/ripple/app/paths/PathRequests.h @@ -38,21 +38,21 @@ public: mFull = collector->make_event ("pathfind_full"); } - void updateAll (const std::shared_ptr& ledger, + void updateAll (std::shared_ptr const& ledger, Job::CancelCallback shouldCancel); RippleLineCache::pointer getLineCache ( - Ledger::pointer& ledger, bool authoritative); + std::shared_ptr const& ledger, bool authoritative); Json::Value makePathRequest ( std::shared_ptr const& subscriber, - const std::shared_ptr& ledger, + std::shared_ptr const& ledger, Json::Value const& request); Json::Value makeLegacyPathRequest ( PathRequest::pointer& req, std::function completion, - const std::shared_ptr& inLedger, + std::shared_ptr const& inLedger, Json::Value const& request); void reportFast (int milliseconds) diff --git a/src/ripple/app/paths/Pathfinder.cpp b/src/ripple/app/paths/Pathfinder.cpp index dfa8e5b051..23a6e9c23f 100644 --- a/src/ripple/app/paths/Pathfinder.cpp +++ b/src/ripple/app/paths/Pathfinder.cpp @@ -298,7 +298,7 @@ bool Pathfinder::findPaths (int searchLevel) return false; } - auto const reserve = STAmount (mLedger->getReserve (0)); + auto const reserve = STAmount (mLedger->fees().accountReserve (0)); if (mDstAmount < reserve) { WriteLog (lsDEBUG, Pathfinder) @@ -704,8 +704,7 @@ int Pathfinder::getPathsOut ( if (!it.second) return it.first->second; - auto sleAccount = cachedRead(*mLedger, getAccountRootIndex (account), - getApp().getSLECache()); + auto sleAccount = mLedger->read(keylet::account (account)); if (!sleAccount) return 0; @@ -841,9 +840,8 @@ bool Pathfinder::isNoRipple ( AccountID const& toAccount, Currency const& currency) { - auto sleRipple = cachedRead (*mLedger, - getRippleStateIndex (toAccount, fromAccount, currency), - getApp().getSLECache()); + auto sleRipple = mLedger->read(keylet::line( + toAccount, fromAccount, currency)); auto const flag ((toAccount > fromAccount) ? lsfHighNoRipple : lsfLowNoRipple); @@ -921,9 +919,7 @@ void Pathfinder::addLink ( else { // search for accounts to add - auto const sleEnd = cachedRead( - *mLedger, getAccountRootIndex (uEndAccount), - getApp().getSLECache()); + auto const sleEnd = mLedger->read(keylet::account(uEndAccount)); if (sleEnd) { @@ -1024,7 +1020,7 @@ void Pathfinder::addLink ( { std::sort (candidates.begin (), candidates.end (), std::bind(compareAccountCandidate, - mLedger->getLedgerSeq (), + mLedger->seq(), std::placeholders::_1, std::placeholders::_2)); diff --git a/src/ripple/app/paths/Pathfinder.h b/src/ripple/app/paths/Pathfinder.h index c63896015b..41dabb40f4 100644 --- a/src/ripple/app/paths/Pathfinder.h +++ b/src/ripple/app/paths/Pathfinder.h @@ -185,7 +185,7 @@ private: been removed. */ STAmount mRemainingAmount; - Ledger::pointer mLedger; + std::shared_ptr mLedger; LoadEvent::pointer m_loadEvent; RippleLineCache::pointer mRLCache; diff --git a/src/ripple/app/paths/RippleLineCache.cpp b/src/ripple/app/paths/RippleLineCache.cpp index 32c7532bf5..22d982c20b 100644 --- a/src/ripple/app/paths/RippleLineCache.cpp +++ b/src/ripple/app/paths/RippleLineCache.cpp @@ -19,12 +19,15 @@ #include #include +#include namespace ripple { -RippleLineCache::RippleLineCache (Ledger::ref l) - : mLedger (l) +RippleLineCache::RippleLineCache (std::shared_ptr const& l) { + // We want the caching that MetaView provides + // And we need to own a shared_ptr to the input view + mLedger = std::make_shared (*l, tapNONE, l); } RippleLineCache::RippleStateVector const& @@ -37,7 +40,7 @@ RippleLineCache::getRippleLines (AccountID const& accountID) auto it = mRLMap.emplace (key, RippleStateVector ()); if (it.second) - it.first->second = ripple::getRippleStateItems (accountID, mLedger); + it.first->second = ripple::getRippleStateItems (accountID, *mLedger); return it.first->second; } diff --git a/src/ripple/app/paths/RippleLineCache.h b/src/ripple/app/paths/RippleLineCache.h index 8fb03531a8..938b407997 100644 --- a/src/ripple/app/paths/RippleLineCache.h +++ b/src/ripple/app/paths/RippleLineCache.h @@ -37,9 +37,9 @@ public: using pointer = std::shared_ptr ; using ref = pointer const&; - explicit RippleLineCache (Ledger::ref l); + explicit RippleLineCache (std::shared_ptr const& l); - Ledger::ref getLedger () // VFALCO TODO const? + std::shared_ptr const& getLedger () // VFALCO TODO const? { return mLedger; } @@ -53,7 +53,7 @@ private: LockType mLock; ripple::hardened_hash<> hasher_; - Ledger::pointer mLedger; + std::shared_ptr mLedger; struct AccountKey { diff --git a/src/ripple/app/paths/RippleState.cpp b/src/ripple/app/paths/RippleState.cpp index f5612de0a5..d4a0742dc9 100644 --- a/src/ripple/app/paths/RippleState.cpp +++ b/src/ripple/app/paths/RippleState.cpp @@ -72,12 +72,9 @@ Json::Value RippleState::getJson (int) } std::vector -getRippleStateItems ( - AccountID const& accountID, - Ledger::ref ledger) +getRippleStateItems (AccountID const& accountID, + BasicView const& view) { - CachedView const view( - *ledger, getApp().getSLECache()); std::vector items; forEachItem(view, accountID, [&items,&accountID]( diff --git a/src/ripple/app/paths/RippleState.h b/src/ripple/app/paths/RippleState.h index fe9ba608cc..f64426f872 100644 --- a/src/ripple/app/paths/RippleState.h +++ b/src/ripple/app/paths/RippleState.h @@ -20,8 +20,7 @@ #ifndef RIPPLE_APP_PATHS_RIPPLESTATE_H_INCLUDED #define RIPPLE_APP_PATHS_RIPPLESTATE_H_INCLUDED -#include -#include +#include #include #include #include @@ -156,9 +155,8 @@ private: }; std::vector -getRippleStateItems ( - AccountID const& accountID, - Ledger::ref ledger); +getRippleStateItems (AccountID const& accountID, + BasicView const& view); } // ripple diff --git a/src/ripple/app/paths/tests/Path_test.cpp b/src/ripple/app/paths/tests/Path_test.cpp index d694fecfa1..67247635fe 100644 --- a/src/ripple/app/paths/tests/Path_test.cpp +++ b/src/ripple/app/paths/tests/Path_test.cpp @@ -50,7 +50,7 @@ public: auto result = ripplePathFind( std::make_shared( ledger), src.id(), dest.id(), saDstAmount, - ledger, jvSrcCurrencies, boost::none, level); + jvSrcCurrencies, boost::none, level); if(!result.first) throw std::runtime_error( "Path_test::findPath: ripplePathFind find failed"); diff --git a/src/ripple/rpc/RipplePathFind.h b/src/ripple/rpc/RipplePathFind.h index eeceb44b54..377fea0010 100644 --- a/src/ripple/rpc/RipplePathFind.h +++ b/src/ripple/rpc/RipplePathFind.h @@ -28,7 +28,7 @@ namespace ripple { std::pair ripplePathFind (RippleLineCache::pointer const& cache, AccountID const& raSrc, AccountID const& raDst, - STAmount const& saDstAmount, Ledger::pointer const& lpLedger, + STAmount const& saDstAmount, Json::Value const& jvSrcCurrencies, boost::optional const& contextPaths, int const& level); diff --git a/src/ripple/rpc/handlers/AccountCurrencies.cpp b/src/ripple/rpc/handlers/AccountCurrencies.cpp index c49ed19b13..475e57d8f8 100644 --- a/src/ripple/rpc/handlers/AccountCurrencies.cpp +++ b/src/ripple/rpc/handlers/AccountCurrencies.cpp @@ -65,7 +65,7 @@ Json::Value doAccountCurrencies (RPC::Context& context) return jvAccepted; std::set send, receive; - for (auto const& item : getRippleStateItems (accountID, ledger)) + for (auto const& item : getRippleStateItems (accountID, *ledger)) { auto const rspEntry = item.get(); diff --git a/src/ripple/rpc/handlers/RipplePathFind.cpp b/src/ripple/rpc/handlers/RipplePathFind.cpp index 6fa16bf8c3..e7a4f3b17a 100644 --- a/src/ripple/rpc/handlers/RipplePathFind.cpp +++ b/src/ripple/rpc/handlers/RipplePathFind.cpp @@ -199,7 +199,7 @@ Json::Value doRipplePathFind (RPC::Context& context) boost::optional(context.params[jss::paths]) : boost::optional(boost::none); auto pathFindResult = ripplePathFind(cache, raSrc, raDst, saDstAmount, - lpLedger, jvSrcCurrencies, contextPaths, level); + jvSrcCurrencies, contextPaths, level); if (!pathFindResult.first) return pathFindResult.second; @@ -217,8 +217,7 @@ Json::Value doRipplePathFind (RPC::Context& context) std::pair ripplePathFind (RippleLineCache::pointer const& cache, AccountID const& raSrc, AccountID const& raDst, - STAmount const& saDstAmount, Ledger::pointer const& lpLedger, - Json::Value const& jvSrcCurrencies, + STAmount const& saDstAmount, Json::Value const& jvSrcCurrencies, boost::optional const& contextPaths, int const& level) { FindPaths fp( @@ -304,7 +303,7 @@ ripplePathFind (RippleLineCache::pointer const& cache, saMaxAmount.negate(); boost::optional sandbox; - sandbox.emplace(*lpLedger, tapNONE); + sandbox.emplace(*cache->getLedger(), tapNONE); assert(sandbox->open()); auto rc = path::RippleCalc::rippleCalculate( @@ -330,7 +329,7 @@ ripplePathFind (RippleLineCache::pointer const& cache, << "Trying with an extra path element"; spsComputed.push_back(fullLiquidityPath); - sandbox.emplace(*lpLedger, tapNONE); + sandbox.emplace(*cache->getLedger(), tapNONE); assert(sandbox->open()); rc = path::RippleCalc::rippleCalculate( *sandbox,