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
26#include <xrpl/basics/chrono.h>
27
28#include <chrono>
29#include <map>
30
31namespace ripple {
32
70
71inline std::string
73{
74 switch (m)
75 {
77 return "proposing";
79 return "observing";
81 return "wrongLedger";
83 return "switchedLedger";
84 default:
85 return "unknown";
86 }
87}
88
105enum class ConsensusPhase {
107 open,
108
110 establish,
111
115 accepted,
116};
117
118inline std::string
120{
121 switch (p)
122 {
124 return "open";
126 return "establish";
128 return "accepted";
129 default:
130 return "unknown";
131 }
132}
133
137{
138 using time_point = std::chrono::steady_clock::time_point;
141
142public:
144 read() const
145 {
146 return dur_;
147 }
148
149 void
151 {
152 dur_ += fixed;
153 }
154
155 void
157 {
158 start_ = tp;
160 }
161
162 void
164 {
165 using namespace std::chrono;
166 dur_ = duration_cast<milliseconds>(tp - start_);
167 }
168};
169
186
188enum class ConsensusState {
189 No,
190 MovedOn,
191 Expired,
192 Yes
193};
194
203template <class Traits>
205{
206 using Ledger_t = typename Traits::Ledger_t;
207 using TxSet_t = typename Traits::TxSet_t;
208 using NodeID_t = typename Traits::NodeID_t;
209
210 using Tx_t = typename TxSet_t::Tx;
212 NodeID_t,
213 typename Ledger_t::ID,
214 typename TxSet_t::ID>;
216
218 : txns{std::move(s)}, position{std::move(p)}
219 {
220 XRPL_ASSERT(
221 txns.id() == position.position(),
222 "ripple::ConsensusResult : valid inputs");
223 }
224
227
230
233
234 // Set of TxSet ids we have already compared/created disputes
236
237 // Measures the duration of the establish phase for this consensus round
239
240 // Indicates state in which consensus ended. Once in the accept phase
241 // will be either Yes or MovedOn or Expired
243
244 // The number of peers proposing during the round
246};
247} // namespace ripple
248
249#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:49
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25
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.
@ Expired
Consensus time limit has hard-expired.
@ 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:630
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.
typename Traits::TxSet_t TxSet_t
Proposal_t position
Our proposed position on transactions/close time.