xrpld
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 <map>
8#include <optional>
9#include <utility>
10
11namespace xrpl {
12
20{
21 explicit ConsensusParms() = default;
22
23 //-------------------------------------------------------------------------
24 // Validation and proposal durations are relative to NetClock times, so use
25 // second resolution
34
43
51
56
61
62 //-------------------------------------------------------------------------
63 // Consensus durations are relative to the internal Consensus clock and use
64 // millisecond resolution.
65
70
75
80
89
94
99
104
112
125
126 //------------------------------------------------------------------------------
127 // Avalanche tuning
128 // As a function of the percent this round's duration is of the prior round,
129 // we increase the threshold for yes votes to add a transaction to our
130 // position.
131 enum class AvalancheState { Init, Mid, Late, Stuck };
138
146 // {state, {time, percent, nextState}},
147 // Initial state: 50% of nodes must vote yes
148 {
150 {.consensusTime = 0, .consensusPct = 50, .next = AvalancheState::Mid},
151 },
152 // mid-consensus starts after 50% of the previous round time, and
153 // requires 65% yes
154 {
156 {.consensusTime = 50, .consensusPct = 65, .next = AvalancheState::Late},
157 },
158 // late consensus starts after 85% time, and requires 70% yes
159 {
161 {.consensusTime = 85, .consensusPct = 70, .next = AvalancheState::Stuck},
162 },
163 // we're stuck after 2x time, requires 95% yes votes
164 {
166 {.consensusTime = 200, .consensusPct = 95, .next = AvalancheState::Stuck},
167 },
168 };
169
174
178 // (Moving to the next avalanche level, considering that votes are stalled
179 // without consensus.)
181
187};
188
191 ConsensusParms const& p,
193 int percentTime,
194 std::size_t currentRounds,
195 std::size_t minimumRounds)
196{
197 // at() can throw, but the map is built by hand to ensure all valid
198 // values are available.
199 auto const& currentCutoff = p.avalancheCutoffs.at(currentState);
200 // Should we consider moving to the next state?
201 if (currentCutoff.next != currentState && currentRounds >= minimumRounds)
202 {
203 // at() can throw, but the map is built by hand to ensure all
204 // valid values are available.
205 auto const& nextCutoff = p.avalancheCutoffs.at(currentCutoff.next);
206 // See if enough time has passed to move on to the next.
207 XRPL_ASSERT(
208 nextCutoff.consensusTime >= currentCutoff.consensusTime,
209 "xrpl::getNeededWeight : next state valid");
210 if (percentTime >= nextCutoff.consensusTime)
211 {
212 return {nextCutoff.consensusPct, currentCutoff.next};
213 }
214 }
215 return {currentCutoff.consensusPct, {}};
216}
217
218} // 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::chrono::milliseconds const ledgerMinClose
Minimum number of seconds to wait to ensure others have computed the LCL.
std::size_t const avCtConsensusPct
Percentage of nodes required to reach agreement on ledger close time.
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::size_t const avMinRounds
Number of rounds before certain actions can happen.
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::seconds const validationValidWall
The duration a validation remains current after its ledger's close time.
std::chrono::seconds const proposeINTERVAL
How often we force generating a new proposal to keep ours fresh.
std::chrono::seconds const validationValidEarly
Duration pre-close in which validations are acceptable.
ConsensusParms()=default
std::chrono::milliseconds const ledgerMaxConsensus
The maximum amount of time to spend pausing for laggards.
std::size_t const avStalledRounds
Number of rounds before a stuck vote is considered unlikely to change because voting stalled.
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::size_t const minConsensusPct
The percentage threshold above which we can declare consensus.
std::chrono::milliseconds const avMinConsensusTime
The minimum amount of time to consider the previous round to have taken.
std::chrono::seconds const validationValidLocal
Duration a validation remains current after first observed.
std::size_t const ledgerAbandonConsensusFactor
How long to wait before completely abandoning consensus.
std::chrono::milliseconds const ledgerIdleInterval
The duration a ledger may remain idle before closing.