rippled
Loading...
Searching...
No Matches
ConsensusParms.h
1#ifndef XRPL_CONSENSUS_CONSENSUS_PARMS_H_INCLUDED
2#define XRPL_CONSENSUS_CONSENSUS_PARMS_H_INCLUDED
3
4#include <xrpl/beast/utility/instrumentation.h>
5
6#include <chrono>
7#include <cstddef>
8#include <functional>
9#include <map>
10#include <optional>
11
12namespace ripple {
13
20{
21 explicit ConsensusParms() = default;
22
23 //-------------------------------------------------------------------------
24 // Validation and proposal durations are relative to NetClock times, so use
25 // second resolution
33
41
48
51
54
55 //-------------------------------------------------------------------------
56 // Consensus durations are relative to the internal Consensus clock and use
57 // millisecond resolution.
58
61
65
69
78
81
84
87
96
109
110 //------------------------------------------------------------------------------
111 // Avalanche tuning
112 // As a function of the percent this round's duration is of the prior round,
113 // we increase the threshold for yes votes to add a transaction to our
114 // position.
128 // {state, {time, percent, nextState}},
129 // Initial state: 50% of nodes must vote yes
130 {init, {0, 50, mid}},
131 // mid-consensus starts after 50% of the previous round time, and
132 // requires 65% yes
133 {mid, {50, 65, late}},
134 // late consensus starts after 85% time, and requires 70% yes
135 {late, {85, 70, stuck}},
136 // we're stuck after 2x time, requires 95% yes votes
137 {stuck, {200, 95, stuck}},
138 };
139
142
144 // (Moving to the next avalanche level, considering that votes are stalled
145 // without consensus.)
147
151};
152
155 ConsensusParms const& p,
157 int percentTime,
158 std::size_t currentRounds,
159 std::size_t minimumRounds)
160{
161 // at() can throw, but the map is built by hand to ensure all valid
162 // values are available.
163 auto const& currentCutoff = p.avalancheCutoffs.at(currentState);
164 // Should we consider moving to the next state?
165 if (currentCutoff.next != currentState && currentRounds >= minimumRounds)
166 {
167 // at() can throw, but the map is built by hand to ensure all
168 // valid values are available.
169 auto const& nextCutoff = p.avalancheCutoffs.at(currentCutoff.next);
170 // See if enough time has passed to move on to the next.
171 XRPL_ASSERT(
172 nextCutoff.consensusTime >= currentCutoff.consensusTime,
173 "ripple::getNeededWeight : next state valid");
174 if (percentTime >= nextCutoff.consensusTime)
175 {
176 return {nextCutoff.consensusPct, currentCutoff.next};
177 }
178 }
179 return {currentCutoff.consensusPct, {}};
180}
181
182} // namespace ripple
183#endif
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
std::pair< std::size_t, std::optional< ConsensusParms::AvalancheState > > getNeededWeight(ConsensusParms const &p, ConsensusParms::AvalancheState currentState, int percentTime, std::size_t currentRounds, std::size_t minimumRounds)
Consensus algorithm parameters.
std::size_t const avSTALLED_ROUNDS
Number of rounds before a stuck vote is considered unlikely to change because voting stalled.
std::chrono::milliseconds const ledgerGRANULARITY
How often we check state or change positions.
std::size_t const avCT_CONSENSUS_PCT
Percentage of nodes required to reach agreement on ledger close time.
std::chrono::seconds const proposeINTERVAL
How often we force generating a new proposal to keep ours fresh.
std::size_t const avMIN_ROUNDS
Number of rounds before certain actions can happen.
std::chrono::milliseconds const avMIN_CONSENSUS_TIME
The minimum amount of time to consider the previous round to have taken.
std::chrono::seconds const validationVALID_EARLY
Duration pre-close in which validations are acceptable.
std::chrono::milliseconds const ledgerIDLE_INTERVAL
The duration a ledger may remain idle before closing.
std::chrono::milliseconds const ledgerMIN_CONSENSUS
The number of seconds we wait minimum to ensure participation.
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::map< AvalancheState, AvalancheCutoff > const avalancheCutoffs
Map the consensus requirement avalanche state to the amount of time that must pass before moving to t...
std::chrono::milliseconds const ledgerMIN_CLOSE
Minimum number of seconds to wait to ensure others have computed the LCL.
std::chrono::seconds const proposeFRESHNESS
How long we consider a proposal fresh.
std::chrono::seconds const validationVALID_LOCAL
Duration a validation remains current after first observed.
std::chrono::milliseconds const ledgerMAX_CONSENSUS
The maximum amount of time to spend pausing for laggards.
std::chrono::seconds const validationVALID_WALL
The duration a validation remains current after its ledger's close time.
std::size_t const ledgerABANDON_CONSENSUS_FACTOR
How long to wait before completely abandoning consensus.