From e674bcea36222c2eb30e4d72fa2cac519cdff386 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Fri, 8 Feb 2013 16:22:27 -0800 Subject: [PATCH] A collection of small bugfixes. --- src/cpp/ripple/Ledger.cpp | 16 ++--- src/cpp/ripple/Ledger.h | 1 + src/cpp/ripple/LedgerAcquire.cpp | 106 +++++++++++++++++-------------- src/cpp/ripple/SHAMap.cpp | 3 +- src/cpp/ripple/SHAMapSync.cpp | 6 +- 5 files changed, 74 insertions(+), 58 deletions(-) diff --git a/src/cpp/ripple/Ledger.cpp b/src/cpp/ripple/Ledger.cpp index 5ca31f04c7..8c4f80bc56 100644 --- a/src/cpp/ripple/Ledger.cpp +++ b/src/cpp/ripple/Ledger.cpp @@ -115,15 +115,12 @@ Ledger::Ledger(const std::string& rawLedger, bool hasPrefix) : void Ledger::setImmutable() { - if (!mImmutable) - { - updateHash(); - mImmutable = true; - if (mTransactionMap) - mTransactionMap->setImmutable(); - if (mAccountStateMap) - mAccountStateMap->setImmutable(); - } + updateHash(); + mImmutable = true; + if (mTransactionMap) + mTransactionMap->setImmutable(); + if (mAccountStateMap) + mAccountStateMap->setImmutable(); } void Ledger::updateHash() @@ -1425,6 +1422,7 @@ void Ledger::pendSave(bool fromConsensus) { if (!fromConsensus && !theApp->isNewFlag(getHash(), SF_SAVED)) return; + assert(isImmutable()); { boost::recursive_mutex::scoped_lock sl(sPendingSaveLock); diff --git a/src/cpp/ripple/Ledger.h b/src/cpp/ripple/Ledger.h index da67e0d119..c22f11aa68 100644 --- a/src/cpp/ripple/Ledger.h +++ b/src/cpp/ripple/Ledger.h @@ -158,6 +158,7 @@ public: SHAMap::ref peekAccountStateMap() { return mAccountStateMap; } void dropCache() { + assert(isImmutable()); if (mTransactionMap) mTransactionMap->dropCache(); if (mAccountStateMap) diff --git a/src/cpp/ripple/LedgerAcquire.cpp b/src/cpp/ripple/LedgerAcquire.cpp index f24c6fe463..84b3a5a85e 100644 --- a/src/cpp/ripple/LedgerAcquire.cpp +++ b/src/cpp/ripple/LedgerAcquire.cpp @@ -94,65 +94,75 @@ LedgerAcquire::LedgerAcquire(const uint256& hash) : PeerSet(hash, LEDGER_ACQUIRE bool LedgerAcquire::tryLocal() { // return value: true = no more work to do - HashedObject::pointer node = theApp->getHashedObjectStore().retrieve(mHash); - if (!node) - { - mLedger = theApp->getLedgerMaster().getLedgerByHash(mHash); - if (!mLedger) - return false; - } - else - mLedger = boost::make_shared(strCopy(node->getData()), true); - if (mLedger->getHash() != mHash) - { // We know for a fact the ledger can never be acquired - cLog(lsWARNING) << mHash << " cannot be a ledger"; - mFailed = true; - return true; - } - - mHaveBase = true; - - if (mLedger->getTransHash().isZero()) + if (!mHaveBase) { - cLog(lsDEBUG) << "No TXNs to fetch"; - mHaveTransactions = true; - } - else - { - try + HashedObject::pointer node = theApp->getHashedObjectStore().retrieve(mHash); + if (!node) { - mLedger->peekTransactionMap()->fetchRoot(mLedger->getTransHash()); - cLog(lsDEBUG) << "Got root txn map locally"; - std::vector h = mLedger->peekTransactionMap()->getNeededHashes(1); - if (h.empty()) + mLedger = theApp->getLedgerMaster().getLedgerByHash(mHash); + if (!mLedger) + return false; + } + else + mLedger = boost::make_shared(strCopy(node->getData()), true); + + if (mLedger->getHash() != mHash) + { // We know for a fact the ledger can never be acquired + cLog(lsWARNING) << mHash << " cannot be a ledger"; + mFailed = true; + return true; + } + + mHaveBase = true; + } + + if (!mHaveTransactions) + { + if (mLedger->getTransHash().isZero()) + { + cLog(lsDEBUG) << "No TXNs to fetch"; + mHaveTransactions = true; + } + else + { + try + { + mLedger->peekTransactionMap()->fetchRoot(mLedger->getTransHash()); + cLog(lsDEBUG) << "Got root txn map locally"; + std::vector h = mLedger->peekTransactionMap()->getNeededHashes(1); + if (h.empty()) + { + cLog(lsDEBUG) << "Had full txn map locally"; + mHaveTransactions = true; + } + } + catch (SHAMapMissingNode&) { - cLog(lsDEBUG) << "Had full txn map locally"; - mHaveTransactions = true; } } - catch (SHAMapMissingNode&) - { - } } - if (mLedger->getAccountHash().isZero()) - mHaveState = true; - else + if (!mHaveState) { - try + if (mLedger->getAccountHash().isZero()) + mHaveState = true; + else { - mLedger->peekAccountStateMap()->fetchRoot(mLedger->getAccountHash()); - cLog(lsDEBUG) << "Got root AS map locally"; - std::vector h = mLedger->peekAccountStateMap()->getNeededHashes(1); - if (h.empty()) + try + { + mLedger->peekAccountStateMap()->fetchRoot(mLedger->getAccountHash()); + cLog(lsDEBUG) << "Got root AS map locally"; + std::vector h = mLedger->peekAccountStateMap()->getNeededHashes(1); + if (h.empty()) + { + cLog(lsDEBUG) << "Had full AS map locally"; + mHaveState = true; + } + } + catch (SHAMapMissingNode&) { - cLog(lsDEBUG) << "Had full AS map locally"; - mHaveState = true; } - } - catch (SHAMapMissingNode&) - { } } @@ -161,6 +171,7 @@ bool LedgerAcquire::tryLocal() cLog(lsDEBUG) << "Had everything locally"; mComplete = true; mLedger->setClosed(); + mLedger->setImmutable(); } return mComplete; @@ -246,6 +257,7 @@ void LedgerAcquire::done() if (isComplete() && !isFailed() && mLedger) { mLedger->setClosed(); + mLedger->setImmutable(); if (mAccept) mLedger->setAccepted(); theApp->getLedgerMaster().storeLedger(mLedger); diff --git a/src/cpp/ripple/SHAMap.cpp b/src/cpp/ripple/SHAMap.cpp index 524232a9a5..1ae98ed143 100644 --- a/src/cpp/ripple/SHAMap.cpp +++ b/src/cpp/ripple/SHAMap.cpp @@ -852,8 +852,9 @@ bool SHAMap::getPath(const uint256& index, std::vector< std::vector& nodeIDs, std::vectorsetFullBelow(); } + if (nodeIDs.empty()) + clearSynching(); } std::vector SHAMap::getNeededHashes(int max) @@ -134,6 +136,8 @@ std::vector SHAMap::getNeededHashes(int max) if (have_all) node->setFullBelow(); } + if (ret.empty()) + clearSynching(); return ret; } @@ -171,7 +175,7 @@ bool SHAMap::getNodeFat(const SHAMapNode& wanted, std::vector& nodeI } } - return true; + return true; } bool SHAMap::getRootNode(Serializer& s, SHANodeFormat format)