From d1547998d71d7aa5640d248adc1754924b616fe0 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Mon, 13 Aug 2012 17:55:55 -0700 Subject: [PATCH] Change LEDGER_MAX_INTERVAL to LEDGER_VAL_INTERVAL to more accurately reflect what it now does. Turn this interval way up to ensure we can't lose synch (due to validations seeming too old) if time resolution drops drastically. --- src/LedgerTiming.h | 5 +++-- src/ValidationCollection.cpp | 8 ++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/LedgerTiming.h b/src/LedgerTiming.h index 9f5cfa903f..eb8f2d56c8 100644 --- a/src/LedgerTiming.h +++ b/src/LedgerTiming.h @@ -5,8 +5,9 @@ # define LEDGER_IDLE_INTERVAL 15 // 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) +// This is a safety to protect against very old validations and the time it takes to adjust +// the close time accuracy window +# define LEDGER_VAL_INTERVAL 600 // The number of seconds before a close time that we consider a validation acceptable // This protects against extreme clock errors diff --git a/src/ValidationCollection.cpp b/src/ValidationCollection.cpp index 68c54fc86e..41c772f819 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 - LEDGER_EARLY_INTERVAL)) && (now < (valClose + LEDGER_MAX_INTERVAL))) + if ((now > (valClose - LEDGER_EARLY_INTERVAL)) && (now < (valClose + LEDGER_VAL_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 - LEDGER_EARLY_INTERVAL)) || (now > (closeTime + LEDGER_MAX_INTERVAL))) + if ((now < (closeTime - LEDGER_EARLY_INTERVAL)) || (now > (closeTime + LEDGER_VAL_INTERVAL))) isTrusted = false; } if (isTrusted) @@ -133,13 +133,13 @@ boost::unordered_map ValidationCollection::getCurrentValidations() { ValidationPair& pair = it->second; - if (pair.oldest && (now > (pair.oldest->getCloseTime() + LEDGER_MAX_INTERVAL))) + if (pair.oldest && (now > (pair.oldest->getCloseTime() + LEDGER_VAL_INTERVAL))) { mStaleValidations.push_back(pair.oldest); pair.oldest = SerializedValidation::pointer(); condWrite(); } - if (pair.newest && (now > (pair.newest->getCloseTime() + LEDGER_MAX_INTERVAL))) + if (pair.newest && (now > (pair.newest->getCloseTime() + LEDGER_VAL_INTERVAL))) { mStaleValidations.push_back(pair.newest); pair.newest = SerializedValidation::pointer();