mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Improve ledger close timing
Added a safety to close the ledger quickly if there's evidence validators we trust have already closed the ledger. Base the minimum ledger open time on how long we saw the ledger open. Do not rely on the rounded close time for enforcing the minimum ledger open time.
This commit is contained in:
@@ -64,10 +64,9 @@ namespace ripple {
|
|||||||
ledger
|
ledger
|
||||||
@param previousMSeconds time, in milliseconds, for the previous ledger to
|
@param previousMSeconds time, in milliseconds, for the previous ledger to
|
||||||
reach consensus (in milliseconds)
|
reach consensus (in milliseconds)
|
||||||
@param currentMSeconds time, in milliseconds since the previous ledger
|
@param currentMSeconds time, in milliseconds, since the previous ledger's
|
||||||
closed
|
(possibly rounded) close time
|
||||||
@param openMSeconds time, in milliseconds, since the previous LCL was
|
@param openMSeconds time, in milliseconds, waiting to close this ledger
|
||||||
computed
|
|
||||||
@param idleInterval the network's desired idle interval
|
@param idleInterval the network's desired idle interval
|
||||||
*/
|
*/
|
||||||
bool shouldCloseLedger (
|
bool shouldCloseLedger (
|
||||||
@@ -76,14 +75,15 @@ bool shouldCloseLedger (
|
|||||||
int proposersClosed,
|
int proposersClosed,
|
||||||
int proposersValidated,
|
int proposersValidated,
|
||||||
int previousMSeconds,
|
int previousMSeconds,
|
||||||
int currentMSeconds,
|
int currentMSeconds, // Time since last ledger's close time
|
||||||
int openMSeconds,
|
int openMSeconds, // Time waiting to close this ledger
|
||||||
int idleInterval,
|
int idleInterval,
|
||||||
beast::Journal j)
|
beast::Journal j)
|
||||||
{
|
{
|
||||||
if ((previousMSeconds < -1000) || (previousMSeconds > 600000) ||
|
if ((previousMSeconds < -1000) || (previousMSeconds > 600000) ||
|
||||||
(currentMSeconds < -1000) || (currentMSeconds > 600000))
|
(currentMSeconds > 600000))
|
||||||
{
|
{
|
||||||
|
// These are unexpected cases, we just close the ledger
|
||||||
JLOG (j.warning) <<
|
JLOG (j.warning) <<
|
||||||
"shouldCloseLedger Trans=" << (anyTransactions ? "yes" : "no") <<
|
"shouldCloseLedger Trans=" << (anyTransactions ? "yes" : "no") <<
|
||||||
" Prop: " << previousProposers << "/" << proposersClosed <<
|
" Prop: " << previousProposers << "/" << proposersClosed <<
|
||||||
@@ -92,42 +92,38 @@ bool shouldCloseLedger (
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!anyTransactions)
|
if ((proposersClosed + proposersValidated) > (previousProposers / 2))
|
||||||
{
|
{
|
||||||
// did we miss a transaction?
|
// If more than half of the network has closed, we close
|
||||||
if (proposersClosed > (previousProposers / 4))
|
JLOG (j.trace) << "Others have closed";
|
||||||
{
|
|
||||||
JLOG (j.trace) <<
|
|
||||||
"no transactions, many proposers: now (" << proposersClosed <<
|
|
||||||
" closed, " << previousProposers << " before)";
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only close if we have idled for too long.
|
if (!anyTransactions)
|
||||||
|
{
|
||||||
|
// Only close at the end of the idle interval
|
||||||
return currentMSeconds >= (idleInterval * 1000); // normal idle
|
return currentMSeconds >= (idleInterval * 1000); // normal idle
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we have any transactions, we don't want to close too frequently:
|
// Preserve minimum ledger open time
|
||||||
if (openMSeconds < LEDGER_MIN_CLOSE)
|
if (openMSeconds < LEDGER_MIN_CLOSE)
|
||||||
{
|
|
||||||
if ((proposersClosed + proposersValidated) < (previousProposers / 2 ))
|
|
||||||
{
|
{
|
||||||
JLOG (j.debug) <<
|
JLOG (j.debug) <<
|
||||||
"Must wait minimum time before closing";
|
"Must wait minimum time before closing";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (currentMSeconds < previousMSeconds)
|
// Don't let this ledger close more than twice as fast as the previous
|
||||||
{
|
// ledger reached consensus so that slower validators can slow down
|
||||||
if ((proposersClosed + proposersValidated) < previousProposers)
|
// the network
|
||||||
|
if (openMSeconds < (previousMSeconds / 2))
|
||||||
{
|
{
|
||||||
JLOG (j.debug) <<
|
JLOG (j.debug) <<
|
||||||
"We are waiting for more closes/validations";
|
"Ledger has not been open long enough";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
// Close the ledger
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -748,7 +744,7 @@ void LedgerConsensusImp::statePreClose ()
|
|||||||
= app_.getValidations ().getTrustedValidationCount
|
= app_.getValidations ().getTrustedValidationCount
|
||||||
(mPrevLedgerHash);
|
(mPrevLedgerHash);
|
||||||
|
|
||||||
// This ledger is open. This computes how long since last ledger closed
|
// This computes how long since last ledger's close time
|
||||||
int sinceClose;
|
int sinceClose;
|
||||||
{
|
{
|
||||||
bool previousCloseCorrect = mHaveCorrectLCL
|
bool previousCloseCorrect = mHaveCorrectLCL
|
||||||
|
|||||||
Reference in New Issue
Block a user