diff --git a/src/LedgerTiming.h b/src/LedgerTiming.h index 41e85762a1..9f5cfa903f 100644 --- a/src/LedgerTiming.h +++ b/src/LedgerTiming.h @@ -4,8 +4,13 @@ // The number of seconds a ledger may remain idle before closing # define LEDGER_IDLE_INTERVAL 15 -// The number of seconds a validation remains current -# define LEDGER_MAX_INTERVAL (LEDGER_IDLE_INTERVAL * 4) +// The number of seconds a validation remains current after its ledger's close time +// This is a safety to protect against very old validations +# define LEDGER_MAX_INTERVAL (LEDGER_IDLE_INTERVAL * 32) + +// The number of seconds before a close time that we consider a validation acceptable +// This protects against extreme clock errors +# define LEDGER_EARLY_INTERVAL 240 // The number of milliseconds we wait minimum to ensure participation # define LEDGER_MIN_CONSENSUS 2000 diff --git a/src/ValidationCollection.cpp b/src/ValidationCollection.cpp index 466b3d7f2e..68c54fc86e 100644 --- a/src/ValidationCollection.cpp +++ b/src/ValidationCollection.cpp @@ -14,7 +14,7 @@ bool ValidationCollection::addValidation(SerializedValidation::pointer val) val->setTrusted(); uint32 now = theApp->getOPs().getCloseTimeNC(); uint32 valClose = val->getCloseTime(); - if ((now > (valClose - 4)) && (now < (valClose + LEDGER_MAX_INTERVAL))) + if ((now > (valClose - LEDGER_EARLY_INTERVAL)) && (now < (valClose + LEDGER_MAX_INTERVAL))) isCurrent = true; else Log(lsWARNING) << "Received stale validation now=" << now << ", close=" << valClose; @@ -81,7 +81,7 @@ void ValidationCollection::getValidationCount(const uint256& ledger, bool curren if (isTrusted && currentOnly) { uint32 closeTime = vit->second->getCloseTime(); - if ((now < closeTime) || (now > (closeTime + 2 * LEDGER_MAX_INTERVAL))) + if ((now < (closeTime - LEDGER_EARLY_INTERVAL)) || (now > (closeTime + LEDGER_MAX_INTERVAL))) isTrusted = false; } if (isTrusted) @@ -129,7 +129,6 @@ boost::unordered_map ValidationCollection::getCurrentValidations() { boost::mutex::scoped_lock sl(mValidationLock); boost::unordered_map::iterator it = mCurrentValidations.begin(); - bool anyNew = false; while (it != mCurrentValidations.end()) { ValidationPair& pair = it->second; @@ -138,13 +137,13 @@ boost::unordered_map ValidationCollection::getCurrentValidations() { mStaleValidations.push_back(pair.oldest); pair.oldest = SerializedValidation::pointer(); - anyNew = true; + condWrite(); } if (pair.newest && (now > (pair.newest->getCloseTime() + LEDGER_MAX_INTERVAL))) { mStaleValidations.push_back(pair.newest); pair.newest = SerializedValidation::pointer(); - anyNew = true; + condWrite(); } if (!pair.newest && !pair.oldest) it = mCurrentValidations.erase(it); @@ -165,8 +164,6 @@ boost::unordered_map ValidationCollection::getCurrentValidations() ++it; } } - if (anyNew) - condWrite(); } return ret;