From 3ec1865ce53ce4e9afde0809be303e72e89dc92d Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Wed, 27 Mar 2013 14:46:31 -0700 Subject: [PATCH] Range of validated ledgers. --- src/cpp/ripple/LedgerMaster.cpp | 16 ++++++++++++++++ src/cpp/ripple/LedgerMaster.h | 1 + src/cpp/ripple/NetworkOPs.h | 1 + 3 files changed, 18 insertions(+) diff --git a/src/cpp/ripple/LedgerMaster.cpp b/src/cpp/ripple/LedgerMaster.cpp index 4d4920f74..9a7ef2074 100644 --- a/src/cpp/ripple/LedgerMaster.cpp +++ b/src/cpp/ripple/LedgerMaster.cpp @@ -141,6 +141,22 @@ bool LedgerMaster::haveLedger(uint32 seq) return mCompleteLedgers.hasValue(seq); } +bool LedgerMaster::getValidatedRange(uint32& minVal, uint32& maxVal) +{ + boost::recursive_mutex::scoped_lock sl(mLock); + if (!mValidLedger) + return false; + maxVal = mValidLedger->getLedgerSeq(); + if (maxVal == 0) + return false; + minVal = mCompleteLedgers.prevMissing(maxVal); + if (minVal == RangeSet::RangeSetAbsent) + minVal = 0; + else + ++minVal; + return true; +} + void LedgerMaster::asyncAccept(Ledger::pointer ledger) { uint32 seq = ledger->getLedgerSeq(); diff --git a/src/cpp/ripple/LedgerMaster.h b/src/cpp/ripple/LedgerMaster.h index d2dc0c2d5..6c9d87122 100644 --- a/src/cpp/ripple/LedgerMaster.h +++ b/src/cpp/ripple/LedgerMaster.h @@ -143,6 +143,7 @@ public: bool haveLedgerRange(uint32 from, uint32 to); bool haveLedger(uint32 seq); + bool getValidatedRange(uint32& minVal, uint32& maxVal); void resumeAcquiring(); diff --git a/src/cpp/ripple/NetworkOPs.h b/src/cpp/ripple/NetworkOPs.h index 3047aa139..55fe7de45 100644 --- a/src/cpp/ripple/NetworkOPs.h +++ b/src/cpp/ripple/NetworkOPs.h @@ -175,6 +175,7 @@ public: bool isValidated(uint32 seq); bool isValidated(uint32 seq, const uint256& hash); bool isValidated(Ledger::ref l) { return isValidated(l->getLedgerSeq(), l->getHash()); } + bool getValidatedRange(uint32& minVal, uint32& maxVal) { return mLedgerMaster->getValidatedRange(minVal, maxVal); } SerializedValidation::ref getLastValidation() { return mLastValidation; } void setLastValidation(SerializedValidation::ref v) { mLastValidation = v; }