rippled
Loading...
Searching...
No Matches
ConsensusTypes.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_TYPES_H_INCLUDED
21#define RIPPLE_CONSENSUS_CONSENSUS_TYPES_H_INCLUDED
22
23#include <xrpld/consensus/ConsensusProposal.h>
24#include <xrpld/consensus/DisputedTx.h>
25#include <xrpl/basics/chrono.h>
26#include <chrono>
27#include <map>
28
29namespace ripple {
30
55enum class ConsensusMode {
67};
68
69inline std::string
71{
72 switch (m)
73 {
75 return "proposing";
77 return "observing";
79 return "wrongLedger";
81 return "switchedLedger";
82 default:
83 return "unknown";
84 }
85}
86
103enum class ConsensusPhase {
105 open,
106
108 establish,
109
113 accepted,
114};
115
116inline std::string
118{
119 switch (p)
120 {
122 return "open";
124 return "establish";
126 return "accepted";
127 default:
128 return "unknown";
129 }
130}
131
135{
136 using time_point = std::chrono::steady_clock::time_point;
139
140public:
142 read() const
143 {
144 return dur_;
145 }
146
147 void
149 {
150 dur_ += fixed;
151 }
152
153 void
155 {
156 start_ = tp;
158 }
159
160 void
162 {
163 using namespace std::chrono;
164 dur_ = duration_cast<milliseconds>(tp - start_);
165 }
166};
167
175{
176 explicit ConsensusCloseTimes() = default;
177
180
183};
184
186enum class ConsensusState {
187 No,
188 MovedOn,
189 Yes
190};
191
200template <class Traits>
202{
203 using Ledger_t = typename Traits::Ledger_t;
204 using TxSet_t = typename Traits::TxSet_t;
205 using NodeID_t = typename Traits::NodeID_t;
206
207 using Tx_t = typename TxSet_t::Tx;
209 NodeID_t,
210 typename Ledger_t::ID,
211 typename TxSet_t::ID>;
213
215 : txns{std::move(s)}, position{std::move(p)}
216 {
217 XRPL_ASSERT(
218 txns.id() == position.position(),
219 "ripple::ConsensusResult : valid inputs");
220 }
221
224
227
230
231 // Set of TxSet ids we have already compared/created disputes
233
234 // Measures the duration of the establish phase for this consensus round
236
237 // Indicates state in which consensus ended. Once in the accept phase
238 // will be either Yes or MovedOn
240
241 // The number of peers proposing during the round
243};
244} // namespace ripple
245
246#endif
Position_t const & position() const
Get the proposed position.
Measures the duration of phases of consensus.
std::chrono::milliseconds read() const
void reset(time_point tp)
std::chrono::milliseconds dur_
std::chrono::steady_clock::time_point time_point
void tick(std::chrono::milliseconds fixed)
void tick(time_point tp)
A transaction discovered to be in dispute during consensus.
Definition: DisputedTx.h:51
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
ConsensusMode
Represents how a node currently participates in Consensus.
@ wrongLedger
We have the wrong ledger and are attempting to acquire it.
@ proposing
We are normal participant in consensus and propose our position.
@ switchedLedger
We switched ledgers since we started this consensus round but are now running on what we believe is t...
@ observing
We are observing peer positions, but not proposing our position.
ConsensusPhase
Phases of consensus for a single ledger round.
@ accepted
We have accepted a new last closed ledger and are waiting on a call to startRound to begin the next c...
@ open
We haven't closed our ledger yet, but others might have.
@ establish
Establishing consensus by exchanging proposals with our peers.
ConsensusState
Whether we have or don't have a consensus.
@ MovedOn
The network has consensus without us.
@ No
We do not have consensus.
@ accepted
Manifest is valid.
std::string to_string(base_uint< Bits, Tag > const &a)
Definition: base_uint.h:629
STL namespace.
Stores the set of initial close times.
std::map< NetClock::time_point, int > peers
Close time estimates, keep ordered for predictable traverse.
NetClock::time_point self
Our close time estimate.
Encapsulates the result of consensus.
typename Traits::Ledger_t Ledger_t
ConsensusResult(TxSet_t &&s, Proposal_t &&p)
typename TxSet_t::Tx Tx_t
hash_map< typename Tx_t::ID, Dispute_t > disputes
Transactions which are under dispute with our peers.
hash_set< typename TxSet_t::ID > compares
typename Traits::NodeID_t NodeID_t
TxSet_t txns
The set of transactions consensus agrees go in the ledger.
ConsensusTimer roundTime
typename Traits::TxSet_t TxSet_t
Proposal_t position
Our proposed position on transactions/close time.