diff --git a/src/cpp/ripple/LedgerConsensus.cpp b/src/cpp/ripple/LedgerConsensus.cpp index 8aa50f4735..518a736e24 100644 --- a/src/cpp/ripple/LedgerConsensus.cpp +++ b/src/cpp/ripple/LedgerConsensus.cpp @@ -485,6 +485,7 @@ void LedgerConsensus::statePreClose() { // it is shortly before ledger close time bool anyTransactions = theApp->getLedgerMaster().getCurrentLedger()->peekTransactionMap()->getHash().isNonZero(); int proposersClosed = mPeerPositions.size(); + int proposersValidated = theApp->getValidations().getTrustedValidationCount(mPrevLedgerHash); // This ledger is open. This computes how long since the last ledger closed int sinceClose; @@ -503,8 +504,8 @@ void LedgerConsensus::statePreClose() idleInterval = LEDGER_IDLE_INTERVAL; } - if (ContinuousLedgerTiming::shouldClose(anyTransactions, mPreviousProposers, proposersClosed, - mPreviousMSeconds, sinceClose, idleInterval)) + if (ContinuousLedgerTiming::shouldClose(anyTransactions, mPreviousProposers, proposersClosed, proposersValidated, + mPreviousMSeconds, sinceClose, mCurrentMSeconds, idleInterval)) { closeLedger(); } diff --git a/src/cpp/ripple/LedgerTiming.cpp b/src/cpp/ripple/LedgerTiming.cpp index dd92c953cf..a23f5e936c 100644 --- a/src/cpp/ripple/LedgerTiming.cpp +++ b/src/cpp/ripple/LedgerTiming.cpp @@ -17,8 +17,10 @@ bool ContinuousLedgerTiming::shouldClose( bool anyTransactions, 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 proposersValidated, // proposers who have validated the last closed ledger + int previousMSeconds, // milliseconds the previous ledger took to reach consensus + int currentMSeconds, // milliseconds since the previous ledger closed + int openMSeconds, // milliseconds since the previous LCL was computed int idleInterval) // network's desired idle interval { if ((previousMSeconds < -1000) || (previousMSeconds > 600000) || @@ -51,6 +53,18 @@ bool ContinuousLedgerTiming::shouldClose( return currentMSeconds >= (idleInterval * 1000); // normal idle } + if (openMSeconds < LEDGER_MIN_CLOSE) + { + cLog(lsDEBUG) << "Must wait minimum time before closing"; + return false; + } + + if ((currentMSeconds < previousMSeconds) && ((proposersClosed + proposersValidated) < previousProposers)) + { + cLog(lsDEBUG) << "We are waiting for more closes/validations"; + return false; + } + return true; // this ledger should close now } diff --git a/src/cpp/ripple/LedgerTiming.h b/src/cpp/ripple/LedgerTiming.h index 246db51cfb..1c7a1c9cef 100644 --- a/src/cpp/ripple/LedgerTiming.h +++ b/src/cpp/ripple/LedgerTiming.h @@ -16,6 +16,9 @@ // The number of milliseconds we wait minimum to ensure participation # define LEDGER_MIN_CONSENSUS 2000 +// The number of milliseconds we wait minimum to ensure others have computed the LCL +# define LEDGER_MIN_CLOSE 2000 + // Initial resolution of ledger close time # define LEDGER_TIME_ACCURACY 30 @@ -62,8 +65,8 @@ public: // Call when a consensus is reached and when any transaction is relayed to be added static bool shouldClose( bool anyTransactions, - int previousProposers, int proposersClosed, - int previousSeconds, int currentSeconds, + int previousProposers, int proposersClosed, int proposerersValidated, + int previousMSeconds, int currentMSeconds, int openMSeconds, int idleInterval); static bool haveConsensus(