mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-25 13:35:54 +00:00
Accept ledgers more efficiently by avoiding allocate/allocate/copy/copy/free cycles.
This commit is contained in:
@@ -49,12 +49,11 @@ void ALTransaction::buildJson()
|
||||
|
||||
if (!mAffected.empty())
|
||||
{
|
||||
Json::Value affected(Json::arrayValue);
|
||||
Json::Value& affected = (mJson["affected"] = Json::arrayValue);
|
||||
BOOST_FOREACH(const RippleAddress& ra, mAffected)
|
||||
{
|
||||
affected.append(ra.humanAccountID());
|
||||
}
|
||||
mJson["affected"] = affected;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,7 +63,7 @@ AcceptedLedger::AcceptedLedger(Ledger::ref ledger) : mLedger(ledger)
|
||||
for (SHAMapItem::pointer item = txSet.peekFirstItem(); !!item; item = txSet.peekNextItem(item->getTag()))
|
||||
{
|
||||
SerializerIterator sit(item->peekSerializer());
|
||||
insert(ALTransaction(ledger->getLedgerSeq(), sit));
|
||||
insert(boost::make_shared<ALTransaction>(ledger->getLedgerSeq(), sit));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,16 +77,16 @@ AcceptedLedger::pointer AcceptedLedger::makeAcceptedLedger(Ledger::ref ledger)
|
||||
return ret;
|
||||
}
|
||||
|
||||
void AcceptedLedger::insert(const ALTransaction& at)
|
||||
void AcceptedLedger::insert(ALTransaction::ref at)
|
||||
{
|
||||
assert(mMap.find(at.getIndex()) == mMap.end());
|
||||
mMap.insert(std::make_pair(at.getIndex(), at));
|
||||
assert(mMap.find(at->getIndex()) == mMap.end());
|
||||
mMap.insert(std::make_pair(at->getIndex(), at));
|
||||
}
|
||||
|
||||
const ALTransaction* AcceptedLedger::getTxn(int i) const
|
||||
ALTransaction::pointer AcceptedLedger::getTxn(int i) const
|
||||
{
|
||||
map_t::const_iterator it = mMap.find(i);
|
||||
if (it == mMap.end())
|
||||
return NULL;
|
||||
return &it->second;
|
||||
return ALTransaction::pointer();
|
||||
return it->second;
|
||||
}
|
||||
|
||||
@@ -19,6 +19,8 @@ protected:
|
||||
void buildJson();
|
||||
|
||||
public:
|
||||
typedef boost::shared_ptr<ALTransaction> pointer;
|
||||
typedef const pointer& ref;
|
||||
|
||||
ALTransaction(uint32 ledgerSeq, SerializerIterator& sit);
|
||||
ALTransaction(SerializedTransaction::ref, TransactionMetaSet::ref);
|
||||
@@ -42,17 +44,17 @@ public:
|
||||
class AcceptedLedger
|
||||
{
|
||||
public:
|
||||
typedef boost::shared_ptr<AcceptedLedger> pointer;
|
||||
typedef const pointer& ret;
|
||||
typedef std::map<int, ALTransaction> map_t; // Must be an ordered map!
|
||||
typedef map_t::value_type value_type;
|
||||
typedef map_t::const_iterator const_iterator;
|
||||
typedef boost::shared_ptr<AcceptedLedger> pointer;
|
||||
typedef const pointer& ret;
|
||||
typedef std::map<int, ALTransaction::pointer> map_t; // Must be an ordered map!
|
||||
typedef map_t::value_type value_type;
|
||||
typedef map_t::const_iterator const_iterator;
|
||||
|
||||
protected:
|
||||
Ledger::pointer mLedger;
|
||||
map_t mMap;
|
||||
|
||||
void insert(const ALTransaction&);
|
||||
void insert(ALTransaction::ref);
|
||||
|
||||
static TaggedCache<uint256, AcceptedLedger> ALCache;
|
||||
AcceptedLedger(Ledger::ref ledger);
|
||||
@@ -68,7 +70,7 @@ public:
|
||||
int getLedgerSeq() const { return mLedger->getLedgerSeq(); }
|
||||
int getTxnCount() const { return mMap.size(); }
|
||||
|
||||
const ALTransaction* getTxn(int) const;
|
||||
ALTransaction::pointer getTxn(int) const;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -471,12 +471,12 @@ void Ledger::saveAcceptedLedger(Job&, bool fromConsensus)
|
||||
|
||||
BOOST_FOREACH(const AcceptedLedger::value_type& vt, aLedger->getMap())
|
||||
{
|
||||
uint256 txID = vt.second.getTransactionID();
|
||||
uint256 txID = vt.second->getTransactionID();
|
||||
theApp->getMasterTransaction().inLedger(txID, mLedgerSeq);
|
||||
|
||||
db->executeSQL(boost::str(deleteAcctTrans % txID.GetHex()));
|
||||
|
||||
const std::vector<RippleAddress>& accts = vt.second.getAffected();
|
||||
const std::vector<RippleAddress>& accts = vt.second->getAffected();
|
||||
if (!accts.empty())
|
||||
{
|
||||
std::string sql = "INSERT INTO AccountTransactions (TransID, Account, LedgerSeq, TxnSeq) VALUES ";
|
||||
@@ -496,7 +496,7 @@ void Ledger::saveAcceptedLedger(Job&, bool fromConsensus)
|
||||
sql += "',";
|
||||
sql += boost::lexical_cast<std::string>(getLedgerSeq());
|
||||
sql += ",";
|
||||
sql += boost::lexical_cast<std::string>(vt.second.getTxnSeq());
|
||||
sql += boost::lexical_cast<std::string>(vt.second->getTxnSeq());
|
||||
sql += ")";
|
||||
}
|
||||
sql += ";";
|
||||
@@ -507,7 +507,7 @@ void Ledger::saveAcceptedLedger(Job&, bool fromConsensus)
|
||||
cLog(lsWARNING) << "Transaction in ledger " << mLedgerSeq << " affects no accounts";
|
||||
|
||||
db->executeSQL(SerializedTransaction::getMetaSQLInsertReplaceHeader() +
|
||||
vt.second.getTxn()->getMetaSQL(getLedgerSeq(), vt.second.getEscMeta()) + ";");
|
||||
vt.second->getTxn()->getMetaSQL(getLedgerSeq(), vt.second->getEscMeta()) + ";");
|
||||
}
|
||||
db->executeSQL("COMMIT TRANSACTION;");
|
||||
}
|
||||
|
||||
@@ -1439,8 +1439,8 @@ void NetworkOPs::pubLedger(Ledger::ref accepted)
|
||||
{
|
||||
BOOST_FOREACH(const AcceptedLedger::value_type& vt, alpAccepted->getMap())
|
||||
{
|
||||
cLog(lsTRACE) << "pubAccepted: " << vt.second.getJson();
|
||||
pubValidatedTransaction(lpAccepted, vt.second);
|
||||
cLog(lsTRACE) << "pubAccepted: " << vt.second->getJson();
|
||||
pubValidatedTransaction(lpAccepted, *vt.second);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user