From f63d9df60b96534beb082a25373e18fadee55bd0 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Wed, 29 Aug 2012 23:38:35 -0700 Subject: [PATCH] Ledger idle timing fixes. --- src/Application.cpp | 2 +- src/LedgerConsensus.cpp | 21 ++++++++++++++++----- src/LedgerTiming.cpp | 5 +++-- src/LedgerTiming.h | 3 ++- src/NetworkOPs.h | 6 +++--- 5 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/Application.cpp b/src/Application.cpp index 2fe18c161f..45adfccf43 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -153,7 +153,7 @@ void Application::run() secondLedger->setAccepted(); mMasterLedger.pushLedger(secondLedger, boost::make_shared(true, boost::ref(*secondLedger))); assert(!!secondLedger->getAccountState(rootAddress)); - mNetOps.setLastCloseNetTime(secondLedger->getCloseTimeNC()); + mNetOps.setLastCloseTime(secondLedger->getCloseTimeNC()); } diff --git a/src/LedgerConsensus.cpp b/src/LedgerConsensus.cpp index 46cd2deb2e..e3c49bb677 100644 --- a/src/LedgerConsensus.cpp +++ b/src/LedgerConsensus.cpp @@ -421,21 +421,32 @@ void LedgerConsensus::statePreClose() int proposersClosed = mPeerPositions.size(); // This ledger is open. This computes how long since the last ledger closed - int lastCloseTime; - if (!anyTransactions && mPreviousLedger->getCloseAgree()) + uint32 lastCloseTime; + int ledgerInterval = 0; + + if (mHaveCorrectLCL && mPreviousLedger->getCloseAgree()) + { // we can use consensus timing lastCloseTime = mPreviousLedger->getCloseTimeNC(); + ledgerInterval = 2 * mPreviousLedger->getCloseResolution(); + if (ledgerInterval < LEDGER_IDLE_INTERVAL) + ledgerInterval = LEDGER_IDLE_INTERVAL; + } else - lastCloseTime = theApp->getOPs().getLastCloseNetTime(); + { + lastCloseTime = theApp->getOPs().getLastCloseTime(); + ledgerInterval = LEDGER_IDLE_INTERVAL; + } + int sinceClose = 1000 * (theApp->getOPs().getCloseTimeNC() - lastCloseTime); if (sinceClose >= ContinuousLedgerTiming::shouldClose(anyTransactions, mPreviousProposers, proposersClosed, - mPreviousMSeconds, sinceClose)) + mPreviousMSeconds, sinceClose, ledgerInterval)) { // it is time to close the ledger Log(lsINFO) << "CLC: closing ledger"; mState = lcsESTABLISH; mConsensusStartTime = boost::posix_time::microsec_clock::universal_time(); mCloseTime = theApp->getOPs().getCloseTimeNC(); - theApp->getOPs().setLastCloseNetTime(mCloseTime); + theApp->getOPs().setLastCloseTime(mCloseTime); statusChange(newcoin::neCLOSING_LEDGER, *mPreviousLedger); takeInitialPosition(*theApp->getMasterLedger().closeLedger()); } diff --git a/src/LedgerTiming.cpp b/src/LedgerTiming.cpp index ce737c2a63..f10acbaadd 100644 --- a/src/LedgerTiming.cpp +++ b/src/LedgerTiming.cpp @@ -17,7 +17,8 @@ int ContinuousLedgerTiming::shouldClose( int previousProposers, // proposers in the last closing int proposersClosed, // proposers who have currently closed this ledgers int previousMSeconds, // seconds the previous ledger took to reach consensus - int currentMSeconds) // seconds since the previous ledger closed + int currentMSeconds, // seconds since the previous ledger closed + int idleInterval) // network's desired idle interval { if ((previousMSeconds < -1000) || (previousMSeconds > 600000) || (currentMSeconds < -1000) || (currentMSeconds > 600000)) @@ -44,7 +45,7 @@ int ContinuousLedgerTiming::shouldClose( return previousMSeconds; return previousMSeconds - 1000; } - return LEDGER_IDLE_INTERVAL * 1000; // normal idle + return idleInterval * 1000; // normal idle } Log(lsTRACE) << "close now"; diff --git a/src/LedgerTiming.h b/src/LedgerTiming.h index eb8f2d56c8..bed4673319 100644 --- a/src/LedgerTiming.h +++ b/src/LedgerTiming.h @@ -49,7 +49,8 @@ public: static int shouldClose( bool anyTransactions, int previousProposers, int proposersClosed, - int previousSeconds, int currentSeconds); + int previousSeconds, int currentSeconds, + int idleInterval); static bool haveConsensus( int previousProposers, int currentProposers, diff --git a/src/NetworkOPs.h b/src/NetworkOPs.h index 9b324edddc..e0a73052f4 100644 --- a/src/NetworkOPs.h +++ b/src/NetworkOPs.h @@ -63,7 +63,7 @@ protected: // last ledger close int mLastCloseProposers, mLastCloseConvergeTime; uint256 mLastCloseHash; - uint32 mLastCloseNetTime; + uint32 mLastCloseTime; // XXX Split into more locks. boost::interprocess::interprocess_upgradable_mutex mMonitorLock; @@ -179,8 +179,8 @@ public: void newLCL(int proposers, int convergeTime, const uint256& ledgerHash); int getPreviousProposers() { return mLastCloseProposers; } int getPreviousConvergeTime() { return mLastCloseConvergeTime; } - uint32 getLastCloseNetTime() { return mLastCloseNetTime; } - void setLastCloseNetTime(uint32 t) { mLastCloseNetTime = t; } + uint32 getLastCloseTime() { return mLastCloseTime; } + void setLastCloseTime(uint32 t) { mLastCloseTime = t; } Json::Value getServerInfo(); // client information retrieval functions