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
149 {.consensusTime = 0, .consensusPct = 50, .next = AvalancheState::Mid}},
150 // mid-consensus starts after 50% of the previous round time, and
151 // requires 65% yes
153 {.consensusTime = 50, .consensusPct = 65, .next = AvalancheState::Late}},
154 // late consensus starts after 85% time, and requires 70% yes
156 {.consensusTime = 85, .consensusPct = 70, .next = AvalancheState::Stuck}},
157 // we're stuck after 2x time, requires 95% yes votes
159 {.consensusTime = 200, .consensusPct = 95, .next = AvalancheState::Stuck}},
160 };
161
166
170 // (Moving to the next avalanche level, considering that votes are stalled
171 // without consensus.)
173
179};
180
183 ConsensusParms const& p,
185 int percentTime,
186 std::size_t currentRounds,
187 std::size_t minimumRounds)
188{
189 // at() can throw, but the map is built by hand to ensure all valid
190 // values are available.
191 auto const& currentCutoff = p.avalancheCutoffs.at(currentState);
192 // Should we consider moving to the next state?
193 if (currentCutoff.next != currentState && currentRounds >= minimumRounds)
194 {
195 // at() can throw, but the map is built by hand to ensure all
196 // valid values are available.
197 auto const& nextCutoff = p.avalancheCutoffs.at(currentCutoff.next);
198 // See if enough time has passed to move on to the next.
199 XRPL_ASSERT(
200 nextCutoff.consensusTime >= currentCutoff.consensusTime,
201 "xrpl::getNeededWeight : next state valid");
202 if (percentTime >= nextCutoff.consensusTime)
203 {
204 return {nextCutoff.consensusPct, currentCutoff.next};
205 }
206 }
207 return {currentCutoff.consensusPct, {}};
208}
209
210} // 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.