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 <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.
109 enum class AvalancheState { Init, Mid, Late, Stuck };
116
122 // {state, {time, percent, nextState}},
123 // Initial state: 50% of nodes must vote yes
125 {.consensusTime = 0, .consensusPct = 50, .next = AvalancheState::Mid}},
126 // mid-consensus starts after 50% of the previous round time, and
127 // requires 65% yes
129 {.consensusTime = 50, .consensusPct = 65, .next = AvalancheState::Late}},
130 // late consensus starts after 85% time, and requires 70% yes
132 {.consensusTime = 85, .consensusPct = 70, .next = AvalancheState::Stuck}},
133 // we're stuck after 2x time, requires 95% yes votes
135 {.consensusTime = 200, .consensusPct = 95, .next = AvalancheState::Stuck}},
136 };
137
140
142 // (Moving to the next avalanche level, considering that votes are stalled
143 // without consensus.)
145
149};
150
153 ConsensusParms const& p,
155 int percentTime,
156 std::size_t currentRounds,
157 std::size_t minimumRounds)
158{
159 // at() can throw, but the map is built by hand to ensure all valid
160 // values are available.
161 auto const& currentCutoff = p.avalancheCutoffs.at(currentState);
162 // Should we consider moving to the next state?
163 if (currentCutoff.next != currentState && currentRounds >= minimumRounds)
164 {
165 // at() can throw, but the map is built by hand to ensure all
166 // valid values are available.
167 auto const& nextCutoff = p.avalancheCutoffs.at(currentCutoff.next);
168 // See if enough time has passed to move on to the next.
169 XRPL_ASSERT(
170 nextCutoff.consensusTime >= currentCutoff.consensusTime,
171 "xrpl::getNeededWeight : next state valid");
172 if (percentTime >= nextCutoff.consensusTime)
173 {
174 return {nextCutoff.consensusPct, currentCutoff.next};
175 }
176 }
177 return {currentCutoff.consensusPct, {}};
178}
179
180} // 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
std::map< AvalancheState, AvalancheCutoff > const avalancheCutoffs
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.