Don't switch to a dead ledger. Without this, we can even get out of sync with ourselves!

This commit is contained in:
JoelKatz
2012-08-06 02:21:17 -07:00
parent b14b2f5dab
commit 39b28e1f50
3 changed files with 34 additions and 7 deletions

View File

@@ -455,16 +455,27 @@ bool NetworkOPs::checkLastClosedLedger(const std::vector<Peer::pointer>& 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<uint256, ValidationCount>::iterator it = ledgers.begin(), end = ledgers.end();
std::list<uint256> deadLedgers = theApp->getValidations().getDeadLedgers();
for (boost::unordered_map<uint256, ValidationCount>::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<uint256>::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<Peer::pointer> peerList = theApp->getConnectionPool().getPeerVector();
for (std::vector<Peer::pointer>::const_iterator it = peerList.begin(), end = peerList.end(); it != end; ++it)
if (*it && ((*it)->getClosedLedgerHash() == deadLedger))

View File

@@ -172,6 +172,13 @@ boost::unordered_map<uint256, int> 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);

View File

@@ -25,9 +25,11 @@ class ValidationCollection
protected:
boost::mutex mValidationLock;
boost::unordered_map<uint256, ValidationSet> mValidations;
boost::unordered_map<uint160, ValidationPair> mCurrentValidations;
std::vector<SerializedValidation::pointer> mStaleValidations;
boost::unordered_map<uint256, ValidationSet> mValidations;
boost::unordered_map<uint160, ValidationPair> mCurrentValidations;
std::vector<SerializedValidation::pointer> mStaleValidations;
std::list<uint256> 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<uint256, int> getCurrentValidations();
void addDeadLedger(const uint256&);
std::list<uint256> getDeadLedgers() { return mDeadLedgers; }
void flush();
};