diff --git a/src/LedgerConsensus.cpp b/src/LedgerConsensus.cpp index 855281b010..cb1a55758c 100644 --- a/src/LedgerConsensus.cpp +++ b/src/LedgerConsensus.cpp @@ -361,8 +361,10 @@ int LedgerConsensus::statePreClose() bool anyTransactions = theApp->getMasterLedger().getCurrentLedger()->peekTransactionMap()->getHash().isNonZero(); int proposersClosed = mPeerPositions.size(); + int sinceClose = theApp->getOPs().getNetworkTimeNC() - mPreviousLedger->getCloseTimeNC(); + if (ContinuousLedgerTiming::shouldClose(anyTransactions, mPreviousProposers, proposersClosed, - mPreviousSeconds, mCurrentSeconds)) + mPreviousSeconds, sinceClose)) { // it is time to close the ledger (swap default and wobble ledgers) Log(lsINFO) << "Closing ledger"; mState = lcsESTABLISH; @@ -428,7 +430,7 @@ void LedgerConsensus::timerEntry() } } - mCurrentSeconds = theApp->getOPs().getNetworkTimeNC() - mCloseTime; + mCurrentSeconds = (mCloseTime != 0) ? (theApp->getOPs().getNetworkTimeNC() - mCloseTime) : 0; mClosePercent = mCurrentSeconds * 100 / mPreviousSeconds; switch (mState) diff --git a/src/LedgerTiming.cpp b/src/LedgerTiming.cpp index db2bc3031b..122f07f5c6 100644 --- a/src/LedgerTiming.cpp +++ b/src/LedgerTiming.cpp @@ -19,6 +19,8 @@ int ContinuousLedgerTiming::shouldClose( int previousSeconds, // seconds the previous ledger took to reach consensus int currentSeconds) // seconds since the previous ledger closed { + assert((previousSeconds > 0) && (previousSeconds < 600)); + assert((currentSeconds >= 0) && (currentSeconds < 600)); Log(lsTRACE) << boost::str(boost::format("CLC::shouldClose Trans=%s, Prop: %d/%d, Secs: %d/%d") % (anyTransactions ? "yes" : "no") % previousProposers % proposersClosed % previousSeconds % currentSeconds);