1#include <xrpld/consensus/Consensus.h>
3#include <xrpl/basics/Log.h>
21 CLOG(clog) <<
"shouldCloseLedger params anyTransactions: " << anyTransactions
22 <<
", prevProposers: " << prevProposers <<
", proposersClosed: " << proposersClosed
23 <<
", proposersValidated: " << proposersValidated <<
", prevRoundTime: " << prevRoundTime.
count() <<
"ms"
24 <<
", timeSincePrevClose: " << timeSincePrevClose.
count() <<
"ms"
25 <<
", openTime: " << openTime.
count() <<
"ms"
26 <<
", idleInterval: " << idleInterval.
count() <<
"ms"
29 using namespace std::chrono_literals;
30 if ((prevRoundTime < -1s) || (prevRoundTime > 10min) || (timeSincePrevClose > 10min))
34 ss <<
"shouldCloseLedger Trans=" << (anyTransactions ?
"yes" :
"no") <<
" Prop: " << prevProposers <<
"/"
35 << proposersClosed <<
" Secs: " << timeSincePrevClose.
count() <<
" (last: " << prevRoundTime.
count() <<
")";
38 CLOG(clog) <<
"closing ledger: " << ss.
str() <<
". ";
42 if ((proposersClosed + proposersValidated) > (prevProposers / 2))
45 JLOG(j.
trace()) <<
"Others have closed";
46 CLOG(clog) <<
"closing ledger because enough others have already. ";
53 CLOG(clog) <<
"no transactions, returning. ";
54 return timeSincePrevClose >= idleInterval;
60 JLOG(j.
debug()) <<
"Must wait minimum time before closing";
61 CLOG(clog) <<
"not closing because under ledgerMIN_CLOSE. ";
68 if (openTime < (prevRoundTime / 2))
70 JLOG(j.
debug()) <<
"Ledger has not been open long enough";
71 CLOG(clog) <<
"not closing because not open long enough. ";
76 CLOG(clog) <<
"no reason to not close. ";
90 CLOG(clog) <<
"checkConsensusReached params: agreeing: " << agreeing <<
", total: " << total
91 <<
", count_self: " << count_self <<
", minConsensusPct: " << minConsensusPct
92 <<
", reachedMax: " << reachedMax <<
". ";
107 CLOG(clog) <<
"Consensus reached because nobody shares our position and "
108 "maximum duration has passed.";
111 CLOG(clog) <<
"Consensus not reached and nobody shares our position. ";
122 CLOG(clog) <<
"consensus stalled. ";
130 CLOG(clog) <<
"agreeing and total adjusted: " << agreeing <<
',' << total <<
". ";
133 std::size_t currentPercentage = (agreeing * 100) / total;
135 CLOG(clog) <<
"currentPercentage: " << currentPercentage;
136 bool const ret = currentPercentage >= minConsensusPct;
139 CLOG(clog) <<
", consensus reached. ";
143 CLOG(clog) <<
", consensus not reached. ";
162 CLOG(clog) <<
"checkConsensus: prop=" << currentProposers <<
"/" << prevProposers <<
" agree=" << currentAgree
163 <<
" validated=" << currentFinished <<
" time=" << currentAgreeTime.
count() <<
"/"
171 CLOG(clog) <<
"Not reached. ";
175 if (currentProposers < (prevProposers * 3 / 4))
181 JLOG(j.
trace()) <<
"too fast, not enough proposers";
182 CLOG(clog) <<
"Too fast, not enough proposers. Not reached. ";
198 JLOG((stalled ? j.
warn() : j.
debug())) <<
"normal consensus" << (stalled ?
", but stalled" :
"");
199 CLOG(clog) <<
"reached" << (stalled ?
", but stalled." :
".");
214 JLOG(j.
warn()) <<
"We see no consensus, but 80% of nodes have moved on";
215 CLOG(clog) <<
"We see no consensus, but 80% of nodes have moved on";
222 JLOG(j.
warn()) <<
"consensus taken too long";
223 CLOG(clog) <<
"Consensus taken too long. ";
229 JLOG(j.
trace()) <<
"no consensus";
230 CLOG(clog) <<
"No consensus. ";
A generic endpoint for log messages.
Stream trace() const
Severity stream access functions.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
@ proposing
We are normal participant in consensus and propose our position.
bool checkConsensusReached(std::size_t agreeing, std::size_t total, bool count_self, std::size_t minConsensusPct, bool reachedMax, bool stalled, std::unique_ptr< std::stringstream > const &clog)
ConsensusState checkConsensus(std::size_t prevProposers, std::size_t currentProposers, std::size_t currentAgree, std::size_t currentFinished, std::chrono::milliseconds previousAgreeTime, std::chrono::milliseconds currentAgreeTime, bool stalled, ConsensusParms const &parms, bool proposing, beast::Journal j, std::unique_ptr< std::stringstream > const &clog)
Determine whether the network reached consensus and whether we joined.
ConsensusState
Whether we have or don't have a consensus.
@ Expired
Consensus time limit has hard-expired.
@ MovedOn
The network has consensus without us.
@ Yes
We have consensus along with the network.
@ No
We do not have consensus.
bool shouldCloseLedger(bool anyTransactions, std::size_t prevProposers, std::size_t proposersClosed, std::size_t proposersValidated, std::chrono::milliseconds prevRoundTime, std::chrono::milliseconds timeSincePrevClose, std::chrono::milliseconds openTime, std::chrono::milliseconds idleInterval, ConsensusParms const &parms, beast::Journal j, std::unique_ptr< std::stringstream > const &clog)
Determines whether the current ledger should close at this time.
Consensus algorithm parameters.
std::chrono::milliseconds const ledgerABANDON_CONSENSUS
Maximum amount of time to give a consensus round.
std::size_t const minCONSENSUS_PCT
The percentage threshold above which we can declare consensus.
std::chrono::milliseconds const ledgerMAX_CONSENSUS
The maximum amount of time to spend pausing for laggards.
std::chrono::milliseconds const ledgerMIN_CONSENSUS
The number of seconds we wait minimum to ensure participation.
std::chrono::milliseconds const ledgerMIN_CLOSE
Minimum number of seconds to wait to ensure others have computed the LCL.
std::size_t const ledgerABANDON_CONSENSUS_FACTOR
How long to wait before completely abandoning consensus.