mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
You can now create a LedgerEntrySet without a TransactionEngine. You can
call all the various entry* functions on it directly. You can throw it out
when you're done. The constructor is:
LedgerEntrySet(Ledger::ref ledger)
All the normal checkpointing, caching, and swapping will work. Of course,
you cannot commit the results. The TransactionEngine::entry* functions now
just directly call the corresponding functions on the LedgerEntrySet. You
can call them in code that will only be used in the context of a
transaction.
This commit is contained in:
@@ -2,9 +2,10 @@
|
||||
|
||||
#include <boost/make_shared.hpp>
|
||||
|
||||
void LedgerEntrySet::init(const uint256& transactionID, uint32 ledgerID)
|
||||
void LedgerEntrySet::init(Ledger::ref ledger, const uint256& transactionID, uint32 ledgerID)
|
||||
{
|
||||
mEntries.clear();
|
||||
mLedger = ledger;
|
||||
mSet.init(transactionID, ledgerID);
|
||||
mSeq = 0;
|
||||
}
|
||||
@@ -17,7 +18,7 @@ void LedgerEntrySet::clear()
|
||||
|
||||
LedgerEntrySet LedgerEntrySet::duplicate() const
|
||||
{
|
||||
return LedgerEntrySet(mEntries, mSet, mSeq + 1);
|
||||
return LedgerEntrySet(mLedger, mEntries, mSet, mSeq + 1);
|
||||
}
|
||||
|
||||
void LedgerEntrySet::setTo(const LedgerEntrySet& e)
|
||||
@@ -25,11 +26,13 @@ void LedgerEntrySet::setTo(const LedgerEntrySet& e)
|
||||
mEntries = e.mEntries;
|
||||
mSet = e.mSet;
|
||||
mSeq = e.mSeq;
|
||||
mLedger = e.mLedger;
|
||||
}
|
||||
|
||||
void LedgerEntrySet::swapWith(LedgerEntrySet& e)
|
||||
{
|
||||
std::swap(mSeq, e.mSeq);
|
||||
std::swap(mLedger, e.mLedger);
|
||||
mSet.swap(e.mSet);
|
||||
mEntries.swap(e.mEntries);
|
||||
}
|
||||
@@ -53,6 +56,36 @@ SLE::pointer LedgerEntrySet::getEntry(const uint256& index, LedgerEntryAction& a
|
||||
return it->second.mEntry;
|
||||
}
|
||||
|
||||
SLE::pointer LedgerEntrySet::entryCreate(LedgerEntryType letType, const uint256& index)
|
||||
{
|
||||
assert(index.isNonZero());
|
||||
SLE::pointer sleNew = boost::make_shared<SLE>(letType);
|
||||
sleNew->setIndex(index);
|
||||
entryCreate(sleNew);
|
||||
return sleNew;
|
||||
}
|
||||
|
||||
SLE::pointer LedgerEntrySet::entryCache(LedgerEntryType letType, const uint256& index)
|
||||
{
|
||||
SLE::pointer sleEntry;
|
||||
if (index.isNonZero())
|
||||
{
|
||||
LedgerEntryAction action;
|
||||
sleEntry = getEntry(index, action);
|
||||
if (!sleEntry)
|
||||
{
|
||||
sleEntry = mLedger->getSLE(index);
|
||||
if (sleEntry)
|
||||
entryCache(sleEntry);
|
||||
}
|
||||
else if (action == taaDELETE)
|
||||
{
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
return sleEntry;
|
||||
}
|
||||
|
||||
LedgerEntryAction LedgerEntrySet::hasEntry(const uint256& index) const
|
||||
{
|
||||
boost::unordered_map<uint256, LedgerEntrySetEntry>::const_iterator it = mEntries.find(index);
|
||||
@@ -147,7 +180,7 @@ void LedgerEntrySet::entryModify(SLE::ref sle)
|
||||
}
|
||||
}
|
||||
|
||||
void LedgerEntrySet::entryDelete(SLE::ref sle, bool unfunded)
|
||||
void LedgerEntrySet::entryDelete(SLE::ref sle)
|
||||
{
|
||||
boost::unordered_map<uint256, LedgerEntrySetEntry>::iterator it = mEntries.find(sle->getIndex());
|
||||
if (it == mEntries.end())
|
||||
@@ -166,15 +199,6 @@ void LedgerEntrySet::entryDelete(SLE::ref sle, bool unfunded)
|
||||
it->second.mSeq = mSeq;
|
||||
it->second.mEntry = sle;
|
||||
it->second.mAction = taaDELETE;
|
||||
if (unfunded)
|
||||
{
|
||||
assert(sle->getType() == ltOFFER); // only offers can be unfunded
|
||||
#if 0
|
||||
mSet.deleteUnfunded(sle->getIndex(),
|
||||
sle->getIValueFieldAmount(sfTakerPays),
|
||||
sle->getIValueFieldAmount(sfTakerGets));
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
|
||||
case taaCREATE:
|
||||
|
||||
@@ -31,12 +31,13 @@ public:
|
||||
class LedgerEntrySet
|
||||
{
|
||||
protected:
|
||||
Ledger::pointer mLedger;
|
||||
boost::unordered_map<uint256, LedgerEntrySetEntry> mEntries;
|
||||
TransactionMetaSet mSet;
|
||||
int mSeq;
|
||||
|
||||
LedgerEntrySet(const boost::unordered_map<uint256, LedgerEntrySetEntry> &e, const TransactionMetaSet& s, int m) :
|
||||
mEntries(e), mSet(s), mSeq(m) { ; }
|
||||
LedgerEntrySet(Ledger::ref ledger, const boost::unordered_map<uint256, LedgerEntrySetEntry> &e,
|
||||
const TransactionMetaSet& s, int m) : mLedger(ledger), mEntries(e), mSet(s), mSeq(m) { ; }
|
||||
|
||||
SLE::pointer getForMod(const uint256& node, Ledger::ref ledger,
|
||||
boost::unordered_map<uint256, SLE::pointer>& newMods);
|
||||
@@ -51,6 +52,9 @@ protected:
|
||||
boost::unordered_map<uint256, SLE::pointer>& newMods);
|
||||
|
||||
public:
|
||||
|
||||
LedgerEntrySet(Ledger::ref ledger) : mLedger(ledger), mSeq(0) { ; }
|
||||
|
||||
LedgerEntrySet() : mSeq(0) { ; }
|
||||
|
||||
// set functions
|
||||
@@ -60,7 +64,7 @@ public:
|
||||
|
||||
int getSeq() const { return mSeq; }
|
||||
void bumpSeq() { ++mSeq; }
|
||||
void init(const uint256& transactionID, uint32 ledgerID);
|
||||
void init(Ledger::ref ledger, const uint256& transactionID, uint32 ledgerID);
|
||||
void clear();
|
||||
|
||||
// basic entry functions
|
||||
@@ -68,14 +72,18 @@ public:
|
||||
LedgerEntryAction hasEntry(const uint256& index) const;
|
||||
void entryCache(SLE::ref); // Add this entry to the cache
|
||||
void entryCreate(SLE::ref); // This entry will be created
|
||||
void entryDelete(SLE::ref, bool unfunded);
|
||||
void entryDelete(SLE::ref); // This entry will be deleted
|
||||
void entryModify(SLE::ref); // This entry will be modified
|
||||
|
||||
// higher-level ledger functions
|
||||
SLE::pointer entryCreate(LedgerEntryType letType, const uint256& uIndex);
|
||||
SLE::pointer entryCache(LedgerEntryType letType, const uint256& uIndex);
|
||||
|
||||
Json::Value getJson(int) const;
|
||||
void calcRawMeta(Serializer&, Ledger::ref originalLedger);
|
||||
|
||||
// iterator functions
|
||||
bool isEmpty() const { return mEntries.empty(); }
|
||||
bool isEmpty() const { return mEntries.empty(); }
|
||||
boost::unordered_map<uint256, LedgerEntrySetEntry>::const_iterator begin() const { return mEntries.begin(); }
|
||||
boost::unordered_map<uint256, LedgerEntrySetEntry>::const_iterator end() const { return mEntries.end(); }
|
||||
boost::unordered_map<uint256, LedgerEntrySetEntry>::iterator begin() { return mEntries.begin(); }
|
||||
|
||||
@@ -865,50 +865,6 @@ TER TransactionEngine::setAuthorized(const SerializedTransaction& txn, bool bMus
|
||||
return tesSUCCESS;
|
||||
}
|
||||
|
||||
SLE::pointer TransactionEngine::entryCache(LedgerEntryType letType, const uint256& uIndex)
|
||||
{
|
||||
SLE::pointer sleEntry;
|
||||
|
||||
if (!!uIndex)
|
||||
{
|
||||
LedgerEntryAction action;
|
||||
sleEntry = mNodes.getEntry(uIndex, action);
|
||||
if (!sleEntry)
|
||||
{
|
||||
sleEntry = mLedger->getSLE(uIndex);
|
||||
if (sleEntry)
|
||||
mNodes.entryCache(sleEntry);
|
||||
}
|
||||
else if (action == taaDELETE)
|
||||
{
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
|
||||
return sleEntry;
|
||||
}
|
||||
|
||||
SLE::pointer TransactionEngine::entryCreate(LedgerEntryType letType, const uint256& uIndex)
|
||||
{
|
||||
assert(!!uIndex);
|
||||
|
||||
SLE::pointer sleNew = boost::make_shared<SerializedLedgerEntry>(letType);
|
||||
sleNew->setIndex(uIndex);
|
||||
mNodes.entryCreate(sleNew);
|
||||
|
||||
return sleNew;
|
||||
}
|
||||
|
||||
void TransactionEngine::entryDelete(SLE::pointer sleEntry, bool bUnfunded)
|
||||
{
|
||||
mNodes.entryDelete(sleEntry, bUnfunded);
|
||||
}
|
||||
|
||||
void TransactionEngine::entryModify(SLE::pointer sleEntry)
|
||||
{
|
||||
mNodes.entryModify(sleEntry);
|
||||
}
|
||||
|
||||
void TransactionEngine::txnWrite()
|
||||
{
|
||||
// Write back the account states and add the transaction to the ledger
|
||||
@@ -956,12 +912,11 @@ void TransactionEngine::txnWrite()
|
||||
}
|
||||
}
|
||||
|
||||
TER TransactionEngine::applyTransaction(const SerializedTransaction& txn,
|
||||
TransactionEngineParams params)
|
||||
TER TransactionEngine::applyTransaction(const SerializedTransaction& txn, TransactionEngineParams params)
|
||||
{
|
||||
Log(lsTRACE) << "applyTransaction>";
|
||||
assert(mLedger);
|
||||
mNodes.init(txn.getTransactionID(), mLedger->getLedgerSeq());
|
||||
mNodes.init(mLedger, txn.getTransactionID(), mLedger->getLedgerSeq());
|
||||
|
||||
#ifdef DEBUG
|
||||
if (1)
|
||||
|
||||
@@ -308,10 +308,10 @@ protected:
|
||||
// If the transaction fails to meet some constraint, still need to delete unfunded offers.
|
||||
boost::unordered_set<uint256> musUnfundedFound; // Offers that were found unfunded.
|
||||
|
||||
SLE::pointer entryCreate(LedgerEntryType letType, const uint256& uIndex);
|
||||
SLE::pointer entryCache(LedgerEntryType letType, const uint256& uIndex);
|
||||
void entryDelete(SLE::pointer sleEntry, bool bUnfunded = false);
|
||||
void entryModify(SLE::pointer sleEntry);
|
||||
SLE::pointer entryCreate(LedgerEntryType type, const uint256& index) { return mNodes.entryCreate(type, index); }
|
||||
SLE::pointer entryCache(LedgerEntryType type, const uint256& index) { return mNodes.entryCache(type, index); }
|
||||
void entryDelete(SLE::ref sleEntry) { mNodes.entryDelete(sleEntry); }
|
||||
void entryModify(SLE::ref sleEntry) { mNodes.entryModify(sleEntry); }
|
||||
|
||||
TER offerDelete(const uint256& uOfferIndex);
|
||||
TER offerDelete(const SLE::pointer& sleOffer, const uint256& uOfferIndex, const uint160& uOwnerID);
|
||||
|
||||
Reference in New Issue
Block a user