From b14b2f5daba4dae54a060037185ab17183e21f88 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Mon, 6 Aug 2012 02:12:27 -0700 Subject: [PATCH] Separate close times and network times. --- src/Ledger.cpp | 2 +- src/LedgerConsensus.cpp | 6 +++--- src/LedgerTiming.h | 2 +- src/NetworkOPs.cpp | 14 ++++++++------ src/NetworkOPs.h | 3 ++- src/ValidationCollection.cpp | 6 +++--- 6 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/Ledger.cpp b/src/Ledger.cpp index aa279f8a46..e94c6dc5b1 100644 --- a/src/Ledger.cpp +++ b/src/Ledger.cpp @@ -71,7 +71,7 @@ Ledger::Ledger(bool dummy, Ledger& prevLedger) : prevLedger.getCloseAgree(), mLedgerSeq); if (prevLedger.mCloseTime == 0) { - mCloseTime = theApp->getOPs().getNetworkTimeNC(); + mCloseTime = theApp->getOPs().getCloseTimeNC(); mCloseTime -= (mCloseTime % mCloseResolution); } else diff --git a/src/LedgerConsensus.cpp b/src/LedgerConsensus.cpp index e4b2fe4288..deeb5a7a6c 100644 --- a/src/LedgerConsensus.cpp +++ b/src/LedgerConsensus.cpp @@ -404,7 +404,7 @@ void LedgerConsensus::statePreClose() int proposersClosed = mPeerPositions.size(); // This ledger is open. This computes how long since the last ledger closed - int sinceClose = 1000 * (theApp->getOPs().getNetworkTimeNC() - theApp->getOPs().getLastCloseNetTime()); + int sinceClose = 1000 * (theApp->getOPs().getCloseTimeNC() - theApp->getOPs().getLastCloseNetTime()); if (sinceClose >= ContinuousLedgerTiming::shouldClose(anyTransactions, mPreviousProposers, proposersClosed, mPreviousMSeconds, sinceClose)) @@ -412,7 +412,7 @@ void LedgerConsensus::statePreClose() Log(lsINFO) << "CLC: closing ledger"; mState = lcsESTABLISH; mConsensusStartTime = boost::posix_time::second_clock::universal_time(); - mCloseTime = theApp->getOPs().getNetworkTimeNC(); + mCloseTime = theApp->getOPs().getCloseTimeNC(); theApp->getOPs().setLastCloseNetTime(mCloseTime); statusChange(newcoin::neCLOSING_LEDGER, *mPreviousLedger); takeInitialPosition(*theApp->getMasterLedger().closeLedger()); @@ -930,7 +930,7 @@ void LedgerConsensus::accept(SHAMap::pointer set) closeTotal += (closeCount / 2); closeTotal /= closeCount; int offset = static_cast(closeTotal) - static_cast(mCloseTime); - Log(lsINFO) << "Our clock offset is estimated at " << offset; + Log(lsINFO) << "Our close offset is estimated at " << offset << " (" << closeCount << ")"; } #ifdef DEBUG diff --git a/src/LedgerTiming.h b/src/LedgerTiming.h index add26558f1..41e85762a1 100644 --- a/src/LedgerTiming.h +++ b/src/LedgerTiming.h @@ -5,7 +5,7 @@ # define LEDGER_IDLE_INTERVAL 15 // The number of seconds a validation remains current -# define LEDGER_MAX_INTERVAL 60 +# define LEDGER_MAX_INTERVAL (LEDGER_IDLE_INTERVAL * 4) // The number of milliseconds we wait minimum to ensure participation # define LEDGER_MIN_CONSENSUS 2000 diff --git a/src/NetworkOPs.cpp b/src/NetworkOPs.cpp index 4d243e654b..22eae18a1a 100644 --- a/src/NetworkOPs.cpp +++ b/src/NetworkOPs.cpp @@ -24,18 +24,15 @@ // there's a functional network. NetworkOPs::NetworkOPs(boost::asio::io_service& io_service, LedgerMaster* pLedgerMaster) : - mMode(omDISCONNECTED),mNetTimer(io_service), mLedgerMaster(pLedgerMaster), mTimeOffset(0), + mMode(omDISCONNECTED),mNetTimer(io_service), mLedgerMaster(pLedgerMaster), mCloseTimeOffset(0), mLastCloseProposers(0), mLastCloseConvergeTime(LEDGER_IDLE_INTERVAL) { } boost::posix_time::ptime NetworkOPs::getNetworkTimePT() { - int offset; - if (theApp->getSystemTimeOffset(offset)) - offset += mTimeOffset; - else - offset = mTimeOffset; + int offset = 0; + theApp->getSystemTimeOffset(offset); return boost::posix_time::second_clock::universal_time() + boost::posix_time::seconds(offset); } @@ -44,6 +41,11 @@ uint32 NetworkOPs::getNetworkTimeNC() return iToSeconds(getNetworkTimePT()); } +uint32 NetworkOPs::getCloseTimeNC() +{ + return iToSeconds(getNetworkTimePT() + boost::posix_time::seconds(mCloseTimeOffset)); +} + uint32 NetworkOPs::getCurrentLedgerID() { return mLedgerMaster->getCurrentLedger()->getLedgerSeq(); diff --git a/src/NetworkOPs.h b/src/NetworkOPs.h index 67ada03636..8e8e45c24c 100644 --- a/src/NetworkOPs.h +++ b/src/NetworkOPs.h @@ -58,7 +58,7 @@ protected: LedgerMaster* mLedgerMaster; LedgerAcquire::pointer mAcquiringLedger; - int mTimeOffset; + int mCloseTimeOffset; // last ledger close int mLastCloseProposers, mLastCloseConvergeTime; @@ -88,6 +88,7 @@ public: // network information uint32 getNetworkTimeNC(); + uint32 getCloseTimeNC(); boost::posix_time::ptime getNetworkTimePT(); uint32 getCurrentLedgerID(); OperatingMode getOperatingMode() { return mMode; } diff --git a/src/ValidationCollection.cpp b/src/ValidationCollection.cpp index c8ba948560..98c70258bc 100644 --- a/src/ValidationCollection.cpp +++ b/src/ValidationCollection.cpp @@ -12,7 +12,7 @@ bool ValidationCollection::addValidation(SerializedValidation::pointer val) if (theApp->getUNL().nodeInUNL(signer)) { val->setTrusted(); - uint32 now = theApp->getOPs().getNetworkTimeNC(); + uint32 now = theApp->getOPs().getCloseTimeNC(); uint32 valClose = val->getCloseTime(); if ((now > valClose) && (now < (valClose + LEDGER_MAX_INTERVAL))) isCurrent = true; @@ -72,7 +72,7 @@ void ValidationCollection::getValidationCount(const uint256& ledger, bool curren trusted = untrusted = 0; boost::mutex::scoped_lock sl(mValidationLock); boost::unordered_map::iterator it = mValidations.find(ledger); - uint32 now = theApp->getOPs().getNetworkTimeNC(); + uint32 now = theApp->getOPs().getCloseTimeNC(); if (it != mValidations.end()) { for (ValidationSet::iterator vit = it->second.begin(), end = it->second.end(); vit != end; ++vit) @@ -123,7 +123,7 @@ int ValidationCollection::getCurrentValidationCount(uint32 afterTime) boost::unordered_map ValidationCollection::getCurrentValidations() { - uint32 now = theApp->getOPs().getNetworkTimeNC(); + uint32 now = theApp->getOPs().getCloseTimeNC(); boost::unordered_map ret; {