1#include <xrpl/consensus/Consensus.h>
3#include <xrpl/basics/Log.h>
4#include <xrpl/beast/utility/Journal.h>
5#include <xrpl/consensus/ConsensusParms.h>
6#include <xrpl/consensus/ConsensusTypes.h>
30 CLOG(clog) <<
"shouldCloseLedger params anyTransactions: " << anyTransactions
31 <<
", prevProposers: " << prevProposers <<
", proposersClosed: " << proposersClosed
32 <<
", proposersValidated: " << proposersValidated
33 <<
", prevRoundTime: " << prevRoundTime.
count() <<
"ms"
34 <<
", timeSincePrevClose: " << timeSincePrevClose.
count() <<
"ms"
35 <<
", openTime: " << openTime.
count() <<
"ms"
36 <<
", idleInterval: " << idleInterval.
count() <<
"ms"
39 using namespace std::chrono_literals;
40 if ((prevRoundTime < -1s) || (prevRoundTime > 10min) || (timeSincePrevClose > 10min))
44 ss <<
"shouldCloseLedger Trans=" << (anyTransactions ?
"yes" :
"no")
45 <<
" Prop: " << prevProposers <<
"/" << proposersClosed
46 <<
" Secs: " << timeSincePrevClose.
count() <<
" (last: " << prevRoundTime.
count() <<
")";
49 CLOG(clog) <<
"closing ledger: " << ss.
str() <<
". ";
53 if ((proposersClosed + proposersValidated) > (prevProposers / 2))
56 JLOG(j.
trace()) <<
"Others have closed";
57 CLOG(clog) <<
"closing ledger because enough others have already. ";
64 CLOG(clog) <<
"no transactions, returning. ";
65 return timeSincePrevClose >= idleInterval;
71 JLOG(j.
debug()) <<
"Must wait minimum time before closing";
72 CLOG(clog) <<
"not closing because under ledgerMIN_CLOSE. ";
79 if (openTime < (prevRoundTime / 2))
81 JLOG(j.
debug()) <<
"Ledger has not been open long enough";
82 CLOG(clog) <<
"not closing because not open long enough. ";
87 CLOG(clog) <<
"no reason to not close. ";
101 CLOG(clog) <<
"checkConsensusReached params: agreeing: " << agreeing <<
", total: " << total
102 <<
", count_self: " << countSelf <<
", minConsensusPct: " << minConsensusPct
103 <<
", reachedMax: " << reachedMax <<
". ";
118 CLOG(clog) <<
"Consensus reached because nobody shares our position and "
119 "maximum duration has passed.";
122 CLOG(clog) <<
"Consensus not reached and nobody shares our position. ";
133 CLOG(clog) <<
"consensus stalled. ";
141 CLOG(clog) <<
"agreeing and total adjusted: " << agreeing <<
',' << total <<
". ";
144 std::size_t const currentPercentage = (agreeing * 100) / total;
146 CLOG(clog) <<
"currentPercentage: " << currentPercentage;
147 bool const ret = currentPercentage >= minConsensusPct;
150 CLOG(clog) <<
", consensus reached. ";
154 CLOG(clog) <<
", consensus not reached. ";
173 CLOG(clog) <<
"checkConsensus: prop=" << currentProposers <<
"/" << prevProposers
174 <<
" agree=" << currentAgree <<
" validated=" << currentFinished
175 <<
" time=" << currentAgreeTime.
count() <<
"/" << previousAgreeTime.
count()
176 <<
" proposing? " << proposing
184 CLOG(clog) <<
"Not reached. ";
188 if (currentProposers < (prevProposers * 3 / 4))
194 JLOG(j.
trace()) <<
"too fast, not enough proposers";
195 CLOG(clog) <<
"Too fast, not enough proposers. Not reached. ";
212 <<
"normal consensus" << (stalled ?
", but stalled" :
"");
213 CLOG(clog) <<
"reached" << (stalled ?
", but stalled." :
".");
228 JLOG(j.
warn()) <<
"We see no consensus, but 80% of nodes have moved on";
229 CLOG(clog) <<
"We see no consensus, but 80% of nodes have moved on";
235 if (currentAgreeTime >
238 JLOG(j.
warn()) <<
"consensus taken too long";
239 CLOG(clog) <<
"Consensus taken too long. ";
245 JLOG(j.
trace()) <<
"no consensus";
246 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.
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 checkConsensusReached(std::size_t agreeing, std::size_t total, bool countSelf, 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.
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 ledgerMinClose
Minimum number of seconds to wait to ensure others have computed the LCL.
std::chrono::milliseconds const ledgerAbandonConsensus
Maximum amount of time to give a consensus round.
std::chrono::milliseconds const ledgerMinConsensus
The number of seconds we wait minimum to ensure participation.
std::chrono::milliseconds const ledgerMaxConsensus
The maximum amount of time to spend pausing for laggards.
std::size_t const minConsensusPct
The percentage threshold above which we can declare consensus.
std::size_t const ledgerAbandonConsensusFactor
How long to wait before completely abandoning consensus.