rippled
Loading...
Searching...
No Matches
ConsensusParms.h
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2012-2017 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#ifndef RIPPLE_CONSENSUS_CONSENSUS_PARMS_H_INCLUDED
21#define RIPPLE_CONSENSUS_CONSENSUS_PARMS_H_INCLUDED
22
23#include <xrpl/beast/utility/instrumentation.h>
24
25#include <chrono>
26#include <cstddef>
27#include <functional>
28#include <map>
29#include <optional>
30
31namespace ripple {
32
39{
40 explicit ConsensusParms() = default;
41
42 //-------------------------------------------------------------------------
43 // Validation and proposal durations are relative to NetClock times, so use
44 // second resolution
52
60
67
70
73
74 //-------------------------------------------------------------------------
75 // Consensus durations are relative to the internal Consensus clock and use
76 // millisecond resolution.
77
80
84
88
97
100
103
106
115
128
129 //------------------------------------------------------------------------------
130 // Avalanche tuning
131 // As a function of the percent this round's duration is of the prior round,
132 // we increase the threshold for yes votes to add a transaction to our
133 // position.
147 // {state, {time, percent, nextState}},
148 // Initial state: 50% of nodes must vote yes
149 {init, {0, 50, mid}},
150 // mid-consensus starts after 50% of the previous round time, and
151 // requires 65% yes
152 {mid, {50, 65, late}},
153 // late consensus starts after 85% time, and requires 70% yes
154 {late, {85, 70, stuck}},
155 // we're stuck after 2x time, requires 95% yes votes
156 {stuck, {200, 95, stuck}},
157 };
158
161
163 // (Moving to the next avalanche level, considering that votes are stalled
164 // without consensus.)
166
170};
171
174 ConsensusParms const& p,
176 int percentTime,
177 std::size_t currentRounds,
178 std::size_t minimumRounds)
179{
180 // at() can throw, but the map is built by hand to ensure all valid
181 // values are available.
182 auto const& currentCutoff = p.avalancheCutoffs.at(currentState);
183 // Should we consider moving to the next state?
184 if (currentCutoff.next != currentState && currentRounds >= minimumRounds)
185 {
186 // at() can throw, but the map is built by hand to ensure all
187 // valid values are available.
188 auto const& nextCutoff = p.avalancheCutoffs.at(currentCutoff.next);
189 // See if enough time has passed to move on to the next.
190 XRPL_ASSERT(
191 nextCutoff.consensusTime >= currentCutoff.consensusTime,
192 "ripple::getNeededWeight : next state valid");
193 if (percentTime >= nextCutoff.consensusTime)
194 {
195 return {nextCutoff.consensusPct, currentCutoff.next};
196 }
197 }
198 return {currentCutoff.consensusPct, {}};
199}
200
201} // namespace ripple
202#endif
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25
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.