diff --git a/src/ValidationCollection.cpp b/src/ValidationCollection.cpp index 2f29327140..1502e4b52d 100644 --- a/src/ValidationCollection.cpp +++ b/src/ValidationCollection.cpp @@ -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 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 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(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(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); diff --git a/src/ValidationCollection.h b/src/ValidationCollection.h index 2198a967fe..1ed522dc54 100644 --- a/src/ValidationCollection.h +++ b/src/ValidationCollection.h @@ -38,7 +38,7 @@ protected: public: ValidationCollection() : mWriting(false) { ; } - bool addValidation(SerializedValidation::pointer); + bool addValidation(SerializedValidation::pointer&); ValidationSet getValidations(const uint256& ledger); void getValidationCount(const uint256& ledger, bool currentOnly, int& trusted, int& untrusted);