From 8f586870917818133924bf2e11acab5321c2b588 Mon Sep 17 00:00:00 2001 From: Nik Bougalis Date: Thu, 10 Feb 2022 09:13:16 -0800 Subject: [PATCH] Cleanup `AcceptedLedger` and `AcceptedLedgerTx`: This commit modernizes the `AcceptedLedger` and `AcceptedLedgerTx` classes, reduces their memory footprint and reduces unnecessary dynamic memory allocations. --- src/ripple/app/ledger/AcceptedLedger.cpp | 40 +-- src/ripple/app/ledger/AcceptedLedger.h | 37 ++- src/ripple/app/ledger/AcceptedLedgerTx.cpp | 70 ++--- src/ripple/app/ledger/AcceptedLedgerTx.h | 51 +--- src/ripple/app/ledger/OrderBookDB.cpp | 5 +- src/ripple/app/misc/NetworkOPs.cpp | 288 +++++++++++------- src/ripple/app/misc/NetworkOPs.h | 6 +- src/ripple/app/rdb/RelationalDBInterface.h | 2 +- .../rdb/impl/RelationalDBInterface_nodes.cpp | 7 +- .../rdb/impl/RelationalDBInterface_shards.cpp | 11 +- src/ripple/protocol/TxMeta.h | 2 +- src/ripple/protocol/impl/TxMeta.cpp | 8 +- src/ripple/protocol/jss.h | 1 + src/ripple/rpc/handlers/GetCounts.cpp | 1 + 14 files changed, 257 insertions(+), 272 deletions(-) diff --git a/src/ripple/app/ledger/AcceptedLedger.cpp b/src/ripple/app/ledger/AcceptedLedger.cpp index 41946f00984..526704d1889 100644 --- a/src/ripple/app/ledger/AcceptedLedger.cpp +++ b/src/ripple/app/ledger/AcceptedLedger.cpp @@ -19,8 +19,7 @@ #include #include -#include -#include +#include namespace ripple { @@ -29,29 +28,34 @@ AcceptedLedger::AcceptedLedger( Application& app) : mLedger(ledger) { + transactions_.reserve(256); + auto insertAll = [&](auto const& txns) { + auto const& idcache = app.accountIDCache(); + for (auto const& item : txns) - { - insert(std::make_shared( - ledger, - item.first, - item.second, - app.accountIDCache(), - app.logs())); - } + transactions_.emplace_back(std::make_unique( + ledger, item.first, item.second, idcache)); }; if (app.config().reporting()) - insertAll(flatFetchTransactions(*ledger, app)); + { + auto const txs = flatFetchTransactions(*ledger, app); + transactions_.reserve(txs.size()); + insertAll(txs); + } else + { + transactions_.reserve(256); insertAll(ledger->txs); -} - -void -AcceptedLedger::insert(AcceptedLedgerTx::ref at) -{ - assert(mMap.find(at->getIndex()) == mMap.end()); - mMap.insert(std::make_pair(at->getIndex(), at)); + } + + std::sort( + transactions_.begin(), + transactions_.end(), + [](auto const& a, auto const& b) { + return a->getTxnSeq() < b->getTxnSeq(); + }); } } // namespace ripple diff --git a/src/ripple/app/ledger/AcceptedLedger.h b/src/ripple/app/ledger/AcceptedLedger.h index 0575013695f..0187fdfb679 100644 --- a/src/ripple/app/ledger/AcceptedLedger.h +++ b/src/ripple/app/ledger/AcceptedLedger.h @@ -41,43 +41,40 @@ namespace ripple { the result of the a consensus process (though haven't validated it yet). */ -class AcceptedLedger +class AcceptedLedger : public CountedObject { public: - using pointer = std::shared_ptr; - using ret = const pointer&; - using map_t = std::map; - // mapt_t must be an ordered map! - using value_type = map_t::value_type; - using const_iterator = map_t::const_iterator; + AcceptedLedger( + std::shared_ptr const& ledger, + Application& app); -public: std::shared_ptr const& getLedger() const { return mLedger; } - const map_t& - getMap() const + + std::size_t + size() const { - return mMap; + return transactions_.size(); } - int - getTxnCount() const + auto + begin() const { - return mMap.size(); + return transactions_.begin(); } - AcceptedLedger( - std::shared_ptr const& ledger, - Application& app); + auto + end() const + { + return transactions_.end(); + } private: - void insert(AcceptedLedgerTx::ref); - std::shared_ptr mLedger; - map_t mMap; + std::vector> transactions_; }; } // namespace ripple diff --git a/src/ripple/app/ledger/AcceptedLedgerTx.cpp b/src/ripple/app/ledger/AcceptedLedgerTx.cpp index c92ebffe04b..f0408b0c049 100644 --- a/src/ripple/app/ledger/AcceptedLedgerTx.cpp +++ b/src/ripple/app/ledger/AcceptedLedgerTx.cpp @@ -18,7 +18,6 @@ //============================================================================== #include -#include #include #include #include @@ -30,72 +29,30 @@ AcceptedLedgerTx::AcceptedLedgerTx( std::shared_ptr const& ledger, std::shared_ptr const& txn, std::shared_ptr const& met, - AccountIDCache const& accountCache, - Logs& logs) - : mLedger(ledger) - , mTxn(txn) - , mMeta(std::make_shared( - txn->getTransactionID(), - ledger->seq(), - *met)) - , mAffected(mMeta->getAffectedAccounts(logs.journal("View"))) - , accountCache_(accountCache) - , logs_(logs) + AccountIDCache const& accountCache) + : mTxn(txn) + , mMeta(txn->getTransactionID(), ledger->seq(), *met) + , mAffected(mMeta.getAffectedAccounts()) { assert(!ledger->open()); - mResult = mMeta->getResultTER(); - Serializer s; met->add(s); mRawMeta = std::move(s.modData()); - buildJson(); -} - -AcceptedLedgerTx::AcceptedLedgerTx( - std::shared_ptr const& ledger, - std::shared_ptr const& txn, - TER result, - AccountIDCache const& accountCache, - Logs& logs) - : mLedger(ledger) - , mTxn(txn) - , mResult(result) - , mAffected(txn->getMentionedAccounts()) - , accountCache_(accountCache) - , logs_(logs) -{ - assert(ledger->open()); - buildJson(); -} - -std::string -AcceptedLedgerTx::getEscMeta() const -{ - assert(!mRawMeta.empty()); - return sqlBlobLiteral(mRawMeta); -} - -void -AcceptedLedgerTx::buildJson() -{ mJson = Json::objectValue; mJson[jss::transaction] = mTxn->getJson(JsonOptions::none); - if (mMeta) - { - mJson[jss::meta] = mMeta->getJson(JsonOptions::none); - mJson[jss::raw_meta] = strHex(mRawMeta); - } + mJson[jss::meta] = mMeta.getJson(JsonOptions::none); + mJson[jss::raw_meta] = strHex(mRawMeta); - mJson[jss::result] = transHuman(mResult); + mJson[jss::result] = transHuman(mMeta.getResultTER()); if (!mAffected.empty()) { Json::Value& affected = (mJson[jss::affected] = Json::arrayValue); for (auto const& account : mAffected) - affected.append(accountCache_.toBase58(account)); + affected.append(accountCache.toBase58(account)); } if (mTxn->getTxnType() == ttOFFER_CREATE) @@ -107,14 +64,21 @@ AcceptedLedgerTx::buildJson() if (account != amount.issue().account) { auto const ownerFunds = accountFunds( - *mLedger, + *ledger, account, amount, fhIGNORE_FREEZE, - logs_.journal("View")); + beast::Journal{beast::Journal::getNullSink()}); mJson[jss::transaction][jss::owner_funds] = ownerFunds.getText(); } } } +std::string +AcceptedLedgerTx::getEscMeta() const +{ + assert(!mRawMeta.empty()); + return sqlBlobLiteral(mRawMeta); +} + } // namespace ripple diff --git a/src/ripple/app/ledger/AcceptedLedgerTx.h b/src/ripple/app/ledger/AcceptedLedgerTx.h index 712e085b6cc..7d68978571b 100644 --- a/src/ripple/app/ledger/AcceptedLedgerTx.h +++ b/src/ripple/app/ledger/AcceptedLedgerTx.h @@ -39,40 +39,22 @@ class Logs; - Which accounts are affected * This is used by InfoSub to report to clients - Cached stuff - - @code - @endcode - - @see {uri} - - @ingroup ripple_ledger */ -class AcceptedLedgerTx +class AcceptedLedgerTx : public CountedObject { -public: - using pointer = std::shared_ptr; - using ref = const pointer&; - public: AcceptedLedgerTx( std::shared_ptr const& ledger, std::shared_ptr const&, std::shared_ptr const&, - AccountIDCache const&, - Logs&); - AcceptedLedgerTx( - std::shared_ptr const&, - std::shared_ptr const&, - TER, - AccountIDCache const&, - Logs&); + AccountIDCache const&); std::shared_ptr const& getTxn() const { return mTxn; } - std::shared_ptr const& + TxMeta const& getMeta() const { return mMeta; @@ -97,45 +79,28 @@ class AcceptedLedgerTx TER getResult() const { - return mResult; + return mMeta.getResultTER(); } std::uint32_t getTxnSeq() const { - return mMeta->getIndex(); - } - - bool - isApplied() const - { - return bool(mMeta); - } - int - getIndex() const - { - return mMeta ? mMeta->getIndex() : 0; + return mMeta.getIndex(); } std::string getEscMeta() const; - Json::Value + + Json::Value const& getJson() const { return mJson; } private: - std::shared_ptr mLedger; std::shared_ptr mTxn; - std::shared_ptr mMeta; - TER mResult; + TxMeta mMeta; boost::container::flat_set mAffected; Blob mRawMeta; Json::Value mJson; - AccountIDCache const& accountCache_; - Logs& logs_; - - void - buildJson(); }; } // namespace ripple diff --git a/src/ripple/app/ledger/OrderBookDB.cpp b/src/ripple/app/ledger/OrderBookDB.cpp index 28ff53f0f81..343e7f6269a 100644 --- a/src/ripple/app/ledger/OrderBookDB.cpp +++ b/src/ripple/app/ledger/OrderBookDB.cpp @@ -245,10 +245,7 @@ OrderBookDB::processTxn( // single client has subscribed to those books. hash_set havePublished; - // Check if this is an offer or an offer cancel or a payment that - // consumes an offer. - // Check to see what the meta looks like. - for (auto& node : alTx.getMeta()->getNodes()) + for (auto const& node : alTx.getMeta().getNodes()) { try { diff --git a/src/ripple/app/misc/NetworkOPs.cpp b/src/ripple/app/misc/NetworkOPs.cpp index 1d1493758df..e5dd5765d9a 100644 --- a/src/ripple/app/misc/NetworkOPs.cpp +++ b/src/ripple/app/misc/NetworkOPs.cpp @@ -445,9 +445,9 @@ class NetworkOPsImp final : public NetworkOPs pubLedger(std::shared_ptr const& lpAccepted) override; void pubProposedTransaction( - std::shared_ptr const& lpCurrent, - std::shared_ptr const& stTxn, - TER terResult) override; + std::shared_ptr const& ledger, + std::shared_ptr const& transaction, + TER result) override; void pubValidation(std::shared_ptr const& val) override; @@ -612,20 +612,26 @@ class NetworkOPsImp final : public NetworkOPs Json::Value transJson( - const STTx& stTxn, - TER terResult, - bool bValidated, - std::shared_ptr const& lpCurrent); + const STTx& transaction, + TER result, + bool validated, + std::shared_ptr const& ledger); void pubValidatedTransaction( - std::shared_ptr const& alAccepted, - const AcceptedLedgerTx& alTransaction); + std::shared_ptr const& ledger, + AcceptedLedgerTx const& transaction); + void pubAccountTransaction( - std::shared_ptr const& lpCurrent, - const AcceptedLedgerTx& alTransaction, - bool isAccepted); + std::shared_ptr const& ledger, + AcceptedLedgerTx const& transaction); + + void + pubProposedAccountTransaction( + std::shared_ptr const& ledger, + std::shared_ptr const& transaction, + TER result); void pubServer(); @@ -2643,11 +2649,11 @@ NetworkOPsImp::getLedgerFetchInfo() void NetworkOPsImp::pubProposedTransaction( - std::shared_ptr const& lpCurrent, - std::shared_ptr const& stTxn, - TER terResult) + std::shared_ptr const& ledger, + std::shared_ptr const& transaction, + TER result) { - Json::Value jvObj = transJson(*stTxn, terResult, false, lpCurrent); + Json::Value jvObj = transJson(*transaction, result, false, ledger); { std::lock_guard sl(mSubLock); @@ -2668,10 +2674,8 @@ NetworkOPsImp::pubProposedTransaction( } } } - AcceptedLedgerTx alt( - lpCurrent, stTxn, terResult, app_.accountIDCache(), app_.logs()); - JLOG(m_journal.trace()) << "pubProposed: " << alt.getJson(); - pubAccountTransaction(lpCurrent, alt, false); + + pubProposedAccountTransaction(ledger, transaction, result); } void @@ -2846,9 +2850,13 @@ NetworkOPsImp::pubLedger(std::shared_ptr const& lpAccepted) lpAccepted->info().hash, alpAccepted); } + assert(alpAccepted->getLedger().get() == lpAccepted.get()); + { JLOG(m_journal.debug()) - << "Publishing ledger = " << lpAccepted->info().seq; + << "Publishing ledger " << lpAccepted->info().seq << " " + << lpAccepted->info().hash; + std::lock_guard sl(mSubLock); if (!mStreamMaps[sLedger].empty()) @@ -2868,7 +2876,7 @@ NetworkOPsImp::pubLedger(std::shared_ptr const& lpAccepted) jvObj[jss::reserve_inc] = lpAccepted->fees().increment.jsonClipped(); - jvObj[jss::txn_count] = Json::UInt(alpAccepted->getTxnCount()); + jvObj[jss::txn_count] = Json::UInt(alpAccepted->size()); if (mMode >= OperatingMode::SYNCING) { @@ -2882,10 +2890,6 @@ NetworkOPsImp::pubLedger(std::shared_ptr const& lpAccepted) InfoSub::pointer p = it->second.lock(); if (p) { - JLOG(m_journal.debug()) - << "Publishing ledger = " << lpAccepted->info().seq - << " : consumer = " << p->getConsumer() - << " : obj = " << jvObj; p->send(jvObj, true); ++it; } @@ -2917,9 +2921,8 @@ NetworkOPsImp::pubLedger(std::shared_ptr const& lpAccepted) } // Don't lock since pubAcceptedTransaction is locking. - for (auto const& [_, accTx] : alpAccepted->getMap()) + for (auto const& accTx : *alpAccepted) { - (void)_; JLOG(m_journal.trace()) << "pubAccepted: " << accTx->getJson(); pubValidatedTransaction(lpAccepted, *accTx); } @@ -2969,26 +2972,26 @@ NetworkOPsImp::getLocalTxCount() // transactions. Json::Value NetworkOPsImp::transJson( - const STTx& stTxn, - TER terResult, - bool bValidated, - std::shared_ptr const& lpCurrent) + const STTx& transaction, + TER result, + bool validated, + std::shared_ptr const& ledger) { Json::Value jvObj(Json::objectValue); std::string sToken; std::string sHuman; - transResultInfo(terResult, sToken, sHuman); + transResultInfo(result, sToken, sHuman); jvObj[jss::type] = "transaction"; - jvObj[jss::transaction] = stTxn.getJson(JsonOptions::none); + jvObj[jss::transaction] = transaction.getJson(JsonOptions::none); - if (bValidated) + if (validated) { - jvObj[jss::ledger_index] = lpCurrent->info().seq; - jvObj[jss::ledger_hash] = to_string(lpCurrent->info().hash); + jvObj[jss::ledger_index] = ledger->info().seq; + jvObj[jss::ledger_hash] = to_string(ledger->info().hash); jvObj[jss::transaction][jss::date] = - lpCurrent->info().closeTime.time_since_epoch().count(); + ledger->info().closeTime.time_since_epoch().count(); jvObj[jss::validated] = true; // WRITEME: Put the account next seq here @@ -2996,24 +2999,24 @@ NetworkOPsImp::transJson( else { jvObj[jss::validated] = false; - jvObj[jss::ledger_current_index] = lpCurrent->info().seq; + jvObj[jss::ledger_current_index] = ledger->info().seq; } - jvObj[jss::status] = bValidated ? "closed" : "proposed"; + jvObj[jss::status] = validated ? "closed" : "proposed"; jvObj[jss::engine_result] = sToken; - jvObj[jss::engine_result_code] = terResult; + jvObj[jss::engine_result_code] = result; jvObj[jss::engine_result_message] = sHuman; - if (stTxn.getTxnType() == ttOFFER_CREATE) + if (transaction.getTxnType() == ttOFFER_CREATE) { - auto const account = stTxn.getAccountID(sfAccount); - auto const amount = stTxn.getFieldAmount(sfTakerGets); + auto const account = transaction.getAccountID(sfAccount); + auto const amount = transaction.getFieldAmount(sfTakerGets); // If the offer create is not self funded then add the owner balance if (account != amount.issue().account) { auto const ownerFunds = accountFunds( - *lpCurrent, + *ledger, account, amount, fhIGNORE_FREEZE, @@ -3027,17 +3030,18 @@ NetworkOPsImp::transJson( void NetworkOPsImp::pubValidatedTransaction( - std::shared_ptr const& alAccepted, - const AcceptedLedgerTx& alTx) + std::shared_ptr const& ledger, + const AcceptedLedgerTx& transaction) { - std::shared_ptr stTxn = alTx.getTxn(); - Json::Value jvObj = transJson(*stTxn, alTx.getResult(), true, alAccepted); + auto const& stTxn = transaction.getTxn(); + + Json::Value jvObj = + transJson(*stTxn, transaction.getResult(), true, ledger); - if (auto const txMeta = alTx.getMeta()) { - jvObj[jss::meta] = txMeta->getJson(JsonOptions::none); - RPC::insertDeliveredAmount( - jvObj[jss::meta], *alAccepted, stTxn, *txMeta); + auto const& meta = transaction.getMeta(); + jvObj[jss::meta] = meta.getJson(JsonOptions::none); + RPC::insertDeliveredAmount(jvObj[jss::meta], *ledger, stTxn, meta); } { @@ -3072,33 +3076,31 @@ NetworkOPsImp::pubValidatedTransaction( it = mStreamMaps[sRTTransactions].erase(it); } } - if (alTx.getResult() == tesSUCCESS) - app_.getOrderBookDB().processTxn(alAccepted, alTx, jvObj); - pubAccountTransaction(alAccepted, alTx, true); + + if (transaction.getResult() == tesSUCCESS) + app_.getOrderBookDB().processTxn(ledger, transaction, jvObj); + + pubAccountTransaction(ledger, transaction); } void NetworkOPsImp::pubAccountTransaction( - std::shared_ptr const& lpCurrent, - const AcceptedLedgerTx& alTx, - bool bAccepted) + std::shared_ptr const& ledger, + AcceptedLedgerTx const& transaction) { hash_set notify; int iProposed = 0; int iAccepted = 0; std::vector accountHistoryNotify; - auto const currLedgerSeq = lpCurrent->seq(); + auto const currLedgerSeq = ledger->seq(); { std::lock_guard sl(mSubLock); - if (!bAccepted && mSubRTAccount.empty()) - return; - - if (!mSubAccount.empty() || (!mSubRTAccount.empty()) || + if (!mSubAccount.empty() || !mSubRTAccount.empty() || !mSubAccountHistory.empty()) { - for (auto const& affectedAccount : alTx.getAffected()) + for (auto const& affectedAccount : transaction.getAffected()) { if (auto simiIt = mSubRTAccount.find(affectedAccount); simiIt != mSubRTAccount.end()) @@ -3120,80 +3122,140 @@ NetworkOPsImp::pubAccountTransaction( } } - if (bAccepted) + if (auto simiIt = mSubAccount.find(affectedAccount); + simiIt != mSubAccount.end()) { - if (auto simiIt = mSubAccount.find(affectedAccount); - simiIt != mSubAccount.end()) + auto it = simiIt->second.begin(); + while (it != simiIt->second.end()) { - auto it = simiIt->second.begin(); - while (it != simiIt->second.end()) - { - InfoSub::pointer p = it->second.lock(); + InfoSub::pointer p = it->second.lock(); - if (p) - { - notify.insert(p); - ++it; - ++iAccepted; - } - else - it = simiIt->second.erase(it); + if (p) + { + notify.insert(p); + ++it; + ++iAccepted; } + else + it = simiIt->second.erase(it); } + } - if (auto histoIt = mSubAccountHistory.find(affectedAccount); - histoIt != mSubAccountHistory.end()) + if (auto histoIt = mSubAccountHistory.find(affectedAccount); + histoIt != mSubAccountHistory.end()) + { + auto& subs = histoIt->second; + auto it = subs.begin(); + while (it != subs.end()) { - auto& subs = histoIt->second; - auto it = subs.begin(); - while (it != subs.end()) + SubAccountHistoryInfoWeak const& info = it->second; + if (currLedgerSeq <= info.index_->separationLedgerSeq_) { - SubAccountHistoryInfoWeak const& info = it->second; - if (currLedgerSeq <= - info.index_->separationLedgerSeq_) - { - ++it; - continue; - } + ++it; + continue; + } - if (auto isSptr = info.sinkWptr_.lock(); isSptr) - { - accountHistoryNotify.emplace_back( - SubAccountHistoryInfo{isSptr, info.index_}); - ++it; - } - else - { - it = subs.erase(it); - } + if (auto isSptr = info.sinkWptr_.lock(); isSptr) + { + accountHistoryNotify.emplace_back( + SubAccountHistoryInfo{isSptr, info.index_}); + ++it; + } + else + { + it = subs.erase(it); } - if (subs.empty()) - mSubAccountHistory.erase(histoIt); } + if (subs.empty()) + mSubAccountHistory.erase(histoIt); } } } } JLOG(m_journal.trace()) - << "pubAccountTransaction:" - << " iProposed=" << iProposed << " iAccepted=" << iAccepted; + << "pubAccountTransaction: " + << "proposed=" << iProposed << ", accepted=" << iAccepted; if (!notify.empty() || !accountHistoryNotify.empty()) { - std::shared_ptr stTxn = alTx.getTxn(); + auto const& stTxn = transaction.getTxn(); + Json::Value jvObj = - transJson(*stTxn, alTx.getResult(), bAccepted, lpCurrent); + transJson(*stTxn, transaction.getResult(), true, ledger); - if (alTx.isApplied()) { - if (auto const txMeta = alTx.getMeta()) + auto const& meta = transaction.getMeta(); + + jvObj[jss::meta] = meta.getJson(JsonOptions::none); + RPC::insertDeliveredAmount(jvObj[jss::meta], *ledger, stTxn, meta); + } + + for (InfoSub::ref isrListener : notify) + isrListener->send(jvObj, true); + + assert(!jvObj.isMember(jss::account_history_tx_stream)); + for (auto& info : accountHistoryNotify) + { + auto& index = info.index_; + if (index->forwardTxIndex_ == 0 && !index->haveHistorical_) + jvObj[jss::account_history_tx_first] = true; + jvObj[jss::account_history_tx_index] = index->forwardTxIndex_++; + info.sink_->send(jvObj, true); + } + } +} + +void +NetworkOPsImp::pubProposedAccountTransaction( + std::shared_ptr const& ledger, + std::shared_ptr const& tx, + TER result) +{ + hash_set notify; + int iProposed = 0; + + std::vector accountHistoryNotify; + + { + std::lock_guard sl(mSubLock); + + if (mSubRTAccount.empty()) + return; + + if (!mSubAccount.empty() || !mSubRTAccount.empty() || + !mSubAccountHistory.empty()) + { + for (auto const& affectedAccount : tx->getMentionedAccounts()) { - jvObj[jss::meta] = txMeta->getJson(JsonOptions::none); - RPC::insertDeliveredAmount( - jvObj[jss::meta], *lpCurrent, stTxn, *txMeta); + if (auto simiIt = mSubRTAccount.find(affectedAccount); + simiIt != mSubRTAccount.end()) + { + auto it = simiIt->second.begin(); + + while (it != simiIt->second.end()) + { + InfoSub::pointer p = it->second.lock(); + + if (p) + { + notify.insert(p); + ++it; + ++iProposed; + } + else + it = simiIt->second.erase(it); + } + } } } + } + + JLOG(m_journal.trace()) << "pubProposedAccountTransaction: " << iProposed; + + if (!notify.empty() || !accountHistoryNotify.empty()) + { + Json::Value jvObj = transJson(*tx, result, false, ledger); for (InfoSub::ref isrListener : notify) isrListener->send(jvObj, true); diff --git a/src/ripple/app/misc/NetworkOPs.h b/src/ripple/app/misc/NetworkOPs.h index 1cf53f12631..d53127ed3b6 100644 --- a/src/ripple/app/misc/NetworkOPs.h +++ b/src/ripple/app/misc/NetworkOPs.h @@ -255,9 +255,9 @@ class NetworkOPs : public InfoSub::Source pubLedger(std::shared_ptr const& lpAccepted) = 0; virtual void pubProposedTransaction( - std::shared_ptr const& lpCurrent, - std::shared_ptr const& stTxn, - TER terResult) = 0; + std::shared_ptr const& ledger, + std::shared_ptr const& transaction, + TER result) = 0; virtual void pubValidation(std::shared_ptr const& val) = 0; diff --git a/src/ripple/app/rdb/RelationalDBInterface.h b/src/ripple/app/rdb/RelationalDBInterface.h index a0d01545bc5..759261832db 100644 --- a/src/ripple/app/rdb/RelationalDBInterface.h +++ b/src/ripple/app/rdb/RelationalDBInterface.h @@ -125,7 +125,7 @@ class RelationalDBInterface TxMeta const& meta, uint256 const& nodestoreHash, beast::Journal j) - : accounts(meta.getAffectedAccounts(j)) + : accounts(meta.getAffectedAccounts()) , ledgerSequence(meta.getLgrSeq()) , transactionIndex(meta.getIndex()) , txHash(meta.getTxID()) diff --git a/src/ripple/app/rdb/impl/RelationalDBInterface_nodes.cpp b/src/ripple/app/rdb/impl/RelationalDBInterface_nodes.cpp index 748265e624b..c067bfe0cd0 100644 --- a/src/ripple/app/rdb/impl/RelationalDBInterface_nodes.cpp +++ b/src/ripple/app/rdb/impl/RelationalDBInterface_nodes.cpp @@ -222,7 +222,7 @@ saveValidatedLedger( hotLEDGER, std::move(s.modData()), ledger->info().hash, seq); } - AcceptedLedger::pointer aLedger; + std::shared_ptr aLedger; try { aLedger = app.getAcceptedLedgerCache().fetch(ledger->info().hash); @@ -269,9 +269,8 @@ saveValidatedLedger( std::string const ledgerSeq(std::to_string(seq)); - for (auto const& [_, acceptedLedgerTx] : aLedger->getMap()) + for (auto const& acceptedLedgerTx : *aLedger) { - (void)_; uint256 transactionID = acceptedLedgerTx->getTransactionID(); std::string const txnId(to_string(transactionID)); @@ -317,7 +316,7 @@ saveValidatedLedger( JLOG(j.trace()) << "ActTx: " << sql; *db << sql; } - else if (auto const sleTxn = acceptedLedgerTx->getTxn(); + else if (auto const& sleTxn = acceptedLedgerTx->getTxn(); !isPseudoTx(*sleTxn)) { // It's okay for pseudo transactions to not affect any diff --git a/src/ripple/app/rdb/impl/RelationalDBInterface_shards.cpp b/src/ripple/app/rdb/impl/RelationalDBInterface_shards.cpp index acda4ea1d4a..32dcfc25188 100644 --- a/src/ripple/app/rdb/impl/RelationalDBInterface_shards.cpp +++ b/src/ripple/app/rdb/impl/RelationalDBInterface_shards.cpp @@ -79,7 +79,8 @@ saveLedgerMeta( if (app.config().useTxTables()) { - AcceptedLedger::pointer const aLedger = [&app, ledger] { + auto const aLedger = [&app, + ledger]() -> std::shared_ptr { try { auto aLedger = @@ -99,7 +100,7 @@ saveLedgerMeta( << "An accepted ledger was missing nodes"; } - return AcceptedLedger::pointer{nullptr}; + return {}; }(); if (!aLedger) @@ -107,10 +108,8 @@ saveLedgerMeta( soci::transaction tr(txnMetaSession); - for (auto const& [_, acceptedLedgerTx] : aLedger->getMap()) + for (auto const& acceptedLedgerTx : *aLedger) { - (void)_; - std::string_view constexpr txnSQL = R"sql(INSERT OR REPLACE INTO TransactionMeta VALUES (:transactionID,:shardIndex);)sql"; @@ -247,7 +246,7 @@ updateLedgerDBs( "WHERE TransID = :txID;", soci::use(sTxID); - auto const& accounts = txMeta->getAffectedAccounts(j); + auto const& accounts = txMeta->getAffectedAccounts(); if (!accounts.empty()) { auto const sTxnSeq{std::to_string(txMeta->getIndex())}; diff --git a/src/ripple/protocol/TxMeta.h b/src/ripple/protocol/TxMeta.h index 6d61a27e833..0a6578b1930 100644 --- a/src/ripple/protocol/TxMeta.h +++ b/src/ripple/protocol/TxMeta.h @@ -84,7 +84,7 @@ class TxMeta /** Return a list of accounts affected by this transaction */ boost::container::flat_set - getAffectedAccounts(beast::Journal j) const; + getAffectedAccounts() const; Json::Value getJson(JsonOptions p) const diff --git a/src/ripple/protocol/impl/TxMeta.cpp b/src/ripple/protocol/impl/TxMeta.cpp index 6030ff89cde..9e199176515 100644 --- a/src/ripple/protocol/impl/TxMeta.cpp +++ b/src/ripple/protocol/impl/TxMeta.cpp @@ -112,7 +112,7 @@ TxMeta::setAffectedNode( } boost::container::flat_set -TxMeta::getAffectedAccounts(beast::Journal j) const +TxMeta::getAffectedAccounts() const { boost::container::flat_set list; list.reserve(10); @@ -147,6 +147,7 @@ TxMeta::getAffectedAccounts(beast::Journal j) const { const STAmount* lim = dynamic_cast(&field); + assert(lim); if (lim != nullptr) { @@ -155,11 +156,6 @@ TxMeta::getAffectedAccounts(beast::Journal j) const if (issuer.isNonZero()) list.insert(issuer); } - else - { - JLOG(j.fatal()) << "limit is not amount " - << field.getJson(JsonOptions::none); - } } } } diff --git a/src/ripple/protocol/jss.h b/src/ripple/protocol/jss.h index a227af42982..bd9edd02eff 100644 --- a/src/ripple/protocol/jss.h +++ b/src/ripple/protocol/jss.h @@ -41,6 +41,7 @@ namespace jss { error: Common properties of RPC error responses. */ +JSS(AL_size); // out: GetCounts JSS(AL_hit_rate); // out: GetCounts JSS(Account); // in: TransactionSign; field. JSS(AccountDelete); // transaction type. diff --git a/src/ripple/rpc/handlers/GetCounts.cpp b/src/ripple/rpc/handlers/GetCounts.cpp index d59e7014b1a..acb306449df 100644 --- a/src/ripple/rpc/handlers/GetCounts.cpp +++ b/src/ripple/rpc/handlers/GetCounts.cpp @@ -109,6 +109,7 @@ getCountsJson(Application& app, int minObjectCount) static_cast(app.getInboundLedgers().fetchRate()); ret[jss::SLE_hit_rate] = app.cachedSLEs().rate(); ret[jss::ledger_hit_rate] = app.getLedgerMaster().getCacheHitRate(); + ret[jss::AL_size] = Json::UInt(app.getAcceptedLedgerCache().size()); ret[jss::AL_hit_rate] = app.getAcceptedLedgerCache().getHitRate(); ret[jss::fullbelow_size] =