diff --git a/src/NetworkOPs.cpp b/src/NetworkOPs.cpp index 22eae18a1a..81f5b0da8b 100644 --- a/src/NetworkOPs.cpp +++ b/src/NetworkOPs.cpp @@ -455,16 +455,27 @@ bool NetworkOPs::checkLastClosedLedger(const std::vector& peerLis // 3) Is there a network ledger we'd like to switch to? If so, do we have it? bool switchLedgers = false; - for(boost::unordered_map::iterator it = ledgers.begin(), end = ledgers.end(); + std::list deadLedgers = theApp->getValidations().getDeadLedgers(); + for (boost::unordered_map::iterator it = ledgers.begin(), end = ledgers.end(); it != end; ++it) { Log(lsTRACE) << "L: " << it->first.GetHex() << " t=" << it->second.trustedValidations << ", n=" << it->second.nodesUsing; if (it->second > bestVC) { - bestVC = it->second; - closedLedger = it->first; - switchLedgers = true; + bool dead = false; + for (std::list::iterator dit = deadLedgers.begin(), end = deadLedgers.end(); dit != end; ++it) + if (*dit == it->first) + { + dead = true; + break; + } + if (!dead) + { + bestVC = it->second; + closedLedger = it->first; + switchLedgers = true; + } } } @@ -665,6 +676,7 @@ void NetworkOPs::endConsensus(bool correctLCL) { uint256 deadLedger = theApp->getMasterLedger().getClosedLedger()->getParentHash(); Log(lsTRACE) << "Ledger " << deadLedger.GetHex() << " is now dead"; + theApp->getValidations().addDeadLedger(deadLedger); std::vector peerList = theApp->getConnectionPool().getPeerVector(); for (std::vector::const_iterator it = peerList.begin(), end = peerList.end(); it != end; ++it) if (*it && ((*it)->getClosedLedgerHash() == deadLedger)) diff --git a/src/ValidationCollection.cpp b/src/ValidationCollection.cpp index 98c70258bc..cd3f981f23 100644 --- a/src/ValidationCollection.cpp +++ b/src/ValidationCollection.cpp @@ -172,6 +172,13 @@ boost::unordered_map ValidationCollection::getCurrentValidations() return ret; } +void ValidationCollection::addDeadLedger(const uint256& ledger) +{ + mDeadLedgers.push_back(ledger); + if (mDeadLedgers.size() >= 128) + mDeadLedgers.pop_front(); +} + void ValidationCollection::flush() { boost::mutex::scoped_lock sl(mValidationLock); diff --git a/src/ValidationCollection.h b/src/ValidationCollection.h index 4120a9e240..5f58956bc6 100644 --- a/src/ValidationCollection.h +++ b/src/ValidationCollection.h @@ -25,9 +25,11 @@ class ValidationCollection protected: boost::mutex mValidationLock; - boost::unordered_map mValidations; - boost::unordered_map mCurrentValidations; - std::vector mStaleValidations; + boost::unordered_map mValidations; + boost::unordered_map mCurrentValidations; + std::vector mStaleValidations; + std::list mDeadLedgers; + bool mWriting; void doWrite(); @@ -39,9 +41,15 @@ public: bool addValidation(SerializedValidation::pointer); ValidationSet getValidations(const uint256& ledger); void getValidationCount(const uint256& ledger, bool currentOnly, int& trusted, int& untrusted); + int getTrustedValidationCount(const uint256& ledger); int getCurrentValidationCount(uint32 afterTime); + boost::unordered_map getCurrentValidations(); + + void addDeadLedger(const uint256&); + std::list getDeadLedgers() { return mDeadLedgers; } + void flush(); };