mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Use BasicView:
Many functions and classes that used a Ledger now use a BasicView. Calls to cachedRead are changed to call member read on the view, note that this bypasses the SLECache optimization. To restore the optimization, the BasicView passed at the top of call stacks should be wrapped with a caching view, coming in future commits.
This commit is contained in:
@@ -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");
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -77,7 +77,6 @@ public:
|
||||
Json::Value getStatus ();
|
||||
|
||||
Json::Value doCreate (
|
||||
const std::shared_ptr<Ledger>&,
|
||||
const RippleLineCache::pointer&,
|
||||
Json::Value const&,
|
||||
bool&);
|
||||
|
||||
@@ -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 <BasicView const> 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>(*ledger, false); // Take a snapshot of the ledger
|
||||
mLineCache = std::make_shared<RippleLineCache> (ledger);
|
||||
}
|
||||
else
|
||||
{
|
||||
ledger = mLineCache->getLedger();
|
||||
}
|
||||
return mLineCache;
|
||||
}
|
||||
|
||||
void PathRequests::updateAll (Ledger::ref inLedger,
|
||||
void PathRequests::updateAll (std::shared_ptr <BasicView const> const& inLedger,
|
||||
Job::CancelCallback shouldCancel)
|
||||
{
|
||||
std::vector<PathRequest::wptr> 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 <InfoSub> const& subscriber,
|
||||
const std::shared_ptr<Ledger>& inLedger,
|
||||
std::shared_ptr<BasicView const> const& inLedger,
|
||||
Json::Value const& requestJson)
|
||||
{
|
||||
PathRequest::pointer req = std::make_shared<PathRequest> (
|
||||
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 <void (void)> completion,
|
||||
const std::shared_ptr<Ledger>& inLedger,
|
||||
std::shared_ptr<BasicView const> 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<PathRequest> (
|
||||
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)
|
||||
{
|
||||
|
||||
@@ -38,21 +38,21 @@ public:
|
||||
mFull = collector->make_event ("pathfind_full");
|
||||
}
|
||||
|
||||
void updateAll (const std::shared_ptr<Ledger>& ledger,
|
||||
void updateAll (std::shared_ptr<BasicView const> const& ledger,
|
||||
Job::CancelCallback shouldCancel);
|
||||
|
||||
RippleLineCache::pointer getLineCache (
|
||||
Ledger::pointer& ledger, bool authoritative);
|
||||
std::shared_ptr <BasicView const> const& ledger, bool authoritative);
|
||||
|
||||
Json::Value makePathRequest (
|
||||
std::shared_ptr <InfoSub> const& subscriber,
|
||||
const std::shared_ptr<Ledger>& ledger,
|
||||
std::shared_ptr<BasicView const> const& ledger,
|
||||
Json::Value const& request);
|
||||
|
||||
Json::Value makeLegacyPathRequest (
|
||||
PathRequest::pointer& req,
|
||||
std::function <void (void)> completion,
|
||||
const std::shared_ptr<Ledger>& inLedger,
|
||||
std::shared_ptr<BasicView const> const& inLedger,
|
||||
Json::Value const& request);
|
||||
|
||||
void reportFast (int milliseconds)
|
||||
|
||||
@@ -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));
|
||||
|
||||
|
||||
@@ -185,7 +185,7 @@ private:
|
||||
been removed. */
|
||||
STAmount mRemainingAmount;
|
||||
|
||||
Ledger::pointer mLedger;
|
||||
std::shared_ptr <BasicView const> mLedger;
|
||||
LoadEvent::pointer m_loadEvent;
|
||||
RippleLineCache::pointer mRLCache;
|
||||
|
||||
|
||||
@@ -19,12 +19,15 @@
|
||||
|
||||
#include <BeastConfig.h>
|
||||
#include <ripple/app/paths/RippleLineCache.h>
|
||||
#include <ripple/app/ledger/MetaView.h>
|
||||
|
||||
namespace ripple {
|
||||
|
||||
RippleLineCache::RippleLineCache (Ledger::ref l)
|
||||
: mLedger (l)
|
||||
RippleLineCache::RippleLineCache (std::shared_ptr <BasicView const> 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 <MetaView> (*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;
|
||||
}
|
||||
|
||||
@@ -37,9 +37,9 @@ public:
|
||||
using pointer = std::shared_ptr <RippleLineCache>;
|
||||
using ref = pointer const&;
|
||||
|
||||
explicit RippleLineCache (Ledger::ref l);
|
||||
explicit RippleLineCache (std::shared_ptr <BasicView const> const& l);
|
||||
|
||||
Ledger::ref getLedger () // VFALCO TODO const?
|
||||
std::shared_ptr <BasicView const> const& getLedger () // VFALCO TODO const?
|
||||
{
|
||||
return mLedger;
|
||||
}
|
||||
@@ -53,7 +53,7 @@ private:
|
||||
LockType mLock;
|
||||
|
||||
ripple::hardened_hash<> hasher_;
|
||||
Ledger::pointer mLedger;
|
||||
std::shared_ptr <BasicView const> mLedger;
|
||||
|
||||
struct AccountKey
|
||||
{
|
||||
|
||||
@@ -72,12 +72,9 @@ Json::Value RippleState::getJson (int)
|
||||
}
|
||||
|
||||
std::vector <RippleState::pointer>
|
||||
getRippleStateItems (
|
||||
AccountID const& accountID,
|
||||
Ledger::ref ledger)
|
||||
getRippleStateItems (AccountID const& accountID,
|
||||
BasicView const& view)
|
||||
{
|
||||
CachedView const view(
|
||||
*ledger, getApp().getSLECache());
|
||||
std::vector <RippleState::pointer> items;
|
||||
forEachItem(view, accountID,
|
||||
[&items,&accountID](
|
||||
|
||||
@@ -20,8 +20,7 @@
|
||||
#ifndef RIPPLE_APP_PATHS_RIPPLESTATE_H_INCLUDED
|
||||
#define RIPPLE_APP_PATHS_RIPPLESTATE_H_INCLUDED
|
||||
|
||||
#include <ripple/app/ledger/Ledger.h>
|
||||
#include <ripple/app/ledger/MetaView.h>
|
||||
#include <ripple/ledger/View.h>
|
||||
#include <ripple/protocol/STAmount.h>
|
||||
#include <ripple/protocol/STLedgerEntry.h>
|
||||
#include <cstdint>
|
||||
@@ -156,9 +155,8 @@ private:
|
||||
};
|
||||
|
||||
std::vector <RippleState::pointer>
|
||||
getRippleStateItems (
|
||||
AccountID const& accountID,
|
||||
Ledger::ref ledger);
|
||||
getRippleStateItems (AccountID const& accountID,
|
||||
BasicView const& view);
|
||||
|
||||
} // ripple
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ public:
|
||||
auto result = ripplePathFind(
|
||||
std::make_shared<RippleLineCache>(
|
||||
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");
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace ripple {
|
||||
std::pair<bool, Json::Value>
|
||||
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<Json::Value> const& contextPaths,
|
||||
int const& level);
|
||||
|
||||
@@ -65,7 +65,7 @@ Json::Value doAccountCurrencies (RPC::Context& context)
|
||||
return jvAccepted;
|
||||
|
||||
std::set<Currency> send, receive;
|
||||
for (auto const& item : getRippleStateItems (accountID, ledger))
|
||||
for (auto const& item : getRippleStateItems (accountID, *ledger))
|
||||
{
|
||||
auto const rspEntry = item.get();
|
||||
|
||||
|
||||
@@ -199,7 +199,7 @@ Json::Value doRipplePathFind (RPC::Context& context)
|
||||
boost::optional<Json::Value>(context.params[jss::paths]) :
|
||||
boost::optional<Json::Value>(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<bool, Json::Value>
|
||||
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<Json::Value> const& contextPaths, int const& level)
|
||||
{
|
||||
FindPaths fp(
|
||||
@@ -304,7 +303,7 @@ ripplePathFind (RippleLineCache::pointer const& cache,
|
||||
saMaxAmount.negate();
|
||||
|
||||
boost::optional<PaymentView> 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,
|
||||
|
||||
Reference in New Issue
Block a user