From a902134133d00757e4a9803cf7f3052b4b17ea19 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Wed, 1 Aug 2012 15:00:39 -0700 Subject: [PATCH] Don't be blind to validations during the idle time. --- src/LedgerConsensus.cpp | 33 +++++++++++++++++++++++++++++++++ src/LedgerConsensus.h | 1 + src/NetworkOPs.cpp | 2 -- 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/LedgerConsensus.cpp b/src/LedgerConsensus.cpp index 699e1bd6c5..a99a54a0b1 100644 --- a/src/LedgerConsensus.cpp +++ b/src/LedgerConsensus.cpp @@ -226,6 +226,38 @@ LedgerConsensus::LedgerConsensus(const uint256& prevLCLHash, Ledger::pointer pre } } +void LedgerConsensus::checkLCL() +{ + uint256 netLgr; + int netLgrCount = 0; + { + boost::unordered_map vals = theApp->getValidations().getCurrentValidations(); + for (boost::unordered_map::iterator it = vals.begin(), end = vals.end(); it != end; ++it) + if (it->second > netLgrCount) + { + netLgr = it->first; + netLgrCount = it->second; + } + } + if ((netLgrCount > 0) && (netLgr != mPrevLedgerHash)) + { // LCL change + Log(lsWARNING) << "View of consensus changed during consensus"; + mPrevLedgerHash = netLgr; + mAcquiringLedger = theApp->getMasterLedgerAcquire().findCreate(mPrevLedgerHash); + std::vector peerList = theApp->getConnectionPool().getPeerVector(); + bool found = false; + for (std::vector::const_iterator it = peerList.begin(), end = peerList.end(); it != end; ++it) + if ((*it)->hasLedger(mPrevLedgerHash)) + { + found = true; + mAcquiringLedger->peerHas(*it); + } + if (!found) + for (std::vector::const_iterator it = peerList.begin(), end = peerList.end(); it != end; ++it) + mAcquiringLedger->peerHas(*it); + } +} + void LedgerConsensus::takeInitialPosition(Ledger& initialLedger) { SHAMap::pointer initialSet = initialLedger.peekTransactionMap()->snapShot(false); @@ -418,6 +450,7 @@ void LedgerConsensus::timerEntry() { if (!mHaveCorrectLCL) { + checkLCL(); Log(lsINFO) << "Checking for consensus ledger " << mPrevLedgerHash.GetHex(); Ledger::pointer consensus = theApp->getMasterLedger().getLedgerByHash(mPrevLedgerHash); if (consensus) diff --git a/src/LedgerConsensus.h b/src/LedgerConsensus.h index 215175d8e3..6f167e72d4 100644 --- a/src/LedgerConsensus.h +++ b/src/LedgerConsensus.h @@ -149,6 +149,7 @@ public: SHAMap::pointer getTransactionTree(const uint256& hash, bool doAcquire); TransactionAcquire::pointer getAcquiring(const uint256& hash); void mapComplete(const uint256& hash, SHAMap::pointer map, bool acquired); + void checkLCL(); void timerEntry(); diff --git a/src/NetworkOPs.cpp b/src/NetworkOPs.cpp index d1b216ebbf..b4f15780d5 100644 --- a/src/NetworkOPs.cpp +++ b/src/NetworkOPs.cpp @@ -655,8 +655,6 @@ void NetworkOPs::endConsensus(bool correctLCL) (*it)->cycleStatus(); } mConsensus = boost::shared_ptr(); - if (correctLCL && (mMode == omCONNECTED)) - setMode(omTRACKING); } void NetworkOPs::setMode(OperatingMode om)