mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Refactor consensus:
Classes implementing the consensus process on Ripple are cleaned up in preparation for modularizations and compartmentalization. Functions and state related to inter-round consensus are moved out of NetworkOPs and into Consensus, where they are more effectively isolated. Some member functions are changed to free functions and some free functions have their scope reduced to specific translation units. * Track inter-round consensus state using new Consensus object * Devirtualize interfaces * Reduce NetworkOPs, Consensus and LedgerConsensus interfaces * Add comments
This commit is contained in:
@@ -25,125 +25,6 @@
|
||||
|
||||
namespace ripple {
|
||||
|
||||
bool shouldCloseLedger (
|
||||
bool anyTransactions,
|
||||
int previousProposers,
|
||||
int proposersClosed,
|
||||
int proposersValidated,
|
||||
int previousMSeconds,
|
||||
int currentMSeconds,
|
||||
int openMSeconds,
|
||||
int idleInterval)
|
||||
{
|
||||
if ((previousMSeconds < -1000) || (previousMSeconds > 600000) ||
|
||||
(currentMSeconds < -1000) || (currentMSeconds > 600000))
|
||||
{
|
||||
WriteLog (lsWARNING, LedgerTiming) <<
|
||||
"shouldCloseLedger Trans=" << (anyTransactions ? "yes" : "no") <<
|
||||
" Prop: " << previousProposers << "/" << proposersClosed <<
|
||||
" Secs: " << currentMSeconds << " (last: " << previousMSeconds << ")";
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!anyTransactions)
|
||||
{
|
||||
// did we miss a transaction?
|
||||
if (proposersClosed > (previousProposers / 4))
|
||||
{
|
||||
WriteLog (lsTRACE, LedgerTiming) <<
|
||||
"no transactions, many proposers: now (" << proposersClosed <<
|
||||
" closed, " << previousProposers << " before)";
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// Only close if we have idled for too long.
|
||||
return currentMSeconds >= (idleInterval * 1000); // normal idle
|
||||
}
|
||||
|
||||
// If we have any transactions, we don't want to close too frequently:
|
||||
if (openMSeconds < LEDGER_MIN_CLOSE)
|
||||
{
|
||||
if ((proposersClosed + proposersValidated) < (previousProposers / 2 ))
|
||||
{
|
||||
WriteLog (lsDEBUG, LedgerTiming) <<
|
||||
"Must wait minimum time before closing";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (currentMSeconds < previousMSeconds)
|
||||
{
|
||||
if ((proposersClosed + proposersValidated) < previousProposers)
|
||||
{
|
||||
WriteLog (lsDEBUG, LedgerTiming) <<
|
||||
"We are waiting for more closes/validations";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
checkConsensusReached (int agreeing, int proposing)
|
||||
{
|
||||
int currentPercentage = (agreeing * 100) / (proposing + 1);
|
||||
|
||||
return currentPercentage > minimumConsensusPercentage;
|
||||
}
|
||||
|
||||
ConsensusState checkConsensus (
|
||||
int previousProposers,
|
||||
int currentProposers,
|
||||
int currentAgree,
|
||||
int currentFinished,
|
||||
int previousAgreeTime,
|
||||
int currentAgreeTime)
|
||||
{
|
||||
WriteLog (lsTRACE, LedgerTiming) <<
|
||||
"checkConsensus: prop=" << currentProposers <<
|
||||
"/" << previousProposers <<
|
||||
" agree=" << currentAgree << " validated=" << currentFinished <<
|
||||
" time=" << currentAgreeTime << "/" << previousAgreeTime;
|
||||
|
||||
if (currentAgreeTime <= LEDGER_MIN_CONSENSUS)
|
||||
return ConsensusState::No;
|
||||
|
||||
if (currentProposers < (previousProposers * 3 / 4))
|
||||
{
|
||||
// Less than 3/4 of the last ledger's proposers are present; don't
|
||||
// rush: we may need more time.
|
||||
if (currentAgreeTime < (previousAgreeTime + LEDGER_MIN_CONSENSUS))
|
||||
{
|
||||
WriteLog (lsTRACE, LedgerTiming) <<
|
||||
"too fast, not enough proposers";
|
||||
return ConsensusState::No;
|
||||
}
|
||||
}
|
||||
|
||||
// Have we, together with the nodes on our UNL list, reached the treshold
|
||||
// to declare consensus?
|
||||
if (checkConsensusReached (currentAgree + 1, currentProposers))
|
||||
{
|
||||
WriteLog (lsDEBUG, LedgerTiming) << "normal consensus";
|
||||
return ConsensusState::Yes;
|
||||
}
|
||||
|
||||
// Have sufficient nodes on our UNL list moved on and reached the threshold
|
||||
// to declare consensus?
|
||||
if (checkConsensusReached (currentFinished, currentProposers))
|
||||
{
|
||||
WriteLog (lsWARNING, LedgerTiming) <<
|
||||
"We see no consensus, but 80% of nodes have moved on";
|
||||
return ConsensusState::MovedOn;
|
||||
}
|
||||
|
||||
// no consensus yet
|
||||
WriteLog (lsTRACE, LedgerTiming) << "no consensus";
|
||||
return ConsensusState::No;
|
||||
}
|
||||
|
||||
int getNextLedgerTimeResolution (
|
||||
int previousResolution,
|
||||
bool previousAgree,
|
||||
|
||||
Reference in New Issue
Block a user