From ffbcb96eff0d64c558963260361ae58e6d3bcfdd Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Tue, 15 Sep 2015 19:10:16 -0400 Subject: [PATCH] Inject Application (cont.) --- src/ripple/app/ledger/AcceptedLedger.cpp | 6 +- src/ripple/app/ledger/AcceptedLedger.h | 7 +- src/ripple/app/ledger/AcceptedLedgerTx.cpp | 11 +- src/ripple/app/ledger/AcceptedLedgerTx.h | 11 +- src/ripple/app/ledger/Ledger.cpp | 507 +++++++++--------- src/ripple/app/ledger/Ledger.h | 77 ++- src/ripple/app/ledger/LedgerHistory.cpp | 10 +- src/ripple/app/ledger/LedgerHistory.h | 6 +- src/ripple/app/ledger/impl/InboundLedger.cpp | 6 +- src/ripple/app/ledger/impl/LedgerCleaner.cpp | 2 +- .../app/ledger/impl/LedgerConsensusImp.cpp | 5 +- src/ripple/app/ledger/impl/LedgerMaster.cpp | 12 +- src/ripple/app/main/Application.cpp | 39 +- src/ripple/app/main/Application.h | 4 +- src/ripple/app/main/Main.cpp | 2 +- src/ripple/app/misc/NetworkOPs.cpp | 19 +- src/ripple/app/misc/impl/AccountTxPaging.cpp | 5 +- src/ripple/app/misc/impl/AccountTxPaging.h | 3 +- src/ripple/app/paths/FindPaths.cpp | 21 +- src/ripple/app/paths/FindPaths.h | 8 +- src/ripple/app/paths/PathRequest.cpp | 2 +- src/ripple/app/paths/Pathfinder.cpp | 14 +- src/ripple/app/paths/Pathfinder.h | 5 +- src/ripple/app/tests/AccountTxPaging.test.cpp | 8 +- src/ripple/app/tests/Path_test.cpp | 27 +- src/ripple/app/tests/Regression_test.cpp | 7 +- src/ripple/app/tx/Transaction.h | 16 +- src/ripple/app/tx/TransactionMaster.h | 7 +- src/ripple/app/tx/impl/CreateOffer.cpp | 2 +- src/ripple/app/tx/impl/Transaction.cpp | 23 +- src/ripple/app/tx/impl/TransactionMaster.cpp | 9 +- src/ripple/ledger/tests/PathSet.h | 2 +- src/ripple/ledger/tests/SkipList_test.cpp | 9 +- src/ripple/ledger/tests/View_test.cpp | 21 +- src/ripple/overlay/impl/Manifest.cpp | 14 +- src/ripple/overlay/impl/Manifest.h | 9 +- src/ripple/overlay/impl/OverlayImpl.cpp | 6 +- src/ripple/overlay/impl/PeerImp.cpp | 2 +- src/ripple/overlay/tests/manifest_test.cpp | 27 +- src/ripple/rpc/Context.h | 2 +- src/ripple/rpc/RipplePathFind.h | 2 +- src/ripple/rpc/Yield.h | 5 +- src/ripple/rpc/handlers/RipplePathFind.cpp | 10 +- src/ripple/rpc/handlers/SignFor.cpp | 2 +- src/ripple/rpc/handlers/SignHandler.cpp | 2 +- src/ripple/rpc/handlers/Submit.cpp | 4 +- src/ripple/rpc/handlers/SubmitMultiSigned.cpp | 2 +- src/ripple/rpc/handlers/TxHistory.cpp | 2 +- src/ripple/rpc/impl/LegacyPathFind.cpp | 6 +- src/ripple/rpc/impl/LegacyPathFind.h | 5 +- src/ripple/rpc/impl/LookupLedger.cpp | 7 +- src/ripple/rpc/impl/TransactionSign.cpp | 54 +- src/ripple/rpc/impl/TransactionSign.h | 9 +- src/ripple/rpc/impl/Yield.cpp | 21 +- src/ripple/rpc/tests/JSONRPC.test.cpp | 13 +- src/ripple/server/impl/ServerHandlerImp.cpp | 2 +- src/ripple/shamap/Family.h | 6 +- src/ripple/shamap/SHAMap.h | 7 +- src/ripple/shamap/tests/FetchPack.test.cpp | 2 - src/ripple/shamap/tests/SHAMap.test.cpp | 2 - src/ripple/shamap/tests/SHAMapSync.test.cpp | 2 - src/ripple/shamap/tests/common.h | 10 +- src/ripple/test/jtx/Env.h | 2 +- src/ripple/test/jtx/balance.h | 2 +- src/ripple/test/jtx/delivermin.h | 2 +- src/ripple/test/jtx/fee.h | 2 +- src/ripple/test/jtx/flags.h | 4 +- src/ripple/test/jtx/impl/Env.cpp | 5 +- src/ripple/test/jtx/impl/balance.cpp | 2 +- src/ripple/test/jtx/impl/delivermin.cpp | 2 +- src/ripple/test/jtx/impl/fee.cpp | 2 +- src/ripple/test/jtx/impl/flags.cpp | 4 +- src/ripple/test/jtx/impl/jtx_json.cpp | 2 +- src/ripple/test/jtx/impl/memo.cpp | 14 +- src/ripple/test/jtx/impl/multisign.cpp | 2 +- src/ripple/test/jtx/impl/owners.cpp | 4 +- src/ripple/test/jtx/impl/paths.cpp | 6 +- src/ripple/test/jtx/impl/sendmax.cpp | 2 +- src/ripple/test/jtx/impl/seq.cpp | 2 +- src/ripple/test/jtx/impl/sig.cpp | 2 +- src/ripple/test/jtx/impl/tag.cpp | 4 +- src/ripple/test/jtx/impl/txflags.cpp | 2 +- src/ripple/test/jtx/jtx_json.h | 2 +- src/ripple/test/jtx/memo.h | 14 +- src/ripple/test/jtx/multisign.h | 2 +- src/ripple/test/jtx/owners.h | 6 +- src/ripple/test/jtx/paths.h | 4 +- src/ripple/test/jtx/prop.h | 2 +- src/ripple/test/jtx/require.h | 4 +- src/ripple/test/jtx/requires.h | 2 +- src/ripple/test/jtx/sendmax.h | 2 +- src/ripple/test/jtx/seq.h | 2 +- src/ripple/test/jtx/sig.h | 2 +- src/ripple/test/jtx/tag.h | 4 +- src/ripple/test/jtx/ter.h | 2 +- src/ripple/test/jtx/txflags.h | 2 +- src/ripple/websocket/Connection.h | 12 +- src/ripple/websocket/Handler.h | 1 + 98 files changed, 708 insertions(+), 570 deletions(-) diff --git a/src/ripple/app/ledger/AcceptedLedger.cpp b/src/ripple/app/ledger/AcceptedLedger.cpp index f68dbb343c..bb79a14323 100644 --- a/src/ripple/app/ledger/AcceptedLedger.cpp +++ b/src/ripple/app/ledger/AcceptedLedger.cpp @@ -24,13 +24,15 @@ namespace ripple { -AcceptedLedger::AcceptedLedger (std::shared_ptr const& ledger) +AcceptedLedger::AcceptedLedger ( + std::shared_ptr const& ledger, + AccountIDCache const& accountCache) : mLedger (ledger) { for (auto const& item : ledger->txs) { insert (std::make_shared( - ledger, item.first, item.second)); + ledger, item.first, item.second, accountCache)); } } diff --git a/src/ripple/app/ledger/AcceptedLedger.h b/src/ripple/app/ledger/AcceptedLedger.h index af86b01dd8..cd31538dc8 100644 --- a/src/ripple/app/ledger/AcceptedLedger.h +++ b/src/ripple/app/ledger/AcceptedLedger.h @@ -21,6 +21,7 @@ #define RIPPLE_APP_LEDGER_ACCEPTEDLEDGER_H_INCLUDED #include +#include namespace ripple { @@ -67,11 +68,11 @@ public: AcceptedLedgerTx::pointer getTxn (int) const; - explicit AcceptedLedger (std::shared_ptr const& ledger); - + AcceptedLedger ( + std::shared_ptr const& ledger, + AccountIDCache const& accountCache); private: - void insert (AcceptedLedgerTx::ref); std::shared_ptr mLedger; diff --git a/src/ripple/app/ledger/AcceptedLedgerTx.cpp b/src/ripple/app/ledger/AcceptedLedgerTx.cpp index 79f77a8014..03ab1af4ca 100644 --- a/src/ripple/app/ledger/AcceptedLedgerTx.cpp +++ b/src/ripple/app/ledger/AcceptedLedgerTx.cpp @@ -29,12 +29,14 @@ namespace ripple { AcceptedLedgerTx::AcceptedLedgerTx ( std::shared_ptr const& ledger, std::shared_ptr const& txn, - std::shared_ptr const& met) + std::shared_ptr const& met, + AccountIDCache const& accountCache) : mLedger (ledger) , mTxn (txn) , mMeta (std::make_shared ( txn->getTransactionID(), ledger->seq(), *met)) , mAffected (mMeta->getAffectedAccounts ()) + , accountCache_ (accountCache) { assert (! ledger->info().open); @@ -49,11 +51,14 @@ AcceptedLedgerTx::AcceptedLedgerTx ( AcceptedLedgerTx::AcceptedLedgerTx ( std::shared_ptr const& ledger, - STTx::ref txn, TER result) + STTx::ref txn, + TER result, + AccountIDCache const& accountCache) : mLedger (ledger) , mTxn (txn) , mResult (result) , mAffected (txn->getMentionedAccounts ()) + , accountCache_ (accountCache) { assert (ledger->info().open); buildJson (); @@ -82,7 +87,7 @@ void AcceptedLedgerTx::buildJson () { Json::Value& affected = (mJson[jss::affected] = Json::arrayValue); for (auto const& account: mAffected) - affected.append (getApp().accountIDCache().toBase58(account)); + affected.append (accountCache_.toBase58(account)); } if (mTxn->getTxnType () == ttOFFER_CREATE) diff --git a/src/ripple/app/ledger/AcceptedLedgerTx.h b/src/ripple/app/ledger/AcceptedLedgerTx.h index fdc93f25a0..c8504e7494 100644 --- a/src/ripple/app/ledger/AcceptedLedgerTx.h +++ b/src/ripple/app/ledger/AcceptedLedgerTx.h @@ -21,6 +21,7 @@ #define RIPPLE_APP_LEDGER_ACCEPTEDLEDGERTX_H_INCLUDED #include +#include #include namespace ripple { @@ -54,8 +55,13 @@ public: AcceptedLedgerTx ( std::shared_ptr const& ledger, std::shared_ptr const&, - std::shared_ptr const&); - AcceptedLedgerTx (std::shared_ptr const&, STTx::ref, TER); + std::shared_ptr const&, + AccountIDCache const&); + AcceptedLedgerTx ( + std::shared_ptr const&, + STTx::ref, + TER, + AccountIDCache const&); std::shared_ptr const& getTxn () const { @@ -111,6 +117,7 @@ private: boost::container::flat_set mAffected; Blob mRawMeta; Json::Value mJson; + AccountIDCache const& accountCache_; void buildJson (); }; diff --git a/src/ripple/app/ledger/Ledger.cpp b/src/ripple/app/ledger/Ledger.cpp index c2cb6494ee..853e49d684 100644 --- a/src/ripple/app/ledger/Ledger.cpp +++ b/src/ripple/app/ledger/Ledger.cpp @@ -39,7 +39,6 @@ #include #include #include -#include #include #include #include @@ -170,12 +169,12 @@ public: //------------------------------------------------------------------------------ -Ledger::Ledger (create_genesis_t, Config const& config) +Ledger::Ledger (create_genesis_t, Config const& config, Family& family) : mImmutable (false) , txMap_ (std::make_shared (SHAMapType::TRANSACTION, - getApp().family(), deprecatedLogs().journal("SHAMap"))) + family, deprecatedLogs().journal("SHAMap"))) , stateMap_ (std::make_shared (SHAMapType::STATE, - getApp().family(), deprecatedLogs().journal("SHAMap"))) + family, deprecatedLogs().journal("SHAMap"))) { info_.seq = 1; info_.drops = SYSTEM_CURRENCY_START; @@ -205,13 +204,14 @@ Ledger::Ledger (uint256 const& parentHash, int closeResolution, std::uint32_t ledgerSeq, bool& loaded, - Config const& config) + Config const& config, + Family& family) : mImmutable (true) , txMap_ (std::make_shared ( - SHAMapType::TRANSACTION, transHash, getApp().family(), + SHAMapType::TRANSACTION, transHash, family, deprecatedLogs().journal("SHAMap"))) , stateMap_ (std::make_shared (SHAMapType::STATE, accountHash, - getApp().family(), deprecatedLogs().journal("SHAMap"))) + family, deprecatedLogs().journal("SHAMap"))) { info_.seq = ledgerSeq; info_.parentCloseTime = parentCloseTime; @@ -256,10 +256,11 @@ Ledger::Ledger (Ledger const& ledger, } // Create a new open ledger that follows this one -Ledger::Ledger (open_ledger_t, Ledger const& prevLedger) +Ledger::Ledger (open_ledger_t, Ledger const& prevLedger, + NetClock::time_point closeTime) : mImmutable (false) , txMap_ (std::make_shared (SHAMapType::TRANSACTION, - getApp().family(), deprecatedLogs().journal("SHAMap"))) + prevLedger.stateMap_->family(), deprecatedLogs().journal("SHAMap"))) , stateMap_ (prevLedger.stateMap_->snapShot (true)) , fees_(prevLedger.fees_) { @@ -274,11 +275,10 @@ Ledger::Ledger (open_ledger_t, Ledger const& prevLedger) info_.closeTimeResolution = getNextLedgerTimeResolution ( prevLedger.info_.closeTimeResolution, getCloseAgree(prevLedger.info()), info_.seq); - // VFALCO Remove this call to getApp if (prevLedger.info_.closeTime == 0) { info_.closeTime = roundCloseTime ( - getApp().timeKeeper().closeTime().time_since_epoch().count(), + closeTime.time_since_epoch().count(), info_.closeTimeResolution); } else @@ -290,28 +290,29 @@ Ledger::Ledger (open_ledger_t, Ledger const& prevLedger) Ledger::Ledger (void const* data, std::size_t size, bool hasPrefix, - Config const& config) + Config const& config, Family& family) : mImmutable (true) , txMap_ (std::make_shared ( - SHAMapType::TRANSACTION, getApp().family(), + SHAMapType::TRANSACTION, family, deprecatedLogs().journal("SHAMap"))) , stateMap_ (std::make_shared ( - SHAMapType::STATE, getApp().family(), + SHAMapType::STATE, family, deprecatedLogs().journal("SHAMap"))) { SerialIter sit (data, size); - setRaw (sit, hasPrefix); + setRaw (sit, hasPrefix, family); // Can't set up until the stateMap is filled in } Ledger::Ledger (std::uint32_t ledgerSeq, - std::uint32_t closeTime, Config const& config) + std::uint32_t closeTime, Config const& config, + Family& family) : mImmutable (false) , txMap_ (std::make_shared ( - SHAMapType::TRANSACTION, getApp().family(), + SHAMapType::TRANSACTION, family, deprecatedLogs().journal("SHAMap"))) , stateMap_ (std::make_shared ( - SHAMapType::STATE, getApp().family(), + SHAMapType::STATE, family, deprecatedLogs().journal("SHAMap"))) { info_.seq = ledgerSeq; @@ -370,7 +371,7 @@ void Ledger::updateHash() mValidHash = true; } -void Ledger::setRaw (SerialIter& sit, bool hasPrefix) +void Ledger::setRaw (SerialIter& sit, bool hasPrefix, Family& family) { if (hasPrefix) sit.get32 (); @@ -386,9 +387,9 @@ void Ledger::setRaw (SerialIter& sit, bool hasPrefix) info_.closeFlags = sit.get8 (); updateHash (); txMap_ = std::make_shared (SHAMapType::TRANSACTION, info_.txHash, - getApp().family(), deprecatedLogs().journal("SHAMap")); + family, deprecatedLogs().journal("SHAMap")); stateMap_ = std::make_shared (SHAMapType::STATE, info_.accountHash, - getApp().family(), deprecatedLogs().journal("SHAMap")); + family, deprecatedLogs().journal("SHAMap")); } void Ledger::addRaw (Serializer& s) const @@ -448,227 +449,6 @@ deserializeTxPlusMeta (SHAMapItem const& item) return result; } -/* - * Load a ledger from the database. - * - * @param sqlSuffix: Additional string to append to the sql query. - * (typically a where clause). - * @return The ledger, ledger sequence, and ledger hash. - */ -std::tuple -loadLedgerHelper(std::string const& sqlSuffix) -{ - Ledger::pointer ledger; - uint256 ledgerHash{}; - std::uint32_t ledgerSeq{0}; - - auto db = getApp ().getLedgerDB ().checkoutDb (); - - boost::optional sLedgerHash, sPrevHash, sAccountHash, - sTransHash; - boost::optional totDrops, closingTime, prevClosingTime, - closeResolution, closeFlags, ledgerSeq64; - - std::string const sql = - "SELECT " - "LedgerHash, PrevHash, AccountSetHash, TransSetHash, " - "TotalCoins," - "ClosingTime, PrevClosingTime, CloseTimeRes, CloseFlags," - "LedgerSeq from Ledgers " + - sqlSuffix + ";"; - - *db << sql, - soci::into(sLedgerHash), - soci::into(sPrevHash), - soci::into(sAccountHash), - soci::into(sTransHash), - soci::into(totDrops), - soci::into(closingTime), - soci::into(prevClosingTime), - soci::into(closeResolution), - soci::into(closeFlags), - soci::into(ledgerSeq64); - - if (!db->got_data ()) - { - WriteLog (lsDEBUG, Ledger) << "Ledger not found: " << sqlSuffix; - return std::make_tuple (Ledger::pointer (), ledgerSeq, ledgerHash); - } - - ledgerSeq = - rangeCheckedCast(ledgerSeq64.value_or (0)); - - uint256 prevHash{}, accountHash{}, transHash{}; - if (sLedgerHash) - ledgerHash.SetHexExact (*sLedgerHash); - if (sPrevHash) - prevHash.SetHexExact (*sPrevHash); - if (sAccountHash) - accountHash.SetHexExact (*sAccountHash); - if (sTransHash) - transHash.SetHexExact (*sTransHash); - - bool loaded = false; - ledger = std::make_shared(prevHash, - transHash, - accountHash, - totDrops.value_or(0), - closingTime.value_or(0), - prevClosingTime.value_or(0), - closeFlags.value_or(0), - closeResolution.value_or(0), - ledgerSeq, - loaded, - getConfig()); - - if (!loaded) - return std::make_tuple (Ledger::pointer (), ledgerSeq, ledgerHash); - - return std::make_tuple (ledger, ledgerSeq, ledgerHash); -} - -void finishLoadByIndexOrHash(Ledger::pointer& ledger) -{ - if (!ledger) - return; - - ledger->setClosed (); - ledger->setImmutable (); - - WriteLog (lsTRACE, Ledger) - << "Loaded ledger: " << to_string (ledger->getHash ()); - - ledger->setFull (); -} - -Ledger::pointer Ledger::loadByIndex (std::uint32_t ledgerIndex) -{ - Ledger::pointer ledger; - { - std::ostringstream s; - s << "WHERE LedgerSeq = " << ledgerIndex; - std::tie (ledger, std::ignore, std::ignore) = - loadLedgerHelper (s.str ()); - } - - finishLoadByIndexOrHash (ledger); - return ledger; -} - -Ledger::pointer Ledger::loadByHash (uint256 const& ledgerHash) -{ - Ledger::pointer ledger; - { - std::ostringstream s; - s << "WHERE LedgerHash = '" << ledgerHash << "'"; - std::tie (ledger, std::ignore, std::ignore) = - loadLedgerHelper (s.str ()); - } - - finishLoadByIndexOrHash (ledger); - - assert (!ledger || ledger->getHash () == ledgerHash); - - return ledger; -} - -uint256 Ledger::getHashByIndex (std::uint32_t ledgerIndex) -{ - uint256 ret; - - std::string sql = - "SELECT LedgerHash FROM Ledgers INDEXED BY SeqLedger WHERE LedgerSeq='"; - sql.append (beast::lexicalCastThrow (ledgerIndex)); - sql.append ("';"); - - std::string hash; - { - auto db = getApp().getLedgerDB ().checkoutDb (); - - boost::optional lh; - *db << sql, - soci::into (lh); - - if (!db->got_data () || !lh) - return ret; - - hash = *lh; - if (hash.empty ()) - return ret; - } - - ret.SetHexExact (hash); - return ret; -} - -bool Ledger::getHashesByIndex ( - std::uint32_t ledgerIndex, uint256& ledgerHash, uint256& parentHash) -{ - auto db = getApp().getLedgerDB ().checkoutDb (); - - boost::optional lhO, phO; - - *db << "SELECT LedgerHash,PrevHash FROM Ledgers " - "INDEXED BY SeqLedger Where LedgerSeq = :ls;", - soci::into (lhO), - soci::into (phO), - soci::use (ledgerIndex); - - if (!lhO || !phO) - { - WriteLog (lsTRACE, Ledger) << "Don't have ledger " << ledgerIndex; - return false; - } - - ledgerHash.SetHexExact (*lhO); - parentHash.SetHexExact (*phO); - - return true; -} - -std::map< std::uint32_t, std::pair > -Ledger::getHashesByIndex (std::uint32_t minSeq, std::uint32_t maxSeq) -{ - std::map< std::uint32_t, std::pair > ret; - - std::string sql = - "SELECT LedgerSeq,LedgerHash,PrevHash FROM Ledgers WHERE LedgerSeq >= "; - sql.append (beast::lexicalCastThrow (minSeq)); - sql.append (" AND LedgerSeq <= "); - sql.append (beast::lexicalCastThrow (maxSeq)); - sql.append (";"); - - auto db = getApp().getLedgerDB ().checkoutDb (); - - std::uint64_t ls; - std::string lh; - boost::optional ph; - soci::statement st = - (db->prepare << sql, - soci::into (ls), - soci::into (lh), - soci::into (ph)); - - st.execute (); - while (st.fetch ()) - { - std::pair& hashes = - ret[rangeCheckedCast(ls)]; - hashes.first.SetHexExact (lh); - if (ph) - hashes.second.SetHexExact (*ph); - else - hashes.second.zero (); - if (!ph) - { - WriteLog (lsWARNING, Ledger) - << "Null prev hash for ledger seq: " << ls; - } - } - - return ret; -} - void Ledger::setAcquiring (void) { if (!txMap_ || !stateMap_) @@ -961,11 +741,7 @@ void Ledger::visitStateItems (std::function callback) const } catch (SHAMapMissingNode&) { - if (info_.hash.isNonZero ()) - { - getApp().getInboundLedgers().acquire( - info_.hash, info_.seq, InboundLedger::fcGENERIC); - } + stateMap_->family().missing_node (info_.hash); throw; } } @@ -1169,7 +945,7 @@ static bool saveValidatedLedger ( aLedger = app.getAcceptedLedgerCache().fetch (ledger->info().hash); if (! aLedger) { - aLedger = std::make_shared(ledger); + aLedger = std::make_shared(ledger, app.accountIDCache()); app.getAcceptedLedgerCache().canonicalize(ledger->info().hash, aLedger); } } @@ -1338,7 +1114,8 @@ qualityDirDescriber ( SLE::ref sle, bool isNew, Currency const& uTakerPaysCurrency, AccountID const& uTakerPaysIssuer, Currency const& uTakerGetsCurrency, AccountID const& uTakerGetsIssuer, - const std::uint64_t& uRate) + const std::uint64_t& uRate, + Application& app) { sle->setFieldH160 (sfTakerPaysCurrency, uTakerPaysCurrency); sle->setFieldH160 (sfTakerPaysIssuer, uTakerPaysIssuer); @@ -1348,7 +1125,7 @@ qualityDirDescriber ( if (isNew) { // VFALCO NO! This shouldn't be done here! - getApp().getOrderBookDB().addOrderBook( + app.getOrderBookDB().addOrderBook( {{uTakerPaysCurrency, uTakerPaysIssuer}, {uTakerGetsCurrency, uTakerGetsIssuer}}); } @@ -1428,4 +1205,234 @@ Ledger::getNeededAccountStateHashes ( return ret; } +//------------------------------------------------------------------------------ + +/* + * Load a ledger from the database. + * + * @param sqlSuffix: Additional string to append to the sql query. + * (typically a where clause). + * @return The ledger, ledger sequence, and ledger hash. + */ +std::tuple +loadLedgerHelper(std::string const& sqlSuffix, Application& app) +{ + Ledger::pointer ledger; + uint256 ledgerHash{}; + std::uint32_t ledgerSeq{0}; + + auto db = app.getLedgerDB ().checkoutDb (); + + boost::optional sLedgerHash, sPrevHash, sAccountHash, + sTransHash; + boost::optional totDrops, closingTime, prevClosingTime, + closeResolution, closeFlags, ledgerSeq64; + + std::string const sql = + "SELECT " + "LedgerHash, PrevHash, AccountSetHash, TransSetHash, " + "TotalCoins," + "ClosingTime, PrevClosingTime, CloseTimeRes, CloseFlags," + "LedgerSeq from Ledgers " + + sqlSuffix + ";"; + + *db << sql, + soci::into(sLedgerHash), + soci::into(sPrevHash), + soci::into(sAccountHash), + soci::into(sTransHash), + soci::into(totDrops), + soci::into(closingTime), + soci::into(prevClosingTime), + soci::into(closeResolution), + soci::into(closeFlags), + soci::into(ledgerSeq64); + + if (!db->got_data ()) + { + WriteLog (lsDEBUG, Ledger) << "Ledger not found: " << sqlSuffix; + return std::make_tuple (Ledger::pointer (), ledgerSeq, ledgerHash); + } + + ledgerSeq = + rangeCheckedCast(ledgerSeq64.value_or (0)); + + uint256 prevHash{}, accountHash{}, transHash{}; + if (sLedgerHash) + ledgerHash.SetHexExact (*sLedgerHash); + if (sPrevHash) + prevHash.SetHexExact (*sPrevHash); + if (sAccountHash) + accountHash.SetHexExact (*sAccountHash); + if (sTransHash) + transHash.SetHexExact (*sTransHash); + + bool loaded = false; + ledger = std::make_shared(prevHash, + transHash, + accountHash, + totDrops.value_or(0), + closingTime.value_or(0), + prevClosingTime.value_or(0), + closeFlags.value_or(0), + closeResolution.value_or(0), + ledgerSeq, + loaded, + getConfig(), + app.family()); + + if (!loaded) + return std::make_tuple (Ledger::pointer (), ledgerSeq, ledgerHash); + + return std::make_tuple (ledger, ledgerSeq, ledgerHash); +} + +void finishLoadByIndexOrHash(Ledger::pointer& ledger) +{ + if (!ledger) + return; + + ledger->setClosed (); + ledger->setImmutable (); + + WriteLog (lsTRACE, Ledger) + << "Loaded ledger: " << to_string (ledger->getHash ()); + + ledger->setFull (); +} + +Ledger::pointer +loadByIndex (std::uint32_t ledgerIndex, Application& app) +{ + Ledger::pointer ledger; + { + std::ostringstream s; + s << "WHERE LedgerSeq = " << ledgerIndex; + std::tie (ledger, std::ignore, std::ignore) = + loadLedgerHelper (s.str (), app); + } + + finishLoadByIndexOrHash (ledger); + return ledger; +} + +Ledger::pointer +loadByHash (uint256 const& ledgerHash, Application& app) +{ + Ledger::pointer ledger; + { + std::ostringstream s; + s << "WHERE LedgerHash = '" << ledgerHash << "'"; + std::tie (ledger, std::ignore, std::ignore) = + loadLedgerHelper (s.str (), app); + } + + finishLoadByIndexOrHash (ledger); + + assert (!ledger || ledger->getHash () == ledgerHash); + + return ledger; +} + +uint256 +getHashByIndex (std::uint32_t ledgerIndex, Application& app) +{ + uint256 ret; + + std::string sql = + "SELECT LedgerHash FROM Ledgers INDEXED BY SeqLedger WHERE LedgerSeq='"; + sql.append (beast::lexicalCastThrow (ledgerIndex)); + sql.append ("';"); + + std::string hash; + { + auto db = app.getLedgerDB ().checkoutDb (); + + boost::optional lh; + *db << sql, + soci::into (lh); + + if (!db->got_data () || !lh) + return ret; + + hash = *lh; + if (hash.empty ()) + return ret; + } + + ret.SetHexExact (hash); + return ret; +} + +bool +getHashesByIndex(std::uint32_t ledgerIndex, + uint256& ledgerHash, uint256& parentHash, + Application& app) +{ + auto db = app.getLedgerDB ().checkoutDb (); + + boost::optional lhO, phO; + + *db << "SELECT LedgerHash,PrevHash FROM Ledgers " + "INDEXED BY SeqLedger Where LedgerSeq = :ls;", + soci::into (lhO), + soci::into (phO), + soci::use (ledgerIndex); + + if (!lhO || !phO) + { + WriteLog (lsTRACE, Ledger) << "Don't have ledger " << ledgerIndex; + return false; + } + + ledgerHash.SetHexExact (*lhO); + parentHash.SetHexExact (*phO); + + return true; +} + +std::map< std::uint32_t, std::pair > +getHashesByIndex (std::uint32_t minSeq, std::uint32_t maxSeq, + Application& app) +{ + std::map< std::uint32_t, std::pair > ret; + + std::string sql = + "SELECT LedgerSeq,LedgerHash,PrevHash FROM Ledgers WHERE LedgerSeq >= "; + sql.append (beast::lexicalCastThrow (minSeq)); + sql.append (" AND LedgerSeq <= "); + sql.append (beast::lexicalCastThrow (maxSeq)); + sql.append (";"); + + auto db = app.getLedgerDB ().checkoutDb (); + + std::uint64_t ls; + std::string lh; + boost::optional ph; + soci::statement st = + (db->prepare << sql, + soci::into (ls), + soci::into (lh), + soci::into (ph)); + + st.execute (); + while (st.fetch ()) + { + std::pair& hashes = + ret[rangeCheckedCast(ls)]; + hashes.first.SetHexExact (lh); + if (ph) + hashes.second.SetHexExact (*ph); + else + hashes.second.zero (); + if (!ph) + { + WriteLog (lsWARNING, Ledger) + << "Null prev hash for ledger seq: " << ls; + } + } + + return ret; +} + } // ripple diff --git a/src/ripple/app/ledger/Ledger.h b/src/ripple/app/ledger/Ledger.h index cc9c55d9e0..1e1a4079b3 100644 --- a/src/ripple/app/ledger/Ledger.h +++ b/src/ripple/app/ledger/Ledger.h @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -98,14 +99,15 @@ public: starts in this account can ever exist, with amounts used to pay fees being destroyed. */ - Ledger (create_genesis_t, Config const& config); + Ledger (create_genesis_t, Config const& config, Family& family); // Used for ledgers loaded from JSON files Ledger (uint256 const& parentHash, uint256 const& transHash, uint256 const& accountHash, std::uint64_t totDrops, std::uint32_t closeTime, std::uint32_t parentCloseTime, int closeFlags, int closeResolution, - std::uint32_t ledgerSeq, bool & loaded, Config const& config); + std::uint32_t ledgerSeq, bool & loaded, Config const& config, + Family& family); // Create a new ledger that's a snapshot of this one Ledger (Ledger const& target, bool isMutable); @@ -116,15 +118,17 @@ public: follows previous, and have parentCloseTime == previous.closeTime. */ - Ledger (open_ledger_t, Ledger const& previous); + Ledger (open_ledger_t, Ledger const& previous, + NetClock::time_point closeTime); Ledger (void const* data, std::size_t size, bool hasPrefix, - Config const& config); + Config const& config, Family& family); // used for database ledgers Ledger (std::uint32_t ledgerSeq, - std::uint32_t closeTime, Config const& config); + std::uint32_t closeTime, Config const& config, + Family& family); ~Ledger(); @@ -250,7 +254,7 @@ public: // ledger signature operations void addRaw (Serializer& s) const; - void setRaw (SerialIter& sit, bool hasPrefix); + void setRaw (SerialIter& sit, bool hasPrefix, Family& family); // DEPRECATED // Remove contract.h include @@ -356,19 +360,6 @@ public: bool assertSane (); - // database functions (low-level) - static Ledger::pointer loadByIndex (std::uint32_t ledgerIndex); - - static Ledger::pointer loadByHash (uint256 const& ledgerHash); - - static uint256 getHashByIndex (std::uint32_t index); - - static bool getHashesByIndex ( - std::uint32_t index, uint256 & ledgerHash, uint256 & parentHash); - - static std::map< std::uint32_t, std::pair > - getHashesByIndex (std::uint32_t minSeq, std::uint32_t maxSeq); - private: class sles_iter_impl; class txs_iter_impl; @@ -416,12 +407,6 @@ private: std::uint32_t mutable mReserveIncrement = 0; }; -bool pendSaveValidated ( - Application& app, - std::shared_ptr const& ledger, - bool isSynchronous, - bool isCurrent); - /** A ledger wrapped in a CachedView. */ using CachedLedger = CachedView; @@ -431,6 +416,43 @@ using CachedLedger = CachedView; // //------------------------------------------------------------------------------ +extern +bool +pendSaveValidated( + Application& app, + std::shared_ptr const& ledger, + bool isSynchronous, + bool isCurrent); + +extern +Ledger::pointer +loadByIndex (std::uint32_t ledgerIndex, + Application& app); + +extern +std::tuple +loadLedgerHelper(std::string const& sqlSuffix, + Application& app); + +extern +Ledger::pointer +loadByHash (uint256 const& ledgerHash, Application& app); + +extern +uint256 +getHashByIndex(std::uint32_t index, Application& app); + +extern +bool +getHashesByIndex(std::uint32_t index, + uint256 &ledgerHash, uint256& parentHash, + Application& app); + +extern +std::map< std::uint32_t, std::pair> +getHashesByIndex (std::uint32_t minSeq, std::uint32_t maxSeq, + Application& app); + /** Deserialize a SHAMapItem containing a single STTx Throw: @@ -454,9 +476,6 @@ std::pair> deserializeTxPlusMeta (SHAMapItem const& item); -std::tuple -loadLedgerHelper(std::string const& sqlSuffix); - // DEPRECATED inline std::shared_ptr @@ -479,7 +498,7 @@ qualityDirDescriber ( SLE::ref, bool, Currency const& uTakerPaysCurrency, AccountID const& uTakerPaysIssuer, Currency const& uTakerGetsCurrency, AccountID const& uTakerGetsIssuer, - const std::uint64_t & uRate); + const std::uint64_t & uRate, Application& app); } // ripple diff --git a/src/ripple/app/ledger/LedgerHistory.cpp b/src/ripple/app/ledger/LedgerHistory.cpp index 77d632bd3f..a63150ade9 100644 --- a/src/ripple/app/ledger/LedgerHistory.cpp +++ b/src/ripple/app/ledger/LedgerHistory.cpp @@ -39,8 +39,10 @@ namespace ripple { // FIXME: Need to clean up ledgers by index at some point LedgerHistory::LedgerHistory ( - beast::insight::Collector::ptr const& collector) - : collector_ (collector) + beast::insight::Collector::ptr const& collector, + Application& app) + : app_ (app) + , collector_ (collector) , mismatch_counter_ (collector->make_counter ("ledger.history", "mismatch")) , m_ledgers_by_hash ("LedgerCache", CACHED_LEDGER_NUM, CACHED_LEDGER_AGE, stopwatch(), deprecatedLogs().journal("TaggedCache")) @@ -89,7 +91,7 @@ Ledger::pointer LedgerHistory::getLedgerBySeq (LedgerIndex index) } } - Ledger::pointer ret (Ledger::loadByIndex (index)); + Ledger::pointer ret = loadByIndex (index, app_); if (!ret) return ret; @@ -118,7 +120,7 @@ Ledger::pointer LedgerHistory::getLedgerByHash (LedgerHash const& hash) return ret; } - ret = Ledger::loadByHash (hash); + ret = loadByHash (hash, app_); if (!ret) return ret; diff --git a/src/ripple/app/ledger/LedgerHistory.h b/src/ripple/app/ledger/LedgerHistory.h index f556f0d0f1..19642f319e 100644 --- a/src/ripple/app/ledger/LedgerHistory.h +++ b/src/ripple/app/ledger/LedgerHistory.h @@ -21,6 +21,7 @@ #define RIPPLE_APP_LEDGER_LEDGERHISTORY_H_INCLUDED #include +#include #include #include #include @@ -33,8 +34,8 @@ namespace ripple { class LedgerHistory { public: - explicit - LedgerHistory (beast::insight::Collector::ptr const& collector); + LedgerHistory (beast::insight::Collector::ptr const& collector, + Application& app); /** Track a ledger @return `true` if the ledger was already tracked @@ -106,6 +107,7 @@ private: */ void handleMismatch (LedgerHash const& built, LedgerHash const& valid); + Application& app_; beast::insight::Collector::ptr collector_; beast::insight::Counter mismatch_counter_; diff --git a/src/ripple/app/ledger/impl/InboundLedger.cpp b/src/ripple/app/ledger/impl/InboundLedger.cpp index c21a844027..2b8adc47d1 100644 --- a/src/ripple/app/ledger/impl/InboundLedger.cpp +++ b/src/ripple/app/ledger/impl/InboundLedger.cpp @@ -166,7 +166,7 @@ bool InboundLedger::tryLocal () if (m_journal.trace) m_journal.trace << "Ledger header found in fetch pack"; mLedger = std::make_shared ( - data.data(), data.size(), true, getConfig()); + data.data(), data.size(), true, getConfig(), app_.family()); app_.getNodeStore ().store ( hotLEDGER, std::move (data), mHash); } @@ -174,7 +174,7 @@ bool InboundLedger::tryLocal () { mLedger = std::make_shared( node->getData().data(), node->getData().size(), - true, getConfig()); + true, getConfig(), app_.family()); } if (mLedger->getHash () != mHash) @@ -769,7 +769,7 @@ bool InboundLedger::takeHeader (std::string const& data) return true; mLedger = std::make_shared( - data.data(), data.size(), false, getConfig()); + data.data(), data.size(), false, getConfig(), app_.family()); if (mLedger->getHash () != mHash) { diff --git a/src/ripple/app/ledger/impl/LedgerCleaner.cpp b/src/ripple/app/ledger/impl/LedgerCleaner.cpp index 2b9b3b8787..44bd65f0bb 100644 --- a/src/ripple/app/ledger/impl/LedgerCleaner.cpp +++ b/src/ripple/app/ledger/impl/LedgerCleaner.cpp @@ -301,7 +301,7 @@ public: return false; } - Ledger::pointer dbLedger = Ledger::loadByIndex(ledgerIndex); + Ledger::pointer dbLedger = loadByIndex(ledgerIndex, app_); if (! dbLedger || (dbLedger->getHash() != ledgerHash) || (dbLedger->info().parentHash != nodeLedger->info().parentHash)) diff --git a/src/ripple/app/ledger/impl/LedgerConsensusImp.cpp b/src/ripple/app/ledger/impl/LedgerConsensusImp.cpp index 7373e397f6..953981c8bd 100644 --- a/src/ripple/app/ledger/impl/LedgerConsensusImp.cpp +++ b/src/ripple/app/ledger/impl/LedgerConsensusImp.cpp @@ -1006,7 +1006,8 @@ void LedgerConsensusImp::accept (std::shared_ptr set) // Build the new last closed ledger auto newLCL = std::make_shared( - open_ledger, *mPreviousLedger); + open_ledger, *mPreviousLedger, + app_.timeKeeper().closeTime()); newLCL->setClosed (); // so applyTransactions sees a closed ledger // Set up to write SHAMap changes to our database, @@ -1113,7 +1114,7 @@ void LedgerConsensusImp::accept (std::shared_ptr set) // Build new open ledger auto newOL = std::make_shared( - open_ledger, *newLCL); + open_ledger, *newLCL, app_.timeKeeper().closeTime()); OpenView accum(&*newOL); assert(accum.open()); diff --git a/src/ripple/app/ledger/impl/LedgerMaster.cpp b/src/ripple/app/ledger/impl/LedgerMaster.cpp index 0bdb1f4081..e4700b50a8 100644 --- a/src/ripple/app/ledger/impl/LedgerMaster.cpp +++ b/src/ripple/app/ledger/impl/LedgerMaster.cpp @@ -148,7 +148,7 @@ public: , app_ (app) , m_journal (journal) , mLastValidLedger (std::make_pair (uint256(), 0)) - , mLedgerHistory (collector) + , mLedgerHistory (collector, app) , mHeldTransactions (uint256 ()) , mLedgerCleaner (make_LedgerCleaner ( app, *this, deprecatedLogs().journal("LedgerCleaner"))) @@ -617,9 +617,9 @@ public: mCompleteLedgers.setRange (minHas, maxHas); } maxHas = minHas; - ledgerHashes = Ledger::getHashesByIndex ((seq < 500) + ledgerHashes = getHashesByIndex ((seq < 500) ? 0 - : (seq - 499), seq); + : (seq - 499), seq, app_); it = ledgerHashes.find (seq); if (it == ledgerHashes.end ()) @@ -755,7 +755,7 @@ public: { // Check the SQL database's entry for the sequence before this // ledger, if it's not this ledger's parent, invalidate it - uint256 prevHash = Ledger::getHashByIndex (ledger->info().seq - 1); + uint256 prevHash = getHashByIndex (ledger->info().seq - 1, app_); if (prevHash.isNonZero () && prevHash != ledger->info().parentHash) clearLedger (ledger->info().seq - 1); } @@ -1451,7 +1451,7 @@ public: if (hash.isNonZero ()) return hash; - return Ledger::getHashByIndex (index); + return getHashByIndex (index, app_); } // VFALCO NOTE This should return boost::optional @@ -1747,7 +1747,7 @@ void LedgerMasterImp::doAdvance () mHistLedger = ledger; auto& parent = ledger->info().parentHash; if (mFillInProgress == 0 && - Ledger::getHashByIndex(seq - 1) == parent) + getHashByIndex(seq - 1, app_) == parent) { // Previous ledger is in DB ScopedLockType lock (m_mutex); diff --git a/src/ripple/app/main/Application.cpp b/src/ripple/app/main/Application.cpp index c639685c73..a66b8656c8 100644 --- a/src/ripple/app/main/Application.cpp +++ b/src/ripple/app/main/Application.cpp @@ -110,7 +110,7 @@ Application* ApplicationImpBase::s_instance; namespace detail { -class AppFamily : public shamap::Family +class AppFamily : public Family { private: Application& app_; @@ -178,6 +178,17 @@ public: app_.getInboundLedgers ().acquire ( hash, seq, InboundLedger::fcGENERIC); } + + virtual + void + missing_node (uint256 const& hash) override + { + if (hash.isNonZero()) + { + app_.getInboundLedgers ().acquire ( + hash, 0, InboundLedger::fcGENERIC); + } + } }; } // detail @@ -341,6 +352,8 @@ public: , timeKeeper_ (make_TimeKeeper( deprecatedLogs().journal("TimeKeeper"))) + , m_txMaster (*this) + , m_nodeStoreScheduler (*this) , m_shaMapStore (make_SHAMapStore (*this, setup_SHAMapStore ( @@ -471,7 +484,7 @@ public: return *m_collectorManager; } - shamap::Family& + Family& family() { return family_; @@ -1064,16 +1077,17 @@ void ApplicationImp::startGenesisLedger () { std::shared_ptr const genesis = std::make_shared( - create_genesis, config_); + create_genesis, config_, family()); auto const next = std::make_shared( - open_ledger, *genesis); + open_ledger, *genesis, timeKeeper().closeTime()); next->setClosed (); next->setImmutable (); m_networkOPs->setLastCloseTime (next->info().closeTime); openLedger_.emplace(next, config_, cachedSLEs_, deprecatedLogs().journal("OpenLedger")); m_ledgerMaster->pushLedger (next, - std::make_shared(open_ledger, *next)); + std::make_shared(open_ledger, *next, + timeKeeper().closeTime())); } Ledger::pointer @@ -1085,7 +1099,7 @@ ApplicationImp::getLastFullLedger() std::uint32_t ledgerSeq; uint256 ledgerHash; std::tie (ledger, ledgerSeq, ledgerHash) = - loadLedgerHelper ("order by LedgerSeq desc limit 1"); + loadLedgerHelper ("order by LedgerSeq desc limit 1", *this); if (!ledger) return ledger; @@ -1192,7 +1206,7 @@ bool ApplicationImp::loadOldLedger ( } else { - loadLedger = std::make_shared (seq, closeTime, config_); + loadLedger = std::make_shared (seq, closeTime, config_, family()); loadLedger->setTotalDrops(totalDrops); for (Json::UInt index = 0; index < ledger.get().size(); ++index) @@ -1237,7 +1251,7 @@ bool ApplicationImp::loadOldLedger ( // by hash uint256 hash; hash.SetHex (ledgerID); - loadLedger = Ledger::loadByHash (hash); + loadLedger = loadByHash (hash, *this); if (!loadLedger) { @@ -1250,8 +1264,8 @@ bool ApplicationImp::loadOldLedger ( } else // assume by sequence - loadLedger = Ledger::loadByIndex ( - beast::lexicalCastThrow (ledgerID)); + loadLedger = loadByIndex ( + beast::lexicalCastThrow (ledgerID), *this); if (!loadLedger) { @@ -1269,7 +1283,7 @@ bool ApplicationImp::loadOldLedger ( m_journal.info << "Loading parent ledger"; - loadLedger = Ledger::loadByHash (replayLedger->info().parentHash); + loadLedger = loadByHash (replayLedger->info().parentHash, *this); if (!loadLedger) { m_journal.info << "Loading parent ledger from node store"; @@ -1318,7 +1332,8 @@ bool ApplicationImp::loadOldLedger ( m_ledgerMaster->setLedgerRangePresent (loadLedger->info().seq, loadLedger->info().seq); auto const openLedger = - std::make_shared(open_ledger, *loadLedger); + std::make_shared(open_ledger, *loadLedger, + timeKeeper().closeTime()); m_ledgerMaster->switchLedgers (loadLedger, openLedger); m_ledgerMaster->forceValid(loadLedger); m_networkOPs->setLastCloseTime (loadLedger->info().closeTime); diff --git a/src/ripple/app/main/Application.h b/src/ripple/app/main/Application.h index 1c4b679025..0a7bccef17 100644 --- a/src/ripple/app/main/Application.h +++ b/src/ripple/app/main/Application.h @@ -40,9 +40,7 @@ namespace NodeStore { class Database; } class AmendmentTable; class CachedSLEs; class CollectorManager; -namespace shamap { class Family; -} // shamap class HashRouter; class Logs; class LoadFeeTrack; @@ -95,7 +93,7 @@ public: virtual Config const& config() const = 0; virtual boost::asio::io_service& getIOService () = 0; virtual CollectorManager& getCollectorManager () = 0; - virtual shamap::Family& family() = 0; + virtual Family& family() = 0; virtual TimeKeeper& timeKeeper() = 0; virtual JobQueue& getJobQueue () = 0; virtual NodeCache& getTempNodeCache () = 0; diff --git a/src/ripple/app/main/Main.cpp b/src/ripple/app/main/Main.cpp index a41180ef3b..2f87153081 100644 --- a/src/ripple/app/main/Main.cpp +++ b/src/ripple/app/main/Main.cpp @@ -94,7 +94,7 @@ void startServer (Application& app) Resource::Charge loadType = Resource::feeReferenceRPC; RPC::Context context { jvCommand, app, loadType, app.getOPs (), - app.getLedgerMaster(), Role::ADMIN}; + app.getLedgerMaster(), Role::ADMIN, app}; Json::Value jvResult; RPC::doCommand (context, jvResult); diff --git a/src/ripple/app/misc/NetworkOPs.cpp b/src/ripple/app/misc/NetworkOPs.cpp index c81f380181..3a470a25a6 100644 --- a/src/ripple/app/misc/NetworkOPs.cpp +++ b/src/ripple/app/misc/NetworkOPs.cpp @@ -699,7 +699,7 @@ void NetworkOPsImp::submitTransaction (STTx::pointer iTrans) } auto tx = std::make_shared ( - trans, Validate::NO, directSigVerify, reason); + trans, Validate::NO, directSigVerify, reason, app_); m_job_queue.addJob (jtTRANSACTION, "submitTxn", [this, tx] (Job&) { auto t = tx; @@ -1316,7 +1316,8 @@ void NetworkOPsImp::switchLastClosedLedger ( clearNeedNetworkLedger (); newLCL->setClosed (); auto const newOL = std::make_shared< - Ledger>(open_ledger, std::ref (*newLCL)); + Ledger>(open_ledger, std::ref (*newLCL), + app_.timeKeeper().closeTime()); // Caller must own master lock { auto const oldOL = @@ -1746,7 +1747,7 @@ NetworkOPs::AccountTxs NetworkOPsImp::getAccountTxs ( txnMeta.clear (); auto txn = Transaction::transactionFromSQL ( - ledgerSeq, status, rawTxn, Validate::NO); + ledgerSeq, status, rawTxn, Validate::NO, app_); if (txnMeta.empty ()) { // Work around a bug that could leave the metadata missing @@ -1824,15 +1825,17 @@ NetworkOPsImp::getTxsAccount ( { static std::uint32_t const page_length (200); + Application& app = app_; NetworkOPsImp::AccountTxs ret; - auto bound = [&ret]( + auto bound = [&ret, &app]( std::uint32_t ledger_index, std::string const& status, Blob const& rawTxn, Blob const& rawMeta) { - convertBlobsToTxResult (ret, ledger_index, status, rawTxn, rawMeta); + convertBlobsToTxResult ( + ret, ledger_index, status, rawTxn, rawMeta, app); }; accountTxPage(app_.getTxnDB (), app_.accountIDCache(), @@ -2099,7 +2102,8 @@ void NetworkOPsImp::pubProposedTransaction ( } } } - AcceptedLedgerTx alt (lpCurrent, stTxn, terResult); + AcceptedLedgerTx alt (lpCurrent, stTxn, terResult, + app_.accountIDCache()); m_journal.trace << "pubProposed: " << alt.getJson (); pubAccountTransaction (lpCurrent, alt, false); } @@ -2113,7 +2117,8 @@ void NetworkOPsImp::pubLedger (Ledger::ref lpAccepted) app_.getAcceptedLedgerCache().fetch (lpAccepted->info().hash); if (! alpAccepted) { - alpAccepted = std::make_shared (lpAccepted); + alpAccepted = std::make_shared ( + lpAccepted, app_.accountIDCache()); app_.getAcceptedLedgerCache().canonicalize ( lpAccepted->info().hash, alpAccepted); } diff --git a/src/ripple/app/misc/impl/AccountTxPaging.cpp b/src/ripple/app/misc/impl/AccountTxPaging.cpp index 1a04eb6e81..acc7433c0a 100644 --- a/src/ripple/app/misc/impl/AccountTxPaging.cpp +++ b/src/ripple/app/misc/impl/AccountTxPaging.cpp @@ -36,14 +36,15 @@ convertBlobsToTxResult ( std::uint32_t ledger_index, std::string const& status, Blob const& rawTxn, - Blob const& rawMeta) + Blob const& rawMeta, + Application& app) { SerialIter it (makeSlice(rawTxn)); STTx::pointer txn = std::make_shared (it); std::string reason; auto tr = std::make_shared (txn, Validate::NO, - directSigVerify, reason); + directSigVerify, reason, app); tr->setStatus (Transaction::sqlTransactionStatus(status)); tr->setLedger (ledger_index); diff --git a/src/ripple/app/misc/impl/AccountTxPaging.h b/src/ripple/app/misc/impl/AccountTxPaging.h index 2d35dddaaa..bd7e772b14 100644 --- a/src/ripple/app/misc/impl/AccountTxPaging.h +++ b/src/ripple/app/misc/impl/AccountTxPaging.h @@ -37,7 +37,8 @@ convertBlobsToTxResult ( std::uint32_t ledger_index, std::string const& status, Blob const& rawTxn, - Blob const& rawMeta); + Blob const& rawMeta, + Application& app); void saveLedgerAsync (Application& app, std::uint32_t seq); diff --git a/src/ripple/app/paths/FindPaths.cpp b/src/ripple/app/paths/FindPaths.cpp index ff800f93ca..fbb6051de5 100644 --- a/src/ripple/app/paths/FindPaths.cpp +++ b/src/ripple/app/paths/FindPaths.cpp @@ -47,9 +47,10 @@ public: findPathsForIssue ( Issue const& issue, STPathSet const& paths, - STPath& fullLiquidityPath) + STPath& fullLiquidityPath, + Application& app) { - if (auto& pathfinder = getPathFinder (issue.currency)) + if (auto& pathfinder = getPathFinder (issue.currency, app)) { return pathfinder->getBestPaths (maxPaths_, fullLiquidityPath, paths, issue.account); @@ -69,14 +70,15 @@ private: int const searchLevel_; unsigned int const maxPaths_; - std::unique_ptr const& getPathFinder (Currency const& currency) + std::unique_ptr const& + getPathFinder (Currency const& currency, Application& app) { auto i = currencyMap_.find (currency); if (i != currencyMap_.end ()) return i->second; auto pathfinder = std::make_unique ( cache_, srcAccount_, dstAccount_, currency, - boost::none, dstAmount_, srcAmount_); + boost::none, dstAmount_, srcAmount_, app); if (pathfinder->findPaths (searchLevel_)) pathfinder->computePathRanks (maxPaths_); else @@ -108,9 +110,10 @@ boost::optional FindPaths::findPathsForIssue ( Issue const& issue, STPathSet const& paths, - STPath& fullLiquidityPath) + STPath& fullLiquidityPath, + Application& app) { - return impl_->findPathsForIssue (issue, paths, fullLiquidityPath); + return impl_->findPathsForIssue (issue, paths, fullLiquidityPath, app); } boost::optional @@ -123,7 +126,8 @@ findPathsForOneIssuer ( int searchLevel, unsigned int const maxPaths, STPathSet const& paths, - STPath& fullLiquidityPath) + STPath& fullLiquidityPath, + Application& app) { Pathfinder pf ( cache, @@ -132,7 +136,8 @@ findPathsForOneIssuer ( srcIssue.currency, srcIssue.account, dstAmount, - boost::none); + boost::none, + app); if (! pf.findPaths(searchLevel)) return boost::none; diff --git a/src/ripple/app/paths/FindPaths.h b/src/ripple/app/paths/FindPaths.h index f7dddda34f..2f09f76cff 100644 --- a/src/ripple/app/paths/FindPaths.h +++ b/src/ripple/app/paths/FindPaths.h @@ -55,7 +55,9 @@ public: On output, if fullLiquidityPath is non-empty, it contains one extra path that can move the entire liquidity requested. */ - STPath& fullLiquidityPath); + STPath& fullLiquidityPath, + + Application& app); private: class Impl; @@ -88,7 +90,9 @@ findPathsForOneIssuer ( On output, if fullLiquidityPath is non-empty, it contains one extra path that can move the entire liquidity requested. */ - STPath& fullLiquidityPath); + STPath& fullLiquidityPath, + + Application& app); void initializePathfinding (); diff --git a/src/ripple/app/paths/PathRequest.cpp b/src/ripple/app/paths/PathRequest.cpp index b85fe90c0c..a545f8673b 100644 --- a/src/ripple/app/paths/PathRequest.cpp +++ b/src/ripple/app/paths/PathRequest.cpp @@ -454,7 +454,7 @@ PathRequest::findPaths ( { STPath fullLiquidityPath; auto result = fp.findPathsForIssue(issue, - mContext[issue], fullLiquidityPath); + mContext[issue], fullLiquidityPath, app_); if (! result) { m_journal.debug << iIdentifier << " No paths found"; diff --git a/src/ripple/app/paths/Pathfinder.cpp b/src/ripple/app/paths/Pathfinder.cpp index 9985da3245..27dd37bc8a 100644 --- a/src/ripple/app/paths/Pathfinder.cpp +++ b/src/ripple/app/paths/Pathfinder.cpp @@ -148,7 +148,8 @@ Pathfinder::Pathfinder ( Currency const& uSrcCurrency, boost::optional const& uSrcIssuer, STAmount const& saDstAmount, - boost::optional const& srcAmount) + boost::optional const& srcAmount, + Application& app) : mSrcAccount (uSrcAccount), mDstAccount (uDstAccount), mEffectiveDst (isXRP(saDstAmount.getIssuer ()) ? @@ -162,7 +163,8 @@ Pathfinder::Pathfinder ( convert_all_ (mDstAmount == STAmount(mDstAmount.issue(), STAmount::cMaxValue, STAmount::cMaxOffset)), mLedger (cache->getLedger ()), - mRLCache (cache) + mRLCache (cache), + app_ (app) { assert (! uSrcIssuer || isXRP(uSrcCurrency) == isXRP(uSrcIssuer.get())); } @@ -201,7 +203,7 @@ bool Pathfinder::findPaths (int searchLevel) return true; } - m_loadEvent = getApp ().getJobQueue ().getLoadEvent ( + m_loadEvent = app_.getJobQueue ().getLoadEvent ( jtPATH_FIND, "FindPath"); auto currencyIsXRP = isXRP (mSrcCurrency); @@ -715,7 +717,7 @@ int Pathfinder::getPathsOut ( if (!bFrozen) { - count = getApp ().getOrderBookDB ().getBookSize (issue); + count = app_.getOrderBookDB ().getBookSize (issue); for (auto const& item : mRLCache->getRippleLines (account)) { @@ -1057,7 +1059,7 @@ void Pathfinder::addLink ( if (addFlags & afOB_XRP) { // to XRP only - if (!bOnXRP && getApp ().getOrderBookDB ().isBookToXRP ( + if (!bOnXRP && app_.getOrderBookDB ().isBookToXRP ( {uEndCurrency, uEndIssuer})) { STPathElement pathElement( @@ -1071,7 +1073,7 @@ void Pathfinder::addLink ( else { bool bDestOnly = (addFlags & afOB_LAST) != 0; - auto books = getApp ().getOrderBookDB ().getBooksByTakerPays( + auto books = app_.getOrderBookDB ().getBooksByTakerPays( {uEndCurrency, uEndIssuer}); WriteLog (lsTRACE, Pathfinder) << books.size () << " books found from this currency/issuer"; diff --git a/src/ripple/app/paths/Pathfinder.h b/src/ripple/app/paths/Pathfinder.h index bb600a99e7..7fc5de1f61 100644 --- a/src/ripple/app/paths/Pathfinder.h +++ b/src/ripple/app/paths/Pathfinder.h @@ -45,7 +45,8 @@ public: Currency const& uSrcCurrency, boost::optional const& uSrcIssuer, STAmount const& dstAmount, - boost::optional const& srcAmount); + boost::optional const& srcAmount, + Application& app); ~Pathfinder(); static void initPathTable (); @@ -190,6 +191,8 @@ private: hash_map mPathsOutCountMap; + Application& app_; + // Add ripple paths static std::uint32_t const afADD_ACCOUNTS = 0x001; diff --git a/src/ripple/app/tests/AccountTxPaging.test.cpp b/src/ripple/app/tests/AccountTxPaging.test.cpp index cd4080c806..3d80a61b73 100644 --- a/src/ripple/app/tests/AccountTxPaging.test.cpp +++ b/src/ripple/app/tests/AccountTxPaging.test.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include // #include #include @@ -90,15 +91,18 @@ struct AccountTxPaging_test : beast::unit_test::suite std::int32_t const page_length = 200; bool const admin = true; + test::jtx::Env env(*this); + Application& app = env.app(); auto& txs = txs_; - auto bound = [&txs]( + auto bound = [&txs, &app]( std::uint32_t ledger_index, std::string const& status, Blob const& rawTxn, Blob const& rawMeta) { - convertBlobsToTxResult (txs, ledger_index, status, rawTxn, rawMeta); + convertBlobsToTxResult ( + txs, ledger_index, status, rawTxn, rawMeta, app); }; accountTxPage(*db_, *idCache_, [](std::uint32_t){}, bound, account_, minLedger, diff --git a/src/ripple/app/tests/Path_test.cpp b/src/ripple/app/tests/Path_test.cpp index 3b0086015e..e04a074dd5 100644 --- a/src/ripple/app/tests/Path_test.cpp +++ b/src/ripple/app/tests/Path_test.cpp @@ -135,12 +135,13 @@ equal(STAmount const& sa1, STAmount const& sa2) } std::tuple -find_paths(std::shared_ptr const& view, +find_paths(jtx::Env& env, jtx::Account const& src, jtx::Account const& dst, STAmount const& saDstAmount, boost::optional const& saSendMax = boost::none) { static int const level = 8; + auto const& view = env.open (); auto cache = std::make_shared(view); auto currencies = accountSourceCurrencies(src, cache, true); auto jvSrcCurrencies = Json::Value(Json::arrayValue); @@ -153,7 +154,7 @@ find_paths(std::shared_ptr const& view, auto result = ripplePathFind(cache, src.id(), dst.id(), saDstAmount, jvSrcCurrencies, boost::none, level, saSendMax, - saDstAmount == STAmount(saDstAmount.issue(), 1u, 0, true)); + saDstAmount == STAmount(saDstAmount.issue(), 1u, 0, true), env.app ()); if (! result.first) { throw std::runtime_error( @@ -191,7 +192,7 @@ public: Env env(*this); env.fund(XRP(10000), "alice", "bob"); - auto const result = find_paths(env.open(), + auto const result = find_paths(env, "alice", "bob", Account("bob")["USD"](5)); expect(std::get<0>(result).empty()); } @@ -207,7 +208,7 @@ public: STPathSet st; STAmount sa; - std::tie(st, sa, std::ignore) = find_paths(env.open(), + std::tie(st, sa, std::ignore) = find_paths(env, "alice", "bob", Account("bob")["USD"](5)); expect(st.empty()); expect(equal(sa, Account("alice")["USD"](5))); @@ -248,7 +249,7 @@ public: STPathSet st; STAmount sa; - std::tie(st, sa, std::ignore) = find_paths(env.open(), + std::tie(st, sa, std::ignore) = find_paths(env, "alice", "bob", Account("bob")["USD"](5)); expect(same(st, stpath("gateway"))); expect(equal(sa, Account("alice")["USD"](5))); @@ -273,7 +274,7 @@ public: STPathSet st; STAmount sa; STAmount da; - std::tie(st, sa, da) = find_paths(env.open(), + std::tie(st, sa, da) = find_paths(env, "alice", "edward", Account("edward")["USD"](-1)); expect(same(st, stpath("dan"), stpath("bob", "carol"))); expect(equal(sa, Account("alice")["USD"](110))); @@ -292,11 +293,11 @@ public: STPathSet st; STAmount sa; STAmount da; - std::tie(st, sa, da) = find_paths(env.open(), + std::tie(st, sa, da) = find_paths(env, "alice", "bob", Account("bob")["AUD"](-1), boost::optional(XRP(100000000))); expect(st.empty()); - std::tie(st, sa, da) = find_paths(env.open(), + std::tie(st, sa, da) = find_paths(env, "alice", "bob", Account("bob")["USD"](-1), boost::optional(XRP(100000000))); expect(sa == XRP(100)); @@ -417,7 +418,7 @@ public: STPathSet st; STAmount sa; - std::tie(st, sa, std::ignore) = find_paths(env.open(), + std::tie(st, sa, std::ignore) = find_paths(env, "alice", "bob", Account("bob")["USD"](5)); expect(same(st, stpath("gateway"), stpath("gateway2"), stpath("dan"), stpath("carol"))); @@ -438,14 +439,14 @@ public: env.require(balance("bob", Account("carol")["USD"](-75))); env.require(balance("carol", Account("bob")["USD"](75))); - auto result = find_paths(env.open(), + auto result = find_paths(env, "alice", "bob", Account("bob")["USD"](25)); expect(std::get<0>(result).empty()); env(pay("alice", "bob", Account("alice")["USD"](25)), ter(tecPATH_DRY)); - result = find_paths(env.open(), + result = find_paths(env, "alice", "bob", Account("alice")["USD"](25)); expect(std::get<0>(result).empty()); @@ -527,7 +528,7 @@ public: env.require(balance("bob", AUD(10))); env.require(balance("carol", AUD(39))); - auto const result = find_paths(env.open(), + auto const result = find_paths(env, "alice", "bob", Account("bob")["USD"](25)); expect(std::get<0>(result).empty()); } @@ -544,7 +545,7 @@ public: STPathSet st; STAmount sa; - std::tie(st, sa, std::ignore) = find_paths(env.open(), + std::tie(st, sa, std::ignore) = find_paths(env, "alice", "carol", Account("carol")["USD"](5)); expect(same(st, stpath("bob"))); expect(equal(sa, Account("alice")["USD"](5))); diff --git a/src/ripple/app/tests/Regression_test.cpp b/src/ripple/app/tests/Regression_test.cpp index c622b1dcde..ac82d573c4 100644 --- a/src/ripple/app/tests/Regression_test.cpp +++ b/src/ripple/app/tests/Regression_test.cpp @@ -49,7 +49,7 @@ struct Regression_test : public beast::unit_test::suite // be reproduced against an open ledger. Make a local // closed ledger and work with it directly. auto closed = std::make_shared( - create_genesis, env.config); + create_genesis, env.config, env.app().family()); auto expectedDrops = SYSTEM_CURRENCY_START; expect(closed->info().drops == expectedDrops); @@ -57,7 +57,8 @@ struct Regression_test : public beast::unit_test::suite auto const aliceAmount = XRP(aliceXRP); auto next = std::make_shared( - open_ledger, *closed); + open_ledger, *closed, + env.app().timeKeeper().closeTime()); next->setClosed(); { // Fund alice @@ -89,7 +90,7 @@ struct Regression_test : public beast::unit_test::suite // doesn't know about this account. auto const jt = env.jt(noop("alice"), fee(expectedDrops), seq(1)); - + OpenView accum(&*next); auto const result = ripple::apply(env.app(), diff --git a/src/ripple/app/tx/Transaction.h b/src/ripple/app/tx/Transaction.h index e40e8ab922..193aaad8c7 100644 --- a/src/ripple/app/tx/Transaction.h +++ b/src/ripple/app/tx/Transaction.h @@ -32,6 +32,7 @@ namespace ripple { // obtain a binary version. // +class Application; class Database; enum TransStatus @@ -62,11 +63,12 @@ public: using ref = const pointer&; public: - Transaction (STTx::ref, Validate, SigVerify, std::string&) noexcept; + Transaction ( + STTx::ref, Validate, SigVerify, std::string&, Application&) noexcept; static Transaction::pointer - sharedTransaction (Blob const&, Validate); + sharedTransaction (Blob const&, Validate, Application& app); static Transaction::pointer @@ -74,7 +76,8 @@ public: boost::optional const& ledgerSeq, boost::optional const& status, Blob const& rawTxn, - Validate validate); + Validate validate, + Application& app); static TransStatus @@ -152,12 +155,10 @@ public: Json::Value getJson (int options, bool binary = false) const; - static Transaction::pointer load (uint256 const& id); + static Transaction::pointer load (uint256 const& id, Application& app); private: uint256 mTransactionID; - // VFALCO NOTE This member appears unused - AccountID mAccountFrom; RippleAddress mFromPubKey; // Sign transaction with this. mSignPubKey RippleAddress mSourcePrivate; // Sign transaction with this. @@ -166,7 +167,8 @@ private: TER mResult = temUNCERTAIN; bool mApplying = false; - STTx::pointer mTransaction; + STTx::pointer mTransaction; + Application& mApp; }; } // ripple diff --git a/src/ripple/app/tx/TransactionMaster.h b/src/ripple/app/tx/TransactionMaster.h index ee16b78e2e..8ddb567b80 100644 --- a/src/ripple/app/tx/TransactionMaster.h +++ b/src/ripple/app/tx/TransactionMaster.h @@ -26,12 +26,16 @@ namespace ripple { +class Application; + // Tracks all transactions in memory class TransactionMaster { public: - TransactionMaster (); + TransactionMaster (Application& app); + TransactionMaster (TransactionMaster const&) = delete; + TransactionMaster& operator= (TransactionMaster const&) = delete; Transaction::pointer fetch (uint256 const& , bool checkDisk); STTx::pointer fetch (std::shared_ptr const& item, SHAMapTreeNode:: TNType type, @@ -44,6 +48,7 @@ public: TaggedCache & getCache(); private: + Application& mApp; TaggedCache mCache; }; diff --git a/src/ripple/app/tx/impl/CreateOffer.cpp b/src/ripple/app/tx/impl/CreateOffer.cpp index 7885c4ed37..3c05575083 100644 --- a/src/ripple/app/tx/impl/CreateOffer.cpp +++ b/src/ripple/app/tx/impl/CreateOffer.cpp @@ -835,7 +835,7 @@ CreateOffer::applyGuts (ApplyView& view, ApplyView& view_cancel) &qualityDirDescriber, std::placeholders::_1, std::placeholders::_2, saTakerPays.getCurrency (), uPaysIssuerID, saTakerGets.getCurrency (), - uGetsIssuerID, uRate)); + uGetsIssuerID, uRate, std::ref(ctx_.app))); } if (result == tesSUCCESS) diff --git a/src/ripple/app/tx/impl/Transaction.cpp b/src/ripple/app/tx/impl/Transaction.cpp index 7d3b31d61b..f5f5614050 100644 --- a/src/ripple/app/tx/impl/Transaction.cpp +++ b/src/ripple/app/tx/impl/Transaction.cpp @@ -31,15 +31,15 @@ namespace ripple { Transaction::Transaction (STTx::ref stx, Validate validate, - SigVerify sigVerify, std::string& reason) + SigVerify sigVerify, std::string& reason, Application& app) noexcept : mTransaction (stx) + , mApp (app) { try { mFromPubKey.setAccountPublic (mTransaction->getSigningPubKey ()); mTransactionID = mTransaction->getTransactionID (); - mAccountFrom = mTransaction->getAccountID(sfAccount); } catch (std::exception& e) { @@ -61,7 +61,7 @@ Transaction::Transaction (STTx::ref stx, Validate validate, } Transaction::pointer Transaction::sharedTransaction ( - Blob const& vucTransaction, Validate validate) + Blob const& vucTransaction, Validate validate, Application& app) { try { @@ -69,7 +69,7 @@ Transaction::pointer Transaction::sharedTransaction ( std::string reason; return std::make_shared (std::make_shared (sit), - validate, getApp().getHashRouter().sigVerify(), reason); + validate, app.getHashRouter().sigVerify(), reason, app); } catch (std::exception& e) { @@ -90,7 +90,7 @@ Transaction::pointer Transaction::sharedTransaction ( bool Transaction::checkSign (std::string& reason, SigVerify sigVerify) const { - bool const allowMultiSign = getApp().getLedgerMaster(). + bool const allowMultiSign = mApp.getLedgerMaster(). getValidatedRules().enabled (featureMultiSign, getConfig().features); if (! mFromPubKey.isValid ()) @@ -135,7 +135,8 @@ Transaction::pointer Transaction::transactionFromSQL ( boost::optional const& ledgerSeq, boost::optional const& status, Blob const& rawTxn, - Validate validate) + Validate validate, + Application& app) { std::uint32_t const inLedger = rangeCheckedCast(ledgerSeq.value_or (0)); @@ -144,14 +145,14 @@ Transaction::pointer Transaction::transactionFromSQL ( auto txn = std::make_shared (it); std::string reason; auto tr = std::make_shared (txn, validate, - getApp().getHashRouter().sigVerify(), reason); + app.getHashRouter().sigVerify(), reason, app); tr->setStatus (sqlTransactionStatus (status)); tr->setLedger (inLedger); return tr; } -Transaction::pointer Transaction::load (uint256 const& id) +Transaction::pointer Transaction::load (uint256 const& id, Application& app) { std::string sql = "SELECT LedgerSeq,Status,RawTxn " "FROM Transactions WHERE TransID='"; @@ -162,7 +163,7 @@ Transaction::pointer Transaction::load (uint256 const& id) boost::optional status; Blob rawTxn; { - auto db = getApp().getTxnDB ().checkoutDb (); + auto db = app.getTxnDB ().checkoutDb (); soci::blob sociRawTxnBlob (*db); soci::indicator rti; @@ -175,7 +176,7 @@ Transaction::pointer Transaction::load (uint256 const& id) } return Transaction::transactionFromSQL ( - ledgerSeq, status, rawTxn, Validate::YES); + ledgerSeq, status, rawTxn, Validate::YES, app); } // options 1 to include the date of the transaction @@ -190,7 +191,7 @@ Json::Value Transaction::getJson (int options, bool binary) const if (options == 1) { - auto ledger = getApp().getLedgerMaster (). + auto ledger = mApp.getLedgerMaster (). getLedgerBySeq (mInLedger); if (ledger) ret[jss::date] = ledger->info().closeTime; diff --git a/src/ripple/app/tx/impl/TransactionMaster.cpp b/src/ripple/app/tx/impl/TransactionMaster.cpp index e193e35b16..8d07a568a8 100644 --- a/src/ripple/app/tx/impl/TransactionMaster.cpp +++ b/src/ripple/app/tx/impl/TransactionMaster.cpp @@ -25,8 +25,9 @@ namespace ripple { -TransactionMaster::TransactionMaster () - : mCache ("TransactionCache", 65536, 1800, stopwatch(), +TransactionMaster::TransactionMaster (Application& app) + : mApp (app) + , mCache ("TransactionCache", 65536, 1800, stopwatch(), deprecatedLogs().journal("TaggedCache")) { } @@ -49,7 +50,7 @@ Transaction::pointer TransactionMaster::fetch (uint256 const& txnID, bool checkD if (!checkDisk || txn) return txn; - txn = Transaction::load (txnID); + txn = Transaction::load (txnID, mApp); if (!txn) return txn; @@ -64,7 +65,7 @@ STTx::pointer TransactionMaster::fetch (std::shared_ptr const& item, bool checkDisk, std::uint32_t uCommitLedger) { STTx::pointer txn; - auto iTx = getApp().getMasterTransaction ().fetch (item->key(), false); + auto iTx = fetch (item->key(), false); if (!iTx) { diff --git a/src/ripple/ledger/tests/PathSet.h b/src/ripple/ledger/tests/PathSet.h index caa61d6005..30f83f5a70 100644 --- a/src/ripple/ledger/tests/PathSet.h +++ b/src/ripple/ledger/tests/PathSet.h @@ -30,7 +30,7 @@ namespace test { */ inline bool -isOffer (jtx::Env const& env, +isOffer (jtx::Env& env, jtx::Account const& account, STAmount const& takerPays, STAmount const& takerGets) diff --git a/src/ripple/ledger/tests/SkipList_test.cpp b/src/ripple/ledger/tests/SkipList_test.cpp index d1f5166a9a..de77a3ce39 100644 --- a/src/ripple/ledger/tests/SkipList_test.cpp +++ b/src/ripple/ledger/tests/SkipList_test.cpp @@ -19,8 +19,9 @@ #include #include -#include #include +#include +#include #include namespace ripple { @@ -34,14 +35,16 @@ class SkipList_test : public beast::unit_test::suite beast::Journal const j; std::vector> history; { + jtx::Env env(*this); Config const config; auto prev = - std::make_shared(create_genesis, config); + std::make_shared(create_genesis, config, env.app().family()); history.push_back(prev); for (auto i = 0; i < 1023; ++i) { auto next = std::make_shared( - open_ledger, *prev); + open_ledger, *prev, + env.app().timeKeeper().closeTime()); next->updateSkipList(); next->setClosed(); history.push_back(next); diff --git a/src/ripple/ledger/tests/View_test.cpp b/src/ripple/ledger/tests/View_test.cpp index c8a7f0f07b..9d7616b34c 100644 --- a/src/ripple/ledger/tests/View_test.cpp +++ b/src/ripple/ledger/tests/View_test.cpp @@ -147,13 +147,15 @@ class View_test testLedger() { using namespace jtx; + Env env(*this); Config const config; std::shared_ptr const genesis = std::make_shared( - create_genesis, config); + create_genesis, config, env.app().family()); auto const ledger = std::make_shared( - open_ledger, *genesis); + open_ledger, *genesis, + env.app().timeKeeper().closeTime()); wipe(*ledger); ReadView& v = *ledger; succ(v, 0, boost::none); @@ -409,13 +411,14 @@ class View_test testSles() { using namespace jtx; + Env env(*this); Config const config; std::shared_ptr const genesis = std::make_shared ( - create_genesis, config); - auto const ledger = - std::make_shared ( - open_ledger, *genesis); + create_genesis, config, env.app().family()); + auto const ledger = std::make_shared( + open_ledger, *genesis, + env.app().timeKeeper().closeTime()); auto setup123 = [&ledger, this]() { // erase middle element @@ -489,13 +492,15 @@ class View_test // ApplyView on that, then another ApplyView, // erase the item, apply. { + Env env(*this); Config const config; std::shared_ptr const genesis = std::make_shared( - create_genesis, config); + create_genesis, config, env.app().family()); auto const ledger = std::make_shared( - open_ledger, *genesis); + open_ledger, *genesis, + env.app().timeKeeper().closeTime()); wipe(*ledger); ledger->rawInsert(sle(1)); ReadView& v0 = *ledger; diff --git a/src/ripple/overlay/impl/Manifest.cpp b/src/ripple/overlay/impl/Manifest.cpp index 528e452bde..642558df11 100644 --- a/src/ripple/overlay/impl/Manifest.cpp +++ b/src/ripple/overlay/impl/Manifest.cpp @@ -156,14 +156,15 @@ ManifestCache::configValidatorKey( } void -ManifestCache::configManifest(Manifest m, beast::Journal const& journal) +ManifestCache::configManifest ( + Manifest m, UniqueNodeList& unl, beast::Journal const& journal) { if (!m.verify()) { throw std::runtime_error("Unverifiable manifest in config"); } - auto const result = applyManifest (std::move(m), journal); + auto const result = applyManifest (std::move(m), unl, journal); if (result != ManifestDisposition::accepted) { @@ -225,7 +226,8 @@ ManifestCache::canApply (PublicKey const& pk, std::uint32_t seq, ManifestDisposition -ManifestCache::applyManifest (Manifest m, beast::Journal const& journal) +ManifestCache::applyManifest ( + Manifest m, UniqueNodeList& unl, beast::Journal const& journal) { { std::lock_guard lock (mutex_); @@ -253,8 +255,6 @@ ManifestCache::applyManifest (Manifest m, beast::Journal const& journal) return ManifestDisposition::invalid; } - auto& unl = getApp().getUNL(); - std::lock_guard lock (mutex_); /* @@ -334,7 +334,7 @@ ManifestCache::applyManifest (Manifest m, beast::Journal const& journal) } void ManifestCache::load ( - DatabaseCon& dbCon, beast::Journal const& journal) + DatabaseCon& dbCon, UniqueNodeList& unl, beast::Journal const& journal) { static const char* const sql = "SELECT RawData FROM ValidatorManifests;"; @@ -358,7 +358,7 @@ void ManifestCache::load ( map_[mo->masterKey]; // OK if not accepted (may have been loaded from the config file) - applyManifest (std::move(*mo), journal); + applyManifest (std::move(*mo), unl, journal); } else { diff --git a/src/ripple/overlay/impl/Manifest.h b/src/ripple/overlay/impl/Manifest.h index 6865a17872..0d342c3b4d 100644 --- a/src/ripple/overlay/impl/Manifest.h +++ b/src/ripple/overlay/impl/Manifest.h @@ -20,6 +20,7 @@ #ifndef RIPPLE_OVERLAY_MANIFEST_H_INCLUDED #define RIPPLE_OVERLAY_MANIFEST_H_INCLUDED +#include #include #include #include @@ -193,14 +194,16 @@ public: ~ManifestCache() = default; void configValidatorKey(std::string const& line, beast::Journal const& journal); - void configManifest(Manifest m, beast::Journal const& journal); + void configManifest (Manifest m, UniqueNodeList& unl, beast::Journal const& journal); void addTrustedKey (PublicKey const& pk, std::string comment); ManifestDisposition - applyManifest (Manifest m, beast::Journal const& journal); + applyManifest ( + Manifest m, UniqueNodeList& unl, beast::Journal const& journal); - void load (DatabaseCon& dbCon, beast::Journal const& journal); + void load ( + DatabaseCon& dbCon, UniqueNodeList& unl, beast::Journal const& journal); void save (DatabaseCon& dbCon) const; // A "for_each" for populated manifests only diff --git a/src/ripple/overlay/impl/OverlayImpl.cpp b/src/ripple/overlay/impl/OverlayImpl.cpp index 857b972e68..052077f1b4 100644 --- a/src/ripple/overlay/impl/OverlayImpl.cpp +++ b/src/ripple/overlay/impl/OverlayImpl.cpp @@ -459,7 +459,7 @@ OverlayImpl::setupValidatorKeyManifests (BasicConfig const& config, s = beast::base64_decode(s); if (auto mo = make_Manifest (std::move (s))) { - manifestCache_.configManifest (std::move (*mo), journal_); + manifestCache_.configManifest (std::move (*mo), app_.getUNL (), journal_); } else { @@ -472,7 +472,7 @@ OverlayImpl::setupValidatorKeyManifests (BasicConfig const& config, journal_.warning << "No [validation_manifest] section in config"; } - manifestCache_.load (db, journal_); + manifestCache_.load (db, app_.getUNL(), journal_); } void @@ -657,7 +657,7 @@ OverlayImpl::onManifests ( auto const serialized = mo->serialized; auto const result = - manifestCache_.applyManifest (std::move(*mo), journal); + manifestCache_.applyManifest (std::move(*mo), app_.getUNL(), journal); if (result == ManifestDisposition::accepted) { diff --git a/src/ripple/overlay/impl/PeerImp.cpp b/src/ripple/overlay/impl/PeerImp.cpp index fca468fdbf..b0a4b5ade0 100644 --- a/src/ripple/overlay/impl/PeerImp.cpp +++ b/src/ripple/overlay/impl/PeerImp.cpp @@ -1737,7 +1737,7 @@ PeerImp::checkTransaction (int flags, STTx::pointer stx) std::string reason; auto tx = std::make_shared (stx, validate, directSigVerify, - reason); + reason, app_); if (tx->getStatus () == INVALID) { diff --git a/src/ripple/overlay/tests/manifest_test.cpp b/src/ripple/overlay/tests/manifest_test.cpp index 72d61ff2ed..827f7d172a 100644 --- a/src/ripple/overlay/tests/manifest_test.cpp +++ b/src/ripple/overlay/tests/manifest_test.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -121,7 +122,7 @@ public: return Manifest (m.serialized, m.masterKey, m.signingKey, m.sequence); } - void testLoadStore (ManifestCache const& m) + void testLoadStore (ManifestCache const& m, UniqueNodeList& unl) { testcase ("load/store"); @@ -137,7 +138,7 @@ public: ManifestCache loaded; beast::Journal journal; - loaded.load (dbCon, journal); + loaded.load (dbCon, unl, journal); auto getPopulatedManifests = [](ManifestCache const& cache) -> std::vector @@ -183,6 +184,8 @@ public: run() override { ManifestCache cache; + test::jtx::Env env(*this); + auto& unl = env.app().getUNL(); { testcase ("apply"); auto const accepted = ManifestDisposition::accepted; @@ -207,26 +210,26 @@ public: make_Manifest (KeyType::ed25519, sk_b, kp_b.first, 2, true); // broken auto const fake = s_b1.serialized + '\0'; - expect (cache.applyManifest (clone (s_a0), journal) == untrusted, + expect (cache.applyManifest (clone (s_a0), unl, journal) == untrusted, "have to install a trusted key first"); cache.addTrustedKey (pk_a, "a"); cache.addTrustedKey (pk_b, "b"); - expect (cache.applyManifest (clone (s_a0), journal) == accepted); - expect (cache.applyManifest (clone (s_a0), journal) == stale); + expect (cache.applyManifest (clone (s_a0), unl, journal) == accepted); + expect (cache.applyManifest (clone (s_a0), unl, journal) == stale); - expect (cache.applyManifest (clone (s_a1), journal) == accepted); - expect (cache.applyManifest (clone (s_a1), journal) == stale); - expect (cache.applyManifest (clone (s_a0), journal) == stale); + expect (cache.applyManifest (clone (s_a1), unl, journal) == accepted); + expect (cache.applyManifest (clone (s_a1), unl, journal) == stale); + expect (cache.applyManifest (clone (s_a0), unl, journal) == stale); - expect (cache.applyManifest (clone (s_b0), journal) == accepted); - expect (cache.applyManifest (clone (s_b0), journal) == stale); + expect (cache.applyManifest (clone (s_b0), unl, journal) == accepted); + expect (cache.applyManifest (clone (s_b0), unl, journal) == stale); expect (!ripple::make_Manifest(fake)); - expect (cache.applyManifest (clone (s_b2), journal) == invalid); + expect (cache.applyManifest (clone (s_b2), unl, journal) == invalid); } - testLoadStore (cache); + testLoadStore (cache, unl); } }; diff --git a/src/ripple/rpc/Context.h b/src/ripple/rpc/Context.h index 1fcd251a52..d8c34fa150 100644 --- a/src/ripple/rpc/Context.h +++ b/src/ripple/rpc/Context.h @@ -43,8 +43,8 @@ struct Context NetworkOPs& netOps; LedgerMaster& ledgerMaster; Role role; - InfoSub::pointer infoSub; JobQueueSuspender suspend; + InfoSub::pointer infoSub; NodeStore::ScopedMetrics metrics; }; diff --git a/src/ripple/rpc/RipplePathFind.h b/src/ripple/rpc/RipplePathFind.h index 9f230f2b41..00fc4fc88f 100644 --- a/src/ripple/rpc/RipplePathFind.h +++ b/src/ripple/rpc/RipplePathFind.h @@ -32,7 +32,7 @@ ripplePathFind (RippleLineCache::pointer const& cache, Json::Value const& jvSrcCurrencies, boost::optional const& contextPaths, int const& level, boost::optional saSendMax, - bool convert_all); + bool convert_all, Application& app); } diff --git a/src/ripple/rpc/Yield.h b/src/ripple/rpc/Yield.h index 7c61691bac..1b507806ca 100644 --- a/src/ripple/rpc/Yield.h +++ b/src/ripple/rpc/Yield.h @@ -28,6 +28,7 @@ namespace ripple { +class Application; class BasicConfig; class JobQueue; class Section; @@ -119,13 +120,13 @@ struct JobQueueSuspender /** Create a JobQueueSuspender where yield does nothing and the suspend immediately executes the continuation. */ - JobQueueSuspender(); + JobQueueSuspender(Application&); /** Create a JobQueueSuspender with a Suspend. When yield is called, it reschedules the current job on the JobQueue with the given jobName. */ - JobQueueSuspender(Suspend const&, std::string const& jobName); + JobQueueSuspender(Application&, Suspend const&, std::string const& jobName); }; } // RPC diff --git a/src/ripple/rpc/handlers/RipplePathFind.cpp b/src/ripple/rpc/handlers/RipplePathFind.cpp index bf2b982ff5..8e9db44366 100644 --- a/src/ripple/rpc/handlers/RipplePathFind.cpp +++ b/src/ripple/rpc/handlers/RipplePathFind.cpp @@ -69,7 +69,7 @@ buildSrcCurrencies(AccountID const& account, // This interface is deprecated. Json::Value doRipplePathFind (RPC::Context& context) { - RPC::LegacyPathFind lpf (context.role == Role::ADMIN); + RPC::LegacyPathFind lpf (context.role == Role::ADMIN, context.app); if (!lpf.isOk ()) return rpcError (rpcTOO_BUSY); @@ -244,7 +244,8 @@ Json::Value doRipplePathFind (RPC::Context& context) boost::optional(context.params[jss::paths]) : boost::optional(boost::none); auto pathFindResult = ripplePathFind(cache, raSrc, raDst, saDstAmount, - jvSrcCurrencies, contextPaths, level, saSendMax, convert_all); + jvSrcCurrencies, contextPaths, level, saSendMax, convert_all, + context.app); if (!pathFindResult.first) return pathFindResult.second; @@ -264,7 +265,7 @@ ripplePathFind (RippleLineCache::pointer const& cache, STAmount const& saDstAmount, Json::Value const& jvSrcCurrencies, boost::optional const& contextPaths, int const& level, boost::optional saSendMax, - bool convert_all) + bool convert_all, Application& app) { auto const sa = STAmount(saDstAmount.issue(), STAmount::cMaxValue, STAmount::cMaxOffset); @@ -356,7 +357,8 @@ ripplePathFind (RippleLineCache::pointer const& cache, auto result = fp.findPathsForIssue( issue, spsComputed, - fullLiquidityPath); + fullLiquidityPath, + app); if (! result) { WriteLog(lsWARNING, RPCHandler) diff --git a/src/ripple/rpc/handlers/SignFor.cpp b/src/ripple/rpc/handlers/SignFor.cpp index 68cf9ae6d1..046e43a840 100755 --- a/src/ripple/rpc/handlers/SignFor.cpp +++ b/src/ripple/rpc/handlers/SignFor.cpp @@ -50,7 +50,7 @@ Json::Value doSignFor (RPC::Context& context) failType, context.role, context.ledgerMaster.getValidatedLedgerAge(), - context.app.getFeeTrack(), + context.app, context.ledgerMaster.getCurrentLedger()); } diff --git a/src/ripple/rpc/handlers/SignHandler.cpp b/src/ripple/rpc/handlers/SignHandler.cpp index dfe6375629..1b77895b35 100644 --- a/src/ripple/rpc/handlers/SignHandler.cpp +++ b/src/ripple/rpc/handlers/SignHandler.cpp @@ -43,7 +43,7 @@ Json::Value doSign (RPC::Context& context) failType, context.role, context.ledgerMaster.getValidatedLedgerAge(), - context.app.getFeeTrack(), + context.app, context.ledgerMaster.getCurrentLedger()); } diff --git a/src/ripple/rpc/handlers/Submit.cpp b/src/ripple/rpc/handlers/Submit.cpp index 556aeea0e0..ccbf29a219 100644 --- a/src/ripple/rpc/handlers/Submit.cpp +++ b/src/ripple/rpc/handlers/Submit.cpp @@ -52,7 +52,7 @@ Json::Value doSubmit (RPC::Context& context) failType, context.role, context.ledgerMaster.getValidatedLedgerAge(), - context.app.getFeeTrack(), + context.app, context.ledgerMaster.getCurrentLedger(), RPC::getProcessTxnFn (context.netOps)); } @@ -83,7 +83,7 @@ Json::Value doSubmit (RPC::Context& context) Transaction::pointer tpTrans; std::string reason; tpTrans = std::make_shared (stpTrans, Validate::YES, - context.app.getHashRouter().sigVerify(), reason); + context.app.getHashRouter().sigVerify(), reason, context.app); if (tpTrans->getStatus() != NEW) { jvResult[jss::error] = "invalidTransaction"; diff --git a/src/ripple/rpc/handlers/SubmitMultiSigned.cpp b/src/ripple/rpc/handlers/SubmitMultiSigned.cpp index 7e45b7c47e..1d75abe8ab 100644 --- a/src/ripple/rpc/handlers/SubmitMultiSigned.cpp +++ b/src/ripple/rpc/handlers/SubmitMultiSigned.cpp @@ -49,7 +49,7 @@ Json::Value doSubmitMultiSigned (RPC::Context& context) failType, context.role, context.ledgerMaster.getValidatedLedgerAge(), - context.app.getFeeTrack(), + context.app, context.ledgerMaster.getCurrentLedger(), RPC::getProcessTxnFn (context.netOps)); } diff --git a/src/ripple/rpc/handlers/TxHistory.cpp b/src/ripple/rpc/handlers/TxHistory.cpp index fa3f1030a4..6b9fc4ce5e 100644 --- a/src/ripple/rpc/handlers/TxHistory.cpp +++ b/src/ripple/rpc/handlers/TxHistory.cpp @@ -81,7 +81,7 @@ Json::Value doTxHistory (RPC::Context& context) rawTxn.clear (); if (auto trans = Transaction::transactionFromSQL ( - ledgerSeq, status, rawTxn, Validate::NO)) + ledgerSeq, status, rawTxn, Validate::NO, context.app)) txs.append (trans->getJson (0)); } } diff --git a/src/ripple/rpc/impl/LegacyPathFind.cpp b/src/ripple/rpc/impl/LegacyPathFind.cpp index dff78ec4cb..d63f3a4350 100644 --- a/src/ripple/rpc/impl/LegacyPathFind.cpp +++ b/src/ripple/rpc/impl/LegacyPathFind.cpp @@ -28,7 +28,7 @@ namespace ripple { namespace RPC { -LegacyPathFind::LegacyPathFind (bool isAdmin) : m_isOk (false) +LegacyPathFind::LegacyPathFind (bool isAdmin, Application& app) : m_isOk (false) { if (isAdmin) { @@ -37,8 +37,8 @@ LegacyPathFind::LegacyPathFind (bool isAdmin) : m_isOk (false) return; } - auto const& jobCount = getApp().getJobQueue ().getJobCountGE (jtCLIENT); - if (jobCount > Tuning::maxPathfindJobCount || getApp().getFeeTrack().isLoadedLocal ()) + auto const& jobCount = app.getJobQueue ().getJobCountGE (jtCLIENT); + if (jobCount > Tuning::maxPathfindJobCount || app.getFeeTrack().isLoadedLocal ()) return; while (true) diff --git a/src/ripple/rpc/impl/LegacyPathFind.h b/src/ripple/rpc/impl/LegacyPathFind.h index 68adbd7e86..d670cb563c 100644 --- a/src/ripple/rpc/impl/LegacyPathFind.h +++ b/src/ripple/rpc/impl/LegacyPathFind.h @@ -23,12 +23,15 @@ #include namespace ripple { + +class Application; + namespace RPC { class LegacyPathFind { public: - LegacyPathFind (bool isAdmin); + LegacyPathFind (bool isAdmin, Application& app); ~LegacyPathFind (); bool isOk () const diff --git a/src/ripple/rpc/impl/LookupLedger.cpp b/src/ripple/rpc/impl/LookupLedger.cpp index 68330ddb63..f1d9d9435c 100644 --- a/src/ripple/rpc/impl/LookupLedger.cpp +++ b/src/ripple/rpc/impl/LookupLedger.cpp @@ -137,7 +137,8 @@ Status ledgerFromRequest (T& ledger, Context& context) return Status::OK; } -bool isValidated (LedgerMaster& ledgerMaster, ReadView const& ledger) +bool isValidated (LedgerMaster& ledgerMaster, ReadView const& ledger, + Application& app) { if (ledger.info().validated) return true; @@ -158,7 +159,7 @@ bool isValidated (LedgerMaster& ledgerMaster, ReadView const& ledger) // This ledger's hash is not the hash of the validated ledger if (hash.isNonZero ()) { - uint256 valHash = Ledger::getHashByIndex (seq); + uint256 valHash = getHashByIndex (seq, app); if (valHash == ledger.info().hash) { // SQL database doesn't match ledger chain @@ -220,7 +221,7 @@ Status lookupLedger ( result[jss::ledger_current_index] = info.seq; } - result[jss::validated] = isValidated (context.ledgerMaster, *ledger); + result[jss::validated] = isValidated (context.ledgerMaster, *ledger, context.app); return Status::OK; } diff --git a/src/ripple/rpc/impl/TransactionSign.cpp b/src/ripple/rpc/impl/TransactionSign.cpp index c7dea5b7e1..072dbd20e6 100644 --- a/src/ripple/rpc/impl/TransactionSign.cpp +++ b/src/ripple/rpc/impl/TransactionSign.cpp @@ -135,6 +135,7 @@ static Json::Value checkPayment( Json::Value& tx_json, AccountID const& srcAddressID, Role const role, + Application& app, std::shared_ptr& ledger, bool doPath) { @@ -187,7 +188,7 @@ static Json::Value checkPayment( "Cannot build XRP to XRP paths."); { - LegacyPathFind lpf (role == Role::ADMIN); + LegacyPathFind lpf (role == Role::ADMIN, app); if (!lpf.isOk ()) return rpcError (rpcTOO_BUSY); @@ -202,7 +203,8 @@ static Json::Value checkPayment( getConfig().PATH_SEARCH_OLD, 4, // iMaxPaths {}, - fullLiquidityPath); + fullLiquidityPath, + app); if (! result) { @@ -329,7 +331,7 @@ transactionPreProcessImpl ( Role role, SigningForParams& signingArgs, int validatedLedgerAge, - LoadFeeTrack const& feeTrack, + Application& app, std::shared_ptr ledger) { KeyPair keypair; @@ -349,8 +351,9 @@ transactionPreProcessImpl ( Json::Value& tx_json (params [jss::tx_json]); // Check tx_json fields, but don't add any. - auto txJsonResult = - checkTxJsonFields (tx_json, role, verify, validatedLedgerAge, feeTrack); + auto txJsonResult = checkTxJsonFields ( + tx_json, role, verify, validatedLedgerAge, app.getFeeTrack()); + if (RPC::contains_error (txJsonResult.first)) return std::move (txJsonResult.first); @@ -381,7 +384,7 @@ transactionPreProcessImpl ( params, role, signingArgs.editFields(), - feeTrack, + app.getFeeTrack(), ledger); if (RPC::contains_error (err)) @@ -392,6 +395,7 @@ transactionPreProcessImpl ( tx_json, srcAddressID, role, + app, ledger, signingArgs.editFields()); @@ -498,7 +502,7 @@ transactionPreProcessImpl ( static std::pair -transactionConstructImpl (STTx::pointer stpTrans) +transactionConstructImpl (STTx::pointer stpTrans, Application& app) { std::pair ret; @@ -507,7 +511,7 @@ transactionConstructImpl (STTx::pointer stpTrans) { std::string reason; tpTrans = std::make_shared(stpTrans, Validate::NO, - directSigVerify, reason); + directSigVerify, reason, app); if (tpTrans->getStatus () != NEW) { ret.first = RPC::make_error (rpcINTERNAL, @@ -526,7 +530,7 @@ transactionConstructImpl (STTx::pointer stpTrans) tpTrans->getSTransaction ()->add (s); Transaction::pointer tpTransNew = - Transaction::sharedTransaction (s.getData (), Validate::YES); + Transaction::sharedTransaction(s.getData(), Validate::YES, app); if (tpTransNew && ( !tpTransNew->getSTransaction ()->isEquivalent ( @@ -645,7 +649,7 @@ Json::Value transactionSign ( NetworkOPs::FailHard failType, Role role, int validatedLedgerAge, - LoadFeeTrack const& feeTrack, + Application& app, std::shared_ptr ledger) { WriteLog (lsDEBUG, RPCHandler) << "transactionSign: " << jvRequest; @@ -655,14 +659,15 @@ Json::Value transactionSign ( // Add and amend fields based on the transaction type. SigningForParams signForParams; transactionPreProcessResult preprocResult = transactionPreProcessImpl ( - jvRequest, role, signForParams, validatedLedgerAge, feeTrack, ledger); + jvRequest, role, signForParams, + validatedLedgerAge, app, ledger); if (!preprocResult.second) return preprocResult.first; // Make sure the STTx makes a legitimate Transaction. std::pair txn = - transactionConstructImpl (preprocResult.second); + transactionConstructImpl (preprocResult.second, app); if (!txn.second) return txn.first; @@ -676,7 +681,7 @@ Json::Value transactionSubmit ( NetworkOPs::FailHard failType, Role role, int validatedLedgerAge, - LoadFeeTrack const& feeTrack, + Application& app, std::shared_ptr ledger, ProcessTransactionFn const& processTransaction) { @@ -687,14 +692,14 @@ Json::Value transactionSubmit ( // Add and amend fields based on the transaction type. SigningForParams signForParams; transactionPreProcessResult preprocResult = transactionPreProcessImpl ( - jvRequest, role, signForParams, validatedLedgerAge, feeTrack, ledger); + jvRequest, role, signForParams, validatedLedgerAge, app, ledger); if (!preprocResult.second) return preprocResult.first; // Make sure the STTx makes a legitimate Transaction. std::pair txn = - transactionConstructImpl (preprocResult.second); + transactionConstructImpl (preprocResult.second, app); if (!txn.second) return txn.first; @@ -750,7 +755,7 @@ Json::Value transactionSignFor ( NetworkOPs::FailHard failType, Role role, int validatedLedgerAge, - LoadFeeTrack const& feeTrack, + Application& app, std::shared_ptr ledger) { WriteLog (lsDEBUG, RPCHandler) << "transactionSignFor: " << jvRequest; @@ -790,7 +795,7 @@ Json::Value transactionSignFor ( role, signForParams, validatedLedgerAge, - feeTrack, + app, ledger); if (!preprocResult.second) @@ -811,7 +816,7 @@ Json::Value transactionSignFor ( // Make sure the STTx makes a legitimate Transaction. std::pair txn = - transactionConstructImpl (preprocResult.second); + transactionConstructImpl (preprocResult.second, app); if (!txn.second) return txn.first; @@ -850,7 +855,7 @@ Json::Value transactionSubmitMultiSigned ( NetworkOPs::FailHard failType, Role role, int validatedLedgerAge, - LoadFeeTrack const& feeTrack, + Application& app, std::shared_ptr ledger, ProcessTransactionFn const& processTransaction) { @@ -868,8 +873,9 @@ Json::Value transactionSubmitMultiSigned ( Json::Value& tx_json (jvRequest ["tx_json"]); - auto const txJsonResult = - checkTxJsonFields (tx_json, role, true, validatedLedgerAge, feeTrack); + auto const txJsonResult = checkTxJsonFields ( + tx_json, role, true, validatedLedgerAge, app.getFeeTrack()); + if (RPC::contains_error (txJsonResult.first)) return std::move (txJsonResult.first); @@ -890,7 +896,8 @@ Json::Value transactionSubmitMultiSigned ( } { - Json::Value err = checkFee (jvRequest, role, false, feeTrack, ledger); + Json::Value err = checkFee ( + jvRequest, role, false, app.getFeeTrack(), ledger); if (RPC::contains_error(err)) return std::move (err); @@ -900,6 +907,7 @@ Json::Value transactionSubmitMultiSigned ( tx_json, srcAddressID, role, + app, ledger, false); @@ -1045,7 +1053,7 @@ Json::Value transactionSubmitMultiSigned ( // Make sure the SerializedTransaction makes a legitimate Transaction. std::pair txn = - transactionConstructImpl (stpTrans); + transactionConstructImpl (stpTrans, app); if (!txn.second) return txn.first; diff --git a/src/ripple/rpc/impl/TransactionSign.h b/src/ripple/rpc/impl/TransactionSign.h index a7fa931ea9..9ffae811a2 100644 --- a/src/ripple/rpc/impl/TransactionSign.h +++ b/src/ripple/rpc/impl/TransactionSign.h @@ -26,6 +26,7 @@ namespace ripple { // Forward declarations +class Application; class LoadFeeTrack; namespace RPC { @@ -78,7 +79,7 @@ Json::Value transactionSign ( NetworkOPs::FailHard failType, Role role, int validatedLedgerAge, - LoadFeeTrack const& feeTrack, + Application& app, std::shared_ptr ledger); /** Returns a Json::objectValue. */ @@ -87,7 +88,7 @@ Json::Value transactionSubmit ( NetworkOPs::FailHard failType, Role role, int validatedLedgerAge, - LoadFeeTrack const& feeTrack, + Application& app, std::shared_ptr ledger, ProcessTransactionFn const& processTransaction); @@ -97,7 +98,7 @@ Json::Value transactionSignFor ( NetworkOPs::FailHard failType, Role role, int validatedLedgerAge, - LoadFeeTrack const& feeTrack, + Application& app, std::shared_ptr ledger); /** Returns a Json::objectValue. */ @@ -106,7 +107,7 @@ Json::Value transactionSubmitMultiSigned ( NetworkOPs::FailHard failType, Role role, int validatedLedgerAge, - LoadFeeTrack const& feeTrack, + Application& app, std::shared_ptr ledger, ProcessTransactionFn const& processTransaction); diff --git a/src/ripple/rpc/impl/Yield.cpp b/src/ripple/rpc/impl/Yield.cpp index 9bf55794c0..6f62510966 100644 --- a/src/ripple/rpc/impl/Yield.cpp +++ b/src/ripple/rpc/impl/Yield.cpp @@ -36,18 +36,20 @@ Suspend const dontSuspend = [] (Continuation const& continuation) namespace { -void runOnJobQueue(std::string const& name, Callback const& callback) +void runOnJobQueue( + Application& app, std::string const& name, Callback const& callback) { auto cb = [callback] (Job&) { callback(); }; - getApp().getJobQueue().addJob(jtCLIENT, name, cb); + app.getJobQueue().addJob(jtCLIENT, name, cb); }; -Callback suspendForJobQueue(Suspend const& suspend, std::string const& jobName) +Callback suspendForJobQueue( + Application& app, Suspend const& suspend, std::string const& jobName) { assert(suspend); - return Callback( [suspend, jobName] () { - suspend([jobName] (Callback const& callback) { - runOnJobQueue(jobName, callback); + return Callback( [suspend, jobName, &app] () { + suspend([jobName, &app] (Callback const& callback) { + runOnJobQueue(app, jobName, callback); }); }); } @@ -112,15 +114,16 @@ YieldStrategy makeYieldStrategy (BasicConfig const& config) } JobQueueSuspender::JobQueueSuspender( - Suspend const& susp, std::string const& jobName) + Application& app, Suspend const& susp, std::string const& jobName) : suspend(susp ? susp : dontSuspend), - yield(suspendForJobQueue(suspend, jobName)) + yield(suspendForJobQueue(app, suspend, jobName)) { // There's a non-empty jobName exactly if there's a non-empty Suspend. assert(!(susp && jobName.empty())); } -JobQueueSuspender::JobQueueSuspender() : JobQueueSuspender({}, {}) +JobQueueSuspender::JobQueueSuspender(Application &app) + : JobQueueSuspender(app, {}, {}) { } diff --git a/src/ripple/rpc/tests/JSONRPC.test.cpp b/src/ripple/rpc/tests/JSONRPC.test.cpp index a6db5d7285..327a9ea25b 100644 --- a/src/ripple/rpc/tests/JSONRPC.test.cpp +++ b/src/ripple/rpc/tests/JSONRPC.test.cpp @@ -1396,9 +1396,10 @@ class JSONRPC_test : public beast::unit_test::suite public: void testAutoFillFees () { + test::jtx::Env env(*this); Config const config; std::shared_ptr ledger = - std::make_shared(create_genesis, config); + std::make_shared(create_genesis, config, env.app().family()); LoadFeeTrack const feeTrack; { @@ -1451,8 +1452,6 @@ public: auto const ledger = env.open(); - LoadFeeTrack const feeTrack; - ProcessTransactionFn processTxn = fakeProcessTransaction; // A list of all the functions we want to test. @@ -1461,7 +1460,7 @@ public: NetworkOPs::FailHard failType, Role role, int validatedLedgerAge, - LoadFeeTrack const& feeTrack, + Application& app, std::shared_ptr ledger); using submitFunc = Json::Value (*) ( @@ -1469,7 +1468,7 @@ public: NetworkOPs::FailHard failType, Role role, int validatedLedgerAge, - LoadFeeTrack const& feeTrack, + Application& app, std::shared_ptr ledger, ProcessTransactionFn const& processTransaction); @@ -1510,7 +1509,7 @@ public: NetworkOPs::FailHard::yes, testRole, 1, - feeTrack, + env.app(), ledger); } else @@ -1522,7 +1521,7 @@ public: NetworkOPs::FailHard::yes, testRole, 1, - feeTrack, + env.app(), ledger, processTxn); } diff --git a/src/ripple/server/impl/ServerHandlerImp.cpp b/src/ripple/server/impl/ServerHandlerImp.cpp index 8993ad1203..b1c4cf60bb 100644 --- a/src/ripple/server/impl/ServerHandlerImp.cpp +++ b/src/ripple/server/impl/ServerHandlerImp.cpp @@ -352,7 +352,7 @@ ServerHandlerImp::processRequest ( RPC::Context context { params, app_, loadType, m_networkOPs, app_.getLedgerMaster(), role, - nullptr, {suspend, "RPC-Coroutine"}}; + {app_, suspend, "RPC-Coroutine"}}; std::string response; diff --git a/src/ripple/shamap/Family.h b/src/ripple/shamap/Family.h index ee1a55a4bc..354ee0c0ac 100644 --- a/src/ripple/shamap/Family.h +++ b/src/ripple/shamap/Family.h @@ -26,7 +26,6 @@ #include namespace ripple { -namespace shamap { class Family { @@ -60,9 +59,12 @@ public: virtual void missing_node (std::uint32_t refNum) = 0; + + virtual + void + missing_node (uint256 const& hash) = 0; }; -} // shamap } // ripple #endif diff --git a/src/ripple/shamap/SHAMap.h b/src/ripple/shamap/SHAMap.h index ba469fa593..09e8796b9c 100644 --- a/src/ripple/shamap/SHAMap.h +++ b/src/ripple/shamap/SHAMap.h @@ -79,7 +79,6 @@ using MissingNodeHandler = std::function ; class SHAMap { private: - using Family = shamap::Family; using NodeStack = std::stack, std::vector>>; @@ -115,6 +114,12 @@ public: Family& f, beast::Journal journal); + Family& + family() + { + return f_; + } + //-------------------------------------------------------------------------- /** Iterator to a SHAMap's leaves diff --git a/src/ripple/shamap/tests/FetchPack.test.cpp b/src/ripple/shamap/tests/FetchPack.test.cpp index 4ec25dc530..3096d67ab1 100644 --- a/src/ripple/shamap/tests/FetchPack.test.cpp +++ b/src/ripple/shamap/tests/FetchPack.test.cpp @@ -30,7 +30,6 @@ #include namespace ripple { -namespace shamap { namespace tests { class FetchPack_test : public beast::unit_test::suite @@ -164,6 +163,5 @@ public: BEAST_DEFINE_TESTSUITE(FetchPack,shamap,ripple); } // tests -} // shamap } // ripple diff --git a/src/ripple/shamap/tests/SHAMap.test.cpp b/src/ripple/shamap/tests/SHAMap.test.cpp index a35eeaefd7..18557ad4e9 100644 --- a/src/ripple/shamap/tests/SHAMap.test.cpp +++ b/src/ripple/shamap/tests/SHAMap.test.cpp @@ -26,7 +26,6 @@ #include namespace ripple { -namespace shamap { namespace tests { inline bool operator== (SHAMapItem const& a, SHAMapItem const& b) { return a.key() == b.key(); } @@ -141,5 +140,4 @@ public: BEAST_DEFINE_TESTSUITE(SHAMap,ripple_app,ripple); } // tests -} // shamap } // ripple diff --git a/src/ripple/shamap/tests/SHAMapSync.test.cpp b/src/ripple/shamap/tests/SHAMapSync.test.cpp index f79213dcc8..fe712e23e9 100644 --- a/src/ripple/shamap/tests/SHAMapSync.test.cpp +++ b/src/ripple/shamap/tests/SHAMapSync.test.cpp @@ -27,7 +27,6 @@ #include // DEPRECATED namespace ripple { -namespace shamap { namespace tests { #ifdef BEAST_DEBUG @@ -227,5 +226,4 @@ public: BEAST_DEFINE_TESTSUITE(sync,shamap,ripple); } // tests -} // shamap } // ripple diff --git a/src/ripple/shamap/tests/common.h b/src/ripple/shamap/tests/common.h index f0211a30a7..8e48b35d6b 100644 --- a/src/ripple/shamap/tests/common.h +++ b/src/ripple/shamap/tests/common.h @@ -33,10 +33,9 @@ #include namespace ripple { -namespace shamap { namespace tests { -class TestFamily : public shamap::Family +class TestFamily : public Family { private: TestStopwatch clock_; @@ -105,10 +104,15 @@ public: { throw std::runtime_error("missing node"); } + + void + missing_node (uint256 const& hash) override + { + throw std::runtime_error("missing node"); + } }; } // tests -} // shamap } // ripple #endif diff --git a/src/ripple/test/jtx/Env.h b/src/ripple/test/jtx/Env.h index e3f97e7244..4362310ee5 100644 --- a/src/ripple/test/jtx/Env.h +++ b/src/ripple/test/jtx/Env.h @@ -318,7 +318,7 @@ public: */ template void - require (Args const&... args) const + require (Args const&... args) { jtx::required(args...)(*this); } diff --git a/src/ripple/test/jtx/balance.h b/src/ripple/test/jtx/balance.h index afea5a1eac..37457b98ac 100644 --- a/src/ripple/test/jtx/balance.h +++ b/src/ripple/test/jtx/balance.h @@ -68,7 +68,7 @@ public: } void - operator()(Env const&) const; + operator()(Env&) const; }; } // jtx diff --git a/src/ripple/test/jtx/delivermin.h b/src/ripple/test/jtx/delivermin.h index 152281927c..7b2d609a21 100644 --- a/src/ripple/test/jtx/delivermin.h +++ b/src/ripple/test/jtx/delivermin.h @@ -40,7 +40,7 @@ public: } void - operator()(Env const&, JTx& jtx) const; + operator()(Env&, JTx& jtx) const; }; } // jtx diff --git a/src/ripple/test/jtx/fee.h b/src/ripple/test/jtx/fee.h index 890227a0f1..1dcd63f463 100644 --- a/src/ripple/test/jtx/fee.h +++ b/src/ripple/test/jtx/fee.h @@ -58,7 +58,7 @@ public: } void - operator()(Env const&, JTx& jt) const; + operator()(Env&, JTx& jt) const; }; } // jtx diff --git a/src/ripple/test/jtx/flags.h b/src/ripple/test/jtx/flags.h index 1a1ea1fb52..907e40b0c8 100644 --- a/src/ripple/test/jtx/flags.h +++ b/src/ripple/test/jtx/flags.h @@ -113,7 +113,7 @@ public: } void - operator()(Env const& env) const; + operator()(Env& env) const; }; /** Match clear account flags */ @@ -132,7 +132,7 @@ public: } void - operator()(Env const& env) const; + operator()(Env& env) const; }; } // jtx diff --git a/src/ripple/test/jtx/impl/Env.cpp b/src/ripple/test/jtx/impl/Env.cpp index 6e38c2c231..dffecd3a1d 100644 --- a/src/ripple/test/jtx/impl/Env.cpp +++ b/src/ripple/test/jtx/impl/Env.cpp @@ -57,7 +57,7 @@ Env::Env (beast::unit_test::suite& test_) KeyType::secp256k1, generateSeed("masterpassphrase"))) , closed_ (std::make_shared( - create_genesis, config)) + create_genesis, config, app().family())) , cachedSLEs_ (std::chrono::seconds(5), stopwatch_) , openLedger (closed_, config, cachedSLEs_, journal) { @@ -83,7 +83,8 @@ Env::close(NetClock::time_point const& closeTime) clock.set(closeTime); // VFALCO TODO Fix the Ledger constructor auto next = std::make_shared( - open_ledger, *closed_); + open_ledger, *closed_, + app().timeKeeper().closeTime()); next->setClosed(); #if 0 // Build a SHAMap, put all the transactions diff --git a/src/ripple/test/jtx/impl/balance.cpp b/src/ripple/test/jtx/impl/balance.cpp index ae8eab7eb1..b4c06a4768 100644 --- a/src/ripple/test/jtx/impl/balance.cpp +++ b/src/ripple/test/jtx/impl/balance.cpp @@ -25,7 +25,7 @@ namespace test { namespace jtx { void -balance::operator()(Env const& env) const +balance::operator()(Env& env) const { if (isXRP(value_.issue())) { diff --git a/src/ripple/test/jtx/impl/delivermin.cpp b/src/ripple/test/jtx/impl/delivermin.cpp index 1d105037bb..bbcb46cb56 100644 --- a/src/ripple/test/jtx/impl/delivermin.cpp +++ b/src/ripple/test/jtx/impl/delivermin.cpp @@ -26,7 +26,7 @@ namespace test { namespace jtx { void -delivermin::operator()(Env const& env, JTx& jt) const +delivermin::operator()(Env& env, JTx& jt) const { jt.jv[jss::DeliverMin] = amount_.getJson(0); } diff --git a/src/ripple/test/jtx/impl/fee.cpp b/src/ripple/test/jtx/impl/fee.cpp index 219745c8a7..f83da00724 100644 --- a/src/ripple/test/jtx/impl/fee.cpp +++ b/src/ripple/test/jtx/impl/fee.cpp @@ -26,7 +26,7 @@ namespace test { namespace jtx { void -fee::operator()(Env const&, JTx& jt) const +fee::operator()(Env&, JTx& jt) const { if (! manual_) return; diff --git a/src/ripple/test/jtx/impl/flags.cpp b/src/ripple/test/jtx/impl/flags.cpp index 9ebe5fe872..941ec6db05 100644 --- a/src/ripple/test/jtx/impl/flags.cpp +++ b/src/ripple/test/jtx/impl/flags.cpp @@ -40,7 +40,7 @@ fset (Account const& account, } void -flags::operator()(Env const& env) const +flags::operator()(Env& env) const { auto const sle = env.le(account_); if (sle->isFieldPresent(sfFlags)) @@ -51,7 +51,7 @@ flags::operator()(Env const& env) const } void -nflags::operator()(Env const& env) const +nflags::operator()(Env& env) const { auto const sle = env.le(account_); if (sle->isFieldPresent(sfFlags)) diff --git a/src/ripple/test/jtx/impl/jtx_json.cpp b/src/ripple/test/jtx/impl/jtx_json.cpp index b3fa2cfb84..879a491cb9 100644 --- a/src/ripple/test/jtx/impl/jtx_json.cpp +++ b/src/ripple/test/jtx/impl/jtx_json.cpp @@ -42,7 +42,7 @@ json::json (Json::Value jv) } void -json::operator()(Env const&, JTx& jt) const +json::operator()(Env&, JTx& jt) const { auto& jv = jt.jv; for (auto iter = jv_.begin(); diff --git a/src/ripple/test/jtx/impl/memo.cpp b/src/ripple/test/jtx/impl/memo.cpp index 0b0e799580..74e6c93b88 100644 --- a/src/ripple/test/jtx/impl/memo.cpp +++ b/src/ripple/test/jtx/impl/memo.cpp @@ -27,7 +27,7 @@ namespace test { namespace jtx { void -memo::operator()(Env const&, JTx& jt) const +memo::operator()(Env&, JTx& jt) const { auto& jv = jt.jv; auto& ma = jv["Memos"]; @@ -39,7 +39,7 @@ memo::operator()(Env const&, JTx& jt) const } void -memodata::operator()(Env const&, JTx& jt) const +memodata::operator()(Env&, JTx& jt) const { auto& jv = jt.jv; auto& ma = jv["Memos"]; @@ -49,7 +49,7 @@ memodata::operator()(Env const&, JTx& jt) const } void -memoformat::operator()(Env const&, JTx& jt) const +memoformat::operator()(Env&, JTx& jt) const { auto& jv = jt.jv; auto& ma = jv["Memos"]; @@ -59,7 +59,7 @@ memoformat::operator()(Env const&, JTx& jt) const } void -memotype::operator()(Env const&, JTx& jt) const +memotype::operator()(Env&, JTx& jt) const { auto& jv = jt.jv; auto& ma = jv["Memos"]; @@ -69,7 +69,7 @@ memotype::operator()(Env const&, JTx& jt) const } void -memondata::operator()(Env const&, JTx& jt) const +memondata::operator()(Env&, JTx& jt) const { auto& jv = jt.jv; auto& ma = jv["Memos"]; @@ -80,7 +80,7 @@ memondata::operator()(Env const&, JTx& jt) const } void -memonformat::operator()(Env const&, JTx& jt) const +memonformat::operator()(Env&, JTx& jt) const { auto& jv = jt.jv; auto& ma = jv["Memos"]; @@ -91,7 +91,7 @@ memonformat::operator()(Env const&, JTx& jt) const } void -memontype::operator()(Env const&, JTx& jt) const +memontype::operator()(Env&, JTx& jt) const { auto& jv = jt.jv; auto& ma = jv["Memos"]; diff --git a/src/ripple/test/jtx/impl/multisign.cpp b/src/ripple/test/jtx/impl/multisign.cpp index 31b161db09..c713d82124 100644 --- a/src/ripple/test/jtx/impl/multisign.cpp +++ b/src/ripple/test/jtx/impl/multisign.cpp @@ -74,7 +74,7 @@ msig::msig (std::vector signers_) } void -msig::operator()(Env const& env, JTx& jt) const +msig::operator()(Env& env, JTx& jt) const { auto const mySigners = signers; jt.signer = [mySigners, &env](Env&, JTx& jt) diff --git a/src/ripple/test/jtx/impl/owners.cpp b/src/ripple/test/jtx/impl/owners.cpp index ff0cf9c3be..b3caed484f 100644 --- a/src/ripple/test/jtx/impl/owners.cpp +++ b/src/ripple/test/jtx/impl/owners.cpp @@ -42,7 +42,7 @@ owned_count_of(ReadView const& view, } void -owned_count_helper(Env const& env, +owned_count_helper(Env& env, AccountID const& id, LedgerEntryType type, std::uint32_t value) @@ -54,7 +54,7 @@ owned_count_helper(Env const& env, } // detail void -owners::operator()(Env const& env) const +owners::operator()(Env& env) const { env.test.expect(env.le( account_)->getFieldU32(sfOwnerCount) == diff --git a/src/ripple/test/jtx/impl/paths.cpp b/src/ripple/test/jtx/impl/paths.cpp index 469e08fbce..466bb4591f 100644 --- a/src/ripple/test/jtx/impl/paths.cpp +++ b/src/ripple/test/jtx/impl/paths.cpp @@ -27,7 +27,7 @@ namespace test { namespace jtx { void -paths::operator()(Env const& env, JTx& jt) const +paths::operator()(Env& env, JTx& jt) const { auto& jv = jt.jv; auto const from = env.lookup( @@ -41,7 +41,7 @@ paths::operator()(Env const& env, JTx& jt) const std::make_shared( env.open()), from, to, in_, amount, - depth_, limit_, {}, fp); + depth_, limit_, {}, fp, env.app()); // VFALCO TODO API to allow caller to examine the STPathSet // VFALCO isDefault should be renamed to empty() if (found && ! found->isDefault()) @@ -80,7 +80,7 @@ path::append_one(BookSpec const& book) } void -path::operator()(Env const& env, JTx& jt) const +path::operator()(Env& env, JTx& jt) const { jt.jv["Paths"].append(jv_); } diff --git a/src/ripple/test/jtx/impl/sendmax.cpp b/src/ripple/test/jtx/impl/sendmax.cpp index ee05435ba8..c680dcaa1f 100644 --- a/src/ripple/test/jtx/impl/sendmax.cpp +++ b/src/ripple/test/jtx/impl/sendmax.cpp @@ -26,7 +26,7 @@ namespace test { namespace jtx { void -sendmax::operator()(Env const& env, JTx& jt) const +sendmax::operator()(Env& env, JTx& jt) const { jt.jv[jss::SendMax] = amount_.getJson(0); } diff --git a/src/ripple/test/jtx/impl/seq.cpp b/src/ripple/test/jtx/impl/seq.cpp index fe198c8067..f5a4f0ec15 100644 --- a/src/ripple/test/jtx/impl/seq.cpp +++ b/src/ripple/test/jtx/impl/seq.cpp @@ -26,7 +26,7 @@ namespace test { namespace jtx { void -seq::operator()(Env const&, JTx& jt) const +seq::operator()(Env&, JTx& jt) const { if (! manual_) return; diff --git a/src/ripple/test/jtx/impl/sig.cpp b/src/ripple/test/jtx/impl/sig.cpp index 7a06aacbe8..c0e5a088f5 100644 --- a/src/ripple/test/jtx/impl/sig.cpp +++ b/src/ripple/test/jtx/impl/sig.cpp @@ -26,7 +26,7 @@ namespace test { namespace jtx { void -sig::operator()(Env const&, JTx& jt) const +sig::operator()(Env&, JTx& jt) const { if (! manual_) return; diff --git a/src/ripple/test/jtx/impl/tag.cpp b/src/ripple/test/jtx/impl/tag.cpp index ee51d0504a..d7260db8ec 100644 --- a/src/ripple/test/jtx/impl/tag.cpp +++ b/src/ripple/test/jtx/impl/tag.cpp @@ -26,13 +26,13 @@ namespace test { namespace jtx { void -dtag::operator()(Env const&, JTx& jt) const +dtag::operator()(Env&, JTx& jt) const { jt.jv["DestinationTag"] = value_; } void -stag::operator()(Env const&, JTx& jt) const +stag::operator()(Env&, JTx& jt) const { jt.jv["SourceTag"] = value_; } diff --git a/src/ripple/test/jtx/impl/txflags.cpp b/src/ripple/test/jtx/impl/txflags.cpp index f2cc608fcd..260fd1a474 100644 --- a/src/ripple/test/jtx/impl/txflags.cpp +++ b/src/ripple/test/jtx/impl/txflags.cpp @@ -26,7 +26,7 @@ namespace test { namespace jtx { void -txflags::operator()(Env const&, JTx& jt) const +txflags::operator()(Env&, JTx& jt) const { jt[jss::Flags] = v_ /*| tfUniversal*/; diff --git a/src/ripple/test/jtx/jtx_json.h b/src/ripple/test/jtx/jtx_json.h index 965ce57813..809c6bb35a 100644 --- a/src/ripple/test/jtx/jtx_json.h +++ b/src/ripple/test/jtx/jtx_json.h @@ -50,7 +50,7 @@ public: } void - operator()(Env const&, JTx& jt) const; + operator()(Env&, JTx& jt) const; }; } // jtx diff --git a/src/ripple/test/jtx/memo.h b/src/ripple/test/jtx/memo.h index 84031d5c99..21360c41a6 100644 --- a/src/ripple/test/jtx/memo.h +++ b/src/ripple/test/jtx/memo.h @@ -50,7 +50,7 @@ public: } void - operator()(Env const&, JTx& jt) const; + operator()(Env&, JTx& jt) const; }; class memodata @@ -65,7 +65,7 @@ public: } void - operator()(Env const&, JTx& jt) const; + operator()(Env&, JTx& jt) const; }; class memoformat @@ -80,7 +80,7 @@ public: } void - operator()(Env const&, JTx& jt) const; + operator()(Env&, JTx& jt) const; }; class memotype @@ -95,7 +95,7 @@ public: } void - operator()(Env const&, JTx& jt) const; + operator()(Env&, JTx& jt) const; }; class memondata @@ -113,7 +113,7 @@ public: } void - operator()(Env const&, JTx& jt) const; + operator()(Env&, JTx& jt) const; }; class memonformat @@ -131,7 +131,7 @@ public: } void - operator()(Env const&, JTx& jt) const; + operator()(Env&, JTx& jt) const; }; class memontype @@ -149,7 +149,7 @@ public: } void - operator()(Env const&, JTx& jt) const; + operator()(Env&, JTx& jt) const; }; } // jtx diff --git a/src/ripple/test/jtx/multisign.h b/src/ripple/test/jtx/multisign.h index 12fe9e4baa..5eee558c6c 100644 --- a/src/ripple/test/jtx/multisign.h +++ b/src/ripple/test/jtx/multisign.h @@ -104,7 +104,7 @@ public: } void - operator()(Env const&, JTx& jt) const; + operator()(Env&, JTx& jt) const; private: template diff --git a/src/ripple/test/jtx/owners.h b/src/ripple/test/jtx/owners.h index 5fb5480024..a6ec061f0c 100644 --- a/src/ripple/test/jtx/owners.h +++ b/src/ripple/test/jtx/owners.h @@ -38,7 +38,7 @@ owned_count_of (ReadView const& view, LedgerEntryType type); void -owned_count_helper(Env const& env, +owned_count_helper(Env& env, AccountID const& id, LedgerEntryType type, std::uint32_t value); @@ -62,7 +62,7 @@ public: } void - operator()(Env const& env) const + operator()(Env& env) const { detail::owned_count_helper( env, account_.id(), Type, value_); @@ -84,7 +84,7 @@ public: } void - operator()(Env const& env) const; + operator()(Env& env) const; }; /** Match the number of trust lines in the account's owner directory */ diff --git a/src/ripple/test/jtx/paths.h b/src/ripple/test/jtx/paths.h index ed80b0f83e..3a9dce674a 100644 --- a/src/ripple/test/jtx/paths.h +++ b/src/ripple/test/jtx/paths.h @@ -46,7 +46,7 @@ public: } void - operator()(Env const&, JTx& jt) const; + operator()(Env&, JTx& jt) const; }; //------------------------------------------------------------------------------ @@ -68,7 +68,7 @@ public: path (T const& t, Args const&... args); void - operator()(Env const&, JTx& jt) const; + operator()(Env&, JTx& jt) const; private: Json::Value& diff --git a/src/ripple/test/jtx/prop.h b/src/ripple/test/jtx/prop.h index f5a7384e71..2719036db6 100644 --- a/src/ripple/test/jtx/prop.h +++ b/src/ripple/test/jtx/prop.h @@ -43,7 +43,7 @@ struct prop } void - operator()(Env const& env, JTx& jt) const + operator()(Env& env, JTx& jt) const { jt.set(p_->clone()); } diff --git a/src/ripple/test/jtx/require.h b/src/ripple/test/jtx/require.h index 1e98051367..c20a88b74e 100644 --- a/src/ripple/test/jtx/require.h +++ b/src/ripple/test/jtx/require.h @@ -55,7 +55,7 @@ required (Args const&... args) { requires_t vec; detail::require_args(vec, args...); - return [vec](Env const& env) + return [vec](Env& env) { for(auto const& f : vec) f(env); @@ -81,7 +81,7 @@ public: } void - operator()(Env const&, JTx& jt) const + operator()(Env&, JTx& jt) const { jt.requires.emplace_back(cond_); } diff --git a/src/ripple/test/jtx/requires.h b/src/ripple/test/jtx/requires.h index c197fc4190..c3b0f2248f 100644 --- a/src/ripple/test/jtx/requires.h +++ b/src/ripple/test/jtx/requires.h @@ -29,7 +29,7 @@ namespace jtx { class Env; -using require_t = std::function; +using require_t = std::function; using requires_t = std::vector; } // jtx diff --git a/src/ripple/test/jtx/sendmax.h b/src/ripple/test/jtx/sendmax.h index 9e58c8ec68..083e9f8b61 100644 --- a/src/ripple/test/jtx/sendmax.h +++ b/src/ripple/test/jtx/sendmax.h @@ -40,7 +40,7 @@ public: } void - operator()(Env const&, JTx& jtx) const; + operator()(Env&, JTx& jtx) const; }; } // jtx diff --git a/src/ripple/test/jtx/seq.h b/src/ripple/test/jtx/seq.h index d91b2be45d..034cf071d8 100644 --- a/src/ripple/test/jtx/seq.h +++ b/src/ripple/test/jtx/seq.h @@ -54,7 +54,7 @@ public: } void - operator()(Env const&, JTx& jt) const; + operator()(Env&, JTx& jt) const; }; } // jtx diff --git a/src/ripple/test/jtx/sig.h b/src/ripple/test/jtx/sig.h index ada0fcd9bd..1465e3b784 100644 --- a/src/ripple/test/jtx/sig.h +++ b/src/ripple/test/jtx/sig.h @@ -55,7 +55,7 @@ public: } void - operator()(Env const&, JTx& jt) const; + operator()(Env&, JTx& jt) const; }; } // jtx diff --git a/src/ripple/test/jtx/tag.h b/src/ripple/test/jtx/tag.h index 94e13f2c02..e8f2d93d32 100644 --- a/src/ripple/test/jtx/tag.h +++ b/src/ripple/test/jtx/tag.h @@ -41,7 +41,7 @@ public: } void - operator()(Env const&, JTx& jt) const; + operator()(Env&, JTx& jt) const; }; /** Set the source tag on a JTx*/ @@ -58,7 +58,7 @@ public: } void - operator()(Env const&, JTx& jt) const; + operator()(Env&, JTx& jt) const; }; } // jtx diff --git a/src/ripple/test/jtx/ter.h b/src/ripple/test/jtx/ter.h index 5b1268e232..1773df376e 100644 --- a/src/ripple/test/jtx/ter.h +++ b/src/ripple/test/jtx/ter.h @@ -42,7 +42,7 @@ public: } void - operator()(Env const&, JTx& jt) const + operator()(Env&, JTx& jt) const { jt.ter = v_; } diff --git a/src/ripple/test/jtx/txflags.h b/src/ripple/test/jtx/txflags.h index f79035d798..5e56e42ab9 100644 --- a/src/ripple/test/jtx/txflags.h +++ b/src/ripple/test/jtx/txflags.h @@ -40,7 +40,7 @@ public: } void - operator()(Env const&, JTx& jt) const; + operator()(Env&, JTx& jt) const; }; } // jtx diff --git a/src/ripple/websocket/Connection.h b/src/ripple/websocket/Connection.h index 722ec70ccd..2480a58de9 100644 --- a/src/ripple/websocket/Connection.h +++ b/src/ripple/websocket/Connection.h @@ -68,6 +68,7 @@ public: using handler_type = HandlerImpl ; ConnectionImpl ( + Application& app, Resource::Manager& resourceManager, InfoSub::Source& source, handler_type& handler, @@ -101,6 +102,7 @@ public: void setPingTimer (); private: + Application& app_; HTTP::Port const& m_port; Resource::Manager& m_resourceManager; Resource::Consumer m_usage; @@ -121,6 +123,7 @@ private: template ConnectionImpl ::ConnectionImpl ( + Application& app, Resource::Manager& resourceManager, InfoSub::Source& source, handler_type& handler, @@ -129,10 +132,11 @@ ConnectionImpl ::ConnectionImpl ( boost::asio::io_service& io_service) : InfoSub (source, // usage resourceManager.newInboundEndpoint (remoteAddress)) + , app_(app) , m_port (handler.port ()) , m_resourceManager (resourceManager) , m_remoteAddress (remoteAddress) - , m_netOPs (getApp ().getOPs ()) + , m_netOPs (app_.getOPs ()) , m_io_service (io_service) , m_pingTimer (io_service) , m_handler (handler) @@ -270,9 +274,9 @@ Json::Value ConnectionImpl ::invokeCommand ( else { RPC::Context context { - jvRequest, getApp(), loadType, m_netOPs, getApp().getLedgerMaster(), role, - this->shared_from_this (), - {suspend, "WSClient::command"}}; + jvRequest, app_, loadType, m_netOPs, app_.getLedgerMaster(), + role, {app_, suspend, "WSClient::command"}, + this->shared_from_this ()}; RPC::doCommand (context, jvResult[jss::result]); } diff --git a/src/ripple/websocket/Handler.h b/src/ripple/websocket/Handler.h index 1780545c86..470f58c309 100644 --- a/src/ripple/websocket/Handler.h +++ b/src/ripple/websocket/Handler.h @@ -199,6 +199,7 @@ public: { auto remoteEndpoint = cpClient->get_socket ().remote_endpoint (); auto connection = std::make_shared > ( + desc_.app, desc_.resourceManager, desc_.source, *this,