20#include <xrpld/consensus/Consensus.h>
21#include <xrpl/basics/Log.h>
40 CLOG(clog) <<
"shouldCloseLedger params anyTransactions: "
41 << anyTransactions <<
", prevProposers: " << prevProposers
42 <<
", proposersClosed: " << proposersClosed
43 <<
", proposersValidated: " << proposersValidated
44 <<
", prevRoundTime: " << prevRoundTime.
count() <<
"ms"
45 <<
", timeSincePrevClose: " << timeSincePrevClose.
count() <<
"ms"
46 <<
", openTime: " << openTime.
count() <<
"ms"
47 <<
", idleInterval: " << idleInterval.
count() <<
"ms"
50 using namespace std::chrono_literals;
51 if ((prevRoundTime < -1s) || (prevRoundTime > 10min) ||
52 (timeSincePrevClose > 10min))
56 ss <<
"shouldCloseLedger Trans=" << (anyTransactions ?
"yes" :
"no")
57 <<
" Prop: " << prevProposers <<
"/" << proposersClosed
58 <<
" Secs: " << timeSincePrevClose.
count()
59 <<
" (last: " << prevRoundTime.
count() <<
")";
62 CLOG(clog) <<
"closing ledger: " << ss.
str() <<
". ";
66 if ((proposersClosed + proposersValidated) > (prevProposers / 2))
69 JLOG(j.
trace()) <<
"Others have closed";
70 CLOG(clog) <<
"closing ledger because enough others have already. ";
77 CLOG(clog) <<
"no transactions, returning. ";
78 return timeSincePrevClose >= idleInterval;
84 JLOG(j.
debug()) <<
"Must wait minimum time before closing";
85 CLOG(clog) <<
"not closing because under ledgerMIN_CLOSE. ";
92 if (openTime < (prevRoundTime / 2))
94 JLOG(j.
debug()) <<
"Ledger has not been open long enough";
95 CLOG(clog) <<
"not closing because not open long enough. ";
100 CLOG(clog) <<
"no reason to not close. ";
113 CLOG(clog) <<
"checkConsensusReached params: agreeing: " << agreeing
114 <<
", total: " << total <<
", count_self: " << count_self
115 <<
", minConsensusPct: " << minConsensusPct
116 <<
", reachedMax: " << reachedMax <<
". ";
132 <<
"Consensus reached because nobody shares our position and "
133 "maximum duration has passed.";
136 CLOG(clog) <<
"Consensus not reached and nobody shares our position. ";
144 CLOG(clog) <<
"agreeing and total adjusted: " << agreeing <<
','
148 std::size_t currentPercentage = (agreeing * 100) / total;
149 CLOG(clog) <<
"currentPercentage: " << currentPercentage;
150 bool const ret = currentPercentage >= minConsensusPct;
153 CLOG(clog) <<
", consensus reached. ";
157 CLOG(clog) <<
", consensus not reached. ";
175 CLOG(clog) <<
"checkConsensus: prop=" << currentProposers <<
"/"
176 << prevProposers <<
" agree=" << currentAgree
177 <<
" validated=" << currentFinished
178 <<
" time=" << currentAgreeTime.
count() <<
"/"
180 <<
" minimum duration to reach consensus: "
189 CLOG(clog) <<
"Not reached. ";
193 if (currentProposers < (prevProposers * 3 / 4))
199 JLOG(j.
trace()) <<
"too fast, not enough proposers";
200 CLOG(clog) <<
"Too fast, not enough proposers. Not reached. ";
215 JLOG(j.
debug()) <<
"normal consensus";
216 CLOG(clog) <<
"reached. ";
230 JLOG(j.
warn()) <<
"We see no consensus, but 80% of nodes have moved on";
231 CLOG(clog) <<
"We see no consensus, but 80% of nodes have moved on";
236 JLOG(j.
trace()) <<
"no consensus";
237 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 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, 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.
@ proposing
We are normal participant in consensus and propose our position.
ConsensusState
Whether we have or don't have a consensus.
@ 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 count_self, std::size_t minConsensusPct, bool reachedMax, std::unique_ptr< std::stringstream > const &clog)
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::size_t minCONSENSUS_PCT
The percentage threshold above which we can declare consensus.
std::chrono::milliseconds ledgerMIN_CONSENSUS
The number of seconds we wait minimum to ensure participation.
std::chrono::milliseconds ledgerMAX_CONSENSUS
The maximum amount of time to spend pausing for laggards.
std::chrono::milliseconds ledgerMIN_CLOSE
Minimum number of seconds to wait to ensure others have computed the LCL.