diff --git a/src/cpp/ripple/LedgerEntrySet.cpp b/src/cpp/ripple/LedgerEntrySet.cpp index 78aeb20de..7c24e8094 100644 --- a/src/cpp/ripple/LedgerEntrySet.cpp +++ b/src/cpp/ripple/LedgerEntrySet.cpp @@ -903,6 +903,39 @@ bool LedgerEntrySet::dirNext( return true; } +uint256 LedgerEntrySet::getNextLedgerIndex(const uint256& uHash) +{ + // find next node in ledger that isn't deleted by LES + uint256 ledgerNext = uHash; + std::map::const_iterator it; + do + { + ledgerNext = mLedger->getNextLedgerIndex(ledgerNext); + it = mEntries.find(ledgerNext); + } while ((it != mEntries.end()) && (it->second.mAction == taaDELETE)); + + // find next node in LES that isn't deleted + for (it = mEntries.upper_bound(uHash); it != mEntries.end(); ++it) + { + + // node found in LES, node found in ledger, return earliest + if (it->second.mAction != taaDELETE) + return (ledgerNext < it->first) ? ledgerNext : it->first; + + } + + // nothing next in LES, return next ledger node + return ledgerNext; +} + +uint256 LedgerEntrySet::getNextLedgerIndex(const uint256& uHash, const uint256& uEnd) +{ + uint256 next = getNextLedgerIndex(uHash); + if (next > uEnd) + return uint256(); + return next; +} + // If there is a count, adjust the owner count by iAmount. Otherwise, compute the owner count and store it. void LedgerEntrySet::ownerCountAdjust(const uint160& uOwnerID, int iAmount, SLE::ref sleAccountRoot) { diff --git a/src/cpp/ripple/LedgerEntrySet.h b/src/cpp/ripple/LedgerEntrySet.h index 20c438361..fb9affb7a 100644 --- a/src/cpp/ripple/LedgerEntrySet.h +++ b/src/cpp/ripple/LedgerEntrySet.h @@ -126,6 +126,9 @@ public: bool dirNext(const uint256& uRootIndex, SLE::pointer& sleNode, unsigned int& uDirEntry, uint256& uEntryIndex); TER dirCount(const uint256& uDirIndex, uint32& uCount); + uint256 getNextLedgerIndex(const uint256& uHash); + uint256 getNextLedgerIndex(const uint256& uHash, const uint256& uEnd); + void ownerCountAdjust(const uint160& uOwnerID, int iAmount, SLE::ref sleAccountRoot=SLE::pointer()); // Offer functions. diff --git a/src/cpp/ripple/RippleCalc.cpp b/src/cpp/ripple/RippleCalc.cpp index 35f100fd5..5f1af0f02 100644 --- a/src/cpp/ripple/RippleCalc.cpp +++ b/src/cpp/ripple/RippleCalc.cpp @@ -889,7 +889,7 @@ TER RippleCalc::calcNodeAdvance( // FIXME: This looks at the original ledger and doesn't take into account any changes // in the LedgerEntrySet. If this code, for example, created offers, this would // not return the pages they're in. - uDirectTip = lesActive.getLedger()->getNextLedgerIndex(uDirectTip, uDirectEnd); + uDirectTip = lesActive.getNextLedgerIndex(uDirectTip, uDirectEnd); bDirectDirDirty = true; bDirectAdvance = false;