Fix what is probably *the* bug. We aren't usually in our own UNL, so we

specially mark our validations trusted. But that wasn't properly taken into
account in one case where we decide if a validation is current. This causes
two nodes to each not recognize their own validations, so they tend to
exchange ledgers.

Cleanups, extra logging.
This commit is contained in:
JoelKatz
2012-08-13 23:14:39 -07:00
parent 5eca52497f
commit 227754496e
2 changed files with 28 additions and 8 deletions

View File

@@ -5,11 +5,13 @@
#include "LedgerTiming.h"
#include "Log.h"
bool ValidationCollection::addValidation(SerializedValidation::pointer val)
// #define VC_DEBUG
bool ValidationCollection::addValidation(SerializedValidation::pointer& val)
{
NewcoinAddress signer = val->getSignerPublic();
bool isCurrent = false;
if (theApp->getUNL().nodeInUNL(signer))
if (theApp->getUNL().nodeInUNL(signer) || val->isTrusted())
{
val->setTrusted();
uint32 now = theApp->getOPs().getCloseTimeNC();
@@ -51,7 +53,7 @@ bool ValidationCollection::addValidation(SerializedValidation::pointer val)
}
Log(lsINFO) << "Val for " << hash.GetHex() << " from " << signer.humanNodePublic()
<< " added " << (val->isTrusted() ? "trusted" : "UNtrusted");
<< " added " << (val->isTrusted() ? "trusted/" : "UNtrusted/") << (isCurrent ? "current" : "stale");
return isCurrent;
}
@@ -83,6 +85,12 @@ void ValidationCollection::getValidationCount(const uint256& ledger, bool curren
uint32 closeTime = vit->second->getCloseTime();
if ((now < (closeTime - LEDGER_EARLY_INTERVAL)) || (now > (closeTime + LEDGER_VAL_INTERVAL)))
isTrusted = false;
else
{
#ifdef VC_DEBUG
Log(lsINFO) << "VC: Untrusted due to time " << ledger.GetHex();
#endif
}
}
if (isTrusted)
++trusted;
@@ -90,6 +98,9 @@ void ValidationCollection::getValidationCount(const uint256& ledger, bool curren
++untrusted;
}
}
#ifdef VC_DEBUG
Log(lsINFO) << "VC: " << ledger.GetHex() << "t:" << trusted << " u:" << untrusted;
#endif
}
int ValidationCollection::getTrustedValidationCount(const uint256& ledger)
@@ -135,12 +146,18 @@ boost::unordered_map<uint256, int> ValidationCollection::getCurrentValidations()
if (pair.oldest && (now > (pair.oldest->getCloseTime() + LEDGER_VAL_INTERVAL)))
{
#ifdef VC_DEBUG
Log(lsINFO) << "VC: " << it->first.GetHex() << " removeOldestStale";
#endif
mStaleValidations.push_back(pair.oldest);
pair.oldest = SerializedValidation::pointer();
condWrite();
}
if (pair.newest && (now > (pair.newest->getCloseTime() + LEDGER_VAL_INTERVAL)))
{
#ifdef VC_DEBUG
Log(lsINFO) << "VC: " << it->first.GetHex() << " removeNewestStale";
#endif
mStaleValidations.push_back(pair.newest);
pair.newest = SerializedValidation::pointer();
condWrite();
@@ -151,14 +168,18 @@ boost::unordered_map<uint256, int> ValidationCollection::getCurrentValidations()
{
if (pair.oldest)
{
// Log(lsTRACE) << "OLD " << pair.oldest->getLedgerHash().GetHex() << " " <<
#ifdef VC_DEBUG
Log(lsTRACE) << "VC: OLD " << pair.oldest->getLedgerHash().GetHex() << " " <<
boost::lexical_cast<std::string>(pair.oldest->getCloseTime());
#endif
++ret[pair.oldest->getLedgerHash()];
}
if (pair.newest)
{
// Log(lsTRACE) << "NEW " << pair.newest->getLedgerHash().GetHex() << " " <<
#ifdef VC_DEBUG
Log(lsTRACE) << "VC: NEW " << pair.newest->getLedgerHash().GetHex() << " " <<
boost::lexical_cast<std::string>(pair.newest->getCloseTime());
#endif
++ret[pair.newest->getLedgerHash()];
}
++it;
@@ -224,8 +245,7 @@ void ValidationCollection::condWrite()
void ValidationCollection::doWrite()
{
static boost::format insVal("INSERT INTO LedgerValidations "
"(LedgerHash,NodePubKey,Flags,CloseTime,Signature) VALUES "
"('%s','%s','%u','%u',%s);");
"(LedgerHash,NodePubKey,Flags,CloseTime,Signature) VALUES ('%s','%s','%u','%u',%s);");
boost::mutex::scoped_lock sl(mValidationLock);
assert(mWriting);