From 687578abd9c8982879e6482602a06f9e144b80ea Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Wed, 5 Sep 2012 21:55:00 -0700 Subject: [PATCH] Get rid of "dead" ledgers. We don't need them any more and they make trouble. Fix close time synch to be more accurate. --- src/LedgerConsensus.cpp | 2 +- src/NetworkOPs.cpp | 18 ++++++++++-------- src/ValidationCollection.cpp | 22 ---------------------- src/ValidationCollection.h | 5 ----- 4 files changed, 11 insertions(+), 36 deletions(-) diff --git a/src/LedgerConsensus.cpp b/src/LedgerConsensus.cpp index e7b984fa8d..cd30acf1e8 100644 --- a/src/LedgerConsensus.cpp +++ b/src/LedgerConsensus.cpp @@ -257,7 +257,7 @@ void LedgerConsensus::checkLCL() typedef std::pair u256_int_pair; BOOST_FOREACH(u256_int_pair& it, vals) { - if ((it.second > netLgrCount) && !theApp->getValidations().isDeadLedger(it.first)) + if (it.second > netLgrCount) { netLgr = it.first; netLgrCount = it.second; diff --git a/src/NetworkOPs.cpp b/src/NetworkOPs.cpp index fc2b547541..68127015f3 100644 --- a/src/NetworkOPs.cpp +++ b/src/NetworkOPs.cpp @@ -56,8 +56,13 @@ uint32 NetworkOPs::getValidationTimeNC() } void NetworkOPs::closeTimeOffset(int offset) -{ - mCloseTimeOffset += offset / 4; +{ // take large offsets, ignore small offsets, push towards our wall time + if (offset > 1) + mCloseTimeOffset += (offset + 3) / 4; + else if (offset < -1) + mCloseTimeOffset += (offset - 3) / 4; + else + mCloseTimeOffset = (mCloseTimeOffset * 3) / 4; if (mCloseTimeOffset) Log(lsINFO) << "Close time offset now " << mCloseTimeOffset; } @@ -487,10 +492,9 @@ bool NetworkOPs::checkLastClosedLedger(const std::vector& peerLis for (boost::unordered_map::iterator it = ledgers.begin(), end = ledgers.end(); it != end; ++it) { - bool isDead = theApp->getValidations().isDeadLedger(it->first); - Log(lsTRACE) << "L: " << it->first << ((isDead) ? " dead" : " live") << - " t=" << it->second.trustedValidations << ", n=" << it->second.nodesUsing; - if ((it->second > bestVC) && !isDead) + Log(lsTRACE) << "L: " << it->first << " t=" << it->second.trustedValidations << + ", n=" << it->second.nodesUsing; + if (it->second > bestVC) { bestVC = it->second; closedLedger = it->first; @@ -718,8 +722,6 @@ void NetworkOPs::mapComplete(const uint256& hash, const SHAMap::pointer& map) void NetworkOPs::endConsensus(bool correctLCL) { uint256 deadLedger = theApp->getMasterLedger().getClosedLedger()->getParentHash(); - Log(lsTRACE) << "Ledger " << deadLedger << " is now dead"; - theApp->getValidations().addDeadLedger(deadLedger); std::vector peerList = theApp->getConnectionPool().getPeerVector(); BOOST_FOREACH(Peer::ref it, peerList) if (it && (it->getClosedLedgerHash() == deadLedger)) diff --git a/src/ValidationCollection.cpp b/src/ValidationCollection.cpp index e788b98e73..b11b38b633 100644 --- a/src/ValidationCollection.cpp +++ b/src/ValidationCollection.cpp @@ -164,28 +164,6 @@ boost::unordered_map ValidationCollection::getCurrentValidations(u return ret; } -bool ValidationCollection::isDeadLedger(const uint256& ledger) -{ - boost::mutex::scoped_lock sl(mValidationLock); - BOOST_FOREACH(const uint256& it, mDeadLedgers) - if (it == ledger) - return true; - return false; -} - -void ValidationCollection::addDeadLedger(const uint256& ledger) -{ - boost::mutex::scoped_lock sl(mValidationLock); - - BOOST_FOREACH(const uint256& it, mDeadLedgers) - if (it == ledger) - return; - - mDeadLedgers.push_back(ledger); - if (mDeadLedgers.size() >= 32) - mDeadLedgers.pop_front(); -} - void ValidationCollection::flush() { boost::mutex::scoped_lock sl(mValidationLock); diff --git a/src/ValidationCollection.h b/src/ValidationCollection.h index 287ba6b68f..1972b7b63e 100644 --- a/src/ValidationCollection.h +++ b/src/ValidationCollection.h @@ -20,7 +20,6 @@ protected: boost::unordered_map mValidations; boost::unordered_map mCurrentValidations; std::vector mStaleValidations; - std::list mDeadLedgers; bool mWriting; @@ -39,10 +38,6 @@ public: boost::unordered_map getCurrentValidations(uint256 currentLedger = uint256()); - void addDeadLedger(const uint256&); - bool isDeadLedger(const uint256&); - std::list getDeadLedgers() { return mDeadLedgers; } - void flush(); };