From b7484e9264a12a8d5946dcdf2c40a5ee0059b10f Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Sat, 13 Apr 2013 20:25:06 -0700 Subject: [PATCH] Make sure we don't use an invalid LES. (Adds asserts.) --- src/cpp/ripple/LedgerEntrySet.h | 2 ++ src/cpp/ripple/RippleCalc.cpp | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/src/cpp/ripple/LedgerEntrySet.h b/src/cpp/ripple/LedgerEntrySet.h index 44e61b53f..1174b1e29 100644 --- a/src/cpp/ripple/LedgerEntrySet.h +++ b/src/cpp/ripple/LedgerEntrySet.h @@ -78,6 +78,8 @@ public: LedgerEntrySet duplicate() const; // Make a duplicate of this set void setTo(const LedgerEntrySet&); // Set this set to have the same contents as another void swapWith(LedgerEntrySet&); // Swap the contents of two sets + void invalidate() { mLedger.reset(); } + bool isValid() const { return !!mLedger; } int getSeq() const { return mSeq; } TransactionEngineParams getParams() const { return mParams; } diff --git a/src/cpp/ripple/RippleCalc.cpp b/src/cpp/ripple/RippleCalc.cpp index 9476f6532..35f100fd5 100644 --- a/src/cpp/ripple/RippleCalc.cpp +++ b/src/cpp/ripple/RippleCalc.cpp @@ -2649,6 +2649,7 @@ TER RippleCalc::rippleCalc( const bool bOpenLedger ) { + assert(lesActive.isValid()); RippleCalc rc(lesActive, bOpenLedger); cLog(lsTRACE) << boost::str(boost::format("rippleCalc> saMaxAmountReq=%s saDstAmountReq=%s") @@ -2807,7 +2808,10 @@ int iPass = 0; % pspCur->saInPass.getFullText() % pspCur->saOutPass.getFullText()); + assert(lesActive.isValid()); lesActive.swapWith(pspCur->lesEntries); // For the path, save ledger state. + lesActive.invalidate(); + iBest = pspCur->getIndex(); } } @@ -2842,7 +2846,9 @@ int iPass = 0; vuUnfundedBecame.insert(vuUnfundedBecame.end(), pspBest->vUnfundedBecame.begin(), pspBest->vUnfundedBecame.end()); // Record best pass' LedgerEntrySet to build off of and potentially return. + assert(pspBest->lesEntries.isValid()); lesActive.swapWith(pspBest->lesEntries); + pspBest->lesEntries.invalidate(); saMaxAmountAct += pspBest->saInPass; saDstAmountAct += pspBest->saOutPass;