mirror of
https://github.com/XRPLF/rippled.git
synced 2026-08-22 23:00:55 +00:00
Cleanup AcceptedLedger and AcceptedLedgerTx:
This commit modernizes the `AcceptedLedger` and `AcceptedLedgerTx` classes, reduces their memory footprint and reduces unnecessary dynamic memory allocations.
This commit is contained in:
committed by
manojsdoshi
parent
c7e6803956
commit
8f58687091
@@ -19,8 +19,7 @@
|
||||
|
||||
#include <ripple/app/ledger/AcceptedLedger.h>
|
||||
#include <ripple/app/main/Application.h>
|
||||
#include <ripple/basics/Log.h>
|
||||
#include <ripple/basics/chrono.h>
|
||||
#include <algorithm>
|
||||
|
||||
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<AcceptedLedgerTx>(
|
||||
ledger,
|
||||
item.first,
|
||||
item.second,
|
||||
app.accountIDCache(),
|
||||
app.logs()));
|
||||
}
|
||||
transactions_.emplace_back(std::make_unique<AcceptedLedgerTx>(
|
||||
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
|
||||
|
||||
@@ -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<AcceptedLedger>
|
||||
{
|
||||
public:
|
||||
using pointer = std::shared_ptr<AcceptedLedger>;
|
||||
using ret = const pointer&;
|
||||
using map_t = std::map<int, AcceptedLedgerTx::pointer>;
|
||||
// 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<ReadView const> const& ledger,
|
||||
Application& app);
|
||||
|
||||
public:
|
||||
std::shared_ptr<ReadView const> 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<ReadView const> const& ledger,
|
||||
Application& app);
|
||||
auto
|
||||
end() const
|
||||
{
|
||||
return transactions_.end();
|
||||
}
|
||||
|
||||
private:
|
||||
void insert(AcceptedLedgerTx::ref);
|
||||
|
||||
std::shared_ptr<ReadView const> mLedger;
|
||||
map_t mMap;
|
||||
std::vector<std::unique_ptr<AcceptedLedgerTx>> transactions_;
|
||||
};
|
||||
|
||||
} // namespace ripple
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
//==============================================================================
|
||||
|
||||
#include <ripple/app/ledger/AcceptedLedgerTx.h>
|
||||
#include <ripple/app/main/Application.h>
|
||||
#include <ripple/basics/Log.h>
|
||||
#include <ripple/basics/StringUtilities.h>
|
||||
#include <ripple/protocol/UintTypes.h>
|
||||
@@ -30,72 +29,30 @@ AcceptedLedgerTx::AcceptedLedgerTx(
|
||||
std::shared_ptr<ReadView const> const& ledger,
|
||||
std::shared_ptr<STTx const> const& txn,
|
||||
std::shared_ptr<STObject const> const& met,
|
||||
AccountIDCache const& accountCache,
|
||||
Logs& logs)
|
||||
: mLedger(ledger)
|
||||
, mTxn(txn)
|
||||
, mMeta(std::make_shared<TxMeta>(
|
||||
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<ReadView const> const& ledger,
|
||||
std::shared_ptr<STTx const> 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
|
||||
|
||||
@@ -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<AcceptedLedgerTx>
|
||||
{
|
||||
public:
|
||||
using pointer = std::shared_ptr<AcceptedLedgerTx>;
|
||||
using ref = const pointer&;
|
||||
|
||||
public:
|
||||
AcceptedLedgerTx(
|
||||
std::shared_ptr<ReadView const> const& ledger,
|
||||
std::shared_ptr<STTx const> const&,
|
||||
std::shared_ptr<STObject const> const&,
|
||||
AccountIDCache const&,
|
||||
Logs&);
|
||||
AcceptedLedgerTx(
|
||||
std::shared_ptr<ReadView const> const&,
|
||||
std::shared_ptr<STTx const> const&,
|
||||
TER,
|
||||
AccountIDCache const&,
|
||||
Logs&);
|
||||
AccountIDCache const&);
|
||||
|
||||
std::shared_ptr<STTx const> const&
|
||||
getTxn() const
|
||||
{
|
||||
return mTxn;
|
||||
}
|
||||
std::shared_ptr<TxMeta> const&
|
||||
TxMeta const&
|
||||
getMeta() const
|
||||
{
|
||||
return mMeta;
|
||||
@@ -97,45 +79,28 @@ public:
|
||||
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<ReadView const> mLedger;
|
||||
std::shared_ptr<STTx const> mTxn;
|
||||
std::shared_ptr<TxMeta> mMeta;
|
||||
TER mResult;
|
||||
TxMeta mMeta;
|
||||
boost::container::flat_set<AccountID> mAffected;
|
||||
Blob mRawMeta;
|
||||
Json::Value mJson;
|
||||
AccountIDCache const& accountCache_;
|
||||
Logs& logs_;
|
||||
|
||||
void
|
||||
buildJson();
|
||||
};
|
||||
|
||||
} // namespace ripple
|
||||
|
||||
@@ -245,10 +245,7 @@ OrderBookDB::processTxn(
|
||||
// single client has subscribed to those books.
|
||||
hash_set<std::uint64_t> 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
|
||||
{
|
||||
|
||||
@@ -445,9 +445,9 @@ public:
|
||||
pubLedger(std::shared_ptr<ReadView const> const& lpAccepted) override;
|
||||
void
|
||||
pubProposedTransaction(
|
||||
std::shared_ptr<ReadView const> const& lpCurrent,
|
||||
std::shared_ptr<STTx const> const& stTxn,
|
||||
TER terResult) override;
|
||||
std::shared_ptr<ReadView const> const& ledger,
|
||||
std::shared_ptr<STTx const> const& transaction,
|
||||
TER result) override;
|
||||
void
|
||||
pubValidation(std::shared_ptr<STValidation> const& val) override;
|
||||
|
||||
@@ -612,20 +612,26 @@ private:
|
||||
|
||||
Json::Value
|
||||
transJson(
|
||||
const STTx& stTxn,
|
||||
TER terResult,
|
||||
bool bValidated,
|
||||
std::shared_ptr<ReadView const> const& lpCurrent);
|
||||
const STTx& transaction,
|
||||
TER result,
|
||||
bool validated,
|
||||
std::shared_ptr<ReadView const> const& ledger);
|
||||
|
||||
void
|
||||
pubValidatedTransaction(
|
||||
std::shared_ptr<ReadView const> const& alAccepted,
|
||||
const AcceptedLedgerTx& alTransaction);
|
||||
std::shared_ptr<ReadView const> const& ledger,
|
||||
AcceptedLedgerTx const& transaction);
|
||||
|
||||
void
|
||||
pubAccountTransaction(
|
||||
std::shared_ptr<ReadView const> const& lpCurrent,
|
||||
const AcceptedLedgerTx& alTransaction,
|
||||
bool isAccepted);
|
||||
std::shared_ptr<ReadView const> const& ledger,
|
||||
AcceptedLedgerTx const& transaction);
|
||||
|
||||
void
|
||||
pubProposedAccountTransaction(
|
||||
std::shared_ptr<ReadView const> const& ledger,
|
||||
std::shared_ptr<STTx const> const& transaction,
|
||||
TER result);
|
||||
|
||||
void
|
||||
pubServer();
|
||||
@@ -2643,11 +2649,11 @@ NetworkOPsImp::getLedgerFetchInfo()
|
||||
|
||||
void
|
||||
NetworkOPsImp::pubProposedTransaction(
|
||||
std::shared_ptr<ReadView const> const& lpCurrent,
|
||||
std::shared_ptr<STTx const> const& stTxn,
|
||||
TER terResult)
|
||||
std::shared_ptr<ReadView const> const& ledger,
|
||||
std::shared_ptr<STTx const> 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<ReadView const> 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<ReadView const> 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<ReadView const> 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<ReadView const> 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<ReadView const> const& lpCurrent)
|
||||
const STTx& transaction,
|
||||
TER result,
|
||||
bool validated,
|
||||
std::shared_ptr<ReadView const> 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<ReadView const> const& alAccepted,
|
||||
const AcceptedLedgerTx& alTx)
|
||||
std::shared_ptr<ReadView const> const& ledger,
|
||||
const AcceptedLedgerTx& transaction)
|
||||
{
|
||||
std::shared_ptr<STTx const> 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<ReadView const> const& lpCurrent,
|
||||
const AcceptedLedgerTx& alTx,
|
||||
bool bAccepted)
|
||||
std::shared_ptr<ReadView const> const& ledger,
|
||||
AcceptedLedgerTx const& transaction)
|
||||
{
|
||||
hash_set<InfoSub::pointer> notify;
|
||||
int iProposed = 0;
|
||||
int iAccepted = 0;
|
||||
|
||||
std::vector<SubAccountHistoryInfo> 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())
|
||||
{
|
||||
auto& subs = histoIt->second;
|
||||
auto it = subs.begin();
|
||||
while (it != subs.end())
|
||||
{
|
||||
SubAccountHistoryInfoWeak const& info = it->second;
|
||||
if (currLedgerSeq <= info.index_->separationLedgerSeq_)
|
||||
{
|
||||
++it;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (auto isSptr = info.sinkWptr_.lock(); isSptr)
|
||||
{
|
||||
accountHistoryNotify.emplace_back(
|
||||
SubAccountHistoryInfo{isSptr, info.index_});
|
||||
++it;
|
||||
}
|
||||
else
|
||||
{
|
||||
it = subs.erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
if (auto histoIt = mSubAccountHistory.find(affectedAccount);
|
||||
histoIt != mSubAccountHistory.end())
|
||||
{
|
||||
auto& subs = histoIt->second;
|
||||
auto it = subs.begin();
|
||||
while (it != subs.end())
|
||||
{
|
||||
SubAccountHistoryInfoWeak const& info = it->second;
|
||||
if (currLedgerSeq <=
|
||||
info.index_->separationLedgerSeq_)
|
||||
{
|
||||
++it;
|
||||
continue;
|
||||
}
|
||||
|
||||
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<STTx const> stTxn = alTx.getTxn();
|
||||
Json::Value jvObj =
|
||||
transJson(*stTxn, alTx.getResult(), bAccepted, lpCurrent);
|
||||
auto const& stTxn = transaction.getTxn();
|
||||
|
||||
Json::Value jvObj =
|
||||
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<ReadView const> const& ledger,
|
||||
std::shared_ptr<STTx const> const& tx,
|
||||
TER result)
|
||||
{
|
||||
hash_set<InfoSub::pointer> notify;
|
||||
int iProposed = 0;
|
||||
|
||||
std::vector<SubAccountHistoryInfo> 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);
|
||||
|
||||
@@ -255,9 +255,9 @@ public:
|
||||
pubLedger(std::shared_ptr<ReadView const> const& lpAccepted) = 0;
|
||||
virtual void
|
||||
pubProposedTransaction(
|
||||
std::shared_ptr<ReadView const> const& lpCurrent,
|
||||
std::shared_ptr<STTx const> const& stTxn,
|
||||
TER terResult) = 0;
|
||||
std::shared_ptr<ReadView const> const& ledger,
|
||||
std::shared_ptr<STTx const> const& transaction,
|
||||
TER result) = 0;
|
||||
virtual void
|
||||
pubValidation(std::shared_ptr<STValidation> const& val) = 0;
|
||||
|
||||
|
||||
@@ -125,7 +125,7 @@ public:
|
||||
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())
|
||||
|
||||
@@ -222,7 +222,7 @@ saveValidatedLedger(
|
||||
hotLEDGER, std::move(s.modData()), ledger->info().hash, seq);
|
||||
}
|
||||
|
||||
AcceptedLedger::pointer aLedger;
|
||||
std::shared_ptr<AcceptedLedger> 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
|
||||
|
||||
@@ -79,7 +79,8 @@ saveLedgerMeta(
|
||||
|
||||
if (app.config().useTxTables())
|
||||
{
|
||||
AcceptedLedger::pointer const aLedger = [&app, ledger] {
|
||||
auto const aLedger = [&app,
|
||||
ledger]() -> std::shared_ptr<AcceptedLedger> {
|
||||
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())};
|
||||
|
||||
@@ -84,7 +84,7 @@ public:
|
||||
|
||||
/** Return a list of accounts affected by this transaction */
|
||||
boost::container::flat_set<AccountID>
|
||||
getAffectedAccounts(beast::Journal j) const;
|
||||
getAffectedAccounts() const;
|
||||
|
||||
Json::Value
|
||||
getJson(JsonOptions p) const
|
||||
|
||||
@@ -112,7 +112,7 @@ TxMeta::setAffectedNode(
|
||||
}
|
||||
|
||||
boost::container::flat_set<AccountID>
|
||||
TxMeta::getAffectedAccounts(beast::Journal j) const
|
||||
TxMeta::getAffectedAccounts() const
|
||||
{
|
||||
boost::container::flat_set<AccountID> list;
|
||||
list.reserve(10);
|
||||
@@ -147,6 +147,7 @@ TxMeta::getAffectedAccounts(beast::Journal j) const
|
||||
{
|
||||
const STAmount* lim =
|
||||
dynamic_cast<const STAmount*>(&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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -109,6 +109,7 @@ getCountsJson(Application& app, int minObjectCount)
|
||||
static_cast<int>(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] =
|
||||
|
||||
Reference in New Issue
Block a user