diff --git a/Builds/VisualStudio2013/RippleD.vcxproj b/Builds/VisualStudio2013/RippleD.vcxproj index 40128c5114..4609902cae 100644 --- a/Builds/VisualStudio2013/RippleD.vcxproj +++ b/Builds/VisualStudio2013/RippleD.vcxproj @@ -1647,6 +1647,12 @@ + + True + True + + + True True @@ -1751,8 +1757,6 @@ True True - - True True @@ -2261,7 +2265,7 @@ True True - + True True @@ -2269,8 +2273,6 @@ - - diff --git a/Builds/VisualStudio2013/RippleD.vcxproj.filters b/Builds/VisualStudio2013/RippleD.vcxproj.filters index 0b97d0865c..4febbbcc55 100644 --- a/Builds/VisualStudio2013/RippleD.vcxproj.filters +++ b/Builds/VisualStudio2013/RippleD.vcxproj.filters @@ -271,6 +271,9 @@ {9AD8D049-10A8-704C-D51A-FAD55B1F235F} + + {38932157-7DA1-A9CC-CABC-2A3D9CACF188} + {2E791662-6ED0-D1E1-03A4-0CB35473EC56} @@ -2373,6 +2376,12 @@ ripple\app\paths + + ripple\app\paths\impl + + + ripple\app\paths\impl + ripple\app\paths @@ -2472,9 +2481,6 @@ ripple\app\tx\impl - - ripple\app\tx\impl - ripple\app\tx\impl @@ -2964,7 +2970,7 @@ ripple\ledger\impl - + ripple\ledger\impl @@ -2973,9 +2979,6 @@ ripple\ledger - - ripple\ledger - ripple\ledger diff --git a/src/ripple/app/ledger/AcceptedLedgerTx.cpp b/src/ripple/app/ledger/AcceptedLedgerTx.cpp index 922b67fe42..bb1158c273 100644 --- a/src/ripple/app/ledger/AcceptedLedgerTx.cpp +++ b/src/ripple/app/ledger/AcceptedLedgerTx.cpp @@ -21,7 +21,6 @@ #include #include #include -#include #include #include #include diff --git a/src/ripple/app/ledger/MetaView.h b/src/ripple/app/ledger/MetaView.h index f4f5a44891..2319e2f2fa 100644 --- a/src/ripple/app/ledger/MetaView.h +++ b/src/ripple/app/ledger/MetaView.h @@ -21,7 +21,6 @@ #define RIPPLE_LEDGER_METAVIEW_H_INCLUDED #include -#include #include #include #include @@ -65,9 +64,6 @@ enum TransactionEngineParams class MetaView : public View { private: - using Mods = - hash_map; - enum Action { taaCACHED, // Unmodified. @@ -76,30 +72,18 @@ private: taaCREATE, // Newly created. }; - class Item - { - public: - int mSeq; - Action mAction; - std::shared_ptr mEntry; + using Item = std::pair>; - Item (SLE::ref e, Action a, int s) - : mSeq (s) - , mAction (a) - , mEntry (e) - { - } - }; + using Mods = hash_map>; using list_type = std::map; BasicView* parent_; - MetaView* mParent_ = NULL; list_type items_; - boost::optional mDeferredCredits; TransactionMetaSet mSet; TransactionEngineParams mParams = tapNONE; - int mSeq = 0; public: MetaView& operator= (MetaView const&) = delete; @@ -116,9 +100,7 @@ public: MetaView (Ledger::ref ledger, TransactionEngineParams tep); - /** Construct a nested view. - */ - MetaView (MetaView&); + MetaView (MetaView& parent); //-------------------------------------------------------------------------- // @@ -153,11 +135,6 @@ public: { return parent_; } - - STAmount - deprecatedBalance (AccountID const& account, - AccountID const& issuer, - STAmount const& amount) const override; //--------------------------------------------- @@ -176,40 +153,12 @@ public: bool openLedger() const override; - void - deprecatedCreditHint (AccountID const& from, - AccountID const& to, STAmount const& amount) override; - //-------------------------------------------------------------------------- /** Apply changes to the parent View */ void apply(); - // Swap the contents of two sets - void swapWith (MetaView&); - - // VFALCO Only called from RippleCalc.cpp - void deprecatedInvalidate() - { - parent_ = nullptr; - mDeferredCredits.reset (); - } - - bool isValid () const - { - return parent_ != nullptr; - } - - void bumpSeq () - { - ++mSeq; - } - - void enableDeferredCredits (bool enable=true); - - bool areCreditsDeferred () const; - // For diagnostics Json::Value getJson (int) const; @@ -221,9 +170,6 @@ public: } private: - std::shared_ptr const& - copyOnRead (list_type::iterator iter); - std::shared_ptr getForMod (uint256 const& key, Mods& mods); @@ -241,29 +187,6 @@ private: SLE const> const& sle, Mods& mods); }; -// DEPRECATED Temporary measure, remove ASAP -template -inline -void -reconstruct (MetaView& v, Args&&... args) noexcept -{ - v.~MetaView(); - new(&v) MetaView( - std::forward(args)...); -} - -//------------------------------------------------------------------------------ - -class ScopedDeferCredits -{ -private: - MetaView& les_; - bool enabled_; -public: - ScopedDeferCredits(MetaView& l); - ~ScopedDeferCredits (); -}; - } // ripple #endif diff --git a/src/ripple/app/ledger/impl/MetaView.cpp b/src/ripple/app/ledger/impl/MetaView.cpp index e1a2b8ffbe..0422df189e 100644 --- a/src/ripple/app/ledger/impl/MetaView.cpp +++ b/src/ripple/app/ledger/impl/MetaView.cpp @@ -22,8 +22,6 @@ #include #include #include -#include -#include #include #include #include @@ -69,35 +67,14 @@ MetaView::MetaView (Ledger::ref ledger, { } -MetaView::MetaView (MetaView& other) - : parent_(&other) - , mParent_(&other) - , items_(other.items_) - , mSet(other.mSet) - // VFALCO NOTE This is a change in behavior, - // previous version set tapNONE - , mParams(other.mParams) - , mSeq(other.mSeq + 1) +MetaView::MetaView (MetaView& parent) + : parent_(&parent) + , mParams(parent.mParams) { - if (other.mDeferredCredits) - mDeferredCredits.emplace(); } //------------------------------------------------------------------------------ -std::shared_ptr const& -MetaView::copyOnRead ( - list_type::iterator iter) -{ - if (iter->second.mSeq != mSeq) - { - iter->second.mSeq = mSeq; - iter->second.mEntry = std::make_shared( - *iter->second.mEntry); - } - return iter->second.mEntry; -} - bool MetaView::exists (Keylet const& k) const { @@ -105,9 +82,9 @@ MetaView::exists (Keylet const& k) const auto const iter = items_.find(k.key); if (iter == items_.end()) return parent_->exists(k); - if (iter->second.mAction == taaDELETE) + if (iter->second.first == taaDELETE) return false; - if (! k.check(*iter->second.mEntry)) + if (! k.check(*iter->second.second)) return false; return true; } @@ -132,12 +109,12 @@ MetaView::succ (uint256 const& key, iter = items_.find(*next); } while (iter != items_.end() && - iter->second.mAction == taaDELETE); + iter->second.first == taaDELETE); // Find non-deleted successor in our list for (iter = items_.upper_bound(key); iter != items_.end (); ++iter) { - if (iter->second.mAction != taaDELETE) + if (iter->second.first != taaDELETE) { // Found both, return the lower key if (! next || next > iter->first) @@ -169,10 +146,10 @@ MetaView::read (Keylet const& k) const return nullptr; return sle; } - if (iter->second.mAction == taaDELETE) + if (iter->second.first == taaDELETE) return nullptr; auto const& sle = - iter->second.mEntry; + iter->second.second; if (! k.check(*sle)) return nullptr; return sle; @@ -191,18 +168,17 @@ MetaView::unchecked_erase (uint256 const& key) using namespace std; items_.emplace_hint(iter, piecewise_construct, forward_as_tuple(key), forward_as_tuple( - make_shared(*parent_->read( - keylet::unchecked(key))), - taaDELETE, mSeq)); + taaDELETE, make_shared( + *parent_->read(keylet::unchecked(key))))); return true; } - if (iter->second.mAction == taaCREATE) + if (iter->second.first == taaCREATE) { items_.erase(iter); return true; } - assert(iter->second.mAction != taaDELETE); - iter->second.mAction = taaDELETE; + assert(iter->second.first != taaDELETE); + iter->second.first = taaDELETE; return true; } @@ -221,11 +197,11 @@ MetaView::unchecked_insert( using namespace std; items_.emplace_hint(iter, piecewise_construct, forward_as_tuple(sle->key()), - forward_as_tuple(move(sle), - taaCREATE, mSeq)); + forward_as_tuple(taaCREATE, + move(sle))); return; } - switch(iter->second.mAction) + switch(iter->second.first) { case taaMODIFY: throw std::runtime_error( @@ -243,9 +219,8 @@ MetaView::unchecked_insert( // VFALCO return Keylet from SLE assert(parent_->exists( Keylet{sle->getType(), sle->key()})); - iter->second.mSeq = mSeq; - iter->second.mEntry = std::move(sle); - iter->second.mAction = taaMODIFY; + iter->second.first = taaMODIFY; + iter->second.second = std::move(sle); } void @@ -262,43 +237,16 @@ MetaView::unchecked_replace (std::shared_ptr&& sle) using namespace std; items_.emplace_hint(iter, piecewise_construct, forward_as_tuple(sle->key()), - forward_as_tuple(move(sle), - taaMODIFY, mSeq)); + forward_as_tuple(taaMODIFY, + move(sle))); return; } - if (iter->second.mAction == taaDELETE) + if (iter->second.first == taaDELETE) throw std::runtime_error( "replace after delete"); - if (iter->second.mAction != taaCREATE) - iter->second.mAction = taaMODIFY; - iter->second.mSeq = mSeq; - iter->second.mEntry = std::move(sle); -} - -STAmount -MetaView::deprecatedBalance( - AccountID const& account, AccountID const& issuer, - STAmount const& amount) const -{ - if (mDeferredCredits) - { - if (mParent_) - { - assert (mParent_->mDeferredCredits); - return mDeferredCredits->adjustedBalance( - account, issuer, mParent_->deprecatedBalance(account, issuer, amount)); - } - - return mDeferredCredits->adjustedBalance( - account, issuer, amount); - } - else if (mParent_ && mParent_->mDeferredCredits) - { - return mParent_->mDeferredCredits->adjustedBalance( - account, issuer, amount); - } - - return amount; + if (iter->second.first != taaCREATE) + iter->second.first = taaMODIFY; + iter->second.second = std::move(sle); } std::shared_ptr @@ -319,18 +267,15 @@ MetaView::peek (Keylet const& k) iter = items_.emplace_hint (iter, std::piecewise_construct, std::forward_as_tuple(sle->getIndex()), - std::forward_as_tuple( - std::make_shared( - *sle), taaCACHED, mSeq)); - return iter->second.mEntry; + std::forward_as_tuple(taaCACHED, + std::make_shared(*sle))); + return iter->second.second; } - if (iter->second.mAction == taaDELETE) + if (iter->second.first == taaDELETE) return nullptr; - auto sle = - copyOnRead(iter); - if (! k.check(*sle)) + if (! k.check(*iter->second.second)) return nullptr; - return sle; + return iter->second.second; } void @@ -341,19 +286,18 @@ MetaView::erase (std::shared_ptr const& sle) assert(iter != items_.end()); if (iter == items_.end()) return; - assert(iter->second.mSeq == mSeq); - assert(iter->second.mEntry == sle); - assert(iter->second.mAction != taaDELETE); - if (iter->second.mAction == taaDELETE) + assert(iter->second.first != taaDELETE); + assert(iter->second.second == sle); + if (iter->second.first == taaDELETE) return; - if (iter->second.mAction == taaCREATE) + if (iter->second.first == taaCREATE) { items_.erase(iter); return; } - assert(iter->second.mAction == taaCACHED || - iter->second.mAction == taaMODIFY); - iter->second.mAction = taaDELETE; + assert(iter->second.first == taaCACHED || + iter->second.first == taaMODIFY); + iter->second.first = taaDELETE; } void @@ -368,10 +312,10 @@ MetaView::insert (std::shared_ptr const& sle) Keylet{sle->getType(), sle->key()})); items_.emplace_hint(iter, std::piecewise_construct, std::forward_as_tuple(sle->getIndex()), - std::forward_as_tuple(sle, taaCREATE, mSeq)); + std::forward_as_tuple(taaCREATE, sle)); return; } - switch(iter->second.mAction) + switch(iter->second.first) { case taaMODIFY: throw std::runtime_error( @@ -389,9 +333,8 @@ MetaView::insert (std::shared_ptr const& sle) // Existed in parent, deleted here assert(parent_->exists( Keylet{sle->getType(), sle->key()})); - iter->second.mSeq = mSeq; - iter->second.mEntry = sle; - iter->second.mAction = taaMODIFY; + iter->second.first = taaMODIFY; + iter->second.second = sle; } void @@ -406,17 +349,16 @@ MetaView::update (std::shared_ptr const& sle) Keylet{sle->getType(), sle->key()})); items_.emplace_hint(iter, std::piecewise_construct, std::forward_as_tuple(sle->key()), - std::forward_as_tuple(sle, taaMODIFY, mSeq)); + std::forward_as_tuple(taaMODIFY, sle)); return; } // VFALCO Should we throw? - assert(iter->second.mSeq == mSeq); - assert(iter->second.mEntry == sle); - if (iter->second.mAction == taaDELETE) + assert(iter->second.second == sle); + if (iter->second.first == taaDELETE) throw std::runtime_error( "update after delete"); - if (iter->second.mAction != taaCREATE) - iter->second.mAction = taaMODIFY; + if (iter->second.first != taaCREATE) + iter->second.first = taaMODIFY; } bool @@ -425,16 +367,6 @@ MetaView::openLedger() const return mParams & tapOPEN_LEDGER; } -void -MetaView::deprecatedCreditHint( - AccountID const& from, AccountID const& to, - STAmount const& amount) -{ - if (mDeferredCredits) - return mDeferredCredits->credit( - from, to, amount); -} - //------------------------------------------------------------------------------ void MetaView::apply() @@ -443,11 +375,11 @@ void MetaView::apply() // Write back the account states for (auto& item : items_) { - // VFALCO TODO rvalue move the mEntry, make + // VFALCO TODO rvalue move the second, make // sure the mNodes is not used after // this function is called. - auto& sle = item.second.mEntry; - switch (item.second.mAction) + auto& sle = item.second.second; + switch (item.second.first) { case taaCACHED: assert(parent_->exists( @@ -477,35 +409,11 @@ void MetaView::apply() } } - if (mDeferredCredits) - { - assert (mParent_ != NULL); - if (mParent_->areCreditsDeferred()) - { - for (auto& credit : *mDeferredCredits) - { - // This will go away soon - mParent_->mDeferredCredits->merge (credit); - } - } - } - // Safety precaution since we moved the // entries out, apply() cannot be called twice. items_.clear(); } -void MetaView::swapWith (MetaView& e) -{ - using std::swap; - swap (parent_, e.parent_); - items_.swap (e.items_); - mSet.swap (e.mSet); - swap (mParams, e.mParams); - swap (mSeq, e.mSeq); - swap (mDeferredCredits, e.mDeferredCredits); -} - Json::Value MetaView::getJson (int) const { Json::Value ret (Json::objectValue); @@ -517,7 +425,7 @@ Json::Value MetaView::getJson (int) const Json::Value entry (Json::objectValue); entry[jss::node] = to_string (it->first); - switch (it->second.mEntry->getType ()) + switch (it->second.second->getType ()) { case ltINVALID: entry[jss::type] = "invalid"; @@ -547,7 +455,7 @@ Json::Value MetaView::getJson (int) const assert (false); } - switch (it->second.mAction) + switch (it->second.first) { case taaCACHED: entry[jss::action] = "cache"; @@ -588,15 +496,15 @@ MetaView::getForMod (uint256 const& key, auto iter = items_.find (key); if (iter != items_.end ()) { - if (iter->second.mAction == taaDELETE) + if (iter->second.first == taaDELETE) { WriteLog (lsFATAL, View) << "Trying to thread to deleted node"; return nullptr; } - if (iter->second.mAction == taaCACHED) - iter->second.mAction = taaMODIFY; - return copyOnRead(iter); + if (iter->second.first == taaCACHED) + iter->second.first = taaMODIFY; + return iter->second.second; } { auto miter = mods.find (key); @@ -701,7 +609,7 @@ MetaView::calcRawMeta (Serializer& s, { auto type = &sfGeneric; - switch (it.second.mAction) + switch (it.second.first) { case taaMODIFY: #ifdef META_DEBUG @@ -733,7 +641,7 @@ MetaView::calcRawMeta (Serializer& s, auto const origNode = parent_->read(keylet::unchecked(it.first)); - auto curNode = it.second.mEntry; + auto curNode = it.second.second; if ((type == &sfModifiedNode) && (*curNode == *origNode)) continue; @@ -830,43 +738,4 @@ MetaView::calcRawMeta (Serializer& s, WriteLog (lsTRACE, View) << "Metadata:" << mSet.getJson (0); } -void MetaView::enableDeferredCredits (bool enable) -{ - assert(enable == !mDeferredCredits); - - if (!enable) - { - mDeferredCredits.reset (); - return; - } - - if (!mDeferredCredits) - mDeferredCredits.emplace (); -} - -bool MetaView::areCreditsDeferred () const -{ - return static_cast (mDeferredCredits); -} - -ScopedDeferCredits::ScopedDeferCredits (MetaView& l) - : les_ (l), enabled_ (false) -{ - if (!les_.areCreditsDeferred ()) - { - WriteLog (lsTRACE, DeferredCredits) << "Enable"; - les_.enableDeferredCredits (true); - enabled_ = true; - } -} - -ScopedDeferCredits::~ScopedDeferCredits () -{ - if (enabled_) - { - WriteLog (lsTRACE, DeferredCredits) << "Disable"; - les_.enableDeferredCredits (false); - } -} - } // ripple diff --git a/src/ripple/app/ledger/tests/DeferredCredits.test.cpp b/src/ripple/app/ledger/tests/DeferredCredits.test.cpp index 724a349271..46a2ff7b51 100644 --- a/src/ripple/app/ledger/tests/DeferredCredits.test.cpp +++ b/src/ripple/app/ledger/tests/DeferredCredits.test.cpp @@ -18,11 +18,12 @@ //============================================================================== #include -#include namespace ripple { namespace test { +#if 0 + class DeferredCredits_test : public beast::unit_test::suite { /* @@ -168,11 +169,11 @@ class DeferredCredits_test : public beast::unit_test::suite STAmount const startingAmount = accountHolds (les, aliceAcc, usd, gw1Acc, fhIGNORE_FREEZE, getConfig()); - accountSend (les, gw1Acc, aliceAcc, toCredit); + accountSend (les, gw1Acc, aliceAcc, toCredit, {}); expect (accountHolds (les, aliceAcc, usd, gw1Acc, fhIGNORE_FREEZE, getConfig()) == startingAmount + toCredit); - accountSend (les, aliceAcc, gw1Acc, toDebit); + accountSend (les, aliceAcc, gw1Acc, toDebit, {}); expect (accountHolds (les, aliceAcc, usd, gw1Acc, fhIGNORE_FREEZE, getConfig()) == startingAmount + toCredit - toDebit); } @@ -186,11 +187,11 @@ class DeferredCredits_test : public beast::unit_test::suite STAmount const startingAmount = accountHolds (les, aliceAcc, usd, gw1Acc, fhIGNORE_FREEZE, getConfig()); - rippleCredit (les, gw1Acc, aliceAcc, toCredit); + rippleCredit (les, gw1Acc, aliceAcc, toCredit, true, {}); expect (accountHolds (les, aliceAcc, usd, gw1Acc, fhIGNORE_FREEZE, getConfig()) == startingAmount + toCredit); - rippleCredit (les, aliceAcc, gw1Acc, toDebit); + rippleCredit (les, aliceAcc, gw1Acc, toDebit, true, {}); expect (accountHolds (les, aliceAcc, usd, gw1Acc, fhIGNORE_FREEZE, getConfig()) == startingAmount + toCredit - toDebit); } @@ -204,11 +205,11 @@ class DeferredCredits_test : public beast::unit_test::suite STAmount const startingAmount = accountHolds (les, aliceAcc, usd, gw1Acc, fhIGNORE_FREEZE, getConfig()); - accountSend (les, gw1Acc, aliceAcc, toCredit); + accountSend (les, gw1Acc, aliceAcc, toCredit, {}); expect (accountHolds (les, aliceAcc, usd, gw1Acc, fhIGNORE_FREEZE, getConfig()) == startingAmount); - accountSend (les, aliceAcc, gw1Acc, toDebit); + accountSend (les, aliceAcc, gw1Acc, toDebit, {}); expect (accountHolds (les, aliceAcc, usd, gw1Acc, fhIGNORE_FREEZE, getConfig()) == startingAmount - toDebit); } @@ -222,11 +223,11 @@ class DeferredCredits_test : public beast::unit_test::suite STAmount const startingAmount = accountHolds (les, aliceAcc, usd, gw1Acc, fhIGNORE_FREEZE, getConfig()); - rippleCredit (les, gw1Acc, aliceAcc, toCredit); + rippleCredit (les, gw1Acc, aliceAcc, toCredit, true, {}); expect (accountHolds (les, aliceAcc, usd, gw1Acc, fhIGNORE_FREEZE, getConfig()) == startingAmount); - rippleCredit (les, aliceAcc, gw1Acc, toDebit); + rippleCredit (les, aliceAcc, gw1Acc, toDebit, true, {}); expect (accountHolds (les, aliceAcc, usd, gw1Acc, fhIGNORE_FREEZE, getConfig()) == startingAmount - toDebit); } @@ -239,7 +240,7 @@ class DeferredCredits_test : public beast::unit_test::suite accountHolds (les, aliceAcc, usd, gw1Acc, fhIGNORE_FREEZE, getConfig()); { ScopedDeferCredits g (les); - rippleCredit (les, gw1Acc, aliceAcc, toCredit); + rippleCredit (les, gw1Acc, aliceAcc, toCredit, true, {}); expect ( accountHolds (les, aliceAcc, usd, gw1Acc, fhIGNORE_FREEZE, getConfig()) == startingAmount); @@ -256,7 +257,7 @@ class DeferredCredits_test : public beast::unit_test::suite les.enableDeferredCredits (); expect (les.areCreditsDeferred ()); - redeemIOU (les, aliceAcc, toDebit, issue); + redeemIOU (les, aliceAcc, toDebit, issue, {}); expect (accountHolds (les, aliceAcc, usd, gw1Acc, fhIGNORE_FREEZE, getConfig()) == startingAmount - toDebit); } @@ -269,7 +270,7 @@ class DeferredCredits_test : public beast::unit_test::suite ScopedDeferCredits g (les); expect (les.areCreditsDeferred ()); - issueIOU (les, aliceAcc, toCredit, issue); + issueIOU (les, aliceAcc, toCredit, issue, {}); expect ( accountHolds (les, aliceAcc, usd, gw1Acc, fhIGNORE_FREEZE, getConfig()) == startingAmount); @@ -289,5 +290,7 @@ public: BEAST_DEFINE_TESTSUITE (DeferredCredits, ledger, ripple); +#endif + } // test } // ripple diff --git a/src/ripple/app/ledger/tests/MetaView_test.cpp b/src/ripple/app/ledger/tests/MetaView_test.cpp index 15371a2205..9b68caa5f9 100644 --- a/src/ripple/app/ledger/tests/MetaView_test.cpp +++ b/src/ripple/app/ledger/tests/MetaView_test.cpp @@ -21,7 +21,6 @@ #include #include #include -#include #include // namespace ripple { diff --git a/src/ripple/app/misc/NetworkOPs.cpp b/src/ripple/app/misc/NetworkOPs.cpp index 4a110aff7d..afd793ebeb 100644 --- a/src/ripple/app/misc/NetworkOPs.cpp +++ b/src/ripple/app/misc/NetworkOPs.cpp @@ -31,7 +31,6 @@ #include #include #include -#include #include #include #include diff --git a/src/ripple/app/paths/NodeDirectory.h b/src/ripple/app/paths/NodeDirectory.h index b1b17578da..8279a466c6 100644 --- a/src/ripple/app/paths/NodeDirectory.h +++ b/src/ripple/app/paths/NodeDirectory.h @@ -27,8 +27,9 @@ namespace ripple { // VFALCO TODO de-inline these function definitions -class NodeDirectory { - public: +class NodeDirectory +{ +public: // Current directory - the last 64 bits of this are the quality. uint256 current; @@ -52,7 +53,7 @@ class NodeDirectory { restartNeeded = true; // Restart at same quality. } - bool initialize (Book const& book, MetaView& les) + bool initialize (Book const& book, View& view) { if (current != zero) return false; @@ -63,19 +64,28 @@ class NodeDirectory { // TODO(tom): it seems impossible that any actual offers with // quality == 0 could occur - we should disallow them, and clear // directory.ledgerEntry without the database call in the next line. - ledgerEntry = les.peek (keylet::page(current)); + ledgerEntry = view.peek (keylet::page(current)); // Advance, if didn't find it. Normal not to be unable to lookup // firstdirectory. Maybe even skip this lookup. - advanceNeeded = !ledgerEntry; + advanceNeeded = ! ledgerEntry; restartNeeded = false; // Associated vars are dirty, if found it. return bool(ledgerEntry); } - enum Advance {NO_ADVANCE, NEW_QUALITY, END_ADVANCE}; - Advance advance(MetaView& les) + enum Advance + { + NO_ADVANCE, + NEW_QUALITY, + END_ADVANCE + }; + + /** Advance to the next quality directory in the order book. */ + // VFALCO Consider renaming this to `nextQuality` or something + Advance + advance (View& view) { if (!(advanceNeeded || restartNeeded)) return NO_ADVANCE; @@ -86,7 +96,7 @@ class NodeDirectory { if (advanceNeeded) { auto const opt = - les.succ (current, next); + view.succ (current, next); current = opt ? *opt : uint256{}; } advanceNeeded = false; @@ -95,7 +105,7 @@ class NodeDirectory { if (current == zero) return END_ADVANCE; - ledgerEntry = les.peek (keylet::page(current)); + ledgerEntry = view.peek (keylet::page(current)); return NEW_QUALITY; } }; diff --git a/src/ripple/app/paths/PathRequest.cpp b/src/ripple/app/paths/PathRequest.cpp index 092369613f..f3efffadfc 100644 --- a/src/ripple/app/paths/PathRequest.cpp +++ b/src/ripple/app/paths/PathRequest.cpp @@ -483,8 +483,9 @@ Json::Value PathRequest::doUpdate (RippleLineCache::ref cache, bool fast) if (valid) { - MetaView sandbox( - cache->getLedger(), tapNONE); + boost::optional sandbox; + sandbox.emplace(cache->getLedger(), tapNONE); + auto& sourceAccount = !isXRP (currIssuer.account) ? currIssuer.account : isXRP (currIssuer.currency) @@ -496,7 +497,7 @@ Json::Value PathRequest::doUpdate (RippleLineCache::ref cache, bool fast) m_journal.debug << iIdentifier << " Paths found, calling rippleCalc"; auto rc = path::RippleCalc::rippleCalculate ( - sandbox, + *sandbox, saMaxAmount, saDstAmount, *raDstAccount, @@ -509,9 +510,9 @@ Json::Value PathRequest::doUpdate (RippleLineCache::ref cache, bool fast) m_journal.debug << iIdentifier << " Trying with an extra path element"; spsPaths.push_back (fullLiquidityPath); - reconstruct(sandbox, cache->getLedger (), tapNONE); + sandbox.emplace(cache->getLedger (), tapNONE); rc = path::RippleCalc::rippleCalculate ( - sandbox, + *sandbox, saMaxAmount, saDstAmount, *raDstAccount, diff --git a/src/ripple/app/paths/PathState.cpp b/src/ripple/app/paths/PathState.cpp index fb9e51a582..cc58d00e07 100644 --- a/src/ripple/app/paths/PathState.cpp +++ b/src/ripple/app/paths/PathState.cpp @@ -268,7 +268,7 @@ TER PathState::pushNode ( auto const& backNode = nodes_.back (); if (backNode.isAccount()) { - auto sleRippleState = metaView_.peek( + auto sleRippleState = view().peek( keylet::line(backNode.account_, node.account_, backNode.issue_.currency)); // A "RippleState" means a balance betweeen two accounts for a @@ -291,7 +291,7 @@ TER PathState::pushNode ( << backNode.account_ << " and " << node.account_ << " for " << node.issue_.currency << "." ; - auto sleBck = metaView_.peek ( + auto sleBck = view().peek ( keylet::account(backNode.account_)); // Is the source account the highest numbered account ID? bool bHigh = backNode.account_ > node.account_; @@ -318,13 +318,13 @@ TER PathState::pushNode ( if (resultCode == tesSUCCESS) { - STAmount saOwed = creditBalance (metaView_, + STAmount saOwed = creditBalance (view(), node.account_, backNode.account_, node.issue_.currency); STAmount saLimit; if (saOwed <= zero) { - saLimit = creditLimit (metaView_, + saLimit = creditLimit (view(), node.account_, backNode.account_, node.issue_.currency); @@ -624,7 +624,7 @@ void PathState::checkFreeze() // Check each order book for a global freeze if (nodes_[i].uFlags & STPathElement::typeIssuer) { - sle = metaView_.peek (keylet::account(nodes_[i].issue_.account)); + sle = view().peek (keylet::account(nodes_[i].issue_.account)); if (sle && sle->isFlag (lsfGlobalFreeze)) { @@ -642,7 +642,7 @@ void PathState::checkFreeze() if (inAccount != outAccount) { - sle = metaView_.peek (keylet::account(outAccount)); + sle = view().peek (keylet::account(outAccount)); if (sle && sle->isFlag (lsfGlobalFreeze)) { @@ -650,7 +650,7 @@ void PathState::checkFreeze() return; } - sle = metaView_.peek (keylet::line(inAccount, + sle = view().peek (keylet::line(inAccount, outAccount, currencyID)); if (sle && sle->isFlag ( @@ -677,9 +677,9 @@ TER PathState::checkNoRipple ( Currency const& currency) { // fetch the ripple lines into and out of this node - SLE::pointer sleIn = metaView_.peek ( + SLE::pointer sleIn = view().peek ( keylet::line(firstAccount, secondAccount, currency)); - SLE::pointer sleOut = metaView_.peek ( + SLE::pointer sleOut = view().peek ( keylet::line(secondAccount, thirdAccount, currency)); if (!sleIn || !sleOut) diff --git a/src/ripple/app/paths/PathState.h b/src/ripple/app/paths/PathState.h index a05b659f92..fe820845b4 100644 --- a/src/ripple/app/paths/PathState.h +++ b/src/ripple/app/paths/PathState.h @@ -23,6 +23,7 @@ #include #include #include +#include #include namespace ripple { @@ -35,13 +36,15 @@ class PathState : public CountedObject using Ptr = std::shared_ptr; using List = std::vector; - PathState (MetaView& view, STAmount const& saSend, STAmount const& saSendMax) - : metaView_ (view) - , mIndex (0) + PathState (PaymentView& parent, + STAmount const& saSend, + STAmount const& saSendMax) + : mIndex (0) , uQuality (0) , saInReq (saSendMax) , saOutReq (saSend) { + view_.emplace(&parent); } void reset(STAmount const& in, STAmount const& out); @@ -101,14 +104,15 @@ class PathState : public CountedObject static bool lessPriority (PathState const& lhs, PathState const& rhs); - MetaView& metaView() + PaymentView& + view() { - return metaView_; + return *view_; } - void resetView (MetaView& view) + void resetView (PaymentView& view) { - reconstruct (metaView_, view); + view_.emplace(&view); } bool isDry() const @@ -136,23 +140,8 @@ private: Json::Value getJson () const; - TER terStatus; - path::Node::List nodes_; - - // When processing, don't want to complicate directory walking with - // deletion. Offers that became unfunded or were completely consumed go - // here and are deleted at the end. - OfferIndexList unfundedOffers_; - - // First time scanning foward, as part of path construction, a funding - // source was mentioned for accounts. Source may only be used there. - AccountIssueToNodeIndex umForward; - - // First time working in reverse a funding source was used. - // Source may only be used there if not mentioned by an account. - AccountIssueToNodeIndex umReverse; - - MetaView metaView_; +private: + boost::optional view_; int mIndex; // Index/rank amoung siblings. std::uint64_t uQuality; // 0 = no quality/liquity left. @@ -167,6 +156,23 @@ private: // If true, all liquidity on this path has been consumed. bool allLiquidityConsumed_ = false; + + TER terStatus; + + path::Node::List nodes_; + + // When processing, don't want to complicate directory walking with + // deletion. Offers that became unfunded or were completely consumed go + // here and are deleted at the end. + OfferIndexList unfundedOffers_; + + // First time scanning foward, as part of path construction, a funding + // source was mentioned for accounts. Source may only be used there. + AccountIssueToNodeIndex umForward; + + // First time working in reverse a funding source was used. + // Source may only be used there if not mentioned by an account. + AccountIssueToNodeIndex umReverse; }; } // ripple diff --git a/src/ripple/app/paths/Pathfinder.cpp b/src/ripple/app/paths/Pathfinder.cpp index f4ffdd4eec..bbe2fa7808 100644 --- a/src/ripple/app/paths/Pathfinder.cpp +++ b/src/ripple/app/paths/Pathfinder.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -377,7 +378,7 @@ TER Pathfinder::getPathLiquidity ( path::RippleCalc::Input rcInput; rcInput.defaultPathsAllowed = false; - MetaView sandbox (mLedger, tapNONE); + PaymentView sandbox (mLedger, tapNONE); try { @@ -442,7 +443,7 @@ void Pathfinder::computePathRanks (int maxPaths) // Must subtract liquidity in default path from remaining amount. try { - MetaView sandbox (mLedger, tapNONE); + PaymentView sandbox (mLedger, tapNONE); path::RippleCalc::Input rcInput; rcInput.partialPaymentAllowed = true; diff --git a/src/ripple/app/paths/RippleCalc.cpp b/src/ripple/app/paths/RippleCalc.cpp index 299aba701b..f88e6f3adf 100644 --- a/src/ripple/app/paths/RippleCalc.cpp +++ b/src/ripple/app/paths/RippleCalc.cpp @@ -21,7 +21,6 @@ #include #include #include -#include #include namespace ripple { @@ -44,7 +43,7 @@ deleteOffers (View& view, } // namespace RippleCalc::Output RippleCalc::rippleCalculate ( - MetaView& activeLedger, + PaymentView& view, // Compute paths using this ledger entry set. Up to caller to actually // apply to ledger. @@ -70,7 +69,7 @@ RippleCalc::Output RippleCalc::rippleCalculate ( Input const* const pInputs) { RippleCalc rc ( - activeLedger, + view, saMaxAmountReq, saDstAmountReq, uDstAccountID, @@ -94,7 +93,7 @@ RippleCalc::Output RippleCalc::rippleCalculate ( bool RippleCalc::addPathState(STPath const& path, TER& resultCode) { auto pathState = std::make_shared ( - metaView, saDstAmountReq_, saMaxAmountReq_); + view, saDstAmountReq_, saMaxAmountReq_); if (!pathState) { @@ -145,7 +144,6 @@ bool RippleCalc::addPathState(STPath const& path, TER& resultCode) // <-- TER: Only returns tepPATH_PARTIAL if partialPaymentAllowed. TER RippleCalc::rippleCalculate () { - assert (metaView.isValid ()); WriteLog (lsTRACE, RippleCalc) << "rippleCalc>" << " saMaxAmountReq_:" << saMaxAmountReq_ @@ -330,9 +328,8 @@ TER RippleCalc::rippleCalculate () pathState->unfundedOffers().begin (), pathState->unfundedOffers().end ()); - // Apply best pass' MetaView - assert (pathState->metaView().isValid ()); - pathState->metaView().apply(); + // Apply best pass' view + pathState->view().apply(); actualAmountIn_ += pathState->inPass(); actualAmountOut_ += pathState->outPass(); @@ -414,9 +411,9 @@ TER RippleCalc::rippleCalculate () if (resultCode == tesSUCCESS) { - resultCode = deleteOffers(metaView, unfundedOffersFromBestPaths); + resultCode = deleteOffers(view, unfundedOffersFromBestPaths); if (resultCode == tesSUCCESS) - resultCode = deleteOffers(metaView, permanentlyUnfundedOffers_); + resultCode = deleteOffers(view, permanentlyUnfundedOffers_); } // If isOpenLedger, then ledger is not final, can vote no. diff --git a/src/ripple/app/paths/RippleCalc.h b/src/ripple/app/paths/RippleCalc.h index 7b23206092..12a3871617 100644 --- a/src/ripple/app/paths/RippleCalc.h +++ b/src/ripple/app/paths/RippleCalc.h @@ -20,7 +20,7 @@ #ifndef RIPPLE_APP_PATHS_RIPPLECALC_H_INCLUDED #define RIPPLE_APP_PATHS_RIPPLECALC_H_INCLUDED -#include +#include #include #include #include @@ -72,8 +72,10 @@ public: }; - static Output rippleCalculate ( - MetaView& activeLedger, + static + Output + rippleCalculate( + PaymentView& view, // Compute paths using this ledger entry set. Up to caller to actually // apply to ledger. @@ -99,8 +101,7 @@ public: Input const* const pInputs = nullptr); // The view we are currently working on - MetaView& metaView; - + PaymentView& view; // If the transaction fails to meet some constraint, still need to delete // unfunded offers. @@ -116,14 +117,14 @@ public: private: RippleCalc ( - MetaView& activeLedger, + PaymentView& view_, STAmount const& saMaxAmountReq, // --> -1 = no limit. STAmount const& saDstAmountReq, AccountID const& uDstAccountID, AccountID const& uSrcAccountID, STPathSet const& spsPaths) - : metaView (activeLedger), + : view (view_), saDstAmountReq_(saDstAmountReq), saMaxAmountReq_(saMaxAmountReq), uDstAccountID_(uDstAccountID), diff --git a/src/ripple/app/paths/RippleState.cpp b/src/ripple/app/paths/RippleState.cpp index db1db3eae4..f5612de0a5 100644 --- a/src/ripple/app/paths/RippleState.cpp +++ b/src/ripple/app/paths/RippleState.cpp @@ -19,7 +19,6 @@ #include #include -#include #include #include #include diff --git a/src/ripple/app/paths/cursor/AdvanceNode.cpp b/src/ripple/app/paths/cursor/AdvanceNode.cpp index 5accf0d035..0d23095550 100644 --- a/src/ripple/app/paths/cursor/AdvanceNode.cpp +++ b/src/ripple/app/paths/cursor/AdvanceNode.cpp @@ -19,7 +19,6 @@ #include #include -#include #include namespace ripple { @@ -68,10 +67,10 @@ TER PathCursor::advanceNode (bool const bReverse) const } bool bDirectDirDirty = node().directory.initialize ( - {previousNode().issue_, node().issue_}, - ledger()); + { previousNode().issue_, node().issue_}, + view()); - if (auto advance = node().directory.advance (ledger())) + if (auto advance = node().directory.advance (view())) { bDirectDirDirty = true; if (advance == NodeDirectory::NEW_QUALITY) @@ -129,7 +128,7 @@ TER PathCursor::advanceNode (bool const bReverse) const = node().sleOffer->getFieldAmount (sfTakerGets); // Funds left. - node().saOfferFunds = accountFunds (ledger(), + node().saOfferFunds = accountFunds(view(), node().offerOwnerAccount_, node().saTakerGets, fhZERO_IF_FROZEN, @@ -145,7 +144,7 @@ TER PathCursor::advanceNode (bool const bReverse) const WriteLog (lsTRACE, RippleCalc) << "advanceNode: as is"; } } - else if (!dirNext (ledger(), + else if (!dirNext (view(), node().directory.current, node().directory.ledgerEntry, node().uEntry, @@ -182,7 +181,7 @@ TER PathCursor::advanceNode (bool const bReverse) const else { // Got a new offer. - node().sleOffer = ledger().peek (keylet::offer(node().offerIndex_)); + node().sleOffer = view().peek (keylet::offer(node().offerIndex_)); if (!node().sleOffer) { @@ -213,7 +212,7 @@ TER PathCursor::advanceNode (bool const bReverse) const if (node().sleOffer->isFieldPresent (sfExpiration) && (node().sleOffer->getFieldU32 (sfExpiration) <= - getParentCloseTimeNC(ledger()))) + getParentCloseTimeNC(view()))) { // Offer is expired. WriteLog (lsTRACE, RippleCalc) @@ -329,7 +328,7 @@ TER PathCursor::advanceNode (bool const bReverse) const // Only the current node is allowed to use the source. - node().saOfferFunds = accountFunds(ledger(), + node().saOfferFunds = accountFunds(view(), node().offerOwnerAccount_, node().saTakerGets, fhZERO_IF_FROZEN, diff --git a/src/ripple/app/paths/cursor/DeliverNodeForward.cpp b/src/ripple/app/paths/cursor/DeliverNodeForward.cpp index 67fd89a518..bf86fca3b8 100644 --- a/src/ripple/app/paths/cursor/DeliverNodeForward.cpp +++ b/src/ripple/app/paths/cursor/DeliverNodeForward.cpp @@ -19,7 +19,6 @@ #include #include -#include #include namespace ripple { @@ -196,7 +195,7 @@ TER PathCursor::deliverNodeForward ( // Output: Debit offer owner, send XRP or non-XPR to next // account. - resultCode = accountSend (ledger(), + resultCode = accountSend(view(), node().offerOwnerAccount_, nextNode().account_, saOutPassAct); @@ -253,7 +252,7 @@ TER PathCursor::deliverNodeForward ( auto const& id = isXRP(node().issue_) ? xrpAccount() : node().issue_.account; auto outPassTotal = saOutPassAct + saOutPassFees; - accountSend (ledger(), + accountSend(view(), node().offerOwnerAccount_, id, outPassTotal); @@ -287,7 +286,7 @@ TER PathCursor::deliverNodeForward ( { auto id = !isXRP(previousNode().issue_.currency) ? uInAccountID : xrpAccount(); - resultCode = accountSend (ledger(), + resultCode = accountSend(view(), id, node().offerOwnerAccount_, saInPassAct); @@ -317,7 +316,7 @@ TER PathCursor::deliverNodeForward ( node().sleOffer->setFieldAmount (sfTakerGets, saTakerGetsNew); node().sleOffer->setFieldAmount (sfTakerPays, saTakerPaysNew); - ledger().update (node().sleOffer); + view().update (node().sleOffer); if (saOutPassAct == saOutFunded || saTakerGetsNew == zero) { diff --git a/src/ripple/app/paths/cursor/DeliverNodeReverse.cpp b/src/ripple/app/paths/cursor/DeliverNodeReverse.cpp index 5e241d4804..620eb85928 100644 --- a/src/ripple/app/paths/cursor/DeliverNodeReverse.cpp +++ b/src/ripple/app/paths/cursor/DeliverNodeReverse.cpp @@ -19,7 +19,6 @@ #include #include -#include #include namespace ripple { @@ -280,7 +279,7 @@ TER PathCursor::deliverNodeReverse ( // visited. However, these deductions and adjustments are tenative. // // Must reset balances when going forward to perform actual transfers. - resultCode = accountSend (ledger(), + resultCode = accountSend(view(), node().offerOwnerAccount_, node().issue_.account, saOutPassAct); if (resultCode != tesSUCCESS) @@ -304,7 +303,7 @@ TER PathCursor::deliverNodeReverse ( node().sleOffer->setFieldAmount (sfTakerGets, saTakerGetsNew); node().sleOffer->setFieldAmount (sfTakerPays, saTakerPaysNew); - ledger().update (node().sleOffer); + view().update (node().sleOffer); if (saOutPassAct == node().saTakerGets) { diff --git a/src/ripple/app/paths/cursor/ForwardLiquidityForAccount.cpp b/src/ripple/app/paths/cursor/ForwardLiquidityForAccount.cpp index 907c7a0e6e..0b68f1f1a8 100644 --- a/src/ripple/app/paths/cursor/ForwardLiquidityForAccount.cpp +++ b/src/ripple/app/paths/cursor/ForwardLiquidityForAccount.cpp @@ -19,7 +19,6 @@ #include #include -#include #include #include @@ -56,13 +55,13 @@ TER PathCursor::forwardLiquidityForAccount () const nextNode().isAccount() ? nextNode().account_ : node().account_; std::uint32_t uQualityIn = nodeIndex_ - ? quality_in (ledger(), + ? quality_in (view(), node().account_, previousAccountID, node().issue_.currency) : QUALITY_ONE; std::uint32_t uQualityOut = (nodeIndex_ == lastNodeIndex) - ? quality_out (ledger(), + ? quality_out (view(), node().account_, nextAccountID, node().issue_.currency) @@ -167,7 +166,7 @@ TER PathCursor::forwardLiquidityForAccount () const if (saCurReceive) { // Actually receive. - resultCode = rippleCredit (ledger(), + resultCode = rippleCredit(view(), previousAccountID, node().account_, previousNode().saFwdRedeem + previousNode().saFwdIssue, @@ -235,7 +234,7 @@ TER PathCursor::forwardLiquidityForAccount () const rippleLiquidity ( rippleCalc_, QUALITY_ONE, - rippleTransferRate (ledger(), node().account_), + rippleTransferRate (view(), node().account_), previousNode().saFwdRedeem, node().saRevIssue, saPrvRedeemAct, @@ -267,7 +266,7 @@ TER PathCursor::forwardLiquidityForAccount () const // Adjust prv --> cur balance : take all inbound resultCode = saProvide - ? rippleCredit (ledger(), + ? rippleCredit(view(), previousAccountID, node().account_, previousNode().saFwdRedeem + previousNode().saFwdIssue, @@ -304,7 +303,7 @@ TER PathCursor::forwardLiquidityForAccount () const rippleLiquidity ( rippleCalc_, QUALITY_ONE, - rippleTransferRate (ledger(), node().account_), + rippleTransferRate (view(), node().account_), previousNode().saFwdRedeem, node().saRevDeliver, saPrvRedeemAct, @@ -332,7 +331,7 @@ TER PathCursor::forwardLiquidityForAccount () const // Adjust prv --> cur balance : take all inbound resultCode = node().saFwdDeliver - ? rippleCredit (ledger(), + ? rippleCredit(view(), previousAccountID, node().account_, previousNode().saFwdRedeem + previousNode().saFwdIssue, false) @@ -354,7 +353,7 @@ TER PathCursor::forwardLiquidityForAccount () const if (isXRP (node().issue_)) node().saFwdDeliver = std::min ( node().saFwdDeliver, - accountHolds (ledger(), + accountHolds(view(), node().account_, xrpCurrency(), xrpAccount(), @@ -391,7 +390,7 @@ TER PathCursor::forwardLiquidityForAccount () const << "ACCOUNT -- XRP --> offer"; // Deliver XRP to limbo. - resultCode = accountSend (ledger(), + resultCode = accountSend(view(), node().account_, xrpAccount(), node().saFwdDeliver); } } @@ -451,7 +450,7 @@ TER PathCursor::forwardLiquidityForAccount () const rippleLiquidity ( rippleCalc_, QUALITY_ONE, - rippleTransferRate (ledger(), node().account_), + rippleTransferRate (view(), node().account_), previousNode().saFwdDeliver, node().saRevIssue, saPrvDeliverAct, @@ -482,7 +481,7 @@ TER PathCursor::forwardLiquidityForAccount () const rippleLiquidity ( rippleCalc_, QUALITY_ONE, - rippleTransferRate (ledger(), node().account_), + rippleTransferRate (view(), node().account_), previousNode().saFwdDeliver, node().saRevDeliver, saPrvDeliverAct, diff --git a/src/ripple/app/paths/cursor/Liquidity.cpp b/src/ripple/app/paths/cursor/Liquidity.cpp index 91bb25f125..f60d37c296 100644 --- a/src/ripple/app/paths/cursor/Liquidity.cpp +++ b/src/ripple/app/paths/cursor/Liquidity.cpp @@ -30,7 +30,7 @@ TER PathCursor::liquidity () const TER resultCode = tecPATH_DRY; PathCursor pc = *this; - pathState_.resetView (rippleCalc_.metaView); + pathState_.resetView (rippleCalc_.view); for (pc.nodeIndex_ = pc.nodeSize(); pc.nodeIndex_--; ) { @@ -59,7 +59,7 @@ TER PathCursor::liquidity () const if (resultCode != tesSUCCESS) return resultCode; - pathState_.resetView (rippleCalc_.metaView); + pathState_.resetView (rippleCalc_.view); for (pc.nodeIndex_ = 0; pc.nodeIndex_ < pc.nodeSize(); ++pc.nodeIndex_) { diff --git a/src/ripple/app/paths/cursor/PathCursor.h b/src/ripple/app/paths/cursor/PathCursor.h index 5bfdf4842a..1a8ddafba8 100644 --- a/src/ripple/app/paths/cursor/PathCursor.h +++ b/src/ripple/app/paths/cursor/PathCursor.h @@ -92,11 +92,10 @@ private: STAmount& saInFees) const; // VFALCO TODO Rename this to view() - MetaView& ledger() const + PaymentView& + view() const { - // VFALCO Rename metaView to view - //return rippleCalc_.metaView; - return pathState_.metaView(); + return pathState_.view(); } NodeIndex nodeSize() const diff --git a/src/ripple/app/paths/cursor/ReverseLiquidity.cpp b/src/ripple/app/paths/cursor/ReverseLiquidity.cpp index aa0d1412c3..113441d252 100644 --- a/src/ripple/app/paths/cursor/ReverseLiquidity.cpp +++ b/src/ripple/app/paths/cursor/ReverseLiquidity.cpp @@ -19,7 +19,6 @@ #include #include -#include #include #include @@ -57,7 +56,7 @@ TER PathCursor::reverseLiquidity () const // node.transferRate_ caches the output transfer rate for this node. node().transferRate_ = amountFromRate ( - rippleTransferRate (ledger(), node().issue_.account)); + rippleTransferRate (view(), node().issue_.account)); if (node().isAccount ()) return reverseLiquidityForAccount (); diff --git a/src/ripple/app/paths/cursor/ReverseLiquidityForAccount.cpp b/src/ripple/app/paths/cursor/ReverseLiquidityForAccount.cpp index 4caa457ad3..8f4fc79206 100644 --- a/src/ripple/app/paths/cursor/ReverseLiquidityForAccount.cpp +++ b/src/ripple/app/paths/cursor/ReverseLiquidityForAccount.cpp @@ -20,7 +20,6 @@ #include #include #include -#include #include #include @@ -66,7 +65,7 @@ TER PathCursor::reverseLiquidityForAccount () const // This is the quality from from the previous node to this one. const std::uint32_t uQualityIn = (nodeIndex_ != 0) - ? quality_in (ledger(), + ? quality_in (view(), node().account_, previousAccountID, node().issue_.currency) @@ -75,7 +74,7 @@ TER PathCursor::reverseLiquidityForAccount () const // And this is the quality from the next one to this one. const std::uint32_t uQualityOut = (nodeIndex_ != lastNodeIndex) - ? quality_out (ledger(), + ? quality_out (view(), node().account_, nextAccountID, node().issue_.currency) @@ -84,7 +83,7 @@ TER PathCursor::reverseLiquidityForAccount () const // For previousNodeIsAccount: // Previous account is already owed. const STAmount saPrvOwed = (previousNodeIsAccount && nodeIndex_ != 0) - ? creditBalance (ledger(), + ? creditBalance (view(), node().account_, previousAccountID, node().issue_.currency) @@ -92,7 +91,7 @@ TER PathCursor::reverseLiquidityForAccount () const // The limit amount that the previous account may owe. const STAmount saPrvLimit = (previousNodeIsAccount && nodeIndex_ != 0) - ? creditLimit (ledger(), + ? creditLimit (view(), node().account_, previousAccountID, node().issue_.currency) @@ -100,7 +99,7 @@ TER PathCursor::reverseLiquidityForAccount () const // Next account is owed. const STAmount saNxtOwed = (nextNodeIsAccount && nodeIndex_ != lastNodeIndex) - ? creditBalance (ledger(), + ? creditBalance (view(), node().account_, nextAccountID, node().issue_.currency) @@ -318,7 +317,7 @@ TER PathCursor::reverseLiquidityForAccount () const rippleLiquidity ( rippleCalc_, QUALITY_ONE, - rippleTransferRate (ledger(), node().account_), + rippleTransferRate (view(), node().account_), saPrvRedeemReq, node().saRevIssue, previousNode().saRevRedeem, @@ -404,7 +403,7 @@ TER PathCursor::reverseLiquidityForAccount () const rippleLiquidity ( rippleCalc_, QUALITY_ONE, - rippleTransferRate (ledger(), node().account_), + rippleTransferRate (view(), node().account_), saPrvRedeemReq, node().saRevDeliver, previousNode().saRevRedeem, @@ -553,7 +552,7 @@ TER PathCursor::reverseLiquidityForAccount () const rippleLiquidity ( rippleCalc_, QUALITY_ONE, - rippleTransferRate (ledger(), node().account_), + rippleTransferRate (view(), node().account_), saPrvDeliverReq, node().saRevIssue, previousNode().saRevDeliver, @@ -586,7 +585,7 @@ TER PathCursor::reverseLiquidityForAccount () const rippleLiquidity ( rippleCalc_, QUALITY_ONE, - rippleTransferRate (ledger(), node().account_), + rippleTransferRate (view(), node().account_), saPrvDeliverReq, node().saRevDeliver, previousNode().saRevDeliver, diff --git a/src/ripple/app/paths/impl/PaymentView.cpp b/src/ripple/app/paths/impl/PaymentView.cpp new file mode 100644 index 0000000000..bdc2f2479d --- /dev/null +++ b/src/ripple/app/paths/impl/PaymentView.cpp @@ -0,0 +1,50 @@ +//------------------------------------------------------------------------------ +/* + 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 + +namespace ripple { + +STAmount +PaymentView::balanceHook (AccountID const& account, + AccountID const& issuer, + STAmount const& amount) const +{ + return tab_.adjustedBalance( + account, issuer, amount); +} + +void +PaymentView::creditHook (AccountID const& from, + AccountID const& to, + STAmount const& amount) +{ + tab_.credit(from, to, amount); +} + +void +PaymentView::apply() +{ + view_.apply(); + if (pv_) + pv_->tab_.apply(tab_); +} + +} // ripple diff --git a/src/ripple/app/tx/impl/PaymentView.h b/src/ripple/app/paths/impl/PaymentView.h similarity index 66% rename from src/ripple/app/tx/impl/PaymentView.h rename to src/ripple/app/paths/impl/PaymentView.h index b2189c1d58..4999ecf7b1 100644 --- a/src/ripple/app/tx/impl/PaymentView.h +++ b/src/ripple/app/paths/impl/PaymentView.h @@ -18,28 +18,61 @@ //============================================================================== #ifndef RIPPLE_APP_PAYMENTVIEW_H_INCLUDED +#define RIPPLE_APP_PAYMENTVIEW_H_INCLUDED +#include +#include #include +#include #include +#include namespace ripple { /** A View wrapper which makes credits unavailable to balances. - This is used for payments, so that consuming liquidity - from a path never causes portions of that path or other - paths to gain liquidity. + This is used for payments and pathfinding, so that consuming + liquidity from a path never causes portions of that path or + other paths to gain liquidity. + + The behavior of certain free functions in the View API + will change via the balanceHook and creditHook overrides + of PaymentView. */ class PaymentView : public View { private: - View& view_; + MetaView view_; DeferredCredits tab_; + PaymentView* pv_ = nullptr; public: + PaymentView (PaymentView const&) = delete; + PaymentView& operator= (PaymentView const&) = delete; + + /** Construct contained MetaView from arguments */ + template explicit - PaymentView (View& view) - : view_(view) + PaymentView (Args&&... args) + : view_ (std::forward(args)...) + { + } + + /** Construct on top of existing PaymentView. + + The changes are pushed to the parent when + apply() is called. + + @param parent A non-null pointer to the parent. + + @note A pointer is used to prevent confusion + with copy construction. + */ + explicit + PaymentView (PaymentView* parent) + : view_ (*parent, + parent->openLedger()) + , pv_ (parent) { } @@ -91,15 +124,6 @@ public: return &view_; } - STAmount - deprecatedBalance (AccountID const& account, - AccountID const& issuer, - STAmount const& amount) const override - { - return tab_.adjustedBalance( - account, issuer, amount); - } - //--------------------------------------------- std::shared_ptr @@ -132,14 +156,20 @@ public: return view_.openLedger(); } - // Unfortunately necessary for DeferredCredits + //-------------------------------------------------------------------------- + + STAmount + balanceHook (AccountID const& account, + AccountID const& issuer, + STAmount const& amount) const override; + void - deprecatedCreditHint (AccountID const& from, + creditHook (AccountID const& from, AccountID const& to, - STAmount const& amount) override - { - tab_.credit(from, to, amount); - } + STAmount const& amount) override; + + void + apply(); }; } // ripple diff --git a/src/ripple/app/tx/impl/BookTip.cpp b/src/ripple/app/tx/impl/BookTip.cpp index a7b8f2e079..74b9b94f6c 100644 --- a/src/ripple/app/tx/impl/BookTip.cpp +++ b/src/ripple/app/tx/impl/BookTip.cpp @@ -19,7 +19,6 @@ #include #include -#include namespace ripple { diff --git a/src/ripple/app/tx/impl/CancelOffer.cpp b/src/ripple/app/tx/impl/CancelOffer.cpp index 11b9117f36..230a9a7979 100644 --- a/src/ripple/app/tx/impl/CancelOffer.cpp +++ b/src/ripple/app/tx/impl/CancelOffer.cpp @@ -19,7 +19,6 @@ #include #include -#include #include #include #include diff --git a/src/ripple/app/tx/impl/CancelTicket.cpp b/src/ripple/app/tx/impl/CancelTicket.cpp index 933fa38db6..5fdc61266f 100644 --- a/src/ripple/app/tx/impl/CancelTicket.cpp +++ b/src/ripple/app/tx/impl/CancelTicket.cpp @@ -19,7 +19,6 @@ #include #include -#include #include #include diff --git a/src/ripple/app/tx/impl/CreateOffer.cpp b/src/ripple/app/tx/impl/CreateOffer.cpp index 16ea4bccb2..5c7822fbe4 100644 --- a/src/ripple/app/tx/impl/CreateOffer.cpp +++ b/src/ripple/app/tx/impl/CreateOffer.cpp @@ -21,7 +21,6 @@ #include #include #include -#include #include #include #include diff --git a/src/ripple/app/tx/impl/CreateTicket.cpp b/src/ripple/app/tx/impl/CreateTicket.cpp index 432ed23113..c5658f3dc8 100644 --- a/src/ripple/app/tx/impl/CreateTicket.cpp +++ b/src/ripple/app/tx/impl/CreateTicket.cpp @@ -19,7 +19,6 @@ #include #include -#include #include #include diff --git a/src/ripple/app/tx/impl/OfferStream.cpp b/src/ripple/app/tx/impl/OfferStream.cpp index 890565717d..96c183fd79 100644 --- a/src/ripple/app/tx/impl/OfferStream.cpp +++ b/src/ripple/app/tx/impl/OfferStream.cpp @@ -19,7 +19,6 @@ #include #include -#include namespace ripple { diff --git a/src/ripple/app/tx/impl/Payment.cpp b/src/ripple/app/tx/impl/Payment.cpp index e45464f046..871a756f98 100644 --- a/src/ripple/app/tx/impl/Payment.cpp +++ b/src/ripple/app/tx/impl/Payment.cpp @@ -20,7 +20,6 @@ #include #include #include -#include #include #include @@ -295,15 +294,19 @@ public: { path::RippleCalc::Output rc; { - ScopedDeferCredits g (mEngine->view ()); + PaymentView view (mEngine->view()); rc = path::RippleCalc::rippleCalculate ( - mEngine->view (), + view, maxSourceAmount, saDstAmount, uDstAccountID, mTxnAccountID, spsPaths, &rcInput); + // VFALCO NOTE We might not need to apply, depending + // on the TER. But always applying *should* + // be safe. + view.apply(); } // TODO: is this right? If the amount is the correct amount, was diff --git a/src/ripple/app/tx/impl/SetAccount.cpp b/src/ripple/app/tx/impl/SetAccount.cpp index 595b5bfa41..e98ef73c86 100644 --- a/src/ripple/app/tx/impl/SetAccount.cpp +++ b/src/ripple/app/tx/impl/SetAccount.cpp @@ -19,7 +19,6 @@ #include #include -#include #include #include #include diff --git a/src/ripple/app/tx/impl/SetSignerList.cpp b/src/ripple/app/tx/impl/SetSignerList.cpp index 58a11ada30..9a458e40e3 100644 --- a/src/ripple/app/tx/impl/SetSignerList.cpp +++ b/src/ripple/app/tx/impl/SetSignerList.cpp @@ -20,7 +20,6 @@ #include #include #include -#include #include #include #include diff --git a/src/ripple/app/tx/impl/SetTrust.cpp b/src/ripple/app/tx/impl/SetTrust.cpp index 672704dbd2..9622efa1a9 100644 --- a/src/ripple/app/tx/impl/SetTrust.cpp +++ b/src/ripple/app/tx/impl/SetTrust.cpp @@ -20,7 +20,6 @@ #include #include #include -#include #include #include #include diff --git a/src/ripple/app/tx/impl/Taker.cpp b/src/ripple/app/tx/impl/Taker.cpp index a0a18178b7..0697d8a6ce 100644 --- a/src/ripple/app/tx/impl/Taker.cpp +++ b/src/ripple/app/tx/impl/Taker.cpp @@ -19,7 +19,6 @@ #include #include -#include namespace ripple { diff --git a/src/ripple/app/tx/tests/Offer.test.cpp b/src/ripple/app/tx/tests/Offer.test.cpp index 1835bac40e..003226d190 100644 --- a/src/ripple/app/tx/tests/Offer.test.cpp +++ b/src/ripple/app/tx/tests/Offer.test.cpp @@ -22,7 +22,6 @@ #include #include #include -#include #include #include diff --git a/src/ripple/app/tx/tests/common_transactor.cpp b/src/ripple/app/tx/tests/common_transactor.cpp index e5790ddb33..7156a5c04e 100644 --- a/src/ripple/app/tx/tests/common_transactor.cpp +++ b/src/ripple/app/tx/tests/common_transactor.cpp @@ -19,7 +19,6 @@ #include #include #include -#include #include #include #include diff --git a/src/ripple/ledger/DeferredCredits.h b/src/ripple/ledger/DeferredCredits.h index c8d2c4a247..e4560513d8 100644 --- a/src/ripple/ledger/DeferredCredits.h +++ b/src/ripple/ledger/DeferredCredits.h @@ -58,8 +58,12 @@ public: AccountID const& receiver, STAmount const& amount); - void clear (); + void apply (DeferredCredits const& child); + // VFALCO Is this needed? + // DEPRECATED + void clear (); + // DEPRECATED std::map::iterator begin() { return map_.begin(); } std::map::iterator end() { return map_.end(); } void merge (std::pair const& p); diff --git a/src/ripple/ledger/View.h b/src/ripple/ledger/View.h index 3d0b6ee2af..83c675585b 100644 --- a/src/ripple/ledger/View.h +++ b/src/ripple/ledger/View.h @@ -21,6 +21,11 @@ #define RIPPLE_LEDGER_VIEW_H_INCLUDED #include +#include +#include +#include +#include +#include #include namespace ripple { @@ -154,11 +159,14 @@ public: //-------------------------------------------------------------------------- - // Unfortunately necessary for DeferredCredits + // Called to adjust returned balances + // This is required to support PaymentView + virtual STAmount - deprecatedBalance (AccountID const& account, - AccountID const& issuer, STAmount const& amount) const + balanceHook (AccountID const& account, + AccountID const& issuer, + STAmount const& amount) const { return amount; } @@ -288,15 +296,254 @@ public: bool openLedger() const = 0; - // Unfortunately necessary for DeferredCredits + //-------------------------------------------------------------------------- + + // Called when a credit is made to an account + // This is required to support PaymentView virtual void - deprecatedCreditHint (AccountID const& from, - AccountID const& to, STAmount const& amount) + creditHook (AccountID const& from, + AccountID const& to, + STAmount const& amount) { } }; +//------------------------------------------------------------------------------ +// +// Observers +// +//------------------------------------------------------------------------------ + +/** Reflects the fee settings for a particular ledger. */ +class Fees +{ +private: + std::uint64_t base_; // Reference tx cost (drops) + std::uint32_t units_; // Reference fee units + std::uint32_t reserve_; // Reserve base (drops) + std::uint32_t increment_; // Reserve increment (drops) + +public: + Fees (BasicView const& view, + Config const& config); + + /** Returns the account reserve given the owner count, in drops. + + The reserve is calculated as the reserve base plus + the reserve increment times the number of increments. + */ + std::uint64_t + reserve (std::size_t ownerCount) const + { + return reserve_ + ownerCount * increment_; + } +}; + +bool +isGlobalFrozen (BasicView const& view, + AccountID const& issuer); + +// Returns the amount an account can spend without going into debt. +// +// <-- saAmount: amount of currency held by account. May be negative. +STAmount +accountHolds (BasicView const& view, + AccountID const& account, Currency const& currency, + AccountID const& issuer, FreezeHandling zeroIfFrozen, + Config const& config); + +STAmount +accountFunds (BasicView const& view, AccountID const& id, + STAmount const& saDefault, FreezeHandling freezeHandling, + Config const& config); + +/** Iterate all items in an account's owner directory. */ +void +forEachItem (BasicView const& view, AccountID const& id, + std::function const&)> f); + +/** Iterate all items after an item in an owner directory. + @param after The key of the item to start after + @param hint The directory page containing `after` + @param limit The maximum number of items to return + @return `false` if the iteration failed +*/ +bool +forEachItemAfter (BasicView const& view, AccountID const& id, + uint256 const& after, std::uint64_t const hint, + unsigned int limit, std::function< + bool (std::shared_ptr const&)> f); + +std::uint32_t +rippleTransferRate (BasicView const& view, + AccountID const& issuer); + +std::uint32_t +rippleTransferRate (BasicView const& view, + AccountID const& uSenderID, + AccountID const& uReceiverID, + AccountID const& issuer); + +/** Returns `true` if the directory is empty + @param key The key of the directory +*/ +bool +dirIsEmpty (BasicView const& view, + Keylet const& k); + +// Return the first entry and advance uDirEntry. +// <-- true, if had a next entry. +// VFALCO Fix these clumsy routines with an iterator +bool +cdirFirst (BasicView const& view, + uint256 const& uRootIndex, // --> Root of directory. + std::shared_ptr& sleNode, // <-> current node + unsigned int& uDirEntry, // <-- next entry + uint256& uEntryIndex); // <-- The entry, if available. Otherwise, zero. + +// Return the current entry and advance uDirEntry. +// <-- true, if had a next entry. +// VFALCO Fix these clumsy routines with an iterator +bool +cdirNext (BasicView const& view, + uint256 const& uRootIndex, // --> Root of directory + std::shared_ptr& sleNode, // <-> current node + unsigned int& uDirEntry, // <-> next entry + uint256& uEntryIndex); // <-- The entry, if available. Otherwise, zero. + +//------------------------------------------------------------------------------ +// +// Modifiers +// +//------------------------------------------------------------------------------ + +/** Adjust the owner count up or down. */ +void +adjustOwnerCount (View& view, + std::shared_ptr const& sle, + int amount); + +// Return the first entry and advance uDirEntry. +// <-- true, if had a next entry. +// VFALCO Fix these clumsy routines with an iterator +bool +dirFirst (View& view, + uint256 const& uRootIndex, // --> Root of directory. + std::shared_ptr& sleNode, // <-> current node + unsigned int& uDirEntry, // <-- next entry + uint256& uEntryIndex); // <-- The entry, if available. Otherwise, zero. + +// Return the current entry and advance uDirEntry. +// <-- true, if had a next entry. +// VFALCO Fix these clumsy routines with an iterator +bool +dirNext (View& view, + uint256 const& uRootIndex, // --> Root of directory + std::shared_ptr& sleNode, // <-> current node + unsigned int& uDirEntry, // <-> next entry + uint256& uEntryIndex); // <-- The entry, if available. Otherwise, zero. + +// <-- uNodeDir: For deletion, present to make dirDelete efficient. +// --> uRootIndex: The index of the base of the directory. Nodes are based off of this. +// --> uLedgerIndex: Value to add to directory. +// Only append. This allow for things that watch append only structure to just monitor from the last node on ward. +// Within a node with no deletions order of elements is sequential. Otherwise, order of elements is random. +TER +dirAdd (View& view, + std::uint64_t& uNodeDir, // Node of entry. + uint256 const& uRootIndex, + uint256 const& uLedgerIndex, + std::function fDescriber); + +TER +dirDelete (View& view, + const bool bKeepRoot, + const std::uint64_t& uNodeDir, // Node item is mentioned in. + uint256 const& uRootIndex, + uint256 const& uLedgerIndex, // Item being deleted + const bool bStable, + const bool bSoft); + +// VFALCO NOTE Both STAmount parameters should just +// be "Amount", a unit-less number. +// +/** Create a trust line + + This can set an initial balance. +*/ +TER +trustCreate (View& view, + const bool bSrcHigh, + AccountID const& uSrcAccountID, + AccountID const& uDstAccountID, + uint256 const& uIndex, // --> ripple state entry + SLE::ref sleAccount, // --> the account being set. + const bool bAuth, // --> authorize account. + const bool bNoRipple, // --> others cannot ripple through + const bool bFreeze, // --> funds cannot leave + STAmount const& saBalance, // --> balance of account being set. + // Issuer should be noAccount() + STAmount const& saLimit, // --> limit for account being set. + // Issuer should be the account being set. + std::uint32_t uSrcQualityIn, + std::uint32_t uSrcQualityOut); + +TER +trustDelete (View& view, + std::shared_ptr const& sleRippleState, + AccountID const& uLowAccountID, + AccountID const& uHighAccountID); + +/** Delete an offer. + + Requirements: + The passed `sle` be obtained from a prior + call to view.peek() +*/ +TER +offerDelete (View& view, + std::shared_ptr const& sle); + +//------------------------------------------------------------------------------ + +// +// Money Transfers +// + +// Direct send w/o fees: +// - Redeeming IOUs and/or sending sender's own IOUs. +// - Create trust line of needed. +// --> bCheckIssuer : normally require issuer to be involved. +TER +rippleCredit (View& view, + AccountID const& uSenderID, AccountID const& uReceiverID, + const STAmount & saAmount, bool bCheckIssuer); + +TER +accountSend (View& view, + AccountID const& from, + AccountID const& to, + const STAmount & saAmount); + +TER +issueIOU (View& view, + AccountID const& account, + STAmount const& amount, + Issue const& issue); + +TER +redeemIOU (View& view, + AccountID const& account, + STAmount const& amount, + Issue const& issue); + +TER +transferXRP (View& view, + AccountID const& from, + AccountID const& to, + STAmount const& amount); + } // ripple #endif diff --git a/src/ripple/ledger/ViewAPI.h b/src/ripple/ledger/ViewAPI.h deleted file mode 100644 index 0009a1543c..0000000000 --- a/src/ripple/ledger/ViewAPI.h +++ /dev/null @@ -1,272 +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_LEDGER_VIEWAPI_H_INCLUDED -#define RIPPLE_LEDGER_VIEWAPI_H_INCLUDED - -#include -#include -#include -#include -#include - -namespace ripple { - -/* - C++ API for reading and writing information in a View. -*/ - -//------------------------------------------------------------------------------ -// -// Observers -// -//------------------------------------------------------------------------------ - -/** Reflects the fee settings for a particular ledger. */ -class Fees -{ -private: - std::uint64_t base_; // Reference tx cost (drops) - std::uint32_t units_; // Reference fee units - std::uint32_t reserve_; // Reserve base (drops) - std::uint32_t increment_; // Reserve increment (drops) - -public: - Fees (BasicView const& view, - Config const& config); - - /** Returns the account reserve given the owner count, in drops. - - The reserve is calculated as the reserve base plus - the reserve increment times the number of increments. - */ - std::uint64_t - reserve (std::size_t ownerCount) const - { - return reserve_ + ownerCount * increment_; - } -}; - -bool -isGlobalFrozen (BasicView const& view, - AccountID const& issuer); - -// Returns the amount an account can spend without going into debt. -// -// <-- saAmount: amount of currency held by account. May be negative. -STAmount -accountHolds (BasicView const& view, - AccountID const& account, Currency const& currency, - AccountID const& issuer, FreezeHandling zeroIfFrozen, - Config const& config); - -STAmount -accountFunds (BasicView const& view, AccountID const& id, - STAmount const& saDefault, FreezeHandling freezeHandling, - Config const& config); - -/** Iterate all items in an account's owner directory. */ -void -forEachItem (BasicView const& view, AccountID const& id, - std::function const&)> f); - -/** Iterate all items after an item in an owner directory. - @param after The key of the item to start after - @param hint The directory page containing `after` - @param limit The maximum number of items to return - @return `false` if the iteration failed -*/ -bool -forEachItemAfter (BasicView const& view, AccountID const& id, - uint256 const& after, std::uint64_t const hint, - unsigned int limit, std::function< - bool (std::shared_ptr const&)> f); - -std::uint32_t -rippleTransferRate (BasicView const& view, - AccountID const& issuer); - -std::uint32_t -rippleTransferRate (BasicView const& view, - AccountID const& uSenderID, - AccountID const& uReceiverID, - AccountID const& issuer); - -/** Returns `true` if the directory is empty - @param key The key of the directory -*/ -bool -dirIsEmpty (BasicView const& view, - Keylet const& k); - -// Return the first entry and advance uDirEntry. -// <-- true, if had a next entry. -// VFALCO Fix these clumsy routines with an iterator -bool -cdirFirst (BasicView const& view, - uint256 const& uRootIndex, // --> Root of directory. - std::shared_ptr& sleNode, // <-> current node - unsigned int& uDirEntry, // <-- next entry - uint256& uEntryIndex); // <-- The entry, if available. Otherwise, zero. - -// Return the current entry and advance uDirEntry. -// <-- true, if had a next entry. -// VFALCO Fix these clumsy routines with an iterator -bool -cdirNext (BasicView const& view, - uint256 const& uRootIndex, // --> Root of directory - std::shared_ptr& sleNode, // <-> current node - unsigned int& uDirEntry, // <-> next entry - uint256& uEntryIndex); // <-- The entry, if available. Otherwise, zero. - -//------------------------------------------------------------------------------ -// -// Modifiers -// -//------------------------------------------------------------------------------ - -/** Adjust the owner count up or down. */ -void -adjustOwnerCount (View& view, - std::shared_ptr const& sle, - int amount); - -// Return the first entry and advance uDirEntry. -// <-- true, if had a next entry. -// VFALCO Fix these clumsy routines with an iterator -bool -dirFirst (View& view, - uint256 const& uRootIndex, // --> Root of directory. - std::shared_ptr& sleNode, // <-> current node - unsigned int& uDirEntry, // <-- next entry - uint256& uEntryIndex); // <-- The entry, if available. Otherwise, zero. - -// Return the current entry and advance uDirEntry. -// <-- true, if had a next entry. -// VFALCO Fix these clumsy routines with an iterator -bool -dirNext (View& view, - uint256 const& uRootIndex, // --> Root of directory - std::shared_ptr& sleNode, // <-> current node - unsigned int& uDirEntry, // <-> next entry - uint256& uEntryIndex); // <-- The entry, if available. Otherwise, zero. - -// <-- uNodeDir: For deletion, present to make dirDelete efficient. -// --> uRootIndex: The index of the base of the directory. Nodes are based off of this. -// --> uLedgerIndex: Value to add to directory. -// Only append. This allow for things that watch append only structure to just monitor from the last node on ward. -// Within a node with no deletions order of elements is sequential. Otherwise, order of elements is random. -TER -dirAdd (View& view, - std::uint64_t& uNodeDir, // Node of entry. - uint256 const& uRootIndex, - uint256 const& uLedgerIndex, - std::function fDescriber); - -TER -dirDelete (View& view, - const bool bKeepRoot, - const std::uint64_t& uNodeDir, // Node item is mentioned in. - uint256 const& uRootIndex, - uint256 const& uLedgerIndex, // Item being deleted - const bool bStable, - const bool bSoft); - -// VFALCO NOTE Both STAmount parameters should just -// be "Amount", a unit-less number. -// -/** Create a trust line - - This can set an initial balance. -*/ -TER -trustCreate (View& view, - const bool bSrcHigh, - AccountID const& uSrcAccountID, - AccountID const& uDstAccountID, - uint256 const& uIndex, // --> ripple state entry - SLE::ref sleAccount, // --> the account being set. - const bool bAuth, // --> authorize account. - const bool bNoRipple, // --> others cannot ripple through - const bool bFreeze, // --> funds cannot leave - STAmount const& saBalance, // --> balance of account being set. - // Issuer should be noAccount() - STAmount const& saLimit, // --> limit for account being set. - // Issuer should be the account being set. - const std::uint32_t uSrcQualityIn = 0, - const std::uint32_t uSrcQualityOut = 0); - -TER -trustDelete (View& view, - std::shared_ptr const& sleRippleState, - AccountID const& uLowAccountID, - AccountID const& uHighAccountID); - -/** Delete an offer. - - Requirements: - The passed `sle` be obtained from a prior - call to view.peek() -*/ -TER -offerDelete (View& view, - std::shared_ptr const& sle); - -//------------------------------------------------------------------------------ - -// -// Money Transfers -// - -// Direct send w/o fees: -// - Redeeming IOUs and/or sending sender's own IOUs. -// - Create trust line of needed. -// --> bCheckIssuer : normally require issuer to be involved. -TER -rippleCredit (View& view, - AccountID const& uSenderID, AccountID const& uReceiverID, - const STAmount & saAmount, bool bCheckIssuer = true); - -TER -accountSend (View& view, - AccountID const& from, - AccountID const& to, - const STAmount & saAmount); - -TER -issueIOU (View& view, - AccountID const& account, - STAmount const& amount, - Issue const& issue); - -TER -redeemIOU (View& view, - AccountID const& account, - STAmount const& amount, - Issue const& issue); - -TER -transferXRP (View& view, - AccountID const& from, - AccountID const& to, - STAmount const& amount); - -} // ripple - -#endif diff --git a/src/ripple/ledger/impl/DeferredCredits.cpp b/src/ripple/ledger/impl/DeferredCredits.cpp index a4e8ed34c2..3da5799ece 100644 --- a/src/ripple/ledger/impl/DeferredCredits.cpp +++ b/src/ripple/ledger/impl/DeferredCredits.cpp @@ -142,6 +142,22 @@ STAmount DeferredCredits::adjustedBalance (AccountID const& main, return result; } +void DeferredCredits::apply( + DeferredCredits const& child) +{ + for (auto& p : child.map_) + { + auto r = + map_.emplace(p); + if (! r.second) + { + using std::get; + get<0>(r.first->second) += get<0>(p.second); + get<1>(r.first->second) += get<1>(p.second); + } + } +} + void DeferredCredits::clear () { map_.clear (); diff --git a/src/ripple/ledger/impl/ViewAPI.cpp b/src/ripple/ledger/impl/View.cpp similarity index 98% rename from src/ripple/ledger/impl/ViewAPI.cpp rename to src/ripple/ledger/impl/View.cpp index 840f76f190..012380d17a 100644 --- a/src/ripple/ledger/impl/ViewAPI.cpp +++ b/src/ripple/ledger/impl/View.cpp @@ -18,7 +18,7 @@ //============================================================================== #include -#include +#include #include #include #include @@ -146,16 +146,14 @@ accountHolds (BasicView const& view, { amount.clear (IssueRef (currency, issuer)); } - else if (account > issuer) - { - // Put balance in account terms. - amount = sle->getFieldAmount (sfBalance); - amount.negate(); - amount.setIssuer (issuer); - } else { amount = sle->getFieldAmount (sfBalance); + if (account > issuer) + { + // Put balance in account terms. + amount.negate(); + } amount.setIssuer (issuer); } WriteLog (lsTRACE, View) << "accountHolds:" << @@ -163,7 +161,8 @@ accountHolds (BasicView const& view, " amount=" << amount.getFullText (); } - return view.deprecatedBalance(account, issuer, amount); + return view.balanceHook( + account, issuer, amount); } STAmount @@ -773,8 +772,8 @@ trustCreate (View& view, // Issuer should be noAccount() STAmount const& saLimit, // --> limit for account being set. // Issuer should be the account being set. - const std::uint32_t uQualityIn, - const std::uint32_t uQualityOut) + std::uint32_t uQualityIn, + std::uint32_t uQualityOut) { WriteLog (lsTRACE, View) << "trustCreate: " << to_string (uSrcAccountID) << ", " @@ -868,7 +867,8 @@ trustCreate (View& view, // ONLY: Create ripple balance. sleRippleState->setFieldAmount (sfBalance, bSetHigh ? -saBalance : saBalance); - view.deprecatedCreditHint (uSrcAccountID, uDstAccountID, saBalance); + view.creditHook (uSrcAccountID, + uDstAccountID, saBalance); } return terResult; @@ -1003,11 +1003,14 @@ rippleCredit (View& view, noRipple, false, saBalance, - saReceiverLimit); + saReceiverLimit, + 0, + 0); } else { - view.deprecatedCreditHint(uSenderID, uReceiverID, saAmount); + view.creditHook (uSenderID, + uReceiverID, saAmount); STAmount saBalance = sleRippleState->getFieldAmount (sfBalance); @@ -1133,6 +1136,7 @@ rippleSend (View& view, if (uSenderID == issuer || uReceiverID == issuer || issuer == noAccount()) { + // VFALCO Why do we need this bCheckIssuer? // Direct send: redeeming IOUs and/or sending own IOUs. terResult = rippleCredit (view, uSenderID, uReceiverID, saAmount, false); saActual = saAmount; @@ -1156,10 +1160,10 @@ rippleSend (View& view, " fee=" << saTransitFee.getFullText () << " cost=" << saActual.getFullText (); - terResult = rippleCredit (view, issuer, uReceiverID, saAmount); + terResult = rippleCredit (view, issuer, uReceiverID, saAmount, true); if (tesSUCCESS == terResult) - terResult = rippleCredit (view, uSenderID, issuer, saActual); + terResult = rippleCredit (view, uSenderID, issuer, saActual, true); } return terResult; @@ -1189,7 +1193,8 @@ accountSend (View& view, return rippleSend (view, uSenderID, uReceiverID, saAmount, saActual); } - view.deprecatedCreditHint (uSenderID, uReceiverID, saAmount); + view.creditHook (uSenderID, + uReceiverID, saAmount); /* XRP send which does not check reserve and can do pure adjustment. * Note that sender or receiver may be null and this not a mistake; this @@ -1359,7 +1364,7 @@ issueIOU (View& view, bool noRipple = (receiverAccount->getFlags() & lsfDefaultRipple) == 0; return trustCreate (view, bSenderHigh, issue.account, account, index, - receiverAccount, false, noRipple, false, final_balance, limit); + receiverAccount, false, noRipple, false, final_balance, limit, 0, 0); } STAmount final_balance = state->getFieldAmount (sfBalance); @@ -1377,7 +1382,8 @@ issueIOU (View& view, if (bSenderHigh) final_balance.negate (); - view.deprecatedCreditHint (issue.account, account, amount); + view.creditHook (issue.account, + account, amount); // Adjust the balance on the trust line if necessary. We do this even if we // are going to delete the line to reflect the correct balance at the time @@ -1443,7 +1449,8 @@ redeemIOU (View& view, if (bSenderHigh) final_balance.negate (); - view.deprecatedCreditHint (account, issue.account, amount); + view.creditHook (account, + issue.account, amount); // Adjust the balance on the trust line if necessary. We do this even if we // are going to delete the line to reflect the correct balance at the time diff --git a/src/ripple/rpc/handlers/AccountLines.cpp b/src/ripple/rpc/handlers/AccountLines.cpp index 1037e2da14..5a8bc8bddb 100644 --- a/src/ripple/rpc/handlers/AccountLines.cpp +++ b/src/ripple/rpc/handlers/AccountLines.cpp @@ -20,7 +20,6 @@ #include #include #include -#include #include #include diff --git a/src/ripple/rpc/handlers/AccountOffers.cpp b/src/ripple/rpc/handlers/AccountOffers.cpp index 553e4f1609..cc4f215fc2 100644 --- a/src/ripple/rpc/handlers/AccountOffers.cpp +++ b/src/ripple/rpc/handlers/AccountOffers.cpp @@ -19,7 +19,6 @@ #include #include -#include #include #include diff --git a/src/ripple/rpc/handlers/GatewayBalances.cpp b/src/ripple/rpc/handlers/GatewayBalances.cpp index 3c4317cd18..7097d8cf40 100644 --- a/src/ripple/rpc/handlers/GatewayBalances.cpp +++ b/src/ripple/rpc/handlers/GatewayBalances.cpp @@ -20,7 +20,6 @@ #include #include #include -#include #include #include #include diff --git a/src/ripple/rpc/handlers/NoRippleCheck.cpp b/src/ripple/rpc/handlers/NoRippleCheck.cpp index fedb5b9ec2..670d1e598d 100644 --- a/src/ripple/rpc/handlers/NoRippleCheck.cpp +++ b/src/ripple/rpc/handlers/NoRippleCheck.cpp @@ -22,7 +22,6 @@ #include #include #include -#include #include #include diff --git a/src/ripple/rpc/handlers/RipplePathFind.cpp b/src/ripple/rpc/handlers/RipplePathFind.cpp index 4ec7ccb9c9..dc74daa97b 100644 --- a/src/ripple/rpc/handlers/RipplePathFind.cpp +++ b/src/ripple/rpc/handlers/RipplePathFind.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -281,10 +282,11 @@ ripplePathFind (RippleLineCache::pointer const& cache, STAmount saMaxAmount({ uSrcCurrencyID, issuer }, 1); saMaxAmount.negate(); - MetaView sandbox(lpLedger, tapNONE); + boost::optional sandbox; + sandbox.emplace(lpLedger, tapNONE); auto rc = path::RippleCalc::rippleCalculate( - sandbox, + *sandbox, saMaxAmount, // --> Amount to send is unlimited // to get an estimate. saDstAmount, // --> Amount to deliver. @@ -306,9 +308,9 @@ ripplePathFind (RippleLineCache::pointer const& cache, << "Trying with an extra path element"; spsComputed.push_back(fullLiquidityPath); - reconstruct(sandbox, lpLedger, tapNONE); + sandbox.emplace(lpLedger, tapNONE); rc = path::RippleCalc::rippleCalculate( - sandbox, + *sandbox, saMaxAmount, // --> Amount to send is unlimited // to get an estimate. saDstAmount, // --> Amount to deliver. diff --git a/src/ripple/test/jtx/impl/owners.cpp b/src/ripple/test/jtx/impl/owners.cpp index 2f26d7ada1..5d4973dc16 100644 --- a/src/ripple/test/jtx/impl/owners.cpp +++ b/src/ripple/test/jtx/impl/owners.cpp @@ -18,7 +18,6 @@ //============================================================================== #include -#include #include namespace ripple { diff --git a/src/ripple/unity/app_paths.cpp b/src/ripple/unity/app_paths.cpp index 1ba8189ba1..4e6f414fa5 100644 --- a/src/ripple/unity/app_paths.cpp +++ b/src/ripple/unity/app_paths.cpp @@ -24,16 +24,13 @@ #include #include #include - -#ifdef _MSC_VER -#pragma warning (push) -//#pragma warning (disable: 4309) // truncation of constant value -#endif #include #include #include #include #include +#include + #include #include #include @@ -44,7 +41,5 @@ #include #include #include -#include -#ifdef _MSC_VER -#pragma warning (pop) -#endif + +#include diff --git a/src/ripple/unity/app_tx.cpp b/src/ripple/unity/app_tx.cpp index 19e08712a0..01ddf4bd9e 100644 --- a/src/ripple/unity/app_tx.cpp +++ b/src/ripple/unity/app_tx.cpp @@ -19,29 +19,28 @@ #include +#include +#include +#include +#include +#include +#include #include #include +#include +#include +#include +#include +#include +#include +#include +#include #include #include #include #include #include #include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include #include #include diff --git a/src/ripple/unity/ledger.cpp b/src/ripple/unity/ledger.cpp index a36562aed6..d9adde3c6c 100644 --- a/src/ripple/unity/ledger.cpp +++ b/src/ripple/unity/ledger.cpp @@ -19,6 +19,6 @@ #include -#include #include -#include +#include +#include