rippled
Loading...
Searching...
No Matches
ConsensusParms.h
1#pragma once
2
3#include <xrpl/beast/utility/instrumentation.h>
4
5#include <chrono>
6#include <cstddef>
7#include <functional>
8#include <map>
9#include <optional>
10
11namespace xrpl {
12
19{
20 explicit ConsensusParms() = default;
21
22 //-------------------------------------------------------------------------
23 // Validation and proposal durations are relative to NetClock times, so use
24 // second resolution
32
40
47
50
53
54 //-------------------------------------------------------------------------
55 // Consensus durations are relative to the internal Consensus clock and use
56 // millisecond resolution.
57
60
63
66
74
77
80
83
91
103
104 //------------------------------------------------------------------------------
105 // Avalanche tuning
106 // As a function of the percent this round's duration is of the prior round,
107 // we increase the threshold for yes votes to add a transaction to our
108 // position.
122 // {state, {time, percent, nextState}},
123 // Initial state: 50% of nodes must vote yes
124 {init, {0, 50, mid}},
125 // mid-consensus starts after 50% of the previous round time, and
126 // requires 65% yes
127 {mid, {50, 65, late}},
128 // late consensus starts after 85% time, and requires 70% yes
129 {late, {85, 70, stuck}},
130 // we're stuck after 2x time, requires 95% yes votes
131 {stuck, {200, 95, stuck}},
132 };
133
136
138 // (Moving to the next avalanche level, considering that votes are stalled
139 // without consensus.)
141
145};
146
149 ConsensusParms const& p,
151 int percentTime,
152 std::size_t currentRounds,
153 std::size_t minimumRounds)
154{
155 // at() can throw, but the map is built by hand to ensure all valid
156 // values are available.
157 auto const& currentCutoff = p.avalancheCutoffs.at(currentState);
158 // Should we consider moving to the next state?
159 if (currentCutoff.next != currentState && currentRounds >= minimumRounds)
160 {
161 // at() can throw, but the map is built by hand to ensure all
162 // valid values are available.
163 auto const& nextCutoff = p.avalancheCutoffs.at(currentCutoff.next);
164 // See if enough time has passed to move on to the next.
165 XRPL_ASSERT(
166 nextCutoff.consensusTime >= currentCutoff.consensusTime, "xrpl::getNeededWeight : next state valid");
167 if (percentTime >= nextCutoff.consensusTime)
168 {
169 return {nextCutoff.consensusPct, currentCutoff.next};
170 }
171 }
172 return {currentCutoff.consensusPct, {}};
173}
174
175} // namespace xrpl
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
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 avCT_CONSENSUS_PCT
Percentage of nodes required to reach agreement on ledger close time.
std::chrono::milliseconds const ledgerIDLE_INTERVAL
The duration a ledger may remain idle before closing.
std::chrono::seconds const validationVALID_WALL
The duration a validation remains current after its ledger's close time.
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::seconds const proposeFRESHNESS
How long we consider a proposal fresh.
std::chrono::milliseconds const ledgerGRANULARITY
How often we check state or change positions.
std::chrono::milliseconds const ledgerMIN_CONSENSUS
The number of seconds we wait minimum to ensure participation.
std::chrono::seconds const proposeINTERVAL
How often we force generating a new proposal to keep ours fresh.
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 ledgerMIN_CLOSE
Minimum number of seconds to wait to ensure others have computed the LCL.
ConsensusParms()=default
std::size_t const avMIN_ROUNDS
Number of rounds before certain actions can happen.
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::seconds const validationVALID_EARLY
Duration pre-close in which validations are acceptable.
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_LOCAL
Duration a validation remains current after first observed.
std::size_t const ledgerABANDON_CONSENSUS_FACTOR
How long to wait before completely abandoning consensus.