Make getSLEi more useful.

This commit is contained in:
JoelKatz
2013-02-21 09:47:34 -08:00
parent 5451e20eaa
commit 53b622db75
5 changed files with 33 additions and 9 deletions

View File

@@ -966,6 +966,7 @@ SLE::pointer Ledger::getSLEi(const uint256& uId)
if (!ret) if (!ret)
{ {
ret = boost::make_shared<SLE>(node->peekSerializer(), node->getTag()); ret = boost::make_shared<SLE>(node->peekSerializer(), node->getTag());
ret->setImmutable();
theApp->getSLECache().canonicalize(hash, ret); theApp->getSLECache().canonicalize(hash, ret);
} }
return ret; return ret;
@@ -1011,6 +1012,14 @@ uint256 Ledger::getPrevLedgerIndex(const uint256& uHash, const uint256& uBegin)
return node->getTag(); return node->getTag();
} }
SLE::pointer Ledger::getASNodeI(const uint256& nodeID, LedgerEntryType let)
{
SLE::pointer node = getSLEi(nodeID);
if (node && (node->getType() != let))
node.reset();
return node;
}
SLE::pointer Ledger::getASNode(LedgerStateParms& parms, const uint256& nodeID, SLE::pointer Ledger::getASNode(LedgerStateParms& parms, const uint256& nodeID,
LedgerEntryType let ) LedgerEntryType let )
{ {
@@ -1047,16 +1056,12 @@ SLE::pointer Ledger::getASNode(LedgerStateParms& parms, const uint256& nodeID,
SLE::pointer Ledger::getAccountRoot(const uint160& accountID) SLE::pointer Ledger::getAccountRoot(const uint160& accountID)
{ {
LedgerStateParms qry = lepNONE; return getASNodeI(getAccountRootIndex(accountID), ltACCOUNT_ROOT);
return getASNode(qry, getAccountRootIndex(accountID), ltACCOUNT_ROOT);
} }
SLE::pointer Ledger::getAccountRoot(const RippleAddress& naAccountID) SLE::pointer Ledger::getAccountRoot(const RippleAddress& naAccountID)
{ {
LedgerStateParms qry = lepNONE; return getASNodeI(getAccountRootIndex(naAccountID.getAccountID()), ltACCOUNT_ROOT);
return getASNode(qry, getAccountRootIndex(naAccountID.getAccountID()), ltACCOUNT_ROOT);
} }
// //

View File

@@ -97,6 +97,9 @@ private:
protected: protected:
SLE::pointer getASNode(LedgerStateParms& parms, const uint256& nodeID, LedgerEntryType let); SLE::pointer getASNode(LedgerStateParms& parms, const uint256& nodeID, LedgerEntryType let);
// returned SLE is immutable
SLE::pointer getASNodeI(const uint256& nodeID, LedgerEntryType let);
static void incPendingSaves(); static void incPendingSaves();
static void decPendingSaves(); static void decPendingSaves();
void saveAcceptedLedger(bool fromConsensus, LoadEvent::pointer); void saveAcceptedLedger(bool fromConsensus, LoadEvent::pointer);

View File

@@ -107,6 +107,7 @@ LedgerEntryAction LedgerEntrySet::hasEntry(const uint256& index) const
void LedgerEntrySet::entryCache(SLE::ref sle) void LedgerEntrySet::entryCache(SLE::ref sle)
{ {
assert(sle->isMutable());
std::map<uint256, LedgerEntrySetEntry>::iterator it = mEntries.find(sle->getIndex()); std::map<uint256, LedgerEntrySetEntry>::iterator it = mEntries.find(sle->getIndex());
if (it == mEntries.end()) if (it == mEntries.end())
{ {
@@ -128,6 +129,7 @@ void LedgerEntrySet::entryCache(SLE::ref sle)
void LedgerEntrySet::entryCreate(SLE::ref sle) void LedgerEntrySet::entryCreate(SLE::ref sle)
{ {
assert(sle->isMutable());
std::map<uint256, LedgerEntrySetEntry>::iterator it = mEntries.find(sle->getIndex()); std::map<uint256, LedgerEntrySetEntry>::iterator it = mEntries.find(sle->getIndex());
if (it == mEntries.end()) if (it == mEntries.end())
{ {
@@ -161,6 +163,7 @@ void LedgerEntrySet::entryCreate(SLE::ref sle)
void LedgerEntrySet::entryModify(SLE::ref sle) void LedgerEntrySet::entryModify(SLE::ref sle)
{ {
assert(sle->isMutable());
std::map<uint256, LedgerEntrySetEntry>::iterator it = mEntries.find(sle->getIndex()); std::map<uint256, LedgerEntrySetEntry>::iterator it = mEntries.find(sle->getIndex());
if (it == mEntries.end()) if (it == mEntries.end())
{ {
@@ -193,6 +196,7 @@ void LedgerEntrySet::entryModify(SLE::ref sle)
void LedgerEntrySet::entryDelete(SLE::ref sle) void LedgerEntrySet::entryDelete(SLE::ref sle)
{ {
assert(sle->isMutable());
std::map<uint256, LedgerEntrySetEntry>::iterator it = mEntries.find(sle->getIndex()); std::map<uint256, LedgerEntrySetEntry>::iterator it = mEntries.find(sle->getIndex());
if (it == mEntries.end()) if (it == mEntries.end())
{ {

View File

@@ -9,7 +9,7 @@ DECLARE_INSTANCE(SerializedLedgerEntry)
SETUP_LOG(); SETUP_LOG();
SerializedLedgerEntry::SerializedLedgerEntry(SerializerIterator& sit, const uint256& index) SerializedLedgerEntry::SerializedLedgerEntry(SerializerIterator& sit, const uint256& index)
: STObject(sfLedgerEntry), mIndex(index) : STObject(sfLedgerEntry), mIndex(index), mMutable(true)
{ {
set(sit); set(sit);
uint16 type = getFieldU16(sfLedgerEntryType); uint16 type = getFieldU16(sfLedgerEntryType);
@@ -22,7 +22,7 @@ SerializedLedgerEntry::SerializedLedgerEntry(SerializerIterator& sit, const uint
} }
SerializedLedgerEntry::SerializedLedgerEntry(const Serializer& s, const uint256& index) SerializedLedgerEntry::SerializedLedgerEntry(const Serializer& s, const uint256& index)
: STObject(sfLedgerEntry), mIndex(index) : STObject(sfLedgerEntry), mIndex(index), mMutable(true)
{ {
SerializerIterator sit(const_cast<Serializer&>(s)); // we know 's' isn't going away SerializerIterator sit(const_cast<Serializer&>(s)); // we know 's' isn't going away
set(sit); set(sit);
@@ -41,7 +41,7 @@ SerializedLedgerEntry::SerializedLedgerEntry(const Serializer& s, const uint256&
} }
SerializedLedgerEntry::SerializedLedgerEntry(LedgerEntryType type, const uint256& index) : SerializedLedgerEntry::SerializedLedgerEntry(LedgerEntryType type, const uint256& index) :
STObject(sfLedgerEntry), mIndex(index), mType(type) STObject(sfLedgerEntry), mIndex(index), mType(type), mMutable(true)
{ {
mFormat = LedgerEntryFormat::getLgrFormat(type); mFormat = LedgerEntryFormat::getLgrFormat(type);
if (mFormat == NULL) throw std::runtime_error("invalid ledger entry type"); if (mFormat == NULL) throw std::runtime_error("invalid ledger entry type");
@@ -49,6 +49,13 @@ SerializedLedgerEntry::SerializedLedgerEntry(LedgerEntryType type, const uint256
setFieldU16(sfLedgerEntryType, static_cast<uint16>(mFormat->t_type)); setFieldU16(sfLedgerEntryType, static_cast<uint16>(mFormat->t_type));
} }
SerializedLedgerEntry::pointer SerializedLedgerEntry::getMutable() const
{
SerializedLedgerEntry::pointer ret = boost::make_shared<SerializedLedgerEntry>(boost::ref(*this));
ret->mMutable = true;
return ret;
}
std::string SerializedLedgerEntry::getFullText() const std::string SerializedLedgerEntry::getFullText() const
{ {
std::string ret = "\""; std::string ret = "\"";

View File

@@ -18,6 +18,7 @@ protected:
uint256 mIndex; uint256 mIndex;
LedgerEntryType mType; LedgerEntryType mType;
const LedgerEntryFormat* mFormat; const LedgerEntryFormat* mFormat;
bool mMutable;
SerializedLedgerEntry* duplicate() const { return new SerializedLedgerEntry(*this); } SerializedLedgerEntry* duplicate() const { return new SerializedLedgerEntry(*this); }
@@ -34,6 +35,10 @@ public:
const uint256& getIndex() const { return mIndex; } const uint256& getIndex() const { return mIndex; }
void setIndex(const uint256& i) { mIndex = i; } void setIndex(const uint256& i) { mIndex = i; }
void setImmutable() { mMutable = false; }
bool isMutable() { return mMutable; }
SerializedLedgerEntry::pointer getMutable() const;
LedgerEntryType getType() const { return mType; } LedgerEntryType getType() const { return mType; }
uint16 getVersion() const { return getFieldU16(sfLedgerEntryType); } uint16 getVersion() const { return getFieldU16(sfLedgerEntryType); }
const LedgerEntryFormat* getFormat() { return mFormat; } const LedgerEntryFormat* getFormat() { return mFormat; }